Using fence sync objects in OpenGL
Asked Answered
U

1

9

I am trying to look for scenarios where Sync Objects can be used in OpenGL. My understanding is that a sync object once put in GL command stream ( using glFenceSync() ) will be signaled after all the GL commands are executed and realized. If the sync objects are synchronization primitives why can't we MANUALLY signal them ? Where exactly this functionality can help GL programmer ?

Is the following scenario a correct one ?

Thread 1 :

Load model
Draw()
glFenceSync()

Thread 2 :

glWaitSync();
ReadPixels
Use data for subsequent operation.

Does this mean that I can't launch thread 2 unless glFenceSync() is called in Thread 1 ?

Unison answered 28/2, 2013 at 13:40 Comment(1)
"Does this mean that I can't launch thread 2 unless glFenceSync() is called in Thread 1 ?" Well, until you call glFenceSync, the sync object doesn't exist yet. You can't wait for something that doesn't exist.Wofford
M
10

Fences are not so much meant to synchronize threads, but to know, when asynchronus operations are finished. For example if you do a glReadPixels into a pixel buffer object (PBO), you might want to know, that the read has been completed, before you even attempt to read from or map the PBO to client address space.

If you do a glReadPixels with a PBO being the target, the call will return immediately, but the data transfer may indeed take some time. That's where fences come in handy.

Mover answered 28/2, 2013 at 14:26 Comment(1)
I have a situation where I draw into an FBO in one thread, and then render from the color attachment texture to a screen in another thread (and create a fence to know when rendering is complete). When a new FBO is available I hand the old FBO and the fence back to the FBO manager so that it can query the fence and know the FBO is available for writing again.Feoff

© 2022 - 2024 — McMap. All rights reserved.