Vulkan Memory Allocator: Memory allocation

Vulkan Memory Allocator

Loading...
Searching...
No Matches
Classes | Typedefs | Enumerations | Functions
Memory allocation

API elements related to the allocation, deallocation, and management of Vulkan memory, buffers, images. Most basic ones being: vmaCreateBuffer(), vmaCreateImage(). More...

## Classes
struct | VmaAllocationCreateInfo
| Parameters of new VmaAllocation. More...
struct | VmaPoolCreateInfo
| Describes parameter of created VmaPool. More...
struct | VmaAllocationInfo
struct | VmaAllocationInfo2
| Extended parameters of a VmaAllocation object that can be retrieved using function vmaGetAllocationInfo2(). More...
struct | VmaDefragmentationInfo
| Parameters for defragmentation. More...
struct | VmaDefragmentationMove
| Single move of an allocation to be done for defragmentation. More...
struct | VmaDefragmentationPassMoveInfo
| Parameters for incremental defragmentation steps. More...
struct | VmaDefragmentationStats
| Statistics returned for defragmentation process in function vmaEndDefragmentation(). More...
struct | VmaPool
| Represents custom memory pool. More...
struct | VmaAllocation
| Represents single memory allocation. More...
struct | VmaDefragmentationContext
| An opaque object that represents started defragmentation process. More...

## Typedefs
typedef enum VmaMemoryUsage | VmaMemoryUsage
| Intended usage of the allocated memory.
typedef enum VmaAllocationCreateFlagBits | VmaAllocationCreateFlagBits
| Flags to be passed as VmaAllocationCreateInfo::flags.
typedef VkFlags | VmaAllocationCreateFlags
| See VmaAllocationCreateFlagBits.
typedef enum VmaPoolCreateFlagBits | VmaPoolCreateFlagBits
| Flags to be passed as VmaPoolCreateInfo::flags.
typedef VkFlags | VmaPoolCreateFlags
| Flags to be passed as VmaPoolCreateInfo::flags. See VmaPoolCreateFlagBits.
typedef enum VmaDefragmentationFlagBits | VmaDefragmentationFlagBits
| Flags to be passed as VmaDefragmentationInfo::flags.
typedef VkFlags | VmaDefragmentationFlags
| See VmaDefragmentationFlagBits.
typedef enum VmaDefragmentationMoveOperation | VmaDefragmentationMoveOperation
| Operation performed on single defragmentation move. See structure VmaDefragmentationMove.
typedef struct VmaAllocationCreateInfo | VmaAllocationCreateInfo
| Parameters of new VmaAllocation.
typedef struct VmaPoolCreateInfo | VmaPoolCreateInfo
| Describes parameter of created VmaPool.
typedef struct VmaAllocationInfo | VmaAllocationInfo
typedef struct VmaAllocationInfo2 | VmaAllocationInfo2
| Extended parameters of a VmaAllocation object that can be retrieved using function vmaGetAllocationInfo2().
typedef VkBool32(VKAPI_PTR * | PFN_vmaCheckDefragmentationBreakFunction) (void *pUserData)
typedef struct VmaDefragmentationInfo | VmaDefragmentationInfo
| Parameters for defragmentation.
typedef struct VmaDefragmentationMove | VmaDefragmentationMove
| Single move of an allocation to be done for defragmentation.
typedef struct VmaDefragmentationPassMoveInfo | VmaDefragmentationPassMoveInfo
| Parameters for incremental defragmentation steps.
typedef struct VmaDefragmentationStats | VmaDefragmentationStats
| Statistics returned for defragmentation process in function vmaEndDefragmentation().

## Enumerations
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_AUTO = 7 , VMA_MEMORY_USAGE_AUTO_PREFER_DEVICE = 8 , VMA_MEMORY_USAGE_AUTO_PREFER_HOST = 9 , VMA_MEMORY_USAGE_MAX_ENUM = 0x7FFFFFFF }
| Intended usage of the allocated memory. More...
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_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_CAN_ALIAS_BIT = 0x00000200 , VMA_ALLOCATION_CREATE_HOST_ACCESS_SEQUENTIAL_WRITE_BIT = 0x00000400 , VMA_ALLOCATION_CREATE_HOST_ACCESS_RANDOM_BIT = 0x00000800 , VMA_ALLOCATION_CREATE_HOST_ACCESS_ALLOW_TRANSFER_INSTEAD_BIT = 0x00001000 , VMA_ALLOCATION_CREATE_STRATEGY_MIN_MEMORY_BIT = 0x00010000 , VMA_ALLOCATION_CREATE_STRATEGY_MIN_TIME_BIT = 0x00020000 , VMA_ALLOCATION_CREATE_STRATEGY_MIN_OFFSET_BIT = 0x00040000 , VMA_ALLOCATION_CREATE_STRATEGY_BEST_FIT_BIT = VMA_ALLOCATION_CREATE_STRATEGY_MIN_MEMORY_BIT , VMA_ALLOCATION_CREATE_STRATEGY_FIRST_FIT_BIT = VMA_ALLOCATION_CREATE_STRATEGY_MIN_TIME_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_ALGORITHM_MASK , VMA_POOL_CREATE_FLAG_BITS_MAX_ENUM = 0x7FFFFFFF }
| Flags to be passed as VmaPoolCreateInfo::flags. More...
enum | VmaDefragmentationFlagBits { VMA_DEFRAGMENTATION_FLAG_ALGORITHM_FAST_BIT = 0x1 , VMA_DEFRAGMENTATION_FLAG_ALGORITHM_BALANCED_BIT = 0x2 , VMA_DEFRAGMENTATION_FLAG_ALGORITHM_FULL_BIT = 0x4 , VMA_DEFRAGMENTATION_FLAG_ALGORITHM_EXTENSIVE_BIT = 0x8 , VMA_DEFRAGMENTATION_FLAG_ALGORITHM_MASK , VMA_DEFRAGMENTATION_FLAG_BITS_MAX_ENUM = 0x7FFFFFFF }
| Flags to be passed as VmaDefragmentationInfo::flags. More...
enum | VmaDefragmentationMoveOperation { VMA_DEFRAGMENTATION_MOVE_OPERATION_COPY = 0 , VMA_DEFRAGMENTATION_MOVE_OPERATION_IGNORE = 1 , VMA_DEFRAGMENTATION_MOVE_OPERATION_DESTROY = 2 }
| Operation performed on single defragmentation move. See structure VmaDefragmentationMove. More...

