Post on: 2025-1-8Last edited: 2026-7-21Words 575Read Time 2 min

NotifyAt
password
ContentType
icon
Featured
NotificationPolicy
Series
date
Jan 8, 2025
paired_with
1751d487-a2a1-80fb-bdff-d7a5648b6115
lang
RelatedProjects
type
Post
status
Published
slug
graph-api-and-shaders
category
Technology
NoIndex
Evergreen
NotificationVersion
translation_locked
translation_locked
UpdateType
LastVerified
source_hash
md:v1:b8db65e32cd11c0f17db0311bf4f2cf960ff091340e49eb258bd8732de9a5549
tags
Development
Tools
Games
TechVersions
summary
Shaders, GPU machine code, graphics APIs, and cache invalidation: why shader compilation takes so long.
RedirectFrom
💭
If you play games, you have probably seen a progress bar saying "compiling shaders," especially the first time you launch a newly downloaded Steam game. It can sit there for several minutes. What is it compiling, why does it need to compile anything, and why was it not already compiled?

What a Shader Is

Every pixel you see in a game is calculated by a small program running on the graphics card. That program is called a shader. Lighting, shadows, water reflections, skin materials, and particle effects are all handled by shaders.
A shader is a program written for the GPU. It is different from writing C for a CPU. The two most common types are vertex shaders, which decide where each vertex appears on screen, and fragment shaders, which decide the color of each pixel.

Why It Needs to Be Compiled

Game developers write shaders in high-level languages such as HLSL and GLSL. Before the GPU can execute them, they must be translated into machine code that the graphics card can run directly. That step is shader compilation.
Unlike x86 on the CPU side, GPU machine code is not one universal standard. NVIDIA, AMD, and Intel GPUs use different instruction sets. The same shader code must therefore compile into different machine code on different cards.
That is why the code cannot always be compiled before the game ships. The developer does not know which GPU or driver version you use. The game ships with source code or an intermediate representation, and your driver translates it for your hardware the first time the game runs.

A Short History of Graphics APIs

Shader compilation sits inside the larger evolution of graphics APIs.
OpenGL began in 1992 with Silicon Graphics as a cross-platform graphics API. It was once a de facto standard for PC games and was gradually replaced in many modern workloads. Its rough timeline is:
  • 1992: OpenGL 1.0
  • 2004: OpenGL 2.0 introduced GLSL
  • 2010: OpenGL 4.0
  • 2017: OpenGL 4.6, with no major version since
DirectX is Microsoft's graphics stack for Windows. Direct3D 12 gives developers direct control over GPU memory and command queues. Its performance ceiling is higher, but it is also harder to use. Most modern AAA PC games run on DX12.
Vulkan is often treated as OpenGL's successor. Khronos released it in 2016. Its design resembles DX12: explicit control, low overhead, cross-platform support, and an open standard. Games such as Doom Eternal and No Man's Sky use it heavily.
Metal is Apple's graphics API, released in 2014. It is the graphics API for Mac and iPhone, and Apple tunes it closely for its own GPUs, especially M-series chips.

Why Compilation Takes So Long

A modern AAA game may contain thousands of shader combinations for different light counts, materials, and overlapping effects. Each combination may need to be compiled once for your card. DX12 and Vulkan also impose stricter requirements around compilation timing, so many games compile the shaders they expect to use during the first launch to avoid stuttering later.
That is the reason for the progress bar. The game translates the shaders it expects to need into machine code for your GPU and stores them in a local cache. The next launch can reuse that cache instead of compiling them again.
The cache can become invalid. Changing GPUs, updating the driver, or installing a game patch can make the cached code unusable. That is why a driver update can make the shader compilation screen appear again.

References

Follow updates

Use open feeds for new articles, research, and important updates.


Loading...
Web Scraping 101: Permissions, Tools, and Anti-Bot Lessons

Web Scraping 101: Permissions, Tools, and Anti-Bot Lessons

A personal, practical guide to robots.txt and data-use boundaries, choosing between requests, aiohttp, Scrapy, and Playwright, and handling anti-bot measures and HTML parsing.


Learning Algorithms: Understand First, Code Second

Learning Algorithms: Understand First, Code Second

To learn algorithms, first draw the structure, simulate the process, and explain the invariant; only then turn the idea into code.


Announcement
This site is still updating…