The idea mentioned in the specification of GL_ARB_sync, issue 18, behavior B6)
I just want to express big support for this idea and to make some comments/suggestions.
In my view the 2 main benefits of this would be that it will allow us to:
- use OS-specific multi-condition waiting APIs (select()/poll() on unix and WaitForMultipleObjects() on ms windows) with OpenGL sync objects.
Currently there is no efficient way for a thread to wait until any of several events occur, one of which is opengl sync and
others are e.g. signal from another thread, window-system-specific event (window message on windows and X event on unix), IO events, etc. - sync with OpenGL events from within different threads without the need to create multiple shared opengl contexts and even from separate processes.
For unix the GL_ARB_sync spec mentions file descriptors, semaphores and X events. File descriptors can be used with select/poll, so they are great choice.
X events can be “converted” to a file descriptor by using the function ConnectionNumber(); this may be more conceptually appropriate in the sense that OpenGL is more close to the X
than to the unix system api but still i vote for plain file descriptors because X events would have to pass through the X server, which adds unnecessary delay and overhead.
(The point of direct glX context is to avoid the overhead of communicating with the X server as much as possible).
Even on non-direct glX contexts that run on remote machine a file descriptor can still be used - in this case it may be internally a socket.
Or this mechanism can just be unavailable for non-direct contexts. I don’t think anyone really cares about those.
Semaphores are not good choice (i assume they were talking about the sysV IPC semaphores) because they can not be used with select/poll.
It is worth to mention that the linux-specific synchronization primitive “futex” can be converted to file descriptor too.
Under windows any object handle that can be used with WaitForMultipleObjects will do; can be windows event or anything else - whatever is most convenient for the implementation.
Is is probably worth to note that if it can be used with WaitForMultipleObjects then it also can be used with MsgWaitForMultipleObjects,
which allows the thread to wait simultaneously for GL syncs and window messages.
I think it would be enough to have only single OS waitable object per opengl context. A thread can use it to wait until anything happens in the context and then use
other means to determine what exactly happened e.g. a function that returns the id of the earliest triggered sync that is not returned by the same function yet:
GLsync glGetNextTriggeredSync(); // return 0 if no sync has been triggered since the last check
The function that gives the OS specific waitable object should probably be located in the window-system APIs - glX, wgl, agl.
int glXGetContextWaitableFileDescriptor(Display *dpy, GLXContext ctx); - for glX
HANDLE wglGetContextWaitableHandle(HGLRC ctx); - for wgl
(add agl variant here - im not familiar with agl)
The application need not close these file descriptors or handles - when the context is destroyed, the implementation will take care of them automatically.
I don’t know what should happen if the application still closes them. Maybe this should lead to undefined consequences or maybe the implementation should support it.