Reputation: 461
Is it possible and safe to call glDispatchCompute()
for same compute shader multiple times or I have to always wait untill the shader finishes and then dispatch again?
Upvotes: 3
Views: 1535
Reputation: 474336
So long as there is no memory dependency between the two dispatch operations (ie: you're not accessing data written by a previous dispatch), it should be fine. Otherwise, you will need to invoke glMemoryBarrier
, with bits appropriate to the way the next dispatch will access the data.
Changes to actual uniform variables (through glUniform
or glProgramUniform
) between the two dispatches are fine. Changes to UBO data is fine so long as you're modifying the buffer's data through actual API calls (glBufferSubData
or call glMapBufferRange
between the dispatches). If you're modifying the buffer's data through a pointer to persistently mapped buffer data, then you need to do a full CPU/GPU sync before you can modify any bytes that were being read by the previous dispatch calls.
Upvotes: 4