The Big Picture: What Is a Graphics API?

An API (Application Programming Interface) is a menu of requests that a program can make. For graphics, the menu has items like "draw these triangles", "load this texture", "show the finished picture".

Without an API, every game would need different code for every GPU model. With an API, the game writes its requests once. The API and the display driver (Section 2) then turn those requests into commands for whatever GPU is installed. (See Chapter 23 — Windows APIs for APIs in general.)

Analogy: An API is a restaurant menu. You order "pizza" without knowing how the kitchen works. Different kitchens (GPUs) cook it their own way, but you get a pizza either way.

The path of a graphics request:

 Application (game, browser, app)
        │   "draw these triangles"
        ▼
 Graphics API runtime  (Direct3D, OpenGL or Vulkan)
        │   checks the request, tidies it up
        ▼
 User-mode driver (UMD)         <- from the GPU vendor
        │   turns it into command buffers
        ▼
 Windows graphics kernel  (dxgkrnl.sys: scheduler)
        │   decides when this work runs
        ▼
 Kernel-mode driver (KMD)  ->  the GPU

A command buffer is simply a list of instructions for the GPU, written into memory. The GPU then reads the list and carries it out, while the CPU gets on with other work.

3.1 DirectX (Direct3D)

What it is: DirectX is Microsoft's family of multimedia APIs for Windows. Its most important member is Direct3D, the one for 3D graphics. People often say "DirectX" when they mean Direct3D.

VersionWhat to know
Direct3D 11Older, easier to use. The driver does a lot of the hard work for the programmer. Still used by many programs
Direct3D 12Newer, "closer to the hardware". The game does more of the work itself and can use many CPU cores to prepare commands. Faster, but harder to program

Other pieces of the DirectX family you will hear about:

PartUsed for
Direct2DFast 2D shapes and graphics on the GPU
DirectWriteHigh-quality text drawing
DXGIPlumbing: lists the GPUs and monitors, creates the swap chain (Section 7)

Direct3D is Windows only (also used on Xbox). Most Windows PC games use it.

Old-style 2D drawing. Plain Windows programs used to draw buttons and text with GDI (Graphics Device Interface), the classic 2D API that has existed since early Windows. It is simple and still works, but it was designed long before GPUs mattered. Modern apps use Direct2D and DirectWrite instead. The DWM (Desktop Window Manager, Chapter 30 — Windows Desktop Internals) then combines all these windows on the GPU.

3.2 OpenGL

What it is: OpenGL is an older, open graphics API (not owned by Microsoft) that works on Windows, Linux and (in the past) macOS. It was the main alternative to DirectX for many years. Many professional 3D and design programs and older games use it.

On Windows, the OpenGL library is a thin layer, and the GPU maker's driver provides the real implementation. OpenGL is mature, but newer APIs have mostly taken over for new games.

3.3 Vulkan

What it is: Vulkan is a modern, open API, designed for the same goals as Direct3D 12: close to the hardware, low CPU overhead, many CPU cores can prepare commands in parallel. It is managed by an industry group called Khronos (the same group behind OpenGL).

Vulkan runs on Windows, Linux and Android. Many modern games offer Vulkan as an option.

What about Apple? Apple computers use Metal, Apple's own API. It does not exist on Windows. It is mentioned here only so you recognise the name.

APIOwnerRuns onStyle
Direct3D 11MicrosoftWindows, XboxEasier, driver does more
Direct3D 12MicrosoftWindows, XboxLow-level, fast, harder
OpenGLKhronos (open standard)Windows, Linux, othersOlder, widely supported
VulkanKhronos (open standard)Windows, Linux, AndroidLow-level, fast, harder
MetalAppleApple devices onlyApple's low-level API

3.4 How an App Chooses and Uses an API

What happens: The programmer decides which API to use when writing the program. At start-up the program asks the API to create a device (a connection to a GPU). If the GPU or driver does not support the needed features, the program may fall back to an older version or show an error such as "your graphics card does not support DirectX 12".

Many games have a setting like "Graphics API: DirectX 11 / DirectX 12 / Vulkan". If a game crashes with one, trying another is a common fix.

What the API actually does (the main requests):

Request typeExample
Create resourcesLoad a texture (image) or a 3D model into VRAM
Set state"Use this shader program; blend colours like this"
Draw"Draw these 3,000 triangles" (a draw call)
Present"The picture is finished; show it"

Draw calls cost CPU time. Each draw call needs a little CPU work to prepare. Too many tiny draw calls can make the CPU the bottleneck even when the GPU is idle. This is one of the reasons Direct3D 12 and Vulkan exist.

API versus driver versus hardware. The three must match:

LayerQuestion it answers
GPU hardwareWhat can the chip physically do?
DriverDoes the software expose those features to the API?
API versionDoes the program's chosen API support those features?

If any layer is too old, the feature is not available. That is why updating the driver can fix a game that "doesn't start".

Where to check: Run dxdiag and open the Display tab. It lists "Feature Levels" and which DirectX features are enabled. The first page, System, shows the DirectX Version (this is the version of the DirectX runtime, not a promise that your GPU supports everything in it).

Summary

TopicRemember this
APIA menu of graphics requests, so programs need not know each GPU
Request pathApp → API runtime → user-mode driver → command buffers → kernel scheduler → GPU
Command bufferA list of GPU instructions stored in memory
Direct3DMicrosoft's 3D API; 11 is easier, 12 is faster but harder
GDI / Direct2D / DirectWriteClassic 2D drawing, and the modern GPU-based 2D and text APIs
OpenGLOlder open API, works on several systems
VulkanModern open low-level API (Khronos)
MetalApple's API, not on Windows
App choiceThe program picks an API; many games let you switch in their settings