Mesa (master): spirv: Add a workaround for OpControlBarrier on old GLSLang

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Mon Jan 13 17:51:20 UTC 2020


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

Author: Jason Ekstrand <jason at jlekstrand.net>
Date:   Tue Jan  7 11:35:54 2020 -0600

spirv: Add a workaround for OpControlBarrier on old GLSLang

As per the Vulkan memory model, the proper translation of GLSL barrier()
is an OpControlBarrier with a scope of Workgroup and semantics of
Acquire, Release, and WorkgroupMemory.  Older versions of GLSLang gave
an OpControlBarrier with semantics of None so we need to patch it up on
those versions.

Reviewed-by: Caio Marcelo de Oliveira Filho <caio.oliveira at intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/merge_requests/3307>

---

 src/compiler/spirv/spirv_to_nir.c | 22 +++++++++++++++++++++-
 src/compiler/spirv/vtn_private.h  |  3 +++
 2 files changed, 24 insertions(+), 1 deletion(-)

diff --git a/src/compiler/spirv/spirv_to_nir.c b/src/compiler/spirv/spirv_to_nir.c
index e54fc6906b8..42895b542ff 100644
--- a/src/compiler/spirv/spirv_to_nir.c
+++ b/src/compiler/spirv/spirv_to_nir.c
@@ -3675,11 +3675,24 @@ vtn_handle_barrier(struct vtn_builder *b, SpvOp opcode,
    }
 
    case SpvOpControlBarrier: {
+      SpvScope execution_scope = vtn_constant_uint(b, w[1]);
       SpvScope memory_scope = vtn_constant_uint(b, w[2]);
       SpvMemorySemanticsMask memory_semantics = vtn_constant_uint(b, w[3]);
+
+      /* GLSLang, prior to commit 8297936dd6eb3, emitted OpControlBarrier with
+       * memory semantics of None for GLSL barrier().
+       */
+      if (b->wa_glslang_cs_barrier &&
+          b->nb.shader->info.stage == MESA_SHADER_COMPUTE &&
+          execution_scope == SpvScopeWorkgroup &&
+          memory_semantics == SpvMemorySemanticsMaskNone) {
+         memory_scope = SpvScopeWorkgroup;
+         memory_semantics = SpvMemorySemanticsAcquireReleaseMask |
+                            SpvMemorySemanticsWorkgroupMemoryMask;
+      }
+
       vtn_emit_memory_barrier(b, memory_scope, memory_semantics);
 
-      SpvScope execution_scope = vtn_constant_uint(b, w[1]);
       if (execution_scope == SpvScopeWorkgroup)
          vtn_emit_barrier(b, nir_intrinsic_barrier);
       break;
@@ -5103,6 +5116,13 @@ vtn_create_builder(const uint32_t *words, size_t word_count,
     */
    b->wa_glslang_179 = (generator_id == 8 && generator_version == 1);
 
+   /* In GLSLang commit 8297936dd6eb3, their handling of barrier() was fixed
+    * to provide correct memory semantics on compute shader barrier()
+    * commands.  Prior to that, we need to fix them up ourselves.  This
+    * GLSLang fix caused them to bump to generator version 3.
+    */
+   b->wa_glslang_cs_barrier = (generator_id == 8 && generator_version < 3);
+
    /* words[2] == generator magic */
    unsigned value_id_bound = words[3];
    if (words[4] != 0) {
diff --git a/src/compiler/spirv/vtn_private.h b/src/compiler/spirv/vtn_private.h
index 436bac8a664..92daf1352bd 100644
--- a/src/compiler/spirv/vtn_private.h
+++ b/src/compiler/spirv/vtn_private.h
@@ -626,6 +626,9 @@ struct vtn_builder {
    /* True if we should watch out for GLSLang issue #179 */
    bool wa_glslang_179;
 
+   /* True if we need to fix up CS OpControlBarrier */
+   bool wa_glslang_cs_barrier;
+
    gl_shader_stage entry_point_stage;
    const char *entry_point_name;
    struct vtn_value *entry_point;



More information about the mesa-commit mailing list