diff --git a/include/vk_mem_alloc.h b/include/vk_mem_alloc.h index 25f72a5..a9cefa6 100644 --- a/include/vk_mem_alloc.h +++ b/include/vk_mem_alloc.h @@ -7767,13 +7767,10 @@ void VmaBlockMetadata_Generic::Init(VkDeviceSize size) suballoc.offset = 0; suballoc.size = size; suballoc.type = VMA_SUBALLOCATION_TYPE_FREE; - suballoc.userData = VMA_NULL; VMA_ASSERT(size > VMA_MIN_FREE_SUBALLOCATION_SIZE_TO_REGISTER); m_Suballocations.push_back(suballoc); - VmaSuballocationList::iterator suballocItem = m_Suballocations.end(); - --suballocItem; - m_FreeSuballocationsBySize.push_back(suballocItem); + m_FreeSuballocationsBySize.push_back(m_Suballocations.begin()); } bool VmaBlockMetadata_Generic::Validate() const @@ -8288,7 +8285,22 @@ void VmaBlockMetadata_Generic::GetAllocationInfo(VkDeviceSize offset, VmaVirtual void VmaBlockMetadata_Generic::Clear() { - VMA_ASSERT(0 && "TODO implement"); + const VkDeviceSize size = GetSize(); + + VMA_ASSERT(IsVirtual()); + m_FreeCount = 1; + m_SumFreeSize = size; + m_Suballocations.clear(); + m_FreeSuballocationsBySize.clear(); + + VmaSuballocation suballoc = {}; + suballoc.offset = 0; + suballoc.size = size; + suballoc.type = VMA_SUBALLOCATION_TYPE_FREE; + m_Suballocations.push_back(suballoc); + + VMA_ASSERT(size > VMA_MIN_FREE_SUBALLOCATION_SIZE_TO_REGISTER); + m_FreeSuballocationsBySize.push_back(m_Suballocations.begin()); } void VmaBlockMetadata_Generic::SetAllocationUserData(VkDeviceSize offset, void* userData) diff --git a/src/Tests.cpp b/src/Tests.cpp index 2c85b76..0c562df 100644 --- a/src/Tests.cpp +++ b/src/Tests.cpp @@ -2799,9 +2799,24 @@ static void TestVirtualBlocks() // # Final cleanup vmaVirtualFree(block, alloc2Offset); - - //vmaClearVirtualBlock(block); vmaDestroyVirtualBlock(block); + + { + // Another virtual block, using Clear this time. + TEST(vmaCreateVirtualBlock(&blockCreateInfo, &block) == VK_SUCCESS); + + allocCreateInfo = VmaVirtualAllocationCreateInfo{}; + allocCreateInfo.size = MEGABYTE; + + for(size_t i = 0; i < 8; ++i) + { + VkDeviceSize offset = 0; + TEST(vmaVirtualAllocate(block, &allocCreateInfo, &offset) == VK_SUCCESS); + } + + vmaClearVirtualBlock(block); + vmaDestroyVirtualBlock(block); + } } static void TestAllocationVersusResourceSize() @@ -6679,7 +6694,7 @@ void Test() { wprintf(L"TESTING:\n"); - if(true) + if(false) { //////////////////////////////////////////////////////////////////////////////// // Temporarily insert custom tests here: