Mesa (main): freedreno/a6xx: Use fdl format swizzle

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Wed Jun 29 03:37:28 UTC 2022


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

Author: Connor Abbott <cwabbott0 at gmail.com>
Date:   Fri Jun 17 16:29:00 2022 +0200

freedreno/a6xx: Use fdl format swizzle

This makes sure that we use a consistent swizzle between computing the
border color and the texture descriptor, and lets us delete the gallium
version.

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/17177>

---

 src/freedreno/fdl/fd6_view.c                    | 31 +++++++++++++++++--------
 src/freedreno/fdl/freedreno_layout.h            |  4 ++++
 src/gallium/drivers/freedreno/a6xx/fd6_emit.c   |  3 +--
 src/gallium/drivers/freedreno/a6xx/fd6_format.c | 30 ------------------------
 src/gallium/drivers/freedreno/a6xx/fd6_format.h |  4 ----
 src/gallium/drivers/freedreno/a6xx/fd6_gmem.c   |  2 +-
 6 files changed, 27 insertions(+), 47 deletions(-)

diff --git a/src/freedreno/fdl/fd6_view.c b/src/freedreno/fdl/fd6_view.c
index 95ae463b06d..5e7e91407aa 100644
--- a/src/freedreno/fdl/fd6_view.c
+++ b/src/freedreno/fdl/fd6_view.c
@@ -54,12 +54,16 @@ fdl6_tex_type(enum fdl_view_type type, bool storage)
       A6XX_TEX_2D : (enum a6xx_tex_type) type;
 }
 
