The WebGPU Spec Explained: A Portable GPU Compute API for the Web

The WebGPU compute API gives portable, validated GPU compute over Vulkan, Metal and D3D12.

The WebGPU Spec Explained: A Portable GPU Compute API for the Web
Written by TechnoLynx Published on 11 Jul 2026

The WebGPU compute API is the general-purpose half of WebGPU, a W3C specification that gives web pages, and native programs using standalone implementations, a validated and portable way to run compute shaders on the GPU. WebGPU has first-class support for general-purpose GPU computation. You write kernels in WGSL, bind their inputs and outputs through bind groups and dispatch workgroups, while the implementation runs over Metal, Vulkan or DirectX underneath. What you get is functional portability. What you can give up is GPU performance: one study measured CUDA and Vulkan backends up to 10x faster than WebGPU in LLM prefill.

That puts WebGPU in the same decision space as the APIs compared in our guide to CUDA vs OpenCL vs SYCL. It is a portability option with its own memory model and its own ceiling, and both are worth understanding before you commit a codebase to it.

Who Maintains the WebGPU Spec, and What It Standardises

The W3C GPU for the Web Working Group’s charter commits it to a web programming interface for graphics and computation, plus a companion shading language that can be translated or compiled into platform-specific instructions. The charter also says the API will not be tied to one platform technology: it has to be generic enough to sit on top of Direct3D 12, Metal and Vulkan. The specification describes itself as designed from the ground up to map efficiently to native GPU APIs from 2014 onwards.

That companion language is WGSL, and no native graphics backend accepts it directly. WGSL has to be translated into a platform-specific format such as SPIR-V, HLSL or MSL. Chrome’s Tint and Firefox’s naga both compile WGSL to HLSL, SPIR-V and Metal, while Safari’s wgslc targets Metal only. Before any of that translation happens, the implementation has to validate the shader against the instruction set and behaviours the specification defines.

Availability is now broad, though still not universal. Chrome 113 shipped WebGPU on ChromeOS devices with Vulkan support, Windows devices with Direct3D 12 and macOS. One announcement reported official support across Chrome, Edge, Firefox and Safari. It also said Android support arrived in Chrome 121 for Android 12 and later on Qualcomm and ARM GPUs, with Linux support still in progress. WebGPU is also not limited to browsers: Chromium’s Dawn and Firefox’s wgpu are available as standalone libraries that native applications can call directly.

How the WebGPU Compute API Runs a Kernel

Chrome’s own developer walkthrough calls WebGPU “very powerful and quite verbose”. These are the steps in the order they have to happen:

  1. Get an adapter and a device. The adapter represents a physical GPU and its driver, and the logical device is the isolated handle an application works through. The features and limits you request are exactly the ones validation enforces on that device, no more and no less.
  2. Create buffers with declared usage. Every GPUBuffer carries usage flags fixed at creation, and the STORAGE flag is what lets a compute shader bind the buffer as a storage buffer.
  3. Write the WGSL entry point. The @compute attribute marks the entry function and @workgroup_size sets the x, y and z dimensions of each workgroup.
  4. Describe the bindings. A bind group layout defines the input and output interface a shader expects, and a bind group supplies the actual resources. The specification recommends explicit pipeline layouts over "auto" in most cases, because a pipeline with an auto layout cannot share bind groups with other pipelines.
  5. Create the compute pipeline. All compute inputs and outputs live in the bindings. Compute shaders have no stage inputs or outputs, so their results are side effects written to storage bindings.
  6. Encode a compute pass and dispatch. dispatchWorkgroups(x, y, z) takes the number of workgroups in each dimension, not the number of invocations. Worked example from the specification: an entry point declared @workgroup_size(4, 4) and dispatched with dispatchWorkgroups(8, 8) runs 4 × 4 × 8 × 8 = 1,024 invocations.
  7. Submit. WebGPU defers execution. Nothing runs on the GPU until the encoder is finished into a command buffer and that buffer is submitted to the queue.
  8. Read back. The usual pattern copies results into a staging buffer and maps it with mapAsync(). While a buffer is mapped, the GPU cannot use it until unmap() is called.

Counting workgroups matches modern native GPU APIs but differs from OpenCL’s behaviour. Pipeline creation is not free either. The LlamaWeb inference backend reports a one-time cost of about 1 to 5 seconds on the first forward pass, after which it runs from cached pipelines.

Buffers and Bindings: Where WebGPU Parts Ways with CUDA

CUDA kernels take raw device pointers and by-value arguments at launch, and unified memory can hide the boundary between host and device altogether. If that host-device boundary is what you are reasoning about, our explainer on unified virtual memory covers how the abstraction works. WebGPU instead validates every command before it reaches the GPU, so a page can only work with its own data.

