From 52d1b5ab7fee4f2c4e63eaf5774d48111becba12 Mon Sep 17 00:00:00 2001 From: Egor Yusov Date: Sun, 8 Sep 2019 14:56:26 -0700 Subject: Added IDeviceContext::Wait() method (updated API version to 240026) --- .../GraphicsEngineOpenGL/include/DeviceContextGLImpl.h | 2 ++ Graphics/GraphicsEngineOpenGL/include/FenceGLImpl.h | 2 ++ .../GraphicsEngineOpenGL/src/DeviceContextGLImpl.cpp | 9 ++++++++- Graphics/GraphicsEngineOpenGL/src/FenceGLImpl.cpp | 17 +++++++++++++++++ 4 files changed, 29 insertions(+), 1 deletion(-) (limited to 'Graphics/GraphicsEngineOpenGL') diff --git a/Graphics/GraphicsEngineOpenGL/include/DeviceContextGLImpl.h b/Graphics/GraphicsEngineOpenGL/include/DeviceContextGLImpl.h index 96653441..3d64ad3f 100644 --- a/Graphics/GraphicsEngineOpenGL/include/DeviceContextGLImpl.h +++ b/Graphics/GraphicsEngineOpenGL/include/DeviceContextGLImpl.h @@ -150,6 +150,8 @@ public: virtual void SignalFence(IFence* pFence, Uint64 Value)override final; + virtual void Wait(IFence* pFence, Uint64 Value)override final; + virtual bool UpdateCurrentGLContext()override final; void BindProgramResources(Uint32& NewMemoryBarriers, IShaderResourceBinding* pResBinding); diff --git a/Graphics/GraphicsEngineOpenGL/include/FenceGLImpl.h b/Graphics/GraphicsEngineOpenGL/include/FenceGLImpl.h index ceab0d57..bade8fd1 100644 --- a/Graphics/GraphicsEngineOpenGL/include/FenceGLImpl.h +++ b/Graphics/GraphicsEngineOpenGL/include/FenceGLImpl.h @@ -59,6 +59,8 @@ public: m_PendingFences.emplace_back(Value, std::move(Fence)); } + void Wait(Uint64 Value); + private: std::deque > m_PendingFences; volatile Uint64 m_LastCompletedFenceValue = 0; diff --git a/Graphics/GraphicsEngineOpenGL/src/DeviceContextGLImpl.cpp b/Graphics/GraphicsEngineOpenGL/src/DeviceContextGLImpl.cpp index 2b19d5f1..ec77379d 100644 --- a/Graphics/GraphicsEngineOpenGL/src/DeviceContextGLImpl.cpp +++ b/Graphics/GraphicsEngineOpenGL/src/DeviceContextGLImpl.cpp @@ -1073,7 +1073,14 @@ namespace Diligent CHECK_GL_ERROR( "Failed to create gl fence" ); auto* pFenceGLImpl = ValidatedCast(pFence); pFenceGLImpl->AddPendingFence(std::move(GLFence), Value); - }; + } + + void DeviceContextGLImpl::Wait(IFence* pFence, Uint64 Value) + { + VERIFY(!m_bIsDeferred, "Fence can only be waited from immediate context"); + auto* pFenceGLImpl = ValidatedCast(pFence); + pFenceGLImpl->Wait(Value); + } bool DeviceContextGLImpl::UpdateCurrentGLContext() { diff --git a/Graphics/GraphicsEngineOpenGL/src/FenceGLImpl.cpp b/Graphics/GraphicsEngineOpenGL/src/FenceGLImpl.cpp index 75983e18..7e39aa2f 100644 --- a/Graphics/GraphicsEngineOpenGL/src/FenceGLImpl.cpp +++ b/Graphics/GraphicsEngineOpenGL/src/FenceGLImpl.cpp @@ -64,6 +64,23 @@ Uint64 FenceGLImpl :: GetCompletedValue() return m_LastCompletedFenceValue; } +void FenceGLImpl :: Wait(Uint64 Value) +{ + while (!m_PendingFences.empty()) + { + auto& val_fence = m_PendingFences.front(); + if (val_fence.first > Value) + break; + + auto res = glClientWaitSync(val_fence.second, GL_SYNC_FLUSH_COMMANDS_BIT, std::numeric_limits::max()); + VERIFY_EXPR(res == GL_ALREADY_SIGNALED || res == GL_CONDITION_SATISFIED); + + if (val_fence.first > m_LastCompletedFenceValue) + m_LastCompletedFenceValue = val_fence.first; + m_PendingFences.pop_front(); + } +} + void FenceGLImpl :: Reset(Uint64 Value) { DEV_CHECK_ERR(Value >= m_LastCompletedFenceValue, "Resetting fence '", m_Desc.Name, "' to the value (", Value, ") that is smaller than the last completed value (", m_LastCompletedFenceValue, ")"); -- cgit v1.2.3