Direct3D®12 Memory Allocator
The industry-leading, open source, memory allocation library for the DirectX®12 API.
The D3D12 Memory Allocator (D3D12MA) is a C++ library that provides a simple and easy-to-integrate API to help you allocate memory for DirectX®12 buffers and textures.
Download the latest version - v3.0.0
*We recommend using the code from the master branch.
This release adds the following features:
- Added helper structs:
CALLOCATION_DESC
,CPOOL_DESC
,CVIRTUAL_BLOCK_DESC
,CVIRTUAL_ALLOCATION_DESC
. - Added macros:
D3D12MA_RECOMMENDED_ALLOCATOR_FLAGS
,D3D12MA_RECOMMENDED_HEAP_FLAGS
,D3D12MA_RECOMMENDED_POOL_FLAGS
. - Added functions:
Allocator::CreateResource3
,CreateAliasingResource2
.- They support parameters:
D3D12_BARRIER_LAYOUT InitialLayout
,const DXGI_FORMAT* pCastableFormats
. - They require recent DirectX 12 Agility SDK. To use them,
ID3D12Device10
must be available. To use non-empty list of castable formats,ID3D12Device12
must be available.
- They support parameters:
- Added support for GPU Upload Heaps (
D3D12_HEAP_TYPE_GPU_UPLOAD
).- Requires recent DirectX 12 Agility SDK. Support on the user’s machine is available only when supported by the motherboard, GPU, drivers, and enabled as “Resizable BAR” in UEFI settings. It can be queried using new
Allocator::IsGPUUploadHeapSupported
function. TotalStatistics::HeapType
array was extended from 4 to 5 elements.
- Requires recent DirectX 12 Agility SDK. Support on the user’s machine is available only when supported by the motherboard, GPU, drivers, and enabled as “Resizable BAR” in UEFI settings. It can be queried using new
- Added missing function
Allocator::CreateAliasingResource1
. - Added
POOL_DESC::ResidencyPriority
member. - Removed
Allocation::WasZeroInitialized
function. It wasn’t fully implemented anyway. - Added
POOL_FLAG_ALWAYS_COMMITTED
. - Added a heuristic that prefers creating small buffers as committed to save memory.
- It is enabled by default. It can be disabled by new flag
ALLOCATOR_FLAG_DONT_PREFER_SMALL_BUFFERS_COMMITTED
.
- It is enabled by default. It can be disabled by new flag
- Macro
D3D12MA_OPTIONS16_SUPPORTED
is no longer exposed in the header or Cmake script. It is defined automatically based on the Agility SDK version. - Added macro
D3D12MA_DEBUG_LOG
, which can be used to log unfreed allocations. - Many improvements in the documentation, including new chapters: “Frequently asked questions”, “Optimal resource allocation”.
- Countless fixes and improvements, including performance optimizations, compatibility with various compilers, tests.
- Major changes in the Cmake script.
- Fixes in “GpuMemDumpVis.py” script.
Benefits
This library can help developers to manage memory allocations and resource creation by offering function Allocator::CreateResource
similar to the standard ID3D12Device::CreateCommittedResource
.
It internally:
- Allocates and keeps track of bigger memory heaps, used and unused ranges inside them, finds best matching unused ranges to create new resources there as placed resources.
- Automatically respects size and alignment requirements for created resources.
- Automatically handles resource heap tier – whether it’s
D2D12_RESOURCE_HEAP_TIER_1
that requires to keep certain classes of resources separate orD3D12_RESOURCE_HEAP_TIER_2
that allows to keep them all together.
Additional features
- Self-contained C++ library in single pair of H + CPP files. Object-oriented interface in a convention similar to D3D12. No external dependencies other than standard C, C++ library and Windows SDK. Some features of C++14 used. STL containers, C++ exceptions, and RTTI are not used.
- Custom memory pools: Create a pool with desired parameters (e.g. fixed or limited maximum size, custom D3D12_HEAP_PROPERTIES and D3D12_HEAP_FLAGS) 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.
- Defragmentation: 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 heaps, number of allocations etc. - globally and per memory heap type. Current memory usage and budget as reported by the system can also be queried.
- Debug annotations: Associate custom void* pPrivateData and debug LPCWSTR 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 using attached Python script.
- Virtual allocator - an API that exposes the core allocation algorithm to be used without allocating real GPU memory, to allocate your own stuff, e.g. sub-allocate pieces of one large buffer.
Frequently Asked Questions
What is D3D12MA?
D3D12 Memory Allocator (D3D12MA) is a software library for developers who use the DirectX(R) 12 graphics API in their code. It is written in C++.
What is the license of D3D12MA?
D3D12MA is licensed under MIT, which means it is open source and free software.
What is the purpose of D3D12MA?
D3D12MA helps with handling one aspect of DX12 usage, which is GPU memory management – allocation of ID3D12Heap
objects and creation of ID3D12Resource
objects – buffers and textures.
Do I need to use D3D12MA?
You don’t need to, but it may be beneficial in many cases. DX12 is a complex and low-level API, so libraries like this that abstract certain aspects of the API and bring them to a higher level are useful. When developing any non-trivial graphics application, you may benefit from using a memory allocator. Using D3D12MA can save time compared to implementing your own.
In DX12 you can create each resource separately with its own implicit memory heap by calling CreateCommittedResource
, but this may not be the optimal solution. For more information, see Committed versus placed resources.
When should I not use D3D12MA?
While D3D12MA is useful for many applications that use the DX12 API, there are cases when it may be a better choice not to use it. For example, if the application is very simple, e.g. serving as a sample or a learning exercise to help you understand or teach others the basics of DX12, and it creates only a small number of buffers and textures, then including D3D12MA may be an overkill. Developing your own memory allocator may also be a good learning exercise.
What are the benefits of using D3D12MA?
- D3D12MA allocates large blocks of
ID3D12Heap
memory and sub-allocates parts of them to create your placed resources. Allocating a new block of GPU memory may be a time-consuming operation. Sub-allocating parts of a memory block requires implementing an allocation algorithm, which is a non-trivial task. D3D12MA does that, using an advanced and efficient algorithm that works well in various use cases. - D3D12MA offers a simple API that allows creating placed buffers and textures within one function call like D3D12MA::Allocator::CreateResource.
The library is doing much more under the hood. For example, it keeps buffers separate from textures when needed, respecting D3D12_RESOURCE_HEAP_TIER
. It also makes use of the “small texture alignment” automatically, so you don’t need to think about it.
Which version should I pick?
You can just pick the latest version from the “master” branch. It is kept in a good shape most of the time, compiling and working correctly, with no compatibility-breaking changes and no unfinished code.
If you want an even more stable version, you can pick the latest official release. Current code from the master branch is occasionally tagged as a release, with CHANGELOG carefully curated to enumerate all important changes since the previous version.
The library uses Semantic Versioning, which means versions that only differ in the patch number are forward and backward compatible (e.g., only fixing some bugs), while versions that differ in the minor number are backward compatible (e.g., only adding new functions to the API, but not removing or changing existing ones).
How to integrate it with my code?
D3D12MA is an small library fully implemented in a single pair of CPP + H files.
You can pull the entire GitHub repository, e.g. using Git submodules. The repository contains ancillary files like the Cmake script, Doxygen config file, sample application, test suite, and others. You can compile it as a library and link with your project.
However, a simpler way is taking only files “include\D3D12MemAlloc.h”, “src\D3D12MemAlloc.cpp” and including them in your project. These files contain all you need: a copyright notice, declarations of the public library interface (API), its internal implementation, and even the documentation in form of Doxygen-style comments.
I am not a fan of modern C++. Can I still use it?
Very likely yes. We acknowledge that many C++ developers, especially in the games industry, do not appreciate all the latest features that the language has to offer.
- D3D12MA doesn’t throw or catch any C++ exceptions. It reports errors by returning a
HRESULT
value instead, just like DX12. If you don’t use exceptions in your project, your code is not exception-safe, or even if you disable exception handling in the compiler options, you can still use D3D12MA. - D3D12MA doesn’t use C++ run-time type information like
typeid
ordynamic_cast
, so if you disable RTTI in the compiler options, you can still use the library. - D3D12MA uses only a limited subset of standard C and C++ library. It doesn’t use STL containers like
std::vector
,map
, orstring
, either in the public interface nor in the internal implementation. It implements its own containers instead. - If you don’t use the default heap memory allocator through
malloc/free
ornew/delete
but implement your own allocator instead, you can pass it to D3D12MA as D3D12MA::ALLOCATOR_DESC::pAllocationCallbacks and the library will use your functions for every dynamic heap allocation made internally.
Is it available for other programming languages?
D3D12MA is a C++ library in similar style as DX12. Bindings to other programming languages are out of scope of this project, but they are welcome as external projects. Some of them are listed in README.md, “See also” section, including binding to C. Before using any of them, please check if they are still maintained and updated to use a recent version of D3D12MA.
What platforms does it support?
D3D12MA relies only on DX12 and some parts of the standard C and C++ library, so it could support any platform where a C++ compiler and DX12 are available. However, it is developed and tested only on Microsoft(R) Windows(R).
Does it only work on AMD GPUs?
No! While D3D12MA is published by AMD, it works on any GPU that supports DX12, whether a discrete PC graphics card or a processor integrated graphics. It doesn’t give AMD GPUs any advantage over any other GPUs.
What DirectX 12 versions are supported?
D3D12MA is updated to support latest versions of DirectX 12, as available through recent retail versions of the DirectX 12 Agility SDK. Support for new features added in the preview version of the Agility SDK is developed on separate branches until they are included in the retail version.
The library also supports older versions down to the base DX12 shipping with Windows SDK. Features added by later versions of the Agility SDK are automatically enabled conditionally using #ifdef
preprocessor macros depending on the version of the SDK that you compile your project with.
Does it support other graphics APIs, like Vulkan(R)?
No, but we offer an equivalent library for Vulkan: Vulkan Memory Allocator. It uses the same core allocation algorithm. It also shares many features with D3D12MA, like the support for custom pools and virtual allocator. However, it is not identical in terms of the features supported. Its API also looks different, because while the interface of D3D12MA is similar in style to DX12, the interface of VMA is similar to Vulkan.
Is the library lightweight?
Yes. D3D12MA is implemented with high-performance and real-time applications like video games in mind. The CPU performance overhead of using this library is low. It uses a high-quality allocation algorithm called Two-Level Segregated Fit (TLSF), which in most cases can find a free place for a new allocation in few steps. The library also doesn’t perform too many CPU heap allocations. In many cases, the allocation happens with 0 new CPU heap allocations performed by the library. Even the creation of a D3D12MA::Allocation object doesn’t typically feature an CPU allocation, because these objects are returned out of a dedicated memory pool.
That said, D3D12MA needs some extra memory and extra time to maintain the metadata about the occupied and free regions of the memory blocks, and the algorithms and data structures used must be generic enough to work well in most cases.
Does it have a documentation?
Yes! D3D12MA comes with full documentation of all elements of the API (classes, structures, enums), as well as many generic chapters that provide an introduction, describe core concepts of the library, good practices, etc. The entire documentation is written in form of code comments inside “D3D12MemAlloc.h”, in Doxygen format. You can access it in multiple ways:
- Browsable online: https://gpuopen-librariesandsdks.github.io/D3D12MemoryAllocator/html/
- Local HTML pages available after you clone the repository and open file “docs\html\index.html”.
- You can rebuild the documentation in HTML or some other format from the source code using Doxygen. Configuration file “Doxyfile” is part of the repository.
- Finally, you can just read the comments preceding declarations of any public classes and functions of the library.
Is it a mature project?
Yes! The library is in development since May 2019, has over 300 commits, and multiple contributors. It is used by many software projects, including some large and popular ones like Qt or Godot Engine, as well as some AAA games.
How can I contribute to the project?
If you have an idea for improvement or a feature request, you can go to the library repository and create an Issue ticket, describing your idea. You can also implement it yourself by forking the repository, making changes to the code, and creating a Pull request.
If you want to ask a question, you can also create a ticket the same way. Before doing this, please make sure you read the relevant part of the DX12 documentation and D3D12MA documentation, where you may find the answers to your question.
If you want to report a suspected bug, you can also create a ticket the same way. Before doing this, please put some effort into the investigation of whether the bug is really in the library and not in your code or in the DX12 implementation (the GPU driver) on your platform:
- Enable D3D Debug Layer and make sure it is free from any errors.
- Make sure
D3D12MA_ASSERT
is defined to an implementation that can report a failure and not ignore it. - Try making your allocation using pure DX12 functions like
CreateCommittedResource()
rather than D3D12MA and see if the bug persists.
I found some compilation warnings. How can we fix them?
Seeing compiler warnings may be annoying to some developers, but it is a design decision to not fix all of them. Due to the nature of the C++ language, certain preprocessor macros can make some variables unused, function parameters unreferenced, or conditional expressions constant in some configurations. The code of this library should not be bigger or more complicated just to silence these warnings. It is recommended to disable such warnings instead. For more information, see Features not supported.
However, if you observe a warning that is really dangerous, e.g., about an implicit conversion from a larger to a smaller integer type, please report it and it will be fixed ASAP.
Version history
- Added helper structs:
CALLOCATION_DESC
,CPOOL_DESC
,CVIRTUAL_BLOCK_DESC
,CVIRTUAL_ALLOCATION_DESC
. - Added macros:
D3D12MA_RECOMMENDED_ALLOCATOR_FLAGS
,D3D12MA_RECOMMENDED_HEAP_FLAGS
,D3D12MA_RECOMMENDED_POOL_FLAGS
. - Added functions:
Allocator::CreateResource3
,CreateAliasingResource2
.- They support parameters:
D3D12_BARRIER_LAYOUT InitialLayout
,const DXGI_FORMAT* pCastableFormats
. - They require recent DirectX 12 Agility SDK. To use them,
ID3D12Device10
must be available. To use non-empty list of castable formats,ID3D12Device12
must be available.
- They support parameters:
- Added support for GPU Upload Heaps (
D3D12_HEAP_TYPE_GPU_UPLOAD
).- Requires recent DirectX 12 Agility SDK. Support on the user’s machine is available only when supported by the motherboard, GPU, drivers, and enabled as “Resizable BAR” in UEFI settings. It can be queried using new
Allocator::IsGPUUploadHeapSupported
function. TotalStatistics::HeapType
array was extended from 4 to 5 elements.
- Requires recent DirectX 12 Agility SDK. Support on the user’s machine is available only when supported by the motherboard, GPU, drivers, and enabled as “Resizable BAR” in UEFI settings. It can be queried using new
- Added missing function
Allocator::CreateAliasingResource1
. - Added
POOL_DESC::ResidencyPriority
member. - Removed
Allocation::WasZeroInitialized
function. It wasn’t fully implemented anyway. - Added
POOL_FLAG_ALWAYS_COMMITTED
. - Added a heuristic that prefers creating small buffers as committed to save memory.
- It is enabled by default. It can be disabled by new flag
ALLOCATOR_FLAG_DONT_PREFER_SMALL_BUFFERS_COMMITTED
.
- It is enabled by default. It can be disabled by new flag
- Macro
D3D12MA_OPTIONS16_SUPPORTED
is no longer exposed in the header or Cmake script. It is defined automatically based on the Agility SDK version. - Added macro
D3D12MA_DEBUG_LOG
, which can be used to log unfreed allocations. - Many improvements in the documentation, including new chapters: “Frequently asked questions”, “Optimal resource allocation”.
- Countless fixes and improvements, including performance optimizations, compatibility with various compilers, tests.
- Major changes in the Cmake script.
- Fixes in “GpuMemDumpVis.py” script.
A maintenance release with some bug fixes and improvements. There are no changes in the library API.
- Fixed an assert failing when detailed JSON dump was made while a custom pool was present with specified string name (#36, thanks @rbertin-aso).
- Fixed image height calculation in JSON dump visualization tool “GpuMemDumpVis.py” (#37, thanks @rbertin-aso).
- Added JSON Schema for JSON dump format – see file “tools\GpuMemDumpVis\GpuMemDump.schema.json”.
- Added documentation section “Resource reference counting”.
So much has changed since the first release that it doesn’t make much sense to compare the differences. Here are the most important features that the library now provides:
- Powerful custom pools, which give an opportunity to not only keep certain resources together, reserve some minimum or limit the maximum amount of memory they can take, but also to pass additional allocation parameters unavailable to simple allocations. Among them, probably the most interesting is
POOL_DESC::HeapProperties
, which allows you to specify parameters of a custom memory type, which may be useful on UMA platforms. Committed allocations can now also be created in custom pools. - The API for statistics and budget has been redesigned – see structures
Statistics
,Budget
,DetailedStatistics
,TotalStatistics
. - The library exposes its core allocation algorithm via the “virtual allocator” interface. This can be used to allocate pieces of custom memory or whatever you like, even something completely unrelated to graphics.
- The allocation algorithm has been replaced with the new, more efficient TLSF.
- Added support for defragmentation.
- Objects of the library can be used with smart pointers designed for COM objects.
- Initial release
- Initial release
Our other SDKs

The AMD Interactive Streaming SDK provides developers with a set of building blocks and samples that allow to easily create custom low-latency streaming solutions for cloud gaming, VDI, and embedded applications using AMD GPUs.

Dense Geometry Compression Format (DGF) is our block-based geometry compression technology. It is a hardware-friendly format, supported by future GPU architectures.

AMD Schola is a library for developing reinforcement learning (RL) agents in Unreal Engine and training with your favorite python-based RL Frameworks.

AMD Radeon™ Anti-Lag 2 reduces the system latency by applying frame alignment between the CPU and GPU jobs.

Capsaicin is a Direct3D12 framework for real-time graphics research which implements the GI-1.0 technique and a reference path-tracer.

The Render Pipeline Shaders (RPS) SDK provides a framework for graphics engines to use Render Graphs with explicit APIs.

ADLX is a modern library designed to access features and functionality of AMD systems such as Display, 3D graphics, Performance Monitoring, GPU Tuning, and more.

Brotli-G is an open-source compression/decompression standard for digital assets (based on Brotli) that is compatible with GPU hardware.

HIP RT is a ray tracing library for HIP, making it easy to write ray tracing applications in HIP.

Orochi is a library which loads HIP and CUDA® APIs dynamically, allowing the user to switch APIs at runtime.

AMD Radeon™ ProRender is our fast, easy, and incredible physically-based rendering engine built on industry standards that enables accelerated rendering on virtually any GPU, any CPU, and any OS in over a dozen leading digital content creation and CAD applications.

Radeon™ Machine Learning (Radeon™ ML or RML) is an AMD SDK for high-performance deep learning inference on GPUs.

Harness the power of machine learning to enhance images with denoising, enabling your application to produce high quality images in a fraction of the time traditional denoising filters take.

The Advanced Media Framework SDK provides developers with optimal access to AMD GPUs for multimedia processing.

The AMD Display Library (ADL) SDK is designed to access display driver functionality for AMD Radeon™ and AMD FirePro™ graphics cards.

The AMD GPU Services (AGS) library provides software developers with the ability to query AMD GPU software and hardware state information that is not normally available through standard operating systems or graphics APIs.

VMA is our single-header, MIT-licensed, C++ library for easily and efficiently managing memory allocation for your Vulkan® games and applications.

AMD TrueAudio Next is a software development kit for GPU accelerated and multi-core high-performance audio signal processing.

AMD Radeon™ ProRender SDK is a powerful physically-based path traced rendering engine that enables creative professionals to produce stunningly photorealistic images.

The lightweight accelerated ray intersection library for DirectX®12 and Vulkan®.