venus: support AHB external format for sampler YCbCr conversion
authorYiwei Zhang <zzyiwei@chromium.org>
Mon, 24 May 2021 18:25:02 +0000 (18:25 +0000)
committerMarge Bot <eric+marge@anholt.net>
Wed, 26 May 2021 20:26:19 +0000 (20:26 +0000)
Signed-off-by: Yiwei Zhang <zzyiwei@chromium.org>
Reviewed-by: Chia-I Wu <olvaffe@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/10960>

src/virtio/vulkan/vn_android.c
src/virtio/vulkan/vn_android.h
src/virtio/vulkan/vn_image.c

index 8a51681..21baf0c 100644 (file)
@@ -137,7 +137,7 @@ vn_android_ahb_format_from_vk_format(VkFormat format)
    }
 }
 
-static VkFormat
+VkFormat
 vn_android_ahb_format_to_vk_format(uint32_t format)
 {
    switch (format) {
index e01ab48..86a641a 100644 (file)
@@ -81,6 +81,9 @@ vn_android_device_allocate_ahb(struct vn_device *dev,
 void
 vn_android_release_ahb(struct AHardwareBuffer *ahb);
 
+VkFormat
+vn_android_ahb_format_to_vk_format(uint32_t format);
+
 #else
 
 static inline VkResult
@@ -160,6 +163,12 @@ vn_android_release_ahb(UNUSED struct AHardwareBuffer *ahb)
    return;
 }
 
+static inline VkFormat
+vn_android_ahb_format_to_vk_format(UNUSED uint32_t format)
+{
+   return VK_FORMAT_UNDEFINED;
+}
+
 #endif /* ANDROID */
 
 #endif /* VN_ANDROID_H */
index 290264e..611664e 100644 (file)
@@ -729,6 +729,26 @@ vn_CreateSamplerYcbcrConversion(
    struct vn_device *dev = vn_device_from_handle(device);
    const VkAllocationCallbacks *alloc =
       pAllocator ? pAllocator : &dev->base.base.alloc;
+   const VkExternalFormatANDROID *ext_info =
+      vk_find_struct_const(pCreateInfo->pNext, EXTERNAL_FORMAT_ANDROID);
+
+   VkSamplerYcbcrConversionCreateInfo local_info;
+   if (ext_info && ext_info->externalFormat) {
+      assert(pCreateInfo->format == VK_FORMAT_UNDEFINED);
+
+      VkFormat format =
+         vn_android_ahb_format_to_vk_format(ext_info->externalFormat);
+      if (format == VK_FORMAT_UNDEFINED)
+         return vn_error(dev->instance, VK_ERROR_OUT_OF_HOST_MEMORY);
+
+      local_info = *pCreateInfo;
+      local_info.format = format;
+      local_info.components.r = VK_COMPONENT_SWIZZLE_IDENTITY;
+      local_info.components.g = VK_COMPONENT_SWIZZLE_IDENTITY;
+      local_info.components.b = VK_COMPONENT_SWIZZLE_IDENTITY;
+      local_info.components.a = VK_COMPONENT_SWIZZLE_IDENTITY;
+      pCreateInfo = &local_info;
+   }
 
    struct vn_sampler_ycbcr_conversion *conv =
       vk_zalloc(alloc, sizeof(*conv), VN_DEFAULT_ALIGN,