@@ -54,39 +54,49 @@ size_t ShaderResourceCacheGL::GetRequiredMemorySize(const TResourceCount& ResCou
5454 return MemSize;
5555}
5656
57- void ShaderResourceCacheGL::Initialize (const TResourceCount& ResCount, IMemoryAllocator& MemAllocator, Uint64 DynamicUBOSlotMask, Uint64 DynamicSSBOSlotMask, Uint32 TotalInlineConstants )
57+ void ShaderResourceCacheGL::Initialize (const InitAttribs& Attribs )
5858{
59- m_DynamicUBOSlotMask = DynamicUBOSlotMask;
60- m_DynamicSSBOSlotMask = DynamicSSBOSlotMask;
61- m_HasInlineConstants = (TotalInlineConstants > 0 );
62- #ifdef DILIGENT_DEBUG
63- m_DbgAssignedInlineConstants.resize (TotalInlineConstants);
64- #endif
65-
6659 VERIFY (!m_pResourceData, " Cache has already been initialized" );
6760
61+ m_DynamicUBOSlotMask = Attribs.DynamicUBOSlotMask ;
62+ m_DynamicSSBOSlotMask = Attribs.DynamicSSBOSlotMask ;
63+
64+ const TResourceCount& ResCount = Attribs.ResCount ;
65+
66+ // Count the total number of inline constants in range
67+ Uint32 TotalInlineConstants = 0 ;
68+ for (Uint32 i = 0 ; i < Attribs.NumInlineConstantBuffers ; ++i)
69+ {
70+ const InlineConstantBufferAttribsGL& InlineCBAttribs = Attribs.pInlineConstantBuffers [i];
71+ if (InlineCBAttribs.CacheOffset < ResCount[BINDING_RANGE_UNIFORM_BUFFER])
72+ TotalInlineConstants += InlineCBAttribs.NumConstants ;
73+ }
74+ VERIFY_EXPR (TotalInlineConstants == Attribs.DbgTotalInlineConstants );
75+
76+ m_HasInlineConstants = (TotalInlineConstants > 0 );
77+
6878 // clang-format off
6979 m_TexturesOffset = static_cast <Uint16>(m_UBsOffset + sizeof (CachedUB) * ResCount[BINDING_RANGE_UNIFORM_BUFFER]);
7080 m_ImagesOffset = static_cast <Uint16>(m_TexturesOffset + sizeof (CachedResourceView) * ResCount[BINDING_RANGE_TEXTURE]);
7181 m_SSBOsOffset = static_cast <Uint16>(m_ImagesOffset + sizeof (CachedResourceView) * ResCount[BINDING_RANGE_IMAGE]);
72- m_MemoryEndOffset = static_cast <Uint16>(m_SSBOsOffset + sizeof (CachedSSBO) * ResCount[BINDING_RANGE_STORAGE_BUFFER]);
82+ m_ResourceEndOffset = static_cast <Uint16>(m_SSBOsOffset + sizeof (CachedSSBO) * ResCount[BINDING_RANGE_STORAGE_BUFFER]);
7383
7484 VERIFY_EXPR (GetUBCount () == static_cast <Uint32>(ResCount[BINDING_RANGE_UNIFORM_BUFFER]));
7585 VERIFY_EXPR (GetTextureCount () == static_cast <Uint32>(ResCount[BINDING_RANGE_TEXTURE]));
7686 VERIFY_EXPR (GetImageCount () == static_cast <Uint32>(ResCount[BINDING_RANGE_IMAGE]));
7787 VERIFY_EXPR (GetSSBOCount () == static_cast <Uint32>(ResCount[BINDING_RANGE_STORAGE_BUFFER]));
7888 // clang-format on
7989
80- // Inline constant data tail is after m_MemoryEndOffset
81- size_t BufferSize = m_MemoryEndOffset + TotalInlineConstants * sizeof (Uint32);
90+ // Inline constant data tail is after m_ResourceEndOffset
91+ size_t BufferSize = m_ResourceEndOffset + TotalInlineConstants * sizeof (Uint32);
8292
8393 VERIFY_EXPR (BufferSize == GetRequiredMemorySize (ResCount, TotalInlineConstants));
8494
8595 if (BufferSize > 0 )
8696 {
8797 m_pResourceData = decltype (m_pResourceData){
88- ALLOCATE (MemAllocator, " Shader resource cache data buffer" , Uint8, BufferSize),
89- STDDeleter<Uint8, IMemoryAllocator>(MemAllocator) //
98+ ALLOCATE (Attribs. MemAllocator , " Shader resource cache data buffer" , Uint8, BufferSize),
99+ STDDeleter<Uint8, IMemoryAllocator>(Attribs. MemAllocator ) //
90100 };
91101 memset (m_pResourceData.get (), 0 , BufferSize);
92102 }
@@ -103,6 +113,26 @@ void ShaderResourceCacheGL::Initialize(const TResourceCount& ResCount, IMemoryAl
103113
104114 for (Uint32 s = 0 ; s < GetSSBOCount (); ++s)
105115 new (&GetSSBO (s)) CachedSSBO;
116+
117+ // Initialize inline constant buffers
118+ Uint32 InlineConstantOffset = 0 ;
119+ for (Uint32 i = 0 ; i < Attribs.NumInlineConstantBuffers ; ++i)
120+ {
121+ const InlineConstantBufferAttribsGL& InlineCBAttribs = Attribs.pInlineConstantBuffers [i];
122+ if (InlineCBAttribs.CacheOffset < ResCount[BINDING_RANGE_UNIFORM_BUFFER])
123+ {
124+ CachedUB& UB = GetUB (InlineCBAttribs.CacheOffset );
125+ UB.pBuffer = InlineCBAttribs.pBuffer ;
126+ UB.BaseOffset = 0 ;
127+ UB.RangeSize = InlineCBAttribs.NumConstants * sizeof (Uint32);
128+ UB.DynamicOffset = 0 ;
129+ UB.pInlineConstantData = reinterpret_cast <Uint32*>(m_pResourceData.get () + m_ResourceEndOffset) + InlineConstantOffset;
130+
131+ InlineConstantOffset += InlineCBAttribs.NumConstants ;
132+ }
133+ }
134+
135+ VERIFY_EXPR (InlineConstantOffset == TotalInlineConstants);
106136}
107137
108138ShaderResourceCacheGL::~ShaderResourceCacheGL ()
@@ -121,10 +151,10 @@ ShaderResourceCacheGL::~ShaderResourceCacheGL()
121151 for (Uint32 s = 0 ; s < GetSSBOCount (); ++s)
122152 GetSSBO (s).~CachedSSBO ();
123153
124- m_TexturesOffset = InvalidResourceOffset;
125- m_ImagesOffset = InvalidResourceOffset;
126- m_SSBOsOffset = InvalidResourceOffset;
127- m_MemoryEndOffset = InvalidResourceOffset;
154+ m_TexturesOffset = InvalidResourceOffset;
155+ m_ImagesOffset = InvalidResourceOffset;
156+ m_SSBOsOffset = InvalidResourceOffset;
157+ m_ResourceEndOffset = InvalidResourceOffset;
128158 }
129159 m_pResourceData.reset ();
130160}
@@ -345,35 +375,6 @@ void ShaderResourceCacheGL::BindDynamicBuffers(GLContextState& GLSt
345375 }
346376}
347377
348- void ShaderResourceCacheGL::InitInlineConstantBuffer (Uint32 CacheOffset,
349- RefCntAutoPtr<BufferGLImpl> pBuffer,
350- Uint32 NumConstants,
351- Uint32 InlineConstantOffset)
352- {
353- VERIFY_EXPR (pBuffer);
354- VERIFY_EXPR (m_HasInlineConstants);
355- VERIFY_EXPR (m_pResourceData);
356-
357- #ifdef DILIGENT_DEBUG
358- if (InlineConstantOffset != ~0u )
359- {
360- VERIFY (InlineConstantOffset + NumConstants <= m_DbgAssignedInlineConstants.size (), " Inline constant storage overflow" );
361- for (Uint32 i = 0 ; i < NumConstants; ++i)
362- {
363- VERIFY (!m_DbgAssignedInlineConstants[InlineConstantOffset + i], " Inline constant storage at offset " , InlineConstantOffset + i, " has already been assigned" );
364- m_DbgAssignedInlineConstants[InlineConstantOffset + i] = true ;
365- }
366- }
367- #endif
368-
369- CachedUB& UB = GetUB (CacheOffset);
370- UB.pBuffer = std::move (pBuffer);
371- UB.BaseOffset = 0 ;
372- UB.RangeSize = NumConstants * sizeof (Uint32);
373- UB.DynamicOffset = 0 ;
374- UB.pInlineConstantData = reinterpret_cast <Uint32*>(m_pResourceData.get () + m_MemoryEndOffset) + InlineConstantOffset;
375- }
376-
377378void ShaderResourceCacheGL::CopyInlineConstants (const ShaderResourceCacheGL& SrcCache,
378379 Uint32 CacheOffset,
379380 Uint32 NumConstants)
@@ -411,14 +412,6 @@ void ShaderResourceCacheGL::DbgVerifyDynamicBufferMasks() const
411412 VERIFY (((m_DynamicSSBOMask & SSBOBit) != 0 ) == (SSBO.IsDynamic () && (m_DynamicSSBOSlotMask & SSBOBit) != 0 ), " Bit " , ssbo, " in m_DynamicSSBOMask is invalid" );
412413 }
413414}
414-
415- void ShaderResourceCacheGL::DbgVerifyResourceInitialization () const
416- {
417- for (bool InlineConstAssigned : m_DbgAssignedInlineConstants)
418- {
419- VERIFY (InlineConstAssigned, " Not all inline constant storage has been assigned. This is a bug." );
420- }
421- }
422415#endif
423416
424417} // namespace Diligent
0 commit comments