@@ -4617,7 +4617,7 @@ in a single VkDeviceMemory block.
46174617class VmaBlockMetadata
46184618{
46194619public:
4620- VmaBlockMetadata () : m_Size( 0 ) { }
4620+ VmaBlockMetadata (VmaAllocator hAllocator);
46214621 virtual ~VmaBlockMetadata () { }
46224622 virtual void Init (VkDeviceSize size) { m_Size = size; }
46234623
@@ -4675,6 +4675,8 @@ class VmaBlockMetadata
46754675 virtual void FreeAtOffset (VkDeviceSize offset) = 0;
46764676
46774677protected:
4678+ const VkAllocationCallbacks* GetAllocationCallbacks () const { return m_pAllocationCallbacks; }
4679+
46784680#if VMA_STATS_STRING_ENABLED
46794681 void PrintDetailedMap_Begin (class VmaJsonWriter & json,
46804682 VkDeviceSize unusedBytes,
@@ -4691,6 +4693,7 @@ class VmaBlockMetadata
46914693
46924694private:
46934695 VkDeviceSize m_Size;
4696+ const VkAllocationCallbacks* m_pAllocationCallbacks;
46944697};
46954698
46964699#define VMA_VALIDATE (cond ) do { if (!(cond)) { \
@@ -6540,6 +6543,12 @@ struct VmaSuballocationItemSizeLess
65406543// //////////////////////////////////////////////////////////////////////////////
65416544// class VmaBlockMetadata
65426545
6546+ VmaBlockMetadata::VmaBlockMetadata (VmaAllocator hAllocator) :
6547+ m_Size(0 ),
6548+ m_pAllocationCallbacks(hAllocator->GetAllocationCallbacks ())
6549+ {
6550+ }
6551+
65436552#if VMA_STATS_STRING_ENABLED
65446553
65456554void VmaBlockMetadata::PrintDetailedMap_Begin (class VmaJsonWriter & json,
@@ -6609,6 +6618,7 @@ void VmaBlockMetadata::PrintDetailedMap_End(class VmaJsonWriter& json) const
66096618// class VmaBlockMetadata_Generic
66106619
66116620VmaBlockMetadata_Generic::VmaBlockMetadata_Generic (VmaAllocator hAllocator) :
6621+ VmaBlockMetadata(hAllocator),
66126622 m_FreeCount(0 ),
66136623 m_SumFreeSize(0 ),
66146624 m_Suballocations(VmaStlAllocator<VmaSuballocation>(hAllocator->GetAllocationCallbacks ())),
@@ -7538,6 +7548,7 @@ void VmaBlockMetadata_Generic::UnregisterFreeSuballocation(VmaSuballocationList:
75387548// class VmaBlockMetadata_Linear
75397549
75407550VmaBlockMetadata_Linear::VmaBlockMetadata_Linear (VmaAllocator hAllocator) :
7551+ VmaBlockMetadata(hAllocator),
75417552 m_SumFreeSize(0 ),
75427553 m_Suballocations0(VmaStlAllocator<VmaSuballocation>(hAllocator->GetAllocationCallbacks ())),
75437554 m_Suballocations1(VmaStlAllocator<VmaSuballocation>(hAllocator->GetAllocationCallbacks ())),
@@ -9215,6 +9226,7 @@ void VmaBlockMetadata_Linear::CleanupAfterFree()
92159226// class VmaBlockMetadata_Buddy
92169227
92179228VmaBlockMetadata_Buddy::VmaBlockMetadata_Buddy (VmaAllocator hAllocator) :
9229+ VmaBlockMetadata(hAllocator),
92189230 m_Root(VMA_NULL),
92199231 m_AllocationCount(0 ),
92209232 m_FreeCount(1 ),
@@ -9243,7 +9255,7 @@ void VmaBlockMetadata_Buddy::Init(VkDeviceSize size)
92439255 ++m_LevelCount;
92449256 }
92459257
9246- Node* rootNode = new Node ();
9258+ Node* rootNode = vma_new ( GetAllocationCallbacks (), Node) ();
92479259 rootNode->offset = 0 ;
92489260 rootNode->type = Node::TYPE_FREE;
92499261 rootNode->parent = VMA_NULL;
@@ -9478,8 +9490,8 @@ void VmaBlockMetadata_Buddy::Alloc(
94789490 const uint32_t childrenLevel = currLevel + 1 ;
94799491
94809492 // Create two free sub-nodes.
9481- Node* leftChild = new Node ();
9482- Node* rightChild = new Node ();
9493+ Node* leftChild = vma_new ( GetAllocationCallbacks (), Node) ();
9494+ Node* rightChild = vma_new ( GetAllocationCallbacks (), Node) ();
94839495
94849496 leftChild->offset = currNode->offset ;
94859497 leftChild->type = Node::TYPE_FREE;
@@ -9533,7 +9545,7 @@ void VmaBlockMetadata_Buddy::DeleteNode(Node* node)
95339545 DeleteNode (node->split .leftChild );
95349546 }
95359547
9536- delete node;
9548+ vma_delete ( GetAllocationCallbacks (), node) ;
95379549}
95389550
95399551bool VmaBlockMetadata_Buddy::ValidateNode (ValidationContext& ctx, const Node* parent, const Node* curr, uint32_t level, VkDeviceSize levelNodeSize) const
@@ -9633,8 +9645,8 @@ void VmaBlockMetadata_Buddy::FreeAtOffset(VmaAllocation alloc, VkDeviceSize offs
96339645 RemoveFromFreeList (level, node->buddy );
96349646 Node* const parent = node->parent ;
96359647
9636- delete node->buddy ;
9637- delete node;
9648+ vma_delete ( GetAllocationCallbacks (), node->buddy ) ;
9649+ vma_delete ( GetAllocationCallbacks (), node) ;
96389650 parent->type = Node::TYPE_FREE;
96399651
96409652 node = parent;
@@ -12474,7 +12486,7 @@ VkResult VmaAllocator_T::Defragment(
1247412486 // This allocation belongs to custom pool.
1247512487 if (hAllocPool != VK_NULL_HANDLE)
1247612488 {
12477- // Pools with linear algorithm are not defragmented.
12489+ // Pools with linear or buddy algorithm are not defragmented.
1247812490 if (hAllocPool->m_BlockVector .GetAlgorithm () == 0 )
1247912491 {
1248012492 pAllocBlockVector = &hAllocPool->m_BlockVector ;
0 commit comments