Skip to content

[WIP] WebGPU Status

Akio Gaule edited this page Nov 12, 2024 · 7 revisions

Introduction:

This document describes the state of the WebGPU implementation in Atom. The document refers only to rendering functionality, and it doesn't contain any information about compiling or running in a browser enviroment.

There's currently an incomplete implementation of a WebGPU RHI in Atom. Most of the main features are already implemented. The main limitations comes from the usage itself, since some features are either not supported by WebGPU and some major changes would be needed in order to accommodate a workaround.

Branches

All of o3de WebGPU changes are in the https://github.com/o3de/o3de/tree/webgpu-rhi branch (there's nothing in the development branch). The current changes in the branch have been "lightly" code reviewed, so a thorough review to all changes has to be done before integrating into the main branch.

AZSLc changes are also required. All of those changes are in the https://github.com/o3de/o3de-azslc/tree/webgpu branch (no changes for WebGPU are in development).

Runtime Environment

If o3de doesn't compile or run in a browser, how are you able to test the WebGPU RHI? You have to remember that WebGPU is just a wrapper around other rendering APIs (it's actually an RHI), and luckily there's open source libraries available that implement the WebGPU functionality on C++. In our case we decided to use Google's implementation, a library called Dawn (https://dawn.googlesource.com/dawn) in order to run in platforms other than the browser. Dawn is actually the same library that is used by Chromium when running WebGPU code.

The Dawn library has 2 main parts: the runtime library and an offline shader compiler called Tint. Both components are treated as separated 3rd party.

Disclaimer: All development was done on Windows. Other platforms have not been tested (but in theory they should work).

3rd Party

At this moment, Dawn and Tint have not been added as 3rd party libraries, so local building is needed in order to run on WebGPU. To achieve this you first need to download the source code of Dawn from https://dawn.googlesource.com/dawn and follow the instructions (https://dawn.googlesource.com/dawn/+/HEAD/docs/quickstart-cmake.md) for building and installing. After installing, go to the DawnTargets.cmake file and add the GLOBAL keyword when adding the library:

add_library(dawn::dawn_public_config INTERFACE IMPORTED GLOBAL)

add_library(dawn::webgpu_dawn SHARED IMPORTED GLOBAL)

Go to the DawnTargets-release.cmake and add the DEBUG and PROFILE configurations (copy paste from the release one)

Building o3de

Since Dawn is not a 3rd party lib yet, CMake is expecting a folder where the Dawn library is. You can do this by using CMAKE_PREFIX_PATH, something like this:

cmake -B build/windows -S . -G "Visual Studio 17" -DCMAKE_PREFIX_PATH=D:\Dawn\install\Release