OpenGL Compute shaders synchronization

Hey there, I have a question about OpenGL compute shader synchronization. When Ì dispatch a compute shader via glDispatchCompute, and afterwards I use a different compute Shader via glDispatchCompute, but the data of the second shader depends on the first one, how do I synchronize this, so that it is guaranteed that the first shader finished processing before the second shader starts.

Also, can I run multiple different compute shaders at the same time?

glMemoryBarrier, with the appropriate bits, is the synchronization tool you need to ensure that the second operation can see the data written by the first.

Also, can I run multiple different compute shaders at the same time?

If you don’t put any synchronization between dispatch calls, then the two calls may overlap in execution to some extent. But otherwise, there is no way to tell the GPU to give equal time (or any particular proportion) to two separate compute shader operations.

If I have multiple glDispatchCompute calls, how do I tell the glMemoryBarrier which shader to target?

They target all prior operations which can perform incoherent writes. That is, anything which did incoherent writes before the barrier is synchronized with anything after the barrier which consumes those writes through the specified accesses.

The synchronization is coarse-grained; OpenGL isn’t Vulkan. Though even Vulkan cannot target a specific shader or dispatch.

1 Like

So it waits for all the shader which were previously dispatched and could perform incoherent writes to finish right?

The function doesn’t “wait”. It simply prevents the GPU from executing later commands until the earlier, potentially conflicting commands have finished. This could introduce a temporary stall in the GPU, but I wouldn’t call that “waiting”.

1 Like

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.