Skip to content

Commit 0ba141b

Browse files
hzqstTheMostDiligent
authored andcommitted
ShaderVariableManagerVk: handle inline constants
1 parent e9267d0 commit 0ba141b

File tree

3 files changed

+38
-6
lines changed

3 files changed

+38
-6
lines changed

Graphics/GraphicsEngineVulkan/include/ShaderResourceCacheVk.hpp

Lines changed: 8 additions & 1 deletion
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");
@@ -246,6 +246,13 @@ class ShaderResourceCacheVk : public ShaderResourceCacheBase
246246
Uint32 DynamicBufferOffset);
247247

248248

249+
// Sets inline constant data in the resource cache
250+
void SetInlineConstants(Uint32 DescrSetIndex,
251+
Uint32 CacheOffset,
252+
const void* pConstants,
253+
Uint32 FirstConstant,
254+
Uint32 NumConstants);
255+
249256
Uint32 GetNumDescriptorSets() const { return m_NumSets; }
250257
bool HasDynamicResources() const { return m_NumDynamicBuffers > 0; }
251258

Graphics/GraphicsEngineVulkan/src/ShaderResourceCacheVk.cpp

Lines changed: 10 additions & 1 deletion
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");
@@ -950,4 +950,13 @@ Uint32 ShaderResourceCacheVk::GetDynamicBufferOffsets(DeviceContextVkImpl* pCt
950950
return OffsetInd - StartInd;
951951
}
952952

953+
void ShaderResourceCacheVk::SetInlineConstants(Uint32 DescrSetIndex,
954+
Uint32 CacheOffset,
955+
const void* pConstants,
956+
Uint32 FirstConstant,
957+
Uint32 NumConstants)
958+
{
959+
UNSUPPORTED("Not implemented yet");
960+
}
961+
953962
} // namespace Diligent

Graphics/GraphicsEngineVulkan/src/ShaderVariableManagerVk.cpp

Lines changed: 20 additions & 4 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");
@@ -286,7 +286,8 @@ BindResourceHelper::BindResourceHelper(const PipelineResourceSignatureVkImpl& Si
286286
m_DstRes {m_CachedSet.GetResource(m_DstResCacheOffset)}
287287
// clang-format on
288288
{
289-
VERIFY(ArrayIndex < m_ResDesc.ArraySize, "Array index is out of range, but it should've been corrected by ShaderVariableBase::SetArray()");
289+
// For inline constants, GetArraySize() returns 1 (actual array size), while ArraySize is the number of constants
290+
VERIFY(ArrayIndex < m_ResDesc.GetArraySize(), "Array index is out of range, but it should've been corrected by ShaderVariableBase::SetArray()");
290291
VERIFY(m_DstRes.Type == m_Attribs.GetDescriptorType(), "Inconsistent types");
291292

292293
#ifdef DILIGENT_DEBUG
@@ -655,7 +656,21 @@ void ShaderVariableManagerVk::SetInlineConstants(Uint32 ResIndex,
655656
Uint32 FirstConstant,
656657
Uint32 NumConstants)
657658
{
658-
UNSUPPORTED("Not yet implemented");
659+
const PipelineResourceAttribsVk& Attribs = m_pSignature->GetResourceAttribs(ResIndex);
660+
const ResourceCacheContentType CacheType = m_ResourceCache.GetContentType();
661+
const Uint32 CacheOffset = Attribs.CacheOffset(CacheType);
662+
663+
#ifdef DILIGENT_DEVELOPMENT
664+
{
665+
const PipelineResourceDesc& ResDesc = m_pSignature->GetResourceDesc(ResIndex);
666+
VerifyInlineConstants(ResDesc, pConstants, FirstConstant, NumConstants);
667+
}
668+
#endif
669+
670+
// All inline constants use the same path at PRS level - store data in the resource cache.
671+
// The data will be used either for push constants (vkCmdPushConstants) or emulated buffers
672+
// depending on the PSO's selection.
673+
m_ResourceCache.SetInlineConstants(Attribs.DescrSet, CacheOffset, pConstants, FirstConstant, NumConstants);
659674
}
660675

661676
IDeviceObject* ShaderVariableManagerVk::Get(Uint32 ArrayIndex, Uint32 ResIndex) const
@@ -664,7 +679,8 @@ IDeviceObject* ShaderVariableManagerVk::Get(Uint32 ArrayIndex, Uint32 ResIndex)
664679
const PipelineResourceAttribsVk& Attribs = GetResourceAttribs(ResIndex);
665680
const Uint32 CacheOffset = Attribs.CacheOffset(m_ResourceCache.GetContentType());
666681

667-
VERIFY_EXPR(ArrayIndex < ResDesc.ArraySize);
682+
// For inline constants, GetArraySize() returns 1 (actual array size), while ArraySize is the number of constants
683+
VERIFY_EXPR(ArrayIndex < ResDesc.GetArraySize());
668684

669685
if (Attribs.DescrSet < m_ResourceCache.GetNumDescriptorSets())
670686
{

0 commit comments

Comments
 (0)