RecompileShaders
RecompileShaders
#Overview
name: RecompileShaders
This variable is created as a Console Variable (cvar).
- type:
Exec
- help:
Sorry: Exec commands have no help
It is referenced in 14
C++ source files.
#Summary
#Usage in the C++ source code
The purpose of RecompileShaders is to provide functionality for recompiling shaders at runtime within the Unreal Engine 5 environment. This setting variable is primarily used in the rendering system, specifically for shader management and compilation.
RecompileShaders is utilized by several Unreal Engine subsystems and modules, including:
- LevelEditor module
- UnrealEd module
- CookOnTheFly system
- ShaderCompiler system
- Engine core
The value of this variable is typically set through console commands or UI actions. It can be triggered via:
- A UI command in the Level Editor (Loc: LevelEditor/Private/LevelEditorActions.cpp:3929)
- Console command “RecompileShaders” (Loc: Engine/Private/UnrealEngine.cpp:5034)
- CookOnTheFly server requests (Loc: CookOnTheFly/Internal/CookOnTheFly.h:39)
RecompileShaders interacts with other variables and systems, such as:
- ShaderCompiler system
- Global shader map
- CookOnTheFly system
- File management system
Developers must be aware of the following when using this variable:
- Recompiling shaders can be a performance-intensive operation.
- It affects runtime behavior and may cause temporary visual artifacts.
- It’s primarily intended for development and debugging purposes.
Best practices when using this variable include:
- Use it sparingly and only when necessary during development.
- Ensure all shader source files are up to date before triggering a recompile.
- Be prepared for potential performance impacts during the recompilation process.
- Use it in conjunction with proper error handling and logging for shader compilation issues.
- Consider platform-specific implications, especially for platforms that require cooked data.
#References in C++ code
#Callsites
This variable is referenced in the following C++ source code:
#Loc: <Workspace>/Engine/Source/Editor/LevelEditor/Private/LevelEditor.cpp:1726
Scope (from outer to inner):
file
function void FLevelEditorModule::BindGlobalLevelEditorCommands
Source code excerpt:
ActionList.MapAction(
Commands.RecompileShaders,
FExecuteAction::CreateStatic( &FLevelEditorActionCallbacks::ExecuteExecCommand, FString( TEXT("RECOMPILESHADERS CHANGED" ) ) )
);
ActionList.MapAction(
Commands.ProfileGPU,
FExecuteAction::CreateStatic( &FLevelEditorActionCallbacks::ExecuteExecCommand, FString( TEXT("PROFILEGPU") ) )
#Loc: <Workspace>/Engine/Source/Editor/LevelEditor/Private/LevelEditorActions.cpp:3929
Scope (from outer to inner):
file
function UE_DISABLE_OPTIMIZATION_SHIP void FLevelEditorCommands::RegisterCommands
Source code excerpt:
UI_COMMAND( ShowSelectedDetails, "Show Actor Details", "Opens a details panel for the selected actors", EUserInterfaceActionType::Button, FInputChord( EKeys::F4 ) );
UI_COMMAND( RecompileShaders, "Recompile Changed Shaders", "Recompiles shaders which are out of date", EUserInterfaceActionType::Button, FInputChord( EModifierKey::Shift|EModifierKey::Control, EKeys::Period ) );
UI_COMMAND( ProfileGPU, "Profile GPU", "Profiles the GPU for the next frame and opens a window with profiled data", EUserInterfaceActionType::Button, FInputChord( EModifierKey::Shift|EModifierKey::Control, EKeys::Comma ) );
UI_COMMAND( DumpGPU, "Dump GPU", "Dump the GPU intermediary resources for the next frame and opens explorer", EUserInterfaceActionType::Button, FInputChord( EModifierKey::Shift|EModifierKey::Control, EKeys::Slash ) );
UI_COMMAND( ResetAllParticleSystems, "Reset All Particle Systems", "Resets all particle system emitters (removes all active particles and restarts them)", EUserInterfaceActionType::Button, FInputChord( EModifierKey::Shift, EKeys::Slash ) );
UI_COMMAND( ResetSelectedParticleSystem, "Resets Selected Particle Systems" , "Resets selected particle system emitters (removes all active particles and restarts them)", EUserInterfaceActionType::Button, FInputChord( EKeys::Slash ) );
#Loc: <Workspace>/Engine/Source/Editor/LevelEditor/Public/LevelEditorActions.h:621
Scope (from outer to inner):
file
class class FLevelEditorCommands : public TCommands<FLevelEditorCommands>
Source code excerpt:
*/
TSharedPtr< FUICommandInfo > ShowSelectedDetails;
TSharedPtr< FUICommandInfo > RecompileShaders;
TSharedPtr< FUICommandInfo > ProfileGPU;
TSharedPtr< FUICommandInfo > DumpGPU;
TSharedPtr< FUICommandInfo > ResetAllParticleSystems;
TSharedPtr< FUICommandInfo > ResetSelectedParticleSystem;
TSharedPtr< FUICommandInfo > SelectActorsInLayers;
#Loc: <Workspace>/Engine/Source/Editor/UnrealEd/Private/CookOnTheFlyServer.cpp:642
Scope (from outer to inner):
file
function bool UCookOnTheFlyServer::StartCookOnTheFly
Source code excerpt:
});
CookOnTheFlyNetworkServer->OnRequest(ECookOnTheFlyMessage::RecompileShaders).BindLambda([this](ICookOnTheFlyClientConnection& Connection, const FCookOnTheFlyRequest& Request)
{
FCookOnTheFlyResponse Response(Request);
if (!Connection.GetTargetPlatform())
{
UE_LOG(LogCook, Warning, TEXT("RecompileShadersRequest from editor client"));
#Loc: <Workspace>/Engine/Source/Runtime/CookOnTheFly/Internal/CookOnTheFly.h:39
Scope (from outer to inner):
file
namespace UE
namespace Cook
Source code excerpt:
GetCookedPackages = 0x30,
/* Request to recompile shaders. */
RecompileShaders = 0x40,
/* One way message indicating that one or more packages has been cooked. */
PackagesCooked = 0x50,
/* One way message indicating that one or more files has been added. */
FilesAdded = 0x60,
/* Request to recook packages. */
RecookPackages = 0x70,
#Loc: <Workspace>/Engine/Source/Runtime/CookOnTheFly/Internal/CookOnTheFly.h:66
Scope (from outer to inner):
file
namespace UE
namespace Cook
function inline const TCHAR* LexToString
Source code excerpt:
case ECookOnTheFlyMessage::GetCookedPackages:
return TEXT("GetCookedPackages");
case ECookOnTheFlyMessage::RecompileShaders:
return TEXT("RecompileShaders");
case ECookOnTheFlyMessage::PackagesCooked:
return TEXT("PackagesCooked");
case ECookOnTheFlyMessage::FilesAdded:
return TEXT("FilesAdded");
case ECookOnTheFlyMessage::RecookPackages:
#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/ODSC/ODSCThread.cpp:285
Scope (from outer to inner):
file
function void FODSCThread::SendMessageToServer
Source code excerpt:
if ((CookOnTheFlyServerConnection == nullptr) || (!CookOnTheFlyServerConnection->IsConnected()))
{
IFileManager::Get().SendMessageToServer(TEXT("RecompileShaders"), Handler);
return;
}
// We don't have a default COTF connection so use our specific connection to send our command.
UE::Cook::FCookOnTheFlyRequest Request(UE::Cook::ECookOnTheFlyMessage::RecompileShaders);
{
#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/ShaderCompiler/ShaderCompiler.cpp:5802
Scope (from outer to inner):
file
lambda-function
Source code excerpt:
// Issue a `recompileshaders /Engine/Shaders/Private/PostProcessGBufferHints.usf` command, which will just compile that shader source file.
RecompileShaders(*RemappedShaderFileName, *GLog);
UE_LOG(LogShaderCompilers, Display, TEXT("Ready for new shader file changes"));
}
}),
DirectoryWatcherHandle);
#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/ShaderCompiler/ShaderCompiler.cpp:8995
Scope (from outer to inner):
file
function bool RecompileShaders
Source code excerpt:
}
bool RecompileShaders(const TCHAR* Cmd, FOutputDevice& Ar)
{
// if this platform can't compile shaders, then we try to send a message to a file/cooker server
if (FPlatformProperties::RequiresCookedData())
{
#if WITH_ODSC
TArray<FString> MaterialsToLoad;
#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/ShaderCompiler/ShaderCompiler.cpp:9016
Scope (from outer to inner):
file
function bool RecompileShaders
Source code excerpt:
if (FlagStr.Len() > 0)
{
TRACE_CPUPROFILER_EVENT_SCOPE(RecompileShaders);
GWarn->BeginSlowTask( NSLOCTEXT("ShaderCompilingManager", "BeginRecompilingShadersTask", "Recompiling shaders"), true );
// Flush the shader file cache so that any changes to shader source files will be detected
FlushShaderFileCache();
FlushRenderingCommands();
#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/UnrealEngine.cpp:5034
Scope: file
Source code excerpt:
return HandleToggleAsyncComputeCommand(Cmd, Ar);
}
else if( FParse::Command(&Cmd,TEXT("RecompileShaders")) )
{
return HandleRecompileShadersCommand( Cmd, Ar );
}
else if( FParse::Command(&Cmd,TEXT("RecompileGlobalShaders")) )
{
return HandleRecompileGlobalShadersCommand( Cmd, Ar );
#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/UnrealEngine.cpp:5839
Scope (from outer to inner):
file
function bool UEngine::HandleRecompileShadersCommand
Source code excerpt:
bool UEngine::HandleRecompileShadersCommand( const TCHAR* Cmd, FOutputDevice& Ar )
{
return RecompileShaders(Cmd, Ar);
}
bool UEngine::HandleRecompileGlobalShadersCommand( const TCHAR* Cmd, FOutputDevice& Ar )
{
extern void RecompileGlobalShaders();
RecompileGlobalShaders();
#Loc: <Workspace>/Engine/Source/Runtime/Engine/Public/ShaderCompiler.h:1068
Scope: file
Source code excerpt:
/** Implementation of the 'recompileshaders' console command. Recompiles shaders at runtime based on various criteria. */
extern bool RecompileShaders(const TCHAR* Cmd, FOutputDevice& Ar);
/** Returns whether all global shader types containing the substring are complete and ready for rendering. if type name is null, check everything */
extern ENGINE_API bool IsGlobalShaderMapComplete(const TCHAR* TypeNameSubstring = nullptr);
#if WITH_EDITORONLY_DATA
/** Returns the delegate triggered when global shaders compilation jobs start. */
#Loc: <Workspace>/Engine/Source/Runtime/Sockets/Public/NetworkMessage.h:55
Scope (from outer to inner):
file
namespace NFS_Messages
Source code excerpt:
GetFileList,
Heartbeat,
RecompileShaders,
};
}
// Reserved channels for the network file system over multichannel tcp
namespace NFS_Channels
{