## Functions
VkResult | vmaFindMemoryTypeIndex (VmaAllocator allocator, uint32_t memoryTypeBits, const VmaAllocationCreateInfo *pAllocationCreateInfo, uint32_t *pMemoryTypeIndex)
| Helps to find memoryTypeIndex, given memoryTypeBits and VmaAllocationCreateInfo.
VkResult | vmaFindMemoryTypeIndexForBufferInfo (VmaAllocator allocator, const VkBufferCreateInfo *pBufferCreateInfo, const VmaAllocationCreateInfo *pAllocationCreateInfo, uint32_t *pMemoryTypeIndex)
| Helps to find memoryTypeIndex, given VkBufferCreateInfo and VmaAllocationCreateInfo.
VkResult | vmaFindMemoryTypeIndexForImageInfo (VmaAllocator allocator, const VkImageCreateInfo *pImageCreateInfo, const VmaAllocationCreateInfo *pAllocationCreateInfo, uint32_t *pMemoryTypeIndex)
| Helps to find memoryTypeIndex, given VkImageCreateInfo and VmaAllocationCreateInfo.
VkResult | vmaCreatePool (VmaAllocator allocator, const VmaPoolCreateInfo *pCreateInfo, VmaPool *pPool)
| Allocates Vulkan device memory and creates VmaPool object.
void | vmaDestroyPool (VmaAllocator allocator, VmaPool pool)
| Destroys VmaPool object and frees Vulkan device memory.
VkResult | vmaCheckPoolCorruption (VmaAllocator allocator, VmaPool pool)
| Checks magic number in margins around all allocations in given memory pool in search for corruptions.
void | vmaGetPoolName (VmaAllocator allocator, VmaPool pool, const char **ppName)
| Retrieves name of a custom pool.
void | vmaSetPoolName (VmaAllocator allocator, VmaPool pool, const char *pName)
| Sets name of a custom pool.
VkResult | vmaAllocateMemory (VmaAllocator allocator, const VkMemoryRequirements *pVkMemoryRequirements, const VmaAllocationCreateInfo *pCreateInfo, VmaAllocation *pAllocation, VmaAllocationInfo *pAllocationInfo)
| General purpose memory allocation.
VkResult | vmaAllocateDedicatedMemory (VmaAllocator allocator, const VkMemoryRequirements *pVkMemoryRequirements, const VmaAllocationCreateInfo *pCreateInfo, void *(VkMemoryAllocateInfo) pMemoryAllocateNext, VmaAllocation *pAllocation, VmaAllocationInfo *pAllocationInfo)
| General purpose allocation of a dedicated memory.
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.
VkResult | vmaAllocateMemoryForBuffer (VmaAllocator allocator, VkBuffer buffer, const VmaAllocationCreateInfo *pCreateInfo, VmaAllocation *pAllocation, VmaAllocationInfo *pAllocationInfo)
| Allocates memory suitable for given VkBuffer.
VkResult | vmaAllocateMemoryForImage (VmaAllocator allocator, VkImage image, const VmaAllocationCreateInfo *pCreateInfo, VmaAllocation *pAllocation, VmaAllocationInfo *pAllocationInfo)
| Allocates memory suitable for given VkImage.
void | vmaFreeMemory (VmaAllocator allocator, VmaAllocation allocation)
| Frees memory previously allocated using vmaAllocateMemory(), vmaAllocateMemoryForBuffer(), or vmaAllocateMemoryForImage().
void | vmaFreeMemoryPages (VmaAllocator allocator, size_t allocationCount, const VmaAllocation *pAllocations)
| Frees memory and destroys multiple allocations.
void | vmaGetAllocationInfo (VmaAllocator allocator, VmaAllocation allocation, VmaAllocationInfo *pAllocationInfo)
| Returns current information about specified allocation.
void | vmaGetAllocationInfo2 (VmaAllocator allocator, VmaAllocation allocation, VmaAllocationInfo2 *pAllocationInfo)
| Returns extended information about specified allocation.
void | vmaSetAllocationUserData (VmaAllocator allocator, VmaAllocation allocation, void *pUserData)
| Sets pUserData in given allocation to new value.
void | vmaSetAllocationName (VmaAllocator allocator, VmaAllocation allocation, const char *pName)
| Sets pName in given allocation to new value.
void | vmaGetAllocationMemoryProperties (VmaAllocator allocator, VmaAllocation allocation, VkMemoryPropertyFlags *pFlags)
| Given an allocation, returns Property Flags of its memory type.
VkResult | vmaGetMemoryWin32Handle (VmaAllocator allocator, VmaAllocation allocation, HANDLE hTargetProcess, HANDLE *pHandle)
| Given an allocation, returns Win32 handle that may be imported by other processes or APIs.
VkResult | vmaGetMemoryWin32Handle2 (VmaAllocator allocator, VmaAllocation allocation, VkExternalMemoryHandleTypeFlagBits handleType, HANDLE hTargetProcess, HANDLE *pHandle)
| Given an allocation, returns Win32 handle that may be imported by other processes or APIs.
VkResult | vmaMapMemory (VmaAllocator allocator, VmaAllocation allocation, void **ppData)
| Maps memory represented by given allocation and returns pointer to it.
void | vmaUnmapMemory (VmaAllocator allocator, VmaAllocation allocation)
| Unmaps memory represented by given allocation, mapped previously using vmaMapMemory().
VkResult | vmaFlushAllocation (VmaAllocator allocator, VmaAllocation allocation, VkDeviceSize offset, VkDeviceSize size)
| Flushes memory of given allocation.
VkResult | vmaInvalidateAllocation (VmaAllocator allocator, VmaAllocation allocation, VkDeviceSize offset, VkDeviceSize size)
| Invalidates memory of given allocation.
VkResult | vmaFlushAllocations (VmaAllocator allocator, uint32_t allocationCount, const VmaAllocation *allocations, const VkDeviceSize *offsets, const VkDeviceSize *sizes)
| Flushes memory of given set of allocations.
VkResult | vmaInvalidateAllocations (VmaAllocator allocator, uint32_t allocationCount, const VmaAllocation *allocations, const VkDeviceSize *offsets, const VkDeviceSize *sizes)
| Invalidates memory of given set of allocations.
VkResult | vmaCopyMemoryToAllocation (VmaAllocator allocator, const void *pSrcHostPointer, VmaAllocation dstAllocation, VkDeviceSize dstAllocationLocalOffset, VkDeviceSize size)
| Maps the allocation temporarily if needed, copies data from specified host pointer to it, and flushes the memory from the host caches if needed.
VkResult | vmaCopyAllocationToMemory (VmaAllocator allocator, VmaAllocation srcAllocation, VkDeviceSize srcAllocationLocalOffset, void *pDstHostPointer, VkDeviceSize size)
| Invalidates memory in the host caches if needed, maps the allocation temporarily if needed, and copies data from it to a specified host pointer.
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.
VkResult | vmaBeginDefragmentation (VmaAllocator allocator, const VmaDefragmentationInfo *pInfo, VmaDefragmentationContext *pContext)
| Begins defragmentation process.
void | vmaEndDefragmentation (VmaAllocator allocator, VmaDefragmentationContext context, VmaDefragmentationStats *pStats)
| Ends defragmentation process.
VkResult | vmaBeginDefragmentationPass (VmaAllocator allocator, VmaDefragmentationContext context, VmaDefragmentationPassMoveInfo *pPassInfo)
| Starts single defragmentation pass.
VkResult | vmaEndDefragmentationPass (VmaAllocator allocator, VmaDefragmentationContext context, VmaDefragmentationPassMoveInfo *pPassInfo)
| Ends single defragmentation pass.
VkResult | vmaBindBufferMemory (VmaAllocator allocator, VmaAllocation allocation, VkBuffer buffer)
| Binds buffer to allocation.
VkResult | vmaBindBufferMemory2 (VmaAllocator allocator, VmaAllocation allocation, VkDeviceSize allocationLocalOffset, VkBuffer buffer, const void *(VkBindBufferMemoryInfoKHR) pNext)
| Binds buffer to allocation with additional parameters.
VkResult | vmaBindImageMemory (VmaAllocator allocator, VmaAllocation allocation, VkImage image)
| Binds image to allocation.
VkResult | vmaBindImageMemory2 (VmaAllocator allocator, VmaAllocation allocation, VkDeviceSize allocationLocalOffset, VkImage image, const void *(VkBindImageMemoryInfoKHR) pNext)
| Binds image to allocation with additional parameters.
VkResult | vmaCreateBuffer (VmaAllocator allocator, const VkBufferCreateInfo *pBufferCreateInfo, const VmaAllocationCreateInfo *pAllocationCreateInfo, VkBuffer *pBuffer, VmaAllocation *pAllocation, VmaAllocationInfo *pAllocationInfo)
| Creates a new VkBuffer, allocates and binds memory for it.
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.
VkResult | vmaCreateDedicatedBuffer (VmaAllocator allocator, const VkBufferCreateInfo *pBufferCreateInfo, const VmaAllocationCreateInfo *pAllocationCreateInfo, void *(VkMemoryAllocateInfo) pMemoryAllocateNext, VkBuffer *pBuffer, VmaAllocation *pAllocation, VmaAllocationInfo *pAllocationInfo)
| Creates a dedicated buffer while offering extra parameter pMemoryAllocateNext.
VkResult | vmaCreateAliasingBuffer (VmaAllocator allocator, VmaAllocation allocation, const VkBufferCreateInfo *pBufferCreateInfo, VkBuffer *pBuffer)
| Creates a new VkBuffer, binds already created memory for it.
VkResult | vmaCreateAliasingBuffer2 (VmaAllocator allocator, VmaAllocation allocation, VkDeviceSize allocationLocalOffset, const VkBufferCreateInfo *pBufferCreateInfo, VkBuffer *pBuffer)
| Creates a new VkBuffer, binds already created memory for it.
void | vmaDestroyBuffer (VmaAllocator allocator, VkBuffer buffer, VmaAllocation allocation)
| Destroys Vulkan buffer and frees allocated memory.
VkResult | vmaCreateImage (VmaAllocator allocator, const VkImageCreateInfo *pImageCreateInfo, const VmaAllocationCreateInfo *pAllocationCreateInfo, VkImage *pImage, VmaAllocation *pAllocation, VmaAllocationInfo *pAllocationInfo)
| Function similar to vmaCreateBuffer() but for images.
VkResult | vmaCreateDedicatedImage (VmaAllocator allocator, const VkImageCreateInfo *pImageCreateInfo, const VmaAllocationCreateInfo *pAllocationCreateInfo, void *(VkMemoryAllocateInfo) pMemoryAllocateNext, VkImage *pImage, VmaAllocation *pAllocation, VmaAllocationInfo *pAllocationInfo)
| Function similar to vmaCreateDedicatedBuffer() but for images.
VkResult | vmaCreateAliasingImage (VmaAllocator allocator, VmaAllocation allocation, const VkImageCreateInfo *pImageCreateInfo, VkImage *pImage)
| Function similar to vmaCreateAliasingBuffer() but for images.
VkResult | vmaCreateAliasingImage2 (VmaAllocator allocator, VmaAllocation allocation, VkDeviceSize allocationLocalOffset, const VkImageCreateInfo *pImageCreateInfo, VkImage *pImage)
| Function similar to vmaCreateAliasingBuffer2() but for images.
void | vmaDestroyImage (VmaAllocator allocator, VkImage image, VmaAllocation allocation)
| Destroys Vulkan image and frees allocated memory.

