[experimental] Add WebGPU demo (built with Bazel)
This uses the Bazel rule wasm_cc_binary, which is defined
in @emsdk [1]
Note that wasm_cc_binary does not have a linkopts argument
defined, so we instead put any emcc options in the cc_binary
target.
This works around a few bugs in the emsdk Bazel rules:
- https://github.com/emscripten-core/emsdk/issues/907
- https://github.com/emscripten-core/emsdk/issues/807
Prior to PS 5, this CL tried a different way to bring in
the toolchain, a more manual way outlined in [2].
A similar approach (modifying the .bazelrc and specifying
the toolchain directly) might be necessary at some point,
but can probably still be done using the @emsdk Bazel rules
and --config=wasm.
To update the version of emscripten used, we just need to
update the parameter in the WORKSPACE call to emsdk_emscripten_deps().
The example/index.html file in this CL does exactly the same
as [3], except the WebGPU calls are made from C++ via WASM.
I made heavy use of these examples [4], [5] while exploring
APIs. What was also useful was looking at the emscripten
source headers [6], [7], [8], [9].
I also learned a lot about WebGPU from [10].
[1] https://github.com/emscripten-core/emsdk/blob/3891e7b04bf8cbb3bc62758e9c575ae096a9a518/bazel/emscripten_toolchain/wasm_cc_binary.bzl
[2] https://hackernoon.com/c-to-webassembly-using-bazel-and-emscripten-4him3ymc
[3] https://github.com/google/skia/blob/206c1f3f7e01b6d7fd2d3aab13ed719ff39d02e4/demos.skia.org/demos/webgpu/index.html
[4] https://github.com/kainino0x/webgpu-cross-platform-demo
[5] https://github.com/Twinklebear/wgpu-cpp-starter
[6] https://github.com/emscripten-core/emscripten/blob/5e6c74153b85fdb3ee3bf1f339d620f4e7ddf705/system/include/emscripten/html5_webgpu.h
[7] https://github.com/emscripten-core/emscripten/blob/5e6c74153b85fdb3ee3bf1f339d620f4e7ddf705/system/include/webgpu/webgpu.h
[8] https://github.com/emscripten-core/emscripten/blob/5e6c74153b85fdb3ee3bf1f339d620f4e7ddf705/system/include/webgpu/webgpu_cpp.h
[9] https://github.com/emscripten-core/emscripten/blob/5e6c74153b85fdb3ee3bf1f339d620f4e7ddf705/src/library_html5_webgpu.js#L24
[10] https://alain.xyz/blog/raw-webgpu
Change-Id: Iff33b72e7265200b2caacbc03e5fcc06a650b56b
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/457396
Reviewed-by: Leandro Lovisolo <lovisolo@google.com>
Reviewed-by: Brian Salomon <bsalomon@google.com>
2021-10-11 18:56:49 +00:00
|
|
|
release:
|
|
|
|
bazel build //src:hello-world-wasm --compilation_mode opt
|
|
|
|
- rm -rf build/
|
|
|
|
mkdir build
|
|
|
|
cp bazel-bin/src/hello-world-wasm/hello-world.js build/hello-world.js
|
|
|
|
cp bazel-bin/src/hello-world-wasm/hello-world.wasm build/hello-world.wasm
|
|
|
|
|
|
|
|
debug:
|
|
|
|
bazel build //src:hello-world-wasm --compilation_mode dbg
|
|
|
|
- rm -rf build/
|
|
|
|
mkdir build
|
|
|
|
cp bazel-bin/src/hello-world-wasm/hello-world.js build/hello-world.js
|
|
|
|
cp bazel-bin/src/hello-world-wasm/hello-world.wasm build/hello-world.wasm
|
|
|
|
|
|
|
|
serve:
|
|
|
|
python3 ../../tools/serve_wasm.py
|