GPGMM
GPGMM, a General-Purpose GPU Memory Management Library
Loading...
Searching...
No Matches
Classes | Typedefs | Enumerations | Functions | Variables
gpgmm::d3d12 Namespace Reference

Classes

struct  FEATURE_DATA_RESOURCE_ALLOCATION_SUPPORT
 
struct  RECORD_OPTIONS
 
struct  RESIDENCY_HEAP_DESC
 
struct  RESIDENCY_HEAP_INFO
 
struct  RESIDENCY_MANAGER_DESC
 
struct  RESIDENCY_MANAGER_STATS
 
struct  RESOURCE_ALLOCATION_DESC
 
struct  RESOURCE_ALLOCATION_INFO
 
struct  RESOURCE_ALLOCATOR_DESC
 
struct  RESOURCE_ALLOCATOR_STATS
 

Typedefs

using CreateHeapFn = HRESULT (*)(void* pCreateHeapContext, ID3D12Pageable** ppPageableOut)
 Callback function used to create a ID3D12Pageable.
 

Enumerations

enum  RESIDENCY_HEAP_STATUS { RESIDENCY_HEAP_STATUS_UNKNOWN = 0 , RESIDENCY_HEAP_STATUS_EVICTED = 1 , RESIDENCY_HEAP_STATUS_RESIDENT = 2 }
 
enum  RESIDENCY_HEAP_FLAGS { RESIDENCY_HEAP_FLAG_NONE = 0x0 , RESIDENCY_HEAP_FLAG_CREATE_IN_BUDGET = 0x1 , RESIDENCY_HEAP_FLAG_CREATE_RESIDENT = 0x2 , RESIDENCY_HEAP_FLAG_CREATE_LOCKED = 0x4 }
 
enum  RECORD_FLAGS {
  RECORD_FLAG_NONE = 0x0 , RECORD_FLAG_API_OBJECTS = 0x1 , RECORD_FLAG_API_CALLS = 0x2 , RECORD_FLAG_API_TIMINGS = 0x4 ,
  RECORD_FLAG_COUNTERS = 0x8 , RECORD_FLAG_CAPTURE = 0x3 , RECORD_FLAG_ALL = 0xFF
}
 
enum  RECORD_SCOPE { RECORD_SCOPE_PER_PROCESS = 0 , RECORD_SCOPE_PER_INSTANCE = 1 }
 
enum  RESIDENCY_MANAGER_FLAGS { RESIDENCY_MANAGER_FLAG_NONE = 0x0 , RESIDENCY_MANAGER_FLAG_ALLOW_BACKGROUND_BUDGET_UPDATES = 0x1 , RESIDENCY_MANAGER_FLAG_NEVER_USE_UNIFIED_MEMORY = 0x2 , RESIDENCY_MANAGER_FLAG_ALWAYS_IN_BUDGET = 0x4 }
 
enum  RESOURCE_ALLOCATION_TYPE { RESOURCE_ALLOCATION_TYPE_UNKNOWN = 0 , RESOURCE_ALLOCATION_TYPE_STANDALONE = 1 , RESOURCE_ALLOCATION_TYPE_SUBALLOCATED = 2 , RESOURCE_ALLOCATION_TYPE_SUBALLOCATED_WITHIN = 3 }
 
enum  RESOURCE_ALLOCATOR_FLAGS {
  RESOURCE_ALLOCATOR_FLAG_NONE = 0x0 , RESOURCE_ALLOCATOR_FLAG_ALWAYS_COMMITTED = 0x1 , RESOURCE_ALLOCATOR_FLAG_ALWAYS_IN_BUDGET = 0x2 , RESOURCE_ALLOCATOR_FLAG_ALLOW_PREFETCH = 0x4 ,
  RESOURCE_ALLOCATOR_FLAG_ALWAYS_ON_DEMAND = 0x8 , RESOURCE_ALLOCATOR_FLAG_ALLOW_UNIFIED_MEMORY = 0x10 , RESOURCE_ALLOCATOR_FLAG_NEVER_LEAK = 0x20 , RESOURCE_ALLOCATOR_FLAG_CREATE_NOT_RESIDENT = 0x40 ,
  RESOURCE_ALLOCATOR_FLAG_NEVER_OVER_ALLOCATE = 0x80
}
 
enum  RESOURCE_ALLOCATION_ALGORITHM {
  RESOURCE_ALLOCATION_ALGORITHM_DEFAULT = 0 , RESOURCE_ALLOCATION_ALGORITHM_SLAB = 1 , RESOURCE_ALLOCATION_ALGORITHM_BUDDY_SYSTEM = 2 , RESOURCE_ALLOCATION_ALGORITHM_FIXED_POOL = 3 ,
  RESOURCE_ALLOCATION_ALGORITHM_SEGMENTED_POOL = 4 , RESOURCE_ALLOCATION_ALGORITHM_DEDICATED = 5
}
 
enum  RESOURCE_ALLOCATION_FLAGS {
  RESOURCE_ALLOCATION_FLAG_NONE = 0x0 , RESOURCE_ALLOCATION_FLAG_NEVER_ALLOCATE_HEAP = 0x1 , RESOURCE_ALLOCATION_FLAG_ALLOW_SUBALLOCATE_WITHIN_RESOURCE = 0x2 , RESOURCE_ALLOCATION_FLAG_NEVER_SUBALLOCATE_HEAP = 0x4 ,
  RESOURCE_ALLOCATION_FLAG_ALWAYS_PREFETCH_HEAP = 0x8 , RESOURCE_ALLOCATION_FLAG_ALWAYS_CACHE_SIZE = 0x10 , RESOURCE_ALLOCATION_FLAG_ALWAYS_ATTRIBUTE_HEAPS = 0x20 , RESOURCE_ALLOCATION_FLAG_NEVER_FALLBACK = 0x40 ,
  RESOURCE_ALLOCATION_FLAG_NEVER_RESIDENT = 0x80 , RESOURCE_ALLOCATION_FLAG_ALWAYS_WARN_ON_ALIGNMENT_MISMATCH = 0x100 , RESOURCE_ALLOCATION_FLAG_ALWAYS_COMMITTED = 0x200
}
 
enum  RESOURCE_ALLOCATOR_FEATURE { RESOURCE_ALLOCATOR_FEATURE_RESOURCE_ALLOCATION_SUPPORT }
 

Functions

