Reputation: 10045
I want to use imageStore
and imageLoad
in multiple compute shaders.
This is mixed with "normal" rendering commands (glDraw) to the screen or to framebuffers, but these don't use imageStore
or imageLoad
(only texture
or texelFetch
).
I only have one OpenGL context and thread.
My assumptions are the following:
imageStore
, I need to do glMemoryBarrier
before doing an imageLoad
in a later compute shader or texture
or texelFetch
in a later fragment shader.coherent
at all.glSync
at all.glMemoryBarrier
after writing to a texture using a framebuffer and then reading it with imageLoad
glMemoryBarrier
between the calls, there are no "threading issues".Are they correct?
Upvotes: 3
Views: 1338
Reputation: 473447
Each of those is correct, with the ''possible'' exception of one:
I don't need to use
coherent
at all.
You may need coherent
, depending on what your compute shader is doing. If your compute shader writes to an image, then reads from data written by another invocation within the same dispatch, then you need coherent
. So if you do an imageStore
, issue a compute shader barrier()
call, then do an imageLoad
to read some other invocation's value, then you need the coherent
qualifier.
coherent
is about ensuring visibility within a rendering command (CS dispatches are considered "rendering commands" in OpenGL). If you don't need internal visibility, then you don't need coherent
.
I want to elaborate on this, because it's a common source of confusion:
I don't need to use
glMemoryBarrier
after writing to a texture using a framebuffer and then reading it withimageLoad
This is absolutely correct. Memory barriers are about ensuring the visibility (and synchronization) of incoherent writes to memory. Rendering to the framebuffer is not an incoherent write. So you can use imageLoad
on such data without needing explicit synchronization.
Assuming of course that you are not rendering to that framebuffer in the same operation you're imageLoad
ing from it. That rule still applies.
Upvotes: 4