D3D12 Memory Allocator
Loading...
Searching...
No Matches
D3D12MemAlloc.h File Reference
#include <d3d12.h>
#include <dxgi1_4.h>

Classes

struct  D3D12MA::ALLOCATION_CALLBACKS
 Custom callbacks to CPU memory allocation functions. More...
 
struct  D3D12MA::ALLOCATION_DESC
 Parameters of created D3D12MA::Allocation object. To be used with Allocator::CreateResource. More...
 
struct  D3D12MA::Statistics
 Calculated statistics of memory usage e.g. in a specific memory heap type, memory segment group, custom pool, or total. More...
 
struct  D3D12MA::DetailedStatistics
 More detailed statistics than D3D12MA::Statistics. More...
 
struct  D3D12MA::TotalStatistics
 General statistics from current state of the allocator - total memory usage across all memory heaps and segments. More...
 
struct  D3D12MA::Budget
 Statistics of current memory usage and available budget for a specific memory segment group. More...
 
struct  D3D12MA::VirtualAllocation
 Represents single memory allocation done inside VirtualBlock. More...
 
class  D3D12MA::Allocation
 Represents single memory allocation. More...
 
struct  D3D12MA::DEFRAGMENTATION_DESC
 Parameters for defragmentation. More...
 
struct  D3D12MA::DEFRAGMENTATION_MOVE
 Single move of an allocation to be done for defragmentation. More...
 
struct  D3D12MA::DEFRAGMENTATION_PASS_MOVE_INFO
 Parameters for incremental defragmentation steps. More...
 
struct  D3D12MA::DEFRAGMENTATION_STATS
 Statistics returned for defragmentation process by function DefragmentationContext::GetStats(). More...
 
class  D3D12MA::DefragmentationContext
 Represents defragmentation process in progress. More...
 
struct  D3D12MA::POOL_DESC
 Parameters of created D3D12MA::Pool object. To be used with D3D12MA::Allocator::CreatePool. More...
 
class  D3D12MA::Pool
 Custom memory pool. More...
 
struct  D3D12MA::ALLOCATOR_DESC
 Parameters of created Allocator object. To be used with CreateAllocator(). More...
 
class  D3D12MA::Allocator
 Represents main object of this library initialized for particular ID3D12Device. More...
 
struct  D3D12MA::VIRTUAL_BLOCK_DESC
 Parameters of created D3D12MA::VirtualBlock object to be passed to CreateVirtualBlock(). More...
 
struct  D3D12MA::VIRTUAL_ALLOCATION_DESC
 Parameters of created virtual allocation to be passed to VirtualBlock::Allocate(). More...
 
struct  D3D12MA::VIRTUAL_ALLOCATION_INFO
 Parameters of an existing virtual allocation, returned by VirtualBlock::GetAllocationInfo(). More...
 
class  D3D12MA::VirtualBlock
 Represents pure allocation algorithm and a data structure with allocations in some memory block, without actually allocating any GPU memory. More...
 
struct  D3D12MA::CALLOCATION_DESC
 Helper structure that helps with complete and conscise initialization of the D3D12MA::ALLOCATION_DESC structure. More...
 
struct  D3D12MA::CPOOL_DESC
 Helper structure that helps with complete and conscise initialization of the D3D12MA::POOL_DESC structure. More...
 
struct  D3D12MA::CVIRTUAL_BLOCK_DESC
 Helper structure that helps with complete and conscise initialization of the D3D12MA::VIRTUAL_BLOCK_DESC structure. More...
 
struct  D3D12MA::CVIRTUAL_ALLOCATION_DESC
 Helper structure that helps with complete and conscise initialization of the D3D12MA::VIRTUAL_ALLOCATION_DESC structure. More...
 

Namespaces

namespace  D3D12MA
 

Macros

#define D3D12MA_DXGI_1_4   1
 Define this macro to 0 to disable usage of DXGI 1.4 (which is used for IDXGIAdapter3 and query for memory budget).
 
#define D3D12MA_CREATE_NOT_ZEROED_AVAILABLE   1
 This macro is defined to 0 or 1 automatically. Define it to 0 to disable support for D3D12_HEAP_FLAG_CREATE_NOT_ZEROED.
 
#define D3D12MA_USE_SMALL_RESOURCE_PLACEMENT_ALIGNMENT   1
 When defined to value other than 0, the library will try to use D3D12_SMALL_RESOURCE_PLACEMENT_ALIGNMENT or D3D12_SMALL_MSAA_RESOURCE_PLACEMENT_ALIGNMENT for created textures when possible, which can save memory because some small textures may get their alignment 4 KB and their size a multiply of 4 KB instead of 64 KB.
 
#define D3D12MA_RECOMMENDED_ALLOCATOR_FLAGS   (ALLOCATOR_FLAG_DEFAULT_POOLS_NOT_ZEROED | ALLOCATOR_FLAG_MSAA_TEXTURES_ALWAYS_COMMITTED)
 Set of flags recommended for use in D3D12MA::ALLOCATOR_DESC::Flags for optimal performance.
 
