Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
76 commits
Select commit Hold shift + click to select a range
5bcedbe
NEF: measured image area and white level for the Nikon D4
Unemars Oct 10, 2026
b59ffcc
raw: find the saturation plateau despite stray samples above it
TicT4x Oct 10, 2026
e7f8faf
LR-IMP-FORMATS: EOS R5 Mark II crop-mode CR3s develop without a black…
radialmonster Oct 10, 2026
bbcbbeb
LR-EDIT-COPY-PASTE: Enter applies the Copy and Paste Settings dialogs…
bitshiftza Oct 10, 2026
61df5d3
LR-MASK-BRUSH: holding the brush still adds no coverage; flow builds …
bitshiftza Oct 10, 2026
6dca631
LR-IMP-CAMERA-COVERAGE: SRF and DSLR-A100 raws open again (#702)
AlexChambers Oct 10, 2026
0bd3f37
LR-BEHAV-GPU: no indirect-call validation pipeline, which Intel Metal…
radialmonster Oct 10, 2026
19833e5
MENU-HELP-SYSINFO: System Info, All Metadata and What's New end with …
bitshiftza Oct 10, 2026
9da719c
LR-EDIT-RESET: Reset Edits returns a raw to its import defaults, shar…
radialmonster Oct 10, 2026
7f96696
Fix #714: mouse wheel zooms the loupe around the pointer
PierrunoYT Oct 10, 2026
732a2f0
Test: wheel zoom in the loupe with and without Ctrl
PierrunoYT Oct 10, 2026
1064e98
Merge origin/main into enter-applies-copy-paste (parity rows applied …
bitshiftza Oct 10, 2026
3cd471b
Smooth the plain mouse-wheel zoom like Ctrl+wheel
PierrunoYT Oct 10, 2026
dd73753
Merge origin/main into info-dialogs-close (no conflicts; MENU-HELP-SY…
bitshiftza Oct 10, 2026
a3c3365
Merge origin/main into brush-hold-hardens (clean merge; tracker edit …
bitshiftza Oct 10, 2026
e1267a7
UI-MODAL: block background input while application dialogs are open
shurkanTwo Oct 10, 2026
fe92e84
UI-PILL: keep rating and flag buttons inside their pill
shurkanTwo Oct 10, 2026
bc5c561
LR-VIEW-BEFOREAFTER: zoomed side by side / stacked views stay in thei…
PiMinusMax Oct 10, 2026
0adcb21
LR-CROP-FLIP: Flip H / Flip V show in the crop tool
PiMinusMax Oct 10, 2026
0067879
KEY-ESC: Esc leaves the crop tool before leaving Detail, and a text f…
PiMinusMax Oct 10, 2026
5a975d0
LR-IMP-FORMATS: CR3 CRX quantization 44 (QP 168) decodes, continuing …
radialmonster Oct 10, 2026
8e9c5af
LR-EDIT-COLOR-WB-PICKER: the selector button does what W does
PiMinusMax Oct 10, 2026
a940dab
web: stop the release zip shipping Cargo build artifacts
eliets2 Oct 10, 2026
7ce13cf
LR-META-EXIF-FULL: All Metadata shows the raw image's Compression, NE…
radialmonster Oct 10, 2026
a67d571
LR-VIEW-COMPARE: a filmstrip click shows the photo in Compare
PiMinusMax Oct 10, 2026
8f3f168
LR-META-EXIF-FULL: raw sensor IFD Compression 7 reads Lossless JPEG (…
radialmonster Oct 10, 2026
40d7b86
LR-VIEW-BEFOREAFTER: click tools work in the Before view of side by s…
PiMinusMax Oct 10, 2026
6807421
LR-CROP-STRAIGHTEN: the rotate pointer faces away from its side of th…
john01px2022 Oct 11, 2026
7d27cf8
LR-CROP-STRAIGHTEN: test the rotate pointer off all four crop corners
john01px2022 Oct 11, 2026
d76a412
LR-PROF-CAMERACOLOR: near-black pixels no longer turn white in the ca…
PiMinusMax Oct 11, 2026
dac0d4c
test(engine): LRC-LIB-LIBFOLDERS normalize sync fixture paths
THEtheChad Oct 11, 2026
aec298c
test(engine): LRC-LIB-LIBFOLDERS cover mixed Windows separators
THEtheChad Oct 11, 2026
21d71fe
LR-HDR-EXPORT: HDR renders keep the camera tone curve in the midtones
robmdunn Oct 11, 2026
d9d1a5a
fix(ui): show completion for library maintenance and Auto Sync (#875)
Ni-zav Oct 11, 2026
38756b8
fix(query): saturate pagination values in 32-bit web builds
Ni-zav Oct 11, 2026
385348b
LR-PROF-CAMERACOLOR: the camera-look guard blends in smoothly instead…
PiMinusMax Oct 11, 2026
ad3c731
Tests: hold the MCP export-cancel test's export after its first photo…
ingolfteetz Oct 10, 2026
2c85203
Dropping photos with XMP sidecars no longer imports the sidecars as p…
MarekSpodBiedry Oct 11, 2026
353c1cf
UI-PILL: retain padding fix with upstream toolbar layout
shurkanTwo Oct 11, 2026
a7382aa
Masking: Color Range "Pick" samples the photo
emmertex Oct 11, 2026
72a7cd8
Merge PR #792
claude Oct 11, 2026
b038c01
Merge PR #829
claude Oct 11, 2026
14679de
Merge PR #885
claude Oct 11, 2026
95662cf
Merge PR #883
claude Oct 11, 2026
f987493
Merge PR #877
claude Oct 11, 2026
09461d0
Merge PR #873
claude Oct 11, 2026
f30ad32
Merge PR #858
claude Oct 11, 2026
5bbce8b
Merge PR #855
claude Oct 11, 2026
72b02c6
Merge PR #817
claude Oct 11, 2026
68f75cc
Merge PR #809
claude Oct 11, 2026
11dd3bd
Merge PR #803
claude Oct 11, 2026
5abc39a
Merge PR #799
claude Oct 11, 2026
9ecd330
Merge PR #779
claude Oct 11, 2026
b23b206
Merge PR #772
claude Oct 11, 2026
0a46f61
Merge PR #767
claude Oct 11, 2026
bda8569
Merge PR #760
claude Oct 11, 2026
d5d9daa
Merge PR #759
claude Oct 11, 2026
8f42f4a
Merge PR #753
claude Oct 11, 2026
f8c01f7
Merge PR #748
claude Oct 11, 2026
f9919ac
Merge PR #785
claude Oct 11, 2026
f4d8a42
Merge PR #848
claude Oct 11, 2026
f9f3fbe
Merge PR #774
claude Oct 11, 2026
aa48f6f
Merge PR #935
claude Oct 11, 2026
5350a8e
Merge PR #773
claude Oct 11, 2026
69f1176
Merge PR #754
claude Oct 11, 2026
dba63bc
Merge PR #747
claude Oct 11, 2026
0e4b52e
Merge PR #746
claude Oct 11, 2026
2bc3326
Issue #793: the last two mentions of target/web point at target/web-s…
claude Oct 11, 2026
170f395
Merge PR #831
claude Oct 11, 2026
69b90ee
LR-META-EXIF-FULL: tags.rs back to LF line endings (#831 mixed in CRLF)
claude Oct 11, 2026
805a15a
Merge PR #943
claude Oct 11, 2026
bb4cdee
Merge PR #957
claude Oct 11, 2026
a33dc70
fix: EXIF values under histogram run together (#913)
squareSphere29 Oct 11, 2026
761a91c
fix: EXIF values under histogram run together (#913)
squareSphere29 Oct 11, 2026
e2a38c2
Masking: keep mask_overlay's doc comment on mask_overlay (#957 put th…
claude Oct 11, 2026
47fe7f7
Batch 26: cargo fmt over the merged PRs
claude Oct 11, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apps/lightcraft-web/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! LightCraft in the browser: the same egui UI as the desktop app, compiled to WASM.
//!
//! Build with `cargo xtask web` (→ `target/web/`), then serve that folder over HTTP (see
//! Build with `cargo xtask web` (→ `target/web-site/`), then serve that folder over HTTP (see
//! `docs/web.md`). Differences from the desktop host:
//! - the library lives in browser storage (OPFS, or IndexedDB where OPFS can't be written from the
//! main thread): catalog journal, presets, view state and prefs are mirrored in memory and
Expand Down
12 changes: 12 additions & 0 deletions apps/lightcraft/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ fn window_wgpu_options() -> eframe::egui_wgpu::WgpuConfiguration {
if let eframe::egui_wgpu::WgpuSetup::CreateNew(n) = &mut c.wgpu_setup {
n.instance_descriptor.backends = lightcraft_engine::gpu::backend::window_backends();
n.instance_descriptor.backend_options = lightcraft_engine::gpu::backend::backend_options();
// no indirect-call validation pipeline: Intel Metal fails to compile it and the window never opens (#250)
n.instance_descriptor.flags = lightcraft_engine::gpu::backend::instance_flags_from_env(n.instance_descriptor.flags);
}
c
}
Expand Down Expand Up @@ -1086,6 +1088,16 @@ mod tests {
}
}

/// Issue #250: the window's device is created without wgpu's indirect-call validation pipeline,
/// which Intel Macs' Metal compiler fails to build (the device was lost, the window never opened).
#[test]
fn window_has_no_indirect_call_validation_pipeline() {
let eframe::egui_wgpu::WgpuSetup::CreateNew(n) = window_wgpu_options().wgpu_setup else { panic!("expected CreateNew") };
if std::env::var_os("WGPU_VALIDATION_INDIRECT_CALL").is_none() {
assert!(!n.instance_descriptor.flags.contains(eframe::wgpu::InstanceFlags::VALIDATION_INDIRECT_CALL));
}
}

/// Issue #234: Windows opens links with the URL protocol handler (the default browser), not
/// File Explorer, and passes the whole map link, `?`, `&` and `#` included, as one argument.
#[test]
Expand Down
85 changes: 84 additions & 1 deletion crates/engine/src/camera_preview.rs
Original file line number Diff line number Diff line change
Expand Up @@ -833,6 +833,22 @@ fn to_prophoto() -> Mat3 {
PROPHOTO.from_xyz().mul(&bradford(D65, D50)).mul(&REC2020.to_xyz())
}

/// [`HueSat::apply`] restores the luminance in full only if the table kept at least this share of it. A colour
/// the table darkens to [`NO_LUMINANCE_KEPT`] or less (only near-black noise, whose channels go negative) keeps
/// its colour; in between the two are blended, so noisy shadows show no step.
const MIN_LUMINANCE_KEPT: f32 = 0.25;
const NO_LUMINANCE_KEPT: f32 = 0.15;

/// How much of the table's colour a pixel gets when the table kept `share` of its luminance: 0 up to
/// [`NO_LUMINANCE_KEPT`], 1 from [`MIN_LUMINANCE_KEPT`], a smoothstep between.
fn restore_weight(share: f32) -> f32 {
if !share.is_finite() {
return 0.0;
}
let t = ((share - NO_LUMINANCE_KEPT) / (MIN_LUMINANCE_KEPT - NO_LUMINANCE_KEPT)).clamp(0.0, 1.0);
t * t * (3.0 - 2.0 * t)
}

/// A fitted [`CameraLook::hue_sat`] table, ready to apply to linear Rec.2020 pixels. It changes
/// hue and saturation only: luminance is restored, the camera tone curve owns it.
pub(crate) struct HueSat<'a> {
Expand All @@ -852,7 +868,19 @@ impl<'a> HueSat<'a> {
let mul = |m: &[[f32; 3]; 3], v: [f32; 3]| -> [f32; 3] { std::array::from_fn(|i| m[i][0] * v[0] + m[i][1] * v[1] + m[i][2] * v[2]) };
let out = mul(&self.from, self.table.apply(mul(&self.to, rgb)));
let (before, after) = (luminance_2020(rgb), luminance_2020(out));
if before > 0.0 && after > 0.0 && out.iter().all(|v| v.is_finite()) { out.map(|v| v * before / after) } else { rgb }
// restoring the luminance divides by the table's: near black, where noise makes some channels
// negative, the table can bring it close to 0, and the gain would turn the pixel white (#820)
if before <= 0.0 || after <= 0.0 || !out.iter().all(|v| v.is_finite()) {
return rgb;
}
let w = restore_weight(after / before);
if w >= 1.0 {
return out.map(|v| v * before / after);
}
if w <= 0.0 {
return rgb;
}
std::array::from_fn(|i| rgb[i] + (out[i] * before / after - rgb[i]) * w)
}
}

Expand Down Expand Up @@ -1439,6 +1467,61 @@ mod tests {
assert!(fit_hue_sat(&[], &Mat3::IDENTITY).is_none(), "too few samples");
}

#[test]
fn hue_sat_never_turns_near_black_noise_white() {
// a saturating table, as fitted to high-ISO Sony files; near-black noise with mixed-sign channels
let table = HsvTable { hue_divisions: 4, sat_divisions: 2, val_divisions: 1, data: vec![[10.0, 1.5, 1.0]; 8], srgb_value: false };
let hue_sat = HueSat::new(&table).unwrap();
let mut seed = 0x9e37_79b9_7f4a_7c15u64;
let mut next = || {
seed ^= seed << 13;
seed ^= seed >> 7;
seed ^= seed << 17;
(seed >> 11) as f32 / (1u64 << 53) as f32 * 2.0 - 1.0
};
let mut worst = 0.0f32;
for _ in 0..200_000 {
let rgb = [0.002 + 0.004 * next(), 0.002 + 0.004 * next(), 0.002 + 0.004 * next()];
if luminance_2020(rgb) <= 0.0 {
continue;
}
let out = hue_sat.apply(rgb);
let scale = rgb.iter().fold(0.0f32, |m, v| m.max(v.abs()));
worst = worst.max(out.iter().fold(0.0f32, |m, v| m.max(v.abs())) / scale);
}
assert!(worst < 20.0, "a near-black pixel came out {worst}× its largest channel");
}

#[test]
fn hue_sat_restore_weight_blends_smoothly_between_the_thresholds() {
assert_eq!(restore_weight(0.0), 0.0);
assert_eq!(restore_weight(NO_LUMINANCE_KEPT), 0.0);
assert_eq!(restore_weight(MIN_LUMINANCE_KEPT), 1.0);
assert_eq!(restore_weight(1.0), 1.0);
assert_eq!(restore_weight(f32::NAN), 0.0);
// monotonic and without a step: neighbouring shares 0.001 apart differ by little
let mut last = 0.0f32;
for i in 0..=400 {
let w = restore_weight(i as f32 * 0.001);
assert!(w >= last && w - last < 0.02, "step at {}: {last} → {w}", i as f32 * 0.001);
last = w;
}
}

#[test]
fn hue_sat_keeps_colours_the_table_leaves_bright_exactly_as_before() {
// the blend only touches colours whose luminance the table cut below MIN_LUMINANCE_KEPT
let table = HsvTable { hue_divisions: 4, sat_divisions: 2, val_divisions: 1, data: vec![[10.0, 1.5, 1.0]; 8], srgb_value: false };
let hue_sat = HueSat::new(&table).unwrap();
let mul = |m: &[[f32; 3]; 3], v: [f32; 3]| -> [f32; 3] { std::array::from_fn(|i| m[i][0] * v[0] + m[i][1] * v[1] + m[i][2] * v[2]) };
for rgb in [[0.4, 0.2, 0.1], [0.05, 0.3, 0.2], [0.18, 0.18, 0.18], [0.6, 0.1, 0.5]] {
let out = mul(&hue_sat.from, table.apply(mul(&hue_sat.to, rgb)));
let (before, after) = (luminance_2020(rgb), luminance_2020(out));
assert!(after >= MIN_LUMINANCE_KEPT * before);
assert_eq!(hue_sat.apply(rgb), out.map(|v| v * before / after));
}
}

fn raw_of(format: RawFormat, make: &str, model: &str, color: lightcraft_raw::ColorData) -> RawImage {
let area = lightcraft_raw::Rect::new(0, 0, 2, 2);
RawImage {
Expand Down
6 changes: 5 additions & 1 deletion crates/engine/src/cmd/develop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,10 +239,14 @@ pub fn specs() -> Vec<CommandSpec> {
let fresh = match look {
Some(l) => (*l).clone(),
None => {
// the photo's built-in defaults (raws: capture sharpening and colour noise
// reduction, embedded lens corrections), as at import, with the white balance
// of its current as-shot reference
let info = s.source_info(id);
let defaults = s.catalog.photo(id).map(|p| p.camera_defaults()).unwrap_or_default();
DevelopSettings {
wb: lightcraft_develop::WhiteBalance { mode: WbMode::AsShot, temp: info.as_shot_temp, tint: info.as_shot_tint },
..Default::default()
..defaults
}
}
};
Expand Down
24 changes: 22 additions & 2 deletions crates/engine/src/cmd/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@ fn photo_arg(s: &Session, p: &Value, c: &str) -> crate::Result<PhotoId> {
}
}

// Catalog queries also run in the 32-bit web build. A narrowing cast wraps
// an out-of-range offset to zero, returning the first page instead of no photos.
fn pagination_usize(value: u64) -> usize {
usize::try_from(value).unwrap_or(usize::MAX)
}

pub fn specs() -> Vec<CommandSpec> {
vec![
cmd!(query "catalog.query", "Query Photos", [], None, "{filter?: Filter, sort?: Sort, offset?, limit?} — omit filter to list the current view", always, |s, p| {
Expand All @@ -69,8 +75,8 @@ pub fn specs() -> Vec<CommandSpec> {
} else {
s.visible_cloned()
};
let off = p.get("offset").and_then(Value::as_u64).unwrap_or(0) as usize;
let lim = p.get("limit").and_then(Value::as_u64).unwrap_or(200) as usize;
let off = pagination_usize(p.get("offset").and_then(Value::as_u64).unwrap_or(0));
let lim = pagination_usize(p.get("limit").and_then(Value::as_u64).unwrap_or(200));
let items: Vec<Value> = ids.iter().skip(off).take(lim).filter_map(|id| s.catalog.photo(*id)).map(|p| photo_summary(p)).collect();
Ok(json!({"total": ids.len(), "photos": items}))
}),
Expand Down Expand Up @@ -237,3 +243,17 @@ pub fn specs() -> Vec<CommandSpec> {
}),
]
}

#[cfg(test)]
mod pagination_tests {
use super::*;

#[test]
fn offsets_and_limits_saturate_instead_of_wrapping_on_wasm() {
assert_eq!(pagination_usize(0), 0);
assert_eq!(pagination_usize(200), 200);
assert_eq!(pagination_usize(u64::MAX), usize::MAX);
#[cfg(target_pointer_width = "32")]
assert_eq!(pagination_usize(u64::from(u32::MAX) + 1), usize::MAX);
}
}
2 changes: 1 addition & 1 deletion crates/engine/src/media.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ impl SettingsHashes {
}

/// Bump when the pipeline's output changes, to invalidate cached thumbnails.
pub const RENDER_CACHE_VERSION: u64 = 42;
pub const RENDER_CACHE_VERSION: u64 = 50;

/// Thumbnails render at one of these long edges (so window/cell size changes reuse the cache).
pub const THUMB_SIZES: [usize; 4] = [128, 256, 384, 512];
Expand Down
27 changes: 27 additions & 0 deletions crates/engine/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,33 @@ fn changing_one_wb_control_resolves_as_shot_without_stale_tint() {
}
}

/// Reset Edits on a raw goes back to its import defaults, capture sharpening and colour noise
/// reduction included (#763: reset left both at 0 while import sets 40 / 25); a rendered file
/// keeps none.
#[test]
fn reset_edits_restores_a_raws_import_defaults() {
use lightcraft_catalog::{Photo, PhotoId, Source};
use lightcraft_develop::DevelopSettings;
let mut s = demo();
for (id, format, raw) in [(200u64, "NEF", true), (201, "JPG", false)] {
let name = format!("p{id}.{format}");
let mut p = Photo::new(PhotoId(id), Source::File { path: name.clone() }, &name, format, 16, 16, "");
if raw {
p.as_shot_wb = Some((5200.0, 4.0));
p.develop = std::sync::Arc::new(DevelopSettings::for_raw(5200.0, 4.0));
}
s.catalog.apply(lightcraft_catalog::Op::AddPhoto { photo: Box::new(p) }).unwrap();
}
for (id, want) in [(200, (40.0, 25.0)), (201, (0.0, 0.0))] {
s.execute("library.select", &json!({"ids": [id], "active": id})).unwrap();
s.execute("develop.set", &json!({"control": "detail.sharpenAmount", "value": 90})).unwrap();
s.execute("develop.set", &json!({"control": "detail.nrColor", "value": 70})).unwrap();
s.execute("develop.reset", &json!({})).unwrap();
let d = active_dev(&s);
assert_eq!((d.detail.sharpen_amount, d.detail.nr_color), want, "photo {id}");
}
}

#[test]
fn demo_library_loads() {
let mut s = demo();
Expand Down
66 changes: 65 additions & 1 deletion crates/engine/src/tests_sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ impl Scratch {
Scratch(dir)
}
fn path(&self, rel: &str) -> String {
self.0.join(rel).to_string_lossy().to_string()
// Fixtures use `/`; rebuild components so expected paths match the native separators
// returned by directory scans, including for files that have already been removed.
self.0.join(rel).components().collect::<PathBuf>().to_string_lossy().into_owned()
}
}

Expand Down Expand Up @@ -103,6 +105,68 @@ fn an_unchanged_folder_has_no_changes() {
assert!(paths(&r, "new").is_empty() && paths(&r, "missing").is_empty() && paths(&r, "metadata").is_empty(), "{r}");
}

#[cfg(windows)]
#[test]
fn importing_and_synchronizing_with_different_windows_separators_keeps_photo_identity() {
for forward_import in [true, false] {
for import_folder in [true, false] {
let dir = Scratch::new(&format!("separators-{forward_import}-{import_folder}"));
let folder = dir.path("trip");
let a = dir.path("trip/a.png");
let b = dir.path("trip/day1/b.png");
write_png(&a, 1);
write_png(&b, 2);
let spelling = |path: &str, forward: bool| if forward { path.replace('\\', "/") } else { path.to_string() };
let import_path = spelling(&folder, forward_import);
let sync_path = spelling(&folder, !forward_import);
assert_ne!(import_path, sync_path, "exercise distinct Windows path spellings");
let inputs = if import_folder { vec![import_path.clone()] } else { vec![spelling(&a, forward_import), spelling(&b, forward_import)] };
let mut s = Session::new().with_fs();
let imported = s.execute("library.import", &json!({"paths": inputs})).unwrap();
assert_eq!(imported["imported"].as_array().unwrap().len(), 2, "{imported}");
let before = s.execute("catalog.query", &json!({})).unwrap();
let photos = before["photos"].as_array().unwrap();
let a_id = photos.iter().find(|p| p["fileName"] == "a.png").unwrap()["id"].clone();
let b_id = photos.iter().find(|p| p["fileName"] == "b.png").unwrap()["id"].clone();

let duplicate = s.execute("library.import", &json!({"paths": [sync_path]})).unwrap();
assert!(duplicate["imported"].as_array().unwrap().is_empty(), "{duplicate}");
assert_eq!(duplicate["duplicates"].as_array().unwrap().len(), 2, "{duplicate}");
assert_eq!(s.execute("catalog.query", &json!({})).unwrap(), before, "reimport preserves the photos and their ids");

std::fs::remove_file(&b).unwrap();
let c = dir.path("trip/day2/c.png");
write_png(&c, 3);
let changes = scan(&mut s, &sync_path);
assert_eq!(changes["new"].as_array().unwrap().len(), 1, "{changes}");
assert_eq!(Path::new(changes["new"][0]["path"].as_str().unwrap()), Path::new(&c));
assert_eq!(changes["missing"].as_array().unwrap().len(), 1, "{changes}");
assert_eq!(changes["missing"][0]["id"], b_id, "the missing photo keeps its id");
assert!(changes["moved"].as_array().unwrap().is_empty(), "{changes}");

// Switching spelling again must consume the confirmed scan of this same folder.
let synced = s.execute("folder.synchronize", &json!({"path": import_path, "scanned": true, "removeMissing": true})).unwrap();
assert_eq!(
(synced["imported"].as_u64(), synced["removed"].as_u64(), synced["relinked"].as_u64()),
(Some(1), Some(1), Some(0)),
"{synced}"
);
assert!(synced["failed"].as_array().unwrap().is_empty(), "{synced}");
let after = s.execute("catalog.query", &json!({})).unwrap();
let photos = after["photos"].as_array().unwrap();
assert_eq!(photos.len(), 2, "{after}");
assert!(photos.iter().any(|p| p["id"] == a_id && p["fileName"] == "a.png"), "{after}");
assert!(photos.iter().any(|p| p["fileName"] == "c.png" && p["id"] != a_id && p["id"] != b_id), "{after}");
for path in [&import_path, &sync_path] {
let changes = scan(&mut s, path);
for kind in ["new", "missing", "moved", "metadata"] {
assert!(changes[kind].as_array().unwrap().is_empty(), "{path}: {changes}");
}
}
}
}
}

#[test]
fn files_added_to_the_folder_or_a_folder_inside_it_are_new() {
let dir = Scratch::new("new");
Expand Down
30 changes: 30 additions & 0 deletions crates/gpu/src/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,25 @@ pub fn backend_options() -> wgpu::BackendOptions {
o
}

/// wgpu's instance flags for every instance LightCraft creates, from `flags` (wgpu's defaults with its
/// environment variables applied) without `VALIDATION_INDIRECT_CALL`, unless
/// `WGPU_VALIDATION_INDIRECT_CALL` asks for it (any value but `0`). That validation builds an internal
/// compute pipeline when each device is created; Intel Macs' Metal compiler fails on it ("Compiler
/// encountered an internal error"), the device is lost and the window never opens (#250). It only
/// guards indirect draws and dispatches, which neither LightCraft nor egui issue.
pub fn instance_flags(flags: wgpu::InstanceFlags, env: Option<&str>) -> wgpu::InstanceFlags {
if env.is_some_and(|v| v != "0") {
flags | wgpu::InstanceFlags::VALIDATION_INDIRECT_CALL
} else {
flags - wgpu::InstanceFlags::VALIDATION_INDIRECT_CALL
}
}

/// [`instance_flags`] with `WGPU_VALIDATION_INDIRECT_CALL` read from the environment.
pub fn instance_flags_from_env(flags: wgpu::InstanceFlags) -> wgpu::InstanceFlags {
instance_flags(flags, std::env::var("WGPU_VALIDATION_INDIRECT_CALL").ok().as_deref())
}

/// `LIGHTCRAFT_GPU_BACKEND=off`.
pub(crate) fn env_off() -> bool {
env_choice() == BackendChoice::Off
Expand Down Expand Up @@ -195,6 +214,17 @@ pub fn read_init_marker(path: &std::path::Path) -> Option<String> {
#[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::*;

#[test]
Expand Down
2 changes: 2 additions & 0 deletions crates/gpu/src/ctx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,8 @@ impl Gpu {
desc.backends = backends;
// DX12 shaders compile with FXC (issue #471)
desc.backend_options = crate::backend::backend_options();
// no indirect-call validation pipeline: Intel Metal fails to compile it (#250)
desc.flags = crate::backend::instance_flags_from_env(desc.flags);
let instance = wgpu::Instance::new(desc);
let adapter = pollster::block_on(
instance.request_adapter(&wgpu::RequestAdapterOptions { power_preference: wgpu::PowerPreference::HighPerformance, ..Default::default() }),
Expand Down
2 changes: 2 additions & 0 deletions crates/gpu/src/nn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ fn make_device(backends: wgpu::Backends) -> Result<Dev, String> {
desc.backends = backends;
// DX12 shaders compile with FXC (issue #471)
desc.backend_options = crate::backend::backend_options();
// no indirect-call validation pipeline: Intel Metal fails to compile it (#250)
desc.flags = crate::backend::instance_flags_from_env(desc.flags);
let instance = wgpu::Instance::new(desc);
let wanted = std::env::var("LIGHTCRAFT_GPU_ADAPTER").ok().map(|s| s.trim().to_lowercase()).filter(|s| !s.is_empty());
let adapter = match &wanted {
Expand Down
Loading
Loading