## Detailed Description

API elements related to the allocation, deallocation, and management of Vulkan memory, buffers, images. Most basic ones being: vmaCreateBuffer(), vmaCreateImage().

## Typedef Documentation

## ◆ PFN_vmaCheckDefragmentationBreakFunction

typedef VkBool32(VKAPI_PTR * PFN_vmaCheckDefragmentationBreakFunction) (void *pUserData)

Callback function called during vmaBeginDefragmentation() to check custom criterion about ending current defragmentation pass.

Should return true if the defragmentation needs to stop current pass.

## ◆ VmaAllocationCreateFlagBits

typedef enum VmaAllocationCreateFlagBits VmaAllocationCreateFlagBits

Flags to be passed as VmaAllocationCreateInfo::flags.

## ◆ VmaAllocationCreateFlags

typedef VkFlags VmaAllocationCreateFlags

See VmaAllocationCreateFlagBits.

## ◆ VmaAllocationCreateInfo

typedef struct VmaAllocationCreateInfo VmaAllocationCreateInfo

Parameters of new VmaAllocation.

To be used with functions like vmaCreateBuffer(), vmaCreateImage(), and many others.

## ◆ VmaAllocationInfo

typedef struct VmaAllocationInfo VmaAllocationInfo

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

There is also an extended version of this structure that carries additional parameters: VmaAllocationInfo2.

## ◆ VmaAllocationInfo2

typedef struct VmaAllocationInfo2 VmaAllocationInfo2

Extended parameters of a VmaAllocation object that can be retrieved using function vmaGetAllocationInfo2().

## ◆ VmaDefragmentationFlagBits

typedef enum VmaDefragmentationFlagBits VmaDefragmentationFlagBits

Flags to be passed as VmaDefragmentationInfo::flags.

## ◆ VmaDefragmentationFlags

typedef VkFlags VmaDefragmentationFlags

See VmaDefragmentationFlagBits.

## ◆ VmaDefragmentationInfo

typedef struct VmaDefragmentationInfo VmaDefragmentationInfo

Parameters for defragmentation.

To be used with function vmaBeginDefragmentation().

## ◆ VmaDefragmentationMove

typedef struct VmaDefragmentationMove VmaDefragmentationMove

Single move of an allocation to be done for defragmentation.

## ◆ VmaDefragmentationMoveOperation

typedef enum VmaDefragmentationMoveOperation VmaDefragmentationMoveOperation

Operation performed on single defragmentation move. See structure VmaDefragmentationMove.

## ◆ VmaDefragmentationPassMoveInfo

typedef struct VmaDefragmentationPassMoveInfo VmaDefragmentationPassMoveInfo

Parameters for incremental defragmentation steps.

To be used with function vmaBeginDefragmentationPass().

## ◆ VmaDefragmentationStats

typedef struct VmaDefragmentationStats VmaDefragmentationStats

Statistics returned for defragmentation process in function vmaEndDefragmentation().

## ◆ VmaMemoryUsage

typedef enum VmaMemoryUsage VmaMemoryUsage

Intended usage of the allocated memory.

## ◆ VmaPoolCreateFlagBits

typedef enum VmaPoolCreateFlagBits VmaPoolCreateFlagBits

Flags to be passed as VmaPoolCreateInfo::flags.

## ◆ VmaPoolCreateFlags

typedef VkFlags VmaPoolCreateFlags

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

