diff --git a/crates/egui-wgpu/src/lib.rs b/crates/egui-wgpu/src/lib.rs index daa2f3642f5..8f65e02ccfc 100644 --- a/crates/egui-wgpu/src/lib.rs +++ b/crates/egui-wgpu/src/lib.rs @@ -56,6 +56,9 @@ pub struct RenderState { /// Wgpu adapter used for rendering. pub adapter: Arc, + /// All the avilable adapters. + pub available_adapters: Arc<[wgpu::Adapter]>, + /// Wgpu device used for rendering, created from the adapter. pub device: Arc, @@ -83,8 +86,7 @@ impl RenderState { ) -> Result { crate::profile_scope!("RenderState::create"); // async yield give bad names using `profile_function` - #[cfg(not(target_arch = "wasm32"))] - let adapters: Vec<_> = instance.enumerate_adapters(wgpu::Backends::all()); + let available_adapters: Vec<_> = instance.enumerate_adapters(wgpu::Backends::all()); let adapter = { crate::profile_scope!("request_adapter"); @@ -97,18 +99,18 @@ impl RenderState { .await .ok_or_else(|| { #[cfg(not(target_arch = "wasm32"))] - if adapters.is_empty() { + if available_adapters.is_empty() { log::info!("No wgpu adapters found"); - } else if adapters.len() == 1 { + } else if available_adapters.len() == 1 { log::info!( "The only available wgpu adapter was not suitable: {}", - adapter_info_summary(&adapters[0].get_info()) + adapter_info_summary(&available_adapters[0].get_info()) ); } else { log::info!( "No suitable wgpu adapter found out of the {} available ones: {}", - adapters.len(), - describe_adapters(&adapters) + available_adapters.len(), + describe_adapters(&available_adapters) ); } @@ -116,14 +118,7 @@ impl RenderState { })? }; - #[cfg(target_arch = "wasm32")] - log::debug!( - "Picked wgpu adapter: {}", - adapter_info_summary(&adapter.get_info()) - ); - - #[cfg(not(target_arch = "wasm32"))] - if adapters.len() == 1 { + if available_adapters.len() == 1 { log::debug!( "Picked the only available wgpu adapter: {}", adapter_info_summary(&adapter.get_info()) @@ -131,8 +126,8 @@ impl RenderState { } else { log::info!( "There were {} available wgpu adapters: {}", - adapters.len(), - describe_adapters(&adapters) + available_adapters.len(), + describe_adapters(&available_adapters) ); log::debug!( "Picked wgpu adapter: {}", @@ -157,6 +152,7 @@ impl RenderState { Ok(Self { adapter: Arc::new(adapter), + available_adapters: available_adapters.into(), device: Arc::new(device), queue: Arc::new(queue), target_format, @@ -165,7 +161,6 @@ 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 591f5cc121f..26fa593f8f4 100644 --- a/crates/egui_demo_app/src/backend_panel.rs +++ b/crates/egui_demo_app/src/backend_panel.rs @@ -184,6 +184,102 @@ fn integration_ui(ui: &mut egui::Ui, _frame: &mut eframe::Frame) { ui.monospace(format!("{:#?}", _frame.info().web_info.location)); }); + #[cfg(feature = "glow")] + if _frame.gl().is_some() { + ui.horizontal(|ui| { + ui.label("Renderer:"); + ui.hyperlink_to("glow", "https://github.com/grovesNL/glow"); + }); + } + + #[cfg(feature = "wgpu")] + if let Some(render_state) = _frame.wgpu_render_state() { + let wgpu_adapter_details_ui = |ui: &mut egui::Ui, adapter: &eframe::wgpu::Adapter| { + let info = &adapter.get_info(); + + let wgpu::AdapterInfo { + name, + vendor, + device, + device_type, + driver, + driver_info, + backend, + } = &info; + + // Example values: + // > name: "llvmpipe (LLVM 16.0.6, 256 bits)", device_type: Cpu, backend: Vulkan, driver: "llvmpipe", driver_info: "Mesa 23.1.6-arch1.4 (LLVM 16.0.6)" + // > name: "Apple M1 Pro", device_type: IntegratedGpu, backend: Metal, driver: "", driver_info: "" + // > name: "ANGLE (Apple, Apple M1 Pro, OpenGL 4.1)", device_type: IntegratedGpu, backend: Gl, driver: "", driver_info: "" + + egui::Grid::new("adapter_info").show(ui, |ui| { + ui.label("Backend:"); + ui.label(format!("{backend:?}")); + ui.end_row(); + + ui.label("Device Type:"); + ui.label(format!("{device_type:?}")); + ui.end_row(); + + if !name.is_empty() { + ui.label("Name:"); + ui.label(format!("{name:?}")); + ui.end_row(); + } + if !driver.is_empty() { + ui.label("Driver:"); + ui.label(format!("{driver:?}")); + ui.end_row(); + } + if !driver_info.is_empty() { + ui.label("Driver info:"); + ui.label(format!("{driver_info:?}")); + ui.end_row(); + } + if *vendor != 0 { + // TODO(emilk): decode using https://github.com/gfx-rs/wgpu/blob/767ac03245ee937d3dc552edc13fe7ab0a860eec/wgpu-hal/src/auxil/mod.rs#L7 + ui.label("Vendor:"); + ui.label(format!("0x{vendor:04X}")); + ui.end_row(); + } + if *device != 0 { + ui.label("Device:"); + ui.label(format!("0x{device:02X}")); + ui.end_row(); + } + }); + }; + + let wgpu_adapter_ui = |ui: &mut egui::Ui, adapter: &eframe::wgpu::Adapter| { + let info = &adapter.get_info(); + ui.label(format!("{:?}", info.backend)).on_hover_ui(|ui| { + wgpu_adapter_details_ui(ui, adapter); + }); + }; + + egui::Grid::new("wgpu_info").num_columns(2).show(ui, |ui| { + ui.label("Renderer:"); + ui.hyperlink_to("wgpu", "https://wgpu.rs/"); + ui.end_row(); + + ui.label("Backend:"); + wgpu_adapter_ui(ui, &render_state.adapter); + ui.end_row(); + + if 1 < render_state.available_adapters.len() { + ui.label("Others:"); + ui.vertical(|ui| { + for adapter in &*render_state.available_adapters { + if adapter.get_info() != render_state.adapter.get_info() { + wgpu_adapter_ui(ui, adapter); + } + } + }); + ui.end_row(); + } + }); + } + #[cfg(not(target_arch = "wasm32"))] { ui.horizontal(|ui| {