UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
TextureMipDataProvider.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3/*=============================================================================
4TextureMipDataProvider.h: Base class for providing the mip data used by FTextureStreamIn.
5=============================================================================*/
6
7#pragma once
8
9#include "CoreMinimal.h"
11#include "PixelFormat.h"
12#include "RHIDefinitions.h"
13#include "RHIFwd.h"
15
16class UTexture;
19struct FTexture2DMipMap;
20
21// Describes a mip that gets updated through FTextureStreamIn.
23{
24 void* DestData = nullptr; // The mip data where the content must be copied too.
25 uint64 DataSize = 0; // Optional, might be 0 in cooked. Mostly for safeguard.
29 uint32 SizeZ = 0; // For 3d textures
30 uint32 ArraySize = 0; // For texture arrays / cubemaps
32 uint32 DepthPitch = 0; // For volume texture, texture array only.
33 ECubeFace CubeFace = CubeFace_MAX; // Cubemap only.
34};
35
36// An array of mips mapped to a given texture asset. 0 based on the highest mip count for this texture.
38
48{
50
51 // A bool to tell whether the tick should be postponed by a small duration (undefined by design).
52 bool* bSnooze = nullptr;
53 // A counter that will be incremented before doing an operation and then decremented once has completed.
55
56 // A callback to force a new tick on the relevant thread.
58};
59
65{
67
70
72
73 // The texture to update, this must be the same one as the one used when creating the FTextureUpdate object.
74 const UTexture* Texture = nullptr;
75
78
81
82 // The current executing thread.
84};
85
92{
93public:
94
95 enum class ETickState : uint32
96 {
97 Init, // Call Init(), which must initialize the mip data provider so that it can efficiently provide the mips in GetMips.
98 GetMips, // Call GetMips(), which must fill mip data from highest to lowest (all mips might not be available thought).
99 PollMips, // Call PollMips(), which stalls the mip update until the mip have been set.
100 PostprocessGPUMipData, // Call PostprocessGPUMipData(), which allows for mip updates after the texture has been uploaded to the GPU
101 CleanUp, // Call CleanUp(), which must release all temporary resource created in the update process.
102 Done
103 };
104
105 enum class ETickThread : uint32
106 {
107 Async, // Tick must run on an async thread.
108 Render, // Tick must run on the renderthread.
109 None, // No tick must run, only valid in ETickState::Done.
110 };
111
112 // Constructor, defining the first tick step and thread.
114
116
117 // Get the next tick state and thread for the mip allocator. Used by FTextureStreamIn to schedule correctly the update between FTextureMipAllocator and FTextureMipDataProvider.
118 inline ETickState GetNextTickState() const { return NextTickState; }
119 inline ETickThread GetNextTickThread() const { return NextTickThread; }
120
129 virtual void Init(const FTextureUpdateContext& Context, const FTextureUpdateSyncOptions& SyncOptions) = 0;
130
142 virtual int32 GetMips(const FTextureUpdateContext& Context, int32 StartingMipIndex, const FTextureMipInfoArray& MipInfos, const FTextureUpdateSyncOptions& SyncOptions) = 0;
143
151 virtual bool PollMips(const FTextureUpdateSyncOptions& SyncOptions) = 0;
152
153 /*
154 * Once the texture has been uploaded to the GPU, the mip provider has the opportunity to perform any modifications necessary
155 * before the texture is finalized and applied to the texture resource.
156 */
157 UE_DEPRECATED(5.7, "Implement the version that takes FirstMip and NumMips.")
159
160 /*
161 * Once the texture has been uploaded to the GPU, the mip provider has the opportunity to perform any modifications necessary
162 * before the texture is finalized and applied to the texture resource.
163 */
164 ENGINE_API virtual bool PostprocessGPUMipData(const FTextureUpdateContext& Context, const FTextureRHIRef& TextureRHI, int32 FirstMip, int32 NumMips, const FTextureUpdateSyncOptions& SyncOptions);
165
173 virtual void AbortPollMips() {}
174
183
189 virtual void CleanUp(const FTextureUpdateSyncOptions& SyncOptions) = 0;
190
198 virtual void Cancel(const FTextureUpdateSyncOptions& SyncOptions) = 0;
199
200 // Returns on which thread Cancel() must be called in the texture update (from FTextureStreamIn) to release ressources safely and correctly. ETickThread::None when ready to delete this.
201 virtual ETickThread GetCancelThread() const = 0;
202
203protected:
204
205 // Helper to set the next tick state and thread. Validates that the progression is coherent.
207 {
208 // State must advance or at least stay to the same step.
209 check((uint32)NextTickState <= (uint32)InState);
210 // Thread must be valid unless in done state.
212
213 NextTickState = InState;
214 NextTickThread = InThread;
215 }
216
219 // The resident first LOD resource index. With domain = [0, ResourceState.NumLODs[. NOT THE ASSET LOD INDEX!
221 // The requested first LOD resource index. With domain = [0, ResourceState.NumLODs[. NOT THE ASSET LOD INDEX!
223
224private:
225
226 // The next tick function that should be called.
227 ETickState NextTickState = ETickState::Done;
228 // The next tick thread from where to call the tick function.
229 ETickThread NextTickThread = ETickThread::None;
230};
231
OODEFFUNC typedef void(OODLE_CALLBACK t_fp_OodleCore_Plugin_Free)(void *ptr)
#define check(expr)
Definition AssertionMacros.h:314
@ INDEX_NONE
Definition CoreMiscDefines.h:150
#define UE_DEPRECATED(Version, Message)
Definition CoreMiscDefines.h:302
FPlatformTypes::int32 int32
A 32-bit signed integer.
Definition Platform.h:1125
FPlatformTypes::uint64 uint64
A 64-bit unsigned integer.
Definition Platform.h:1117
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
EPixelFormat
Definition PixelFormat.h:16
@ PF_Unknown
Definition PixelFormat.h:17
ECubeFace
Definition RHIDefinitions.h:525
@ CubeFace_MAX
Definition RHIDefinitions.h:532
TArray< TUniquePtr< FTextureMipDataProvider >, TInlineAllocator< 2 > > FTextureMipDataProviderArray
Definition TextureMipDataProvider.h:232
TArray< FTextureMipInfo, TInlineAllocator< MAX_TEXTURE_MIP_COUNT > > FTextureMipInfoArray
Definition TextureMipDataProvider.h:37
uint32_t uint32
Definition binka_ue_file_header.h:6
Definition StreamableTextureResource.h:20
Definition TextureMipDataProvider.h:92
virtual ETickThread GetCancelThread() const =0
ETickThread
Definition TextureMipDataProvider.h:106
ETickState
Definition TextureMipDataProvider.h:96
virtual void CleanUp(const FTextureUpdateSyncOptions &SyncOptions)=0
virtual void AbortPostprocessGPUMipData()
Definition TextureMipDataProvider.h:182
virtual bool PollMips(const FTextureUpdateSyncOptions &SyncOptions)=0
virtual int32 GetMips(const FTextureUpdateContext &Context, int32 StartingMipIndex, const FTextureMipInfoArray &MipInfos, const FTextureUpdateSyncOptions &SyncOptions)=0
const int32 PendingFirstLODIdx
Definition TextureMipDataProvider.h:222
virtual void Cancel(const FTextureUpdateSyncOptions &SyncOptions)=0
void AdvanceTo(ETickState InState, ETickThread InThread)
Definition TextureMipDataProvider.h:206
ETickState GetNextTickState() const
Definition TextureMipDataProvider.h:118
virtual void AbortPollMips()
Definition TextureMipDataProvider.h:173
const FStreamableRenderResourceState ResourceState
Definition TextureMipDataProvider.h:218
virtual ~FTextureMipDataProvider()
Definition TextureMipDataProvider.h:115
virtual void Init(const FTextureUpdateContext &Context, const FTextureUpdateSyncOptions &SyncOptions)=0
ETickThread GetNextTickThread() const
Definition TextureMipDataProvider.h:119
const int32 CurrentFirstLODIdx
Definition TextureMipDataProvider.h:220
Definition ThreadSafeCounter.h:14
Definition ArrayView.h:139
Definition Array.h:670
Definition AndroidPlatformMisc.h:14
Definition ContainerAllocationPolicies.h:894
Definition StreamableRenderAsset.h:37
Definition Texture.h:1219
Definition StreamableRenderResourceState.h:23
Definition TextureResource.h:46
Definition TextureMipDataProvider.h:23
uint32 RowPitch
Definition TextureMipDataProvider.h:31
uint32 DepthPitch
Definition TextureMipDataProvider.h:32
uint32 SizeZ
Definition TextureMipDataProvider.h:29
EPixelFormat Format
Definition TextureMipDataProvider.h:26
uint32 ArraySize
Definition TextureMipDataProvider.h:30
uint32 SizeX
Definition TextureMipDataProvider.h:27
ECubeFace CubeFace
Definition TextureMipDataProvider.h:33
void * DestData
Definition TextureMipDataProvider.h:24
uint32 SizeY
Definition TextureMipDataProvider.h:28
uint64 DataSize
Definition TextureMipDataProvider.h:25
Definition TextureMipDataProvider.h:65
EThreadType CurrentThread
Definition TextureMipDataProvider.h:83
int32 EThreadType
Definition TextureMipDataProvider.h:66
EThreadType GetCurrentThread() const
Definition TextureMipDataProvider.h:71
TArrayView< const FTexture2DMipMap * > MipsView
Definition TextureMipDataProvider.h:80
FStreamableTextureResource * Resource
Definition TextureMipDataProvider.h:77
const UTexture * Texture
Definition TextureMipDataProvider.h:74
Definition TextureMipDataProvider.h:48
bool * bSnooze
Definition TextureMipDataProvider.h:52
FCallback RescheduleCallback
Definition TextureMipDataProvider.h:57
TFunction< void()> FCallback
Definition TextureMipDataProvider.h:49
FThreadSafeCounter * Counter
Definition TextureMipDataProvider.h:54