UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
VisualizeTexture.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
5#include "Containers/Array.h"
6#include "Containers/Map.h"
8#include "HAL/Platform.h"
9#include "HAL/PlatformCrt.h"
10#include "Misc/EnumClassFlags.h"
11#include "Misc/Optional.h"
12#include "Misc/WildcardString.h"
14#include "RenderResource.h"
15#include "RendererInterface.h"
17
18
19class FOutputDevice;
20class FRDGBuilder;
22class FWildcardString;
23
25{
26public:
27 FVisualizeTexture() = default;
28
29 RENDERCORE_API void ParseCommands(const TCHAR* Cmd, FOutputDevice &Ar);
30
32
34
35#if SUPPORTS_VISUALIZE_TEXTURE
37 RENDERCORE_API void BeginViewRenderThread(ERHIFeatureLevel::Type InFeatureLevel, int32 UniqueId, const TCHAR* Description, bool bIsSceneCapture);
41
43 RENDERCORE_API void SetCheckPoint(FRDGBuilder& GraphBuilder, IPooledRenderTarget* PooledRenderTarget);
44 RENDERCORE_API void SetCheckPoint(FRHICommandListImmediate& RHICmdList, IPooledRenderTarget* PooledRenderTarget);
45#else
46 inline void BeginFrameRenderThread() {}
47 inline void EndFrameRenderThread() {}
48
49 inline void SetCheckPoint(FRDGBuilder& GraphBuilder, IPooledRenderTarget* PooledRenderTarget) {}
50 inline void SetCheckPoint(FRHICommandListImmediate& RHICmdList, IPooledRenderTarget* PooledRenderTarget) {}
51#endif
52
53 inline bool IsActive() const
54 {
55#if SUPPORTS_VISUALIZE_TEXTURE
56 return State != EState::Inactive;
57#else
58 return false;
59#endif
60 }
61
62 inline bool IsRequestedView() const
63 {
64#if SUPPORTS_VISUALIZE_TEXTURE
65 return bIsRequestedView;
66#else
67 return false;
68#endif
69 }
70
72 FRDGBuilder& GraphBuilder,
73 class FGlobalShaderMap* ShaderMap,
74 const FRDGTextureRef InputTexture);
75
77 FRDGBuilder& GraphBuilder,
78 class FGlobalShaderMap* ShaderMap,
79 const FRDGTextureRef InputTexture);
80
81private:
82 enum class EFlags
83 {
84 None = 0,
85 SaveBitmap = 1 << 0,
86 SaveBitmapAsStencil = 1 << 1, // stencil normally displays in the alpha channel of depth buffer visualization. This option is just for BMP writeout to get a stencil only BMP.
87 };
89
90 enum class EState
91 {
92 Inactive, // Default initial state, negligible overhead
93 DisplayViews, // Display views next render frame -- state activated on DisplayViewListToLog call if Inactive
94 DisplayResources, // Display resources next render frame -- state activated on DisplayResourceListToLog call if Inactive
95 TrackResources, // Track resources every frame, adding overhead -- state activated after visualize texture related command is issued
96 };
97
98 enum class ECommand
99 {
100 Unknown,
101 DisableVisualization,
102 VisualizeResource,
103 DisplayHelp,
104 DisplayPoolResourceList,
105 DisplayResourceList,
106 DisplayViewList,
107 SetViewId
108 };
109
110 enum class EInputUVMapping
111 {
112 LeftTop,
113 Whole,
114 PixelPerfectCenter,
115 PictureInPicture
116 };
117
118 enum class EInputValueMapping
119 {
120 Color,
121 Depth,
122 Shadow
123 };
124
125 enum class EDisplayMode
126 {
127 MultiColomn,
128 Detailed,
129 };
130
131 enum class ESortBy
132 {
133 Index,
134 Name,
135 Size
136 };
137
138 enum class EShaderOp
139 {
140 Frac,
142 };
143
144#if SUPPORTS_VISUALIZE_TEXTURE
145 static RENDERCORE_API void DisplayHelp(FOutputDevice &Ar);
146 RENDERCORE_API void DisplayPoolResourceListToLog(ESortBy SortBy);
149
151 RENDERCORE_API TOptional<uint32> ShouldCapture(const TCHAR* DebugName, uint32 MipIndex);
152
153 struct FConfig
154 {
155 float RGBMul = 1.0f;
156 float AMul = 0.0f;
157
158 // -1=off, 0=R, 1=G, 2=B, 3=A
159 int32 SingleChannel = -1;
160 float SingleChannelMul = 0.0f;
161
162 EFlags Flags = EFlags::None;
163 EInputUVMapping InputUVMapping = EInputUVMapping::PictureInPicture;
164 EShaderOp ShaderOp = EShaderOp::Frac;
165 uint32 MipIndex = 0;
166 uint32 ArrayIndex = 0;
167 };
168
171 FRDGBuilder& GraphBuilder,
172 class FGlobalShaderMap* ShaderMap,
173 const FRDGTextureRef InputTexture,
174 const FConfig& Config,
175 EInputValueMapping InputValueMapping,
177
180
181 RENDERCORE_API void ReleaseRHI() override;
182
183 RENDERCORE_API void Visualize(const FString& InName, TOptional<uint32> InVersion = {});
184
185 RENDERCORE_API uint32 GetVersionCount(const TCHAR* InName) const;
186
187 FConfig Config;
188
189 EState State = EState::Inactive;
190 TOptional<FWildcardString> DisplayResourcesParam; // Cached parameter for EState::DisplayResources
191
192 bool bAnyViewRendered = false; // Track when any view is rendered in the current frame, so we can ignore frames where no views render
193 bool bIsRequestedView = false; // Set when this is a requested view, and we should capture visualizations from it
194 bool bFoundRequestedView = false; // Set so we can stop considering other views, after we found the specific view that was requested
195
196 // Initialized in SetSceneTextures, tracks viewports from whichever scene renderer contains the view being visualized
198
199 struct FRequested
200 {
201 uint32 ViewUniqueId = 0; // View requested to be visualized -- zero visualizes the last non-scene-capture view
202 FString ViewName; // Alternately, string name of view to visualize
203 FString Name;
205 } Requested;
206
207 struct FCaptured
208 {
209 FCaptured()
210 {
211 Desc.DebugName = TEXT("VisualizeTexture");
212 }
213
214 TRefCountPtr<IPooledRenderTarget> PooledRenderTarget;
215 FRDGTextureRef Texture = nullptr;
217 EInputValueMapping InputValueMapping = EInputValueMapping::Color;
218 int32 ViewUniqueId = 0; // View actually visualized
219 FIntPoint OutputExtent; // Viewport extent for visualized scene renderer
220 TArray<FIntRect> ViewRects; // Viewports from scene renderer being visualized
221 } Captured;
222
224
225 // Map of unique view ID to description, updated when views get rendered.
227
228 // Maps a texture name to its checkpoint version.
230#endif
231
232 friend class FRDGBuilder;
234};
235
236ENUM_CLASS_FLAGS(FVisualizeTexture::EFlags);
237
240
241#if SUPPORTS_VISUALIZE_TEXTURE
242
243// We use a macro to compile out calls to BeginViewRenderThread, because generating the arguments to the call may involve utility function calls
244// that the compiler can't optimize out, even if the function itself was an empty inline. This commonly includes a call to the "GetViewKey"
245// function to fetch UniqueId, which involves two function calls (one virtual), and any string formatting used to generate the Description.
246// For symmetry, a macro is also provided for EndViewRenderThread (even though for that case, an empty inline would compile out fine).
247#define VISUALIZE_TEXTURE_BEGIN_VIEW(FeatureLevel, UniqueId, Description, bIsSceneCapture) GVisualizeTexture.BeginViewRenderThread(FeatureLevel, UniqueId, Description, bIsSceneCapture)
248#define VISUALIZE_TEXTURE_END_VIEW() GVisualizeTexture.EndViewRenderThread()
249
250#else
251#define VISUALIZE_TEXTURE_BEGIN_VIEW(FeatureLevel, UniqueId, Description, bIsSceneCapture) (void)0
252#define VISUALIZE_TEXTURE_END_VIEW() (void)0
253#endif
#define TEXT(x)
Definition Platform.h:1272
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
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
#define FRIEND_ENUM_CLASS_FLAGS(Enum)
Definition EnumClassFlags.h:17
#define ENUM_CLASS_FLAGS(Enum)
Definition EnumClassFlags.h:6
RENDERCORE_API TGlobalResource< FVisualizeTexture > GVisualizeTexture
Definition VisualizeTexture.cpp:327
uint32 Size
Definition VulkanMemory.cpp:4034
uint32_t uint32
Definition binka_ue_file_header.h:6
Definition GlobalShader.h:173
Definition OutputDevice.h:133
Definition RenderGraphBuilder.h:49
Definition RenderGraphResources.h:571
Definition RHICommandList.h:4626
Definition RenderResource.h:37
virtual void ReleaseRHI()
Definition RenderResource.h:90
Definition VisualizeTexturePresent.h:8
Definition VisualizeTexture.h:25
static RENDERCORE_API FRDGTextureRef AddVisualizeTextureAlphaPass(FRDGBuilder &GraphBuilder, class FGlobalShaderMap *ShaderMap, const FRDGTextureRef InputTexture)
Definition VisualizeTexture.cpp:1143
void BeginFrameRenderThread()
Definition VisualizeTexture.h:46
bool IsRequestedView() const
Definition VisualizeTexture.h:62
void EndFrameRenderThread()
Definition VisualizeTexture.h:47
RENDERCORE_API void ParseCommands(const TCHAR *Cmd, FOutputDevice &Ar)
Definition VisualizeTexture.cpp:17
FVisualizeTexture()=default
RENDERCORE_API void GetTextureInfos_GameThread(TArray< FString > &Infos) const
Definition VisualizeTexture.cpp:302
RENDERCORE_API void DebugLogOnCrash()
Definition VisualizeTexture.cpp:294
void SetCheckPoint(FRDGBuilder &GraphBuilder, IPooledRenderTarget *PooledRenderTarget)
Definition VisualizeTexture.h:49
static RENDERCORE_API FRDGTextureRef AddVisualizeTexturePass(FRDGBuilder &GraphBuilder, class FGlobalShaderMap *ShaderMap, const FRDGTextureRef InputTexture)
Definition VisualizeTexture.cpp:1113
void SetCheckPoint(FRHICommandListImmediate &RHICmdList, IPooledRenderTarget *PooledRenderTarget)
Definition VisualizeTexture.h:50
bool IsActive() const
Definition VisualizeTexture.h:53
Definition WildcardString.h:18
Definition Array.h:670
Definition RenderResource.h:543
Definition UnrealString.h.inl:34
Definition RefCounting.h:454
@ Detailed
Definition BehaviorTreeTypes.h:219
@ Unknown
Definition BehaviorTreeTypes.h:183
@ Inactive
Definition BehaviorTreeTypes.h:174
Type
Definition RHIFeatureLevel.h:20
@ SM5
Definition RHIFeatureLevel.h:42
@ Color
Definition MeshPaintVisualize.h:20
const TCHAR * Name
Definition OodleDataCompression.cpp:30
State
Definition PacketHandler.h:88
Version
Definition NNEModelData.cpp:15
FValue Saturate(const FValue &Value)
Definition ShaderValue.cpp:1399
FValue Frac(const FValue &Value)
Definition ShaderValue.cpp:1429
@ Config
Property should be loaded/saved to ini file as permanent profile.
Definition ObjectMacros.h:1053
U16 Index
Definition radfft.cpp:71
Definition RendererInterface.h:81
Definition RendererInterface.h:494
Definition Optional.h:131
Definition IntPoint.h:25