radv: Derive android usage from create flags.
authorBas Nieuwenhuizen <basni@chromium.org>
Mon, 8 Jul 2019 13:33:06 +0000 (15:33 +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 df4812257e600f6b926029173462eaaad211db76..f3cbe2d4bd2fc73d2302a0741d389d6507e802fe 100644 (file)
@@ -410,6 +410,32 @@ vk_format_from_android(unsigned android_format, unsigned android_usage)
        }
 }
 
+uint64_t
+radv_ahb_usage_from_vk_usage(const VkImageCreateFlags vk_create,
+                             const VkImageUsageFlags vk_usage)
+{
+   uint64_t ahb_usage = 0;
+   if (vk_usage & VK_IMAGE_USAGE_SAMPLED_BIT)
+      ahb_usage |= AHARDWAREBUFFER_USAGE_GPU_SAMPLED_IMAGE;
+
+   if (vk_usage & VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT)
+      ahb_usage |= AHARDWAREBUFFER_USAGE_GPU_SAMPLED_IMAGE;
+
+   if (vk_usage & VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT)
+      ahb_usage |= AHARDWAREBUFFER_USAGE_GPU_COLOR_OUTPUT;
+
+   if (vk_create & VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT)
+      ahb_usage |= AHARDWAREBUFFER_USAGE_GPU_CUBE_MAP;
+
+   if (vk_create & VK_IMAGE_CREATE_PROTECTED_BIT)
+      ahb_usage |= AHARDWAREBUFFER_USAGE_PROTECTED_CONTENT;
+
+   /* No usage bits set - set at least one GPU usage. */
+   if (ahb_usage == 0)
+      ahb_usage = AHARDWAREBUFFER_USAGE_GPU_SAMPLED_IMAGE;
+   return ahb_usage;
+}
+
 static VkResult
 get_ahb_buffer_format_properties(
    VkDevice device_h,
index e68f7c9040f19e1a61015d406c638b2ca7cb307b..c6e01d66fa6702f8e41c5cbdb927d72d344a038f 100644 (file)
@@ -1345,6 +1345,7 @@ VkResult radv_GetPhysicalDeviceImageFormatProperties2(
        RADV_FROM_HANDLE(radv_physical_device, physical_device, physicalDevice);
        const VkPhysicalDeviceExternalImageFormatInfo *external_info = NULL;
        VkExternalImageFormatProperties *external_props = NULL;
+       struct VkAndroidHardwareBufferUsageANDROID *android_usage = NULL;
        VkSamplerYcbcrConversionImageFormatProperties *ycbcr_props = NULL;
        VkResult result;
 
@@ -1373,11 +1374,23 @@ VkResult radv_GetPhysicalDeviceImageFormatProperties2(
                case VK_STRUCTURE_TYPE_SAMPLER_YCBCR_CONVERSION_IMAGE_FORMAT_PROPERTIES:
                        ycbcr_props = (void *) s;
                        break;
+               case VK_STRUCTURE_TYPE_ANDROID_HARDWARE_BUFFER_USAGE_ANDROID:
+                       android_usage = (void *) s;
+                       break;
                default:
                        break;
                }
        }
 
+       bool ahb_supported = physical_device->supported_extensions.ANDROID_external_memory_android_hardware_buffer;
+       if (android_usage && ahb_supported) {
+#if RADV_SUPPORT_ANDROID_HARDWARE_BUFFER
+               android_usage->androidHardwareBufferUsage =
+                       radv_ahb_usage_from_vk_usage(base_info->flags,
+                                                    base_info->usage);
+#endif
+       }
+
        /* From the Vulkan 1.0.97 spec:
         *
         *    If handleType is 0, vkGetPhysicalDeviceImageFormatProperties2 will
index 8674d1bd931bf5ea77f9c3826e5fbccb1df7b7ae..6ad055aacdc02db12bdf86b35a7241bf8b18dc3e 100644 (file)
@@ -1924,6 +1924,10 @@ radv_image_from_gralloc(VkDevice device_h,
                        const VkNativeBufferANDROID *gralloc_info,
                        const VkAllocationCallbacks *alloc,
                        VkImage *out_image_h);
+uint64_t
+radv_ahb_usage_from_vk_usage(const VkImageCreateFlags vk_create,
+                             const VkImageUsageFlags vk_usage);
+
 
 struct radv_image_view_extra_create_info {
        bool disable_compression;