venus: swizzle the chroma channels for YVU420 to match the VkFormat
authorYiwei Zhang <zzyiwei@chromium.org>
Thu, 30 Jun 2022 22:06:05 +0000 (22:06 +0000)
committerMarge Bot <emma+marge@anholt.net>
Fri, 1 Jul 2022 18:46:31 +0000 (18:46 +0000)
Test:
- testVP8EncodeDecodeVideoFromBufferToSurface
- android.media.cts.DecodeAccuracyTest

Signed-off-by: Yiwei Zhang <zzyiwei@chromium.org>
Reviewed-by: Ryan Neph <ryanneph@google.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/17323>

src/virtio/vulkan/vn_android.c

index 6720640..ca94d99 100644 (file)
@@ -104,6 +104,8 @@ struct cros_gralloc0_buffer_info {
 struct vn_android_gralloc_buffer_properties {
    uint32_t drm_fourcc;
    uint64_t modifier;
+
+   /* plane order matches VkImageDrmFormatModifierExplicitCreateInfoEXT */
    uint32_t offset[4];
    uint32_t stride[4];
 };
@@ -131,6 +133,18 @@ vn_android_gralloc_get_buffer_properties(
       out_props->stride[i] = info.stride[i];
       out_props->offset[i] = info.offset[i];
    }
+
+   /* YVU420 has a chroma order of CrCb. So we must swap the planes for CrCb
+    * to align with VK_FORMAT_G8_B8_R8_3PLANE_420_UNORM. This is to serve
+    * VkImageDrmFormatModifierExplicitCreateInfoEXT explicit plane layouts.
+    */
+   if (info.drm_fourcc == DRM_FORMAT_YVU420) {
+      out_props->stride[1] = info.stride[2];
+      out_props->offset[1] = info.offset[2];
+      out_props->stride[2] = info.stride[1];
+      out_props->offset[2] = info.offset[1];
+   }
+
    out_props->modifier = info.modifier;
 
    return true;