#define D3D12MA_RECOMMENDED_HEAP_FLAGS   (D3D12_HEAP_FLAG_NONE)
 Set of flags recommended for use in D3D12MA::POOL_DESC::HeapFlags for optimal performance.
 
#define D3D12MA_RECOMMENDED_POOL_FLAGS   (POOL_FLAG_MSAA_TEXTURES_ALWAYS_COMMITTED)
 Set of flags recommended for use in D3D12MA::POOL_DESC::Flags for optimal performance.
 

Typedefs

typedef UINT64 D3D12MA::AllocHandle
 Unique identifier of single allocation done inside the memory heap.
 
using D3D12MA::ALLOCATE_FUNC_PTR = void* (*)(size_t Size, size_t Alignment, void* pPrivateData)
 Pointer to custom callback function that allocates CPU memory.
 
using D3D12MA::FREE_FUNC_PTR = void (*)(void* pMemory, void* pPrivateData)
 Pointer to custom callback function that deallocates CPU memory.
 

Enumerations

enum  D3D12MA::ALLOCATION_FLAGS {
  D3D12MA::ALLOCATION_FLAG_NONE = 0 , D3D12MA::ALLOCATION_FLAG_COMMITTED = 0x1 , D3D12MA::ALLOCATION_FLAG_NEVER_ALLOCATE = 0x2 , D3D12MA::ALLOCATION_FLAG_WITHIN_BUDGET = 0x4 ,
  D3D12MA::ALLOCATION_FLAG_UPPER_ADDRESS = 0x8 , D3D12MA::ALLOCATION_FLAG_CAN_ALIAS = 0x10 , D3D12MA::ALLOCATION_FLAG_STRATEGY_MIN_MEMORY = 0x00010000 , D3D12MA::ALLOCATION_FLAG_STRATEGY_MIN_TIME = 0x00020000 ,
  D3D12MA::ALLOCATION_FLAG_STRATEGY_MIN_OFFSET = 0x0004000 , D3D12MA::ALLOCATION_FLAG_STRATEGY_BEST_FIT = ALLOCATION_FLAG_STRATEGY_MIN_MEMORY , D3D12MA::ALLOCATION_FLAG_STRATEGY_FIRST_FIT = ALLOCATION_FLAG_STRATEGY_MIN_TIME , D3D12MA::ALLOCATION_FLAG_STRATEGY_MASK
}
 Bit flags to be used with ALLOCATION_DESC::Flags. More...
 
enum  D3D12MA::DEFRAGMENTATION_FLAGS { D3D12MA::DEFRAGMENTATION_FLAG_ALGORITHM_FAST = 0x1 , D3D12MA::DEFRAGMENTATION_FLAG_ALGORITHM_BALANCED = 0x2 , D3D12MA::DEFRAGMENTATION_FLAG_ALGORITHM_FULL = 0x4 , D3D12MA::DEFRAGMENTATION_FLAG_ALGORITHM_MASK }
 Flags to be passed as DEFRAGMENTATION_DESC::Flags. More...
 
enum  D3D12MA::DEFRAGMENTATION_MOVE_OPERATION { D3D12MA::DEFRAGMENTATION_MOVE_OPERATION_COPY = 0 , D3D12MA::DEFRAGMENTATION_MOVE_OPERATION_IGNORE = 1 , D3D12MA::DEFRAGMENTATION_MOVE_OPERATION_DESTROY = 2 }
 Operation performed on single defragmentation move. More...
 
enum  D3D12MA::POOL_FLAGS {
  D3D12MA::POOL_FLAG_NONE = 0 , D3D12MA::POOL_FLAG_ALGORITHM_LINEAR = 0x1 , D3D12MA::POOL_FLAG_MSAA_TEXTURES_ALWAYS_COMMITTED = 0x2 , D3D12MA::POOL_FLAG_ALWAYS_COMMITTED = 0x4 ,
  D3D12MA::POOL_FLAG_ALGORITHM_MASK = POOL_FLAG_ALGORITHM_LINEAR
}
 Bit flags to be used with POOL_DESC::Flags. More...
 
enum  D3D12MA::ALLOCATOR_FLAGS {
  D3D12MA::ALLOCATOR_FLAG_NONE = 0 , D3D12MA::ALLOCATOR_FLAG_SINGLETHREADED = 0x1 , D3D12MA::ALLOCATOR_FLAG_ALWAYS_COMMITTED = 0x2 , D3D12MA::ALLOCATOR_FLAG_DEFAULT_POOLS_NOT_ZEROED = 0x4 ,
  D3D12MA::ALLOCATOR_FLAG_MSAA_TEXTURES_ALWAYS_COMMITTED = 0x8 , D3D12MA::ALLOCATOR_FLAG_DONT_PREFER_SMALL_BUFFERS_COMMITTED = 0x10
}
 Bit flags to be used with ALLOCATOR_DESC::Flags. More...
 
