Home > Blockchain >  Do I need to fence/sync when I use GL_MAP_COHERENT_BIT in a PMB?
Do I need to fence/sync when I use GL_MAP_COHERENT_BIT in a PMB?

Time:02-08

I've seen contradictory documentation about it. In the Khronos documentation it's a bit ambiguous whether I need to glFinish (or variants) or not. I'm currently triple-buffering my buffer to avoid this problem (as I use the PMB dynamically) but it obviously consumes a lot of memory. I know that the flag makes the data-changes automatically visible both to the GPU and CPU, but don't know if I have to sync the writes with the reads. I need to know if I really need to sync the GL_MAP_COHERENT_BIT flag or there's an implicit synchronization.

CodePudding user response:

There's no implicit synchronization because the driver/GPU has no idea when you're accessing the mapped pointer. That's what persistent mapping is all about, after all.

And yes, you still need synchronization. If you're trying to read something the GPU has written... you need the GPU to have written it before you can read it. And vice-versa for writing; you don't want to write to data that's being read by the GPU.

So use synchronization. If you're triple-buffering, odds are good that the wait-fence call will be a quick no-op.

  •  Tags:  
  • Related