diff options
| author | Egor Yusov <egor.yusov@gmail.com> | 2018-05-19 23:55:17 +0000 |
|---|---|---|
| committer | Egor Yusov <egor.yusov@gmail.com> | 2018-05-19 23:55:17 +0000 |
| commit | f652bad06ebadcf45b6117479d6873dde49ef43f (patch) | |
| tree | 90a35179b9e6b33f6a04fe1ca902f242157daf43 /Graphics/GraphicsEngineVulkan | |
| parent | Minor update (diff) | |
| download | DiligentCore-f652bad06ebadcf45b6117479d6873dde49ef43f.tar.gz DiligentCore-f652bad06ebadcf45b6117479d6873dde49ef43f.zip | |
Updated PipelineState VK: only creating default SRB if there are static resources and no non-static resources
Diffstat (limited to 'Graphics/GraphicsEngineVulkan')
3 files changed, 30 insertions, 8 deletions
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<ShaderResourceLayoutVk*, 6> m_pShaderResourceLayouts = {}; AdaptiveFixedBlockAllocator m_ResourceCacheDataAllocator; // Use separate allocator for every shader stage std::array<VulkanUtilities::ShaderModuleWrapper, 6> 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); } } } |