## ◆ VmaPoolCreateInfo

typedef struct VmaPoolCreateInfo VmaPoolCreateInfo

Describes parameter of created VmaPool.

## Enumeration Type Documentation

## ◆ VmaAllocationCreateFlagBits

enum 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. If you use this flag while creating a buffer or an image, VkMemoryDedicatedAllocateInfo structure is applied if possible.
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.
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).
VMA_ALLOCATION_CREATE_USER_DATA_COPY_STRING_BIT | Deprecated Preserved for backward compatibility. Consider using vmaSetAllocationName() instead. 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 pName. 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. If you want to make sure the new buffer/image is not tied to the new memory allocation through VkMemoryDedicatedAllocateInfoKHR structure in case the allocation ends up in its own memory block, use also flag VMA_ALLOCATION_CREATE_CAN_ALIAS_BIT.
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_CAN_ALIAS_BIT | Set this flag if the allocated memory will have aliasing resources. Usage of this flag prevents supplying VkMemoryDedicatedAllocateInfoKHR when VMA_ALLOCATION_CREATE_DEDICATED_MEMORY_BIT is specified. Otherwise created dedicated memory will not be suitable for aliasing resources, resulting in Vulkan Validation Layer errors.
VMA_ALLOCATION_CREATE_HOST_ACCESS_SEQUENTIAL_WRITE_BIT | Requests possibility to map the allocation (using vmaMapMemory() or VMA_ALLOCATION_CREATE_MAPPED_BIT). If you use VMA_MEMORY_USAGE_AUTO or other VMA_MEMORY_USAGE_AUTO* value, you must use this flag to be able to map the allocation. Otherwise, mapping is incorrect. If you use other value of VmaMemoryUsage, this flag is ignored and mapping is always possible in memory types that are HOST_VISIBLE. This includes allocations created in Custom memory pools. Declares that mapped memory will only be written sequentially, e.g. using memcpy() or a loop writing number-by-number, never read or accessed randomly, so a memory type can be selected that is uncached and write-combined. Warning Violating this declaration may work correctly, but will likely be very slow. Watch out for implicit reads introduced by doing e.g. pMappedData[i] += x; Better prepare your data in a local variable and memcpy() it to the mapped pointer all at once.
VMA_ALLOCATION_CREATE_HOST_ACCESS_RANDOM_BIT | Requests possibility to map the allocation (using vmaMapMemory() or VMA_ALLOCATION_CREATE_MAPPED_BIT). If you use VMA_MEMORY_USAGE_AUTO or other VMA_MEMORY_USAGE_AUTO* value, you must use this flag to be able to map the allocation. Otherwise, mapping is incorrect. If you use other value of VmaMemoryUsage, this flag is ignored and mapping is always possible in memory types that are HOST_VISIBLE. This includes allocations created in Custom memory pools. Declares that mapped memory can be read, written, and accessed in random order, so a HOST_CACHED memory type is preferred.
VMA_ALLOCATION_CREATE_HOST_ACCESS_ALLOW_TRANSFER_INSTEAD_BIT | Together with VMA_ALLOCATION_CREATE_HOST_ACCESS_SEQUENTIAL_WRITE_BIT or VMA_ALLOCATION_CREATE_HOST_ACCESS_RANDOM_BIT, it says that despite request for host access, a not-HOST_VISIBLE memory type can be selected if it may improve performance. By using this flag, you declare that you will check if the allocation ended up in a HOST_VISIBLE memory type (e.g. using vmaGetAllocationMemoryProperties()) and if not, you will create some "staging" buffer and issue an explicit transfer to write/read your data. To prepare for this possibility, don't forget to add appropriate flags like VK_BUFFER_USAGE_TRANSFER_DST_BIT, VK_BUFFER_USAGE_TRANSFER_SRC_BIT to the parameters of created buffer or image.
VMA_ALLOCATION_CREATE_STRATEGY_MIN_MEMORY_BIT | Allocation strategy that chooses smallest possible free range for the allocation to minimize memory usage and fragmentation, possibly at the expense of allocation time.
VMA_ALLOCATION_CREATE_STRATEGY_MIN_TIME_BIT | Allocation strategy that chooses first suitable free range for the allocation - not necessarily in terms of the smallest offset but the one that is easiest and fastest to find to minimize allocation time, possibly at the expense of allocation quality.
VMA_ALLOCATION_CREATE_STRATEGY_MIN_OFFSET_BIT | Allocation strategy that chooses always the lowest offset in available space. This is not the most efficient strategy but achieves highly packed data. Used internally by defragmentation, not recommended in typical usage.
VMA_ALLOCATION_CREATE_STRATEGY_BEST_FIT_BIT | Alias to VMA_ALLOCATION_CREATE_STRATEGY_MIN_MEMORY_BIT.
VMA_ALLOCATION_CREATE_STRATEGY_FIRST_FIT_BIT | Alias to VMA_ALLOCATION_CREATE_STRATEGY_MIN_TIME_BIT.
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 |

## ◆ VmaDefragmentationFlagBits

enum VmaDefragmentationFlagBits

Flags to be passed as VmaDefragmentationInfo::flags.

Enumerator
VMA_DEFRAGMENTATION_FLAG_ALGORITHM_FAST_BIT |
VMA_DEFRAGMENTATION_FLAG_ALGORITHM_BALANCED_BIT |
VMA_DEFRAGMENTATION_FLAG_ALGORITHM_FULL_BIT |
VMA_DEFRAGMENTATION_FLAG_ALGORITHM_EXTENSIVE_BIT | Use the most roboust algorithm at the cost of time to compute and number of copies to make. Only available when bufferImageGranularity is greater than 1, since it aims to reduce alignment issues between different types of resources. Otherwise falls back to same behavior as VMA_DEFRAGMENTATION_FLAG_ALGORITHM_FULL_BIT.
VMA_DEFRAGMENTATION_FLAG_ALGORITHM_MASK | A bit mask to extract only ALGORITHM bits from entire set of flags.
VMA_DEFRAGMENTATION_FLAG_BITS_MAX_ENUM |

## ◆ VmaDefragmentationMoveOperation

enum VmaDefragmentationMoveOperation

Operation performed on single defragmentation move. See structure VmaDefragmentationMove.

Enumerator
VMA_DEFRAGMENTATION_MOVE_OPERATION_COPY | Buffer/image has been recreated at dstTmpAllocation, data has been copied, old buffer/image has been destroyed. srcAllocation should be changed to point to the new place. This is the default value set by vmaBeginDefragmentationPass().
VMA_DEFRAGMENTATION_MOVE_OPERATION_IGNORE | Set this value if you cannot move the allocation. New place reserved at dstTmpAllocation will be freed. srcAllocation will remain unchanged.
VMA_DEFRAGMENTATION_MOVE_OPERATION_DESTROY | Set this value if you decide to abandon the allocation and you destroyed the buffer/image. New place reserved at dstTmpAllocation will be freed, along with srcAllocation, which will be destroyed.

## ◆ VmaMemoryUsage

enum VmaMemoryUsage

Intended usage of the allocated memory.

