summaryrefslogtreecommitdiffstats
path: root/Graphics/GraphicsEngineD3D11
diff options
context:
space:
mode:
authorEgor Yusov <egor.yusov@gmail.com>2018-03-11 19:07:09 +0000
committerEgor Yusov <egor.yusov@gmail.com>2018-03-11 19:07:09 +0000
commitbbbf3434aefd105662f9efd4bf9e7d56f9e8170b (patch)
tree42806921a62dcc82b4925927d52e9f453048e959 /Graphics/GraphicsEngineD3D11
parentEnabled full optimization (/Ox) for windows release builds (diff)
downloadDiligentCore-bbbf3434aefd105662f9efd4bf9e7d56f9e8170b.tar.gz
DiligentCore-bbbf3434aefd105662f9efd4bf9e7d56f9e8170b.zip
Implemented PSO compatibility in D3D11
Diffstat (limited to 'Graphics/GraphicsEngineD3D11')
-rw-r--r--Graphics/GraphicsEngineD3D11/include/PipelineStateD3D11Impl.h2
-rw-r--r--Graphics/GraphicsEngineD3D11/src/DeviceContextD3D11Impl.cpp4
-rw-r--r--Graphics/GraphicsEngineD3D11/src/PipelineStateD3D11Impl.cpp40
-rw-r--r--Graphics/GraphicsEngineD3D11/src/ShaderResourceLayoutD3D11.cpp10
-rw-r--r--Graphics/GraphicsEngineD3D11/src/ShaderResourcesD3D11.cpp10
5 files changed, 50 insertions, 16 deletions
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<PipelineStateD3D11Impl>(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<ShaderD3D11Impl>( PipelineDesc.ComputePipeline.pCS );
+ auto *pCS = ValidatedCast<ShaderD3D11Impl>(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<ShaderD3D11Impl>( PipelineDesc.GraphicsPipeline.p##ShortName ); \
+ auto *pShader = ValidatedCast<ShaderD3D11Impl>(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<IObject**>(static_cast<IShaderResourceBinding**>(ppShaderResourceBinding)));
}
+bool PipelineStateD3D11Impl::IsCompatibleWith(const IPipelineState *pPSO)const
+{
+ if (pPSO == this)
+ return true;
+
+ VERIFY_EXPR(pPSO != nullptr);
+ const PipelineStateD3D11Impl *pPSOD3D11 = ValidatedCast<const PipelineStateD3D11Impl>(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<ShaderD3D11Impl>(m_ppShaders[s]);
+ auto *pShader1 = ValidatedCast<ShaderD3D11Impl>(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_ptr<const ShaderRes
pSrcResources->ProcessResources(
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<const ShaderRes
NumCBSlots = std::max(NumCBSlots, static_cast<Uint32>(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<const ShaderRes
NumSamplerSlots = std::max(NumSamplerSlots, static_cast<Uint32>(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<const ShaderRes
NumUAVSlots = std::max(NumUAVSlots, static_cast<Uint32>(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<const ShaderRes
NumSRVSlots = std::max(NumSRVSlots, static_cast<Uint32>(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)
{