UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
RenderAssetUpdate.inl
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3/*=============================================================================
4RenderAssetUpdate.inl: Base class of helpers to stream in and out texture/mesh LODs
5=============================================================================*/
6
7#pragma once
8
9#include "RenderAssetUpdate.h"
10
11template <typename TContext>
14 , TaskThread(TT_None)
15 , TaskCallback(nullptr)
16 , CancelationThread(TT_None)
17 , CancelationCallback(nullptr)
18{
19
20}
21
22template <typename TContext>
24{
25 // PushTask can only be called by the one thread/callback that is doing the processing.
26 // This means we don't need to check whether other threads could be trying to push tasks.
27 check(TaskState == TS_Locked || TaskState == TS_Init);
28 checkSlow((bool)InTaskCallback == (InTaskThread != TT_None));
30
31 TaskThread = InTaskThread;
32 TaskCallback = InTaskCallback;
33 CancelationThread = InCancelationThread;
34 CancelationCallback = InCancelationCallback;
35}
36
37template <typename TContext>
39{
40 check(TaskState == TS_Locked);
41
42 // Thread, callback and asset must be coherent because Abort() could be called while this is executing.
43 EThreadType RelevantThread = TaskThread;
44 FCallback RelevantCallback = TaskCallback;
45 const UStreamableRenderAsset* RelevantAsset = StreamableAsset;
46 if (bIsCancelled || !RelevantAsset)
47 {
48 RelevantThread = CancelationThread;
49 RelevantCallback = CancelationCallback;
50 // RelevantAsset = nullptr; // TODO once Cancel supports it!
51 }
52
53 if (RelevantThread == TT_None)
54 {
55 ClearCallbacks();
56 return TS_Done;
57 }
58 else if (TaskSynchronization.GetValue() > 0)
59 {
60 return TS_Suspended;
61 }
63 {
64 return TS_Suspended;
65 }
66 else if (bDeferExecution)
67 {
68 bDeferExecution = false;
69 return TS_Suspended;
70 }
72 {
73 ClearCallbacks();
76 return TS_Locked;
77 }
78 else if (RelevantThread == FRenderAssetUpdate::TT_GameThread && !ScheduledGTTasks)
79 {
80 ScheduleGTTask();
81 return TS_Locked;
82 }
83 else if (RelevantThread == FRenderAssetUpdate::TT_Render && !ScheduledRenderTasks)
84 {
86 {
87 // Note that it could execute now if this is the renderthread.
88 ScheduleRenderTask();
89 return TS_Locked;
90 }
91 else
92 {
93 // If render commands do not have their own thread, avoid unrelated thread to enqueue commands.
94 // This is to avoid issues from using RHIAsyncCreateTexture2D which doesn't give any feedback of when it is ready.
95 return TS_InProgress;
96 }
97 }
98 else if (RelevantThread == FRenderAssetUpdate::TT_Async && !ScheduledAsyncTasks)
99 {
100 ScheduleAsyncTask();
101 return TS_Locked;
102 }
103 else
104 {
105 return TS_InProgress;
106 }
107}
#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
bool IsAssetStreamingSuspended()
Definition RenderAssetUpdate.cpp:41
RENDERCORE_API bool GIsThreadedRendering
Definition RenderingThread.cpp:48
Definition RenderAssetUpdate.h:38
ETaskState
Definition RenderAssetUpdate.h:53
EThreadType
Definition RenderAssetUpdate.h:43
@ TT_Async
Definition RenderAssetUpdate.h:46
@ TT_Render
Definition RenderAssetUpdate.h:45
@ TT_GameThread
Definition RenderAssetUpdate.h:47
TContext FContext
Definition RenderAssetUpdate.h:246
void PushTask(const FContext &Context, EThreadType InTaskThread, const FCallback &InTaskCallback, EThreadType InCancelationThread, const FCallback &InCancelationCallback)
Definition RenderAssetUpdate.inl:23
ETaskState TickInternal(EThreadType InCurrentThread, bool bCheckForSuspension) final override
Definition RenderAssetUpdate.inl:38
TRenderAssetUpdate(const UStreamableRenderAsset *InAsset)
Definition RenderAssetUpdate.inl:12
Definition StreamableRenderAsset.h:37