Source: ViewEdit

GPU programming

Developers run into GPU API names across wildly different corners of a stack: a machine-learning repository asks for CUDA, a browser demo renders with WebGL 2 or WebGPU, a game engine ships a Vulkan backend, and a Linux media script passes -hwaccel vaapi to FFmpeg. Because every README calls the underlying feature "GPU acceleration," those names look like competing brands for the same switch. They are not. One graphics card performs three distinct kinds of work — drawing frames, running general-purpose parallel math, and encoding or decoding video — and the ecosystem divides APIs by job first, then by operating system and hardware vendor.

This guide ties those pieces together. Read Graphics programming for the rendering pipeline, draw calls, WebGL 2, Vulkan graphics, and WebGPU’s render pass. Read GPU compute for CUDA, HIP on ROCm, Vulkan compute, and WebGPU compute. When you need a quick table of API names, shading languages, and translation layers, keep GPU API lookup open alongside them. To practice drawing and compute side by side without installing a native SDK, jump straight to Draw a triangle and run a compute shader. For 2D UI stacks that sit above these APIs, see Graphics rendering engines.

Three jobs on one card

Before picking an API or installing a driver package, name what you want back from the card: a rendered frame, a buffer of numbers, or a compressed or decoded video picture.

Draw a frame, run a calculation, and decode a picture each reach the same GPU through separate paths

Graphics turns geometry, textures, and shaders into pixels for a display or an offscreen render target. That path includes OpenGL, OpenGL ES, WebGL and WebGL 2, Vulkan’s graphics pipeline, Direct3D 11 and 12, Metal, and WebGPU’s render pass. Graphics APIs are built around rasterization, depth testing, blending, and delivering finished frames to a window or canvas. See Graphics programming for how that pipeline works.

Compute runs a small function across thousands of array elements, matrix tiles, or simulation cells in parallel, with no window or pixel pipeline required. Dedicated compute platforms — CUDA on NVIDIA, ROCm and HIP on AMD, plus OpenCL and SYCL — pair a kernel compiler and runtime with vendor math libraries. Modern explicit graphics APIs — Vulkan, Direct3D 12, Metal, and WebGPU — expose the same parallel execution hardware through compute shaders, without tying you to one GPU vendor’s toolkit. See GPU compute for how those doors compare.

Video decodes or encodes compressed bitstreams such as H.264, HEVC, VP9, and AV1 using dedicated fixed-function media engines on the silicon. Those blocks are separate from the programmable shader cores; a video API fills frames without compiling your vertex or compute shaders. Because video is neither triangle rendering nor general compute, it has its own API family:

  • On Linux, the standard entry point is VA-API (libva), implemented natively by Intel’s media driver and Mesa’s AMD driver. NVIDIA’s native Linux path is NVDEC (decode) and NVENC (encode), superseding the older VDPAU interface. A third-party adapter, nvidia-vaapi-driver, translates VA-API calls onto NVDEC, so a working vainfo on an NVIDIA machine usually means a translation layer is installed rather than a native NVIDIA VA-API driver.

  • On Windows, playback and transcoding normally go through Media Foundation (or vendor SDKs such as NVDEC/NVENC and AMD’s AMF).

  • On Apple platforms, hardware media runs through VideoToolbox.

  • Vulkan Video exposes decode and encode as opt-in Vulkan queues; it is newer than VA-API and is not what a default FFmpeg build selects.

  • In browsers, WebCodecs gives web pages direct access to hardware video encoders and decoders. It processes frames and compressed chunks, not WGSL or GLSL shaders, and a WebGL canvas does not become a hardware video decoder just because both APIs live in the browser.

  • Most developers reach these backends through FFmpeg. Running ffmpeg -hwaccel vaapi requests the VA-API media path, not Vulkan and not CUDA. See Decode video with VA-API for a quick verification test on Linux.

Calling all three "GPU acceleration" hides the boundaries between them. A single workstation can render a 3D viewport smoothly, refuse a CUDA script because the NVIDIA toolkit is missing (or the card is AMD or Intel), and fall back to CPU video decoding because libva lacks the right driver package. Those are three installations, three diagnostic tools, and three failure modes sharing one physical card.

The five layers between your code and silicon

Even when a project’s README mentions only one API, your program rarely speaks directly to the GPU driver.

Your program often calls a translator, which calls a target API, which calls a vendor driver, which drives the GPU

In practice, calls pass through up to five layers: your application code, an optional translator or runtime abstraction, the target GPU API, the vendor driver (NVIDIA, AMD, Intel, Apple, or a mobile GPU vendor), and finally the hardware itself. Two architectural realities fall straight out of that stack.

