Skip to content

Commit 89d3a6a

Browse files
Added macro VMA_DEBUG_DONT_EXCEED_HEAP_SIZE_WITH_ALLOCATION_SIZE
Default to 1. Also changed VMA_DEBUG_DONT_EXCEED_MAX_MEMORY_ALLOCATION_COUNT to default to 1. Fixes #338
1 parent c578a4f commit 89d3a6a

File tree

1 file changed

+21
-3
lines changed

1 file changed

+21
-3
lines changed

include/vk_mem_alloc.h

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3276,7 +3276,18 @@ If providing your own implementation, you need to implement a subset of std::ato
32763276
Set this to 1 to make VMA never exceed VkPhysicalDeviceLimits::maxMemoryAllocationCount
32773277
and return error instead of leaving up to Vulkan implementation what to do in such cases.
32783278
*/
3279-
#define VMA_DEBUG_DONT_EXCEED_MAX_MEMORY_ALLOCATION_COUNT (0)
3279+
#define VMA_DEBUG_DONT_EXCEED_MAX_MEMORY_ALLOCATION_COUNT (1)
3280+
#endif
3281+
3282+
#ifndef VMA_DEBUG_DONT_EXCEED_HEAP_SIZE_WITH_ALLOCATION_SIZE
3283+
/*
3284+
Set this to 1 to make VMA never exceed VkPhysicalDeviceMemoryProperties::memoryHeaps[i].size
3285+
with a single allocation size VkMemoryAllocateInfo::allocationSize
3286+
and return error instead of leaving up to Vulkan implementation what to do in such cases.
3287+
It protects agaist validation error VUID-vkAllocateMemory-pAllocateInfo-01713.
3288+
On the other hand, allowing exceeding this size may result in a successful allocation despite the validation error.
3289+
*/
3290+
#define VMA_DEBUG_DONT_EXCEED_HEAP_SIZE_WITH_ALLOCATION_SIZE (1)
32803291
#endif
32813292

32823293
#ifndef VMA_SMALL_HEAP_MAX_SIZE
@@ -14415,6 +14426,15 @@ VkResult VmaAllocator_T::CheckCorruption(uint32_t memoryTypeBits)
1441514426

1441614427
VkResult VmaAllocator_T::AllocateVulkanMemory(const VkMemoryAllocateInfo* pAllocateInfo, VkDeviceMemory* pMemory)
1441714428
{
14429+
const uint32_t heapIndex = MemoryTypeIndexToHeapIndex(pAllocateInfo->memoryTypeIndex);
14430+
14431+
#if VMA_DEBUG_DONT_EXCEED_HEAP_SIZE_WITH_ALLOCATION_SIZE
14432+
if (pAllocateInfo->allocationSize > m_MemProps.memoryHeaps[heapIndex].size)
14433+
{
14434+
return VK_ERROR_OUT_OF_DEVICE_MEMORY;
14435+
}
14436+
#endif
14437+
1441814438
AtomicTransactionalIncrement<VMA_ATOMIC_UINT32> deviceMemoryCountIncrement;
1441914439
const uint64_t prevDeviceMemoryCount = deviceMemoryCountIncrement.Increment(&m_DeviceMemoryCount);
1442014440
#if VMA_DEBUG_DONT_EXCEED_MAX_MEMORY_ALLOCATION_COUNT
@@ -14424,8 +14444,6 @@ VkResult VmaAllocator_T::AllocateVulkanMemory(const VkMemoryAllocateInfo* pAlloc
1442414444
}
1442514445
#endif
1442614446

14427-
const uint32_t heapIndex = MemoryTypeIndexToHeapIndex(pAllocateInfo->memoryTypeIndex);
14428-
1442914447
// HeapSizeLimit is in effect for this heap.
1443014448
if((m_HeapSizeLimitMask & (1u << heapIndex)) != 0)
1443114449
{

0 commit comments

Comments
 (0)