diff --git a/docs/html/_d3_d12_mem_alloc_8h.html b/docs/html/_d3_d12_mem_alloc_8h.html
index 4ef0e9e..9492ee2 100644
--- a/docs/html/_d3_d12_mem_alloc_8h.html
+++ b/docs/html/_d3_d12_mem_alloc_8h.html
@@ -212,6 +212,7 @@ Enumerations
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
} |
| Bit flags to be used with ALLOCATOR_DESC::Flags. More...
|
|
diff --git a/docs/html/configuration.html b/docs/html/configuration.html
index 185943b..a914bfc 100644
--- a/docs/html/configuration.html
+++ b/docs/html/configuration.html
@@ -101,15 +101,15 @@ Custom CPU memory allocator
-Represents main object of this library initialized for particular ID3D12Device.
Definition: D3D12MemAlloc.h:1039
+Represents main object of this library initialized for particular ID3D12Device.
Definition: D3D12MemAlloc.h:1055
D3D12MA_API HRESULT CreateAllocator(const ALLOCATOR_DESC *pDesc, Allocator **ppAllocator)
Creates new main D3D12MA::Allocator object and returns it through ppAllocator.
Custom callbacks to CPU memory allocation functions.
Definition: D3D12MemAlloc.h:187
FREE_FUNC_PTR pFree
Dellocation function.
Definition: D3D12MemAlloc.h:191
ALLOCATE_FUNC_PTR pAllocate
Allocation function.
Definition: D3D12MemAlloc.h:189
-Parameters of created Allocator object. To be used with CreateAllocator().
Definition: D3D12MemAlloc.h:1000
-const ALLOCATION_CALLBACKS * pAllocationCallbacks
Custom CPU memory allocation callbacks. Optional.
Definition: D3D12MemAlloc.h:1020
-IDXGIAdapter * pAdapter
Definition: D3D12MemAlloc.h:1026
-ID3D12Device * pDevice
Definition: D3D12MemAlloc.h:1008
+Parameters of created Allocator object. To be used with CreateAllocator().
Definition: D3D12MemAlloc.h:1016
+const ALLOCATION_CALLBACKS * pAllocationCallbacks
Custom CPU memory allocation callbacks. Optional.
Definition: D3D12MemAlloc.h:1036
+IDXGIAdapter * pAdapter
Definition: D3D12MemAlloc.h:1042
+ID3D12Device * pDevice
Definition: D3D12MemAlloc.h:1024
Debug margins
By default, allocations are laid out in memory blocks next to each other if possible (considering required alignment returned by ID3D12Device::GetResourceAllocationInfo
).
diff --git a/docs/html/namespace_d3_d12_m_a.html b/docs/html/namespace_d3_d12_m_a.html
index b8d536a..5f33b72 100644
--- a/docs/html/namespace_d3_d12_m_a.html
+++ b/docs/html/namespace_d3_d12_m_a.html
@@ -192,6 +192,7 @@ Enumerations
enum | ALLOCATOR_FLAGS { ALLOCATOR_FLAG_NONE = 0
, ALLOCATOR_FLAG_SINGLETHREADED = 0x1
, ALLOCATOR_FLAG_ALWAYS_COMMITTED = 0x2
+, ALLOCATOR_FLAG_DEFAULT_POOLS_NOT_ZEROED = 0x4
} |
| Bit flags to be used with ALLOCATOR_DESC::Flags. More...
|
|
@@ -347,6 +348,61 @@ Functions
ALLOCATOR_FLAG_ALWAYS_COMMITTED | Every allocation will have its own memory block. To be used for debugging purposes.
|
+ALLOCATOR_FLAG_DEFAULT_POOLS_NOT_ZEROED | Heaps created for the default pools will be created with flag D3D12_HEAP_FLAG_CREATE_NOT_ZEROED , allowing for their memory to be not zeroed by the system if possible, which can speed up allocation.
+Only affects default pools. To use the flag with Custom memory pools, you need to add it manually:
+poolDesc.heapFlags |= D3D12_HEAP_FLAG_CREATE_NOT_ZEROED;
+ Only avaiable if ID3D12Device8 is present. Otherwise, the flag is ignored.
+ |
+
+
+
+
+
+◆ DEFRAGMENTATION_FLAGS
+
+
+
+
+
Flags to be passed as DEFRAGMENTATION_DESC::Flags.
+
+Enumerator |
---|
DEFRAGMENTATION_FLAG_ALGORITHM_FAST | Use simple but fast algorithm for defragmentation. May not achieve best results but will require least time to compute and least allocations to copy.
+ |
+DEFRAGMENTATION_FLAG_ALGORITHM_BALANCED | Default defragmentation algorithm, applied also when no ALGORITHM flag is specified. Offers a balance between defragmentation quality and the amount of allocations and bytes that need to be moved.
+ |
+DEFRAGMENTATION_FLAG_ALGORITHM_FULL | Perform full defragmentation of memory. Can result in notably more time to compute and allocations to copy, but will achieve best memory packing.
+ |
+DEFRAGMENTATION_FLAG_ALGORITHM_MASK | A bit mask to extract only ALGORITHM bits from entire set of flags.
+ |
+
+
+
+
+
+◆ DEFRAGMENTATION_MOVE_OPERATION
+
+
+
+
+
Operation performed on single defragmentation move.
+
+Enumerator |
---|
DEFRAGMENTATION_MOVE_OPERATION_COPY | Resource has been recreated at pDstTmpAllocation , data has been copied, old resource has been destroyed. pSrcAllocation will be changed to point to the new place. This is the default value set by DefragmentationContext::BeginPass().
+ |
+DEFRAGMENTATION_MOVE_OPERATION_IGNORE | Set this value if you cannot move the allocation. New place reserved at pDstTmpAllocation will be freed. pSrcAllocation will remain unchanged.
+ |
+DEFRAGMENTATION_MOVE_OPERATION_DESTROY | Set this value if you decide to abandon the allocation and you destroyed the resource. New place reserved pDstTmpAllocation will be freed, along with pSrcAllocation .
+ |
diff --git a/docs/html/namespacemembers.html b/docs/html/namespacemembers.html
index 0cfd9b1..1a98292 100644
--- a/docs/html/namespacemembers.html
+++ b/docs/html/namespacemembers.html
@@ -80,6 +80,7 @@ $(function() {
ALLOCATION_FLAG_WITHIN_BUDGET : D3D12MA
ALLOCATION_FLAGS : D3D12MA
ALLOCATOR_FLAG_ALWAYS_COMMITTED : D3D12MA
+
ALLOCATOR_FLAG_DEFAULT_POOLS_NOT_ZEROED : D3D12MA
ALLOCATOR_FLAG_NONE : D3D12MA
ALLOCATOR_FLAG_SINGLETHREADED : D3D12MA
ALLOCATOR_FLAGS : D3D12MA
diff --git a/docs/html/namespacemembers_eval.html b/docs/html/namespacemembers_eval.html
index f06c36a..9447ea3 100644
--- a/docs/html/namespacemembers_eval.html
+++ b/docs/html/namespacemembers_eval.html
@@ -78,6 +78,7 @@ $(function() {
ALLOCATION_FLAG_UPPER_ADDRESS : D3D12MA
ALLOCATION_FLAG_WITHIN_BUDGET : D3D12MA
ALLOCATOR_FLAG_ALWAYS_COMMITTED : D3D12MA
+
ALLOCATOR_FLAG_DEFAULT_POOLS_NOT_ZEROED : D3D12MA
ALLOCATOR_FLAG_NONE : D3D12MA
ALLOCATOR_FLAG_SINGLETHREADED : D3D12MA
diff --git a/docs/html/quick_start.html b/docs/html/quick_start.html
index 24fd81f..6aec9de 100644
--- a/docs/html/quick_start.html
+++ b/docs/html/quick_start.html
@@ -90,11 +90,11 @@ Project setup and initialization
-
Represents main object of this library initialized for particular ID3D12Device.
Definition: D3D12MemAlloc.h:1039
+
Represents main object of this library initialized for particular ID3D12Device.
Definition: D3D12MemAlloc.h:1055
D3D12MA_API HRESULT CreateAllocator(const ALLOCATOR_DESC *pDesc, Allocator **ppAllocator)
Creates new main D3D12MA::Allocator object and returns it through ppAllocator.
-
Parameters of created Allocator object. To be used with CreateAllocator().
Definition: D3D12MemAlloc.h:1000
-
IDXGIAdapter * pAdapter
Definition: D3D12MemAlloc.h:1026
-
ID3D12Device * pDevice
Definition: D3D12MemAlloc.h:1008
+
Parameters of created Allocator object. To be used with CreateAllocator().
Definition: D3D12MemAlloc.h:1016
+
IDXGIAdapter * pAdapter
Definition: D3D12MemAlloc.h:1042
+
ID3D12Device * pDevice
Definition: D3D12MemAlloc.h:1024
(5.) Right before destroying the D3D12 device, destroy the allocator object.
Objects of this library must be destroyed by calling Release
method. They are somewhat compatible with COM: they implement IUnknown
interface with its virtual methods: AddRef
, Release
, QueryInterface
, and they are reference-counted internally. You can use smart pointers designed for COM with objects of this library - e.g. CComPtr
or Microsoft::WRL::ComPtr
. The reference counter is thread-safe. QueryInterface
method supports only IUnknown
, as classes of this library don't define their own GUIDs.
allocator->Release();
diff --git a/docs/html/search/all_0.js b/docs/html/search/all_0.js
index e5cc243..e8cd098 100644
--- a/docs/html/search/all_0.js
+++ b/docs/html/search/all_0.js
@@ -28,10 +28,11 @@ var searchData=
['allocator_25',['Allocator',['../class_d3_d12_m_a_1_1_allocator.html',1,'D3D12MA']]],
['allocator_5fdesc_26',['ALLOCATOR_DESC',['../struct_d3_d12_m_a_1_1_a_l_l_o_c_a_t_o_r___d_e_s_c.html',1,'D3D12MA']]],
['allocator_5fflag_5falways_5fcommitted_27',['ALLOCATOR_FLAG_ALWAYS_COMMITTED',['../namespace_d3_d12_m_a.html#ad5ae5a5e42b878f2e18ab5d1fbfb9916a068863dc0538ff4ea153b046b31e94fb',1,'D3D12MA']]],
- ['allocator_5fflag_5fnone_28',['ALLOCATOR_FLAG_NONE',['../namespace_d3_d12_m_a.html#ad5ae5a5e42b878f2e18ab5d1fbfb9916a2fb30967b492c27823a80b5de3aea26f',1,'D3D12MA']]],
- ['allocator_5fflag_5fsinglethreaded_29',['ALLOCATOR_FLAG_SINGLETHREADED',['../namespace_d3_d12_m_a.html#ad5ae5a5e42b878f2e18ab5d1fbfb9916a1b06bb21df006f76a9ed1bc41838bc52',1,'D3D12MA']]],
- ['allocator_5fflags_30',['ALLOCATOR_FLAGS',['../namespace_d3_d12_m_a.html#ad5ae5a5e42b878f2e18ab5d1fbfb9916',1,'D3D12MA']]],
- ['allochandle_31',['AllocHandle',['../struct_d3_d12_m_a_1_1_virtual_allocation.html#a5d3166cf1f284fbbea4d0b169c4dba13',1,'D3D12MA::VirtualAllocation']]],
- ['allochandle_32',['allocHandle',['../class_d3_d12_m_a_1_1_allocation.html#a5c38846905b1ca0ff228c6081f2fc20c',1,'D3D12MA::Allocation']]],
- ['allochandle_33',['AllocHandle',['../namespace_d3_d12_m_a.html#a15e349adce86a40e0417d405aef1af80',1,'D3D12MA']]]
+ ['allocator_5fflag_5fdefault_5fpools_5fnot_5fzeroed_28',['ALLOCATOR_FLAG_DEFAULT_POOLS_NOT_ZEROED',['../namespace_d3_d12_m_a.html#ad5ae5a5e42b878f2e18ab5d1fbfb9916ae7dc7ab9168148281ebfe1586f554335',1,'D3D12MA']]],
+ ['allocator_5fflag_5fnone_29',['ALLOCATOR_FLAG_NONE',['../namespace_d3_d12_m_a.html#ad5ae5a5e42b878f2e18ab5d1fbfb9916a2fb30967b492c27823a80b5de3aea26f',1,'D3D12MA']]],
+ ['allocator_5fflag_5fsinglethreaded_30',['ALLOCATOR_FLAG_SINGLETHREADED',['../namespace_d3_d12_m_a.html#ad5ae5a5e42b878f2e18ab5d1fbfb9916a1b06bb21df006f76a9ed1bc41838bc52',1,'D3D12MA']]],
+ ['allocator_5fflags_31',['ALLOCATOR_FLAGS',['../namespace_d3_d12_m_a.html#ad5ae5a5e42b878f2e18ab5d1fbfb9916',1,'D3D12MA']]],
+ ['allochandle_32',['AllocHandle',['../struct_d3_d12_m_a_1_1_virtual_allocation.html#a5d3166cf1f284fbbea4d0b169c4dba13',1,'D3D12MA::VirtualAllocation']]],
+ ['allochandle_33',['allocHandle',['../class_d3_d12_m_a_1_1_allocation.html#a5c38846905b1ca0ff228c6081f2fc20c',1,'D3D12MA::Allocation']]],
+ ['allochandle_34',['AllocHandle',['../namespace_d3_d12_m_a.html#a15e349adce86a40e0417d405aef1af80',1,'D3D12MA']]]
];
diff --git a/docs/html/search/enumvalues_0.js b/docs/html/search/enumvalues_0.js
index 4d32fea..ac4038d 100644
--- a/docs/html/search/enumvalues_0.js
+++ b/docs/html/search/enumvalues_0.js
@@ -13,6 +13,7 @@ var searchData=
['allocation_5fflag_5fupper_5faddress_10',['ALLOCATION_FLAG_UPPER_ADDRESS',['../namespace_d3_d12_m_a.html#abbad31a7e0b3d09d77f3fb704b77645eafb0e2dacce691336e717550a1df72474',1,'D3D12MA']]],
['allocation_5fflag_5fwithin_5fbudget_11',['ALLOCATION_FLAG_WITHIN_BUDGET',['../namespace_d3_d12_m_a.html#abbad31a7e0b3d09d77f3fb704b77645eab374417c1f22a833ead268a6c21424e6',1,'D3D12MA']]],
['allocator_5fflag_5falways_5fcommitted_12',['ALLOCATOR_FLAG_ALWAYS_COMMITTED',['../namespace_d3_d12_m_a.html#ad5ae5a5e42b878f2e18ab5d1fbfb9916a068863dc0538ff4ea153b046b31e94fb',1,'D3D12MA']]],
- ['allocator_5fflag_5fnone_13',['ALLOCATOR_FLAG_NONE',['../namespace_d3_d12_m_a.html#ad5ae5a5e42b878f2e18ab5d1fbfb9916a2fb30967b492c27823a80b5de3aea26f',1,'D3D12MA']]],
- ['allocator_5fflag_5fsinglethreaded_14',['ALLOCATOR_FLAG_SINGLETHREADED',['../namespace_d3_d12_m_a.html#ad5ae5a5e42b878f2e18ab5d1fbfb9916a1b06bb21df006f76a9ed1bc41838bc52',1,'D3D12MA']]]
+ ['allocator_5fflag_5fdefault_5fpools_5fnot_5fzeroed_13',['ALLOCATOR_FLAG_DEFAULT_POOLS_NOT_ZEROED',['../namespace_d3_d12_m_a.html#ad5ae5a5e42b878f2e18ab5d1fbfb9916ae7dc7ab9168148281ebfe1586f554335',1,'D3D12MA']]],
+ ['allocator_5fflag_5fnone_14',['ALLOCATOR_FLAG_NONE',['../namespace_d3_d12_m_a.html#ad5ae5a5e42b878f2e18ab5d1fbfb9916a2fb30967b492c27823a80b5de3aea26f',1,'D3D12MA']]],
+ ['allocator_5fflag_5fsinglethreaded_15',['ALLOCATOR_FLAG_SINGLETHREADED',['../namespace_d3_d12_m_a.html#ad5ae5a5e42b878f2e18ab5d1fbfb9916a1b06bb21df006f76a9ed1bc41838bc52',1,'D3D12MA']]]
];
diff --git a/docs/html/virtual_allocator.html b/docs/html/virtual_allocator.html
index 7a25e3c..f3c4a59 100644
--- a/docs/html/virtual_allocator.html
+++ b/docs/html/virtual_allocator.html
@@ -83,10 +83,10 @@ Creating virtual block
-
Represents pure allocation algorithm and a data structure with allocations in some memory block,...
Definition: D3D12MemAlloc.h:1389
+
Represents pure allocation algorithm and a data structure with allocations in some memory block,...
Definition: D3D12MemAlloc.h:1405
D3D12MA_API HRESULT CreateVirtualBlock(const VIRTUAL_BLOCK_DESC *pDesc, VirtualBlock **ppVirtualBlock)
Creates new D3D12MA::VirtualBlock object and returns it through ppVirtualBlock.
-
Parameters of created D3D12MA::VirtualBlock object to be passed to CreateVirtualBlock().
Definition: D3D12MemAlloc.h:1295
-
UINT64 Size
Total size of the block.
Definition: D3D12MemAlloc.h:1303
+
Parameters of created D3D12MA::VirtualBlock object to be passed to CreateVirtualBlock().
Definition: D3D12MemAlloc.h:1311
+
UINT64 Size
Total size of the block.
Definition: D3D12MemAlloc.h:1319
Making virtual allocations
D3D12MA::VirtualBlock object contains internal data structure that keeps track of free and occupied regions using the same code as the main D3D12 memory allocator. A single allocation is identified by a lightweight structure D3D12MA::VirtualAllocation. You will also likely want to know the offset at which the allocation was made in the block.
@@ -111,8 +111,8 @@ Making virtual allocations
}
HRESULT Allocate(const VIRTUAL_ALLOCATION_DESC *pDesc, VirtualAllocation *pAllocation, UINT64 *pOffset)
Creates new allocation.
-Parameters of created virtual allocation to be passed to VirtualBlock::Allocate().
Definition: D3D12MemAlloc.h:1340
-UINT64 Size
Size of the allocation.
Definition: D3D12MemAlloc.h:1347
+Parameters of created virtual allocation to be passed to VirtualBlock::Allocate().
Definition: D3D12MemAlloc.h:1356
+UINT64 Size
Size of the allocation.
Definition: D3D12MemAlloc.h:1363
Represents single memory allocation done inside VirtualBlock.
Definition: D3D12MemAlloc.h:444
Deallocation
@@ -150,7 +150,7 @@ Alignment and units
UINT64 allocOffset;
hr = block->
Allocate(&allocDesc, &alloc, &allocOffset);
-UINT64 Alignment
Required alignment of the allocation.
Definition: D3D12MemAlloc.h:1352
+UINT64 Alignment
Required alignment of the allocation.
Definition: D3D12MemAlloc.h:1368
Alignments of different allocations made from one block may vary. However, if all alignments and sizes are always multiply of some size e.g. 4 B or sizeof(MyDataStruct)
, you can express all sizes, alignments, and offsets in multiples of that size instead of individual bytes. It might be more convenient, but you need to make sure to use this new unit consistently in all the places:
- D3D12MA::VIRTUAL_BLOCK_DESC::Size
diff --git a/include/D3D12MemAlloc.h b/include/D3D12MemAlloc.h
index 806636d..12eddb3 100644
--- a/include/D3D12MemAlloc.h
+++ b/include/D3D12MemAlloc.h
@@ -993,6 +993,22 @@ enum ALLOCATOR_FLAGS
To be used for debugging purposes.
*/
ALLOCATOR_FLAG_ALWAYS_COMMITTED = 0x2,
+
+ /**
+ Heaps created for the default pools will be created with flag `D3D12_HEAP_FLAG_CREATE_NOT_ZEROED`,
+ allowing for their memory to be not zeroed by the system if possible,
+ which can speed up allocation.
+
+ Only affects default pools.
+ To use the flag with @ref custom_pools, you need to add it manually:
+
+ \code
+ poolDesc.heapFlags |= D3D12_HEAP_FLAG_CREATE_NOT_ZEROED;
+ \endcode
+
+ Only avaiable if `ID3D12Device8` is present. Otherwise, the flag is ignored.
+ */
+ ALLOCATOR_FLAG_DEFAULT_POOLS_NOT_ZEROED = 0x4,
};
/// \brief Parameters of created Allocator object. To be used with CreateAllocator().
diff --git a/src/D3D12MemAlloc.cpp b/src/D3D12MemAlloc.cpp
index 070788d..736d46f 100644
--- a/src/D3D12MemAlloc.cpp
+++ b/src/D3D12MemAlloc.cpp
@@ -6583,6 +6583,11 @@ HRESULT AllocatorPimpl::Init(const ALLOCATOR_DESC& desc)
D3D12_HEAP_FLAGS heapFlags;
CalcDefaultPoolParams(heapProps.Type, heapFlags, i);
+#ifdef __ID3D12Device8_INTERFACE_DEFINED__
+ if (desc.Flags & ALLOCATOR_FLAG_DEFAULT_POOLS_NOT_ZEROED)
+ heapFlags |= D3D12_HEAP_FLAG_CREATE_NOT_ZEROED;
+#endif
+
m_BlockVectors[i] = D3D12MA_NEW(GetAllocs(), BlockVector)(
this, // hAllocator
heapProps, // heapType
diff --git a/src/D3D12Sample.cpp b/src/D3D12Sample.cpp
index 22643ca..ee4a877 100644
--- a/src/D3D12Sample.cpp
+++ b/src/D3D12Sample.cpp
@@ -58,7 +58,7 @@ static const D3D_FEATURE_LEVEL MY_D3D_FEATURE_LEVEL = D3D_FEATURE_LEVEL_12_0;
static const bool ENABLE_DEBUG_LAYER = true;
static const bool ENABLE_CPU_ALLOCATION_CALLBACKS = true;
static const bool ENABLE_CPU_ALLOCATION_CALLBACKS_PRINT = false;
-static constexpr D3D12MA::ALLOCATOR_FLAGS g_AllocatorFlags = D3D12MA::ALLOCATOR_FLAG_NONE;
+static constexpr D3D12MA::ALLOCATOR_FLAGS g_AllocatorFlags = D3D12MA::ALLOCATOR_FLAG_DEFAULT_POOLS_NOT_ZEROED;
static D3D12MA::ALLOCATION_CALLBACKS g_AllocationCallbacks = {}; // Used only when ENABLE_CPU_ALLOCATION_CALLBACKS
static HINSTANCE g_Instance;