In Firefox builds specification support , providing a programming interface for handling 3D graphics and computations on the GPU, conceptually similar to an API , and . The specification is being developed by Mozilla, Google, Apple, Microsoft, and community representatives in , established under the W3C organization.
The key task of WebGPU is to create a safe, convenient, portable, and high-performance programming interface for use in the Web platform for technologies and capabilities of 3D graphics provided by modern system graphics APIs such as Direct3D 12 on Windows, Metal on macOS, and Vulkan on Linux. Conceptually, WebGPU differs from WebGL in much the same way that Vulkan differs from OpenGL, and it does not rely on a specific graphics API but represents a universal layer that generally utilizes the same low-level primitives as those found in Vulkan, Metal, and Direct3D.
WebGPU provides JavaScript applications with lower-level control over the organization, processing, and transmission of commands to the GPU, managing associated resources, memory, buffers, texture objects, and compiled graphic shaders. This approach allows for higher performance in graphics applications by reducing overhead and enhancing efficiency in working with the GPU.
WebGPU enables the creation of fully complex 3D projects for the Web that perform as well as standalone applications that interface directly with Vulkan, Metal, or Direct3D, but are not tied to specific platforms. WebGPU also offers enhanced options for porting native graphics applications to a form capable of running on web technologies, thanks to the implementation of WebAssembly. In addition to 3D graphics, WebGPU covers capabilities related to offloading calculations to the GPU and supports shader development. Shaders can be created in the WebGPU Shading Language or specified in the SPIR-V intermediate format, then translated into the shading languages supported by current drivers.
WebGPU employs separate management of resources, preparation tasks, and command transmission to the GPU (in WebGL, a single object was responsible for everything at once). Three separate contexts are provided:
GPUDevice for creating resources like textures and buffers; GPUCommandEncoder for encoding individual commands, including rendering and compute stages; GPUCommandBuffer for queuing for execution on the GPU. The result can be rendered in an area associated with one or more canvas elements, or processed without output (for example, when running compute tasks). The separation of stages simplifies the distribution of resource creation and preparatory operations into different handlers that can be executed in different threads.
The second difference between WebGPU and WebGL is its approach to state handling. WebGPU offers two objects—GPURenderPipeline and GPUComputePipeline—that allow combining various states pre-defined by the developer, which enables the browser to save resources by avoiding extra work, such as recompiling shaders. Supported states include shaders, vertex buffer layouts and attributes, attached group layouts, blending, depth, and rendering output formats.
The third feature of WebGPU is its binding model, which largely
resembles the resource grouping mechanisms present in Vulkan.
To group resources in WebGPU, a GPUBindGroup object is provided, which can be linked with other such objects during command recording for use in shaders. Creating such groups allows the driver to carry out necessary preparatory actions in advance, and enables the browser to switch resource bindings significantly faster between rendering calls. The resource binding layout can be defined in advance using a GPUBindGroupLayout object.

In Firefox, to enable WebGPU in about:config, there's a setting titled 'dom.webgpu.enabled'. For rendering the CanvasContext, enabling the compositing system is also required ('gfx.webrender.all' in about:config), which is written in Rust and offloads the rendering operations of the page content to the GPU. The WebGPU implementation is based on the code from the
, written in Rust and capable of working on top of the DX12, Vulkan, and Metal APIs in Linux, Android, Windows, and macOS (support for DX11 and OpenGL ES 3.0 is also in development). Concurrently, another implementation is being developed by Google, which is available in the Chromium is activated using the flag "chrome://flags/#enable-unsafe-webgpu" but currently works only on macOS and Windows.
Source: opennet.ru
