From 6aee7848bb00dd3742fbb1b8c65610188e77d939 Mon Sep 17 00:00:00 2001 From: Chia-I Wu Date: Thu, 20 Apr 2023 22:37:02 -0700 Subject: [PATCH] radv: improve externalMemoryFeatures for android ahb VK_EXTERNAL_MEMORY_FEATURE_DEDICATED_ONLY_BIT should always be set, as required by the spec. VK_EXTERNAL_MEMORY_FEATURE_EXPORTABLE_BIT should be set when radv_ahb_format_for_vk_format knowns the format. That is, radv_create_ahb_memory should at least know how to call AHardwareBuffer_allocate. VK_EXTERNAL_MEMORY_FEATURE_IMPORTABLE_BIT is always set. We can't know if gralloc can allocate the format/flags/usage combo or not (gralloc might use a private format for the combo). Fixed dEQP-VK.api.external.memory.android_hardware_buffer.image_formats.*. Part-of: --- src/amd/vulkan/radv_android.c | 20 +++++--------------- src/amd/vulkan/radv_formats.c | 12 ++++++------ 2 files changed, 11 insertions(+), 21 deletions(-) diff --git a/src/amd/vulkan/radv_android.c b/src/amd/vulkan/radv_android.c index 53b18d4b7b9..9785f5294ab 100644 --- a/src/amd/vulkan/radv_android.c +++ b/src/amd/vulkan/radv_android.c @@ -737,21 +737,11 @@ bool radv_android_gralloc_supports_format(VkFormat format, VkImageUsageFlagBits usage) { #if RADV_SUPPORT_ANDROID_HARDWARE_BUFFER - /* Ideally we check Gralloc for what it supports and then merge that with the radv - format support, but there is no easy gralloc query besides just creating an image. - That seems a bit on the expensive side, so just hardcode for now. */ - /* TODO: Add multi-plane formats after confirming everything works between radeonsi - and radv. */ - switch (format) { - case VK_FORMAT_R8G8B8A8_UNORM: - case VK_FORMAT_R5G6B5_UNORM_PACK16: - return true; - case VK_FORMAT_R8_UNORM: - case VK_FORMAT_R8G8_UNORM: - return !(usage & VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT); - default: - return false; - } + /* Ideally we check AHardwareBuffer_isSupported. But that test-allocates on most platforms and + * seems a bit on the expensive side. Return true as long as it is a format we understand. + */ + (void)usage; + return radv_ahb_format_for_vk_format(format); #else (void)format; (void)usage; diff --git a/src/amd/vulkan/radv_formats.c b/src/amd/vulkan/radv_formats.c index ed24cf2805b..7164312baa1 100644 --- a/src/amd/vulkan/radv_formats.c +++ b/src/amd/vulkan/radv_formats.c @@ -1723,9 +1723,6 @@ get_external_image_format_properties(struct radv_physical_device *physical_devic if (!physical_device->vk.supported_extensions.ANDROID_external_memory_android_hardware_buffer) break; - if (!radv_android_gralloc_supports_format(pImageFormatInfo->format, pImageFormatInfo->usage)) - break; - if (pImageFormatInfo->type != VK_IMAGE_TYPE_2D) break; @@ -1733,9 +1730,12 @@ get_external_image_format_properties(struct radv_physical_device *physical_devic format_properties->maxArrayLayers = MIN2(1, format_properties->maxArrayLayers); format_properties->sampleCounts &= VK_SAMPLE_COUNT_1_BIT; - flags = VK_EXTERNAL_MEMORY_FEATURE_EXPORTABLE_BIT | VK_EXTERNAL_MEMORY_FEATURE_IMPORTABLE_BIT; - if (pImageFormatInfo->tiling != VK_IMAGE_TILING_LINEAR) - flags |= VK_EXTERNAL_MEMORY_FEATURE_DEDICATED_ONLY_BIT; + flags = VK_EXTERNAL_MEMORY_FEATURE_DEDICATED_ONLY_BIT | + VK_EXTERNAL_MEMORY_FEATURE_IMPORTABLE_BIT; + + /* advertise EXPORTABLE only when radv_create_ahb_memory supports the format */ + if (radv_android_gralloc_supports_format(pImageFormatInfo->format, pImageFormatInfo->usage)) + flags |= VK_EXTERNAL_MEMORY_FEATURE_EXPORTABLE_BIT; compat_flags = VK_EXTERNAL_MEMORY_HANDLE_TYPE_ANDROID_HARDWARE_BUFFER_BIT_ANDROID; break;