Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 5 additions & 1 deletion apps/lightcraft-web/src/wire.rs
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,11 @@ mod tests {
let mut core = WorkerCore::default();
assert_eq!(core.needs_original(&wire), None, "demo scenes are generated");
let a = core.render(&wire, None).unwrap();
let b = job.run().rendered.unwrap();
// The worker uses the CPU. A native thumbnail job may use an already initialized GPU,
// so exact serialization parity must use the engine's CPU reference (#3778), regardless
// of test order. The window test above separately checks native CPU/GPU equivalence.
let source = job.source.load_source().unwrap();
let b = lightcraft_engine::pipeline::render(&source.image, &source.info_or(job.info), &job.settings, &job.request);
assert_eq!((a.image.width, a.image.height), (b.image.width, b.image.height));
assert_eq!(a.image.data, b.image.data);
assert_eq!(a.histogram, b.histogram);
Expand Down
3 changes: 3 additions & 0 deletions contributors/people.toml
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,6 @@ sync_github_name = true
[people.Peaperfish]
real_name = "Yule Wang"
display_name = "Brian Wang"

[people.nkovanen]
sync_github_name = true
19 changes: 16 additions & 3 deletions crates/gpu/tests/it/equivalence.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,22 @@ fn check_v3_luminance_cutoff(chroma: f32, pixel: [f32; 3], expected: [u8; 4]) {
let cpu = render(&src, &info, &s, &req).image;
let gpu = lightcraft_gpu::try_render(&src, &info, &s, &req, None).expect("GPU render without CPU fallback").image;
for image in [&cpu, &gpu] {
assert!(image.data.iter().all(|p| *p == image.data[0]));
for (actual, expected) in image.data[0].into_iter().zip(expected) {
assert!(actual.abs_diff(expected) <= 1, "chroma {chroma}: {:?}, expected {expected}", image.data[0]);
// A flat fractional color repeats the 8×8 Bayer tile, within adjacent byte values.
for pixel in &image.data {
assert_eq!(pixel[3], 255);
for (actual, expected) in pixel.iter().copied().zip(expected) {
assert!(actual.abs_diff(expected) <= 1, "chroma {chroma}: {pixel:?}, expected {expected}");
}
}
for channel in 0..3 {
let lo = image.data.iter().map(|p| p[channel]).min().unwrap();
let hi = image.data.iter().map(|p| p[channel]).max().unwrap();
assert!(hi - lo <= 1, "chroma {chroma}: channel {channel} spans {lo}..{hi}");
}
for y in 0..image.height {
for x in 0..image.width {
assert_eq!(image.get(x, y), image.get(x % 8, y % 8), "chroma {chroma}: Bayer tile at {x},{y}");
}
}
}
let (_, max, _) = diff(&cpu, &gpu);
Expand Down
9 changes: 7 additions & 2 deletions crates/gpu/tests/mask_geometry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,11 @@ fn luma(img: &Rgba8, i: usize) -> f64 {
(p[0] as f64 + p[1] as f64 + p[2] as f64) / 3.0
}

/// Match the CPU geometry test: exclude the one-level quantization difference from centroid weights.
fn above_dither(d: f64) -> f64 {
(d - 1.5).max(0.0)
}

fn centroid(w: usize, weights: impl Iterator<Item = f64>) -> (f64, f64) {
let (mut sx, mut sy, mut n) = (0.0, 0.0, 0.0);
for (i, v) in weights.enumerate() {
Expand Down Expand Up @@ -140,9 +145,9 @@ fn masks_stay_on_the_content_under_every_geometry_change_on_the_gpu() {
let plain = on_gpu(&src, &unmasked, None);
// (where the marked photo differs from an unmarked one: a warp leaves light blank canvas)
let bare = on_gpu(&Arc::new(marked(false)), &unmasked, None);
let mark = centroid(plain.width, (0..plain.data.len()).map(|i| (luma(&plain, i) - luma(&bare, i)).max(0.0)));
let mark = centroid(plain.width, (0..plain.data.len()).map(|i| above_dither(luma(&plain, i) - luma(&bare, i))));
for (how, m) in [("fresh", on_gpu(&src, &s, None)), ("cached", on_gpu(&src, &s, Some(&cache)))] {
let at = centroid(m.width, (0..m.data.len()).map(|i| (luma(&m, i) - luma(&plain, i)).max(0.0)));
let at = centroid(m.width, (0..m.data.len()).map(|i| above_dither(luma(&m, i) - luma(&plain, i))));
let d = ((at.0 - mark.0).powi(2) + (at.1 - mark.1).powi(2)).sqrt();
assert!(d < 2.0, "{name} after {what} ({how}): the mask's effect is at {at:?}, the mark at {mark:?}");
}
Expand Down