mirror of
https://github.com/emilk/egui.git
synced 2026-08-29 04:40:03 -04:00
Make egui work on WebGPU out of the box. (#2945)
* Make wgpu webgl/gles opt-in (but still work out of the box via feature flag), workaround canvas creation issue * missing allow unsafe code annotations * add breaking change not to eframe release notes * Add --webgpu flag to build_demo_web.sh * Improve CHANGELOG docs * Clean up, and prepare for having to wasm:s * put canvas without workaround under `if false` * fix spelling --------- Co-authored-by: Emil Ernerfeldt <emil.ernerfeldt@gmail.com>
This commit is contained in:
@@ -13,23 +13,27 @@ export RUSTFLAGS=--cfg=web_sys_unstable_apis
|
||||
CRATE_NAME="egui_demo_app"
|
||||
|
||||
# NOTE: persistence use up about 400kB (10%) of the WASM!
|
||||
FEATURES="glow,http,persistence,web_screen_reader"
|
||||
FEATURES="http,persistence,web_screen_reader"
|
||||
|
||||
OPEN=false
|
||||
OPTIMIZE=false
|
||||
BUILD=debug
|
||||
BUILD_FLAGS=""
|
||||
WEB_GPU=false
|
||||
|
||||
while test $# -gt 0; do
|
||||
case "$1" in
|
||||
-h|--help)
|
||||
echo "build_demo_web.sh [--release] [--open]"
|
||||
echo "build_demo_web.sh [--release] [--webgpu] [--open]"
|
||||
echo ""
|
||||
echo " --release: Build with --release, and enable extra optimization step"
|
||||
echo " Runs wasm-opt."
|
||||
echo " NOTE: --release also removes debug symbols which are otherwise useful for in-browser profiling."
|
||||
echo ""
|
||||
echo " --open: Open the result in a browser"
|
||||
echo " --webgpu: Build a binary for WebGPU instead of WebGL"
|
||||
echo " Note that the resulting wasm will ONLY work on browsers with WebGPU."
|
||||
echo ""
|
||||
echo " --open: Open the result in a browser"
|
||||
exit 0
|
||||
;;
|
||||
|
||||
@@ -40,6 +44,11 @@ while test $# -gt 0; do
|
||||
BUILD_FLAGS="--release"
|
||||
;;
|
||||
|
||||
--webgpu)
|
||||
shift
|
||||
WEB_GPU=true
|
||||
;;
|
||||
|
||||
--open)
|
||||
shift
|
||||
OPEN=true
|
||||
@@ -51,8 +60,18 @@ while test $# -gt 0; do
|
||||
esac
|
||||
done
|
||||
|
||||
OUT_FILE_NAME="egui_demo_app"
|
||||
|
||||
if [[ "${WEB_GPU}" == true ]]; then
|
||||
FEATURES="${FEATURES},wgpu"
|
||||
else
|
||||
FEATURES="${FEATURES},glow"
|
||||
fi
|
||||
|
||||
FINAL_WASM_PATH=docs/${OUT_FILE_NAME}_bg.wasm
|
||||
|
||||
# Clear output from old stuff:
|
||||
rm -f "docs/${CRATE_NAME}_bg.wasm"
|
||||
rm -f "${FINAL_WASM_PATH}"
|
||||
|
||||
echo "Building rust…"
|
||||
|
||||
@@ -71,22 +90,22 @@ TARGET=`cargo metadata --format-version=1 | jq --raw-output .target_directory`
|
||||
echo "Generating JS bindings for wasm…"
|
||||
TARGET_NAME="${CRATE_NAME}.wasm"
|
||||
WASM_PATH="${TARGET}/wasm32-unknown-unknown/$BUILD/$TARGET_NAME"
|
||||
wasm-bindgen "${WASM_PATH}" --out-dir docs --no-modules --no-typescript
|
||||
wasm-bindgen "${WASM_PATH}" --out-dir docs --out-name ${OUT_FILE_NAME} --no-modules --no-typescript
|
||||
|
||||
# if this fails with "error: cannot import from modules (`env`) with `--no-modules`", you can use:
|
||||
# wasm2wat target/wasm32-unknown-unknown/release/egui_demo_app.wasm | rg env
|
||||
# wasm2wat target/wasm32-unknown-unknown/release/egui_demo_app.wasm | rg "call .now\b" -B 20 # What calls `$now` (often a culprit)
|
||||
|
||||
# to get wasm-strip: apt/brew/dnf install wabt
|
||||
# wasm-strip docs/${CRATE_NAME}_bg.wasm
|
||||
# wasm-strip ${FINAL_WASM_PATH}
|
||||
|
||||
if [[ "${OPTIMIZE}" = true ]]; then
|
||||
echo "Optimizing wasm…"
|
||||
# to get wasm-opt: apt/brew/dnf install binaryen
|
||||
wasm-opt "docs/${CRATE_NAME}_bg.wasm" -O2 --fast-math -o "docs/${CRATE_NAME}_bg.wasm" # add -g to get debug symbols
|
||||
wasm-opt "${FINAL_WASM_PATH}" -O2 --fast-math -o "${FINAL_WASM_PATH}" # add -g to get debug symbols
|
||||
fi
|
||||
|
||||
echo "Finished docs/${CRATE_NAME}_bg.wasm"
|
||||
echo "Finished ${FINAL_WASM_PATH}"
|
||||
|
||||
if [[ "${OPEN}" == true ]]; then
|
||||
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
|
||||
|
||||
Reference in New Issue
Block a user