summaryrefslogtreecommitdiffstats
path: root/Graphics/GraphicsEngineD3D12
diff options
context:
space:
mode:
authorazhirnov <zh1dron@gmail.com>2020-08-25 01:07:40 +0000
committerazhirnov <zh1dron@gmail.com>2020-08-25 01:30:09 +0000
commit142c7880f92c3517a8897d2601336f6dba319c17 (patch)
tree55fd757db90d80fe2a72b54970e95764f181bbfb /Graphics/GraphicsEngineD3D12
parentUpdated description of DrawMeshIndirect command (diff)
parentFixed test crash in d3d11 mode on Intel GPU (diff)
downloadDiligentCore-142c7880f92c3517a8897d2601336f6dba319c17.tar.gz
DiligentCore-142c7880f92c3517a8897d2601336f6dba319c17.zip
Merge branch 'master' into mesh_shader
# Conflicts: # Graphics/GraphicsEngineD3D11/src/DeviceContextD3D11Impl.cpp # Graphics/GraphicsEngineD3D12/include/CommandContext.hpp # Graphics/GraphicsEngineVulkan/include/VulkanUtilities/VulkanPhysicalDevice.hpp
Diffstat (limited to 'Graphics/GraphicsEngineD3D12')
-rw-r--r--Graphics/GraphicsEngineD3D12/include/CommandContext.hpp83
-rw-r--r--Graphics/GraphicsEngineD3D12/include/CommandListManager.hpp3
-rw-r--r--Graphics/GraphicsEngineD3D12/src/BufferD3D12Impl.cpp21
-rw-r--r--Graphics/GraphicsEngineD3D12/src/CommandContext.cpp2
-rw-r--r--Graphics/GraphicsEngineD3D12/src/CommandListManager.cpp28
-rw-r--r--Graphics/GraphicsEngineD3D12/src/DeviceContextD3D12Impl.cpp8
6 files changed, 116 insertions, 29 deletions
diff --git a/Graphics/GraphicsEngineD3D12/include/CommandContext.hpp b/Graphics/GraphicsEngineD3D12/include/CommandContext.hpp
index 2f97b239..75c5dd3c 100644
--- a/Graphics/GraphicsEngineD3D12/include/CommandContext.hpp
+++ b/Graphics/GraphicsEngineD3D12/include/CommandContext.hpp
@@ -80,8 +80,14 @@ public:
ID3D12GraphicsCommandList* Close(CComPtr<ID3D12CommandAllocator>& pAllocator);
void Reset(CommandListManager& CmdListManager);
- class GraphicsContext& AsGraphicsContext();
- class ComputeContext& AsComputeContext();
+ class GraphicsContext& AsGraphicsContext();
+ class GraphicsContext1& AsGraphicsContext1();
+ class GraphicsContext2& AsGraphicsContext2();
+ class GraphicsContext3& AsGraphicsContext3();
+ class GraphicsContext4& AsGraphicsContext4();
+ class GraphicsContext5& AsGraphicsContext5();
+ class GraphicsContext6& AsGraphicsContext6();
+ class ComputeContext& AsComputeContext();
void ClearUAVFloat(D3D12_GPU_DESCRIPTOR_HANDLE GpuHandle,
D3D12_CPU_DESCRIPTOR_HANDLE CpuHandle,
@@ -228,9 +234,7 @@ protected:
D3D12_PRIMITIVE_TOPOLOGY m_PrimitiveTopology = D3D_PRIMITIVE_TOPOLOGY_UNDEFINED;
-#ifdef D12_H_HAS_MESH_SHADER
- CComPtr<ID3D12GraphicsCommandList6> m_pCommandList6;
-#endif
+ Uint32 m_MaxInterfaceVer = 0;
};
@@ -348,7 +352,24 @@ public:
FlushResourceBarriers();
m_pCommandList->DrawIndexedInstanced(IndexCountPerInstance, InstanceCount, StartIndexLocation, BaseVertexLocation, StartInstanceLocation);
}
+};
+
+class GraphicsContext1 : public GraphicsContext
+{
+};
+
+class GraphicsContext2 : public GraphicsContext1
+{
+};
+
+class GraphicsContext3 : public GraphicsContext2
+{
+};
+
+class GraphicsContext4 : public GraphicsContext3
+{
+public:
void BeginRenderPass(UINT NumRenderTargets,
const D3D12_RENDER_PASS_RENDER_TARGET_DESC* pRenderTargets,
const D3D12_RENDER_PASS_DEPTH_STENCIL_DESC* pDepthStencil,
@@ -362,19 +383,21 @@ public:
{
static_cast<ID3D12GraphicsCommandList4*>(m_pCommandList.p)->EndRenderPass();
}
+};
+class GraphicsContext5 : public GraphicsContext4
+{
+};
+
+class GraphicsContext6 : public GraphicsContext5
+{
+public:
void DrawMesh(UINT ThreadGroupCountX, UINT ThreadGroupCountY, UINT ThreadGroupCountZ)
{
#ifdef D12_H_HAS_MESH_SHADER
FlushResourceBarriers();
-
- if (!m_pCommandList6)
- {
- CHECK_D3D_RESULT_THROW(m_pCommandList->QueryInterface(IID_PPV_ARGS(&m_pCommandList6)),
- "Failed to get ID3D12GraphicsCommandList6, can't call DrawMesh()");
- }
-
m_pCommandList6->DispatchMesh(ThreadGroupCountX, ThreadGroupCountY, ThreadGroupCountZ);
+ static_cast<ID3D12GraphicsCommandList6*>(m_pCommandList.p)->DispatchMesh(ThreadGroupCountX, ThreadGroupCountY, ThreadGroupCountZ);
#else
UNSUPPORTED("DrawMesh is not supported in current D3D12 header");
#endif
@@ -446,6 +469,42 @@ 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_MaxInterfaceVer >= 4, "Maximum supported interface version is ", m_MaxInterfaceVer);
+ return static_cast<GraphicsContext4&>(*this);
+}
+
+inline GraphicsContext5& CommandContext::AsGraphicsContext5()
+{
+ VERIFY(m_MaxInterfaceVer >= 5, "Maximum supported interface version is ", m_MaxInterfaceVer);
+ return static_cast<GraphicsContext5&>(*this);
+}
+
+inline GraphicsContext6& CommandContext::AsGraphicsContext6()
+{
+ VERIFY(m_MaxInterfaceVer >= 6, "Maximum supported interface version is ", m_MaxInterfaceVer);
+ return static_cast<GraphicsContext6&>(*this);
+}
+
inline ComputeContext& CommandContext::AsComputeContext()
{
return static_cast<ComputeContext&>(*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/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;
}
diff --git a/Graphics/GraphicsEngineD3D12/src/CommandContext.cpp b/Graphics/GraphicsEngineD3D12/src/CommandContext.cpp
index dded6b29..389bf3eb 100644
--- a/Graphics/GraphicsEngineD3D12/src/CommandContext.cpp
+++ b/Graphics/GraphicsEngineD3D12/src/CommandContext.cpp
@@ -46,7 +46,7 @@ CommandContext::CommandContext(CommandListManager& CmdListManager) :
// clang-format on
{
m_PendingResourceBarriers.reserve(MaxPendingBarriers);
- CmdListManager.CreateNewCommandList(&m_pCommandList, &m_pCurrentAllocator);
+ 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..8d3238c6 100644
--- a/Graphics/GraphicsEngineD3D12/src/CommandListManager.cpp
+++ b/Graphics/GraphicsEngineD3D12/src/CommandListManager.cpp
@@ -46,11 +46,35 @@ 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[] =
+ {
+#ifdef D12_H_HAS_MESH_SHADER
+ __uuidof(ID3D12GraphicsCommandList6),
+ __uuidof(ID3D12GraphicsCommandList5),
+#endif
+ __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");
}
diff --git a/Graphics/GraphicsEngineD3D12/src/DeviceContextD3D12Impl.cpp b/Graphics/GraphicsEngineD3D12/src/DeviceContextD3D12Impl.cpp
index 19c02a0d..a644155d 100644
--- a/Graphics/GraphicsEngineD3D12/src/DeviceContextD3D12Impl.cpp
+++ b/Graphics/GraphicsEngineD3D12/src/DeviceContextD3D12Impl.cpp
@@ -564,7 +564,7 @@ void DeviceContextD3D12Impl::DrawMesh(const DrawMeshAttribs& Attribs)
if (!DvpVerifyDrawMeshArguments(Attribs))
return;
- auto& GraphCtx = GetCmdContext().AsGraphicsContext();
+ auto& GraphCtx = GetCmdContext().AsGraphicsContext6();
PrepareForDraw(GraphCtx, Attribs.Flags);
GraphCtx.DrawMesh(Attribs.ThreadGroupCount, 1, 1);
@@ -1259,7 +1259,7 @@ void DeviceContextD3D12Impl::CommitSubpassRenderTargets()
}
auto& CmdCtx = GetCmdContext();
- CmdCtx.AsGraphicsContext().BeginRenderPass(
+ CmdCtx.AsGraphicsContext4().BeginRenderPass(
Subpass.RenderTargetAttachmentCount,
RenderPassRTs,
m_pBoundDepthStencil ? &RenderPassDS : nullptr,
@@ -1284,7 +1284,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();
@@ -1293,7 +1293,7 @@ void DeviceContextD3D12Impl::NextSubpass()
void DeviceContextD3D12Impl::EndRenderPass()
{
auto& CmdCtx = GetCmdContext();
- CmdCtx.AsGraphicsContext().EndRenderPass();
+ CmdCtx.AsGraphicsContext4().EndRenderPass();
TransitionSubpassAttachments(m_SubpassIndex + 1);
TDeviceContextBase::EndRenderPass();
}