craft-develop tests: capped bad-pixel list on a small buffer, fewer tile draws, sampled cancel polls

This commit is contained in:
aiongg committed 2026-11-24 19:48:59 +00:00
1 parent cbe6812a02
commit 4d13bda621
4 files changed
+27 -15

No files matched your search

+4 -1
View File
@@ -116,7 +116,10 @@ mod tests {
assert!(matches!(complete_with(w, h, 1, &img, &hole, &p, &count), Ok(Some(_))));
let total = polls.load(Ordering::Relaxed);
assert!(total > 8, "the scene polls in the workers too: {total}");
for nth in 0..total {
// Cancelling at the first, a quarter, the middle, three quarters and the last polls, workers' polls included.
let mut picks = vec![0, 1, 2, total / 4, total / 2, 3 * total / 4, total - 3, total - 2, total - 1];
picks.dedup();
for nth in picks {
let polls = AtomicUsize::new(0);
let once = || polls.fetch_add(1, Ordering::Relaxed) == nth;
assert_eq!(complete_with(w, h, 1, &img, &hole, &p, &once), Err(Cancelled), "poll {nth} of {total}");
+9 -3
View File
@@ -100,6 +100,12 @@ fn op_cost(op: &Opcode, w: usize, h: usize, cpp: usize) -> usize {
}
pub fn apply_list(list: &[Opcode], buf: &mut [f32], w: usize, h: usize, cpp: usize, cfa: Option<&Cfa>, scale: f32) {
apply_list_capped(list, buf, w, h, cpp, cfa, scale, MAX_BAD_PIXELS);
}
/// [`apply_list`] with each bad-pixel opcode repairing at most `max_bad_pixels` pixels.
#[allow(clippy::too_many_arguments)]
fn apply_list_capped(list: &[Opcode], buf: &mut [f32], w: usize, h: usize, cpp: usize, cfa: Option<&Cfa>, scale: f32, max_bad_pixels: usize) {
let mut budget = w.saturating_mul(h).saturating_mul(cpp).max(1).saturating_mul(MAX_LIST_PASSES);
for op in list {
let cost = op_cost(op, w, h, cpp);
@@ -175,17 +181,17 @@ pub fn apply_list(list: &[Opcode], buf: &mut [f32], w: usize, h: usize, cpp: usi
Opcode::FixBadPixelsConstant { constant, .. } => {
let c = (*constant as f64 / 65535.0 * scale as f64) as f32;
let bad: Vec<(usize, usize)> =
(0..h).flat_map(|y| (0..w).map(move |x| (x, y))).filter(|&(x, y)| cpp == 1 && buf[y * w + x] == c).take(MAX_BAD_PIXELS).collect();
(0..h).flat_map(|y| (0..w).map(move |x| (x, y))).filter(|&(x, y)| cpp == 1 && buf[y * w + x] == c).take(max_bad_pixels).collect();
fix_pixels(buf, w, h, cpp, cfa, &bad);
}
Opcode::FixBadPixelsList { points, rects, .. } => {
let mut bad: Vec<(usize, usize)> =
points.iter().map(|&(r, c)| (c as usize, r as usize)).filter(|&(x, y)| x < w && y < h).take(MAX_BAD_PIXELS).collect();
points.iter().map(|&(r, c)| (c as usize, r as usize)).filter(|&(x, y)| x < w && y < h).take(max_bad_pixels).collect();
'rects: for r in rects {
let [t, l, b, rr] = r.map(|v| v as usize);
for y in t..b.min(h) {
for x in l..rr.min(w) {
if bad.len() >= MAX_BAD_PIXELS {
if bad.len() >= max_bad_pixels {
break 'rects;
}
bad.push((x, y));
+6 -6
View File
@@ -117,15 +117,15 @@ fn map_table_raw_scale_and_bad_pixels() {
/// A mosaic equal to the bad-pixel constant, or one rectangle over the whole image, used to list every pixel as
/// bad: w × h entries (plus a set of them), tens of GB at the decoder's size limit. Here the rows between a good
/// first row (500) and a good last row (900) are bad: 2052 rows of 2048 pixels, four rows more than the 1 << 22
/// cap. Row 1, within the cap, is repaired from the first row; the second-last row, past the cap, must be left
/// as it is (uncapped, it was rewritten from the last row).
/// first row (500) and a good last row (900) are bad: 8 rows of 64 pixels, four rows more than the cap of 256 the
/// test passes. Row 1, within the cap, is repaired from the first row; the second-last row, past the cap, must be
/// left as it is (uncapped, it was rewritten from the last row).
fn assert_bad_pixels_capped(op: Opcode) {
let (w, h) = (2048, 2054);
let (w, h) = (64, 10);
let mut buf = vec![0.0f32; w * h];
buf[..w].fill(500.0);
buf[(h - 1) * w..].fill(900.0);
apply_list(&[op], &mut buf, w, h, 1, None, 65535.0);
apply_list_capped(&[op], &mut buf, w, h, 1, None, 65535.0, 256);
assert!(buf[w..2 * w].iter().all(|&v| v == 500.0), "row 1 (within the cap) not repaired: {:?}", &buf[w..w + 4]);
let past = &buf[(h - 2) * w..(h - 1) * w];
assert!(past.iter().all(|&v| v == 0.0), "a row past the cap was rewritten: {:?}", &past[..4]);
@@ -139,7 +139,7 @@ fn bad_pixels_constant_is_capped() {
#[test]
fn bad_pixels_list_is_capped_inside_a_rectangle() {
// top, left, bottom, right: every row but the first and the last
assert_bad_pixels_capped(Opcode::FixBadPixelsList { bayer_phase: 0, points: vec![], rects: vec![[1, 0, 2053, 2048]] });
assert_bad_pixels_capped(Opcode::FixBadPixelsList { bayer_phase: 0, points: vec![], rects: vec![[1, 0, 9, 64]] });
}
#[test]
+8 -5
View File
@@ -104,8 +104,8 @@ fn small_render_is_the_downscaled_reference() {
for (size, rough) in [(0.0, 50.0), (25.0, 50.0), (100.0, 50.0), (25.0, 0.0), (25.0, 100.0)] {
let t = tile_of(size, rough);
for k in [2usize, 4, 8] {
let full = patch(&t, REF_LONG, 120 * k, 0);
let n = 120;
let n = 48;
let full = patch(&t, REF_LONG, n * k, 0);
let down: Vec<f32> = (0..n * n)
.map(|q| {
let (x, y) = (q % n, q / n);
@@ -388,7 +388,9 @@ fn a_drag_takes_the_last_tile_while_the_next_is_drawn() {
let (seed, fresh) = (0x0d4a_0001, 0x0d4a_0002);
let (a, b) = (CrystalLook::new(30.0, 50.0), CrystalLook::new(31.0, 50.0));
let exact = |look: CrystalLook, seed: u32| patch(&CrystalTile::new(look, seed).expect("tile"), REF_LONG, 32, 0);
let drawing = std::time::Instant::now();
let first = tile(a, seed, true).expect("tile");
eprintln!("DIAG crystal tile at size 30: {:?}", drawing.elapsed());
assert_eq!(first.look, a);
let stand_in = tile(b, seed, false).expect("tile");
assert_eq!(stand_in.look, a, "the draft waited for its tile");
@@ -402,8 +404,9 @@ fn a_drag_takes_the_last_tile_while_the_next_is_drawn() {
assert!(std::time::Instant::now() < deadline, "the background tile never arrived");
std::thread::sleep(std::time::Duration::from_millis(5));
};
assert_eq!(patch(&drawn, REF_LONG, 32, 0), exact(b, seed));
assert_eq!(patch(&tile(b, seed, true).expect("tile"), REF_LONG, 32, 0), exact(b, seed));
let exact_b = exact(b, seed);
assert_eq!(patch(&drawn, REF_LONG, 32, 0), exact_b);
assert_eq!(patch(&tile(b, seed, true).expect("tile"), REF_LONG, 32, 0), exact_b);
// nothing drawn for this seed: nothing to stand in, the draft draws it
assert_eq!(patch(&tile(a, fresh, false).expect("tile"), REF_LONG, 32, 0), exact(a, fresh));
}
@@ -474,7 +477,7 @@ fn renders_that_miss_a_tile_together_draw_it_once() {
static OWN: Cache = Mutex::new(Vec::new());
const N: usize = 8;
// the first render's draw waits for the other seven to miss the tile too
const SEEDS: u32 = 40;
const SEEDS: u32 = 5;
HOLDS.lock().unwrap_or_else(PoisonError::into_inner).push((std::ptr::from_ref(&OWN) as usize, N - 1, SEEDS as usize));
let look = CrystalLook::new(0.0, 50.0);
for seed in 0x0d4a_1000..0x0d4a_1000 + SEEDS {