summaryrefslogtreecommitdiffstats
path: root/Graphics/GraphicsEngineD3D12
diff options
context:
space:
mode:
authorassiduous <assiduous@diligentgraphics.com>2021-02-20 06:25:28 +0000
committerassiduous <assiduous@diligentgraphics.com>2021-03-19 00:38:09 +0000
commit0d267af8aebdc4a1cdc42d4b45d7dda7c725922c (patch)
treebe2966651b468bd245da2da05daba3f2305c8d45 /Graphics/GraphicsEngineD3D12
parentD3D12 backend: moved resource state transition logic from PipelineResourceSig... (diff)
downloadDiligentCore-0d267af8aebdc4a1cdc42d4b45d7dda7c725922c.tar.gz
DiligentCore-0d267af8aebdc4a1cdc42d4b45d7dda7c725922c.zip
Reworked PipelineResourceSignatureD3D12Impl::CommitRootViews
Diffstat (limited to 'Graphics/GraphicsEngineD3D12')
-rw-r--r--Graphics/GraphicsEngineD3D12/include/ShaderResourceCacheD3D12.hpp2
-rw-r--r--Graphics/GraphicsEngineD3D12/src/PipelineResourceSignatureD3D12Impl.cpp79
2 files changed, 54 insertions, 27 deletions
diff --git a/Graphics/GraphicsEngineD3D12/include/ShaderResourceCacheD3D12.hpp b/Graphics/GraphicsEngineD3D12/include/ShaderResourceCacheD3D12.hpp
index 2daa4183..045c67d7 100644
--- a/Graphics/GraphicsEngineD3D12/include/ShaderResourceCacheD3D12.hpp
+++ b/Graphics/GraphicsEngineD3D12/include/ShaderResourceCacheD3D12.hpp
@@ -133,6 +133,8 @@ public:
D3D12_CPU_DESCRIPTOR_HANDLE CPUDescriptorHandle = {0};
RefCntAutoPtr<IDeviceObject> pObject;
+ bool IsNull() const { return pObject == nullptr; }
+
__forceinline void TransitionResource(CommandContext& Ctx);
#ifdef DILIGENT_DEVELOPMENT
void DvpVerifyResourceState();
diff --git a/Graphics/GraphicsEngineD3D12/src/PipelineResourceSignatureD3D12Impl.cpp b/Graphics/GraphicsEngineD3D12/src/PipelineResourceSignatureD3D12Impl.cpp
index 6d38ceaf..a2ee2981 100644
--- a/Graphics/GraphicsEngineD3D12/src/PipelineResourceSignatureD3D12Impl.cpp
+++ b/Graphics/GraphicsEngineD3D12/src/PipelineResourceSignatureD3D12Impl.cpp
@@ -718,46 +718,71 @@ void PipelineResourceSignatureD3D12Impl::CommitRootViews(ShaderResourceCacheD3D1
{
for (Uint32 rv = 0; rv < m_RootParams.GetNumRootViews(); ++rv)
{
- auto& RootView = m_RootParams.GetRootView(rv);
- auto RootInd = RootView.RootIndex;
+ const auto& RootView = m_RootParams.GetRootView(rv);
+ const auto RootInd = RootView.RootIndex;
auto& Res = ResourceCache.GetRootTable(RootInd).GetResource(0, D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV);
+ if (Res.IsNull())
+ {
+ LOG_ERROR_MESSAGE("Failed to bind root view at index ", BaseRootIndex + RootInd, ": no resource is bound in the cache.");
+ continue;
+ }
+
+ BufferD3D12Impl* pBuffer = nullptr;
if (Res.Type == SHADER_RESOURCE_TYPE_CONSTANT_BUFFER)
{
- if (auto* pBuff = Res.pObject.RawPtr<BufferD3D12Impl>())
- {
- bool IsDynamic = pBuff->GetDesc().Usage == USAGE_DYNAMIC;
- if (IsDynamic == CommitDynamicBuffers)
- {
- auto CBVAddress = pBuff->GetGPUAddress(DeviceCtxId, pDeviceCtx);
- if (IsCompute)
- CmdCtx.GetCommandList()->SetComputeRootConstantBufferView(BaseRootIndex + RootInd, CBVAddress);
- else
- CmdCtx.GetCommandList()->SetGraphicsRootConstantBufferView(BaseRootIndex + RootInd, CBVAddress);
- }
- }
+ // No need to QueryInterface() - the type is verified when a resource is bound
+ pBuffer = Res.pObject.RawPtr<BufferD3D12Impl>();
}
else if (Res.Type == SHADER_RESOURCE_TYPE_BUFFER_SRV ||
Res.Type == SHADER_RESOURCE_TYPE_BUFFER_UAV)
{
- if (auto* pBuffView = Res.pObject.RawPtr<BufferViewD3D12Impl>())
- {
- auto* pBuffer = pBuffView->GetBuffer<BufferD3D12Impl>();
- bool IsDynamic = pBuffer->GetDesc().Usage == USAGE_DYNAMIC;
- if (IsDynamic == CommitDynamicBuffers)
- {
- auto SRVAddress = pBuffer->GetGPUAddress(DeviceCtxId, pDeviceCtx);
- if (IsCompute)
- CmdCtx.GetCommandList()->SetComputeRootShaderResourceView(BaseRootIndex + RootInd, SRVAddress);
- else
- CmdCtx.GetCommandList()->SetGraphicsRootShaderResourceView(BaseRootIndex + RootInd, SRVAddress);
- }
- }
+ auto* pBuffView = Res.pObject.RawPtr<BufferViewD3D12Impl>();
+ pBuffer = pBuffView->GetBuffer<BufferD3D12Impl>();
}
else
{
UNEXPECTED("Unexpected root view resource type");
}
+ VERIFY_EXPR(pBuffer != nullptr);
+
+ auto IsDynamic = pBuffer->GetDesc().Usage == USAGE_DYNAMIC;
+ if (IsDynamic != CommitDynamicBuffers)
+ continue;
+
+ auto BufferGPUAddress = pBuffer->GetGPUAddress(DeviceCtxId, pDeviceCtx);
+ VERIFY_EXPR(BufferGPUAddress != 0);
+
+ auto* pd3d12CmdList = CmdCtx.GetCommandList();
+ switch (Res.Type)
+ {
+ case SHADER_RESOURCE_TYPE_CONSTANT_BUFFER:
+ VERIFY_EXPR(RootView.GetParameterType() == D3D12_ROOT_PARAMETER_TYPE_CBV);
+ if (IsCompute)
+ pd3d12CmdList->SetComputeRootConstantBufferView(BaseRootIndex + RootInd, BufferGPUAddress);
+ else
+ pd3d12CmdList->SetGraphicsRootConstantBufferView(BaseRootIndex + RootInd, BufferGPUAddress);
+ break;
+
+ case SHADER_RESOURCE_TYPE_BUFFER_SRV:
+ VERIFY_EXPR(RootView.GetParameterType() == D3D12_ROOT_PARAMETER_TYPE_SRV);
+ if (IsCompute)
+ pd3d12CmdList->SetComputeRootShaderResourceView(BaseRootIndex + RootInd, BufferGPUAddress);
+ else
+ pd3d12CmdList->SetGraphicsRootShaderResourceView(BaseRootIndex + RootInd, BufferGPUAddress);
+ break;
+
+ case SHADER_RESOURCE_TYPE_BUFFER_UAV:
+ VERIFY_EXPR(RootView.GetParameterType() == D3D12_ROOT_PARAMETER_TYPE_UAV);
+ if (IsCompute)
+ pd3d12CmdList->SetComputeRootUnorderedAccessView(BaseRootIndex + RootInd, BufferGPUAddress);
+ else
+ pd3d12CmdList->SetGraphicsRootUnorderedAccessView(BaseRootIndex + RootInd, BufferGPUAddress);
+ break;
+
+ default:
+ UNEXPECTED("Unexpected root view resource type");
+ }
}
}