First, GPU memory is not process mmap. When you allocate a buffer through CUDA, Vulkan, or WebGPU, the driver allocates memory under device ownership rules, not inside ordinary CPU virtual memory. On discrete cards, bytes travel across the PCIe bus through explicit copy commands or mapped staging buffers. Even on unified-memory machines where CPU and GPU share physical RAM, the API still treats GPU buffers as separate allocations with explicit ownership and synchronization rules so the two processors do not race on the same bytes.

Second, a window is a separate system concern. Vulkan, Direct3D 12, and Metal do not open windows or read mouse events; to put pixels on screen, your program asks the window system (Win32, Wayland, X11, AppKit, or a browser <canvas>) for a surface and negotiates a swapchain of images to present. Compute kernels and headless video decoders skip that layer altogether.

Translators: why your code and your logs disagree

Much of modern GPU programming relies on translation layers that accept one API at the top and emit another API for the vendor driver at the bottom. Knowing the major translators explains why a crash dump or profiler frequently names an API your source code never imported.

WebGL routes through ANGLE, WebGPU through Dawn or wgpu, Vulkan on Apple through MoltenVK, and OpenGL through Zink
  • ANGLE sits behind WebGL in major browsers. Your page calls WebGL (an OpenGL ES dialect), and ANGLE translates those calls into Direct3D 11 on Windows, Metal on Apple devices, or Vulkan and native OpenGL elsewhere.

  • Dawn (used by Chrome and Chromium) and wgpu (used by Firefox and native Rust applications) implement WebGPU and translate WGSL shaders and command buffers onto Direct3D 12, Metal, or Vulkan depending on the operating system.

  • MoltenVK translates Vulkan calls and SPIR-V shaders into Metal so Vulkan applications can run on macOS and iOS, where Apple ships Metal rather than native Vulkan drivers.

  • Zink is Mesa’s driver that translates desktop OpenGL onto Vulkan, allowing older OpenGL programs to ride newer Vulkan drivers.

  • DXVK (for Direct3D 9, 10, and 11) and vkd3d-proton (for Direct3D 12) translate Windows Direct3D calls onto Vulkan on Linux, which is how Proton runs most Windows games without native Linux builds.

  • nvidia-vaapi-driver translates Linux VA-API media requests onto NVIDIA’s NVDEC hardware path.

Translators are rarely the APIs you sit down to learn first, yet they shape every real debugging session. Read a stack trace from the top when deciding which SDK or headers your build requires, and read it from the bottom when investigating a driver bug, missing extension, or unexpected performance cliff: the install belongs to the API you wrote, while the hardware behavior belongs to the API the vendor driver actually received.

Browsers, Node, and virtualized guests

A modern desktop browser exposes all three GPU jobs to a web page through three separate doors: drawing through WebGL 2 or WebGPU, general compute through WebGPU (WebGL 2 has no compute shader), and hardware video through WebCodecs. Each door runs inside the browser’s sandboxed GPU process and routes through its platform translators (ANGLE, Dawn or wgpu, and the host media stack).

Node has none of those doors. A stock Node process has no WebGL, no WebGPU, and no WebCodecs. When a test runner boots a script in Node and checks navigator.gpu or tries to create a WebGL canvas context, it is asking a headless JavaScript runtime for browser APIs that do not exist there. Native GPU access from Node requires native bindings or launching a real browser.

That split shows up sharply whenever a guest environment tries to borrow a browser’s GPU. In unkernel, for example, a Linux guest running inside a web page maps guest OpenGL onto the page’s WebGL 2 context, guest Vulkan (kwvk) onto the page’s WebGPU device by translating SPIR-V into WGSL (giving workloads like llama.cpp access to both draw and compute), and guest VA-API onto WebCodecs; run that same guest under Node and it keeps its CPU and Linux memory manager, while all three GPU switches do nothing because the page’s GPU doors are absent.

Where to start

Pick your path in two steps: decide which job you need, then look at the environment where the code will run.

Job Environment Start here

Draw frames

Concepts and pipelines

Graphics programming

Run parallel math

Concepts across CUDA, HIP, Vulkan, WebGPU

GPU compute

Draw and compute

Browser (zero SDK install)

Draw a triangle and run a compute shader

Compute

NVIDIA GPU (Linux or Windows)

Compile and run a CUDA kernel

Compute

AMD GPU on Linux (ROCm)

Compile and run a HIP kernel

Compute

Cross-vendor native (Vulkan)

Dispatch a Vulkan compute shader

Video decode

Linux (libva and FFmpeg)

Decode video with VA-API

Any

Checking what this machine actually exposes

Check which GPU APIs are available

Reference

APIs, shading languages, and translators

GPU API lookup

For the essay version of this mental model, see Your GPU is not a single API.