From b492f73f87ab80dfae0d89631b5286ec8d4e8be4 Mon Sep 17 00:00:00 2001 From: Chris Spencer Date: Tue, 29 Aug 2023 20:26:20 +0100 Subject: [PATCH] anv/android: Enable shared presentable image support MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Chris Spencer Reviewed-by: Roman Stratiienko Reviewed-by: Tapani Pälli Part-of: --- src/intel/vulkan/anv_android.c | 10 +++++++++- src/intel/vulkan/anv_device.c | 21 ++++++++++++++++++++- src/intel/vulkan/anv_private.h | 6 ++++++ src/intel/vulkan/meson.build | 1 + 4 files changed, 36 insertions(+), 2 deletions(-) diff --git a/src/intel/vulkan/anv_android.c b/src/intel/vulkan/anv_android.c index 05fb87feb8e..9dd3114f621 100644 --- a/src/intel/vulkan/anv_android.c +++ b/src/intel/vulkan/anv_android.c @@ -570,7 +570,8 @@ VkResult anv_GetSwapchainGrallocUsage2ANDROID( *grallocConsumerUsage = 0; *grallocProducerUsage = 0; - mesa_logd("%s: format=%d, usage=0x%x", __func__, format, imageUsage); + mesa_logd("%s: format=%d, usage=0x%x, swapchainUsage=0x%x", __func__, format, + imageUsage, swapchainImageUsage); result = format_supported_with_usage(device_h, format, imageUsage); if (result != VK_SUCCESS) @@ -599,6 +600,13 @@ VkResult anv_GetSwapchainGrallocUsage2ANDROID( *grallocConsumerUsage |= GRALLOC1_CONSUMER_USAGE_HWCOMPOSER; } + if ((swapchainImageUsage & VK_SWAPCHAIN_IMAGE_USAGE_SHARED_BIT_ANDROID) && + device->u_gralloc != NULL) { + uint64_t front_rendering_usage = 0; + u_gralloc_get_front_rendering_usage(device->u_gralloc, &front_rendering_usage); + *grallocProducerUsage |= front_rendering_usage; + } + return VK_SUCCESS; } #endif diff --git a/src/intel/vulkan/anv_device.c b/src/intel/vulkan/anv_device.c index 1c50a5c3977..0602da77087 100644 --- a/src/intel/vulkan/anv_device.c +++ b/src/intel/vulkan/anv_device.c @@ -48,6 +48,9 @@ #include "util/os_file.h" #include "util/os_misc.h" #include "util/u_atomic.h" +#ifdef ANDROID +#include "util/u_gralloc/u_gralloc.h" +#endif #include "util/u_string.h" #include "util/driconf.h" #include "git_sha1.h" @@ -2449,15 +2452,23 @@ void anv_GetPhysicalDeviceProperties2( break; } +#ifdef ANDROID #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wswitch" case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PRESENTATION_PROPERTIES_ANDROID: { VkPhysicalDevicePresentationPropertiesANDROID *props = (VkPhysicalDevicePresentationPropertiesANDROID *)ext; - props->sharedImage = VK_FALSE; + uint64_t front_rendering_usage = 0; + struct u_gralloc *gralloc = u_gralloc_create(U_GRALLOC_TYPE_AUTO); + if (gralloc != NULL) { + u_gralloc_get_front_rendering_usage(gralloc, &front_rendering_usage); + u_gralloc_destroy(&gralloc); + } + props->sharedImage = front_rendering_usage ? VK_TRUE : VK_FALSE; break; } #pragma GCC diagnostic pop +#endif case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROVOKING_VERTEX_PROPERTIES_EXT: { VkPhysicalDeviceProvokingVertexPropertiesEXT *properties = @@ -3447,6 +3458,10 @@ VkResult anv_CreateDevice( goto fail_internal_cache; } +#ifdef 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; @@ -3546,6 +3561,10 @@ void anv_DestroyDevice( if (!device) return; +#ifdef ANDROID + u_gralloc_destroy(&device->u_gralloc); +#endif + struct anv_physical_device *pdevice = device->physical; anv_device_utrace_finish(device); diff --git a/src/intel/vulkan/anv_private.h b/src/intel/vulkan/anv_private.h index a2723903fa7..50471ed7338 100644 --- a/src/intel/vulkan/anv_private.h +++ b/src/intel/vulkan/anv_private.h @@ -63,6 +63,9 @@ #include "util/set.h" #include "util/sparse_array.h" #include "util/u_atomic.h" +#ifdef ANDROID +#include "util/u_gralloc/u_gralloc.h" +#endif #include "util/u_vector.h" #include "util/u_math.h" #include "util/vma.h" @@ -1298,6 +1301,9 @@ struct anv_device { uint32_t draw_call_count; struct anv_state breakpoint; +#ifdef ANDROID + struct u_gralloc *u_gralloc; +#endif }; static inline struct anv_state diff --git a/src/intel/vulkan/meson.build b/src/intel/vulkan/meson.build index 0cc6fdd3dbe..cc742d10bed 100644 --- a/src/intel/vulkan/meson.build +++ b/src/intel/vulkan/meson.build @@ -210,6 +210,7 @@ if with_xlib_lease endif if with_platform_android + anv_deps += idep_u_gralloc libanv_files += files('anv_android.c') else libanv_files += files('anv_android_stubs.c')