diff --git a/crates/algo/examples/bench_filters2.rs b/crates/algo/examples/bench_filters2.rs index c646bac808..e90799d60c 100644 --- a/crates/algo/examples/bench_filters2.rs +++ b/crates/algo/examples/bench_filters2.rs @@ -12,6 +12,10 @@ use photocraft_color::PixelFormat; use photocraft_geom::Rect; use photocraft_raster::Surface; +/// Rows per band when hashing an output region: the hash sequence must match hashing the whole +/// region, so bands walk `y` in order, but the buffer stays a few MB instead of the layer's 384 MB. +const HASH_BAND_ROWS: usize = 64; + fn main() { let a: Vec = std::env::args().skip(1).collect(); let flag = |k: &str| a.iter().position(|v| v == k); @@ -95,11 +99,21 @@ fn main() { let out = apply(&s, &p, area, r, None); let ms = t.elapsed().as_secs_f64() * 1e3; samples.push(ms); - // FNV-1a over the output samples: "same pixels" as a comparison, not a promise. + // FNV-1a 64 over the output's raw f32 bytes, in row order: "same pixels" as a + // comparison, not a promise. Hashing byte bands of rows keeps the sequence identical + // to hashing the whole region while holding a few MB instead of the layer's 384 MB. + let mut hash = 0xcbf29ce484222325u64; let mut buf = Vec::new(); - out.read_region_into(r, &mut buf); - let hash = buf.iter().fold(0xcbf29ce484222325u64, |h, v| (h ^ v.to_bits() as u64).wrapping_mul(0x100000001b3)); - eprintln!("HASH {} {hash:016x}", p.label()); + for y in (r.y0..r.y1).step_by(HASH_BAND_ROWS) { + let band = Rect::new(r.x0, y, r.x1, (y + HASH_BAND_ROWS as i32).min(r.y1)); + out.read_region_into(band, &mut buf); + for v in &buf { + for byte in v.to_bits().to_le_bytes() { + hash = (hash ^ u64::from(byte)).wrapping_mul(0x100000001b3); + } + } + } + eprintln!("HASH {name} {hash:016x}"); drop(out); } let mut sorted = samples.clone();