virtual HRESULT SetDebugName (LPCWSTR Name)=0
 Associate a debug name.
 
virtual HRESULT Lock ()=0
 Locks the specified heap.
 
virtual HRESULT Unlock ()=0
 Unlocks the specified heap.
 
virtual HRESULT GetResidencyManager (IResidencyManager **ppResidencyManagerOut) const =0
 Get the residency manager that manages this heap.
 
GPGMM_EXPORT HRESULT CreateResidencyHeap (const RESIDENCY_HEAP_DESC &descriptor, IResidencyManager *const pResidencyManager, CreateHeapFn createHeapFn, void *pCreateHeapContext, IResidencyHeap **ppResidencyHeapOut)
 Create a residency managed heap.
 
GPGMM_EXPORT HRESULT CreateResidencyHeap (const RESIDENCY_HEAP_DESC &descriptor, IResidencyManager *const pResidencyManager, ID3D12Pageable *pPageable, IResidencyHeap **ppResidencyHeapOut)
 Create a residency managed heap.
 
virtual HRESULT Reset ()=0
 Resets list to its initial state as if a new list was created.
 
GPGMM_EXPORT HRESULT CreateResidencyList (IResidencyList **ppResidencyListOut)
 Create a residency list or collection of heaps to manage together for residency.
 
virtual HRESULT SetVideoMemoryReservation (const DXGI_MEMORY_SEGMENT_GROUP &heapSegment, UINT64 availableForReservation, UINT64 *pCurrentReservationOut=nullptr)=0
 Sets video memory reservation.
 
virtual HRESULT QueryVideoMemoryInfo (const DXGI_MEMORY_SEGMENT_GROUP &heapSegment, DXGI_QUERY_VIDEO_MEMORY_INFO *pVideoMemoryInfoOut)=0
 Get the current budget and memory usage.
 
virtual HRESULT SetResidencyStatus (IResidencyHeap *pHeap, const RESIDENCY_HEAP_STATUS &newStatus)=0
 Update the residency status of a heap.
 
virtual HRESULT QueryStats (RESIDENCY_MANAGER_STATS *pResidencyManagerStats)=0
 Query the current residency usage.
 
GPGMM_EXPORT HRESULT CreateResidencyManager (const RESIDENCY_MANAGER_DESC &descriptor, ID3D12Device *pDevice, IDXGIAdapter3 *pAdapter, IResidencyManager **ppResidencyManagerOut)
 Create residency residency manager to manage video memory.
 
virtual void Unmap (UINT subresource, const D3D12_RANGE *pWrittenRange)=0
 Unmaps the resource allocation.
 
virtual ID3D12Resource * GetResource () const =0
 Returns the resource owned by this allocation.
 
virtual D3D12_GPU_VIRTUAL_ADDRESS GetGPUVirtualAddress () const =0
 Returns the GPU virtual address of the resource allocation.
 
virtual UINT64 GetOffsetFromResource () const =0
 Returns the start of the allocation in the resource.
 
virtual RESOURCE_ALLOCATION_INFO GetInfo () const =0
 Returns information about this resource allocation.
 
virtual IResidencyHeapGetMemory () const =0
 Returns the heap assigned to this resource allocation.
 
virtual HRESULT GetResourceAllocator (IResourceAllocator **ppResourceAllocatorOut) const =0
 Get the resource allocator that created the resource for this allocation.
 
virtual HRESULT CreateResource (const RESOURCE_ALLOCATION_DESC &allocationDescriptor, ID3D12Resource *pCommittedResource, IResourceAllocation **ppResourceAllocationOut)=0
 Use existing ID3D12Resource as a resource allocation.
 
virtual HRESULT ReleaseResourceHeaps (UINT64 bytesToRelease, UINT64 *pBytesReleased)=0
 Return free memory back to the OS.
 
virtual HRESULT QueryStats (RESOURCE_ALLOCATOR_STATS *pResourceAllocatorStats)=0
 Query the current allocator usage.
 
virtual HRESULT CheckFeatureSupport (RESOURCE_ALLOCATOR_FEATURE feature, void *pFeatureSupportData, UINT featureSupportDataSize) const =0
 Gets information about the features that are supported by the resource allocator.
 
GPGMM_EXPORT HRESULT CreateResourceAllocator (const RESOURCE_ALLOCATOR_DESC &allocatorDescriptor, ID3D12Device *pDevice, IDXGIAdapter *pAdapter, IResourceAllocator **ppResourceAllocatorOut, IResidencyManager **ppResidencyManagerOut)
 Create a resource allocator with residency.
 
GPGMM_EXPORT HRESULT CreateResourceAllocator (const RESOURCE_ALLOCATOR_DESC &allocatorDescriptor, ID3D12Device *pDevice, IDXGIAdapter *pAdapter, IResidencyManager *pResidencyManager, IResourceAllocator **ppResourceAllocatorOut)
 Create a resource allocator using a specified residency manager.
 
GPGMM_EXPORT HRESULT CreateResourceAllocator (const RESOURCE_ALLOCATOR_DESC &allocatorDescriptor, IResourceAllocator *pResourceAllocator, IResourceAllocator **ppResourceAllocatorOut)
 Create a resource allocator from an existing resource allocator.
 

Variables

GPGMM_INTERFACE IDebugObject
 Debug object associates additional information for D3D objects using SetPrivateData.
 
GPGMM_INTERFACE IResidencyManager
 ResidencyManager tracks and maintains one or more heaps within a residency cache.
 
GPGMM_INTERFACE IResidencyHeap
 IResidencyHeap represents a ID3D12Pageable object used for residency management.
 
GPGMM_INTERFACE IResidencyList
 Represents a list of heaps which will be "made resident" upon executing a command-list.
 
GPGMM_INTERFACE ID3D12CommandList *const * ppCommandLists
 
GPGMM_INTERFACE ID3D12CommandList *const IResidencyList *const * ppResidencyLists
 
GPGMM_INTERFACE ID3D12CommandList *const IResidencyList *const UINT count = 0
 
GPGMM_INTERFACE IResourceAllocator
 ResourceAllocator is an allocator that creates ID3D12Resources in a ResourceAllocation.
 
GPGMM_INTERFACE IResourceAllocation
 ResourceAllocation is an allocation that contains a ID3D12Resource.
 
GPGMM_INTERFACE const D3D12_RANGE * pReadRange
 
