freedreno/fdl: use XYZW swap for PIPE_FORMAT_X24S8_UINT
authorChia-I Wu <olvaffe@gmail.com>
Fri, 20 May 2022 23:49:42 +0000 (16:49 -0700)
committerMarge Bot <emma+marge@anholt.net>
Fri, 17 Jun 2022 18:39:47 +0000 (18:39 +0000)
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
src/freedreno/fdl/fd6_view.c
src/freedreno/vulkan/tu_cmd_buffer.c
src/gallium/drivers/freedreno/a6xx/fd6_emit.c

index 5e2cfa6..6050244 100644 (file)
@@ -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);
 }
 
index 432d8f7..0039399 100644 (file)
@@ -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;
index 88022f5..642de4c 100644 (file)
@@ -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) {
index 8a08701..a0f9d25 100644 (file)
@@ -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;
             }