GPGMM
GPGMM, a General-Purpose GPU Memory Management Library
|
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. | |
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 IResidencyHeap * | GetMemory () 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 |
using gpgmm::d3d12::CreateHeapFn = HRESULT (*)(void* pCreateHeapContext, ID3D12Pageable** ppPageableOut) |
Callback function used to create a ID3D12Pageable.
Represents different event categories to record.
Specify creation options to configure the heap.
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.
Specify options to configure the residency manager.
Describes the algorithm used for allocation of resources.
Additional controls that modify allocations.
Represents how memory was allocated.
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. |
Specify creation options for allocator.
|
pure virtual |
Gets information about the features that are supported by the resource allocator.
feature | A constant from the RESOURCE_ALLOCATOR_FEATURE enumeration describing the feature(s) that you want to query for support. |
pFeatureSupportData | A 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. |
featureSupportDataSize | The sie of the structure pointed by the pFeatureSupportData parameter. |
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.
descriptor | A reference to RESIDENCY_HEAP_DESC structure that describes the heap. | |
pResidencyManager | A pointer to the ResidencyManager used to manage this heap. If NULL, the residency heap will be created without residency management. | |
createHeapFn | A callback function which creates a ID3D12Pageable derived type. | |
pCreateHeapContext | A pointer to a class designed to implement the actual heap creation function and store any necessary variables. | |
[out] | ppResidencyHeapOut | Pointer to a memory block that receives a pointer to the heap. |
Example call showing the usage of createHeapFn and pCreateHeapContext:
Example Callback Context Class:
Example implementation of CallbackWrapper:
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.
descriptor | A reference to RESIDENCY_HEAP_DESC structure that describes the heap. | |
pResidencyManager | A pointer to the ResidencyManager used to manage this heap. If NULL, the residency heap will be created without residency management. | |
pPageable | A pointer to the pageable object that represents the heap. | |
[out] | ppResidencyHeapOut | Pointer to a memory block that receives a pointer to the heap. |
GPGMM_EXPORT HRESULT gpgmm::d3d12::CreateResidencyList | ( | IResidencyList ** | ppResidencyListOut | ) |
Create a residency list or collection of heaps to manage together for residency.
[out] | ppResidencyListOut | An optional pointer to a memory block that receives the required interface pointer to the created residency list object. |
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.
descriptor | A reference to RESIDENCY_MANAGER_DESC structure that describes the residency manager. | |
pDevice | device used by this allocator. Required parameter. Use CreateDevice get the device. | |
pAdapter | DXGI adapter used to create the device. Requires DXGI 1.4 due to IDXGIAdapter3::QueryVideoMemoryInfo. Use EnumAdapters to get the adapter. | |
[out] | ppResidencyManagerOut | Pointer 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. |
|
pure virtual |
Use existing ID3D12Resource as a resource allocation.
Returns a ResourceAllocation which represents an existing resource with a resource heap.
allocationDescriptor | A reference to RESOURCE_ALLOCATION_DESC structure that provides. properties for the resource allocation. | |
pCommittedResource | A pointer to a committed ID3D12Resource. | |
[out] | ppResourceAllocationOut | Pointer 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. |
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.
allocatorDescriptor | A reference to RESOURCE_ALLOCATOR_DESC structure that describes the allocator. | |
pDevice | device used by this allocator. Required parameter. Use CreateDevice get the device. | |
pAdapter | DXGI adapter used to create the device. Used to detect for additional device capabilities (by GPU vendor). Optional parameter. Use EnumAdapters to get the adapter. | |
pResidencyManager | Pointer to a memory block that receives a pointer to the residency manager. | |
[out] | ppResourceAllocatorOut | Pointer 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. |
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.
allocatorDescriptor | A reference to RESOURCE_ALLOCATOR_DESC structure that describes the allocator. | |
pDevice | device used by this allocator. Required parameter. Use CreateDevice get the device. | |
pAdapter | DXGI 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] | ppResourceAllocatorOut | Pointer 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] | ppResidencyManagerOut | Pointer to a memory block that receives a pointer to the residency manager. If NULL is passed, the allocator will be created without using residency. |
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.
allocatorDescriptor | A reference to RESOURCE_ALLOCATOR_DESC structure that describes the allocator. | |
pResourceAllocator | allocator used to create the allocator. Required parameter. | |
[out] | ppResourceAllocatorOut | Pointer 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. |
|
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.
|
pure virtual |
Returns information about this resource allocation.
|
pure virtual |
Returns the heap assigned to this resource allocation.
|
pure virtual |
Returns the start of the allocation in the resource.
If sub-allocated within the resource, the offset could be greater than zero.
|
pure virtual |
Get the residency manager that manages this heap.
[out] | ppResidencyManagerOut | Pointer to a memory block that receives a pointer to the residency manager. Pass NULL to test if the residency manager exists. |
|
pure virtual |
Returns the resource owned by this allocation.
|
pure virtual |
Get the resource allocator that created the resource for this allocation.
[out] | ppResourceAllocatorOut | Pointer to a memory block that receives a pointer to the resource allocator. |
|
pure virtual |
Locks the specified heap.
Locking a heap means the residency manager will never evict it when over budget.
|
pure virtual |
Query the current residency usage.
pResidencyManagerStats | A pointer to a RESIDENCY_MANAGER_STATS structure or NULL if statistics information should only be gathered for recording. |
|
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%.
pResourceAllocatorStats | A pointer to a RESOURCE_ALLOCATOR_STATS structure or NULL if statistics information should only be gathered for recording. |
|
pure virtual |
Get the current budget and memory usage.
heapSegment | Memory segment to retrieve info from. | |
[out] | pVideoMemoryInfoOut | Pointer to DXGI_QUERY_VIDEO_MEMORY_INFO to populate. A value of nullptr will update but not return the current info. |
|
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.
bytesToRelease | Amount of memory to release, in bytes. A value of UINT64_MAX releases ALL memory held by the allocator. |
pBytesReleased | Optional pointer to integer which receives the amount of memory released, in bytes. |
|
pure virtual |
Resets list to its initial state as if a new list was created.
|
pure virtual |
Associate a debug name.
Name | A NULL-terminated UNICODE string that contains the name to associate with the debug object. |
|
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.
pHeap | A pointer to the heap being updated. |
newStatus | The RESIDENCY_HEAP_STATUS enum of the new status. |
|
pure virtual |
Sets video memory reservation.
A reservation is the lowest amount of physical memory the application need to continue operation safely.
heapSegment | Memory segment to reserve. | |
availableForReservation | Amount of memory to reserve, in bytes. | |
[out] | pCurrentReservationOut | the 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. |
|
pure virtual |
Unlocks the specified heap.
Unlocking a heap allows the residency manager will evict it when over budget.
|
pure virtual |
Unmaps the resource allocation.
Invalidates the CPU pointer to the specified subresource in the resource.
subresource | Specifies the index number of the subresource. |
pWrittenRange | A pointer to a D3D12_RANGE structure that describes the range of memory to unmap. |
GPGMM_INTERFACE ID3D12CommandList* const IResidencyList* const UINT gpgmm::d3d12::count = 0 |
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.
GPGMM_INTERFACE const D3D12_RESOURCE_DESC D3D12_RESOURCE_STATES gpgmm::d3d12::initialResourceState |
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.
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.
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.
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).
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.
GPGMM_INTERFACE const D3D12_RESOURCE_DESC D3D12_RESOURCE_STATES const D3D12_CLEAR_VALUE* gpgmm::d3d12::pClearValue |
GPGMM_INTERFACE ID3D12CommandList* const* gpgmm::d3d12::ppCommandLists |
GPGMM_INTERFACE const D3D12_RANGE void** gpgmm::d3d12::ppDataOut = 0 |
GPGMM_INTERFACE ID3D12CommandList* const IResidencyList* const* gpgmm::d3d12::ppResidencyLists |
GPGMM_INTERFACE const D3D12_RESOURCE_DESC D3D12_RESOURCE_STATES const D3D12_CLEAR_VALUE IResourceAllocation** gpgmm::d3d12::ppResourceAllocationOut = 0 |
GPGMM_INTERFACE const D3D12_RANGE* gpgmm::d3d12::pReadRange |
GPGMM_INTERFACE const D3D12_RESOURCE_DESC& gpgmm::d3d12::resourceDescriptor |