GPGMM_INTERFACE const D3D12_RANGE void ** ppDataOut = 0
 
GPGMM_INTERFACE const D3D12_RESOURCE_DESC & resourceDescriptor
 
GPGMM_INTERFACE const D3D12_RESOURCE_DESC D3D12_RESOURCE_STATES initialResourceState
 
GPGMM_INTERFACE const D3D12_RESOURCE_DESC D3D12_RESOURCE_STATES const D3D12_CLEAR_VALUE * pClearValue
 
GPGMM_INTERFACE const D3D12_RESOURCE_DESC D3D12_RESOURCE_STATES const D3D12_CLEAR_VALUE IResourceAllocation ** ppResourceAllocationOut = 0
 

Typedef Documentation

◆ CreateHeapFn

using gpgmm::d3d12::CreateHeapFn = HRESULT (*)(void* pCreateHeapContext, ID3D12Pageable** ppPageableOut)

Callback function used to create a ID3D12Pageable.

Enumeration Type Documentation

◆ RECORD_FLAGS

Represents different event categories to record.

Enumerator
RECORD_FLAG_NONE 

Record nothing.

RECORD_FLAG_API_OBJECTS 

Record lifetimes of API objects created by GPGMM.

RECORD_FLAG_API_CALLS 

Record API calls made to GPGMM.

RECORD_FLAG_API_TIMINGS 

Record duration of GPGMM API calls.

RECORD_FLAG_COUNTERS 

Record metrics made to GPGMM API calls.

RECORD_FLAG_CAPTURE 

Record events required for playback.

 Bitwise OR'd combination of kApiObjects and
 kApiCalls.
RECORD_FLAG_ALL 

Record everything.

◆ RECORD_SCOPE

Represents recording scopes to limit event recording.

Enumerator
RECORD_SCOPE_PER_PROCESS 

Scopes events per process (or multiple instances).

RECORD_SCOPE_PER_INSTANCE 

Scopes events per instance.

◆ RESIDENCY_HEAP_FLAGS

Specify creation options to configure the heap.

Enumerator
RESIDENCY_HEAP_FLAG_NONE 

Disables all option flags.

RESIDENCY_HEAP_FLAG_CREATE_IN_BUDGET 

Requires the heap to be created in budget.

This flags ensures there is enough budget to exist for the heap or E_OUTOFMEMORY.
RESIDENCY_HEAP_FLAG_CREATE_RESIDENT 

Requires the heap to be managed for residency.

This flag is equivalent to calling LockHeap then UnlockHeap after
creation. The flag only has effect when the heap's residency status
cannot be determined.
RESIDENCY_HEAP_FLAG_CREATE_LOCKED 

Creates a residency heap that is locked.

A locked heap cannot be evicted once made resident.

This flag is equivalent to calling LockHeap immediately after creation.

◆ RESIDENCY_HEAP_STATUS

Additional information about the heap residency status.

A heap is in one of three states: never made resident or unknown, about to become resident or evicted, and resident. When a heap gets paged-out, it transitions from being resident to evicted. Paged-in is the reverse of this, evicted to resident. If the heap was known to be created resident by D3D12, it will immediately become resident. If the heap becomes locked, it will stay resident until unlocked, then back to evicted.

Enumerator
RESIDENCY_HEAP_STATUS_UNKNOWN 

Residency status is not known.

Unknown heaps must become locked to be managed for residency.
RESIDENCY_HEAP_STATUS_EVICTED 

Heap was evicted or about to be made resident. Evicted heaps must be previously locked, resident, or D3D12_HEAP_FLAG_CREATE_NOT_RESIDENT.

RESIDENCY_HEAP_STATUS_RESIDENT 

Heap is resident. Locked heaps stay resident.

◆ RESIDENCY_MANAGER_FLAGS

Specify options to configure the residency manager.

Enumerator
RESIDENCY_MANAGER_FLAG_NONE 

Disables all option flags.

RESIDENCY_MANAGER_FLAG_ALLOW_BACKGROUND_BUDGET_UPDATES 

Allow background budget updates from OS notifications.

By default, budget updates will be queried by the residency manager
instead of pushed by OS notifications using a background thread.
RESIDENCY_MANAGER_FLAG_NEVER_USE_UNIFIED_MEMORY 

Specifies if unified memory architecture (UMA) is always disabled, even if the adapter supports UMA.

By default, UMA is enabled when the adapter supports the unified memory architecture. UMA allows the residency manager to budget using a single memory segment. Otherwise, the residency manager will have two budgets for local and non-local memory segments, respectively.

RESIDENCY_MANAGER_FLAG_ALWAYS_IN_BUDGET 

Requires heaps to be in budget or E_OUTOFMEMORY.

With this flag, heaps created for this residency manager will effectively never
specify D3D12_RESIDENCY_MANAGER_FLAG_DENY_OVERBUDGET.

◆ RESOURCE_ALLOCATION_ALGORITHM

Describes the algorithm used for allocation of resources.

Enumerator
RESOURCE_ALLOCATION_ALGORITHM_DEFAULT 

Default allocation mechanism.

Relies on internal heuristics to automatically determine the best allocation mechanism. The
selection of algorithm depends on:

1. The heap properties or flags specified by the user.
2. The size the resource being created.
3. The amount of available memory.

In general, the most efficient resource allocator will be attempted first (efficient
being defined as fastest service-time to allocate/deallocate with smallest memory
footprint), subject to other constraints. However, since it's impossible to predict all
future memory accesses, allocation techniques that rely on amortization of GPU heaps may not
prove to be faster as expected. Further experimentation is recommended.
RESOURCE_ALLOCATION_ALGORITHM_SLAB 

Slab allocation mechanism.

Slab allocation allocates/deallocates in O(1) time using O(N * pageSize) space.

Slab allocation does not suffer from internal fragmentation but could externally fragment
when many unique request sizes are used.
RESOURCE_ALLOCATION_ALGORITHM_BUDDY_SYSTEM 

Buddy system mechanism.

Buddy system allocate/deallocates in O(Log2) time using O(1) space.

Buddy system suffers from internal fragmentation (ie. resources are not a power-of-two) but
does not suffer from external fragmentation as much since the resource heap size does not
change.

It is recommend to specify a PreferredResourceHeapSize large enough such that multiple
requests can fit within the specified PreferredResourceHeapSize but not too large where
creating the larger resource heap becomes a bigger bottleneck.
RESOURCE_ALLOCATION_ALGORITHM_FIXED_POOL 

