UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
MeshDrawCommandStats.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2#pragma once
3
4#include "MeshPassProcessor.h"
5
6class FRDGBuilder;
8
9#if MESH_DRAW_COMMAND_STATS
10
15{
17
18 FMeshDrawCommandStatsData StatsData; //< Extracted stats data from the MDC
19 int32 PrimitiveCount = 0; //< Primitice count of a single instance
20 int32 TotalInstanceCount = 0; //< Total instance count if no per instance culling would be done
21 int16 VisibleInstanceCount = 0; //< Visisble instances (read back from indirect args if needed)
22 int16 NumBatches = 0; //< Total number of batched in this specific draw command
23
24 uint32 IndirectArgsOffset : 31; //< Offset in indirect arg buffer where results can be read (when using instance culling indirect args the pass offset needs to be applied on top of this to get the correct offset)
25 uint32 UseInstantCullingIndirectBuffer : 1; //< Is the draw command using the shared GPU scene instance culling indirect arg buffer?
26 FRHIBuffer* CustomIndirectArgsBuffer = nullptr; //< Optional custom indirect arg buffer which was provided to the MDC at draw time
27
28#if MESH_DRAW_COMMAND_DEBUG_DATA
29 int32 LODIndex = 0; //< LOD index in draw command.
30 int32 SegmentIndex = 0; //< Segment index in draw command.
31 FName ResourceName; //< Minimal resource name
32 FString MaterialName; //< Material name used during draw event
33#endif // MESH_DRAW_COMMAND_DEBUG_DATA
34};
35
40{
42
43 const TCHAR* PassName; //< Name of the pass
44 bool bBuildRenderingCommandsCalled = false; //< Have the final render commands been build and is the passed used
45 TArray<FVisibleMeshDrawCommandStatsData> DrawData; //< All the draw commands
46 TSet<FRHIBuffer*> CustomIndirectArgsBuffers; //< Set of all the custom indirect args used by the draw commands - needs manual readback requests
47
49 {
50 }
51
54 {
57 }
58
59private:
60
61 FRHIGPUBufferReadback* InstanceCullingGPUBufferReadback = nullptr; //< Possible shared instance culling readback buffer
62 int32 IndirectArgParameterOffset = 0; //< Base offset into the readback buffer when shared with other passes
63};
64
69{
70public:
71
72 static void CreateInstance();
73 static FMeshDrawCommandStatsManager* Get() { return Instance; }
74
76
83
84 bool CollectStats() const { return bCollectStats; }
85 void RequestDumpStats(const FString& InOptionalCategory)
86 {
87 bRequestDumpStats = true;
89 }
90 void Update();
91
92private:
93
95 {
96 FRHIGPUBufferReadback* GPUBufferReadback = nullptr;
98 };
99
103 struct FFrameData
104 {
106 ~FFrameData();
107
108 void Validate() const;
109 bool IsCompleted();
110
111 int32 FrameNumber = 0; //< Unique ever incrementing frame number
112 TArray<FMeshDrawCommandPassStats*> PassData; //< Stats for all the MDC passes running during this frame
113 TMap<FRHIBuffer*, FIndirectArgsBufferResult> CustomIndirectArgsBufferResults; //< Custom indirect arg readback result buffer lookup map
114 TArray<FRHIGPUBufferReadback*> RDGIndirectArgsReadbackBuffers; //< All indirect args buffers requested via RDG passes
115 bool bIndirectArgReadbackRequested = false;
116 };
117
118 struct FDrawData
119 {
120 FDrawData() = default;
122
123 void Reset()
124 {
125 PrimitiveCount = 0;
126 VertexCount = 0;
127 }
128
129 uint64 PrimitiveCount = 0;
130 uint64 VertexCount = 0;
131 };
132
136 struct FStats
137 {
138 void Reset()
139 {
140 TotalDrawData.Reset();
141 TotalInstances = 0;
142
145
148
149 CategoryStats.Empty();
150 }
151
153 int32 TotalInstances = 0;
154
157
160
164 struct FCategoryStats
165 {
167 : PassName(InPassName), CategoryName(InCategoryName), DrawData(InDrawData) {}
168 FName PassName;
169 FName CategoryName;
170 FDrawData DrawData;
171 };
173 };
174
175 FFrameData* GetOrAddFrameData()
176 {
177 // Need to add a new frame?
178 if (Frames.IsEmpty() || Frames.Last()->FrameNumber != CurrentFrameNumber)
179 {
180 if (!Frames.IsEmpty())
181 {
182 Frames.Last()->Validate();
183 }
184 Frames.Emplace(new FFrameData(CurrentFrameNumber));
185 }
186 return Frames.Last();
187 }
188
190 {
191 FName Name; // User supplied name for this category
192 FString PassFriendlyName; // Pipe delimited names of the passes for this category (FString because append to it as it's being created)
193 TSet<FName> Passes; // Passes this category cares about
194 TSet<FName> LinkedNames; // LinkedStats this collection cares about
195 FDrawData DrawBudgets; // Draw budget for this category
196 };
197
198 struct FStatCollection
199 {
201 {
203 }
204
205 void Finish()
206 {
207 for (int i = 0; i < Categories.Num(); i++)
208 {
209 for (FName& LinkedName : Categories[i].LinkedNames)
210 {
211 StatToCategoryIndices.FindOrAdd(LinkedName).Add(i);
212 }
213 }
214 }
215
220 };
221
223
225 void DumpStats(FFrameData* FrameData);
226
227 int32 CurrentFrameNumber = 0; //< Ever incrementing frame number
228 bool bRequestDumpStats = false; //< Dump stats requested via command?
229 bool bCollectStats = false; //< Collect stats during next frame?
230
231 FString OptionalCategory; //< Optional category to append to stats filename. Empty string if no category.
233 TArray<FFrameData*> Frames; //< All active frames (contains the frame for which we are collecting stats now and all frames waiting for GPU readback)
234 FStats Stats; //< Last updated frame stats
235 FStatCollectionMap StatCollections; //< Per Collection LinkedStatName to Budget CategoryName
236
237 TMap<FName, FDrawData> BudgetedDrawData; //< Budget CategoryName to Total Draw data Count
238 TMap<FName, FDrawData> UntrackedDrawData; //< Draw data stats which aren't tracked by any Budgets
239
240 FDelegateHandle ScreenMessageDelegate; //< Delegate used to render optional screen stats
241
243};
244
245#endif // MESH_DRAW_COMMAND_STATS
FPlatformTypes::int16 int16
A 16-bit signed integer.
Definition Platform.h:1123
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
UE::FPlatformRecursiveMutex FCriticalSection
Definition CriticalSection.h:53
uint32 Offset
Definition VulkanMemory.cpp:4033
uint32_t uint32
Definition binka_ue_file_header.h:6
Definition IDelegateInstance.h:14
Definition NameTypes.h:617
Definition RenderGraphResources.h:1321
Definition RenderGraphBuilder.h:49
Definition RHIResources.h:1581
Definition RHICommandList.h:4626
Definition RHIGPUReadback.h:116
Definition Array.h:670
UE_NODEBUG UE_FORCEINLINE_HINT ElementType & Last(SizeType IndexFromTheEnd=0) UE_LIFETIMEBOUND
Definition Array.h:1263
UE_NODEBUG UE_FORCEINLINE_HINT bool Find(const ElementType &Item, SizeType &Index) const
Definition Array.h:1302
Definition UnrealString.h.inl:34
FORCEINLINE T * Get(const FObjectPtr &ObjectPtr)
Definition ObjectPtr.h:426
bool IsCompleted(const HigherLevelTaskType &Prerequisite)
Definition Task.h:351
Definition MeshPassProcessor.h:837
Definition StatsSystem.h:13