Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions .github/workflows/pages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,9 @@ jobs:
# `ring` (under iroh) compiles C for wasm32, which needs clang and llvm-ar.
- name: clang
run: sudo apt-get update && sudo apt-get install -y --no-install-recommends clang llvm
# The WebGL2 build and the WebGPU one: the page picks by what the browser has.
- run: ./web/build.sh dist both
# WebGL2 only. The WebGPU build (`web/build.sh dist both`, then `?backend=webgpu`) is left out
# until it draws dependably.
- run: ./web/build.sh dist webgl2
env:
LLVM: /usr
- uses: actions/upload-pages-artifact@v5
Expand Down
4 changes: 2 additions & 2 deletions web/build.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#!/bin/sh
# Usage: web/build.sh [release|dev|dist] [webgl2|webgpu|both], into target/web. Needs
# wasm-bindgen-cli at Cargo.lock's version, wasm-opt for dist, and an LLVM clang that targets wasm
# (brew install llvm, or LLVM=<prefix>). The page draws through WebGPU where the browser has it and
# that build was made, and through WebGL2 elsewhere; with webgpu alone, a browser without WebGPU
# (brew install llvm, or LLVM=<prefix>). The page draws through WebGL2, and through WebGPU only when
# asked (`?backend=webgpu`) or when that is the only build made; then a browser without WebGPU
# shows nothing.
set -eu
cd "$(dirname "$0")/.."
Expand Down
17 changes: 9 additions & 8 deletions web/play.html
Original file line number Diff line number Diff line change
Expand Up @@ -193,16 +193,17 @@ <h1><a href="../">CTR-RS</a></h1>
// The builds of the game here, one for each way of drawing: `web/build.sh` puts the ones it made
// in this list.
const BUILT = ["webgl2"];
// WebGPU where the browser has it (and an adapter to give), WebGL2 elsewhere.
// WebGL2, unless `?backend=webgpu` asks for the WebGPU build (or it is the only one made). WebGPU is
// opt-in for now: it has been the less dependable of the two, and WebKit's WGSL compiler (Safari,
// and every browser on iOS) holds to the spec where Chrome's and naga's do not, and rejects Bevy's
// PBR shader for its texture-typed `let`s.
const asked = new URLSearchParams(location.search).get("backend");
const backend = (async () => {
if (BUILT.includes("webgpu")) {
try {
if ((await navigator.gpu?.requestAdapter({ powerPreference: "high-performance" })) != null) {
return "webgpu";
}
} catch (e) {
console.warn(`could not ask for WebGPU: ${e}`);
if (asked != null) {
if (BUILT.includes(asked)) {
return asked;
}
console.warn(`ctr-rs: backend=${asked} asked for, but the builds here are ${BUILT.join(", ")}`);
}
return BUILT.includes("webgl2") ? "webgl2" : BUILT[0];
})();
Expand Down
Loading