Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Which to use for OpenGL client side waiting: glGetSynciv vs. glClientWaitSync?

I am unclear from the OpenGL Specification on Sync objects, whether to use glGetSynciv or glClientWaitSync in case I want to check for signalling of a sync object without waiting. How do the following two commands compare in terms of behavior and performance:

GLint syncStatus;
glGetSynciv(*sync, GL_SYNC_STATUS, sizeof(GLint), NULL, &syncStatus);
bool finished = syncStatus == GL_SIGNALED;

vs

bool finished = glClientWaitSync(*sync, 0 /*flags*/, 0 /*timeout*/) == ALREADY_SIGNALED;

Some details to the questions:

  • Does glGetSynciv perform a roundtrip to the GL server?
  • Is any method preferred in terms of driver support / bugs?
  • Could either method deadlock or not return immediately?

Some context:

  • This is for a video player, which is streaming images from a physical source to the GPU for rendering.
  • One thread is streaming / continuously uploading textures and another thread renders them once they are finished uploading. Each render frame we are checking if the next texture has finished uploading. If it has, then we start rendering this new texture, otherwise continue to using the old texture.
  • The decision is client side only and I do not want to wait at all, but quickly continue to render the correct texture.

Both methods have examples of people using them for the purpose of not waiting, but none seem to discuss the merits of using one or the other.

like image 879
Christopher Oezbek Avatar asked Jan 04 '16 22:01

Christopher Oezbek


1 Answers

Quoting the Red Book,

void glGetSynciv(GLsync sync, GLenum pname, GLsizei bufSize, GLsizei *lenght, GLint *values);

Retrieves the properties of a sync object. sync specifies a handle to the sync object from wich to read the property specified by pname. bufSize is the size in bytes of the buffer whose address is given in values. lenght is the address of an integer variable that will receive the number of bytes written into values

While for glClientWaitSync:

GLenum glClientWaitSync(GLsync sync, GLbitfields flags, GLuint64 timeout);

Causes the client to wait for the sync object to become signaled. glClientWaitSync() will wait at most timeout nanoseconds for the object to become signaled before generating a timeout. The flags parameter may be used to control flushing behavior of the command. Specifying GL_SYNC_FLUSH_COMMANDS_BIT is equivalent to calling glFlush() before executing wait.

So, basically glGetSynciv() is used to know if the fence object has become signaled and glClientWaitSync() is used to wait until the fence object has become signaled.

If you only want to know if a fence object has become signaled, I would suggest using glGetSynciv(). Obviously glClientWaitSync() should take longer to execute then glGetSynciv(), but I'm guessing. Hope i helped you.

like image 169
Matth Avatar answered Oct 06 '22 07:10

Matth