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