diff options
| author | assiduous <assiduous@diligentgraphics.com> | 2021-02-18 23:24:58 +0000 |
|---|---|---|
| committer | assiduous <assiduous@diligentgraphics.com> | 2021-03-19 00:38:08 +0000 |
| commit | 9cb6abf396e6598f2753872388843d599632912f (patch) | |
| tree | b9a9749265b3131e992c81a12dd9a4d0d3564474 /Graphics/GraphicsEngineVulkan | |
| parent | Refactored implementation of state tranistions in D3D12 backend (diff) | |
| download | DiligentCore-9cb6abf396e6598f2753872388843d599632912f.tar.gz DiligentCore-9cb6abf396e6598f2753872388843d599632912f.zip | |
Reworked CommandQueueD3D12Impl and CommandQueueVkImpl to use atomics
Diffstat (limited to 'Graphics/GraphicsEngineVulkan')
| -rw-r--r-- | Graphics/GraphicsEngineVulkan/include/CommandQueueVkImpl.hpp | 6 | ||||
| -rw-r--r-- | Graphics/GraphicsEngineVulkan/src/CommandQueueVkImpl.cpp | 9 |
2 files changed, 8 insertions, 7 deletions
diff --git a/Graphics/GraphicsEngineVulkan/include/CommandQueueVkImpl.hpp b/Graphics/GraphicsEngineVulkan/include/CommandQueueVkImpl.hpp index 4daa714e..cc1f7e3d 100644 --- a/Graphics/GraphicsEngineVulkan/include/CommandQueueVkImpl.hpp +++ b/Graphics/GraphicsEngineVulkan/include/CommandQueueVkImpl.hpp @@ -32,6 +32,8 @@ #include <mutex> #include <deque> +#include <atomic> + #include "VulkanUtilities/VulkanHeaders.h" #include "CommandQueueVk.h" #include "ObjectBase.hpp" @@ -55,7 +57,7 @@ public: IMPLEMENT_QUERY_INTERFACE_IN_PLACE(IID_CommandQueueVk, TBase) /// Implementation of ICommandQueueVk::GetNextFenceValue(). - virtual Uint64 DILIGENT_CALL_TYPE GetNextFenceValue() const override final { return m_NextFenceValue; } + virtual Uint64 DILIGENT_CALL_TYPE GetNextFenceValue() const override final { return m_NextFenceValue.load(); } /// Implementation of ICommandQueueVk::Submit(). virtual Uint64 DILIGENT_CALL_TYPE SubmitCmdBuffer(VkCommandBuffer cmdBuffer) override final; @@ -95,7 +97,7 @@ private: RefCntAutoPtr<FenceVkImpl> m_pFence; // A value that will be signaled by the command queue next - Atomics::AtomicInt64 m_NextFenceValue; + std::atomic_uint64_t m_NextFenceValue{1}; std::mutex m_QueueMutex; }; diff --git a/Graphics/GraphicsEngineVulkan/src/CommandQueueVkImpl.cpp b/Graphics/GraphicsEngineVulkan/src/CommandQueueVkImpl.cpp index 540363ca..bd3833dd 100644 --- a/Graphics/GraphicsEngineVulkan/src/CommandQueueVkImpl.cpp +++ b/Graphics/GraphicsEngineVulkan/src/CommandQueueVkImpl.cpp @@ -56,9 +56,8 @@ Uint64 CommandQueueVkImpl::Submit(const VkSubmitInfo& SubmitInfo) { std::lock_guard<std::mutex> Lock{m_QueueMutex}; - Atomics::Int64 FenceValue = m_NextFenceValue; // Increment the value before submitting the buffer to be overly safe - Atomics::AtomicIncrement(m_NextFenceValue); + auto FenceValue = m_NextFenceValue.fetch_add(1); auto vkFence = m_pFence->GetVkFence(); @@ -102,10 +101,10 @@ Uint64 CommandQueueVkImpl::WaitForIdle() { std::lock_guard<std::mutex> Lock{m_QueueMutex}; - // Update last completed fence value to unlock all waiting events - Uint64 LastCompletedFenceValue = m_NextFenceValue; + // Update last completed fence value to unlock all waiting events. + auto LastCompletedFenceValue = m_NextFenceValue.fetch_add(1); // Increment fence before idling the queue - Atomics::AtomicIncrement(m_NextFenceValue); + vkQueueWaitIdle(m_VkQueue); // For some reason after idling the queue not all fences are signaled m_pFence->Wait(UINT64_MAX); |