Aspect CUDA WebGPU compute
Passing memory to a kernel Raw device pointers as kernel arguments Buffers bound through bind groups and a pipeline layout
Small runtime parameters Passed by value at kernel launch No push-constant equivalent yet, so frameworks keep pools of small parameter buffers
Aliasing : Buffer aliasing is not allowed, which changes how in-place operations are bound
CPU access to GPU memory Synchronisation is the application’s job Mapping transfers ownership, so only the CPU or the GPU can access a buffer at any moment
Out-of-bounds access : Prevented by robust buffer access or bounds checks inserted into the shader
Fast on-chip memory Shared memory per block Workgroup memory, which the LlamaWeb authors describe as analogous to CUDA shared memory
Default workgroup ceiling : 256 invocations and 16,384 bytes of workgroup storage by default

Two more constraints matter for anyone moving CUDA code across. WGSL makes no guarantee that workgroups run concurrently, that they run one at a time, or that they launch in any particular order, so algorithms that rely on inter-block co-operation have no portable footing. Alignment rules also apply. A value placed in a buffer must sit at an offset that is a multiple of its type’s alignment. The LlamaWeb authors stored every quantisation format as flat u32 buffers to work around WebGPU’s limits on loading structs and on data-type alignment.

The upshot is that porting a CUDA kernel to WebGPU means restructuring it around explicit buffer semantics, not translating syntax. WebGPU’s validated command and binding model is what buys security and portability across Vulkan, Metal and D3D12.

Is WebGPU Compute Faster than WebGL for General-Purpose GPU Work?

Yes for large matrix work in SitePoint’s tests, and the reason is structural. WebGL was built for drawing. It can be repurposed for computation only with great effort, whereas WebGPU supports general computation as a first-class feature. An earlier effort, WebGL 2.0 Compute, was dropped because the mismatch with native APIs made it too hard, and its contributors moved to WebGPU instead. Compute on WebGL means encoding data as textures and treating draw calls as dispatches. WebGPU removes that indirection with storage buffers, workgroup shared memory and workgroupBarrier() synchronisation, which together make tiled algorithms possible.

A SitePoint benchmark of FP32 matrix multiplication measured WebGPU 3 to 8 times faster than WebGL at 2048×2048 and above on an Apple M2 and an NVIDIA RTX 3060. The gap narrowed to roughly 1.5 to 2 times at 512×512, and below 256×256 the difference fell within measurement noise, because pipeline creation and dispatch overhead dominate small problems. Those WebGL timings were wall-clock upper bounds, since WebGL timer queries are disabled in Chrome stable, so the ratios lean in WebGPU’s favour. The Chrome team’s launch announcement claims “more than three times” improvements in ML model inference.

Where WebGPU Compute Sits Next to CUDA, OpenCL and SYCL

WebGPU is a portability layer over native APIs. On Linux and Android it runs on Vulkan, on Apple platforms on Metal and on Windows on DirectX. SYCL comes from a different tradition: a vendor-neutral standard for single-source C++ across CPUs, GPUs, FPGAs and AI accelerators. For the native side of the comparison, our article on CUDA vs Vulkan compute covers what you gain by programming the layer WebGPU sits on.

Measured comparisons with SYCL changed with the benchmark configuration. A thesis benchmarked Dawn, wgpu, Vulkan and SYCL (AdaptiveCpp) on an AMD Radeon RX 6800 under Linux. In the 4096 matrix benchmark, SYCL was almost twice as fast as every other framework, while Dawn and wgpu performed on par with hand-written Vulkan compute shaders. In other configurations the order flipped. At workgroup size 4 in the timestamp runs, SYCL trailed the three Vulkan-based frameworks by about 8%, and with local-memory optimisation at sample size 7104 and workgroup size 4, SYCL came last, about 12% behind Dawn. The thesis also notes that the 256-invocation workgroup limit capped its 2D tile sizes at 16.

OpenCL is another portable route, though its dispatch semantics differ from WebGPU’s. Our guide to OpenCL on Linux as a portable inference backend covers that route.

How Far WebGPU Compute Falls Short of CUDA, and Why

The measured gap is large, and the studies point to two causes. The first is access to hardware features. The LlamaWeb study ran llama.cpp backends and found CUDA and Vulkan up to 10x faster than WebGPU during prefill and 2.5x faster during decode. The authors say this is likely due to better use of tensor cores and to vendor-specific features such as asynchronous memory loads. Metal outperformed WebGPU by more than 2x in prefill and 50% in decode, a smaller gap the authors put down to the Apple GPU’s lack of tensor cores and lower overall performance. Browser safety checks added slowdown in prefill, reaching 42% on an NVIDIA RTX 5080.

The second cause is dispatch overhead. A cross-vendor characterisation of WebGPU dispatch measured the true per-dispatch API cost at 24 to 36 µs on Vulkan and 32 to 71 µs on Metal. The same paper measured CUDA at 7.4 µs and notes that CUDA Graphs can bring launch latency below 1 µs through capture and replay. Command buffer submission accounted for 40% of that per-dispatch cost. Neural network inference issues many small dispatches, so per-operation validation compounds. Fusing kernels on native Vulkan at batch size 1 cut dispatches from 876 to 564 and raised throughput by 53%, while the same fusion on CUDA gave no benefit. The authors read this as evidence that the gap at small batch sizes comes from per-operation overhead, not kernel quality.

