Vulkan Memory Allocator
Classes | Macros | Typedefs | Enumerations | Functions
vk_mem_alloc.h File Reference
#include <vulkan/vulkan.h>

Classes

struct  VmaDeviceMemoryCallbacks
 Set of callbacks that the library will call for vkAllocateMemory and vkFreeMemory. More...
 
struct  VmaVulkanFunctions
 Pointers to some Vulkan functions - a subset used by the library. More...
 
struct  VmaRecordSettings
 Parameters for recording calls to VMA functions. To be used in VmaAllocatorCreateInfo::pRecordSettings. More...
 
struct  VmaAllocatorCreateInfo
 Description of a Allocator to be created. More...
 
struct  VmaAllocatorInfo
 Information about existing VmaAllocator object. More...
 
struct  VmaStatInfo
 Calculated statistics of memory usage in entire allocator. More...
 
struct  VmaStats
 General statistics from current state of Allocator. More...
 
struct  VmaBudget
 Statistics of current memory usage and available budget, in bytes, for specific memory heap. More...
 
struct  VmaAllocationCreateInfo
 
struct  VmaPoolCreateInfo
 Describes parameter of created VmaPool. More...
 
struct  VmaPoolStats
 Describes parameter of existing VmaPool. More...
 
struct  VmaAllocationInfo
 Parameters of VmaAllocation objects, that can be retrieved using function vmaGetAllocationInfo(). More...
 
struct  VmaDefragmentationInfo2
 Parameters for defragmentation. More...
 
struct  VmaDefragmentationPassMoveInfo
 
struct  VmaDefragmentationPassInfo
 Parameters for incremental defragmentation steps. More...
 
struct  VmaDefragmentationInfo
 Deprecated. Optional configuration parameters to be passed to function vmaDefragment(). More...
 
struct  VmaDefragmentationStats
 Statistics returned by function vmaDefragment(). More...
 
struct  VmaVirtualBlockCreateInfo
 Parameters of created VmaVirtualBlock object to be passed to vmaCreateVirtualBlock(). More...
 
struct  VmaVirtualAllocationCreateInfo
 Parameters of created virtual allocation to be passed to vmaVirtualAllocate(). More...
 
struct  VmaVirtualAllocationInfo
 Parameters of an existing virtual allocation, returned by vmaGetVirtualAllocationInfo(). More...
 

Macros

#define VMA_RECORDING_ENABLED   0
 
#define VMA_DEDICATED_ALLOCATION   0
 
#define VMA_BIND_MEMORY2   0
 
#define VMA_MEMORY_BUDGET   0
 
#define VMA_BUFFER_DEVICE_ADDRESS   1
 
#define VMA_STATS_STRING_ENABLED   1
 

Typedefs

typedef void(VKAPI_PTR * PFN_vmaAllocateDeviceMemoryFunction) (VmaAllocator allocator, uint32_t memoryType, VkDeviceMemory memory, VkDeviceSize size, void *pUserData)
 Callback function called after successful vkAllocateMemory. More...
 
typedef void(VKAPI_PTR * PFN_vmaFreeDeviceMemoryFunction) (VmaAllocator allocator, uint32_t memoryType, VkDeviceMemory memory, VkDeviceSize size, void *pUserData)
 Callback function called before vkFreeMemory. More...
 
typedef struct VmaDeviceMemoryCallbacks VmaDeviceMemoryCallbacks
 Set of callbacks that the library will call for vkAllocateMemory and vkFreeMemory. More...
 
typedef enum VmaAllocatorCreateFlagBits VmaAllocatorCreateFlagBits
 Flags for created VmaAllocator. More...
 
typedef VkFlags VmaAllocatorCreateFlags
 
typedef struct VmaVulkanFunctions VmaVulkanFunctions
 Pointers to some Vulkan functions - a subset used by the library. More...
 
typedef enum VmaRecordFlagBits VmaRecordFlagBits
 Flags to be used in VmaRecordSettings::flags. More...
 
typedef VkFlags VmaRecordFlags
 
typedef struct VmaRecordSettings VmaRecordSettings
 Parameters for recording calls to VMA functions. To be used in VmaAllocatorCreateInfo::pRecordSettings. More...
 
typedef struct VmaAllocatorCreateInfo VmaAllocatorCreateInfo
 Description of a Allocator to be created. More...
 
typedef struct VmaAllocatorInfo VmaAllocatorInfo
 Information about existing VmaAllocator object. More...
 
typedef struct VmaStatInfo VmaStatInfo
 Calculated statistics of memory usage in entire allocator. More...
 
typedef struct VmaStats VmaStats
 General statistics from current state of Allocator. More...
 
typedef struct VmaBudget VmaBudget
 Statistics of current memory usage and available budget, in bytes, for specific memory heap. More...
 
typedef enum VmaMemoryUsage VmaMemoryUsage
 
typedef enum VmaAllocationCreateFlagBits VmaAllocationCreateFlagBits
 Flags to be passed as VmaAllocationCreateInfo::flags. More...
 
typedef VkFlags VmaAllocationCreateFlags
 
typedef struct VmaAllocationCreateInfo VmaAllocationCreateInfo
 
typedef enum VmaPoolCreateFlagBits VmaPoolCreateFlagBits
 Flags to be passed as VmaPoolCreateInfo::flags. More...
 
typedef VkFlags VmaPoolCreateFlags
 Flags to be passed as VmaPoolCreateInfo::flags. See VmaPoolCreateFlagBits. More...
 
typedef struct VmaPoolCreateInfo VmaPoolCreateInfo
 Describes parameter of created VmaPool. More...
 
typedef struct VmaPoolStats VmaPoolStats
 Describes parameter of existing VmaPool. More...
 
typedef struct VmaAllocationInfo VmaAllocationInfo
 Parameters of VmaAllocation objects, that can be retrieved using function vmaGetAllocationInfo(). More...
 
typedef enum VmaDefragmentationFlagBits VmaDefragmentationFlagBits
 Flags to be used in vmaDefragmentationBegin(). None at the moment. Reserved for future use. More...
 
typedef VkFlags VmaDefragmentationFlags
 
typedef struct VmaDefragmentationInfo2 VmaDefragmentationInfo2
 Parameters for defragmentation. More...
 
typedef struct VmaDefragmentationPassMoveInfo VmaDefragmentationPassMoveInfo
 
typedef struct VmaDefragmentationPassInfo VmaDefragmentationPassInfo
 Parameters for incremental defragmentation steps. More...
 
typedef struct VmaDefragmentationInfo VmaDefragmentationInfo
 Deprecated. Optional configuration parameters to be passed to function vmaDefragment(). More...
 
typedef struct VmaDefragmentationStats VmaDefragmentationStats
 Statistics returned by function vmaDefragment(). More...
 
typedef enum VmaVirtualBlockCreateFlagBits VmaVirtualBlockCreateFlagBits
 Flags to be passed as VmaVirtualBlockCreateInfo::flags. More...
 
typedef VkFlags VmaVirtualBlockCreateFlags
 Flags to be passed as VmaVirtualBlockCreateInfo::flags. See VmaVirtualBlockCreateFlagBits. More...
 
typedef struct VmaVirtualBlockCreateInfo VmaVirtualBlockCreateInfo
 Parameters of created VmaVirtualBlock object to be passed to vmaCreateVirtualBlock(). More...
 
typedef enum VmaVirtualAllocationCreateFlagBits VmaVirtualAllocationCreateFlagBits
 Flags to be passed as VmaVirtualAllocationCreateInfo::flags. More...
 
typedef VkFlags VmaVirtualAllocationCreateFlags
 Flags to be passed as VmaVirtualAllocationCreateInfo::flags. See VmaVirtualAllocationCreateFlagBits. More...
 
typedef struct VmaVirtualAllocationCreateInfo VmaVirtualAllocationCreateInfo
 Parameters of created virtual allocation to be passed to vmaVirtualAllocate(). More...
 
typedef struct VmaVirtualAllocationInfo VmaVirtualAllocationInfo
 Parameters of an existing virtual allocation, returned by vmaGetVirtualAllocationInfo(). More...
 

Enumerations

enum  VmaAllocatorCreateFlagBits {
  VMA_ALLOCATOR_CREATE_EXTERNALLY_SYNCHRONIZED_BIT = 0x00000001 , VMA_ALLOCATOR_CREATE_KHR_DEDICATED_ALLOCATION_BIT = 0x00000002 , VMA_ALLOCATOR_CREATE_KHR_BIND_MEMORY2_BIT = 0x00000004 , VMA_ALLOCATOR_CREATE_EXT_MEMORY_BUDGET_BIT = 0x00000008 ,
  VMA_ALLOCATOR_CREATE_AMD_DEVICE_COHERENT_MEMORY_BIT = 0x00000010 , VMA_ALLOCATOR_CREATE_BUFFER_DEVICE_ADDRESS_BIT = 0x00000020 , VMA_ALLOCATOR_CREATE_EXT_MEMORY_PRIORITY_BIT = 0x00000040 , VMA_ALLOCATOR_CREATE_FLAG_BITS_MAX_ENUM = 0x7FFFFFFF
}
 Flags for created VmaAllocator. More...
 
enum  VmaRecordFlagBits { VMA_RECORD_FLUSH_AFTER_CALL_BIT = 0x00000001 , VMA_RECORD_FLAG_BITS_MAX_ENUM = 0x7FFFFFFF }
 Flags to be used in VmaRecordSettings::flags. More...
 
enum  VmaMemoryUsage {
  VMA_MEMORY_USAGE_UNKNOWN = 0 , VMA_MEMORY_USAGE_GPU_ONLY = 1 , VMA_MEMORY_USAGE_CPU_ONLY = 2 , VMA_MEMORY_USAGE_CPU_TO_GPU = 3 ,
  VMA_MEMORY_USAGE_GPU_TO_CPU = 4 , VMA_MEMORY_USAGE_CPU_COPY = 5 , VMA_MEMORY_USAGE_GPU_LAZILY_ALLOCATED = 6 , VMA_MEMORY_USAGE_MAX_ENUM = 0x7FFFFFFF
}
 
enum  VmaAllocationCreateFlagBits {
  VMA_ALLOCATION_CREATE_DEDICATED_MEMORY_BIT = 0x00000001 , VMA_ALLOCATION_CREATE_NEVER_ALLOCATE_BIT = 0x00000002 , VMA_ALLOCATION_CREATE_MAPPED_BIT = 0x00000004 , VMA_ALLOCATION_CREATE_CAN_BECOME_LOST_BIT = 0x00000008 ,
  VMA_ALLOCATION_CREATE_CAN_MAKE_OTHER_LOST_BIT = 0x00000010 , VMA_ALLOCATION_CREATE_USER_DATA_COPY_STRING_BIT = 0x00000020 , VMA_ALLOCATION_CREATE_UPPER_ADDRESS_BIT = 0x00000040 , VMA_ALLOCATION_CREATE_DONT_BIND_BIT = 0x00000080 ,
  VMA_ALLOCATION_CREATE_WITHIN_BUDGET_BIT = 0x00000100 , VMA_ALLOCATION_CREATE_STRATEGY_BEST_FIT_BIT = 0x00010000 , VMA_ALLOCATION_CREATE_STRATEGY_WORST_FIT_BIT = 0x00020000 , VMA_ALLOCATION_CREATE_STRATEGY_FIRST_FIT_BIT = 0x00040000 ,
  VMA_ALLOCATION_CREATE_STRATEGY_MIN_MEMORY_BIT = VMA_ALLOCATION_CREATE_STRATEGY_BEST_FIT_BIT , VMA_ALLOCATION_CREATE_STRATEGY_MIN_TIME_BIT = VMA_ALLOCATION_CREATE_STRATEGY_FIRST_FIT_BIT , VMA_ALLOCATION_CREATE_STRATEGY_MIN_FRAGMENTATION_BIT = VMA_ALLOCATION_CREATE_STRATEGY_WORST_FIT_BIT , VMA_ALLOCATION_CREATE_STRATEGY_MASK ,
  VMA_ALLOCATION_CREATE_FLAG_BITS_MAX_ENUM = 0x7FFFFFFF
}
 Flags to be passed as VmaAllocationCreateInfo::flags. More...
 
