UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
ShaderCompiler.cpp File Reference
#include "ShaderCompiler.h"
#include "ShaderCompiler/ShaderCompilerInternal.h"
#include "ShaderCompilerPrivate.h"
#include "AsyncCompilationHelpers.h"
#include "AssetCompilingManager.h"
#include "ClearReplacementShaders.h"
#include "ComponentRecreateRenderStateContext.h"
#include "Components/PrimitiveComponent.h"
#include "DataDrivenShaderPlatformInfo.h"
#include "DistributedBuildControllerInterface.h"
#include "EditorSupportDelegates.h"
#include "Engine/RendererSettings.h"
#include "Features/IModularFeatures.h"
#include "Interfaces/IShaderFormat.h"
#include "Interfaces/ITargetPlatform.h"
#include "Interfaces/ITargetPlatformManagerModule.h"
#include "Internationalization/LocKeyFuncs.h"
#include "Logging/StructuredLog.h"
#include "MaterialShared.h"
#include "Materials/Material.h"
#include "Materials/MaterialInstance.h"
#include "Misc/ConfigCacheIni.h"
#include "Misc/CoreDelegates.h"
#include "Misc/FeedbackContext.h"
#include "Misc/FileHelper.h"
#include "Misc/MessageDialog.h"
#include "Misc/ScopedSlowTask.h"
#include "Modules/ModuleManager.h"
#include "ObjectCacheContext.h"
#include "ProfilingDebugging/CookStats.h"
#include "ProfilingDebugging/DiagnosticTable.h"
#include "ProfilingDebugging/LoadTimeTracker.h"
#include "ProfilingDebugging/StallDetector.h"
#include "RenderUtils.h"
#include "SceneInterface.h"
#include "SceneManagement.h"
#include "Serialization/CompactBinaryWriter.h"
#include "Serialization/MemoryReader.h"
#include "Serialization/NameAsStringProxyArchive.h"
#include "ShaderCodeLibrary.h"
#include "ShaderSerialization.h"
#include "ShaderDiagnostics.h"
#include "ShaderPlatformCachedIniValue.h"
#include "StaticBoundShaderState.h"
#include "StereoRenderUtils.h"
#include "Tasks/Task.h"
#include "UObject/DevObjectVersion.h"
#include "UObject/UObjectIterator.h"
#include "Math/UnitConversion.h"
#include "UnrealEngine.h"
#include "ColorManagement/ColorSpace.h"
#include "SceneTexturesConfig.h"
#include "PSOPrecacheMaterial.h"
#include "Misc/PreLoadFile.h"
#include "Serialization/LargeMemoryReader.h"

Classes

class  FRecompileShadersTimer
 

Namespaces

namespace  ShaderCompiler
 

Macros

#define LOCTEXT_NAMESPACE   "ShaderCompiler"
 
#define DEBUG_SHADERCOMPILEWORKER   0
 

Functions

 DEFINE_LOG_CATEGORY (LogShaderCompilers)
 
 LLM_DEFINE_TAG (ShaderCompiler)
 
bool AreShaderErrorsFatal ()
 
FString ShaderCompiler::GetTargetPlatformName (const ITargetPlatform *TargetPlatform)
 
bool ShaderCompiler::IsRemoteCompilingAllowed ()
 
const FGuidGetGlobalShaderMapDDCGuid ()
 
const FGuidGetMaterialShaderMapDDCGuid ()
 
bool ShouldDumpShaderDDCKeys ()
 
void DumpShaderDDCKeyToFile (const EShaderPlatform InPlatform, bool bWithEditor, const FString &FileName, const FString &DDCKey)
 
void DumpShaderDDCKeyToFile (const EShaderPlatform InPlatform, bool bEditorOnly, const TCHAR *DebugGroupName, const FString &DDCKey)
 
template<class EnumType >
constexpr autoCastEnumToUnderlyingTypeReference (EnumType &Type)
 
bool CreateShadersOnLoad ()
 
bool ShaderCompiler::IsDumpShaderDebugInfoAlwaysEnabled ()
 
void ProcessCookOnTheFlyShaders (bool bReloadGlobalShaders, const TArray< uint8 > &MeshMaterialMaps, const TArray< FString > &MaterialsToLoad, const TArray< uint8 > &GlobalShaderMap)
 
void RecompileGlobalShaders ()
 
