This is a small test app that uses WebGPU’s
webgpu.h
header
as a platform-agnostic hardware abstraction layer.
It uses a C++ layer over webgpu.h
, called webgpu_cpp.h
.
On native platforms, this project can be built against Dawn, Chromium’s native WebGPU implementation.
On the Web, this project can be built against Emscripten, using Dawn’s “emdawnwebgpu”
implementation of webgpu.h
on top of the browser’s own WebGPU JavaScript API.
It currently hasn’t been set up to build against
wgpu-native’s webgpu.h
implementation,
but that is a goal.
Check the issues tab for known issues.
Please note the webgpu.h
API (implemented by Dawn/wgpu-native/Emscripten) and webgpu_cpp.h
bindings (from Dawn) are not yet stabilized.
Instructions are for Linux/Mac; Windows builds should work, but you need to adjust the command syntax accordingly.
This setup step is always required for native builds.
For web builds, it is only strictly needed if you need to rebuild emdawnwebgpu_pkg
(but
without it, you’ll need to build manually with your own emsdk, because build_all.sh
uses Dawn’s).
The web build has been mainly tested with Chrome Canary on Mac, but it should work on any conformant browser and supported platform.
Once you have an Emscripten SDK, you can
simply build it using emcmake
. This will use the snapshot of emdawnwebgpu
in this repository.
You can also get newer releases of emdawnwebgpu
from https://github.com/google/dawn/releases.
mkdir out/web
cd out/web
path/to/emcmake cmake ../.. -DDEMO_USE_ASYNCIFY=1 # Add other flags here as desired
make -j4
For development of emdawnwebgpu, there’s a script that will build a bunch of
different variants. To use this, set up the Dawn dependency, which regenerates
emdawnwebgpu_pkg
, and then run this script (which uses Dawn’s copy of emsdk):
./setup_build.sh --checkout=1
./build_web_many_configs.sh --parallel=0
Build has been tested on Linux/Mac/Win10 (though may be broken on some platforms).
mkdir -p out/native
cd out/native
# Using Make:
cmake ../.. # Add -DCMAKE_BUILD_TYPE=Release, -DDEMO_USE_GLFW=OFF, etc. here as desired
make clean
make -j4 all
# Or, to use Ninja instead of Make:
cmake -GNinja ../.. # Add flags here as desired
ninja
Note: If you want to have window displayed, make sure to have glfw available.
Alternatively, you can disable using glfw and window display by
cmake ../.. -DDEMO_USE_GLFW=OFF