enum  VmaPoolCreateFlagBits {
  VMA_POOL_CREATE_IGNORE_BUFFER_IMAGE_GRANULARITY_BIT = 0x00000002 , VMA_POOL_CREATE_LINEAR_ALGORITHM_BIT = 0x00000004 , VMA_POOL_CREATE_BUDDY_ALGORITHM_BIT = 0x00000008 , VMA_POOL_CREATE_ALGORITHM_MASK ,
  VMA_POOL_CREATE_FLAG_BITS_MAX_ENUM = 0x7FFFFFFF
}
 Flags to be passed as VmaPoolCreateInfo::flags. More...
 
enum  VmaDefragmentationFlagBits { VMA_DEFRAGMENTATION_FLAG_INCREMENTAL = 0x1 , VMA_DEFRAGMENTATION_FLAG_BITS_MAX_ENUM = 0x7FFFFFFF }
 Flags to be used in vmaDefragmentationBegin(). None at the moment. Reserved for future use. More...
 
enum  VmaVirtualBlockCreateFlagBits { VMA_VIRTUAL_BLOCK_CREATE_LINEAR_ALGORITHM_BIT = 0x00000001 , VMA_VIRTUAL_BLOCK_CREATE_BUDDY_ALGORITHM_BIT = 0x00000002 , VMA_VIRTUAL_BLOCK_CREATE_ALGORITHM_MASK , VMA_VIRTUAL_BLOCK_CREATE_FLAG_BITS_MAX_ENUM = 0x7FFFFFFF }
 Flags to be passed as VmaVirtualBlockCreateInfo::flags. More...
 
enum  VmaVirtualAllocationCreateFlagBits {
  VMA_VIRTUAL_ALLOCATION_CREATE_UPPER_ADDRESS_BIT = VMA_ALLOCATION_CREATE_UPPER_ADDRESS_BIT , VMA_VIRTUAL_ALLOCATION_CREATE_STRATEGY_MIN_MEMORY_BIT = VMA_ALLOCATION_CREATE_STRATEGY_MIN_MEMORY_BIT , VMA_VIRTUAL_ALLOCATION_CREATE_STRATEGY_MIN_TIME_BIT = VMA_ALLOCATION_CREATE_STRATEGY_MIN_TIME_BIT , VMA_VIRTUAL_ALLOCATION_CREATE_STRATEGY_MIN_FRAGMENTATION_BIT = VMA_ALLOCATION_CREATE_STRATEGY_MIN_FRAGMENTATION_BIT ,
  VMA_VIRTUAL_ALLOCATION_CREATE_STRATEGY_MASK = VMA_ALLOCATION_CREATE_STRATEGY_MASK , VMA_VIRTUAL_ALLOCATION_CREATE_FLAG_BITS_MAX_ENUM = 0x7FFFFFFF
}
 Flags to be passed as VmaVirtualAllocationCreateInfo::flags. More...
 

Functions

VkResult vmaCreateAllocator (const VmaAllocatorCreateInfo *pCreateInfo, VmaAllocator *pAllocator)
 Creates Allocator object. More...
 
void vmaDestroyAllocator (VmaAllocator allocator)
 Destroys allocator object. More...
 
void vmaGetAllocatorInfo (VmaAllocator allocator, VmaAllocatorInfo *pAllocatorInfo)
 Returns information about existing VmaAllocator object - handle to Vulkan device etc. More...
 
void vmaGetPhysicalDeviceProperties (VmaAllocator allocator, const VkPhysicalDeviceProperties **ppPhysicalDeviceProperties)
 
void vmaGetMemoryProperties (VmaAllocator allocator, const VkPhysicalDeviceMemoryProperties **ppPhysicalDeviceMemoryProperties)
 
void vmaGetMemoryTypeProperties (VmaAllocator allocator, uint32_t memoryTypeIndex, VkMemoryPropertyFlags *pFlags)
 Given Memory Type Index, returns Property Flags of this memory type. More...
 
void vmaSetCurrentFrameIndex (VmaAllocator allocator, uint32_t frameIndex)
 Sets index of the current frame. More...
 
void vmaCalculateStats (VmaAllocator allocator, VmaStats *pStats)
 Retrieves statistics from current state of the Allocator. More...
 
void vmaGetBudget (VmaAllocator allocator, VmaBudget *pBudget)
 Retrieves information about current memory budget for all memory heaps. More...
 
void vmaBuildStatsString (VmaAllocator allocator, char **ppStatsString, VkBool32 detailedMap)
 Builds and returns statistics as a null-terminated string in JSON format. More...
 
void vmaFreeStatsString (VmaAllocator allocator, char *pStatsString)
 
VkResult vmaFindMemoryTypeIndex (VmaAllocator allocator, uint32_t memoryTypeBits, const VmaAllocationCreateInfo *pAllocationCreateInfo, uint32_t *pMemoryTypeIndex)
 Helps to find memoryTypeIndex, given memoryTypeBits and VmaAllocationCreateInfo. More...
 
VkResult vmaFindMemoryTypeIndexForBufferInfo (VmaAllocator allocator, const VkBufferCreateInfo *pBufferCreateInfo, const VmaAllocationCreateInfo *pAllocationCreateInfo, uint32_t *pMemoryTypeIndex)
 Helps to find memoryTypeIndex, given VkBufferCreateInfo and VmaAllocationCreateInfo. More...
 
VkResult vmaFindMemoryTypeIndexForImageInfo (VmaAllocator allocator, const VkImageCreateInfo *pImageCreateInfo, const VmaAllocationCreateInfo *pAllocationCreateInfo, uint32_t *pMemoryTypeIndex)
 Helps to find memoryTypeIndex, given VkImageCreateInfo and VmaAllocationCreateInfo. More...
 
VkResult vmaCreatePool (VmaAllocator allocator, const VmaPoolCreateInfo *pCreateInfo, VmaPool *pPool)
 Allocates Vulkan device memory and creates VmaPool object. More...
 
void vmaDestroyPool (VmaAllocator allocator, VmaPool pool)
 Destroys VmaPool object and frees Vulkan device memory. More...
 
void vmaGetPoolStats (VmaAllocator allocator, VmaPool pool, VmaPoolStats *pPoolStats)
 Retrieves statistics of existing VmaPool object. More...
 
void vmaMakePoolAllocationsLost (VmaAllocator allocator, VmaPool pool, size_t *pLostAllocationCount)
 Marks all allocations in given pool as lost if they are not used in current frame or VmaPoolCreateInfo::frameInUseCount back from now. More...
 
VkResult vmaCheckPoolCorruption (VmaAllocator allocator, VmaPool pool)
 Checks magic number in margins around all allocations in given memory pool in search for corruptions. More...
 
void vmaGetPoolName (VmaAllocator allocator, VmaPool pool, const char **ppName)
 Retrieves name of a custom pool. More...
 
void vmaSetPoolName (VmaAllocator allocator, VmaPool pool, const char *pName)
 Sets name of a custom pool. More...
 
VkResult vmaAllocateMemory (VmaAllocator allocator, const VkMemoryRequirements *pVkMemoryRequirements, const VmaAllocationCreateInfo *pCreateInfo, VmaAllocation *pAllocation, VmaAllocationInfo *pAllocationInfo)
 General purpose memory allocation. More...
 
VkResult vmaAllocateMemoryPages (VmaAllocator allocator, const VkMemoryRequirements *pVkMemoryRequirements, const VmaAllocationCreateInfo *pCreateInfo, size_t allocationCount, VmaAllocation *pAllocations, VmaAllocationInfo *pAllocationInfo)
 General purpose memory allocation for multiple allocation objects at once. More...
 
VkResult vmaAllocateMemoryForBuffer (VmaAllocator allocator, VkBuffer buffer, const VmaAllocationCreateInfo *pCreateInfo, VmaAllocation *pAllocation, VmaAllocationInfo *pAllocationInfo)
 
VkResult vmaAllocateMemoryForImage (VmaAllocator allocator, VkImage image, const VmaAllocationCreateInfo *pCreateInfo, VmaAllocation *pAllocation, VmaAllocationInfo *pAllocationInfo)
 Function similar to vmaAllocateMemoryForBuffer(). More...
 
void vmaFreeMemory (VmaAllocator allocator, const VmaAllocation allocation)
 Frees memory previously allocated using vmaAllocateMemory(), vmaAllocateMemoryForBuffer(), or vmaAllocateMemoryForImage(). More...
 
void vmaFreeMemoryPages (VmaAllocator allocator, size_t allocationCount, const VmaAllocation *pAllocations)
 Frees memory and destroys multiple allocations. More...
 
void vmaGetAllocationInfo (VmaAllocator allocator, VmaAllocation allocation, VmaAllocationInfo *pAllocationInfo)
 Returns current information about specified allocation and atomically marks it as used in current frame. More...
 
VkBool32 vmaTouchAllocation (VmaAllocator allocator, VmaAllocation allocation)
 Returns VK_TRUE if allocation is not lost and atomically marks it as used in current frame. More...
 
void vmaSetAllocationUserData (VmaAllocator allocator, VmaAllocation allocation, void *pUserData)
 Sets pUserData in given allocation to new value. More...
 
void vmaCreateLostAllocation (VmaAllocator allocator, VmaAllocation *pAllocation)
 Creates new allocation that is in lost state from the beginning. More...
 
VkResult vmaMapMemory (VmaAllocator allocator, VmaAllocation allocation, void **ppData)
 Maps memory represented by given allocation and returns pointer to it. More...
 
void vmaUnmapMemory (VmaAllocator allocator, VmaAllocation allocation)
 Unmaps memory represented by given allocation, mapped previously using vmaMapMemory(). More...
 
VkResult vmaFlushAllocation (VmaAllocator allocator, VmaAllocation allocation, VkDeviceSize offset, VkDeviceSize size)
 Flushes memory of given allocation. More...
 
VkResult vmaInvalidateAllocation (VmaAllocator allocator, VmaAllocation allocation, VkDeviceSize offset, VkDeviceSize size)
 Invalidates memory of given allocation. More...
 
VkResult vmaFlushAllocations (VmaAllocator allocator, uint32_t allocationCount, const VmaAllocation *allocations, const VkDeviceSize *offsets, const VkDeviceSize *sizes)
 Flushes memory of given set of allocations. More...
 
VkResult vmaInvalidateAllocations (VmaAllocator allocator, uint32_t allocationCount, const VmaAllocation *allocations, const VkDeviceSize *offsets, const VkDeviceSize *sizes)
 Invalidates memory of given set of allocations. More...
 
VkResult vmaCheckCorruption (VmaAllocator allocator, uint32_t memoryTypeBits)
 Checks magic number in margins around all allocations in given memory types (in both default and custom pools) in search for corruptions. More...
 
VkResult vmaDefragmentationBegin (VmaAllocator allocator, const VmaDefragmentationInfo2 *pInfo, VmaDefragmentationStats *pStats, VmaDefragmentationContext *pContext)
 Begins defragmentation process. More...
 
VkResult vmaDefragmentationEnd (VmaAllocator allocator, VmaDefragmentationContext context)
 Ends defragmentation process. More...
 
