Skip to content

Commit ceca0c5

Browse files
PipelineResourceSignatureVkImpl: use ResDesc.GetArraySize() to correctly handle inline constants
1 parent b0ce020 commit ceca0c5

File tree

1 file changed

+16
-10
lines changed

1 file changed

+16
-10
lines changed

Graphics/GraphicsEngineVulkan/src/PipelineResourceSignatureVkImpl.cpp

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2019-2025 Diligent Graphics LLC
2+
* Copyright 2019-2026 Diligent Graphics LLC
33
* Copyright 2015-2019 Egor Yusov
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -177,7 +177,10 @@ void PipelineResourceSignatureVkImpl::CreateSetLayouts(const bool IsSerialized)
177177
{
178178
const PipelineResourceDesc& ResDesc = m_Desc.Resources[i];
179179
if (ResDesc.VarType == SHADER_RESOURCE_VARIABLE_TYPE_STATIC)
180-
StaticResourceCount += ResDesc.ArraySize;
180+
{
181+
// For inline constants, ArraySize holds the number of 4-byte constants
182+
StaticResourceCount += ResDesc.GetArraySize();
183+
}
181184
}
182185
m_pStaticResCache->InitializeSets(GetRawAllocator(), 1, &StaticResourceCount);
183186
}
@@ -191,7 +194,7 @@ void PipelineResourceSignatureVkImpl::CreateSetLayouts(const bool IsSerialized)
191194

192195
BindingCount[CacheGroup] += 1;
193196
// Note that we may reserve space for separate immutable samplers, which will never be used, but this is OK.
194-
CacheGroupSizes[CacheGroup] += ResDesc.ArraySize;
197+
CacheGroupSizes[CacheGroup] += ResDesc.GetArraySize(); // For inline constants, ArraySize holds the number of 4-byte constants
195198
}
196199

197200
// Descriptor set mapping (static/mutable (0) or dynamic (1) -> set index)
@@ -322,12 +325,15 @@ void PipelineResourceSignatureVkImpl::CreateSetLayouts(const bool IsSerialized)
322325
"Static cache offset is invalid.");
323326
}
324327

328+
// For inline constants, ArraySize holds the number of 4-byte constants
329+
const Uint32 DescriptorCount = ResDesc.GetArraySize();
330+
325331
BindingIndices[CacheGroup] += 1;
326-
CacheGroupOffsets[CacheGroup] += ResDesc.ArraySize;
332+
CacheGroupOffsets[CacheGroup] += DescriptorCount;
327333

328334
VkDescriptorSetLayoutBinding vkSetLayoutBinding{};
329335
vkSetLayoutBinding.binding = pAttribs->BindingIndex;
330-
vkSetLayoutBinding.descriptorCount = ResDesc.ArraySize;
336+
vkSetLayoutBinding.descriptorCount = DescriptorCount;
331337
vkSetLayoutBinding.stageFlags = ShaderTypesToVkShaderStageFlags(ResDesc.ShaderStages);
332338
vkSetLayoutBinding.pImmutableSamplers = pVkImmutableSamplers;
333339
vkSetLayoutBinding.descriptorType = DescriptorTypeToVkDescriptorType(pAttribs->GetDescriptorType());
@@ -336,9 +342,9 @@ void PipelineResourceSignatureVkImpl::CreateSetLayouts(const bool IsSerialized)
336342
if (ResDesc.VarType == SHADER_RESOURCE_VARIABLE_TYPE_STATIC)
337343
{
338344
VERIFY(pAttribs->DescrSet == 0, "Static resources must always be allocated in descriptor set 0");
339-
m_pStaticResCache->InitializeResources(pAttribs->DescrSet, StaticCacheOffset, ResDesc.ArraySize,
345+
m_pStaticResCache->InitializeResources(pAttribs->DescrSet, StaticCacheOffset, DescriptorCount,
340346
pAttribs->GetDescriptorType(), pAttribs->IsImmutableSamplerAssigned());
341-
StaticCacheOffset += ResDesc.ArraySize;
347+
StaticCacheOffset += DescriptorCount;
342348
}
343349
}
344350

@@ -509,7 +515,7 @@ void PipelineResourceSignatureVkImpl::InitSRBResourceCache(ShaderResourceCacheVk
509515
{
510516
const PipelineResourceDesc& ResDesc = GetResourceDesc(r);
511517
const ResourceAttribs& Attr = GetResourceAttribs(r);
512-
ResourceCache.InitializeResources(Attr.DescrSet, Attr.CacheOffset(CacheType), ResDesc.ArraySize,
518+
ResourceCache.InitializeResources(Attr.DescrSet, Attr.CacheOffset(CacheType), ResDesc.GetArraySize(),
513519
Attr.GetDescriptorType(), Attr.IsImmutableSamplerAssigned());
514520
}
515521

@@ -555,7 +561,7 @@ void PipelineResourceSignatureVkImpl::CopyStaticResources(ShaderResourceCacheVk&
555561
if (ResDesc.ResourceType == SHADER_RESOURCE_TYPE_SAMPLER && Attr.IsImmutableSamplerAssigned())
556562
continue; // Skip immutable separate samplers
557563

558-
for (Uint32 ArrInd = 0; ArrInd < ResDesc.ArraySize; ++ArrInd)
564+
for (Uint32 ArrInd = 0; ArrInd < ResDesc.GetArraySize(); ++ArrInd)
559565
{
560566
const Uint32 SrcCacheOffset = Attr.CacheOffset(SrcCacheType) + ArrInd;
561567
const ShaderResourceCacheVk::Resource& SrcCachedRes = SrcDescrSet.GetResource(SrcCacheOffset);
@@ -659,7 +665,7 @@ void PipelineResourceSignatureVkImpl::CommitDynamicResources(const ShaderResourc
659665
#ifdef DILIGENT_DEBUG
660666
{
661667
const PipelineResourceDesc& Res = GetResourceDesc(ResIdx);
662-
VERIFY_EXPR(ArraySize == GetResourceDesc(ResIdx).ArraySize);
668+
VERIFY_EXPR(ArraySize == GetResourceDesc(ResIdx).GetArraySize());
663669
VERIFY_EXPR(Res.VarType == SHADER_RESOURCE_VARIABLE_TYPE_DYNAMIC);
664670
}
665671
#endif

0 commit comments

Comments
 (0)