UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
TextureInstanceView.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3/*=============================================================================
4TextureInstanceView.h: Definitions of classes used for texture streaming.
5=============================================================================*/
6
7#pragma once
8
9#include "CoreMinimal.h"
13
14class UPrimitiveComponent;
18
19#define MAX_TEXTURE_SIZE (float(1 << (MAX_TEXTURE_MIP_COUNT - 1)))
20
21
22// The bounds are into their own arrays to allow SIMD-friendly processing
77
79{
82 /*
83 * The biggest normalized size accross all view for visible instances only.
84 * Visible instances are the one that are in range and also that have been seen recently.
85 */
89};
90
92{
93 // The screen size factor including the view boost.
95
96 // The extra view boost for visible primitive (if ViewInfo.BoostFactor > "r.Streaming.MaxHiddenPrimitiveViewBoost").
98};
99
101
102// Main Thread Job Requirement : find all instance of a component and update it's bound.
103// Threaded Job Requirement : get the list of instance texture or mesh easily from the list of
104
105// A constant view on the relationship between textures/meshes, components and bounds.
106// Has everything needed for the worker task to compute the required size per texture/mesh.
107
109{
110public:
111
112 struct FElement
113 {
115 : Component(nullptr)
116 , RenderAsset(nullptr)
117 , BoundsIndex(INDEX_NONE)
118 , TexelFactor(0)
119 , PrevRenderAssetLink(INDEX_NONE)
120 , NextRenderAssetLink(INDEX_NONE)
121 , NextComponentLink(INDEX_NONE)
122 {
123 }
124
125 const UPrimitiveComponent* Component; // Which component this relates too
126 const UStreamableRenderAsset* RenderAsset; // Texture or mesh, never dereferenced.
127
128 int32 BoundsIndex; // The Index associated to this component (static component can have several bounds).
129 float TexelFactor; // The texture scale to be applied to this instance.
130 bool bForceLoad; // The texture or mesh needs to be force loaded.
131
132 int32 PrevRenderAssetLink; // The previous element which uses the same asset as this Element. The first element referred by RenderAssetMap will have INDEX_NONE.
133 int32 NextRenderAssetLink; // The next element which uses the same asset as this Element. Last element will have INDEX_NONE
134
135 // Components are always updated as a whole, so individual elements can not be removed. Removing the need for PrevComponentLink.
136 int32 NextComponentLink; // The next element that uses the same component as this Element. The first one is referred by ComponentMap and the last one will have INDEX_NONE.
137 };
138
144 {
146 FCompiledElement(const FElement& InElement) : BoundsIndex(InElement.BoundsIndex), TexelFactor(InElement.TexelFactor), bForceLoad(InElement.bForceLoad) {}
147
151
152 FORCEINLINE bool operator==(const FCompiledElement& Rhs) const { return BoundsIndex == Rhs.BoundsIndex && TexelFactor == Rhs.TexelFactor && bForceLoad == Rhs.bForceLoad; }
153 };
154
156 {
158
159 // The index of head element using the renderable asset.
161 // The LODGroup of the texture or mesh, used to performe some tasks async.
163 };
164
165
166 // Iterator processing all elements refering to a texture/mesh.
168 {
169 public:
171
172 FORCEINLINE explicit operator bool() const { return CurrElementIndex != INDEX_NONE; }
173 FORCEINLINE void operator++() { CurrElementIndex = State.Elements[CurrElementIndex].NextRenderAssetLink; }
174
175 void OutputToLog(float MaxNormalizedSize, float MaxNormalizedSize_VisibleOnly, const TCHAR* Prefix) const;
176
177 FORCEINLINE int32 GetBoundsIndex() const { return State.Elements[CurrElementIndex].BoundsIndex; }
178 FORCEINLINE float GetTexelFactor() const { return State.Elements[CurrElementIndex].TexelFactor; }
179 FORCEINLINE bool GetForceLoad() const { return State.Elements[CurrElementIndex].bForceLoad; }
180
181 FBoxSphereBounds GetBounds() const;
182
183 FORCEINLINE const UPrimitiveComponent* GetComponent() const { return State.Elements[CurrElementIndex].Component; }
184
187 };
188
190 {
191 public:
193
195 {
196 float& TexelFactor = const_cast<FRenderAssetInstanceView&>(State).Elements[CurrElementIndex].TexelFactor;
197 TexelFactor = FMath::Clamp<float>(TexelFactor, CMin, CMax);
198 }
199 };
200
202 {
203 public:
205
206 explicit operator bool() const { return (bool)MapIt; }
207 void operator++() { ++MapIt; }
208
209 const UStreamableRenderAsset* operator*() const { return MapIt.Key(); }
210 int32 GetLODGroup() const { return MapIt.Value().LODGroup; }
211
212 private:
213
215 };
216
217 FRenderAssetInstanceView() : MaxTexelFactor(FLT_MAX) {}
218
219 FORCEINLINE int32 NumBounds4() const { return Bounds4.Num(); }
220 FORCEINLINE const FBounds4& GetBounds4(int32 Bounds4Index ) const { return Bounds4[Bounds4Index]; }
222
226
227 // Whether or not this state has compiled elements.
228 bool HasCompiledElements() const { return CompiledRenderAssetMap.Num() != 0; }
229 // If this has compiled elements, return the array relate to a given texture or mesh.
230 const TArray<FCompiledElement>* GetCompiledElements(const UStreamableRenderAsset* Asset) const { return CompiledRenderAssetMap.Find(Asset); }
231
232 bool HasComponentWithForcedLOD(const UStreamableRenderAsset* Asset) const { return !!CompiledNumForcedLODCompMap.Find(Asset); }
233 bool HasAnyComponentWithForcedLOD() const { return !!CompiledNumForcedLODCompMap.Num(); }
234
236 static TRefCountPtr<FRenderAssetInstanceView> CreateViewWithUninitializedBounds(const FRenderAssetInstanceView* RefView);
237 static void SwapData(FRenderAssetInstanceView* Lfs, FRenderAssetInstanceView* Rhs);
238
239 float GetMaxTexelFactor() const { return MaxTexelFactor; }
240
241 static float GetMaxDrawDistSqWithLODParent(const FVector& Origin, const FVector& ParentOrigin, float ParentMinDrawDist, float ParentBoundingSphereRadius);
242
243 static void GetDistanceAndRange(const UPrimitiveComponent* Component, const FBoxSphereBounds& RenderAssetInstanceBounds, float& MinDistanceSq, float& MinRangeSq, float& MaxRangeSq);
244
245 static void OutputToLog(const FBoxSphereBounds& Bounds, int32 BoundsIndex, const TArray<FBounds4>& Bounds4, float TexelFactor, bool bForceLoad, float MaxNormalizedSize, float MaxNormalizedSize_VisibleOnly, const TCHAR* Prefix, const UPrimitiveComponent* Component = nullptr);
246
247protected:
248
250
252
254
255 // CompiledTextureMap is used to iterate more quickly on each elements by avoiding the linked list indirections.
257
258 // If an asset has components with forced LOD levels, it will appear here after level compilation.
260
263};
264
265// Data used to compute visibility
267{
268public:
269
270 FRenderAssetInstanceAsyncView() : MaxLevelRenderAssetScreenSize(UE_MAX_FLT) {}
271
272 FRenderAssetInstanceAsyncView(const FRenderAssetInstanceView* InView) : View(InView), MaxLevelRenderAssetScreenSize(UE_MAX_FLT) {}
273
274 void UpdateBoundSizes_Async(
275 const TArray<FStreamingViewInfo>& ViewInfos,
276 const FStreamingViewInfoExtraArray& ViewInfoExtras,
277 float LastUpdateTime,
278 const FRenderAssetStreamingSettings& Settings);
279
280 // Screen size is the number of screen pixels overlap with this asset
281 // MaxSize : Biggest screen size for all instances.
282 // MaxSize_VisibleOnly : Biggest screen size for visble instances only.
283 // MaxForcedNumLODs: max number of LODs forced resident. Used for meshes only
284 void GetRenderAssetScreenSize(
287 float& MaxSize,
288 float& MaxSize_VisibleOnly,
290 const float MaxAssetSize,
291 const TCHAR* LogPrefix) const;
292
294 {
295 return View.IsValid() && (bool)View->GetElementIterator(InAsset);
296 }
297
299 {
300 return View.IsValid() && View->HasComponentWithForcedLOD(InAsset);
301 }
302
304 {
305 return View.IsValid() && View->HasAnyComponentWithForcedLOD();
306 }
307
308 // Release the data now as this is expensive.
309 void OnTaskDone() { BoundsViewInfo.Empty(); }
310
311 float GetMaxLevelRenderAssetScreenSize() const { return MaxLevelRenderAssetScreenSize; }
312
313private:
314
316
317 // Normalized Texel Factors for each bounds and view. This is the data built by ComputeBoundsViewInfos
318 // @TODO : store data for different views continuously to improve reads.
319 TArray<FBoundsViewInfo> BoundsViewInfo;
320
322 float MaxLevelRenderAssetScreenSize;
323
324public:
325 static void UpdateBoundSizes(
326 const TArray<FStreamingViewInfo>& ViewInfos,
327 const FStreamingViewInfoExtraArray& ViewInfoExtras,
328 float LastUpdateTime,
329 float MaxTexelFactor,
330 const FRenderAssetStreamingSettings& Settings,
331 const TConstArrayView<FBounds4>& Bounds,
334 );
335
336 static void ProcessElement(
339 float TexelFactor,
340 bool bForceLoad,
341 float& MaxSize,
342 float& MaxSize_VisibleOnly,
344};
#define FORCEINLINE
Definition AndroidPlatform.h:140
@ INDEX_NONE
Definition CoreMiscDefines.h:150
FPlatformTypes::TCHAR TCHAR
Either ANSICHAR or WIDECHAR, depending on whether the platform supports wide characters or the requir...
Definition Platform.h:1135
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
const bool
Definition NetworkReplayStreaming.h:178
EStreamableRenderAssetType
Definition StreamableRenderAsset.h:26
TArray< FStreamingViewInfoExtra, TInlineAllocator< 4 > > FStreamingViewInfoExtraArray
Definition TextureInstanceView.h:100
#define UE_MAX_FLT
Definition UnrealMathUtility.h:147
uint32 Offset
Definition VulkanMemory.cpp:4033
uint32_t uint32
Definition binka_ue_file_header.h:6
Definition RefCounting.h:252
Definition TextureInstanceView.h:267
FORCEINLINE bool HasRenderAssetReferences(const UStreamableRenderAsset *InAsset) const
Definition TextureInstanceView.h:293
FORCEINLINE bool HasComponentWithForcedLOD(const UStreamableRenderAsset *InAsset) const
Definition TextureInstanceView.h:298
float GetMaxLevelRenderAssetScreenSize() const
Definition TextureInstanceView.h:311
FRenderAssetInstanceAsyncView()
Definition TextureInstanceView.h:270
FRenderAssetInstanceAsyncView(const FRenderAssetInstanceView *InView)
Definition TextureInstanceView.h:272
void OnTaskDone()
Definition TextureInstanceView.h:309
FORCEINLINE bool HasAnyComponentWithForcedLOD() const
Definition TextureInstanceView.h:303
Definition TextureInstanceView.h:202
FRenderAssetIterator(const FRenderAssetInstanceView &InState)
Definition TextureInstanceView.h:204
const UStreamableRenderAsset * operator*() const
Definition TextureInstanceView.h:209
int32 GetLODGroup() const
Definition TextureInstanceView.h:210
void operator++()
Definition TextureInstanceView.h:207
FORCEINLINE const UPrimitiveComponent * GetComponent() const
Definition TextureInstanceView.h:183
FORCEINLINE float GetTexelFactor() const
Definition TextureInstanceView.h:178
int32 CurrElementIndex
Definition TextureInstanceView.h:186
FORCEINLINE int32 GetBoundsIndex() const
Definition TextureInstanceView.h:177
FORCEINLINE bool GetForceLoad() const
Definition TextureInstanceView.h:179
const FRenderAssetInstanceView & State
Definition TextureInstanceView.h:185
FORCEINLINE void operator++()
Definition TextureInstanceView.h:173
Definition TextureInstanceView.h:190
FORCEINLINE void ClampTexelFactor(float CMin, float CMax)
Definition TextureInstanceView.h:194
FRenderAssetLinkIterator(FRenderAssetInstanceView &InState, const UStreamableRenderAsset *InAsset)
Definition TextureInstanceView.h:192
Definition TextureInstanceView.h:109
TArray< FBounds4 > Bounds4
Definition TextureInstanceView.h:249
bool HasComponentWithForcedLOD(const UStreamableRenderAsset *Asset) const
Definition TextureInstanceView.h:232
TMap< const UStreamableRenderAsset *, TArray< FCompiledElement > > CompiledRenderAssetMap
Definition TextureInstanceView.h:256
FORCEINLINE FRenderAssetLinkIterator GetElementIterator(const UStreamableRenderAsset *InTexture)
Definition TextureInstanceView.h:223
TMap< const UStreamableRenderAsset *, int32 > CompiledNumForcedLODCompMap
Definition TextureInstanceView.h:259
FORCEINLINE TConstArrayView< FBounds4 > GetBoundsView() const
Definition TextureInstanceView.h:221
FORCEINLINE const FBounds4 & GetBounds4(int32 Bounds4Index) const
Definition TextureInstanceView.h:220
FRenderAssetInstanceView()
Definition TextureInstanceView.h:217
float MaxTexelFactor
Definition TextureInstanceView.h:262
FORCEINLINE FRenderAssetIterator GetRenderAssetIterator() const
Definition TextureInstanceView.h:225
TMap< const UStreamableRenderAsset *, FRenderAssetDesc > RenderAssetMap
Definition TextureInstanceView.h:253
TChunkedArray< FElement > Elements
Definition TextureInstanceView.h:251
FORCEINLINE int32 NumBounds4() const
Definition TextureInstanceView.h:219
const TArray< FCompiledElement > * GetCompiledElements(const UStreamableRenderAsset *Asset) const
Definition TextureInstanceView.h:230
float GetMaxTexelFactor() const
Definition TextureInstanceView.h:239
FORCEINLINE FRenderAssetLinkConstIterator GetElementIterator(const UStreamableRenderAsset *InTexture) const
Definition TextureInstanceView.h:224
bool HasAnyComponentWithForcedLOD() const
Definition TextureInstanceView.h:233
bool HasCompiledElements() const
Definition TextureInstanceView.h:228
Definition Array.h:670
Definition ChunkedArray.h:56
Definition UnrealString.h.inl:34
Definition RefCounting.h:454
Definition StreamableRenderAsset.h:37
U16 Index
Definition radfft.cpp:71
Definition TextureInstanceView.h:24
FVector4f MaxRangeSq
Definition TextureInstanceView.h:59
FVector4f ExtentY
Definition TextureInstanceView.h:44
FVector4 RangeOriginZ
Definition TextureInstanceView.h:39
FVector4f MinRangeSq
Definition TextureInstanceView.h:57
void UnpackBounds(int32 Index, const UPrimitiveComponent *Component)
Definition TextureInstanceView.cpp:39
FORCEINLINE void OffsetBounds(int32 Index, const FVector &Offset)
Definition TextureInstanceView.inl:49
FVector4f MinDistanceSq
Definition TextureInstanceView.h:55
FVector4f RadiusOrComponentScale
Definition TextureInstanceView.h:49
FVector4f ExtentX
Definition TextureInstanceView.h:42
FORCEINLINE FBounds4()
Definition TextureInstanceView.inl:9
FVector4 RangeOriginX
Definition TextureInstanceView.h:35
FVector4 OriginZ
Definition TextureInstanceView.h:32
FVector4 RangeOriginY
Definition TextureInstanceView.h:37
FVector4 OriginY
Definition TextureInstanceView.h:30
FVector4f LastRenderTime
Definition TextureInstanceView.h:62
MS_ALIGN(16) FUintVector4 PackedRelativeBox
FORCEINLINE void UpdateMaxDrawDistanceSquared(int32 Index, float InMaxRangeSq)
Definition TextureInstanceView.inl:65
FVector4f ExtentZ
Definition TextureInstanceView.h:46
FORCEINLINE void UpdateLastRenderTime(int32 Index, float LastRenderTime)
Definition TextureInstanceView.inl:58
FVector4 OriginX
Definition TextureInstanceView.h:28
Definition TextureInstanceView.h:79
float MaxNormalizedSize_VisibleOnly
Definition TextureInstanceView.h:86
float ComponentScale
Definition TextureInstanceView.h:88
float MaxNormalizedSize
Definition TextureInstanceView.h:81
Definition TextureInstanceView.h:144
bool bForceLoad
Definition TextureInstanceView.h:150
FORCEINLINE bool operator==(const FCompiledElement &Rhs) const
Definition TextureInstanceView.h:152
int32 BoundsIndex
Definition TextureInstanceView.h:148
FCompiledElement(const FElement &InElement)
Definition TextureInstanceView.h:146
FCompiledElement()
Definition TextureInstanceView.h:145
float TexelFactor
Definition TextureInstanceView.h:149
Definition TextureInstanceView.h:113
bool bForceLoad
Definition TextureInstanceView.h:130
int32 PrevRenderAssetLink
Definition TextureInstanceView.h:132
FORCEINLINE FElement()
Definition TextureInstanceView.h:114
const UStreamableRenderAsset * RenderAsset
Definition TextureInstanceView.h:126
const UPrimitiveComponent * Component
Definition TextureInstanceView.h:125
int32 NextRenderAssetLink
Definition TextureInstanceView.h:133
float TexelFactor
Definition TextureInstanceView.h:129
int32 BoundsIndex
Definition TextureInstanceView.h:128
int32 NextComponentLink
Definition TextureInstanceView.h:136
Definition TextureInstanceView.h:156
int32 HeadLink
Definition TextureInstanceView.h:160
const int32 LODGroup
Definition TextureInstanceView.h:162
FRenderAssetDesc(int32 InHeadLink, int32 InLODGroup)
Definition TextureInstanceView.h:157
Definition TextureStreamingHelpers.h:72
Definition TextureInstanceView.h:92
float ScreenSizeFloat
Definition TextureInstanceView.h:94
float ExtraBoostForVisiblePrimitiveFloat
Definition TextureInstanceView.h:97
Definition ContentStreaming.h:75
Definition BoxSphereBounds.h:25