enum  D3D12MA::VIRTUAL_BLOCK_FLAGS { D3D12MA::VIRTUAL_BLOCK_FLAG_NONE = 0 , D3D12MA::VIRTUAL_BLOCK_FLAG_ALGORITHM_LINEAR = POOL_FLAG_ALGORITHM_LINEAR , D3D12MA::VIRTUAL_BLOCK_FLAG_ALGORITHM_MASK = POOL_FLAG_ALGORITHM_MASK }
 Bit flags to be used with VIRTUAL_BLOCK_DESC::Flags. More...
 
enum  D3D12MA::VIRTUAL_ALLOCATION_FLAGS {
  D3D12MA::VIRTUAL_ALLOCATION_FLAG_NONE = 0 , D3D12MA::VIRTUAL_ALLOCATION_FLAG_UPPER_ADDRESS = ALLOCATION_FLAG_UPPER_ADDRESS , D3D12MA::VIRTUAL_ALLOCATION_FLAG_STRATEGY_MIN_MEMORY = ALLOCATION_FLAG_STRATEGY_MIN_MEMORY , D3D12MA::VIRTUAL_ALLOCATION_FLAG_STRATEGY_MIN_TIME = ALLOCATION_FLAG_STRATEGY_MIN_TIME ,
  D3D12MA::VIRTUAL_ALLOCATION_FLAG_STRATEGY_MIN_OFFSET = ALLOCATION_FLAG_STRATEGY_MIN_OFFSET , D3D12MA::VIRTUAL_ALLOCATION_FLAG_STRATEGY_MASK = ALLOCATION_FLAG_STRATEGY_MASK
}
 Bit flags to be used with VIRTUAL_ALLOCATION_DESC::Flags. More...
 

Functions

D3D12MA_API HRESULT D3D12MA::CreateAllocator (const ALLOCATOR_DESC *pDesc, Allocator **ppAllocator)
 Creates new main D3D12MA::Allocator object and returns it through ppAllocator.
 
D3D12MA_API HRESULT D3D12MA::CreateVirtualBlock (const VIRTUAL_BLOCK_DESC *pDesc, VirtualBlock **ppVirtualBlock)
 Creates new D3D12MA::VirtualBlock object and returns it through ppVirtualBlock.
 

Macro Definition Documentation

◆ D3D12MA_CREATE_NOT_ZEROED_AVAILABLE

#define D3D12MA_CREATE_NOT_ZEROED_AVAILABLE   1

This macro is defined to 0 or 1 automatically. Define it to 0 to disable support for D3D12_HEAP_FLAG_CREATE_NOT_ZEROED.

◆ D3D12MA_DXGI_1_4

#define D3D12MA_DXGI_1_4   1

Define this macro to 0 to disable usage of DXGI 1.4 (which is used for IDXGIAdapter3 and query for memory budget).

◆ D3D12MA_RECOMMENDED_ALLOCATOR_FLAGS

#define D3D12MA_RECOMMENDED_ALLOCATOR_FLAGS   (ALLOCATOR_FLAG_DEFAULT_POOLS_NOT_ZEROED | ALLOCATOR_FLAG_MSAA_TEXTURES_ALWAYS_COMMITTED)

Set of flags recommended for use in D3D12MA::ALLOCATOR_DESC::Flags for optimal performance.

◆ D3D12MA_RECOMMENDED_HEAP_FLAGS

#define D3D12MA_RECOMMENDED_HEAP_FLAGS   (D3D12_HEAP_FLAG_NONE)

Set of flags recommended for use in D3D12MA::POOL_DESC::HeapFlags for optimal performance.

◆ D3D12MA_RECOMMENDED_POOL_FLAGS

#define D3D12MA_RECOMMENDED_POOL_FLAGS   (POOL_FLAG_MSAA_TEXTURES_ALWAYS_COMMITTED)

Set of flags recommended for use in D3D12MA::POOL_DESC::Flags for optimal performance.

◆ D3D12MA_USE_SMALL_RESOURCE_PLACEMENT_ALIGNMENT

#define D3D12MA_USE_SMALL_RESOURCE_PLACEMENT_ALIGNMENT   1

When defined to value other than 0, the library will try to use D3D12_SMALL_RESOURCE_PLACEMENT_ALIGNMENT or D3D12_SMALL_MSAA_RESOURCE_PLACEMENT_ALIGNMENT for created textures when possible, which can save memory because some small textures may get their alignment 4 KB and their size a multiply of 4 KB instead of 64 KB.

  • #define D3D12MA_USE_SMALL_RESOURCE_PLACEMENT_ALIGNMENT 0 - Disables small texture alignment.
  • #define D3D12MA_USE_SMALL_RESOURCE_PLACEMENT_ALIGNMENT 1 (the default) - Enables conservative algorithm that will use small alignment only for some textures that are surely known to support it.
  • #define D3D12MA_USE_SMALL_RESOURCE_PLACEMENT_ALIGNMENT 2 - Enables query for small alignment to D3D12 (based on Microsoft sample) which will enable small alignment for more textures, but will also generate D3D Debug Layer error #721 on call to ID3D12Device::GetResourceAllocationInfo, which you should just ignore.