Navigation
API > API/Runtime > API/Runtime/RHI
References
| Module | RHI |
| Header | /Engine/Source/Runtime/RHI/Public/GPUDefragAllocator.h |
| Include | #include "GPUDefragAllocator.h" |
Syntax
class FGPUDefragAllocator
Remarks
Simple best fit allocator, splitting and coalescing whenever/ wherever possible. NOT THREAD-SAFE.
- uses TMap to find memory chunk given a Pointer (potentially colliding with malloc/ free from main thread)
- uses separate linked list for free allocations, assuming that relatively few free chunks due to coalescing
Variables
| Type | Name | Description | |
|---|---|---|---|
| memsize_t | AllocatedMemorySize | ||
| int32 | AllocationAlignment | Allocation alignment requirements. | |
| memsize_t | AvailableMemorySize | Available memory in uint8s. | |
| bool | bBenchmarkMode | When in benchmark mode, don't call any Platform functions. | |
| uint32 | BlockedCycles | Amount of time blocked by a platform fence since the beginning of the last call to Tick(), in appCycles. | |
| uint64 | CompletedSyncIndex | Sync index that has been completed, so far. | |
| uint64 | CurrentLargestHole | ||
| int32 | CurrentNumHoles | ||
| uint64 | CurrentSyncIndex | Ever-increasing index to synchronize all relocations initiated by Tick(). | |
| FMemoryChunk * | FirstChunk | Head of linked list of chunks. Sorted by memory address. | |
| FMemoryChunk * | FirstFreeChunk | Head of linked list of free chunks. Unsorted. | |
| friend | FScopedGPUDefragLock | ||
| FMemoryChunk * | LastChunk | Last chunk in the linked list of chunks (see FirstChunk). | |
| int32 | MaxNumHoles | Maximum number of disjoint32 free memory regions we've had. | |
| uint8 * | MemoryBase | Base of memory pool. | |
| uint64 | MemorySize | Total size of memory pool, in uint8s. | |
| int64 | MinLargestHole | Smallest consecutive free memory region we've had. | |
| int32 | NumCanceledAsyncRequests | Total number of async requests that has been canceled so far. | |
| int32 | NumFinishedAsyncAllocations | Total number of async allocations successfully completed so far. | |
| int32 | NumFinishedAsyncReallocations | Total number of async reallocations successfully completed so far. | |
| int32 | NumLockedChunks | ||
| int32 | NumRelocationsInProgress | Number of async relocations that are currently in progress. | |
| memsize_t | PaddingWasteSize | ||
| TDoubleLinkedList< FMemoryChunk * > | PendingFreeChunks | Chunks that couldn't be freed immediately because they were being relocated. | |
| memsize_t | PendingMemoryAdjustment | Adjustment to allocated memory, pending all reallocations. | |
| uint64 | PlatformSyncFence | Platform-specific (GPU) fence, used for synchronizing the Sync Index. | |
| TMap< void *, FMemoryChunk * > | PointerToChunkMap | Mapping from Pointer to chunk for fast removal. | |
| FSettings | Settings | Allocator settings that affect its behavior. | |
| FCriticalSection | SynchronizationObject | ||
| double | TimeSpentInAllocator | Cumulative time spent in allocator. | |
| uint64 | TotalNumBytesRelocated | Total number of uint8s relocated so far. | |
| uint64 | TotalNumRelocations | Stats. |
Constructors
| Type | Name | Description | |
|---|---|---|---|
| Constructor, zero initializing all member variables |
Destructors
| Type | Name | Description | |
|---|---|---|---|
Functions
| Type | Name | Description | |
|---|---|---|---|
| void * | Allocate physical memory. | ||
| FMemoryChunk * | AllocateChunk
(
FMemoryChunk* FreeChunk, |
Marks the specified chunk as 'allocated' and updates tracking variables. | |
| void | Benchmark
(
int32 MinChunkSize, |
Performs a benchmark of the allocator and outputs the result to the log. | |
| void | BlockOnAsyncReallocation
(
FAsyncReallocationRequest* Request |
Blocks the calling thread until the specified request has been completed. | |
| void | BlockOnFence () |
Blocks the calling thread until the current sync fence has been completed. | |
| void | BlockOnSyncIndex
(
uint32 SyncIndex |
Blocks the calling thread until the specified sync index has been completed. | |
| void | CancelAsyncReallocation
(
FAsyncReallocationRequest* Request, |
Cancels the specified reallocation request. | |
| bool | CanRelocate
(
const FMemoryChunk* Chunk |
Returns true if the specified chunk is allowed to relocate at this time. | |
| void | CheckForErrors
(
bool bCheckSortedFreeList |
Checks the int32ernal state for errors. (Slow)Checks the internal state for errors. (Slow) | |
| void | Coalesce
(
FMemoryChunk* FreedChunk |
Merges any adjacent free chunks into the specified free chunk. | |
| void | DefragmentMemory
(
FRelocationStats& Stats |
Fully defragments the memory and blocks until it's done. | |
| void | DumpAllocs
(
FOutputDevice& Ar |
Dump allocation information. | |
| FMemoryChunk * | FindAdjacent
(
FMemoryChunk* UsedChunk, |
Defrag helper function. Checks if the specified allocation fits within the adjacent free chunk(s). | |
| FMemoryChunk * | FindAdjacentToHole
(
FMemoryChunk* FreeChunk |
Searches for an allocated chunk that would fit within the specified free chunk. | |
| FMemoryChunk * | FindAny
(
FMemoryChunk* FreeChunk |
Searches for an allocated chunk that would fit within the specified free chunk. | |
| bool | Blocks the calling thread until all relocations and reallocations that were initiated by Tick() have completed. | ||
| void | Free
(
void* Pointer |
Frees allocation associated with the specified Pointer. | |
| void | FreeChunk
(
FMemoryChunk* Chunk |
Marks the specified chunk as 'free' and updates tracking variables. | |
| void | FullDefragmentation
(
FRelocationStats& Stats |
Performs a full defrag and ignores all reallocation requests. | |
| int64 | GetAllocatedSize
(
void* Pointer |
Returns the amount of memory allocated for the specified address. | |
| int32 | |||
| uint32 | Returns the amount of time blocked by a platform fence since the beginning of the last call to Tick(), in appCycles. | ||
| EMemoryElementType | GetChunkType
(
FMemoryChunk* Chunk |
||
| uint32 | Returns the sync index to be completed by the next call to FinishAllRelocations(). | ||
| int32 | GetLargestAvailableAllocation
(
int32* OutNumFreeChunks |
Scans the free chunks and returns the largest size you can allocate. | |
| void | GetMemoryLayout
(
TArray< FMemoryLayoutElement >& MemoryLayout |
||
| void | GetMemoryStats
(
int64& OutAllocatedMemorySize, |
Retrieves allocation stats. | |
| void | GetSettings
(
FSettings& OutSettings |
Returns the current allocator settings. | |
| bool | GetTextureMemoryVisualizeData
(
FColor* TextureData, |
Fills a texture with to visualize the texture pool memory. | |
| int64 | GetTotalSize () |
||
| void * | GetUserPayload
(
const void* Pointer |
Returns the user payload for an FMemoryChunk | |
| FMemoryChunk * | Grow
(
FMemoryChunk* Chunk, |
Tries to immediately grow a memory chunk by moving the base address, without relocating any memory. | |
| bool | Returns whether we're in benchmark mode or not. | ||
| void | Initialize
(
uint8* InMemoryBase, |
||
| void | Initialize
(
uint8* InMemoryBase, |
Initialize this allocator with a preallocated block of memory. | |
| void | InsertFence () |
Inserts a platform fence and updates the allocator sync index to match. | |
| bool | IsAligned
(
const volatile void* Ptr, |
||
| bool | Returns whether allocator has been initialized. | ||
| bool | IsValidPoolMemory
(
const void* Pointer |
||
| void | LinkFreeChunk
(
FMemoryChunk* Chunk |
Frees the passed in chunk and coalesces adjacent free chunks into 'Chunk' if possible. | |
| void | Lock
(
const void* Pointer |
Locks an FMemoryChunk | |
| void | PartialDefragmentationDownshift
(
FRelocationStats& Stats, |
Performs a partial defrag by shifting down memory to fill holes, in a brute-force manner. | |
| void | PartialDefragmentationFast
(
FRelocationStats& Stats, |
Performs a partial defrag doing fast checks only. Adjacency and freelist walk. | |
| void | PartialDefragmentationSlow
(
FRelocationStats& Stats, |
Performs a partial defrag doing slow all chunk search to find used chunks to move that are surrounded by other used chunks That a freechunk walk won't find. | |
| void | PlatformBlockOnFence
(
uint64 Fence |
Blocks the calling thread until all relocations initiated before the fence was added has been fully completed. | |
| bool | PlatformCanRelocate
(
const void* Source, |
Allows each platform to decide whether an allocation can be relocated at this time. | |
| uint64 | Inserts a fence to synchronize relocations. | ||
| void | PlatformNotifyReallocationFinished
(
FAsyncReallocationRequest* FinishedRequest, |
Notifies the platform that an async reallocation request has been completed. | |
| void | PlatformRelocate
(
void* Dest, |
Copy memory from one location to another. | |
| void * | Reallocate
(
void* OldBaseAddress, |
Tries to reallocate texture memory in-place (without relocating), by adjusting the base address of the allocation but keeping the end address the same. | |
| void | Relocate
(
FRelocationStats& Stats, |
Copy memory from one location to another. | |
| FMemoryChunk * | RelocateAllowed
(
FMemoryChunk* FreeChunk, |
Performs a partial defrag while trying to process any pending async reallocation requests. | |
| FMemoryChunk * | RelocateIntoFreeChunk
(
FRelocationStats& Stats, |
Initiates an async relocation of an allocated chunk into a free chunk. | |
| void | SetSettings
(
const FSettings& InSettings |
Sets new allocator settings. | |
| void | SetUserPayload
(
const void* Pointer, |
Sets the user payload for an FMemoryChunk | |
| FMemoryChunk * | Shrink
(
FMemoryChunk* Chunk, |
Immediately shrinks a memory chunk by moving the base address, without relocating any memory. | |
| void | SortFreeList
(
int32& NumFreeChunks, |
Sorts the freelist based on increasing base address. | |
| void | Split
(
FMemoryChunk* BaseChunk, |
Split allocation into two, first chunk being used and second being available. | |
| int32 | Tick
(
FRelocationStats& Stats, |
Partially defragments the memory and tries to process all async reallocation requests at the same time. | |
| void | Unlock
(
const void* Pointer |
Unlocks an FMemoryChunk |
Classes
| Type | Name | Description | |
|---|---|---|---|
| FMemoryChunk | Contains information of a single allocation or free block. | ||
| FMemoryLayoutElement | |||
| FRelocationStats | Container for allocator relocation stats. | ||
| FSettings | Container for allocator settings. |
Enums
| Type | Name | Description | |
|---|---|---|---|
| EMemoryElementType |
Typedefs
| Name | Description |
|---|---|
| FRequestList | |
| FRequestNode | |
| memsize_t | Allocated memory in uint8s. |