Google has announced the default inclusion of support for the graphics API WebGPU and the WebGPU Shading Language (WGSL) in Chrome version 113, scheduled for release on May 2. WebGPU provides a programming interface similar to Vulkan, Metal, and Direct3D 12 for performing operations on the GPU side, such as rendering and computations, and also allows the use of a shading language to write programs that run on the GPU. The implementation of WebGPU will initially be included only in builds for ChromeOS, macOS, and Windows. Support for WebGPU on Linux and Android will be enabled later.
In addition to Chrome, experimental support for WebGPU has been tested in Firefox since April 2020 and in Safari since November 2021. To enable WebGPU in Firefox, the flags dom.webgpu.enabled and gfx.webgpu.force-enabled must be set in about:config. No information has been provided yet regarding plans to enable WebGPU by default in Firefox and Safari. The implementations of WebGPU for Firefox and Chrome are available as separate libraries—Dawn (C++) and wgpu (Rust)—which can be used to integrate WebGPU support into your applications. Work is also underway to add WebGPU support to popular JavaScript libraries that initially used WebGL. For example, full support for WebGPU has already been announced in Babylon.js, with partial support in Three.js, PlayCanvas, and TensorFlow.js.
Conceptually, WebGPU differs from WebGL in a way similar to how the Vulkan graphics API differs from OpenGL, yet WebGPU is not based on a specific graphics API; rather, it serves as a universal layer that uses the same low-level primitives found in Vulkan, Metal, and Direct3D. WebGPU provides JavaScript applications with tools for low-level control over the organization, processing, and dispatch of commands to the GPU, management of related resources, memory, buffers, texture objects, and compiled graphics shaders. This approach allows for higher performance in graphics applications by reducing overhead and improving the efficiency of GPU handling.
WebGPU enables the creation of complex 3D projects for the web, performing as well as standalone applications that directly utilize Vulkan, Metal, or Direct3D, but without being tied to specific platforms. WebGPU also offers additional capabilities for porting native graphics applications to a format that can run on web technologies, thanks to compilation to WebAssembly. In addition to 3D graphics, WebGPU also encompasses functionalities related to offloading computations to the GPU and executing shaders.
Key features of WebGPU:
- Separate management of resources, setup operations, and command submission 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; and GPUCommandBuffer for queuing for execution in the GPU. The result can be rendered in an area associated with one or more canvas elements or processed without output (for example, when executing compute tasks). This separation of stages simplifies the distribution of resource creation and setup operations into different handlers that can run in different threads.
- A different approach to state management. WebGPU proposes two objects — GPURenderPipeline and GPUComputePipeline, which allow for the combination of various states predefined by the developer, enabling the browser to avoid expending resources on additional tasks like recompiling shaders. Among the supported states are: shaders, vertex buffer layouts and attributes, attached group layouts, blending, depth and templates, output formats after rendering.
- The binding model is largely reminiscent of the grouping resources found in Vulkan. To group resources in WebGPU, a GPUBindGroup object is provided, which can be linked with other similar objects during command recording for use in shaders. Creating such groups allows the driver to perform necessary preparatory actions in advance and enables the browser to switch resource bindings between rendering calls much faster. The layout of resource bindings can be defined in advance using a GPUBindGroupLayout object.
Source: opennet.ru
