From 4b28b49cf7d601bec6a5e966106edd2a78257cc3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Wed, 30 Sep 2026 01:46:16 +0300 Subject: [PATCH] lane-av1pixprobe: land the EC_AV1_PIXPROBE rung re-anchored + diffwtd_mask's cast move and its 8/10-bit gate MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The two items lanes/av1cheapwins.report.md §C triaged "land after rebase". A: the env-gated one-sample write probe from lane-av1-ibcwrite @ 25f5c729, re-anchored by hand -- the branch's two mc store hunks no longer attach because those stores now live in reconstruct_mc_rect (lane-perf4 / lane-recoparse reshaped it: row-at-a-time slices, an early residual.is_empty() return, and a w/h block extent with side demoted to the prediction stride). pix_write("mc_copy"/"mc_add", x, y, w, ...) reports w, not the branch's side, because that is what the block=(bx,by)+SIDE field means for a rectangular inter block. Fires on the pinned R5 fixture (sha256 bc699af4..., re-encoded here byte-identically) at px (296,128), three stores one per plane; prints nothing with the variable unset. B: 295dc3fe's u8 cast move in diffwtd_mask plus its 8/10-bit libaom transcription gate. The cast is value-preserving: clamp(0,64) leaves m in {0..=64}, so `as u8` is a no-op on the binding and both uses (forward `m`, inverse `64 - m`, which is 1..=64) emit the same mask byte as the old `m as u8` / `(64 - m) as u8` pair. The gate is the 10-bit coverage diffwtd_mask's (bd - 8) term landed without; adapted to main's blend_masked_compound, whose `subsampled: bool` is now subw/subh. Proven non-vacuous at both depths, including a 10-bit-only round mutation that is inert at 8-bit and still fails the gate. C: the 189-vs-170 intrabc partition defect is recorded, not chased -- and does not reproduce on merged main (the fixture decodes byte-exact vs ffmpeg at 1d47ff54; the measuring tree 37a64d99 is 439 commits stale). The hand-off row carries the original coordinates and numbers plus that caveat, so the next charter re-bisects instead of trusting the coordinates. Report: lanes/av1pixprobe.report.md --- crates/ec-av1/src/decode.rs | 68 +++++++- crates/ec-av1/src/mc.rs | 222 ++++++++++++++++++++++- lanes/av1pixprobe.report.md | 338 ++++++++++++++++++++++++++++++++++++ 3 files changed, 620 insertions(+), 8 deletions(-) create mode 100644 lanes/av1pixprobe.report.md diff --git a/crates/ec-av1/src/decode.rs b/crates/ec-av1/src/decode.rs index a0071f8e..5132fe26 100644 --- a/crates/ec-av1/src/decode.rs +++ b/crates/ec-av1/src/decode.rs @@ -20395,6 +20395,42 @@ struct PlaneBuf<'a> { /// (lane-av1refs: the same "empty slot" case `GOLDEN_FRAME` already /// refused by name, now generic across `LAST2`/`LAST3`/`GOLDEN`/`BWDREF`/ /// `ALTREF2`/`ALTREF`). +// lane-av1pixprobe: env-gated one-sample write probe -- `EC_AV1_PIXPROBE=x,y` +// prints one PIXWRITE line per reconstruction store landing on that sample, +// naming the store site, the value it replaces and the one it leaves. Re-anchored +// from `lane-av1-ibcwrite` @ 25f5c729 onto the main-shape sites (the two mc stores +// now live in `reconstruct_mc_rect`). +static PIXPROBE_ON: std::sync::LazyLock = + std::sync::LazyLock::new(|| std::env::var_os("EC_AV1_PIXPROBE").is_some()); + +static PIXPROBE: std::sync::LazyLock> = std::sync::LazyLock::new(|| { + crate::envflags::var("EC_AV1_PIXPROBE").ok().and_then(|v| { + let (x, y) = v.split_once(',')?; + Some(( + x.trim().parse::().ok()?, + y.trim().parse::().ok()?, + )) + }) +}); + +#[inline] +fn pix_write( + site: &str, + bx: usize, + by: usize, + bside: usize, + x: usize, + y: usize, + prev: u16, + val: u16, +) { + if *PIXPROBE_ON && Some((x, y)) == *PIXPROBE { + eprintln!( + "PIXWRITE {site} block=({bx},{by})+{bside} px=({x},{y}) prev={prev} val={val} at {}", + std::panic::Location::caller() + ); + } +} impl PlaneBuf<'_> { /// Sets this plane's own tile pixel origin ([`Self::tile_x0`]/ @@ -20599,6 +20635,16 @@ impl PlaneBuf<'_> { base = (base + cfl_scaled(alpha_q3, ac_q3[idx])).clamp(0, sample_max(fctx)); } let sample = (base + residual[idx]).clamp(0, sample_max(fctx)) as u16; + pix_write( + "reconstruct_rect", + x, + y, + bw, + x + col, + y + row, + self.data[(y + row) * self.width + x + col], + sample, + ); self.data.to_mut()[(y + row) * self.width + x + col] = sample; } } @@ -20745,6 +20791,16 @@ impl PlaneBuf<'_> { base = (base + cfl_scaled(alpha_q3, ac_q3[idx])).clamp(0, sample_max(fctx)); } let sample = (base + residual[idx]).clamp(0, sample_max(fctx)) as u16; + pix_write( + "reconstruct", + x, + y, + side, + x + col, + y + row, + self.data[(y + row) * self.width + x + col], + sample, + ); self.data.to_mut()[(y + row) * self.width + x + col] = sample; } } @@ -36484,8 +36540,10 @@ impl PlaneBuf<'_> { let dst = (y + row) * self.width + x; let pred = &prediction[src..src + w]; let out = &mut self.data.to_mut()[dst..dst + w]; - for (o, &p) in out.iter_mut().zip(pred) { - *o = i32::from(p).clamp(0, max) as u16; + for (col, (o, &p)) in out.iter_mut().zip(pred).enumerate() { + let v = i32::from(p).clamp(0, max) as u16; + pix_write("mc_copy", x, y, w, x + col, y + row, *o, v); + *o = v; } } return; @@ -36497,8 +36555,10 @@ impl PlaneBuf<'_> { let pred = &prediction[src..src + w]; let res = &residual[src..src + w]; let out = &mut self.data.to_mut()[dst..dst + w]; - for ((o, &p), &r) in out.iter_mut().zip(pred).zip(res) { - *o = (i32::from(p) + r).clamp(0, max) as u16; + for (col, ((o, &p), &r)) in out.iter_mut().zip(pred).zip(res).enumerate() { + let v = (i32::from(p) + r).clamp(0, max) as u16; + pix_write("mc_add", x, y, w, x + col, y + row, *o, v); + *o = v; } } } diff --git a/crates/ec-av1/src/mc.rs b/crates/ec-av1/src/mc.rs index a9c96c6c..5265951e 100644 --- a/crates/ec-av1/src/mc.rs +++ b/crates/ec-av1/src/mc.rs @@ -1984,7 +1984,9 @@ pub(crate) fn predict_compound_intermediate_kern( let y0 = y_q4.div_euclid(16); let yfrac = y_q4.rem_euclid(16) as usize; if crate::envflags::env_flag!("EC_MC_TRACE") { - eprintln!("EC_MC_COMP x_q4={x_q4} y_q4={y_q4} w={block_w} h={block_h} hk={h_kind:?} vk={v_kind:?}"); + eprintln!( + "EC_MC_COMP x_q4={x_q4} y_q4={y_q4} w={block_w} h={block_h} hk={h_kind:?} vk={v_kind:?}" + ); } let (v_wide, v_narrow) = v_kind.tables(); @@ -2129,7 +2131,7 @@ pub(crate) fn diffwtd_mask( let round = INTER_POST_ROUND + bd.saturating_sub(8) - round_delta(bd); for i in 0..mask.len() { let diff = round2((pred0[i] - pred1[i]).abs(), round); - let m = (38 + diff / 16).clamp(0, 64); + let m = (38 + diff / 16).clamp(0, 64) as u8; mask[i] = if inv { (64 - m) as u8 } else { m as u8 }; } } @@ -2239,11 +2241,223 @@ fn compound_intermediate_whole_pel_identity_round_trips_through_combine() { assert!(dst.iter().all(|&v| v == 100), "{dst:?}"); } +/// lane-av1c10: the whole compound pipeline -- two +/// [`predict_compound_intermediate`] taps through every combine this crate +/// ships ([`combine_compound`] dist-wtd and (8,8), [`diffwtd_mask`] both +/// inverses, [`blend_masked_compound`]) -- vs faithful transcriptions of the +/// libaom C at the same inputs, over all 16x16 phase pairs at 8 and 10 bits. +/// +/// The C twins keep the CONV_BUF biased (`sum = dot + (1 << (bd + FILTER_BITS +/// - 1))` horizontally, `1 << offset_bits` vertically -- `convolve.c` +/// `av1_highbd_dist_wtd_convolve_2d_c`); this crate's intermediates are +/// unbiased, so each transcription adds the constant bias +/// `(1 << (bd + 4)) + (1 << (bd + 3))` (= `(1 << (offset_bits - round_1)) + +/// (1 << (offset_bits - round_1 - 1))`) before its combine and subtracts it +/// where libaom does. The diffwtd transcription is `diffwtd_mask_d16` +/// (reconinter.c:301): `round = 2*FILTER_BITS - round_0 - round_1 + (bd-8)`; +/// the blend is `aom_highbd_blend_a64_d16_mask_c` (blend_a64_mask.c): +/// `((m*c0 + (64-m)*c1) >> 6) - bias`, one `ROUND_POWER_OF_TWO` by +/// `round_bits`, `negative_to_zero`, clip. A 10-bit-only wrong constant in +/// any of the three -- the exact shape of the compound rounding defect the +/// cwarp-r1 charter named (and of the `(bd - 8)` diffwtd term that landed +/// without a 10-bit gate behind it) -- fails here per phase, no aomenc stream +/// needed. +#[cfg(test)] +mod libaom_transcription { + use super::{ + InterpFilterKind, REF_NO_SCALE, blend_masked_compound, combine_compound, diffwtd_mask, + predict_compound_intermediate, + }; + + fn lcg(state: &mut u64) -> u32 { + *state = state + .wrapping_mul(6364136223846793005) + .wrapping_add(1442695040888963407); + (*state >> 33) as u32 + } + + /// `ROUND_POWER_OF_TWO` on the C `int` domain: arithmetic shift of + /// `value + half` (halves round toward +inf, negatives included). + fn c_round(value: i32, shift: u32) -> i32 { + (value + (1 << (shift - 1))) >> shift + } + + /// `av1_highbd_dist_wtd_convolve_2d_c` for both taps (biased domain) plus + /// its `do_average` finish: dist-wtd two-weight split, or the plain + /// `>> 1` average. + #[allow(clippy::too_many_arguments)] + fn libaom_compound_2d( + reference: &[u16], + stride: usize, + (x0_q4, y0_q4): (i32, i32), + (x1_q4, y1_q4): (i32, i32), + w: usize, + h: usize, + hf: &[i32; 8], + vf: &[i32; 8], + fwd: i32, + bck: i32, + bd: u32, + dist_wtd: bool, + ) -> Vec { + let rd = if bd > 10 { bd - 10 } else { 0 }; + let round_0 = 3 + rd; + let round_1 = 7u32; + let offset_bits = (bd + 14 - round_0) as i32; + let bias = + (1 << (offset_bits - round_1 as i32)) + (1 << (offset_bits - round_1 as i32 - 1)); + let round_bits = 14 - round_0 - round_1; + let mut out = vec![0u16; w * h]; + let mut conv = vec![0i32; w * h]; + for (tap, (x_q4, y_q4)) in [(0usize, (x0_q4, y0_q4)), (1usize, (x1_q4, y1_q4))] { + // horizontal, biased + let mut im = vec![0i32; (h + 7) * w]; + for y in 0..h + 7 { + for x in 0..w { + let mut sum = 1i32 << (bd + 7 - 1); + for (k, &t) in hf.iter().enumerate() { + let sx = (x_q4.div_euclid(16) + x as i32 + k as i32 - 3) as usize; + let sy = (y_q4.div_euclid(16) + y as i32 - 3) as usize; + sum += t * i32::from(reference[sy * stride + sx]); + } + im[y * w + x] = c_round(sum, round_0); + } + } + for y in 0..h { + for x in 0..w { + let mut sum = 1i32 << offset_bits; + for (k, &t) in vf.iter().enumerate() { + sum += t * im[(y + k) * w + x]; + } + let res = c_round(sum, round_1); + if tap == 0 { + conv[y * w + x] = res; + } else { + let mut tmp = if dist_wtd { + (conv[y * w + x] * fwd + res * bck) >> 4 // DIST_PRECISION_BITS + } else { + (conv[y * w + x] + res) >> 1 + }; + tmp -= bias; + let v = c_round(tmp, round_bits).max(0) as u32; + out[y * w + x] = v.min((1u32 << bd) - 1) as u16; + } + } + } + } + out + } + + /// `diffwtd_mask_d16` on the biased conv bufs. + fn libaom_diffwtd(c0: &[i32], c1: &[i32], inv: bool, bd: u32, round_0: u32) -> Vec { + let round = (14 - round_0 - 7 + (bd - 8)) as i32; + c0.iter() + .zip(c1) + .map(|(&a, &b)| { + let diff = c_round((a - b).abs(), round.unsigned_abs()); + let m = (38 + diff / 16).clamp(0, 64) as u8; + if inv { 64 - m } else { m } + }) + .collect() + } + + /// `aom_highbd_blend_a64_d16_mask_c`, subw == subh == 0, biased domain. + fn libaom_blend(c0: &[i32], c1: &[i32], mask: &[u8], bd: u32, round_0: u32) -> Vec { + let bias = (1i32 << (bd + 4)) + (1i32 << (bd + 3)); + let round_bits = 14 - round_0 - 7; + c0.iter() + .zip(c1) + .zip(mask) + .map(|((&a, &b), &m)| { + let res = ((i32::from(m) * a + (64 - i32::from(m)) * b) >> 6) - bias; + let v = c_round(res, round_bits).max(0) as u32; + v.min((1u32 << bd) - 1) as u16 + }) + .collect() + } + + #[test] + fn compound_pipeline_matches_the_libaom_transcription_at_8_and_10_bits() { + let fctx = &crate::decode::FrameCtx::new(); + for bd in [8u32, 10u32] { + crate::decode::set_bit_depth(bd as u8, fctx); + let max = (1u16 << bd) - 1; + let (wide, _narrow) = InterpFilterKind::Regular.tables(); + let mut state = 0x9e37_79b9_7f4a_7c15u64 ^ u64::from(bd); + let reference: Vec = (0..48 * 48) + .map(|_| (lcg(&mut state) % (u32::from(max) + 1)) as u16) + .collect(); + let rd = if bd > 10 { bd - 10 } else { 0 }; + let round_0 = 3 + rd; + let bias = (1i32 << (bd + 4)) + (1i32 << (bd + 3)); + for &dist_wtd in &[false, true] { + let (fwd, bck) = if dist_wtd { (9, 7) } else { (8, 8) }; + for xf in 0..16i32 { + for yf in 0..16i32 { + let (mv0, mv1) = ((16 * 8 + xf, 16 * 8 + yf), (16 * 10 + xf, 16 * 7 + yf)); + let (hf, vf) = (&wide[xf as usize], &wide[yf as usize]); + let mut p0 = vec![0i32; 64]; + let mut p1 = vec![0i32; 64]; + for (mv, dst) in [(mv0, &mut p0), (mv1, &mut p1)] { + predict_compound_intermediate( + &reference, + 48, + 48, + 48, + mv.0, + mv.1, + REF_NO_SCALE, + 8, + 8, + InterpFilterKind::Regular, + InterpFilterKind::Regular, + dst, + fctx, + ); + } + let mut got = vec![0u16; 64]; + combine_compound(&p0, &p1, fwd, bck, &mut got, fctx); + let want = libaom_compound_2d( + &reference, 48, mv0, mv1, 8, 8, hf, vf, fwd, bck, bd, dist_wtd, + ); + assert_eq!( + got, want, + "combine bd {bd} dist_wtd {dist_wtd} phase ({xf},{yf})" + ); + + let c0: Vec = p0.iter().map(|&v| v + bias).collect(); + let c1: Vec = p1.iter().map(|&v| v + bias).collect(); + for inv in [false, true] { + let mut mask = vec![0u8; 64]; + diffwtd_mask(&p0, &p1, inv, &mut mask, fctx); + assert_eq!( + mask, + libaom_diffwtd(&c0, &c1, inv, bd, round_0), + "diffwtd bd {bd} inv {inv} phase ({xf},{yf})" + ); + } + let mask: Vec = (0..64).map(|_| (lcg(&mut state) % 65) as u8).collect(); + let mut blended = vec![0u16; 64]; + // main shape: the branch's `subsampled: bool` split into + // the plane's own `subw`/`subh` shifts; luma is (0, 0). + blend_masked_compound(&p0, &p1, &mask, 8, 8, 8, 0, 0, &mut blended, fctx); + assert_eq!( + blended, + libaom_blend(&c0, &c1, &mask, bd, round_0), + "blend bd {bd} phase ({xf},{yf})" + ); + } + } + } + } + } +} + #[cfg(test)] mod tests { use super::{ - predict, predict_scaled, predict_with_filter, predict_with_filters, InterpFilterKind, - REF_NO_SCALE, + InterpFilterKind, REF_NO_SCALE, predict, predict_scaled, predict_with_filter, + predict_with_filters, }; /// Regression pin for the lane-av1flake ±1 defect: a real aomenc chroma diff --git a/lanes/av1pixprobe.report.md b/lanes/av1pixprobe.report.md new file mode 100644 index 00000000..be79d8f7 --- /dev/null +++ b/lanes/av1pixprobe.report.md @@ -0,0 +1,338 @@ +# lane-av1pixprobe — the two `av1cheapwins` §C "land after rebase" items + +Base: `1d47ff54` (main). Two independent pieces, landed: + +* **A** — `EC_AV1_PIXPROBE=x,y`, the env-gated one-sample write probe from + `lane-av1-ibcwrite` @ `25f5c729`, **re-anchored by hand** onto main's + reconstruction-store sites (the branch's two mc hunks no longer attach: the + mc stores live in `reconstruct_mc_rect` now, and its block extent is `w`, + not `side`). +* **B** — the substance behind `lane-av1-c10`: ancestor commit **`295dc3fe`**'s + byte-identical `u8` cast move in `diffwtd_mask` **plus** its 8/10-bit libaom + transcription gate `mc::libaom_transcription::compound_pipeline_matches_the_libaom_transcription_at_8_and_10_bits` + (adapted, not cherry-picked — see "B" below). + +Defect **C** is recorded, not chased — and it does **not** reproduce on merged +main; see "C". + +`cargo check --all-targets -p ec-av1` clean, gate green, rung fires and is +inert when unset. + +--- + +## A — the write probe, re-anchored + +### Why the cherry-pick does not apply + +`git show 25f5c729 -- crates/ec-av1/src/decode.rs` has four store hunks. Two of +them (the intra pair) still attach: `reconstruct_rect` and `reconstruct` both +exist on main with the same +`self.data.to_mut()[(y + row) * self.width + x + col] = sample;` line inside +the same `let sample = (base + residual[idx]).clamp(...)` store. The two mc +hunks do **not**: they were written against the pre-restructure +`mc_copy`/`mc_add` loops; on `1d47ff54` both stores are inside +`PlaneBuf::reconstruct_mc_rect` (`decode.rs:36454` onward), which +lane-perf4/lane-recoparse reshaped (row-at-a-time `pred`/`out` slice pairs, an +early `residual.is_empty()` return for the prediction-only path, and a +`w`/`h` block extent with `side` demoted to the prediction stride). So the +loops were re-located by grep and re-written in place. + +Two deliberate deviations from the branch's text, both forced by main's shape: + +1. `pix_write("mc_copy", x, y, w, …)` / `pix_write("mc_add", x, y, w, …)` — the + branch passed `side`. In `reconstruct_mc_rect` `side` is the *prediction + stride*, not the block width (a rect block is `w` wide and `side`-strided), + so reporting `side` in the `block=(bx,by)+SIDE` field would misreport the + block extent for every rectangular inter block. `w` is what the field means. +2. **Formatting.** The branch wrote the two intra `pix_write` calls as single + long lines. This repo does have a formatting hook, but not where I first + looked: `core.hooksPath` is `/home/user/omp/omp/agent/hooks/git`, so + `$(git rev-parse --git-common-dir)/hooks/pre-commit` is absent and says + nothing. The commit-time rustfmt reflowed the four call sites and the + `pix_write` signature across lines (semantic-only; the diff grew from the + branch's +33/-4 to +64/-4 and every extra line is reflow). Accepted, not + reverted. + +### The landed diff (`decode.rs +64/-4`; the +31 over the branch's +33 is pure reflow) + +(shown in the branch's single-line form for readability; as committed the +`pix_write` signature and the two intra call sites are rustfmt-reflowed, which +is where the extra 31 lines are — no token changed) + +``` + @@ -20395,6 +20395,31 @@ struct PlaneBuf<'a> { + +// lane-av1pixprobe: env-gated one-sample write probe -- `EC_AV1_PIXPROBE=x,y` + +// prints one PIXWRITE line per reconstruction store landing on that sample, + +// naming the store site, the value it replaces and the one it leaves. Re-anchored + +// from `lane-av1-ibcwrite` @ 25f5c729 onto the main-shape sites (the two mc stores + +// now live in `reconstruct_mc_rect`). + +static PIXPROBE_ON: std::sync::LazyLock = + + std::sync::LazyLock::new(|| std::env::var_os("EC_AV1_PIXPROBE").is_some()); + +static PIXPROBE: std::sync::LazyLock> = LazyLock::new(|| { … }); + +#[inline] + +fn pix_write(site: &str, bx: usize, by: usize, bside: usize, x: usize, y: usize, prev: u16, val: u16) { + + if *PIXPROBE_ON && Some((x, y)) == *PIXPROBE { + + eprintln!("PIXWRITE {site} block=({bx},{by})+{bside} px=({x},{y}) prev={prev} val={val} at {}", Location::caller()); + + } + +} + @@ -20599,6 +20624,7 @@ (reconstruct_rect store) + + pix_write("reconstruct_rect", x, y, bw, x + col, y + row, self.data[…], sample); + @@ -20745,6 +20771,7 @@ (reconstruct store) + + pix_write("reconstruct", x, y, side, x + col, y + row, self.data[…], sample); + @@ -36485,8 +36512,10 @@ (reconstruct_mc_rect, residual.is_empty() path) + - for (o, &p) in out.iter_mut().zip(pred) { + - *o = i32::from(p).clamp(0, max) as u16; + + for (col, (o, &p)) in out.iter_mut().zip(pred).enumerate() { + + let v = i32::from(p).clamp(0, max) as u16; + + pix_write("mc_copy", x, y, w, x + col, y + row, *o, v); + + *o = v; + @@ -36498,8 +36527,10 @@ (reconstruct_mc_rect, dense-residual path) + - for ((o, &p), &r) in out.iter_mut().zip(pred).zip(res) { + - *o = (i32::from(p) + r).clamp(0, max) as u16; + + for (col, ((o, &p), &r)) in out.iter_mut().zip(pred).zip(res).enumerate() { + + let v = (i32::from(p) + r).clamp(0, max) as u16; + + pix_write("mc_add", x, y, w, x + col, y + row, *o, v); + + *o = v; +``` + +Inertness is structural, not incidental: `PIXPROBE_ON` is a `LazyLock` over +`std::env::var_os(..).is_some()`, so with the variable unset the whole body +compiles to one atomic load per store and the `eprintln!` is behind a `false` +that the branch's own envflags note (lane-perf1) shows is free. Nothing in the +crate calls `set_var` (`grep -rn set_var crates/ec-av1` = 0 hits), so the +snapshot cannot change under a run. + +### Proof it fires — the pinned fixture, re-encoded here + +The `lane-av1ibcwrite` / `lane-av1ibcpix` recipe, re-run verbatim +(`testsrc2=size=320x180:rate=25 -t 0.2 -vf tile=2x2` y4m → +`aomenc --passes=1 --end-usage=q --cpu-used=0 --lag-in-frames=0 --kf-max-dist=1 +--limit=1 --threads=1 --tile-columns=0 --min-partition-size=8 +--max-partition-size=32 --sb-size=64 --tune-content=screen --enable-intrabc=1 +--enable-palette=0 --cq-level=20 --enable-tx-size-search=1 +--enable-rect-partitions=0 --enable-1to4-partitions=0 --max-partition-size=64 +--obu`): + +``` +$ sha256sum out.obu +bc699af4a6e7c1c5657f041e8cbdf2d3d899ddb80ec2a549a950b7cebb5b41bd out.obu +``` + +— byte-identical to the sha both parked reports pin. + +Set: + +``` +$ EC_AV1_PIXPROBE=296,128 decode_probe out.obu +PIXWRITE reconstruct block=(288,128)+32 px=(296,128) prev=0 val=170 at crates/ec-av1/src/decode.rs:20418:13 +PIXWRITE reconstruct block=(288,128)+16 px=(296,128) prev=0 val=167 at crates/ec-av1/src/decode.rs:20418:13 +PIXWRITE reconstruct block=(288,128)+16 px=(296,128) prev=0 val=15 at crates/ec-av1/src/decode.rs:20418:13 +OK: 1 frames decoded, 640x360 +``` + +Three stores, one per plane (luma `val=170`, U `val=167`, V `val=15`) — the +same three-stores-one-per-plane shape the branch reported, at the sample the +branch named. Unset: + +``` +$ env -u EC_AV1_PIXPROBE decode_probe out.obu 2>&1 | grep -c PIXWRITE +0 +``` + +Build: + +``` +$ CARGO_TARGET_DIR=$HOME/.cache/cargo-target-av1pixprobe cargo check --all-targets -p ec-av1 + Finished `dev` profile [optimized + debuginfo] target(s) in 1.76s (exit 0) +``` + +--- + +## B — `diffwtd_mask`'s `u8` cast move + its 8/10-bit gate + +### The cast move is byte-identical — argued from the clamp, not asserted + +```rust +let diff = round2((pred0[i] - pred1[i]).abs(), round); +let m = (38 + diff / 16).clamp(0, 64) as u8; // was: (… .clamp(0, 64); with `m as u8` at the use +mask[i] = if inv { (64 - m) as u8 } else { m as u8 }; +``` + +`clamp(0, 64)` on an integer leaves `m ∈ {0,…,64}` — 65 values, all +representable in `u8` — so `as u8` is value-preserving and the two forms bind +the *same* integer. Every use is a narrowing of a value already in range: + +* forward: `m as u8` (old) vs `m` already `u8` (new) — identical byte. +* inverse: `64 - m` is in `1..=64` for `m ∈ 0..=64`, so it is non-negative and + `u8`-representable; `64u8 - m_u8` cannot wrap, and `(64 - m_i32) as u8` is the + same value. Identical byte. + +The only behavioural difference between the two bindings is the *domain* of the +subtraction (`u8` vs `i32`), and since neither operand can leave `[0,64]` there +is no value for which the two domains differ. The mask array is `&mut [u8]`, so +the stored bytes are the same in both. This is a type-tightening only: it moves +the range proof to the binding and deletes two now-redundant casts. + +### The gate — landed, and proven non-vacuous at BOTH depths + +`mc::libaom_transcription::compound_pipeline_matches_the_libaom_transcription_at_8_and_10_bits` +(213 lines, from `295dc3fe`) pins the whole compound path — two +`predict_compound_intermediate` taps through `combine_compound` (dist-wtd 9/7 +and simple 8/8), `diffwtd_mask` both inverses, and `blend_masked_compound` — +against faithful transcriptions of `av1_highbd_dist_wtd_convolve_2d_c`, +`diffwtd_mask_d16` and `aom_highbd_blend_a64_d16_mask_c`, over **all 256 phase +pairs at 8 and 10 bits**, with no aomenc stream and no fixture. That is +precisely the 10-bit coverage the `(bd - 8)` term in `diffwtd_mask` landed +without (cwarp-r1's `accepted` residue). + +Adaptation, because main's `blend_masked_compound` signature has drifted: the +branch's `subsampled: bool` is now the plane's own `subw`/`subh` shift pair, so +the call is + +```rust +blend_masked_compound(&p0, &p1, &mask, 8, 8, 8, 0, 0, &mut blended, fctx); +``` + +(luma, `(subw, subh) = (0, 0)`), and the transcription is unchanged — the +branch's transcription was already the `subw == subh == 0` luma case. Every +other identifier and signature (`predict_compound_intermediate`, +`combine_compound`, `InterpFilterKind::Regular.tables()`, `FrameCtx::new`, +`set_bit_depth`, `REF_NO_SCALE`) still matches main unchanged. One +`#[allow(clippy::too_many_arguments)]` was added to the transcription helper, +which main's lints require and the branch's tree did not. + +Run: + +``` +$ cargo test -p ec-av1 --lib compound_pipeline_matches_the_libaom_transcription +running 1 test +test mc::libaom_transcription::compound_pipeline_matches_the_libaom_transcription_at_8_and_10_bits ... ok +test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 764 filtered out; finished in 0.06s +``` + +Non-vacuity, two counterfactuals on `diffwtd_mask`'s own `round` line, each +reverted immediately: + +| mutation | result | +|---|---| +| `… - round_delta(bd) + 1` (bites at 8-bit) | `FAILED … assertion left == right failed: diffwtd bd 8 inv false phase (0,0)` | +| `INTER_POST_ROUND + bd.saturating_sub(8) * 2 - round_delta(bd)` — **zero at 8-bit, nonzero at 10-bit only** | `FAILED … assertion left == right failed: diffwtd bd 10 inv false phase (0,0)` | + +The second is the load-bearing one: it is inert at 8-bit and only the 10-bit arm +catches it, so the 10-bit coverage is real, not a duplicate of the 8-bit arm. +Both reverted; the green run above is the reverted tree. + +--- + +## C — the defect the branch named: RECORDED, NOT INVESTIGATED + +**Not investigated by contract.** Re-measured only to the extent needed to say +whether the recorded numbers still describe merged main, which changes what a +charter must start from. That re-measurement is itself the most important line +in this section. + +### The recorded defect (verbatim from `lane-av1ibcwrite.report.md`, `25f5c729`) + +> An 8x8 intra-BC leaf at px **(296, 128)** stores **prediction 170 + residual +> 19 = 189** where the oracle's single all-zero `TX_32X32` unit stores **170**. +> First value divergence upstream: at mi **(row 32, col 72)** (the owning 32x32 +> luma TU at px (288,128), the 64x64 at x 256..320 / y 128..192) ours reads +> `skip=1` where the oracle reads `skip=0`; the oracle codes that quadrant +> `PARTITION_NONE` as one 32x32 with `all_zero=1`, ours splits it into 8x8/16x16 +> leaves, and from that symbol the arithmetic streams desync. Our desynced 8x8 +> leaf at (296,128) then reads `all_zero=0` with one DC level 2 → dequant 19 → +> the 189 store. Oracle output at that sample: **170**; the class repeats **301 +> times** per frame (independent roots with a clean left/above/above-left), +> 127,862 differing samples (Y 84,510 / U 21,005 / V 22,347), rows y 128..359. +> Fixture: the R5 encode above, sha256 +> `bc699af4a6e7c1c5657f041e8cbdf2d3d899ddb80ec2a549a950b7cebb5b41bd`. The +> named home is the partition-context / leaf8 intrabc neighbour stamping +> (`leaf8_intrabc_hits` territory), upstream of the whole decode tail. + +### What merged main does with the same fixture today + +The branch tip `37a64d99` is **not** an ancestor of main; its merge-base with +`1d47ff54` is `7f863c5f`, i.e. the measurement tree is **439 commits behind** +main with one commit of its own on top. Re-encoding the recipe reproduces the +pinned sha byte-for-byte, and on this tree: + +``` +$ dump_yuv out.obu /tmp/ours ; ffmpeg -i out.obu -pix_fmt yuv420p -f rawvideo ref.yuv +$ cmp ours.f0.yuv ref.yuv +$ # python: total differing samples vs ffmpeg: 0 Y differing: 0 +$ # Y(296,128): ours 170 ref 170 +``` + +**The frame is byte-exact against ffmpeg on `1d47ff54`**, so the 189 store is +**not reproducible on merged main** for this fixture: Y(296,128) is 170 in both +frames, and the probe above prints `val=170` for the luma plane at that +coordinate. Luma still contains four samples equal to 189 in total — at +**(70,218), (70,219), (70,223), (389,225)** — but they match the oracle +byte-for-byte, so they are picture content, not residues of this class. + +### Hand-off row + +> **OPEN, un-reproduced on merged main.** Class: partition-tree divergence +> around skipped intrabc leaves (entropy desync, not a write bug — the +> reconstruction arithmetic is correct and the write site is exonerated). The +> original numbers: 8x8 intrabc leaf at px **(296,128)** storing +> **pred 170 + res 19 = 189** where the oracle's all-zero `TX_32X32` stores +> **170**; first divergent symbol at mi **(32,72)** — `skip=1` vs `skip=0`, +> `PARTITION_NONE` vs an 8x8/16x16 split; **301** independent roots per frame; +> **127,862** differing samples (Y 84,510 / U 21,005 / V 22,347), y 128..359; +> fixture sha256 `bc699af4a6e7c1c5657f041e8cbdf2d3d899ddb80ec2a549a950b7cebb5b41bd` +> (recipe reproduced here, byte-identical). **On `1d47ff54` the fixture decodes +> byte-exact vs ffmpeg (0 differing samples)** — the measuring tree `37a64d99` +> is 439 commits stale (merge-base `7f863c5f`), so either a later lane closed +> it on this input or the tree it was measured on is not the tree it was +> reported against. **A charter must start by re-bisecting on merged main, not +> by trusting these coordinates**; `EC_AV1_PIXPROBE=x,y` (this branch) is the +> re-measurement instrument, and the owning area named by the original report +> is the partition-context / leaf8 intrabc neighbour stamping. + +**Not investigated:** I did not trace the partition path, did not run the +oracle's `EC_ISTEP`/`EC_TRACE_COEFF` rungs against main, did not try to find +which of the 439 commits changed the outcome, and did not confirm or deny that +the class still exists anywhere. The 301-root / 127,862-sample figures are the +branch's, quoted for provenance; they are **not** re-measured numbers. + +--- + +## What I deliberately did not do + +- **Did not cherry-pick.** Both commits were re-anchored/re-adapted by hand; + `git cherry-pick` was never run against either, because both would conflict + (`decode.rs` sites moved; `blend_masked_compound`'s signature changed). +- **Did not land `lane-av1c10` @ `a2806383`** (the report-only disclosure + correction at that tip). §C triaged it "record only" and its content + duplicates this report; only the ancestor `295dc3fe` substance landed. +- **Did not land `lanes/av1ibcwrite.report.md` / `lanes/av1c10.report.md`** + verbatim. The ibcwrite report's "the write is named" narrative is superseded + for merged main by the re-measurement above; C quotes it as a record instead. +- **Did not investigate the C defect.** See the hand-off row: one fixture + re-encode + one `cmp` against ffmpeg to establish non-reproduction, nothing + further. +- **Did not touch the main checkout.** It is clean after every batch; the + absolute-path discipline held (see below). +- **Did not run any full suite.** Scoped to one named test in one crate, one + example build, one one-frame fixture probe. Box was loaded. +- **Did not run rustfmt myself.** The commit hook reflowed the new lines + (`core.hooksPath=/home/user/omp/omp/agent/hooks/git`); the reflow is + semantic-only and was left in place rather than fought. +- **Did not add a gate for the pixprobe rung itself** (e.g. a + fires-when-set assertion). A test that would have to spawn a process with the + env set is out of proportion to an inert debug rung, and the repo's + convention for these is the example-binary probe quoted above. +- **Did not push.** + +### One process note worth carrying forward + +The `edit` tool resolved a **relative** path header against the session's cwd +(the main checkout), not the worktree, and silently wrote the first insertion +into `main`'s `decode.rs`. Caught immediately by +`git status --porcelain` in the main checkout showing +` M crates/ec-av1/src/decode.rs`, reverted with `git checkout --`, and every +later edit used an absolute `/home/user/.cache/wt/av1pixprobe/…` path. The +contract's "relative edits land in the main checkout" is not a warning about a +*different* worktree arrangement — it is literally what happens, on the first +edit, with a relative path.