LightCraft: An open-source non-destructive photo editor written by scratch in pure Rust
Merge PR #694
Claude76cf8ca4c951
diff --cc crates/gpu/src/backend.rsindex bcbd4fd7c,3d71fd935..57e47f22e--- a/crates/gpu/src/backend.rs+++ b/crates/gpu/src/backend.rs@@@ -297,19 -237,11 +339,22 @@@ pub fn window_renderer_order#[cfg(test)]#[allow(clippy::unwrap_used)]mod tests {++ /// #250: the indirect-call validation pipeline is off unless asked for; other flags are kept.+ #[test]+ fn indirect_call_validation_is_off_unless_asked_for() {+ use wgpu::InstanceFlags as F;+ let base = F::VALIDATION_INDIRECT_CALL | F::DEBUG;+ assert_eq!(instance_flags(base, None), F::DEBUG);+ assert_eq!(instance_flags(base, Some("0")), F::DEBUG);+ assert_eq!(instance_flags(F::empty(), Some("1")), F::VALIDATION_INDIRECT_CALL);+ assert_eq!(instance_flags(F::empty(), None), F::empty());+ }use super::*;+ /// The tests that set the process-wide marker take turns.+ static GLOBAL: Mutex<()> = Mutex::new(());+#[test]fn parses_backend_names() {assert_eq!(parse_backends("dx12"), Some(BackendChoice::Use(Backends::DX12)));@@@ -394,43 -327,40 +440,80 @@@let _ = std::fs::remove_dir_all(&dir);}+ /// The window's renderer fallback: forced, remembered, the platform chain, the failed one last.+ #[test]+ fn window_renderer_fallback_order() {+ use WindowRenderer::{Glow, Wgpu};+ let all = Backends::DX12 | Backends::VULKAN | Backends::GL | Backends::METAL;+ let (dx, vk, gl) = (Wgpu(Backends::DX12), Wgpu(Backends::VULKAN), Wgpu(Backends::GL));+ assert_eq!(window_renderer_order(None, None, None, "windows", all, true), [dx, vk, gl, Glow]);+ assert_eq!(window_renderer_order(None, None, None, "windows", all, false), [dx, vk, gl]);+ // a build without GL+ assert_eq!(window_renderer_order(None, None, None, "windows", Backends::DX12 | Backends::VULKAN, true), [dx, vk, Glow]);+ // remembered from the last good start goes first+ assert_eq!(window_renderer_order(None, Some(vk), None, "windows", all, true), [vk, dx, gl, Glow]);+ // the environment wins over the remembered one+ assert_eq!(window_renderer_order(Some(gl), Some(vk), None, "windows", all, true), [gl, vk, dx, Glow]);+ assert_eq!(window_renderer_order(Some(Glow), None, None, "windows", all, true)[0], Glow);+ // the last start died in DX12: tried last only (also when it was remembered)+ assert_eq!(window_renderer_order(None, Some(dx), Some(dx), "windows", all, true), [vk, gl, Glow, dx]);+ // a forced backend that is not in the build is skipped+ assert_eq!(window_renderer_order(Some(Wgpu(Backends::METAL)), None, None, "windows", Backends::DX12, false), [dx]);+ // never empty+ assert!(!window_renderer_order(None, None, None, "windows", Backends::empty(), false).is_empty());+ assert_eq!(window_renderer_order(None, None, None, "macos", all, true), [Wgpu(Backends::METAL), Glow]);+ }++ #[test]+ fn window_renderer_names_round_trip() {+ for n in ["dx12", "vulkan", "metal", "gl", "glow"] {+ assert_eq!(WindowRenderer::parse(n).map(WindowRenderer::name), Some(n));+ }+ assert_eq!(WindowRenderer::parse(" DX12 "), Some(WindowRenderer::Wgpu(Backends::DX12)));+ for n in ["auto", "off", "vulkan,gl", "", "bogus"] {+ assert_eq!(WindowRenderer::parse(n), None, "{n}");+ }+ assert_eq!(forced_window_renderer(Some("glow"), Some("dx12")), Some(WindowRenderer::Glow));+ assert_eq!(forced_window_renderer(Some("auto"), Some("vulkan")), Some(WindowRenderer::Wgpu(Backends::VULKAN)));+ assert_eq!(forced_window_renderer(None, None), None);+ // `glow` only concerns the window: compute keeps its default, without a warning+ assert_eq!(parse_backends("glow"), Some(BackendChoice::Auto));+ }+++ #[test]+ fn overlapping_scopes_share_one_marker_until_the_last_ends() {+ let dir = std::env::temp_dir().join(format!("lc-gpu-scopes-{}", std::process::id()));+ let m = dir.join("gpu-init.marker");+ let _ = std::fs::remove_dir_all(&dir);+ let active = Mutex::new(0);+ arm(&m, &active, "device creation");+ assert!(read_init_marker(&m).unwrap().contains("device creation"));+ // a second scope (a denoise network's kernels) keeps the first's text and the file+ arm(&m, &active, "denoise kernel compilation");+ assert!(read_init_marker(&m).unwrap().contains("device creation"));+ disarm(&m, &active);+ assert!(m.exists(), "the first scope is still running");+ disarm(&m, &active);+ assert!(!m.exists(), "the last scope removes it");+ // a stray extra disarm does not underflow or break the next scope+ disarm(&m, &active);+ arm(&m, &active, "kernel compilation");+ assert!(m.exists());+ disarm(&m, &active);+ let _ = std::fs::remove_dir_all(&dir);+ }++ #[test]+ fn a_panic_inside_the_scope_still_removes_the_marker() {+ let _turn = GLOBAL.lock().unwrap_or_else(|e| e.into_inner());+ let dir = std::env::temp_dir().join(format!("lc-gpu-panic-{}", std::process::id()));+ let m = dir.join("gpu-init.marker");+ let _ = std::fs::remove_dir_all(&dir);+ set_init_marker(Some(m.clone()));+ let r = std::panic::catch_unwind(|| with_marker("kernel compilation", || panic!("compile")));+ set_init_marker(None);+ assert!(r.is_err());+ assert!(!m.exists(), "the process survived, so nothing is left to report");+ let _ = std::fs::remove_dir_all(&dir);+ }}diff --cc docs/gpu-pipeline.mdindex d1510774f,fc53aae76..2eeb43c58--- a/docs/gpu-pipeline.md+++ b/docs/gpu-pipeline.md@@@ -81,20 -85,10 +85,20 @@@ marker and says so in a notice. Checkinwhich writes nothing: it neither arms the sentinel nor removes a marker it finds (it still starts with GPUrendering off when one is there, and the next ordinary launch reports and clears it). Killing the app duringthe ~0.3 s of device creation, or two instances starting at the same moment, can trip it falsely β- harmless: rendering is then on the CPU until the box is checked again. The sentinel only covers the- compute device; a crash while the window's renderer starts is avoided by the backend defaults above+ harmless: rendering is then on the CPU until the box is checked again. The sentinel covers the compute+ device and every kernel build; a crash while the window's renderer starts is avoided by the backend defaults aboveor worked around with `LIGHTCRAFT_GPU_BACKEND`.+**The window's renderer and its fallback (Windows).** Before the window opens, each renderer is probed in+order: DX12, Vulkan, GL, then eframe's OpenGL renderer (glow). A probe creates a device and builds egui's+pipeline inside wgpu error scopes, so a driver that cannot compile egui's shaders ("The parameter is+incorrect. (0x80070057)" in `egui_pipeline`) is logged and skipped instead of killing the app. The renderer+that worked is remembered in the settings folder (`window-renderer`); a start that dies before the window is up+leaves `window-init.marker`, and the next start (relaunched automatically, at most 4 times) tries that+renderer last. `LIGHTCRAFT_GPU_BACKEND=dx12 | vulkan | gl | glow` (or `WGPU_BACKEND`) forces one; DX12 stays+first because a broken Vulkan driver can crash the process uncatchably (#136). Compute keeps its own+device and falls back to the CPU as before.+**Troubleshooting a crash at startup (Windows).** Start LightCraft from a `.cmd` file or a terminalwith `set LIGHTCRAFT_GPU_BACKEND=dx12` (the default since #136), or `=off` to keep the GPU out ofrendering; `set VK_LOADER_DRIVERS_DISABLE=*igvk64*` (Vulkan loader) hides a specific Vulkan driverdiff --cc docs/parity-checklist.mdindex 88dfc2eb0,0dbbc8a8f..73ba5ccd2--- a/docs/parity-checklist.md+++ b/docs/parity-checklist.md@@@ -426,8 -491,8 +426,8 @@@ differences and missing bindings are i| LR-PREF-ACCOUNT | Account | OOS | π« | | || LR-PREF-INTERFACE | Interface options | P1 | β | `cmd:app.settings` | filmstrip names/badges, grid badges (auto/always/never), square-grid names, navigator, info overlay || LR-PREF-DISPLAY | Monitor (display) colour management | P1 | π‘ | `cmd:app.displayProfile`, `crates/codecs/src/display.rs`, `crates/engine/src/display.rs`, `crates/ui-egui/src/panels/settings.rs`, `docs/display-profiles.md` | Settings βΈ Display: a monitor ICC profile (matrix/TRC exactly, LUT-based through the CMS) chosen by hand; the loupe, Before, Compare, hover previews and the second window render into the display's primaries (its full gamut, CPU and GPU), thumbnails and stand-ins are converted from sRGB; histogram, preview caches and exports stay sRGB; soft proofing's display gamut warning uses the display's gamut. Missing: picking up the profile the OS assigns (X11 `_ICC_PROFILE`, colord, ColorSync, WCS), per-monitor profiles |- | LR-PREF-PERFORMANCE | GPU / performance | P1 | β | `cmd:app.gpu`, `cmd:app.memoryBudget`, `cmd:app.settings` | GPU on/off, preview size (Automatic = the whole-frame loupe render at canvas size, up to 2560 px; or a 1600β5120 px size for it; zoomed views add a window at up to 100 %, issue #323), memory budget (a quarter of it is the idle per-view stage caches' share; the open photo's views are counted and reported, and cut only past four times that, the before side's and the zoom window's first β a Before/After at 1:1 on a 2800 px canvas holds about 1 GB of GPU stages, plus the one 288 MB copy of the original, which `ui.inspect` reports as `sharedSourceBytes`), thumbnail cache size in Settings |+ | LR-PREF-PERFORMANCE | GPU / performance | P1 | β | `cmd:app.gpu`, `cmd:app.memoryBudget`, `cmd:app.settings` | GPU on/off (a crash while the GPU device or its kernels are built, issue #250, turns it off for the next launch), preview size (Automatic = the whole-frame loupe render at canvas size, up to 2560 px; or a 1600β5120 px size for it; zoomed views add a window at up to 100 %, issue #323), memory budget (a quarter of it is the idle per-view stage caches' share; the open photo's views are counted and reported, and cut only past four times that, the before side's and the zoom window's first β a Before/After at 1:1 on a 2800 px canvas holds about 1 GB of GPU stages, plus the one 288 MB copy of the original, which `ui.inspect` reports as `sharedSourceBytes`), thumbnail cache size in Settings |-| LR-PREF-PEOPLE | Face recognition | P2 | π‘ | `cmd:faces.enable`, `cmd:faces.models.list`, `cmd:faces.models.inspect`, `cmd:faces.models.install`, `cmd:faces.models.download`, `cmd:faces.models.downloads`, `cmd:faces.models.downloadCancel`, `cmd:faces.models.remove`, `cmd:faces.models.select`, `cmd:dialog.faceModel`, `crates/faces/src/lib.rs`, `crates/ui-egui/src/panels/faces.rs` | Settings βΈ Faces: an off-by-default toggle and the face model list. Models are opt-in and never bundled, the 232 KB YuNet detector included. Press Download (terms first; then a pinned address, size and SHA-256 checked, fetched over pure-Rust https with `lightcraft-fetch`), or add any `.onnx` by picking or dropping it: it is recognised by hash or described from its shape, shows its licence terms and training-data note, runs a self-test, and installs only after an "I accept" box; an installed model is chosen and recognition switched on at once (the newest wins, each model keeps its own embedding cache). Non-commercial models are add-by-file only, never offered for download. Suggestions of names run on the shared pure-Rust CPU interpreter (`crates/faces/src/net.rs`, `crates/faces/src/runtime.rs`; bounded im2col/GEMM, checked ONNX shapes/operators; no external inference runtime; 40 public crops agree within 2.1e-6, one-thread SFace 34β36 ms / AuraFace 233β252 ms, see docs/faces.md) in a background worker and are never applied automatically. Thresholds are starting points calibrated on busts, not yet on live faces+| LR-PREF-PEOPLE | Face recognition | P2 | π‘ | `cmd:faces.enable`, `cmd:faces.models.list`, `cmd:faces.models.inspect`, `cmd:faces.models.install`, `cmd:faces.models.download`, `cmd:faces.models.downloads`, `cmd:faces.models.downloadCancel`, `cmd:faces.models.remove`, `cmd:faces.models.select`, `cmd:dialog.faceModel`, `crates/faces/src/lib.rs`, `crates/ui-egui/src/panels/faces.rs` | Settings βΈ Faces: an off-by-default toggle and the face model list. Models are opt-in and never bundled, the 232 KB YuNet detector included. Press Download (terms first; then a pinned address, size and SHA-256 checked, fetched over pure-Rust https with `lightcraft-fetch`), or add any `.onnx` by picking or dropping it: it is recognised by hash or described from its shape, shows its licence terms and training-data note, runs a self-test, and installs only after an "I accept" box; an installed model is chosen and recognition switched on at once (the newest wins, each model keeps its own embedding cache). Non-commercial models are add-by-file only, never offered for download. Suggestions of names run on the shared pure-Rust CPU interpreter (`crates/faces/src/net.rs`, `crates/faces/src/runtime.rs`; bounded im2col/GEMM, checked ONNX shapes/operators; no external inference runtime; 40 public crops agree within 2.1e-6, one-thread SFace 34β36 ms / AuraFace 233β252 ms, see docs/faces.md) in a background worker and are never applied automatically. Thresholds are starting points calibrated on busts, not yet on live faces; the Recognise faces switch is off until a recognition model is chosen and installed (`faces.enable {enabled: true}` refuses otherwise; removing the last recogniser switches it off), issue #678 || LR-PREF-WATERMARK | Watermark settings | P1 | β | `cmd:export.savePreset`, `crates/ui-egui/src/panels/dialogs.rs` | set in the Export dialog; kept with Export with Previous and in saved export presets || LR-PREF-SHORTCUTS | Shortcut customisation | β | β | `cmd:app.setShortcut`, `cmd:app.resetShortcuts`, `crates/ui-egui/src/panels/keymap.rs` | an extra (the reference app has no keymap editor): Help βΈ Keyboard Shortcuts (β/) lists every command; click a shortcut and press the new keys (Esc cancels), Γ removes, βΊ restores, Reset All; a key another command had moves over; saved in `ui.json`; native menu accelerators follow. Rating/label digits and secondary keys are listed read-only and yield to a key given to a command || LR-PREF-TECHPREVIEW | Early-access toggles | P2 | β¬ | | |