From d292417cdb06e30ee128eb70b947d7f851226c96 Mon Sep 17 00:00:00 2001 From: Adam Sawicki Date: Mon, 11 Jun 2018 12:48:46 +0200 Subject: [PATCH] Minor improvement in VmaBlockVector::Allocate. TestPool_SameSize: Added test for it. --- src/Tests.cpp | 17 +++++++++++++++++ src/vk_mem_alloc.h | 6 ++++++ 2 files changed, 23 insertions(+) diff --git a/src/Tests.cpp b/src/Tests.cpp index 46b456e..1881ff5 100644 --- a/src/Tests.cpp +++ b/src/Tests.cpp @@ -1585,6 +1585,23 @@ static void TestPool_SameSize() items.clear(); + //////////////////////////////////////////////////////////////////////////////// + // Test for allocation too large for pool + + { + VmaAllocationCreateInfo allocCreateInfo = {}; + allocCreateInfo.pool = pool; + + VkMemoryRequirements memReq; + memReq.memoryTypeBits = UINT32_MAX; + memReq.alignment = 1; + memReq.size = poolCreateInfo.blockSize + 4; + + VmaAllocation alloc = nullptr; + res = vmaAllocateMemory(g_hAllocator, &memReq, &allocCreateInfo, &alloc, nullptr); + assert(res == VK_ERROR_OUT_OF_DEVICE_MEMORY && alloc == nullptr); + } + vmaDestroyPool(g_hAllocator, pool); } diff --git a/src/vk_mem_alloc.h b/src/vk_mem_alloc.h index 91ae6f2..745dcb8 100644 --- a/src/vk_mem_alloc.h +++ b/src/vk_mem_alloc.h @@ -6694,6 +6694,12 @@ VkResult VmaBlockVector::Allocate( VmaSuballocationType suballocType, VmaAllocation* pAllocation) { + // Early reject: requested allocation size is larger that maximum block size for this block vector. + if(size > m_PreferredBlockSize) + { + return VK_ERROR_OUT_OF_DEVICE_MEMORY; + } + const bool mapped = (createInfo.flags & VMA_ALLOCATION_CREATE_MAPPED_BIT) != 0; const bool isUserDataString = (createInfo.flags & VMA_ALLOCATION_CREATE_USER_DATA_COPY_STRING_BIT) != 0;