Cached Shader Formats Reset On Restart

Reproduce:

  • Open UE4 project on Mac
  • Edit > Project Settings… > Platforms > Mac
  • Enable Cached Shader Formats for OpenGL and Metal
  • Close UE4 editor
  • Reopen UE4 project
  • Edit > Project Settings… > Platforms > Mac
  • Notice how Cached Shader Formats are reset to all empty again

Expected:

  • Cached Shader Formats should be persistent

Workaround:

  • Reconfigure Cached Shader Formats before each build since they seem to be stored until the editor is closed

Hey dgrieshofer,

I believe you are missing some steps when setting up your project to used Cached Shaders. Take a read over the documentation below, and if you have any questions or need additional assistance, please let me know.

FShaderCache

Thanks,

Hey Andrew, I have been reading the linked information regarding Cached Shaders and have not been able to get it to work. I added a Mac folder under ProjectName/Config with a MacEngine.ini containing:

[/Script/Engine.RendererSettings]
r.UseShaderCaching=True
r.UseShaderDrawLog=True
r.UseShaderPredraw=True
r.UseShaderBinaryCache=True

Now in game in the console r.UseShaderCaching returns true however it does not seem to change anything after that. The .ushadercache is never written to any folder when running in standalong (-game) or when running a built executable. Also the binary cache does not get built on cooking (using build button in engine). Setting r.UseShaderDrawLog to =False or any other r.UseShader… combinations does not change this either. Also even with those settings Edit > Project Settings… > Platforms > Mac > Cached Shader Formats still get reset on project reload.

It seems like I am doing something wrong but information about this feature is very sparse. If it is not ready yet for public consumption then you can disregard the reported bug.

However I would still like to know how to remove shader compile hitching on OpenGL (Linux/Mac) and on Metal (Mac) eventually so I would be grateful for any more information. Thanks.

You are definitely on the right track, but I believe there are a few things that you could be overlooking.

Users/players should consume the cache by enabling r.UseShaderCaching and r.UseShaderPredraw which is set in the project configuration for all players. I would do this within the project settings config files instead of the engine .ini

I can also see you have used the r.UseShaderBinaryCache config variable, which it also asks you to ‘configure the CachedShaderFormats’ to ensure population of the binary cache. This could be where it is going wrong and not writing to the cache.

All shader code will now be loaded at startup and all predraw operations will occur on the first frame, so if the loading times are too extreme also set r.PredrawBatchTime to a value greater than 0 in ms to spend predrawing each frame.

I know this was taken directly from the documentation, but sometimes pulling specific information can help bring attention to potentially overlooked details.

I am currently working on testing this on my end, and cannot guarantee it will be resolved before the weekend, but if I discover any new information I will keep you in the loop. This process is new to me so I need to have a deeper understanding before I can see if it is working as intended.

Let me know if you have further questions or need additional assistance.

Cheers,