bench: hash the output as bytes, in bands, labelled by row

Three fixes to the "same pixels" harness, from review:

* The fold ran one FNV step per `u32`, not one per byte, so it was only
  FNV-shaped. It is now FNV-1a 64 over the sample's little-endian `f32`
  bytes, which is what the published values claim to be and what a reader
  can reproduce with any FNV-1a implementation.
* Reading the whole 6000x4000 RGBA8 region at once allocated 384 MB inside
  the rep loop. The region is now read in 64-row bands; bands walk `y` in
  order and each sample's bytes are folded in order, so the hash sequence is
  identical to hashing the whole region with a few MB held at a time.
* Every Smart Blur row printed the bare `p.label()`, so the three radii were
  indistinguishable and had to be matched by position. It prints `name`,
  which carries the radius.

The hash values in this branch's PR description and in the follow-up doc
were regenerated with the corrected harness; they differ from the earlier
ones because the earlier ones were not FNV-1a.
This commit is contained in:
ebosido444-ai committed 2026-10-31 08:36:44 +03:00
1 parent 4b0442b86a
commit e356260e87
1 file changed
+18 -4
+18 -4
View File
@@ -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<String> = 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();