Enumerator
VMA_MEMORY_USAGE_UNKNOWN | No intended memory usage specified. Use other members of VmaAllocationCreateInfo to specify your requirements.
VMA_MEMORY_USAGE_GPU_ONLY | Deprecated Obsolete, preserved for backward compatibility. Prefers VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT.
VMA_MEMORY_USAGE_CPU_ONLY | Deprecated Obsolete, preserved for backward compatibility. Guarantees VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT and VK_MEMORY_PROPERTY_HOST_COHERENT_BIT.
VMA_MEMORY_USAGE_CPU_TO_GPU | Deprecated Obsolete, preserved for backward compatibility. Guarantees VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT, prefers VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT.
VMA_MEMORY_USAGE_GPU_TO_CPU | Deprecated Obsolete, preserved for backward compatibility. Guarantees VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT, prefers VK_MEMORY_PROPERTY_HOST_CACHED_BIT.
VMA_MEMORY_USAGE_CPU_COPY | Deprecated Obsolete, preserved for backward compatibility. Prefers not VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT.
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_AUTO | Selects best memory type automatically. This flag is recommended for most common use cases. When using this flag, if you want to map the allocation (using vmaMapMemory() or VMA_ALLOCATION_CREATE_MAPPED_BIT), you must pass one of the flags: VMA_ALLOCATION_CREATE_HOST_ACCESS_SEQUENTIAL_WRITE_BIT or VMA_ALLOCATION_CREATE_HOST_ACCESS_RANDOM_BIT in VmaAllocationCreateInfo::flags. It can be used only with functions that let the library know VkBufferCreateInfo or VkImageCreateInfo, e.g. vmaCreateBuffer(), vmaCreateImage(), vmaFindMemoryTypeIndexForBufferInfo(), vmaFindMemoryTypeIndexForImageInfo() and not with generic memory allocation functions.
VMA_MEMORY_USAGE_AUTO_PREFER_DEVICE | Selects best memory type automatically with preference for GPU (device) memory. When using this flag, if you want to map the allocation (using vmaMapMemory() or VMA_ALLOCATION_CREATE_MAPPED_BIT), you must pass one of the flags: VMA_ALLOCATION_CREATE_HOST_ACCESS_SEQUENTIAL_WRITE_BIT or VMA_ALLOCATION_CREATE_HOST_ACCESS_RANDOM_BIT in VmaAllocationCreateInfo::flags. It can be used only with functions that let the library know VkBufferCreateInfo or VkImageCreateInfo, e.g. vmaCreateBuffer(), vmaCreateImage(), vmaFindMemoryTypeIndexForBufferInfo(), vmaFindMemoryTypeIndexForImageInfo() and not with generic memory allocation functions.
VMA_MEMORY_USAGE_AUTO_PREFER_HOST | Selects best memory type automatically with preference for CPU (host) memory. When using this flag, if you want to map the allocation (using vmaMapMemory() or VMA_ALLOCATION_CREATE_MAPPED_BIT), you must pass one of the flags: VMA_ALLOCATION_CREATE_HOST_ACCESS_SEQUENTIAL_WRITE_BIT or VMA_ALLOCATION_CREATE_HOST_ACCESS_RANDOM_BIT in VmaAllocationCreateInfo::flags. It can be used only with functions that let the library know VkBufferCreateInfo or VkImageCreateInfo, e.g. vmaCreateBuffer(), vmaCreateImage(), vmaFindMemoryTypeIndexForBufferInfo(), vmaFindMemoryTypeIndexForImageInfo() and not with generic memory allocation functions.
VMA_MEMORY_USAGE_MAX_ENUM |

## ◆ VmaPoolCreateFlagBits

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.
VMA_POOL_CREATE_ALGORITHM_MASK | Bit mask to extract only ALGORITHM bits from entire set of flags.
VMA_POOL_CREATE_FLAG_BITS_MAX_ENUM |

## Function Documentation

## ◆ vmaAllocateDedicatedMemory()

VkResult vmaAllocateDedicatedMemory | ( | VmaAllocator | allocator,
|  | const VkMemoryRequirements * | pVkMemoryRequirements,
|  | const VmaAllocationCreateInfo * | pCreateInfo,
|  | void *(VkMemoryAllocateInfo) | pMemoryAllocateNext,
|  | VmaAllocation * | pAllocation,
|  | VmaAllocationInfo * | pAllocationInfo )

General purpose allocation of a dedicated memory.

This function is similar vmaAllocateMemory(), but it always allocates dedicated memory - flag VMA_ALLOCATION_CREATE_DEDICATED_MEMORY_BIT is implied. It offers additional parameter pMemoryAllocateNext, which can be used to attach pNext chain to the VkMemoryAllocateInfo structure. It can be useful for importing external memory. For more information, see Interop with other graphics APIs.

## ◆ vmaAllocateMemory()

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

General purpose memory allocation.

Parameters

  | allocator | The main allocator object.
  | pVkMemoryRequirements | Requirements for the allocated memory.
  | pCreateInfo | Allocation creation parameters.
  [out] | pAllocation | Handle to allocated memory.
  [out] | pAllocationInfo | Optional, can be null. Information about allocated memory. It can be also fetched later using vmaGetAllocationInfo().

The function creates a VmaAllocation object without creating a buffer or an image together with it.

- It is recommended to use vmaAllocateMemoryForBuffer(), vmaAllocateMemoryForImage(), vmaCreateBuffer(), vmaCreateImage() instead whenever possible.
- You can also create a buffer or an image later in an existing allocation using vmaCreateAliasingBuffer2(), vmaCreateAliasingImage2().
- You can also create a buffer or an image on your own and bind it to an existing allocation using vmaBindBufferMemory2(), vmaBindImageMemory2().

You must free the returned allocation object using vmaFreeMemory() or vmaFreeMemoryPages().

There is also extended version of this function: vmaAllocateDedicatedMemory() that offers additional parameter pMemoryAllocateNext.

## ◆ vmaAllocateMemoryForBuffer()

VkResult vmaAllocateMemoryForBuffer | ( | VmaAllocator | allocator,
|  | VkBuffer | buffer,
|  | const VmaAllocationCreateInfo * | pCreateInfo,
|  | VmaAllocation * | pAllocation,
|  | VmaAllocationInfo * | pAllocationInfo )

Allocates memory suitable for given VkBuffer.

Parameters

  | allocator |
  | buffer |
  | pCreateInfo |
  [out] | pAllocation | Handle to allocated memory.
  [out] | pAllocationInfo | Optional. Information about allocated memory. It can be later fetched using function vmaGetAllocationInfo().

It only creates VmaAllocation. To bind the memory to the buffer, use vmaBindBufferMemory().

This is a special-purpose function. In most cases you should use vmaCreateBuffer().

You must free the allocation using vmaFreeMemory() when no longer needed.

## ◆ vmaAllocateMemoryForImage()

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

Allocates memory suitable for given VkImage.

Parameters

  | allocator |
  | image |
  | pCreateInfo |
  [out] | pAllocation | Handle to allocated memory.
  [out] | pAllocationInfo | Optional. Information about allocated memory. It can be later fetched using function vmaGetAllocationInfo().