void GetOutdatedShaderTypes (TArray< const FShaderType * > &OutdatedShaderTypes, TArray< const FShaderPipelineType * > &OutdatedShaderPipelineTypes, TArray< const FVertexFactoryType * > &OutdatedFactoryTypes)
 
bool RecompileShaders (const TCHAR *Cmd, FOutputDevice &Ar)
 
void VerifyGlobalShaders (EShaderPlatform Platform, const ITargetPlatform *TargetPlatform, bool bLoadedFromCacheFile, const TArray< const FShaderType * > *OutdatedShaderTypes, const TArray< const FShaderPipelineType * > *OutdatedShaderPipelineTypes, const FShaderCompilerFlags &InExtraCompilerFlags)
 
void VerifyGlobalShaders (EShaderPlatform Platform, bool bLoadedFromCacheFile, const TArray< const FShaderType * > *OutdatedShaderTypes, const TArray< const FShaderPipelineType * > *OutdatedShaderPipelineTypes)
 
void PrecacheComputePipelineStatesForGlobalShaders (ERHIFeatureLevel::Type FeatureLevel, const ITargetPlatform *TargetPlatform)
 
FString SaveGlobalShaderFile (EShaderPlatform Platform, FString SavePath, class ITargetPlatform *TargetPlatform)
 
bool IsGlobalShaderMapComplete (const TCHAR *TypeNameSubstring, FGlobalShaderMap *GlobalShaderMap, EShaderPlatform Platform, FString *FailureReason=nullptr)
 
bool IsGlobalShaderMapComplete (const TCHAR *TypeNameSubstring)
 
void CompileGlobalShaderMap (EShaderPlatform Platform, const ITargetPlatform *TargetPlatform, bool bRefreshShaderMap)
 
void CompileGlobalShaderMap (EShaderPlatform Platform, bool bRefreshShaderMap)
 
void CompileGlobalShaderMap (ERHIFeatureLevel::Type InFeatureLevel, bool bRefreshShaderMap)
 
void CompileGlobalShaderMap (bool bRefreshShaderMap)
 
void ShutdownGlobalShaderMap ()
 
void ReloadGlobalShaders ()
 
void SetGlobalShaderCacheOverrideDirectory (const TArray< FString > &Args)
 
bool RecompileChangedShadersForPlatform (const FString &PlatformName)
 
ENGINE_API const TCHARODSCCmdEnumToString (ODSCRecompileCommand Cmd)
 
void BeginRecompileGlobalShaders (const TArray< const FShaderType * > &OutdatedShaderTypes, const TArray< const FShaderPipelineType * > &OutdatedShaderPipelineTypes, EShaderPlatform ShaderPlatform, const ITargetPlatform *TargetPlatform, const FShaderCompilerFlags &InExtraCompilerFlags)
 
void FinishRecompileGlobalShaders ()
 
void LoadGlobalShadersForRemoteRecompile (FArchive &Ar, EShaderPlatform ShaderPlatform)
 

Variables

int32 GShaderCompilerAllowDistributedCompilation = 1
 
int32 GMaxNumDumpedShaderSources = 10
 
int32 GSShaderCheckLevel = 1
 
bool GDebugDumpWorkerCrashLog = false
 
FGlobalShaderMapGGlobalShaderMap_DeferredDeleteCopy [SP_NumPlatforms] = {nullptr}
 
bool GRetryShaderCompilation = true
 
int32 GCreateShadersOnLoad = 0
 
FShaderCompilingManagerGShaderCompilingManager = nullptr
 
const ITargetPlatformGGlobalShaderTargetPlatform [SP_NumPlatforms] = { nullptr }
 

Macro Definition Documentation

◆ DEBUG_SHADERCOMPILEWORKER

#define DEBUG_SHADERCOMPILEWORKER   0

◆ LOCTEXT_NAMESPACE

#define LOCTEXT_NAMESPACE   "ShaderCompiler"

Function Documentation

◆ AreShaderErrorsFatal()

bool AreShaderErrorsFatal ( )

◆ BeginRecompileGlobalShaders()

void BeginRecompileGlobalShaders ( const TArray< const FShaderType * > &  OutdatedShaderTypes,
const TArray< const FShaderPipelineType * > &  OutdatedShaderPipelineTypes,
EShaderPlatform  ShaderPlatform,
const ITargetPlatform TargetPlatform = nullptr,
const FShaderCompilerFlags InExtraCompilerFlags = {} 
)

