Build crash when enabling r.CreateShadersOnLoad=1

Hello,

We are working on improving the performance or our game. We already do collect PSOs and precompile them and now we want to use r.CreateShadersOnLoad=1. I understand it’s useful for the case where you assemble a dynamic material “on the go” (ie you change some bool and you make a new variant that was not in game) - it will be ready and precompiled even if we missed it in the PSO collection.

The only problem is that it will crash the cooking process with the following error :

LogWindows: Error: FShaderMapResource_InlineCode::InitRHI is unable to create a shader: frequency=10, hash=519279342940241A16ED194E315B5CBE0459E45B.

We also tried with UE 5.7.0 vanilla and Lyra and we get the same problem with a different frequency value.

Since all shaders are required in FShaderMapResource::BeginCreateAllShaders(), wouldn’t those shaders also fail at runtime? I’m thinking that maybe it compiles more variants of shaders than our project can use. Is this a correct assumption?

Related threads: [Content removed]

We could put breakpoints and understand which shader fails and why but I wonder if our understanding and usage of r.CreateShadersOnLoad=1 is right.

Hello,

Thank you for reaching out.

I’ve been assigned this issue, and we will be looking into this crash for you.

And the callstacks for reference :

FShaderMapResource_InlineCode::InitRHI is unable to create a shader: frequency=10, hash=519279342940241A16ED194E315B5CBE0459E45B.

LogWindows: Error: begin: stack for UAT

LogWindows: Error: === Critical error: ===

LogWindows: Error:

LogWindows: Error: Fatal error: [File:D:\Jenkins\LastFlag_Development\Engine\Source\Runtime\RenderCore\Private\ShaderResource.cpp] [Line: 731]

LogWindows: Error: FShaderMapResource_InlineCode::InitRHI is unable to create a shader: frequency=10, hash=519279342940241A16ED194E315B5CBE0459E45B.

LogWindows: Error:

LogWindows: Error:

LogWindows: Error: [Callstack] 0x00007ffe0296079a UnrealEditor-RenderCore.dll!FShaderMapResource_InlineCode::CreateRHIShaderOrCrash() [D:\Jenkins\LastFlag_Development\Engine\Source\Runtime\RenderCore\Private\ShaderResource.cpp:731]

LogWindows: Error: [Callstack] 0x00007ffe02960912 UnrealEditor-RenderCore.dll!FShaderMapResource::CreateShaderOrCrash() [D:\Jenkins\LastFlag_Development\Engine\Source\Runtime\RenderCore\Private\ShaderResource.cpp:594]

LogWindows: Error: [Callstack] 0x00007ffe02965e5a UnrealEditor-RenderCore.dll!TGraphTask<TEnqueueUniqueRenderCommandType<TRenderCommandTag<`FShaderMapResource::BeginCreateAllShaders’::`2’::TSTR_InitCommand579>,`FShaderMapResource::BeginCreateAllShaders’::`2’::<lambda_1> > >::ExecuteTask() [D:\Jenkins\LastFlag_Development\Engine\Source\Runtime\Core\Public\Async\TaskGraphInterfaces.h:634]

LogWindows: Error: [Callstack] 0x00007ffe03753092 UnrealEditor-Core.dll!UE::Tasks::Private::FTaskBase::TryExecuteTask() [D:\Jenkins\LastFlag_Development\Engine\Source\Runtime\Core\Public\Tasks\TaskPrivate.h:504]

LogWindows: Error: [Callstack] 0x00007ffe03748c5a UnrealEditor-Core.dll!FNamedTaskThread::ProcessTasksNamedThread() [D:\Jenkins\LastFlag_Development\Engine\Source\Runtime\Core\Private\Async\TaskGraph.cpp:779]

LogWindows: Error: [Callstack] 0x00007ffe037490fe UnrealEditor-Core.dll!FNamedTaskThread::ProcessTasksUntilQuit() [D:\Jenkins\LastFlag_Development\Engine\Source\Runtime\Core\Private\Async\TaskGraph.cpp:668]

LogWindows: Error: [Callstack] 0x00007ffe028b8eec UnrealEditor-RenderCore.dll!RenderingThreadMain() [D:\Jenkins\LastFlag_Development\Engine\Source\Runtime\RenderCore\Private\RenderingThread.cpp:317]

