In your project code:
- Include "vk_mem_alloc.h" file wherever you want to use the library.
- In exacly one C++ file define following macro before include to build library implementation.
#define VMA_IMPLEMENTATION
#include "vk_mem_alloc.h"
At program startup:
- Initialize Vulkan to have
VkPhysicalDevice
and VkDevice
object.
- Fill VmaAllocatorCreateInfo structure and create
VmaAllocator
object by calling vmaCreateAllocator().
allocatorInfo.
device = device;
VmaAllocator allocator;
When you want to create a buffer or image:
- Fill
VkBufferCreateInfo
/ VkImageCreateInfo
structure.
- Fill VmaAllocationCreateInfo structure.
- Call vmaCreateBuffer() / vmaCreateImage() to get
VkBuffer
/VkImage
with memory already allocated and bound to it.
VkBufferCreateInfo bufferInfo = { VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO };
bufferInfo.size = 65536;
bufferInfo.usage = VK_BUFFER_USAGE_VERTEX_BUFFER_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT;
VkBuffer buffer;
VmaAllocation allocation;
vmaCreateBuffer(allocator, &bufferInfo, &allocInfo, &buffer, &allocation,
nullptr);
Don't forget to destroy your objects when no longer needed: