Navigation
API > API/Runtime > API/Runtime/RHI
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
| Name | FGPUDefragAllocator |
| Type | class |
| Header File | /Engine/Source/Runtime/RHI/Public/GPUDefragAllocator.h |
| Include Path | #include "GPUDefragAllocator.h" |
Syntax
class FGPUDefragAllocator
Constructors
| Name | Remarks | Include Path | Unreal Specifiers |
|---|---|---|---|
FGPUDefragAllocator() |
Constructor, zero initializing all member variables | GPUDefragAllocator.h |
Destructors
| Name | Remarks | Include Path | Unreal Specifiers |
|---|---|---|---|
virtual ~FGPUDefragAllocator() |
GPUDefragAllocator.h |
Classes
| Name | Remarks |
|---|---|
| FMemoryChunk | Contains information of a single allocation or free block. |
Structs
| Name | Remarks |
|---|---|
| FMemoryLayoutElement | |
| FRelocationStats | Container for allocator relocation stats. |
| FSettings | Container for allocator settings. |
Enums
Public
| Name | Remarks |
|---|---|
| EMemoryElementType |
Typedefs
| Name | Type | Remarks | Include Path |
|---|---|---|---|
| FRequestList | TDoubleLinkedList< FAsyncReallocationRequest * > | GPUDefragAllocator.h | |
| FRequestNode | TDoubleLinkedList< FAsyncReallocationRequest * >::TDoubleLinkedListNode | GPUDefragAllocator.h | |
| memsize_t | int64 | Allocated memory in uint8s. | GPUDefragAllocator.h |
Functions
Public
| Name | Remarks | Include Path | Unreal Specifiers |
|---|---|---|---|
virtual void * Allocate
(
int64 AllocationSize, |
Allocate physical memory. | GPUDefragAllocator.h | |
void Benchmark
(
int32 MinChunkSize, |
Performs a benchmark of the allocator and outputs the result to the log. | GPUDefragAllocator.h | |
void BlockOnAsyncReallocation
(
FAsyncReallocationRequest* Request |
Blocks the calling thread until the specified request has been completed. | GPUDefragAllocator.h | |
void CancelAsyncReallocation
(
FAsyncReallocationRequest* Request, |
Cancels the specified reallocation request. | GPUDefragAllocator.h | |
void DefragmentMemory
(
FRelocationStats& Stats |
Fully defragments the memory and blocks until it's done. | GPUDefragAllocator.h | |
void DumpAllocs
(
FOutputDevice& Ar |
Dump allocation information. | GPUDefragAllocator.h | |
bool FinishAllRelocations() |
Blocks the calling thread until all relocations and reallocations that were initiated by Tick() have completed. | GPUDefragAllocator.h | |
virtual void Free
(
void* Pointer |
Frees allocation associated with the specified Pointer. | GPUDefragAllocator.h | |
int64 GetAllocatedSize
(
void* Pointer |
Returns the amount of memory allocated for the specified address. | GPUDefragAllocator.h | |
int32 GetAllocationAlignment() |
GPUDefragAllocator.h | ||
uint32 GetBlockedCycles() |
Returns the amount of time blocked by a platform fence since the beginning of the last call to Tick(), in appCycles. | GPUDefragAllocator.h | |
EMemoryElementType GetChunkType
(
FMemoryChunk* Chunk |
GPUDefragAllocator.h | ||
int32 GetLargestAvailableAllocation
(
int32* OutNumFreeChunks |
Scans the free chunks and returns the largest size you can allocate. | GPUDefragAllocator.h | |
void GetMemoryLayout
(
TArray< FMemoryLayoutElement >& MemoryLayout |
GPUDefragAllocator.h | ||
virtual void GetMemoryStats
(
int64& OutAllocatedMemorySize, |
Retrieves allocation stats. | GPUDefragAllocator.h | |
void GetSettings
(
FSettings& OutSettings |
Returns the current allocator settings. | GPUDefragAllocator.h | |
bool GetTextureMemoryVisualizeData
(
FColor* TextureData, |
Fills a texture with to visualize the texture pool memory. | GPUDefragAllocator.h | |
int64 GetTotalSize() |
GPUDefragAllocator.h | ||
void * GetUserPayload
(
const void* Pointer |
Returns the user payload for an FMemoryChunk | GPUDefragAllocator.h | |
bool InBenchmarkMode() |
Returns whether we're in benchmark mode or not. | GPUDefragAllocator.h | |
virtual void Initialize
(
uint8* InMemoryBase, |
GPUDefragAllocator.h | ||
virtual void Initialize
(
uint8* InMemoryBase, |
Initialize this allocator with a preallocated block of memory. | GPUDefragAllocator.h | |
bool IsInitialized() |
Returns whether allocator has been initialized. | GPUDefragAllocator.h | |
bool IsValidPoolMemory
(
const void* Pointer |
GPUDefragAllocator.h | ||
virtual void Lock
(
const void* Pointer |
Locks an FMemoryChunk | GPUDefragAllocator.h | |
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. | GPUDefragAllocator.h | |
void SetSettings
(
const FSettings& InSettings |
Sets new allocator settings. | GPUDefragAllocator.h | |
void SetUserPayload
(
const void* Pointer, |
Sets the user payload for an FMemoryChunk | GPUDefragAllocator.h | |
virtual int32 Tick
(
FRelocationStats& Stats, |
Partially defragments the memory and tries to process all async reallocation requests at the same time. | GPUDefragAllocator.h | |
virtual void Unlock
(
const void* Pointer |
Unlocks an FMemoryChunk | GPUDefragAllocator.h |
Protected
| Name | Remarks | Include Path | Unreal Specifiers |
|---|---|---|---|
FMemoryChunk * AllocateChunk
(
FMemoryChunk* FreeChunk, |
Marks the specified chunk as 'allocated' and updates tracking variables. | GPUDefragAllocator.h | |
void BlockOnFence() |
Blocks the calling thread until the current sync fence has been completed. | GPUDefragAllocator.h | |
void BlockOnSyncIndex
(
uint32 SyncIndex |
Blocks the calling thread until the specified sync index has been completed. | GPUDefragAllocator.h | |
bool CanRelocate
(
const FMemoryChunk* Chunk |
Returns true if the specified chunk is allowed to relocate at this time. | GPUDefragAllocator.h | |
void CheckForErrors
(
bool bCheckSortedFreeList |
Checks the int32ernal state for errors. (Slow)Checks the internal state for errors. (Slow) | GPUDefragAllocator.h | |
void Coalesce
(
FMemoryChunk* FreedChunk |
Merges any adjacent free chunks into the specified free chunk. | GPUDefragAllocator.h | |
FMemoryChunk * FindAdjacent
(
FMemoryChunk* UsedChunk, |
Defrag helper function. Checks if the specified allocation fits within the adjacent free chunk(s). | GPUDefragAllocator.h | |
FMemoryChunk * FindAdjacentToHole
(
FMemoryChunk* FreeChunk |
Searches for an allocated chunk that would fit within the specified free chunk. | GPUDefragAllocator.h | |
FMemoryChunk * FindAny
(
FMemoryChunk* FreeChunk |
Searches for an allocated chunk that would fit within the specified free chunk. | GPUDefragAllocator.h | |
void FreeChunk
(
FMemoryChunk* Chunk |
Marks the specified chunk as 'free' and updates tracking variables. | GPUDefragAllocator.h | |
void FullDefragmentation
(
FRelocationStats& Stats |
Performs a full defrag and ignores all reallocation requests. | GPUDefragAllocator.h | |
uint32 GetCurrentSyncIndex() |
Returns the sync index to be completed by the next call to FinishAllRelocations(). | GPUDefragAllocator.h | |
FMemoryChunk * Grow
(
FMemoryChunk* Chunk, |
Tries to immediately grow a memory chunk by moving the base address, without relocating any memory. | GPUDefragAllocator.h | |
void InsertFence() |
Inserts a platform fence and updates the allocator sync index to match. | GPUDefragAllocator.h | |
void LinkFreeChunk
(
FMemoryChunk* Chunk |
Frees the passed in chunk and coalesces adjacent free chunks into 'Chunk' if possible. | GPUDefragAllocator.h | |
void PartialDefragmentationDownshift
(
FRelocationStats& Stats, |
Performs a partial defrag by shifting down memory to fill holes, in a brute-force manner. | GPUDefragAllocator.h | |
void PartialDefragmentationFast
(
FRelocationStats& Stats, |
Performs a partial defrag doing fast checks only. Adjacency and freelist walk. | GPUDefragAllocator.h | |
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. | GPUDefragAllocator.h | |
void PlatformBlockOnFence
(
uint64 Fence |
Blocks the calling thread until all relocations initiated before the fence was added has been fully completed. | GPUDefragAllocator.h | |
bool PlatformCanRelocate
(
const void* Source, |
Allows each platform to decide whether an allocation can be relocated at this time. | GPUDefragAllocator.h | |
uint64 PlatformInsertFence () |
Inserts a fence to synchronize relocations. | GPUDefragAllocator.h | |
void PlatformNotifyReallocationFinished
(
FAsyncReallocationRequest* FinishedRequest, |
Notifies the platform that an async reallocation request has been completed. | GPUDefragAllocator.h | |
void PlatformRelocate
(
void* Dest, |
Copy memory from one location to another. | GPUDefragAllocator.h | |
void Relocate
(
FRelocationStats& Stats, |
Copy memory from one location to another. | GPUDefragAllocator.h | |
FMemoryChunk * RelocateAllowed
(
FMemoryChunk* FreeChunk, |
Performs a partial defrag while trying to process any pending async reallocation requests. | GPUDefragAllocator.h | |
FMemoryChunk * RelocateIntoFreeChunk
(
FRelocationStats& Stats, |
Initiates an async relocation of an allocated chunk into a free chunk. | GPUDefragAllocator.h | |
FMemoryChunk * Shrink
(
FMemoryChunk* Chunk, |
Immediately shrinks a memory chunk by moving the base address, without relocating any memory. | GPUDefragAllocator.h | |
void SortFreeList
(
int32& NumFreeChunks, |
Sorts the freelist based on increasing base address. | GPUDefragAllocator.h | |
void Split
(
FMemoryChunk* BaseChunk, |
Split allocation into two, first chunk being used and second being available. | GPUDefragAllocator.h |
Static
| Name | Remarks | Include Path | Unreal Specifiers |
|---|---|---|---|
static bool IsAligned
(
const volatile void* Ptr, |
GPUDefragAllocator.h |