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
This commit is contained in:
Adam Sawicki 2025-03-26 20:46:38 +01:00
parent c578a4f4f1
commit 89d3a6a5ea

View file

@ -3276,7 +3276,18 @@ If providing your own implementation, you need to implement a subset of std::ato
Set this to 1 to make VMA never exceed VkPhysicalDeviceLimits::maxMemoryAllocationCount Set this to 1 to make VMA never exceed VkPhysicalDeviceLimits::maxMemoryAllocationCount
and return error instead of leaving up to Vulkan implementation what to do in such cases. and return error instead of leaving up to Vulkan implementation what to do in such cases.
*/ */
#define VMA_DEBUG_DONT_EXCEED_MAX_MEMORY_ALLOCATION_COUNT (0) #define VMA_DEBUG_DONT_EXCEED_MAX_MEMORY_ALLOCATION_COUNT (1)
#endif
#ifndef VMA_DEBUG_DONT_EXCEED_HEAP_SIZE_WITH_ALLOCATION_SIZE
/*
Set this to 1 to make VMA never exceed VkPhysicalDeviceMemoryProperties::memoryHeaps[i].size
with a single allocation size VkMemoryAllocateInfo::allocationSize
and return error instead of leaving up to Vulkan implementation what to do in such cases.
It protects agaist validation error VUID-vkAllocateMemory-pAllocateInfo-01713.
On the other hand, allowing exceeding this size may result in a successful allocation despite the validation error.
*/
#define VMA_DEBUG_DONT_EXCEED_HEAP_SIZE_WITH_ALLOCATION_SIZE (1)
#endif #endif
#ifndef VMA_SMALL_HEAP_MAX_SIZE #ifndef VMA_SMALL_HEAP_MAX_SIZE
@ -14415,6 +14426,15 @@ VkResult VmaAllocator_T::CheckCorruption(uint32_t memoryTypeBits)
VkResult VmaAllocator_T::AllocateVulkanMemory(const VkMemoryAllocateInfo* pAllocateInfo, VkDeviceMemory* pMemory) VkResult VmaAllocator_T::AllocateVulkanMemory(const VkMemoryAllocateInfo* pAllocateInfo, VkDeviceMemory* pMemory)
{ {
const uint32_t heapIndex = MemoryTypeIndexToHeapIndex(pAllocateInfo->memoryTypeIndex);
#if VMA_DEBUG_DONT_EXCEED_HEAP_SIZE_WITH_ALLOCATION_SIZE
if (pAllocateInfo->allocationSize > m_MemProps.memoryHeaps[heapIndex].size)
{
return VK_ERROR_OUT_OF_DEVICE_MEMORY;
}
#endif
AtomicTransactionalIncrement<VMA_ATOMIC_UINT32> deviceMemoryCountIncrement; AtomicTransactionalIncrement<VMA_ATOMIC_UINT32> deviceMemoryCountIncrement;
const uint64_t prevDeviceMemoryCount = deviceMemoryCountIncrement.Increment(&m_DeviceMemoryCount); const uint64_t prevDeviceMemoryCount = deviceMemoryCountIncrement.Increment(&m_DeviceMemoryCount);
#if VMA_DEBUG_DONT_EXCEED_MAX_MEMORY_ALLOCATION_COUNT #if VMA_DEBUG_DONT_EXCEED_MAX_MEMORY_ALLOCATION_COUNT
@ -14424,8 +14444,6 @@ VkResult VmaAllocator_T::AllocateVulkanMemory(const VkMemoryAllocateInfo* pAlloc
} }
#endif #endif
const uint32_t heapIndex = MemoryTypeIndexToHeapIndex(pAllocateInfo->memoryTypeIndex);
// HeapSizeLimit is in effect for this heap. // HeapSizeLimit is in effect for this heap.
if((m_HeapSizeLimitMask & (1u << heapIndex)) != 0) if((m_HeapSizeLimitMask & (1u << heapIndex)) != 0)
{ {