GPU tests allow a level of 8-bit dither (#3789)

The CPU tests got this in #3779. These only run with a real GPU, so
hosted CI never showed them failing.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
FredApps
2026-11-05 11:30:38 +01:00
committed by GitHub
co-authored by Claude Opus 5.5
parent bf96a5fa79
commit b79f9971a3
2 changed files with 9 additions and 3 deletions
+2 -1
View File
@@ -53,7 +53,8 @@ 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]));
// (8-bit output is dithered: a flat source varies by a level)
assert!(image.data.iter().all(|p| p.iter().zip(image.data[0]).all(|(a, b)| a.abs_diff(b) <= 1)));
for (actual, expected) in image.data[0].into_iter().zip(expected) {
assert!(actual.abs_diff(expected) <= 1, "chroma {chroma}: {:?}, expected {expected}", image.data[0]);
}
+7 -2
View File
@@ -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
}
/// A difference between two renders, without the one level of 8-bit dither any pixel can differ by.
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() {
@@ -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:?}");
}