From 6c1c16f05c067790eb9bfa2b81212720bdc96238 Mon Sep 17 00:00:00 2001 From: Adam Sawicki Date: Wed, 26 Jan 2022 17:46:38 +0100 Subject: [PATCH] Misc minor fixes --- include/vk_mem_alloc.h | 15 +++++---------- src/Tests.cpp | 8 ++++---- 2 files changed, 9 insertions(+), 14 deletions(-) diff --git a/include/vk_mem_alloc.h b/include/vk_mem_alloc.h index 9f16ee4..487cbcb 100644 --- a/include/vk_mem_alloc.h +++ b/include/vk_mem_alloc.h @@ -9639,11 +9639,6 @@ private: static const uint32_t INITIAL_BLOCK_ALLOC_COUNT = 16; static const uint8_t MEMORY_CLASS_SHIFT = 7; - struct RegionInfo - { - uint8_t allocType; - uint16_t allocCount; - }; class Block { public: @@ -9717,7 +9712,7 @@ VmaBlockMetadata_TLSF::VmaBlockMetadata_TLSF(const VkAllocationCallbacks* pAlloc m_InnerIsFree(VMA_NULL), m_ListsCount(0), m_FreeList(VMA_NULL), - m_BlockAllocator(pAllocationCallbacks, INITIAL_BLOCK_ALLOC_COUNT * sizeof(Block)), + m_BlockAllocator(pAllocationCallbacks, INITIAL_BLOCK_ALLOC_COUNT), m_NullBlock(VMA_NULL), m_GranularityHandler(bufferImageGranularity) {} @@ -9909,7 +9904,7 @@ void VmaBlockMetadata_TLSF::PrintDetailedMap(class VmaJsonWriter& json) const if (block->IsFree()) PrintDetailedMap_UnusedRange(json, block->offset, block->size); else - PrintDetailedMap_Allocation(json, block->offset, block->size, block->PrevFree()); + PrintDetailedMap_Allocation(json, block->offset, block->size, block->UserData()); } if (m_NullBlock->size > 0) PrintDetailedMap_UnusedRange(json, m_NullBlock->offset, m_NullBlock->size); @@ -9942,7 +9937,7 @@ bool VmaBlockMetadata_TLSF::CreateAllocationRequest( return CheckBlock(*m_NullBlock, m_ListsCount, allocSize, allocAlignment, allocType, pAllocationRequest); VkDeviceSize roundedSize = allocSize; - if (allocSize >= (1 << SECOND_LEVEL_INDEX)) + if (allocSize >= (1ULL << SECOND_LEVEL_INDEX)) { // Round up to the next block roundedSize += (1ULL << (VMA_BITSCAN_MSB(allocSize) - SECOND_LEVEL_INDEX)) - 1; @@ -9986,7 +9981,7 @@ bool VmaBlockMetadata_TLSF::CreateAllocationRequest( return true; } - // If all searches failed and first bucket still have some free regions then check it fully + // If all searches failed and first bucket still has some free regions then check it fully while (block) { if (CheckBlock(*block, listIndex, allocSize, allocAlignment, allocType, pAllocationRequest)) @@ -11042,7 +11037,7 @@ VkResult VmaVirtualBlock_T::Allocate(const VmaVirtualAllocationCreateInfo& creat *outOffset = m_Metadata->GetAllocationOffset(request.allocHandle); return VK_SUCCESS; } - outAllocation = (VmaVirtualAllocation)VK_WHOLE_SIZE; + outAllocation = (VmaVirtualAllocation)VK_NULL_HANDLE; return VK_ERROR_OUT_OF_DEVICE_MEMORY; } diff --git a/src/Tests.cpp b/src/Tests.cpp index fe943f1..7644989 100644 --- a/src/Tests.cpp +++ b/src/Tests.cpp @@ -2695,7 +2695,7 @@ static void TestVirtualBlocks() allocCreateInfo.alignment = alignment; allocCreateInfo.pUserData = (void*)(uintptr_t)1; allocCreateInfo.size = 8 * MEGABYTE; - VmaVirtualAllocation allocation0; + VmaVirtualAllocation allocation0 = VK_NULL_HANDLE; TEST(vmaVirtualAllocate(block, &allocCreateInfo, &allocation0, &offset) == VK_SUCCESS); // # Validate the allocation @@ -2716,7 +2716,7 @@ static void TestVirtualBlocks() // # Allocate 4 MB (also test passing null as pOffset during allocation) allocCreateInfo.size = 4 * MEGABYTE; - VmaVirtualAllocation allocation1; + VmaVirtualAllocation allocation1 = VK_NULL_HANDLE; TEST(vmaVirtualAllocate(block, &allocCreateInfo, &allocation1, nullptr) == VK_SUCCESS); VmaVirtualAllocationInfo allocInfo1 = {}; vmaGetVirtualAllocationInfo(block, allocation1, &allocInfo1); @@ -2726,9 +2726,9 @@ static void TestVirtualBlocks() // # Allocate another 8 MB - it should fail allocCreateInfo.size = 8 * MEGABYTE; - VmaVirtualAllocation allocation2; + VmaVirtualAllocation allocation2 = VK_NULL_HANDLE; TEST(vmaVirtualAllocate(block, &allocCreateInfo, &allocation2, nullptr) < 0); - TEST(allocation2 == (VmaVirtualAllocation)VK_WHOLE_SIZE); + TEST(allocation2 == VK_NULL_HANDLE); // # Free the 4 MB block. Now allocation of 8 MB should succeed.