Vulkan Memory Allocator
Classes | Typedefs | Enumerations | Functions
Layer 1 Choosing Memory Type

Classes

struct  VmaMemoryRequirements
 

Typedefs

typedef enum VmaMemoryUsage VmaMemoryUsage
 
typedef enum VmaMemoryRequirementFlagBits VmaMemoryRequirementFlagBits
 Flags to be passed as VmaMemoryRequirements::flags. More...
 
typedef VkFlags VmaMemoryRequirementFlags
 
typedef struct VmaMemoryRequirements VmaMemoryRequirements
 

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_MAX_ENUM = 0x7FFFFFFF
}
 
enum  VmaMemoryRequirementFlagBits { VMA_MEMORY_REQUIREMENT_OWN_MEMORY_BIT = 0x00000001, VMA_MEMORY_REQUIREMENT_NEVER_ALLOCATE_BIT = 0x00000002, VMA_MEMORY_REQUIREMENT_PERSISTENT_MAP_BIT = 0x00000004, VMA_MEMORY_REQUIREMENT_FLAG_BITS_MAX_ENUM = 0x7FFFFFFF }
 Flags to be passed as VmaMemoryRequirements::flags. More...
 

Functions

VkResult vmaFindMemoryTypeIndex (VmaAllocator allocator, uint32_t memoryTypeBits, const VmaMemoryRequirements *pMemoryRequirements, uint32_t *pMemoryTypeIndex)
 

Detailed Description

Typedef Documentation

◆ VmaMemoryRequirementFlagBits

Flags to be passed as VmaMemoryRequirements::flags.

◆ VmaMemoryRequirementFlags

typedef VkFlags VmaMemoryRequirementFlags

◆ VmaMemoryRequirements

◆ VmaMemoryUsage

Enumeration Type Documentation

◆ VmaMemoryRequirementFlagBits

Flags to be passed as VmaMemoryRequirements::flags.

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

This flag must also be used for host visible resources that you want to map simultaneously because otherwise they might end up as regions of the same VkDeviceMemory, while mapping same VkDeviceMemory multiple times is illegal.

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

It makes no sense to set VMA_MEMORY_REQUIREMENT_OWN_MEMORY_BIT and VMA_MEMORY_REQUIREMENT_NEVER_ALLOCATE_BIT at the same time.

VMA_MEMORY_REQUIREMENT_PERSISTENT_MAP_BIT 

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

Pointer to mapped memory will be returned through VmaAllocationInfo::pMappedData. You cannot map the memory on your own as multiple maps of a single VkDeviceMemory are illegal.

VMA_MEMORY_REQUIREMENT_FLAG_BITS_MAX_ENUM 

◆ VmaMemoryUsage

Enumerator
VMA_MEMORY_USAGE_UNKNOWN 

No intended memory usage specified.

VMA_MEMORY_USAGE_GPU_ONLY 

Memory will be used on device only, no need to be mapped on host.

VMA_MEMORY_USAGE_CPU_ONLY 

Memory will be mapped on host. Could be used for transfer to device.

Guarantees to be HOST_VISIBLE and HOST_COHERENT.

VMA_MEMORY_USAGE_CPU_TO_GPU 

Memory will be used for frequent (dynamic) updates from host and reads on device.

Guarantees to be HOST_VISIBLE.

VMA_MEMORY_USAGE_GPU_TO_CPU 

Memory will be used for writing on device and readback on host.

Guarantees to be HOST_VISIBLE.

VMA_MEMORY_USAGE_MAX_ENUM 

Function Documentation

◆ vmaFindMemoryTypeIndex()

VkResult vmaFindMemoryTypeIndex ( VmaAllocator  allocator,
uint32_t  memoryTypeBits,
const VmaMemoryRequirements pMemoryRequirements,
uint32_t *  pMemoryTypeIndex 
)

This algorithm tries to find a memory type that:

  • Is allowed by memoryTypeBits.
  • Contains all the flags from pMemoryRequirements->requiredFlags.
  • Matches intended usage.
  • Has as many flags from pMemoryRequirements->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.