From c2e611e1a458ddb7c72bb82847c64ba665002402 Mon Sep 17 00:00:00 2001 From: Mike Blumenkrantz Date: Tue, 25 May 2021 14:17:56 -0400 Subject: [PATCH] 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 Part-of: (cherry picked from commit eb12f7f11ea8d9e05193f475620ff9f9e0947c73) --- .pick_status.json | 2 +- src/gallium/drivers/zink/zink_program.c | 20 ++++++++------------ 2 files changed, 9 insertions(+), 13 deletions(-) diff --git a/.pick_status.json b/.pick_status.json index f996124fc2f..f770efda57f 100644 --- a/.pick_status.json +++ b/.pick_status.json @@ -40,7 +40,7 @@ "description": "zink: fix caching of shader variants with inlined uniforms", "nominated": true, "nomination_type": 1, - "resolution": 0, + "resolution": 1, "main_sha": null, "because_sha": "7f28775edcc727791528d8439c86e8dffd5059a9" }, diff --git a/src/gallium/drivers/zink/zink_program.c b/src/gallium/drivers/zink/zink_program.c index 32a81e8068d..023f9eac576 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; } @@ -282,7 +280,7 @@ get_shader_module_for_stage(struct zink_context *ctx, struct zink_shader *zs, st struct zink_shader_module *zm; 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); @@ -292,11 +290,9 @@ 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); } - 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);