WebGPU and Why It’s Exciting

by Michael Gandolfi

This article was published in Better Programming.

WebGPU is a new web standard currently being developed by the W3C GPU for the web community group, along with engineers from Apple, Mozilla, Microsoft, and Google, who promise to provide low-level graphics and compute API for the web.

Development first began in 2017 when Apple proposed a new web API for GPU-accelerated graphics and compute tasks. The initial proposal was based on Apple’s Metal graphics API. But, in 2018, Mozilla proposed a new API called WebGPU, based on the Vulkan graphics API developed by the Khronos Group. Microsoft and Google also joined the effort to develop the API, and the proposal was merged with Apple’s WebMetal proposal to form a new standard.

WebGPU will allow developers to leverage the power of modern GPUs for web-based graphics and general-purpose computing applications across all platforms and devices, including desktops, mobile devices, and VR/AR headsets. As of writing, the API is currently supported in the experimental versions of Chrome, Firefox, and Edge.

Compared to its predecessor, WebGL, WebGPU brings several advancements and improvements. One of the key advantages of WebGPU over WebGL is its low-level design that provides a much lower level of abstraction and more fine-grained control. WebGPU is also based on modern graphics APIs such as DirectX 12, developed by Microsoft, Vulkan, and Metal. WebGL, on the other hand, is based on the OpenGL ES 2.0 graphics API, which was primarily developed for mobile devices and embedded systems. Another advantage of WebGPU over WebGL is its cross-platform compatibility.

While a limited number of web browsers only support WebGL, WebGPU is designed to work on all major operating systems and devices, allowing developers to ignore platform-specific APIs or code.

WebGPU has many potential use cases across different industries and applications. Some of which include: gaming, virtual and augmented reality, machine learning, scientific simulations, and digital media and advertising. WebGPU can create high-performance, cross-platform games running in a web browser. Developers can use modern graphics hardware features like ray tracing and asynchronous computing to create more immersive and realistic gaming experiences similar to those achieved by a desktop game. As of now, gaming is very platform-specific.

Most desktop games are developed for Windows leaving Mac and Linux users behind. If WebGPU succeeds at becoming the standard for desktop gaming, developers could create just one version that can be run cross-platform. Another benefit of browser-based games is that there would no longer be a need for a centralized storefront, like Steam, for distributing games. Developers could sell access to their game directly in the browser and eliminate the middleman.

Currently, no major online games use WebGPU exclusively, as the API is still in the early stages of development. However, some experimental games and demos have been created using the API, demonstrating the potential for high-performance web-based graphics. One project that I am particularly interested in is Ambient, a multiplayer game engine powered by Rust, WebAssembly, and WebGPU. It was just announced on the twenty-second of this month, and they currently have a video showcasing a demo linked here. If you want to see some WebGPU renderings without downloading the experimental build of Chrome, check this out.

For those of you who want to use WebGPU on your computer, you will need to first download Chrome Canary from here. After it installs, you must enter about://flags in your search bar and hit enter. Then use the search bar for “Unsafe WebGPU” and toggle enable. Make sure to disable this when you’re done, as it could be unsafe for browsing. Now you should be able to run WebGPU on your machine. If you want to see one of the first games using the API, check this out. It is called SpookyBall and was created by Brandon Jones (@torjiro on Twitter). Another cool example of WebGPU is the demo called “WebGPU Meatballs,” created by Brandon Jones, and can be found here.

WebGPU is an exciting development for the web, as it promises to provide a modern, efficient, and cross-platform API for creating high-performance web-based graphics and compute applications. While it is still in the early stages of development and very much experimental, it has the potential to enable a new generation of web applications that can provide a rich, immersive, and responsive experience across a wide range of devices.

© 2024 GANDOLFI LLC. All rights reserved.