Begins recompiling the specified global shader types, and flushes their bound shader states. FinishRecompileGlobalShaders must be called after this and before using the global shaders for anything.

◆ CastEnumToUnderlyingTypeReference()

template<class EnumType >
constexpr auto & CastEnumToUnderlyingTypeReference ( EnumType &  Type)
constexpr

◆ CompileGlobalShaderMap() [1/4]

void CompileGlobalShaderMap ( bool  bRefreshShaderMap)

◆ CompileGlobalShaderMap() [2/4]

void CompileGlobalShaderMap ( ERHIFeatureLevel::Type  InFeatureLevel,
bool  bRefreshShaderMap 
)

◆ CompileGlobalShaderMap() [3/4]

void CompileGlobalShaderMap ( EShaderPlatform  Platform,
bool  bRefreshShaderMap 
)

◆ CompileGlobalShaderMap() [4/4]

void CompileGlobalShaderMap ( EShaderPlatform  Platform,
const ITargetPlatform TargetPlatform,
bool  bRefreshShaderMap 
)

◆ CreateShadersOnLoad()

bool CreateShadersOnLoad ( )

◆ DEFINE_LOG_CATEGORY()

DEFINE_LOG_CATEGORY ( LogShaderCompilers  )

◆ DumpShaderDDCKeyToFile() [1/2]

void DumpShaderDDCKeyToFile ( const EShaderPlatform  InPlatform,
bool  bEditorOnly,
const TCHAR DebugGroupName,
const FString &  DDCKey 
)

◆ DumpShaderDDCKeyToFile() [2/2]

void DumpShaderDDCKeyToFile ( const EShaderPlatform  InPlatform,
bool  bWithEditor,
const FString &  FileName,
const FString &  DDCKey 
)

◆ FinishRecompileGlobalShaders()

void FinishRecompileGlobalShaders ( )

Finishes recompiling global shaders. Must be called after BeginRecompileGlobalShaders.

◆ GetGlobalShaderMapDDCGuid()

const FGuid & GetGlobalShaderMapDDCGuid ( )

◆ GetMaterialShaderMapDDCGuid()

const FGuid & GetMaterialShaderMapDDCGuid ( )

◆ GetOutdatedShaderTypes()

void GetOutdatedShaderTypes ( TArray< const FShaderType * > &  OutdatedShaderTypes,
TArray< const FShaderPipelineType * > &  OutdatedShaderPipelineTypes,
TArray< const FVertexFactoryType * > &  OutdatedFactoryTypes 
)

◆ IsGlobalShaderMapComplete() [1/2]

bool IsGlobalShaderMapComplete ( const TCHAR TypeNameSubstring = nullptr)

Returns whether all global shader types containing the substring are complete and ready for rendering. if type name is null, check everything

◆ IsGlobalShaderMapComplete() [2/2]

bool IsGlobalShaderMapComplete ( const TCHAR TypeNameSubstring,
FGlobalShaderMap GlobalShaderMap,
EShaderPlatform  Platform,
FString *  FailureReason = nullptr 
)

◆ LLM_DEFINE_TAG()

LLM_DEFINE_TAG ( ShaderCompiler  )

◆ LoadGlobalShadersForRemoteRecompile()

void LoadGlobalShadersForRemoteRecompile ( FArchive Ar,
EShaderPlatform  ShaderPlatform 
)

Serializes a global shader map to an archive (used with recompiling shaders for a remote console)

◆ ODSCCmdEnumToString()

ENGINE_API const TCHAR * ODSCCmdEnumToString ( ODSCRecompileCommand  Cmd)
extern

◆ PrecacheComputePipelineStatesForGlobalShaders()

void PrecacheComputePipelineStatesForGlobalShaders ( ERHIFeatureLevel::Type  FeatureLevel,
const ITargetPlatform TargetPlatform 
)

Precreates compute PSOs for global shaders. Separate from Compile/VerifyGlobalShaders to avoid blocking loads.

◆ ProcessCookOnTheFlyShaders()

void ProcessCookOnTheFlyShaders ( bool  bReloadGlobalShaders,
const TArray< uint8 > &  MeshMaterialMaps,
const TArray< FString > &  MaterialsToLoad,
const TArray< uint8 > &  GlobalShaderMap 
)

Handles serializing in MeshMaterialMaps or GlobalShaderMap from a CookOnTheFly command and applying them to the in-memory shadermaps.

