Vulkan Memory Allocator
|
The library automatically creates and manages default memory pool for each memory type available on the device. A pool contains a number of VkDeviceMemory
blocks. You can create custom pool and allocate memory out of it. It can be useful if you want to:
To use custom memory pools:
VmaPool
handle.Example:
.// Create a pool that could have at most 2 blocks, 128 MB each. VmaPoolCreateInfo poolCreateInfo = {}; poolCreateInfo.memoryTypeIndex = ... poolCreateInfo.blockSize = 128ull * 1024 * 1024; poolCreateInfo.maxBlockCount = 2; VmaPool pool; vmaCreatePool(allocator, &poolCreateInfo, &pool); .// Allocate a buffer out of it. VkBufferCreateInfo bufCreateInfo = { VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO }; bufCreateInfo.size = 1024; bufCreateInfo.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT; VmaAllocationCreateInfo allocCreateInfo = {}; allocCreateInfo.pool = pool; VkBuffer buf; VmaAllocation alloc; VmaAllocationInfo allocInfo; vmaCreateBuffer(allocator, &bufCreateInfo, &allocCreateInfo, &buf, &alloc, &allocInfo);
You have to free all allocations made from this pool before destroying it.
vmaDestroyBuffer(allocator, buf, alloc); vmaDestroyPool(allocator, pool);