3737// m_pMemory | | m_pResources, m_NumResources == m |
3838// | m_DescriptorSetAllocation| | |
3939// V | | V
40- // | DescriptorSet[0] | .... | DescriptorSet[Ns-1] | Res[0] | ... | Res[n-1] | .... | Res[0] | ... | Res[m-1] |
40+ // | DescriptorSet[0] | .... | DescriptorSet[Ns-1] | Res[0] | ... | Res[n-1] | .... | Res[0] | ... | Res[m-1] | Inline constant values |
4141// | | A \
4242// | | | \
4343// | |________________________________________________| \RefCntAutoPtr
@@ -74,7 +74,8 @@ class ShaderResourceCacheVk : public ShaderResourceCacheBase
7474public:
7575 explicit ShaderResourceCacheVk (ResourceCacheContentType ContentType) noexcept :
7676 m_TotalResources{0 },
77- m_ContentType{static_cast <Uint32>(ContentType)}
77+ m_ContentType{static_cast <Uint32>(ContentType)},
78+ m_HasInlineConstants{0 }
7879 {
7980 VERIFY_EXPR (GetContentType () == ContentType);
8081 }
@@ -88,12 +89,12 @@ class ShaderResourceCacheVk : public ShaderResourceCacheBase
8889
8990 ~ShaderResourceCacheVk ();
9091
91- static size_t GetRequiredMemorySize (Uint32 NumSets, const Uint32* SetSizes);
92+ static size_t GetRequiredMemorySize (Uint32 NumSets, const Uint32* SetSizes, Uint32 TotalInlineConstantBytes = 0 );
9293
93- void InitializeSets (IMemoryAllocator& MemAllocator, Uint32 NumSets, const Uint32* SetSizes);
94+ void InitializeSets (IMemoryAllocator& MemAllocator, Uint32 NumSets, const Uint32* SetSizes, Uint32 TotalInlineConstantBytes = 0 );
9495 void InitializeResources (Uint32 Set, Uint32 Offset, Uint32 ArraySize, DescriptorType Type, bool HasImmutableSampler);
9596
96- // sizeof(Resource) == 32 (x64, msvc, Release)
97+ // sizeof(Resource) == 40 (x64, msvc, Release)
9798 struct Resource
9899 {
99100 explicit Resource (DescriptorType _Type, bool _HasImmutableSampler) noexcept :
@@ -120,6 +121,10 @@ class ShaderResourceCacheVk : public ShaderResourceCacheBase
120121/* 16 */ Uint64 BufferBaseOffset = 0 ;
121122/* 24 */ Uint64 BufferRangeSize = 0 ;
122123
124+ // For inline constants only - pointer to CPU-side staging buffer
125+ /* 32 */ void * pInlineConstantData = nullptr ;
126+ /* 40 */ // End of structure
127+
123128 VkDescriptorBufferInfo GetUniformBufferDescriptorWriteInfo () const ;
124129 VkDescriptorBufferInfo GetStorageBufferDescriptorWriteInfo () const ;
125130 VkDescriptorImageInfo GetImageDescriptorWriteInfo () const ;
@@ -245,13 +250,46 @@ class ShaderResourceCacheVk : public ShaderResourceCacheBase
245250 Uint32 CacheOffset,
246251 Uint32 DynamicBufferOffset);
247252
253+ // Sets inline constant data in the resource cache
254+ void SetInlineConstants (Uint32 DescrSetIndex,
255+ Uint32 CacheOffset,
256+ const void * pConstants,
257+ Uint32 FirstConstant,
258+ Uint32 NumConstants);
259+
260+ // Gets the inline constant data pointer from the resource cache
261+ const void * GetInlineConstantData (Uint32 DescrSetIndex, Uint32 CacheOffset) const ;
262+
263+ // Initialize inline constant buffer in the resource cache
264+ void InitializeInlineConstantBuffer (Uint32 DescrSetIndex,
265+ Uint32 CacheOffset,
266+ Uint32 NumConstants,
267+ Uint32 InlineConstantOffset);
268+
269+ // Returns pointer to inline constant storage at the given byte offset
270+ void * GetInlineConstantStorage (Uint32 ByteOffset = 0 )
271+ {
272+ return reinterpret_cast <Uint8*>(GetFirstResourcePtr () + m_TotalResources) + ByteOffset;
273+ }
274+ const void * GetInlineConstantStorage (Uint32 ByteOffset = 0 ) const
275+ {
276+ return reinterpret_cast <const Uint8*>(GetFirstResourcePtr () + m_TotalResources) + ByteOffset;
277+ }
278+
279+ // Explicitly marks that this cache contains inline constants.
280+ // This is useful when inline constant memory is initialized externally
281+ // (e.g., during SRB cache setup) before any data is written.
282+ void MarkHasInlineConstants ()
283+ {
284+ m_HasInlineConstants = 1 ;
285+ }
248286
249287 Uint32 GetNumDescriptorSets () const { return m_NumSets; }
250288 bool HasDynamicResources () const { return m_NumDynamicBuffers > 0 ; }
251289
252290 bool HasInlineConstants () const
253291 {
254- return false ;
292+ return m_HasInlineConstants ;
255293 }
256294
257295 ResourceCacheContentType GetContentType () const { return static_cast <ResourceCacheContentType>(m_ContentType); }
@@ -292,11 +330,14 @@ class ShaderResourceCacheVk : public ShaderResourceCacheBase
292330 // Total actual number of dynamic buffers (that were created with USAGE_DYNAMIC) bound in the resource cache
293331 // regardless of the variable type. Note this variable is not equal to dynamic offsets count, which is constant.
294332 Uint16 m_NumDynamicBuffers = 0 ;
295- Uint32 m_TotalResources : 31 ;
333+ Uint32 m_TotalResources : 30 ;
296334
297335 // Indicates what types of resources are stored in the cache
298336 const Uint32 m_ContentType : 1 ;
299337
338+ // Indicates whether the cache contains inline constants
339+ Uint32 m_HasInlineConstants : 1 ;
340+
300341#ifdef DILIGENT_DEBUG
301342 // Debug array that stores flags indicating if resources in the cache have been initialized
302343 std::vector<std::vector<bool >> m_DbgInitializedResources;
0 commit comments