radv: Expose image handle compat types for Android handles.
authorBas Nieuwenhuizen <bas@basnieuwenhuizen.nl>
Tue, 8 Oct 2019 20:15:43 +0000 (22:15 +0200)
committerBas Nieuwenhuizen <bas@basnieuwenhuizen.nl>
Thu, 10 Oct 2019 17:02:34 +0000 (17:02 +0000)
Reviewed-by: Samuel Pitoiset <samuel.pitoiset@gmail.com>
src/amd/vulkan/radv_android.c
src/amd/vulkan/radv_formats.c
src/amd/vulkan/radv_private.h

index 07123bf0af9f5c21a11277801f68c7d3a0dd414c..8716c4f4660abf7ee7e47c81b06633ed0dfad9ae 100644 (file)
@@ -742,3 +742,27 @@ radv_create_ahb_memory(struct radv_device *device,
        return VK_ERROR_EXTENSION_NOT_PRESENT;
 #endif
 }
+
+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;
+       }
+#else
+       (void)format;
+       (void)usage;
+       return false;
+#endif
+}
index 0a84b064b2188d2daf100a3c8e33017b77e63907..01917875528b2052e26e12cfa19b39d4503e6645 100644 (file)
@@ -1299,9 +1299,11 @@ VkResult radv_GetPhysicalDeviceImageFormatProperties(
 }
 
 static void
-get_external_image_format_properties(const VkPhysicalDeviceImageFormatInfo2 *pImageFormatInfo,
+get_external_image_format_properties(struct radv_physical_device *physical_device,
+                                    const VkPhysicalDeviceImageFormatInfo2 *pImageFormatInfo,
                                     VkExternalMemoryHandleTypeFlagBits handleType,
-                                    VkExternalMemoryProperties *external_properties)
+                                    VkExternalMemoryProperties *external_properties,
+                                    VkImageFormatProperties *format_properties)
 {
        VkExternalMemoryFeatureFlagBits flags = 0;
        VkExternalMemoryHandleTypeFlags export_flags = 0;
@@ -1323,6 +1325,24 @@ get_external_image_format_properties(const VkPhysicalDeviceImageFormatInfo2 *pIm
                        break;
                }
                break;
+       case VK_EXTERNAL_MEMORY_HANDLE_TYPE_ANDROID_HARDWARE_BUFFER_BIT_ANDROID:
+               if (!physical_device->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;
+
+               format_properties->maxMipLevels = MIN2(1, format_properties->maxMipLevels);
+               format_properties->maxArrayLayers = MIN2(1, format_properties->maxArrayLayers);
+               format_properties->sampleCounts &= VK_SAMPLE_COUNT_1_BIT;
+
+               flags = VK_EXTERNAL_MEMORY_FEATURE_DEDICATED_ONLY_BIT|VK_EXTERNAL_MEMORY_FEATURE_EXPORTABLE_BIT|VK_EXTERNAL_MEMORY_FEATURE_IMPORTABLE_BIT;
+               compat_flags = VK_EXTERNAL_MEMORY_HANDLE_TYPE_ANDROID_HARDWARE_BUFFER_BIT_ANDROID;
+               break;
        case VK_EXTERNAL_MEMORY_HANDLE_TYPE_HOST_ALLOCATION_BIT_EXT:
                flags = VK_EXTERNAL_MEMORY_FEATURE_IMPORTABLE_BIT;
                compat_flags = VK_EXTERNAL_MEMORY_HANDLE_TYPE_HOST_ALLOCATION_BIT_EXT;
@@ -1400,8 +1420,9 @@ VkResult radv_GetPhysicalDeviceImageFormatProperties2(
         *    present and VkExternalImageFormatProperties will be ignored.
         */
        if (external_info && external_info->handleType != 0) {
-               get_external_image_format_properties(base_info, external_info->handleType,
-                                                    &external_props->externalMemoryProperties);
+               get_external_image_format_properties(physical_device, base_info, external_info->handleType,
+                                                    &external_props->externalMemoryProperties,
+                                                    &base_props->imageFormatProperties);
                if (!external_props->externalMemoryProperties.externalMemoryFeatures) {
                        /* From the Vulkan 1.0.97 spec:
                         *
index ee69ccf6f0f07a8dda3e7d6a688abfc86714f906..1995d59045f34aa3630331cb6a1f79aecf2dcfc2 100644 (file)
@@ -1947,6 +1947,7 @@ radv_create_ahb_memory(struct radv_device *device,
 VkFormat
 radv_select_android_external_format(const void *next, VkFormat default_format);
 
+bool radv_android_gralloc_supports_format(VkFormat format, VkImageUsageFlagBits usage);
 
 struct radv_image_view_extra_create_info {
        bool disable_compression;