Module: Mesa Branch: main Commit: 94240f561c8665fba780ac7c1a68bf076de64231 URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=94240f561c8665fba780ac7c1a68bf076de64231
Author: Marek Olšák <[email protected]> Date: Sun Aug 7 19:59:48 2022 -0400 cso: fix broken optimization for sampler state lookups Since the key size wasn't a constant expression, all the function inlining didn't do much. This makes it a constant expression. Reviewed-by: Pierre-Eric Pelloux-Prayer <[email protected]> Fixes: c4e18cd4dd1 - mesa/st: add PIPE_QUIRK_TEXTURE_BORDER_COLOR_SWIZZLE_FREEDRENO Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/19129> --- src/gallium/auxiliary/cso_cache/cso_context.c | 29 ++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/src/gallium/auxiliary/cso_cache/cso_context.c b/src/gallium/auxiliary/cso_cache/cso_context.c index 0d276fb033d..4c0502aa8fb 100644 --- a/src/gallium/auxiliary/cso_cache/cso_context.c +++ b/src/gallium/auxiliary/cso_cache/cso_context.c @@ -1323,10 +1323,19 @@ void cso_single_sampler(struct cso_context *ctx, enum pipe_shader_type shader_stage, unsigned idx, const struct pipe_sampler_state *templ) { - size_t size = ctx->sampler_format ? sizeof(struct pipe_sampler_state) : - offsetof(struct pipe_sampler_state, border_color_format); - if (cso_set_sampler(ctx, shader_stage, idx, templ, size)) - ctx->max_sampler_seen = MAX2(ctx->max_sampler_seen, (int)idx); + /* The reasons both blocks are duplicated is that we want the size parameter + * to be a constant expression to inline and unroll memcmp and hash key + * computations. + */ + if (ctx->sampler_format) { + if (cso_set_sampler(ctx, shader_stage, idx, templ, + sizeof(struct pipe_sampler_state))) + ctx->max_sampler_seen = MAX2(ctx->max_sampler_seen, (int)idx); + } else { + if (cso_set_sampler(ctx, shader_stage, idx, templ, + offsetof(struct pipe_sampler_state, border_color_format))) + ctx->max_sampler_seen = MAX2(ctx->max_sampler_seen, (int)idx); + } } @@ -1403,10 +1412,16 @@ cso_set_samplers(struct cso_context *ctx, unsigned nr, const struct pipe_sampler_state **templates) { + int last; + /* ensure sampler size is a constant for memcmp */ - size_t size = ctx->sampler_format ? sizeof(struct pipe_sampler_state) : - offsetof(struct pipe_sampler_state, border_color_format); - int last = set_samplers(ctx, shader_stage, nr, templates, size); + if (ctx->sampler_format) { + last = set_samplers(ctx, shader_stage, nr, templates, + sizeof(struct pipe_sampler_state)); + } else { + last = set_samplers(ctx, shader_stage, nr, templates, + offsetof(struct pipe_sampler_state, border_color_format)); + } ctx->max_sampler_seen = MAX2(ctx->max_sampler_seen, last); cso_single_sampler_done(ctx, shader_stage);
