From 6f0521b78cfec6d461e17d293b9c90fc391cc795 Mon Sep 17 00:00:00 2001 From: Eric Anholt Date: Thu, 25 Jul 2019 13:21:56 -0700 Subject: [PATCH] freedreno: Take a lock around shader variant creation. Shaders are shared across contexts in gallium (part of making it so that you get shader compile at link time, for shader-db and to reduce compiles at draw time). So, we need to protect from variant creation for a shader from multiple threads at the same time. Reviewed-by: Rob Clark --- src/freedreno/ir3/ir3_shader.c | 5 +++++ src/freedreno/ir3/ir3_shader.h | 2 ++ 2 files changed, 7 insertions(+) diff --git a/src/freedreno/ir3/ir3_shader.c b/src/freedreno/ir3/ir3_shader.c index f366332c303..bbe27ce4dbb 100644 --- a/src/freedreno/ir3/ir3_shader.c +++ b/src/freedreno/ir3/ir3_shader.c @@ -239,6 +239,7 @@ struct ir3_shader_variant * ir3_shader_get_variant(struct ir3_shader *shader, struct ir3_shader_key *key, bool binning_pass, bool *created) { + mtx_lock(&shader->variants_lock); struct ir3_shader_variant *v = shader_variant(shader, key, created); @@ -247,8 +248,10 @@ ir3_shader_get_variant(struct ir3_shader *shader, struct ir3_shader_key *key, v->binning = create_variant(shader, key, true); *created = true; } + mtx_unlock(&shader->variants_lock); return v->binning; } + mtx_unlock(&shader->variants_lock); return v; } @@ -264,6 +267,7 @@ ir3_shader_destroy(struct ir3_shader *shader) } free(shader->const_state.immediates); ralloc_free(shader->nir); + mtx_destroy(&shader->variants_lock); free(shader); } @@ -272,6 +276,7 @@ ir3_shader_from_nir(struct ir3_compiler *compiler, nir_shader *nir) { struct ir3_shader *shader = CALLOC_STRUCT(ir3_shader); + mtx_init(&shader->variants_lock, mtx_plain); shader->compiler = compiler; shader->id = ++shader->compiler->shader_count; shader->type = nir->info.stage; diff --git a/src/freedreno/ir3/ir3_shader.h b/src/freedreno/ir3/ir3_shader.h index b3291896f4d..77e40a71b5c 100644 --- a/src/freedreno/ir3/ir3_shader.h +++ b/src/freedreno/ir3/ir3_shader.h @@ -29,6 +29,7 @@ #include +#include "c11/threads.h" #include "compiler/shader_enums.h" #include "compiler/nir/nir.h" #include "util/bitscan.h" @@ -544,6 +545,7 @@ struct ir3_shader { struct ir3_stream_output_info stream_output; struct ir3_shader_variant *variants; + mtx_t variants_lock; }; void * ir3_shader_assemble(struct ir3_shader_variant *v, uint32_t gpu_id); -- 2.30.2