๐ŸŽฎ

WebGPU โ€” How Browsers Access the Local GPU Directly

Successor to WebGL โ€” Vulkan/Metal/DX12-level low-level GPU API arrives in the browser

WebGPU is a browser-built-in API accessed via navigator.gpu. No installation needed โ€” JavaScript directly controls the local GPU.

How Is It Different from WebGL?

WebGL shipped in 2011. It wraps OpenGL ES 2.0 for browsers โ€” a 1990s-era design that couldn't leverage modern GPU features. No compute shaders, implicit state management causing driver overhead.

WebGPU arrived starting 2023. Based on post-2015 designs like Vulkan, Metal, and DirectX 12. More direct GPU access, compute shader support, and multi-threaded command preparation.

Browser โ†’ OS Mapping

Calling navigator.gpu.requestAdapter() has the browser internally map to OS-native APIs.

  • Windows โ†’ DirectX 12

  • macOS โ†’ Metal

  • Linux โ†’ Vulkan

Developers don't see this difference. Same JavaScript/WGSL code runs on all OSes.

What Is It Used For?

  1. Video editing โ€” per-frame effect compositing via GPU shaders (Tooscut, etc.)
  2. 3D games/rendering โ€” Three.js added a WebGPU backend
  3. AI inference โ€” running models in-browser (ONNX Runtime Web, etc.)
  4. Scientific simulation โ€” massive parallel computation (fluid, particle sims)

CPUs process sequentially with 8-16 cores. GPUs run identical operations across thousands of cores simultaneously. Applying the same function to every pixel is exactly this pattern โ€” making GPU acceleration highly effective.

Is WebGL Dead?

WebGL runs in nearly all browsers. WebGPU currently supports Chrome/Edge only. Safari and Firefox are incomplete. For 3D graphics alone, WebGL is still the safer compatibility bet. If you need compute shaders or modern GPU features, WebGPU is the only option.

How It Works

1

navigator.gpu.requestAdapter() โ†’ Request GPU adapter (browser maps to OS-native API)

2

adapter.requestDevice() โ†’ Acquire GPU device (connection)

3

device.createShaderModule({ code: WGSL }) โ†’ Compile WGSL shader

4

device.createRenderPipeline() โ†’ Vertex/fragment shader + blending config

5

commandEncoder โ†’ renderPass โ†’ draw() โ†’ GPU executes in parallel across thousands of cores

Pros

  • No installation โ€” GPU access with a single navigator.gpu call
  • Compute shader support โ€” general-purpose GPU computation, not just graphics
  • Cross-platform โ€” same WGSL code runs on Windows/macOS/Linux
  • Near-native performance when combined with Rust/WASM

Cons

  • Full support only on Chrome/Edge โ€” no Safari, Firefox unstable
  • WebGPU 1.0 spec doesn't cover all modern GPU features
  • Steeper learning curve vs WebGL โ€” pipeline/bind group low-level concepts required
  • Wide GPU performance variance across devices โ€” integrated vs discrete

Use Cases

Browser video editors โ€” per-frame GPU shader effect compositing (Tooscut) 3D games/visualization โ€” Three.js WebGPU backend, Babylon.js Browser AI inference โ€” ONNX Runtime Web, Transformers.js GPU backend Scientific simulation โ€” fluid/particle simulation via compute shaders