forked from 1b-agent/opencadstudio-upstream
feat(gpu): refine backend choices, Metal labels, and graphics options per platform
This commit is contained in:
1 parent
1eae36e726
commit
c501f755a2
3 files changed
+93
-26
No files matched your search
+47
-4
@@ -96,9 +96,12 @@ impl BackendChoice {
|
|||||||
let mut v = vec![BackendChoice::Auto];
|
let mut v = vec![BackendChoice::Auto];
|
||||||
if cfg!(target_os = "windows") {
|
if cfg!(target_os = "windows") {
|
||||||
v.push(BackendChoice::Dx12);
|
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
|
v
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -123,7 +126,13 @@ impl BackendChoice {
|
|||||||
|
|
||||||
pub fn label(self) -> &'static str {
|
pub fn label(self) -> &'static str {
|
||||||
match self {
|
match self {
|
||||||
BackendChoice::Auto => "Automatic (recommended)",
|
BackendChoice::Auto => {
|
||||||
|
if cfg!(target_os = "macos") {
|
||||||
|
"Automatic (Metal)"
|
||||||
|
} else {
|
||||||
|
"Automatic (recommended)"
|
||||||
|
}
|
||||||
|
}
|
||||||
BackendChoice::Dx12 => "DirectX 12",
|
BackendChoice::Dx12 => "DirectX 12",
|
||||||
BackendChoice::Vulkan => "Vulkan",
|
BackendChoice::Vulkan => "Vulkan",
|
||||||
BackendChoice::Gl => "OpenGL",
|
BackendChoice::Gl => "OpenGL",
|
||||||
@@ -236,7 +245,13 @@ pub fn active_gpu_summary() -> String {
|
|||||||
Some("gl") => "OpenGL",
|
Some("gl") => "OpenGL",
|
||||||
Some("metal") => "Metal",
|
Some("metal") => "Metal",
|
||||||
Some(other) => other,
|
Some(other) => other,
|
||||||
None => "default",
|
None => {
|
||||||
|
if cfg!(target_os = "macos") {
|
||||||
|
"Metal"
|
||||||
|
} else {
|
||||||
|
"default"
|
||||||
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
match a.adapter {
|
match a.adapter {
|
||||||
Some(name) => format!("{name} ({backend})"),
|
Some(name) => format!("{name} ({backend})"),
|
||||||
@@ -1536,6 +1551,34 @@ mod tests {
|
|||||||
assert_eq!(BackendChoice::parse("garbage"), BackendChoice::Auto);
|
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]
|
#[test]
|
||||||
fn graphics_prefs_persist_and_default_when_missing() {
|
fn graphics_prefs_persist_and_default_when_missing() {
|
||||||
let _guard = SENTINEL_TESTS.lock().unwrap_or_else(|e| e.into_inner());
|
let _guard = SENTINEL_TESTS.lock().unwrap_or_else(|e| e.into_inner());
|
||||||
|
|||||||
@@ -152,6 +152,10 @@ pub(crate) fn report() -> String {
|
|||||||
prefs.legacy_gl,
|
prefs.legacy_gl,
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
#[cfg(target_arch = "wasm32")]
|
||||||
|
{
|
||||||
|
out.push_str("\n[Graphics]\nBackend: WebGPU / WebGL\n");
|
||||||
|
}
|
||||||
out
|
out
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ pub(crate) fn view(prefs: GraphicsPrefs, active: ActiveGpu) -> Element<'static,
|
|||||||
.on_select(Message::GraphicsBackendChanged)
|
.on_select(Message::GraphicsBackendChanged)
|
||||||
.width(260);
|
.width(260);
|
||||||
|
|
||||||
column![
|
let mut col = column![
|
||||||
text(crate::t!("Graphics")).size(15),
|
text(crate::t!("Graphics")).size(15),
|
||||||
Space::new().height(6),
|
Space::new().height(6),
|
||||||
text(crate::t!(
|
text(crate::t!(
|
||||||
@@ -55,7 +55,20 @@ pub(crate) fn view(prefs: GraphicsPrefs, active: ActiveGpu) -> Element<'static,
|
|||||||
Space::new().height(4),
|
Space::new().height(4),
|
||||||
current_row(
|
current_row(
|
||||||
crate::t!("Backend"),
|
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),
|
Space::new().height(4),
|
||||||
current_row(crate::t!("Selected by"), unknown(&active.origin)),
|
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)
|
.spacing(8)
|
||||||
.align_y(iced::Center),
|
.align_y(iced::Center),
|
||||||
Space::new().height(10),
|
];
|
||||||
row![
|
|
||||||
checkbox(prefs.legacy_gl)
|
if cfg!(target_os = "windows") {
|
||||||
.on_toggle(Message::GraphicsLegacyGlToggled)
|
col = col.push(Space::new().height(10)).push(
|
||||||
.size(15),
|
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!(
|
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),
|
.size(11)
|
||||||
]
|
.width(Fill),
|
||||||
.spacing(8)
|
)
|
||||||
.align_y(iced::Center),
|
.spacing(0)
|
||||||
Space::new().height(16),
|
.into()
|
||||||
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()
|
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user