From 095e4961a0d3c88d459af7d48550dfff220cbada Mon Sep 17 00:00:00 2001 From: assiduous Date: Fri, 19 Feb 2021 15:22:37 -0800 Subject: Moved duplicate static resources logic from PipelineResourceSignatureD3D12Impl and PipelineResourceSignatureVkImpl to PipelineResourceSignatureBase --- .../include/PipelineResourceSignatureVkImpl.hpp | 5 -- .../src/PipelineResourceSignatureVkImpl.cpp | 64 +++++++--------------- 2 files changed, 19 insertions(+), 50 deletions(-) (limited to 'Graphics/GraphicsEngineVulkan') diff --git a/Graphics/GraphicsEngineVulkan/include/PipelineResourceSignatureVkImpl.hpp b/Graphics/GraphicsEngineVulkan/include/PipelineResourceSignatureVkImpl.hpp index 4236f7c1..b873d828 100644 --- a/Graphics/GraphicsEngineVulkan/include/PipelineResourceSignatureVkImpl.hpp +++ b/Graphics/GraphicsEngineVulkan/include/PipelineResourceSignatureVkImpl.hpp @@ -334,11 +334,6 @@ private: // accounting for array size. Uint16 m_DynamicStorageBufferCount = 0; - // Mapping from shader type index given by GetShaderTypePipelineIndex() to - // static variable manager index in m_StaticVarsMgrs array. - std::array m_StaticVarIndex = {-1, -1, -1, -1, -1, -1}; - static_assert(MAX_SHADERS_IN_PIPELINE == 6, "Please update the initializer list above"); - // Static resource cache for all static resources ShaderResourceCacheVk* m_pStaticResCache = nullptr; // Static variables manager for every shader stage diff --git a/Graphics/GraphicsEngineVulkan/src/PipelineResourceSignatureVkImpl.cpp b/Graphics/GraphicsEngineVulkan/src/PipelineResourceSignatureVkImpl.cpp index 38fa6670..2489ee10 100644 --- a/Graphics/GraphicsEngineVulkan/src/PipelineResourceSignatureVkImpl.cpp +++ b/Graphics/GraphicsEngineVulkan/src/PipelineResourceSignatureVkImpl.cpp @@ -275,8 +275,6 @@ PipelineResourceSignatureVkImpl::PipelineResourceSignatureVkImpl(IReferenceCount TPipelineResourceSignatureBase{pRefCounters, pDevice, Desc, bIsDeviceInternal}, m_SRBMemAllocator{GetRawAllocator()} { - m_StaticVarIndex.fill(-1); - try { FixedLinearAllocator MemPool{GetRawAllocator()}; @@ -293,43 +291,24 @@ PipelineResourceSignatureVkImpl::PipelineResourceSignatureVkImpl(IReferenceCount CacheOffsetsType CacheGroupSizes = {}; // Required cache size for each cache group BindingCountType BindingCount = {}; // Binding count in each cache group - SHADER_TYPE StaticResStages = SHADER_TYPE_UNKNOWN; // Shader stages that have static resources for (Uint32 i = 0; i < Desc.NumResources; ++i) { const auto& ResDesc = Desc.Resources[i]; const auto CacheGroup = GetResourceCacheGroup(ResDesc); - m_ShaderStages |= ResDesc.ShaderStages; - if (ResDesc.VarType == SHADER_RESOURCE_VARIABLE_TYPE_STATIC) - { - StaticResStages |= ResDesc.ShaderStages; StaticResourceCount += ResDesc.ArraySize; - } BindingCount[CacheGroup] += 1; // Note that we may reserve space for separate immutable samplers, which will never be used, but this is OK. CacheGroupSizes[CacheGroup] += ResDesc.ArraySize; } - m_NumShaderStages = static_cast(PlatformMisc::CountOneBits(static_cast(m_ShaderStages))); - if (m_ShaderStages != SHADER_TYPE_UNKNOWN) - { - m_PipelineType = PipelineTypeFromShaderStages(m_ShaderStages); - DEV_CHECK_ERR(m_PipelineType != PIPELINE_TYPE_INVALID, "Failed to deduce pipeline type from shader stages"); - } - - int StaticVarStageCount = 0; // The number of shader stages that have static variables - for (; StaticResStages != SHADER_TYPE_UNKNOWN; ++StaticVarStageCount) - { - const auto StageBit = ExtractLSB(StaticResStages); - const auto ShaderTypeInd = GetShaderTypePipelineIndex(StageBit, m_PipelineType); - m_StaticVarIndex[ShaderTypeInd] = static_cast(StaticVarStageCount); - } - if (StaticVarStageCount > 0) + const auto NumStaticResStages = GetNumStaticResStages(); + if (NumStaticResStages > 0) { MemPool.AddSpace(1); - MemPool.AddSpace(StaticVarStageCount); + MemPool.AddSpace(NumStaticResStages); } MemPool.Reserve(); @@ -344,28 +323,26 @@ PipelineResourceSignatureVkImpl::PipelineResourceSignatureVkImpl(IReferenceCount CopyDescription(MemPool, Desc); - if (StaticVarStageCount > 0) + if (NumStaticResStages > 0) { m_pStaticResCache = MemPool.Construct(CacheContentType::Signature); - m_StaticVarsMgrs = MemPool.Allocate(StaticVarStageCount); + m_StaticVarsMgrs = MemPool.ConstructArray(NumStaticResStages, std::ref(*this), std::ref(*m_pStaticResCache)); m_pStaticResCache->InitializeSets(GetRawAllocator(), 1, &StaticResourceCount); } CreateSetLayouts(CacheGroupSizes, BindingCount); - if (StaticVarStageCount > 0) + if (NumStaticResStages > 0) { - const SHADER_RESOURCE_VARIABLE_TYPE AllowedVarTypes[] = {SHADER_RESOURCE_VARIABLE_TYPE_STATIC}; - - for (Uint32 i = 0; i < m_StaticVarIndex.size(); ++i) + constexpr SHADER_RESOURCE_VARIABLE_TYPE AllowedVarTypes[] = {SHADER_RESOURCE_VARIABLE_TYPE_STATIC}; + for (Uint32 i = 0; i < m_StaticResStageIndex.size(); ++i) { - Int8 Idx = m_StaticVarIndex[i]; + Int8 Idx = m_StaticResStageIndex[i]; if (Idx >= 0) { - VERIFY_EXPR(Idx < StaticVarStageCount); + VERIFY_EXPR(static_cast(Idx) < NumStaticResStages); const auto ShaderType = GetShaderTypeFromPipelineIndex(i, GetPipelineType()); - new (m_StaticVarsMgrs + Idx) ShaderVariableManagerVk{*this, *m_pStaticResCache}; m_StaticVarsMgrs[Idx].Initialize(*this, GetRawAllocator(), AllowedVarTypes, _countof(AllowedVarTypes), ShaderType); } } @@ -610,7 +587,7 @@ void PipelineResourceSignatureVkImpl::CreateSetLayouts(const CacheOffsetsType& C std::array ShaderVariableDataSizes = {}; for (Uint32 s = 0; s < GetNumActiveShaderStages(); ++s) { - const SHADER_RESOURCE_VARIABLE_TYPE AllowedVarTypes[] = {SHADER_RESOURCE_VARIABLE_TYPE_MUTABLE, SHADER_RESOURCE_VARIABLE_TYPE_DYNAMIC}; + constexpr SHADER_RESOURCE_VARIABLE_TYPE AllowedVarTypes[] = {SHADER_RESOURCE_VARIABLE_TYPE_MUTABLE, SHADER_RESOURCE_VARIABLE_TYPE_DYNAMIC}; Uint32 UnusedNumVars = 0; ShaderVariableDataSizes[s] = ShaderVariableManagerVk::GetRequiredMemorySize(*this, AllowedVarTypes, _countof(AllowedVarTypes), GetActiveShaderStageType(s), UnusedNumVars); @@ -683,16 +660,14 @@ void PipelineResourceSignatureVkImpl::Destruct() if (m_StaticVarsMgrs != nullptr) { - for (size_t i = 0; i < m_StaticVarIndex.size(); ++i) + for (auto Idx : m_StaticResStageIndex) { - auto Idx = m_StaticVarIndex[i]; if (Idx >= 0) { m_StaticVarsMgrs[Idx].DestroyVariables(RawAllocator); m_StaticVarsMgrs[Idx].~ShaderVariableManagerVk(); } } - m_StaticVarIndex.fill(-1); m_StaticVarsMgrs = nullptr; } @@ -772,7 +747,7 @@ void PipelineResourceSignatureVkImpl::CreateShaderResourceBinding(IShaderResourc Uint32 PipelineResourceSignatureVkImpl::GetStaticVariableCount(SHADER_TYPE ShaderType) const { - const auto VarMngrInd = GetStaticVariableCountHelper(ShaderType, m_StaticVarIndex); + const auto VarMngrInd = GetStaticVariableCountHelper(ShaderType); if (VarMngrInd < 0) return 0; @@ -782,7 +757,7 @@ Uint32 PipelineResourceSignatureVkImpl::GetStaticVariableCount(SHADER_TYPE Shade IShaderResourceVariable* PipelineResourceSignatureVkImpl::GetStaticVariableByName(SHADER_TYPE ShaderType, const Char* Name) { - const auto VarMngrInd = GetStaticVariableByNameHelper(ShaderType, Name, m_StaticVarIndex); + const auto VarMngrInd = GetStaticVariableByNameHelper(ShaderType, Name); if (VarMngrInd < 0) return nullptr; @@ -792,7 +767,7 @@ IShaderResourceVariable* PipelineResourceSignatureVkImpl::GetStaticVariableByNam IShaderResourceVariable* PipelineResourceSignatureVkImpl::GetStaticVariableByIndex(SHADER_TYPE ShaderType, Uint32 Index) { - const auto VarMngrInd = GetStaticVariableByIndexHelper(ShaderType, Index, m_StaticVarIndex); + const auto VarMngrInd = GetStaticVariableByIndexHelper(ShaderType, Index); if (VarMngrInd < 0) return nullptr; @@ -805,16 +780,15 @@ void PipelineResourceSignatureVkImpl::BindStaticResources(Uint32 Shad Uint32 Flags) { const auto PipelineType = GetPipelineType(); - for (Uint32 ShaderInd = 0; ShaderInd < m_StaticVarIndex.size(); ++ShaderInd) + for (auto StaticResStageIdx : m_StaticResStageIndex) { - const auto VarMngrInd = m_StaticVarIndex[ShaderInd]; - if (VarMngrInd >= 0) + if (StaticResStageIdx >= 0) { // ShaderInd is the shader type pipeline index here - const auto ShaderType = GetShaderTypeFromPipelineIndex(ShaderInd, PipelineType); + const auto ShaderType = GetShaderTypeFromPipelineIndex(StaticResStageIdx, PipelineType); if (ShaderFlags & ShaderType) { - m_StaticVarsMgrs[VarMngrInd].BindResources(pResMapping, Flags); + m_StaticVarsMgrs[StaticResStageIdx].BindResources(pResMapping, Flags); } } } -- cgit v1.2.3