WebGPU — the new web standard (W3C, finalized 2023) for working with the GPU in the browser. Replaces WebGL 2.0, adds compute shaders (ML inference, physics), maps natively to Vulkan/Metal/Direct3D 12. Shading language: WGSL (not GLSL). Support: Chrome 113+, Safari 17+ (iOS 18), Firefox 141+ (flag). Production use: WebLLM, TensorFlow.js GPU backend.
Below: details, example, related terms, FAQ.
Free online tool — HTTP header checker: instant results, no signup.
// WebGPU — minimal compute shader
const adapter = await navigator.gpu.requestAdapter();
const device = await adapter.requestDevice();
const shader = device.createShaderModule({ code: /* WGSL */ `
@compute @workgroup_size(64)
fn main(@builtin(global_invocation_id) id: vec3<u32>) {
// parallel work here
}
`});WebGPU is designed to provide a modern interface for accessing GPU resources, aligning closely with low-level graphics APIs like Vulkan, Metal, and Direct3D 12. Its architecture is built around a set of core concepts that developers should understand to leverage its full potential.
At its core, WebGPU defines device, context, and pipeline objects, which are essential for managing GPU resources:
GPUAdapter, which identifies the available hardware.canvas element in HTML.Additionally, WebGPU introduces command buffers, which allow developers to record a series of GPU commands that can be executed efficiently in batches. This is crucial for optimizing performance, especially in complex applications.
Furthermore, WebGPU supports resource views that allow shaders to access textures and buffers. These resources can be dynamically created and managed, providing flexibility in rendering and computation tasks.
In summary, understanding the architecture of WebGPU is vital for developers aiming to create high-performance web applications that utilize GPU capabilities effectively.
To get started with WebGPU, developers need to set up a basic rendering pipeline and execute commands. Below are practical examples demonstrating how to initialize WebGPU, create a device, and render a simple triangle.
First, ensure that you have access to WebGPU by checking for support in the browser:
const adapter = await navigator.gpu.requestAdapter(); If the adapter is available, create a device:
const device = await adapter.requestDevice(); Next, create a swap chain for rendering:
const context = canvas.getContext('webgpu'); const swapChainFormat = 'bgra8unorm'; context.configure({ device, format: swapChainFormat }); Now, define a simple vertex buffer:
const vertices = new Float32Array([0, 1, -1, -1, 1, -1]); const vertexBuffer = device.createBuffer({ size: vertices.byteLength, usage: GPUBufferUsage.VERTEX, mappedAtCreation: true }); Map the buffer and copy the vertex data:
new Float32Array(vertexBuffer.getMappedRange()).set(vertices); vertexBuffer.unmap(); Finally, create a render pass and submit the commands:
const commandEncoder = device.createCommandEncoder(); const passEncoder = commandEncoder.beginRenderPass({ colorAttachments: [{ view: context.getCurrentTexture().createView(), loadValue: [0, 0, 0, 1], storeOp: 'store' }] }); passEncoder.setVertexBuffer(0, vertexBuffer); passEncoder.draw(3); passEncoder.endPass(); device.queue.submit([commandEncoder.finish()]); This simple example sets up the environment to render a triangle using WebGPU. Developers can build upon this foundation to create more complex graphics and compute applications.
When utilizing WebGPU, it is essential to consider performance optimization strategies to ensure that applications run smoothly and efficiently. Here are some key aspects to focus on:
By focusing on these performance considerations, developers can create high-quality web applications that fully utilize the capabilities of WebGPU while maintaining responsiveness and efficiency.
WebGL — graphics only. WebGPU adds compute shaders + a better memory model, mirrors modern backend APIs.
For progressive enhancement — yes (Chrome 113+). For production-critical workloads — wait for Firefox stable (2026).
WebLLM runs Llama-7B on an RTX 3060 via WebGPU at 20-30 tokens/sec. Not better than server-side, but handy for private workloads.
Free plan — 10 monitors, checks every 5 min, no card required. Upgrade for 1-minute interval and multi-region monitoring.