+ /* If the fence doesn't exist, assume it's signalled. */
+ simple_mtx_lock(&so->mutex);
+ if (!so->fence) {
+ simple_mtx_unlock(&so->mutex);
+ so->b.StatusFlag = GL_TRUE;
+ return;
+ }
+
+ /* We need a local copy of the fence pointer, so that we can call
+ * fence_finish unlocked.
+ */
+ screen->fence_reference(screen, &fence, so->fence);
+ simple_mtx_unlock(&so->mutex);
+
+ /* Section 4.1.2 of OpenGL 4.5 (Compatibility Profile) says:
+ * [...] if ClientWaitSync is called and all of the following are true:
+ * - the SYNC_FLUSH_COMMANDS_BIT bit is set in flags,
+ * - sync is unsignaled when ClientWaitSync is called,
+ * - and the calls to ClientWaitSync and FenceSync were issued from
+ * the same context,
+ * then the GL will behave as if the equivalent of Flush were inserted
+ * immediately after the creation of sync.
+ *
+ * Assume GL_SYNC_FLUSH_COMMANDS_BIT is always set, because applications
+ * forget to set it.
+ */
+ if (screen->fence_finish(screen, pipe, fence, timeout)) {
+ simple_mtx_lock(&so->mutex);