From f652bad06ebadcf45b6117479d6873dde49ef43f Mon Sep 17 00:00:00 2001 From: Egor Yusov Date: Sat, 19 May 2018 16:55:17 -0700 Subject: Updated PipelineState VK: only creating default SRB if there are static resources and no non-static resources --- .../include/PipelineStateVkImpl.h | 2 +- .../include/ShaderResourceLayoutVk.h | 5 ++++ .../src/PipelineStateVkImpl.cpp | 31 +++++++++++++++++----- 3 files changed, 30 insertions(+), 8 deletions(-) (limited to 'Graphics/GraphicsEngineVulkan') diff --git a/Graphics/GraphicsEngineVulkan/include/PipelineStateVkImpl.h b/Graphics/GraphicsEngineVulkan/include/PipelineStateVkImpl.h index 062a5340..9377ef39 100644 --- a/Graphics/GraphicsEngineVulkan/include/PipelineStateVkImpl.h +++ b/Graphics/GraphicsEngineVulkan/include/PipelineStateVkImpl.h @@ -123,7 +123,7 @@ private: AdaptiveFixedBlockAllocator *m_pAllocators[5] = {}; }m_ResLayoutDataAllocators; // Allocators must be defined before default SRB - ShaderResourceLayoutVk* m_pShaderResourceLayouts[6] = {}; + std::array m_pShaderResourceLayouts = {}; AdaptiveFixedBlockAllocator m_ResourceCacheDataAllocator; // Use separate allocator for every shader stage std::array m_ShaderModules; diff --git a/Graphics/GraphicsEngineVulkan/include/ShaderResourceLayoutVk.h b/Graphics/GraphicsEngineVulkan/include/ShaderResourceLayoutVk.h index 7b79d268..fb968b43 100644 --- a/Graphics/GraphicsEngineVulkan/include/ShaderResourceLayoutVk.h +++ b/Graphics/GraphicsEngineVulkan/include/ShaderResourceLayoutVk.h @@ -273,6 +273,11 @@ public: IObject& GetOwner(){return m_Owner;} + Uint32 GetResourceCount(SHADER_VARIABLE_TYPE VarType)const + { + return m_NumResources[VarType]; + } + private: void InitVariablesHashMap(); diff --git a/Graphics/GraphicsEngineVulkan/src/PipelineStateVkImpl.cpp b/Graphics/GraphicsEngineVulkan/src/PipelineStateVkImpl.cpp index 71db4fe1..8e3a5219 100644 --- a/Graphics/GraphicsEngineVulkan/src/PipelineStateVkImpl.cpp +++ b/Graphics/GraphicsEngineVulkan/src/PipelineStateVkImpl.cpp @@ -372,9 +372,26 @@ PipelineStateVkImpl :: PipelineStateVkImpl(IReferenceCounters *pRefCounters, Ren if(PipelineDesc.SRBAllocationGranularity > 1) m_ResLayoutDataAllocators.Init(m_NumShaders, PipelineDesc.SRBAllocationGranularity); - auto &SRBAllocator = pDeviceVk->GetSRBAllocator(); - // Default shader resource binding must be initialized after resource layouts are parsed! - m_pDefaultShaderResBinding.reset( NEW_RC_OBJ(SRBAllocator, "ShaderResourceBindingVkImpl instance", ShaderResourceBindingVkImpl, this)(this, true) ); + bool HasStaticResources = false; + bool HasNonStaticResources = false; + for (auto *pLayout : m_pShaderResourceLayouts) + { + if (pLayout != nullptr) + { + HasStaticResources = pLayout->GetResourceCount(SHADER_VARIABLE_TYPE_STATIC) != 0; + HasNonStaticResources = pLayout->GetResourceCount(SHADER_VARIABLE_TYPE_MUTABLE) != 0 || + pLayout->GetResourceCount(SHADER_VARIABLE_TYPE_DYNAMIC) != 0; + } + } + + // If there are only static resources, create default shader resource binding + if(HasStaticResources && !HasNonStaticResources) + { + auto &SRBAllocator = pDeviceVk->GetSRBAllocator(); + // Default shader resource binding must be initialized after resource layouts are parsed! + m_pDefaultShaderResBinding.reset( NEW_RC_OBJ(SRBAllocator, "ShaderResourceBindingVkImpl instance", ShaderResourceBindingVkImpl, this)(this, true) ); + } + #if 0 m_ShaderResourceLayoutHash = m_RootSig.GetHash(); #endif @@ -397,12 +414,12 @@ PipelineStateVkImpl::~PipelineStateVkImpl() } auto &ShaderResLayoutAllocator = GetRawAllocator(); - for(Int32 l = 0; l < _countof(m_pShaderResourceLayouts); ++l) + for (auto *pLayout : m_pShaderResourceLayouts) { - if (m_pShaderResourceLayouts[l] != nullptr) + if (pLayout != nullptr) { - m_pShaderResourceLayouts[l]->~ShaderResourceLayoutVk(); - ShaderResLayoutAllocator.Free(m_pShaderResourceLayouts[l]); + pLayout->~ShaderResourceLayoutVk(); + ShaderResLayoutAllocator.Free(pLayout); } } } -- cgit v1.2.3