freedreno: Use our border-color quirk
authorRob Clark <robdclark@chromium.org>
Sun, 6 Nov 2022 16:29:40 +0000 (08:29 -0800)
committerMarge Bot <emma+marge@anholt.net>
Wed, 9 Nov 2022 02:51:17 +0000 (02:51 +0000)
This will let us remove our assumption that samplers and views map 1:1,
and generally simplify our border-color handling.

Signed-off-by: Rob Clark <robdclark@chromium.org>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/19561>

src/gallium/drivers/freedreno/a5xx/fd5_emit.c
src/gallium/drivers/freedreno/a6xx/fd6_emit.c
src/gallium/drivers/freedreno/freedreno_screen.c
src/gallium/drivers/freedreno/freedreno_texture.c

index ce8af76a656db0c313d7a15645b95c33010adaa1..7f237f5da019cc119fa19018e83ecbaa9bea9308 100644 (file)
@@ -198,19 +198,7 @@ setup_border_colors(struct fd_texture_stateobj *tex,
 
       bc = &sampler->border_color;
 
-      /*
-       * XXX HACK ALERT XXX
-       *
-       * The border colors need to be swizzled in a particular
-       * format-dependent order. Even though samplers don't know about
-       * formats, we can assume that with a GL state tracker, there's a
-       * 1:1 correspondence between sampler and texture. Take advantage
-       * of that knowledge.
-       */
-      if ((i >= tex->num_textures) || !tex->textures[i])
-         continue;
-
-      enum pipe_format format = tex->textures[i]->format;
+      enum pipe_format format = sampler->border_color_format;
       const struct util_format_description *desc =
          util_format_description(format);
 
index c1268729ab8a8331d46de0359d0282192b83501a..34fdd9e0b8dad259fba9bebd74d2f9db884eb82d 100644 (file)
@@ -97,20 +97,7 @@ setup_border_colors(struct fd_texture_stateobj *tex,
 
       bc = &sampler->border_color;
 
-      /*
-       * XXX HACK ALERT XXX
-       *
-       * The border colors need to be swizzled in a particular
-       * format-dependent order. Even though samplers don't know about
-       * formats, we can assume that with a GL state tracker, there's a
-       * 1:1 correspondence between sampler and texture. Take advantage
-       * of that knowledge.
-       */
-      if ((i >= tex->num_textures) || !tex->textures[i])
-         continue;
-
-      struct pipe_sampler_view *view = tex->textures[i];
-      enum pipe_format format = view->format;
+      enum pipe_format format = sampler->border_color_format;
       const struct util_format_description *desc =
          util_format_description(format);
 
index 8716c921aac8b9c5ff1a4d3eb66a60b7cb66d95d..bcbe465e25af28bd629d7a0ca9daa13037ab7858 100644 (file)
@@ -305,6 +305,9 @@ fd_screen_get_param(struct pipe_screen *pscreen, enum pipe_cap param)
 
       return 0;
 
+   case PIPE_CAP_TEXTURE_BORDER_COLOR_QUIRK:
+      return PIPE_QUIRK_TEXTURE_BORDER_COLOR_SWIZZLE_FREEDRENO;
+
    case PIPE_CAP_TEXTURE_FLOAT_LINEAR:
    case PIPE_CAP_CUBE_MAP_ARRAY:
    case PIPE_CAP_SAMPLER_VIEW_TARGET:
index c1765b39f8a25edeac59007f87355f79356de1c4..a7ece466f7b96bec768199c61a63cb62f23a73ee 100644 (file)
@@ -150,50 +150,41 @@ fd_setup_border_colors(struct fd_texture_stateobj *tex, void *ptr,
       if (!sampler)
          continue;
 
-      /*
-       * XXX HACK ALERT XXX
-       *
-       * The border colors need to be swizzled in a particular
-       * format-dependent order. Even though samplers don't know about
-       * formats, we can assume that with a GL state tracker, there's a
-       * 1:1 correspondence between sampler and texture. Take advantage
-       * of that knowledge.
-       */
-      if (i < tex->num_textures && tex->textures[i]) {
-         const struct util_format_description *desc =
-            util_format_description(tex->textures[i]->format);
-         for (j = 0; j < 4; j++) {
-            if (desc->swizzle[j] >= 4)
-               continue;
-
-            const struct util_format_channel_description *chan =
+      enum pipe_format format = sampler->border_color_format;
+
+      const struct util_format_description *desc =
+            util_format_description(sampler->border_color_format);
+      for (j = 0; j < 4; j++) {
+         if (desc->swizzle[j] >= 4)
+            continue;
+
+         const struct util_format_channel_description *chan =
                &desc->channel[desc->swizzle[j]];
-            uint8_t native = desc->swizzle[j];
-            /* Special cases:
-             *  - X24S8 is implemented with 8_8_8_8_UINT, so the 'native'
-             *    location is actually 0 rather than 1
-             *  - X32_S8X24_UINT has stencil with a secretly-S8_UINT resource
-             *    so again we want 0 rather than 1
-             *
-             * In both cases, there is only one non-void format, so we don't
-             * have to be too careful.
-             *
-             * Note that this only affects a4xx -- a3xx did not support
-             * stencil texturing, and a5xx+ don't use this helper.
-             */
-            if (tex->textures[i]->format == PIPE_FORMAT_X24S8_UINT ||
-                tex->textures[i]->format == PIPE_FORMAT_X32_S8X24_UINT) {
-               native = 0;
-            }
-
-            if (chan->pure_integer) {
-               bcolor32[native + 4] = sampler->border_color.i[j];
-               bcolor[native + 8] = sampler->border_color.i[j];
-            } else {
-               bcolor32[native] = fui(sampler->border_color.f[j]);
-               bcolor[native] =
+         uint8_t native = desc->swizzle[j];
+         /* Special cases:
+          *  - X24S8 is implemented with 8_8_8_8_UINT, so the 'native'
+          *    location is actually 0 rather than 1
+          *  - X32_S8X24_UINT has stencil with a secretly-S8_UINT resource
+          *    so again we want 0 rather than 1
+          *
+          * In both cases, there is only one non-void format, so we don't
+          * have to be too careful.
+          *
+          * Note that this only affects a4xx -- a3xx did not support
+          * stencil texturing, and a5xx+ don't use this helper.
+          */
+         if (format == PIPE_FORMAT_X24S8_UINT ||
+               format == PIPE_FORMAT_X32_S8X24_UINT) {
+            native = 0;
+         }
+
+         if (chan->pure_integer) {
+            bcolor32[native + 4] = sampler->border_color.i[j];
+            bcolor[native + 8] = sampler->border_color.i[j];
+         } else {
+            bcolor32[native] = fui(sampler->border_color.f[j]);
+            bcolor[native] =
                   _mesa_float_to_half(sampler->border_color.f[j]);
-            }
          }
       }
    }