Recycles resource heaps using a single pool.

Fixed pools allocate/deallocate in O(1) time using O(N) space.

Fixed-size pool limits recycling to resource heaps equal to
PreferredResourceHeapSize. A PreferredResourceHeapSize of zero is effectively
equivalent to RESOURCE_ALLOCATOR_FLAG_ALWAYS_ON_DEMAND.
RESOURCE_ALLOCATION_ALGORITHM_SEGMENTED_POOL 

Recycles resource heaps of any size using one or more pools.

Segmented pool allocate/deallocates in O(Log2) time using O(N * K) space.
RESOURCE_ALLOCATION_ALGORITHM_DEDICATED 

Dedicate allocation resource heaps.

Creates resources with their own resource heap, never sub-allocated.
A dedicated allocation allocates exactly what is needed for the resource and nothing more.

Internally, dedicated allocations are "placed resources" which allows the heap to be
recycled. Otherwise, RESOURCE_ALLOCATOR_FLAG_ALWAYS_COMMITTED is equivalent to a
"dedicated allocation" but without recycling heaps.

Dedicated allocation allocates/deallocates in O(1) time using O(N * pageSize) space.

◆ RESOURCE_ALLOCATION_FLAGS

Additional controls that modify allocations.

Enumerator
RESOURCE_ALLOCATION_FLAG_NONE 

Disables all allocation flags.

Enabled by default.
RESOURCE_ALLOCATION_FLAG_NEVER_ALLOCATE_HEAP 

Disallow creating a new resource heap when creating a resource.

The created resource must use an existing resource heap or E_OUTOFMEMORY. Effectively
disables creating standalone allocations whose memory cannot be reused.
RESOURCE_ALLOCATION_FLAG_ALLOW_SUBALLOCATE_WITHIN_RESOURCE 

Sub-allocate a resource allocation within the same resource.

The resource alignment is allowed to be byte-aligned instead of being resource-aligned,
which significantly reduces app memory usage (1B vs 64KB per allocation). Since the resource
can only be in one state at a time, this is mostly restricted to constant buffers (index and
vertex buffers which will stay read-only after creation). The app developer must use offsets
from the start of the allocation (vs subresource index) by using
ResourceAllocation::GetOffsetFromResource().

The app developer must either check if the allocator supports sub-allocation within resource
beforehand (via ResourceAllocator::CheckFeatureSupport) OR simply ensure only a single
command queue is used since not all devices guarantee command queue accesses are coherent
between sub-allocations within the same resource.
RESOURCE_ALLOCATION_FLAG_NEVER_SUBALLOCATE_HEAP 

Disallow allowing the creation of multiple resources using the same resource heap.

When this flag is used, the created resource will always be allocated with it's own resource heap.

RESOURCE_ALLOCATION_FLAG_ALWAYS_PREFETCH_HEAP 

Force pre-fetch for the next resource allocation.

This flag has no effect if RESOURCE_ALLOCATOR_FLAG_ALLOW_PREFETCH was not specified.

Should not be used with RESOURCE_ALLOCATION_FLAG_NEVER_ALLOCATE_HEAP.
RESOURCE_ALLOCATION_FLAG_ALWAYS_CACHE_SIZE 

Cache the request size.

Allow internal data structures used for resource allocation to be cached in-memory.
RESOURCE_ALLOCATION_FLAG_ALWAYS_ATTRIBUTE_HEAPS 

Requires heaps to be always attributed by D3D12_HEAP_TYPE.

With cache-coherent UMA adapters, a single custom-equivalent heap will be used everywhere.
This enables better resource optimization during allocation. However, certain heap flags or
access-patterns may beneifit specifying D3D12_HEAP_TYPE. For example,
D3D12_HEAP_FLAG_SHARED requires D3D12_HEAP_TYPE_READBACK or D3D12_HEAP_TYPE_UPLOAD,
as well as frequent CPU reads would beneifit from D3D12_HEAP_TYPE_READBACK since the CPU
properties are always write-combined.

If RESOURCE_ALLOCATOR_FLAG_ALLOW_UNIFIED_MEMORY was not specified, heap type was
D3D12_HEAP_TYPE_READBACK, or the adapter is not cache-coherent UMA, this flag has no effect.
RESOURCE_ALLOCATION_FLAG_NEVER_FALLBACK 

Forces use of the resource allocator or E_FAIL.

The flag disables the fall-back behavior of using
RESOURCE_ALLOCATION_FLAG_ALWAYS_COMMITTED as a last resort.

Mostly used for debug and testing when certain allocations unexpectedly fail.
RESOURCE_ALLOCATION_FLAG_NEVER_RESIDENT 

Disable residency management for the resource allocation.

The flag disables residency management for the resource allocation.

Mostly used when external resources are residency managed elsewhere.
RESOURCE_ALLOCATION_FLAG_ALWAYS_WARN_ON_ALIGNMENT_MISMATCH 

Report alignment mismatches upon successful resource creation.

Flag is used to report when requested size does not match the allocation size due to
resource or allocation alignment requirements.

Must compile with GPGMM_ENABLE_MEMORY_ALIGN_CHECKS to use as the request size
is normally not tracked.
RESOURCE_ALLOCATION_FLAG_ALWAYS_COMMITTED 

Disable re-use of resource heap.

A committed resource is allocated through D3D12 instead of GPGMM. This could be favorable
for large static resources. Otherwise, this is mostly used for debugging and testing
purposes.

◆ RESOURCE_ALLOCATION_TYPE

Represents how memory was allocated.

Enumerator
RESOURCE_ALLOCATION_TYPE_UNKNOWN 

Not yet allocated or invalid.

This is an invalid state that assigned temporary before the actual method is known.
RESOURCE_ALLOCATION_TYPE_STANDALONE 

Not sub-divided.

One and only one resource allocation exists for the heap.
RESOURCE_ALLOCATION_TYPE_SUBALLOCATED 

Sub-divided using one or more allocations.

Underlying heap will be broken up into one or more resource allocations.
RESOURCE_ALLOCATION_TYPE_SUBALLOCATED_WITHIN 

Sub-divided within a single memory allocation.

A single resource allocation will be broken into one or more sub-allocations.

◆ RESOURCE_ALLOCATOR_FEATURE

