From 08bad3b2b87e6aef3d7ef80f835a137cd0f64e81 Mon Sep 17 00:00:00 2001 From: Mike Blumenkrantz Date: Tue, 6 Apr 2021 10:18:41 -0400 Subject: [PATCH] zink: move void format detection function to zink_format Reviewed-by: Dave Airlie Part-of: --- src/gallium/drivers/zink/zink_context.c | 27 +++---------------------- src/gallium/drivers/zink/zink_format.c | 25 +++++++++++++++++++++++ src/gallium/drivers/zink/zink_format.h | 3 +++ 3 files changed, 31 insertions(+), 24 deletions(-) diff --git a/src/gallium/drivers/zink/zink_context.c b/src/gallium/drivers/zink/zink_context.c index 1ff2edbaa42..bed0def0075 100644 --- a/src/gallium/drivers/zink/zink_context.c +++ b/src/gallium/drivers/zink/zink_context.c @@ -26,6 +26,7 @@ #include "zink_batch.h" #include "zink_compiler.h" #include "zink_fence.h" +#include "zink_format.h" #include "zink_framebuffer.h" #include "zink_helpers.h" #include "zink_program.h" @@ -692,28 +693,6 @@ 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) @@ -753,8 +732,8 @@ zink_create_sampler_view(struct pipe_context *pctx, struct pipe_resource *pres, /* if we have e.g., R8G8B8X8, then we have to ignore alpha since we're just emulating * these formats */ - const struct util_format_description *desc = util_format_description(state->format); - if (format_is_usable_rgba_variant(desc)) { + if (zink_format_is_voidable_rgba_variant(state->format)) { + const struct util_format_description *desc = util_format_description(state->format); 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); diff --git a/src/gallium/drivers/zink/zink_format.c b/src/gallium/drivers/zink/zink_format.c index 3e1bea65725..87c1ea548b5 100644 --- a/src/gallium/drivers/zink/zink_format.c +++ b/src/gallium/drivers/zink/zink_format.c @@ -1,3 +1,4 @@ +#include "util/format/u_format.h" #include "zink_format.h" static const VkFormat formats[PIPE_FORMAT_COUNT] = { @@ -152,3 +153,27 @@ zink_pipe_format_to_vk_format(enum pipe_format format) { return formats[format]; } + + +bool +zink_format_is_voidable_rgba_variant(enum pipe_format format) +{ + const struct util_format_description *desc = util_format_description(format); + 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; +} diff --git a/src/gallium/drivers/zink/zink_format.h b/src/gallium/drivers/zink/zink_format.h index 966ee9bd9a8..5f81a78b10e 100644 --- a/src/gallium/drivers/zink/zink_format.h +++ b/src/gallium/drivers/zink/zink_format.h @@ -26,9 +26,12 @@ #include "pipe/p_format.h" +#include #include VkFormat zink_pipe_format_to_vk_format(enum pipe_format format); +bool +zink_format_is_voidable_rgba_variant(enum pipe_format format); #endif