VkResult vmaBeginDefragmentationPass (VmaAllocator allocator, VmaDefragmentationContext context, VmaDefragmentationPassInfo *pInfo)
 
VkResult vmaEndDefragmentationPass (VmaAllocator allocator, VmaDefragmentationContext context)
 
VkResult vmaDefragment (VmaAllocator allocator, const VmaAllocation *pAllocations, size_t allocationCount, VkBool32 *pAllocationsChanged, const VmaDefragmentationInfo *pDefragmentationInfo, VmaDefragmentationStats *pDefragmentationStats)
 Deprecated. Compacts memory by moving allocations. More...
 
VkResult vmaBindBufferMemory (VmaAllocator allocator, VmaAllocation allocation, VkBuffer buffer)
 Binds buffer to allocation. More...
 
VkResult vmaBindBufferMemory2 (VmaAllocator allocator, VmaAllocation allocation, VkDeviceSize allocationLocalOffset, VkBuffer buffer, const void *pNext)
 Binds buffer to allocation with additional parameters. More...
 
VkResult vmaBindImageMemory (VmaAllocator allocator, VmaAllocation allocation, VkImage image)
 Binds image to allocation. More...
 
VkResult vmaBindImageMemory2 (VmaAllocator allocator, VmaAllocation allocation, VkDeviceSize allocationLocalOffset, VkImage image, const void *pNext)
 Binds image to allocation with additional parameters. More...
 
VkResult vmaCreateBuffer (VmaAllocator allocator, const VkBufferCreateInfo *pBufferCreateInfo, const VmaAllocationCreateInfo *pAllocationCreateInfo, VkBuffer *pBuffer, VmaAllocation *pAllocation, VmaAllocationInfo *pAllocationInfo)
 
VkResult vmaCreateBufferWithAlignment (VmaAllocator allocator, const VkBufferCreateInfo *pBufferCreateInfo, const VmaAllocationCreateInfo *pAllocationCreateInfo, VkDeviceSize minAlignment, VkBuffer *pBuffer, VmaAllocation *pAllocation, VmaAllocationInfo *pAllocationInfo)
 Creates a buffer with additional minimum alignment. More...
 
void vmaDestroyBuffer (VmaAllocator allocator, VkBuffer buffer, VmaAllocation allocation)
 Destroys Vulkan buffer and frees allocated memory. More...
 
VkResult vmaCreateImage (VmaAllocator allocator, const VkImageCreateInfo *pImageCreateInfo, const VmaAllocationCreateInfo *pAllocationCreateInfo, VkImage *pImage, VmaAllocation *pAllocation, VmaAllocationInfo *pAllocationInfo)
 Function similar to vmaCreateBuffer(). More...
 
void vmaDestroyImage (VmaAllocator allocator, VkImage image, VmaAllocation allocation)
 Destroys Vulkan image and frees allocated memory. More...
 
 VK_DEFINE_HANDLE (VmaVirtualBlock)
 
VkResult vmaCreateVirtualBlock (const VmaVirtualBlockCreateInfo *pCreateInfo, VmaVirtualBlock *pVirtualBlock)
 Creates new VmaVirtualBlock object. More...
 
void vmaDestroyVirtualBlock (VmaVirtualBlock virtualBlock)
 Destroys VmaVirtualBlock object. More...
 
VkBool32 vmaIsVirtualBlockEmpty (VmaVirtualBlock virtualBlock)
 Returns true of the VmaVirtualBlock is empty - contains 0 virtual allocations and has all its space available for new allocations. More...
 
void vmaGetVirtualAllocationInfo (VmaVirtualBlock virtualBlock, VkDeviceSize offset, VmaVirtualAllocationInfo *pVirtualAllocInfo)
 Returns information about a specific virtual allocation within a virtual block, like its size and pUserData pointer. More...
 
VkResult vmaVirtualAllocate (VmaVirtualBlock virtualBlock, const VmaVirtualAllocationCreateInfo *pCreateInfo, VkDeviceSize *pOffset)
 Allocates new virtual allocation inside given VmaVirtualBlock. More...
 
void vmaVirtualFree (VmaVirtualBlock virtualBlock, VkDeviceSize offset)
 Frees virtual allocation inside given VmaVirtualBlock. More...
 
void vmaClearVirtualBlock (VmaVirtualBlock virtualBlock)
 Frees all virtual allocations inside given VmaVirtualBlock. More...
 
void vmaSetVirtualAllocationUserData (VmaVirtualBlock virtualBlock, VkDeviceSize offset, void *pUserData)
 Changes custom pointer associated with given virtual allocation. More...
 
void vmaCalculateVirtualBlockStats (VmaVirtualBlock virtualBlock, VmaStatInfo *pStatInfo)
 Calculates and returns statistics about virtual allocations and memory usage in given VmaVirtualBlock. More...
 
void vmaBuildVirtualBlockStatsString (VmaVirtualBlock virtualBlock, char **ppStatsString, VkBool32 detailedMap)
 Builds and returns a null-terminated string in JSON format with information about given VmaVirtualBlock. More...
 
void vmaFreeVirtualBlockStatsString (VmaVirtualBlock virtualBlock, char *pStatsString)
 Frees a string returned by vmaBuildVirtualBlockStatsString(). More...
 

Macro Definition Documentation

◆ VMA_BIND_MEMORY2

#define VMA_BIND_MEMORY2   0

◆ VMA_BUFFER_DEVICE_ADDRESS

#define VMA_BUFFER_DEVICE_ADDRESS   1

◆ VMA_DEDICATED_ALLOCATION

#define VMA_DEDICATED_ALLOCATION   0

◆ VMA_MEMORY_BUDGET

#define VMA_MEMORY_BUDGET   0

◆ VMA_RECORDING_ENABLED

#define VMA_RECORDING_ENABLED   0

◆ VMA_STATS_STRING_ENABLED

#define VMA_STATS_STRING_ENABLED   1

Typedef Documentation

◆ PFN_vmaAllocateDeviceMemoryFunction

typedef void(VKAPI_PTR * PFN_vmaAllocateDeviceMemoryFunction) (VmaAllocator allocator, uint32_t memoryType, VkDeviceMemory memory, VkDeviceSize size, void *pUserData)

Callback function called after successful vkAllocateMemory.

◆ PFN_vmaFreeDeviceMemoryFunction

typedef void(VKAPI_PTR * PFN_vmaFreeDeviceMemoryFunction) (VmaAllocator allocator, uint32_t memoryType, VkDeviceMemory memory, VkDeviceSize size, void *pUserData)

Callback function called before vkFreeMemory.

◆ VmaAllocationCreateFlagBits

Flags to be passed as VmaAllocationCreateInfo::flags.

◆ VmaAllocationCreateFlags

typedef VkFlags VmaAllocationCreateFlags

◆ VmaAllocationCreateInfo

◆ VmaAllocationInfo

Parameters of VmaAllocation objects, that can be retrieved using function vmaGetAllocationInfo().

◆ VmaAllocatorCreateFlagBits

Flags for created VmaAllocator.

◆ VmaAllocatorCreateFlags

typedef VkFlags VmaAllocatorCreateFlags

◆ VmaAllocatorCreateInfo

Description of a Allocator to be created.

◆ VmaAllocatorInfo

Information about existing VmaAllocator object.

◆ VmaBudget

typedef struct VmaBudget VmaBudget

Statistics of current memory usage and available budget, in bytes, for specific memory heap.

◆ VmaDefragmentationFlagBits

Flags to be used in vmaDefragmentationBegin(). None at the moment. Reserved for future use.

◆ VmaDefragmentationFlags

typedef VkFlags VmaDefragmentationFlags

◆ VmaDefragmentationInfo

Deprecated. Optional configuration parameters to be passed to function vmaDefragment().

Deprecated:
This is a part of the old interface. It is recommended to use structure VmaDefragmentationInfo2 and function vmaDefragmentationBegin() instead.

◆ VmaDefragmentationInfo2

Parameters for defragmentation.

To be used with function vmaDefragmentationBegin().

◆ VmaDefragmentationPassInfo

Parameters for incremental defragmentation steps.

To be used with function vmaBeginDefragmentationPass().

◆ VmaDefragmentationPassMoveInfo

◆ VmaDefragmentationStats

Statistics returned by function vmaDefragment().

◆ VmaDeviceMemoryCallbacks

Set of callbacks that the library will call for vkAllocateMemory and vkFreeMemory.

Provided for informative purpose, e.g. to gather statistics about number of allocations or total amount of memory allocated in Vulkan.

Used in VmaAllocatorCreateInfo::pDeviceMemoryCallbacks.

◆ VmaMemoryUsage

◆ VmaPoolCreateFlagBits

Flags to be passed as VmaPoolCreateInfo::flags.

◆ VmaPoolCreateFlags

typedef VkFlags VmaPoolCreateFlags

Flags to be passed as VmaPoolCreateInfo::flags. See VmaPoolCreateFlagBits.

◆ VmaPoolCreateInfo

Describes parameter of created VmaPool.

◆ VmaPoolStats

typedef struct VmaPoolStats VmaPoolStats

Describes parameter of existing VmaPool.

◆ VmaRecordFlagBits

Flags to be used in VmaRecordSettings::flags.

◆ VmaRecordFlags

typedef VkFlags VmaRecordFlags

◆ VmaRecordSettings

Parameters for recording calls to VMA functions. To be used in VmaAllocatorCreateInfo::pRecordSettings.

◆ VmaStatInfo

typedef struct VmaStatInfo VmaStatInfo

Calculated statistics of memory usage in entire allocator.

◆ VmaStats

typedef struct VmaStats VmaStats

General statistics from current state of Allocator.

◆ VmaVirtualAllocationCreateFlagBits

Flags to be passed as VmaVirtualAllocationCreateInfo::flags.

◆ VmaVirtualAllocationCreateFlags

◆ VmaVirtualAllocationCreateInfo

Parameters of created virtual allocation to be passed to vmaVirtualAllocate().

◆ VmaVirtualAllocationInfo

Parameters of an existing virtual allocation, returned by vmaGetVirtualAllocationInfo().

◆ VmaVirtualBlockCreateFlagBits

Flags to be passed as VmaVirtualBlockCreateInfo::flags.

◆ VmaVirtualBlockCreateFlags

typedef VkFlags VmaVirtualBlockCreateFlags

◆ VmaVirtualBlockCreateInfo

Parameters of created VmaVirtualBlock object to be passed to vmaCreateVirtualBlock().

◆ VmaVulkanFunctions

Pointers to some Vulkan functions - a subset used by the library.

Used in VmaAllocatorCreateInfo::pVulkanFunctions.

Enumeration Type Documentation

◆ VmaAllocationCreateFlagBits

Flags to be passed as VmaAllocationCreateInfo::flags.

Enumerator
VMA_ALLOCATION_CREATE_DEDICATED_MEMORY_BIT 

Set this flag if the allocation should have its own memory block.

Use it for special, big resources, like fullscreen images used as attachments.

You should not use this flag if VmaAllocationCreateInfo::pool is not null.

VMA_ALLOCATION_CREATE_NEVER_ALLOCATE_BIT 

Set this flag to only try to allocate from existing VkDeviceMemory blocks and never create new such block.

If new allocation cannot be placed in any of the existing blocks, allocation fails with VK_ERROR_OUT_OF_DEVICE_MEMORY error.

You should not use VMA_ALLOCATION_CREATE_DEDICATED_MEMORY_BIT and VMA_ALLOCATION_CREATE_NEVER_ALLOCATE_BIT at the same time. It makes no sense.

