UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
StreamingManagerTexture.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3/*=============================================================================
4TextureStreamingManager.h: Definitions of classes used for texture streaming.
5=============================================================================*/
6
7#pragma once
8
9#include "CoreMinimal.h"
10#include "ContentStreaming.h"
16
17class AActor;
19class IPakFile;
20class UPrimitiveComponent;
21
22template<typename TTask> class FAsyncTask;
23
24/*-----------------------------------------------------------------------------
25 Texture or mesh streaming.
26-----------------------------------------------------------------------------*/
27
32{
35
37
40
47 virtual void UpdateResourceStreaming( float DeltaTime, bool bProcessEverything=false ) override;
48
54 virtual void UpdateIndividualRenderAsset( UStreamableRenderAsset* RenderAsset ) override;
55
64 virtual bool FastForceFullyResident(UStreamableRenderAsset* RenderAsset) override;
65
73 virtual int32 BlockTillAllRequestsFinished( float TimeLimit = 0.0f, bool bLogResults = false ) override;
74
78 virtual void CancelForcedResources() override;
79
83 virtual void NotifyLevelChange() override;
84
86 virtual void SetDisregardWorldResourcesForFrames( int32 NumFrames ) override;
87
93 virtual bool StreamOutRenderAssetData( int64 RequiredMemorySize ) override;
94
95 virtual int64 GetMemoryOverBudget() const override { return MemoryOverBudget; }
96
98 virtual int64 GetPoolSize() const override;
99
100 virtual int64 GetRequiredPoolSize() const override { return DisplayedStats.RequiredPool; }
101
102 virtual int64 GetMaxEverRequired() const override { return MaxEverRequired; }
103
104 virtual float GetCachedMips() const override { return DisplayedStats.CachedMips; }
105
106 virtual void ResetMaxEverRequired() override { MaxEverRequired = 0; }
107
116 virtual bool Exec( UWorld* InWorld, const TCHAR* Cmd, FOutputDevice& Ar ) override;
117
121#if !UE_BUILD_SHIPPING
128 bool HandleNumStreamedMipsCommand( const TCHAR* Cmd, FOutputDevice& Ar );
129 bool HandleTrackRenderAssetCommand( const TCHAR* Cmd, FOutputDevice& Ar );
133 bool HandleStreamOutCommand( const TCHAR* Cmd, FOutputDevice& Ar );
136 bool HandleLODGroupsCommand( const TCHAR* Cmd, FOutputDevice& Ar );
138#endif // !UE_BUILD_SHIPPING
139
141 virtual void AddStreamingRenderAsset( UStreamableRenderAsset* RenderAsset ) override;
142
144 virtual void RemoveStreamingRenderAsset( UStreamableRenderAsset* RenderAsset ) override;
145
147 virtual bool IsFullyStreamedIn(UStreamableRenderAsset* RenderAsset) override;
148
150 virtual void AddLevel( class ULevel* Level ) override;
151
153 virtual void RemoveLevel( class ULevel* Level ) override;
154
155 /* Notifies manager that level primitives were shifted */
156 virtual void NotifyLevelOffset(ULevel* Level, const FVector& Offset) override;
158 virtual void NotifyActorDestroyed( AActor* Actor ) override;
159
161 virtual void NotifyPrimitiveDetached( const UPrimitiveComponent* Primitive ) override;
162
164 virtual void NotifyPrimitiveUpdated( const UPrimitiveComponent* Primitive ) override;
165
167 virtual void NotifyPrimitiveUpdated_Concurrent( const UPrimitiveComponent* Primitive ) override;
168
171
173 virtual void PauseRenderAssetStreaming(bool bInShouldPause) override
174 {
175 bPauseRenderAssetStreaming = bInShouldPause;
176 }
177
179 virtual void GetObjectReferenceBounds(const UObject* RefObject, TArray<FBox>& AssetBoxes) override;
180
181 virtual void GetAssetComponents(const UStreamableRenderAsset* RenderAsset, TArray<const UPrimitiveComponent*>& OutComps, TFunction<bool(const UPrimitiveComponent*)> ShouldChoose) override;
182
184 void PropagateLightingScenarioChange() override;
185
187
189
197
200
201private:
202//BEGIN: Thread-safe functions and data
205
207 void RemoveStaticReferences(const UPrimitiveComponent* Primitive);
208
217 void UpdateStreamingRenderAssets(int32 StageIndex, int32 NumStages, bool bWaitForMipFading, bool bAsync = false);
218
220 void TickFastResponseAssets();
221
222 void ProcessRemovedRenderAssets();
223 void ProcessAddedRenderAssets();
224 void ConditionalUpdateStaticData();
225 void ProcessLevelsToReferenceToStreamedTextures();
226
228 void PrepareAsyncTask( bool bProcessEverything );
229
231 void CheckUserSettings();
232
237 void BoostTextures( AActor* Actor, float BoostFactor ) override;
238
242 void SetOptionalBulkData( UTexture* Texture, bool bHasOptionalBulkData );
243
249 void StreamRenderAssets( bool bProcessEverything );
250
251 int32 GetNumStreamedMipsArray(EStreamableRenderAssetType AssetType, const int32*& OutArray)
252 {
253 switch (AssetType)
254 {
256 OutArray = NumStreamedMips_Texture;
257 return TEXTUREGROUP_MAX;
259 OutArray = NumStreamedMips_StaticMesh.GetData();
260 return NumStreamedMips_StaticMesh.Num();
262 OutArray = NumStreamedMips_SkeletalMesh.GetData();
263 return NumStreamedMips_SkeletalMesh.Num();
264 default:
265 check(false);
266 OutArray = nullptr;
267 return -1;
268 }
269 }
270
275 TArray<FStreamingRenderAsset> AsyncUnsafeStreamingRenderAssets;
276
282 struct FPointerKeyFunc : BaseKeyFuncs<UStreamableRenderAsset*, const UStreamableRenderAsset*, false>
283 {
284 static KeyInitType GetSetKey(ElementInitType& Element) { return Element; }
285 static KeyInitType GetSetKey(const TObjectPtr<UStreamableRenderAsset>& Element) { return Element.Get(); }
286 static bool Matches(KeyInitType A, KeyInitType B) { return A == B; }
287 static uint32 GetKeyHash(KeyInitType Key) { return GetTypeHash(Key); }
288 };
289
291 TSet<TObjectPtr<UStreamableRenderAsset>, FPointerKeyFunc> ReferencedRenderAssets;
292
294 TSet<FString> OptionalBulkDataFiles;
295
297 int32 CurrentUpdateStreamingRenderAssetIndex;
298//END: Thread-safe functions and data
299
300 void SetLastUpdateTime();
301 void UpdateStats();
302 void UpdateCSVOnlyStats();
303 void LogViewLocationChange();
304
305 void IncrementalUpdate( float Percentage, bool bUpdateDynamicComponents);
306
312 void UpdatePendingStates(bool bUpdateDynamicComponents);
313
319 void SyncStates(bool bCompleteFullUpdateCycle);
320
326 void ProcessPendingMipCopyRequests();
327
332 void TickDeferredMipLevelChangeCallbacks();
333
334 void ProcessPendingLevelManagers();
335
337 int32 NumStreamedMips_Texture[TEXTUREGROUP_MAX];
338 TArray<int32> NumStreamedMips_StaticMesh;
339 TArray<int32> NumStreamedMips_SkeletalMesh;
340
342
345
348
350 FDynamicRenderAssetInstanceManager DynamicComponentManager;
351
353 TArray<UStreamableRenderAsset*> PendingStreamingRenderAssets;
354
356 TArray<int32> RemovedRenderAssetIndices;
357
359 TArray<UStreamableRenderAsset*> DeferredTickCBAssets;
360
362 TSet<UStreamableRenderAsset*> FastResponseRenderAssets;
363
365 TSet<int32> VisibleFastResponseRenderAssetIndices;
366
367 // Represent a pending request to stream in/out mips to/from GPU for a texture or mesh
368 struct FPendingMipCopyRequest
369 {
370 const UStreamableRenderAsset* RenderAsset;
371 // Used to find the corresponding FStreamingRenderAsset in the StreamingRenderAssets array
372 int32 CachedIdx;
373
374 FPendingMipCopyRequest() = default;
375
376 FPendingMipCopyRequest(const UStreamableRenderAsset* InAsset, int32 InCachedIdx)
377 : RenderAsset(InAsset)
378 , CachedIdx(InCachedIdx)
379 {}
380 };
381 TArray<FPendingMipCopyRequest> PendingMipCopyRequests;
382
383 // The index of the next FPendingMipCopyRequest to process so the requests can be amortized accross multiple frames
384 int32 CurrentPendingMipCopyRequestIdx;
385
387 TArray<FLevelRenderAssetManager*> LevelRenderAssetManagers;
388
389 // Used to prevent hazard when LevelRenderAssetManagers array is modified through recursion
391 {
392 FRenderAssetStreamingManager* StreamingManager;
393 TArray<FLevelRenderAssetManager*> PendingAddLevelManagers;
394 TArray<FLevelRenderAssetManager*> PendingRemoveLevelManagers;
395
396 FScopedLevelRenderAssetManagersLock(FRenderAssetStreamingManager* InStreamingManager);
397
398 ~FScopedLevelRenderAssetManagersLock();
399 };
400
402
403 FScopedLevelRenderAssetManagersLock* LevelRenderAssetManagersLock;
404
406 int32 ProcessingStage;
407
409 int32 NumRenderAssetProcessingStages;
410
412 bool bUseDynamicStreaming;
413
414 float BoostPlayerTextures;
415
417 int64 MemoryMargin;
418
420 int64 EffectiveStreamingPoolSize;
421
422 // Stats we need to keep across frames as we only iterate over a subset of textures.
423
424 int64 MemoryOverBudget;
425 int64 MaxEverRequired;
426
428 bool bPauseRenderAssetStreaming;
429
431 float LastWorldUpdateTime;
432
434 float LastWorldUpdateTime_MipCalcTask;
435
436 FRenderAssetStreamingStats DisplayedStats;
437 FRenderAssetStreamingStats GatheredStats;
438
439 TArray<int32> InflightRenderAssets;
440
442 FCriticalSection MountedStateDirtyFilesCS;
444 bool bRecacheAllFiles = false;
446 typedef TSet<FIoFilenameHash> FIoFilenameHashSet;
447 FIoFilenameHashSet MountedStateDirtyFiles;
448
449 FDelegateHandle OnPakFileMounted2Handle;
450 FDelegateHandle NewFileAddedDelegateHandle;
451
452 ENGINE_API virtual void MarkMountedStateDirty(FIoFilenameHash FilenameHash) override;
453
454 // A critical section use around code that could be called in parallel with NotifyPrimitiveUpdated() or NotifyPrimitiveUpdated_Concurrent().
455 FCriticalSection CriticalSection;
456
457 // An event used to prevent FUpdateStreamingRenderAssetsTask from overlapping with related work
458 FGraphEventRef StreamingRenderAssetsSyncEvent;
459 TArray<FStreamingRenderAsset>& GetStreamingRenderAssetsAsyncSafe();
460
461 FAbandonedRenderAssetUpdateManager AbandonedRenderAssetUpdateManager;
462
464};
465
467{
468 static float GetWorldTime(UWorld* InWorld);
469};
#define check(expr)
Definition AssertionMacros.h:314
uint32 FIoFilenameHash
Definition BulkData.h:68
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
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
UE::FPlatformRecursiveMutex FCriticalSection
Definition CriticalSection.h:53
EStreamableRenderAssetType
Definition StreamableRenderAsset.h:26
@ TEXTUREGROUP_MAX
Definition TextureDefines.h:124
@ Percentage
uint32 Offset
Definition VulkanMemory.cpp:4033
uint32_t uint32
Definition binka_ue_file_header.h:6
Definition Actor.h:257
Definition AbandonedRenderAssetUpdateManager.h:18
Definition AsyncWork.h:585
Definition IDelegateInstance.h:14
Definition DynamicTextureInstanceManager.h:19
Definition OutputDevice.h:133
Definition AsyncTextureStreaming.h:135
Definition StreamingManagerTexture.cpp:1861
Definition GenericPlatformFile.h:1020
Definition Array.h:670
UE_REWRITE SizeType Num() const
Definition Array.h:1144
UE_NODEBUG UE_FORCEINLINE_HINT ElementType * GetData() UE_LIFETIMEBOUND
Definition Array.h:1027
Definition AndroidPlatformMisc.h:14
Definition UnrealString.h.inl:34
Definition RefCounting.h:454
Definition Level.h:423
Definition Object.h:95
Definition StreamableRenderAsset.h:37
Definition Texture.h:1219
Definition World.h:918
uint32 GetTypeHash(const FKey &Key)
Definition BlackboardKey.h:35
@ Element
Definition Visu.h:18
VERSECOMPILER_API bool Matches(const CTypeBase *PositiveType1, const CTypeBase *NegativeType2, const uint32_t UploadedAtFnVersion)
Determine if argument PositiveType1 is a match for parameter NegativeType2
Definition SemanticTypes.cpp:2971
Definition SetUtilities.h:23
TCallTraits< UStreamableRenderAsset * >::ParamType ElementInitType
Definition SetUtilities.h:26
TCallTraits< const UStreamableRenderAsset * >::ParamType KeyInitType
Definition SetUtilities.h:25
Definition StreamingManagerTexture.h:467
static float GetWorldTime(UWorld *InWorld)
Definition StreamingManagerTexture.cpp:3219
Definition StreamingManagerTexture.h:32
virtual void AddLevel(class ULevel *Level) override
Definition StreamingManagerTexture.cpp:871
virtual void GetObjectReferenceBounds(const UObject *RefObject, TArray< FBox > &AssetBoxes) override
Definition StreamingManagerTexture.cpp:2139
bool HandleNumStreamedMipsCommand(const TCHAR *Cmd, FOutputDevice &Ar)
Definition StreamingManagerTexture.cpp:2514
virtual int64 GetMaxEverRequired() const override
Definition StreamingManagerTexture.h:102
FStreamingRenderAsset * GetStreamingRenderAsset(const UStreamableRenderAsset *RenderAsset)
Definition StreamingManagerTexture.cpp:1348
virtual void NotifyPrimitiveUpdated(const UPrimitiveComponent *Primitive) override
Definition StreamingManagerTexture.cpp:1245
virtual void AddStreamingRenderAsset(UStreamableRenderAsset *RenderAsset) override
Definition StreamingManagerTexture.cpp:999
virtual int64 GetMemoryOverBudget() const override
Definition StreamingManagerTexture.h:95
bool HandleLightmapStreamingFactorCommand(const TCHAR *Cmd, FOutputDevice &Ar)
Definition StreamingManagerTexture.cpp:2476
virtual void GetAssetComponents(const UStreamableRenderAsset *RenderAsset, TArray< const UPrimitiveComponent * > &OutComps, TFunction< bool(const UPrimitiveComponent *)> ShouldChoose) override
Definition StreamingManagerTexture.cpp:2203
virtual ~FRenderAssetStreamingManager()
Definition StreamingManagerTexture.cpp:237
virtual void RemoveLevel(class ULevel *Level) override
Definition StreamingManagerTexture.cpp:939
friend struct FScopedLevelRenderAssetManagersLock
Definition StreamingManagerTexture.h:401
void AddRenderedTextureStats(TMap< FString, FRenderedTextureStats > &InOutRenderedTextureStats) override
Definition StreamingManagerTexture.cpp:2271
bool HandleListStreamingRenderAssetsCommand(const TCHAR *Cmd, FOutputDevice &Ar)
Definition StreamingManagerTexture.cpp:2336
virtual void SetDisregardWorldResourcesForFrames(int32 NumFrames) override
Definition StreamingManagerTexture.cpp:371
virtual bool Exec(UWorld *InWorld, const TCHAR *Cmd, FOutputDevice &Ar) override
Definition StreamingManagerTexture.cpp:3120
FRenderAssetStreamingManager()
Definition StreamingManagerTexture.cpp:142
bool HandleDebugTrackedRenderAssetsCommand(const TCHAR *Cmd, FOutputDevice &Ar)
Definition StreamingManagerTexture.cpp:2576
virtual bool StreamOutRenderAssetData(int64 RequiredMemorySize) override
Definition StreamingManagerTexture.cpp:381
bool HandleCancelRenderAssetStreamingCommand(const TCHAR *Cmd, FOutputDevice &Ar)
Definition StreamingManagerTexture.cpp:2490
virtual void NotifyLevelOffset(ULevel *Level, const FVector &Offset) override
Definition StreamingManagerTexture.cpp:980
virtual float GetCachedMips() const override
Definition StreamingManagerTexture.h:104
bool HandleDumpTextureStreamingStatsCommand(const TCHAR *Cmd, FOutputDevice &Ar)
Definition StreamingManagerTexture.cpp:2309
virtual int64 GetRequiredPoolSize() const override
Definition StreamingManagerTexture.h:100
bool HandlePauseRenderAssetStreamingCommand(const TCHAR *Cmd, FOutputDevice &Ar)
Definition StreamingManagerTexture.cpp:2712
virtual void NotifyPrimitiveDetached(const UPrimitiveComponent *Primitive) override
Definition StreamingManagerTexture.cpp:1167
virtual void UpdateIndividualRenderAsset(UStreamableRenderAsset *RenderAsset) override
Definition StreamingManagerTexture.cpp:1371
virtual void CancelForcedResources() override
Definition StreamingManagerTexture.cpp:331
bool HandleInvestigateRenderAssetCommand(const TCHAR *Cmd, FOutputDevice &Ar, UWorld *InWorld)
Definition StreamingManagerTexture.cpp:2858
bool HandleTrackRenderAssetCommand(const TCHAR *Cmd, FOutputDevice &Ar)
Definition StreamingManagerTexture.cpp:2549
virtual void PauseRenderAssetStreaming(bool bInShouldPause) override
Definition StreamingManagerTexture.h:173
bool HandleStreamOutCommand(const TCHAR *Cmd, FOutputDevice &Ar)
Definition StreamingManagerTexture.cpp:2694
bool HandleLODGroupsCommand(const TCHAR *Cmd, FOutputDevice &Ar)
Definition StreamingManagerTexture.cpp:2751
bool HandleResetMaxEverRequiredRenderAssetMemoryCommand(const TCHAR *Cmd, FOutputDevice &Ar)
Definition StreamingManagerTexture.cpp:2467
virtual bool FastForceFullyResident(UStreamableRenderAsset *RenderAsset) override
Definition StreamingManagerTexture.cpp:1397
bool HandleListTrackedRenderAssetsCommand(const TCHAR *Cmd, FOutputDevice &Ar)
Definition StreamingManagerTexture.cpp:2561
void SetRenderAssetsRemovedTimestamp(const FRemovedRenderAssetArray &RemovedRenderAssets)
Definition StreamingManagerTexture.cpp:1226
virtual void RemoveStreamingRenderAsset(UStreamableRenderAsset *RenderAsset) override
Definition StreamingManagerTexture.cpp:1025
virtual void ResetMaxEverRequired() override
Definition StreamingManagerTexture.h:106
bool HandleUntrackRenderAssetCommand(const TCHAR *Cmd, FOutputDevice &Ar)
Definition StreamingManagerTexture.cpp:2682
void OnRenderAssetUpdateAbandoned(UStreamableRenderAsset *OwningRenderAsset, TRefCountPtr< class FRenderAssetUpdate > &RenderAssetUpdate) override
Definition StreamingManagerTexture.cpp:2301
virtual void UpdateResourceStreaming(float DeltaTime, bool bProcessEverything=false) override
Definition StreamingManagerTexture.cpp:1897
virtual void NotifyActorDestroyed(AActor *Actor) override
Definition StreamingManagerTexture.cpp:1088
virtual int32 BlockTillAllRequestsFinished(float TimeLimit=0.0f, bool bLogResults=false) override
Definition StreamingManagerTexture.cpp:2091
virtual bool IsFullyStreamedIn(UStreamableRenderAsset *RenderAsset) override
Definition StreamingManagerTexture.cpp:1064
void OnPreGarbageCollect()
Definition StreamingManagerTexture.cpp:265
bool HandleShadowmapStreamingFactorCommand(const TCHAR *Cmd, FOutputDevice &Ar)
Definition StreamingManagerTexture.cpp:2500
bool HandleStreamingManagerMemoryCommand(const TCHAR *Cmd, FOutputDevice &Ar, UWorld *InWorld)
Definition StreamingManagerTexture.cpp:2721
virtual int64 GetPoolSize() const override
Definition StreamingManagerTexture.cpp:453
static bool IsParallelForAllowedDuringIncrementalUpdate(int32 NumElementsToProcess, int32 &OutParallelForMinBatchSize)
Definition StreamingManagerTexture.cpp:458
void PropagateLightingScenarioChange() override
Definition StreamingManagerTexture.cpp:2239
virtual void NotifyLevelChange() override
Definition StreamingManagerTexture.cpp:366
friend bool TrackRenderAssetEvent(FStreamingRenderAsset *StreamingRenderAsset, UStreamableRenderAsset *RenderAsset, bool bForceMipLevelsToBeResident, const FRenderAssetStreamingManager *Manager)
Definition ContentStreaming.cpp:226
virtual void NotifyPrimitiveUpdated_Concurrent(const UPrimitiveComponent *Primitive) override
Definition StreamingManagerTexture.cpp:1300
Definition TextureStreamingHelpers.h:72
Definition TextureStreamingHelpers.h:161
int64 RequiredPool
Definition TextureStreamingHelpers.h:177
int64 CachedMips
Definition TextureStreamingHelpers.h:185
Definition StreamingTexture.h:23
Definition ContentStreaming.h:424
Definition ObjectPtr.h:488