PDA

View Full Version : Should I use glFinish / FenceSync for this or not?



Pygmy
02-02-2011, 05:57 AM
Suppose I'm rendering stuff to FrameBuffer A, and then want to use FrameBuffer A as a texture to render something to FrameBuffer B - do I need to wait for rendering to A to finish (using fencesync) before I can bind buffer A as a texture and use it to draw to B ?
Or does OpenGL automaticly wait for A to finish before it can be used as a texture ?

mfort
02-02-2011, 06:03 AM
no need to wait when everything is done in single OpenGL context.

Alfonse Reinheart
02-02-2011, 10:32 AM
To clarify this more:

The OpenGL specification requires that implementations process commands in the order given. Or at least, if they do them out-of-order, the results must be the same as if they were processed in order. So any OpenGL function you call will execute as if all of the prior OpenGL functions had executed to completion.

Now, this does not mean that each function call waits until the last one is done. The way it generally works is that the GPU has an internal command stream. Most OpenGL function calls simply write new commands into this stream, in the order the user calls the functions.

This all means that the OpenGL implementation will synchronize with itself. If you upload data to a buffer or texture, that process might not be fully complete immediately after the call to glBufferSubData/glTexSubImage. But it must behave as if it were complete. So the driver will do its own synchronization to ensure that, if you issue commands that use these objects, it will wait until those objects have finished uploading before executing them. The same goes with render targets.

glFinish is something you almost never need to call. You generally call it for debugging reasons at most. And FenceSync objects typically are used for the few OpenGL operations that are not implicitly synchronous (glMapBufferRange with the GL_UNSYNCHRONIZED) flag set.