r.ShaderPrint
r.ShaderPrint
#Overview
name: r.ShaderPrint
This variable is created as a Console Variable (cvar).
- type:
Var
- help:
ShaderPrint debugging toggle.\n
It is referenced in 3
C++ source files.
#Summary
#Usage in the C++ source code
The purpose of r.ShaderPrint is to enable or disable shader print debugging functionality in Unreal Engine 5. This console variable acts as a toggle for the ShaderPrint system, which allows developers to output debug information directly from shaders.
The ShaderPrint system is primarily used in the rendering subsystem of Unreal Engine. Based on the callsites, it’s evident that the Renderer module and the DeformerGraph plugin (part of the Animation system) rely on this setting variable.
The value of this variable is set through the console or configuration files. It’s defined as an FAutoConsoleVariableRef, which means it can be changed at runtime using console commands.
Other variables that interact with r.ShaderPrint include:
- r.ShaderPrint.FontSize, which likely controls the size of the debug text output.
- bForceEnable in the OptimusDataInterfaceDebugDraw class, which can force enable debug rendering regardless of the r.ShaderPrint setting.
Developers must be aware that:
- This is a cheat and render thread safe console variable, meaning it’s intended for debugging and can be safely changed during rendering.
- Enabling this variable may have performance implications, as it adds additional debug rendering.
- Some systems, like the SubstrateRoughRefraction, explicitly check if ShaderPrint is enabled before proceeding with certain debug operations.
Best practices when using this variable include:
- Only enable it when necessary for debugging, as it may impact performance.
- Combine it with other debug variables (like r.ShaderPrint.FontSize) for more effective debugging.
- Be aware of the bForceEnable option in certain systems that may override this setting.
- Remember to disable it after debugging to ensure optimal performance in production builds.
- Use it in conjunction with other rendering debug tools for comprehensive shader analysis.
#References in C++ code
#Callsites
This variable is referenced in the following C++ source code:
#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/ShaderPrint.cpp:24
Scope (from outer to inner):
file
namespace ShaderPrint
Source code excerpt:
static int32 GEnabled = false;
static FAutoConsoleVariableRef CVarEnable(
TEXT("r.ShaderPrint"),
GEnabled,
TEXT("ShaderPrint debugging toggle.\n"),
ECVF_Cheat | ECVF_RenderThreadSafe);
static TAutoConsoleVariable<int32> CVarFontSize(
TEXT("r.ShaderPrint.FontSize"),
#Loc: <Workspace>/Engine/Plugins/Animation/DeformerGraph/Source/OptimusCore/Private/DataInterfaces/OptimusDataInterfaceDebugDraw.h:19
Scope: file
Source code excerpt:
/**
* Force enable debug rendering.
* Otherwise "r.ShaderPrint 1" needs to be set.
*/
UPROPERTY(EditAnywhere, Category = DebugDraw)
bool bForceEnable = false;
/** Space to allocate for line collection. */
UPROPERTY(EditAnywhere, Category = DebugDraw)
int32 MaxLineCount = 10000;
/** Space to allocate for triangle collection. */
UPROPERTY(EditAnywhere, Category = DebugDraw)
int32 MaxTriangleCount = 2000;
#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/Substrate/SubstrateRoughRefraction.cpp:415
Scope: file
Source code excerpt:
return;
}
check(ShaderPrint::IsEnabled(View.ShaderPrintData)); // One must enable ShaderPrint beforehand using r.ShaderPrint=1
//////////////////////////////////////////////////////////////////////////
// Create resources
// Texture to count
const uint32 SampleCountTextureWidth = 64;