It only creates VmaAllocation. To bind the memory to the buffer, use vmaBindImageMemory().

This is a special-purpose function. In most cases you should use vmaCreateImage().

You must free the allocation using vmaFreeMemory() when no longer needed.

## ◆ 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

  | allocator | Allocator object.
  | pVkMemoryRequirements | Memory requirements for each allocation.
  | pCreateInfo | Creation parameters for each allocation.
  | allocationCount | Number of allocations to make.
  [out] | pAllocations | Pointer to array that will be filled with handles to created allocations.
  [out] | pAllocationInfo | Optional. 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.

## ◆ vmaBeginDefragmentation()

VkResult vmaBeginDefragmentation | ( | VmaAllocator | allocator,
|  | const VmaDefragmentationInfo * | pInfo,
|  | VmaDefragmentationContext * | pContext )

Begins defragmentation process.

Parameters

  | allocator | Allocator object.
  | pInfo | Structure filled with parameters of defragmentation.
  [out] | pContext | Context object that must be passed to vmaEndDefragmentation() to finish defragmentation.

Returns
  - VK_SUCCESS if defragmentation can begin.
  - VK_ERROR_FEATURE_NOT_PRESENT if defragmentation is not supported.

For more information about defragmentation, see documentation chapter: Defragmentation.

## ◆ vmaBeginDefragmentationPass()

VkResult vmaBeginDefragmentationPass | ( | VmaAllocator | allocator,
|  | VmaDefragmentationContext | context,
|  | VmaDefragmentationPassMoveInfo * | pPassInfo )

Starts single defragmentation pass.

Parameters

  | allocator | Allocator object.
  | context | Context object that has been created by vmaBeginDefragmentation().
  [out] | pPassInfo | Computed information for current pass.

Returns
  - VK_SUCCESS if no more moves are possible. Then you can omit call to vmaEndDefragmentationPass() and simply end whole defragmentation.
  - VK_INCOMPLETE if there are pending moves returned in pPassInfo. You need to perform them, call vmaEndDefragmentationPass(), and then preferably try another pass with vmaBeginDefragmentationPass().

## ◆ 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 *(VkBindBufferMemoryInfoKHR) | pNext )

Binds buffer to allocation with additional parameters.

Parameters

  allocator |
  allocation |
  allocationLocalOffset | Additional offset to be added while binding, relative to the beginning of the allocation. Normally it should be 0.
  buffer |
  pNext | A 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 *(VkBindImageMemoryInfoKHR) | pNext )

Binds image to allocation with additional parameters.

Parameters

  allocator |
  allocation |
  allocationLocalOffset | Additional offset to be added while binding, relative to the beginning of the allocation. Normally it should be 0.
  image |
  pNext | A 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.

## ◆ 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 |
  memoryTypeBits | Bit 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.

## ◆ vmaCopyAllocationToMemory()

VkResult vmaCopyAllocationToMemory | ( | VmaAllocator | allocator,
|  | VmaAllocation | srcAllocation,
|  | VkDeviceSize | srcAllocationLocalOffset,
|  | void * | pDstHostPointer,
|  | VkDeviceSize | size )

Invalidates memory in the host caches if needed, maps the allocation temporarily if needed, and copies data from it to a specified host pointer.

Parameters

  allocator |
  srcAllocation | Handle to the allocation that becomes source of the copy.
  srcAllocationLocalOffset | Offset within srcAllocation where to read copied data, in bytes.
  pDstHostPointer | Pointer to the host memory that become destination of the copy.
  size | Number of bytes to copy.

This is a convenience function that allows to copy data from an allocation to a host pointer easily. Same behavior can be achieved by calling vmaInvalidateAllocation(), vmaMapMemory(), memcpy(), vmaUnmapMemory().

This function should be called only for allocations created in a memory type that has VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT and VK_MEMORY_PROPERTY_HOST_CACHED_BIT flag. It can be ensured e.g. by using VMA_MEMORY_USAGE_AUTO and VMA_ALLOCATION_CREATE_HOST_ACCESS_RANDOM_BIT. Otherwise, the function may fail and generate a Validation Layers error. It may also work very slowly when reading from an uncached memory.

srcAllocationLocalOffset is relative to the contents of given srcAllocation. If you mean whole allocation, you should pass 0. Do not pass allocation's offset within device memory block as this parameter!

## ◆ vmaCopyMemoryToAllocation()

VkResult vmaCopyMemoryToAllocation | ( | VmaAllocator | allocator,
|  | const void * | pSrcHostPointer,
|  | VmaAllocation | dstAllocation,
|  | VkDeviceSize | dstAllocationLocalOffset,
|  | VkDeviceSize | size )

Maps the allocation temporarily if needed, copies data from specified host pointer to it, and flushes the memory from the host caches if needed.

Parameters

  allocator |
  pSrcHostPointer | Pointer to the host data that become source of the copy.
  dstAllocation | Handle to the allocation that becomes destination of the copy.
  dstAllocationLocalOffset | Offset within dstAllocation where to write copied data, in bytes.
  size | Number of bytes to copy.

This is a convenience function that allows to copy data from a host pointer to an allocation easily. Same behavior can be achieved by calling vmaMapMemory(), memcpy(), vmaUnmapMemory(), vmaFlushAllocation().

This function can be called only for allocations created in a memory type that has VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT flag. It can be ensured e.g. by using VMA_MEMORY_USAGE_AUTO and VMA_ALLOCATION_CREATE_HOST_ACCESS_SEQUENTIAL_WRITE_BIT or VMA_ALLOCATION_CREATE_HOST_ACCESS_RANDOM_BIT. Otherwise, the function will fail and generate a Validation Layers error.

dstAllocationLocalOffset is relative to the contents of given dstAllocation. If you mean whole allocation, you should pass 0. Do not pass allocation's offset within device memory block this parameter!

## ◆ vmaCreateAliasingBuffer()

VkResult vmaCreateAliasingBuffer | ( | VmaAllocator | allocator,
|  | VmaAllocation | allocation,
|  | const VkBufferCreateInfo * | pBufferCreateInfo,
|  | VkBuffer * | pBuffer )

Creates a new VkBuffer, binds already created memory for it.

Parameters

  | allocator |
  | allocation | Allocation that provides memory to be used for binding new buffer to it.
  | pBufferCreateInfo |
  [out] | pBuffer | Buffer that was created.

This function automatically:

1. Creates buffer.
2. Binds the buffer with the supplied memory.

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

If the function succeeded, you must destroy the buffer when you no longer need it using vkDestroyBuffer(). If you want to also destroy the corresponding allocation you can use convenience function vmaDestroyBuffer().

Note
  There is a new version of this function augmented with parameter allocationLocalOffset - see vmaCreateAliasingBuffer2().

## ◆ vmaCreateAliasingBuffer2()

VkResult vmaCreateAliasingBuffer2 | ( | VmaAllocator | allocator,
|  | VmaAllocation | allocation,
|  | VkDeviceSize | allocationLocalOffset,
|  | const VkBufferCreateInfo * | pBufferCreateInfo,
|  | VkBuffer * | pBuffer )

