Loko Kung | 90fdaa8 | 2024-07-24 00:59:58 +0000 | [diff] [blame] | 1 | # Dawn Emscripten Fork |
| 2 | |
Kai Ninomiya | 1178400 | 2024-07-03 19:46:03 +0000 | [diff] [blame] | 3 | Dawn temporarily maintains a fork of the Emscripten WebGPU bindings |
| 4 | (`library_webgpu.js` and friends). The forked files live in |
| 5 | [`//third_party/emdawnwebgpu`](../third_party/emdawnwebgpu/) |
| 6 | and the build targets in this directory produce the other files needed to build |
| 7 | an Emscripten-based project using these bindings. |
| 8 | |
| 9 | This allows the the webgpu.h interface to be kept roughly in sync\* between the |
| 10 | two implementations in a single place (the Dawn repository) instead of two, |
| 11 | while also avoiding constantly breaking the version of webgpu.h that is |
| 12 | currently in Emscripten. (\* Note we don't guarantee it will always be in sync, |
| 13 | though - we don't have any automated testing for this, so we'll periodically fix |
| 14 | it up as needed for import into other projects that use these bindings.) |
| 15 | |
| 16 | Changes to this code in the Dawn repository will be synced back out to the |
| 17 | upstream Emscripten repository after webgpu.h becomes stable, in what should |
| 18 | theoretically be one big final breaking update. Between then and now, projects |
Loko Kung | 90fdaa8 | 2024-07-24 00:59:58 +0000 | [diff] [blame] | 19 | can use Dawn's fork of the bindings. |
| 20 | |
| 21 | ## Setting up Emscripten |
Kai Ninomiya | 1178400 | 2024-07-03 19:46:03 +0000 | [diff] [blame] | 22 | |
| 23 | - Get an emsdk toolchain: |
| 24 | [instructions](https://emscripten.org/docs/getting_started/downloads.html#installation-instructions-using-the-emsdk-recommended). |
| 25 | |
| 26 | - Get a separate source checkout of [Emscripten](https://github.com/emscripten-core/emscripten) |
| 27 | and set it up to point at the toolchain from emsdk by creating a file at `emscripten/.emscripten`: |
| 28 | |
| 29 | ``` |
| 30 | LLVM_ROOT = '/path/to/emsdk/upstream/bin' |
| 31 | BINARYEN_ROOT = '/path/to/emsdk/upstream' |
| 32 | NODE_JS = '/path/to/emsdk/node/18.20.3_64bit/bin/node' |
| 33 | ``` |
| 34 | |
| 35 | Note this must be a source checkout of Emscripten, |
| 36 | not emsdk's `upstream/emscripten` release, which excludes necessary tools. |
| 37 | |
dan sinclair | 0ee0afa | 2024-10-22 22:58:25 +0000 | [diff] [blame] | 38 | |
| 39 | - Make sure you run the `./bootstrap` in the `emscripten` folder to make sure node is setup. |
| 40 | |
Loko Kung | 90fdaa8 | 2024-07-24 00:59:58 +0000 | [diff] [blame] | 41 | ## Building Dawn Emscripten bindings with GN |
| 42 | |
Kai Ninomiya | 1178400 | 2024-07-03 19:46:03 +0000 | [diff] [blame] | 43 | - Set up a Dawn GN build, with `dawn_emscripten_dir` in the GN args set to point to |
| 44 | your Emscripten source checkout. |
| 45 | |
Jaswant Panchumarti | 36af762 | 2024-07-15 21:03:05 +0000 | [diff] [blame] | 46 | - Build the `emdawnwebgpu` GN build target. |
Kai Ninomiya | 1178400 | 2024-07-03 19:46:03 +0000 | [diff] [blame] | 47 | |
Jaswant Panchumarti | 36af762 | 2024-07-15 21:03:05 +0000 | [diff] [blame] | 48 | - Configure the Emscripten build with all of the linker flags listed in `emdawnwebgpu_config` |
Kai Ninomiya | 1178400 | 2024-07-03 19:46:03 +0000 | [diff] [blame] | 49 | (and without `-sUSE_WEBGPU`, because we don't want the built-in bindings). |
Loko Kung | 90fdaa8 | 2024-07-24 00:59:58 +0000 | [diff] [blame] | 50 | |
| 51 | ## Building Dawn Emscripten bindings and samples with CMake |
| 52 | |
| 53 | Set up the build directory using emcmake |
| 54 | |
| 55 | ``` |
| 56 | mkdir out/cmake-wasm |
| 57 | cd out/cmake-wasm |
| 58 | |
| 59 | # Make sure the path is to the source checkout of Emscripten, not emsdk's release. |
| 60 | emcmake cmake -GNinja -DDAWN_EMSCRIPTEN_TOOLCHAIN="path/to/emscripten" ../.. |
| 61 | |
| 62 | ninja |
| 63 | |
| 64 | # The resulting html files can then be served and viewed in a compatible Browser. |
| 65 | |
dan sinclair | 0ee0afa | 2024-10-22 22:58:25 +0000 | [diff] [blame] | 66 | ``` |