From bbbf3434aefd105662f9efd4bf9e7d56f9e8170b Mon Sep 17 00:00:00 2001 From: Egor Yusov Date: Sun, 11 Mar 2018 12:07:09 -0700 Subject: Implemented PSO compatibility in D3D11 --- .../include/PipelineStateD3D11Impl.h | 2 ++ .../src/DeviceContextD3D11Impl.cpp | 4 +-- .../src/PipelineStateD3D11Impl.cpp | 40 +++++++++++++++++++--- .../src/ShaderResourceLayoutD3D11.cpp | 10 +++--- .../src/ShaderResourcesD3D11.cpp | 10 +++--- 5 files changed, 50 insertions(+), 16 deletions(-) (limited to 'Graphics/GraphicsEngineD3D11') diff --git a/Graphics/GraphicsEngineD3D11/include/PipelineStateD3D11Impl.h b/Graphics/GraphicsEngineD3D11/include/PipelineStateD3D11Impl.h index e8cc719a..0a5897f2 100644 --- a/Graphics/GraphicsEngineD3D11/include/PipelineStateD3D11Impl.h +++ b/Graphics/GraphicsEngineD3D11/include/PipelineStateD3D11Impl.h @@ -69,6 +69,8 @@ public: virtual void CreateShaderResourceBinding( IShaderResourceBinding **ppShaderResourceBinding )override final; + virtual bool IsCompatibleWith(const IPipelineState *pPSO)const override final; + class ShaderResourceBindingD3D11Impl* GetDefaultResourceBinding(){return m_pDefaultShaderResBinding.get();} IMemoryAllocator &GetResourceCacheDataAllocator(Uint32 ActiveShaderInd) { diff --git a/Graphics/GraphicsEngineD3D11/src/DeviceContextD3D11Impl.cpp b/Graphics/GraphicsEngineD3D11/src/DeviceContextD3D11Impl.cpp index 803fab7f..fd8e58f1 100644 --- a/Graphics/GraphicsEngineD3D11/src/DeviceContextD3D11Impl.cpp +++ b/Graphics/GraphicsEngineD3D11/src/DeviceContextD3D11Impl.cpp @@ -170,7 +170,7 @@ namespace Diligent #ifdef _DEBUG else { - if (pdbgPipelineStateD3D11 != pShaderResourceBinding->GetPipelineState()) + if (pdbgPipelineStateD3D11->IsIncompatibleWith(pShaderResourceBinding->GetPipelineState())) { LOG_ERROR_MESSAGE("Shader resource binding does not match Pipeline State"); return; @@ -526,7 +526,7 @@ namespace Diligent void DeviceContextD3D11Impl::CommitShaderResources(IShaderResourceBinding *pShaderResourceBinding, Uint32 Flags) { - if( !DeviceContextBase::CommitShaderResources(pShaderResourceBinding, Flags, 0 /*Dummy*/) ) + if( !DeviceContextBase::CommitShaderResources(pShaderResourceBinding, Flags, 0 /*Dummy*/) ) return; if(Flags & COMMIT_SHADER_RESOURCES_FLAG_TRANSITION_RESOURCES) diff --git a/Graphics/GraphicsEngineD3D11/src/PipelineStateD3D11Impl.cpp b/Graphics/GraphicsEngineD3D11/src/PipelineStateD3D11Impl.cpp index 964614e6..c4e60dfe 100644 --- a/Graphics/GraphicsEngineD3D11/src/PipelineStateD3D11Impl.cpp +++ b/Graphics/GraphicsEngineD3D11/src/PipelineStateD3D11Impl.cpp @@ -37,27 +37,32 @@ PipelineStateD3D11Impl::PipelineStateD3D11Impl(IReferenceCounters *pRefCounters, { if (PipelineDesc.IsComputePipeline) { - m_pCS = ValidatedCast( PipelineDesc.ComputePipeline.pCS ); + auto *pCS = ValidatedCast(PipelineDesc.ComputePipeline.pCS); + m_pCS = pCS; if (m_pCS == nullptr) { LOG_ERROR_AND_THROW("Compute shader is null"); } if (m_pCS && m_pCS->GetDesc().ShaderType != SHADER_TYPE_COMPUTE) - { - LOG_ERROR_AND_THROW( GetShaderTypeLiteralName(SHADER_TYPE_COMPUTE), " shader is expeceted while ", GetShaderTypeLiteralName(m_pCS->GetDesc().ShaderType)," provided" ); + { + LOG_ERROR_AND_THROW(GetShaderTypeLiteralName(SHADER_TYPE_COMPUTE), " shader is expeceted while ", GetShaderTypeLiteralName(m_pCS->GetDesc().ShaderType), " provided"); } + m_ShaderResourceLayoutHash = pCS->GetResources()->GetHash(); } else { #define INIT_SHADER(ShortName, ExpectedType)\ { \ - m_p##ShortName = ValidatedCast( PipelineDesc.GraphicsPipeline.p##ShortName ); \ + auto *pShader = ValidatedCast(PipelineDesc.GraphicsPipeline.p##ShortName); \ + m_p##ShortName = pShader; \ if (m_p##ShortName && m_p##ShortName->GetDesc().ShaderType != ExpectedType) \ { \ LOG_ERROR_AND_THROW( GetShaderTypeLiteralName(ExpectedType), " shader is expeceted while ", GetShaderTypeLiteralName(m_p##ShortName->GetDesc().ShaderType)," provided" ); \ } \ + if(pShader!=nullptr) \ + HashCombine(m_ShaderResourceLayoutHash, pShader->GetResources()->GetHash() ); \ } INIT_SHADER(VS, SHADER_TYPE_VERTEX); @@ -186,6 +191,33 @@ void PipelineStateD3D11Impl::CreateShaderResourceBinding(IShaderResourceBinding pShaderResBinding->QueryInterface(IID_ShaderResourceBinding, reinterpret_cast(static_cast(ppShaderResourceBinding))); } +bool PipelineStateD3D11Impl::IsCompatibleWith(const IPipelineState *pPSO)const +{ + if (pPSO == this) + return true; + + VERIFY_EXPR(pPSO != nullptr); + const PipelineStateD3D11Impl *pPSOD3D11 = ValidatedCast(pPSO); + if (m_ShaderResourceLayoutHash != pPSOD3D11->m_ShaderResourceLayoutHash) + return false; + + if (m_NumShaders != pPSOD3D11->m_NumShaders) + return false; + + for (Uint32 s = 0; s < m_NumShaders; ++s) + { + auto *pShader0 = ValidatedCast(m_ppShaders[s]); + auto *pShader1 = ValidatedCast(pPSOD3D11->m_ppShaders[s]); + if (pShader0->GetShaderTypeIndex() != pShader1->GetShaderTypeIndex()) + return false; + const ShaderResourcesD3D11 *pRes0 = pShader0->GetResources().get(); + const ShaderResourcesD3D11 *pRes1 = pShader1->GetResources().get(); + if (!pRes0->IsCompatibleWith(*pRes1)) + return false; + } + + return true; +} ID3D11VertexShader* PipelineStateD3D11Impl::GetD3D11VertexShader() { diff --git a/Graphics/GraphicsEngineD3D11/src/ShaderResourceLayoutD3D11.cpp b/Graphics/GraphicsEngineD3D11/src/ShaderResourceLayoutD3D11.cpp index 47274ba2..e653fa3a 100644 --- a/Graphics/GraphicsEngineD3D11/src/ShaderResourceLayoutD3D11.cpp +++ b/Graphics/GraphicsEngineD3D11/src/ShaderResourceLayoutD3D11.cpp @@ -143,7 +143,7 @@ void ShaderResourceLayoutD3D11::Initialize(const std::shared_ptrProcessResources( VarTypes, NumVarTypes, - [&](const D3DShaderResourceAttribs &CB) + [&](const D3DShaderResourceAttribs &CB, Uint32) { VERIFY_EXPR( IsAllowedType(CB.GetVariableType(), AllowedTypeBits) ); // Initialize current CB in place, increment CB counter @@ -151,7 +151,7 @@ void ShaderResourceLayoutD3D11::Initialize(const std::shared_ptr(CB.BindPoint + CB.BindCount)); }, - [&](const D3DShaderResourceAttribs& TexSRV) + [&](const D3DShaderResourceAttribs& TexSRV, Uint32) { VERIFY_EXPR( IsAllowedType(TexSRV.GetVariableType(), AllowedTypeBits) ); // Set reference to a special static instance representing invalid sampler @@ -165,7 +165,7 @@ void ShaderResourceLayoutD3D11::Initialize(const std::shared_ptr(SamplerAttribs.BindPoint + SamplerAttribs.BindCount)); }, - [&](const D3DShaderResourceAttribs &TexUAV) + [&](const D3DShaderResourceAttribs &TexUAV, Uint32) { VERIFY_EXPR( IsAllowedType(TexUAV.GetVariableType(), AllowedTypeBits) ); @@ -174,7 +174,7 @@ void ShaderResourceLayoutD3D11::Initialize(const std::shared_ptr(TexUAV.BindPoint + TexUAV.BindCount)); }, - [&](const D3DShaderResourceAttribs &BuffSRV) + [&](const D3DShaderResourceAttribs &BuffSRV, Uint32) { VERIFY_EXPR(IsAllowedType(BuffSRV.GetVariableType(), AllowedTypeBits)); @@ -183,7 +183,7 @@ void ShaderResourceLayoutD3D11::Initialize(const std::shared_ptr(BuffSRV.BindPoint + BuffSRV.BindCount)); }, - [&](const D3DShaderResourceAttribs &BuffUAV) + [&](const D3DShaderResourceAttribs &BuffUAV, Uint32) { VERIFY_EXPR(IsAllowedType(BuffUAV.GetVariableType(), AllowedTypeBits)); diff --git a/Graphics/GraphicsEngineD3D11/src/ShaderResourcesD3D11.cpp b/Graphics/GraphicsEngineD3D11/src/ShaderResourcesD3D11.cpp index cfc93de5..74149c5e 100644 --- a/Graphics/GraphicsEngineD3D11/src/ShaderResourcesD3D11.cpp +++ b/Graphics/GraphicsEngineD3D11/src/ShaderResourcesD3D11.cpp @@ -195,7 +195,7 @@ void ShaderResourcesD3D11::dbgVerifyCommittedResources(ID3D11Buffer* ProcessResources( nullptr, 0, - [&](const D3DShaderResourceAttribs &cb) + [&](const D3DShaderResourceAttribs &cb, Uint32) { for(auto BindPoint = cb.BindPoint; BindPoint < cb.BindPoint + cb.BindCount; ++BindPoint) { @@ -233,7 +233,7 @@ void ShaderResourcesD3D11::dbgVerifyCommittedResources(ID3D11Buffer* } }, - [&](const D3DShaderResourceAttribs& tex) + [&](const D3DShaderResourceAttribs& tex, Uint32) { for(auto BindPoint = tex.BindPoint; BindPoint < tex.BindPoint + tex.BindCount; ++BindPoint) { @@ -308,7 +308,7 @@ void ShaderResourcesD3D11::dbgVerifyCommittedResources(ID3D11Buffer* } }, - [&](const D3DShaderResourceAttribs &uav) + [&](const D3DShaderResourceAttribs &uav, Uint32) { for(auto BindPoint = uav.BindPoint; BindPoint < uav.BindPoint + uav.BindCount; ++BindPoint) { @@ -349,7 +349,7 @@ void ShaderResourcesD3D11::dbgVerifyCommittedResources(ID3D11Buffer* }, - [&](const D3DShaderResourceAttribs &buf) + [&](const D3DShaderResourceAttribs &buf, Uint32) { for(auto BindPoint = buf.BindPoint; BindPoint < buf.BindPoint + buf.BindCount; ++BindPoint) { @@ -389,7 +389,7 @@ void ShaderResourcesD3D11::dbgVerifyCommittedResources(ID3D11Buffer* } }, - [&](const D3DShaderResourceAttribs &uav) + [&](const D3DShaderResourceAttribs &uav, Uint32) { for(auto BindPoint = uav.BindPoint; BindPoint < uav.BindPoint + uav.BindCount; ++BindPoint) { -- cgit v1.2.3