Defines constants that specify a resource allocator feature to query about. When you want to query for the level to which an allocator supports a feature, pass one of these values to ResourceAllocator::CheckFeatureSupport.

Enumerator
RESOURCE_ALLOCATOR_FEATURE_RESOURCE_ALLOCATION_SUPPORT 

Indicates a query for the level of support for allocated resources. The corresponding data structure for this value is FEATURE_DATA_RESOURCE_ALLOCATION_SUPPORT.

◆ RESOURCE_ALLOCATOR_FLAGS

Specify creation options for allocator.

Enumerator
RESOURCE_ALLOCATOR_FLAG_NONE 

Disables all option flags.

RESOURCE_ALLOCATOR_FLAG_ALWAYS_COMMITTED 

Disable re-use of resource heap.

A committed resource is allocated through D3D12 instead of GPGMM. This could be favorable
for large static resources. Otherwise, this is mostly used for debugging and testing
purposes.
RESOURCE_ALLOCATOR_FLAG_ALWAYS_IN_BUDGET 

Requires resource allocation to be created within budget.

Always use RESIDENCY_HEAP_FLAG_CREATE_IN_BUDGET to resource heaps created by this resource
allocator.
RESOURCE_ALLOCATOR_FLAG_ALLOW_PREFETCH 

Allow pre-fetching of resource heaps on background thread.

Allows GPGMM to trigger prefetching based on heurstics. Prefetching enables more
performance when allocating for contiguous allocations or many resources of the same size.
RESOURCE_ALLOCATOR_FLAG_ALWAYS_ON_DEMAND 

Disables recycling of heaps.

Forces the creation of new heaps and to de-allocate heaps immediately once no longer needed
(instead of re-using it).

This is very slow and not recommended for general use but may be useful for running with the
minimal possible GPU memory footprint, avoiding out-of-memory, or debugging possible
corruption of heaps.
RESOURCE_ALLOCATOR_FLAG_ALLOW_UNIFIED_MEMORY 

Uses D3D12_HEAP_TYPE_CUSTOM-equivalent upload heap everywhere on UMA.

Allocates resources with a D3D12_HEAP_TYPE_CUSTOM-equivalent upload heap type from
a single heap pool.
RESOURCE_ALLOCATOR_FLAG_NEVER_LEAK 

Report leaks of resource allocations.

Used to track outstanding allocations made with this allocator. When the allocator is about
to be released, it will report details on any leaked allocations as log messages.
RESOURCE_ALLOCATOR_FLAG_CREATE_NOT_RESIDENT 

Create resource allocation to be NOT created resident.

With this flag, resource heaps created by this resource allocator will specify
D3D12_HEAP_FLAG_CREATE_NOT_RESIDENT, when supported, to avoid unnecessary GPU paging
operations at resource creation.
RESOURCE_ALLOCATOR_FLAG_NEVER_OVER_ALLOCATE 

Never allow creation of resources when out of memory.

By default, unused heaps will be freed if there is not enough available memory for
allocation. This prevents allocation from failing should the application forgo calling
ReleaseResourceHeaps(). It is recommended for application developers to periodically call
ReleaseResourceHeaps() when pooling is enabled or when the working set size changes
significantly.

With this flag, there will be no attempt to free unused heaps when E_OUTOFMEMORY.

Function Documentation

◆ CheckFeatureSupport()

virtual HRESULT gpgmm::d3d12::CheckFeatureSupport ( RESOURCE_ALLOCATOR_FEATURE feature,
void * pFeatureSupportData,
UINT featureSupportDataSize ) const
pure virtual

Gets information about the features that are supported by the resource allocator.

Parameters
featureA constant from the RESOURCE_ALLOCATOR_FEATURE enumeration describing the feature(s) that you want to query for support.
pFeatureSupportDataA pointer to the data structure that corresponds to the value of the feature parameter. To determine the corresponding data structure for each constant, see FEATURE.
featureSupportDataSizeThe sie of the structure pointed by the pFeatureSupportData parameter.
Returns
Returns S_OK if successful. Returns E_INVALIDARG if unsupported data type is passed to pFeatureSupportData or if a size mismatch is detected for the featureSupportDataSize parameter.

◆ CreateResidencyHeap() [1/2]

GPGMM_EXPORT HRESULT gpgmm::d3d12::CreateResidencyHeap ( const RESIDENCY_HEAP_DESC & descriptor,
IResidencyManager *const pResidencyManager,
CreateHeapFn createHeapFn,
void * pCreateHeapContext,
IResidencyHeap ** ppResidencyHeapOut )

Create a residency managed heap.

Unlike a D3D12 heap, a IResidencyHeap means it can be managed for residency purposes.

Parameters
descriptorA reference to RESIDENCY_HEAP_DESC structure that describes the heap.
pResidencyManagerA pointer to the ResidencyManager used to manage this heap. If NULL, the residency heap will be created without residency management.
createHeapFnA callback function which creates a ID3D12Pageable derived type.
pCreateHeapContextA pointer to a class designed to implement the actual heap creation function and store any necessary variables.
[out]ppResidencyHeapOutPointer to a memory block that receives a pointer to the heap.

Example call showing the usage of createHeapFn and pCreateHeapContext:

CreateResidencyHeap(descriptor, pResidencyManager, CallbackContext:CallbackWrapper,
reinterpret_cast<void*>(callbackContext), ppResidencyHeapOut);
GPGMM_EXPORT HRESULT CreateResidencyHeap(const RESIDENCY_HEAP_DESC &descriptor, IResidencyManager *const pResidencyManager, CreateHeapFn createHeapFn, void *pCreateHeapContext, IResidencyHeap **ppResidencyHeapOut)
Create a residency managed heap.

Example Callback Context Class:

class CallbackContext {
public:
CallbackContext(<Pass variables needed for heap creation here>);
CreateResidencyHeap(void *context, ID3D12Pageable** ppPageableOut);
static CallbackWrapper(ID3D12Pageable** ppPageableOut);
private:
(Declare variables needed for heap creation here)
}

Example implementation of CallbackWrapper:

HRESULT CallbackContext:CallbackWrapper(void* context, ID3D12Pageable** ppPageableOut) {
CallbackContext* callbackContext = reinterpret_cast<CallbackContext*>(context);
return callbackContext->CreateResidencyHeap(ppPageableOut);
}

◆ CreateResidencyHeap() [2/2]

