Optimize away redundant barriers.

This commit is contained in:
Hans-Kristian Arntzen 2018-01-09 12:17:38 +01:00
parent 9c72aa00c9
commit 7bb8874b43
3 changed files with 20 additions and 3 deletions

View File

@ -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];
}

View File

@ -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];
}

View File

@ -6678,8 +6678,27 @@ void CompilerGLSL::emit_instruction(const Instruction &instruction)
uint32_t next_semantics = get<SPIRConstant>(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;
}
}