Shader compilation: why PC games stutter the first time
Average FPS can remain high while creation of a new pipeline delays one frame. Caching, precaching and advance delivery reduce the problem.
R42 / SUMMARY
PC games can stutter when they must compile a shader or create a graphics pipeline as an effect appears for the first time. The work increases the duration of one frame, so average FPS may still look high despite a visible interruption. Precaching, background work and reusable caches reduce the problem, but updates and previously unseen combinations can require new processing.
KEY POINTS
- Shaders are GPU programs that must be prepared for the combination of game, graphics hardware and driver.
- A Pipeline State Object combines shaders with rendering state; creating one at draw time can delay a frame.
- Stutter is easier to see in frame-time spikes than in average FPS.
- Caches make later runs smoother, but game or driver changes can invalidate them.
- Compiling during loading or delivering prepared shaders trades in-game pauses for earlier waiting and more technical coordination.
A game can display 90 or 120 frames per second most of the time and still feel unstable when a door opens, an attack is used or a new effect appears. The contradiction is only apparent: average FPS summarizes many frames, while a hitch comes from one specific frame arriving late. If the engine must compile a shader or create a graphics pipeline at that moment, delivery time can rise enough to produce a visible pause.
This behavior is known as shader compilation stutter. It often appears on the first run or the first encounter with a particular combination of material, light and effect. The same scene may be smoother later because the compilation result is already in memory or has been stored in a cache.
Shaders are programs, not textures
A shader is a small program executed by the GPU at one stage of rendering. Some transform vertices, while others calculate pixel colors, lighting, shadows and additional effects. A game commonly provides this code in an intermediate form, but the driver must still prepare it for the architecture of the installed graphics processor.
On PC, the same game build must work across multiple GPU families, driver versions and settings. That makes it difficult to ship one graphics binary that is ready for everyone. Compilation can happen before play, in the background or only when an effect is requested.
The pipeline multiplies the combinations
Modern APIs do not work only with an isolated shader. Direct3D 12 and Vulkan group shaders and several rendering settings into pipeline objects. A Pipeline State Object, or PSO, can include vertex and pixel programs, data formats, rasterization, color blending, depth behavior and render-target formats.
This organization lets a driver prepare dependencies in advance and switch states quickly while drawing. The cost appears when a game requests a pipeline that does not exist yet. Vulkan documentation warns that creating pipelines during rendering without a cache can significantly increase frame time. Epic describes the same choice in Unreal Engine: if a required PSO is still compiling, the engine can delay the draw, use a temporary material or continue and accept a possible hitch.
Average FPS hides a frame-time spike
At 60 FPS, each frame has about 16.7 milliseconds to finish. If hundreds of frames meet that target but one takes 40 or 80 milliseconds, the average can remain respectable. The player still notices the interruption. This is why frame-time graphs are more useful than average FPS for identifying stutter: they show the duration of every frame.
Compilation also consumes CPU resources. Even when it runs as asynchronous work, it can compete with simulation, command preparation and loading. Precaching must balance speed, memory use, thread count and the length of the loading screen.
Why a second visit is often better
A cache stores prepared representations for reuse. Vulkan allows pipeline data to be saved to disk and loaded in later application runs. Graphics drivers maintain caches of their own. When the engine requests the same combination again, it may avoid part of the expensive work.
This explains why crossing an area a second time often feels smoother and why testing after an initial run can hide the issue. Epic recommends deliberately clearing the cache when testing the first-start experience so that a warmed session is not mistaken for a new player’s first encounter.
The cache is not permanent. Game changes can create new variants, and compiled data is specific to a GPU and driver. Microsoft says a driver update can invalidate caches and require new preparation. Changing graphics settings may also expose combinations that have not been used before, although the exact behavior depends on the engine.
Loading first is better than stopping during action
A common solution is to compile shaders at startup or during a loading screen. The wait becomes explicit, but the work is less likely to block a frame in the middle of play. Another approach is to record pipelines used during testing and warm the cache before they appear. Unreal Engine also supports automatic collection and asynchronous compilation of PSOs.
Microsoft is moving part of this process into distribution. Advanced Shader Delivery combines data supplied by a game with hardware-vendor compilers to deliver a cache compatible with a hardware and driver combination. The company says the system reduces loading times and stutter in supported titles and devices. Those results are Microsoft’s claims and depend on support from the store, game and hardware; they are not a universal solution for every PC game.
Not every hitch is compilation
Texture and model loading, open-world traversal, file decompression, memory shortages, CPU tasks, garbage collection and network communication can also lengthen a frame. The pattern “it hitches when an effect first appears and improves on repetition” is consistent with compilation, but it does not establish the cause by itself.
For players, allowing a compilation stage to finish and avoiding unnecessary cache deletion can help when a title is designed around that flow. The lasting fix, however, mainly depends on development work: enumerate variants, prepare pipelines at the appropriate time, test with an empty cache and prevent an unseen combination from blocking rendering. Faster hardware reduces the cost, but it does not replace a sound compilation strategy.
Misael
Responsible for reporting and writing this story at Rota42.
R42 / FAQ
What is a shader in a game?
It is a small program executed by the GPU for rendering stages such as transforming geometry, calculating lighting, applying materials and producing pixels. Before use, it must reach a form compatible with the GPU and driver.
Why does shader compilation cause stutter?
If the game encounters a graphics combination that has not been prepared, it may need to compile code and create the pipeline before drawing the frame. When that work blocks rendering, the frame takes longer and the player sees a pause.
Why is the same section often smoother the second time?
After its first creation, the pipeline may remain in memory or be stored in a cache. When the effect appears again, the game or driver can reuse prepared work instead of repeating the full compilation.
Can a driver update make shaders compile again?
Yes. Compiled data depends on the driver and GPU, and an update can invalidate existing caches. A game may also rebuild them after changes to shaders, effects or configurations.
Does every PC game stutter come from shaders?
No. File loading, world traversal, memory pressure, CPU work, garbage collection and networking can also cause pauses. A hitch on an effect’s first appearance is a clue, not conclusive proof.