diff options
| author | assiduous <assiduous@diligentgraphics.com> | 2021-03-06 05:37:08 +0000 |
|---|---|---|
| committer | assiduous <assiduous@diligentgraphics.com> | 2021-03-19 00:38:16 +0000 |
| commit | 4d71f65aea34a3c959281c61ac1085818ed6ebc6 (patch) | |
| tree | f162df1f583e4bb0853b1670c2ae623ba66dd733 /Graphics/GraphicsEngineOpenGL | |
| parent | OpenGL backend: updated resource binding procedure (diff) | |
| download | DiligentCore-4d71f65aea34a3c959281c61ac1085818ed6ebc6.tar.gz DiligentCore-4d71f65aea34a3c959281c61ac1085818ed6ebc6.zip | |
Reworked FenceGLImpl to use std::atomic
Diffstat (limited to 'Graphics/GraphicsEngineOpenGL')
| -rw-r--r-- | Graphics/GraphicsEngineOpenGL/include/FenceGLImpl.hpp | 8 | ||||
| -rw-r--r-- | Graphics/GraphicsEngineOpenGL/src/FenceGLImpl.cpp | 24 |
2 files changed, 22 insertions, 10 deletions
diff --git a/Graphics/GraphicsEngineOpenGL/include/FenceGLImpl.hpp b/Graphics/GraphicsEngineOpenGL/include/FenceGLImpl.hpp index 108a676d..bd2a78a4 100644 --- a/Graphics/GraphicsEngineOpenGL/include/FenceGLImpl.hpp +++ b/Graphics/GraphicsEngineOpenGL/include/FenceGLImpl.hpp @@ -31,6 +31,8 @@ /// Declaration of Diligent::FenceGLImpl class #include <deque> +#include <atomic> + #include "FenceGL.h" #include "RenderDeviceGL.h" #include "FenceBase.hpp" @@ -67,8 +69,12 @@ public: void Wait(Uint64 Value, bool FlushCommands); private: + void UpdateFenceValue(Uint64 NewValue); + +private: std::deque<std::pair<Uint64, GLObjectWrappers::GLSyncObj>> m_PendingFences; - volatile Uint64 m_LastCompletedFenceValue = 0; + + std::atomic_uint64_t m_LastCompletedFenceValue{0}; }; } // namespace Diligent diff --git a/Graphics/GraphicsEngineOpenGL/src/FenceGLImpl.cpp b/Graphics/GraphicsEngineOpenGL/src/FenceGLImpl.cpp index 78c840f1..ce23b5c9 100644 --- a/Graphics/GraphicsEngineOpenGL/src/FenceGLImpl.cpp +++ b/Graphics/GraphicsEngineOpenGL/src/FenceGLImpl.cpp @@ -51,6 +51,15 @@ FenceGLImpl::~FenceGLImpl() { } +void FenceGLImpl::UpdateFenceValue(Uint64 NewValue) +{ + auto CurrValue = m_LastCompletedFenceValue.load(); + while (!m_LastCompletedFenceValue.compare_exchange_strong(CurrValue, std::max(CurrValue, NewValue))) + { + // If exchange fails, CurrValue will hold the actual value of m_LastCompletedFenceValue + } +} + Uint64 FenceGLImpl::GetCompletedValue() { while (!m_PendingFences.empty()) @@ -64,8 +73,7 @@ Uint64 FenceGLImpl::GetCompletedValue() ); if (res == GL_ALREADY_SIGNALED) { - if (val_fence.first > m_LastCompletedFenceValue) - m_LastCompletedFenceValue = val_fence.first; + UpdateFenceValue(val_fence.first); m_PendingFences.pop_front(); } else @@ -74,7 +82,7 @@ Uint64 FenceGLImpl::GetCompletedValue() } } - return m_LastCompletedFenceValue; + return m_LastCompletedFenceValue.load(); } void FenceGLImpl::Wait(Uint64 Value, bool FlushCommands) @@ -89,17 +97,15 @@ void FenceGLImpl::Wait(Uint64 Value, bool FlushCommands) VERIFY_EXPR(res == GL_ALREADY_SIGNALED || res == GL_CONDITION_SATISFIED); (void)res; - if (val_fence.first > m_LastCompletedFenceValue) - m_LastCompletedFenceValue = val_fence.first; + UpdateFenceValue(val_fence.first); m_PendingFences.pop_front(); } } -void FenceGLImpl::Reset(Uint64 Value) +void FenceGLImpl::Reset(Uint64 NewValue) { - 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, ")"); - if (Value > m_LastCompletedFenceValue) - m_LastCompletedFenceValue = Value; + DEV_CHECK_ERR(NewValue >= m_LastCompletedFenceValue, "Resetting fence '", m_Desc.Name, "' to the value (", NewValue, ") that is smaller than the last completed value (", m_LastCompletedFenceValue, ")"); + UpdateFenceValue(NewValue); } } // namespace Diligent |
