feat(gpu): refine backend choices, Metal labels, and graphics options per platform

This commit is contained in:
Karim Jerbi committed 2026-10-06 16:53:38 +01:00
1 parent 1eae36e726
commit c501f755a2
3 files changed
+93 -26

No files matched your search

+47 -4
View File
@@ -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());
+4
View File
@@ -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
}
+42 -22
View File
@@ -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()
}