From a1379bf3d86f71d26879c95166acdc87038c2896 Mon Sep 17 00:00:00 2001 From: Elias Miettinen Date: Wed, 4 Nov 2026 21:47:38 +0200 Subject: [PATCH] :D --- .github/workflows/pages.yml | 5 +++-- web/build.sh | 4 ++-- web/play.html | 17 +++++++++-------- 3 files changed, 14 insertions(+), 12 deletions(-) diff --git a/.github/workflows/pages.yml b/.github/workflows/pages.yml index 3aee907..681241d 100644 --- a/.github/workflows/pages.yml +++ b/.github/workflows/pages.yml @@ -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 diff --git a/web/build.sh b/web/build.sh index 548fada..f3dda36 100755 --- a/web/build.sh +++ b/web/build.sh @@ -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=). 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=). 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")/.." diff --git a/web/play.html b/web/play.html index c706d97..7c07fee 100644 --- a/web/play.html +++ b/web/play.html @@ -193,16 +193,17 @@

CTR-RS

// 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]; })();