From 2f2976e9e1c2f4a2258d4710cdb27d011e246c5b Mon Sep 17 00:00:00 2001 From: Mike Blumenkrantz Date: Fri, 2 Apr 2021 13:34:26 -0400 Subject: [PATCH] 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 Part-of: --- 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);