5#include "Containers/Array.h"
13#if PLATFORM_64BITS && PLATFORM_HAS_FPlatformVirtualMemoryBlock
32#define BINNEDGPU_MAX_GMallocBinnedGPUMaxBundlesBeforeRecycle (8)
34#define COLLECT_BINNEDGPU_STATS (!UE_BUILD_SHIPPING)
36#if COLLECT_BINNEDGPU_STATS
47 uint64 AddressLimit = 1024 * 1024 * 1024;
85 struct PoolHashBucket;
112 , NextFreeBlock(nullptr)
120 return NumFreeBlocks;
124 return Canary == FFreeBlock::CANARY_VALUE;
127 inline void CanaryTest()
const
134 void CanaryFail()
const;
146 FFreeBlock* NextFreeBlock;
164 struct FPtrToPoolMapping
167 : PtrToPoolPageBitShift(0)
182 PtrToPoolPageBitShift = FPlatformMath::CeilLogTwo(
InPageSize);
185 MaxHashBuckets = AddressLimit >> HashKeyShift;
197 return MaxHashBuckets;
202 uint64 PtrToPoolPageBitShift;
213 FBundleNode* NextNodeInCurrentBundle;
234 inline void PushHead(FBundleNode* Node)
236 Node->NextNodeInCurrentBundle = Head;
237 Node->NextBundle =
nullptr;
242 inline FBundleNode* PopHead()
244 FBundleNode*
Result = Head;
247 Head = Head->NextNodeInCurrentBundle;
255 struct FFreeBlockList
268 FullBundle = PartialBundle;
269 PartialBundle.Reset();
281 if ((!PartialBundle.Head) & (!!FullBundle.Head))
283 PartialBundle = FullBundle;
287 if (PartialBundle.Head)
290 Result = Proxy->GPUMemory;
303 FBundle PartialBundle;
307 struct FPerThreadFreeBlockLists
316 FPerThreadFreeBlockLists(
uint32 PoolCount)
319 FreeLists.AddDefaulted(PoolCount);
350 int64 AllocatedMemory;
366 if (!FPlatformAtomics::InterlockedCompareExchangePointer((
void**)&Bundles[
InPoolIndex].FreeBundles[Slot],
InBundle,
nullptr))
382 if (FPlatformAtomics::InterlockedCompareExchangePointer((
void**)&Bundles[
InPoolIndex].FreeBundles[Slot],
nullptr, Result) == Result)
494 uint32 PoolIndex = BoundSizeToPoolIndex(AlignedSize);
524 CORE_API virtual bool IsInternallyThreadSafe()
const override;
527 Alignment = FMath::Max<uint32>(Alignment,
ArenaParams.MinimumAlignment);
538 uint32 PoolIndex = BoundSizeToPoolIndex(
Size);
540 Result = Lists->Malloc(*
this, PoolIndex);
543 Lists->AllocatedMemory += BlockSize;
548 if (Result ==
nullptr)
555 inline virtual void* Realloc(
void* Ptr,
SIZE_T NewSize,
uint32 Alignment)
override
557 check(!
"MallocBinnedGPU cannot realloc memory because the memory is assumed to not be writable by the CPU");
561 inline virtual void Free(
void* Ptr)
override
570 if (Lists->Free(*
this, Ptr, PoolIndex, BlockSize,
ArenaParams))
572 Lists->AllocatedMemory -= BlockSize;
579 inline virtual bool GetAllocationSize(
void *Ptr,
SIZE_T &
SizeOut)
override
587 return GetAllocationSizeExternal(Ptr,
SizeOut);
593 checkSlow((Alignment & (Alignment - 1)) == 0);
601 Alignment = FPlatformMath::Max<uint32>(Alignment,
ArenaParams.AllocationGranularity);
608 CORE_API virtual bool ValidateHeap()
override;
610 CORE_API virtual void SetupTLSCachesOnCurrentThread()
override;
611 CORE_API virtual void ClearAndDisableTLSCachesOnCurrentThread()
override;
615 CORE_API void FlushCurrentThreadCache();
617 CORE_API void FreeExternal(
void *Ptr);
647 PoolHashBucket* HashBuckets;
648 PoolHashBucket* HashBucketFreeList;
653 FPtrToPoolMapping PtrToPoolMapping;
692 void RegisterThreadFreeBlockLists(FPerThreadFreeBlockLists*
FreeBlockLists)
709#if UE_ENABLE_INCLUDE_ORDER_DEPRECATED_IN_5_7
OODEFFUNC typedef void(OODLE_CALLBACK t_fp_OodleCore_Plugin_Free)(void *ptr)
constexpr T Align(T Val, uint64 Alignment)
Definition AlignmentTemplates.h:18
constexpr bool IsAligned(T Val, uint64 Alignment)
Definition AlignmentTemplates.h:50
#define checkSlow(expr)
Definition AssertionMacros.h:332
#define check(expr)
Definition AssertionMacros.h:314
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
void Init()
Definition LockFreeList.h:4
#define BINNEDCOMMON_USE_SEPARATE_VM_PER_POOL
Definition MallocBinnedCommon.h:41
@ DEFAULT_ALIGNMENT
Definition MemoryBase.h:24
#define MAX_uint16
Definition NumericLimits.h:20
#define MAX_uint8
Definition NumericLimits.h:19
FRWLock Lock
Definition UnversionedPropertySerialization.cpp:921
uint32 Size
Definition VulkanMemory.cpp:4034
Definition MallocBinnedCommon.h:120
Definition MemoryBase.h:99
Definition OutputDevice.h:133
SizeType AddDefaulted()
Definition Array.h:2795
Definition AndroidPlatformMisc.h:14
Definition UniqueLock.h:20
UE::FRecursiveMutex Mutex
Definition MeshPaintVirtualTexture.cpp:164
FORCEINLINE T * Get(const FObjectPtr &ObjectPtr)
Definition ObjectPtr.h:426
Definition OverriddenPropertySet.cpp:45
UE_STRING_CLASS Result(Forward< LhsType >(Lhs), RhsLen)
Definition String.cpp.inl:732
FPThreadsRecursiveMutex FPlatformRecursiveMutex
Definition AndroidPlatformMutex.h:12
U16 Index
Definition radfft.cpp:71
static UE_FORCEINLINE_HINT void * GetTlsValue(uint32 SlotIndex)
Definition AndroidPlatformTLS.h:57
Definition MemoryMisc.h:21