Shader Compilation Stutter
Frame hitches caused by compiling GPU programs the first time they are needed, and the caching schemes that try to move that work elsewhere.
Shader compilation stutter is the hitch a game shows the first time it draws something that needs a GPU program not yet compiled for the current hardware. A Shader ships in an intermediate form (bytecode such as DXIL or SPIR-V) and has to be compiled by the driver into machine code for the specific GPU before it can run. Modern graphics APIs bundle shaders with fixed rendering state into pipeline state objects, and a large game can need tens of thousands of combinations. Compiling one takes milliseconds to hundreds of milliseconds. Done on the render thread, at the moment a new effect first appears, that is a visible freeze: the first explosion, the first time in a new area.
It is a caching problem with an awkward cache key. The compiled result depends on the shader, the pipeline state, the GPU model, and the driver version. Change any of them and the cache is invalid. That leads to a set of familiar behaviors:
- Precompilation at launch. Many games compile everything up front behind a progress bar. It is slow the first time and after every driver update, and it only covers combinations the developers knew to enumerate.
- Stutter after updates. A driver update or a switch to a different API Translation Layer build silently empties the cache, and the game hitches again until it rebuilds. Deleting a stale cache is also a standard troubleshooting step, because a corrupt or mismatched entry can cause crashes instead of stutter.
- Shared caches. On a fixed hardware target, a console or a handheld, the platform can ship precompiled shaders, because the cache key is the same for every player. Some PC storefronts distribute caches gathered from other players with identical configurations.
- Asynchronous compilation. Compiling in the background and drawing something approximate, or nothing, until it is ready trades a hitch for a visual pop.
The general shape is Memoization where the key includes the environment, and Cache Invalidation driven by changes the application cannot see. Because the stutter happens once per combination, a benchmark run twice in a row understates it badly, a measurement trap that favors the second run.
See also7
Frame Pacing
How evenly frames are delivered over time, which shapes perceived smoothness more than average frame rate does.
Graphics & Rendering12 connections
Compiler
A program that translates source code into another form, ahead of running it, checking it along the way.
Computation & Algorithms11 connections
Graphics Driver
The software that translates a program's drawing commands into instructions a particular graphics card can execute, split between a kernel part that manages memory and displays and a large user-space part that compiles shaders and implements graphics interfaces.
Systems & Tooling17 connections
Lazy Evaluation
Deferring a computation until its result is actually needed, and then caching it so it never runs twice.
Computation & Algorithms10 connections
Amortized Analysis
Averaging cost over a sequence of operations so occasional expensive ones don't distort the per-operation bound.
Computation & Algorithms6 connections
Graphics Processing Unit
A processor built to run the same small program on thousands of data items at once, designed for pixels and now the engine of machine learning.
Graphics & Rendering11 connections
Graphics API
The programming interfaces through which software drives the GPU, from the driver-heavy OpenGL era to explicit modern APIs like Vulkan, Direct3D 12, and Metal.
Graphics & Rendering7 connections
Linked from6
- API Translation LayerGraphics & Rendering
Software that implements one platform's API on top of another's, so unmodified programs run somewhere they were never built for.
- Frame PacingGraphics & Rendering
How evenly frames are delivered over time, which shapes perceived smoothness more than average frame rate does.
- Graphics APIGraphics & Rendering
The programming interfaces through which software drives the GPU, from the driver-heavy OpenGL era to explicit modern APIs like Vulkan, Direct3D 12, and Metal.
- Graphics DriverSystems & Tooling
The software that translates a program's drawing commands into instructions a particular graphics card can execute, split between a kernel part that manages memory and displays and a large user-space part that compiles shaders and implements graphics interfaces.
- Graphics Processing UnitGraphics & Rendering
A processor built to run the same small program on thousands of data items at once, designed for pixels and now the engine of machine learning.
- ShaderGraphics & Rendering
A small program run on the graphics processor for every vertex or every pixel.