@@ -162,6 +162,22 @@ class BufferSuballocatorImpl final : public ObjectBase<IBufferSuballocator>
162162 if (Size != m_Buffer.GetDesc ().Size )
163163 {
164164 m_Buffer.Resize (pDevice, pContext, Size);
165+
166+ // Actual buffer size may be larger due to alignment requirements
167+ // (for sparse buffers, the size is aligned by the memory page size)
168+ const auto BufferSize = m_Buffer.GetDesc ().Size ;
169+ VERIFY_EXPR (BufferSize >= Size);
170+ if (BufferSize > Size)
171+ {
172+ std::lock_guard<std::mutex> Lock{m_MgrMtx};
173+ // Since we released the mutex, the size may have changed in other thread
174+ Size = m_Mgr.GetMaxSize ();
175+ if (BufferSize > Size)
176+ {
177+ m_Mgr.Extend (StaticCast<size_t >(BufferSize - Size));
178+ }
179+ VERIFY_EXPR (BufferSize == m_Mgr.GetMaxSize ());
180+ }
165181 }
166182
167183 return m_Buffer.GetBuffer (pDevice, pContext);
@@ -230,9 +246,9 @@ class BufferSuballocatorImpl final : public ObjectBase<IBufferSuballocator>
230246 virtual void GetUsageStats (BufferSuballocatorUsageStats& UsageStats) override final
231247 {
232248 std::lock_guard<std::mutex> Lock{m_MgrMtx};
233- UsageStats.Size = static_cast <Uint32>( m_Mgr.GetMaxSize () );
234- UsageStats.UsedSize = static_cast <Uint32>( m_Mgr.GetUsedSize () );
235- UsageStats.MaxFreeChunkSize = static_cast <Uint32>( m_Mgr.GetMaxFreeBlockSize () );
249+ UsageStats.Size = m_Mgr.GetMaxSize ();
250+ UsageStats.UsedSize = m_Mgr.GetUsedSize ();
251+ UsageStats.MaxFreeChunkSize = m_Mgr.GetMaxFreeBlockSize ();
236252 UsageStats.AllocationCount = m_AllocationCount.load ();
237253 }
238254
0 commit comments