shrekshao / webgpu-cross-platform-demo

Barebones demo of WebGPU cross-platform (web/native) via CMake/Emscripten

Home Page:https://kai.graphics/webgpu-cross-platform-demo/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

This is a small test app that uses WebGPU's unofficial 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, which implements webgpu.h on top of the browser's own WebGPU JavaScript API (if enabled). 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.

Open pre-installed VSCode in Browser

Open in Gitpod

Building

Instructions are for Linux/Mac; they will need to be adapted to work on Windows.

Native build

Build has only been tested on Linux/Mac.

./setup_native_build.sh
mkdir -p out/native
cd out/native

Then:

cmake ../..
make -j4 clean all

Or, to use Ninja instead of Make:

cmake -GNinja ../..
ninja

Note: If you want to have window displayed, make sure to have glfw available. e.g. to install on Linux/Ubuntu:

apt-get install libglfw3-dev

Or on macOS:

brew install glfw

Alternatively, you can disable using glfw and window display by

cmake ../.. -DDEMO_USE_GLFW=OFF

Web build

This has been mainly tested with Chrome Canary on Mac, but should work on Chrome/Edge/Firefox on any platform with support (modulo compatibility differences due to pre-release spec changes). Requires chrome://flags/#enable-unsafe-webgpu on Chrome/Edge.

Note: To build, the active Emscripten version must be at least 2.0.0.

# Make sure Emscripten tools are in the path.
pushd path/to/emsdk
source emsdk_env.sh
popd

mkdir -p out/web
cd out/web

Then:

emcmake cmake ../..
make -j4 clean all

Or, to use Ninja instead of Make:

emcmake cmake -GNinja ../..
ninja

There are shorthands for these in package.json so you can use, for example, npm run ninja-web.

About

Barebones demo of WebGPU cross-platform (web/native) via CMake/Emscripten

https://kai.graphics/webgpu-cross-platform-demo/


Languages

Language:JavaScript 48.0%Language:HTML 40.5%Language:C++ 9.6%Language:CMake 0.9%Language:C 0.6%Language:Objective-C++ 0.3%Language:Shell 0.1%