UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
TextureInstanceTask.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3/*=============================================================================
4TextureInstanceTask.h: Definitions of classes used for texture streaming.
5=============================================================================*/
6
7#pragma once
8
9#include "CoreMinimal.h"
11#include "Async/AsyncWork.h"
12
14
22
23template <typename TWork>
25{
26public:
27
29 template<typename...T>
30 explicit TDoWorkTask(T&&... Args) : Work(Forward<T>(Args)...), TaskState(TS_Done) {}
31
32 virtual ~TDoWorkTask() {}
33
34 // Whether to run the work
36 {
37 // Force inline as this is only called from a single place.
38 if (FPlatformAtomics::InterlockedCompareExchange(&TaskState, TS_WorkInProgress, TS_WorkPending) == TS_WorkPending)
39 {
40 Work(bAsync);
41 TaskState = TS_SyncPending;
42 }
43 }
44
45 // Force inline as this is only called from a single place.
47 {
48 if (TaskState != TS_Done)
49 {
50 while (TaskState != TS_SyncPending)
51 {
52 FPlatformProcess::Sleep(0);
53 }
54 Work.Sync();
55 }
56 TaskState = TS_Done;
57 }
58
60 template<typename...T>
61 FORCEINLINE void Init(T&&... Args)
62 {
63 check(TaskState == TS_Done);
64 Work.Init(Forward<T>(Args)...);
65 TaskState = TS_WorkPending;
66 }
67
68private:
69
70 TWork Work;
71 volatile int32 TaskState;
72};
73
76{
77public:
78
80
83 void operator()(bool bAsync);
84 void Sync();
85
86private:
87
88 // Callback to process the results.
89 FOnWorkDone OnWorkDoneDelegate;
90 // The state to update (no re/allocation allowed)
92 // The index of the first bound to update.
93 int32 BeginIndex;
94 // The index of the last bound to update.
95 int32 EndIndex;
96};
97
100{
101public:
102
104
107 void operator()(bool bAsync);
108 void Sync();
109
110private:
111
112 // Callback to process the results.
113 FOnWorkDone OnWorkDoneDelegate;
114 // The first free bound seen (used for defrag)
115 int32 FirstFreeBound = INDEX_NONE;
116 // The last free bound seen (used for defrag)
117 int32 LastUsedBound = INDEX_NONE;
118 // Any bounds that couldn't be updated for some reason (incoherent bounds).
119 TArray<int32> SkippedIndices;
120 // The state to update (no re/allocation allowed)
122 // The index of the first bound to update.
123 int32 BeginIndex;
124 // The index of the last bound to update.
125 int32 EndIndex;
126};
127
130{
131public:
132
134 void operator()(bool bAsync);
135 void Sync() { State.SafeRelease(); }
136
137private:
138
139 // The state to update (no re/allocation allowed)
141};
142
143// Create an independent view of a state
145{
146public:
148
151 {
152 State = InState;
153 ViewToRelease = InViewToRelease;
154 }
155
156 void operator()(bool bAsync);
157 void Sync();
158
159private:
160
161 // Callback to process the results.
162 FOnWorkDone OnWorkDoneDelegate;
163 // The view created from the state, as a result of the execution.
165 // The state for which to create the view.
167 // The previous view of the state. Used to release the state and run the destructor async.
169};
170
175
177{
178public:
179
180 void DoWork();
181
182 void Add(FRefreshFullTask* RefreshFullTask) { RefreshFullTasks.Add(RefreshFullTask); }
183 void Add(FRefreshVisibilityTask* RefreshVisibilityTask) { RefreshVisibilityTasks.Add(RefreshVisibilityTask); }
184 void Add(FNormalizeLightmapTexelFactorTask* NormalizeLightmapTexelFactorTask) { NormalizeLightmapTexelFactorTasks.Add(NormalizeLightmapTexelFactorTask); }
186
188
189private:
190
191 template <typename TTask>
193
195 TArray< TRefCountPtr<FRefreshVisibilityTask> > RefreshVisibilityTasks;
196 TArray< TRefCountPtr<FNormalizeLightmapTexelFactorTask> > NormalizeLightmapTexelFactorTasks;
197 TArray< TRefCountPtr<FCreateViewWithUninitializedBoundsTask> > CreateViewWithUninitializedBoundsTasks;
198};
199
200class FDoWorkAsyncTask : public FAsyncTask<FDoWorkTask>, public FRefCountedObject
201{
202};
203
204} // namespace RenderAssetInstanceTask
#define FORCEINLINE
Definition AndroidPlatform.h:140
#define check(expr)
Definition AssertionMacros.h:314
@ INDEX_NONE
Definition CoreMiscDefines.h:150
#define FORCEINLINE_DEBUGGABLE
Definition CoreMiscDefines.h:74
FPlatformTypes::int32 int32
A 32-bit signed integer.
Definition Platform.h:1125
#define RETURN_QUICK_DECLARE_CYCLE_STAT(StatId, GroupId)
Definition Stats.h:655
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
void Init()
Definition LockFreeList.h:4
Definition AsyncWork.h:585
Definition AsyncWork.h:663
Definition RefCounting.h:252
Definition TextureInstanceState.h:28
Definition TextureInstanceView.h:109
void Init(const FRenderAssetInstanceState *InState, const FRenderAssetInstanceView *InViewToRelease)
Definition TextureInstanceTask.h:150
FCreateViewWithUninitializedBounds(const FOnWorkDone &InOnWorkDoneDelegate)
Definition TextureInstanceTask.h:149
void Sync()
Definition TextureInstanceTask.cpp:151
DECLARE_DELEGATE_OneParam(FOnWorkDone, FRenderAssetInstanceView *)
void operator()(bool bAsync)
Definition TextureInstanceTask.cpp:141
Definition TextureInstanceTask.h:201
Definition TextureInstanceTask.h:177
void Add(FNormalizeLightmapTexelFactorTask *NormalizeLightmapTexelFactorTask)
Definition TextureInstanceTask.h:184
FORCEINLINE TStatId GetStatId() const
Definition TextureInstanceTask.h:187
void Add(FRefreshFullTask *RefreshFullTask)
Definition TextureInstanceTask.h:182
void Add(FRefreshVisibilityTask *RefreshVisibilityTask)
Definition TextureInstanceTask.h:183
void DoWork()
Definition TextureInstanceTask.cpp:178
void Add(FCreateViewWithUninitializedBoundsTask *CreateViewWithUninitializedBoundsTask)
Definition TextureInstanceTask.h:185
Definition TextureInstanceTask.h:130
void Init(FRenderAssetInstanceState *InState)
Definition TextureInstanceTask.h:133
void operator()(bool bAsync)
Definition TextureInstanceTask.cpp:114
void Sync()
Definition TextureInstanceTask.h:135
Definition TextureInstanceTask.h:100
DECLARE_DELEGATE_FiveParams(FOnWorkDone, int32, int32, const TArray< int32 > &, int32, int32)
void operator()(bool bAsync)
Definition TextureInstanceTask.cpp:61
void Sync()
Definition TextureInstanceTask.cpp:107
Definition TextureInstanceTask.h:76
DECLARE_DELEGATE_TwoParams(FOnWorkDone, int32, int32)
void Sync()
Definition TextureInstanceTask.cpp:35
void operator()(bool bAsync)
Definition TextureInstanceTask.cpp:27
Definition TextureInstanceTask.h:25
FORCEINLINE_DEBUGGABLE void TrySync()
Definition TextureInstanceTask.h:46
TDoWorkTask(T &&... Args)
Definition TextureInstanceTask.h:30
FORCEINLINE void Init(T &&... Args)
Definition TextureInstanceTask.h:61
FORCEINLINE_DEBUGGABLE void TryWork(bool bAsync)
Definition TextureInstanceTask.h:35
virtual ~TDoWorkTask()
Definition TextureInstanceTask.h:32
Definition Array.h:670
Definition RefCounting.h:454
UE_FORCEINLINE_HINT void SafeRelease()
Definition RefCounting.h:599
Definition TextureInstanceTask.cpp:11
TDoWorkTask< FRefreshVisibility > FRefreshVisibilityTask
Definition TextureInstanceTask.h:172
TDoWorkTask< FNormalizeLightmapTexelFactor > FNormalizeLightmapTexelFactorTask
Definition TextureInstanceTask.h:173
ETaskState
Definition TextureInstanceTask.h:16
@ TS_SyncPending
Definition TextureInstanceTask.h:20
@ TS_Done
Definition TextureInstanceTask.h:17
@ TS_WorkInProgress
Definition TextureInstanceTask.h:19
@ TS_WorkPending
Definition TextureInstanceTask.h:18
TDoWorkTask< FCreateViewWithUninitializedBounds > FCreateViewWithUninitializedBoundsTask
Definition TextureInstanceTask.h:174
TDoWorkTask< FRefreshFull > FRefreshFullTask
Definition TextureInstanceTask.h:171
Definition LightweightStats.h:416