GPGMM_EXPORT HRESULT gpgmm::d3d12::CreateResidencyHeap ( const RESIDENCY_HEAP_DESC & descriptor,
IResidencyManager *const pResidencyManager,
ID3D12Pageable * pPageable,
IResidencyHeap ** ppResidencyHeapOut )

Create a residency managed heap.

This version of CreateResidencyHeap is a simpler way to create residency heaps by disallowing use of RESIDENCY_HEAP_FLAG_CREATE_IN_BUDGET by specifying the ID3D12Pageable.

Parameters
descriptorA reference to RESIDENCY_HEAP_DESC structure that describes the heap.
pResidencyManagerA pointer to the ResidencyManager used to manage this heap. If NULL, the residency heap will be created without residency management.
pPageableA pointer to the pageable object that represents the heap.
[out]ppResidencyHeapOutPointer to a memory block that receives a pointer to the heap.

◆ CreateResidencyList()

GPGMM_EXPORT HRESULT gpgmm::d3d12::CreateResidencyList ( IResidencyList ** ppResidencyListOut)

Create a residency list or collection of heaps to manage together for residency.

Parameters
[out]ppResidencyListOutAn optional pointer to a memory block that receives the required interface pointer to the created residency list object.
Returns
Returns S_OK if successful.

◆ CreateResidencyManager()

GPGMM_EXPORT HRESULT gpgmm::d3d12::CreateResidencyManager ( const RESIDENCY_MANAGER_DESC & descriptor,
ID3D12Device * pDevice,
IDXGIAdapter3 * pAdapter,
IResidencyManager ** ppResidencyManagerOut )

Create residency residency manager to manage video memory.

Parameters
descriptorA reference to RESIDENCY_MANAGER_DESC structure that describes the residency manager.
pDevicedevice used by this allocator. Required parameter. Use CreateDevice get the device.
pAdapterDXGI adapter used to create the device. Requires DXGI 1.4 due to IDXGIAdapter3::QueryVideoMemoryInfo. Use EnumAdapters to get the adapter.
[out]ppResidencyManagerOutPointer to a memory block that receives a pointer to the residency manager. Pass NULL to test if residency Manager creation would succeed, but not actually create the residency Manager. If NULL is passed and residency manager creating would succeed, S_FALSE is returned.

◆ CreateResource()

virtual HRESULT gpgmm::d3d12::CreateResource ( const RESOURCE_ALLOCATION_DESC & allocationDescriptor,
ID3D12Resource * pCommittedResource,
IResourceAllocation ** ppResourceAllocationOut )
pure virtual

Use existing ID3D12Resource as a resource allocation.

Returns a ResourceAllocation which represents an existing resource with a resource heap.

Parameters
allocationDescriptorA reference to RESOURCE_ALLOCATION_DESC structure that provides. properties for the resource allocation.
pCommittedResourceA pointer to a committed ID3D12Resource.
[out]ppResourceAllocationOutPointer to a memory block that receives a pointer to the resource allocation. Pass NULL to test if resource allocation creation would succeed, but not actually create the resource allocation. If NULL is passed and resource allocation creation would succeed, S_FALSE is returned.
Returns
S_OK if successful or E_OUTOFMEMORY if there was not enough available memory.

◆ CreateResourceAllocator() [1/3]

GPGMM_EXPORT HRESULT gpgmm::d3d12::CreateResourceAllocator ( const RESOURCE_ALLOCATOR_DESC & allocatorDescriptor,
ID3D12Device * pDevice,
IDXGIAdapter * pAdapter,
IResidencyManager * pResidencyManager,
IResourceAllocator ** ppResourceAllocatorOut )

Create a resource allocator using a specified residency manager.

Parameters
allocatorDescriptorA reference to RESOURCE_ALLOCATOR_DESC structure that describes the allocator.
pDevicedevice used by this allocator. Required parameter. Use CreateDevice get the device.
pAdapterDXGI adapter used to create the device. Used to detect for additional device capabilities (by GPU vendor). Optional parameter. Use EnumAdapters to get the adapter.
pResidencyManagerPointer to a memory block that receives a pointer to the residency manager.
[out]ppResourceAllocatorOutPointer to a memory block that receives a pointer to the resource allocator. Pass NULL to test if allocator creation would succeed, but not actually create the allocator.

◆ CreateResourceAllocator() [2/3]

GPGMM_EXPORT HRESULT gpgmm::d3d12::CreateResourceAllocator ( const RESOURCE_ALLOCATOR_DESC & allocatorDescriptor,
ID3D12Device * pDevice,
IDXGIAdapter * pAdapter,
IResourceAllocator ** ppResourceAllocatorOut,
IResidencyManager ** ppResidencyManagerOut )

Create a resource allocator with residency.

Residency requires at-least DXGI version 1.4.

Parameters
allocatorDescriptorA reference to RESOURCE_ALLOCATOR_DESC structure that describes the allocator.
pDevicedevice used by this allocator. Required parameter. Use CreateDevice get the device.
pAdapterDXGI adapter used to create the device. Used to detect for additional device capabilities (by GPU vendor). Optional parameter. Use EnumAdapters to get the adapter.
[out]ppResourceAllocatorOutPointer to a memory block that receives a pointer to the resource allocator. Pass NULL to test if allocator creation would succeed, but not actually create the allocator.
[out]ppResidencyManagerOutPointer to a memory block that receives a pointer to the residency manager. If NULL is passed, the allocator will be created without using residency.

◆ CreateResourceAllocator() [3/3]

GPGMM_EXPORT HRESULT gpgmm::d3d12::CreateResourceAllocator ( const RESOURCE_ALLOCATOR_DESC & allocatorDescriptor,
IResourceAllocator * pResourceAllocator,
IResourceAllocator ** ppResourceAllocatorOut )

Create a resource allocator from an existing resource allocator.

Creating a resource allocator from another resource allocator allows resources heaps to be re-used between allocators that have seperate configurations. For example, the application developer may want a global resource allocator to service large requests using dedication allocations but still prefer smaller requests to use sub-allocation. By creating a resource allocator from another, the same pool can be re-used instead of managing multiple pools.

Parameters
allocatorDescriptorA reference to RESOURCE_ALLOCATOR_DESC structure that describes the allocator.
pResourceAllocatorallocator used to create the allocator. Required parameter.
[out]ppResourceAllocatorOutPointer to a memory block that receives a pointer to the resource allocator. Pass NULL to test if allocator creation would succeed, but not actually create the allocator.

