From 710282f83cc00bd9c0100a217f095f81b0279c79 Mon Sep 17 00:00:00 2001 From: Yiwei Zhang Date: Mon, 16 Jun 2025 00:54:47 -0700 Subject: [PATCH] anv: adopt common Android gralloc helpers u_gralloc will be initialized upon the initial vk_android_get_ugralloc. v2: drop explicit gralloc init Reviewed-by: Lionel Landwerlin (v1) Acked-by: Rob Clark Part-of: --- src/intel/vulkan/anv_android.c | 12 +++++++----- src/intel/vulkan/anv_device.c | 11 ----------- src/intel/vulkan/anv_formats.c | 1 - src/intel/vulkan/anv_physical_device.c | 6 ++---- src/intel/vulkan/anv_private.h | 4 +--- 5 files changed, 10 insertions(+), 24 deletions(-) diff --git a/src/intel/vulkan/anv_android.c b/src/intel/vulkan/anv_android.c index 6a50c5ef217..1b8947f5595 100644 --- a/src/intel/vulkan/anv_android.c +++ b/src/intel/vulkan/anv_android.c @@ -331,10 +331,11 @@ anv_android_get_tiling(struct anv_device *device, struct u_gralloc_buffer_handle *gr_handle, enum isl_tiling *tiling_out) { - assert(device->u_gralloc); + struct u_gralloc *gralloc = vk_android_get_ugralloc(); + assert(gralloc); struct u_gralloc_buffer_basic_info buf_info; - if (u_gralloc_get_buffer_basic_info(device->u_gralloc, gr_handle, &buf_info)) + if (u_gralloc_get_buffer_basic_info(gralloc, gr_handle, &buf_info)) return vk_errorf(device, VK_ERROR_INVALID_EXTERNAL_HANDLE, "failed to get tiling from gralloc buffer info"); @@ -385,7 +386,7 @@ anv_image_init_from_gralloc(struct anv_device *device, } enum isl_tiling tiling; - if (device->u_gralloc) { + if (vk_android_get_ugralloc()) { struct u_gralloc_buffer_handle gr_handle = { .handle = gralloc_info->handle, .hal_format = gralloc_info->format, @@ -644,10 +645,11 @@ VkResult anv_GetSwapchainGrallocUsage2ANDROID( *grallocConsumerUsage |= GRALLOC1_CONSUMER_USAGE_HWCOMPOSER; } + struct u_gralloc *gralloc = vk_android_get_ugralloc(); if ((swapchainImageUsage & VK_SWAPCHAIN_IMAGE_USAGE_SHARED_BIT_ANDROID) && - device->u_gralloc != NULL) { + gralloc) { uint64_t front_rendering_usage = 0; - u_gralloc_get_front_rendering_usage(device->u_gralloc, &front_rendering_usage); + u_gralloc_get_front_rendering_usage(gralloc, &front_rendering_usage); *grallocProducerUsage |= front_rendering_usage; } diff --git a/src/intel/vulkan/anv_device.c b/src/intel/vulkan/anv_device.c index bb642647d08..aa01c8f6b92 100644 --- a/src/intel/vulkan/anv_device.c +++ b/src/intel/vulkan/anv_device.c @@ -36,9 +36,6 @@ #include "util/os_file.h" #include "util/os_misc.h" #include "util/u_atomic.h" -#if DETECT_OS_ANDROID -#include "util/u_gralloc/u_gralloc.h" -#endif #include "util/u_string.h" #include "vk_common_entrypoints.h" #include "vk_util.h" @@ -912,10 +909,6 @@ VkResult anv_CreateDevice( goto fail_internal_cache; } -#if DETECT_OS_ANDROID - device->u_gralloc = u_gralloc_create(U_GRALLOC_TYPE_AUTO); -#endif - device->robust_buffer_access = device->vk.enabled_features.robustBufferAccess || device->vk.enabled_features.nullDescriptor; @@ -1157,10 +1150,6 @@ void anv_DestroyDevice( if (!device) return; -#if DETECT_OS_ANDROID - u_gralloc_destroy(&device->u_gralloc); -#endif - anv_memory_trace_finish(device); struct anv_physical_device *pdevice = device->physical; diff --git a/src/intel/vulkan/anv_formats.c b/src/intel/vulkan/anv_formats.c index 7dd47682add..d865574453f 100644 --- a/src/intel/vulkan/anv_formats.c +++ b/src/intel/vulkan/anv_formats.c @@ -23,7 +23,6 @@ #include "anv_private.h" #include "drm-uapi/drm_fourcc.h" -#include "vk_android.h" #include "vk_enum_defines.h" #include "vk_enum_to_str.h" #include "vk_format.h" diff --git a/src/intel/vulkan/anv_physical_device.c b/src/intel/vulkan/anv_physical_device.c index 07e609ca881..7c856685dad 100644 --- a/src/intel/vulkan/anv_physical_device.c +++ b/src/intel/vulkan/anv_physical_device.c @@ -1266,11 +1266,9 @@ get_properties(const struct anv_physical_device *pdevice, #if DETECT_OS_ANDROID /* Used to fill struct VkPhysicalDevicePresentationPropertiesANDROID */ uint64_t front_rendering_usage = 0; - struct u_gralloc *gralloc = u_gralloc_create(U_GRALLOC_TYPE_AUTO); - if (gralloc != NULL) { + struct u_gralloc *gralloc = vk_android_get_ugralloc(); + if (gralloc != NULL) u_gralloc_get_front_rendering_usage(gralloc, &front_rendering_usage); - u_gralloc_destroy(&gralloc); - } #endif /* DETECT_OS_ANDROID */ struct anv_descriptor_limits desc_limits; diff --git a/src/intel/vulkan/anv_private.h b/src/intel/vulkan/anv_private.h index a472992bb1f..020ffe732a1 100644 --- a/src/intel/vulkan/anv_private.h +++ b/src/intel/vulkan/anv_private.h @@ -74,6 +74,7 @@ #include "util/xmlconfig.h" #include "vk_acceleration_structure.h" #include "vk_alloc.h" +#include "vk_android.h" #include "vk_buffer.h" #include "vk_buffer_view.h" #include "vk_command_buffer.h" @@ -2136,9 +2137,6 @@ struct anv_device { uint32_t draw_call_count; struct anv_state breakpoint; -#if DETECT_OS_ANDROID - struct u_gralloc *u_gralloc; -#endif /** Precompute all dirty graphics bits *