Do not exceed heap size when allocating memory
authorSlawomir Cygan <slawomir.cygan@intel.com>
Wed, 19 May 2021 15:18:48 +0000 (17:18 +0200)
committerAlexander Galazin <Alexander.Galazin@arm.com>
Wed, 16 Jun 2021 06:51:29 +0000 (06:51 +0000)
It is invalid to make larger allocations than heap size.

Components: Vulkan

VK-GL-CTS Issue: 2927

Change-Id: I738356254d95a152a2bb89d711eb6b3f047b405c
Affects: dEQP-VK.memory.mapping

external/vulkancts/modules/vulkan/memory/vktMemoryMappingTests.cpp

index 221cea4..a9bf33a 100644 (file)
@@ -1189,7 +1189,9 @@ MemoryObject* MemoryHeap::allocateRandom (const DeviceInterface& vkd, VkDevice d
                                // atomSizeBits = atomSize * 8
                                // maxAllocationSizeBytes == atomSize * 8 * availableBits / (17 * atomSize * 8 + 8)
                                // maxAllocationSizeBytes == atomSize * availableBits / (17 * atomSize + 1)
-                               const VkDeviceSize      maxAllocationSize               = roundDownToMultiple(((atomSize * availableBits) / (17 * atomSize + 1)), allocationSizeGranularity);
+                               //
+                               // Finally, the allocation size must be less than or equal to memory heap size
+                               const VkDeviceSize      maxAllocationSize               = roundDownToMultiple(de::min((atomSize * availableBits) / (17 * atomSize + 1), availableInHeap), allocationSizeGranularity);
 
                                DE_ASSERT(totalUsage <= totalSysMem);
                                DE_ASSERT(maxAllocationSize <= totalSysMem);
@@ -1219,7 +1221,9 @@ MemoryObject* MemoryHeap::allocateRandom (const DeviceInterface& vkd, VkDevice d
                                // maxRefBits = 8 * atomSize * 8 * availableRefBits / (9 * atomSize * 8 + 8)
                                // maxRefBits = atomSize * 8 * availableRefBits / (9 * atomSize + 1)
                                // maxRefBytes = atomSize * availableRefBits / (9 * atomSize + 1)
-                               const VkDeviceSize      maxAllocationSize       = roundDownToMultiple(de::min(totalMemClass - usedMemClass, (atomSize * 8 * (totalSysMem - totalUsage)) / (9 * atomSize + 1)), allocationSizeGranularity);
+                               //
+                               // Finally, the allocation size must be less than or equal to memory heap size
+                               const VkDeviceSize      maxAllocationSize = roundDownToMultiple(de::min(de::min(totalMemClass - usedMemClass, (atomSize * 8 * (totalSysMem - totalUsage)) / (9 * atomSize + 1)), availableInHeap), allocationSizeGranularity);
 
                                DE_ASSERT(usedMemClass <= totalMemClass);