From c501f755a2cb80113a89c6e2aadef94991f7c0e8 Mon Sep 17 00:00:00 2001 From: Karim Jerbi Date: Tue, 6 Oct 2026 13:34:19 +0100 Subject: [PATCH] feat(gpu): refine backend choices, Metal labels, and graphics options per platform --- src/gpu_backend.rs | 51 ++++++++++++++++++++++-- src/ui/window/about.rs | 4 ++ src/ui/window/options/graphics.rs | 64 ++++++++++++++++++++----------- 3 files changed, 93 insertions(+), 26 deletions(-) diff --git a/src/gpu_backend.rs b/src/gpu_backend.rs index bac15d63e..09fcd4236 100644 --- a/src/gpu_backend.rs +++ b/src/gpu_backend.rs @@ -96,9 +96,12 @@ impl BackendChoice { let mut v = vec![BackendChoice::Auto]; if cfg!(target_os = "windows") { v.push(BackendChoice::Dx12); + v.push(BackendChoice::Vulkan); + v.push(BackendChoice::Gl); + } else if cfg!(target_os = "linux") { + v.push(BackendChoice::Vulkan); + v.push(BackendChoice::Gl); } - v.push(BackendChoice::Vulkan); - v.push(BackendChoice::Gl); v } @@ -123,7 +126,13 @@ impl BackendChoice { pub fn label(self) -> &'static str { match self { - BackendChoice::Auto => "Automatic (recommended)", + BackendChoice::Auto => { + if cfg!(target_os = "macos") { + "Automatic (Metal)" + } else { + "Automatic (recommended)" + } + } BackendChoice::Dx12 => "DirectX 12", BackendChoice::Vulkan => "Vulkan", BackendChoice::Gl => "OpenGL", @@ -236,7 +245,13 @@ pub fn active_gpu_summary() -> String { Some("gl") => "OpenGL", Some("metal") => "Metal", Some(other) => other, - None => "default", + None => { + if cfg!(target_os = "macos") { + "Metal" + } else { + "default" + } + } }; match a.adapter { Some(name) => format!("{name} ({backend})"), @@ -1536,6 +1551,34 @@ mod tests { assert_eq!(BackendChoice::parse("garbage"), BackendChoice::Auto); } + #[test] + fn backend_choices_match_target_os() { + let choices = BackendChoice::available(); + assert!(choices.contains(&BackendChoice::Auto)); + if cfg!(target_os = "windows") { + assert_eq!( + choices, + vec![ + BackendChoice::Auto, + BackendChoice::Dx12, + BackendChoice::Vulkan, + BackendChoice::Gl, + ] + ); + } else if cfg!(target_os = "linux") { + assert_eq!( + choices, + vec![ + BackendChoice::Auto, + BackendChoice::Vulkan, + BackendChoice::Gl, + ] + ); + } else if cfg!(target_os = "macos") { + assert_eq!(choices, vec![BackendChoice::Auto]); + } + } + #[test] fn graphics_prefs_persist_and_default_when_missing() { let _guard = SENTINEL_TESTS.lock().unwrap_or_else(|e| e.into_inner()); diff --git a/src/ui/window/about.rs b/src/ui/window/about.rs index 3d326563a..089840905 100644 --- a/src/ui/window/about.rs +++ b/src/ui/window/about.rs @@ -152,6 +152,10 @@ pub(crate) fn report() -> String { prefs.legacy_gl, )); } + #[cfg(target_arch = "wasm32")] + { + out.push_str("\n[Graphics]\nBackend: WebGPU / WebGL\n"); + } out } diff --git a/src/ui/window/options/graphics.rs b/src/ui/window/options/graphics.rs index a1f722a2d..b3894d826 100644 --- a/src/ui/window/options/graphics.rs +++ b/src/ui/window/options/graphics.rs @@ -35,7 +35,7 @@ pub(crate) fn view(prefs: GraphicsPrefs, active: ActiveGpu) -> Element<'static, .on_select(Message::GraphicsBackendChanged) .width(260); - column![ + let mut col = column![ text(crate::t!("Graphics")).size(15), Space::new().height(6), text(crate::t!( @@ -55,7 +55,20 @@ pub(crate) fn view(prefs: GraphicsPrefs, active: ActiveGpu) -> Element<'static, Space::new().height(4), current_row( crate::t!("Backend"), - unknown(active.backend.as_deref().unwrap_or("")) + match active.backend.as_deref() { + Some("dx12") => "DirectX 12".to_string(), + Some("vulkan") => "Vulkan".to_string(), + Some("gl") => "OpenGL".to_string(), + Some("metal") => "Metal".to_string(), + Some(other) => other.to_string(), + None => { + if cfg!(target_os = "macos") { + "Metal".to_string() + } else { + unknown("") + } + } + }, ), Space::new().height(4), current_row(crate::t!("Selected by"), unknown(&active.origin)), @@ -77,26 +90,33 @@ pub(crate) fn view(prefs: GraphicsPrefs, active: ActiveGpu) -> Element<'static, ] .spacing(8) .align_y(iced::Center), - Space::new().height(10), - row![ - checkbox(prefs.legacy_gl) - .on_toggle(Message::GraphicsLegacyGlToggled) - .size(15), + ]; + + if cfg!(target_os = "windows") { + col = col.push(Space::new().height(10)).push( + row![ + checkbox(prefs.legacy_gl) + .on_toggle(Message::GraphicsLegacyGlToggled) + .size(15), + text(crate::t!( + "Prefer OpenGL on older GPUs (automatic backend only)" + )) + .size(12), + ] + .spacing(8) + .align_y(iced::Center), + ); + } + + col.push(Space::new().height(16)) + .push( text(crate::t!( - "Prefer OpenGL on older GPUs (Windows, automatic backend only)" + "If a pinned backend fails to start, the next launch falls back to automatic selection. \ + The --backend option and the WGPU_BACKEND variable override this page." )) - .size(12), - ] - .spacing(8) - .align_y(iced::Center), - Space::new().height(16), - text(crate::t!( - "If a pinned backend fails to start, the next launch falls back to automatic selection. \ - The --backend option and the WGPU_BACKEND variable override this page." - )) - .size(11) - .width(Fill), - ] - .spacing(0) - .into() + .size(11) + .width(Fill), + ) + .spacing(0) + .into() }