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) --- .../include/DeviceContextD3D11Impl.h | 2 ++ .../GraphicsEngineD3D11/include/FenceD3D11Impl.h | 2 ++ .../src/DeviceContextD3D11Impl.cpp | 10 +++++++++- Graphics/GraphicsEngineD3D11/src/FenceD3D11Impl.cpp | 20 ++++++++++++++++++++ 4 files changed, 33 insertions(+), 1 deletion(-) (limited to 'Graphics/GraphicsEngineD3D11') diff --git a/Graphics/GraphicsEngineD3D11/include/DeviceContextD3D11Impl.h b/Graphics/GraphicsEngineD3D11/include/DeviceContextD3D11Impl.h index bc5c87a6..ef7124be 100755 --- a/Graphics/GraphicsEngineD3D11/include/DeviceContextD3D11Impl.h +++ b/Graphics/GraphicsEngineD3D11/include/DeviceContextD3D11Impl.h @@ -156,6 +156,8 @@ public: virtual void SignalFence(IFence* pFence, Uint64 Value)override final; + virtual void Wait(IFence* pFence, Uint64 Value)override final; + virtual ID3D11DeviceContext* GetD3D11DeviceContext()override final { return m_pd3d11DeviceContext; } void CommitRenderTargets(); diff --git a/Graphics/GraphicsEngineD3D11/include/FenceD3D11Impl.h b/Graphics/GraphicsEngineD3D11/include/FenceD3D11Impl.h index 9de594cf..bdfc5262 100644 --- a/Graphics/GraphicsEngineD3D11/include/FenceD3D11Impl.h +++ b/Graphics/GraphicsEngineD3D11/include/FenceD3D11Impl.h @@ -58,6 +58,8 @@ public: m_PendingQueries.emplace_back(std::move(pCtx), std::move(pQuery), Value); } + void Wait(Uint64 Value); + private: struct PendingFenceData { diff --git a/Graphics/GraphicsEngineD3D11/src/DeviceContextD3D11Impl.cpp b/Graphics/GraphicsEngineD3D11/src/DeviceContextD3D11Impl.cpp index dc6c3281..1ccdc2e2 100755 --- a/Graphics/GraphicsEngineD3D11/src/DeviceContextD3D11Impl.cpp +++ b/Graphics/GraphicsEngineD3D11/src/DeviceContextD3D11Impl.cpp @@ -1764,7 +1764,15 @@ namespace Diligent m_pd3d11DeviceContext->End(pd3d11Query); auto* pFenceD3D11Impl = ValidatedCast(pFence); pFenceD3D11Impl->AddPendingQuery(m_pd3d11DeviceContext, std::move(pd3d11Query), Value); - }; + } + + void DeviceContextD3D11Impl::Wait(IFence* pFence, Uint64 Value) + { + VERIFY(!m_bIsDeferred, "Fence can only be waited from immediate context"); + Flush(); + auto* pFenceD3D11Impl = ValidatedCast(pFence); + pFenceD3D11Impl->Wait(Value); + } void DeviceContextD3D11Impl::ClearStateCache() { diff --git a/Graphics/GraphicsEngineD3D11/src/FenceD3D11Impl.cpp b/Graphics/GraphicsEngineD3D11/src/FenceD3D11Impl.cpp index 73d32f51..e3bd2f4e 100644 --- a/Graphics/GraphicsEngineD3D11/src/FenceD3D11Impl.cpp +++ b/Graphics/GraphicsEngineD3D11/src/FenceD3D11Impl.cpp @@ -64,6 +64,26 @@ Uint64 FenceD3D11Impl :: GetCompletedValue() return m_LastCompletedFenceValue; } +void FenceD3D11Impl :: Wait(Uint64 Value) +{ + while (!m_PendingQueries.empty()) + { + auto& QueryData = m_PendingQueries.front(); + if (QueryData.Value > Value) + break; + + BOOL Data; + while (QueryData.pd3d11Ctx->GetData(QueryData.pd3d11Query, &Data, sizeof(Data), 0) != S_OK) + std::this_thread::yield(); + + VERIFY_EXPR(Data == TRUE); + if (QueryData.Value > m_LastCompletedFenceValue) + m_LastCompletedFenceValue = QueryData.Value; + + m_PendingQueries.pop_front(); + } +} + 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, ")"); -- cgit v1.2.3