Mesa (main): freedreno/fdl: use XYZW swap for PIPE_FORMAT_X24S8_UINT

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Fri Jun 17 19:02:01 UTC 2022


Module: Mesa
Branch: main
Commit: 858cd2797c64aa21dc912bf7f0a31d3d47915abb
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=858cd2797c64aa21dc912bf7f0a31d3d47915abb

Author: Chia-I Wu <olvaffe at gmail.com>
Date:   Fri May 20 16:49:42 2022 -0700

freedreno/fdl: use XYZW swap for PIPE_FORMAT_X24S8_UINT

We used to use WZYX and apply swizzles.  Because swizzles apply for
border colors as well, the gallium driver un-swizzled the border colors
to cancel out swizzles.  That did not work for turnip because turnip
advertises customBorderColorWithoutFormat and does not know when to
un-swizzle.

This change replaces WZYX by XYZW and removes the swizzles.

Closes: https://gitlab.freedesktop.org/mesa/mesa/-/issues/6516
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/16647>

---

 src/freedreno/fdl/fd6_format_table.c          | 16 ++++++++++++++++
 src/freedreno/fdl/fd6_view.c                  |  9 +++++----
 src/freedreno/vulkan/tu_cmd_buffer.c          |  4 ++++
 src/gallium/drivers/freedreno/a6xx/fd6_emit.c |  6 +++---
 4 files changed, 28 insertions(+), 7 deletions(-)

diff --git a/src/freedreno/fdl/fd6_format_table.c b/src/freedreno/fdl/fd6_format_table.c
index 5e2cfa69ce2..60502441820 100644
--- a/src/freedreno/fdl/fd6_format_table.c
+++ b/src/freedreno/fdl/fd6_format_table.c
@@ -374,6 +374,10 @@ fd6_pipe2swap(enum pipe_format format, enum a6xx_tile_mode tile_mode)
    if (!formats[format].present)
       return WZYX;
 
+   /* It seems CCU ignores swap and always uses WZYX when tiled.  TP, on the
+    * other hand, always respects swap.  We should return WZYX such that CCU
+    * and TP agree each other.
+    */
    if (tile_mode)
       return WZYX;
 
@@ -437,6 +441,18 @@ fd6_texture_swap(enum pipe_format format, enum a6xx_tile_mode tile_mode)
       }
    }
 
+   /* format is PIPE_FORMAT_X24S8_UINT when texturing the stencil aspect of
+    * PIPE_FORMAT_Z24_UNORM_S8_UINT.  Because we map the format to
+    * FMT6_8_8_8_8_UINT, return XYZW such that the stencil value is in X
+    * component.
+    *
+    * We used to return WZYX and apply swizzles.  That required us to
+    * un-swizzle the user-specified border color, which could not be done for
+    * turnip.
+    */
+   if (format == PIPE_FORMAT_X24S8_UINT)
+      return XYZW;
+
    return fd6_pipe2swap(format, tile_mode);
 }
 
diff --git a/src/freedreno/fdl/fd6_view.c b/src/freedreno/fdl/fd6_view.c
index 432d8f76477..003939954e0 100644
--- a/src/freedreno/fdl/fd6_view.c
+++ b/src/freedreno/fdl/fd6_view.c
@@ -75,10 +75,9 @@ fdl6_texswiz(const struct fdl_view_args *args, bool has_z24uint_s8uint)
       break;
    case PIPE_FORMAT_X24S8_UINT:
       if (!has_z24uint_s8uint) {
-         /* using FMT6_8_8_8_8_UINT, so need to pick out the W channel and
-          * swizzle (0,0,1) in the rest (see "Conversion to RGBA").
+         /* using FMT6_8_8_8_8_UINT/XYZW so need to swizzle (0,0,1) in the
+          * rest (see "Conversion to RGBA").
           */
-         format_swiz[0] = PIPE_SWIZZLE_W;
          format_swiz[1] = PIPE_SWIZZLE_0;
          format_swiz[2] = PIPE_SWIZZLE_0;
          format_swiz[3] = PIPE_SWIZZLE_1;
@@ -194,8 +193,10 @@ fdl6_view_init(struct fdl6_view *view, const struct fdl_layout **layouts,
                     args->format == PIPE_FORMAT_Z24X8_UNORM ||
                     args->format == PIPE_FORMAT_X24S8_UINT);
 
-   if (args->format == PIPE_FORMAT_X24S8_UINT && has_z24uint_s8uint)
+   if (args->format == PIPE_FORMAT_X24S8_UINT && has_z24uint_s8uint) {
       texture_format = FMT6_Z24_UINT_S8_UINT;
+      swap = WZYX;
+   }
 
    if (texture_format == FMT6_Z24_UNORM_S8_UINT_AS_R8G8B8A8 && !ubwc_enabled)
       texture_format = FMT6_8_8_8_8_UNORM;
diff --git a/src/freedreno/vulkan/tu_cmd_buffer.c b/src/freedreno/vulkan/tu_cmd_buffer.c
index 88022f5635f..642de4cc68b 100644
--- a/src/freedreno/vulkan/tu_cmd_buffer.c
+++ b/src/freedreno/vulkan/tu_cmd_buffer.c
@@ -1140,8 +1140,12 @@ tu_emit_input_attachments(struct tu_cmd_buffer *cmd,
       if (i % 2 == 1 && att->format == VK_FORMAT_D24_UNORM_S8_UINT) {
          /* note this works because spec says fb and input attachments
           * must use identity swizzle
+          *
+          * Also we clear swap to WZYX.  This is because the view might have
+          * picked XYZW to work better with border colors.
           */
          dst[0] &= ~(A6XX_TEX_CONST_0_FMT__MASK |
+            A6XX_TEX_CONST_0_SWAP__MASK |
             A6XX_TEX_CONST_0_SWIZ_X__MASK | A6XX_TEX_CONST_0_SWIZ_Y__MASK |
             A6XX_TEX_CONST_0_SWIZ_Z__MASK | A6XX_TEX_CONST_0_SWIZ_W__MASK);
          if (!cmd->device->physical_device->info->a6xx.has_z24uint_s8uint) {
diff --git a/src/gallium/drivers/freedreno/a6xx/fd6_emit.c b/src/gallium/drivers/freedreno/a6xx/fd6_emit.c
index 8a087015b41..a0f9d255958 100644
--- a/src/gallium/drivers/freedreno/a6xx/fd6_emit.c
+++ b/src/gallium/drivers/freedreno/a6xx/fd6_emit.c
@@ -132,14 +132,14 @@ setup_border_colors(struct fd_texture_stateobj *tex,
           * stencil border color value in bc->ui[0] but according
           * to desc->swizzle and desc->channel, the .x/.w component
           * is NONE and the stencil value is in the y component.
-          * Meanwhile the hardware wants this in the .w component
-          * for x24s8 and the .x component for x32_s8x24.
+          * Meanwhile the hardware wants this in the .x component
+          * for x24s8 and x32_s8x24.
           */
          if ((format == PIPE_FORMAT_X24S8_UINT) ||
              (format == PIPE_FORMAT_X32_S8X24_UINT)) {
             if (j == 0) {
                c = 1;
-               cd = (format == PIPE_FORMAT_X32_S8X24_UINT) ? 0 : 3;
+               cd = 0;
             } else {
                continue;
             }



More information about the mesa-commit mailing list