WebGPU
How it works
The entry point is navigator.gpu. You call navigator.gpu.requestAdapter() to obtain a GPUAdapter, then adapter.requestDevice() to get a GPUDevice โ the main interface for most WebGPU functionality. Shaders (in WGSL) are loaded via device.createShaderModule() and assembled into a pipeline: a render pipeline (GPURenderPipeline) or a compute pipeline (GPUComputePipeline). Commands are recorded with a GPUCommandEncoder (render/compute passes) and submitted to the GPU through the device.queue (GPUQueue) via submit(). To render to a canvas, you call canvas.getContext("webgpu") (returns a GPUCanvasContext) and configure the context (context.configure) with the device and a texture format (navigator.gpu.getPreferredCanvasFormat()). In a compute pipeline, a compute shader processes data in parallel across a specified number of workgroups and writes results into buffers. WebGPU requires a secure context (HTTPS).
Problem solved
The older, OpenGL ES-based WebGL did not keep up with the architecture of modern GPUs: it had limited general-purpose compute support, more overhead, and no access to advanced GPU features. WebGPU provides a modern API compatible with Vulkan/Metal/Direct3D 12, with first-class GPGPU support, faster operation, and access to newer GPU capabilities.
Components
The WebGPU entry point exposed on navigator; provides requestAdapter() and getPreferredCanvasFormat().
Represents a GPU adapter; from it you request a GPUDevice and read adapter info, features and limits.
A logical GPU device โ the main interface through which most WebGPU functionality is accessed (creating buffers, shaders, pipelines).
Controls execution of encoded commands on the GPU; commands are submitted via device.queue.submit().
Encodes commands (render and compute passes) to be issued to the GPU; the finish() result is submitted to the queue.
Renders graphics, typically into a <canvas> element, but can also render offscreen.
Official
A general-purpose compute pipeline: a compute shader processes data in parallel across workgroups and writes the result into buffers.
Official
A low-level, Rust-like shading language; shader code is loaded via device.createShaderModule(). It has a separate W3C specification.
The WebGPU rendering context of a <canvas> element, obtained via canvas.getContext("webgpu"); configured through context.configure({ device, format }).
Official
Implementation
WebGPU is not Baseline and does not work in some of the most widely-used browsers โ support depends on browser and platform.
WebGPU is only available in a secure context, so it will not work on pages served without HTTPS (other than localhost).
navigator.gpu may be undefined and requestAdapter() may return null when no compatible GPU/driver is present โ skipping this check causes runtime errors.
Evolution
W3C publishes the First Public Working Draft of the WebGPU specification (18 May 2021).
WebGPU becomes available by default in Chrome 113 (ChromeOS with Vulkan, Windows with Direct3D 12, macOS) โ the first shipment in a major browser.
W3C publishes the Candidate Recommendation Snapshot of the WebGPU specification (19 December 2024).
Hyperparameters (configurable axes)
The number of workgroups across which a compute shader processes data in parallel. Determines how GPU computation is parallelized.
The texture format of the <canvas> context set in context.configure(). The recommended value is returned by navigator.gpu.getPreferredCanvasFormat().
How the alpha channel is handled when compositing canvas content, set in context.configure() (e.g. "premultiplied").
Hardware requirements
WebGPU abstracts over different native GPU backends (Vulkan, Metal, Direct3D 12) independently of the card vendor; it does, however, require GPU hardware and a compatible driver.