@NonnullDefault
Package org.lwjgl.util.vma
Contains bindings to Vulkan, an easy to integrate Vulkan memory
allocation library.
Problem
Memory allocation and resource (buffer and image) creation in Vulkan is difficult (comparing to older graphics API-s, like D3D11 or OpenGL) for several reasons:
- It requires a lot of boilerplate code, just like everything else in Vulkan, because it is a low-level and high-performance API.
- There is additional level of indirection:
VkDeviceMemory
is allocated separately from creatingVkBuffer/VkImage
and they must be bound together. The binding cannot be changed later - resource must be recreated. - Driver must be queried for supported memory heaps and memory types. Different IHVs provide different types of it.
- It is recommended practice to allocate bigger chunks of memory and assign parts of them to particular resources.
Features
This library can help game developers to manage memory allocations and resource creation by offering some higher-level functions. Features of the library are divided into several layers, low level to high level:
- Functions that help to choose correct and optimal memory type based on intended usage of the memory.
- Required or preferred traits of the memory are expressed using higher-level description comparing to Vulkan flags.
- Functions that allocate memory blocks, reserve and return parts of them (`VkDeviceMemory` + offset + size) to the user.
- Library keeps track of allocated memory blocks, used and unused ranges inside them, finds best matching unused ranges for new allocations, takes all the rules of alignment and buffer/image granularity into consideration.
- Functions that can create an image/buffer, allocate memory for it and bind them together - all in one call.
Additional features:
- Thread-safety: Library is designed to be used by multithreaded code.
- Configuration: Fill optional members of CreateInfo structure to provide custom CPU memory allocator and other parameters.
- Customization: Predefine appropriate macros to provide your own implementation of all external facilities used by the library, from assert, mutex, and atomic, to vector and linked list.
- Support memory mapping, reference-counted internally. Support for persistently mapped memory: Just allocate with appropriate flag and you get access to mapped pointer.
- Custom memory pools: Create a pool with desired parameters (e.g. fixed or limited maximum size) and allocate memory out of it.
- Support for VK_KHR_dedicated_allocation extension: Enable it and it will be used automatically by the library.
- Defragmentation: Call one function and let the library move data around to free some memory blocks and make your allocations better compacted.
- Lost allocations: Allocate memory with appropriate flags and let the library remove allocations that are not used for many frames to make room for new ones.
- Statistics: Obtain detailed statistics about the amount of memory used, unused, number of allocated blocks, number of allocations etc. - globally, per memory heap, and per memory type.
- Debug annotations: Associate string with name or opaque pointer to your own data with every allocation.
- JSON dump: Obtain a string in JSON format with detailed map of internal state, including list of allocations and gaps between them.
-
Interface Summary Interface Description VmaAllocateDeviceMemoryFunctionI Instances of this interface may be set to theVmaDeviceMemoryCallbacks
struct.VmaFreeDeviceMemoryFunctionI Instances of this interface may be set to theVmaDeviceMemoryCallbacks
struct. -
Class Summary Class Description Vma The Vulkan Memory Allocator.VmaAllocateDeviceMemoryFunction Instances of this class may be set to theVmaDeviceMemoryCallbacks
struct.VmaAllocationCreateInfo Member documentationVmaAllocationCreateInfo.Buffer An array ofVmaAllocationCreateInfo
structs.VmaAllocationInfo Parameters ofVmaAllocation
objects, that can be retrieved using functionGetAllocationInfo
.VmaAllocationInfo.Buffer An array ofVmaAllocationInfo
structs.VmaAllocatorCreateInfo Description of an Allocator to be created.VmaBudget Statistics of current memory usage and available budget, in bytes, for specific memory heap.VmaBudget.Buffer An array ofVmaBudget
structs.VmaDefragmentationInfo Deprecated.VmaDefragmentationInfo.Buffer An array ofVmaDefragmentationInfo
structs.VmaDefragmentationInfo2 Parameters for defragmentation.VmaDefragmentationInfo2.Buffer An array ofVmaDefragmentationInfo2
structs.VmaDefragmentationStats Statistics returned by functionDefragment
.VmaDefragmentationStats.Buffer An array ofVmaDefragmentationStats
structs.VmaDeviceMemoryCallbacks Set of callbacks that the library will call forvkAllocateMemory
andvkFreeMemory
.VmaDeviceMemoryCallbacks.Buffer An array ofVmaDeviceMemoryCallbacks
structs.VmaFreeDeviceMemoryFunction Instances of this class may be set to theVmaDeviceMemoryCallbacks
struct.VmaPoolCreateInfo Describes parameter of createdVmaPool
.VmaPoolCreateInfo.Buffer An array ofVmaPoolCreateInfo
structs.VmaPoolStats Describes parameter of existingVmaPool
.VmaPoolStats.Buffer An array ofVmaPoolStats
structs.VmaRecordSettings Parameters for recording calls to VMA functions.VmaRecordSettings.Buffer An array ofVmaRecordSettings
structs.VmaStatInfo Calculated statistics of memory usage in entire allocator.VmaStatInfo.Buffer An array ofVmaStatInfo
structs.VmaStats General statistics from current state of Allocator.VmaStats.Buffer An array ofVmaStats
structs.VmaVulkanFunctions Pointers to some Vulkan functions - a subset used by the library.