If you have a compute shader where different work groups in the same dispatch are put in a continuous loop and you want to signal them all to exit said loop by any of them setting a flag. Is this actually possible?
I've tried using a flag in an SSBO marked both coherent and volatile to trigger their exit. Which sometimes doesn't work on AMD it seems. When one of the work groups wants to trigger all of them to exit I simply set the flag from zero to one directly (as it doesn't matter as long as someone sets it) with no use of atomics and call a memoryBarrier() afterwards.
From the documentation of memoryBarrier() it seems to me like it will guarantee the eventual visibility of the set to other work groups within the same dispatch?
From the documentation of memoryBarrier() it seems to me like it will guarantee the eventual visibility of the set to other work groups within the same dispatch?
Visibility, yes. But what about the execution of them?
Do you have any guarantees that the work group that will trigger this shutdown will be executed alongside the looping work groups? No.
There are no ordering guarantees at all between invocations from different work groups. So it is entirely possible that the GPU will fill all of its execution time with the looping work groups. Which means that they will wait for a signal that will never come.
Compute shaders offer no guarantees that all threads will progress. And therefore, you cannot write code that assumes they will. The only tool to control the execution of compute shaders is barrier
, and that only controls the execution of invocations within a work group.