Shader Compilation Stutters

Hi all,

I wanted to raise an issue that appeared in several topics a few years ago, yet has become increasingly problematic: shader compilation stutters seem more aggressive lately. As a result, for the first 20–30 seconds, the game constantly stutters as new assets and materials appear on screen and their shaders get compiled. These stutters happen even in basic, simple scenes with little going on, just by moving the camera around. They occur even on powerful devices like my MacBook Pro (M4) and Asus ROG Zephyrus (Windows/RTX 4070), and of course, the situation is worse on mobile devices, which I primarily target.

Some details:

  • There were workarounds proposed. 1) Disabling frustum culling for a frame (to force all visible materials to compile) only helps with assets present at startup. It doesn’t solve the problem for materials and templates spawned later, or for custom shaders introduced at runtime.
    1. Putting all the assets on camera for one frame: I’ve tried forcing all shaders to compile in a single frame by dumping everything at once. This works on PC, but on mobile devices it’s overwhelming—the page dies instantly.
  • At this point, I can’t see a viable workaround: the usual tricks either don’t scale or break on lower-end hardware.

I’m aware of related GitHub issues (e.g. #6085 :arrow_upper_right: :arrow_upper_right:, #3559 :arrow_upper_right: :arrow_upper_right:), but they seem old or inactive, and I haven’t seen any recent progress or official updates.

My questions:

  • Is there any current status or roadmap for addressing this shader compilation issue (especially for mobile)?
  • Is there any recommended workaround for scenes that dynamically spawn new materials/templates after load (mobile friendly)?
  • Should we expect a fix soon, or is it better to start building our own workaround logic?

Any insights or updates would be much appreciated!

2 Likes

We’re all in agreement that this is a problem. I analysed this just over a year ago, with some options listed in the issue you linked already. A lot of refactoring went to shader system generation over the last 6 months, with a hope to improve the situation, but we’re not there yet. Not that there really is a magical solution here, compiling larger shaders takes time.

Apart from already mentioned workarounds (render everything in a single frame), here are some possible improvements:

  1. If you do not need clustered lighting, disable it, as it makes shader compilation time longer. This would be a good option if you only use a single directional light.
  2. Consider using WebGPU as your preferred device. Chrome uses under the hood caching, and returns shaders compiled on previous runs very quickly, if still in cache.
  3. This section from the mentioned issue is really important: “Limit the amount of generated shaders”. Trace number of shaders you compile and try to minimise this, by configuring materials the same way, to avoid too many variations. This is relevant for you, as it seems many shaders get compiled in your case based on described behaviour.
3 Likes