◆ GetGPUVirtualAddress()

virtual D3D12_GPU_VIRTUAL_ADDRESS gpgmm::d3d12::GetGPUVirtualAddress ( ) const
pure virtual

Returns the GPU virtual address of the resource allocation.

If sub-allocated within the resource, the GPU virtual address will start from the allocation instead of the resource.

Returns
A D3D12_GPU_VIRTUAL_ADDRESS, equal to UINT64, to represent a location in GPU memory.

◆ GetInfo()

virtual RESOURCE_ALLOCATION_INFO gpgmm::d3d12::GetInfo ( ) const
pure virtual

Returns information about this resource allocation.

Returns
A RESOURCE_ALLOCATION_INFO struct containing the information.

◆ GetMemory()

virtual IResidencyHeap * gpgmm::d3d12::GetMemory ( ) const
pure virtual

Returns the heap assigned to this resource allocation.

Returns
A pointer to the IResidencyHeap used by this resource allocation.

◆ GetOffsetFromResource()

virtual UINT64 gpgmm::d3d12::GetOffsetFromResource ( ) const
pure virtual

Returns the start of the allocation in the resource.

If sub-allocated within the resource, the offset could be greater than zero.

Returns
A offset, in bytes, of the start of this allocation in the resource.

◆ GetResidencyManager()

virtual HRESULT gpgmm::d3d12::GetResidencyManager ( IResidencyManager ** ppResidencyManagerOut) const
pure virtual

Get the residency manager that manages this heap.

Parameters
[out]ppResidencyManagerOutPointer to a memory block that receives a pointer to the residency manager. Pass NULL to test if the residency manager exists.
Returns
S_OK when exists else S_FALSE if NULL was passed to test.

◆ GetResource()

virtual ID3D12Resource * gpgmm::d3d12::GetResource ( ) const
pure virtual

Returns the resource owned by this allocation.

Returns
Pointer to ID3D12Resource, owned by this allocation.

◆ GetResourceAllocator()

virtual HRESULT gpgmm::d3d12::GetResourceAllocator ( IResourceAllocator ** ppResourceAllocatorOut) const
pure virtual

Get the resource allocator that created the resource for this allocation.

Parameters
[out]ppResourceAllocatorOutPointer to a memory block that receives a pointer to the resource allocator.

◆ Lock()

virtual HRESULT gpgmm::d3d12::Lock ( )
pure virtual

Locks the specified heap.

Locking a heap means the residency manager will never evict it when over budget.

Returns
S_OK if locking was successful.

◆ QueryStats() [1/2]

virtual HRESULT gpgmm::d3d12::QueryStats ( RESIDENCY_MANAGER_STATS * pResidencyManagerStats)
pure virtual

Query the current residency usage.

Parameters
pResidencyManagerStatsA pointer to a RESIDENCY_MANAGER_STATS structure or NULL if statistics information should only be gathered for recording.
Returns
Returns S_OK if successful. Returns S_FALSE if statistics information was only gathered for recording.

◆ QueryStats() [2/2]

virtual HRESULT gpgmm::d3d12::QueryStats ( RESOURCE_ALLOCATOR_STATS * pResourceAllocatorStats)
pure virtual

Query the current allocator usage.

Returned info can be used to monitor memory usage per allocator. For example, the amount of internal fragmentation is equal to UsedBlockUsage / UsedMemoryUsage. Or the percent of recycled memory is equal to FreeMemoryUsage / (UsedMemoryUsage + FreeMemoryUsage) * 100%.

Parameters
pResourceAllocatorStatsA pointer to a RESOURCE_ALLOCATOR_STATS structure or NULL if statistics information should only be gathered for recording.
Returns
Returns S_OK if successful. Returns S_FALSE if statistics information was only gathered for recording.

◆ QueryVideoMemoryInfo()

virtual HRESULT gpgmm::d3d12::QueryVideoMemoryInfo ( const DXGI_MEMORY_SEGMENT_GROUP & heapSegment,
DXGI_QUERY_VIDEO_MEMORY_INFO * pVideoMemoryInfoOut )
pure virtual

Get the current budget and memory usage.

Parameters
heapSegmentMemory segment to retrieve info from.
[out]pVideoMemoryInfoOutPointer to DXGI_QUERY_VIDEO_MEMORY_INFO to populate. A value of nullptr will update but not return the current info.

◆ ReleaseResourceHeaps()

virtual HRESULT gpgmm::d3d12::ReleaseResourceHeaps ( UINT64 bytesToRelease,
UINT64 * pBytesReleased )
pure virtual

Return free memory back to the OS.

When pooling is enabled, the allocator will retain resource heaps in order to speed-up subsequent resource allocation requests. These resource allocations count against the app's memory usage and in general, will lead to increased memory usage by the overall system. Apps should call ReleaseResourceHeaps() when going idle for a period of time since there is a brief performance hit when the internal resource heaps get reallocated by the OS.

Parameters
bytesToReleaseAmount of memory to release, in bytes. A value of UINT64_MAX releases ALL memory held by the allocator.
pBytesReleasedOptional pointer to integer which receives the amount of memory released, in bytes.
Returns
Returns S_OK if successfully released equal to or greater than the memory amount specified. Or S_FALSE if the released size was smaller, there was not enough memory or larger if releasable memory doesn't exactly total up to the amount.

◆ Reset()

virtual HRESULT gpgmm::d3d12::Reset ( )
pure virtual

Resets list to its initial state as if a new list was created.

Returns
Returns S_OK if successful.

◆ SetDebugName()

virtual HRESULT gpgmm::d3d12::SetDebugName ( LPCWSTR Name)
pure virtual

Associate a debug name.

Parameters
NameA NULL-terminated UNICODE string that contains the name to associate with the debug object.

◆ SetResidencyStatus()

virtual HRESULT gpgmm::d3d12::SetResidencyStatus ( IResidencyHeap * pHeap,
const RESIDENCY_HEAP_STATUS & newStatus )
pure virtual

Update the residency status of a heap.

Allows the application to explicitly MakeResident/Evict without using a residency manager operation. This is useful should the application already perform some residency management but also want to use a residency manager. It is the application developers responsibility to ensure MakeResident/Evict will be called before updating the residency status.

Parameters
pHeapA pointer to the heap being updated.
newStatusThe RESIDENCY_HEAP_STATUS enum of the new status.

