From 7e66aa502ea5f399139cd80044a410ca5eaa4ca7 Mon Sep 17 00:00:00 2001 From: Emil Ernerfeldt Date: Thu, 18 Jan 2024 16:40:30 +0100 Subject: [PATCH] We cannot list available adapters on web --- crates/egui-wgpu/src/lib.rs | 17 ++++++++++++++++- crates/egui_demo_app/src/backend_panel.rs | 1 + 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/crates/egui-wgpu/src/lib.rs b/crates/egui-wgpu/src/lib.rs index 95b44bc01cf..8aafc06b0a0 100644 --- a/crates/egui-wgpu/src/lib.rs +++ b/crates/egui-wgpu/src/lib.rs @@ -57,6 +57,10 @@ pub struct RenderState { pub adapter: Arc, /// All the available adapters. + /// + /// This is not availabler on web. + /// On web, we always select WebGPU is available, then fall back to WebGL if not. + #[cfg(not(target_arch = "wasm32"))] pub available_adapters: Arc<[wgpu::Adapter]>, /// Wgpu device used for rendering, created from the adapter. @@ -86,7 +90,9 @@ impl RenderState { ) -> Result { crate::profile_scope!("RenderState::create"); // async yield give bad names using `profile_function` - let available_adapters: Vec<_> = instance.enumerate_adapters(wgpu::Backends::all()); + // This is always an empty list on web. + #[cfg(not(target_arch = "wasm32"))] + let available_adapters = instance.enumerate_adapters(wgpu::Backends::all()); let adapter = { crate::profile_scope!("request_adapter"); @@ -118,6 +124,13 @@ impl RenderState { })? }; + #[cfg(target_arch = "wasm32")] + log::debug!( + "Picked wgpu adapter: {}", + adapter_info_summary(&adapter.get_info()) + ); + + #[cfg(not(target_arch = "wasm32"))] if available_adapters.len() == 1 { log::debug!( "Picked the only available wgpu adapter: {}", @@ -152,6 +165,7 @@ impl RenderState { Ok(Self { adapter: Arc::new(adapter), + #[cfg(not(target_arch = "wasm32"))] available_adapters: available_adapters.into(), device: Arc::new(device), queue: Arc::new(queue), @@ -161,6 +175,7 @@ impl RenderState { } } +#[cfg(not(target_arch = "wasm32"))] fn describe_adapters(adapters: &[wgpu::Adapter]) -> String { if adapters.is_empty() { "(none)".to_owned() diff --git a/crates/egui_demo_app/src/backend_panel.rs b/crates/egui_demo_app/src/backend_panel.rs index e8aebe7287c..2e2f0f0a71c 100644 --- a/crates/egui_demo_app/src/backend_panel.rs +++ b/crates/egui_demo_app/src/backend_panel.rs @@ -266,6 +266,7 @@ fn integration_ui(ui: &mut egui::Ui, _frame: &mut eframe::Frame) { wgpu_adapter_ui(ui, &render_state.adapter); ui.end_row(); + #[cfg(not(target_arch = "wasm32"))] if 1 < render_state.available_adapters.len() { ui.label("Others:"); ui.vertical(|ui| {