commit | 5f826f3239344d4f0b61e3379aaa15c97dca7e67 | [log] [tgz] |
---|---|---|
author | Elliot <apachehaisley@gmail.com> | Mon Oct 28 11:26:59 2024 -0400 |
committer | Elliot <apachehaisley@gmail.com> | Mon Oct 28 11:26:59 2024 -0400 |
tree | 8484e349e0fbe98a5828f44dd7e6a681d735ffa8 | |
parent | e00c4a7c85cf9c28c6f4a6cc75032736f416410f [diff] |
Resolve -Wtautological-undefined-compare when building with clang Comparing 'this' to 'nullptr' will always evaluate to false. clang and gcc optimize away the check entirely, removing the checks silences the warnings. https://clang.llvm.org/docs/DiagnosticsReference.html#wtautological-undefined-compare
Easy to integrate memory allocation library for Direct3D 12.
Documentation: Browse online: D3D12 Memory Allocator (generated from Doxygen-style comments in include/D3D12MemAlloc.h)
License: MIT. See LICENSE.txt
Changelog: See CHANGELOG.md
Product page: D3D12 Memory Allocator on GPUOpen
Build status:
Memory allocation and resource (buffer and texture) creation in new, explicit graphics APIs (VulkanĀ® and Direct3D 12) is difficult comparing to older graphics APIs like Direct3D 11 or OpenGLĀ® because it is recommended to allocate bigger blocks of memory and assign parts of them to resources. Vulkan Memory Allocator is a library that implements this functionality for Vulkan. It is available online since 2017 and it is successfully used in many software projects, including some AAA game studios. This is an equivalent library for D3D12.
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:
D3D12_RESOURCE_HEAP_TIER_1
that requires to keep certain classes of resources separate or D3D12_RESOURCE_HEAP_TIER_2
that allows to keep them all together.Additional features:
ALLOCATOR_DESC
structure to provide custom CPU memory allocator and other parameters.D3D12_HEAP_PROPERTIES
and D3D12_HEAP_FLAGS
) and allocate memory out of it.D3D12MA_OPTIONS16_SUPPORTED
macro).void* pPrivateData
and debug LPCWSTR pName
with each allocation.HRESULT
error codes - same way as in D3D12.Basic usage of this library is very simple. Advanced features are optional. After you created global Allocator
object, a complete code needed to create a texture may look like this:
D3D12_RESOURCE_DESC resourceDesc = {}; resourceDesc.Dimension = D3D12_RESOURCE_DIMENSION_TEXTURE2D; resourceDesc.Alignment = 0; resourceDesc.Width = 1024; resourceDesc.Height = 1024; resourceDesc.DepthOrArraySize = 1; resourceDesc.MipLevels = 1; resourceDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM; resourceDesc.SampleDesc.Count = 1; resourceDesc.SampleDesc.Quality = 0; resourceDesc.Layout = D3D12_TEXTURE_LAYOUT_UNKNOWN; resourceDesc.Flags = D3D12_RESOURCE_FLAG_NONE; D3D12MA::ALLOCATION_DESC allocDesc = {}; allocDesc.HeapType = D3D12_HEAP_TYPE_DEFAULT; D3D12Resource* resource; D3D12MA::Allocation* allocation; HRESULT hr = allocator->CreateResource( &allocDesc, &resourceDesc, D3D12_RESOURCE_STATE_COPY_DEST, NULL, &allocation, IID_PPV_ARGS(&resource));
With this one function call:
ID3D12Heap
memory block is allocated if needed.ID3D12Resource
is created as placed resource, bound to this region.Allocation
is an object that represents memory assigned to this texture. It can be queried for parameters like offset and size.
The release comes with precompiled binary executable for “D3D12Sample” 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 its 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.
This software package uses third party software:
For more information see NOTICES.txt.
Some other projects on GitHub and some game development studios that use DX12 in their games.