Added VmaDefragmentationInfo::customBreakCallback - a callback pointer of new type PFN_vmaCheckDefragmentationBreak
diff --git a/include/vk_mem_alloc.h b/include/vk_mem_alloc.h index fbe4f13..a61a77d 100644 --- a/include/vk_mem_alloc.h +++ b/include/vk_mem_alloc.h
@@ -1395,6 +1395,12 @@ const char* VMA_NULLABLE pName; } VmaAllocationInfo; +/** Callback function called during defragmentation to check custom criterion about ending current defragmentation pass. + +Should return 'true' if the defragmentation needs to stop current pass. +*/ +typedef VkBool32 (VKAPI_PTR* PFN_vmaCheckDefragmentationBreak)(); + /** \brief Parameters for defragmentation. To be used with function vmaBeginDefragmentation(). @@ -1418,6 +1424,11 @@ `0` means no limit. */ uint32_t maxAllocationsPerPass; + /** \brief Optional custom callback for stopping pass of defragmentation. + + Have to return 'VK_TRUE' for breaking current defragmentation pass. + */ + PFN_vmaCheckDefragmentationBreak customBreakCallback; } VmaDefragmentationInfo; /// Single move of an allocation to be done for defragmentation. @@ -11044,6 +11055,7 @@ const VkDeviceSize m_MaxPassBytes; const uint32_t m_MaxPassAllocations; + const PFN_vmaCheckDefragmentationBreak m_IsBreak; VmaStlAllocator<VmaDefragmentationMove> m_MoveAllocator; VmaVector<VmaDefragmentationMove, VmaStlAllocator<VmaDefragmentationMove>> m_Moves; @@ -12974,6 +12986,7 @@ const VmaDefragmentationInfo& info) : m_MaxPassBytes(info.maxBytesPerPass == 0 ? VK_WHOLE_SIZE : info.maxBytesPerPass), m_MaxPassAllocations(info.maxAllocationsPerPass == 0 ? UINT32_MAX : info.maxAllocationsPerPass), + m_IsBreak(info.customBreakCallback), m_MoveAllocator(hAllocator->GetAllocationCallbacks()), m_Moves(m_MoveAllocator) { @@ -13369,6 +13382,10 @@ VmaDefragmentationContext_T::CounterStatus VmaDefragmentationContext_T::CheckCounters(VkDeviceSize bytes) { + // Check custom criteria if exists + if (m_IsBreak && m_IsBreak()) + return CounterStatus::End; + // Ignore allocation if will exceed max size for copy if (m_PassStats.bytesMoved + bytes > m_MaxPassBytes) {