diff options
author | Eric Anholt <[email protected]> | 2019-07-25 13:21:56 -0700 |
---|---|---|
committer | Eric Anholt <[email protected]> | 2019-07-29 12:50:49 -0700 |
commit | 6f0521b78cfec6d461e17d293b9c90fc391cc795 (patch) | |
tree | a60ded70fef7b888a70392eec25dd9d9cf476a62 | |
parent | 6e3b220ad3c6b790ccba63e0ed742f3314c158ef (diff) |
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 <[email protected]>
-rw-r--r-- | src/freedreno/ir3/ir3_shader.c | 5 | ||||
-rw-r--r-- | src/freedreno/ir3/ir3_shader.h | 2 |
2 files changed, 7 insertions, 0 deletions
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 <stdio.h> +#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); |