summaryrefslogtreecommitdiffstats
path: root/Graphics/GraphicsEngineD3D12
diff options
context:
space:
mode:
authorassiduous <assiduous@diligentgraphics.com>2020-08-20 23:21:55 +0000
committerassiduous <assiduous@diligentgraphics.com>2020-08-20 23:21:55 +0000
commit2360888747b7115cffd8b73edbf884a8e71f3084 (patch)
treef65ff5401ecf243daf892bb2fecc567e38d4d335 /Graphics/GraphicsEngineD3D12
parentGL backend: committing GL program or pipeline in SetPipelineState function (diff)
downloadDiligentCore-2360888747b7115cffd8b73edbf884a8e71f3084.tar.gz
DiligentCore-2360888747b7115cffd8b73edbf884a8e71f3084.zip
D3D12 backend: improved command list version detection
Diffstat (limited to 'Graphics/GraphicsEngineD3D12')
-rw-r--r--Graphics/GraphicsEngineD3D12/include/CommandContext.hpp42
-rw-r--r--Graphics/GraphicsEngineD3D12/include/CommandListManager.hpp3
-rw-r--r--Graphics/GraphicsEngineD3D12/src/CommandContext.cpp12
-rw-r--r--Graphics/GraphicsEngineD3D12/src/CommandListManager.cpp24
4 files changed, 62 insertions, 19 deletions
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<GraphicsContext&>(*this);
}
+inline GraphicsContext1& CommandContext::AsGraphicsContext1()
+{
+ VERIFY(m_MaxInterfaceVer >= 1, "Maximum supported interface version is ", m_MaxInterfaceVer);
+ return static_cast<GraphicsContext1&>(*this);
+}
+
+inline GraphicsContext2& CommandContext::AsGraphicsContext2()
+{
+ VERIFY(m_MaxInterfaceVer >= 2, "Maximum supported interface version is ", m_MaxInterfaceVer);
+ return static_cast<GraphicsContext2&>(*this);
+}
+
+inline GraphicsContext3& CommandContext::AsGraphicsContext3()
+{
+ VERIFY(m_MaxInterfaceVer >= 3, "Maximum supported interface version is ", m_MaxInterfaceVer);
+ return static_cast<GraphicsContext3&>(*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<GraphicsContext4&>(*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<ID3D12CommandAllocator>&& 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<ID3D12GraphicsCommandList4>(m_pCommandList))
- m_DbgMaxInterfaceVer = 4;
- else if (CComQIPtr<ID3D12GraphicsCommandList3>(m_pCommandList))
- m_DbgMaxInterfaceVer = 3;
- else if (CComQIPtr<ID3D12GraphicsCommandList2>(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<void**>(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<void**>(List));
+ if (SUCCEEDED(hr))
+ {
+ IfaceVersion = _countof(CmdListIIDs) - 1 - i;
+ break;
+ }
+ }
+
VERIFY(SUCCEEDED(hr), "Failed to create command list");
(*List)->SetName(L"CommandList");
}