Parameters
MeshMaterialMapsByte array that contains the serialized material shadermap from across the network.
MaterialsToLoadThe materials contained in the MeshMaterialMaps
GlobalShaderMapByte array that contains the serialized global shadermap from across the network.

◆ RecompileChangedShadersForPlatform()

bool RecompileChangedShadersForPlatform ( const FString &  PlatformName)

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

◆ RecompileGlobalShaders()

void RecompileGlobalShaders ( )

Forces a recompile of the global shaders.

◆ RecompileShaders()

bool RecompileShaders ( const TCHAR Cmd,
FOutputDevice Ar 
)

Implementation of the 'recompileshaders' console command. Recompiles shaders at runtime based on various criteria.

◆ ReloadGlobalShaders()

void ReloadGlobalShaders ( )

◆ SaveGlobalShaderFile()

FString SaveGlobalShaderFile ( EShaderPlatform  Platform,
FString  SavePath,
class ITargetPlatform TargetPlatform 
)

Saves the global shader map as a file for the target platform.

◆ SetGlobalShaderCacheOverrideDirectory()

void SetGlobalShaderCacheOverrideDirectory ( const TArray< FString > &  Args)

◆ ShouldDumpShaderDDCKeys()

bool ShouldDumpShaderDDCKeys ( )

◆ ShutdownGlobalShaderMap()

void ShutdownGlobalShaderMap ( )

◆ VerifyGlobalShaders() [1/2]

void VerifyGlobalShaders ( EShaderPlatform  Platform,
bool  bLoadedFromCacheFile,
const TArray< const FShaderType * > *  OutdatedShaderTypes = nullptr,
const TArray< const FShaderPipelineType * > *  OutdatedShaderPipelineTypes = nullptr 
)

Makes sure all global shaders are loaded and/or compiled for the passed in platform. Note: if compilation is needed, this only kicks off the compile.

Parameters
PlatformPlatform to verify global shaders for
bLoadedFromCacheFileLoad the shaders from cache, will error out and not compile shaders if missing
OutdatedShaderTypesOptional list of shader types, will trigger compilation job for shader types found in this list even if the map already has the shader.
OutdatedShaderPipelineTypesOptional list of shader pipeline types, will trigger compilation job for shader pipeline types found in this list even if the map already has the pipeline.

◆ VerifyGlobalShaders() [2/2]

void VerifyGlobalShaders ( EShaderPlatform  Platform,
const ITargetPlatform TargetPlatform,
bool  bLoadedFromCacheFile,
const TArray< const FShaderType * > *  OutdatedShaderTypes,
const TArray< const FShaderPipelineType * > *  OutdatedShaderPipelineTypes,
const FShaderCompilerFlags InExtraCompilerFlags 
)

Makes sure all global shaders are loaded and/or compiled for the passed in platform. Note: if compilation is needed, this only kicks off the compile.

Parameters
PlatformPlatform to verify global shaders for

Variable Documentation

◆ GCreateShadersOnLoad

int32 GCreateShadersOnLoad = 0

◆ GDebugDumpWorkerCrashLog

bool GDebugDumpWorkerCrashLog = false

◆ GGlobalShaderMap_DeferredDeleteCopy

FGlobalShaderMap* GGlobalShaderMap_DeferredDeleteCopy[SP_NumPlatforms] = {nullptr}

Storage for the global shadar map(s) that have been replaced by new one(s), which aren't yet compiled.

Sometimes a mesh drawing command references a pointer to global SM's memory. To nix these MDCs when we're replacing a global SM, we would just recreate the render state for all the components, but we may need to access a global shader during such an update, creating a catch 22. So deleting the global SM and updating components is deferred until the new one is compiled.

◆ GGlobalShaderTargetPlatform

const ITargetPlatform* GGlobalShaderTargetPlatform[SP_NumPlatforms] = { nullptr }

◆ GMaxNumDumpedShaderSources

int32 GMaxNumDumpedShaderSources = 10

◆ GRetryShaderCompilation

bool GRetryShaderCompilation = true

◆ GShaderCompilerAllowDistributedCompilation

int32 GShaderCompilerAllowDistributedCompilation = 1

◆ GShaderCompilingManager

FShaderCompilingManager* GShaderCompilingManager = nullptr

The global shader compiling thread manager.

◆ GSShaderCheckLevel

int32 GSShaderCheckLevel = 1