Emdawnwebgpu is easiest to use as a pre-built package from https://github.com/google/dawn/releases. For information on using those, and other general information, read pkg/README.md
instead.
This README discusses building the pre-packaged emdawnwebgpu_pkg
, building the in-tree Dawn samples/tests for Wasm, and using our CMake or GN build files to link either Dawn (for native) or Emdawnwebgpu (for Wasm).
Please read https://developer.chrome.com/docs/web-platform/webgpu/build-app.
First, get the Dawn code and its dependencies. See building.md.
To build the package, you‘ll build Dawn’s emdawnwebgpu_pkg
target using Emscripten. out/yourbuild/emdawnwebgpu_pkg
combines files from:
src/emdawnwebgpu
third_party/emdawnwebgpu
out/yourbuild/gen
Get an emsdk toolchain (at least Emscripten 4.0.3, which includes the necessary tools in the package release). There are two options to do this:
dawn_wasm
gclient variable (use standalone-with-wasm.gclient
as your .gclient
), and gclient sync
. This installs emsdk in //third_party/emsdk
.Set up the build directory using emcmake:
mkdir out/cmake-wasm cd out/cmake-wasm path/to/emsdk/upstream/emscripten/emcmake cmake ../.. # Package make -j8 emdawnwebgpu_pkg
Samples and tests:
# Samples (for a list of samples, see ENABLE_EMSCRIPTEN targets in src/dawn/samples/CMakeLists.txt) make -j8 HelloTriangle # Tests make -j8 emdawnwebgpu_tests_asyncify emdawnwebgpu_tests_jspi
(To use Ninja instead of Make, for better parallelism, add -GNinja
to the cmake
invocation, and build using ninja
.)
Samples and tests produce HTML files which can be served and viewed in a compatible browser.
Set up Emscripten as per instructions above using dawn_wasm
.
Build the emdawnwebgpu
and samples
GN build targets.
Samples and tests produce HTML files in out/<dir>/wasm
which can be served and viewed in a compatible browser.