VulkanMemoryAllocator icon indicating copy to clipboard operation
VulkanMemoryAllocator copied to clipboard

Stack corruption calling vmaGetHeapBudgets without VK_EXT_memory_budget

Open rnbhatt opened this issue 1 year ago • 1 comments

The readme indicates that this should work regardless:

VK_EXT_memory_budget: Used internally if available to query for current usage and budget. If not available, it falls back to an estimation based on memory heap sizes.

However, the following code triggers a stack corruption assert in Visual Studio if called without the extension enabled:

size_t DeviceVk::GetCurrentVRAMInUse() const
{
    VmaBudget budgets;
    vmaGetHeapBudgets(vkallocator, &budgets);

    return budgets.usage;
}

image

The issue does not occur if the extension is enabled. Because only 5% of Android devices have this extension, it is important for this functionality to work without VK_EXT_memory_budget.

rnbhatt avatar Aug 20 '24 00:08 rnbhatt

Please read the documentation of function vmaGetHeapBudgets. The name uses plural form "heap budgets" for a reason. It returns budgets for all the memory heaps available in the Vulkan device. Parameter pBudgets:

Must point to array with number of elements at least equal to number of memory heaps in physical device used.

You pass a pointer to a single budget struct, hence the stack corruption.

adam-sawicki-a avatar Aug 20 '24 08:08 adam-sawicki-a