See my updated template repo: https://github.com/Twinklebear/webgpu-cpp-wasm which builds native + wasm SDL2 + WebGPU apps.
A starter code for cross-platform (i.e., web & native) C++ WebGPU projects.
You can build the project using Emscripten's CMake wrapper.
mkdir emcmake-build
emcmake cmake ..
cmake --build .
You can then run a webserver in the build directory and view the application in a browser that supports WebGPU.
python3 -m http.server
# navigate to localhost:8000 to see the triangle!
The application uses Dawn to provide an implementation of WebGPU for native platforms. Carl Woffenden has a good guide about building Dawn which you can follow to build Dawn.
mkdir cmake-build
cmake .. -DDawn_DIR=<path to Dawn build output> `
-DCMAKE_TOOLCHAIN_FILE=<vcpkg toolchain file>
cmake --build .
If on Windows copy over the dll's in Dawn's build directory, and you can then run the native app. On Mac or Linux, the dylibs/sos just need to be in the path of the executable.
Then on Windows you can run:
./<build config>/wgpu-starter.exe
Or on Mac/Linux:
./wgpu-starter