UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
TexturePagePool.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
5#include "CoreMinimal.h"
8#include "Containers/HashTable.h"
9
16
24{
25public:
28
30
31 FCriticalSection& GetLock() { return CriticalSection; }
32
33 uint32 GetNumPages() const { return FMath::Max(NumPages, NumReservedPages) - NumReservedPages; }
34 uint32 GetNumLockedPages() const { return GetNumPages() - FreeHeap.Num(); }
35 uint32 GetNumMappedPages() const { return NumPagesMapped; }
36 uint32 GetNumAllocatedPages() const { return NumPagesAllocated; }
37
42
46 void EvictPages(FVirtualTextureSystem* System, const FVirtualTextureProducerHandle& ProducerHandle);
47
54
58 void UnmapAllPagesForSpace(FVirtualTextureSystem* System, uint8 SpaceID, uint32 vAddress, uint32 Width, uint32 Height, uint32 MaxLevel);
59
64
69
71
73 inline uint8 GetLocalLevelForAddress(uint16 pAddress) const { check(Pages[pAddress].PackedValue != 0u); return Pages[pAddress].Local_vLevel; }
74
79
83 uint32 FindPageAddress(const FVirtualTextureProducerHandle& ProducerHandle, uint8 GroupIndex, uint32 Local_vAddress, uint8 Local_vLevel) const;
84
88 uint32 FindNearestPageAddress(const FVirtualTextureProducerHandle& ProducerHandle, uint8 GroupIndex, uint32 Local_vAddress, uint8 Local_vLevel, uint8 MaxLevel) const;
89
93 uint32 FindNearestPageLevel(const FVirtualTextureProducerHandle& ProducerHandle, uint8 GroupIndex, uint32 Local_vAddress, uint8 Local_vLevel) const;
94
106 uint32 Alloc(FVirtualTextureSystem* System, uint32 Frame, const FVirtualTextureProducerHandle& ProducerHandle, uint8 GroupIndex, uint32 Local_vAddress, uint8 Local_vLevel, bool bLock);
107
111 void Free(FVirtualTextureSystem* System, uint16 pAddress);
112
116 void Lock(uint16 pAddress);
117
121 void Unlock(uint32 Frame, uint16 pAddress);
122
127 void UpdateUsage(uint32 Frame, uint16 pAddress);
128
133
138
142 void MapPage(FVirtualTextureSpace* Space, FVirtualTexturePhysicalSpace* PhysicalSpace, uint8 PageTableLayerIndex, uint8 MaxLevel, uint8 vLogSize, uint32 vAddress, uint8 Local_vLevel, uint16 pAddress);
143
144private:
145 // Allocate 24 bits to store next/prev indices, pack layer index into 8 bits
146 static const uint32 PAGE_MAPPING_CAPACITY = 0x00ffffff;
147
148 struct FPageMapping
149 {
150 uint32 vAddress : 24;
151 uint32 vLogSize : 4;
152 uint32 MaxLevel : 4;
153
154 uint32 NextIndex : 24;
155 uint32 SpaceID : 8;
156
157 uint32 PrevIndex : 24;
158 uint32 PageTableLayerIndex : 8;
159 };
160
161 union FPageEntry
162 {
163 uint64 PackedValue;
164 struct
165 {
166 uint32 PackedProducerHandle;
167 uint32 Local_vAddress : 24;
168 uint32 Local_vLevel : 4;
169 uint32 GroupIndex : 4;
170 };
171 };
172
173 static uint16 GetPageHash(const FPageEntry& Entry);
174
175 void UnmapPageMapping(FVirtualTextureSystem* System, uint32 MappingIndex, bool bMapAncestorPage);
176 void UnmapAllPages(FVirtualTextureSystem* System, uint16 pAddress, bool bMapAncestorPages);
177
178 void RemoveMappingFromList(uint32 Index)
179 {
180 FPageMapping& Mapping = PageMapping[Index];
181 PageMapping[Mapping.PrevIndex].NextIndex = Mapping.NextIndex;
182 PageMapping[Mapping.NextIndex].PrevIndex = Mapping.PrevIndex;
183 Mapping.NextIndex = Mapping.PrevIndex = Index;
184 }
185
186 void AddMappingToList(uint32 HeadIndex, uint32 Index)
187 {
188 FPageMapping& Head = PageMapping[HeadIndex];
189 FPageMapping& Mapping = PageMapping[Index];
190 check(Index > NumPages); // make sure we're not trying to add a list head to another list
191 check(Index <= PAGE_MAPPING_CAPACITY);
192
193 // make sure we're not currently in any list
194 check(Mapping.NextIndex == Index);
195 check(Mapping.PrevIndex == Index);
196
197 Mapping.NextIndex = HeadIndex;
198 Mapping.PrevIndex = Head.PrevIndex;
199 PageMapping[Head.PrevIndex].NextIndex = Index;
200 Head.PrevIndex = Index;
201 }
202
203 uint32 AcquireMapping()
204 {
205 const uint32 FreeHeadIndex = NumPages;
206 FPageMapping& FreeHead = PageMapping[FreeHeadIndex];
207 uint32 Index = FreeHead.NextIndex;
208 if (Index != FreeHeadIndex)
209 {
210 RemoveMappingFromList(Index);
211 return Index;
212 }
213
214 Index = PageMapping.AddDefaulted();
215 check(Index <= PAGE_MAPPING_CAPACITY);
216 FPageMapping& Mapping = PageMapping[Index];
217 Mapping.NextIndex = Mapping.PrevIndex = Index;
218 return Index;
219 }
220
221 void ReleaseMapping(uint32 Index)
222 {
223 const uint32 FreeHeadIndex = NumPages;
224 RemoveMappingFromList(Index);
225 AddMappingToList(FreeHeadIndex, Index);
226 }
227
228 FCriticalSection CriticalSection;
229
231
232 FHashTable PageHash;
233 FHashTable ProducerToPageIndex;
234 TArray<FPageEntry> Pages;
235
236 // Holds linked lists of mappings for each physical page in the pool
237 // Indices [0, NumPages) hold the list head for list of mappings for each page
238 // Index 'NumPages' holds the list head for the free list
239 // Additional indices are list elements belonging to one of the prior lists
240 TArray<FPageMapping> PageMapping;
241
242 uint32 NumPages;
243 uint32 NumPagesMapped;
244 uint32 NumPagesAllocated;
245
246 static const uint32 NumReservedPages;
247};
#define check(expr)
Definition AssertionMacros.h:314
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
UE::FPlatformRecursiveMutex FCriticalSection
Definition CriticalSection.h:53
FRWLock Lock
Definition UnversionedPropertySerialization.cpp:921
EVTInvalidatePriority
Definition VirtualTextureEnum.h:29
uint8_t uint8
Definition binka_ue_file_header.h:8
uint16_t uint16
Definition binka_ue_file_header.h:7
uint32_t uint32
Definition binka_ue_file_header.h:6
Definition BinaryHeap.h:20
uint32 Num() const
Definition BinaryHeap.h:37
Definition HashTable.h:210
Definition TexturePagePool.h:24
uint8 GetLocalLevelForAddress(uint16 pAddress) const
Definition TexturePagePool.h:73
FCriticalSection & GetLock()
Definition TexturePagePool.h:31
void CollectProducerCounts(TMap< uint32, FUintVector2 > &OutProducerCountMap) const
Definition TexturePagePool.cpp:371
uint32 GetNumVisiblePages(uint32 Frame) const
Definition TexturePagePool.cpp:348
~FTexturePagePool()
Definition TexturePagePool.cpp:20
uint32 FindPageAddress(const FVirtualTextureProducerHandle &ProducerHandle, uint8 GroupIndex, uint32 Local_vAddress, uint8 Local_vLevel) const
Definition TexturePagePool.cpp:222
void RemapPages(FVirtualTextureSystem *System, uint8 SpaceID, FVirtualTexturePhysicalSpace *PhysicalSpace, FVirtualTextureProducerHandle const &ProducerHandleOld, uint32 OldVirtualAddress, FVirtualTextureProducerHandle const &ProducerHandleNew, uint32 NewVirtualAddress, int32 vLevelBias, uint32 Frame)
Definition TexturePagePool.cpp:453
uint32 Alloc(FVirtualTextureSystem *System, uint32 Frame, const FVirtualTextureProducerHandle &ProducerHandle, uint8 GroupIndex, uint32 Local_vAddress, uint8 Local_vLevel, bool bLock)
Definition TexturePagePool.cpp:275
FTexturePagePool()
Definition TexturePagePool.cpp:12
uint32 GetNumAllocatedPages() const
Definition TexturePagePool.h:36
void EvictAllPages(FVirtualTextureSystem *System)
Definition TexturePagePool.cpp:46
uint32 FindNearestPageLevel(const FVirtualTextureProducerHandle &ProducerHandle, uint8 GroupIndex, uint32 Local_vAddress, uint8 Local_vLevel) const
Definition TexturePagePool.cpp:259
void EvictPages(FVirtualTextureSystem *System, const FVirtualTextureProducerHandle &ProducerHandle)
Definition TexturePagePool.cpp:104
void UpdateUsage(uint32 Frame, uint16 pAddress)
Definition TexturePagePool.cpp:339
void GetAllLockedPages(FVirtualTextureSystem *System, TSet< union FVirtualTextureLocalTile > &OutPages)
Definition TexturePagePool.cpp:185
uint32 GetNumPages() const
Definition TexturePagePool.h:33
uint32 FindNearestPageAddress(const FVirtualTextureProducerHandle &ProducerHandle, uint8 GroupIndex, uint32 Local_vAddress, uint8 Local_vLevel, uint8 MaxLevel) const
Definition TexturePagePool.cpp:243
bool AnyFreeAvailable(uint32 Frame, uint32 FreeThreshold) const
Definition TexturePagePool.cpp:203
void MapPage(FVirtualTextureSpace *Space, FVirtualTexturePhysicalSpace *PhysicalSpace, uint8 PageTableLayerIndex, uint8 MaxLevel, uint8 vLogSize, uint32 vAddress, uint8 Local_vLevel, uint16 pAddress)
Definition TexturePagePool.cpp:385
FVirtualTextureLocalTile GetLocalTileFromPhysicalAddress(uint16 pAddress)
Definition TexturePagePool.cpp:198
void UnmapAllPagesForSpace(FVirtualTextureSystem *System, uint8 SpaceID, uint32 vAddress, uint32 Width, uint32 Height, uint32 MaxLevel)
Definition TexturePagePool.cpp:63
uint32 GetNumLockedPages() const
Definition TexturePagePool.h:34
void Unlock(uint32 Frame, uint16 pAddress)
Definition TexturePagePool.cpp:327
uint32 GetNumMappedPages() const
Definition TexturePagePool.h:35
Definition VirtualTexturePhysicalSpace.h:86
Definition VirtualTextureSpace.h:48
Definition VirtualTextureSystem.h:108
Definition Array.h:670
SizeType AddDefaulted()
Definition Array.h:2795
Definition UnrealString.h.inl:34
U16 Index
Definition radfft.cpp:71
Definition VirtualTexturing.h:148
Definition VirtualTexturing.h:495
Definition VirtualTexturing.h:33