Mesa (main): zink: add a more direct check for rgbx formats in create_sampler_view hook

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Wed Jun 16 19:55:00 UTC 2021


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

Author: Mike Blumenkrantz <michael.blumenkrantz at gmail.com>
Date:   Fri Apr  2 13:34:26 2021 -0400

zink: add a more direct check for rgbx formats in create_sampler_view hook

really the point of this is to clamp void channels for any permutation of rgbx
where all channels are the same (e.g., both rgbx8 and rgbx16), so the previous
helper isn't inclusive enough

Reviewed-by: Erik Faye-Lund <erik.faye-lund at collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/11391>

---

 src/gallium/drivers/zink/zink_context.c | 24 +++++++++++++++++++++++-
 1 file changed, 23 insertions(+), 1 deletion(-)

diff --git a/src/gallium/drivers/zink/zink_context.c b/src/gallium/drivers/zink/zink_context.c
index 2b9046ce1a1..2ebf1b2c7f2 100644
--- a/src/gallium/drivers/zink/zink_context.c
+++ b/src/gallium/drivers/zink/zink_context.c
@@ -666,6 +666,28 @@ clamp_zs_swizzle(enum pipe_swizzle swizzle)
    return swizzle;
 }
 
+static inline bool
+format_is_usable_rgba_variant(const struct util_format_description *desc)
+{
+   unsigned chan;
+
+   if(desc->block.width != 1 ||
+      desc->block.height != 1 ||
+      (desc->block.bits != 32 && desc->block.bits != 64))
+      return false;
+
+   if (desc->nr_channels != 4)
+      return false;
+
+   unsigned size = desc->channel[0].size;
+   for(chan = 0; chan < 4; ++chan) {
+      if(desc->channel[chan].size != size)
+         return false;
+   }
+
+   return true;
+}
+
 static struct pipe_sampler_view *
 zink_create_sampler_view(struct pipe_context *pctx, struct pipe_resource *pres,
                          const struct pipe_sampler_view *state)
@@ -706,7 +728,7 @@ zink_create_sampler_view(struct pipe_context *pctx, struct pipe_resource *pres,
           * these formats
           */
           const struct util_format_description *desc = util_format_description(state->format);
-          if (util_format_is_rgba8_variant(desc)) {
+          if (format_is_usable_rgba_variant(desc)) {
              sampler_view->base.swizzle_r = clamp_void_swizzle(desc, sampler_view->base.swizzle_r);
              sampler_view->base.swizzle_g = clamp_void_swizzle(desc, sampler_view->base.swizzle_g);
              sampler_view->base.swizzle_b = clamp_void_swizzle(desc, sampler_view->base.swizzle_b);



More information about the mesa-commit mailing list