diff options
author | Jason Ekstrand <[email protected]> | 2020-01-07 11:35:54 -0600 |
---|---|---|
committer | Marge Bot <[email protected]> | 2020-01-13 17:23:47 +0000 |
commit | 2365520c9d321c015a8e6751351d75cffea5008f (patch) | |
tree | b635fab8467e990f4832c15748942966af397491 /src/compiler | |
parent | 60097cc840e33af8506d7d4d621fefdca1a77695 (diff) |
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 <[email protected]>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/merge_requests/3307>
Diffstat (limited to 'src/compiler')
-rw-r--r-- | src/compiler/spirv/spirv_to_nir.c | 22 | ||||
-rw-r--r-- | src/compiler/spirv/vtn_private.h | 3 |
2 files changed, 24 insertions, 1 deletions
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; |