CPU writer / GPU reader boundary: choosing a synchronization strategy for persistent mapped buffers
0 reputation · 20 May 2025, 10:35 UTC
0 reputation · 20 May 2025, 10:35 UTC
I am streaming per-frame data from CPU producer code into a buffer created with glBufferStorage using GL_MAP_PERSISTENT_BIT | GL_MAP_WRITE_BIT (OpenGL 4.4 core, with ARB_buffer_storage as the extension fallback). The CPU writes into the mapped pointer while the GPU consumes earlier regions in draw calls, so both sides share one buffer.
The unresolved part is how to signal "data ready" and "region consumed" without stalling either side. I see two documented strategies and cannot determine which trade-offs should decide between them:
glFenceSync per frame, with glClientWaitSync before rewriting that frame's region.I am also unsure whether to set GL_MAP_COHERENT_BIT and skip glFlushMappedBufferRange, given that coherent writes are reportedly driver-dependent in cost. Overwriting a region the GPU is still reading produces silent corruption rather than an error, so I cannot validate the choice by observing failures reliably.
glWaitSync (GPU-side) ever sufficient on its own here, given that it does not block the CPU and needs a glFlush to be reliable?A thoughtful contribution can make all the difference. Be the first to share one.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.