This question is similar as GLSL memoryBarrierShared() usefulness? .
However I wonder when do we have to use subgroupMemoryBarrier
and similar functions since the subgroupBarrier
performs both an execution and a memory barrier. For the memoryBarrier
function I understand, because barrier
function does not perform a memory barrier. so you must use both :
memoryBarrier(); // memoryBarrierShared, Buffer, Image...
barrier();
But I do not know when can I use subgroupMemoryBarrier
because it is already done by the subgroupBarrier
.
GL_KHR_shader_subgroup extension
The function subgroupBarrier() enforces that all active invocations within a subgroup must execute this function before any are allowed to continue their execution, and the results of any memory stores performed using coherent variables performed prior to the call will be visible to any future coherent access to the same memory performed by any other shader invocation within the same subgroup.
I don't think they have made these functions if they are not useful. So I wonder when do we need to use them?
Is it because on a subgroup, it is assumed that they run in parallel, so, you can just issue a subgroupMemoryBarrier
. But in this case, when do you have to use subgroupBarrier
?