LogWindows: Error: [Callstack] 0x00007ffe028be014 UnrealEditor-RenderCore.dll!FRenderingThread::Run() [D:\Jenkins\LastFlag_Development\Engine\Source\Runtime\RenderCore\Private\RenderingThread.cpp:443]

LogWindows: Error: [Callstack] 0x00007ffe03d79a8d UnrealEditor-Core.dll!FRunnableThreadWin::Run() [D:\Jenkins\LastFlag_Development\Engine\Source\Runtime\Core\Private\Windows\WindowsRunnableThread.cpp:159]

LogWindows: Error: [Callstack] 0x00007ffe03d70eaf UnrealEditor-Core.dll!FRunnableThreadWin::GuardedRun() [D:\Jenkins\LastFlag_Development\Engine\Source\Runtime\Core\Private\Windows\WindowsRunnableThread.cpp:79]

LogWindows: Error: [Callstack] 0x00007ffe2d2f4de0 KERNEL32.DLL!UnknownFunction

LogWindows: Error:

and

UATHelper: Error: Cooking (Windows): LogWindows: Error: begin: stack for UAT

UATHelper: Error: Cooking (Windows): LogWindows: Error: === Critical error: ===

UATHelper: Error: Cooking (Windows): LogWindows: Error:

UATHelper: Error: Cooking (Windows): LogWindows: Error: Fatal error: [File:D:\Workspace\Epic_Unreal_5_7_0\Engine\Source\Runtime\RenderCore\Private\ShaderResource.cpp] [Line: 769]

UATHelper: Error: Cooking (Windows): LogWindows: Error: FShaderMapResource_InlineCode::InitRHI is unable to create a shader: frequency=6, hash=0B22440423AC6508585A60DC345F860A683F7748.

UATHelper: Error: Cooking (Windows): LogWindows: Error:

UATHelper: Error: Cooking (Windows): LogWindows: Error:

UATHelper: Error: Cooking (Windows): LogWindows: Error: [Callstack] 0x00007ffdc5c54342 UnrealEditor-RenderCore.dll!FShaderMapResource_InlineCode::CreateRHIShaderOrCrash() [D:\Workspace\Epic_Unreal_5_7_0\Engine\Source\Runtime\RenderCore\Private\ShaderResource.cpp:769]

UATHelper: Error: Cooking (Windows): LogWindows: Error: [Callstack] 0x00007ffdc5c54572 UnrealEditor-RenderCore.dll!FShaderMapResource::CreateShaderOrCrash() [D:\Workspace\Epic_Unreal_5_7_0\Engine\Source\Runtime\RenderCore\Private\ShaderResource.cpp:631]

UATHelper: Error: Cooking (Windows): LogWindows: Error: [Callstack] 0x00007ffdc5c5011a UnrealEditor-RenderCore.dll!UE::Core::Private::Function::TFunctionRefCaller<`FShaderMapResource::BeginCreateAllShaders’::`2’::<lambda_1>,void,FRHICommandListImmediate &>::Call() [D:\Workspace\Epic_Unreal_5_7_0\Engine\Source\Runtime\Core\Public\Templates\Function.h:292]

UATHelper: Error: Cooking (Windows): LogWindows: Error: [Callstack] 0x00007ffdc5a776ec UnrealEditor-RenderCore.dll!TGraphTask<FRenderThreadCommandPipe::TRenderCommandTask<TUniqueFunction<void __cdecl(FRHICommandListImmediate &)> > >::ExecuteTask() [D:\Workspace\Epic_Unreal_5_7_0\Engine\Source\Runtime\Core\Public\Async\TaskGraphInterfaces.h:696]

UATHelper: Error: Cooking (Windows): LogWindows: Error: [Callstack] 0x00007ffdb4d15d62 UnrealEditor-Core.dll!UE::Tasks::Private::FTaskBase::TryExecuteTask() [D:\Workspace\Epic_Unreal_5_7_0\Engine\Source\Runtime\Core\Public\Tasks\TaskPrivate.h:518]

UATHelper: Error: Cooking (Windows): LogWindows: Error: [Callstack] 0x00007ffdb4d09e11 UnrealEditor-Core.dll!FNamedTaskThread::ProcessTasksNamedThread() [D:\Workspace\Epic_Unreal_5_7_0\Engine\Source\Runtime\Core\Private\Async\TaskGraph.cpp:791]