◆ SetVideoMemoryReservation()

virtual HRESULT gpgmm::d3d12::SetVideoMemoryReservation ( const DXGI_MEMORY_SEGMENT_GROUP & heapSegment,
UINT64 availableForReservation,
UINT64 * pCurrentReservationOut = nullptr )
pure virtual

Sets video memory reservation.

A reservation is the lowest amount of physical memory the application need to continue operation safely.

Parameters
heapSegmentMemory segment to reserve.
availableForReservationAmount of memory to reserve, in bytes.
[out]pCurrentReservationOutthe amount of memory reserved, which may be less then the |reservation| when under video memory pressure. A value of nullptr will update but not return the current reservation.

◆ Unlock()

virtual HRESULT gpgmm::d3d12::Unlock ( )
pure virtual

Unlocks the specified heap.

Unlocking a heap allows the residency manager will evict it when over budget.

Returns
S_OK if unlocking was successful or S_FALSE if a lock remains.

◆ Unmap()

virtual void gpgmm::d3d12::Unmap ( UINT subresource,
const D3D12_RANGE * pWrittenRange )
pure virtual

Unmaps the resource allocation.

Invalidates the CPU pointer to the specified subresource in the resource.

Parameters
subresourceSpecifies the index number of the subresource.
pWrittenRangeA pointer to a D3D12_RANGE structure that describes the range of memory to unmap.

Variable Documentation

◆ count

GPGMM_INTERFACE ID3D12CommandList* const IResidencyList* const UINT gpgmm::d3d12::count = 0

◆ IDebugObject

GPGMM_INTERFACE gpgmm::d3d12::IDebugObject

Debug object associates additional information for D3D objects using SetPrivateData.

Since a single D3D object could be re-used by one or more GPGMM objects, debug information must be stored and retrieved separately.

◆ initialResourceState

GPGMM_INTERFACE const D3D12_RESOURCE_DESC D3D12_RESOURCE_STATES gpgmm::d3d12::initialResourceState

◆ IResidencyHeap

GPGMM_INTERFACE gpgmm::d3d12::IResidencyHeap

IResidencyHeap represents a ID3D12Pageable object used for residency management.

For example, a IResidencyHeap could represent a "resource heap" (ID3D12Heap or committed ID3D12Resource) or ID3D12DescriptorHeap and so on.

IResidencyHeap serves as a node within the IResidencyManager's residency cache. This node is inserted into the cache when it is first created, and any time it is scheduled to be used by the GPU. This node is removed from the cache when it is evicted from video memory due to budget constraints, or when the memory is released.

◆ IResidencyList

GPGMM_INTERFACE gpgmm::d3d12::IResidencyList

Represents a list of heaps which will be "made resident" upon executing a command-list.

A residency list helps track heaps for residency which will be referenced together by a command-list. The application uses a IResidencyList by inserting heaps, by calling IResourceAllocation::GetMemory, into the list. Once IResidencyManager::ExecuteCommandLists is called, the list can be reset or cleared for the next frame or compute job.

Without IResidencyList, the application would need to lock and unlock each heap before and after every GPU command or command-list being executed.

◆ IResidencyManager

GPGMM_INTERFACE gpgmm::d3d12::IResidencyManager

ResidencyManager tracks and maintains one or more heaps within a residency cache.

A heap is considered "resident" when it is accessible by the GPU. A heap can be made explicitly resident by calling ResidencyManager::LockHeap or implicitly resident by using the heap with a ResidencyList upon calling ResidencyManager::ExecuteCommandLists or through a operation that always requires the heap to be resident (eg. Map, Unmap).

Internally, the ResidencyManager keeps the application in-budget by calling ID3D12Device::Evict and ID3D12Device::MakeResident to page-out or page-in heaps, respectively.

◆ IResourceAllocation

GPGMM_INTERFACE gpgmm::d3d12::IResourceAllocation

ResourceAllocation is an allocation that contains a ID3D12Resource.

It can represent a allocation using a resource in one of three ways: 1) ID3D12Resource "placed" in a ID3D12Heap, 2) a ID3D12Resource at a specific offset, or 3) a ID3D12Resource without a ID3D12Heap (called a committed resource).

It is recommend to use ResourceAllocation instead of ID3D12Resource (1:1) for performing D3D12 operations with it (eg. Map, Unmap, etc).

◆ IResourceAllocator

GPGMM_INTERFACE gpgmm::d3d12::IResourceAllocator

ResourceAllocator is an allocator that creates ID3D12Resources in a ResourceAllocation.

Internally, ResourceAllocator creates a request, by determining the resource allocation requirements, then finds an allocator able to service the request.

If the first ResourceAllocator attempt fails, it will try a second allocator, and so on. ResourceAllocator attempts are greedy: re-use of resources > re-use of heaps > re-use by pools > no re-use, in order of maximizing performance while minimizing memory footprint.

ResourceAllocator also uses ResidencyManager to determine available memory (or budget left) when creating the request. This is because residency is managed per heap and not per resource). A larger heap could be ideal for allocation but only if there is budget. And similarly, a smaller heap allows for finer grained residency but could increase overall memory usage for allocation.

◆ pClearValue

GPGMM_INTERFACE const D3D12_RESOURCE_DESC D3D12_RESOURCE_STATES const D3D12_CLEAR_VALUE* gpgmm::d3d12::pClearValue

◆ ppCommandLists

GPGMM_INTERFACE ID3D12CommandList* const* gpgmm::d3d12::ppCommandLists

◆ ppDataOut

GPGMM_INTERFACE const D3D12_RANGE void** gpgmm::d3d12::ppDataOut = 0

◆ ppResidencyLists

GPGMM_INTERFACE ID3D12CommandList* const IResidencyList* const* gpgmm::d3d12::ppResidencyLists

◆ ppResourceAllocationOut

GPGMM_INTERFACE const D3D12_RESOURCE_DESC D3D12_RESOURCE_STATES const D3D12_CLEAR_VALUE IResourceAllocation** gpgmm::d3d12::ppResourceAllocationOut = 0

◆ pReadRange

GPGMM_INTERFACE const D3D12_RANGE* gpgmm::d3d12::pReadRange

◆ resourceDescriptor

GPGMM_INTERFACE const D3D12_RESOURCE_DESC& gpgmm::d3d12::resourceDescriptor