r.MeshDrawCommands.Stats
r.MeshDrawCommands.Stats
#Overview
name: r.MeshDrawCommands.Stats
This variable is created as a Console Variable (cvar).
- type:
Var
- help:
Show on screen mesh draw command stats.\nThe stats for visible triangles are post GPU culling.\n 1 = Show stats per pass.\n 2...N = Show the collection of stats matching the \'Collection\' parameter in the ini file.\nYou can also use \'stat culling\' to see global culling stats.\n
It is referenced in 7
C++ source files.
#Summary
#Usage in the C++ source code
The purpose of r.MeshDrawCommands.Stats is to provide on-screen statistics for mesh draw commands in Unreal Engine 5. This setting variable is primarily used for performance monitoring and debugging in the rendering system.
This setting variable is relied upon by the Renderer module of Unreal Engine 5. It is specifically used within the MeshDrawCommandStats system, which is responsible for collecting and displaying statistics about mesh draw commands.
The value of this variable is set through a console variable (CVarMeshDrawCommandStats) defined in the MeshDrawCommandStats.cpp file. It can be set to different integer values, each representing a different level of statistics display:
- 0: No stats shown (default)
- 1: Show stats per pass
- 2 and above: Show stats for a specific collection defined in the ini file
The associated variable CVarMeshDrawCommandStats interacts directly with r.MeshDrawCommands.Stats. They share the same value and are used interchangeably in the code.
Developers should be aware of the following when using this variable:
- The stats shown are post-GPU culling, meaning they represent visible triangles.
- Different values provide different levels of detail in the statistics.
- The variable can be used in conjunction with ‘stat culling’ for more comprehensive culling stats.
Best practices when using this variable include:
- Use it judiciously, as displaying stats can impact performance.
- Combine it with other debugging tools like ‘stat culling’ for a more complete picture.
- Be aware of the different collection options available in the ini file for more targeted statistics.
Regarding the associated variable CVarMeshDrawCommandStats:
The purpose of CVarMeshDrawCommandStats is to provide a programmatic way to control the r.MeshDrawCommands.Stats setting within the C++ code of Unreal Engine 5.
This variable is used directly in the Renderer module, specifically in the MeshDrawCommandStats system. It controls the behavior of the stats collection and display.
The value of CVarMeshDrawCommandStats is set when it’s initialized in the MeshDrawCommandStats.cpp file. It can be modified at runtime through console commands.
CVarMeshDrawCommandStats interacts directly with r.MeshDrawCommands.Stats, effectively serving as its C++ representation.
Developers should be aware that changes to CVarMeshDrawCommandStats will directly affect the behavior of the mesh draw command statistics system.
Best practices for using CVarMeshDrawCommandStats include:
- Use it for programmatic control of mesh draw command statistics in C++ code.
- Be cautious when modifying its value, as it can affect performance and debugging capabilities.
- Consider the implications on different platforms and hardware configurations when enabling or modifying statistics collection.
#References in C++ code
#Callsites
This variable is referenced in the following C++ source code:
#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/MeshDrawCommandStats.cpp:40
Scope: file
Source code excerpt:
static TAutoConsoleVariable<int32> CVarMeshDrawCommandStats(
TEXT("r.MeshDrawCommands.Stats"),
0,
TEXT("Show on screen mesh draw command stats.\n")
TEXT("The stats for visible triangles are post GPU culling.\n")
TEXT(" 1 = Show stats per pass.\n")
TEXT(" 2...N = Show the collection of stats matching the 'Collection' parameter in the ini file.\n")
TEXT("You can also use 'stat culling' to see global culling stats.\n"),
#Loc: <Workspace>/Engine/Source/Runtime/Engine/Public/MeshDrawCommandStatsSettings.h:51
Scope (from outer to inner):
file
function class ENGINE_API UMeshDrawCommandStatsSettings : public UDeveloperSettings { GENERATED_BODY
Source code excerpt:
public:
/** Budgets used by r.MeshDrawCommands.Stats */
UPROPERTY(config, EditAnywhere, Category = Engine)
TArray<FMeshDrawCommandStatsBudget> Budgets;
/** The total primitive budget for a collection. */
UPROPERTY(config, EditAnywhere, Category = Engine)
TArray<FMeshDrawCommandStatsBudgetTotals> BudgetTotals;
/** Which collection to export to CSV */
#Associated Variable and Callsites
This variable is associated with another variable named CVarMeshDrawCommandStats
. They share the same value. See the following C++ source code.
#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/MeshDrawCommandStats.cpp:39
Scope: file
Source code excerpt:
};
static TAutoConsoleVariable<int32> CVarMeshDrawCommandStats(
TEXT("r.MeshDrawCommands.Stats"),
0,
TEXT("Show on screen mesh draw command stats.\n")
TEXT("The stats for visible triangles are post GPU culling.\n")
TEXT(" 1 = Show stats per pass.\n")
TEXT(" 2...N = Show the collection of stats matching the 'Collection' parameter in the ini file.\n")
#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/MeshDrawCommandStats.cpp:149
Scope (from outer to inner):
file
function FMeshDrawCommandStatsManager::FMeshDrawCommandStatsManager
lambda-function
Source code excerpt:
int32 TotalPrimitivesUntracked = 0;
const bool bShowStats = CVarMeshDrawCommandStats->GetInt() != (int)MeshDrawStatsCollection::None;
if (bShowStats)
{
OutMessages.Add(FCoreDelegates::EOnScreenMessageSeverity::Info, FText::FromString(FString::Printf(TEXT("MeshDrawCommandStats (Triangles / Budget - Category):"), Stats.TotalPrimitives / 1000)));
int Collection = CVarMeshDrawCommandStats->GetInt();
// Show budgeted stats first.
const UMeshDrawCommandStatsSettings* Settings = GetDefault<UMeshDrawCommandStatsSettings>();
for (FMeshDrawCommandStatsBudget const& CategoryBudget : Settings->Budgets)
{
if (CategoryBudget.Collection == Collection)
#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/MeshDrawCommandStats.cpp:285
Scope (from outer to inner):
file
function void FMeshDrawCommandStatsManager::Update
Source code excerpt:
++CurrentFrameNumber;
const bool bShowPassNameStats = CVarMeshDrawCommandStats->GetInt() == (int)MeshDrawStatsCollection::Pass;
FScopeLock ScopeLock(&FrameDataCS);
bool bHasProcessedFrame = false;
// TODO: might be more than one from a given frame. E.g., if it was using a scene capture, need to filter out those, or perhaps record them as a group actually.
#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/MeshDrawCommandStats.cpp:419
Scope (from outer to inner):
file
function void FMeshDrawCommandStatsManager::Update
Source code excerpt:
// Collect stats during the next frame (check if STATGROUP_Culling is also visible somehow)
const bool bShowStats = CVarMeshDrawCommandStats->GetInt() != (int)MeshDrawStatsCollection::None;
bCollectStats = bShowStats || bRequestDumpStats;
#if CSV_PROFILER
const bool bCsvExport = FCsvProfiler::Get()->IsCapturing_Renderthread() && FCsvProfiler::Get()->IsCategoryEnabled(CSV_CATEGORY_INDEX(MeshDrawCommandStats));
bCollectStats |= bCsvExport;
#endif
#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/MeshDrawCommandStats.cpp:485
Scope (from outer to inner):
file
function void FMeshDrawCommandStatsManager::Update
Source code excerpt:
UntrackedPrimitives.Reset();
int CollectionIdx = CVarMeshDrawCommandStats->GetInt();
#if CSV_PROFILER // If capturing for CSV, override the collection to the one requested in the ini file
if (FCsvProfiler::Get()->IsCapturing_Renderthread() && FCsvProfiler::Get()->IsCategoryEnabled(CSV_CATEGORY_INDEX(MeshDrawCommandStats)))
{
CollectionIdx = GetDefault<UMeshDrawCommandStatsSettings>()->CollectionForCsvProfiler;
}