UATHelper: Error: Cooking (Windows): LogWindows: Error: [Callstack] 0x00007ffdb4d0a19e UnrealEditor-Core.dll!FNamedTaskThread::ProcessTasksUntilQuit() [D:\Workspace\Epic_Unreal_5_7_0\Engine\Source\Runtime\Core\Private\Async\TaskGraph.cpp:680]

UATHelper: Error: Cooking (Windows): LogWindows: Error: [Callstack] 0x00007ffdc5bb2189 UnrealEditor-RenderCore.dll!RenderingThreadMain() [D:\Workspace\Epic_Unreal_5_7_0\Engine\Source\Runtime\RenderCore\Private\RenderingThread.cpp:260]

UATHelper: Error: Cooking (Windows): LogWindows: Error: [Callstack] 0x00007ffdc5bb2a44 UnrealEditor-RenderCore.dll!FRenderingThread::Run() [D:\Workspace\Epic_Unreal_5_7_0\Engine\Source\Runtime\RenderCore\Private\RenderingThread.cpp:393]

UATHelper: Error: Cooking (Windows): LogWindows: Error: [Callstack] 0x00007ffdb53e0a48 UnrealEditor-Core.dll!FRunnableThreadWin::Run() [D:\Workspace\Epic_Unreal_5_7_0\Engine\Source\Runtime\Core\Private\Windows\WindowsRunnableThread.cpp:159]

UATHelper: Error: Cooking (Windows): LogWindows: Error: [Callstack] 0x00007ffdb53d98af UnrealEditor-Core.dll!FRunnableThreadWin::GuardedRun() [D:\Workspace\Epic_Unreal_5_7_0\Engine\Source\Runtime\Core\Private\Windows\WindowsRunnableThread.cpp:79]

UATHelper: Error: Cooking (Windows): LogWindows: Error: [Callstack] 0x00007fff35d6e8d7 KERNEL32.DLL!UnknownFunction

UATHelper: Error: Cooking (Windows): LogWindows: Error:

UATHelper: Error: Cooking (Windows): LogWindows: Error: end: stack for UAT

Hello,

The CVar “r.CreateShadersOnLoad” does not help with PSO-related hitches. For more information, please see this ticket:

[Content removed]

We are investigating the crash, and will get back to you about it.

To help deal with the PSO creation hitches you describe, please look into PSO Precaching, as it is designed to address such situations.

For more information about PSO Precaching, please see it’s documentation:

https://dev.epicgames.com/documentation/en\-us/unreal\-engine/pso\-precaching\-for\-unreal\-engine

Additional information is available in this ticket:

[Content removed]

Please let us know if this helps.

Hello,

Thank you for reporting this crash. I can confirm it can be reproduced as described in the latest CL, and have opened a bug report:

The tracker will be visible after it is approved internally at Epic Games and is publicly accessible.

If you have any further questions, please let us know.

Thank you for those infos.

We already do the PSO Precaching and it works very well. We were missing a few PSO but reading the other threads we will very likely pick them all now.

I think that the question we still have is what does the CVar “r.CreateShadersOnLoad" really does? What would it be used for?

It says “Whether to create shaders on load, which can reduce hitching, but use more memory. Otherwise they will be created as needed.” but ven reading the [Content removed] I can’t quite understand what it really does and what it should be used for.

Hello,

The CVar “r.CreateShadersOnLoad” controls if Materials will populate a full shadermap of all possible permutations when loaded, or only populate the used shaders.

It is primarily used by “FMaterialShaderMap::Register(…)” from MaterialShader.cpp.

For raytracing, it is one condition that allows skipping of some shadermaps that only contain ray tracing shaders, when ray tracing is not allowed. For more information, please see “FIoStoreShaderCodeArchive::PreloadShaderMap(…)” (both overloads) and “FShaderCodeArchive::PreloadShaderMap(…)” from ShaderCodeArchive.cpp.

It is temporarily enabled by the Cook On the Fly Server, to facilitate global shader compilation for some RHIs. For more information, please see “ProcessCookOnTheFlyShaders(…)” from ShaderCompiler.cpp.

Please let us know if this helps.