From f5b9d16823a72a4e6bd1cd594f2e8b7729f750bf Mon Sep 17 00:00:00 2001 From: Mike Blumenkrantz Date: Wed, 9 Jun 2021 17:54:06 -0400 Subject: [PATCH] zink: add locking for zink_shader::programs shaders are screen objects now with liveshader caching, so modifications after creation need to be locked Reviewed-by: Hoe Hao Cheng Part-of: --- src/gallium/drivers/zink/zink_compiler.c | 2 ++ src/gallium/drivers/zink/zink_compiler.h | 2 ++ src/gallium/drivers/zink/zink_program.c | 2 ++ 3 files changed, 6 insertions(+) diff --git a/src/gallium/drivers/zink/zink_compiler.c b/src/gallium/drivers/zink/zink_compiler.c index 0f6603a..4cd2d28 100644 --- a/src/gallium/drivers/zink/zink_compiler.c +++ b/src/gallium/drivers/zink/zink_compiler.c @@ -938,6 +938,7 @@ zink_shader_create(struct zink_screen *screen, struct nir_shader *nir, bool have_psiz = false; ret->programs = _mesa_pointer_set_create(NULL); + simple_mtx_init(&ret->lock, mtx_plain); nir_variable_mode indirect_derefs_modes = nir_var_function_temp; if (nir->info.stage == MESA_SHADER_TESS_CTRL || @@ -1140,6 +1141,7 @@ zink_shader_tcs_create(struct zink_context *ctx, struct zink_shader *vs) unsigned vertices_per_patch = ctx->gfx_pipeline_state.vertices_per_patch; struct zink_shader *ret = CALLOC_STRUCT(zink_shader); ret->programs = _mesa_pointer_set_create(NULL); + simple_mtx_init(&ret->lock, mtx_plain); nir_shader *nir = nir_shader_create(NULL, MESA_SHADER_TESS_CTRL, &zink_screen(ctx->base.screen)->nir_options, NULL); nir_function *fn = nir_function_create(nir, "main"); diff --git a/src/gallium/drivers/zink/zink_compiler.h b/src/gallium/drivers/zink/zink_compiler.h index 94f4ffe..855fc1e 100644 --- a/src/gallium/drivers/zink/zink_compiler.h +++ b/src/gallium/drivers/zink/zink_compiler.h @@ -82,6 +82,8 @@ struct zink_shader { unsigned num_texel_buffers; uint32_t ubos_used; // bitfield of which ubo indices are used uint32_t ssbos_used; // bitfield of which ssbo indices are used + + simple_mtx_t lock; struct set *programs; union { diff --git a/src/gallium/drivers/zink/zink_program.c b/src/gallium/drivers/zink/zink_program.c index de3f1ea..13b118c 100644 --- a/src/gallium/drivers/zink/zink_program.c +++ b/src/gallium/drivers/zink/zink_program.c @@ -460,7 +460,9 @@ zink_create_gfx_program(struct zink_context *ctx, _mesa_sha1_init(&sctx); for (int i = 0; i < ZINK_SHADER_COUNT; ++i) { if (prog->modules[i]) { + simple_mtx_lock(&prog->shaders[i]->lock); _mesa_set_add(prog->shaders[i]->programs, prog); + simple_mtx_unlock(&prog->shaders[i]->lock); zink_gfx_program_reference(screen, NULL, prog); _mesa_sha1_update(&sctx, prog->shaders[i]->base.sha1, sizeof(prog->shaders[i]->base.sha1)); } -- 2.7.4