From 0d267af8aebdc4a1cdc42d4b45d7dda7c725922c Mon Sep 17 00:00:00 2001 From: assiduous Date: Fri, 19 Feb 2021 22:25:28 -0800 Subject: Reworked PipelineResourceSignatureD3D12Impl::CommitRootViews --- .../include/ShaderResourceCacheD3D12.hpp | 2 + .../src/PipelineResourceSignatureD3D12Impl.cpp | 79 ++++++++++++++-------- 2 files changed, 54 insertions(+), 27 deletions(-) (limited to 'Graphics/GraphicsEngineD3D12') 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 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()) - { - 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(); } else if (Res.Type == SHADER_RESOURCE_TYPE_BUFFER_SRV || Res.Type == SHADER_RESOURCE_TYPE_BUFFER_UAV) { - if (auto* pBuffView = Res.pObject.RawPtr()) - { - auto* pBuffer = pBuffView->GetBuffer(); - 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(); + pBuffer = pBuffView->GetBuffer(); } 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"); + } } } -- cgit v1.2.3