ShaderCompile rans out of memory

Hey, Guys!
Recently, I have enlarged my computer memory to 96G.
However, while I start my UE4 level from VS code build, I still see the shader compiling cost almost all of the memory. It finaly causes a memory crash .
Even though the level is a bit complex, and their is lots of shaders to compile(nearly 60,000 plus), but I don’t think the shader compiling process Will take up all of the memory.
There must be some configuration to solve this problem, I need your help!
I wonder if it is possible to compile all the shader from VS runtime, or I need to copy all the exe or dll files and then to start UE4 from there ?
For shader debug reasons, I modify my Engine/Config/ConsoleVarible.ini , as follows:
r.Shaders.Optimize=0
r.Shaders.KeepDebugInfo=1
r.Shaders.SkipCompression=1
r.ShaderDevelopmentMode=1
r.DumpShaderDebugShortNames=1

I turned on these debug switches only to hope to use renderDoc to anylise my shader code.


Later I found some clue to reduce my shader compile threads, It works after all shader being compiled. But the memory is still high.
It can’t be possible…



I finally found a solution.

As my project use huge numbers of shader, so once I modify the *.usf/f shader files, the rebuild of all shaders could reach to 60,000 plus, which is very time consuming.
Last week , it took me almost a whole day to compile all the project shaders…
just because of the memory ran out, the UE4 editor crash several times and even cause my computer to reboot.

There are mainly two factors to lead to this memory problem.
first, when compiling shaders , there are some code bug I think to lead to memory leak.

all you have to do is change the variable form to it could be actually released.

//FPendingShaderMapCompileResultsPtr PendingShaderMap;
FPendingShaderMapCompileResults* PendingShaderMap = nullptr;

second, once you enable the r.Shaders.KeepDebugInfo=1 , UE4 will compile all the shader to debug version. But in my case, I only concern some of the shaders I want to debug with, so I did some modification in my engine, added a white list. So UE4 only compiles a small portion of all the whole shaders. It worked.

2 Likes

do you enabled vsync?