If VmaAllocationCreateInfo::pool is not null, this flag is implied and ignored.

VMA_ALLOCATION_CREATE_MAPPED_BIT 

Set this flag to use a memory that will be persistently mapped and retrieve pointer to it.

Pointer to mapped memory will be returned through VmaAllocationInfo::pMappedData.

It is valid to use this flag for allocation made from memory type that is not HOST_VISIBLE. This flag is then ignored and memory is not mapped. This is useful if you need an allocation that is efficient to use on GPU (DEVICE_LOCAL) and still want to map it directly if possible on platforms that support it (e.g. Intel GPU).

You should not use this flag together with VMA_ALLOCATION_CREATE_CAN_BECOME_LOST_BIT.

VMA_ALLOCATION_CREATE_CAN_BECOME_LOST_BIT 

Allocation created with this flag can become lost as a result of another allocation with VMA_ALLOCATION_CREATE_CAN_MAKE_OTHER_LOST_BIT flag, so you must check it before use.

To check if allocation is not lost, call vmaGetAllocationInfo() and check if VmaAllocationInfo::deviceMemory is not VK_NULL_HANDLE.

For details about supporting lost allocations, see Lost Allocations chapter of User Guide on Main Page.

You should not use this flag together with VMA_ALLOCATION_CREATE_MAPPED_BIT.

VMA_ALLOCATION_CREATE_CAN_MAKE_OTHER_LOST_BIT 

While creating allocation using this flag, other allocations that were created with flag VMA_ALLOCATION_CREATE_CAN_BECOME_LOST_BIT can become lost.

For details about supporting lost allocations, see Lost Allocations chapter of User Guide on Main Page.

VMA_ALLOCATION_CREATE_USER_DATA_COPY_STRING_BIT 

Set this flag to treat VmaAllocationCreateInfo::pUserData as pointer to a null-terminated string. Instead of copying pointer value, a local copy of the string is made and stored in allocation's pUserData. The string is automatically freed together with the allocation. It is also used in vmaBuildStatsString().

VMA_ALLOCATION_CREATE_UPPER_ADDRESS_BIT 

Allocation will be created from upper stack in a double stack pool.

This flag is only allowed for custom pools created with VMA_POOL_CREATE_LINEAR_ALGORITHM_BIT flag.

VMA_ALLOCATION_CREATE_DONT_BIND_BIT 

Create both buffer/image and allocation, but don't bind them together. It is useful when you want to bind yourself to do some more advanced binding, e.g. using some extensions. The flag is meaningful only with functions that bind by default: vmaCreateBuffer(), vmaCreateImage(). Otherwise it is ignored.

VMA_ALLOCATION_CREATE_WITHIN_BUDGET_BIT 

Create allocation only if additional device memory required for it, if any, won't exceed memory budget. Otherwise return VK_ERROR_OUT_OF_DEVICE_MEMORY.

VMA_ALLOCATION_CREATE_STRATEGY_BEST_FIT_BIT 

Allocation strategy that chooses smallest possible free range for the allocation.

VMA_ALLOCATION_CREATE_STRATEGY_WORST_FIT_BIT 

Allocation strategy that chooses biggest possible free range for the allocation.

VMA_ALLOCATION_CREATE_STRATEGY_FIRST_FIT_BIT 

Allocation strategy that chooses first suitable free range for the allocation.

"First" doesn't necessarily means the one with smallest offset in memory, but rather the one that is easiest and fastest to find.

VMA_ALLOCATION_CREATE_STRATEGY_MIN_MEMORY_BIT 

Allocation strategy that tries to minimize memory usage.

VMA_ALLOCATION_CREATE_STRATEGY_MIN_TIME_BIT 

Allocation strategy that tries to minimize allocation time.

VMA_ALLOCATION_CREATE_STRATEGY_MIN_FRAGMENTATION_BIT 

Allocation strategy that tries to minimize memory fragmentation.

VMA_ALLOCATION_CREATE_STRATEGY_MASK 

A bit mask to extract only STRATEGY bits from entire set of flags.

VMA_ALLOCATION_CREATE_FLAG_BITS_MAX_ENUM 

◆ VmaAllocatorCreateFlagBits

Flags for created VmaAllocator.

Enumerator
VMA_ALLOCATOR_CREATE_EXTERNALLY_SYNCHRONIZED_BIT 

Allocator and all objects created from it will not be synchronized internally, so you must guarantee they are used from only one thread at a time or synchronized externally by you.

Using this flag may increase performance because internal mutexes are not used.

VMA_ALLOCATOR_CREATE_KHR_DEDICATED_ALLOCATION_BIT 

Enables usage of VK_KHR_dedicated_allocation extension.

The flag works only if VmaAllocatorCreateInfo::vulkanApiVersion == VK_API_VERSION_1_0. When it is VK_API_VERSION_1_1, the flag is ignored because the extension has been promoted to Vulkan 1.1.

Using this extension will automatically allocate dedicated blocks of memory for some buffers and images instead of suballocating place for them out of bigger memory blocks (as if you explicitly used VMA_ALLOCATION_CREATE_DEDICATED_MEMORY_BIT flag) when it is recommended by the driver. It may improve performance on some GPUs.

You may set this flag only if you found out that following device extensions are supported, you enabled them while creating Vulkan device passed as VmaAllocatorCreateInfo::device, and you want them to be used internally by this library:

  • VK_KHR_get_memory_requirements2 (device extension)
  • VK_KHR_dedicated_allocation (device extension)

When this flag is set, you can experience following warnings reported by Vulkan validation layer. You can ignore them.

vkBindBufferMemory(): Binding memory to buffer 0x2d but vkGetBufferMemoryRequirements() has not been called on that buffer.

VMA_ALLOCATOR_CREATE_KHR_BIND_MEMORY2_BIT 

Enables usage of VK_KHR_bind_memory2 extension.

The flag works only if VmaAllocatorCreateInfo::vulkanApiVersion == VK_API_VERSION_1_0. When it is VK_API_VERSION_1_1, the flag is ignored because the extension has been promoted to Vulkan 1.1.

You may set this flag only if you found out that this device extension is supported, you enabled it while creating Vulkan device passed as VmaAllocatorCreateInfo::device, and you want it to be used internally by this library.

The extension provides functions vkBindBufferMemory2KHR and vkBindImageMemory2KHR, which allow to pass a chain of pNext structures while binding. This flag is required if you use pNext parameter in vmaBindBufferMemory2() or vmaBindImageMemory2().

VMA_ALLOCATOR_CREATE_EXT_MEMORY_BUDGET_BIT 

Enables usage of VK_EXT_memory_budget extension.

You may set this flag only if you found out that this device extension is supported, you enabled it while creating Vulkan device passed as VmaAllocatorCreateInfo::device, and you want it to be used internally by this library, along with another instance extension VK_KHR_get_physical_device_properties2, which is required by it (or Vulkan 1.1, where this extension is promoted).

The extension provides query for current memory usage and budget, which will probably be more accurate than an estimation used by the library otherwise.

VMA_ALLOCATOR_CREATE_AMD_DEVICE_COHERENT_MEMORY_BIT 

Enables usage of VK_AMD_device_coherent_memory extension.

You may set this flag only if you:

  • found out that this device extension is supported and enabled it while creating Vulkan device passed as VmaAllocatorCreateInfo::device,
  • checked that VkPhysicalDeviceCoherentMemoryFeaturesAMD::deviceCoherentMemory is true and set it while creating the Vulkan device,
  • want it to be used internally by this library.

The extension and accompanying device feature provide access to memory types with VK_MEMORY_PROPERTY_DEVICE_COHERENT_BIT_AMD and VK_MEMORY_PROPERTY_DEVICE_UNCACHED_BIT_AMD flags. They are useful mostly for writing breadcrumb markers - a common method for debugging GPU crash/hang/TDR.

When the extension is not enabled, such memory types are still enumerated, but their usage is illegal. To protect from this error, if you don't create the allocator with this flag, it will refuse to allocate any memory or create a custom pool in such memory type, returning VK_ERROR_FEATURE_NOT_PRESENT.

VMA_ALLOCATOR_CREATE_BUFFER_DEVICE_ADDRESS_BIT 

Enables usage of "buffer device address" feature, which allows you to use function vkGetBufferDeviceAddress* to get raw GPU pointer to a buffer and pass it for usage inside a shader.

You may set this flag only if you:

  1. (For Vulkan version < 1.2) Found as available and enabled device extension VK_KHR_buffer_device_address. This extension is promoted to core Vulkan 1.2.
  2. Found as available and enabled device feature VkPhysicalDeviceBufferDeviceAddressFeatures::bufferDeviceAddress.

When this flag is set, you can create buffers with VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT using VMA. The library automatically adds VK_MEMORY_ALLOCATE_DEVICE_ADDRESS_BIT to allocated memory blocks wherever it might be needed.

For more information, see documentation chapter Enabling buffer device address.

VMA_ALLOCATOR_CREATE_EXT_MEMORY_PRIORITY_BIT 

Enables usage of VK_EXT_memory_priority extension in the library.

You may set this flag only if you found available and enabled this device extension, along with VkPhysicalDeviceMemoryPriorityFeaturesEXT::memoryPriority == VK_TRUE, while creating Vulkan device passed as VmaAllocatorCreateInfo::device.

When this flag is used, VmaAllocationCreateInfo::priority and VmaPoolCreateInfo::priority are used to set priorities of allocated Vulkan memory. Without it, these variables are ignored.

A priority must be a floating-point value between 0 and 1, indicating the priority of the allocation relative to other memory allocations. Larger values are higher priority. The granularity of the priorities is implementation-dependent. It is automatically passed to every call to vkAllocateMemory done by the library using structure VkMemoryPriorityAllocateInfoEXT. The value to be used for default priority is 0.5. For more details, see the documentation of the VK_EXT_memory_priority extension.

VMA_ALLOCATOR_CREATE_FLAG_BITS_MAX_ENUM 

◆ VmaDefragmentationFlagBits

Flags to be used in vmaDefragmentationBegin(). None at the moment. Reserved for future use.

Enumerator
VMA_DEFRAGMENTATION_FLAG_INCREMENTAL 
VMA_DEFRAGMENTATION_FLAG_BITS_MAX_ENUM 

◆ VmaMemoryUsage

Enumerator
VMA_MEMORY_USAGE_UNKNOWN 

No intended memory usage specified. Use other members of VmaAllocationCreateInfo to specify your requirements.

VMA_MEMORY_USAGE_GPU_ONLY 

Memory will be used on device only, so fast access from the device is preferred. It usually means device-local GPU (video) memory. No need to be mappable on host. It is roughly equivalent of D3D12_HEAP_TYPE_DEFAULT.

Usage:

  • Resources written and read by device, e.g. images used as attachments.
  • Resources transferred from host once (immutable) or infrequently and read by device multiple times, e.g. textures to be sampled, vertex buffers, uniform (constant) buffers, and majority of other types of resources used on GPU.

Allocation may still end up in HOST_VISIBLE memory on some implementations. In such case, you are free to map it. You can use VMA_ALLOCATION_CREATE_MAPPED_BIT with this usage type.

VMA_MEMORY_USAGE_CPU_ONLY 

Memory will be mappable on host. It usually means CPU (system) memory. Guarantees to be HOST_VISIBLE and HOST_COHERENT. CPU access is typically uncached. Writes may be write-combined. Resources created in this pool may still be accessible to the device, but access to them can be slow. It is roughly equivalent of D3D12_HEAP_TYPE_UPLOAD.

Usage: Staging copy of resources used as transfer source.

VMA_MEMORY_USAGE_CPU_TO_GPU 

