UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
VirtualTextureAllocator.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"
6#include "Containers/HashTable.h"
8
10
13{
14public:
15 RENDERER_API explicit FVirtualTextureAllocator(uint32 Dimensions);
17
22
23 uint32 GetAllocatedWidth() const { return AllocatedWidth; }
24 uint32 GetAllocatedHeight() const { return AllocatedHeight; }
25
31 inline FAllocatedVirtualTexture* Find(uint32 vAddress) const { uint32 UnusedLocal_vAddress = 0u; return Find(vAddress, UnusedLocal_vAddress); }
32
38
44
49
51 inline uint32 GetNumAllocations() const { return NumAllocations; }
52
54 inline uint32 GetNumAllocatedPages() const { return NumAllocatedPages; }
55
58
59#if WITH_EDITOR
60 RENDERER_API void SaveDebugImage(const TCHAR* ImageName) const;
61#endif
62
63private:
64 enum class EBlockState : uint8
65 {
66 None,
67 GlobalFreeList,
68 FreeList,
69 PartiallyFreeList,
70 AllocatedTexture,
71 };
72
73 struct FTestRegion
74 {
75 uint32 BaseIndex;
76 uint32 vTileX0;
77 uint32 vTileY0;
78 uint32 vTileX1;
79 uint32 vTileY1;
80 };
81
82 RENDERER_API void LinkFreeList(uint16& InOutListHead, EBlockState State, uint16 Index);
83 RENDERER_API void UnlinkFreeList(uint16& InOutListHead, EBlockState State, uint16 Index);
84
85 RENDERER_API int32 AcquireBlock();
86 RENDERER_API void FreeAddressBlock(uint32 Index, bool bTopLevelBlock);
87 RENDERER_API uint32 FindAddressBlock(uint32 vAddress) const;
88
89 RENDERER_API void SubdivideBlock(uint32 ParentIndex);
90
92
93 RENDERER_API bool TestAllocation(uint32 Index, uint32 vTileX0, uint32 vTileY0, uint32 vTileX1, uint32 vTileY1) const;
94
95 RENDERER_API void RecurseComputeFreeMip(uint16 BlockIndex, uint32 Depth, uint64& IoBlockMap) const;
96 RENDERER_API uint32 ComputeFreeMip(uint16 BlockIndex) const;
97
98 RENDERER_API void FreeMipUpdateParents(uint16 ParentIndex);
99
100#if WITH_EDITOR
102#endif
103
104 struct FAddressBlock
105 {
107 uint32 vAddress : 24;
108 uint32 vLogSize : 4;
109 uint32 MipBias : 4;
111 uint16 FirstChild;
112 uint16 FirstSibling;
113 uint16 NextSibling;
114 uint16 NextFree;
115 uint16 PrevFree;
116 EBlockState State;
117 uint8 FreeMip;
118
119 FAddressBlock()
120 {}
121
122 FAddressBlock(uint8 LogSize)
123 : VT(nullptr)
124 , vAddress(0)
125 , vLogSize(LogSize)
126 , MipBias(0)
127 , Parent(0xffff)
128 , FirstChild(0xffff)
129 , FirstSibling(0xffff)
130 , NextSibling(0xffff)
131 , NextFree(0xffff)
132 , PrevFree(0xffff)
133 , State(EBlockState::None)
134 , FreeMip(0)
135 {}
136
137 FAddressBlock(const FAddressBlock& Block, uint32 Offset, uint32 Dimensions)
138 : VT(nullptr)
139 , vAddress(Block.vAddress + (Offset << (Dimensions * Block.vLogSize)))
140 , vLogSize(Block.vLogSize)
141 , MipBias(0)
143 , FirstChild(0xffff)
144 , FirstSibling(Block.FirstSibling)
145 , NextSibling(0xffff)
146 , NextFree(0xffff)
147 , PrevFree(0xffff)
148 , State(EBlockState::None)
149 , FreeMip(0)
150 {}
151 };
152
153 // We separate items in the partially free list by the alignment of sub-allocation that can
154 // potentially fit, based on what's already allocated. A level of zero means a block could
155 // be allocated at 1x1 tile alignment, one means 2x2, etc. It caps at level 3 (8x8) to
156 // keep the cost of updating this information manageable. Capping it means we don't need
157 // to recurse too far into children or update too many parents when a block's state changes.
158 static const uint32 PartiallyFreeMipDepth = 4;
159
160 struct FPartiallyFreeMip
161 {
162 uint16 Mips[PartiallyFreeMipDepth];
163 };
164
165 const uint32 vDimensions;
166 uint32 AllocatedWidth;
167 uint32 AllocatedHeight;
168
169 TArray< FAddressBlock > AddressBlocks;
170 TArray< uint16 > FreeList;
171 TArray< FPartiallyFreeMip > PartiallyFreeList;
172 uint16 GlobalFreeList;
173 TArray< uint32 > SortedAddresses;
174 TArray< uint16 > SortedIndices;
175 FHashTable HashTable;
176 uint16 RootIndex;
177
178 uint32 NumAllocations;
179 uint32 NumAllocatedPages;
180};
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
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
uint32 Offset
Definition VulkanMemory.cpp:4033
int BlockIndex
Definition binka_ue_decode_test.cpp:38
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 AllocatedVirtualTexture.h:18
Definition HashTable.h:210
Definition VirtualTextureAllocator.h:13
RENDERER_API void DumpToConsole(bool verbose)
Definition VirtualTextureAllocator.cpp:771
RENDERER_API bool TryAlloc(uint32 InSize)
Definition VirtualTextureAllocator.cpp:172
~FVirtualTextureAllocator()
Definition VirtualTextureAllocator.h:16
uint32 GetAllocatedWidth() const
Definition VirtualTextureAllocator.h:23
uint32 GetNumAllocatedPages() const
Definition VirtualTextureAllocator.h:54
uint32 GetAllocatedHeight() const
Definition VirtualTextureAllocator.h:24
uint32 GetNumAllocations() const
Definition VirtualTextureAllocator.h:51
FAllocatedVirtualTexture * Find(uint32 vAddress) const
Definition VirtualTextureAllocator.h:31
RENDERER_API uint32 Alloc(FAllocatedVirtualTexture *VT)
Definition VirtualTextureAllocator.cpp:396
Definition UnrealString.h.inl:34
@ None
Definition EnvQueryTypes.h:117
State
Definition PacketHandler.h:88
U16 Index
Definition radfft.cpp:71