I'm working on improving the framerate of a GearVR game that suffers from many hitches whenever the environment changes or a new object appears in the player's field of view. The profiler shows that this is caused by OpenGL compiling and linking the shaders for the objects that just appeared.
I'd like to use Unreal Engine's Shader Cache feature to solve that, but I'm not sure how to use the various console commands.
Our game uses OpenGL ES3.1. It contains only a few environments and doesn't use level streaming, so ideally I'd like the engine to pre-compile all useful shaders during loadings, instead of at first use.
From what I read in the documentation I imagined I would proceed like this:
enabling r.UseShaderCaching and r.UseShaderDrawLog in Development Android builds of the game
playing through the entire game on the device to populate the cache
locating the shader cache file on the device and moving it to the development PC inside the Content directory.
enabling r.UseShaderCaching and r.UseShaderPredraw in final builds of the game
checking that shader-related hitches are gone.
However, I ran in to several problems.
I found no easy way to get the mobile application to save the shader cache file on the sdcard. As we use the Launcher version of the engine, I ended up calling FShaderCache::ShutdownShaderCache() from game code, which triggers a save, then crashes the game.
launching the game with r.UseShaderCaching and r.UseShaderPredraw enabled crashes at startup in FShaderCache::InternalLogSamplerState(). This has been reported here: https://issues.unrealengine.com/issue/UE-47553
On 4.18 preview 4:
reading through the code, I can see that two console variables are overriden in FShaderCache's constructor, so I'm not sure how the shader cache is supposed to work anymore:
// Make sure this is disabled on mobile
// Mobile only needs FShaderCache::bUseShaderCaching
FShaderCache::bUseShaderPredraw = 0;
FShaderCache::bUseShaderDrawLog = 0;
What workflow would you suggest to use the shader cache on Android?
Oct 13 '17 at 08:50 AM