From: Nicolai Hähnle <nicolai.haeh...@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.ol...@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

_______________________________________________
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev

Reply via email to