Open 3D Engine Atom Gem API Reference  24.09
O3DE is an open-source, fully-featured, high-fidelity, modular 3D engine for building games and simulations, available to every industry.
D3D12MA::VirtualBlock Class Reference

Represents pure allocation algorithm and a data structure with allocations in some memory block, without actually allocating any GPU memory. More...

#include <D3D12MemAlloc.h>

Inherits IUnknownImpl.

Public Member Functions

BOOL IsEmpty () const
 Returns true if the block is empty - contains 0 allocations.
 
void GetAllocationInfo (VirtualAllocation allocation, VIRTUAL_ALLOCATION_INFO *pInfo) const
 Returns information about an allocation - its offset, size and custom pointer.
 
HRESULT Allocate (const VIRTUAL_ALLOCATION_DESC *pDesc, VirtualAllocation *pAllocation, UINT64 *pOffset)
 Creates new allocation. More...
 
void FreeAllocation (VirtualAllocation allocation)
 Frees the allocation. More...
 
void Clear ()
 Frees all the allocations.
 
void SetAllocationPrivateData (VirtualAllocation allocation, void *pPrivateData)
 Changes custom pointer for an allocation to a new value.
 
void GetStatistics (Statistics *pStats) const
 Retrieves basic statistics of the virtual block that are fast to calculate. More...
 
void CalculateStatistics (DetailedStatistics *pStats) const
 Retrieves detailed statistics of the virtual block that are slower to calculate. More...
 
void BuildStatsString (WCHAR **ppStatsString) const
 Builds and returns statistics as a string in JSON format, including the list of allocations with their parameters. More...
 
void FreeStatsString (WCHAR *pStatsString) const
 Frees memory of a string returned from VirtualBlock::BuildStatsString.
 

Protected Member Functions

void ReleaseThis () override
 

Friends

D3D12MA_API HRESULT CreateVirtualBlock (const VIRTUAL_BLOCK_DESC *, VirtualBlock **)
 Creates new D3D12MA::VirtualBlock object and returns it through ppVirtualBlock. More...
 
template<typename T >
void D3D12MA_DELETE (const ALLOCATION_CALLBACKS &, T *)
 

Detailed Description

Represents pure allocation algorithm and a data structure with allocations in some memory block, without actually allocating any GPU memory.

This class allows to use the core algorithm of the library custom allocations e.g. CPU memory or sub-allocation regions inside a single GPU buffer.

To create this object, fill in D3D12MA::VIRTUAL_BLOCK_DESC and call CreateVirtualBlock(). To destroy it, call its method VirtualBlock::Release(). You need to free all the allocations within this block or call Clear() before destroying it.

This object is not thread-safe - should not be used from multiple threads simultaneously, must be synchronized externally.

Member Function Documentation

◆ Allocate()

HRESULT D3D12MA::VirtualBlock::Allocate ( const VIRTUAL_ALLOCATION_DESC pDesc,
VirtualAllocation pAllocation,
UINT64 *  pOffset 
)

Creates new allocation.

Parameters
pDesc
[out]pAllocationUnique indentifier of the new allocation within single block.
[out]pOffsetReturned offset of the new allocation. Optional, can be null.
Returns
S_OK if allocation succeeded, E_OUTOFMEMORY if it failed.

If the allocation failed, pAllocation->AllocHandle is set to 0 and pOffset, if not null, is set to UINT64_MAX.

◆ BuildStatsString()

void D3D12MA::VirtualBlock::BuildStatsString ( WCHAR **  ppStatsString) const

Builds and returns statistics as a string in JSON format, including the list of allocations with their parameters.

Parameters
[out]ppStatsStringMust be freed using VirtualBlock::FreeStatsString.

◆ CalculateStatistics()

void D3D12MA::VirtualBlock::CalculateStatistics ( DetailedStatistics pStats) const

Retrieves detailed statistics of the virtual block that are slower to calculate.

Parameters
[out]pStatsStatistics of the virtual block.

◆ FreeAllocation()

void D3D12MA::VirtualBlock::FreeAllocation ( VirtualAllocation  allocation)

Frees the allocation.

Calling this function with allocation.AllocHandle == 0 is correct and does nothing.

◆ GetStatistics()

void D3D12MA::VirtualBlock::GetStatistics ( Statistics pStats) const

Retrieves basic statistics of the virtual block that are fast to calculate.

Parameters
[out]pStatsStatistics of the virtual block.

Friends And Related Function Documentation

◆ CreateVirtualBlock

D3D12MA_API HRESULT CreateVirtualBlock ( const VIRTUAL_BLOCK_DESC ,
VirtualBlock **   
)
friend

Creates new D3D12MA::VirtualBlock object and returns it through ppVirtualBlock.

Note you don't need to create D3D12MA::Allocator to use virtual blocks.


The documentation for this class was generated from the following file: