diff options
| author | assiduous <assiduous@diligentgraphics.com> | 2021-02-23 04:27:10 +0000 |
|---|---|---|
| committer | assiduous <assiduous@diligentgraphics.com> | 2021-03-19 00:38:10 +0000 |
| commit | bb3588e228a480272dfddc14cdd0efebdfa54c24 (patch) | |
| tree | a4ad9b9450b3cc64df41760863681c47e9c5a277 /Graphics/GraphicsEngineD3D12 | |
| parent | Implemented committed resource validation in d3d12 (diff) | |
| download | DiligentCore-bb3588e228a480272dfddc14cdd0efebdfa54c24.tar.gz DiligentCore-bb3588e228a480272dfddc14cdd0efebdfa54c24.zip | |
Few updates to DeviceContextD3D12Impl
Diffstat (limited to 'Graphics/GraphicsEngineD3D12')
5 files changed, 77 insertions, 89 deletions
diff --git a/Graphics/GraphicsEngineD3D12/include/DeviceContextD3D12Impl.hpp b/Graphics/GraphicsEngineD3D12/include/DeviceContextD3D12Impl.hpp index c8fabce5..67092a1d 100644 --- a/Graphics/GraphicsEngineD3D12/include/DeviceContextD3D12Impl.hpp +++ b/Graphics/GraphicsEngineD3D12/include/DeviceContextD3D12Impl.hpp @@ -399,11 +399,6 @@ private: std::array<class ShaderResourceBindingD3D12Impl*, MAX_RESOURCE_SIGNATURES> SRBs{}; - RootTableInfo() - { - memset(this, 0, sizeof(*this)); - } - __forceinline bool RequireUpdate(bool DynamicBuffersIntact = false) const { return !bRootViewsCommitted || !bRootTablesCommited || ((DynamicBuffersMask & ActiveSRBMask) != 0 && !DynamicBuffersIntact); @@ -415,7 +410,8 @@ private: __forceinline RootTableInfo& GetRootTableInfo(PIPELINE_TYPE PipelineType); template <bool IsCompute> - __forceinline void CommitRootTables(RootTableInfo& RootInfo); + __forceinline void CommitRootTablesAndViews(RootTableInfo& RootInfo); + #ifdef DILIGENT_DEVELOPMENT void DvpValidateCommittedShaderResources(); #endif diff --git a/Graphics/GraphicsEngineD3D12/include/ShaderResourceCacheD3D12.hpp b/Graphics/GraphicsEngineD3D12/include/ShaderResourceCacheD3D12.hpp index c092f481..6a5f1712 100644 --- a/Graphics/GraphicsEngineD3D12/include/ShaderResourceCacheD3D12.hpp +++ b/Graphics/GraphicsEngineD3D12/include/ShaderResourceCacheD3D12.hpp @@ -239,9 +239,12 @@ public: return m_DescriptorAllocations[AllocationIdx]; } - void TransitionResources(CommandContext& Ctx, - bool PerformTransitions, - bool ValidateStates); + enum class StateTransitionMode + { + Transition, + Verify + }; + void TransitionResourceStates(CommandContext& Ctx, StateTransitionMode Mode); Uint32& GetDynamicRootBuffersCounter() { return m_NumDynamicRootBuffers; } diff --git a/Graphics/GraphicsEngineD3D12/src/DeviceContextD3D12Impl.cpp b/Graphics/GraphicsEngineD3D12/src/DeviceContextD3D12Impl.cpp index 495a13d2..fb3ea4a9 100644 --- a/Graphics/GraphicsEngineD3D12/src/DeviceContextD3D12Impl.cpp +++ b/Graphics/GraphicsEngineD3D12/src/DeviceContextD3D12Impl.cpp @@ -231,14 +231,16 @@ void DeviceContextD3D12Impl::SetPipelineState(IPipelineState* pPipelineState) if (RootInfo.pRootSig != pd3d12RootSig) { - RootInfo.pRootSig = pd3d12RootSig; - RootInfo.bRootTablesCommited = false; - RootInfo.bRootViewsCommitted = false; - RootInfo.ActiveSRBMask = 0; + // When root signature changes, all root resoruces must be committed + RootInfo.pRootSig = pd3d12RootSig; + RootInfo.bRootTablesCommited = false; + RootInfo.bRootViewsCommitted = false; + RootInfo.ActiveSRBMask = 0; + m_State.CommittedResourcesValidated = false; for (Uint32 i = 0, SignCount = pPipelineStateD3D12->GetSignatureCount(); i < SignCount; ++i) { - auto* pSignature = pPipelineStateD3D12->GetSignature(i); + const auto* pSignature = pPipelineStateD3D12->GetSignature(i); if (pSignature != nullptr) RootInfo.ActiveSRBMask |= 1u << i; } @@ -300,40 +302,31 @@ void DeviceContextD3D12Impl::SetPipelineState(IPipelineState* pPipelineState) } template <bool IsCompute> -void DeviceContextD3D12Impl::CommitRootTables(RootTableInfo& RootInfo) +void DeviceContextD3D12Impl::CommitRootTablesAndViews(RootTableInfo& RootInfo) { const auto& RootSig = *m_pPipelineState->GetRootSignature(); - auto& CmdCtx = GetCmdContext(); - if (!RootInfo.bRootTablesCommited) + auto& CmdCtx = GetCmdContext(); + for (Uint32 s = 0; s < RootSig.GetSignatureCount(); ++s) { - RootInfo.bRootTablesCommited = true; - for (Uint32 s = 0; s < RootSig.GetSignatureCount(); ++s) - { - auto* pSignature = RootSig.GetResourceSignature(s); - auto* pSRB = RootInfo.SRBs[s]; - - if (pSignature == nullptr || pSignature->GetTotalResourceCount() == 0) - continue; + const auto* const pSignature = RootSig.GetResourceSignature(s); + if (pSignature == nullptr || pSignature->GetTotalResourceCount() == 0) + continue; - VERIFY_EXPR(pSRB != nullptr); + auto* const pSRB = RootInfo.SRBs[s]; + DEV_CHECK_ERR(pSRB != nullptr, "No SRB is committed and binding index ", s); + if (!RootInfo.bRootTablesCommited) + { pSignature->CommitRootTables(pSRB->GetResourceCache(), CmdCtx, this, GetContextId(), IsCompute, RootSig.GetBaseRootIndex(s)); } - } - RootInfo.bRootViewsCommitted = true; - for (Uint32 s = 0; s < RootSig.GetSignatureCount(); ++s) - { - auto* pSignature = RootSig.GetResourceSignature(s); - auto* pSRB = RootInfo.SRBs[s]; - - if (pSignature == nullptr || pSignature->GetNumRootViews() == 0) - continue; - - VERIFY_EXPR(pSRB != nullptr); + // Always commit root views. This method is not called if root views are up to date constexpr auto CommitDynamicBuffers = true; pSignature->CommitRootViews(pSRB->GetResourceCache(), CmdCtx, this, GetContextId(), RootSig.GetBaseRootIndex(s), IsCompute, CommitDynamicBuffers); } + + RootInfo.bRootTablesCommited = true; + RootInfo.bRootViewsCommitted = true; } void DeviceContextD3D12Impl::TransitionShaderResources(IPipelineState* pPipelineState, IShaderResourceBinding* pShaderResourceBinding) @@ -349,7 +342,7 @@ void DeviceContextD3D12Impl::TransitionShaderResources(IPipelineState* pPipeline auto* pResBindingD3D12Impl = ValidatedCast<ShaderResourceBindingD3D12Impl>(pShaderResourceBinding); auto& ResourceCache = pResBindingD3D12Impl->GetResourceCache(); - ResourceCache.TransitionResources(CmdCtx, true, false); + ResourceCache.TransitionResourceStates(CmdCtx, ShaderResourceCacheD3D12::StateTransitionMode::Transition); } void DeviceContextD3D12Impl::CommitShaderResources(IShaderResourceBinding* pShaderResourceBinding, RESOURCE_STATE_TRANSITION_MODE StateTransitionMode) @@ -368,12 +361,12 @@ void DeviceContextD3D12Impl::CommitShaderResources(IShaderResourceBinding* pShad if (StateTransitionMode == RESOURCE_STATE_TRANSITION_MODE_TRANSITION) { - ResourceCache.TransitionResources(CmdCtx, true, false); + ResourceCache.TransitionResourceStates(CmdCtx, ShaderResourceCacheD3D12::StateTransitionMode::Transition); } #ifdef DILIGENT_DEVELOPMENT else if (StateTransitionMode == RESOURCE_STATE_TRANSITION_MODE_VERIFY) { - ResourceCache.TransitionResources(CmdCtx, false, true); + ResourceCache.TransitionResourceStates(CmdCtx, ShaderResourceCacheD3D12::StateTransitionMode::Verify); } #endif @@ -387,8 +380,9 @@ void DeviceContextD3D12Impl::CommitShaderResources(IShaderResourceBinding* pShad else RootInfo.ClearDynamicBufferBit(SRBIndex); - RootInfo.bRootTablesCommited = false; - RootInfo.bRootViewsCommitted = false; + RootInfo.bRootTablesCommited = false; + RootInfo.bRootViewsCommitted = false; + m_State.CommittedResourcesValidated = false; } DeviceContextD3D12Impl::RootTableInfo& DeviceContextD3D12Impl::GetRootTableInfo(PIPELINE_TYPE PipelineType) @@ -404,41 +398,8 @@ void DeviceContextD3D12Impl::DvpValidateCommittedShaderResources() if (m_State.CommittedResourcesValidated) return; - const auto& RootSig = *m_pPipelineState->GetRootSignature(); - auto& RootInfo = GetRootTableInfo(m_pPipelineState->GetDesc().PipelineType); - const auto SignCount = RootSig.GetSignatureCount(); - - for (Uint32 i = 0; i < SignCount; ++i) - { - auto* pSignature = RootSig.GetResourceSignature(i); - if (pSignature == nullptr) - continue; - - if (pSignature->GetTotalRootParamsCount() == 0) - { - // Skip signatures without any resources - continue; - } - - const auto* pSRB = RootInfo.SRBs[i]; - if (pSRB == nullptr) - { - LOG_ERROR_MESSAGE("Shader resource binding is not bound to index (", i, ")."); - continue; - } - - auto* pSRBSign = pSRB->GetSignature(); - VERIFY_EXPR(pSRBSign != nullptr); - - if (!pSignature->IsCompatibleWith(*pSRBSign)) - { - LOG_ERROR_MESSAGE("Shader resource binding at index ", i, " with signature '", pSRBSign->GetDesc().Name, - "' is not compatible with pipeline layout in current pipeline '", m_pPipelineState->GetDesc().Name, "'."); - } - } - + auto& RootInfo = GetRootTableInfo(m_pPipelineState->GetDesc().PipelineType); m_pPipelineState->DvpVerifySRBResources(RootInfo.SRBs.data(), static_cast<Uint32>(RootInfo.SRBs.size())); - m_State.CommittedResourcesValidated = true; } #endif @@ -584,7 +545,7 @@ void DeviceContextD3D12Impl::PrepareForDraw(GraphicsContext& GraphCtx, DRAW_FLAG auto& RootInfo = GetRootTableInfo(PIPELINE_TYPE_GRAPHICS); if (RootInfo.RequireUpdate(Flags & DRAW_FLAG_DYNAMIC_RESOURCE_BUFFERS_INTACT)) { - CommitRootTables<false>(RootInfo); + CommitRootTablesAndViews<false>(RootInfo); } #ifdef DILIGENT_DEVELOPMENT @@ -717,7 +678,7 @@ void DeviceContextD3D12Impl::PrepareForDispatchCompute(ComputeContext& ComputeCt auto& RootInfo = GetRootTableInfo(PIPELINE_TYPE_COMPUTE); if (RootInfo.RequireUpdate()) { - CommitRootTables<true>(RootInfo); + CommitRootTablesAndViews<true>(RootInfo); } #ifdef DILIGENT_DEVELOPMENT @@ -730,7 +691,7 @@ void DeviceContextD3D12Impl::PrepareForDispatchRays(GraphicsContext& GraphCtx) auto& RootInfo = GetRootTableInfo(PIPELINE_TYPE_RAY_TRACING); if (RootInfo.RequireUpdate()) { - CommitRootTables<true>(RootInfo); + CommitRootTablesAndViews<true>(RootInfo); } #ifdef DILIGENT_DEVELOPMENT diff --git a/Graphics/GraphicsEngineD3D12/src/PipelineStateD3D12Impl.cpp b/Graphics/GraphicsEngineD3D12/src/PipelineStateD3D12Impl.cpp index d649046c..2bbfb956 100644 --- a/Graphics/GraphicsEngineD3D12/src/PipelineStateD3D12Impl.cpp +++ b/Graphics/GraphicsEngineD3D12/src/PipelineStateD3D12Impl.cpp @@ -796,6 +796,31 @@ void PipelineStateD3D12Impl::DvpValidateShaderResources(const ShaderD3D12Impl* p void PipelineStateD3D12Impl::DvpVerifySRBResources(ShaderResourceBindingD3D12Impl* pSRBs[], Uint32 NumSRBs) const { + // Verify SRB compatibility with this pipeline + const auto SignCount = GetResourceSignatureCount(); + for (Uint32 sign = 0; sign < SignCount; ++sign) + { + // Get resource signature from the root signature + const auto* const pSignature = m_RootSig->GetResourceSignature(sign); + if (pSignature == nullptr || pSignature->GetTotalResourceCount() == 0) + continue; // Skip null and empty signatures + + VERIFY_EXPR(pSignature->GetDesc().BindingIndex == sign); + const auto* const pSRB = pSRBs[sign]; + if (pSRB == nullptr) + { + LOG_ERROR_MESSAGE("Pipeline state '", m_Desc.Name, "' requires SRB at index ", sign, " but none is bound in the device context."); + continue; + } + + const auto* const pSRBSign = pSRB->GetSignature(); + if (!pSignature->IsCompatibleWith(pSRBSign)) + { + LOG_ERROR_MESSAGE("Shader resource binding at index ", sign, " with signature '", pSRBSign->GetDesc().Name, + "' is not compatible with pipeline layout in current pipeline '", m_Desc.Name, "'."); + } + } + auto attrib_it = m_ResourceAttibutions.begin(); for (const auto& pResources : m_ShaderResources) { diff --git a/Graphics/GraphicsEngineD3D12/src/ShaderResourceCacheD3D12.cpp b/Graphics/GraphicsEngineD3D12/src/ShaderResourceCacheD3D12.cpp index e92f77ef..58d1ea3b 100644 --- a/Graphics/GraphicsEngineD3D12/src/ShaderResourceCacheD3D12.cpp +++ b/Graphics/GraphicsEngineD3D12/src/ShaderResourceCacheD3D12.cpp @@ -462,23 +462,26 @@ void ShaderResourceCacheD3D12::Resource::DvpVerifyResourceState() } #endif // DILIGENT_DEVELOPMENT -void ShaderResourceCacheD3D12::TransitionResources(CommandContext& Ctx, - bool PerformTransitions, - bool ValidateStates) +void ShaderResourceCacheD3D12::TransitionResourceStates(CommandContext& Ctx, StateTransitionMode Mode) { for (Uint32 r = 0; r < m_TotalResourceCount; ++r) { auto& Res = GetResource(r); - if (PerformTransitions) + switch (Mode) { - Res.TransitionResource(Ctx); - } + case StateTransitionMode::Transition: + Res.TransitionResource(Ctx); + break; + + case StateTransitionMode::Verify: #ifdef DILIGENT_DEVELOPMENT - else if (ValidateStates) - { - Res.DvpVerifyResourceState(); - } + Res.DvpVerifyResourceState(); #endif + break; + + default: + UNEXPECTED("Unexpected mode"); + } } } |