Memory that is both mappable on host (guarantees to be HOST_VISIBLE) and preferably fast to access by GPU. CPU access is typically uncached. Writes may be write-combined.

Usage: Resources written frequently by host (dynamic), read by device. E.g. textures (with LINEAR layout), vertex buffers, uniform buffers updated every frame or every draw call.

VMA_MEMORY_USAGE_GPU_TO_CPU 

Memory mappable on host (guarantees to be HOST_VISIBLE) and cached. It is roughly equivalent of D3D12_HEAP_TYPE_READBACK.

Usage:

  • Resources written by device, read by host - results of some computations, e.g. screen capture, average scene luminance for HDR tone mapping.
  • Any resources read or accessed randomly on host, e.g. CPU-side copy of vertex buffer used as source of transfer, but also used for collision detection.
VMA_MEMORY_USAGE_CPU_COPY 

CPU memory - memory that is preferably not DEVICE_LOCAL, but also not guaranteed to be HOST_VISIBLE.

Usage: Staging copy of resources moved from GPU memory to CPU memory as part of custom paging/residency mechanism, to be moved back to GPU memory when needed.

VMA_MEMORY_USAGE_GPU_LAZILY_ALLOCATED 

Lazily allocated GPU memory having VK_MEMORY_PROPERTY_LAZILY_ALLOCATED_BIT. Exists mostly on mobile platforms. Using it on desktop PC or other GPUs with no such memory type present will fail the allocation.

Usage: Memory for transient attachment images (color attachments, depth attachments etc.), created with VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT.

Allocations with this usage are always created as dedicated - it implies VMA_ALLOCATION_CREATE_DEDICATED_MEMORY_BIT.

VMA_MEMORY_USAGE_MAX_ENUM 

◆ VmaPoolCreateFlagBits

Flags to be passed as VmaPoolCreateInfo::flags.

Enumerator
VMA_POOL_CREATE_IGNORE_BUFFER_IMAGE_GRANULARITY_BIT 

Use this flag if you always allocate only buffers and linear images or only optimal images out of this pool and so Buffer-Image Granularity can be ignored.

This is an optional optimization flag.

If you always allocate using vmaCreateBuffer(), vmaCreateImage(), vmaAllocateMemoryForBuffer(), then you don't need to use it because allocator knows exact type of your allocations so it can handle Buffer-Image Granularity in the optimal way.

If you also allocate using vmaAllocateMemoryForImage() or vmaAllocateMemory(), exact type of such allocations is not known, so allocator must be conservative in handling Buffer-Image Granularity, which can lead to suboptimal allocation (wasted memory). In that case, if you can make sure you always allocate only buffers and linear images or only optimal images out of this pool, use this flag to make allocator disregard Buffer-Image Granularity and so make allocations faster and more optimal.

VMA_POOL_CREATE_LINEAR_ALGORITHM_BIT 

Enables alternative, linear allocation algorithm in this pool.

Specify this flag to enable linear allocation algorithm, which always creates new allocations after last one and doesn't reuse space from allocations freed in between. It trades memory consumption for simplified algorithm and data structure, which has better performance and uses less memory for metadata.

By using this flag, you can achieve behavior of free-at-once, stack, ring buffer, and double stack. For details, see documentation chapter Linear allocation algorithm.

When using this flag, you must specify VmaPoolCreateInfo::maxBlockCount == 1 (or 0 for default).

VMA_POOL_CREATE_BUDDY_ALGORITHM_BIT 

Enables alternative, buddy allocation algorithm in this pool.

It operates on a tree of blocks, each having size that is a power of two and a half of its parent's size. Comparing to default algorithm, this one provides faster allocation and deallocation and decreased external fragmentation, at the expense of more memory wasted (internal fragmentation). For details, see documentation chapter Buddy allocation algorithm.

VMA_POOL_CREATE_ALGORITHM_MASK 

Bit mask to extract only ALGORITHM bits from entire set of flags.

VMA_POOL_CREATE_FLAG_BITS_MAX_ENUM 

◆ VmaRecordFlagBits

Flags to be used in VmaRecordSettings::flags.

Enumerator
VMA_RECORD_FLUSH_AFTER_CALL_BIT 

Enables flush after recording every function call.

Enable it if you expect your application to crash, which may leave recording file truncated. It may degrade performance though.

VMA_RECORD_FLAG_BITS_MAX_ENUM 

◆ VmaVirtualAllocationCreateFlagBits

Flags to be passed as VmaVirtualAllocationCreateInfo::flags.

Enumerator
VMA_VIRTUAL_ALLOCATION_CREATE_UPPER_ADDRESS_BIT 

Allocation will be created from upper stack in a double stack pool.

This flag is only allowed for virtual blocks created with VMA_VIRTUAL_BLOCK_CREATE_LINEAR_ALGORITHM_BIT flag.

VMA_VIRTUAL_ALLOCATION_CREATE_STRATEGY_MIN_MEMORY_BIT 

Allocation strategy that tries to minimize memory usage.

VMA_VIRTUAL_ALLOCATION_CREATE_STRATEGY_MIN_TIME_BIT 

Allocation strategy that tries to minimize allocation time.

VMA_VIRTUAL_ALLOCATION_CREATE_STRATEGY_MIN_FRAGMENTATION_BIT 

Allocation strategy that tries to minimize memory fragmentation.

VMA_VIRTUAL_ALLOCATION_CREATE_STRATEGY_MASK 

A bit mask to extract only STRATEGY bits from entire set of flags.

These stategy flags are binary compatible with equivalent flags in VmaAllocationCreateFlagBits.

VMA_VIRTUAL_ALLOCATION_CREATE_FLAG_BITS_MAX_ENUM 

◆ VmaVirtualBlockCreateFlagBits

Flags to be passed as VmaVirtualBlockCreateInfo::flags.

Enumerator
VMA_VIRTUAL_BLOCK_CREATE_LINEAR_ALGORITHM_BIT 

Enables alternative, linear allocation algorithm in this virtual block.

Specify this flag to enable linear allocation algorithm, which always creates new allocations after last one and doesn't reuse space from allocations freed in between. It trades memory consumption for simplified algorithm and data structure, which has better performance and uses less memory for metadata.

By using this flag, you can achieve behavior of free-at-once, stack, ring buffer, and double stack. For details, see documentation chapter Linear allocation algorithm.

VMA_VIRTUAL_BLOCK_CREATE_BUDDY_ALGORITHM_BIT 

Enables alternative, buddy allocation algorithm in this virtual block.

It operates on a tree of blocks, each having size that is a power of two and a half of its parent's size. Comparing to default algorithm, this one provides faster allocation and deallocation and decreased external fragmentation, at the expense of more memory wasted (internal fragmentation). For details, see documentation chapter Buddy allocation algorithm.

VMA_VIRTUAL_BLOCK_CREATE_ALGORITHM_MASK 

Bit mask to extract only ALGORITHM bits from entire set of flags.

VMA_VIRTUAL_BLOCK_CREATE_FLAG_BITS_MAX_ENUM 

Function Documentation

◆ VK_DEFINE_HANDLE()

VK_DEFINE_HANDLE ( VmaVirtualBlock  )

◆ vmaAllocateMemory()

VkResult vmaAllocateMemory ( VmaAllocator  allocator,
const VkMemoryRequirements *  pVkMemoryRequirements,
const VmaAllocationCreateInfo pCreateInfo,
VmaAllocation pAllocation,
VmaAllocationInfo pAllocationInfo 
)

General purpose memory allocation.

Parameters
allocator
pVkMemoryRequirements
pCreateInfo
[out]pAllocationHandle to allocated memory.
[out]pAllocationInfoOptional. Information about allocated memory. It can be later fetched using function vmaGetAllocationInfo().

You should free the memory using vmaFreeMemory() or vmaFreeMemoryPages().

It is recommended to use vmaAllocateMemoryForBuffer(), vmaAllocateMemoryForImage(), vmaCreateBuffer(), vmaCreateImage() instead whenever possible.

◆ vmaAllocateMemoryForBuffer()

VkResult vmaAllocateMemoryForBuffer ( VmaAllocator  allocator,
VkBuffer  buffer,
const VmaAllocationCreateInfo pCreateInfo,
VmaAllocation pAllocation,
VmaAllocationInfo pAllocationInfo 
)
Parameters
allocator
buffer
pCreateInfo
[out]pAllocationHandle to allocated memory.
[out]pAllocationInfoOptional. Information about allocated memory. It can be later fetched using function vmaGetAllocationInfo().

You should free the memory using vmaFreeMemory().

◆ vmaAllocateMemoryForImage()

VkResult vmaAllocateMemoryForImage ( VmaAllocator  allocator,
VkImage  image,
const VmaAllocationCreateInfo pCreateInfo,
VmaAllocation pAllocation,
VmaAllocationInfo pAllocationInfo 
)

Function similar to vmaAllocateMemoryForBuffer().

◆ vmaAllocateMemoryPages()

VkResult vmaAllocateMemoryPages ( VmaAllocator  allocator,
const VkMemoryRequirements *  pVkMemoryRequirements,
const VmaAllocationCreateInfo pCreateInfo,
size_t  allocationCount,
VmaAllocation pAllocations,
VmaAllocationInfo pAllocationInfo 
)

General purpose memory allocation for multiple allocation objects at once.

Parameters
allocatorAllocator object.
pVkMemoryRequirementsMemory requirements for each allocation.
pCreateInfoCreation parameters for each alloction.
allocationCountNumber of allocations to make.
[out]pAllocationsPointer to array that will be filled with handles to created allocations.
[out]pAllocationInfoOptional. Pointer to array that will be filled with parameters of created allocations.

You should free the memory using vmaFreeMemory() or vmaFreeMemoryPages().

Word "pages" is just a suggestion to use this function to allocate pieces of memory needed for sparse binding. It is just a general purpose allocation function able to make multiple allocations at once. It may be internally optimized to be more efficient than calling vmaAllocateMemory() allocationCount times.

All allocations are made using same parameters. All of them are created out of the same memory pool and type. If any allocation fails, all allocations already made within this function call are also freed, so that when returned result is not VK_SUCCESS, pAllocation array is always entirely filled with VK_NULL_HANDLE.

◆ vmaBeginDefragmentationPass()

VkResult vmaBeginDefragmentationPass ( VmaAllocator  allocator,
VmaDefragmentationContext  context,
VmaDefragmentationPassInfo pInfo 
)

◆ vmaBindBufferMemory()

VkResult vmaBindBufferMemory ( VmaAllocator  allocator,
VmaAllocation  allocation,
VkBuffer  buffer 
)

Binds buffer to allocation.

Binds specified buffer to region of memory represented by specified allocation. Gets VkDeviceMemory handle and offset from the allocation. If you want to create a buffer, allocate memory for it and bind them together separately, you should use this function for binding instead of standard vkBindBufferMemory(), because it ensures proper synchronization so that when a VkDeviceMemory object is used by multiple allocations, calls to vkBind*Memory() or vkMapMemory() won't happen from multiple threads simultaneously (which is illegal in Vulkan).

It is recommended to use function vmaCreateBuffer() instead of this one.

◆ vmaBindBufferMemory2()

VkResult vmaBindBufferMemory2 ( VmaAllocator  allocator,
VmaAllocation  allocation,
VkDeviceSize  allocationLocalOffset,
VkBuffer  buffer,
const void *  pNext 
)

Binds buffer to allocation with additional parameters.

Parameters
allocator
allocation
allocationLocalOffsetAdditional offset to be added while binding, relative to the beginning of the allocation. Normally it should be 0.
buffer
pNextA chain of structures to be attached to VkBindBufferMemoryInfoKHR structure used internally. Normally it should be null.

