From a67c5221e327950855a6cc70ade245d548bcba06 Mon Sep 17 00:00:00 2001 From: Zach Pomerantz Date: Thu, 18 Aug 2016 18:40:53 -0700 Subject: [PATCH 1/2] flush openvr fence before looking for it --- plugins/openvr/src/OpenVrDisplayPlugin.cpp | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/plugins/openvr/src/OpenVrDisplayPlugin.cpp b/plugins/openvr/src/OpenVrDisplayPlugin.cpp index e751427ce2..8818cce628 100644 --- a/plugins/openvr/src/OpenVrDisplayPlugin.cpp +++ b/plugins/openvr/src/OpenVrDisplayPlugin.cpp @@ -111,12 +111,17 @@ public: _plugin.withNonPresentThreadLock([&] { while (!_queue.empty()) { auto& front = _queue.front(); + auto result = glClientWaitSync(front.fence, 0, 0); - if (GL_TIMEOUT_EXPIRED == result && GL_WAIT_FAILED == result) { + + if (GL_TIMEOUT_EXPIRED == result || GL_WAIT_FAILED == result) { break; + } else if (GL_CONDITION_SATISFIED == result || GL_CONDITION_SATISFIED == result) { + glDeleteSync(front.fence); + } else { + assert(false); } - glDeleteSync(front.fence); front.fence = 0; _current = front; _queue.pop(); @@ -455,6 +460,16 @@ void OpenVrDisplayPlugin::compositeLayers() { #if OPENVR_THREADED_SUBMIT newComposite.fence = glFenceSync(GL_SYNC_GPU_COMMANDS_COMPLETE, 0); + // https://www.opengl.org/registry/specs/ARB/sync.txt: + // > The simple flushing behavior defined by + // > SYNC_FLUSH_COMMANDS_BIT will not help when waiting for a fence + // > command issued in another context's command stream to complete. + // > Applications which block on a fence sync object must take + // > additional steps to assure that the context from which the + // > corresponding fence command was issued has flushed that command + // > to the graphics pipeline. + glFlush(); + if (!newComposite.textureID) { newComposite.textureID = getGLBackend()->getTextureID(newComposite.texture, false); } From dbb916e2d9f56b6ec158c528ce48221217798706 Mon Sep 17 00:00:00 2001 From: Zach Pomerantz Date: Mon, 22 Aug 2016 13:59:18 -0700 Subject: [PATCH 2/2] fix redundant openvr fence condition --- plugins/openvr/src/OpenVrDisplayPlugin.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/openvr/src/OpenVrDisplayPlugin.cpp b/plugins/openvr/src/OpenVrDisplayPlugin.cpp index 8818cce628..0cb95e5747 100644 --- a/plugins/openvr/src/OpenVrDisplayPlugin.cpp +++ b/plugins/openvr/src/OpenVrDisplayPlugin.cpp @@ -116,7 +116,7 @@ public: if (GL_TIMEOUT_EXPIRED == result || GL_WAIT_FAILED == result) { break; - } else if (GL_CONDITION_SATISFIED == result || GL_CONDITION_SATISFIED == result) { + } else if (GL_CONDITION_SATISFIED == result || GL_ALREADY_SIGNALED == result) { glDeleteSync(front.fence); } else { assert(false);