From 3cf3141e8f07ce1a2c736e2cf1c4d500a6c5f7a7 Mon Sep 17 00:00:00 2001 From: Emil Ernerfeldt Date: Fri, 27 Mar 2026 11:12:46 +0100 Subject: [PATCH] `wgpu` backend: Enable WebGL fallback (#8038) * Fix for https://github.com/emilk/eframe_template/issues/223 * Related: https://github.com/gfx-rs/wgpu/pull/9319 By default, we would only turn on the WebGPU backend on web, which means browsers without WebGPU support would just crash. You can still opt-out of all the default `wgpu` features by enabling `eframe/wgpu_no_default_features` instead of `eframe/wgpu` --- Cargo.lock | 1 - crates/eframe/Cargo.toml | 3 +-- crates/eframe/src/lib.rs | 2 +- crates/egui-wgpu/Cargo.toml | 7 ++++++- crates/egui_demo_app/Cargo.toml | 5 +---- crates/egui_demo_app/src/backend_panel.rs | 2 +- 6 files changed, 10 insertions(+), 10 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 526f8dd10..d9da12ef5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1330,7 +1330,6 @@ dependencies = [ "wasm-bindgen", "wasm-bindgen-futures", "web-sys", - "wgpu", ] [[package]] diff --git a/crates/eframe/Cargo.toml b/crates/eframe/Cargo.toml index 0f08eb7f1..0530b64a8 100644 --- a/crates/eframe/Cargo.toml +++ b/crates/eframe/Cargo.toml @@ -89,7 +89,7 @@ web_screen_reader = ["web-sys/SpeechSynthesis", "web-sys/SpeechSynthesisUtteranc ## See for more details. ## ## By default, eframe will prefer WebGPU over WebGL, but -## you can configure this at run-time with [`NativeOptions::wgpu_options`]. +## you can configure this at run-time with `WebOptions::wgpu_options`. wgpu = ["wgpu_no_default_features", "egui-wgpu/default"] ## This is exactly like the `wgpu` feature, but does NOT enable the default features of `wgpu` and `egui-wgpu`. @@ -155,7 +155,6 @@ glutin-winit = { workspace = true, optional = true, default-features = false, fe "wgl", ] } home = { workspace = true, optional = true } -wgpu = { workspace = true, optional = true } # mac: [target.'cfg(any(target_os = "macos"))'.dependencies] diff --git a/crates/eframe/src/lib.rs b/crates/eframe/src/lib.rs index 86260ee5f..c644289e0 100644 --- a/crates/eframe/src/lib.rs +++ b/crates/eframe/src/lib.rs @@ -159,7 +159,7 @@ pub use {egui, egui::emath, egui::epaint}; pub use {egui_glow, glow}; #[cfg(feature = "wgpu_no_default_features")] -pub use {egui_wgpu, wgpu}; +pub use {egui_wgpu, egui_wgpu::wgpu}; mod epi; diff --git a/crates/egui-wgpu/Cargo.toml b/crates/egui-wgpu/Cargo.toml index 86cd3192b..0b081e134 100644 --- a/crates/egui-wgpu/Cargo.toml +++ b/crates/egui-wgpu/Cargo.toml @@ -25,7 +25,12 @@ all-features = true rustdoc-args = ["--generate-link-to-definition"] [features] -default = ["fragile-send-sync-non-atomic-wasm", "macos-window-resize-jitter-fix", "wgpu/default"] +default = [ + "fragile-send-sync-non-atomic-wasm", + "macos-window-resize-jitter-fix", + "wgpu/default", + "wgpu/webgl", # A very important fallback for web support +] ## Enables the `capture` module for capturing screenshots. capture = ["dep:egui"] diff --git a/crates/egui_demo_app/Cargo.toml b/crates/egui_demo_app/Cargo.toml index 49609746f..5bb093ced 100644 --- a/crates/egui_demo_app/Cargo.toml +++ b/crates/egui_demo_app/Cargo.toml @@ -37,7 +37,7 @@ serde = ["dep:serde", "egui_demo_lib/serde", "egui/serde"] syntect = ["egui_demo_lib/syntect"] glow = ["eframe/glow"] -wgpu = ["eframe/wgpu", "bytemuck", "dep:wgpu"] +wgpu = ["eframe/wgpu", "bytemuck"] wayland = ["eframe/wayland"] x11 = ["eframe/x11"] @@ -60,9 +60,6 @@ accesskit_consumer = { workspace = true, optional = true } bytemuck = { workspace = true, optional = true } puffin = { workspace = true, optional = true } puffin_http = { workspace = true, optional = true } -# Enable both WebGL & WebGPU when targeting the web (these features have no effect when not targeting wasm32) -# Also enable the default features so we have a supported backend for every platform. -wgpu = { workspace = true, features = ["default", "webgpu", "webgl"], optional = true } # feature "http": diff --git a/crates/egui_demo_app/src/backend_panel.rs b/crates/egui_demo_app/src/backend_panel.rs index dfc4d116b..cd17afd4a 100644 --- a/crates/egui_demo_app/src/backend_panel.rs +++ b/crates/egui_demo_app/src/backend_panel.rs @@ -211,7 +211,7 @@ fn integration_ui(ui: &mut egui::Ui, _frame: &mut eframe::Frame) { let wgpu_adapter_details_ui = |ui: &mut egui::Ui, adapter: &eframe::wgpu::Adapter| { let info = &adapter.get_info(); - let wgpu::AdapterInfo { + let eframe::wgpu::AdapterInfo { name, vendor, device,