This function is similar to vmaBindBufferMemory(), but it provides additional parameters.

If pNext is not null, VmaAllocator object must have been created with VMA_ALLOCATOR_CREATE_KHR_BIND_MEMORY2_BIT flag or with VmaAllocatorCreateInfo::vulkanApiVersion >= VK_API_VERSION_1_1. Otherwise the call fails.

◆ vmaBindImageMemory()

VkResult vmaBindImageMemory ( VmaAllocator  allocator,
VmaAllocation  allocation,
VkImage  image 
)

Binds image to allocation.

Binds specified image to region of memory represented by specified allocation. Gets VkDeviceMemory handle and offset from the allocation. If you want to create an image, allocate memory for it and bind them together separately, you should use this function for binding instead of standard vkBindImageMemory(), because it ensures proper synchronization so that when a VkDeviceMemory object is used by multiple allocations, calls to vkBind*Memory() or vkMapMemory() won't happen from multiple threads simultaneously (which is illegal in Vulkan).

It is recommended to use function vmaCreateImage() instead of this one.

◆ vmaBindImageMemory2()

VkResult vmaBindImageMemory2 ( VmaAllocator  allocator,
VmaAllocation  allocation,
VkDeviceSize  allocationLocalOffset,
VkImage  image,
const void *  pNext 
)

Binds image to allocation with additional parameters.

Parameters
allocator
allocation
allocationLocalOffsetAdditional offset to be added while binding, relative to the beginning of the allocation. Normally it should be 0.
image
pNextA chain of structures to be attached to VkBindImageMemoryInfoKHR structure used internally. Normally it should be null.

This function is similar to vmaBindImageMemory(), but it provides additional parameters.

If pNext is not null, VmaAllocator object must have been created with VMA_ALLOCATOR_CREATE_KHR_BIND_MEMORY2_BIT flag or with VmaAllocatorCreateInfo::vulkanApiVersion >= VK_API_VERSION_1_1. Otherwise the call fails.

◆ vmaBuildStatsString()

void vmaBuildStatsString ( VmaAllocator  allocator,
char **  ppStatsString,
VkBool32  detailedMap 
)

Builds and returns statistics as a null-terminated string in JSON format.

Parameters
allocator
[out]ppStatsStringMust be freed using vmaFreeStatsString() function.
detailedMap

◆ vmaBuildVirtualBlockStatsString()

void vmaBuildVirtualBlockStatsString ( VmaVirtualBlock  virtualBlock,
char **  ppStatsString,
VkBool32  detailedMap 
)

Builds and returns a null-terminated string in JSON format with information about given VmaVirtualBlock.

Parameters
virtualBlockVirtual block.
[out]ppStatsStringReturned string.
detailedMapPass VK_FALSE to only obtain statistics as returned by vmaCalculateVirtualBlockStats(). Pass VK_TRUE to also obtain full list of allocations and free spaces.

Returned string must be freed using vmaFreeVirtualBlockStatsString().

◆ vmaCalculateStats()

void vmaCalculateStats ( VmaAllocator  allocator,
VmaStats pStats 
)

Retrieves statistics from current state of the Allocator.

This function is called "calculate" not "get" because it has to traverse all internal data structures, so it may be quite slow. For faster but more brief statistics suitable to be called every frame or every allocation, use vmaGetBudget().

Note that when using allocator from multiple threads, returned information may immediately become outdated.

◆ vmaCalculateVirtualBlockStats()

void vmaCalculateVirtualBlockStats ( VmaVirtualBlock  virtualBlock,
VmaStatInfo pStatInfo 
)

Calculates and returns statistics about virtual allocations and memory usage in given VmaVirtualBlock.

◆ vmaCheckCorruption()

VkResult vmaCheckCorruption ( VmaAllocator  allocator,
uint32_t  memoryTypeBits 
)

Checks magic number in margins around all allocations in given memory types (in both default and custom pools) in search for corruptions.

Parameters
allocator
memoryTypeBitsBit mask, where each bit set means that a memory type with that index should be checked.

Corruption detection is enabled only when VMA_DEBUG_DETECT_CORRUPTION macro is defined to nonzero, VMA_DEBUG_MARGIN is defined to nonzero and only for memory types that are HOST_VISIBLE and HOST_COHERENT. For more information, see Corruption detection.

Possible return values:

  • VK_ERROR_FEATURE_NOT_PRESENT - corruption detection is not enabled for any of specified memory types.
  • VK_SUCCESS - corruption detection has been performed and succeeded.
  • VK_ERROR_UNKNOWN - corruption detection has been performed and found memory corruptions around one of the allocations. VMA_ASSERT is also fired in that case.
  • Other value: Error returned by Vulkan, e.g. memory mapping failure.

◆ vmaCheckPoolCorruption()

VkResult vmaCheckPoolCorruption ( VmaAllocator  allocator,
VmaPool  pool 
)

Checks magic number in margins around all allocations in given memory pool in search for corruptions.

Corruption detection is enabled only when VMA_DEBUG_DETECT_CORRUPTION macro is defined to nonzero, VMA_DEBUG_MARGIN is defined to nonzero and the pool is created in memory type that is HOST_VISIBLE and HOST_COHERENT. For more information, see Corruption detection.

Possible return values:

  • VK_ERROR_FEATURE_NOT_PRESENT - corruption detection is not enabled for specified pool.
  • VK_SUCCESS - corruption detection has been performed and succeeded.
  • VK_ERROR_UNKNOWN - corruption detection has been performed and found memory corruptions around one of the allocations. VMA_ASSERT is also fired in that case.
  • Other value: Error returned by Vulkan, e.g. memory mapping failure.

◆ vmaClearVirtualBlock()

void vmaClearVirtualBlock ( VmaVirtualBlock  virtualBlock)

Frees all virtual allocations inside given VmaVirtualBlock.

You must either call this function or free each virtual allocation individually with vmaVirtualFree() before destroying a virtual block. Otherwise, an assert is called.

If you keep pointer to some additional metadata associated with your virtual allocation in its pUserData, don't forget to free it as well.

◆ vmaCreateAllocator()

VkResult vmaCreateAllocator ( const VmaAllocatorCreateInfo pCreateInfo,
VmaAllocator pAllocator 
)

Creates Allocator object.

◆ vmaCreateBuffer()

VkResult vmaCreateBuffer ( VmaAllocator  allocator,
const VkBufferCreateInfo *  pBufferCreateInfo,
const VmaAllocationCreateInfo pAllocationCreateInfo,
VkBuffer *  pBuffer,
VmaAllocation pAllocation,
VmaAllocationInfo pAllocationInfo 
)
Parameters
allocator
pBufferCreateInfo
pAllocationCreateInfo
[out]pBufferBuffer that was created.
[out]pAllocationAllocation that was created.
[out]pAllocationInfoOptional. Information about allocated memory. It can be later fetched using function vmaGetAllocationInfo().

This function automatically:

  1. Creates buffer.
  2. Allocates appropriate memory for it.
  3. Binds the buffer with the memory.

If any of these operations fail, buffer and allocation are not created, returned value is negative error code, *pBuffer and *pAllocation are null.

If the function succeeded, you must destroy both buffer and allocation when you no longer need them using either convenience function vmaDestroyBuffer() or separately, using vkDestroyBuffer() and vmaFreeMemory().

If VMA_ALLOCATOR_CREATE_KHR_DEDICATED_ALLOCATION_BIT flag was used, VK_KHR_dedicated_allocation extension is used internally to query driver whether it requires or prefers the new buffer to have dedicated allocation. If yes, and if dedicated allocation is possible (VmaAllocationCreateInfo::pool is null and VMA_ALLOCATION_CREATE_NEVER_ALLOCATE_BIT is not used), it creates dedicated allocation for this buffer, just like when using VMA_ALLOCATION_CREATE_DEDICATED_MEMORY_BIT.

Note
This function creates a new VkBuffer. Sub-allocation of parts of one large buffer, although recommended as a good practice, is out of scope of this library and could be implemented by the user as a higher-level logic on top of VMA.

◆ vmaCreateBufferWithAlignment()

VkResult vmaCreateBufferWithAlignment ( VmaAllocator  allocator,
const VkBufferCreateInfo *  pBufferCreateInfo,
const VmaAllocationCreateInfo pAllocationCreateInfo,
VkDeviceSize  minAlignment,
VkBuffer *  pBuffer,
VmaAllocation pAllocation,
VmaAllocationInfo pAllocationInfo 
)

Creates a buffer with additional minimum alignment.

Similar to vmaCreateBuffer() but provides additional parameter minAlignment which allows to specify custom, minimum alignment to be used when placing the buffer inside a larger memory block, which may be needed e.g. for interop with OpenGL.

◆ vmaCreateImage()

VkResult vmaCreateImage ( VmaAllocator  allocator,
const VkImageCreateInfo *  pImageCreateInfo,
const VmaAllocationCreateInfo pAllocationCreateInfo,
VkImage *  pImage,
VmaAllocation pAllocation,
VmaAllocationInfo pAllocationInfo 
)

Function similar to vmaCreateBuffer().

◆ vmaCreateLostAllocation()

void vmaCreateLostAllocation ( VmaAllocator  allocator,
VmaAllocation pAllocation 
)

Creates new allocation that is in lost state from the beginning.

It can be useful if you need a dummy, non-null allocation.

You still need to destroy created object using vmaFreeMemory().

Returned allocation is not tied to any specific memory pool or memory type and not bound to any image or buffer. It has size = 0. It cannot be turned into a real, non-empty allocation.

◆ vmaCreatePool()

VkResult vmaCreatePool ( VmaAllocator  allocator,
const VmaPoolCreateInfo pCreateInfo,
VmaPool pPool 
)

Allocates Vulkan device memory and creates VmaPool object.

Parameters
allocatorAllocator object.
pCreateInfoParameters of pool to create.
[out]pPoolHandle to created pool.

◆ vmaCreateVirtualBlock()

VkResult vmaCreateVirtualBlock ( const VmaVirtualBlockCreateInfo pCreateInfo,
VmaVirtualBlock pVirtualBlock 
)

Creates new VmaVirtualBlock object.

Parameters
pCreateInfoParameters for creation.
[out]pVirtualBlockReturned virtual block object or VMA_NULL if creation failed.

◆ vmaDefragment()

VkResult vmaDefragment ( VmaAllocator  allocator,
const VmaAllocation pAllocations,
size_t  allocationCount,
VkBool32 *  pAllocationsChanged,
const VmaDefragmentationInfo pDefragmentationInfo,
VmaDefragmentationStats pDefragmentationStats 
)

Deprecated. Compacts memory by moving allocations.

Parameters
allocator
pAllocationsArray of allocations that can be moved during this compation.
allocationCountNumber of elements in pAllocations and pAllocationsChanged arrays.
[out]pAllocationsChangedArray of boolean values that will indicate whether matching allocation in pAllocations array has been moved. This parameter is optional. Pass null if you don't need this information.
pDefragmentationInfoConfiguration parameters. Optional - pass null to use default values.
[out]pDefragmentationStatsStatistics returned by the function. Optional - pass null if you don't need this information.
Returns
VK_SUCCESS if completed, negative error code in case of error.
Deprecated:
This is a part of the old interface. It is recommended to use structure VmaDefragmentationInfo2 and function vmaDefragmentationBegin() instead.

