diff options
| author | Egor Yusov <egor.yusov@gmail.com> | 2019-09-08 21:56:26 +0000 |
|---|---|---|
| committer | Egor Yusov <egor.yusov@gmail.com> | 2019-09-08 21:56:26 +0000 |
| commit | 52d1b5ab7fee4f2c4e63eaf5774d48111becba12 (patch) | |
| tree | 9eac4952a2eb4765352270cc7993fbefec83c6ce /Graphics/GraphicsEngineOpenGL | |
| parent | Updated constructor of RefCountedObject to forward arguments to its base class (diff) | |
| download | DiligentCore-52d1b5ab7fee4f2c4e63eaf5774d48111becba12.tar.gz DiligentCore-52d1b5ab7fee4f2c4e63eaf5774d48111becba12.zip | |
Added IDeviceContext::Wait() method (updated API version to 240026)
Diffstat (limited to 'Graphics/GraphicsEngineOpenGL')
4 files changed, 29 insertions, 1 deletions
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<std::pair<Uint64, GLObjectWrappers::GLSyncObj> > 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<FenceGLImpl>(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<FenceGLImpl>(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<GLuint64>::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, ")"); |
