From a2182ec6a9a7b5ab67f234fe0c3187670cca95af Mon Sep 17 00:00:00 2001 From: assiduous Date: Wed, 23 Dec 2020 16:43:26 -0800 Subject: ShaderResourceLayoutVk: added a few extra debug check in InitializeStaticResources --- .../src/ShaderResourceLayoutVk.cpp | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) (limited to 'Graphics/GraphicsEngineVulkan') diff --git a/Graphics/GraphicsEngineVulkan/src/ShaderResourceLayoutVk.cpp b/Graphics/GraphicsEngineVulkan/src/ShaderResourceLayoutVk.cpp index ab90fd0f..6c82350d 100644 --- a/Graphics/GraphicsEngineVulkan/src/ShaderResourceLayoutVk.cpp +++ b/Graphics/GraphicsEngineVulkan/src/ShaderResourceLayoutVk.cpp @@ -209,6 +209,8 @@ StringPool ShaderResourceLayoutVk::AllocateMemory(const std::vector, MAX_SHADERS_IN_PIPELINE> CurrResInd = {}; - std::array CurrImmutableSamplerInd = {}; + // Current resource index, for every variable type in every shader stage + std::array, MAX_SHADERS_IN_PIPELINE> CurrResInd = {}; + // Current immutable sampler index, for every shader stage + std::array CurrImmutableSamplerInd = {}; + #ifdef DILIGENT_DEBUG std::unordered_map> dbgBindings_CacheOffsets; #endif @@ -631,6 +637,9 @@ void ShaderResourceLayoutVk::Initialize(IRenderDevice* pRende if (SrcImmutableSamplerInd >= 0) { // NB: for immutable separate samplers we still allocate VkResource instances, but they are never exposed to the app + + // We reserve enough space for the maximum number of immutable samplers that may be used in the stage, + // but not all of them will necessarily be initialized. auto& ImmutableSampler = ResLayout.GetImmutableSampler(CurrImmutableSamplerInd[ShaderInd]++); VERIFY(!ImmutableSampler, "Immutable sampler has already been initialized. This is unexpected " "as all resources are deduplicated and should only be initialized once."); @@ -1319,12 +1328,15 @@ void ShaderResourceLayoutVk::InitializeStaticResources(const ShaderResourceLayou // Static shader resources are stored in one large continuous descriptor set for (Uint32 r = 0; r < NumStaticResources; ++r) { - // Get resource attributes + // Get resource attributes. Resources have the same index in both layouts. const auto& DstRes = GetResource(SHADER_RESOURCE_VARIABLE_TYPE_STATIC, r); const auto& SrcRes = SrcLayout.GetResource(SHADER_RESOURCE_VARIABLE_TYPE_STATIC, r); VERIFY(strcmp(SrcRes.Name, DstRes.Name) == 0, "Src resource name ('", SrcRes.Name, "') does match the dst resource name '(", DstRes.Name, "'). This is a bug."); + VERIFY(SrcRes.Type == DstRes.Type, "Src and dst resource types are incompatible. This is a bug."); + VERIFY(SrcRes.ResourceDim == DstRes.ResourceDim, "Src and dst resource dimensions are incompatible. This is a bug."); VERIFY(SrcRes.Binding == Uint32{SrcRes.Type}, "Unexpected binding"); - VERIFY(SrcRes.ArraySize == DstRes.ArraySize, "Inconsistent array size"); + VERIFY(SrcRes.ArraySize == DstRes.ArraySize, "Src and dst resource array sizes are not identical. This is a bug."); + VERIFY(SrcRes.IsImmutableSamplerAssigned() == DstRes.IsImmutableSamplerAssigned(), "Src and dst resource immutable sampler flags are not identical. This is a bug."); if (DstRes.Type == SPIRVShaderResourceAttribs::ResourceType::SeparateSampler && DstRes.IsImmutableSamplerAssigned()) -- cgit v1.2.3