summaryrefslogtreecommitdiffstats
path: root/Graphics
diff options
context:
space:
mode:
authorassiduous <assiduous@diligentgraphics.com>2021-03-14 02:57:23 +0000
committerassiduous <assiduous@diligentgraphics.com>2021-03-19 00:38:22 +0000
commitae289a9d49ab469a5fc1962274b4b0fd7eb8dfb1 (patch)
tree236cb6dabd2f0a5b2a9dc720f1b36b97a330ebf4 /Graphics
parentReworked CommandListBase to use EngineImplTraits like the rest of the base cl... (diff)
downloadDiligentCore-ae289a9d49ab469a5fc1962274b4b0fd7eb8dfb1.tar.gz
DiligentCore-ae289a9d49ab469a5fc1962274b4b0fd7eb8dfb1.zip
Unified fence implementations in all backends
Diffstat (limited to 'Graphics')
-rw-r--r--Graphics/GraphicsEngine/include/FenceBase.hpp14
-rw-r--r--Graphics/GraphicsEngineD3D11/include/FenceD3D11Impl.hpp6
-rw-r--r--Graphics/GraphicsEngineD3D11/src/FenceD3D11Impl.cpp14
-rw-r--r--Graphics/GraphicsEngineOpenGL/include/FenceGLImpl.hpp5
-rw-r--r--Graphics/GraphicsEngineOpenGL/src/FenceGLImpl.cpp15
-rw-r--r--Graphics/GraphicsEngineVulkan/include/FenceVkImpl.hpp3
-rw-r--r--Graphics/GraphicsEngineVulkan/src/FenceVkImpl.cpp9
7 files changed, 25 insertions, 41 deletions
diff --git a/Graphics/GraphicsEngine/include/FenceBase.hpp b/Graphics/GraphicsEngine/include/FenceBase.hpp
index 0bcaae36..e9dc0f9f 100644
--- a/Graphics/GraphicsEngine/include/FenceBase.hpp
+++ b/Graphics/GraphicsEngine/include/FenceBase.hpp
@@ -30,6 +30,8 @@
/// \file
/// Implementation of the Diligent::FenceBase template class
+#include <atomic>
+
#include "DeviceObjectBase.hpp"
#include "GraphicsTypes.h"
#include "RefCntAutoPtr.hpp"
@@ -66,6 +68,18 @@ public:
}
IMPLEMENT_QUERY_INTERFACE_IN_PLACE(IID_Fence, TDeviceObjectBase)
+
+protected:
+ void UpdateLastCompletedFenceValue(uint64_t NewValue)
+ {
+ auto LastCompletedValue = m_LastCompletedFenceValue.load();
+ while (!m_LastCompletedFenceValue.compare_exchange_strong(LastCompletedValue, std::max(LastCompletedValue, NewValue)))
+ {
+ // If exchange fails, LastCompletedValue will hold the actual value of m_LastCompletedFenceValue.
+ }
+ }
+
+ std::atomic_uint64_t m_LastCompletedFenceValue{0};
};
} // namespace Diligent
diff --git a/Graphics/GraphicsEngineD3D11/include/FenceD3D11Impl.hpp b/Graphics/GraphicsEngineD3D11/include/FenceD3D11Impl.hpp
index 9385d3c4..49b5ea54 100644
--- a/Graphics/GraphicsEngineD3D11/include/FenceD3D11Impl.hpp
+++ b/Graphics/GraphicsEngineD3D11/include/FenceD3D11Impl.hpp
@@ -31,10 +31,11 @@
/// Declaration of Diligent::FenceD3D11Impl class
#include <deque>
+#include <atlbase.h>
+
+#include "EngineD3D11ImplTraits.hpp"
#include "FenceD3D11.h"
-#include "RenderDeviceD3D11.h"
#include "FenceBase.hpp"
-#include "RenderDeviceD3D11Impl.hpp"
namespace Diligent
{
@@ -81,7 +82,6 @@ private:
{}
};
std::deque<PendingFenceData> m_PendingQueries;
- volatile Uint64 m_LastCompletedFenceValue = 0;
};
} // namespace Diligent
diff --git a/Graphics/GraphicsEngineD3D11/src/FenceD3D11Impl.cpp b/Graphics/GraphicsEngineD3D11/src/FenceD3D11Impl.cpp
index 28da90ff..2bb2bdf5 100644
--- a/Graphics/GraphicsEngineD3D11/src/FenceD3D11Impl.cpp
+++ b/Graphics/GraphicsEngineD3D11/src/FenceD3D11Impl.cpp
@@ -26,9 +26,9 @@
*/
#include "pch.h"
-#include <atlbase.h>
#include "FenceD3D11Impl.hpp"
+#include "RenderDeviceD3D11Impl.hpp"
#include "EngineMemory.h"
namespace Diligent
@@ -55,8 +55,7 @@ Uint64 FenceD3D11Impl::GetCompletedValue()
if (res == S_OK)
{
VERIFY_EXPR(Data == TRUE);
- if (QueryData.Value > m_LastCompletedFenceValue)
- m_LastCompletedFenceValue = QueryData.Value;
+ UpdateLastCompletedFenceValue(QueryData.Value);
m_PendingQueries.pop_front();
}
else
@@ -65,7 +64,7 @@ Uint64 FenceD3D11Impl::GetCompletedValue()
}
}
- return m_LastCompletedFenceValue;
+ return m_LastCompletedFenceValue.load();
}
void FenceD3D11Impl::Wait(Uint64 Value, bool FlushCommands)
@@ -81,9 +80,7 @@ void FenceD3D11Impl::Wait(Uint64 Value, bool FlushCommands)
std::this_thread::yield();
VERIFY_EXPR(Data == TRUE);
- if (QueryData.Value > m_LastCompletedFenceValue)
- m_LastCompletedFenceValue = QueryData.Value;
-
+ UpdateLastCompletedFenceValue(QueryData.Value);
m_PendingQueries.pop_front();
}
}
@@ -91,8 +88,7 @@ void FenceD3D11Impl::Wait(Uint64 Value, bool FlushCommands)
void FenceD3D11Impl::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, ")");
- if (Value > m_LastCompletedFenceValue)
- m_LastCompletedFenceValue = Value;
+ UpdateLastCompletedFenceValue(Value);
}
} // namespace Diligent
diff --git a/Graphics/GraphicsEngineOpenGL/include/FenceGLImpl.hpp b/Graphics/GraphicsEngineOpenGL/include/FenceGLImpl.hpp
index d0095402..727886cb 100644
--- a/Graphics/GraphicsEngineOpenGL/include/FenceGLImpl.hpp
+++ b/Graphics/GraphicsEngineOpenGL/include/FenceGLImpl.hpp
@@ -68,12 +68,7 @@ public:
void Wait(Uint64 Value, bool FlushCommands);
private:
- void UpdateFenceValue(Uint64 NewValue);
-
-private:
std::deque<std::pair<Uint64, GLObjectWrappers::GLSyncObj>> m_PendingFences;
-
- std::atomic_uint64_t m_LastCompletedFenceValue{0};
};
} // namespace Diligent
diff --git a/Graphics/GraphicsEngineOpenGL/src/FenceGLImpl.cpp b/Graphics/GraphicsEngineOpenGL/src/FenceGLImpl.cpp
index fe88669e..677e1db9 100644
--- a/Graphics/GraphicsEngineOpenGL/src/FenceGLImpl.cpp
+++ b/Graphics/GraphicsEngineOpenGL/src/FenceGLImpl.cpp
@@ -52,15 +52,6 @@ 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())
@@ -74,7 +65,7 @@ Uint64 FenceGLImpl::GetCompletedValue()
);
if (res == GL_ALREADY_SIGNALED)
{
- UpdateFenceValue(val_fence.first);
+ UpdateLastCompletedFenceValue(val_fence.first);
m_PendingFences.pop_front();
}
else
@@ -98,7 +89,7 @@ void FenceGLImpl::Wait(Uint64 Value, bool FlushCommands)
VERIFY_EXPR(res == GL_ALREADY_SIGNALED || res == GL_CONDITION_SATISFIED);
(void)res;
- UpdateFenceValue(val_fence.first);
+ UpdateLastCompletedFenceValue(val_fence.first);
m_PendingFences.pop_front();
}
}
@@ -106,7 +97,7 @@ void FenceGLImpl::Wait(Uint64 Value, bool FlushCommands)
void FenceGLImpl::Reset(Uint64 NewValue)
{
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);
+ UpdateLastCompletedFenceValue(NewValue);
}
} // namespace Diligent
diff --git a/Graphics/GraphicsEngineVulkan/include/FenceVkImpl.hpp b/Graphics/GraphicsEngineVulkan/include/FenceVkImpl.hpp
index b720d604..21b2a7b9 100644
--- a/Graphics/GraphicsEngineVulkan/include/FenceVkImpl.hpp
+++ b/Graphics/GraphicsEngineVulkan/include/FenceVkImpl.hpp
@@ -76,11 +76,8 @@ public:
void Wait(Uint64 Value);
private:
- inline void UpdateLastCompletedFenceValue(uint64_t NewValue);
-
VulkanUtilities::VulkanFencePool m_FencePool;
std::deque<std::pair<Uint64, VulkanUtilities::FenceWrapper>> m_PendingFences;
- std::atomic_uint64_t m_LastCompletedFenceValue{0};
};
} // namespace Diligent
diff --git a/Graphics/GraphicsEngineVulkan/src/FenceVkImpl.cpp b/Graphics/GraphicsEngineVulkan/src/FenceVkImpl.cpp
index 9170516a..656e3333 100644
--- a/Graphics/GraphicsEngineVulkan/src/FenceVkImpl.cpp
+++ b/Graphics/GraphicsEngineVulkan/src/FenceVkImpl.cpp
@@ -64,15 +64,6 @@ FenceVkImpl::~FenceVkImpl()
}
}
-void FenceVkImpl::UpdateLastCompletedFenceValue(uint64_t NewValue)
-{
- auto LastCompletedValue = m_LastCompletedFenceValue.load();
- while (!m_LastCompletedFenceValue.compare_exchange_strong(LastCompletedValue, std::max(LastCompletedValue, NewValue)))
- {
- // If exchange fails, LastCompletedValue will hold the actual value of m_LastCompletedFenceValue.
- }
-}
-
Uint64 FenceVkImpl::GetCompletedValue()
{
const auto& LogicalDevice = m_pDevice->GetLogicalDevice();