From ce496ba73a61fe88db3d5c233dd920c2689d9e9b Mon Sep 17 00:00:00 2001 From: assiduous Date: Thu, 17 Sep 2020 22:00:26 -0700 Subject: Refactored internal shader resouce variable indexing --- .../include/PipelineStateVkImpl.hpp | 7 ++-- .../include/ShaderResourceBindingVkImpl.hpp | 7 ++-- .../src/PipelineStateVkImpl.cpp | 8 ++-- .../src/ShaderResourceBindingVkImpl.cpp | 44 ++++++---------------- Graphics/GraphicsEngineVulkan/src/ShaderVkImpl.cpp | 2 +- 5 files changed, 25 insertions(+), 43 deletions(-) (limited to 'Graphics/GraphicsEngineVulkan') diff --git a/Graphics/GraphicsEngineVulkan/include/PipelineStateVkImpl.hpp b/Graphics/GraphicsEngineVulkan/include/PipelineStateVkImpl.hpp index 5f00317e..43ae0456 100644 --- a/Graphics/GraphicsEngineVulkan/include/PipelineStateVkImpl.hpp +++ b/Graphics/GraphicsEngineVulkan/include/PipelineStateVkImpl.hpp @@ -155,9 +155,10 @@ private: VulkanUtilities::PipelineWrapper m_Pipeline; PipelineLayout m_PipelineLayout; - std::array m_ResourceLayoutIndex = {}; - bool m_HasStaticResources = false; - bool m_HasNonStaticResources = false; + std::array m_ResourceLayoutIndex = {}; + + bool m_HasStaticResources = false; + bool m_HasNonStaticResources = false; }; } // namespace Diligent diff --git a/Graphics/GraphicsEngineVulkan/include/ShaderResourceBindingVkImpl.hpp b/Graphics/GraphicsEngineVulkan/include/ShaderResourceBindingVkImpl.hpp index d93a72ac..b3cbe742 100644 --- a/Graphics/GraphicsEngineVulkan/include/ShaderResourceBindingVkImpl.hpp +++ b/Graphics/GraphicsEngineVulkan/include/ShaderResourceBindingVkImpl.hpp @@ -78,9 +78,10 @@ private: ShaderVariableManagerVk* m_pShaderVarMgrs = nullptr; // Shader variable manager index in m_pShaderVarMgrs[] array for every shader stage - std::array m_ResourceLayoutIndex; - bool m_bStaticResourcesInitialized = false; - Uint8 m_NumShaders = 0; + std::array m_ResourceLayoutIndex; + + bool m_bStaticResourcesInitialized = false; + Uint8 m_NumShaders = 0; }; } // namespace Diligent diff --git a/Graphics/GraphicsEngineVulkan/src/PipelineStateVkImpl.cpp b/Graphics/GraphicsEngineVulkan/src/PipelineStateVkImpl.cpp index c5b70426..0f824d41 100644 --- a/Graphics/GraphicsEngineVulkan/src/PipelineStateVkImpl.cpp +++ b/Graphics/GraphicsEngineVulkan/src/PipelineStateVkImpl.cpp @@ -177,7 +177,7 @@ PipelineStateVkImpl::PipelineStateVkImpl(IReferenceCounters* pRefCoun ShaderSPIRVs[s] = pShaderVk->GetSPIRV(); const auto ShaderType = pShaderVk->GetDesc().ShaderType; - const auto ShaderTypeInd = GetShaderTypeIndex(ShaderType); + const auto ShaderTypeInd = GetShaderTypePipelineIndex(ShaderType, m_Desc.PipelineType); m_ResourceLayoutIndex[ShaderTypeInd] = static_cast(s); auto* pStaticResLayout = new (m_ShaderResourceLayouts + m_NumShaders + s) ShaderResourceLayoutVk(LogicalDevice); @@ -679,7 +679,7 @@ void PipelineStateVkImpl::BindStaticResources(Uint32 ShaderFlags, IResourceMappi Uint32 PipelineStateVkImpl::GetStaticVariableCount(SHADER_TYPE ShaderType) const { - const auto LayoutInd = m_ResourceLayoutIndex[GetShaderTypeIndex(ShaderType)]; + const auto LayoutInd = GetStaticVariableCountHelper(ShaderType, m_ResourceLayoutIndex); if (LayoutInd < 0) return 0; @@ -689,7 +689,7 @@ Uint32 PipelineStateVkImpl::GetStaticVariableCount(SHADER_TYPE ShaderType) const IShaderResourceVariable* PipelineStateVkImpl::GetStaticVariableByName(SHADER_TYPE ShaderType, const Char* Name) { - const auto LayoutInd = m_ResourceLayoutIndex[GetShaderTypeIndex(ShaderType)]; + const auto LayoutInd = GetStaticVariableByNameHelper(ShaderType, Name, m_ResourceLayoutIndex); if (LayoutInd < 0) return nullptr; @@ -699,7 +699,7 @@ IShaderResourceVariable* PipelineStateVkImpl::GetStaticVariableByName(SHADER_TYP IShaderResourceVariable* PipelineStateVkImpl::GetStaticVariableByIndex(SHADER_TYPE ShaderType, Uint32 Index) { - const auto LayoutInd = m_ResourceLayoutIndex[GetShaderTypeIndex(ShaderType)]; + const auto LayoutInd = GetStaticVariableByIndexHelper(ShaderType, Index, m_ResourceLayoutIndex); if (LayoutInd < 0) return nullptr; diff --git a/Graphics/GraphicsEngineVulkan/src/ShaderResourceBindingVkImpl.cpp b/Graphics/GraphicsEngineVulkan/src/ShaderResourceBindingVkImpl.cpp index b978c592..efbdc006 100644 --- a/Graphics/GraphicsEngineVulkan/src/ShaderResourceBindingVkImpl.cpp +++ b/Graphics/GraphicsEngineVulkan/src/ShaderResourceBindingVkImpl.cpp @@ -64,7 +64,7 @@ ShaderResourceBindingVkImpl::ShaderResourceBindingVkImpl(IReferenceCounters* pR { auto* pShader = ppShaders[s]; auto ShaderType = pShader->GetDesc().ShaderType; - auto ShaderInd = GetShaderTypeIndex(ShaderType); + auto ShaderInd = GetShaderTypePipelineIndex(ShaderType, pPSO->GetDesc().PipelineType); m_ResourceLayoutIndex[ShaderInd] = static_cast(s); @@ -102,12 +102,13 @@ IMPLEMENT_QUERY_INTERFACE(ShaderResourceBindingVkImpl, IID_ShaderResourceBinding void ShaderResourceBindingVkImpl::BindResources(Uint32 ShaderFlags, IResourceMapping* pResMapping, Uint32 Flags) { - for (auto ShaderInd = 0; ShaderInd <= CSInd; ++ShaderInd) + const auto PipelineType = m_pPSO->GetDesc().PipelineType; + for (Int32 ShaderInd = 0; ShaderInd < static_cast(m_ResourceLayoutIndex.size()); ++ShaderInd) { - if (ShaderFlags & GetShaderTypeFromIndex(ShaderInd)) + auto ResLayoutInd = m_ResourceLayoutIndex[ShaderInd]; + if (ResLayoutInd >= 0) { - auto ResLayoutInd = m_ResourceLayoutIndex[ShaderInd]; - if (ResLayoutInd >= 0) + if (ShaderFlags & GetShaderTypeFromPipelineIndex(ShaderInd, PipelineType)) { m_pShaderVarMgrs[ResLayoutInd].BindResources(pResMapping, Flags); } @@ -117,41 +118,20 @@ void ShaderResourceBindingVkImpl::BindResources(Uint32 ShaderFlags, IResourceMap IShaderResourceVariable* ShaderResourceBindingVkImpl::GetVariableByName(SHADER_TYPE ShaderType, const char* Name) { - auto ShaderInd = GetShaderTypeIndex(ShaderType); - auto ResLayoutInd = m_ResourceLayoutIndex[ShaderInd]; - if (ResLayoutInd < 0) - { - LOG_WARNING_MESSAGE("Unable to find mutable/dynamic variable '", Name, "': shader stage ", GetShaderTypeLiteralName(ShaderType), - " is inactive in Pipeline State '", m_pPSO->GetDesc().Name, "'."); - return nullptr; - } - return m_pShaderVarMgrs[ResLayoutInd].GetVariable(Name); + auto ResLayoutInd = GetVariableByNameHelper(ShaderType, Name, m_ResourceLayoutIndex); + return ResLayoutInd >= 0 ? m_pShaderVarMgrs[ResLayoutInd].GetVariable(Name) : nullptr; } Uint32 ShaderResourceBindingVkImpl::GetVariableCount(SHADER_TYPE ShaderType) const { - auto ShaderInd = GetShaderTypeIndex(ShaderType); - auto ResLayoutInd = m_ResourceLayoutIndex[ShaderInd]; - if (ResLayoutInd < 0) - { - LOG_WARNING_MESSAGE("Unable to get the number of mutable/dynamic variables: shader stage ", GetShaderTypeLiteralName(ShaderType), - " is inactive in Pipeline State '", m_pPSO->GetDesc().Name, "'."); - return 0; - } - return m_pShaderVarMgrs[ResLayoutInd].GetVariableCount(); + auto ResLayoutInd = GetVariableCountHelper(ShaderType, m_ResourceLayoutIndex); + return ResLayoutInd >= 0 ? m_pShaderVarMgrs[ResLayoutInd].GetVariableCount() : 0; } IShaderResourceVariable* ShaderResourceBindingVkImpl::GetVariableByIndex(SHADER_TYPE ShaderType, Uint32 Index) { - auto ShaderInd = GetShaderTypeIndex(ShaderType); - auto ResLayoutInd = m_ResourceLayoutIndex[ShaderInd]; - if (ResLayoutInd < 0) - { - LOG_WARNING_MESSAGE("Unable to get mutable/dynamic variable at index ", Index, ": shader stage ", GetShaderTypeLiteralName(ShaderType), - " is inactive in Pipeline State '", m_pPSO->GetDesc().Name, "'."); - return nullptr; - } - return m_pShaderVarMgrs[ResLayoutInd].GetVariable(Index); + auto ResLayoutInd = GetVariableByIndexHelper(ShaderType, Index, m_ResourceLayoutIndex); + return ResLayoutInd >= 0 ? m_pShaderVarMgrs[ResLayoutInd].GetVariable(Index) : 0; } void ShaderResourceBindingVkImpl::InitializeStaticResources(const IPipelineState* pPipelineState) diff --git a/Graphics/GraphicsEngineVulkan/src/ShaderVkImpl.cpp b/Graphics/GraphicsEngineVulkan/src/ShaderVkImpl.cpp index 5e27beb2..718cc39a 100644 --- a/Graphics/GraphicsEngineVulkan/src/ShaderVkImpl.cpp +++ b/Graphics/GraphicsEngineVulkan/src/ShaderVkImpl.cpp @@ -115,7 +115,7 @@ ShaderVkImpl::ShaderVkImpl(IReferenceCounters* pRefCounters, if (m_SPIRV.empty()) { - LOG_ERROR_AND_THROW("Failed to compile shader \"", CreationAttribs.Desc.Name, "\""); + LOG_ERROR_AND_THROW("Failed to compile shader '", CreationAttribs.Desc.Name, '\''); } } else if (CreationAttribs.ByteCode != nullptr) -- cgit v1.2.3