From 01108131af397a32dbcb94f77b8a4c1f564bd474 Mon Sep 17 00:00:00 2001 From: Egor Yusov Date: Sun, 8 Sep 2019 16:09:11 -0700 Subject: D3D12 backend: fixed issue with fences not being signaled if there is no command list when flushing the context --- .../include/RenderDeviceD3D12Impl.h | 2 ++ .../src/DeviceContextD3D12Impl.cpp | 7 +++++++ .../GraphicsEngineD3D12/src/RenderDeviceD3D12Impl.cpp | 19 +++++++++++-------- 3 files changed, 20 insertions(+), 8 deletions(-) (limited to 'Graphics/GraphicsEngineD3D12') diff --git a/Graphics/GraphicsEngineD3D12/include/RenderDeviceD3D12Impl.h b/Graphics/GraphicsEngineD3D12/include/RenderDeviceD3D12Impl.h index 9a70e68d..b447fdc5 100644 --- a/Graphics/GraphicsEngineD3D12/include/RenderDeviceD3D12Impl.h +++ b/Graphics/GraphicsEngineD3D12/include/RenderDeviceD3D12Impl.h @@ -85,6 +85,8 @@ public: PooledCommandContext AllocateCommandContext(const Char* ID = ""); void CloseAndExecuteTransientCommandContext(Uint32 CommandQueueIndex, PooledCommandContext&& Ctx); Uint64 CloseAndExecuteCommandContext(Uint32 QueueIndex, PooledCommandContext&& Ctx, bool DiscardStaleObjects, std::vector > >* pSignalFences); + + void SignalFences(Uint32 QueueIndex, std::vector > >& SignalFences); void WaitForFence(Uint32 QueueIndex, IFence* pFence, Uint64 Value); diff --git a/Graphics/GraphicsEngineD3D12/src/DeviceContextD3D12Impl.cpp b/Graphics/GraphicsEngineD3D12/src/DeviceContextD3D12Impl.cpp index 7daa6437..1a654109 100644 --- a/Graphics/GraphicsEngineD3D12/src/DeviceContextD3D12Impl.cpp +++ b/Graphics/GraphicsEngineD3D12/src/DeviceContextD3D12Impl.cpp @@ -594,6 +594,13 @@ namespace Diligent pDeviceD3D12Impl->DisposeCommandContext(std::move(m_CurrCmdCtx)); } + // If there is no command list to submit, but there are pending fences, we need to signal them now + if (!m_PendingFences.empty()) + { + pDeviceD3D12Impl->SignalFences(m_CommandQueueId, m_PendingFences); + m_PendingFences.clear(); + } + if(RequestNewCmdCtx) RequestCommandContext(pDeviceD3D12Impl); diff --git a/Graphics/GraphicsEngineD3D12/src/RenderDeviceD3D12Impl.cpp b/Graphics/GraphicsEngineD3D12/src/RenderDeviceD3D12Impl.cpp index 0b04c709..8ad14c16 100644 --- a/Graphics/GraphicsEngineD3D12/src/RenderDeviceD3D12Impl.cpp +++ b/Graphics/GraphicsEngineD3D12/src/RenderDeviceD3D12Impl.cpp @@ -179,14 +179,7 @@ Uint64 RenderDeviceD3D12Impl::CloseAndExecuteCommandContext(Uint32 QueueIndex, P auto SubmittedCmdBuffInfo = TRenderDeviceBase::SubmitCommandBuffer(QueueIndex, pCmdList, true); FenceValue = SubmittedCmdBuffInfo.FenceValue; if (pSignalFences != nullptr) - { - for (auto& val_fence : *pSignalFences) - { - auto* pFenceD3D12Impl = val_fence.second.RawPtr(); - auto* pd3d12Fence = pFenceD3D12Impl->GetD3D12Fence(); - m_CommandQueues[QueueIndex].CmdQueue->SignalFence(pd3d12Fence, val_fence.first); - } - } + SignalFences(QueueIndex, *pSignalFences); } m_CmdListManager.ReleaseAllocator(std::move(pAllocator), QueueIndex, FenceValue); @@ -197,6 +190,16 @@ Uint64 RenderDeviceD3D12Impl::CloseAndExecuteCommandContext(Uint32 QueueIndex, P return FenceValue; } +void RenderDeviceD3D12Impl::SignalFences(Uint32 QueueIndex, std::vector > >& SignalFences) +{ + for (auto& val_fence : SignalFences) + { + auto* pFenceD3D12Impl = val_fence.second.RawPtr(); + auto* pd3d12Fence = pFenceD3D12Impl->GetD3D12Fence(); + m_CommandQueues[QueueIndex].CmdQueue->SignalFence(pd3d12Fence, val_fence.first); + } +} + void RenderDeviceD3D12Impl::WaitForFence(Uint32 QueueIndex, IFence* pFence, Uint64 Value) { VERIFY_EXPR(QueueIndex < m_CmdQueueCount); -- cgit v1.2.3