vulkan/format: Use correct swizzle for 1-plane YCbCr formats
authorFaith Ekstrand <faith.ekstrand@collabora.com>
Thu, 10 Aug 2023 18:54:40 +0000 (13:54 -0500)
committerMarge Bot <emma+marge@anholt.net>
Mon, 14 Aug 2023 23:44:19 +0000 (23:44 +0000)
VK_FORMAT_G8B8G8R8_422_UNORM and VK_FORMAT_B8G8R8G8_422_UNORM already
place the luminance channel in the green component which is where we NIR
lowering code for ycbcr expects it.  Set an RGBA swizzle in the common
format table and make it the driver's responsibility to re-map the
formats as needed for their hardware.

The only Vulkan drivers affected by this change are the Intel drivers
and lavapipe.  None of NVK, RADV, and v3dv support these formats yet and
Turnip has its own lowering that doesn't rely on the YCbCr format table
in util/vk_format.c.

Reviewed-by: Dave Airlie <airlied@redhat.com>
Reviewed-by: Roland Scheidegger <sroland@vmware.com>
Acked-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/24619>

src/gallium/auxiliary/gallivm/lp_bld_format_yuv.c
src/intel/vulkan/anv_formats.c
src/intel/vulkan_hasvk/anv_formats.c
src/vulkan/util/vk_format.c

index bd6091b..a00af7b 100644 (file)
@@ -373,7 +373,7 @@ uyvy_to_rgba_aos(struct gallivm_state *gallivm,
 
    if (gallivm->texture_descriptor) {
       /* Vulkan expects us to pack raw data. */
-      rgba = rgb_to_rgba_aos(gallivm, n, u, y, v);
+      rgba = rgb_to_rgba_aos(gallivm, n, v, y, u);
    } else {
       LLVMValueRef r, g, b;
       yuv_to_rgb_soa(gallivm, n, y, u, v, &r, &g, &b);
@@ -420,7 +420,7 @@ yuyv_to_rgba_aos(struct gallivm_state *gallivm,
 
    if (gallivm->texture_descriptor) {
       /* Vulkan expects us to pack raw data. */
-      rgba = rgb_to_rgba_aos(gallivm, n, u, y, v);
+      rgba = rgb_to_rgba_aos(gallivm, n, v, y, u);
    } else {
       LLVMValueRef r, g, b;
       yuv_to_rgb_soa(gallivm, n, y, u, v, &r, &g, &b);
index b4ba8e4..e0f5c68 100644 (file)
@@ -326,9 +326,9 @@ static const struct anv_format _4444_formats[] = {
 
 static const struct anv_format ycbcr_formats[] = {
    ycbcr_fmt(VK_FORMAT_G8B8G8R8_422_UNORM, 1, true, false,
-             ycbcr_plane(0, ISL_FORMAT_YCRCB_SWAPUV, RGBA)),
+             ycbcr_plane(0, ISL_FORMAT_YCRCB_NORMAL, RGBA)),
    ycbcr_fmt(VK_FORMAT_B8G8R8G8_422_UNORM, 1, true, false,
-             ycbcr_plane(0, ISL_FORMAT_YCRCB_SWAPUVY, RGBA)),
+             ycbcr_plane(0, ISL_FORMAT_YCRCB_SWAPY, RGBA)),
    ycbcr_fmt(VK_FORMAT_G8_B8_R8_3PLANE_420_UNORM, 3, true, false,
              ycbcr_plane(0, ISL_FORMAT_R8_UNORM, RGBA),
              ycbcr_plane(1, ISL_FORMAT_R8_UNORM, RGBA),
index bdd0000..caed128 100644 (file)
@@ -342,9 +342,9 @@ static const struct anv_format _4444_formats[] = {
 
 static const struct anv_format ycbcr_formats[] = {
    ycbcr_fmt(VK_FORMAT_G8B8G8R8_422_UNORM, 1,
-             y_plane(0, ISL_FORMAT_YCRCB_SWAPUV, RGBA, _ISL_SWIZZLE(BLUE, GREEN, RED, ZERO), 1, 1)),
+             y_plane(0, ISL_FORMAT_YCRCB_NORMAL, RGBA, _ISL_SWIZZLE(RED, GREEN, BLUE, ZERO), 1, 1)),
    ycbcr_fmt(VK_FORMAT_B8G8R8G8_422_UNORM, 1,
-             y_plane(0, ISL_FORMAT_YCRCB_SWAPUVY, RGBA, _ISL_SWIZZLE(BLUE, GREEN, RED, ZERO), 1, 1)),
+             y_plane(0, ISL_FORMAT_YCRCB_SWAPY, RGBA, _ISL_SWIZZLE(RED, GREEN, BLUE, ZERO), 1, 1)),
    ycbcr_fmt(VK_FORMAT_G8_B8_R8_3PLANE_420_UNORM, 3,
              y_plane(0, ISL_FORMAT_R8_UNORM, RGBA, _ISL_SWIZZLE(GREEN, ZERO, ZERO, ZERO), 1, 1),
              chroma_plane(1, ISL_FORMAT_R8_UNORM, RGBA, _ISL_SWIZZLE(BLUE, ZERO, ZERO, ZERO), 2, 2),
index d016e70..3a043ca 100644 (file)
@@ -475,9 +475,9 @@ vk_component_mapping_to_pipe_swizzle(VkComponentMapping mapping,
 
 static const struct vk_format_ycbcr_info ycbcr_infos[] = {
    ycbcr_fmt(VK_FORMAT_G8B8G8R8_422_UNORM, 1,
-             y_plane(VK_FORMAT_G8B8G8R8_422_UNORM, YCBCR_SWIZ(B, G, R, ZERO), 1, 1)),
+             y_plane(VK_FORMAT_G8B8G8R8_422_UNORM, YCBCR_SWIZ(R, G, B, ZERO), 1, 1)),
    ycbcr_fmt(VK_FORMAT_B8G8R8G8_422_UNORM, 1,
-             y_plane(VK_FORMAT_B8G8R8G8_422_UNORM, YCBCR_SWIZ(B, G, R, ZERO), 1, 1)),
+             y_plane(VK_FORMAT_B8G8R8G8_422_UNORM, YCBCR_SWIZ(R, G, B, ZERO), 1, 1)),
    ycbcr_fmt(VK_FORMAT_G8_B8_R8_3PLANE_420_UNORM, 3,
              y_plane(VK_FORMAT_R8_UNORM, YCBCR_SWIZ(G, ZERO, ZERO, ZERO), 1, 1),
              c_plane(VK_FORMAT_R8_UNORM, YCBCR_SWIZ(B, ZERO, ZERO, ZERO), 2, 2),