From: Marek Olšák Date: Sun, 7 Aug 2022 23:59:48 +0000 (-0400) Subject: cso: fix broken optimization for sampler state lookups X-Git-Tag: upstream/22.3.5~1537 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=94240f561c8665fba780ac7c1a68bf076de64231;p=platform%2Fupstream%2Fmesa.git 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 Fixes: c4e18cd4dd1 - mesa/st: add PIPE_QUIRK_TEXTURE_BORDER_COLOR_SWIZZLE_FREEDRENO Part-of: --- diff --git a/src/gallium/auxiliary/cso_cache/cso_context.c b/src/gallium/auxiliary/cso_cache/cso_context.c index 0d276fb..4c0502a 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);