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 <samuel.pitoiset@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/18135>
This commit is contained in:
Mike Blumenkrantz 2022-08-05 08:52:07 -04:00 committed by Marge Bot
parent 59fa328589
commit 190e5bda11

View file

@ -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;