WebGPU API: GPU Compute, WGSL, Ecosystem and Troubleshooting
What WebGPU is, how to request a GPU in the browser, compute shaders, differences from WebGL, cross-platform tooling, and common Chrome fixes.
This page summarises Chrome’s WebGPU documentation and related platform notes. WebGPU is the modern path for GPU rendering and general-purpose compute in the browser, with a growing stack that also reaches native apps through shared C APIs and libraries like Dawn and wgpu.
WebGPU is a web graphics API that offers significant benefits, such as greatly reduced JavaScript workload for the same graphics and more than three times improvements in machine learning model inferences. This is possible because of flexible GPU programming and access to advanced capabilities that WebGL does not provide.
— Google Chrome, Overview of WebGPU
Chrome positions WebGPU alongside Wasm, WebGPU, and WebNN under “accelerate compute” for in-browser AI and heavy numeric work.
WebGPU: what it is and when to use it
Section titled “WebGPU: what it is and when to use it”WebGPU answers the need for GPU compute (GPGPU) and next-generation graphics on the web without staying locked to WebGL’s older model. The W3C “GPU for the Web” community group defined a low-level API; implementations expose adapters and devices, use WGSL for shaders, and support compute shaders that WebGL lacks.
| Goal | Why WebGPU |
|---|---|
| ML inference or large matrix math in the page | Compute shaders and storage buffers; TensorFlow.js and similar stacks target WebGPU |
| Modern 3D with less CPU overhead | Stateless pipelines, async command recording, closer to Vulkan/D3D12/Metal |
| Video or camera processing on the GPU | Tight integration with WebCodecs (VideoFrame, external textures) |
| Same GPU code on web and desktop | webgpu.h, Dawn, Emscripten (emdawnwebgpu) |
For a focused compute walkthrough (buffers, bind groups, matrix multiply), see Get started with GPU Compute on the web. For AI-specific platform context, see Accelerate AI on the web.
Browser support and secure contexts
Section titled “Browser support and secure contexts”The initial WebGPU release in Chrome shipped in Chrome 113 on ChromeOS (Vulkan), Windows (D3D12), and macOS; Android followed in Chrome 121 on supported devices. Firefox and Safari have also shipped WebGPU in recent releases; Chrome’s overview points readers to the gpuweb implementation status page for current coverage.
WebGPU is only available in secure contexts. If navigator.gpu is missing, version, HTTPS, and localhost rules are the first things to check (troubleshooting guide).
Access the GPU: navigator.gpu, adapter, and device
Section titled “Access the GPU: navigator.gpu, adapter, and device”In JavaScript, the entry point is navigator.gpu, analogous to navigator.gpu / wgpu::CreateInstance() in native C++ samples.
Accessing the GPU is easy in WebGPU. Calling
navigator.gpu.requestAdapter()returns a JavaScript promise that will asynchronously resolve with a GPU adapter. Think of this adapter as the graphics card.— Google Chrome, Get started with GPU Compute on the web
Typical flow:
const adapter = await navigator.gpu.requestAdapter()(options: power preference, etc.).const device = await adapter.requestDevice()(optional features and limits).- Use
devicefor buffers, pipelines, and command encoders.
By design, requestDevice() may give a lowest-common-denominator device unless you request higher limits—improving portability across GPUs (From WebGL to WebGPU).
Buffer memory: map, unmap, and async GPU work
Section titled “Buffer memory: map, unmap, and async GPU work”CPU and GPU must not race on the same buffer. Patterns from Chrome’s compute guide:
- Create with
mappedAtCreation: trueto write from JavaScript, thenunmap()before GPU use. - Queue copies with a
GPUCommandEncoderanddevice.queue.submit(). - Read back with
mapAsync(GPUMapMode.READ)after work finishes.
Buffered GPU commands vs immediate buffer API calls are an important distinction: encoder methods are batched; many GPUBuffer operations run immediately when called.
GPU compute shaders: pipelines, bind groups, dispatch
Section titled “GPU compute shaders: pipelines, bind groups, dispatch”Compute programs run on the GPU in parallel; inputs and outputs are buffers (often storage buffers), not render targets.
Programs running on the GPU that only perform computations (and don’t draw triangles) are called compute shaders. They are executed in parallel by hundreds of GPU cores (which are smaller than CPU cores) that operate together to crunch data.
— Google Chrome, Get started with GPU Compute on the web
A minimal compute path:
- Define a bind group layout (shader interface) and bind group (actual buffers at binding indices).
- Create a compute pipeline with WGSL (
@compute @workgroup_size(...)). beginComputePass()→setPipeline→setBindGroup→dispatchWorkgroups(x, y, z)→end().- Copy results to a mappable buffer and
mapAsyncto read.
Chrome’s matrix-multiply sample shows dispatchWorkgroups sized from matrix dimensions and workgroup size (e.g. 8×8). For large matrices, GPU execution wins over CPU implementations beyond modest sizes (performance discussion).
computePipeline.getBindGroupLayout(0) can infer layout from the shader and reduce boilerplate.
From WebGL to WebGPU: what changes in practice
Section titled “From WebGL to WebGPU: what changes in practice”Both APIs run shaders on the GPU, but mental models differ: WebGL uses GLSL and lots of global state; WebGPU uses WGSL, immutable pipelines, and command encoders.
| Area | WebGL | WebGPU |
|---|---|---|
| State | Global bindings until changed | Encapsulated in immutable render/compute pipelines |
| Errors / sync | e.g. gl.getError() can force sync IPC |
Fully asynchronous error reporting |
| Compute | Not available | Compute shaders (ML, simulation, etc.) |
| Canvas | Context manages canvas | You manage surfaces, MSAA resolve, multiple canvases per device |
| Uniform linkage | Names (getUniformLocation) |
Byte offsets / binding indices—you keep WGSL and JS in sync |
| Mipmaps | generateMipmap() |
You generate mips yourself (or use a utility) |
| Clip space Z | −1…1 (OpenGL) | 0…1 (Metal-style); Y axis conventions differ in framebuffer space |
WebGPU is a stateless API, and does not maintain a global state. Instead, it uses the concept of a pipeline to encapsulate all of the rendering state that was global in WebGL.
— Google Chrome, From WebGL to WebGPU
Storage buffers (WebGPU-only) support much larger bindings than uniform buffers, optional atomics, and runtime-sized arrays—enabling algorithms WebGL cannot express cleanly.
For video, device.importExternalTexture({ source: videoFrame }) pairs with WebCodecs; Chromium’s VideoNG narrative describes WebGPU buffers alongside WebCodecs primitives for advanced playback and processing.
Cross-platform WebGPU ecosystem: Dawn, webgpu.h, and Wasm
Section titled “Cross-platform WebGPU ecosystem: Dawn, webgpu.h, and Wasm”WebGPU is not only a JavaScript API. Chrome documents a collaborative standard with native implementations:
For web developers, WebGPU is a web graphics API that provides unified and fast access to GPUs. WebGPU exposes modern hardware capabilities and allows rendering and computation operations on a GPU, similar to Direct3D 12, Metal, and Vulkan.
— Google Chrome, Build an app with WebGPU
Parallel tracks:
- JavaScript in browsers (
navigator.gpu). webgpu.h— platform-agnostic C API; Dawn (Chromium) and wgpu-native (Rust) implement it.- Emscripten + emdawnwebgpu — same C++ can target desktop (Dawn + GLFW) and the web (
emcmake,ASYNCIFY,USE_GLFW=3); see Build an app with WebGPU. - Node.js can run JS WebGPU via a Dawn-based module; Deno can use wgpu (ecosystem article).
When compiling C/C++ to Wasm with Emscripten for the web, Chrome’s Cpp on the web recommends modern link flags (-sEXPORT_ES6, -sENVIRONMENT=web, -sSTRICT, -sALLOW_MEMORY_GROWTH, -Oz/LTO) and wrapping builds with emcmake / emmake.
Libraries (Babylon.js, PlayCanvas, TensorFlow.js, Three.js in progress) are adopting WebGPU so application code may need small changes (overview).
Cloudflare Durable Objects and WebGPU
Section titled “Cloudflare Durable Objects and WebGPU”On Cloudflare, WebGPU is not a production Workers feature.
From Cloudflare Durable Objects WebGPU: enable compatibility_flags = ["experimental", "webgpu"] in Wrangler for local dev; the API is reachable inside Durable Objects, not ordinary Workers. The documented surface supports compute-oriented types (adapters, buffers, compute pipelines) but not full rendering types such as GPURenderPipeline, GPUTexture, or canvas formats yet. For deployed GPU ML on Cloudflare’s network, the docs point to Workers AI instead.
Chrome-only developer features (not for production)
Section titled “Chrome-only developer features (not for production)”Chrome exposes non-standard WebGPU helpers for debugging—timestamp queries without quantization, extended GPUAdapterInfo, strictMath on shader modules, and GPUExternalTexture.isZeroCopy. These require the WebGPU Developer Features flag at chrome://flags/#enable-webgpu-developer-features and must not ship to end users (WebGPU developer features).
Troubleshooting: navigator.gpu, null adapter, and performance
Section titled “Troubleshooting: navigator.gpu, null adapter, and performance”Chrome’s WebGPU: Troubleshooting tips and fixes is the canonical checklist.
navigator.gpu is undefined
Section titled “navigator.gpu is undefined”Check in order: Chrome 113+ (121+ on Android), HTTPS or localhost, then insecure-origin flags or local SSL workarounds if needed.
requestAdapter() returns null
Section titled “requestAdapter() returns null”Common causes: hardware acceleration disabled in chrome://settings/system, unsupported platform (try chrome://flags/#enable-unsafe-webgpu, plus Vulkan on Linux), GPU blocklist (chrome://gpu), adapter options mismatch, missing GPU, or repeated GPU process crashes.
WebGPU slower than WebGL
Section titled “WebGPU slower than WebGL”Confirm chrome://gpu shows WebGPU: Hardware accelerated. A straight WebGL port may miss WebGPU-specific batching and pipeline patterns (From WebGL to WebGPU).
Windows-specific notes
Section titled “Windows-specific notes”Chrome does not use multiple GPU adapters at once; powerPreference may be ignored on laptops (integrated GPU chosen for power). chrome://flags/#force-high-performance-gpu can force the discrete GPU when available.
Common mistakes (short list)
Section titled “Common mistakes (short list)”- Using
http://on a non-localhost origin without treating it as secure. - Reading GPU buffers while still mapped, or submitting commands before
unmap(). - Assuming WebGL-style global state instead of new pipelines per state change.
- Relying on production WebGPU on Cloudflare Workers instead of local Durable Object dev only.
- Enabling Chrome developer-only flags in production builds.
Implementation churn is tracked in What’s New in WebGPU; use that series when a feature mentioned in older samples is missing in your Chrome version.
How to check this on your site
Section titled “How to check this on your site”- Open
chrome://versionand confirm Chrome meets the minimum for your target platform (113+ desktop, 121+ Android where applicable), per troubleshooting. - Load your page over HTTPS or
http://localhost, open DevTools, and runawait navigator.gpu?.requestAdapter(); a null result triggers the adapter checklist on WebGPU: Troubleshooting tips and fixes. - Visit
chrome://gpuand confirm WebGPU: Hardware accelerated when diagnosing performance. - Run a known sample from Get started with GPU Compute on the web or Overview of WebGPU resources to validate compute or rendering paths.
- You can check automatically in Answerwell (our tool): https://answerwell.org/workspace
Report an error or ask a question
Section titled “Report an error or ask a question”If something on this page is wrong or unclear, email yimasynthetic@gmail.com with the page URL and the exact statement you are asking about.