This function works by moving allocations to different places (different VkDeviceMemory objects and/or different offsets) in order to optimize memory usage. Only allocations that are in pAllocations array can be moved. All other allocations are considered nonmovable in this call. Basic rules:

  • Only allocations made in memory types that have VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT and VK_MEMORY_PROPERTY_HOST_COHERENT_BIT flags can be compacted. You may pass other allocations but it makes no sense - these will never be moved.
  • Custom pools created with VMA_POOL_CREATE_LINEAR_ALGORITHM_BIT or VMA_POOL_CREATE_BUDDY_ALGORITHM_BIT flag are not defragmented. Allocations passed to this function that come from such pools are ignored.
  • Allocations created with VMA_ALLOCATION_CREATE_DEDICATED_MEMORY_BIT or created as dedicated allocations for any other reason are also ignored.
  • Both allocations made with or without VMA_ALLOCATION_CREATE_MAPPED_BIT flag can be compacted. If not persistently mapped, memory will be mapped temporarily inside this function if needed.
  • You must not pass same VmaAllocation object multiple times in pAllocations array.

The function also frees empty VkDeviceMemory blocks.

Warning: This function may be time-consuming, so you shouldn't call it too often (like after every resource creation/destruction). You can call it on special occasions (like when reloading a game level or when you just destroyed a lot of objects). Calling it every frame may be OK, but you should measure that on your platform.

For more information, see Defragmentation chapter.

◆ vmaDefragmentationBegin()

VkResult vmaDefragmentationBegin ( VmaAllocator  allocator,
const VmaDefragmentationInfo2 pInfo,
VmaDefragmentationStats pStats,
VmaDefragmentationContext pContext 
)

Begins defragmentation process.

Parameters
allocatorAllocator object.
pInfoStructure filled with parameters of defragmentation.
[out]pStatsOptional. Statistics of defragmentation. You can pass null if you are not interested in this information.
[out]pContextContext object that must be passed to vmaDefragmentationEnd() to finish defragmentation.
Returns
VK_SUCCESS and *pContext == null if defragmentation finished within this function call. VK_NOT_READY and *pContext != null if defragmentation has been started and you need to call vmaDefragmentationEnd() to finish it. Negative value in case of error.

Use this function instead of old, deprecated vmaDefragment().

Warning! Between the call to vmaDefragmentationBegin() and vmaDefragmentationEnd():

  • You should not use any of allocations passed as pInfo->pAllocations or any allocations that belong to pools passed as pInfo->pPools, including calling vmaGetAllocationInfo(), vmaTouchAllocation(), or access their data.
  • Some mutexes protecting internal data structures may be locked, so trying to make or free any allocations, bind buffers or images, map memory, or launch another simultaneous defragmentation in between may cause stall (when done on another thread) or deadlock (when done on the same thread), unless you are 100% sure that defragmented allocations are in different pools.
  • Information returned via pStats and pInfo->pAllocationsChanged are undefined. They become valid after call to vmaDefragmentationEnd().
  • If pInfo->commandBuffer is not null, you must submit that command buffer and make sure it finished execution before calling vmaDefragmentationEnd().

For more information and important limitations regarding defragmentation, see documentation chapter: Defragmentation.

◆ vmaDefragmentationEnd()

VkResult vmaDefragmentationEnd ( VmaAllocator  allocator,
VmaDefragmentationContext  context 
)

Ends defragmentation process.

Use this function to finish defragmentation started by vmaDefragmentationBegin(). It is safe to pass context == null. The function then does nothing.

◆ vmaDestroyAllocator()

void vmaDestroyAllocator ( VmaAllocator  allocator)

Destroys allocator object.

◆ vmaDestroyBuffer()

void vmaDestroyBuffer ( VmaAllocator  allocator,
VkBuffer  buffer,
VmaAllocation  allocation 
)

Destroys Vulkan buffer and frees allocated memory.

This is just a convenience function equivalent to:

vkDestroyBuffer(device, buffer, allocationCallbacks);
vmaFreeMemory(allocator, allocation);
void vmaFreeMemory(VmaAllocator allocator, const VmaAllocation allocation)
Frees memory previously allocated using vmaAllocateMemory(), vmaAllocateMemoryForBuffer(),...

It it safe to pass null as buffer and/or allocation.

◆ vmaDestroyImage()

void vmaDestroyImage ( VmaAllocator  allocator,
VkImage  image,
VmaAllocation  allocation 
)

Destroys Vulkan image and frees allocated memory.

This is just a convenience function equivalent to:

vkDestroyImage(device, image, allocationCallbacks);
vmaFreeMemory(allocator, allocation);

It it safe to pass null as image and/or allocation.

◆ vmaDestroyPool()

void vmaDestroyPool ( VmaAllocator  allocator,
VmaPool  pool 
)

Destroys VmaPool object and frees Vulkan device memory.

◆ vmaDestroyVirtualBlock()

void vmaDestroyVirtualBlock ( VmaVirtualBlock  virtualBlock)

Destroys VmaVirtualBlock object.

Please note that you should consciously handle virtual allocations that could remain unfreed in the block. You should either free them individually using vmaVirtualFree() or call vmaClearVirtualBlock() if you are sure this is what you want. If you do neither, an assert is called.

If you keep pointers to some additional metadata associated with your virtual allocations in their pUserData, don't forget to free them.

◆ vmaEndDefragmentationPass()

VkResult vmaEndDefragmentationPass ( VmaAllocator  allocator,
VmaDefragmentationContext  context 
)

◆ vmaFindMemoryTypeIndex()

VkResult vmaFindMemoryTypeIndex ( VmaAllocator  allocator,
uint32_t  memoryTypeBits,
const VmaAllocationCreateInfo pAllocationCreateInfo,
uint32_t *  pMemoryTypeIndex 
)

Helps to find memoryTypeIndex, given memoryTypeBits and VmaAllocationCreateInfo.

This algorithm tries to find a memory type that:

  • Is allowed by memoryTypeBits.
  • Contains all the flags from pAllocationCreateInfo->requiredFlags.
  • Matches intended usage.
  • Has as many flags from pAllocationCreateInfo->preferredFlags as possible.
Returns
Returns VK_ERROR_FEATURE_NOT_PRESENT if not found. Receiving such result from this function or any other allocating function probably means that your device doesn't support any memory type with requested features for the specific type of resource you want to use it for. Please check parameters of your resource, like image layout (OPTIMAL versus LINEAR) or mip level count.

◆ vmaFindMemoryTypeIndexForBufferInfo()

VkResult vmaFindMemoryTypeIndexForBufferInfo ( VmaAllocator  allocator,
const VkBufferCreateInfo *  pBufferCreateInfo,
const VmaAllocationCreateInfo pAllocationCreateInfo,
uint32_t *  pMemoryTypeIndex 
)

Helps to find memoryTypeIndex, given VkBufferCreateInfo and VmaAllocationCreateInfo.

It can be useful e.g. to determine value to be used as VmaPoolCreateInfo::memoryTypeIndex. It internally creates a temporary, dummy buffer that never has memory bound. It is just a convenience function, equivalent to calling:

  • vkCreateBuffer
  • vkGetBufferMemoryRequirements
  • vmaFindMemoryTypeIndex
  • vkDestroyBuffer

◆ vmaFindMemoryTypeIndexForImageInfo()

VkResult vmaFindMemoryTypeIndexForImageInfo ( VmaAllocator  allocator,
const VkImageCreateInfo *  pImageCreateInfo,
const VmaAllocationCreateInfo pAllocationCreateInfo,
uint32_t *  pMemoryTypeIndex 
)

Helps to find memoryTypeIndex, given VkImageCreateInfo and VmaAllocationCreateInfo.

It can be useful e.g. to determine value to be used as VmaPoolCreateInfo::memoryTypeIndex. It internally creates a temporary, dummy image that never has memory bound. It is just a convenience function, equivalent to calling:

  • vkCreateImage
  • vkGetImageMemoryRequirements
  • vmaFindMemoryTypeIndex
  • vkDestroyImage

◆ vmaFlushAllocation()

VkResult vmaFlushAllocation ( VmaAllocator  allocator,
VmaAllocation  allocation,
VkDeviceSize  offset,
VkDeviceSize  size 
)

Flushes memory of given allocation.

Calls vkFlushMappedMemoryRanges() for memory associated with given range of given allocation. It needs to be called after writing to a mapped memory for memory types that are not HOST_COHERENT. Unmap operation doesn't do that automatically.

  • offset must be relative to the beginning of allocation.
  • size can be VK_WHOLE_SIZE. It means all memory from offset the the end of given allocation.
  • offset and size don't have to be aligned. They are internally rounded down/up to multiply of nonCoherentAtomSize.
  • If size is 0, this call is ignored.
  • If memory type that the allocation belongs to is not HOST_VISIBLE or it is HOST_COHERENT, this call is ignored.

Warning! offset and size are relative to the contents of given allocation. If you mean whole allocation, you can pass 0 and VK_WHOLE_SIZE, respectively. Do not pass allocation's offset as offset!!!

This function returns the VkResult from vkFlushMappedMemoryRanges if it is called, otherwise VK_SUCCESS.

◆ vmaFlushAllocations()

VkResult vmaFlushAllocations ( VmaAllocator  allocator,
uint32_t  allocationCount,
const VmaAllocation allocations,
const VkDeviceSize *  offsets,
const VkDeviceSize *  sizes 
)

Flushes memory of given set of allocations.

Calls vkFlushMappedMemoryRanges() for memory associated with given ranges of given allocations. For more information, see documentation of vmaFlushAllocation().

Parameters
allocator
allocationCount
allocations
offsetsIf not null, it must point to an array of offsets of regions to flush, relative to the beginning of respective allocations. Null means all ofsets are zero.
sizesIf not null, it must point to an array of sizes of regions to flush in respective allocations. Null means VK_WHOLE_SIZE for all allocations.

This function returns the VkResult from vkFlushMappedMemoryRanges if it is called, otherwise VK_SUCCESS.

◆ vmaFreeMemory()

void vmaFreeMemory ( VmaAllocator  allocator,
const VmaAllocation  allocation 
)

Frees memory previously allocated using vmaAllocateMemory(), vmaAllocateMemoryForBuffer(), or vmaAllocateMemoryForImage().

Passing VK_NULL_HANDLE as allocation is valid. Such function call is just skipped.

◆ vmaFreeMemoryPages()

void vmaFreeMemoryPages ( VmaAllocator  allocator,
size_t  allocationCount,
const VmaAllocation pAllocations 
)

Frees memory and destroys multiple allocations.

Word "pages" is just a suggestion to use this function to free pieces of memory used for sparse binding. It is just a general purpose function to free memory and destroy allocations made using e.g. vmaAllocateMemory(), vmaAllocateMemoryPages() and other functions. It may be internally optimized to be more efficient than calling vmaFreeMemory() allocationCount times.

Allocations in pAllocations array can come from any memory pools and types. Passing VK_NULL_HANDLE as elements of pAllocations array is valid. Such entries are just skipped.

◆ vmaFreeStatsString()

void vmaFreeStatsString ( VmaAllocator  allocator,
char *  pStatsString 
)

◆ vmaFreeVirtualBlockStatsString()

void vmaFreeVirtualBlockStatsString ( VmaVirtualBlock  virtualBlock,
char *  pStatsString 
)

Frees a string returned by vmaBuildVirtualBlockStatsString().

◆ vmaGetAllocationInfo()

void vmaGetAllocationInfo ( VmaAllocator  allocator,
VmaAllocation  allocation,
VmaAllocationInfo pAllocationInfo 
)

Returns current information about specified allocation and atomically marks it as used in current frame.

Current paramteres of given allocation are returned in pAllocationInfo.

This function also atomically "touches" allocation - marks it as used in current frame, just like vmaTouchAllocation(). If the allocation is in lost state, pAllocationInfo->deviceMemory == VK_NULL_HANDLE.

