[Mesa-dev] [PATCH v2 8/8] radeonsi: reduce the scope of sel->mutex in si_shader_select_with_key
Nicolai Hähnle
nhaehnle at gmail.com
Fri Nov 3 20:09:17 UTC 2017
From: Nicolai Hähnle <nicolai.haehnle at amd.com>
We only need the lock to guard changes in the variant linked list. The
actual compilation can happen outside the lock, since we use the ready
fence as a guard.
v2: fix double-unlock
Reviewed-by: Marek Olšák <marek.olsak at amd.com>
---
src/gallium/drivers/radeonsi/si_state_shaders.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/src/gallium/drivers/radeonsi/si_state_shaders.c b/src/gallium/drivers/radeonsi/si_state_shaders.c
index 4c0292404e6..75b16487480 100644
--- a/src/gallium/drivers/radeonsi/si_state_shaders.c
+++ b/src/gallium/drivers/radeonsi/si_state_shaders.c
@@ -1614,41 +1614,40 @@ current_not_ready:
if (thread_index < 0)
util_queue_fence_wait(&sel->ready);
mtx_lock(&sel->mutex);
/* Find the shader variant. */
for (iter = sel->first_variant; iter; iter = iter->next_variant) {
/* Don't check the "current" shader. We checked it above. */
if (current != iter &&
memcmp(&iter->key, key, sizeof(*key)) == 0) {
+ mtx_unlock(&sel->mutex);
+
if (unlikely(!util_queue_fence_is_signalled(&iter->ready))) {
/* If it's an optimized shader and its compilation has
* been started but isn't done, use the unoptimized
* shader so as not to cause a stall due to compilation.
*/
if (iter->is_optimized) {
memset(&key->opt, 0, sizeof(key->opt));
- mtx_unlock(&sel->mutex);
goto again;
}
util_queue_fence_wait(&iter->ready);
}
if (iter->compilation_failed) {
- mtx_unlock(&sel->mutex);
return -1; /* skip the draw call */
}
state->current = iter;
- mtx_unlock(&sel->mutex);
return 0;
}
}
/* Build a new shader. */
shader = CALLOC_STRUCT(si_shader);
if (!shader) {
mtx_unlock(&sel->mutex);
return -ENOMEM;
}
@@ -1761,29 +1760,30 @@ current_not_ready:
util_queue_fence_reset(&shader->ready);
if (!sel->last_variant) {
sel->first_variant = shader;
sel->last_variant = shader;
} else {
sel->last_variant->next_variant = shader;
sel->last_variant = shader;
}
+ mtx_unlock(&sel->mutex);
+
assert(!shader->is_optimized);
si_build_shader_variant(shader, thread_index, false);
util_queue_fence_signal(&shader->ready);
if (!shader->compilation_failed)
state->current = shader;
- mtx_unlock(&sel->mutex);
return shader->compilation_failed ? -1 : 0;
}
static int si_shader_select(struct pipe_context *ctx,
struct si_shader_ctx_state *state,
struct si_compiler_ctx_state *compiler_state)
{
struct si_context *sctx = (struct si_context *)ctx;
struct si_shader_key key;
--
2.11.0
More information about the mesa-dev
mailing list