PhotoCraft: An open-source, photo editor written by scratch in pure Rust
Choose the graphics adapter on multi-GPU Linux machines (#1885)
Ernie Smithb892c0412e2e
diff --git a/apps/photocraft/src/gpu_startup.rs b/apps/photocraft/src/gpu_startup.rsindex e79b4bafa..a709e9967 100644--- a/apps/photocraft/src/gpu_startup.rs+++ b/apps/photocraft/src/gpu_startup.rs@@ -228,6 +228,8 @@ pub struct Candidate {pub backend: wgpu::Backend,/// Can present to the window.pub surface_ok: bool,+ /// Its name matches the adapter the user asked for ([`adapter_matches`]).+ pub wanted: bool,}/// Rank of an adapter (lower is better): high-performance device types first (egui's power@@ -259,9 +261,38 @@ fn rank(a: &Candidate, backend: GpuBackend, os: Os) -> (u8, u8, u8) {(fallback, ty, be)}-/// The adapter to use among `adapters` (`None` when there is none).+/// The adapter to use among `adapters` (`None` when there is none). Adapters the user asked for+/// win over the rest when any of them can present; otherwise the ranking decides (see+/// [`wanted_missed`]).pub fn pick(adapters: &[Candidate], backend: GpuBackend, os: Os) -> Option<usize> {- adapters.iter().enumerate().filter(|(_, a)| a.surface_ok).min_by_key(|(i, a)| (rank(a, backend, os), *i)).map(|(i, _)| i)+ let usable = |a: &&Candidate| a.surface_ok;+ let any_wanted = adapters.iter().filter(usable).any(|a| a.wanted);+ adapters+ .iter()+ .enumerate()+ .filter(|(_, a)| a.surface_ok && (a.wanted || !any_wanted))+ .min_by_key(|(i, a)| (rank(a, backend, os), *i))+ .map(|(i, _)| i)+}++/// Whether an adapter called `name` is the one the user asked for: `wanted` is a case-insensitive+/// 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()))+}++/// The user asked for an adapter and none of `adapters` that can present is it.+pub fn wanted_missed(adapters: &[Candidate], wanted: Option<&str>) -> bool {+ wanted.is_some() && !adapters.iter().any(|a| a.surface_ok && a.wanted)+}++/// The adapter to ask for: `PHOTOCRAFT_GPU_ADAPTER` when set (for one launch), else+/// `performance.gpuAdapter`; `None` is automatic.+pub fn wanted_adapter(env: Option<&str>, pref: &str) -> Option<String> {+ [env.unwrap_or(""), pref].iter().map(|s| s.trim()).find(|s| !s.is_empty()).map(str::to_string)}/// Whether picking `chosen` applied the Intel-on-Windows DX12 default (a Vulkan adapter of the@@ -285,7 +316,7 @@ fn skips_indirect_validation(os: Os, intel: bool) -> bool {/// Configure eframe's wgpu setup for `plan`: instance backends, the DX12 shader compiler, adapter/// selection (Intel on Windows, software adapters for `cpu`) and the marker update once the/// adapter is chosen. `note` receives a remark for System Info (e.g. the Intel default).-pub fn configure(setup: &mut egui_wgpu::WgpuSetup, plan: &Plan, os: Os, sentinel: SharedSentinel, note: Arc<Mutex<Option<String>>>) {+pub fn configure(setup: &mut egui_wgpu::WgpuSetup, plan: &Plan, os: Os, wanted: Option<String>, sentinel: SharedSentinel, note: Arc<Mutex<Option<String>>>) {if let egui_wgpu::WgpuSetup::CreateNew(create) = setup {if let Some(b) = backends(plan, os) {create.instance_descriptor.backends = b;@@ -298,7 +329,9 @@ pub fn configure(setup: &mut egui_wgpu::WgpuSetup, plan: &Plan, os: Os, sentinellet env = std::env::var("WGPU_DX12_COMPILER").ok();create.instance_descriptor.backend_options.dx12.shader_compiler = dx12_compiler(env.as_deref(), exe.as_deref().and_then(Path::parent));}- let select = plan.env.is_none() && (plan.backend == GpuBackend::Cpu || (plan.backend == GpuBackend::Auto && os == Os::Windows));+ // CPU mode wants a software adapter, whatever the preference says.+ let wanted = wanted.filter(|_| plan.backend != GpuBackend::Cpu);+ let select = wanted.is_some() || (plan.env.is_none() && (plan.backend == GpuBackend::Cpu || (plan.backend == GpuBackend::Auto && os == Os::Windows)));if select {let backend = plan.backend;create.native_adapter_selector = Some(Arc::new(move |adapters: &[wgpu::Adapter], surface: Option<&wgpu::Surface<'_>>| {@@ -311,10 +344,15 @@ pub fn configure(setup: &mut egui_wgpu::WgpuSetup, plan: &Plan, os: Os, sentineldevice_type: i.device_type,backend: i.backend,surface_ok: surface.is_none_or(|s| a.is_surface_supported(s)),+ wanted: wanted.as_deref().is_some_and(|w| adapter_matches(&i.name, w)),}}).collect();let i = pick(&cands, backend, os).ok_or_else(|| "no graphics adapter found".to_string())?;+ if let Some(w) = wanted.as_deref().filter(|_| wanted_missed(&cands, wanted.as_deref())) {+ *note.lock().unwrap_or_else(PoisonError::into_inner) =+ Some(format!("No graphics adapter named \"{w}\" can draw the window; using the automatic choice"));+ }if backend == GpuBackend::Cpu && cands.get(i).is_some_and(|c| c.device_type != wgpu::DeviceType::Cpu) {*note.lock().unwrap_or_else(PoisonError::into_inner) =Some("CPU image rendering; no software graphics adapter is available, so the window uses hardware graphics".into());@@ -443,6 +481,13 @@ pub fn read_display_server(path: Option<&Path>) -> photocraft_engine::prefs::Lin.unwrap_or_default()}+/// Preferences › Performance › Graphics Adapter (`performance.gpuAdapter`), read before the window+/// opens; empty (automatic) when the file or value is missing.+pub fn read_gpu_adapter(path: Option<&Path>) -> String {+ let v: Value = path.and_then(|p| std::fs::read_to_string(p).ok()).and_then(|t| serde_json::from_str(&t).ok()).unwrap_or(Value::Null);+ v.get("performance").and_then(|p| p.get("gpuAdapter")).and_then(Value::as_str).unwrap_or("").chars().take(256).collect()+}+/// Preferences › Performance › Low-Latency Drawing (`performance.lowLatencyDrawing`, off unless/// turned on), read before the window opens: it picks the surface's present mode.pub fn read_low_latency(path: Option<&Path>) -> bool {@@ -604,7 +649,60 @@ mod tests {}fn cand(vendor: u32, device_type: wgpu::DeviceType, backend: wgpu::Backend) -> Candidate {- Candidate { vendor, device_type, backend, surface_ok: true }+ Candidate { vendor, device_type, backend, surface_ok: true, wanted: false }+ }++ #[test]+ fn a_requested_adapter_beats_the_automatic_ranking() {+ use wgpu::{Backend as B, DeviceType as T};+ // The order Vulkan lists this machine's GPUs in: iGPU, dGPU, eGPU.+ let mut a = [cand(INTEL, T::IntegratedGpu, B::Vulkan), cand(INTEL, T::DiscreteGpu, B::Vulkan), cand(0x10de, T::DiscreteGpu, B::Vulkan)];+ assert_eq!(pick(&a, Auto, Os::Other), Some(1), "automatic takes the first discrete adapter, the Arc");+ a[2].wanted = true;+ assert_eq!(pick(&a, Auto, Os::Other), Some(2));+ a[2].wanted = false;+ a[0].wanted = true;+ assert_eq!(pick(&a, Auto, Os::Other), Some(0), "even the iGPU, when asked for");+ // A wanted adapter that can't present is skipped, not an error.+ a[0].surface_ok = false;+ assert_eq!(pick(&a, Auto, Os::Other), Some(1));+ assert!(wanted_missed(&a, Some("iris")));+ assert!(!wanted_missed(&a, None));+ a[0].surface_ok = true;+ assert!(!wanted_missed(&a, Some("iris")));+ // Among several wanted ones (same GPU on Vulkan and GL) the usual ranking decides.+ let mut gl = [cand(0x10de, T::DiscreteGpu, B::Gl), cand(0x10de, T::DiscreteGpu, B::Vulkan)];+ gl.iter_mut().for_each(|c| c.wanted = true);+ assert_eq!(pick(&gl, Auto, Os::Other), Some(1));+ }++ #[test]+ fn adapter_names_match_loosely_and_the_environment_wins() {+ assert!(adapter_matches("NVIDIA GeForce RTX 5060 Ti", "nvidia"));+ assert!(adapter_matches("Intel(R) Arc(tm) A370M Graphics (DG2)", " ARC A370M "));+ assert!(!adapter_matches("Intel(R) Iris(R) Xe Graphics (ADL GT2)", "arc"));+ assert!(!adapter_matches("anything", ""));+ assert!(!adapter_matches("anything", " "));+ assert_eq!(wanted_adapter(None, ""), None);+ assert_eq!(wanted_adapter(Some(" "), "iris"), Some("iris".into()));+ assert_eq!(wanted_adapter(Some("nvidia"), "iris"), Some("nvidia".into()));+ }++ #[test]+ fn gpu_adapter_is_read_before_the_window_opens() {+ let dir = std::env::temp_dir().join(format!("photocraft-gpu-adapter-{}", std::process::id()));+ std::fs::create_dir_all(&dir).unwrap();+ let file = dir.join("preferences.json");+ let read = |json: &str| {+ std::fs::write(&file, json).unwrap();+ read_gpu_adapter(Some(&file))+ };+ assert_eq!(read(r#"{"performance":{"gpuAdapter":"nvidia"}}"#), "nvidia");+ assert_eq!(read(r#"{"performance":{"gpuAdapter":7}}"#), "");+ assert_eq!(read(r#"{"performance":{}}"#), "");+ assert_eq!(read("not json"), "");+ assert_eq!(read_gpu_adapter(None), "");+ let _ = std::fs::remove_dir_all(&dir);}#[test]@@ -894,7 +992,7 @@ mod tests {// The app's setup replaces wgpu's default (`Auto`: DXC by name from the search path).let mut setup = egui_wgpu::WgpuSetup::without_display_handle();let plan = plan(Auto, None, None, false, Os::Windows);- configure(&mut setup, &plan, Os::Windows, Arc::new(Mutex::new(None)), Arc::default());+ configure(&mut setup, &plan, Os::Windows, None, Arc::new(Mutex::new(None)), Arc::default());let egui_wgpu::WgpuSetup::CreateNew(create) = &setup else { panic!("a new instance") };if std::env::var_os("WGPU_DX12_COMPILER").is_none() {let safe = match &create.instance_descriptor.backend_options.dx12.shader_compiler {@@ -918,13 +1016,13 @@ mod tests {let mut setup = egui_wgpu::WgpuSetup::without_display_handle();let egui_wgpu::WgpuSetup::CreateNew(before) = &setup else { panic!("a new instance") };let before = before.instance_descriptor.flags;- configure(&mut setup, &plan(Auto, None, None, safe_gpu, os), os, Arc::new(Mutex::new(None)), Arc::default());+ configure(&mut setup, &plan(Auto, None, None, safe_gpu, os), os, None, Arc::new(Mutex::new(None)), Arc::default());let egui_wgpu::WgpuSetup::CreateNew(create) = &setup else { panic!("a new instance") };assert_eq!(create.instance_descriptor.flags, before, "{os:?}: flags untouched");}if cfg!(target_arch = "x86_64") && std::env::var_os("WGPU_VALIDATION_INDIRECT_CALL").is_none() {let mut setup = egui_wgpu::WgpuSetup::without_display_handle();- configure(&mut setup, &plan(Auto, None, None, false, Os::Mac), Os::Mac, Arc::new(Mutex::new(None)), Arc::default());+ configure(&mut setup, &plan(Auto, None, None, false, Os::Mac), Os::Mac, None, Arc::new(Mutex::new(None)), Arc::default());let egui_wgpu::WgpuSetup::CreateNew(create) = &setup else { panic!("a new instance") };assert!(!create.instance_descriptor.flags.contains(wgpu::InstanceFlags::VALIDATION_INDIRECT_CALL));}diff --git a/apps/photocraft/src/main.rs b/apps/photocraft/src/main.rsindex b0b00a865..befff8302 100644--- a/apps/photocraft/src/main.rs+++ b/apps/photocraft/src/main.rs@@ -678,7 +678,11 @@ fn main() -> eframe::Result {}let gpu_note: std::sync::Arc<std::sync::Mutex<Option<String>>> = Default::default();// The adapter's real texture limits (egui asks for 8192 px), so big documents stay on the GPU.- gpu_startup::configure(&mut options.wgpu_options.wgpu_setup, &plan, os, sentinel.clone(), gpu_note.clone());+ let wanted_adapter = gpu_startup::wanted_adapter(+ std::env::var("PHOTOCRAFT_GPU_ADAPTER").ok().as_deref(),+ &gpu_startup::read_gpu_adapter(services::prefs_file().as_deref()),+ );+ gpu_startup::configure(&mut options.wgpu_options.wgpu_setup, &plan, os, wanted_adapter, sentinel.clone(), gpu_note.clone());// Preferences › Performance › Low-Latency Drawing (#1343): without vsync a stroke shows about// 50 ms sooner; wgpu picks Immediate, else Mailbox, else Fifo by what the driver offers.if gpu_startup::read_low_latency(services::prefs_file().as_deref()) {@@ -774,6 +778,7 @@ fn main() -> eframe::Result {info.canvas = "cpu".into();if let Some(rs) = cc.wgpu_render_state.clone() {app.perf.gpu_info.set_adapter(&rs.adapter.get_info());+ app.perf.gpu_info.set_available(&rs.available_adapters);let software_window = rs.adapter.get_info().device_type == eframe::wgpu::DeviceType::Cpu;if software_window && mode != photocraft_engine::prefs::RenderingMode::Cpu {app.perf.gpu_info.fallback = Some("No compatible hardware graphics adapter; using software graphics.".into());diff --git a/crates/engine/src/prefs.rs b/crates/engine/src/prefs.rsindex 3e87d43fc..eed66a324 100644--- a/crates/engine/src/prefs.rs+++ b/crates/engine/src/prefs.rs@@ -525,6 +525,11 @@ pub struct Performance {pub rendering_mode: Option<RenderingMode>,/// Graphics backend (applies at next launch; see [`GpuBackend`]).pub gpu_backend: GpuBackend,+ /// Which graphics adapter the window and canvas use on a machine with several (applies at+ /// next launch): part of the adapter's name, matched case-insensitively ("nvidia", "arc"). Empty+ /// is automatic. `PHOTOCRAFT_GPU_ADAPTER` overrides it for one launch. If nothing matches or the+ /// match can't present to the window, startup falls back to automatic and says so.+ pub gpu_adapter: String,/// Live previews of large documents (adjustment and filter dialogs, an adjustment layer's/// sliders while they drag) render on a reduced copy: fast, but blocky when zoomed in. Off:/// they render at full resolution.@@ -570,6 +575,7 @@ impl Default for Performance {use_gpu: true,rendering_mode: None,gpu_backend: GpuBackend::Auto,+ gpu_adapter: String::new(),low_resolution_previews: true,low_latency_drawing: false,linux_display_server: LinuxDisplayServer::Auto,@@ -1059,7 +1065,7 @@ pub fn is_hidden(path: &str) -> bool {/// Preferences that only do something on Linux; the dialog doesn't show them elsewhere. They/// still load, save and round-trip on every platform.-pub const LINUX_ONLY: &[&str] = &["performance.linuxDisplayServer"];+pub const LINUX_ONLY: &[&str] = &["performance.linuxDisplayServer", "performance.gpuAdapter"];/// Choices of an enumerated preference (dotted path, e.g. `"cursors.painting"`).pub fn choices(path: &str) -> Option<&'static [&'static str]> {diff --git a/crates/engine/src/prefs/tests.rs b/crates/engine/src/prefs/tests.rsindex 5314d1f19..bbb9df4ff 100644--- a/crates/engine/src/prefs/tests.rs+++ b/crates/engine/src/prefs/tests.rs@@ -493,6 +493,22 @@ fn right_click_with_painting_tools_pref() {assert_eq!(old.right_click_with_painting_tools, RightClickPaint::BrushPicker);}+#[test]+fn gpu_adapter_round_trips_and_defaults_to_automatic() {+ let mut s = session();+ assert_eq!(s.prefs().performance.gpu_adapter, "");+ s.execute("prefs.set", json!({"path": "performance.gpuAdapter", "value": "NVIDIA"})).unwrap();+ assert_eq!(s.prefs().performance.gpu_adapter, "NVIDIA");+ assert!(s.execute("prefs.set", json!({"path": "performance.gpuAdapter", "value": 3})).is_err());+ assert_eq!(s.prefs().performance.gpu_adapter, "NVIDIA");+ let mut t = Session::new();+ t.load_prefs_json(&s.prefs_to_json()).unwrap();+ assert_eq!(t.prefs().performance.gpu_adapter, "NVIDIA");+ let mut u = Session::new();+ u.load_prefs_json(r#"{"performance": {"useGpu": true}}"#).unwrap();+ assert_eq!(u.prefs().performance.gpu_adapter, "");+}+#[test]fn gpu_backend_round_trips_and_validates() {let mut s = session();@@ -553,7 +569,9 @@ fn notification_autohide_preferences() {fn linux_only_preferences_show_only_on_linux() {assert_eq!(is_hidden("performance.linuxDisplayServer"), !cfg!(target_os = "linux"));assert!(!is_hidden("performance.gpuBackend"));- assert!(LINUX_ONLY.iter().all(|p| choices(p).is_some()), "every Linux-only preference is a real one");+ assert!(LINUX_ONLY.contains(&"performance.gpuAdapter"));+ let free_text = ["performance.gpuAdapter"];+ assert!(LINUX_ONLY.iter().all(|p| free_text.contains(p) || choices(p).is_some()), "every Linux-only preference is a real one");}#[test]diff --git a/crates/ui-egui/src/gpu_canvas.rs b/crates/ui-egui/src/gpu_canvas.rsindex 65388d504..476137ff3 100644--- a/crates/ui-egui/src/gpu_canvas.rs+++ b/crates/ui-egui/src/gpu_canvas.rs@@ -1058,6 +1058,9 @@ pub struct GpuInfo {pub video_memory_mb: Option<u64>,/// `performance.gpuBackend` at launch.pub preference: String,+ /// Every graphics adapter the window could have used, by name (Preferences › Performance ›+ /// Graphics Adapter lists them). Empty in hosts that don't set it.+ pub adapters: Vec<String>,/// The backend startup chose ("auto", "dx12", "cpu", …, or "env" for `WGPU_BACKEND`).pub selected: String,/// Why startup didn't use the preference as is (previous start crashed, `--safe-gpu`,@@ -1073,6 +1076,17 @@ pub struct GpuInfo {}impl GpuInfo {+ /// Record the adapters the instance found, without duplicates (one GPU shows up once per backend).+ pub fn set_available(&mut self, adapters: &[wgpu::Adapter]) {+ self.adapters.clear();+ for a in adapters {+ let name = a.get_info().name;+ if !name.is_empty() && !self.adapters.contains(&name) {+ self.adapters.push(name);+ }+ }+ }+/// Fill the adapter fields from `info`.pub fn set_adapter(&mut self, info: &wgpu::AdapterInfo) {self.adapter = info.name.clone();diff --git a/crates/ui-egui/src/i18n/cs.tsv b/crates/ui-egui/src/i18n/cs.tsvindex 6175183cb..f4d8798b4 100644--- a/crates/ui-egui/src/i18n/cs.tsv+++ b/crates/ui-egui/src/i18n/cs.tsv@@ -3838,3 +3838,6 @@ navigator Zoom ZvětšeníIncrease Brush Size Zvětšit velikost štětceDecrease Brush Hardness Snížit tvrdost štětceIncrease Brush Hardness Zvýšit tvrdost štětce++# Graphics Adapter preference (#1885)+ GPU adapter Adaptér GPUdiff --git a/crates/ui-egui/src/i18n/de.tsv b/crates/ui-egui/src/i18n/de.tsvindex 5fbbceb44..fd7254628 100644--- a/crates/ui-egui/src/i18n/de.tsv+++ b/crates/ui-egui/src/i18n/de.tsv@@ -3230,3 +3230,6 @@ curves Smooth GlättenGPU Memory (MB, 0 = Automatic) GPU-Speicher (MB, 0 = Automatisch){name} was changed by another app after it was opened or saved here. {name} wurde von einer anderen App geändert, nachdem es hier geöffnet oder gespeichert wurde.Replace it with this document, or cancel and use File › Save As to keep both. Ersetze die Datei durch dieses Dokument oder brich ab und nutze Datei › Speichern unter, um beide zu behalten.++# Graphics Adapter preference (#1885)+ GPU adapter GPU-Adapterdiff --git a/crates/ui-egui/src/i18n/el.tsv b/crates/ui-egui/src/i18n/el.tsvindex d21c3ba6e..3f31bec6c 100644--- a/crates/ui-egui/src/i18n/el.tsv+++ b/crates/ui-egui/src/i18n/el.tsv@@ -3930,3 +3930,6 @@ curves Smooth ΕξομάλυνσηIncrease Brush Size Αύξηση μεγέθους πινέλουDecrease Brush Hardness Μείωση σκληρότητας πινέλουIncrease Brush Hardness Αύξηση σκληρότητας πινέλου++# Graphics Adapter preference (#1885)+ GPU adapter Προσαρμογέας GPUdiff --git a/crates/ui-egui/src/i18n/es.tsv b/crates/ui-egui/src/i18n/es.tsvindex 4956fcd97..3dcfb2568 100644--- a/crates/ui-egui/src/i18n/es.tsv+++ b/crates/ui-egui/src/i18n/es.tsv@@ -4192,3 +4192,6 @@ navigator Zoom ZoomIncrease Brush Size Aumentar tamaño del pincelDecrease Brush Hardness Reducir dureza del pincelIncrease Brush Hardness Aumentar dureza del pincel++# Graphics Adapter preference (#1885)+ GPU adapter Adaptador de GPUdiff --git a/crates/ui-egui/src/i18n/fr.tsv b/crates/ui-egui/src/i18n/fr.tsvindex 62b2e8ea2..9f15ac108 100644--- a/crates/ui-egui/src/i18n/fr.tsv+++ b/crates/ui-egui/src/i18n/fr.tsv@@ -3238,3 +3238,6 @@ curves Smooth LisserIncrease Brush Size Augmenter la taille du pinceauDecrease Brush Hardness Réduire la dureté du pinceauIncrease Brush Hardness Augmenter la dureté du pinceau++# Graphics Adapter preference (#1885)+ GPU adapter Adaptateur GPUdiff --git a/crates/ui-egui/src/i18n/hu.tsv b/crates/ui-egui/src/i18n/hu.tsvindex a52cb5fdb..ad4d3c19f 100644--- a/crates/ui-egui/src/i18n/hu.tsv+++ b/crates/ui-egui/src/i18n/hu.tsv@@ -4149,3 +4149,6 @@ cameraRaw Yellow SárgaIncrease Brush Size Ecsetméret növeléseDecrease Brush Hardness Ecsetkeménység csökkentéseIncrease Brush Hardness Ecsetkeménység növelése++# Graphics Adapter preference (#1885)+ GPU adapter GPU-adapterdiff --git a/crates/ui-egui/src/i18n/id.tsv b/crates/ui-egui/src/i18n/id.tsvindex 14e65b2b7..e63f82baf 100644--- a/crates/ui-egui/src/i18n/id.tsv+++ b/crates/ui-egui/src/i18n/id.tsv@@ -3225,3 +3225,6 @@ curves Smooth HaluskanIncrease Brush Size Perbesar ukuran kuasDecrease Brush Hardness Kurangi kekerasan kuasIncrease Brush Hardness Tambah kekerasan kuas++# Graphics Adapter preference (#1885)+ GPU adapter Adaptor GPUdiff --git a/crates/ui-egui/src/i18n/it.tsv b/crates/ui-egui/src/i18n/it.tsvindex 857cc66d9..6c754f1b3 100644--- a/crates/ui-egui/src/i18n/it.tsv+++ b/crates/ui-egui/src/i18n/it.tsv@@ -4347,3 +4347,6 @@ shape Appearance AspettoGPU Memory (MB, 0 = Automatic) Memoria GPU (MB, 0 = Automatico){name} was changed by another app after it was opened or saved here. {name} è stato modificato da un'altra app dopo essere stato aperto o salvato qui.Replace it with this document, or cancel and use File › Save As to keep both. Sostituiscilo con questo documento, oppure annulla e usa File › Salva con nome per tenerli entrambi.++# Graphics Adapter preference (#1885)+ GPU adapter Adattatore GPUdiff --git a/crates/ui-egui/src/i18n/ja.tsv b/crates/ui-egui/src/i18n/ja.tsvindex b14f5c119..5204f384e 100644--- a/crates/ui-egui/src/i18n/ja.tsv+++ b/crates/ui-egui/src/i18n/ja.tsv@@ -3907,3 +3907,6 @@ curves Smooth スムーズIncrease Brush Size ブラシサイズを大きくDecrease Brush Hardness ブラシの硬さを下げるIncrease Brush Hardness ブラシの硬さを上げる++# Graphics Adapter preference (#1885)+ GPU adapter GPU アダプターdiff --git a/crates/ui-egui/src/i18n/ko.tsv b/crates/ui-egui/src/i18n/ko.tsvindex d5d58b2ff..ff7165f70 100644--- a/crates/ui-egui/src/i18n/ko.tsv+++ b/crates/ui-egui/src/i18n/ko.tsv@@ -3411,3 +3411,6 @@ curves Smooth 매끄럽게Increase Brush Size 브러시 크기 늘리기Decrease Brush Hardness 브러시 경도 줄이기Increase Brush Hardness 브러시 경도 늘리기++# Graphics Adapter preference (#1885)+ GPU adapter GPU 어댑터diff --git a/crates/ui-egui/src/i18n/nl.tsv b/crates/ui-egui/src/i18n/nl.tsvindex 394aaecbb..41bc8ca4f 100644--- a/crates/ui-egui/src/i18n/nl.tsv+++ b/crates/ui-egui/src/i18n/nl.tsv@@ -3990,3 +3990,6 @@ curves Smooth Vloeiend makenIncrease Brush Size Penseelgrootte vergrotenDecrease Brush Hardness Penseelhardheid verlagenIncrease Brush Hardness Penseelhardheid verhogen++# Graphics Adapter preference (#1885)+ GPU adapter GPU-adapterdiff --git a/crates/ui-egui/src/i18n/pl.tsv b/crates/ui-egui/src/i18n/pl.tsvindex 660e93bbb..097f1d105 100644--- a/crates/ui-egui/src/i18n/pl.tsv+++ b/crates/ui-egui/src/i18n/pl.tsv@@ -3829,3 +3829,6 @@ curves Smooth WygładźIncrease Brush Size Zwiększ rozmiar pędzlaDecrease Brush Hardness Zmniejsz twardość pędzlaIncrease Brush Hardness Zwiększ twardość pędzla++# Graphics Adapter preference (#1885)+ GPU adapter Karta GPUdiff --git a/crates/ui-egui/src/i18n/pt-br.tsv b/crates/ui-egui/src/i18n/pt-br.tsvindex 338c4fadb..967efd5e6 100644--- a/crates/ui-egui/src/i18n/pt-br.tsv+++ b/crates/ui-egui/src/i18n/pt-br.tsv@@ -4020,3 +4020,6 @@ layerLabel No Color Sem corIncrease Brush Size Aumentar tamanho do pincelDecrease Brush Hardness Diminuir dureza do pincelIncrease Brush Hardness Aumentar dureza do pincel++# Graphics Adapter preference (#1885)+ GPU adapter Adaptador de GPUdiff --git a/crates/ui-egui/src/i18n/ru.tsv b/crates/ui-egui/src/i18n/ru.tsvindex 11fd43811..5b52178d6 100644--- a/crates/ui-egui/src/i18n/ru.tsv+++ b/crates/ui-egui/src/i18n/ru.tsv@@ -3203,3 +3203,6 @@ curves Smooth СгладитьIncrease Brush Size Увеличить размер кистиDecrease Brush Hardness Уменьшить жёсткость кистиIncrease Brush Hardness Увеличить жёсткость кисти++# Graphics Adapter preference (#1885)+ GPU adapter Адаптер GPUdiff --git a/crates/ui-egui/src/i18n/sr.tsv b/crates/ui-egui/src/i18n/sr.tsvindex 25175aeff..0b9bdb75a 100644--- a/crates/ui-egui/src/i18n/sr.tsv+++ b/crates/ui-egui/src/i18n/sr.tsv@@ -4303,3 +4303,6 @@ shape Appearance IzgledIncrease Brush Size Povećaj veličinu četkiceDecrease Brush Hardness Smanji tvrdoću četkiceIncrease Brush Hardness Povećaj tvrdoću četkice++# Graphics Adapter preference (#1885)+ GPU adapter GPU adapterdiff --git a/crates/ui-egui/src/i18n/tr.tsv b/crates/ui-egui/src/i18n/tr.tsvindex 6af551012..278623f6a 100644--- a/crates/ui-egui/src/i18n/tr.tsv+++ b/crates/ui-egui/src/i18n/tr.tsv@@ -3960,3 +3960,6 @@ cameraData Lens LensIncrease Brush Size Fırça boyutunu büyütDecrease Brush Hardness Fırça sertliğini azaltIncrease Brush Hardness Fırça sertliğini artır++# Graphics Adapter preference (#1885)+ GPU adapter GPU bağdaştırıcısıdiff --git a/crates/ui-egui/src/i18n/uk.tsv b/crates/ui-egui/src/i18n/uk.tsvindex 37851e90f..605cf3df6 100644--- a/crates/ui-egui/src/i18n/uk.tsv+++ b/crates/ui-egui/src/i18n/uk.tsv@@ -3938,3 +3938,6 @@ curves Smooth ЗгладитиThis shape layer must be rasterized before proceeding. It will no longer be editable as a shape. Rasterize the shape? Щоб продовжити, потрібно растеризувати цей шар фігури. Після цього його більше не можна буде редагувати як фігуру. Растеризувати фігуру?This Smart Object must be rasterized before proceeding. Its contents will no longer be editable. Rasterize the Smart Object? Щоб продовжити, потрібно растеризувати цей смартоб’єкт. Після цього його вміст більше не можна буде редагувати. Растеризувати смартоб’єкт?This fill layer must be rasterized before proceeding. Its fill content will no longer be editable. Rasterize the layer? Щоб продовжити, потрібно растеризувати цей шар заливки. Після цього його заливку більше не можна буде редагувати. Растеризувати шар?++# Graphics Adapter preference (#1885)+ GPU adapter Адаптер GPUdiff --git a/crates/ui-egui/src/i18n/vi.tsv b/crates/ui-egui/src/i18n/vi.tsvindex fd7950b93..3a9f2ba4e 100644--- a/crates/ui-egui/src/i18n/vi.tsv+++ b/crates/ui-egui/src/i18n/vi.tsv@@ -3717,3 +3717,6 @@ curves Smooth Làm mượtIncrease Brush Size Tăng kích thước cọDecrease Brush Hardness Giảm độ cứng của cọIncrease Brush Hardness Tăng độ cứng của cọ++# Graphics Adapter preference (#1885)+ GPU adapter Bộ điều hợp GPUdiff --git a/crates/ui-egui/src/i18n/zh-hans.tsv b/crates/ui-egui/src/i18n/zh-hans.tsvindex 0f242f8f6..604786a29 100644--- a/crates/ui-egui/src/i18n/zh-hans.tsv+++ b/crates/ui-egui/src/i18n/zh-hans.tsv@@ -2853,3 +2853,6 @@ curves Smooth 平滑Increase Brush Size 增大画笔大小Decrease Brush Hardness 减小画笔硬度Increase Brush Hardness 增大画笔硬度++# Graphics Adapter preference (#1885)+ GPU adapter GPU 适配器diff --git a/crates/ui-egui/src/i18n/zh-hant.tsv b/crates/ui-egui/src/i18n/zh-hant.tsvindex 621bee551..e61580cef 100644--- a/crates/ui-egui/src/i18n/zh-hant.tsv+++ b/crates/ui-egui/src/i18n/zh-hant.tsv@@ -2838,3 +2838,6 @@ curves Smooth 平滑Increase Brush Size 放大筆刷大小Decrease Brush Hardness 降低筆刷硬度Increase Brush Hardness 提高筆刷硬度++# Graphics Adapter preference (#1885)+ GPU adapter GPU 介面卡diff --git a/crates/ui-egui/src/lib.rs b/crates/ui-egui/src/lib.rsindex 5948bd4ed..5634dfa72 100644--- a/crates/ui-egui/src/lib.rs+++ b/crates/ui-egui/src/lib.rs@@ -1013,6 +1013,7 @@ 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());+ 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,Err(payload) => {diff --git a/crates/ui-egui/src/prefs_ui.rs b/crates/ui-egui/src/prefs_ui.rsindex 4156e380c..1b5908326 100644--- a/crates/ui-egui/src/prefs_ui.rs+++ b/crates/ui-egui/src/prefs_ui.rs@@ -1058,6 +1058,7 @@ pub fn body(app: &mut PhotocraftApp, ui: &mut egui::Ui, f: &mut Map<String, Valulet mut info = app.perf.gpu_info.lines();info.extend(gpu_memory_lines(app));f.insert("__gpuInfo".into(), json!(info));+ f.insert("__gpuAdapters".into(), json!(app.perf.gpu_info.adapters));let system = system_theme(app, ui.ctx());prefs_body(ui, f, system);}@@ -1287,7 +1288,7 @@ fn prefs_body(ui: &mut egui::Ui, f: &mut Map<String, Value>, system: Option<egui);}if section == "performance" {- gpu_status_rows(ui, f.get("__gpuInfo"), obj);+ gpu_status_rows(ui, f.get("__gpuInfo"), f.get("__gpuAdapters"), obj);}ui.add_space(8.0);}@@ -1312,7 +1313,7 @@ fn prefs_body(ui: &mut egui::Ui, f: &mut Map<String, Value>, system: Option<egui/// Preferences › Performance: what the app renders with now, and a reset of the GPU backend/// (a crashed start may have moved it to a safer choice).-fn gpu_status_rows(ui: &mut egui::Ui, info: Option<&Value>, obj: &mut Map<String, Value>) {+fn gpu_status_rows(ui: &mut egui::Ui, info: Option<&Value>, adapters: Option<&Value>, obj: &mut Map<String, Value>) {let t = Tokens::get(ui.ctx());ui.add_space(10.0);ui.label(RichText::new(tl!("Graphics")).font(crate::theme::semibold(12.5)).color(t.text));@@ -1331,7 +1332,32 @@ fn gpu_status_rows(ui: &mut egui::Ui, info: Option<&Value>, obj: &mut Map<Stringcrate::widgets::dropdown(ui, "graphics-backend", &mut current, &pairs, 220.0);obj.insert("gpuBackend".into(), json!(current));});+ if !prefs::is_hidden("performance.gpuAdapter") {+ graphics_adapter_row(ui, adapters, obj);+ }+ });+}++/// Preferences › Performance › Graphics Adapter: which GPU draws on a machine with several. The+/// value is the adapter's name; empty is automatic. A saved adapter that isn't present now (an+/// unplugged eGPU) stays listed, marked ⚠, so opening the dialog doesn't silently change the choice.+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(¤t);+ if missing {+ names.push(current.clone());+ }+ let automatic = tl!("Automatic");+ let labels: Vec<String> = names.iter().map(|n| if missing && *n == current { format!("⚠ {n}") } else { n.clone() }).collect();+ let mut pairs: Vec<(String, &str)> = vec![(String::new(), automatic)];+ pairs.extend(names.iter().cloned().zip(labels.iter().map(String::as_str)));+ ui.horizontal(|ui| {+ ui.label(tl!("GPU adapter"));+ crate::widgets::dropdown_literal(ui, "graphics-adapter", &mut current, &pairs, 320.0);});+ ui.label(RichText::new(tl!("Applies at next launch.")).color(Tokens::get(ui.ctx()).text_faint));+ obj.insert("gpuAdapter".into(), json!(current));}/// One user-facing choice; legacy flags remain compatible with older settings.@@ -1566,7 +1592,7 @@ fn field_visible(section: &str, obj: &Map<String, Value>, k: &str, query: &str)let drawn_elsewhere = (section == "interface" && matches!(k, "theme" | "appearanceMode" | "darkTheme" | "lightTheme" | "favoriteThemes"))// View › Rulers (⌘R) sets it, as in Photoshop.|| path == "unitsAndRulers.showRulers"- || (section == "performance" && matches!(k, "useGpu" | "gpuBackend" | "renderingMode"))+ || (section == "performance" && matches!(k, "useGpu" | "gpuBackend" | "gpuAdapter" | "renderingMode"))// The browser presents frames itself: Low-Latency Drawing does nothing there.|| (cfg!(target_arch = "wasm32") && path == "performance.lowLatencyDrawing")|| (section == "export" && !export_field_visible(obj, k))diff --git a/docs/development.md b/docs/development.mdindex 6891e88a9..bf4898482 100644--- a/docs/development.md+++ b/docs/development.md@@ -86,7 +86,7 @@ On Windows and Linux the first PhotoCraft holds an exclusive lock on `instance.l## Graphics startup and device loss-`--safe-gpu` starts with the CPU renderer for one launch (no GPU canvas; a software adapter for the window where the platform has one: WARP on Windows, llvmpipe over GL on Linux). Before creating the wgpu device the app writes and locks `gpu-starting.json` in the config directory; it clears it once the first frames have rendered. A launch that finds an unlocked marker knows the previous start died inside the graphics driver (#4) and uses the next safer backend (Windows: Vulkan → DX12 → CPU; Linux: Vulkan → GL → CPU; macOS: Metal → CPU), remembering a working hardware backend in `performance.gpuBackend` (Preferences › Performance › GPU Backend, with **Reset GPU Backend**). CPU recovery is temporary until **Keep Using CPU** is chosen in the recovery dialog; dismissing the dialog or quitting without a choice preserves the previous GPU preference (#3483). With `auto`, Intel adapters on Windows use DX12. Help › System Info shows the adapter, backend, driver and fallback state.+`--safe-gpu` starts with the CPU renderer for one launch (no GPU canvas; a software adapter for the window where the platform has one: WARP on Windows, llvmpipe over GL on Linux). Before creating the wgpu device the app writes and locks `gpu-starting.json` in the config directory; it clears it once the first frames have rendered. A launch that finds an unlocked marker knows the previous start died inside the graphics driver (#4) and uses the next safer backend (Windows: Vulkan → DX12 → CPU; Linux: Vulkan → GL → CPU; macOS: Metal → CPU), remembering a working hardware backend in `performance.gpuBackend` (Preferences › Performance › GPU Backend, with **Reset GPU Backend**). CPU recovery is temporary until **Keep Using CPU** is chosen in the recovery dialog; dismissing the dialog or quitting without a choice preserves the previous GPU preference (#3483). With `auto`, Intel adapters on Windows use DX12. On a machine with several GPUs (say an eGPU, a discrete laptop GPU and an iGPU), `auto` takes the first discrete adapter the driver lists; choose another in Preferences › Performance › Advanced › GPU adapter (`performance.gpuAdapter`, Linux; a case-insensitive piece of the adapter's name, empty is automatic), or for one launch with `PHOTOCRAFT_GPU_ADAPTER=nvidia`. An adapter that is missing or can't present to the window falls back to the automatic choice, with a note in System Info. Help › System Info shows the adapter, backend, driver and fallback state.On DX12 the shader compiler is FXC (`d3dcompiler_47.dll`, part of Windows), or a `dxcompiler.dll` placed beside `photocraft.exe`, loaded by its full path. wgpu's default looks `dxcompiler.dll` up by name, which reaches the current directory and `PATH` and loaded other programs' incompatible builds (#712).@@ -116,6 +116,7 @@ By default PhotoCraft's own crates log at `info` and everything else at `warn`.| `PHOTOCRAFT_AUTOMATION_WRITE_ROOT` | Desktop app only: automation write root. Headless CLI modes require the `--automation-write-root` flag || `PHOTOCRAFT_CPU_CANVAS=1` | Force the CPU canvas path instead of the wgpu shader canvas || `PHOTOCRAFT_NATIVE_WAYLAND=1` | Linux: stay on native Wayland when a pen is attached (by default the window then opens through Xwayland, because Wayland gives the app no pen input; #639). A pen is an input device with `BTN_TOOL_PEN` and the `ABS_X`/`ABS_Y` axes; virtual keyboards that claim every key are not pens (#1072) |+| `PHOTOCRAFT_GPU_ADAPTER=nvidia` | Use the graphics adapter whose name contains this (case-insensitive); overrides `performance.gpuAdapter` for one launch || `WGPU_BACKEND=dx12` | Pick the wgpu backend(s) (`vulkan`, `dx12`, `metal`, `gl`); overrides `performance.gpuBackend` and the startup fallback || `WGPU_DX12_COMPILER=fxc` | DX12 shader compiler (`fxc`, `dxc`, `auto`); `dxc` and `auto` look `dxcompiler.dll` up through the DLL search path || `PHOTOCRAFT_GPU_TILE=2048` | Force GPU canvas tiling (tests tile seams) |diff --git a/docs/hardware-parity.md b/docs/hardware-parity.mdindex 60175de1e..1417821f0 100644--- a/docs/hardware-parity.md+++ b/docs/hardware-parity.md@@ -22,6 +22,7 @@ HDR display to verify.| GPU filters (Blur Gallery, Liquify, Smart Sharpen, Camera Raw) | yes | CPU (rayon) for filters; GPU for compose and effects | partial || Documents larger than the GPU texture limit | yes (tiled) | CPU fallback; tiling in progress (#49) | partial || CPU-only fallback when no GPU | yes, reduced | `cpu` canvas preference; fails to start without an adapter on some Linux systems (#2519, #2412) | partial |+| Choosing the GPU on a multi-GPU machine | Preferences › Performance › Use Graphics Processor | Linux: Preferences › Performance › Advanced › GPU adapter and `PHOTOCRAFT_GPU_ADAPTER` (#1885); Windows and macOS not yet | partial || Old / integrated GPUs | yes | black line on Intel HD (#2426), OpenCore Macs fail (#1859), Rgba32Float panic (#2020) | partial |## Pen tablets@@ -62,3 +63,4 @@ HDR display to verify.| Date | Change | Summary ||---|---|---|| 2026-10-10 | major | First version |+| 2026-10-19 | minor | Graphics Adapter choice on Linux (#1885) |