Creates a new VkBuffer, binds already created memory for it.

Parameters

  | allocator |
  | allocation | Allocation that provides memory to be used for binding new buffer to it.
  | allocationLocalOffset | Additional offset to be added while binding, relative to the beginning of the allocation. Normally it should be 0.
  | pBufferCreateInfo |
  [out] | pBuffer | Buffer that was created.

This function automatically:

1. Creates buffer.
2. Binds the buffer with the supplied memory.

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

If the function succeeded, you must destroy the buffer when you no longer need it using vkDestroyBuffer(). If you want to also destroy the corresponding allocation you can use convenience function vmaDestroyBuffer().

Note
  This is a new version of the function augmented with parameter allocationLocalOffset.

## ◆ vmaCreateAliasingImage()

VkResult vmaCreateAliasingImage | ( | VmaAllocator | allocator,
|  | VmaAllocation | allocation,
|  | const VkImageCreateInfo * | pImageCreateInfo,
|  | VkImage * | pImage )

Function similar to vmaCreateAliasingBuffer() but for images.

## ◆ vmaCreateAliasingImage2()

VkResult vmaCreateAliasingImage2 | ( | VmaAllocator | allocator,
|  | VmaAllocation | allocation,
|  | VkDeviceSize | allocationLocalOffset,
|  | const VkImageCreateInfo * | pImageCreateInfo,
|  | VkImage * | pImage )

Function similar to vmaCreateAliasingBuffer2() but for images.

## ◆ vmaCreateBuffer()

VkResult vmaCreateBuffer | ( | VmaAllocator | allocator,
|  | const VkBufferCreateInfo * | pBufferCreateInfo,
|  | const VmaAllocationCreateInfo * | pAllocationCreateInfo,
|  | VkBuffer * | pBuffer,
|  | VmaAllocation * | pAllocation,
|  | VmaAllocationInfo * | pAllocationInfo )

Creates a new VkBuffer, allocates and binds memory for it.

