Game dev
Saved & recent

Shader compilation stutter

Related terms: shader cache, PSO, pipeline state, shader variants, warm-up

A shader must be compiled for the player's exact GPU and driver before it is first used. If that happens during play, the game freezes for a moment the first time a new effect or material appears.

The fixes: compile everything on a loading screen or at first launch, keep the results in a cache, and cut down the number of shader variants. It is mostly a PC problem. Consoles have fixed hardware, so shaders ship precompiled.

Further reading
Unity: How Unity loads and uses shaders
1 6 12 18 24 0 10 20 30 40 50 frame frame time (ms) 16.7 ms first material first effect
The amber segments show compilation added the first time each shader is used. The regular frame work stays within the dashed 16.7 ms budget.

View in the full Game dev collection