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/PipelineStateVkImpl.hpp | 6 ++++-- .../include/ShaderResourceBindingVkImpl.hpp | 5 +++-- .../src/PipelineStateVkImpl.cpp | 8 ++++---- .../src/ShaderResourceBindingVkImpl.cpp | 24 +++++++++++++++++----- 4 files changed, 30 insertions(+), 13 deletions(-) (limited to 'Graphics/GraphicsEngineVulkan') diff --git a/Graphics/GraphicsEngineVulkan/include/PipelineStateVkImpl.hpp b/Graphics/GraphicsEngineVulkan/include/PipelineStateVkImpl.hpp index 43ae0456..d1732211 100644 --- a/Graphics/GraphicsEngineVulkan/include/PipelineStateVkImpl.hpp +++ b/Graphics/GraphicsEngineVulkan/include/PipelineStateVkImpl.hpp @@ -150,12 +150,14 @@ private: // SRB memory allocator must be declared before m_pDefaultShaderResBinding SRBMemoryAllocator m_SRBMemAllocator; - std::array m_ShaderModules; + std::array m_ShaderModules = {}; VulkanUtilities::PipelineWrapper m_Pipeline; PipelineLayout m_PipelineLayout; - std::array m_ResourceLayoutIndex = {}; + // Resource layout index in m_ShaderResourceLayouts array for every shader stage, + // indexed by the shader type pipeline index (returned by GetShaderTypePipelineIndex) + std::array m_ResourceLayoutIndex = {-1, -1, -1, -1, -1}; bool m_HasStaticResources = false; bool m_HasNonStaticResources = false; diff --git a/Graphics/GraphicsEngineVulkan/include/ShaderResourceBindingVkImpl.hpp b/Graphics/GraphicsEngineVulkan/include/ShaderResourceBindingVkImpl.hpp index 55c65757..026bb9da 100644 --- a/Graphics/GraphicsEngineVulkan/include/ShaderResourceBindingVkImpl.hpp +++ b/Graphics/GraphicsEngineVulkan/include/ShaderResourceBindingVkImpl.hpp @@ -79,8 +79,9 @@ private: ShaderResourceCacheVk m_ShaderResourceCache; ShaderVariableManagerVk* m_pShaderVarMgrs = nullptr; - // Shader variable manager index in m_pShaderVarMgrs[] array for every shader stage - std::array m_ResourceLayoutIndex; + // Resource layout index in m_ShaderResourceCache array for every shader stage, + // indexed by the shader type pipeline index (returned by GetShaderTypePipelineIndex) + std::array m_ResourceLayoutIndex = {-1, -1, -1, -1, -1}; bool m_bStaticResourcesInitialized = false; Uint8 m_NumShaders = 0; diff --git a/Graphics/GraphicsEngineVulkan/src/PipelineStateVkImpl.cpp b/Graphics/GraphicsEngineVulkan/src/PipelineStateVkImpl.cpp index 0f824d41..5c165e32 100644 --- a/Graphics/GraphicsEngineVulkan/src/PipelineStateVkImpl.cpp +++ b/Graphics/GraphicsEngineVulkan/src/PipelineStateVkImpl.cpp @@ -171,7 +171,7 @@ PipelineStateVkImpl::PipelineStateVkImpl(IReferenceCounters* pRefCoun for (Uint32 s = 0; s < m_NumShaders; ++s) { - new (m_ShaderResourceLayouts + s) ShaderResourceLayoutVk(LogicalDevice); + new (m_ShaderResourceLayouts + s) ShaderResourceLayoutVk{LogicalDevice}; auto* pShaderVk = GetShader(s); ShaderResources[s] = pShaderVk->GetShaderResources(); ShaderSPIRVs[s] = pShaderVk->GetSPIRV(); @@ -180,11 +180,11 @@ PipelineStateVkImpl::PipelineStateVkImpl(IReferenceCounters* pRefCoun const auto ShaderTypeInd = GetShaderTypePipelineIndex(ShaderType, m_Desc.PipelineType); m_ResourceLayoutIndex[ShaderTypeInd] = static_cast(s); - auto* pStaticResLayout = new (m_ShaderResourceLayouts + m_NumShaders + s) ShaderResourceLayoutVk(LogicalDevice); - auto* pStaticResCache = new (m_StaticResCaches + s) ShaderResourceCacheVk(ShaderResourceCacheVk::DbgCacheContentType::StaticShaderResources); + auto* pStaticResLayout = new (m_ShaderResourceLayouts + m_NumShaders + s) ShaderResourceLayoutVk{LogicalDevice}; + auto* pStaticResCache = new (m_StaticResCaches + s) ShaderResourceCacheVk{ShaderResourceCacheVk::DbgCacheContentType::StaticShaderResources}; pStaticResLayout->InitializeStaticResourceLayout(ShaderResources[s], ShaderResLayoutAllocator, m_Desc.ResourceLayout, m_StaticResCaches[s]); - new (m_StaticVarsMgrs + s) ShaderVariableManagerVk(*this, *pStaticResLayout, GetRawAllocator(), nullptr, 0, *pStaticResCache); + new (m_StaticVarsMgrs + s) ShaderVariableManagerVk{*this, *pStaticResLayout, GetRawAllocator(), nullptr, 0, *pStaticResCache}; } ShaderResourceLayoutVk::Initialize(pDeviceVk, m_NumShaders, m_ShaderResourceLayouts, ShaderResources.data(), GetRawAllocator(), m_Desc.ResourceLayout, ShaderSPIRVs.data(), m_PipelineLayout, diff --git a/Graphics/GraphicsEngineVulkan/src/ShaderResourceBindingVkImpl.cpp b/Graphics/GraphicsEngineVulkan/src/ShaderResourceBindingVkImpl.cpp index efbdc006..6e6c142f 100644 --- a/Graphics/GraphicsEngineVulkan/src/ShaderResourceBindingVkImpl.cpp +++ b/Graphics/GraphicsEngineVulkan/src/ShaderResourceBindingVkImpl.cpp @@ -78,7 +78,7 @@ ShaderResourceBindingVkImpl::ShaderResourceBindingVkImpl(IReferenceCounters* pR // Initialize vars manager to reference mutable and dynamic variables // Note that the cache has space for all variable types const SHADER_RESOURCE_VARIABLE_TYPE VarTypes[] = {SHADER_RESOURCE_VARIABLE_TYPE_MUTABLE, SHADER_RESOURCE_VARIABLE_TYPE_DYNAMIC}; - new (m_pShaderVarMgrs + s) ShaderVariableManagerVk(*this, SrcLayout, VarDataAllocator, VarTypes, _countof(VarTypes), m_ShaderResourceCache); + new (m_pShaderVarMgrs + s) ShaderVariableManagerVk{*this, SrcLayout, VarDataAllocator, VarTypes, _countof(VarTypes), m_ShaderResourceCache}; } #ifdef DILIGENT_DEBUG m_ShaderResourceCache.DbgVerifyResourceInitialization(); @@ -108,7 +108,9 @@ void ShaderResourceBindingVkImpl::BindResources(Uint32 ShaderFlags, IResourceMap auto ResLayoutInd = m_ResourceLayoutIndex[ShaderInd]; if (ResLayoutInd >= 0) { - if (ShaderFlags & GetShaderTypeFromPipelineIndex(ShaderInd, PipelineType)) + // ShaderInd is the shader type pipeline index here + const auto ShaderType = GetShaderTypeFromPipelineIndex(ShaderInd, PipelineType); + if (ShaderFlags & ShaderType) { m_pShaderVarMgrs[ResLayoutInd].BindResources(pResMapping, Flags); } @@ -119,19 +121,31 @@ void ShaderResourceBindingVkImpl::BindResources(Uint32 ShaderFlags, IResourceMap IShaderResourceVariable* ShaderResourceBindingVkImpl::GetVariableByName(SHADER_TYPE ShaderType, const char* Name) { auto ResLayoutInd = GetVariableByNameHelper(ShaderType, Name, m_ResourceLayoutIndex); - return ResLayoutInd >= 0 ? m_pShaderVarMgrs[ResLayoutInd].GetVariable(Name) : nullptr; + if (ResLayoutInd < 0) + return nullptr; + + VERIFY_EXPR(static_cast(ResLayoutInd) < Uint32{m_NumShaders}); + return m_pShaderVarMgrs[ResLayoutInd].GetVariable(Name); } Uint32 ShaderResourceBindingVkImpl::GetVariableCount(SHADER_TYPE ShaderType) const { auto ResLayoutInd = GetVariableCountHelper(ShaderType, m_ResourceLayoutIndex); - return ResLayoutInd >= 0 ? m_pShaderVarMgrs[ResLayoutInd].GetVariableCount() : 0; + if (ResLayoutInd < 0) + return 0; + + VERIFY_EXPR(static_cast(ResLayoutInd) < Uint32{m_NumShaders}); + return m_pShaderVarMgrs[ResLayoutInd].GetVariableCount(); } IShaderResourceVariable* ShaderResourceBindingVkImpl::GetVariableByIndex(SHADER_TYPE ShaderType, Uint32 Index) { auto ResLayoutInd = GetVariableByIndexHelper(ShaderType, Index, m_ResourceLayoutIndex); - return ResLayoutInd >= 0 ? m_pShaderVarMgrs[ResLayoutInd].GetVariable(Index) : 0; + if (ResLayoutInd < 0) + return nullptr; + + VERIFY_EXPR(static_cast(ResLayoutInd) < Uint32{m_NumShaders}); + return m_pShaderVarMgrs[ResLayoutInd].GetVariable(Index); } void ShaderResourceBindingVkImpl::InitializeStaticResources(const IPipelineState* pPipelineState) -- cgit v1.2.3