From e08590880055ef1dc3e5bda68079598a8d1567e3 Mon Sep 17 00:00:00 2001 From: assiduous Date: Thu, 20 Aug 2020 13:23:53 -0700 Subject: D3D12 backend: added version support to GraphicsContext --- .../GraphicsEngineD3D12/include/CommandContext.hpp | 19 +++++++++++++++++-- Graphics/GraphicsEngineD3D12/src/CommandContext.cpp | 12 ++++++++++++ .../src/DeviceContextD3D12Impl.cpp | 6 +++--- 3 files changed, 32 insertions(+), 5 deletions(-) (limited to 'Graphics/GraphicsEngineD3D12') diff --git a/Graphics/GraphicsEngineD3D12/include/CommandContext.hpp b/Graphics/GraphicsEngineD3D12/include/CommandContext.hpp index 6fd7c63f..b2fe9bb1 100644 --- a/Graphics/GraphicsEngineD3D12/include/CommandContext.hpp +++ b/Graphics/GraphicsEngineD3D12/include/CommandContext.hpp @@ -80,8 +80,9 @@ public: ID3D12GraphicsCommandList* Close(CComPtr& pAllocator); void Reset(CommandListManager& CmdListManager); - class GraphicsContext& AsGraphicsContext(); - class ComputeContext& AsComputeContext(); + class GraphicsContext& AsGraphicsContext(); + class GraphicsContext4& AsGraphicsContext4(); + class ComputeContext& AsComputeContext(); void ClearUAVFloat(D3D12_GPU_DESCRIPTOR_HANDLE GpuHandle, D3D12_CPU_DESCRIPTOR_HANDLE CpuHandle, @@ -227,6 +228,10 @@ protected: String m_ID; D3D12_PRIMITIVE_TOPOLOGY m_PrimitiveTopology = D3D_PRIMITIVE_TOPOLOGY_UNDEFINED; + +#ifdef DILIGENT_DEBUG + Uint32 m_DbgMaxInterfaceVer = 0; +#endif }; @@ -344,7 +349,11 @@ public: FlushResourceBarriers(); m_pCommandList->DrawIndexedInstanced(IndexCountPerInstance, InstanceCount, StartIndexLocation, BaseVertexLocation, StartInstanceLocation); } +}; +class GraphicsContext4 : public GraphicsContext +{ +public: void BeginRenderPass(UINT NumRenderTargets, const D3D12_RENDER_PASS_RENDER_TARGET_DESC* pRenderTargets, const D3D12_RENDER_PASS_DEPTH_STENCIL_DESC* pDepthStencil, @@ -425,6 +434,12 @@ inline GraphicsContext& CommandContext::AsGraphicsContext() return static_cast(*this); } +inline GraphicsContext4& CommandContext::AsGraphicsContext4() +{ + VERIFY(m_DbgMaxInterfaceVer >= 4, "Maximum supported interface version is ", m_DbgMaxInterfaceVer); + return static_cast(*this); +} + inline ComputeContext& CommandContext::AsComputeContext() { return static_cast(*this); diff --git a/Graphics/GraphicsEngineD3D12/src/CommandContext.cpp b/Graphics/GraphicsEngineD3D12/src/CommandContext.cpp index dded6b29..da26de46 100644 --- a/Graphics/GraphicsEngineD3D12/src/CommandContext.cpp +++ b/Graphics/GraphicsEngineD3D12/src/CommandContext.cpp @@ -47,6 +47,18 @@ CommandContext::CommandContext(CommandListManager& CmdListManager) : { m_PendingResourceBarriers.reserve(MaxPendingBarriers); CmdListManager.CreateNewCommandList(&m_pCommandList, &m_pCurrentAllocator); +#ifdef DILIGENT_DEBUG + if (CComQIPtr(m_pCommandList)) + m_DbgMaxInterfaceVer = 5; + else if (CComQIPtr(m_pCommandList)) + m_DbgMaxInterfaceVer = 4; + else if (CComQIPtr(m_pCommandList)) + m_DbgMaxInterfaceVer = 3; + else if (CComQIPtr(m_pCommandList)) + m_DbgMaxInterfaceVer = 2; + else + m_DbgMaxInterfaceVer = 1; +#endif } CommandContext::~CommandContext(void) diff --git a/Graphics/GraphicsEngineD3D12/src/DeviceContextD3D12Impl.cpp b/Graphics/GraphicsEngineD3D12/src/DeviceContextD3D12Impl.cpp index 08b64857..355b90b0 100644 --- a/Graphics/GraphicsEngineD3D12/src/DeviceContextD3D12Impl.cpp +++ b/Graphics/GraphicsEngineD3D12/src/DeviceContextD3D12Impl.cpp @@ -1221,7 +1221,7 @@ void DeviceContextD3D12Impl::CommitSubpassRenderTargets() } auto& CmdCtx = GetCmdContext(); - CmdCtx.AsGraphicsContext().BeginRenderPass( + CmdCtx.AsGraphicsContext4().BeginRenderPass( Subpass.RenderTargetAttachmentCount, RenderPassRTs, m_pBoundDepthStencil ? &RenderPassDS : nullptr, @@ -1246,7 +1246,7 @@ void DeviceContextD3D12Impl::BeginRenderPass(const BeginRenderPassAttribs& Attri void DeviceContextD3D12Impl::NextSubpass() { auto& CmdCtx = GetCmdContext(); - CmdCtx.AsGraphicsContext().EndRenderPass(); + CmdCtx.AsGraphicsContext4().EndRenderPass(); TDeviceContextBase::NextSubpass(); TransitionSubpassAttachments(m_SubpassIndex); CommitSubpassRenderTargets(); @@ -1255,7 +1255,7 @@ void DeviceContextD3D12Impl::NextSubpass() void DeviceContextD3D12Impl::EndRenderPass() { auto& CmdCtx = GetCmdContext(); - CmdCtx.AsGraphicsContext().EndRenderPass(); + CmdCtx.AsGraphicsContext4().EndRenderPass(); TransitionSubpassAttachments(m_SubpassIndex + 1); TDeviceContextBase::EndRenderPass(); } -- cgit v1.2.3 From 97b6b497cb42acb1e8c2ef7b0eb6f1d78590dd30 Mon Sep 17 00:00:00 2001 From: assiduous Date: Thu, 20 Aug 2020 13:44:16 -0700 Subject: D3D12 backend: removed ID3D12GraphicsCommandList5 that is not support by CI --- Graphics/GraphicsEngineD3D12/src/CommandContext.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'Graphics/GraphicsEngineD3D12') diff --git a/Graphics/GraphicsEngineD3D12/src/CommandContext.cpp b/Graphics/GraphicsEngineD3D12/src/CommandContext.cpp index da26de46..82bb8db8 100644 --- a/Graphics/GraphicsEngineD3D12/src/CommandContext.cpp +++ b/Graphics/GraphicsEngineD3D12/src/CommandContext.cpp @@ -48,9 +48,7 @@ CommandContext::CommandContext(CommandListManager& CmdListManager) : m_PendingResourceBarriers.reserve(MaxPendingBarriers); CmdListManager.CreateNewCommandList(&m_pCommandList, &m_pCurrentAllocator); #ifdef DILIGENT_DEBUG - if (CComQIPtr(m_pCommandList)) - m_DbgMaxInterfaceVer = 5; - else if (CComQIPtr(m_pCommandList)) + if (CComQIPtr(m_pCommandList)) m_DbgMaxInterfaceVer = 4; else if (CComQIPtr(m_pCommandList)) m_DbgMaxInterfaceVer = 3; -- cgit v1.2.3 From 2360888747b7115cffd8b73edbf884a8e71f3084 Mon Sep 17 00:00:00 2001 From: assiduous Date: Thu, 20 Aug 2020 16:21:55 -0700 Subject: D3D12 backend: improved command list version detection --- .../GraphicsEngineD3D12/include/CommandContext.hpp | 42 +++++++++++++++++++--- .../include/CommandListManager.hpp | 3 +- .../GraphicsEngineD3D12/src/CommandContext.cpp | 12 +------ .../GraphicsEngineD3D12/src/CommandListManager.cpp | 24 +++++++++++-- 4 files changed, 62 insertions(+), 19 deletions(-) (limited to 'Graphics/GraphicsEngineD3D12') diff --git a/Graphics/GraphicsEngineD3D12/include/CommandContext.hpp b/Graphics/GraphicsEngineD3D12/include/CommandContext.hpp index b2fe9bb1..42efec8b 100644 --- a/Graphics/GraphicsEngineD3D12/include/CommandContext.hpp +++ b/Graphics/GraphicsEngineD3D12/include/CommandContext.hpp @@ -81,6 +81,9 @@ public: void Reset(CommandListManager& CmdListManager); class GraphicsContext& AsGraphicsContext(); + class GraphicsContext1& AsGraphicsContext1(); + class GraphicsContext2& AsGraphicsContext2(); + class GraphicsContext3& AsGraphicsContext3(); class GraphicsContext4& AsGraphicsContext4(); class ComputeContext& AsComputeContext(); @@ -229,9 +232,7 @@ protected: D3D12_PRIMITIVE_TOPOLOGY m_PrimitiveTopology = D3D_PRIMITIVE_TOPOLOGY_UNDEFINED; -#ifdef DILIGENT_DEBUG - Uint32 m_DbgMaxInterfaceVer = 0; -#endif + Uint32 m_MaxInterfaceVer = 0; }; @@ -351,7 +352,20 @@ public: } }; -class GraphicsContext4 : public GraphicsContext +class GraphicsContext1 : public GraphicsContext +{ +}; + +class GraphicsContext2 : public GraphicsContext1 +{ +}; + +class GraphicsContext3 : public GraphicsContext2 +{ +}; + + +class GraphicsContext4 : public GraphicsContext3 { public: void BeginRenderPass(UINT NumRenderTargets, @@ -434,9 +448,27 @@ inline GraphicsContext& CommandContext::AsGraphicsContext() return static_cast(*this); } +inline GraphicsContext1& CommandContext::AsGraphicsContext1() +{ + VERIFY(m_MaxInterfaceVer >= 1, "Maximum supported interface version is ", m_MaxInterfaceVer); + return static_cast(*this); +} + +inline GraphicsContext2& CommandContext::AsGraphicsContext2() +{ + VERIFY(m_MaxInterfaceVer >= 2, "Maximum supported interface version is ", m_MaxInterfaceVer); + return static_cast(*this); +} + +inline GraphicsContext3& CommandContext::AsGraphicsContext3() +{ + VERIFY(m_MaxInterfaceVer >= 3, "Maximum supported interface version is ", m_MaxInterfaceVer); + return static_cast(*this); +} + inline GraphicsContext4& CommandContext::AsGraphicsContext4() { - VERIFY(m_DbgMaxInterfaceVer >= 4, "Maximum supported interface version is ", m_DbgMaxInterfaceVer); + VERIFY(m_MaxInterfaceVer >= 4, "Maximum supported interface version is ", m_MaxInterfaceVer); return static_cast(*this); } diff --git a/Graphics/GraphicsEngineD3D12/include/CommandListManager.hpp b/Graphics/GraphicsEngineD3D12/include/CommandListManager.hpp index b9fe244c..e8a862e8 100644 --- a/Graphics/GraphicsEngineD3D12/include/CommandListManager.hpp +++ b/Graphics/GraphicsEngineD3D12/include/CommandListManager.hpp @@ -49,7 +49,8 @@ public: CommandListManager& operator = ( CommandListManager&&) = delete; // clang-format on - void CreateNewCommandList(ID3D12GraphicsCommandList** ppList, ID3D12CommandAllocator** ppAllocator); + // Returns the maximum supported interface version + void CreateNewCommandList(ID3D12GraphicsCommandList** ppList, ID3D12CommandAllocator** ppAllocator, Uint32& IfaceVersion); void RequestAllocator(ID3D12CommandAllocator** ppAllocator); void ReleaseAllocator(CComPtr&& Allocator, Uint32 CmdQueue, Uint64 FenceValue); diff --git a/Graphics/GraphicsEngineD3D12/src/CommandContext.cpp b/Graphics/GraphicsEngineD3D12/src/CommandContext.cpp index 82bb8db8..389bf3eb 100644 --- a/Graphics/GraphicsEngineD3D12/src/CommandContext.cpp +++ b/Graphics/GraphicsEngineD3D12/src/CommandContext.cpp @@ -46,17 +46,7 @@ CommandContext::CommandContext(CommandListManager& CmdListManager) : // clang-format on { m_PendingResourceBarriers.reserve(MaxPendingBarriers); - CmdListManager.CreateNewCommandList(&m_pCommandList, &m_pCurrentAllocator); -#ifdef DILIGENT_DEBUG - if (CComQIPtr(m_pCommandList)) - m_DbgMaxInterfaceVer = 4; - else if (CComQIPtr(m_pCommandList)) - m_DbgMaxInterfaceVer = 3; - else if (CComQIPtr(m_pCommandList)) - m_DbgMaxInterfaceVer = 2; - else - m_DbgMaxInterfaceVer = 1; -#endif + CmdListManager.CreateNewCommandList(&m_pCommandList, &m_pCurrentAllocator, m_MaxInterfaceVer); } CommandContext::~CommandContext(void) diff --git a/Graphics/GraphicsEngineD3D12/src/CommandListManager.cpp b/Graphics/GraphicsEngineD3D12/src/CommandListManager.cpp index c4d6e1b5..41e2a52b 100644 --- a/Graphics/GraphicsEngineD3D12/src/CommandListManager.cpp +++ b/Graphics/GraphicsEngineD3D12/src/CommandListManager.cpp @@ -46,11 +46,31 @@ CommandListManager::~CommandListManager() LOG_INFO_MESSAGE("Command list manager: created ", m_FreeAllocators.size(), " allocators"); } -void CommandListManager::CreateNewCommandList(ID3D12GraphicsCommandList** List, ID3D12CommandAllocator** Allocator) +void CommandListManager::CreateNewCommandList(ID3D12GraphicsCommandList** List, ID3D12CommandAllocator** Allocator, Uint32& IfaceVersion) { RequestAllocator(Allocator); auto* pd3d12Device = m_DeviceD3D12Impl.GetD3D12Device(); - auto hr = pd3d12Device->CreateCommandList(1, D3D12_COMMAND_LIST_TYPE_DIRECT, *Allocator, nullptr, __uuidof(ID3D12GraphicsCommandList4), reinterpret_cast(List)); + + const IID CmdListIIDs[] = + { + __uuidof(ID3D12GraphicsCommandList4), + __uuidof(ID3D12GraphicsCommandList3), + __uuidof(ID3D12GraphicsCommandList2), + __uuidof(ID3D12GraphicsCommandList1), + __uuidof(ID3D12GraphicsCommandList) // + }; + + HRESULT hr = E_FAIL; + for (Uint32 i = 0; i < _countof(CmdListIIDs); ++i) + { + hr = pd3d12Device->CreateCommandList(1, D3D12_COMMAND_LIST_TYPE_DIRECT, *Allocator, nullptr, CmdListIIDs[i], reinterpret_cast(List)); + if (SUCCEEDED(hr)) + { + IfaceVersion = _countof(CmdListIIDs) - 1 - i; + break; + } + } + VERIFY(SUCCEEDED(hr), "Failed to create command list"); (*List)->SetName(L"CommandList"); } -- cgit v1.2.3 From 2771c71fad9cc4311c287ad119d078662ef52c29 Mon Sep 17 00:00:00 2001 From: assiduous Date: Sat, 22 Aug 2020 20:26:49 -0700 Subject: Added USAGE_UNIFIED usage type (API 240066) --- .../GraphicsEngineD3D12/src/BufferD3D12Impl.cpp | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) (limited to 'Graphics/GraphicsEngineD3D12') diff --git a/Graphics/GraphicsEngineD3D12/src/BufferD3D12Impl.cpp b/Graphics/GraphicsEngineD3D12/src/BufferD3D12Impl.cpp index a6e4a0c8..77fb9bc2 100644 --- a/Graphics/GraphicsEngineD3D12/src/BufferD3D12Impl.cpp +++ b/Graphics/GraphicsEngineD3D12/src/BufferD3D12Impl.cpp @@ -61,13 +61,17 @@ BufferD3D12Impl::BufferD3D12Impl(IReferenceCounters* pRefCounters, ) // clang-format on { -#define LOG_BUFFER_ERROR_AND_THROW(...) LOG_ERROR_AND_THROW("Buffer \"", BuffDesc.Name ? BuffDesc.Name : "", "\": ", ##__VA_ARGS__) + ValidateBufferInitData(BuffDesc, pBuffData); - if (m_Desc.Usage == USAGE_STATIC && (pBuffData == nullptr || pBuffData->pData == nullptr)) - LOG_BUFFER_ERROR_AND_THROW("Static buffer must be initialized with data at creation time"); + if (m_Desc.Usage == USAGE_UNIFIED) + { + DecayUnifiedBuffer(); + } - if (m_Desc.Usage == USAGE_DYNAMIC && pBuffData != nullptr && pBuffData->pData != nullptr) - LOG_BUFFER_ERROR_AND_THROW("Dynamic buffer must be initialized via Map()"); + if (m_Desc.Usage == USAGE_STATIC) + VERIFY(pBuffData != nullptr && pBuffData->pData != nullptr, "Initial data must not be null for static buffers"); + if (m_Desc.Usage == USAGE_DYNAMIC) + VERIFY(pBuffData == nullptr || pBuffData->pData == nullptr, "Initial data must be null for dynamic buffers"); Uint32 AlignmentMask = 1; if (m_Desc.BindFlags & BIND_UNIFORM_BUFFER) @@ -75,13 +79,12 @@ BufferD3D12Impl::BufferD3D12Impl(IReferenceCounters* pRefCounters, if (m_Desc.Usage == USAGE_STAGING) { - if (m_Desc.CPUAccessFlags != CPU_ACCESS_WRITE && m_Desc.CPUAccessFlags != CPU_ACCESS_READ) - LOG_BUFFER_ERROR_AND_THROW("Exactly one of the CPU_ACCESS_WRITE or CPU_ACCESS_READ flags must be specified for a cpu-accessible buffer"); + VERIFY(m_Desc.CPUAccessFlags == CPU_ACCESS_WRITE || m_Desc.CPUAccessFlags == CPU_ACCESS_READ, + "Exactly one of the CPU_ACCESS_WRITE or CPU_ACCESS_READ flags must be specified for a staging buffer"); if (m_Desc.CPUAccessFlags == CPU_ACCESS_WRITE) { - if (pBuffData != nullptr && pBuffData->pData != nullptr) - LOG_BUFFER_ERROR_AND_THROW("CPU-writable staging buffers must be updated via map"); + VERIFY(pBuffData == nullptr || pBuffData->pData == nullptr, "CPU-writable staging buffers must be updated via map"); AlignmentMask = D3D12_TEXTURE_DATA_PITCH_ALIGNMENT - 1; } -- cgit v1.2.3