Although this function uses atomics and doesn't lock any mutex, so it should be quite efficient, you can avoid calling it too often.

◆ vmaGetAllocatorInfo()

void vmaGetAllocatorInfo ( VmaAllocator  allocator,
VmaAllocatorInfo pAllocatorInfo 
)

Returns information about existing VmaAllocator object - handle to Vulkan device etc.

It might be useful if you want to keep just the VmaAllocator handle and fetch other required handles to VkPhysicalDevice, VkDevice etc. every time using this function.

◆ vmaGetBudget()

void vmaGetBudget ( VmaAllocator  allocator,
VmaBudget pBudget 
)

Retrieves information about current memory budget for all memory heaps.

Parameters
allocator
[out]pBudgetMust point to array with number of elements at least equal to number of memory heaps in physical device used.

This function is called "get" not "calculate" because it is very fast, suitable to be called every frame or every allocation. For more detailed statistics use vmaCalculateStats().

Note that when using allocator from multiple threads, returned information may immediately become outdated.

◆ vmaGetMemoryProperties()

void vmaGetMemoryProperties ( VmaAllocator  allocator,
const VkPhysicalDeviceMemoryProperties **  ppPhysicalDeviceMemoryProperties 
)

PhysicalDeviceMemoryProperties are fetched from physicalDevice by the allocator. You can access it here, without fetching it again on your own.

◆ vmaGetMemoryTypeProperties()

void vmaGetMemoryTypeProperties ( VmaAllocator  allocator,
uint32_t  memoryTypeIndex,
VkMemoryPropertyFlags *  pFlags 
)

Given Memory Type Index, returns Property Flags of this memory type.

This is just a convenience function. Same information can be obtained using vmaGetMemoryProperties().

◆ vmaGetPhysicalDeviceProperties()

void vmaGetPhysicalDeviceProperties ( VmaAllocator  allocator,
const VkPhysicalDeviceProperties **  ppPhysicalDeviceProperties 
)

PhysicalDeviceProperties are fetched from physicalDevice by the allocator. You can access it here, without fetching it again on your own.

◆ vmaGetPoolName()

void vmaGetPoolName ( VmaAllocator  allocator,
VmaPool  pool,
const char **  ppName 
)

Retrieves name of a custom pool.

After the call ppName is either null or points to an internally-owned null-terminated string containing name of the pool that was previously set. The pointer becomes invalid when the pool is destroyed or its name is changed using vmaSetPoolName().

◆ vmaGetPoolStats()

void vmaGetPoolStats ( VmaAllocator  allocator,
VmaPool  pool,
VmaPoolStats pPoolStats 
)

Retrieves statistics of existing VmaPool object.

Parameters
allocatorAllocator object.
poolPool object.
[out]pPoolStatsStatistics of specified pool.

◆ vmaGetVirtualAllocationInfo()

void vmaGetVirtualAllocationInfo ( VmaVirtualBlock  virtualBlock,
VkDeviceSize  offset,
VmaVirtualAllocationInfo pVirtualAllocInfo 
)

Returns information about a specific virtual allocation within a virtual block, like its size and pUserData pointer.

◆ vmaInvalidateAllocation()

VkResult vmaInvalidateAllocation ( VmaAllocator  allocator,
VmaAllocation  allocation,
VkDeviceSize  offset,
VkDeviceSize  size 
)

Invalidates memory of given allocation.

Calls vkInvalidateMappedMemoryRanges() for memory associated with given range of given allocation. It needs to be called before reading from a mapped memory for memory types that are not HOST_COHERENT. Map operation doesn't do that automatically.

  • offset must be relative to the beginning of allocation.
  • size can be VK_WHOLE_SIZE. It means all memory from offset the the end of given allocation.
  • offset and size don't have to be aligned. They are internally rounded down/up to multiply of nonCoherentAtomSize.
  • If size is 0, this call is ignored.
  • If memory type that the allocation belongs to is not HOST_VISIBLE or it is HOST_COHERENT, this call is ignored.

Warning! offset and size are relative to the contents of given allocation. If you mean whole allocation, you can pass 0 and VK_WHOLE_SIZE, respectively. Do not pass allocation's offset as offset!!!

This function returns the VkResult from vkInvalidateMappedMemoryRanges if it is called, otherwise VK_SUCCESS.

◆ vmaInvalidateAllocations()

VkResult vmaInvalidateAllocations ( VmaAllocator  allocator,
uint32_t  allocationCount,
const VmaAllocation allocations,
const VkDeviceSize *  offsets,
const VkDeviceSize *  sizes 
)

Invalidates memory of given set of allocations.

Calls vkInvalidateMappedMemoryRanges() for memory associated with given ranges of given allocations. For more information, see documentation of vmaInvalidateAllocation().

Parameters
allocator
allocationCount
allocations
offsetsIf not null, it must point to an array of offsets of regions to flush, relative to the beginning of respective allocations. Null means all ofsets are zero.
sizesIf not null, it must point to an array of sizes of regions to flush in respective allocations. Null means VK_WHOLE_SIZE for all allocations.

This function returns the VkResult from vkInvalidateMappedMemoryRanges if it is called, otherwise VK_SUCCESS.

◆ vmaIsVirtualBlockEmpty()

VkBool32 vmaIsVirtualBlockEmpty ( VmaVirtualBlock  virtualBlock)

Returns true of the VmaVirtualBlock is empty - contains 0 virtual allocations and has all its space available for new allocations.

◆ vmaMakePoolAllocationsLost()

void vmaMakePoolAllocationsLost ( VmaAllocator  allocator,
VmaPool  pool,
size_t *  pLostAllocationCount 
)

Marks all allocations in given pool as lost if they are not used in current frame or VmaPoolCreateInfo::frameInUseCount back from now.

Parameters
allocatorAllocator object.
poolPool.
[out]pLostAllocationCountNumber of allocations marked as lost. Optional - pass null if you don't need this information.

◆ vmaMapMemory()

VkResult vmaMapMemory ( VmaAllocator  allocator,
VmaAllocation  allocation,
void **  ppData 
)

Maps memory represented by given allocation and returns pointer to it.

Maps memory represented by given allocation to make it accessible to CPU code. When succeeded, *ppData contains pointer to first byte of this memory. If the allocation is part of bigger VkDeviceMemory block, the pointer is correctly offsetted to the beginning of region assigned to this particular allocation.

Mapping is internally reference-counted and synchronized, so despite raw Vulkan function vkMapMemory() cannot be used to map same block of VkDeviceMemory multiple times simultaneously, it is safe to call this function on allocations assigned to the same memory block. Actual Vulkan memory will be mapped on first mapping and unmapped on last unmapping.

If the function succeeded, you must call vmaUnmapMemory() to unmap the allocation when mapping is no longer needed or before freeing the allocation, at the latest.

It also safe to call this function multiple times on the same allocation. You must call vmaUnmapMemory() same number of times as you called vmaMapMemory().

It is also safe to call this function on allocation created with VMA_ALLOCATION_CREATE_MAPPED_BIT flag. Its memory stays mapped all the time. You must still call vmaUnmapMemory() same number of times as you called vmaMapMemory(). You must not call vmaUnmapMemory() additional time to free the "0-th" mapping made automatically due to VMA_ALLOCATION_CREATE_MAPPED_BIT flag.

This function fails when used on allocation made in memory type that is not HOST_VISIBLE.

This function always fails when called for allocation that was created with VMA_ALLOCATION_CREATE_CAN_BECOME_LOST_BIT flag. Such allocations cannot be mapped.

This function doesn't automatically flush or invalidate caches. If the allocation is made from a memory types that is not HOST_COHERENT, you also need to use vmaInvalidateAllocation() / vmaFlushAllocation(), as required by Vulkan specification.

◆ vmaSetAllocationUserData()

void vmaSetAllocationUserData ( VmaAllocator  allocator,
VmaAllocation  allocation,
void *  pUserData 
)

Sets pUserData in given allocation to new value.

If the allocation was created with VMA_ALLOCATION_CREATE_USER_DATA_COPY_STRING_BIT, pUserData must be either null, or pointer to a null-terminated string. The function makes local copy of the string and sets it as allocation's pUserData. String passed as pUserData doesn't need to be valid for whole lifetime of the allocation - you can free it after this call. String previously pointed by allocation's pUserData is freed from memory.

If the flag was not used, the value of pointer pUserData is just copied to allocation's pUserData. It is opaque, so you can use it however you want - e.g. as a pointer, ordinal number or some handle to you own data.

◆ vmaSetCurrentFrameIndex()

void vmaSetCurrentFrameIndex ( VmaAllocator  allocator,
uint32_t  frameIndex 
)

Sets index of the current frame.

This function must be used if you make allocations with VMA_ALLOCATION_CREATE_CAN_BECOME_LOST_BIT and VMA_ALLOCATION_CREATE_CAN_MAKE_OTHER_LOST_BIT flags to inform the allocator when a new frame begins. Allocations queried using vmaGetAllocationInfo() cannot become lost in the current frame.

◆ vmaSetPoolName()

void vmaSetPoolName ( VmaAllocator  allocator,
VmaPool  pool,
const char *  pName 
)

Sets name of a custom pool.

pName can be either null or pointer to a null-terminated string with new name for the pool. Function makes internal copy of the string, so it can be changed or freed immediately after this call.

◆ vmaSetVirtualAllocationUserData()

void vmaSetVirtualAllocationUserData ( VmaVirtualBlock  virtualBlock,
VkDeviceSize  offset,
void *  pUserData 
)

Changes custom pointer associated with given virtual allocation.

◆ vmaTouchAllocation()

VkBool32 vmaTouchAllocation ( VmaAllocator  allocator,
VmaAllocation  allocation 
)

Returns VK_TRUE if allocation is not lost and atomically marks it as used in current frame.

If the allocation has been created with VMA_ALLOCATION_CREATE_CAN_BECOME_LOST_BIT flag, this function returns VK_TRUE if it is not in lost state, so it can still be used. It then also atomically "touches" the allocation - marks it as used in current frame, so that you can be sure it won't become lost in current frame or next frameInUseCount frames.

If the allocation is in lost state, the function returns VK_FALSE. Memory of such allocation, as well as buffer or image bound to it, should not be used. Lost allocation and the buffer/image still need to be destroyed.

If the allocation has been created without VMA_ALLOCATION_CREATE_CAN_BECOME_LOST_BIT flag, this function always returns VK_TRUE.

◆ vmaUnmapMemory()

void vmaUnmapMemory ( VmaAllocator  allocator,
VmaAllocation  allocation 
)

Unmaps memory represented by given allocation, mapped previously using vmaMapMemory().

For details, see description of vmaMapMemory().

This function doesn't automatically flush or invalidate caches. If the allocation is made from a memory types that is not HOST_COHERENT, you also need to use vmaInvalidateAllocation() / vmaFlushAllocation(), as required by Vulkan specification.

◆ vmaVirtualAllocate()

VkResult vmaVirtualAllocate ( VmaVirtualBlock  virtualBlock,
const VmaVirtualAllocationCreateInfo pCreateInfo,
VkDeviceSize *  pOffset 
)

Allocates new virtual allocation inside given VmaVirtualBlock.

There is no handle type for a virtual allocation. Virtual allocations within a specific virtual block are uniquely identified by their offsets.

If the allocation fails due to not enough free space available, VK_ERROR_OUT_OF_DEVICE_MEMORY is returned (despite the function doesn't ever allocate actual GPU memory).

◆ vmaVirtualFree()

void vmaVirtualFree ( VmaVirtualBlock  virtualBlock,
VkDeviceSize  offset 
)

Frees virtual allocation inside given VmaVirtualBlock.