Mesa (main): zink: fix caching of shader variants with inlined uniforms
GitLab Mirror
gitlab-mirror at kemper.freedesktop.org
Thu Jun 10 09:35:53 UTC 2021
Module: Mesa
Branch: main
Commit: eb12f7f11ea8d9e05193f475620ff9f9e0947c73
URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=eb12f7f11ea8d9e05193f475620ff9f9e0947c73
Author: Mike Blumenkrantz <michael.blumenkrantz at gmail.com>
Date: Tue May 25 14:17:56 2021 -0400
zink: fix caching of shader variants with inlined uniforms
attempting to read the inlined uniforms directly after the variant key
using the size of the variant is not going to work since the variant union
is (sometimes) much larger than the size of the actual struct being used,
meaning that this would just copy a bunch of zeroes instead of the actual
inlined uniforms
Fixes: 7f28775edcc ("zink: implement uniform inlining")
Reviewed-by: Dave Airlie <airlied at redhat.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/11003>
---
src/gallium/drivers/zink/zink_program.c | 20 ++++++++------------
1 file changed, 8 insertions(+), 12 deletions(-)
diff --git a/src/gallium/drivers/zink/zink_program.c b/src/gallium/drivers/zink/zink_program.c
index 0419c7b1d47..8bf3a87586a 100644
--- a/src/gallium/drivers/zink/zink_program.c
+++ b/src/gallium/drivers/zink/zink_program.c
@@ -83,18 +83,16 @@ struct keybox {
};
static struct keybox *
-make_keybox(void *mem_ctx,
- gl_shader_stage stage,
- const void *key,
- uint32_t key_size)
+make_keybox(void *mem_ctx, gl_shader_stage stage, const void *key, uint32_t key_size, void *base, uint32_t base_size)
{
struct keybox *keybox =
- ralloc_size(mem_ctx, sizeof(struct keybox) + key_size);
+ ralloc_size(mem_ctx, sizeof(struct keybox) + key_size + base_size);
keybox->stage = stage;
- keybox->size = key_size;
+ keybox->size = key_size + base_size;
memcpy(keybox->data, key, key_size);
-
+ if (base_size)
+ memcpy(&keybox->data[key_size], base, base_size);
return keybox;
}
@@ -215,7 +213,7 @@ get_shader_module_for_stage(struct zink_context *ctx, struct zink_shader *zs, st
struct zink_shader_module **default_zm = NULL;
struct keybox *keybox;
uint32_t hash;
- bool needs_base_size = false;
+ unsigned base_size = 0;
shader_key_vtbl[stage](ctx, zs, ctx->gfx_stages, &key);
/* this is default variant if there is no default or it matches the default */
@@ -234,7 +232,7 @@ get_shader_module_for_stage(struct zink_context *ctx, struct zink_shader *zs, st
memcpy(key.base.inlined_uniform_values,
ctx->inlinable_uniforms[pstage],
zs->nir->info.num_inlinable_uniforms * 4);
- needs_base_size = true;
+ base_size = zs->nir->info.num_inlinable_uniforms * sizeof(uint32_t);
key.is_default_variant = false;
}
if (key.is_default_variant) {
@@ -242,9 +240,7 @@ get_shader_module_for_stage(struct zink_context *ctx, struct zink_shader *zs, st
if (*default_zm)
return *default_zm;
}
- if (needs_base_size)
- key.size += sizeof(struct zink_shader_key_base);
- keybox = make_keybox(prog->shader_cache, stage, &key, key.size);
+ keybox = make_keybox(prog->shader_cache, stage, &key, key.size, &key.base, base_size);
hash = keybox_hash(keybox);
struct hash_entry *entry = _mesa_hash_table_search_pre_hashed(prog->shader_cache->shader_cache,
hash, keybox);
More information about the mesa-commit
mailing list