VK_ERROR_OUT_OF_DEVICE_MEMORY during memory heap allocation
0 reputation · 23 Feb 2021, 21:30 UTC
0 reputation · 23 Feb 2021, 21:30 UTC
An application utilizing the Vulkan API manages memory by requesting specific heap types based on the VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT flag. While the allocation logic functions correctly on high-capacity development hardware, it fails on production devices with smaller VRAM footprints or different memory architectures.
The current implementation relies on querying vkGetPhysicalDeviceMemoryProperties, but the strategy for handling cases where the requested memory exceeds the available physical device heap remains undefined. There is uncertainty regarding whether to implement a fallback to system-visible memory or to dynamically scale asset quality based on the reported heap size.
28775 reputation · 24 Feb 2021, 04:57 UTC
1. Prioritization when the primary device‑local heap is exhausted
vkGetPhysicalDeviceMemoryProperties and build a list of memory types that satisfy both the required usage flags and the VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT property.VkMemoryHeap.size for each heap during initialization. Before calling vkAllocateMemory, compare the requested size against the heap’s remaining free space to predict VK_ERROR_OUT_OF_DEVICE_MEMORY and skip the call if it would fail.2. Mapping memory types portably across GPU vendors
VkPhysicalDeviceMemoryProperties prop; vkGetPhysicalDeviceMemoryProperties(phys, &prop);
for (uint32_t i = 0; i < prop.memoryTypeCount; ++i) {
if ((prop.memoryTypes[i].propertyFlags & requestedProps) == requestedProps &&
(prop.memoryTypes[i].propertyFlags & VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT)) {
// candidate device‑local type
}
}
VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT and repeat the scan.VkMemoryHeap.size and the corresponding VkMemoryType.propertyFlags so you can see the actual capacities.vkAllocateMemory, subtract the requested size from the free space you tracked. If the result is negative, skip the allocation and go to step 3.vkGetDeviceMemoryProperties (if available) or keep a mapping table. Verify that the allocation succeeded and that the heap size is sufficient.Do you have the exact size of the asset you are trying to allocate on the production device? Knowing the requested size relative to the reported heap sizes can help refine the fallback selection logic.
Use comments to ask for clarification. Post a solution as an answer.
28,775 reputation · 24 Feb 2021, 08:39 UTC
When vkAllocateMemory returns VK_ERROR_OUT_OF_DEVICE_MEMORY, first verify that the requested size does not exceed VkMemoryHeap.size for the heap index of the chosen memory type.