19#define SIMPLE_STREAMABLE_ASSET_MANAGER_ALLOW_DEBUG_POINTER !(UE_BUILD_SHIPPING)
21template<
typename T, u
int32 N>
26 uint32 Reserve() {
return ReservedIndex.fetch_add(1, std::memory_order_acq_rel); }
37 while (!ReleasedIndex.compare_exchange_weak(Expected,
ToRelease + 1, std::memory_order_acq_rel))
45 while(ReleasedIndex.load(std::memory_order_acquire) < std::min(
MaxElements, ReservedIndex.load(std::memory_order_acquire))){}
51 std::atomic_uint32_t ReservedIndex = 0;
52 std::atomic_uint32_t ReleasedIndex = 0;
66 FStorageShard* Storage = Shard.load(std::memory_order_acquire);
78 if (StorageAllocatorGuard.compare_exchange_strong(Expected, 1, std::memory_order_acq_rel))
81 if (Shard.compare_exchange_strong(Storage,
NewStorage, std::memory_order_acq_rel))
85 LockedStorage.Add(Storage);
92 StorageAllocatorGuard.store(0, std::memory_order_release);
100 while (!StorageAllocatorGuard.compare_exchange_strong(Expected, 1, std::memory_order_acq_rel)){ Expected = 0; }
103 StorageAllocatorGuard.store(0, std::memory_order_release);
123 std::atomic_uint32_t StorageAllocatorGuard = 0;
124 std::atomic<FStorageShard*> Shard =
nullptr;
139 CriticalSection->Lock();
146 CriticalSection->Unlock();
151 bool bShouldLock =
false;
158#if SIMPLE_STREAMABLE_ASSET_MANAGER_ALLOW_DEBUG_POINTER
172 template<
typename TObject>
184#if SIMPLE_STREAMABLE_ASSET_MANAGER_ALLOW_DEBUG_POINTER
199 const void* InObject,
214#if SIMPLE_STREAMABLE_ASSET_MANAGER_ALLOW_DEBUG_POINTER
234 const void* InObject,
262 template<
typename TObject,
typename TPrimitive>
277#if SIMPLE_STREAMABLE_ASSET_MANAGER_ALLOW_DEBUG_POINTER
287#if SIMPLE_STREAMABLE_ASSET_MANAGER_ALLOW_DEBUG_POINTER
298 template <
typename T>
299 struct TSimpleSparseArray
303 if (UsedElementsCount == FreeElementIndexHint)
305 UsedElements.Add(
false, GSimpleStreamableAssetManagerSparseArrayGrowSize);
306 Elements.AddDefaulted(GSimpleStreamableAssetManagerSparseArrayGrowSize);
308 const int32 Index = UsedElements.FindAndSetFirstZeroBit(FreeElementIndexHint);
310 FreeElementIndexHint =
Index + 1;
318 if (UsedElements.Num() >
Index && UsedElements[
Index])
320 UsedElements[
Index] =
false;
321 FreeElementIndexHint = FMath::Min(FreeElementIndexHint,
Index);
322 Elements[
Index] = T{};
329 FreeElementIndexHint = 0;
330 UsedElementsCount = 0;
331 UsedElements.Empty();
335 int32 Num()
const {
return UsedElementsCount; }
339 return sizeof(TSimpleSparseArray)
340 + UsedElements.GetAllocatedSize()
341 + Elements.GetAllocatedSize();
346 const int32 Max = UsedElements.FindLast(
true);
350 int32 FreeElementIndexHint = 0;
351 int32 UsedElementsCount = 0;
360 ENGINE_API static int32 GSimpleStreamableAssetManagerSparseArrayGrowSize;
363 ENGINE_API static int32 GSimpleStreamableAssetManagerEnsureAssetUniqueOnRegistration;
366 ENGINE_API static int32 GSimpleStreamableAssetManagerConsiderVisibility;
378 int32 RegisteredObjectCount = 0;
379 int32 MaxObjects = 0;
381 int32 FreeObjectIndexHint = 0;
386 void RegisterRecord(FRegister& Record);
387 void UpdateRecord(FUpdate& Record);
388 void UpdateRecord(FUpdateLastRenderTime& Record);
389 void UnregisterRecord(FUnregister& Record);
392 void SetBounds(
int32 BoundsIndex,
const FBoxSphereBounds& Bounds,
uint32 PackedRelativeBox,
float StreamingScaleFactor,
float LastRenderTime,
const FVector4& RangeOrigin,
float MinDistanceSq,
float MinRangeSq,
float MaxRangeSq);
396 int32 FreeAssetIndexHint = 0;
397 int32 UsedAssetIndices = 0;
401 void RemoveRenderAssetElements(
int32 ObjectRegistrationIndex);
404 void TrySetLastRenderTime(
int32 BoundsIndex,
float LastRenderTime);
409 void GetRenderAssetScreenSize_Impl(
419 void UpdateBoundSizes_Impl(
422 float LastUpdateTime,
425 static void GetDistanceAndRange(
426 const FUpdate& Record,
427 float& MinDistanceSq,
float& MinRangeSq,
float& MaxRangeSq);
429 void UpdateTask_Async();
432 uint32 GetAllocatedSize_Impl()
const;
441 static bool IsEnabled() {
return GUseSimpleStreamableAssetManager != 0; }
454 float LastUpdateTime,
469 template<
typename TObject>
473template<
typename TObject>
479template<
typename TObject,
typename TPrimitive>
483 InObject->SimpleStreamableAssetManagerIndex,
486 InObject->GetMinDrawDistance(),
487 InObject->GetMaxDrawDistance(),
488 InObject->GetPrimitiveSceneInfo()->LastRenderTime,
489 InObject->IsForceMipStreaming())
491 if (InObject->IsSupportingStreamableRenderAssetsGathering())
#define check(expr)
Definition AssertionMacros.h:314
#define checkNoEntry()
Definition AssertionMacros.h:316
@ INDEX_NONE
Definition CoreMiscDefines.h:150
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
UE::FPlatformRecursiveMutex FCriticalSection
Definition CriticalSection.h:53
int32 GetTypeHash(const FSimpleStreamableAssetManager::FAssetRecord &Object)
Definition SimpleStreamableAssetManager.h:506
#define SIMPLE_STREAMABLE_ASSET_MANAGER_ALLOW_DEBUG_POINTER
Definition SimpleStreamableAssetManager.h:19
EStreamableRenderAssetType
Definition StreamableRenderAsset.h:26
UE_INTRINSIC_CAST UE_REWRITE constexpr std::remove_reference_t< T > && MoveTemp(T &&Obj) noexcept
Definition UnrealTemplate.h:520
if(Failed) console_printf("Failed.\n")
UEBinkAudioDecodeInterface * Interface
Definition binka_ue_decode_test.cpp:24
Definition IConsoleManager.h:1580
Definition PrimitiveSceneProxy.h:296
Definition SimpleStreamableAssetManager.h:129
static void GetAssetReferenceBounds(const UStreamableRenderAsset *Asset, TArray< FBox > &AssetBoxes)
Definition SimpleStreamableAssetManager.cpp:115
static void Shutdown()
Definition SimpleStreamableAssetManager.cpp:70
static uint32 GetAllocatedSize()
Definition SimpleStreamableAssetManager.cpp:103
static void GetRenderAssetScreenSize(EStreamableRenderAssetType AssetType, const int32 InAssetIndex, float &MaxSize, float &MaxSize_VisibleOnly, int32 &MaxNumForcedLODs, const float MaxAssetSize, const int32 MaxAllowedMip, const TCHAR *LogPrefix)
Definition SimpleStreamableAssetManager.cpp:131
static void UnregisterAsset(UStreamableRenderAsset *InAsset)
Definition SimpleStreamableAssetManager.cpp:86
static float GetStreamingScaleFactor(const TObject *Object, const FMatrix &LocalToWorld)
Definition SimpleStreamableAssetManager.h:474
static void UpdateBoundSizes(const TArray< FStreamingViewInfo > &ViewInfos, const TArray< FStreamingViewInfoExtra, TInlineAllocator< 4 > > &ViewInfoExtras, float LastUpdateTime, const FRenderAssetStreamingSettings &Settings)
Definition SimpleStreamableAssetManager.cpp:121
static FCriticalSection * GetCriticalSection()
Definition SimpleStreamableAssetManager.h:434
static void Init()
Definition SimpleStreamableAssetManager.cpp:64
static bool ShouldConsiderVisibility()
Definition SimpleStreamableAssetManager.h:442
static void Process()
Definition SimpleStreamableAssetManager.cpp:76
static bool IsEnabled()
Definition SimpleStreamableAssetManager.h:441
static ENGINE_API void Unregister(FUnregister &&Record)
Definition SimpleStreamableAssetManager.cpp:162
Definition ComponentInterfaces.h:59
Definition ArrayView.h:139
Definition SimpleStreamableAssetManager.h:58
TArray< FStorageShard * > ExtractShards()
Definition SimpleStreamableAssetManager.h:96
~TLocklessGrowingStorage()
Definition SimpleStreamableAssetManager.h:113
TLocklessStaticStorage< T, 512 > FStorageShard
Definition SimpleStreamableAssetManager.h:60
void Push(T &&In)
Definition SimpleStreamableAssetManager.h:62
Definition SharedPointer.h:692
Definition ContainerAllocationPolicies.h:894
Definition StreamableRenderAsset.h:37
SIZE_T GetAllocatedSize(const T &Value)
Definition ManagedArray.h:93
U16 Index
Definition radfft.cpp:71
Definition TextureInstanceView.h:24
Definition TextureInstanceView.h:79
Definition TextureStreamingHelpers.h:72
Definition SimpleStreamableAssetManager.h:267
float TexelFactor
Definition SimpleStreamableAssetManager.h:269
int32 ObjectRegistrationIndex
Definition SimpleStreamableAssetManager.h:268
uint32 bForceLOD
Definition SimpleStreamableAssetManager.h:270
Definition SimpleStreamableAssetManager.h:274
const UStreamableRenderAsset * StreamableRenderAsset_ForDebug
Definition SimpleStreamableAssetManager.h:278
int32 AssetElementIndex
Definition SimpleStreamableAssetManager.h:276
int32 AssetRegistrationIndex
Definition SimpleStreamableAssetManager.h:275
friend bool operator==(const FAssetRecord &A, const FAssetRecord &B)
Definition SimpleStreamableAssetManager.h:280
Definition SimpleStreamableAssetManager.h:294
int32 BoundsIndex
Definition SimpleStreamableAssetManager.h:295
Definition SimpleStreamableAssetManager.h:253
FRegister & operator=(const FRegister &)=default
TArray< FStreamingRenderAssetPrimitiveInfo > Assets
Definition SimpleStreamableAssetManager.h:254
FRegister & operator=(FRegister &&)=default
FRegister(const FRegister &)=default
FRegister(FRegister &&)=default
Definition SimpleStreamableAssetManager.h:284
const UStreamableRenderAsset * StreamableRenderAsset_ForDebug
Definition SimpleStreamableAssetManager.h:288
TSharedPtr< int32, ESPMode::ThreadSafe > SimpleStreamableAssetManagerIndex
Definition SimpleStreamableAssetManager.h:285
int32 AssetElementIndex
Definition SimpleStreamableAssetManager.h:286
friend bool operator==(const FRemovedAssetRecord &A, const FRemovedAssetRecord &B)
Definition SimpleStreamableAssetManager.h:290
Definition SimpleStreamableAssetManager.h:132
FScopedLock(FCriticalSection *InCriticalSection, bool bInShouldLock)
Definition SimpleStreamableAssetManager.h:133
~FScopedLock()
Definition SimpleStreamableAssetManager.h:142
Definition SimpleStreamableAssetManager.h:155
TSharedPtr< int32, ESPMode::ThreadSafe > ObjectRegistrationIndex
Definition SimpleStreamableAssetManager.h:156
FUnregister & operator=(const FUnregister &)=default
FUnregister(const TObject *Object)
Definition SimpleStreamableAssetManager.h:173
FUnregister & operator=(FUnregister &&)=default
const FPrimitiveSceneProxy * SceneProxy_ForDebug
Definition SimpleStreamableAssetManager.h:162
FUnregister(const FUnregister &)=default
UPTRINT ObjectKey
Definition SimpleStreamableAssetManager.h:161
FUnregister(FUnregister &&)=default
Definition SimpleStreamableAssetManager.h:182
UPTRINT ObjectKey
Definition SimpleStreamableAssetManager.h:187
FUpdateLastRenderTime(const void *InObject, const TSharedPtr< int32, ESPMode::ThreadSafe > &InObjectRegistrationIndex, const float InLastRenderedTime)
Definition SimpleStreamableAssetManager.h:198
const FPrimitiveSceneProxy * SceneProxy_ForDebug
Definition SimpleStreamableAssetManager.h:188
FUpdateLastRenderTime(FUpdateLastRenderTime &&)=default
TSharedPtr< int32, ESPMode::ThreadSafe > ObjectRegistrationIndex
Definition SimpleStreamableAssetManager.h:183
FUpdateLastRenderTime()=default
FUpdateLastRenderTime & operator=(FUpdateLastRenderTime &&)=default
FUpdateLastRenderTime(const FUpdateLastRenderTime &)=default
FUpdateLastRenderTime & operator=(const FUpdateLastRenderTime &)=default
float LastRenderedTime
Definition SimpleStreamableAssetManager.h:191
Definition SimpleStreamableAssetManager.h:211
UPTRINT ObjectKey
Definition SimpleStreamableAssetManager.h:217
TSharedPtr< int32, ESPMode::ThreadSafe > ObjectRegistrationIndex
Definition SimpleStreamableAssetManager.h:212
float MaxDistance
Definition SimpleStreamableAssetManager.h:223
FUpdate(const void *InObject, const TSharedPtr< int32, ESPMode::ThreadSafe > &InObjectRegistrationIndex, const FBoxSphereBounds &InBounds, float InStreamingScaleFactor, const float InMinDistance, const float InMaxDistance, const float InLastRenderedTime, bool InForceMipStreaming)
Definition SimpleStreamableAssetManager.h:233
FUpdate & operator=(FUpdate &&)=default
float LastRenderedTime
Definition SimpleStreamableAssetManager.h:224
uint8 bForceMipStreaming
Definition SimpleStreamableAssetManager.h:225
FBoxSphereBounds ObjectBounds
Definition SimpleStreamableAssetManager.h:213
const FPrimitiveSceneProxy * SceneProxy_ForDebug
Definition SimpleStreamableAssetManager.h:218
FUpdate(FUpdate &&)=default
float StreamingScaleFactor
Definition SimpleStreamableAssetManager.h:221
float MinDistance
Definition SimpleStreamableAssetManager.h:222
FUpdate(const FUpdate &)=default
FUpdate & operator=(const FUpdate &)=default
Definition TextureStreamingTypes.h:37
Definition ContentStreaming.h:75
Definition SimpleStreamableAssetManager.h:23
uint32 Reserve()
Definition SimpleStreamableAssetManager.h:26
void Release(uint32 ToRelease)
Definition SimpleStreamableAssetManager.h:34
TArrayView< T > GetData()
Definition SimpleStreamableAssetManager.h:48
void WaitForWrites() const
Definition SimpleStreamableAssetManager.h:43
static constexpr uint32 MaxElements
Definition SimpleStreamableAssetManager.h:25
void Store(T &&In, uint32 ItemReservedIndex)
Definition SimpleStreamableAssetManager.h:28
Definition BoxSphereBounds.h:25
T GetMaximumAxisScale() const
Definition Matrix.inl:618