diff --git a/reference/opt/shaders/comp/shared.comp b/reference/opt/shaders/comp/shared.comp index 694a0793..66ec1c2c 100644 --- a/reference/opt/shaders/comp/shared.comp +++ b/reference/opt/shaders/comp/shared.comp @@ -17,7 +17,6 @@ void main() { sShared[gl_LocalInvocationIndex] = _22.in_data[gl_GlobalInvocationID.x]; memoryBarrierShared(); - memoryBarrierShared(); barrier(); _44.out_data[gl_GlobalInvocationID.x] = sShared[(4u - gl_LocalInvocationIndex) - 1u]; } diff --git a/reference/shaders/comp/shared.comp b/reference/shaders/comp/shared.comp index d287991a..d0987a65 100644 --- a/reference/shaders/comp/shared.comp +++ b/reference/shaders/comp/shared.comp @@ -19,7 +19,6 @@ void main() float idata = _22.in_data[ident]; sShared[gl_LocalInvocationIndex] = idata; memoryBarrierShared(); - memoryBarrierShared(); barrier(); _44.out_data[ident] = sShared[(4u - gl_LocalInvocationIndex) - 1u]; } diff --git a/spirv_glsl.cpp b/spirv_glsl.cpp index 0283769f..211b4b92 100644 --- a/spirv_glsl.cpp +++ b/spirv_glsl.cpp @@ -6678,8 +6678,27 @@ void CompilerGLSL::emit_instruction(const Instruction &instruction) uint32_t next_semantics = get(next_ops[2]).scalar(); next_semantics = mask_relevant_memory_semantics(next_semantics); + bool memory_scope_covered = false; + if (next_memory == memory) + memory_scope_covered = true; + else if (next_semantics == MemorySemanticsWorkgroupMemoryMask) + { + // If we only care about workgroup memory, either Device or Workgroup scope is fine, + // scope does not have to match. + if ((next_memory == ScopeDevice || next_memory == ScopeWorkgroup) && + (memory == ScopeDevice || memory == ScopeWorkgroup)) + { + memory_scope_covered = true; + } + } + else if (memory == ScopeWorkgroup && next_memory == ScopeDevice) + { + // The control barrier has device scope, but the memory barrier just has workgroup scope. + memory_scope_covered = true; + } + // If we have the same memory scope, and all memory types are covered, we're good. - if (next_memory == memory && (semantics & next_semantics) == semantics) + if (memory_scope_covered && (semantics & next_semantics) == semantics) break; } }