Mesa (master): mesa/st: use a lock to protect access to variants when updating them

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Fri Nov 6 08:25:05 UTC 2020


Module: Mesa
Branch: master
Commit: d4285805345836cbe1a1a0f282aa3a25d5c0aa60
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=d4285805345836cbe1a1a0f282aa3a25d5c0aa60

Author: Tapani Pälli <tapani.palli at intel.com>
Date:   Mon Nov  2 14:56:40 2020 +0200

mesa/st: use a lock to protect access to variants when updating them

Multiple threads may access st_update_* function at same time. Issues
happen when the threads modify lists managed by shader compiler.

Issues were found with script that runs multithread tests 1000 times in
a row with MESA_GLSL_CACHE_DISABLE=1 set. Problems start when 2
simultaneous st_create_[vp|fp]_variant calls start to compile a new
shader variant for the same program and various nir passes use and
modify same exec_lists.

Example failure:
   deqp-egl: ../src/compiler/glsl/list.h:575: exec_list_validate: Assertion `node->next->prev == node' failed.

v2: instead of introducing new mutex, lock shared state

Signed-off-by: Tapani Pälli <tapani.palli at intel.com>
Reviewed-by: Marek Olšák <marek.olsak at amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/7418>

---

 src/mesa/state_tracker/st_atom_shader.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/src/mesa/state_tracker/st_atom_shader.c b/src/mesa/state_tracker/st_atom_shader.c
index 18acc3017a8..ec55e336ebb 100644
--- a/src/mesa/state_tracker/st_atom_shader.c
+++ b/src/mesa/state_tracker/st_atom_shader.c
@@ -160,7 +160,9 @@ st_update_fp( struct st_context *st )
 
       key.external = st_get_external_sampler_key(st, &stfp->Base);
 
+      simple_mtx_lock(&st->ctx->Shared->Mutex);
       shader = st_get_fp_variant(st, stfp, &key)->base.driver_shader;
+      simple_mtx_unlock(&st->ctx->Shared->Mutex);
    }
 
    st_reference_prog(st, &st->fp, stfp);
@@ -232,7 +234,9 @@ st_update_vp( struct st_context *st )
           !st->ctx->GeometryProgram._Current)
          key.lower_ucp = st->ctx->Transform.ClipPlanesEnabled;
 
+      simple_mtx_lock(&st->ctx->Shared->Mutex);
       st->vp_variant = st_get_vp_variant(st, stvp, &key);
+      simple_mtx_unlock(&st->ctx->Shared->Mutex);
    }
 
    st_reference_prog(st, &st->vp, stvp);
@@ -291,7 +295,11 @@ st_update_common_program(struct st_context *st, struct gl_program *prog,
          key.lower_ucp = st->ctx->Transform.ClipPlanesEnabled;
    }
 
-   return st_get_common_variant(st, stp, &key)->driver_shader;
+   simple_mtx_lock(&st->ctx->Shared->Mutex);
+   void *result = st_get_common_variant(st, stp, &key)->driver_shader;
+   simple_mtx_unlock(&st->ctx->Shared->Mutex);
+
+   return result;
 }
 
 



More information about the mesa-commit mailing list