Parameters

  | allocator | The main allocator object.
  | pBufferCreateInfo | Buffer creation parameters.
  | pAllocationCreateInfo | Allocation creation parameters.
  [out] | pBuffer | Buffer that was created.
  [out] | pAllocation | Allocation that was created.
  [out] | pAllocationInfo | Optional, can be null. Information about allocated memory. It can be also fetched later using 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 returned as 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 VK_KHR_dedicated_allocation extenion or Vulkan version >= 1.1 is used, the function queries the driver whether it requires or prefers the new buffer to have dedicated allocation. If yes, and if dedicated allocation is possible (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.

There is also an extended versions of this function available with additional parameter pMemoryAllocateNext - see vmaCreateDedicatedBuffer().

## ◆ 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.

Deprecated
  This function in obsolete since new VmaAllocationCreateInfo::minAlignment member allows specifying custom alignment while using any allocation function, like the standard vmaCreateBuffer().

## ◆ vmaCreateDedicatedBuffer()

VkResult vmaCreateDedicatedBuffer | ( | VmaAllocator | allocator,
|  | const VkBufferCreateInfo * | pBufferCreateInfo,
|  | const VmaAllocationCreateInfo * | pAllocationCreateInfo,
|  | void *(VkMemoryAllocateInfo) | pMemoryAllocateNext,
|  | VkBuffer * | pBuffer,
|  | VmaAllocation * | pAllocation,
|  | VmaAllocationInfo * | pAllocationInfo )

Creates a dedicated buffer while offering extra parameter pMemoryAllocateNext.

This function is similar vmaCreateBuffer(), but it always allocates dedicated memory for the buffer - flag VMA_ALLOCATION_CREATE_DEDICATED_MEMORY_BIT is implied. It offers additional parameter pMemoryAllocateNext, which can be used to attach pNext chain to the VkMemoryAllocateInfo structure. It can be useful for importing external memory. For more information, see Interop with other graphics APIs.

## ◆ vmaCreateDedicatedImage()

VkResult vmaCreateDedicatedImage | ( | VmaAllocator | allocator,
|  | const VkImageCreateInfo * | pImageCreateInfo,
|  | const VmaAllocationCreateInfo * | pAllocationCreateInfo,
|  | void *(VkMemoryAllocateInfo) | pMemoryAllocateNext,
|  | VkImage * | pImage,
|  | VmaAllocation * | pAllocation,
|  | VmaAllocationInfo * | pAllocationInfo )

Function similar to vmaCreateDedicatedBuffer() but for images.

This function is similar vmaCreateImage(), but it always allocates dedicated memory for the image - flag VMA_ALLOCATION_CREATE_DEDICATED_MEMORY_BIT is implied. It offers additional parameter pMemoryAllocateNext, which can be used to attach pNext chain to the VkMemoryAllocateInfo structure. It can be useful for importing external memory. For more information, see Interop with other graphics APIs.

## ◆ vmaCreateImage()

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

Function similar to vmaCreateBuffer() but for images.

There is also an extended version of this function available: vmaCreateDedicatedImage() which offers additional parameter pMemoryAllocateNext.

## ◆ vmaCreatePool()

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

Allocates Vulkan device memory and creates VmaPool object.

Parameters

  | allocator | Allocator object.
  | pCreateInfo | Parameters of pool to create.
  [out] | pPool | Handle to created pool.

## ◆ 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);
vmaFreeMemory
void vmaFreeMemory(VmaAllocator allocator, VmaAllocation allocation)
Frees memory previously allocated using vmaAllocateMemory(), vmaAllocateMemoryForBuffer(),...

It is 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 is safe to pass null as image and/or allocation.

## ◆ vmaDestroyPool()

void vmaDestroyPool | ( | VmaAllocator | allocator,
|  | VmaPool | pool )

Destroys VmaPool object and frees Vulkan device memory.

## ◆ vmaEndDefragmentation()

void vmaEndDefragmentation | ( | VmaAllocator | allocator,
|  | VmaDefragmentationContext | context,
|  | VmaDefragmentationStats * | pStats )

Ends defragmentation process.

Parameters

  | allocator | Allocator object.
  | context | Context object that has been created by vmaBeginDefragmentation().
  [out] | pStats | Optional stats for the defragmentation. Can be null.

Use this function to finish defragmentation started by vmaBeginDefragmentation().

## ◆ vmaEndDefragmentationPass()

VkResult vmaEndDefragmentationPass | ( | VmaAllocator | allocator,
|  | VmaDefragmentationContext | context,
|  | VmaDefragmentationPassMoveInfo * | pPassInfo )

Ends single defragmentation pass.

Parameters

  allocator | Allocator object.
  context | Context object that has been created by vmaBeginDefragmentation().
  pPassInfo | Computed information for current pass filled by vmaBeginDefragmentationPass() and possibly modified by you.

Returns VK_SUCCESS if no more moves are possible or VK_INCOMPLETE if more defragmentations are possible.

Ends incremental defragmentation pass and commits all defragmentation moves from pPassInfo. After this call:

- Allocations at pPassInfo[i].srcAllocation that had pPassInfo[i].operation == VMA_DEFRAGMENTATION_MOVE_OPERATION_COPY (which is the default) will be pointing to the new destination place.
- Allocation at pPassInfo[i].srcAllocation that had pPassInfo[i].operation == VMA_DEFRAGMENTATION_MOVE_OPERATION_DESTROY will be freed.

If no more moves are possible you can end whole defragmentation.

## ◆ 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 may need to internally create a temporary, dummy buffer that never has memory bound.

## ◆ 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 may need to internally create a temporary, dummy image that never has memory bound.

## ◆ 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 |
  offsets | If not null, it must point to an array of offsets of regions to flush, relative to the beginning of respective allocations. Null means all offsets are zero.
  sizes | If 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,
|  | 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.

## ◆ vmaGetAllocationInfo()

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

Returns current information about specified allocation.

Current parameters of given allocation are returned in pAllocationInfo.

Although this function doesn't lock any mutex, so it should be quite efficient, you should avoid calling it too often. You can retrieve same VmaAllocationInfo structure while creating your resource, from function vmaCreateBuffer(), vmaCreateImage(). You can remember it if you are sure parameters don't change (e.g. due to defragmentation).

There is also a new function vmaGetAllocationInfo2() that offers extended information about the allocation, returned using new structure VmaAllocationInfo2.

## ◆ vmaGetAllocationInfo2()

void vmaGetAllocationInfo2 | ( | VmaAllocator | allocator,
|  | VmaAllocation | allocation,
|  | VmaAllocationInfo2 * | pAllocationInfo )

Returns extended information about specified allocation.

Current parameters of given allocation are returned in pAllocationInfo. Extended parameters in structure VmaAllocationInfo2 include memory block size and a flag telling whether the allocation has dedicated memory. It can be useful e.g. for interop with OpenGL.

## ◆ vmaGetAllocationMemoryProperties()

void vmaGetAllocationMemoryProperties | ( | VmaAllocator | allocator,
|  | VmaAllocation | allocation,
|  | VkMemoryPropertyFlags * | pFlags )

Given an allocation, returns Property Flags of its memory type.

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

## ◆ vmaGetMemoryWin32Handle()

VkResult vmaGetMemoryWin32Handle | ( | VmaAllocator | allocator,
|  | VmaAllocation | allocation,
|  | HANDLE | hTargetProcess,
|  | HANDLE * | pHandle )

Given an allocation, returns Win32 handle that may be imported by other processes or APIs.

Parameters

  | allocator | The main allocator object.
  | allocation | Allocation.
  | hTargetProcess | A valid handle to target process or null. If it's null, the function returns handle for the current process.
  [out] | pHandle | Output parameter that returns the handle.

The function fills pHandle with handle that can be used in target process. The handle is fetched using function vkGetMemoryWin32HandleKHR.

Each call to this function creates a new handle that must be closed using:

CloseHandle(handle);

You can close it any time, before or after destroying the allocation object. It is reference-counted internally by Windows.

Note the handle is returned for the entire VkDeviceMemory block that the allocation belongs to. If the allocation is sub-allocated from a larger block, you may need to consider the offset of the allocation (VmaAllocationInfo::offset).

This function always uses VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_WIN32_BIT. An extended version of this function is available as vmaGetMemoryWin32Handle2() that allows using other handle type.

This function is available compile-time only when VK_KHR_external_memory_win32 extension is available. It can be manually disabled by predefining VMA_EXTERNAL_MEMORY_WIN32=0 macro.

If the function fails with VK_ERROR_FEATURE_NOT_PRESENT error code, please double-check that VmaVulkanFunctions::vkGetMemoryWin32HandleKHR function pointer is set, e.g. either by using macro VMA_DYNAMIC_VULKAN_FUNCTIONS or by manually passing it through VmaAllocatorCreateInfo::pVulkanFunctions.

For more information, see chapter Interop with other graphics APIs.

## ◆ vmaGetMemoryWin32Handle2()

VkResult vmaGetMemoryWin32Handle2 | ( | VmaAllocator | allocator,
|  | VmaAllocation | allocation,
|  | VkExternalMemoryHandleTypeFlagBits | handleType,
|  | HANDLE | hTargetProcess,
|  | HANDLE * | pHandle )

Given an allocation, returns Win32 handle that may be imported by other processes or APIs.

Parameters

  | allocator | The main allocator object.
  | allocation | Allocation.
  | handleType | Type of handle to be exported. It should be one of: VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_WIN32_BIT_KHR VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_WIN32_KMT_BIT_KHR VK_EXTERNAL_MEMORY_HANDLE_TYPE_D3D11_TEXTURE_BIT_KHR VK_EXTERNAL_MEMORY_HANDLE_TYPE_D3D11_TEXTURE_KMT_BIT_KHR VK_EXTERNAL_MEMORY_HANDLE_TYPE_D3D12_HEAP_BIT_KHR VK_EXTERNAL_MEMORY_HANDLE_TYPE_D3D12_RESOURCE_BIT_KHR
  | hTargetProcess | A valid handle to target process or null. If it's null, the function returns handle for the current process.
  [out] | pHandle | Output parameter that returns the handle.

The function fills pHandle with handle that can be used in target process. The handle is fetched using function vkGetMemoryWin32HandleKHR.

If handleType == VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_WIN32_BIT_KHR, or other NT handle types, each call to this function creates a new handle that must be closed using:

CloseHandle(handle);

You can close it any time, before or after destroying the allocation object. It is reference-counted internally by Windows.

Note the handle is returned for the entire VkDeviceMemory block that the allocation belongs to. If the allocation is sub-allocated from a larger block, you may need to consider the offset of the allocation (VmaAllocationInfo::offset).

This function is available compile-time only when VK_KHR_external_memory_win32 extension is available. It can be manually disabled by predefining VMA_EXTERNAL_MEMORY_WIN32=0 macro.

If the function fails with VK_ERROR_FEATURE_NOT_PRESENT error code, please double-check that VmaVulkanFunctions::vkGetMemoryWin32HandleKHR function pointer is set, e.g. either by using macro VMA_DYNAMIC_VULKAN_FUNCTIONS or by manually passing it through VmaAllocatorCreateInfo::pVulkanFunctions.

For more information, see chapter Interop with other graphics APIs.

## ◆ 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().

## ◆ 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 |
  offsets | If not null, it must point to an array of offsets of regions to flush, relative to the beginning of respective allocations. Null means all offsets are zero.
  sizes | If 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.

## ◆ 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.

Warning
  If the allocation is part of a bigger VkDeviceMemory block, returned pointer is correctly offsetted to the beginning of region assigned to this particular allocation. Unlike the result of vkMapMemory, it points to the allocation, not to the beginning of the whole block. You should not add VmaAllocationInfo::offset to it!

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 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.

## ◆ vmaSetAllocationName()

void vmaSetAllocationName | ( | VmaAllocator | allocator,
|  | VmaAllocation | allocation,
|  | const char * | pName )

Sets pName in given allocation to new value.

pName 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 pName. String passed as pName 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 pName is freed from memory.

## ◆ vmaSetAllocationUserData()

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

Sets pUserData in given allocation to new value.

The value of pointer pUserData is 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.

## ◆ 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.

## ◆ 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.