anv,hasvk: android ahb is not always exportable
authorChia-I Wu <olvaffe@gmail.com>
Fri, 21 Apr 2023 05:34:59 +0000 (22:34 -0700)
committerMarge Bot <emma+marge@anholt.net>
Thu, 11 May 2023 22:18:03 +0000 (22:18 +0000)
anv_ahb_format_for_vk_format needs to know the format at least.  There
is no guarantee that AHardwareBuffer_allocate will succeed, but we are
reluctant to check with AHardwareBuffer_isSupported which may
test-allocate internally and is expensive.

v2: add anv_ahb_format_for_vk_format to anv_android_stubs.c

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/22619>

src/intel/vulkan/anv_android_stubs.c
src/intel/vulkan/anv_formats.c
src/intel/vulkan_hasvk/anv_android.h
src/intel/vulkan_hasvk/anv_android_stubs.c
src/intel/vulkan_hasvk/anv_formats.c
src/intel/vulkan_hasvk/anv_private.h

index 4e8c05f..f1b2ef6 100644 (file)
@@ -39,6 +39,11 @@ VkResult anv_image_bind_from_gralloc(struct anv_device *device,
    return VK_ERROR_EXTENSION_NOT_PRESENT;
 }
 
+unsigned anv_ahb_format_for_vk_format(VkFormat vk_format)
+{
+   return 0;
+}
+
 VkResult
 anv_import_ahw_memory(VkDevice device_h,
                       struct anv_device_memory *mem)
index 0a71bae..a726229 100644 (file)
@@ -1511,8 +1511,8 @@ static const VkExternalMemoryProperties android_buffer_props = {
 
 
 static const VkExternalMemoryProperties android_image_props = {
-   .externalMemoryFeatures = VK_EXTERNAL_MEMORY_FEATURE_EXPORTABLE_BIT |
-                             VK_EXTERNAL_MEMORY_FEATURE_IMPORTABLE_BIT |
+   /* VK_EXTERNAL_MEMORY_FEATURE_EXPORTABLE_BIT will be set dynamically */
+   .externalMemoryFeatures = VK_EXTERNAL_MEMORY_FEATURE_IMPORTABLE_BIT |
                              VK_EXTERNAL_MEMORY_FEATURE_DEDICATED_ONLY_BIT,
    .exportFromImportedHandleTypes =
       VK_EXTERNAL_MEMORY_HANDLE_TYPE_ANDROID_HARDWARE_BUFFER_BIT_ANDROID,
@@ -1705,6 +1705,10 @@ VkResult anv_GetPhysicalDeviceImageFormatProperties2(
           */
          if (ahw_supported && external_props) {
             external_props->externalMemoryProperties = android_image_props;
+            if (anv_ahb_format_for_vk_format(base_info->format)) {
+               external_props->externalMemoryProperties.externalMemoryFeatures |=
+                  VK_EXTERNAL_MEMORY_FEATURE_EXPORTABLE_BIT;
+            }
             break;
          }
          FALLTHROUGH; /* If ahw not supported */
index f0a47e6..d8c3113 100644 (file)
@@ -44,6 +44,8 @@ VkResult anv_image_bind_from_gralloc(struct anv_device *device,
                                      struct anv_image *image,
                                      const VkNativeBufferANDROID *gralloc_info);
 
+unsigned anv_ahb_format_for_vk_format(VkFormat vk_format);
+
 VkResult anv_import_ahw_memory(VkDevice device_h,
                                struct anv_device_memory *mem,
                                const VkImportAndroidHardwareBufferInfoANDROID *info);
index 53e0af0..491d502 100644 (file)
@@ -39,6 +39,11 @@ VkResult anv_image_bind_from_gralloc(struct anv_device *device,
    return VK_ERROR_EXTENSION_NOT_PRESENT;
 }
 
+unsigned anv_ahb_format_for_vk_format(VkFormat vk_format)
+{
+   return 0;
+}
+
 VkResult
 anv_import_ahw_memory(VkDevice device_h,
                       struct anv_device_memory *mem,
index ee883ab..ba9ed47 100644 (file)
@@ -1354,8 +1354,8 @@ static const VkExternalMemoryProperties android_buffer_props = {
 
 
 static const VkExternalMemoryProperties android_image_props = {
-   .externalMemoryFeatures = VK_EXTERNAL_MEMORY_FEATURE_EXPORTABLE_BIT |
-                             VK_EXTERNAL_MEMORY_FEATURE_IMPORTABLE_BIT |
+   /* VK_EXTERNAL_MEMORY_FEATURE_EXPORTABLE_BIT will be set dynamically */
+   .externalMemoryFeatures = VK_EXTERNAL_MEMORY_FEATURE_IMPORTABLE_BIT |
                              VK_EXTERNAL_MEMORY_FEATURE_DEDICATED_ONLY_BIT,
    .exportFromImportedHandleTypes =
       VK_EXTERNAL_MEMORY_HANDLE_TYPE_ANDROID_HARDWARE_BUFFER_BIT_ANDROID,
@@ -1546,6 +1546,10 @@ VkResult anv_GetPhysicalDeviceImageFormatProperties2(
           */
          if (ahw_supported && external_props) {
             external_props->externalMemoryProperties = android_image_props;
+            if (anv_ahb_format_for_vk_format(base_info->format)) {
+               external_props->externalMemoryProperties.externalMemoryFeatures |=
+                  VK_EXTERNAL_MEMORY_FEATURE_EXPORTABLE_BIT;
+            }
             break;
          }
          FALLTHROUGH; /* If ahw not supported */
index 7d6c985..51233fa 100644 (file)
@@ -3132,8 +3132,6 @@ anv_get_isl_format(const struct intel_device_info *devinfo, VkFormat vk_format,
 extern VkFormat
 vk_format_from_android(unsigned android_format, unsigned android_usage);
 
-unsigned anv_ahb_format_for_vk_format(VkFormat vk_format);
-
 static inline struct isl_swizzle
 anv_swizzle_for_render(struct isl_swizzle swizzle)
 {