Read the headline figures with their conditions attached. That paper’s PyTorch-to-WebGPU backend reached 11% to 12% of CUDA throughput, but on float32, at batch size 1, with WGSL shaders running at 1% to 2% of FP32 peak where optimised third-party WGSL reaches about 17%. With WebLLM’s optimisations the picture changes. WebLLM on Chrome over Metal reached 97% of native MPS float16 decode throughput. The authors argue that closing the remaining gap likely needs changes to the specification itself, such as compute graph capture and replay, cooperative groups, persistent kernels and reduced validation for trusted workloads.

Whether that prefill gap matters depends on whether your workload would actually use tensor cores and asynchronous memory loads.

Can One WebGPU Kernel Run on NVIDIA, AMD and Intel Without a Rewrite?

Functionally, yes. Performantly, no. The LlamaWeb authors say plainly that WebGPU provides functional but not performance portability, which is why they built a kernel library that generates shaders from templates, specialising parameters such as matrix-multiply tile sizes per device and using subgroup or subgroup-matrix instructions only where the hardware supports them. Their evaluation covered 16 devices from 8 GPU vendors, and in some configurations their tuned parameters beat the Vulkan-specific llama.cpp backend, even though Vulkan is WebGPU’s runtime on Linux.

The specification expects functionality to differ between implementations. Optional features and numeric limits differ between implementations because of hardware and system software constraints. Subgroup sizes are powers of two between 4 and 128, and the actual size depends on the shader, the device and its compiler. Half precision has to be switched on explicitly with enable f16;. Browsers also report limits in tiers, not exact values, to reduce fingerprinting: a GPU with a real limit of 16,384 may be reported as 8,192. In the dispatch-overhead study, Qwen models failed with shader compilation errors on Chrome Canary over Linux and Vulkan, and other models needed the shader-f16 extension, while D3D12 on Windows succeeded.

Within a backend, the implementation matters substantially. Dispatch cost on Vulkan varied only between 24 and 36 µs across NVIDIA, AMD and Intel, but on Metal it ranged from 31.7 µs in Safari to 71.1 µs in wgpu-native. Firefox showed about 1,040 µs per dispatch on every platform tested. The LlamaWeb team measured about 1 token per second on Firefox against about 52 on Chrome for the same model on an Apple M3, and left Firefox out of its evaluation. A portable kernel therefore needs testing per browser and backend, not just per GPU.

Workloads That Fit WebGPU Compute, and Workloads That Do Not

The dispatch-overhead authors conclude that WebGPU ML inference is currently practical for latency-tolerant, portability-critical, privacy-sensitive or educational workloads. They also conclude it is not practical for latency-critical or high-throughput serving where CUDA is available. The table below applies that boundary, together with the measurements above, to common cases.

Workload Fit Why
Privacy-sensitive client-side inference Good Practical for privacy-sensitive workloads, with computation moved into the user’s browser
One codebase across browsers, operating systems and GPU vendors Good, with per-device tuning Functional portability holds, performance portability does not
Large matrix work currently running on WebGL Good 3 to 8x faster GEMM at 2048×2048 and above in SitePoint’s tests
Very small kernels or single operations Poor Pipeline creation cost can dominate, and gains fell within noise below 256×256
Batch-1 inference made of many small operations Acceptable if fused, on native Vulkan Fusion gave a 53% gain on native Vulkan but none on Metal
High-throughput serving where CUDA is available Poor Not practical for such serving, and CUDA led by up to 10x in prefill
Models that depend on hardware-native low-precision formats Limited WebGPU lacks formats such as nvfp4, bf16 and f8, so MLC-LLM converts such weights at runtime into f32 or f16

On that last row, the LlamaWeb authors found llama.cpp quantisation in WebGPU to be mainly a way of reducing memory, not a speed optimisation. If you are weighing the native llama.cpp backends instead, our comparison of llama.cpp Vulkan vs CUDA covers that choice.

Profile the Workload Before Picking a Portability Ceiling

The mistake to avoid here is choosing on an assumed ceiling instead of a profile. That happens in two ways: dismissing WebGPU as a browser toy without checking whether it reaches your deployment target, or adopting it without measuring the throughput it gives up. Choosing between WebGPU and a vendor API should rest on a profile of the actual workload.

The first step is to find where a representative run spends its time. If the run is dominated by dispatch count at small batch sizes, kernel fusion is the most effective lever on native Vulkan. If it is dominated by something a browser target makes possible at all, the throughput question may matter less than reach. Graph capture, cooperative groups and lighter validation for trusted workloads are proposals that have to be weighed against browser security, not features you can plan around today.

FAQ

What Is the Difference Between let and var in WGSL?

A let declaration names a value that is fixed each time the statement executes. A var declares a variable, a named reference to memory that can hold a value of a given type in a given address space.

Is WebGPU Better than OpenGL?

WebGPU supersedes WebGL, which mostly mirrors the older OpenGL ES API, and it is designed to expose the features of Vulkan, Metal and Direct3D. Unlike OpenGL, it is designed to allow command encoding from multiple threads, though using a single device from several threads is not supported yet.

What Can You Do with WebGPU?

Besides 3D graphics, WebGPU’s compute pipeline supports general-purpose GPU work such as ML inference and training, video processing and physics simulation in the browser.