-static uint32_t
-fdl6_texswiz(const struct fdl_view_args *args, bool has_z24uint_s8uint)
+void
+fdl6_format_swiz(enum pipe_format format, bool has_z24uint_s8uint,
+                 unsigned char *format_swiz)
 {
-   unsigned char format_swiz[4] =
-      { PIPE_SWIZZLE_X, PIPE_SWIZZLE_Y, PIPE_SWIZZLE_Z, PIPE_SWIZZLE_W };
-   switch (args->format) {
+   format_swiz[0] = PIPE_SWIZZLE_X;
+   format_swiz[1] = PIPE_SWIZZLE_Y;
+   format_swiz[2] = PIPE_SWIZZLE_Z;
+   format_swiz[3] = PIPE_SWIZZLE_W;
+
+   switch (format) {
    case PIPE_FORMAT_R8G8_R8B8_UNORM:
    case PIPE_FORMAT_G8R8_B8R8_UNORM:
    case PIPE_FORMAT_G8_B8R8_420_UNORM:
@@ -92,32 +96,39 @@ fdl6_texswiz(const struct fdl_view_args *args, bool has_z24uint_s8uint)
 
    default:
       /* Our I, L, A, and LA formats use R or RG HW formats. */
-      if (util_format_is_alpha(args->format)) {
+      if (util_format_is_alpha(format)) {
          format_swiz[0] = PIPE_SWIZZLE_0;
          format_swiz[1] = PIPE_SWIZZLE_0;
          format_swiz[2] = PIPE_SWIZZLE_0;
          format_swiz[3] = PIPE_SWIZZLE_X;
-      } else if (util_format_is_luminance(args->format)) {
+      } else if (util_format_is_luminance(format)) {
          format_swiz[0] = PIPE_SWIZZLE_X;
          format_swiz[1] = PIPE_SWIZZLE_X;
          format_swiz[2] = PIPE_SWIZZLE_X;
          format_swiz[3] = PIPE_SWIZZLE_1;
-      } else if (util_format_is_intensity(args->format)) {
+      } else if (util_format_is_intensity(format)) {
          format_swiz[0] = PIPE_SWIZZLE_X;
          format_swiz[1] = PIPE_SWIZZLE_X;
          format_swiz[2] = PIPE_SWIZZLE_X;
          format_swiz[3] = PIPE_SWIZZLE_X;
-      } else if (util_format_is_luminance_alpha(args->format)) {
+      } else if (util_format_is_luminance_alpha(format)) {
          format_swiz[0] = PIPE_SWIZZLE_X;
          format_swiz[1] = PIPE_SWIZZLE_X;
          format_swiz[2] = PIPE_SWIZZLE_X;
          format_swiz[3] = PIPE_SWIZZLE_Y;
-      } else if (!util_format_has_alpha(args->format)) {
+      } else if (!util_format_has_alpha(format)) {
          /* for rgbx, force A to 1.  Harmless for R/RG, where we already get 1. */
          format_swiz[3] = PIPE_SWIZZLE_1;
       }
       break;
    }
+}
+
+static uint32_t
+fdl6_texswiz(const struct fdl_view_args *args, bool has_z24uint_s8uint)
+{
+   unsigned char format_swiz[4];
+   fdl6_format_swiz(args->format, has_z24uint_s8uint, format_swiz);
 
    unsigned char swiz[4];
    util_format_compose_swizzles(format_swiz, args->swiz, swiz);
diff --git a/src/freedreno/fdl/freedreno_layout.h b/src/freedreno/fdl/freedreno_layout.h
index b743b0eb690..b6be49d207c 100644
--- a/src/freedreno/fdl/freedreno_layout.h
+++ b/src/freedreno/fdl/freedreno_layout.h
@@ -324,4 +324,8 @@ void
 fdl6_buffer_view_init(uint32_t *descriptor, enum pipe_format format,
                       const uint8_t *swiz, uint64_t iova, uint32_t size);
 
+void
+fdl6_format_swiz(enum pipe_format format, bool has_z24uint_s8uint,
+                 unsigned char *format_swiz);
+
 #endif /* FREEDRENO_LAYOUT_H_ */
diff --git a/src/gallium/drivers/freedreno/a6xx/fd6_emit.c b/src/gallium/drivers/freedreno/a6xx/fd6_emit.c
index e578b2f7cb5..78c0db5f3ad 100644
--- a/src/gallium/drivers/freedreno/a6xx/fd6_emit.c
+++ b/src/gallium/drivers/freedreno/a6xx/fd6_emit.c
@@ -120,8 +120,7 @@ setup_border_colors(struct fd_texture_stateobj *tex,
 
       unsigned char swiz[4];
 
-      fd6_tex_swiz(format, swiz, PIPE_SWIZZLE_X, PIPE_SWIZZLE_Y,
-                   PIPE_SWIZZLE_Z, PIPE_SWIZZLE_W);
+      fdl6_format_swiz(format, false, swiz);
 
       for (j = 0; j < 4; j++) {
          int c = swiz[j];
diff --git a/src/gallium/drivers/freedreno/a6xx/fd6_format.c b/src/gallium/drivers/freedreno/a6xx/fd6_format.c
index 2b4acc6010a..021d5f5281c 100644
--- a/src/gallium/drivers/freedreno/a6xx/fd6_format.c
+++ b/src/gallium/drivers/freedreno/a6xx/fd6_format.c
@@ -51,33 +51,3 @@ fd6_pipe2swiz(unsigned swiz)
    }
 }
 
-void
-fd6_tex_swiz(enum pipe_format format, unsigned char *swiz, unsigned swizzle_r,
-             unsigned swizzle_g, unsigned swizzle_b, unsigned swizzle_a)
-{
-   const struct util_format_description *desc = util_format_description(format);
-   const unsigned char uswiz[4] = {swizzle_r, swizzle_g, swizzle_b, swizzle_a};
-
-   /* Gallium expects stencil sampler to return (s,s,s,s), so massage
-    * the swizzle to do so.
-    */
-   if (format == PIPE_FORMAT_X24S8_UINT) {
-      const unsigned char stencil_swiz[4] = {PIPE_SWIZZLE_W, PIPE_SWIZZLE_W,
-                                             PIPE_SWIZZLE_W, PIPE_SWIZZLE_W};
-      util_format_compose_swizzles(stencil_swiz, uswiz, swiz);
-   } else if (format == PIPE_FORMAT_R8G8_R8B8_UNORM || format == PIPE_FORMAT_G8R8_B8R8_UNORM) {
-      unsigned char fswiz[4] = {PIPE_SWIZZLE_Z, PIPE_SWIZZLE_X, PIPE_SWIZZLE_Y, PIPE_SWIZZLE_1};
-      util_format_compose_swizzles(fswiz, uswiz, swiz);
-   } else if (fd6_texture_swap(format, TILE6_LINEAR) != WZYX || format == PIPE_FORMAT_A1R5G5B5_UNORM) {
-      /* Formats with a non-pass-through swap are permutations of RGBA
-       * formats. We program the permutation using the swap and don't
-       * need to compose the format swizzle with the user swizzle.
-       */
-      memcpy(swiz, uswiz, sizeof(uswiz));
-   } else {
-      /* Otherwise, it's an unswapped RGBA format or a format like L8 where
-       * we need the XXX1 swizzle from the gallium format description.
-       */
-      util_format_compose_swizzles(desc->swizzle, uswiz, swiz);
-   }
-}
diff --git a/src/gallium/drivers/freedreno/a6xx/fd6_format.h b/src/gallium/drivers/freedreno/a6xx/fd6_format.h
index d525dfcaa1c..cde24f1845d 100644
--- a/src/gallium/drivers/freedreno/a6xx/fd6_format.h
+++ b/src/gallium/drivers/freedreno/a6xx/fd6_format.h
@@ -36,8 +36,4 @@
 
 enum a6xx_tex_swiz fd6_pipe2swiz(unsigned swiz);
 
-void fd6_tex_swiz(enum pipe_format format, unsigned char *swiz,
-                  unsigned swizzle_r, unsigned swizzle_g, unsigned swizzle_b,
-                  unsigned swizzle_a);
-
 #endif /* FD6_UTIL_H_ */
diff --git a/src/gallium/drivers/freedreno/a6xx/fd6_gmem.c b/src/gallium/drivers/freedreno/a6xx/fd6_gmem.c
index 40c5c85efda..da5152ae38d 100644
--- a/src/gallium/drivers/freedreno/a6xx/fd6_gmem.c
+++ b/src/gallium/drivers/freedreno/a6xx/fd6_gmem.c
@@ -270,7 +270,7 @@ patch_fb_read_gmem(struct fd_batch *batch)
    enum pipe_format format = psurf->format;
 
    uint8_t swiz[4];
-   fd6_tex_swiz(psurf->format, swiz, PIPE_SWIZZLE_X, PIPE_SWIZZLE_Y, PIPE_SWIZZLE_Z, PIPE_SWIZZLE_W);
+   fdl6_format_swiz(psurf->format, false, swiz);
 
    /* always TILE6_2 mode in GMEM, which also means no swap: */
    uint32_t texconst0 = A6XX_TEX_CONST_0_FMT(fd6_texture_format(format, rsc->layout.tile_mode)) |



More information about the mesa-commit mailing list