Skip to content

PhotoCraft: An open-source, photo editor written by scratch in pure Rust

Address review: adapter override process, wasm build, saved-name warning

Ernie Smith0b6480cdc5d6
diff --git a/apps/photocraft/src/gpu_startup.rs b/apps/photocraft/src/gpu_startup.rs
index a709e9967..411708c8f 100644
--- a/apps/photocraft/src/gpu_startup.rs
+++ b/apps/photocraft/src/gpu_startup.rs
@@ -279,9 +279,7 @@ pub fn pick(adapters: &[Candidate], backend: GpuBackend, os: Os) -> Option<usize
/// piece of its name ("nvidia"), or several words that each appear in it ("arc a370m" finds
/// "Intel(R) Arc(tm) A370M Graphics"). An empty `wanted` matches nothing.
pub fn adapter_matches(name: &str, wanted: &str) -> bool {
- let name = name.to_lowercase();
- let mut words = wanted.split_whitespace().peekable();
- words.peek().is_some() && words.all(|w| name.contains(&w.to_lowercase()))
+ photocraft_engine::prefs::gpu_adapter_matches(name, wanted)
}
/// The user asked for an adapter and none of `adapters` that can present is it.
diff --git a/apps/photocraft/src/main.rs b/apps/photocraft/src/main.rs
index befff8302..1c06e2389 100644
--- a/apps/photocraft/src/main.rs
+++ b/apps/photocraft/src/main.rs
@@ -496,7 +496,7 @@ fn main() -> eframe::Result {
unreadable_paths,
safe_gpu,
new_instance,
- launch_options,
+ mut launch_options,
present_mode_arg,
frame_latency_arg,
stroke_trace_arg,
@@ -516,6 +516,10 @@ fn main() -> eframe::Result {
}
}
+ // An adapter named in the environment is chosen at startup, which a forwarded launch never reaches.
+ if std::env::var("PHOTOCRAFT_GPU_ADAPTER").is_ok_and(|v| !v.trim().is_empty()) {
+ launch_options.push("PHOTOCRAFT_GPU_ADAPTER");
+ }
// One PhotoCraft per user (#3708): files opened from Explorer or a file manager while it runs
// become tabs in its window. Only with the per-user settings folder (a portable copy's may be
// shared between users), and not for automation, `--new-instance` or per-process options.
diff --git a/crates/engine/src/prefs.rs b/crates/engine/src/prefs.rs
index eed66a324..375fb9cea 100644
--- a/crates/engine/src/prefs.rs
+++ b/crates/engine/src/prefs.rs
@@ -1067,6 +1067,15 @@ pub fn is_hidden(path: &str) -> bool {
/// still load, save and round-trip on every platform.
pub const LINUX_ONLY: &[&str] = &["performance.linuxDisplayServer", "performance.gpuAdapter"];
+/// Whether a graphics adapter called `name` is the one `performance.gpuAdapter` (`wanted`) asks
+/// for: every whitespace-separated word of `wanted` appears in the name, ignoring case ("nvidia",
+/// "arc a370m"). An empty `wanted` matches nothing. Startup and Preferences share this.
+pub fn gpu_adapter_matches(name: &str, wanted: &str) -> bool {
+ let name = name.to_lowercase();
+ let mut words = wanted.split_whitespace().peekable();
+ words.peek().is_some() && words.all(|w| name.contains(&w.to_lowercase()))
+}
+
/// Choices of an enumerated preference (dotted path, e.g. `"cursors.painting"`).
pub fn choices(path: &str) -> Option<&'static [&'static str]> {
Some(match path {
diff --git a/crates/engine/src/prefs/tests.rs b/crates/engine/src/prefs/tests.rs
index bbb9df4ff..c5970adb1 100644
--- a/crates/engine/src/prefs/tests.rs
+++ b/crates/engine/src/prefs/tests.rs
@@ -509,6 +509,16 @@ fn gpu_adapter_round_trips_and_defaults_to_automatic() {
assert_eq!(u.prefs().performance.gpu_adapter, "");
}
+#[test]
+fn gpu_adapter_names_match_by_word_ignoring_case() {
+ let arc = "Intel(R) Arc(tm) A370M Graphics (DG2)";
+ assert!(gpu_adapter_matches("NVIDIA GeForce RTX 5060 Ti", "nvidia"));
+ assert!(gpu_adapter_matches(arc, " ARC A370M "));
+ assert!(!gpu_adapter_matches(arc, "arc a380"));
+ assert!(!gpu_adapter_matches(arc, ""));
+ assert!(!gpu_adapter_matches(arc, " "));
+}
+
#[test]
fn gpu_backend_round_trips_and_validates() {
let mut s = session();
diff --git a/crates/ui-egui/src/lib.rs b/crates/ui-egui/src/lib.rs
index 5634dfa72..52c640815 100644
--- a/crates/ui-egui/src/lib.rs
+++ b/crates/ui-egui/src/lib.rs
@@ -1013,6 +1013,8 @@ impl PhotocraftApp {
let tile = self.session.prefs().performance.cache_tile_size;
// Escaped driver/setup panics must leave the session and CPU canvas alive.
self.perf.gpu_info.set_adapter(&rs.adapter.get_info());
+ // The browser has no adapter list (egui-wgpu only has it natively).
+ #[cfg(not(target_arch = "wasm32"))]
self.perf.gpu_info.set_available(&rs.available_adapters);
let gpu = match std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| gpu_canvas::GpuCanvas::with_tile(&rs, Some(tile)))) {
Ok(gpu) => gpu,
diff --git a/crates/ui-egui/src/prefs_ui.rs b/crates/ui-egui/src/prefs_ui.rs
index 1b5908326..9a57a4127 100644
--- a/crates/ui-egui/src/prefs_ui.rs
+++ b/crates/ui-egui/src/prefs_ui.rs
@@ -1344,8 +1344,11 @@ fn gpu_status_rows(ui: &mut egui::Ui, info: Option<&Value>, adapters: Option<&Va
fn graphics_adapter_row(ui: &mut egui::Ui, adapters: Option<&Value>, obj: &mut Map<String, Value>) {
let mut current = obj.get("gpuAdapter").and_then(Value::as_str).unwrap_or("").to_string();
let mut names: Vec<String> = adapters.and_then(Value::as_array).into_iter().flatten().filter_map(Value::as_str).map(str::to_string).collect();
- let missing = !current.is_empty() && !names.contains(&current);
- if missing {
+ // A saved name fragment ("nvidia") isn't an adapter's full name but still selects one; only a
+ // value no listed adapter matches is marked.
+ let kept = !current.is_empty() && !names.contains(&current);
+ let missing = kept && !names.iter().any(|n| prefs::gpu_adapter_matches(n, &current));
+ if kept {
names.push(current.clone());
}
let automatic = tl!("Automatic");