From 28521eb517f26af909a56222cb586a07b8245d80 Mon Sep 17 00:00:00 2001 From: assiduous Date: Fri, 18 Sep 2020 16:07:26 -0700 Subject: Few minor (mostly cosmetic) updates to SRB and PSO implementations --- .../include/PipelineStateD3D11Impl.hpp | 4 +++- .../include/ShaderResourceBindingD3D11Impl.hpp | 10 ++++---- .../src/PipelineStateD3D11Impl.cpp | 16 +++++++++---- .../src/ShaderResourceBindingD3D11Impl.cpp | 27 ++++++++++++++++------ 4 files changed, 40 insertions(+), 17 deletions(-) (limited to 'Graphics/GraphicsEngineD3D11') diff --git a/Graphics/GraphicsEngineD3D11/include/PipelineStateD3D11Impl.hpp b/Graphics/GraphicsEngineD3D11/include/PipelineStateD3D11Impl.hpp index 6040dc31..02f922a6 100644 --- a/Graphics/GraphicsEngineD3D11/include/PipelineStateD3D11Impl.hpp +++ b/Graphics/GraphicsEngineD3D11/include/PipelineStateD3D11Impl.hpp @@ -142,7 +142,9 @@ private: // SRB memory allocator must be defined before the default shader res binding SRBMemoryAllocator m_SRBMemAllocator; - std::array m_ResourceLayoutIndex; + // Resource layout index in m_pStaticResourceLayouts array for every shader stage, + // indexed by the shader type pipeline index (returned by GetShaderTypePipelineIndex) + std::array m_ResourceLayoutIndex = {-1, -1, -1, -1, -1}; std::array m_StaticSamplerOffsets = {}; struct StaticSamplerInfo diff --git a/Graphics/GraphicsEngineD3D11/include/ShaderResourceBindingD3D11Impl.hpp b/Graphics/GraphicsEngineD3D11/include/ShaderResourceBindingD3D11Impl.hpp index de92785b..eb97dfdc 100644 --- a/Graphics/GraphicsEngineD3D11/include/ShaderResourceBindingD3D11Impl.hpp +++ b/Graphics/GraphicsEngineD3D11/include/ShaderResourceBindingD3D11Impl.hpp @@ -90,7 +90,7 @@ public: Uint32 GetNumActiveShaders() const { - return static_cast(m_NumActiveShaders); + return Uint32{m_NumActiveShaders}; } SHADER_TYPE GetActiveShaderType(Uint32 s) const @@ -106,9 +106,11 @@ private: std::array m_ShaderTypes = {}; - // Resource layout index in m_ResourceLayouts[] array for every shader stage - std::array m_ResourceLayoutIndex; - Uint8 m_NumActiveShaders = 0; + // Resource layout index in m_pResourceLayouts array for every shader stage, + // indexed by the shader type pipeline index (returned by GetShaderTypePipelineIndex) + std::array m_ResourceLayoutIndex = {-1, -1, -1, -1, -1}; + + Uint8 m_NumActiveShaders = 0; bool m_bIsStaticResourcesBound = false; }; diff --git a/Graphics/GraphicsEngineD3D11/src/PipelineStateD3D11Impl.cpp b/Graphics/GraphicsEngineD3D11/src/PipelineStateD3D11Impl.cpp index f4b7268b..39a6ca4a 100644 --- a/Graphics/GraphicsEngineD3D11/src/PipelineStateD3D11Impl.cpp +++ b/Graphics/GraphicsEngineD3D11/src/PipelineStateD3D11Impl.cpp @@ -156,8 +156,10 @@ PipelineStateD3D11Impl::PipelineStateD3D11Impl(IReferenceCounters* pR std::array ShaderResCacheDataSizes = {}; for (Uint32 s = 0; s < m_NumShaders; ++s) { - auto* pShader = GetShader(s); + const auto* pShader = GetShader(s); + const auto& ShaderDesc = pShader->GetDesc(); const auto& ShaderResources = *pShader->GetD3D11Resources(); + VERIFY_EXPR(ShaderDesc.ShaderType == ShaderResources.GetShaderType()); new (m_pStaticResourceCaches + s) ShaderResourceCacheD3D11; // Do not initialize the cache as this will be performed by the resource layout @@ -197,12 +199,16 @@ PipelineStateD3D11Impl::PipelineStateD3D11Impl(IReferenceCounters* pR if (m_Desc.SRBAllocationGranularity > 1) { - const SHADER_RESOURCE_VARIABLE_TYPE SRBVarTypes[] = {SHADER_RESOURCE_VARIABLE_TYPE_MUTABLE, SHADER_RESOURCE_VARIABLE_TYPE_DYNAMIC}; - ShaderResLayoutDataSizes[s] = ShaderResourceLayoutD3D11::GetRequiredMemorySize(ShaderResources, ResourceLayout, SRBVarTypes, _countof(SRBVarTypes)); - ShaderResCacheDataSizes[s] = ShaderResourceCacheD3D11::GetRequriedMemorySize(ShaderResources); + const SHADER_RESOURCE_VARIABLE_TYPE SRBVarTypes[] = // + { + SHADER_RESOURCE_VARIABLE_TYPE_MUTABLE, + SHADER_RESOURCE_VARIABLE_TYPE_DYNAMIC // + }; + ShaderResLayoutDataSizes[s] = ShaderResourceLayoutD3D11::GetRequiredMemorySize(ShaderResources, ResourceLayout, SRBVarTypes, _countof(SRBVarTypes)); + ShaderResCacheDataSizes[s] = ShaderResourceCacheD3D11::GetRequriedMemorySize(ShaderResources); } - auto ShaderInd = GetShaderTypePipelineIndex(pShader->GetDesc().ShaderType, m_Desc.PipelineType); + auto ShaderInd = GetShaderTypePipelineIndex(ShaderDesc.ShaderType, m_Desc.PipelineType); m_ResourceLayoutIndex[ShaderInd] = static_cast(s); } diff --git a/Graphics/GraphicsEngineD3D11/src/ShaderResourceBindingD3D11Impl.cpp b/Graphics/GraphicsEngineD3D11/src/ShaderResourceBindingD3D11Impl.cpp index 521e3504..62fd2df7 100644 --- a/Graphics/GraphicsEngineD3D11/src/ShaderResourceBindingD3D11Impl.cpp +++ b/Graphics/GraphicsEngineD3D11/src/ShaderResourceBindingD3D11Impl.cpp @@ -92,11 +92,12 @@ ShaderResourceBindingD3D11Impl::ShaderResourceBindingD3D11Impl(IReferenceCounter }; // clang-format on - const auto ShaderType = pShaderD3D11->GetDesc().ShaderType; - const auto ResLayoutInd = GetShaderTypePipelineIndex(ShaderType, PSODesc.PipelineType); - m_ShaderTypes[s] = ShaderType; + const auto ShaderType = pShaderD3D11->GetDesc().ShaderType; + const auto ShaderInd = GetShaderTypePipelineIndex(ShaderType, PSODesc.PipelineType); + VERIFY_EXPR(ShaderType == m_pResourceLayouts[s].GetShaderType()); + m_ShaderTypes[s] = ShaderType; - m_ResourceLayoutIndex[ResLayoutInd] = s; + m_ResourceLayoutIndex[ShaderInd] = s; } } @@ -186,19 +187,31 @@ void ShaderResourceBindingD3D11Impl::InitializeStaticResources(const IPipelineSt IShaderResourceVariable* ShaderResourceBindingD3D11Impl::GetVariableByName(SHADER_TYPE ShaderType, const char* Name) { auto ResLayoutInd = GetVariableByNameHelper(ShaderType, Name, m_ResourceLayoutIndex); - return ResLayoutInd >= 0 ? m_pResourceLayouts[ResLayoutInd].GetShaderVariable(Name) : nullptr; + if (ResLayoutInd < 0) + return nullptr; + + VERIFY_EXPR(static_cast(ResLayoutInd) < Uint32{m_NumActiveShaders}); + return m_pResourceLayouts[ResLayoutInd].GetShaderVariable(Name); } Uint32 ShaderResourceBindingD3D11Impl::GetVariableCount(SHADER_TYPE ShaderType) const { auto ResLayoutInd = GetVariableCountHelper(ShaderType, m_ResourceLayoutIndex); - return ResLayoutInd >= 0 ? m_pResourceLayouts[ResLayoutInd].GetTotalResourceCount() : 0; + if (ResLayoutInd < 0) + return 0; + + VERIFY_EXPR(static_cast(ResLayoutInd) < Uint32{m_NumActiveShaders}); + return m_pResourceLayouts[ResLayoutInd].GetTotalResourceCount(); } IShaderResourceVariable* ShaderResourceBindingD3D11Impl::GetVariableByIndex(SHADER_TYPE ShaderType, Uint32 Index) { auto ResLayoutInd = GetVariableByIndexHelper(ShaderType, Index, m_ResourceLayoutIndex); - return ResLayoutInd >= 0 ? m_pResourceLayouts[ResLayoutInd].GetShaderVariable(Index) : nullptr; + if (ResLayoutInd < 0) + return nullptr; + + VERIFY_EXPR(static_cast(ResLayoutInd) < Uint32{m_NumActiveShaders}); + return m_pResourceLayouts[ResLayoutInd].GetShaderVariable(Index); } } // namespace Diligent -- cgit v1.2.3