![]() |
UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
|
#include <GPUDefragAllocator.h>
Classes | |
| class | FMemoryChunk |
| struct | FMemoryLayoutElement |
| struct | FRelocationStats |
| struct | FSettings |
Public Types | |
| enum | EMemoryElementType { MET_Allocated , MET_Free , MET_Locked , MET_Relocating , MET_Resizing , MET_Resized , MET_Max } |
| typedef TDoubleLinkedList< FAsyncReallocationRequest * > | FRequestList |
| typedef TDoubleLinkedList< FAsyncReallocationRequest * >::TDoubleLinkedListNode | FRequestNode |
Static Public Member Functions | |
| static bool | IsAligned (const volatile void *Ptr, const uint32 Alignment) |
Protected Types | |
| typedef int64 | memsize_t |
Simple best fit allocator, splitting and coalescing whenever/ wherever possible. NOT THREAD-SAFE.
| typedef TDoubleLinkedList<FAsyncReallocationRequest*>::TDoubleLinkedListNode FGPUDefragAllocator::FRequestNode |
|
protected |
Allocated memory in uint8s.
|
inline |
Constructor, zero initializing all member variables
|
inlinevirtual |
|
virtual |
Allocate physical memory.
| AllocationSize | Size of allocation |
| bAllowFailure | Whether to allow allocation failure or not |
|
protected |
Marks the specified chunk as 'allocated' and updates tracking variables. Splits the chunk if only a portion of it is allocated.
| FreeChunk | Chunk to allocate |
| AllocationSize | Number of uint8s to allocate |
| bAsync | If true, allows allocating from relocating chunks and maint32ains the free-list sort order. |
Marks the specified chunk as 'allocated' and updates tracking variables. Splits the chunk if only a portion of it is allocated.
| FreeChunk | Chunk to allocate |
| AllocationSize | Number of bytes to allocate |
| bAsync | If true, allows allocating from relocating chunks and maintains the free-list sort order. |
| void FGPUDefragAllocator::Benchmark | ( | int32 | MinChunkSize, |
| int32 | MaxChunkSize, | ||
| float | FreeRatio, | ||
| float | LockRatio, | ||
| bool | bFullDefrag, | ||
| bool | bSaveImages, | ||
| const TCHAR * | Filename | ||
| ) |
Performs a benchmark of the allocator and outputs the result to the log.
| MinChunkSize | Minimum number of uint8s per random chunk |
| MaxChunkSize | Maximum number of uint8s per random chunk |
| FreeRatio | Free 0.0-1.0 of the memory before benchmarking |
| LockRatio | Lock 0.0-1.0 % of the memory before benchmarking |
| bFullDefrag | Whether to test full defrag (true) or continuous defrag (false) |
| bSaveImages | Whether to save before/after images to hard disk (TexturePoolBenchmark-*.bmp) |
| Filename | [opt] Filename to a previously saved memory layout to use for benchmarking, or nullptr |
Performs a benchmark of the allocator and outputs the result to the log.
| MinChunkSize | Minimum number of bytes per random chunk |
| MaxChunkSize | Maximum number of bytes per random chunk |
| FreeRatio | Free 0.0-1.0 % of the memory before benchmarking |
| LockRatio | Lock 0.0-1.0 % of the memory before benchmarking |
| bFullDefrag | Whether to test full defrag (true) or continuous defrag (false) |
| bSaveImages | Whether to save before/after images to hard disk (TexturePoolBenchmark-*.bmp) |
| Filename | [opt] Filename to a previously saved memory layout to use for benchmarking, or nullptr |
|
inline |
Blocks the calling thread until the specified request has been completed.
| Request | Request to wait for. Must be a valid request. |
|
protected |
Blocks the calling thread until the current sync fence has been completed.
Blocks the calling thread until the specified sync index has been completed.
| SyncIndex | Sync index to wait for |
| void FGPUDefragAllocator::CancelAsyncReallocation | ( | FAsyncReallocationRequest * | Request, |
| const void * | CurrentBaseAddress | ||
| ) |
Cancels the specified reallocation request. Note that the allocator doesn't keep track of requests after it's been completed, so the user must provide the current base address. This may not match any of the addresses in the (old) request since the memory may have been relocated since then.
| Request | Request to cancel. Must be a valid request. |
| CurrentBaseAddress | Current baseaddress used by the allocation. |
|
inlineprotected |
Returns true if the specified chunk is allowed to relocate at this time. Will also call PlatformCanRelocate().
| Chunk | Chunk to check |
Checks the int32ernal state for errors. (Slow)
| bCheckSortedFreeList | If true, also checks that the freelist is sorted |
Checks the internal state for errors. (Slow)
| bCheckSortedFreeList | If true, also checks that the freelist is sorted |
|
protected |
Merges any adjacent free chunks into the specified free chunk. Doesn't affect the free-list sort order.
| FreedChunk | Chunk that just became available. |
| void FGPUDefragAllocator::DefragmentMemory | ( | FRelocationStats & | Stats | ) |
Fully defragments the memory and blocks until it's done.
| Stats | [out] Stats |
| void FGPUDefragAllocator::DumpAllocs | ( | FOutputDevice & | Ar = *GLog | ) |
Dump allocation information.
|
protected |
Defrag helper function. Checks if the specified allocation fits within the adjacent free chunk(s).
| UsedChunk | Allocated chunk to check for a fit |
| bAnyChunkType | If false, only succeeds if 'UsedChunk' has a reallocation request and fits |
|
protected |
Searches for an allocated chunk that would fit within the specified free chunk. The allocated chunk must be adjacent to a free chunk and have a larger base address than 'FreeChunk'. Starts searching from the end of the texture pool.
| FreeChunk | Free chunk we're trying to fill up |
|
protected |
Searches for an allocated chunk that would fit within the specified free chunk. Any chunk that fits and has a larger base address than 'FreeChunk' is accepted. Starts searching from the end of the texture pool.
| FreeChunk | Free chunk we're trying to fill up |
| bool FGPUDefragAllocator::FinishAllRelocations | ( | ) |
Blocks the calling thread until all relocations and reallocations that were initiated by Tick() have completed.
Frees allocation associated with the specified Pointer.
| Pointer | Pointer to free. |
Frees allocation associated with passed in pointer.
| Pointer | Pointer to free. |
|
protected |
Marks the specified chunk as 'free' and updates tracking variables. Calls LinkFreeChunk() to coalesce adjacent free memory.
| Chunk | Chunk to free |
Marks the specified chunk as 'free' and updates tracking variables. Calls LinkFreeChunk() to coalesce adjacent free memory.
| Chunk | Chunk to free |
| bMaintainSortedFreelist | If true, maintains the free-list sort order |
|
protected |
Performs a full defrag and ignores all reallocation requests.
| Stats | [out] Stats |
Returns the amount of memory allocated for the specified address.
| Pointer | Pointer to check. |
Returns the amount of memory allocated for the specified address.
| Pointer | Pointer to check. |
|
inline |
|
inline |
Returns the amount of time blocked by a platform fence since the beginning of the last call to Tick(), in appCycles.
| FGPUDefragAllocator::EMemoryElementType FGPUDefragAllocator::GetChunkType | ( | FMemoryChunk * | Chunk | ) | const |
|
inlineprotected |
Returns the sync index to be completed by the next call to FinishAllRelocations().
Scans the free chunks and returns the largest size you can allocate.
| OutNumFreeChunks | Upon return, contains the total number of free chunks. May be nullptr. |
| void FGPUDefragAllocator::GetMemoryLayout | ( | TArray< FMemoryLayoutElement > & | MemoryLayout | ) |
|
inlinevirtual |
Retrieves allocation stats.
| OutAllocatedMemorySize | [out] Size of allocated memory |
| OutAvailableMemorySize | [out] Size of available memory |
| OutPendingMemoryAdjustment | [out] Size of pending allocation change (due to async reallocation) |
Returns the current allocator settings.
| OutSettings | [out] Current allocator settings |
| bool FGPUDefragAllocator::GetTextureMemoryVisualizeData | ( | FColor * | TextureData, |
| int32 | SizeX, | ||
| int32 | SizeY, | ||
| int32 | Pitch, | ||
| const int32 | PixelSize | ||
| ) |
Fills a texture with to visualize the texture pool memory.
| TextureData | Start address |
| SizeX | Number of pixels along X |
| SizeY | Number of pixels along Y |
| Pitch | Number of uint8s between each row |
| PixelSize | Number of uint8s each pixel represents |
Fills a texture with to visualize the texture pool memory.
| TextureData | Start address |
| SizeX | Number of pixels along X |
| SizeY | Number of pixels along Y |
| Pitch | Number of bytes between each row |
| PixelSize | Number of bytes each pixel represents |
|
inline |
Returns the user payload for an FMemoryChunk
| Pointer | Pointer indicating a chunk return The chunk's user payload |
|
protected |
Tries to immediately grow a memory chunk by moving the base address, without relocating any memory.
| Chunk | Chunk to grow |
| GrowAmount | Number of uint8s to grow by |
Tries to immediately grow a memory chunk by moving the base address, without relocating any memory.
| Chunk | Chunk to grow |
| GrowAmount | Number of bytes to grow by |
|
inline |
Returns whether we're in benchmark mode or not.
|
inlinevirtual |
|
inlinevirtual |
Initialize this allocator with a preallocated block of memory.
| InMemoryBase | Base address for the block of memory |
| InMemorySize | Size of the block of memory, in uint8s |
| InAllocationAlignment | Alignment for all allocations, in uint8s |
|
protected |
Inserts a platform fence and updates the allocator sync index to match.
|
inlinestatic |
|
inline |
Returns whether allocator has been initialized.
|
inlineprotected |
Frees the passed in chunk and coalesces adjacent free chunks into 'Chunk' if possible. Maint32ains the free-list order if bSortedFreeList is true.
| Chunk | Chunk to mark as available. |
| bSortedFreeList | If true, maintains the free-list sort order |
Locks an FMemoryChunk
| Pointer | Pointer indicating which chunk to lock |
|
protected |
Performs a partial defrag by shifting down memory to fill holes, in a brute-force manner. Takes consideration to async reallocations, but processes the all memory in order.
| Stats | [out] Stats |
| StartTime | Start time, used for limiting the Tick() time |
|
protected |
Performs a partial defrag doing fast checks only. Adjacency and freelist walk.
| Stats | [out] Stats |
| StartTime | Start time, used for limiting the Tick() time |
|
protected |
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.
| Stats | [out] Stats |
| StartTime | Start time, used for limiting the Tick() time |
Blocks the calling thread until all relocations initiated before the fence was added has been fully completed.
| Fence | Fence to block on |
|
protectedpure virtual |
Allows each platform to decide whether an allocation can be relocated at this time.
| Source | Base address of the allocation |
| UserPayload | User payload for the allocation |
Inserts a fence to synchronize relocations. The fence can be blocked on at a later time to ensure that all relocations initiated so far has been fully completed.
|
protectedpure virtual |
Notifies the platform that an async reallocation request has been completed.
| FinishedRequest | The request that got completed |
| UserPayload | User payload for the allocation |
|
protectedpure virtual |
Copy memory from one location to another. If it returns false, the defragmentation process will assume the memory is not relocatable and keep it in place. Note: Source and destination may overlap.
| Dest | Destination memory start address |
| Source | Source memory start address |
| Size | Number of uint8s to copy |
| UserPayload | User payload for this allocation |
Tries to reallocate texture memory in-place (without relocating), by adjusting the base address of the allocation but keeping the end address the same. Note: Newly freed memory due to shrinking won't be available for allocation right away (need GPU sync).
| OldBaseAddress | Pointer to the original allocation |
Tries to reallocate texture memory in-place (without relocating), by adjusting the base address of the allocation but keeping the end address the same.
| OldBaseAddress | Pointer to the original allocation |
|
inlineprotected |
Copy memory from one location to another. If it returns false, the defragmentation process will assume the memory is not relocatable and keep it in place. Note: Source and destination may overlap.
| Stats | [out] Stats |
| Dest | Destination memory chunk |
| DestOffset | Destination offset, counted from the base address of the destination memory chunk, in uint8s |
| Source | Base address of the source memory |
| Size | Number of uint8s to copy |
| UserPayload | User payload for the allocation |
|
protected |
Performs a partial defrag while trying to process any pending async reallocation requests.
| Stats | [out] Stats |
| StartTime | Start time, used for limiting the Tick() time |
|
protected |
Initiates an async relocation of an allocated chunk into a free chunk. Takes potential reallocation request into account.
| Stats | [out] Stats |
| FreeChunk | Destination chunk (free memory) |
| UsedChunk | Source chunk (allocated memory) |
Initiates an async relocation of an allocated chunk into a free chunk. Takes potential reallocation request into account.
| Stats | [out] Stats |
| FreeChunk | Destination chunk (free memory) |
| SourceChunk | Source chunk (allocated memory) |
Sets new allocator settings.
| InSettings | New allocator settings to replace the old ones. |
Sets the user payload for an FMemoryChunk
| Pointer | Pointer indicating a chunk |
| UserPayload | User payload to set |
|
protected |
Immediately shrinks a memory chunk by moving the base address, without relocating any memory. Always succeeds.
| Chunk | Chunk to shrink |
| ShrinkAmount | Number of uint8s to shrink by |
Immediately shrinks a memory chunk by moving the base address, without relocating any memory. Always succeeds.
| Chunk | Chunk to shrink |
| ShrinkAmount | Number of bytes to shrink by |
|
protected |
Sorts the freelist based on increasing base address.
| NumFreeChunks | [out] Number of free chunks |
| LargestFreeChunk | [out] Size of the largest free chunk, in uint8s |
Sorts the freelist based on increasing base address.
| NumFreeChunks | [out] Number of free chunks |
| LargestFreeChunk | [out] Size of the largest free chunk, in bytes |
|
inlineprotected |
Split allocation into two, first chunk being used and second being available. Maint32ains the free-list order if bSortedFreeList is true.
| BaseChunk | Chunk to split |
| FirstSize | New size of first chunk |
| bSortedFreeList | If true, maint32ains the free-list order |
|
virtual |
Partially defragments the memory and tries to process all async reallocation requests at the same time. Call this once per frame.
| Stats | [out] Stats |
| bPanicDefrag | If true, performs a full defrag and ignores all reallocation requests |
Partially defragments the memory and tries to process all async reallocation requests at the same time. Call this once per frame.
| Stats | [out] Stats |
| bPanicDefrag | If true, performs a full defrag and ignores all reallocation requests |
Unlocks an FMemoryChunk
| Pointer | Pointer indicating which chunk to unlock |
|
protected |
Allocation alignment requirements.
|
protected |
When in benchmark mode, don't call any Platform functions.
|
protected |
Amount of time blocked by a platform fence since the beginning of the last call to Tick(), in appCycles.
|
protected |
Sync index that has been completed, so far.
|
protected |
|
protected |
|
protected |
Ever-increasing index to synchronize all relocations initiated by Tick().
|
protected |
Head of linked list of chunks. Sorted by memory address.
|
protected |
Head of linked list of free chunks. Unsorted.
|
protected |
|
protected |
Last chunk in the linked list of chunks (see FirstChunk).
|
protected |
Maximum number of disjoint32 free memory regions we've had.
|
protected |
Base of memory pool.
|
protected |
Total size of memory pool, in uint8s.
|
protected |
Smallest consecutive free memory region we've had.
|
protected |
Total number of async requests that has been canceled so far.
|
protected |
Total number of async allocations successfully completed so far.
|
protected |
Total number of async reallocations successfully completed so far.
|
protected |
|
protected |
Number of async relocations that are currently in progress.
|
protected |
Chunks that couldn't be freed immediately because they were being relocated.
Adjustment to allocated memory, pending all reallocations.
|
protected |
Platform-specific (GPU) fence, used for synchronizing the Sync Index.
|
protected |
Mapping from Pointer to chunk for fast removal.
|
protected |
Allocator settings that affect its behavior.
|
protected |
|
protected |
Cumulative time spent in allocator.
|
protected |
Total number of uint8s relocated so far.
|
protected |
Total number of relocations performed so far.