WebGPU C++ Starter Project
A starter code for cross-platform (i.e., web & native) C++ WebGPU projects.
Building for Web with Emscripten
You can build the project using Emscripten's CMake wrapper. The VulkanSDK is required to provide
glslc to compile shaders to SPV. This path should be to the specific version of Vulkan you have installed, e.g.,
-DVULKAN_SDK=. On macOS you must also specify the
macOS subdirectory after the version. The Vulkan requirement may be removed in the future if SPV support is removed from WebGPU and replaced with WGSL.
mkdir emcmake-build emcmake cmake .. -DVULKAN_SDK=
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!
Building for Native with Dawn
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. Note: right now this builds against Dawn at tag:
You can then build a native application with CMake, passing the location where you build Dawn and the VulkanSDK (required to compile shaders to SPV). SDL2 is also required to provide cross-platform windowing support, on Windows you can install it via vcpkg and specify
-DCMAKE_TOOLCHAIN_FILE to find the installation.
mkdir cmake-build cmake .. -DVULKAN_SDK=
` -DDawn_DIR= ` -DCMAKE_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:
Or on Mac/Linux: