Modern tooling: WebAssembly, WebGPU and AI assistants · Part 35 of 36

WebGPU: graphics and compute in the browser

Expert 18 min

How GPUs differ from CPUs, the WebGPU pipeline and WGSL shaders, compute shaders for parallel work, and browser support as of 2026.

What you will learn

  • You can explain why GPUs are fast for parallel data work.
  • You can outline the WebGPU objects: adapter, device, buffers, pipelines, command encoders.
  • You can write a simple WGSL compute shader.

Before this: WebAssembly: a portable compilation target

CPU vs GPU

A CPU has a few powerful cores, built to run varied, branching code fast. A GPU has thousands of simple cores that run the same program on many data items at once — every pixel, every vertex, every element of a matrix. When your problem is "do the same thing to a million items", a GPU can be tens to hundreds of times faster. That's why GPUs power graphics, image processing, simulations and machine learning.

A graphics chip with many tiny cores glowing in a grid

From WebGL to WebGPU

WebGL (2011) exposed an OpenGL ES-style API to the web. It is graphics-focused and based on a 1990s design. WebGPU is its modern successor, modelled on Vulkan, Metal and Direct3D 12: explicit, lower overhead, and with first-class compute shaders for general-purpose GPU work.

Support timeline:

  • Chrome and Edge shipped WebGPU on Windows, macOS and ChromeOS with version 113 (May 2023), Android later.
  • Firefox shipped it on Windows with Firefox 141 (July 2025), other platforms following.
  • Safari shipped it with Safari 26 (September 2025) on macOS, iOS, iPadOS and visionOS.

So as of late 2026 it is available in all major browser engines, though not on every platform/GPU combination — always feature-detect with navigator.gpu and keep a fallback.

The building blocks

const adapter = await navigator.gpu?.requestAdapter();
if (!adapter) throw new Error("WebGPU not available");
const device = await adapter.requestDevice();
  • Adapter: a physical GPU (or software implementation).
  • Device: your logical connection to it; creates everything else.
  • Buffers and textures: GPU memory for data and images.
  • Shader modules: programs in WGSL (WebGPU Shading Language).
  • Pipelines: a render pipeline (vertex + fragment shader → pixels) or a compute pipeline.
  • Bind groups: which buffers/textures a shader can see.
  • Command encoder → queue: you record commands and submit them in a batch.

A compute shader

This WGSL shader doubles every number in a buffer, with each GPU invocation handling one element:

@group(0) @binding(0) var<storage, read_write> data: array<f32>;

@compute @workgroup_size(64)
fn main(@builtin(global_invocation_id) id: vec3<u32>) {
  if (id.x < arrayLength(&data)) {
    data[id.x] = data[id.x] * 2.0;
  }
}

JavaScript creates a storage buffer, binds it, dispatches ceil(n / 64) workgroups and copies the result to a mappable buffer to read it back. The bounds check matters: the last workgroup may have more invocations than remaining elements.

Thinking in parallel

GPU programming rewards a different style:

  • No shared mutable state between invocations except through atomics or carefully synchronised workgroup memory.
  • Avoid divergent branches — invocations in a group run in lockstep; if half take one branch and half the other, both paths run.
  • Minimise transfers between CPU and GPU memory; they are often the bottleneck.
  • Reductions (sums, maxima) need multi-step patterns, not a simple loop.

What people build

Real-time 3D (Babylon.js and three.js support WebGPU), image and video filters, physics and particle simulations, and running machine-learning models locally in the browser (ONNX Runtime Web and Transformers.js have WebGPU back ends) — useful when data should never leave the device.

Key points

  • GPUs run the same program on thousands of data items in parallel.
  • WebGPU is the modern successor of WebGL with compute shaders; shaders are written in WGSL.
  • Support: Chrome 113 (May 2023), Firefox 141 on Windows (July 2025), Safari 26 (September 2025); feature-detect navigator.gpu.
  • Objects: adapter, device, buffers/textures, shader modules, pipelines, bind groups, command encoder + queue.
  • Parallel style: no shared mutable state, few divergent branches, few CPU–GPU transfers.

Flashcards

Question: Why is a GPU fast for "do the same to a million items"?
Answer: It has thousands of simple cores running the same program on different data in parallel.
Question: What language are WebGPU shaders written in?
Answer: WGSL (WebGPU Shading Language).
Question: Which Chrome version first shipped WebGPU?
Answer: Chrome 113 (May 2023).
Question: Why does a compute shader check id.x < arrayLength?
Answer: The last workgroup may have more invocations than remaining elements.

Check yourself

Think about your answer, then open it. In the app the quiz is interactive, earns points and brings back what you missed.

  1. A compute shader with @workgroup_size(64) must process 1,000 elements. How many workgroups do you dispatch?

    Show the answer

    16 workgroups

    ceil(1000 / 64) = 16 (the last one partly idle).

    Source: W3C WebGPU / MDN

  2. Match the WebGPU object with its role.

    Show the answer

    Adapter = Represents a physical GPU; Device = Logical connection that creates resources; Bind group = Connects buffers and textures to a shader; Command encoder = Records commands to submit to the queue

    These are the core WebGPU objects.

    Source: W3C WebGPU

  3. Which browsers shipped WebGPU by the end of 2025?

    • Chrome (113, 2023)
    • Firefox on Windows (141, 2025)
    • Safari (26, 2025)
    • Internet Explorer 11
    Show the answer

    Chrome (113, 2023); Firefox on Windows (141, 2025); Safari (26, 2025)

    IE 11 is retired and never supported WebGPU.

    Source: MDN, WebGPU API browser compatibility

  4. What slows GPU code down most often in practice?

    • Transfers between CPU and GPU memory
    • Too many cores
    • Using WGSL
    • Using 32-bit floats
    Show the answer

    Transfers between CPU and GPU memory

    Copying data across the bus is often the bottleneck; keep data on the GPU.

    Source: MDN, WebGPU best practices

Sources

Facts checked on 2026-11-30. Skillgrove lessons are free learning material — no certificate and no accreditation.