• Stars
    star
    2,214
  • Rank 20,828 (Top 0.5 %)
  • Language
    C
  • License
    MIT License
  • Created over 7 years ago
  • Updated 12 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Easy to integrate Vulkan memory allocation library

Vulkan Memory Allocator

Easy to integrate Vulkan memory allocation library.

Documentation: Browse online: Vulkan Memory Allocator (generated from Doxygen-style comments in include/vk_mem_alloc.h)

License: MIT. See LICENSE.txt

Changelog: See CHANGELOG.md

Product page: Vulkan Memory Allocator on GPUOpen

Build status:

  • Windows: Build status
  • Linux: Build Status

Average time to resolve an issue

Problem

Memory allocation and resource (buffer and image) creation in Vulkan is difficult (comparing to older graphics APIs, 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 creating VkBuffer/VkImage and they must be bound together.
  • Driver must be queried for supported memory heaps and memory types. Different GPU vendors provide different types of it.
  • It is recommended to allocate bigger chunks of memory and assign parts of them to particular resources, as there is a limit on maximum number of memory blocks that can be allocated.

Features

This library can help game developers to manage memory allocations and resource creation by offering some higher-level functions:

  1. 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.
  2. 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, respects all the rules of alignment and buffer/image granularity.
  3. Functions that can create an image/buffer, allocate memory for it and bind them together - all in one call.

Additional features:

  • Well-documented - description of all functions and structures provided, along with chapters that contain general description and example code.
  • Thread-safety: Library is designed to be used in multithreaded code. Access to a single device memory block referred by different buffers and textures (binding, mapping) is synchronized internally. Memory mapping is reference-counted.
  • Configuration: Fill optional members of VmaAllocatorCreateInfo structure to provide custom CPU memory allocator, pointers to Vulkan functions and other parameters.
  • Customization and integration with custom engines: Predefine appropriate macros to provide your own implementation of all external facilities used by the library like assert, mutex, atomic.
  • Support for memory mapping, reference-counted internally. Support for persistently mapped memory: Just allocate with appropriate flag and access the pointer to already mapped memory.
  • Support for non-coherent memory. Functions that flush/invalidate memory. nonCoherentAtomSize is respected automatically.
  • Support for resource aliasing (overlap).
  • Support for sparse binding and sparse residency: Convenience functions that allocate or free multiple memory pages at once.
  • Custom memory pools: Create a pool with desired parameters (e.g. fixed or limited maximum size) and allocate memory out of it.
  • Linear allocator: Create a pool with linear algorithm and use it for much faster allocations and deallocations in free-at-once, stack, double stack, or ring buffer fashion.
  • Support for Vulkan 1.0, 1.1, 1.2, 1.3.
  • Support for extensions (and equivalent functionality included in new Vulkan versions):
    • VK_KHR_dedicated_allocation: Just enable it and it will be used automatically by the library.
    • VK_KHR_buffer_device_address: Flag VK_MEMORY_ALLOCATE_DEVICE_ADDRESS_BIT_KHR is automatically added to memory allocations where needed.
    • VK_EXT_memory_budget: Used internally if available to query for current usage and budget. If not available, it falls back to an estimation based on memory heap sizes.
    • VK_EXT_memory_priority: Set priority of allocations or custom pools and it will be set automatically using this extension.
    • VK_AMD_device_coherent_memory
  • Defragmentation of GPU and CPU memory: Let the library move data around to free some memory blocks and make your allocations better compacted.
  • Statistics: Obtain brief or 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 custom void* pUserData and debug char* pName with each allocation.
  • JSON dump: Obtain a string in JSON format with detailed map of internal state, including list of allocations, their string names, and gaps between them.
  • Convert this JSON dump into a picture to visualize your memory. See tools/GpuMemDumpVis.
  • Debugging incorrect memory usage: Enable initialization of all allocated memory with a bit pattern to detect usage of uninitialized or freed memory. Enable validation of a magic number after every allocation to detect out-of-bounds memory corruption.
  • Support for interoperability with OpenGL.
  • Virtual allocator: Interface for using core allocation algorithm to allocate any custom data, e.g. pieces of one large buffer.

Prerequisites

  • Self-contained C++ library in single header file. No external dependencies other than standard C and C++ library and of course Vulkan. Some features of C++14 used. STL containers, RTTI, or C++ exceptions are not used.
  • Public interface in C, in same convention as Vulkan API. Implementation in C++.
  • Error handling implemented by returning VkResult error codes - same way as in Vulkan.
  • Interface documented using Doxygen-style comments.
  • Platform-independent, but developed and tested on Windows using Visual Studio. Continuous integration setup for Windows and Linux. Used also on Android, MacOS, and other platforms.

Example

Basic usage of this library is very simple. Advanced features are optional. After you created global VmaAllocator object, a complete code needed to create a buffer may look like this:

VkBufferCreateInfo bufferInfo = { VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO };
bufferInfo.size = 65536;
bufferInfo.usage = VK_BUFFER_USAGE_VERTEX_BUFFER_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT;

VmaAllocationCreateInfo allocInfo = {};
allocInfo.usage = VMA_MEMORY_USAGE_AUTO;

VkBuffer buffer;
VmaAllocation allocation;
vmaCreateBuffer(allocator, &bufferInfo, &allocInfo, &buffer, &allocation, nullptr);

With this one function call:

  1. VkBuffer is created.
  2. VkDeviceMemory block is allocated if needed.
  3. An unused region of the memory block is bound to this buffer.

VmaAllocation is an object that represents memory assigned to this buffer. It can be queried for parameters like VkDeviceMemory handle and offset.

How to build

On Windows it is recommended to use CMake GUI.

Alternatively you can generate/open a Visual Studio from the command line:

# By default CMake picks the newest version of Visual Studio it can use
cmake -S .  -B build -D VMA_BUILD_SAMPLES=ON
cmake --open build

On Linux:

cmake -S . -B build
# Since VMA has no source files, you can skip to installation immediately
cmake --install build --prefix build/install

How to use

After calling either find_package or add_subdirectory simply link the library. This automatically handles configuring the include directory. Example:

find_package(VulkanMemoryAllocator CONFIG REQUIRED)
target_link_libraries(YourGameEngine PRIVATE GPUOpen::VulkanMemoryAllocator)

For more info on using CMake visit the official CMake documentation.

Building using vcpkg

You can download and install VulkanMemoryAllocator using the vcpkg dependency manager:

git clone https://github.com/Microsoft/vcpkg.git
cd vcpkg
./bootstrap-vcpkg.sh
./vcpkg integrate install
./vcpkg install vulkan-memory-allocator

The VulkanMemoryAllocator port in vcpkg is kept up to date by Microsoft team members and community contributors. If the version is out of date, please create an issue or pull request on the vcpkg repository.

Binaries

The release comes with precompiled binary executable for "VulkanSample" application which contains test suite. It is compiled using Visual Studio 2019, so it requires appropriate libraries to work, including "MSVCP140.dll", "VCRUNTIME140.dll", "VCRUNTIME140_1.dll". If the launch fails with error message telling about those files missing, please download and install Microsoft Visual C++ Redistributable for Visual Studio 2015, 2017 and 2019, "x64" version.

Read more

See Documentation.

Software using this library

Many other projects on GitHub and some game development studios that use Vulkan in their games.

See also

  • D3D12 Memory Allocator - equivalent library for Direct3D 12. License: MIT.
  • Awesome Vulkan - a curated list of awesome Vulkan libraries, debuggers and resources.
  • vcpkg dependency manager from Microsoft also offers a port of this library.
  • VulkanMemoryAllocator-Hpp - C++ binding for this library. License: CC0-1.0.
  • PyVMA - Python wrapper for this library. Author: Jean-SΓ©bastien B. (@realitix). License: Apache 2.0.
  • vk-mem - Rust binding for this library. Author: Graham Wihlidal. License: Apache 2.0 or MIT.
  • Haskell bindings, github - Haskell bindings for this library. Author: Ellie Hermaszewska (@expipiplus1). License BSD-3-Clause.
  • vma_sample_sdl - SDL port of the sample app of this library (with the goal of running it on multiple platforms, including MacOS). Author: @rextimmy. License: MIT.
  • vulkan-malloc - Vulkan memory allocation library for Rust. Based on version 1 of this library. Author: Dylan Ede (@dylanede). License: MIT / Apache 2.0.

More Repositories

1

RadeonRays_SDK

Radeon Rays is ray intersection acceleration library for hardware and software multiplatforms using CPU and GPU
C++
1,032
star
2

V-EZ

C
839
star
3

Cauldron

A simple framework for rapid prototyping on Vulkan or Direct3D 12
C++
821
star
4

D3D12MemoryAllocator

Easy to integrate memory allocation library for Direct3D 12
C++
740
star
5

FidelityFX-SDK

The main repository for the FidelityFX SDK.
C++
685
star
6

AMF

The Advanced Media Framework (AMF) SDK provides developers with optimal access to AMD devices for multimedia processing
C++
516
star
7

RadeonProRenderBlenderAddon

This hardware-agnostic rendering plug-in for Blender uses accurate ray-tracing technology to produce images and animations of your scenes, and provides real-time interactive rendering and continuous adjustment of effects.
Python
481
star
8

Capsaicin

AMD ARR team rendering framework
C
363
star
9

BlenderUSDHydraAddon

This add-on allows you to assemble and compose USD data with Blender data and render it all using various renderers via Hydra.
Python
350
star
10

RadeonProRender-Baikal

C++
334
star
11

RenderPipelineShaders

Render Pipeline Shaders SDK
C++
268
star
12

AGS_SDK

AMD GPU Services (AGS) library and samples
C++
232
star
13

RadeonProRenderSDK

AMD Radeonβ„’ ProRender is a powerful physically-based path traced rendering engine that enables creative professionals to produce stunningly photorealistic images.
C
220
star
14

RadeonProRenderUSD

This plug-in allows GPU or CPU accelerated viewport rendering on all OpenCL 1.2 hardware for the open source USD and Hydra system. You can build this plug-in as a USDView plug-in or a Houdini plug-in.
C++
212
star
15

Orochi

C++
197
star
16

MxGPU-Virtualization

C
176
star
17

Radeon-ReLive-VR

157
star
18

OCL-SDK

140
star
19

HelloD3D12

Introductory DirectX 12 sample
C
138
star
20

TAN

AMD TrueAudio Next is a software development kit for GPU accelerated audio signal processing
C++
133
star
21

brotli_g_sdk

Brotli-G SDK provides an improved lossless compression ratio with GPU decompression support than the standard Brotli compression algorithm maintained by the IETF (also known as RFC7932)
C++
132
star
22

ForwardPlus11

AMD Forward+ sample based on DirectX 11
C++
131
star
23

display-library

AMD Display Library SDK
HTML
115
star
24

HelloVulkan

Introductory Vulkan sample
C
115
star
25

glTFSample

A simple demo to show off the capabilities of the Cauldron framework
C++
112
star
26

GPUParticles11

AMD GPU particles sample based on DirectX 11
C++
105
star
27

LiquidVR

The LiquidVRβ„’ SDK is a platform based on DirectX 11 designed to simplify and optimize VR development
C++
102
star
28

HIPRT

C++
91
star
29

RadeonML

C
81
star
30

TiledLighting11

AMD compute-based tiled lighting sample based on DirectX 11
C++
71
star
31

Tessellation

OpenGL sample that demonstrates terrain tessellation on the GPU
C++
61
star
32

GameEngineIntegrations

Information about example integrations of GPUOpen technology into game engines
55
star
33

cpu-core-counts

A sample demonstrating how to correctly detect physical core and logical processor counts on AMD processors.
C++
53
star
34

HIPRTSDK

C
53
star
35

RadeonImageFilter

C++
49
star
36

RadeonProRenderMayaPlugin

This hardware-agnostic rendering plug-in for Maya uses accurate ray-tracing technology to produce images and animations of your scenes, and provides real-time interactive rendering and continuous adjustment of effects.
C++
46
star
37

SSAA11

AMD supersample anti-aliasing (SSAA) sample based on DirectX 11
C++
41
star
38

RapidFire_SDK

RapidFire SDK - interface for cloud gaming and virtualization (VDI)
C++
36
star
39

MLAA11

AMD morphological anti-aliasing (MLAA) sample based on DirectX 11
C++
35
star
40

SilhouetteTessellation11

AMD tessellation sample based on DirectX 11
C++
34
star
41

SPARSEtextures

OpenGL sample demonstrating the GL_AMD_sparse_texture extension introduced by the AMD FirePro W and Radeon HD 7000 series
C++
30
star
42

ADLX

AMD Device Library eXtra
HTML
29
star
43

SeparableFilter11

AMD separable filter sample based on DirectX 11
C++
27
star
44

CrossfireAPI11

AMD Crossfire API sample for DirectX 11
C++
26
star
45

DepthBoundsTest11

AMD depth bounds test DirectX 11 driver extension sample
C++
23
star
46

RenderStudioKit

C++
23
star
47

RadeonProRenderUE

C++
21
star
48

Vulkan-Samples

based on Khronos Vulkan-Samples
C++
19
star
49

DOPPEngine

C++
18
star
50

Framelock

OpenGL sample that demonstrates how to enable Framelock in an application
C++
18
star
51

FreesyncPremiumProSample

A simple demo to show Freesync Premium Pro integration into DX12 and Vulkan API.
C++
18
star
52

DirectGMA_P2P

Samples showing FIrePro DirectGMA features in OpenGL and OpenCL
C++
17
star
53

VkMBCNT

Vulkan mbcnt sample that shows how to use the AMD_shader_ballot extension and mbcnt to perform a fast reduction within a wavefront
C++
16
star
54

Cauldron-Media

A selection of media files needed by Cauldron samples
16
star
55

RadeonProRenderANARI

C++
15
star
56

UnityIntegrations

Examples that demonstrate game integration with some of the libraries and SDKs available on GPUOpen.
C
15
star
57

OutOfOrderRasterization

Vulkan sample built on the Anvil framework
15
star
58

Barycentrics11

Barycentric coordinates GCN shader extension sample for DirectX 11
HLSL
14
star
59

DOPP

C++
14
star
60

Barycentrics12

Barycentric coordinates GCN shader extension sample for DirectX 12
C++
12
star
61

DirectStorageSample

Demonstrating the advantages of using DirectStorage over standard file I/O asset loading. Includes the API and changes required to make such a pipeline work.
C++
11
star
62

RadeonProRenderMaxPlugin

C++
10
star
63

VkD3DDeviceMapping

Simple example to show how to map devices between Vulkan and Direct3D
C++
8
star
64

WorkGraphComputeRasterizer

A compute/workgraph workload running inside the Cauldron framework
C++
8
star
65

RadeonProRender-Tests

7
star
66

WorkGraphsHelloWorkGraphs

C++
5
star
67

WorkGraphsDirectX-Graphics-Samples

A fork of https://github.com/microsoft/DirectX-Graphics-Samples modified to include a sample for Work Graphs
C++
5
star
68

RadeonProRenderMayaUSD

C++
2
star
69

RadeonProRenderSharedComponents

C++
2
star
70

RadeonProRenderSDKKernels

2
star
71

CapsaicinTestMedia

Capsaicin Framework test media assets
1
star