RecompileGlobalShaders
RecompileGlobalShaders
#Overview
name: RecompileGlobalShaders
This variable is created as a Console Variable (cvar).
- type:
Exec
- help:
Sorry: Exec commands have no help
It is referenced in 6
C++ source files.
#Summary
#Usage in the C++ source code
The purpose of RecompileGlobalShaders is to force a recompilation of global shaders in Unreal Engine 5. Global shaders are shader programs that are not specific to any particular material or object but are used across the entire rendering pipeline.
This function is part of Unreal Engine’s rendering system and is primarily used in the shader compilation and management subsystem. It’s particularly relevant in development and editor environments where shader changes may occur frequently.
Based on the callsites, this function is used in the Engine module, specifically in the ShaderCompiler component. It’s also accessible through the UEngine class, indicating its importance in the core engine functionality.
The value of this variable (which is actually a function) is not set, but rather called or invoked when needed. It’s typically called in response to certain engine events or user commands, such as when handling the “RecompileGlobalShaders” console command.
RecompileGlobalShaders interacts with other shader-related functions and systems, such as FlushRenderingCommands() which is called before the recompilation to ensure pending rendering operations are completed.
Developers should be aware that:
- This function is only available in editor builds (WITH_EDITOR).
- It can be time-consuming, especially on larger projects with many shaders.
- It’s typically used during development and debugging, not in shipping builds.
Best practices when using this function include:
- Use it sparingly, as it can be a heavy operation.
- Ensure all pending rendering commands are flushed before calling it (which the function does internally).
- Consider using it in conjunction with other shader recompilation functions if you need to recompile specific material shaders as well.
- Be aware that it may cause temporary hitches or freezes in the editor while the recompilation is occurring.
#References in C++ code
#Callsites
This variable is referenced in the following C++ source code:
#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/ShaderCompiler/ShaderCompiler.cpp:8947
Scope (from outer to inner):
file
function void RecompileGlobalShaders
Source code excerpt:
* Forces a recompile of the global shaders.
*/
void RecompileGlobalShaders()
{
#if WITH_EDITOR
if (!FPlatformProperties::RequiresCookedData())
{
// Flush pending accesses to the existing global shaders.
FlushRenderingCommands();
#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/ShaderCompiler/ShaderCompiler.cpp:9063
Scope (from outer to inner):
file
function bool RecompileShaders
Source code excerpt:
{
FRecompileShadersTimer TestTimer(TEXT("RecompileShaders Global"));
RecompileGlobalShaders();
}
else if (FCString::Stricmp(*FlagStr, TEXT("Material")) == 0)
{
FString RequestedMaterialName(FParse::Token(Cmd, 0));
FRecompileShadersTimer TestTimer(FString::Printf(TEXT("Recompile Material %s"), *RequestedMaterialName));
#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/ShaderCompiler/ShaderCompiler.cpp:9117
Scope (from outer to inner):
file
function bool RecompileShaders
Source code excerpt:
{
FRecompileShadersTimer TestTimer(TEXT("RecompileShaders"));
RecompileGlobalShaders();
FMaterialUpdateContext UpdateContext(0);
for( TObjectIterator<UMaterial> It; It; ++It )
{
UMaterial* Material = *It;
if( Material )
#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/UnrealEngine.cpp:5038
Scope: file
Source code excerpt:
return HandleRecompileShadersCommand( Cmd, Ar );
}
else if( FParse::Command(&Cmd,TEXT("RecompileGlobalShaders")) )
{
return HandleRecompileGlobalShadersCommand( Cmd, Ar );
}
else if( FParse::Command(&Cmd,TEXT("DUMPSHADERSTATS")) )
{
return HandleDumpShaderStatsCommand( Cmd, Ar );
#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/UnrealEngine.cpp:5844
Scope (from outer to inner):
file
function bool UEngine::HandleRecompileGlobalShadersCommand
Source code excerpt:
bool UEngine::HandleRecompileGlobalShadersCommand( const TCHAR* Cmd, FOutputDevice& Ar )
{
extern void RecompileGlobalShaders();
RecompileGlobalShaders();
return 1;
}
bool UEngine::HandleDumpShaderStatsCommand( const TCHAR* Cmd, FOutputDevice& Ar )
{
FString FlagStr(FParse::Token(Cmd, 0));
#Loc: <Workspace>/Engine/Source/Runtime/Engine/Public/ShaderCompiler.h:1097
Scope: file
Source code excerpt:
* Forces a recompile of the global shaders.
*/
extern ENGINE_API void RecompileGlobalShaders();
/**
* Recompiles global shaders and material shaders
* rebuilds global shaders and also
* clears the cooked platform data for all materials if there is a global shader change detected
* can be slow