diff options
| author | assiduous <assiduous@diligentgraphics.com> | 2021-01-31 23:36:17 +0000 |
|---|---|---|
| committer | assiduous <assiduous@diligentgraphics.com> | 2021-01-31 23:36:17 +0000 |
| commit | 0d85f9b0336c6ebb4b9689ed8105719786ab41d1 (patch) | |
| tree | f32245aa8340b3e7d85953de69d0a819e6be80af /Graphics/GraphicsEngineVulkan | |
| parent | Shader resource cache Vk: added debug checks for dynamic buffers and offsets (diff) | |
| download | DiligentCore-0d85f9b0336c6ebb4b9689ed8105719786ab41d1.tar.gz DiligentCore-0d85f9b0336c6ebb4b9689ed8105719786ab41d1.zip | |
ShaderVariableManagerVk: removed duplicate logic
Diffstat (limited to 'Graphics/GraphicsEngineVulkan')
4 files changed, 55 insertions, 53 deletions
diff --git a/Graphics/GraphicsEngineVulkan/include/ShaderVariableVk.hpp b/Graphics/GraphicsEngineVulkan/include/ShaderVariableVk.hpp index 5f960065..76f9a9e4 100644 --- a/Graphics/GraphicsEngineVulkan/include/ShaderVariableVk.hpp +++ b/Graphics/GraphicsEngineVulkan/include/ShaderVariableVk.hpp @@ -80,7 +80,7 @@ public: m_ResourceCache{ResourceCache} {} - void Initialize(const PipelineResourceSignatureVkImpl& SrcLayout, + void Initialize(const PipelineResourceSignatureVkImpl& Signature, IMemoryAllocator& Allocator, const SHADER_RESOURCE_VARIABLE_TYPE* AllowedVarTypes, Uint32 NumAllowedTypes, @@ -95,7 +95,7 @@ public: void BindResources(IResourceMapping* pResourceMapping, Uint32 Flags) const; - static size_t GetRequiredMemorySize(const PipelineResourceSignatureVkImpl& Layout, + static size_t GetRequiredMemorySize(const PipelineResourceSignatureVkImpl& Signature, const SHADER_RESOURCE_VARIABLE_TYPE* AllowedVarTypes, Uint32 NumAllowedTypes, SHADER_TYPE ShaderStages, @@ -120,6 +120,13 @@ private: return m_pSignature->GetResourceAttribs(Index); } + template <typename HandlerType> + static void ProcessSignatureResources(const PipelineResourceSignatureVkImpl& Signature, + const SHADER_RESOURCE_VARIABLE_TYPE* AllowedVarTypes, + Uint32 NumAllowedTypes, + SHADER_TYPE ShaderStages, + HandlerType Handler); + private: PipelineResourceSignatureVkImpl const* m_pSignature = nullptr; @@ -225,7 +232,7 @@ private: private: ShaderVariableManagerVk& m_ParentManager; - const Uint32 m_ResIndex; + const Uint32 m_ResIndex; // Index in Signatures' m_Desc.Resources }; } // namespace Diligent diff --git a/Graphics/GraphicsEngineVulkan/src/PipelineLayoutVk.cpp b/Graphics/GraphicsEngineVulkan/src/PipelineLayoutVk.cpp index 1b810933..4e412e0e 100644 --- a/Graphics/GraphicsEngineVulkan/src/PipelineLayoutVk.cpp +++ b/Graphics/GraphicsEngineVulkan/src/PipelineLayoutVk.cpp @@ -108,11 +108,11 @@ void PipelineLayoutVk::Create(RenderDeviceVkImpl* pDeviceVk, PIPELINE_TYPE Pipel "Descriptor set layout count (", DescSetLayoutCount, ") exceeds the maximum representable value"); m_FirstDescrSetIndex[i] = static_cast<FirstDescrSetIndexArrayType::value_type>(DescSetLayoutCount); - auto vkStaticDSLayout = pSignature->GetVkDescriptorSetLayout(PipelineResourceSignatureVkImpl::DESCRIPTOR_SET_ID_STATIC_MUTABLE); - auto vkDynamicDSLayout = pSignature->GetVkDescriptorSetLayout(PipelineResourceSignatureVkImpl::DESCRIPTOR_SET_ID_DYNAMIC); - - if (vkStaticDSLayout != VK_NULL_HANDLE) DescSetLayouts[DescSetLayoutCount++] = vkStaticDSLayout; - if (vkDynamicDSLayout != VK_NULL_HANDLE) DescSetLayouts[DescSetLayoutCount++] = vkDynamicDSLayout; + for (auto SetId : {PipelineResourceSignatureVkImpl::DESCRIPTOR_SET_ID_STATIC_MUTABLE, PipelineResourceSignatureVkImpl::DESCRIPTOR_SET_ID_DYNAMIC}) + { + if (pSignature->HasDescriptorSet(SetId)) + DescSetLayouts[DescSetLayoutCount++] = pSignature->GetVkDescriptorSetLayout(SetId); + } DynamicUniformBufferCount += pSignature->GetDynamicUniformBufferCount(); DynamicStorageBufferCount += pSignature->GetDynamicStorageBufferCount(); diff --git a/Graphics/GraphicsEngineVulkan/src/PipelineStateVkImpl.cpp b/Graphics/GraphicsEngineVulkan/src/PipelineStateVkImpl.cpp index 7fbd5a39..9aab9c2d 100644 --- a/Graphics/GraphicsEngineVulkan/src/PipelineStateVkImpl.cpp +++ b/Graphics/GraphicsEngineVulkan/src/PipelineStateVkImpl.cpp @@ -721,7 +721,7 @@ RenderPassDesc PipelineStateVkImpl::GetImplicitRenderPassDesc( void PipelineStateVkImpl::InitPipelineLayout(const PipelineStateCreateInfo& CreateInfo, TShaderStages& ShaderStages) { - std::array<IPipelineResourceSignature*, MAX_RESOURCE_SIGNATURES> Signatures; + std::array<IPipelineResourceSignature*, MAX_RESOURCE_SIGNATURES> Signatures = {}; RefCntAutoPtr<IPipelineResourceSignature> pImplicitSignature; Uint32 SignatureCount = CreateInfo.ResourceSignaturesCount; diff --git a/Graphics/GraphicsEngineVulkan/src/ShaderVariableVk.cpp b/Graphics/GraphicsEngineVulkan/src/ShaderVariableVk.cpp index 1540c8a8..73cff300 100644 --- a/Graphics/GraphicsEngineVulkan/src/ShaderVariableVk.cpp +++ b/Graphics/GraphicsEngineVulkan/src/ShaderVariableVk.cpp @@ -34,28 +34,29 @@ namespace Diligent { -size_t ShaderVariableManagerVk::GetRequiredMemorySize(const PipelineResourceSignatureVkImpl& Layout, - const SHADER_RESOURCE_VARIABLE_TYPE* AllowedVarTypes, - Uint32 NumAllowedTypes, - SHADER_TYPE ShaderStages, - Uint32& NumVariables) +template <typename HandlerType> +void ShaderVariableManagerVk::ProcessSignatureResources(const PipelineResourceSignatureVkImpl& Signature, + const SHADER_RESOURCE_VARIABLE_TYPE* AllowedVarTypes, + Uint32 NumAllowedTypes, + SHADER_TYPE ShaderStages, + HandlerType Handler) { - NumVariables = 0; const Uint32 AllowedTypeBits = GetAllowedTypeBits(AllowedVarTypes, NumAllowedTypes); - const bool UsingSeparateSamplers = Layout.IsUsingSeparateSamplers(); + const bool UsingSeparateSamplers = Signature.IsUsingSeparateSamplers(); - for (SHADER_RESOURCE_VARIABLE_TYPE VarType = SHADER_RESOURCE_VARIABLE_TYPE_STATIC; VarType < SHADER_RESOURCE_VARIABLE_TYPE_NUM_TYPES; VarType = static_cast<SHADER_RESOURCE_VARIABLE_TYPE>(VarType + 1)) + for (Uint32 var_type = 0; var_type < SHADER_RESOURCE_VARIABLE_TYPE_NUM_TYPES; ++var_type) { + const auto VarType = static_cast<SHADER_RESOURCE_VARIABLE_TYPE>(var_type); if (IsAllowedType(VarType, AllowedTypeBits)) { - const auto ResIdxRange = Layout.GetResourceIndexRange(VarType); + const auto ResIdxRange = Signature.GetResourceIndexRange(VarType); for (Uint32 r = ResIdxRange.first; r < ResIdxRange.second; ++r) { - const auto& Res = Layout.GetResourceDesc(r); - const auto& Attr = Layout.GetResourceAttribs(r); + const auto& Res = Signature.GetResourceDesc(r); + const auto& Attr = Signature.GetResourceAttribs(r); VERIFY_EXPR(Res.VarType == VarType); - if (!(Res.ShaderStages & ShaderStages)) + if ((Res.ShaderStages & ShaderStages) == 0) continue; // When using HLSL-style combined image samplers, we need to skip separate samplers. @@ -64,16 +65,30 @@ size_t ShaderVariableManagerVk::GetRequiredMemorySize(const PipelineResourceSign (!UsingSeparateSamplers || Attr.IsImmutableSamplerAssigned())) continue; - ++NumVariables; + Handler(r); } } } +} + +size_t ShaderVariableManagerVk::GetRequiredMemorySize(const PipelineResourceSignatureVkImpl& Signature, + const SHADER_RESOURCE_VARIABLE_TYPE* AllowedVarTypes, + Uint32 NumAllowedTypes, + SHADER_TYPE ShaderStages, + Uint32& NumVariables) +{ + NumVariables = 0; + ProcessSignatureResources(Signature, AllowedVarTypes, NumAllowedTypes, ShaderStages, + [&NumVariables](Uint32) // + { + ++NumVariables; + }); return NumVariables * sizeof(ShaderVariableVkImpl); } // Creates shader variable for every resource from SrcLayout whose type is one AllowedVarTypes -void ShaderVariableManagerVk::Initialize(const PipelineResourceSignatureVkImpl& SrcLayout, +void ShaderVariableManagerVk::Initialize(const PipelineResourceSignatureVkImpl& Signature, IMemoryAllocator& Allocator, const SHADER_RESOURCE_VARIABLE_TYPE* AllowedVarTypes, Uint32 NumAllowedTypes, @@ -87,7 +102,7 @@ void ShaderVariableManagerVk::Initialize(const PipelineResourceSignatureVkImpl& const Uint32 AllowedTypeBits = GetAllowedTypeBits(AllowedVarTypes, NumAllowedTypes); VERIFY_EXPR(m_NumVariables == 0); - auto MemSize = GetRequiredMemorySize(SrcLayout, AllowedVarTypes, NumAllowedTypes, ShaderType, m_NumVariables); + auto MemSize = GetRequiredMemorySize(Signature, AllowedVarTypes, NumAllowedTypes, ShaderType, m_NumVariables); if (m_NumVariables == 0) return; @@ -95,36 +110,16 @@ void ShaderVariableManagerVk::Initialize(const PipelineResourceSignatureVkImpl& auto* pRawMem = ALLOCATE_RAW(Allocator, "Raw memory buffer for shader variables", MemSize); m_pVariables = reinterpret_cast<ShaderVariableVkImpl*>(pRawMem); - Uint32 VarInd = 0; - const bool UsingSeparateSamplers = SrcLayout.IsUsingSeparateSamplers(); - - for (SHADER_RESOURCE_VARIABLE_TYPE VarType = SHADER_RESOURCE_VARIABLE_TYPE_STATIC; VarType < SHADER_RESOURCE_VARIABLE_TYPE_NUM_TYPES; VarType = static_cast<SHADER_RESOURCE_VARIABLE_TYPE>(VarType + 1)) - { - if (IsAllowedType(VarType, AllowedTypeBits)) - { - const auto ResIdxRange = SrcLayout.GetResourceIndexRange(VarType); - for (Uint32 r = ResIdxRange.first; r < ResIdxRange.second; ++r) - { - const auto& Res = SrcLayout.GetResourceDesc(r); - const auto& Attr = SrcLayout.GetResourceAttribs(r); - VERIFY_EXPR(Res.VarType == VarType); - - if (!(Res.ShaderStages & ShaderType)) - continue; - - // Skip separate samplers when using combined HLSL-style image samplers. Also always skip immutable separate samplers. - if (Res.ResourceType == SHADER_RESOURCE_TYPE_SAMPLER && - (!UsingSeparateSamplers || Attr.IsImmutableSamplerAssigned())) - continue; - - ::new (m_pVariables + VarInd) ShaderVariableVkImpl(*this, r); - ++VarInd; - } - } - } + Uint32 VarInd = 0; + ProcessSignatureResources(Signature, AllowedVarTypes, NumAllowedTypes, ShaderType, + [this, &VarInd](Uint32 ResIndex) // + { + ::new (m_pVariables + VarInd) ShaderVariableVkImpl{*this, ResIndex}; + ++VarInd; + }); VERIFY_EXPR(VarInd == m_NumVariables); - m_pSignature = &SrcLayout; + m_pSignature = &Signature; } ShaderVariableManagerVk::~ShaderVariableManagerVk() @@ -261,7 +256,7 @@ void ShaderVariableVkImpl::SetArray(IDeviceObject* const* ppObjects, bool ShaderVariableVkImpl::IsBound(Uint32 ArrayIndex) const { - auto& ResourceCache = m_ParentManager.m_ResourceCache; + const auto& ResourceCache = m_ParentManager.m_ResourceCache; const auto& ResDesc = GetDesc(); const auto& Attribs = GetAttribs(); const Uint32 CacheOffset = Attribs.CacheOffset(ResourceCache.GetContentType()); |
