From 190e5bda110e5aee3204c8215ad5629f9a0d212e Mon Sep 17 00:00:00 2001 From: Mike Blumenkrantz Date: Fri, 5 Aug 2022 08:52:07 -0400 Subject: [PATCH] zink: simplify shader key comparison by splitting out non-generated tcs non-generated tcs has unique mechanics in that it doesn't have a base shader key, so split that out to avoid unnecessary complexity Reviewed-by: Samuel Pitoiset Part-of: --- src/gallium/drivers/zink/zink_program.c | 36 ++++++++++++++++--------- 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/src/gallium/drivers/zink/zink_program.c b/src/gallium/drivers/zink/zink_program.c index 34440f6e66a..d63316648e3 100644 --- a/src/gallium/drivers/zink/zink_program.c +++ b/src/gallium/drivers/zink/zink_program.c @@ -55,11 +55,21 @@ debug_describe_zink_compute_program(char *buf, const struct zink_compute_program } static bool -shader_key_matches(const struct zink_shader_module *zm, bool ignore_size, +shader_key_matches_tcs_nongenerated(const struct zink_shader_module *zm, const struct zink_shader_key *key, unsigned num_uniforms) +{ + if (zm->num_uniforms != num_uniforms || zm->has_nonseamless != !!key->base.nonseamless_cube_mask) + return false; + const uint32_t nonseamless_size = zm->has_nonseamless ? sizeof(uint32_t) : 0; + return (!nonseamless_size || !memcmp(zm->key + zm->key_size, &key->base.nonseamless_cube_mask, nonseamless_size)) && + (!num_uniforms || !memcmp(zm->key + zm->key_size + nonseamless_size, + key->base.inlined_uniform_values, zm->num_uniforms * sizeof(uint32_t))); +} + +static bool +shader_key_matches(const struct zink_shader_module *zm, const struct zink_shader_key *key, unsigned num_uniforms) { - bool key_size_differs = ignore_size ? false : zm->key_size != key->size; - if (key_size_differs || zm->num_uniforms != num_uniforms || zm->has_nonseamless != !!key->base.nonseamless_cube_mask) + if (zm->key_size != key->size || zm->num_uniforms != num_uniforms || zm->has_nonseamless != !!key->base.nonseamless_cube_mask) return false; const uint32_t nonseamless_size = zm->has_nonseamless ? sizeof(uint32_t) : 0; return !memcmp(zm->key, key, zm->key_size) && @@ -86,11 +96,8 @@ get_shader_module_for_stage(struct zink_context *ctx, struct zink_screen *screen struct zink_shader_module *zm = NULL; unsigned inline_size = 0, nonseamless_size = 0; struct zink_shader_key *key = &state->shader_keys.key[stage]; - bool ignore_key_size = false; - if (stage == MESA_SHADER_TESS_CTRL && !zs->is_generated) { - /* non-generated tcs won't use the shader key */ - ignore_key_size = true; - } + /* non-generated tcs won't use the shader key */ + const bool is_nongenerated_tcs = stage == MESA_SHADER_TESS_CTRL && !zs->is_generated; if (ctx && zs->nir->info.num_inlinable_uniforms && ctx->inlinable_uniforms_valid_mask & BITFIELD64_BIT(stage)) { if (zs->can_inline && (screen->is_cpu || prog->inlined_variant_count[stage] < ZINK_MAX_INLINED_VARIANTS)) @@ -103,8 +110,13 @@ get_shader_module_for_stage(struct zink_context *ctx, struct zink_screen *screen struct zink_shader_module *iter, *next; LIST_FOR_EACH_ENTRY_SAFE(iter, next, &prog->shader_cache[stage][!!nonseamless_size][!!inline_size], list) { - if (!shader_key_matches(iter, ignore_key_size, key, inline_size)) - continue; + if (is_nongenerated_tcs) { + if (!shader_key_matches_tcs_nongenerated(iter, key, inline_size)) + continue; + } else { + if (!shader_key_matches(iter, key, inline_size)) + continue; + } list_delinit(&iter->list); zm = iter; break; @@ -129,7 +141,7 @@ get_shader_module_for_stage(struct zink_context *ctx, struct zink_screen *screen zm->shader = mod; list_inithead(&zm->list); zm->num_uniforms = inline_size; - if (!ignore_key_size) { + if (!is_nongenerated_tcs) { zm->key_size = key->size; memcpy(zm->key, key, key->size); } else { @@ -355,7 +367,7 @@ update_cs_shader_module(struct zink_context *ctx, struct zink_compute_program *c if (inline_size || nonseamless_size) { struct zink_shader_module *iter, *next; LIST_FOR_EACH_ENTRY_SAFE(iter, next, &comp->shader_cache[!!nonseamless_size], list) { - if (!shader_key_matches(iter, false, key, inline_size)) + if (!shader_key_matches(iter, key, inline_size)) continue; list_delinit(&iter->list); zm = iter;