UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
GPUDefragAllocator.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
5#include "CoreMinimal.h"
7#include "Stats/Stats.h"
10#include "Containers/List.h"
13
14#define LOG_EVERY_ALLOCATION 0
15#define DUMP_ALLOC_FREQUENCY 0 // 100
16
17#define VALIDATE_SYNC_SIZE 0 //validates that the CPU is returning memory in an allocate that's part of an active GPU move.
18#define VALIDATE_MOVES 0 //validates that GPU moves in a given frame do not overlap destination areas.
19#define TRACK_RELOCATIONS (VALIDATE_SYNC_SIZE || VALIDATE_MOVES)
20#define VALIDATE_MEMORY_PROTECTION 0
21
22#define USE_ALLOCATORFIXEDSIZEFREELIST 0
23
26
27/*-----------------------------------------------------------------------------
28Custom fixed size pool best fit texture memory allocator
29-----------------------------------------------------------------------------*/
30
31// Forward declaration
33
43{
44public:
45
48
68
79
81 {
83 : Size(0)
85 {
86 }
94
96 {
97 Ar << Element.Size;
98 uint32 ElementType = Element.Type;
99 Ar << ElementType;
100 Element.Type = EMemoryElementType(ElementType);
101 return Ar;
102 }
103 };
104
138
143 {
144 public:
171
176 {
177 // Remove from linked lists.
178 Unlink();
179 UnlinkFree();
180 //todo: add check for numlocks == 0
181 }
182
183 bool IsLocked() const
184 {
185 return (LockCount != 0);
186 }
187
194 {
196 {
200 if (NextChunk)
201 {
202 NextChunk->PreviousChunk = this;
203 }
204 else
205 {
207 }
208 }
209 else
210 {
211 PreviousChunk = nullptr;
212 NextChunk = nullptr;
213 ChunkToInsertAfter = this;
215 }
216 }
217
222
226 void Unlink()
227 {
228 if (PreviousChunk)
229 {
231 }
232 else
233 {
235 }
236
237 if (NextChunk)
238 {
240 }
241 else
242 {
244 }
245
246 PreviousChunk = nullptr;
247 NextChunk = nullptr;
248 }
249
254 {
256 bIsAvailable = false;
257
259 {
261 }
262 else
263 {
265 }
266
267 if (NextFreeChunk)
268 {
270 }
271
272 PreviousFreeChunk = nullptr;
273 NextFreeChunk = nullptr;
274 }
275
279 bool IsRelocating() const
280 {
282 }
283
288 {
289 if (bIsAvailable)
290 {
291 return IsRelocating() ? (Size - SyncSize) : Size;
292 }
293 else
294 {
295 return 0;
296 }
297 }
298
302 int64 GetFinalSize() const;
303
314
319 {
320 return SyncIndex;
321 }
322
326 static uint64 Compare(const FMemoryChunk* A, const FMemoryChunk* B)
327 {
328 return B->Base - A->Base;
329 }
330
331#if USE_ALLOCATORFIXEDSIZEFREELIST
333 void* operator new(size_t Size);
334 void operator delete(void *RawMemory);
335#endif
336
348
355
362
367
368 //stat associated with this allocation
370 bool bTail;
371 };
372
403
405 {
406 }
407
416 {
417 // Update size, Pointer and alignment.
422
423 // Update stats in a thread safe way.
424 FPlatformAtomics::InterlockedExchange(&AvailableMemorySize, MemorySize);
425 // Allocate initial chunk.
428 }
429
434
444
451 {
453 }
454
459 {
460 return MemoryBase != nullptr;
461 }
462
470 virtual void* Allocate(int64 AllocationSize, int32 Alignment, TStatId InStat, bool bAllowFailure);
471
477 virtual void Free(void* Pointer);
478
484 virtual void Lock(const void* Pointer);
485
491 virtual void Unlock(const void* Pointer);
492
499 void SetUserPayload(const void* Pointer, void* UserPayload);
500
507 void* GetUserPayload(const void* Pointer);
508
515 int64 GetAllocatedSize(void* Pointer);
516
525 void* Reallocate(void* OldBaseAddress, int64 NewSize);
526
527 bool IsValidPoolMemory(const void* Pointer) const
528 {
529 return (Pointer != nullptr) && (Pointer >= MemoryBase) && (Pointer < (MemoryBase + MemorySize));
530 }
531
532#if 0
542#endif
543
547 void DumpAllocs(FOutputDevice& Ar = *GLog);
548
563
565 {
566 return MemorySize;
567 }
568
576
581 {
582 return BlockedCycles;
583 }
584
588 bool InBenchmarkMode() const
589 {
590 return bBenchmarkMode;
591 }
592
604 bool GetTextureMemoryVisualizeData(FColor* TextureData, int32 SizeX, int32 SizeY, int32 Pitch, const int32 PixelSize);
605
607
608 EMemoryElementType GetChunkType(FMemoryChunk* Chunk) const;
609
615 void DefragmentMemory(FRelocationStats& Stats);
616
625 virtual int32 Tick(FRelocationStats& Stats, bool bPanicDefrag);
626
633
640
651
663 void Benchmark(int32 MinChunkSize, int32 MaxChunkSize, float FreeRatio, float LockRatio, bool bFullDefrag, bool bSaveImages, const TCHAR* Filename);
664
665 static inline bool IsAligned(const volatile void* Ptr, const uint32 Alignment)
666 {
667 return !(UPTRINT(Ptr) & (Alignment - 1));
668 }
669
671 {
672 return AllocationAlignment;
673 }
674
675protected:
676
677#if TRACK_RELOCATIONS
678 struct FRelocationEntry
679 {
681
682 const uint8* OldBase;
683 const uint8* NewBase;
684 uint64 Size;
685 uint64 SyncIndex;
686 };
687
689
691#endif
692
693#if VALIDATE_MEMORY_PROTECTION
694 struct FMemProtectTracker
695 {
698 , UserPayload(InUserPayload)
699 , BlockSize(InBlockSize)
700 , SyncIndex(InSyncIndex)
701 {
702
703 }
704 const void* Memory;
705 const void* UserPayload;
706 uint64 BlockSize;
707 uint32 SyncIndex;
708 };
709
712
715
718
721
724
727
731#endif
732
733
744 virtual void PlatformRelocate(void* Dest, const void* Source, int64 Size, void* UserPayload) = 0;
745
746
747
756
763 virtual void PlatformBlockOnFence(uint64 Fence) = 0;
764
772 virtual bool PlatformCanRelocate(const void* Source, void* UserPayload) const = 0;
773
780 virtual void PlatformNotifyReallocationFinished(FAsyncReallocationRequest* FinishedRequest, void* UserPayload) = 0;
781
794 void Relocate(FRelocationStats& Stats, FMemoryChunk* Dest, int64 DestOffset, const void* Source, int64 Size, void* UserPayload)
795 {
798 LLM_IF_ENABLED(FLowLevelMemTracker::Get().OnLowLevelAllocMoved(ELLMTracker::Default, Dest->Base, Source));
799
800 uint8* DestAddr = Dest->Base + DestOffset;
801 int64 MemDistance = (int64)(DestAddr) - (int64)(Source);
802 int64 AbsDistance = FMath::Abs(MemDistance);
804
805 if (!bBenchmarkMode)
806 {
807#if VALIDATE_MEMORY_PROTECTION
808 BlocksToProtect.Emplace(DestAddr, UserPayload, Size, CurrentSyncIndex);
809 BlocksToProtect.Emplace(Source, UserPayload, Size, CurrentSyncIndex);
810#endif
811 PlatformRelocate(DestAddr, Source, Size, UserPayload);
812 }
814 Dest->UserPayload = UserPayload;
816 Stats.NumRelocations++;
817 }
818
823 {
824 return CurrentSyncIndex;
825 }
826
833 void PartialDefragmentationFast(FRelocationStats& Stats, double StartTime);
834
842 void PartialDefragmentationSlow(FRelocationStats& Stats, double StartTime);
843
851 void PartialDefragmentationDownshift(FRelocationStats& Stats, double StartTime);
852
858 void FullDefragmentation(FRelocationStats& Stats);
859
867 FMemoryChunk* Grow(FMemoryChunk* Chunk, int64 GrowAmount);
868
877 FMemoryChunk* Shrink(FMemoryChunk* Chunk, int64 ShrinkAmount);
878
885
893 bool CanRelocate(const FMemoryChunk* Chunk) const;
894
898 void InsertFence();
899
903 void BlockOnFence();
904
910 void BlockOnSyncIndex(uint32 SyncIndex);
911
921 {
924 check(FirstSize > 0);
925
926 // Don't make any assumptions on the following chunk. Because Reallocate() will make the 1st chunk free
927 // and the 2nd chunk used, so it's ok to have the following chunk free. Note, this only happens when Reallocate()
928 // is splitting the very first chunk in the pool.
929 // Don't make any assumptions for the previous chunk either...
930 // check( !BaseChunk->NextChunk || !BaseChunk->NextChunk->bIsAvailable );
931 // check( !BaseChunk->PreviousChunk || !BaseChunk->PreviousChunk->bIsAvailable || !BaseChunk->bIsAvailable );
932
933 // Calculate size of second chunk...
935 // ... and create it.
936
937 //todo: fix stats
938 //ensureMsgf(BaseChunk->Stat.IsNone(), TEXT("Free chunk has stat"));
940
941 // Keep the original sync index for the new chunk if necessary.
942 if (BaseChunk->IsRelocating() && BaseChunk->SyncSize > FirstSize)
943 {
945 NewFreeChunk->SetSyncIndex(BaseChunk->SyncIndex, SecondSyncSize);
946 }
947 BaseChunk->SetSyncIndex(BaseChunk->SyncIndex, FMath::Min((int64)FirstSize, BaseChunk->SyncSize));
948
949 // Resize base chunk.
950 BaseChunk->Size = FirstSize;
951 } //-V773
952
962 FMemoryChunk* AllocateChunk(FMemoryChunk* FreeChunk, int64 AllocationSize, bool bAsync, bool bDoValidation = true);
963
970 void FreeChunk(FMemoryChunk* Chunk);
971
980 {
981 check(Chunk);
982 // Mark chunk as available.
983 Chunk->LinkFree(nullptr);
984 // Kick of merge pass.
985 Coalesce(Chunk);
986 }
987
994 void Coalesce(FMemoryChunk* FreedChunk);
995
1003
1012 FMemoryChunk* FindAdjacent(FMemoryChunk* UsedChunk, bool bAnyChunkType);
1013
1023 FMemoryChunk* FindAdjacentToHole(FMemoryChunk* FreeChunk);
1024
1033 FMemoryChunk* FindAny(FMemoryChunk* FreeChunk);
1034
1044 FMemoryChunk* RelocateIntoFreeChunk(FRelocationStats& Stats, FMemoryChunk* FreeChunk, FMemoryChunk* UsedChunk);
1045
1046 FMemoryChunk* RelocateAllowed(FMemoryChunk* FreeChunk, FMemoryChunk* UsedChunk);
1047
1049
1066
1068
1074
1077
1080
1085
1090
1093
1096
1097 // Stats
1114
1116
1117#if VALIDATE_MEMORY_PROTECTION
1118 double TimeInMemProtect;
1119#endif
1120
1123
1125};
1126
1127//FScopedGPUDefragLock can't cover any scope that will add dcb commands or we might deadlock.
1129{
1130public:
1132 : DefragAllocator(InDefragAllocator)
1133 {
1134 DefragAllocator.SynchronizationObject.Lock();
1135 }
1136
1138 {
1139 DefragAllocator.SynchronizationObject.Unlock();
1140 }
1141private:
1142 FGPUDefragAllocator& DefragAllocator;
1143};
1144
1151{
1152public:
1161 : OldAddress(InCurrentBaseAddress)
1162 , NewAddress(nullptr)
1163 , OldSize(0) // Set by AsyncReallocate()
1164 , NewSize(InNewSize)
1165 , int32ernalRequestStatus(1)
1166 , ExternalRequestStatus(InRequestStatus)
1167 , bIsCanceled(false)
1168 , MemoryChunk(nullptr)
1169 {
1170 }
1171
1177
1179 bool IsAllocation() const
1180 {
1181 return OldAddress == nullptr && OldSize == 0;
1182 }
1183
1185 bool IsReallocation() const
1186 {
1187 return OldAddress != nullptr;
1188 }
1189
1191 bool IsCanceled() const
1192 {
1193 return bIsCanceled;
1194 }
1195
1197 bool HasCompleted() const
1198 {
1199 bool bHasCompleted = int32ernalRequestStatus.GetValue() == 0;
1200 check(!bHasCompleted || NewAddress || bIsCanceled);
1201 return bHasCompleted;
1202 }
1203
1205 bool HasStarted() const
1206 {
1207 return NewAddress ? true : false;
1208 }
1209
1211 void* GetOldBaseAddress() const
1212 {
1213 return OldAddress;
1214 }
1215
1217 void* GetNewBaseAddress() const
1218 {
1219 return NewAddress;
1220 }
1221
1224 {
1225 return NewSize;
1226 }
1227
1228private:
1229 // Hidden on purpose since outside usage isn't necessarily thread-safe.
1231 void operator=(const FAsyncReallocationRequest& Other) { FMemory::Memcpy(this, &Other, sizeof(FAsyncReallocationRequest)); }
1232
1236 void MarkCompleted()
1237 {
1238 check(int32ernalRequestStatus.GetValue() == 1);
1239 int32ernalRequestStatus.Decrement();
1240 if (ExternalRequestStatus)
1241 {
1242 ExternalRequestStatus->Decrement();
1243 }
1244 }
1245
1247 void* OldAddress;
1249 void* NewAddress;
1251 int32 OldSize;
1253 int32 NewSize;
1255 FThreadSafeCounter int32ernalRequestStatus;
1257 FThreadSafeCounter* ExternalRequestStatus;
1259 uint32 bIsCanceled : 1;
1260
1265 class FGPUDefragAllocator::FMemoryChunk* MemoryChunk;
1266
1268};
1269
1270
1275{
1276 return Size;
1277}
1278
1286inline bool FGPUDefragAllocator::CanRelocate(const FMemoryChunk* Chunk) const
1287{
1288 if (Chunk->IsLocked())
1289 {
1290 return false;
1291 }
1292
1293 if (!bBenchmarkMode)
1294 {
1295 return PlatformCanRelocate(Chunk->Base, Chunk->UserPayload);
1296 }
1297 else
1298 {
1299 return true;
1300 }
1301}
1302
1309{
1310 check(Request->HasStarted());
1311 if (!Request->HasCompleted())
1312 {
1313 BlockOnSyncIndex(Request->MemoryChunk->SyncIndex);
1314 }
1315}
constexpr T Align(T Val, uint64 Alignment)
Definition AlignmentTemplates.h:18
#define check(expr)
Definition AssertionMacros.h:314
void * DestAddr
Definition BlueprintTypeConversions.cpp:389
#define GLog
Definition CoreGlobals.h:95
FPlatformTypes::TCHAR TCHAR
Either ANSICHAR or WIDECHAR, depending on whether the platform supports wide characters or the requir...
Definition Platform.h:1135
FPlatformTypes::int64 int64
A 64-bit signed integer.
Definition Platform.h:1127
FPlatformTypes::int32 int32
A 32-bit signed integer.
Definition Platform.h:1125
FPlatformTypes::UPTRINT UPTRINT
An unsigned integer the same size as a pointer.
Definition Platform.h:1146
FPlatformTypes::uint64 uint64
A 64-bit unsigned integer.
Definition Platform.h:1117
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
UE::FPlatformRecursiveMutex FCriticalSection
Definition CriticalSection.h:53
return true
Definition ExternalRpcRegistry.cpp:601
#define LLM_IF_ENABLED(...)
Definition LowLevelMemTracker.h:1093
void MemoryTrace_ReallocAlloc(uint64 Address, uint64 NewSize, uint32 Alignment, HeapId RootHeap=EMemoryTraceRootHeap::SystemMemory, uint32 ExternalCallstackId=0)
Definition MemoryTrace.h:202
void MemoryTrace_ReallocFree(uint64 Address, HeapId RootHeap=EMemoryTraceRootHeap::SystemMemory, uint32 ExternalCallstackId=0)
Definition MemoryTrace.h:201
#define MAX_int64
Definition NumericLimits.h:26
FRWLock Lock
Definition UnversionedPropertySerialization.cpp:921
uint32 Size
Definition VulkanMemory.cpp:4034
uint8_t uint8
Definition binka_ue_file_header.h:8
uint16_t uint16
Definition binka_ue_file_header.h:7
uint32_t uint32
Definition binka_ue_file_header.h:6
Definition Archive.h:1208
Definition GPUDefragAllocator.h:1151
bool HasCompleted() const
Definition GPUDefragAllocator.h:1197
bool HasStarted() const
Definition GPUDefragAllocator.h:1205
bool IsAllocation() const
Definition GPUDefragAllocator.h:1179
int32 GetNewSize() const
Definition GPUDefragAllocator.h:1223
FAsyncReallocationRequest(void *InCurrentBaseAddress, int32 InNewSize, FThreadSafeCounter *InRequestStatus)
Definition GPUDefragAllocator.h:1160
void * GetNewBaseAddress() const
Definition GPUDefragAllocator.h:1217
~FAsyncReallocationRequest()
Definition GPUDefragAllocator.h:1173
void * GetOldBaseAddress() const
Definition GPUDefragAllocator.h:1211
bool IsCanceled() const
Definition GPUDefragAllocator.h:1191
bool IsReallocation() const
Definition GPUDefragAllocator.h:1185
Definition IConsoleManager.h:1580
Definition GPUDefragAllocator.h:143
uint32 GetSyncIndex() const
Definition GPUDefragAllocator.h:318
void SetSyncIndex(uint32 InSyncIndex, int64 InSyncSize)
Definition GPUDefragAllocator.h:309
int64 OrigSize
Definition GPUDefragAllocator.h:341
FMemoryChunk(uint8 *InBase, int64 InSize, FGPUDefragAllocator &InBestFitAllocator, FMemoryChunk *&ChunkToInsertAfter, TStatId InStat)
Definition GPUDefragAllocator.h:153
int64 Size
Definition GPUDefragAllocator.h:340
int32 LockCount
Definition GPUDefragAllocator.h:345
bool IsLocked() const
Definition GPUDefragAllocator.h:183
void Link(FMemoryChunk *&ChunkToInsertAfter)
Definition GPUDefragAllocator.h:193
FMemoryChunk * PreviousChunk
Definition GPUDefragAllocator.h:352
uint32 SyncIndex
Definition GPUDefragAllocator.h:361
bool IsRelocating() const
Definition GPUDefragAllocator.h:279
uint16 DefragCounter
Definition GPUDefragAllocator.h:347
int64 GetFinalSize() const
Definition GPUDefragAllocator.h:1274
~FMemoryChunk()
Definition GPUDefragAllocator.h:175
bool bTail
Definition GPUDefragAllocator.h:370
int64 GetAvailableSize() const
Definition GPUDefragAllocator.h:287
FMemoryChunk * NextChunk
Definition GPUDefragAllocator.h:354
uint8 * Base
Definition GPUDefragAllocator.h:338
int64 SyncSize
Definition GPUDefragAllocator.h:364
FMemoryChunk * NextFreeChunk
Definition GPUDefragAllocator.h:359
void Unlink()
Definition GPUDefragAllocator.h:226
bool bIsAvailable
Definition GPUDefragAllocator.h:343
TStatId Stat
Definition GPUDefragAllocator.h:369
FGPUDefragAllocator & BestFitAllocator
Definition GPUDefragAllocator.h:350
void LinkFree(FMemoryChunk *FirstFreeChunkToSearch)
Definition GPUDefragAllocator.cpp:71
void UnlinkFree()
Definition GPUDefragAllocator.h:253
FMemoryChunk * PreviousFreeChunk
Definition GPUDefragAllocator.h:357
static uint64 Compare(const FMemoryChunk *A, const FMemoryChunk *B)
Definition GPUDefragAllocator.h:326
void * UserPayload
Definition GPUDefragAllocator.h:366
Definition GPUDefragAllocator.h:43
void Split(FMemoryChunk *BaseChunk, int64 FirstSize)
Definition GPUDefragAllocator.h:920
EMemoryElementType
Definition GPUDefragAllocator.h:70
@ MET_Resized
Definition GPUDefragAllocator.h:76
@ MET_Locked
Definition GPUDefragAllocator.h:73
@ MET_Max
Definition GPUDefragAllocator.h:77
@ MET_Relocating
Definition GPUDefragAllocator.h:74
@ MET_Free
Definition GPUDefragAllocator.h:72
@ MET_Resizing
Definition GPUDefragAllocator.h:75
@ MET_Allocated
Definition GPUDefragAllocator.h:71
volatile memsize_t AllocatedMemorySize
Definition GPUDefragAllocator.h:1069
int64 GetAllocatedSize(void *Pointer)
Definition GPUDefragAllocator.cpp:475
void GetSettings(FSettings &OutSettings)
Definition GPUDefragAllocator.h:440
int32 GetAllocationAlignment() const
Definition GPUDefragAllocator.h:670
int32 NumLockedChunks
Definition GPUDefragAllocator.h:1115
FMemoryChunk * FindAny(FMemoryChunk *FreeChunk)
Definition GPUDefragAllocator.cpp:826
TDoubleLinkedList< FAsyncReallocationRequest * >::TDoubleLinkedListNode FRequestNode
Definition GPUDefragAllocator.h:47
void BlockOnFence()
Definition GPUDefragAllocator.cpp:1210
bool InBenchmarkMode() const
Definition GPUDefragAllocator.h:588
void FullDefragmentation(FRelocationStats &Stats)
Definition GPUDefragAllocator.cpp:1458
void BlockOnAsyncReallocation(FAsyncReallocationRequest *Request)
Definition GPUDefragAllocator.h:1308
int32 NumFinishedAsyncReallocations
Definition GPUDefragAllocator.h:1107
static bool IsAligned(const volatile void *Ptr, const uint32 Alignment)
Definition GPUDefragAllocator.h:665
uint64 CurrentSyncIndex
Definition GPUDefragAllocator.h:1082
FMemoryChunk * FirstFreeChunk
Definition GPUDefragAllocator.h:1061
FCriticalSection SynchronizationObject
Definition GPUDefragAllocator.h:1048
void GetMemoryLayout(TArray< FMemoryLayoutElement > &MemoryLayout)
Definition GPUDefragAllocator.cpp:1741
FMemoryChunk * RelocateIntoFreeChunk(FRelocationStats &Stats, FMemoryChunk *FreeChunk, FMemoryChunk *UsedChunk)
Definition GPUDefragAllocator.cpp:936
bool CanRelocate(const FMemoryChunk *Chunk) const
Definition GPUDefragAllocator.h:1286
void Benchmark(int32 MinChunkSize, int32 MaxChunkSize, float FreeRatio, float LockRatio, bool bFullDefrag, bool bSaveImages, const TCHAR *Filename)
Definition GPUDefragAllocator.cpp:1926
uint64 MemorySize
Definition GPUDefragAllocator.h:1051
uint8 * MemoryBase
Definition GPUDefragAllocator.h:1053
virtual void PlatformNotifyReallocationFinished(FAsyncReallocationRequest *FinishedRequest, void *UserPayload)=0
void * Reallocate(void *OldBaseAddress, int64 NewSize)
Definition GPUDefragAllocator.cpp:489
EMemoryElementType GetChunkType(FMemoryChunk *Chunk) const
Definition GPUDefragAllocator.cpp:1753
FMemoryChunk * AllocateChunk(FMemoryChunk *FreeChunk, int64 AllocationSize, bool bAsync, bool bDoValidation=true)
Definition GPUDefragAllocator.cpp:239
void BlockOnSyncIndex(uint32 SyncIndex)
Definition GPUDefragAllocator.cpp:1234
int64 MinLargestHole
Definition GPUDefragAllocator.h:1103
bool bBenchmarkMode
Definition GPUDefragAllocator.h:1122
uint32 GetBlockedCycles() const
Definition GPUDefragAllocator.h:580
virtual void Unlock(const void *Pointer)
Definition GPUDefragAllocator.cpp:420
uint32 BlockedCycles
Definition GPUDefragAllocator.h:1113
int32 AllocationAlignment
Definition GPUDefragAllocator.h:1055
bool GetTextureMemoryVisualizeData(FColor *TextureData, int32 SizeX, int32 SizeY, int32 Pitch, const int32 PixelSize)
Definition GPUDefragAllocator.cpp:1686
FMemoryChunk * FindAdjacentToHole(FMemoryChunk *FreeChunk)
Definition GPUDefragAllocator.cpp:789
void SortFreeList(int32 &NumFreeChunks, int64 &LargestFreeChunk)
Definition GPUDefragAllocator.cpp:706
double TimeSpentInAllocator
Definition GPUDefragAllocator.h:1063
bool IsInitialized()
Definition GPUDefragAllocator.h:458
FGPUDefragAllocator()
Definition GPUDefragAllocator.h:374
virtual void GetMemoryStats(int64 &OutAllocatedMemorySize, int64 &OutAvailableMemorySize, int64 &OutPendingMemoryAdjustment, int64 &OutPaddingWasteSize)
Definition GPUDefragAllocator.h:556
virtual ~FGPUDefragAllocator()
Definition GPUDefragAllocator.h:404
volatile memsize_t AvailableMemorySize
Definition GPUDefragAllocator.h:1071
int64 GetTotalSize() const
Definition GPUDefragAllocator.h:564
FMemoryChunk * FindAdjacent(FMemoryChunk *UsedChunk, bool bAnyChunkType)
Definition GPUDefragAllocator.cpp:753
void SetUserPayload(const void *Pointer, void *UserPayload)
Definition GPUDefragAllocator.cpp:436
uint64 CurrentLargestHole
Definition GPUDefragAllocator.h:1094
virtual void PlatformRelocate(void *Dest, const void *Source, int64 Size, void *UserPayload)=0
void LinkFreeChunk(FMemoryChunk *Chunk)
Definition GPUDefragAllocator.h:979
uint64 PlatformSyncFence
Definition GPUDefragAllocator.h:1089
void InsertFence()
Definition GPUDefragAllocator.cpp:1181
FSettings Settings
Definition GPUDefragAllocator.h:1079
FMemoryChunk * LastChunk
Definition GPUDefragAllocator.h:1059
TDoubleLinkedList< FAsyncReallocationRequest * > FRequestList
Definition GPUDefragAllocator.h:46
bool FinishAllRelocations()
Definition GPUDefragAllocator.cpp:1154
virtual uint64 PlatformInsertFence()=0
volatile memsize_t PendingMemoryAdjustment
Definition GPUDefragAllocator.h:1073
uint64 TotalNumRelocations
Definition GPUDefragAllocator.h:1099
void CancelAsyncReallocation(FAsyncReallocationRequest *Request, const void *CurrentBaseAddress)
void FreeChunk(FMemoryChunk *Chunk)
Definition GPUDefragAllocator.cpp:319
int64 memsize_t
Definition GPUDefragAllocator.h:1065
bool IsValidPoolMemory(const void *Pointer) const
Definition GPUDefragAllocator.h:527
int32 NumFinishedAsyncAllocations
Definition GPUDefragAllocator.h:1109
void Coalesce(FMemoryChunk *FreedChunk)
Definition GPUDefragAllocator.cpp:1842
FMemoryChunk * RelocateAllowed(FMemoryChunk *FreeChunk, FMemoryChunk *UsedChunk)
Definition GPUDefragAllocator.cpp:1282
TDoubleLinkedList< FMemoryChunk * > PendingFreeChunks
Definition GPUDefragAllocator.h:1092
friend FScopedGPUDefragLock
Definition GPUDefragAllocator.h:1124
volatile memsize_t PaddingWasteSize
Definition GPUDefragAllocator.h:1067
int32 GetLargestAvailableAllocation(int32 *OutNumFreeChunks=nullptr)
Definition GPUDefragAllocator.cpp:1785
void Relocate(FRelocationStats &Stats, FMemoryChunk *Dest, int64 DestOffset, const void *Source, int64 Size, void *UserPayload)
Definition GPUDefragAllocator.h:794
void PartialDefragmentationFast(FRelocationStats &Stats, double StartTime)
Definition GPUDefragAllocator.cpp:1297
void CheckForErrors(bool bCheckSortedFreeList)
Definition GPUDefragAllocator.cpp:865
TMap< void *, FMemoryChunk * > PointerToChunkMap
Definition GPUDefragAllocator.h:1076
virtual void PlatformBlockOnFence(uint64 Fence)=0
void DumpAllocs(FOutputDevice &Ar= *GLog)
Definition GPUDefragAllocator.cpp:1585
virtual bool PlatformCanRelocate(const void *Source, void *UserPayload) const =0
FMemoryChunk * FirstChunk
Definition GPUDefragAllocator.h:1057
int32 NumCanceledAsyncRequests
Definition GPUDefragAllocator.h:1111
uint32 GetCurrentSyncIndex() const
Definition GPUDefragAllocator.h:822
uint64 TotalNumBytesRelocated
Definition GPUDefragAllocator.h:1101
int32 MaxNumHoles
Definition GPUDefragAllocator.h:1105
int32 CurrentNumHoles
Definition GPUDefragAllocator.h:1095
virtual void Initialize(uint8 *InMemoryBase, int64 InMemorySize, int32 InAllocationAlignment)
Definition GPUDefragAllocator.h:415
void PartialDefragmentationDownshift(FRelocationStats &Stats, double StartTime)
Definition GPUDefragAllocator.cpp:1418
void DefragmentMemory(FRelocationStats &Stats)
Definition GPUDefragAllocator.cpp:1809
virtual void * Allocate(int64 AllocationSize, int32 Alignment, TStatId InStat, bool bAllowFailure)
Definition GPUDefragAllocator.cpp:138
void PartialDefragmentationSlow(FRelocationStats &Stats, double StartTime)
Definition GPUDefragAllocator.cpp:1356
uint64 CompletedSyncIndex
Definition GPUDefragAllocator.h:1084
void SetSettings(const FSettings &InSettings)
Definition GPUDefragAllocator.h:450
void * GetUserPayload(const void *Pointer)
Definition GPUDefragAllocator.cpp:457
int32 NumRelocationsInProgress
Definition GPUDefragAllocator.h:1087
virtual void Initialize(uint8 *InMemoryBase, int64 InMemorySize)
Definition GPUDefragAllocator.h:430
Definition OutputDevice.h:133
Definition GPUDefragAllocator.h:1129
~FScopedGPUDefragLock()
Definition GPUDefragAllocator.h:1137
FScopedGPUDefragLock(FGPUDefragAllocator &InDefragAllocator)
Definition GPUDefragAllocator.h:1131
Definition ThreadSafeCounter.h:14
int32 Decrement()
Definition ThreadSafeCounter.h:75
int32 GetValue() const
Definition ThreadSafeCounter.h:120
Definition Array.h:670
Definition List.h:439
Definition UnrealString.h.inl:34
@ false
Definition radaudio_common.h:23
Definition Color.h:486
Definition GPUDefragAllocator.h:81
FMemoryLayoutElement()
Definition GPUDefragAllocator.h:82
int32 Size
Definition GPUDefragAllocator.h:92
EMemoryElementType Type
Definition GPUDefragAllocator.h:93
FMemoryLayoutElement(int32 InSize, EMemoryElementType InType)
Definition GPUDefragAllocator.h:87
friend FArchive & operator<<(FArchive &Ar, FMemoryLayoutElement &Element)
Definition GPUDefragAllocator.h:95
Definition GPUDefragAllocator.h:109
int64 NumBytesRelocated
Definition GPUDefragAllocator.h:121
int64 LargestHoleSize
Definition GPUDefragAllocator.h:127
int64 NumBytesDownShifted
Definition GPUDefragAllocator.h:124
int32 NumRelocations
Definition GPUDefragAllocator.h:130
FRelocationStats()
Definition GPUDefragAllocator.h:110
int32 NumHoles
Definition GPUDefragAllocator.h:133
int32 NumLockedChunks
Definition GPUDefragAllocator.h:136
Definition GPUDefragAllocator.h:53
int32 MaxDefragDownShift
Definition GPUDefragAllocator.h:64
int32 OverlappedBandwidthScale
Definition GPUDefragAllocator.h:66
int32 MaxDefragRelocations
Definition GPUDefragAllocator.h:62
FSettings()
Definition GPUDefragAllocator.h:54
static UE_FORCEINLINE_HINT void * Memcpy(void *Dest, const void *Src, SIZE_T Count)
Definition UnrealMemory.h:160
Definition LightweightStats.h:416