diff options
| author | Egor Yusov <egor.yusov@gmail.com> | 2018-07-22 02:46:57 +0000 |
|---|---|---|
| committer | Egor Yusov <egor.yusov@gmail.com> | 2018-07-22 02:46:57 +0000 |
| commit | 2dfbbae491090f3b0f0e622791515c59f3948ee0 (patch) | |
| tree | 898621085fe8253e7e52dc81ff03904931dcb36f /Graphics/GraphicsEngineD3D12 | |
| parent | Disabled D3D11 fence for now to fix build (diff) | |
| download | DiligentCore-2dfbbae491090f3b0f0e622791515c59f3948ee0.tar.gz DiligentCore-2dfbbae491090f3b0f0e622791515c59f3948ee0.zip | |
Implemented IFence interface in all backends
Diffstat (limited to 'Graphics/GraphicsEngineD3D12')
11 files changed, 46 insertions, 11 deletions
diff --git a/Graphics/GraphicsEngineD3D12/include/CommandQueueD3D12Impl.h b/Graphics/GraphicsEngineD3D12/include/CommandQueueD3D12Impl.h index 071ddde5..0db94e2b 100644 --- a/Graphics/GraphicsEngineD3D12/include/CommandQueueD3D12Impl.h +++ b/Graphics/GraphicsEngineD3D12/include/CommandQueueD3D12Impl.h @@ -55,6 +55,8 @@ public: virtual Uint64 GetCompletedFenceValue()override final; + void SignalFence(ID3D12Fence* pFence, Uint64 Value)override final; + private: // A value that will be signaled by the command queue next Atomics::AtomicInt64 m_NextFenceValue; diff --git a/Graphics/GraphicsEngineD3D12/include/DeviceContextD3D12Impl.h b/Graphics/GraphicsEngineD3D12/include/DeviceContextD3D12Impl.h index bf072f78..785c6f32 100644 --- a/Graphics/GraphicsEngineD3D12/include/DeviceContextD3D12Impl.h +++ b/Graphics/GraphicsEngineD3D12/include/DeviceContextD3D12Impl.h @@ -88,6 +88,8 @@ public: virtual void ExecuteCommandList(class ICommandList *pCommandList)override final; + virtual void SignalFence(IFence* pFence, Uint64 Value)override final; + virtual void TransitionTextureState(ITexture *pTexture, D3D12_RESOURCE_STATES State)override final; virtual void TransitionBufferState(IBuffer *pBuffer, D3D12_RESOURCE_STATES State)override final; @@ -157,6 +159,8 @@ private: FixedBlockMemoryAllocator m_CmdListAllocator; const Uint32 m_ContextId; + + std::vector<std::pair<Uint64, RefCntAutoPtr<IFence> > > m_PendingFences; }; } diff --git a/Graphics/GraphicsEngineD3D12/include/FenceD3D12Impl.h b/Graphics/GraphicsEngineD3D12/include/FenceD3D12Impl.h index 7412aeb0..636557a9 100644 --- a/Graphics/GraphicsEngineD3D12/include/FenceD3D12Impl.h +++ b/Graphics/GraphicsEngineD3D12/include/FenceD3D12Impl.h @@ -51,10 +51,10 @@ public: /// Resets the fence to the specified value. virtual void Reset(Uint64 Value)override final; - ID3D12Fence* GetD3D12Fence()override final{ return m_pD3D12Fence; } + ID3D12Fence* GetD3D12Fence()override final{ return m_pd3d12Fence; } private: - CComPtr<ID3D12Fence> m_pD3D12Fence; ///< D3D12 Fence object + CComPtr<ID3D12Fence> m_pd3d12Fence; ///< D3D12 Fence object }; } diff --git a/Graphics/GraphicsEngineD3D12/include/RenderDeviceD3D12Impl.h b/Graphics/GraphicsEngineD3D12/include/RenderDeviceD3D12Impl.h index 036cf0b9..34b8f864 100644 --- a/Graphics/GraphicsEngineD3D12/include/RenderDeviceD3D12Impl.h +++ b/Graphics/GraphicsEngineD3D12/include/RenderDeviceD3D12Impl.h @@ -92,7 +92,7 @@ public: void IdleGPU(bool ReleaseStaleObjects); CommandContext* AllocateCommandContext(const Char *ID = ""); - void CloseAndExecuteCommandContext(CommandContext *pCtx, bool DiscardStaleObjects); + void CloseAndExecuteCommandContext(CommandContext *pCtx, bool DiscardStaleObjects, std::vector<std::pair<Uint64, RefCntAutoPtr<IFence> > >* pSignalFences); void DisposeCommandContext(CommandContext*); void SafeReleaseD3D12Object(ID3D12Object* pObj); diff --git a/Graphics/GraphicsEngineD3D12/interface/CommandQueueD3D12.h b/Graphics/GraphicsEngineD3D12/interface/CommandQueueD3D12.h index 071b0109..62aaf3b3 100644 --- a/Graphics/GraphicsEngineD3D12/interface/CommandQueueD3D12.h +++ b/Graphics/GraphicsEngineD3D12/interface/CommandQueueD3D12.h @@ -53,6 +53,9 @@ public: /// Blocks execution until all pending GPU commands are complete virtual void IdleGPU() = 0; + + /// Signals the given fence + virtual void SignalFence(ID3D12Fence* pFence, Uint64 Value) = 0; }; } diff --git a/Graphics/GraphicsEngineD3D12/src/BufferD3D12Impl.cpp b/Graphics/GraphicsEngineD3D12/src/BufferD3D12Impl.cpp index 4a5df652..07438730 100644 --- a/Graphics/GraphicsEngineD3D12/src/BufferD3D12Impl.cpp +++ b/Graphics/GraphicsEngineD3D12/src/BufferD3D12Impl.cpp @@ -201,7 +201,7 @@ BufferD3D12Impl :: BufferD3D12Impl(IReferenceCounters* pRefCounters, // | N+1, but resource it references | | // | was added to the delete queue | | // | with value N | | - pRenderDeviceD3D12->CloseAndExecuteCommandContext(pInitContext, false); + pRenderDeviceD3D12->CloseAndExecuteCommandContext(pInitContext, false, nullptr); // Add reference to the object to the release queue to keep it alive // until copy operation is complete. This must be done after diff --git a/Graphics/GraphicsEngineD3D12/src/CommandQueueD3D12Impl.cpp b/Graphics/GraphicsEngineD3D12/src/CommandQueueD3D12Impl.cpp index 89e70d37..ca474933 100644 --- a/Graphics/GraphicsEngineD3D12/src/CommandQueueD3D12Impl.cpp +++ b/Graphics/GraphicsEngineD3D12/src/CommandQueueD3D12Impl.cpp @@ -80,4 +80,9 @@ Uint64 CommandQueueD3D12Impl::GetCompletedFenceValue() return m_LastCompletedFenceValue; } +void CommandQueueD3D12Impl::SignalFence(ID3D12Fence* pFence, Uint64 Value) +{ + m_pd3d12CmdQueue->Signal(pFence, Value); +} + } diff --git a/Graphics/GraphicsEngineD3D12/src/DeviceContextD3D12Impl.cpp b/Graphics/GraphicsEngineD3D12/src/DeviceContextD3D12Impl.cpp index d11dd975..b07c6067 100644 --- a/Graphics/GraphicsEngineD3D12/src/DeviceContextD3D12Impl.cpp +++ b/Graphics/GraphicsEngineD3D12/src/DeviceContextD3D12Impl.cpp @@ -29,6 +29,7 @@ #include "CommandContext.h" #include "TextureD3D12Impl.h" #include "BufferD3D12Impl.h" +#include "FenceD3D12Impl.h" #include "D3D12TypeConversions.h" #include "d3dx12_win.h" #include "DynamicUploadHeap.h" @@ -513,7 +514,8 @@ namespace Diligent if (m_NumCommandsInCurCtx != 0) { m_pCurrCmdCtx->FlushResourceBarriers(); - pDeviceD3D12Impl->CloseAndExecuteCommandContext(m_pCurrCmdCtx, true); + pDeviceD3D12Impl->CloseAndExecuteCommandContext(m_pCurrCmdCtx, true, &m_PendingFences); + m_PendingFences.clear(); } else pDeviceD3D12Impl->DisposeCommandContext(m_pCurrCmdCtx); @@ -863,9 +865,16 @@ namespace Diligent InvalidateState(); CommandListD3D12Impl* pCmdListD3D12 = ValidatedCast<CommandListD3D12Impl>(pCommandList); - m_pDevice.RawPtr<RenderDeviceD3D12Impl>()->CloseAndExecuteCommandContext(pCmdListD3D12->Close(), true); + VERIFY_EXPR(m_PendingFences.empty()); + m_pDevice.RawPtr<RenderDeviceD3D12Impl>()->CloseAndExecuteCommandContext(pCmdListD3D12->Close(), true, nullptr); } + void DeviceContextD3D12Impl::SignalFence(IFence* pFence, Uint64 Value) + { + VERIFY(!m_bIsDeferred, "Fence can only be signalled from immediate context"); + m_PendingFences.emplace_back(Value, pFence); + }; + void DeviceContextD3D12Impl::TransitionTextureState(ITexture *pTexture, D3D12_RESOURCE_STATES State) { VERIFY_EXPR(pTexture != nullptr); diff --git a/Graphics/GraphicsEngineD3D12/src/FenceD3D12Impl.cpp b/Graphics/GraphicsEngineD3D12/src/FenceD3D12Impl.cpp index 92939fea..7577c9c4 100644 --- a/Graphics/GraphicsEngineD3D12/src/FenceD3D12Impl.cpp +++ b/Graphics/GraphicsEngineD3D12/src/FenceD3D12Impl.cpp @@ -26,7 +26,7 @@ #include "FenceD3D12Impl.h" #include "EngineMemory.h" - +#include "RenderDeviceD3D12Impl.h" namespace Diligent { @@ -35,6 +35,9 @@ FenceD3D12Impl :: FenceD3D12Impl(IReferenceCounters* pRefCounters, const FenceDesc& Desc) : TFenceBase(pRefCounters, pDevice, Desc) { + auto* pd3d12Device = ValidatedCast<RenderDeviceD3D12Impl>(pDevice)->GetD3D12Device(); + auto hr = pd3d12Device->CreateFence(0, D3D12_FENCE_FLAG_NONE, __uuidof(m_pd3d12Fence), reinterpret_cast<void**>(static_cast<ID3D12Fence**>(&m_pd3d12Fence))); + CHECK_D3D_RESULT_THROW(hr, "Failed to create D3D12 fence"); } FenceD3D12Impl :: ~FenceD3D12Impl() @@ -43,12 +46,12 @@ FenceD3D12Impl :: ~FenceD3D12Impl() Uint64 FenceD3D12Impl :: GetCompletedValue() { - return m_pD3D12Fence->GetCompletedValue(); + return m_pd3d12Fence->GetCompletedValue(); } void FenceD3D12Impl :: Reset(Uint64 Value) { - m_pD3D12Fence->Signal(Value); + m_pd3d12Fence->Signal(Value); } } diff --git a/Graphics/GraphicsEngineD3D12/src/RenderDeviceD3D12Impl.cpp b/Graphics/GraphicsEngineD3D12/src/RenderDeviceD3D12Impl.cpp index ea744aff..a7a4fdce 100644 --- a/Graphics/GraphicsEngineD3D12/src/RenderDeviceD3D12Impl.cpp +++ b/Graphics/GraphicsEngineD3D12/src/RenderDeviceD3D12Impl.cpp @@ -114,7 +114,7 @@ void RenderDeviceD3D12Impl::DisposeCommandContext(CommandContext* pCtx) m_AvailableContexts.push_back(pCtx); } -void RenderDeviceD3D12Impl::CloseAndExecuteCommandContext(CommandContext* pCtx, bool DiscardStaleObjects) +void RenderDeviceD3D12Impl::CloseAndExecuteCommandContext(CommandContext* pCtx, bool DiscardStaleObjects, std::vector<std::pair<Uint64, RefCntAutoPtr<IFence> > >* pSignalFences) { CComPtr<ID3D12CommandAllocator> pAllocator; auto *pCmdList = pCtx->Close(&pAllocator); @@ -130,6 +130,15 @@ void RenderDeviceD3D12Impl::CloseAndExecuteCommandContext(CommandContext* pCtx, FenceValue = std::max(FenceValue, NextFenceValue); CmdListNumber = m_NextCmdListNumber; Atomics::AtomicIncrement(m_NextCmdListNumber); + if (pSignalFences != nullptr) + { + for (auto& val_fence : *pSignalFences) + { + auto* pFenceD3D12Impl = val_fence.second.RawPtr<FenceD3D12Impl>(); + auto* pd3d12Fence = pFenceD3D12Impl->GetD3D12Fence(); + m_pCommandQueue->SignalFence(pd3d12Fence, val_fence.first); + } + } } if (DiscardStaleObjects) diff --git a/Graphics/GraphicsEngineD3D12/src/TextureD3D12Impl.cpp b/Graphics/GraphicsEngineD3D12/src/TextureD3D12Impl.cpp index f9b0ce49..bf01b26c 100644 --- a/Graphics/GraphicsEngineD3D12/src/TextureD3D12Impl.cpp +++ b/Graphics/GraphicsEngineD3D12/src/TextureD3D12Impl.cpp @@ -218,7 +218,7 @@ TextureD3D12Impl :: TextureD3D12Impl(IReferenceCounters* pRefCounters, // | N+1, but resource it references | | // | was added to the delete queue | | // | with value N | | - pRenderDeviceD3D12->CloseAndExecuteCommandContext(pInitContext, false); + pRenderDeviceD3D12->CloseAndExecuteCommandContext(pInitContext, false, nullptr); // We MUST NOT call TransitionResource() from here, because // it will call AddRef() and potentially Release(), while |
