diff --git a/CHANGELOG.md b/CHANGELOG.md index 21c20af..e188f0c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,14 @@ -# 1.0.0 (2019-09-02) +# 2.0.0 (2022-03-25) + +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. + +# 1.0.0 (2019-09-02) First published version. diff --git a/bin/D3D12Sample_Release_vs2019.exe b/bin/D3D12Sample_Release_vs2019.exe index 5b0b991..a515894 100644 Binary files a/bin/D3D12Sample_Release_vs2019.exe and b/bin/D3D12Sample_Release_vs2019.exe differ diff --git a/docs/html/_d3_d12_mem_alloc_8h.html b/docs/html/_d3_d12_mem_alloc_8h.html index 9492ee2..975b912 100644 --- a/docs/html/_d3_d12_mem_alloc_8h.html +++ b/docs/html/_d3_d12_mem_alloc_8h.html @@ -205,14 +205,19 @@ Enumerations   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_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 +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 +
}  Bit flags to be used with ALLOCATOR_DESC::Flags. More...
  diff --git a/docs/html/configuration.html b/docs/html/configuration.html index a914bfc..c9a759a 100644 --- a/docs/html/configuration.html +++ b/docs/html/configuration.html @@ -101,15 +101,15 @@ Custom CPU memory allocator
D3D12MA::Allocator* allocator;
HRESULT hr = D3D12MA::CreateAllocator(&allocatorDesc, &allocator);
-
D3D12MA::Allocator
Represents main object of this library initialized for particular ID3D12Device.
Definition: D3D12MemAlloc.h:1055
+
D3D12MA::Allocator
Represents main object of this library initialized for particular ID3D12Device.
Definition: D3D12MemAlloc.h:1067
D3D12MA::CreateAllocator
D3D12MA_API HRESULT CreateAllocator(const ALLOCATOR_DESC *pDesc, Allocator **ppAllocator)
Creates new main D3D12MA::Allocator object and returns it through ppAllocator.
D3D12MA::ALLOCATION_CALLBACKS
Custom callbacks to CPU memory allocation functions.
Definition: D3D12MemAlloc.h:187
D3D12MA::ALLOCATION_CALLBACKS::pFree
FREE_FUNC_PTR pFree
Dellocation function.
Definition: D3D12MemAlloc.h:191
D3D12MA::ALLOCATION_CALLBACKS::pAllocate
ALLOCATE_FUNC_PTR pAllocate
Allocation function.
Definition: D3D12MemAlloc.h:189
-
D3D12MA::ALLOCATOR_DESC
Parameters of created Allocator object. To be used with CreateAllocator().
Definition: D3D12MemAlloc.h:1016
-
D3D12MA::ALLOCATOR_DESC::pAllocationCallbacks
const ALLOCATION_CALLBACKS * pAllocationCallbacks
Custom CPU memory allocation callbacks. Optional.
Definition: D3D12MemAlloc.h:1036
-
D3D12MA::ALLOCATOR_DESC::pAdapter
IDXGIAdapter * pAdapter
Definition: D3D12MemAlloc.h:1042
-
D3D12MA::ALLOCATOR_DESC::pDevice
ID3D12Device * pDevice
Definition: D3D12MemAlloc.h:1024
+
D3D12MA::ALLOCATOR_DESC
Parameters of created Allocator object. To be used with CreateAllocator().
Definition: D3D12MemAlloc.h:1028
+
D3D12MA::ALLOCATOR_DESC::pAllocationCallbacks
const ALLOCATION_CALLBACKS * pAllocationCallbacks
Custom CPU memory allocation callbacks. Optional.
Definition: D3D12MemAlloc.h:1048
+
D3D12MA::ALLOCATOR_DESC::pAdapter
IDXGIAdapter * pAdapter
Definition: D3D12MemAlloc.h:1054
+
D3D12MA::ALLOCATOR_DESC::pDevice
ID3D12Device * pDevice
Definition: D3D12MemAlloc.h:1036

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/defragmentation.html b/docs/html/defragmentation.html index 2855492..1909bf0 100644 --- a/docs/html/defragmentation.html +++ b/docs/html/defragmentation.html @@ -127,19 +127,19 @@ $(function() {
defragCtx->Release();
D3D12MA::Allocation::SetResource
void SetResource(ID3D12Resource *pResource)
Releases the resource currently pointed by the allocation (if any), sets it to new one,...
D3D12MA::Allocation::GetOffset
UINT64 GetOffset() const
Returns offset in bytes from the start of memory heap.
-
D3D12MA::Allocation::GetResource
ID3D12Resource * GetResource() const
Returns D3D12 resource associated with this object.
Definition: D3D12MemAlloc.h:493
+
D3D12MA::Allocation::GetResource
ID3D12Resource * GetResource() const
Returns D3D12 resource associated with this object.
Definition: D3D12MemAlloc.h:490
D3D12MA::Allocation::GetHeap
ID3D12Heap * GetHeap() const
Returns memory heap that the resource is created in.
-
D3D12MA::DefragmentationContext
Represents defragmentation process in progress.
Definition: D3D12MemAlloc.h:773
+
D3D12MA::DefragmentationContext
Represents defragmentation process in progress.
Definition: D3D12MemAlloc.h:769
D3D12MA::DefragmentationContext::BeginPass
HRESULT BeginPass(DEFRAGMENTATION_PASS_MOVE_INFO *pPassInfo)
Starts single defragmentation pass.
D3D12MA::DefragmentationContext::EndPass
HRESULT EndPass(DEFRAGMENTATION_PASS_MOVE_INFO *pPassInfo)
Ends single defragmentation pass.
-
D3D12MA::DEFRAGMENTATION_FLAG_ALGORITHM_FAST
@ DEFRAGMENTATION_FLAG_ALGORITHM_FAST
Definition: D3D12MemAlloc.h:653
-
D3D12MA::DEFRAGMENTATION_DESC
Parameters for defragmentation.
Definition: D3D12MemAlloc.h:675
-
D3D12MA::DEFRAGMENTATION_DESC::Flags
DEFRAGMENTATION_FLAGS Flags
Flags.
Definition: D3D12MemAlloc.h:677
-
D3D12MA::DEFRAGMENTATION_MOVE::pSrcAllocation
Allocation * pSrcAllocation
Allocation that should be moved.
Definition: D3D12MemAlloc.h:711
-
D3D12MA::DEFRAGMENTATION_MOVE::pDstTmpAllocation
Allocation * pDstTmpAllocation
Temporary allocation pointing to destination memory that will replace pSrcAllocation.
Definition: D3D12MemAlloc.h:719
-
D3D12MA::DEFRAGMENTATION_PASS_MOVE_INFO
Parameters for incremental defragmentation steps.
Definition: D3D12MemAlloc.h:727
-
D3D12MA::DEFRAGMENTATION_PASS_MOVE_INFO::pMoves
DEFRAGMENTATION_MOVE * pMoves
Array of moves to be performed by the user in the current defragmentation pass.
Definition: D3D12MemAlloc.h:751
-
D3D12MA::DEFRAGMENTATION_PASS_MOVE_INFO::MoveCount
UINT32 MoveCount
Number of elements in the pMoves array.
Definition: D3D12MemAlloc.h:729
+
D3D12MA::DEFRAGMENTATION_FLAG_ALGORITHM_FAST
@ DEFRAGMENTATION_FLAG_ALGORITHM_FAST
Definition: D3D12MemAlloc.h:649
+
D3D12MA::DEFRAGMENTATION_DESC
Parameters for defragmentation.
Definition: D3D12MemAlloc.h:671
+
D3D12MA::DEFRAGMENTATION_DESC::Flags
DEFRAGMENTATION_FLAGS Flags
Flags.
Definition: D3D12MemAlloc.h:673
+
D3D12MA::DEFRAGMENTATION_MOVE::pSrcAllocation
Allocation * pSrcAllocation
Allocation that should be moved.
Definition: D3D12MemAlloc.h:707
+
D3D12MA::DEFRAGMENTATION_MOVE::pDstTmpAllocation
Allocation * pDstTmpAllocation
Temporary allocation pointing to destination memory that will replace pSrcAllocation.
Definition: D3D12MemAlloc.h:715
+
D3D12MA::DEFRAGMENTATION_PASS_MOVE_INFO
Parameters for incremental defragmentation steps.
Definition: D3D12MemAlloc.h:723
+
D3D12MA::DEFRAGMENTATION_PASS_MOVE_INFO::pMoves
DEFRAGMENTATION_MOVE * pMoves
Array of moves to be performed by the user in the current defragmentation pass.
Definition: D3D12MemAlloc.h:747
+
D3D12MA::DEFRAGMENTATION_PASS_MOVE_INFO::MoveCount
UINT32 MoveCount
Number of elements in the pMoves array.
Definition: D3D12MemAlloc.h:725

Although functions like D3D12MA::Allocator::CreateResource() create an allocation and a buffer/texture at once, these are just a shortcut for allocating memory and creating a placed resource. Defragmentation works on memory allocations only. You must handle the rest manually. Defragmentation is an iterative process that should repreat "passes" as long as related functions return S_FALSE not S_OK. In each pass:

  1. D3D12MA::DefragmentationContext::BeginPass() function call: @@ -98,6 +99,7 @@ $(function() {

    - p -

    diff --git a/docs/html/namespacemembers_vars.html b/docs/html/namespacemembers_vars.html deleted file mode 100644 index b789fa4..0000000 --- a/docs/html/namespacemembers_vars.html +++ /dev/null @@ -1,74 +0,0 @@ - - - - - - - -Direct3D 12 Memory Allocator: Namespace Members - - - - - - - - - -
    -
    - - - - - - -
    -
    Direct3D 12 Memory Allocator -
    -
    -
    - - - - - - - -
    - -
    -
    - - -
    - -
    - -
    -
    - - - - diff --git a/docs/html/quick_start.html b/docs/html/quick_start.html index 6aec9de..e9a2ce8 100644 --- a/docs/html/quick_start.html +++ b/docs/html/quick_start.html @@ -90,11 +90,11 @@ Project setup and initialization
    D3D12MA::Allocator* allocator;
    HRESULT hr = D3D12MA::CreateAllocator(&allocatorDesc, &allocator);
    -
    Represents main object of this library initialized for particular ID3D12Device.
    Definition: D3D12MemAlloc.h:1055
    +
    Represents main object of this library initialized for particular ID3D12Device.
    Definition: D3D12MemAlloc.h:1067
    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:1016
    -
    IDXGIAdapter * pAdapter
    Definition: D3D12MemAlloc.h:1042
    -
    ID3D12Device * pDevice
    Definition: D3D12MemAlloc.h:1024
    +
    Parameters of created Allocator object. To be used with CreateAllocator().
    Definition: D3D12MemAlloc.h:1028
    +
    IDXGIAdapter * pAdapter
    Definition: D3D12MemAlloc.h:1054
    +
    ID3D12Device * pDevice
    Definition: D3D12MemAlloc.h:1036

    (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();
    @@ -128,10 +128,10 @@ Creating resources
    NULL,
    &allocation,
    IID_PPV_ARGS(&resource));
    -
    Represents single memory allocation.
    Definition: D3D12MemAlloc.h:464
    +
    Represents single memory allocation.
    Definition: D3D12MemAlloc.h:461
    HRESULT CreateResource(const ALLOCATION_DESC *pAllocDesc, const D3D12_RESOURCE_DESC *pResourceDesc, D3D12_RESOURCE_STATES InitialResourceState, const D3D12_CLEAR_VALUE *pOptimizedClearValue, Allocation **ppAllocation, REFIID riidResource, void **ppvResource)
    Allocates memory and creates a D3D12 resource (buffer or texture). This is the main allocation functi...
    -
    Parameters of created D3D12MA::Allocation object. To be used with Allocator::CreateResource.
    Definition: D3D12MemAlloc.h:280
    -
    D3D12_HEAP_TYPE HeapType
    The type of memory heap where the new allocation should be placed.
    Definition: D3D12MemAlloc.h:289
    +
    Parameters of created D3D12MA::Allocation object. To be used with Allocator::CreateResource.
    Definition: D3D12MemAlloc.h:277
    +
    D3D12_HEAP_TYPE HeapType
    The type of memory heap where the new allocation should be placed.
    Definition: D3D12MemAlloc.h:286

    You need to remember both resource and allocation objects and destroy them separately when no longer needed.

    allocation->Release();
    resource->Release();
    diff --git a/docs/html/resource_aliasing.html b/docs/html/resource_aliasing.html index 9a30e55..9b6d9ec 100644 --- a/docs/html/resource_aliasing.html +++ b/docs/html/resource_aliasing.html @@ -144,11 +144,11 @@ $(function() {
    res2->Release();
    res1->Release();
    alloc->Release();
    -
    Represents single memory allocation.
    Definition: D3D12MemAlloc.h:464
    +
    Represents single memory allocation.
    Definition: D3D12MemAlloc.h:461
    ID3D12Heap * GetHeap() const
    Returns memory heap that the resource is created in.
    -
    Parameters of created D3D12MA::Allocation object. To be used with Allocator::CreateResource.
    Definition: D3D12MemAlloc.h:280
    -
    D3D12_HEAP_FLAGS ExtraHeapFlags
    Additional heap flags to be used when allocating memory.
    Definition: D3D12MemAlloc.h:305
    -
    D3D12_HEAP_TYPE HeapType
    The type of memory heap where the new allocation should be placed.
    Definition: D3D12MemAlloc.h:289
    +
    Parameters of created D3D12MA::Allocation object. To be used with Allocator::CreateResource.
    Definition: D3D12MemAlloc.h:277
    +
    D3D12_HEAP_FLAGS ExtraHeapFlags
    Additional heap flags to be used when allocating memory.
    Definition: D3D12MemAlloc.h:302
    +
    D3D12_HEAP_TYPE HeapType
    The type of memory heap where the new allocation should be placed.
    Definition: D3D12MemAlloc.h:286

    Remember that using resouces that alias in memory requires proper synchronization. You need to issue a special barrier of type D3D12_RESOURCE_BARRIER_TYPE_ALIASING. You also need to treat a resource after aliasing as uninitialized - containing garbage data. For example, if you use res1 and then want to use res2, you need to first initialize res2 using either Clear, Discard, or Copy to the entire resource.

    Additional considerations: