![]() |
ImFusion SDK 4.3
|
#include <ImFusion/Core/GL/SyncObject.h>
Helper class to synchronize between multiple OpenGL contexts or a context and the application. More...
Helper class to synchronize between multiple OpenGL contexts or a context and the application.
OpenGL Sync objects provide more fine-grained control over GPU/client synchronization that GL::flush() and GL::finish(). You can insert them into the GPU command stream at any time to create a "marker" in the command stream. Then, at any time later you can check if that marker has already been reached (i.e. all commands before have been completed) and/or wait for this condition. The waiting for completion can be done either on the GPU side or on the client (CPU) side.
The main use case of is to synchronize write/read access to objects shared between multiple OpenGL contexts/threads. The OpenGL specification defines a set of rules that need to be followed to ensure that changes to a share object T
are visible across contexts (paraphrased/simplified, see section 5.3 "Propagating Changes to Objects" of the OpenGL 4.6 spec for the full definition):
T
on context A
must have completed before they can be seen on context B
.T
to context B
after the changes have completed on context A
.This can be achieved for instance like this:
Public Types | |
enum | WaitResult { AlreadySignaled = 0x911A , TimeoutExpired = 0x911B , ConditionSatisfied = 0x911C , WaitFailed = 0x911D } |
Enumeration of possible return values of waitClient(). More... | |
Public Member Functions | |
SyncObject () | |
Default constructor inserts a marker into the OpenGL command stream of the current context. | |
SyncObject (SyncObject &&) noexcept | |
SyncObject & | operator= (SyncObject &&) noexcept |
void | wait () const |
Wait on the GPU side until the underlying sync object has been signaled. | |
WaitResult | waitClient (std::chrono::nanoseconds timeout) const |
Wait on the client side until the underlying sync object has been signaled. | |
enum WaitResult |
Enumeration of possible return values of waitClient().
Enumerator | |
---|---|
AlreadySignaled | The fence was already signaled when waitClient() was called. |
TimeoutExpired | The fence was not signaled until the timeout was reached. |
ConditionSatisfied | The fence was signaled. |
WaitFailed | An OpenGL error occurred, you can use GL::Debug::check() to query details. |
void wait | ( | ) | const |
Wait on the GPU side until the underlying sync object has been signaled.
This function will return immediately, however current OpenGL context processing will wait until either the sync object becomes signaled or a driver-specific timeout occurred.
WaitResult waitClient | ( | std::chrono::nanoseconds | timeout | ) | const |
Wait on the client side until the underlying sync object has been signaled.
This function will block until either the sync object becomes signaled or a the given timeout occurred.
GL_SYNC_FLUSH_COMMANDS_BIT
flag internally to avoid deadlocks if called on the same context as the sync object was created.