Tests: reuse the CPU adjustment mask matrix

This commit is contained in:
Dan committed 2026-11-30 21:45:50 +00:00
1 parent b47c7afb04
commit 796bfedfdd
1 file changed
+12 -16
@@ -194,6 +194,12 @@ fn preview_layer_composites_on_the_gpu_like_the_command() {
for selection in [false, true] {
let (doc, target) = document(mode, depth, selection);
for (kind_index, kind) in photocraft_ui_egui::adjust_editors::KINDS.into_iter().enumerate() {
// Keep every shader at every mode and depth, sampling both mask
// paths. The CPU test preview_composite_matches_the_destructive_command
// already compares all combinations; the full GPU sweep keeps them too.
if !full_sweep && selection != (kind_index + depth_index).is_multiple_of(2) {
continue;
}
let params = sample(kind);
let preview = match preview_document(&doc, target, kind, &params) {
Ok(p) => p,
@@ -210,28 +216,18 @@ fn preview_layer_composites_on_the_gpu_like_the_command() {
// The GPU holds 16- and 32-bit layers as half floats: Threshold and Posterize
// may flip a few pixels sitting right at a step (1 % allowed).
let skip = if matches!(kind, "threshold" | "posterize") && depth != SampleType::U8 { (b.width() * b.height()) as usize / 100 } else { 0 };
// The selection is a mask on the same preview layer and does not change
// the adjustment shader. Keep every shader at every mode and depth, with
// both mask paths represented there. The full sweep crosses the mask
// axis with every shader on the GPU.
let check_gpu = full_sweep || selection == (kind_index + depth_index).is_multiple_of(2);
let on_gpu = render_to_vec(&mut comp, &device, &queue, &preview, b).unwrap_or_else(|e| panic!("{what}: {e:?}"));
let on_cpu = photocraft_compose::render(&preview, b).into_px();
let d = max_diff(&on_gpu, &on_cpu, skip);
assert!(d <= tol_gpu, "{what}: GPU vs CPU {:.2}/255", d * 255.0);
let mut s = photocraft_engine::Session::new();
s.add_document(doc.clone(), None);
s.select_layer(target).unwrap();
s.execute(&format!("image.adjustments.{kind}"), params).unwrap();
let cmd = photocraft_compose::render(&s.active().unwrap().doc, b).into_px();
if check_gpu {
let on_gpu = render_to_vec(&mut comp, &device, &queue, &preview, b).unwrap_or_else(|e| panic!("{what}: {e:?}"));
let d = max_diff(&on_gpu, &on_cpu, skip);
assert!(d <= tol_gpu, "{what}: GPU vs CPU {:.2}/255", d * 255.0);
let d = max_diff(&on_gpu, &cmd, skip);
worst = worst.max(d);
assert!(d <= tol_cmd, "{what}: GPU preview vs command {:.2}/255", d * 255.0);
} else {
let d = max_diff(&on_cpu, &cmd, skip);
assert!(d <= tol_cmd, "{what}: CPU preview vs command {:.2}/255", d * 255.0);
}
let d = max_diff(&on_gpu, &cmd, skip);
worst = worst.max(d);
assert!(d <= tol_cmd, "{what}: GPU preview vs command {:.2}/255", d * 255.0);
}
}
}