diff --git a/crates/ec-av1/fixtures/r512_rect1x2_444_palette.obu b/crates/ec-av1/fixtures/r512_rect1x2_444_palette.obu new file mode 100644 index 0000000000000000000000000000000000000000..410f406b00ec3f9b60516830d2fb55e97ae261ee GIT binary patch literal 2250 zcmV;*2sQT-015^;9smE^1Twu5OrHYTLV8nTzVJ_SeeQHv9>^zsnPJ+lvlJ zj+|k>&mV)rXJxh;8;S#bvcwh3<0BpD)h9ck`OjecyT*PKLL}^^-+KlY4_cR9quNEf z{BwqL6kk3_ECw9=jJ_0QEs?jgM-$$Bz8R;zNAPx-D7vL)(vIhej z4OEQy*<|)xYn?{=CYHlHgx=2|j&c64YdcRoor(_YOX~L2BxqN8Q<0o(UA2 zS~CQ$ytxVpRvmclLyjJ)9`Ch9|5BUpQ+EWZzy3+5m_`x%K4o&E)DcM%JpTsUD9W0x zalDVU$TX&vpbBK-MvVF(^sV28G^(W&vGj*G z72Cr&?%OSTevobqB7Ct$|2dLPoI#0t`Ad#c@HXuj z^I>+8>_N)S`d3rp$(@z{g3^8O}`81C|_PAbR)!WPe zz2*9unBtu^0TZ+5DCjUcq&f3(eLKK&xm z%OL1{)~fm^(Mn|0uG!RAJ2Dz;Xtz(qQjUxAX>NO?plh+p9*H>380_^%kDvTmZj{C)qSnfqgK>8FJxU$iSV&~ zaUDo=&g1&*wBGMTqA@`b=Y1Vdm2JJP<{qRwopSw>w;Kq)8=-*OTWb#%U$gd;D*Pi^;R0TuS_@ zQJc7~p=FBMbggOa(2x%^MW+yuiqnxebmX;(ylpS!09xWpC+gu0%&ayx!Q8pEMmA++ zqE*n0tUTj?Tt(5>Y7bXt??&5knW?Y6G0*`^%QO+N9tRnW(bt zuu9EjD9Rg_(eM{J*GapHp+uru0f+gPHrz*702_yB`JciAS@%aL2PVDgcA{Ag)yj=1 zlz+hLYNqXnAH^ncCW~Y65j!+kKs}+0X7a@irwz23jv)2cnT;v@D!H{HG03;VzK|0E zw4`eZR7x^d2!n1MoWR;8%p@j#Phpv~%$HNW1|V`Std>D(WY@ab`s`DSVyWY;kfOd{ zFi@LciOJ7q;Fk~Q4?ISf3I93~%tleZ7OQl9~>Nc&4<5MWrB z-&052a2D-YJ=)*?qm|IUyZhm{JU!=+STs<-Sl-YSx)i~p{Sp0A0?5uT#uKN&hUY0j zr50^#&ZTyN;{QC9jB0D7aJ$iV^Lisq*9r{$@9ACqrbEeq$KDr}Nni0G9{`emB#{+Z zulUWeb!2bZgaA7fGU^x1R8KngMovjcO12?pRPSaH)H#~A#cTR+A<+^OKO+6M{Z|xj zcli82A6e%T@0Gw__b}Am2m%V!QqCUm85SiM>V2D(PuAN(rCsn>Ae$7&%i#Kqc2ops Y&DIh+u78zP_u*bw&V~U6#I3xRfEpfYVgLXD literal 0 HcmV?d00001 diff --git a/crates/ec-av1/fixtures/r512_rect2x1_1x2_444.obu b/crates/ec-av1/fixtures/r512_rect2x1_1x2_444.obu new file mode 100644 index 0000000000000000000000000000000000000000..a6724a2f81aafd954ad6268b49b838a95268f880 GIT binary patch literal 2697 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 = + const { std::cell::Cell::new(0) }; + /// Chroma units of the same walk whose grid is exactly 2x1 (a 4:4:4 + /// 64x32 chroma plane block as two 32x32 units). + static RECT_TILED_CHROMA_2X1_HITS: std::cell::Cell = const { std::cell::Cell::new(0) }; + /// Chroma units of the same walk whose grid is exactly 1x2 (4:4:4 32x64, + /// or 16x64 as two 16x32s). + static RECT_TILED_CHROMA_1X2_HITS: std::cell::Cell = const { std::cell::Cell::new(0) }; + /// Chroma units of the same walk in any other multi-unit grid (2x2 and up + /// -- only reachable at 4:2:2, which is refused, so this stays 0 on + /// every admitted stream; kept so the match above is exhaustive). + static RECT_TILED_CHROMA_NXN_HITS: std::cell::Cell = const { std::cell::Cell::new(0) }; +} + +/// Current values of the four `RECT_TILED_CHROMA_*` counters, in the order +/// `(unit_reach_differs, 2x1, 1x2, other multi-unit)`. +#[allow(dead_code)] // read only from the `#[cfg(test)]` gates +pub(crate) fn rect_tiled_chroma_grid_hits() -> (usize, usize, usize, usize) { + ( + RECT_TILED_CHROMA_UNIT_REACH_HITS.with(|c| c.get()), + RECT_TILED_CHROMA_2X1_HITS.with(|c| c.get()), + RECT_TILED_CHROMA_1X2_HITS.with(|c| c.get()), + RECT_TILED_CHROMA_NXN_HITS.with(|c| c.get()), + ) +} + +/// Zeroes the four `RECT_TILED_CHROMA_*` counters (gate tests call this +/// before their own decode). +#[allow(dead_code)] // read only from the `#[cfg(test)]` gates +pub(crate) fn reset_rect_tiled_chroma_grid_hits() { + RECT_TILED_CHROMA_UNIT_REACH_HITS.with(|c| c.set(0)); + RECT_TILED_CHROMA_2X1_HITS.with(|c| c.set(0)); + RECT_TILED_CHROMA_1X2_HITS.with(|c| c.set(0)); + RECT_TILED_CHROMA_NXN_HITS.with(|c| c.set(0)); +} + // lane-t900 r22: palette blocks reconstructed inside an INTER frame (the // intra-in-inter path, `decode_inter_block`/`decode_inter_block8`) -- counted // apart from [`PALETTE_HITS`] so a witness gate can prove the INTER-frame @@ -12786,6 +12837,58 @@ fn decode_rect_split( fctx, ); } + // libaom computes `has_top_right` PER TRANSFORM UNIT (defined + // reconintra.c:196, called from `av1_build_intra_predictors` at + // reconintra.c:1847 with the txb walk's own + // `blk_col`/`blk_row`), never per block: the + // `row_off == 0` arm asks `col_off + top_right_count_unit + // < plane_bw_unit`, so the FIRST unit of a 2-wide chroma + // grid reads its above-right out of the already-reconstructed + // block ABOVE even when the block's own right edge is the + // frame's. Passing this walk's block-level `reach` gave + // every unit the same answer, and `PlaneBuf::edges` + // (decode.rs:20840) truncates the above row at + // `own_across` when `above_right` is false -- so a + // directional unit whose angle is below 90 + // (`need_right`, intra.rs:546) predicted with a 32-sample + // above row where libaom used 64. + // MEASURED on `fixtures/r512_rect2x1_1x2_444.obu` + // (4:4:4 8-bit 256x256, one frame): frame 0 plane U 130 + // samples and plane V 30 samples wrong, every one of them + // in the right 6 columns of the `cu=(0,0)` unit at + // `mi=(48,48)` `px=(192,192)` -- the unit whose above-right + // the block reach denied. Row0 and col0 of the prediction + // matched the oracle exactly and the prediction SUM did + // not (172662 vs 171512 on U, 125978 vs 126008 on V), so + // the residual read is bit-identical and the divergence is + // prediction-side, not entropy. Gate: + // `a_444_rect_strip_chroma_tiled_2x1_and_1x2_units_take_their_own_above_right_reach`. + let cu_reach = tu_reach_rect( + bw, + bh, + (cu_col * uw) << ss_x(fctx), + (cu_row * uh) << ss_y(fctx), + uw << ss_x(fctx), + uh << ss_y(fctx), + reach, + px, + py, + y.width, + y.height, + fctx, + ); + if cu_reach.above_right != reach.above_right + || cu_reach.below_left != reach.below_left + { + hit!(RECT_TILED_CHROMA_UNIT_REACH_HITS); + } + if nw * nh > 1 { + match (nw, nh) { + (2, 1) => hit!(RECT_TILED_CHROMA_2X1_HITS), + (1, 2) => hit!(RECT_TILED_CHROMA_1X2_HITS), + _ => hit!(RECT_TILED_CHROMA_NXN_HITS), + } + } // 32x32 does not fit read_coeffs_rect's scratch (768). The // square reader is the path every other 32x32 chroma unit uses. let levels = if uw == uh { @@ -12800,7 +12903,7 @@ fn decode_rect_split( m.mode, m.uv_predict_mode, m.angle_delta_uv, - reach, + cu_reach, plane, cu_x, cu_y, @@ -12848,7 +12951,7 @@ fn decode_rect_split( uh, m.uv_predict_mode, m.angle_delta_uv, - reach, + cu_reach, &residual, cfl, None, diff --git a/crates/ec-av1/src/stream.rs b/crates/ec-av1/src/stream.rs index ad0dd678..ec1cfe20 100644 --- a/crates/ec-av1/src/stream.rs +++ b/crates/ec-av1/src/stream.rs @@ -171,6 +171,18 @@ pub fn reset_skip_chroma_override_window_hits() { crate::decode::reset_skip_chroma_override_window_hits() } +/// lane-av1rectreach: the `chroma_tiled` walk's per-unit reach and grid-shape +/// counters, as `(unit_reach_differs_from_block, 2x1 units, 1x2 units, other +/// multi-unit units)`. See [`crate::decode::rect_tiled_chroma_grid_hits`]. +pub fn rect_tiled_chroma_grid_hits() -> (usize, usize, usize, usize) { + crate::decode::rect_tiled_chroma_grid_hits() +} + +/// Gate-side reset for the lane-av1rectreach counters above. +pub fn reset_rect_tiled_chroma_grid_hits() { + crate::decode::reset_rect_tiled_chroma_grid_hits() +} + /// `(y, uv)` palette blocks RECONSTRUCTED inside an inter frame (lane-t900 /// r22) -- the counter a screen-content witness gate reads to prove it /// exercises the inter-frame palette path, not the key frame's. @@ -50333,4 +50345,271 @@ pub(crate) mod tests { } let _ = std::fs::remove_dir_all(&dir); } + + /// lane-av1rectreach, the 2x1 / 1x2 half of the class sweep + /// `a_444_skipped_64x64_square_block_windows_its_chroma_override_per_unit` + /// opened: `decode_rect_split`'s `chroma_tiled` walk is the THIRD site that + /// walks a 4:4:4 chroma plane block as a grid of Chroma32 units, and the + /// only one that handed every unit the BLOCK's reach. + /// + /// The other two are already per-unit and are not touched by this gate: + /// `decode_block`'s skip arm (`chroma_window`, lane-av1chromadc) and + /// `decode_block`'s coded arm (its own `tu_reach_rect`) both resolve + /// `has_top_right` per transform unit, the way libaom's + /// `av1_build_intra_predictors` does + /// (`has_top_right`, defined reconintra.c:196, called from + /// `av1_build_intra_predictors` at reconintra.c:1847), + /// fed the chroma txb walk's own `blk_col`/`blk_row`). + /// + /// Witness `fixtures/r512_rect2x1_1x2_444.obu`, 2697 B, + /// sha256 `a009ec580a1ff24250be53e11b8d09616da71e095cefd5eb621c941d40a8688b`: + /// + /// ```text + /// ffmpeg -f lavfi -i testsrc2=size=256x256:rate=1:duration=1 -pix_fmt yuv444p \ + /// -f rawvideo in.yuv + /// aomenc --codec=av1 -w 256 -h 256 --i444 --sb-size=64 --enable-palette=1 \ + /// --enable-rect-partitions=1 --enable-1to4-partitions=1 \ + /// --min-partition-size=32 --cq-level=40 --profile=1 --obu --limit=1 \ + /// -o r512_rect2x1_1x2_444.obu in.yuv + /// ``` + /// + /// (aom-affine aomenc, one key frame, 4:4:4 8-bit 256x256.) It reaches + /// BOTH grid shapes: a 64x32 chroma plane block as `nw=2 nh=1` of 32x32 + /// and a 32x64 one as `nw=1 nh=2`. + /// + /// RED-BEFORE, on the unpatched tree, measured with `EC_AV1_FINAL_DUMP` + /// (aomdec) against `set_final_dump_prefix` (ours), 786432 B per frame: + /// frame 0 plane Y 0 wrong, plane U 130 wrong, plane V 30 wrong -- all of + /// them in the right 6 columns of the `cu=(0,0)` unit at `mi=(48,48)` + /// `px=(192,192)`, a 64x32 block whose right edge IS the frame's, so the + /// block-level reach denied an above-right that libaom's per-unit + /// `col_off + top_right_count_unit < plane_bw_unit` (0 + 8 < 16) grants. + /// After: 0 wrong on all three planes. + #[test] + fn a_444_rect_strip_chroma_tiled_2x1_and_1x2_units_take_their_own_above_right_reach() { + const NAME: &str = + "a_444_rect_strip_chroma_tiled_2x1_and_1x2_units_take_their_own_above_right_reach"; + const FILE: &str = "r512_rect2x1_1x2_444.obu"; + const LEN: usize = 2697; + const SHA: &str = "a009ec580a1ff24250be53e11b8d09616da71e095cefd5eb621c941d40a8688b"; + const W: usize = 256; + const PLANE: usize = W * W; + let path = + std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR")).join(format!("fixtures/{FILE}")); + let stream = std::fs::read(&path) + .unwrap_or_else(|e| panic!("{NAME}: pinned fixture {FILE} missing: {e}")); + assert_eq!(stream.len(), LEN, "{NAME}: {FILE} length moved"); + assert_444_header(&stream, NAME, 8); + // The byte pin is fnv1a64, the same load-bearing-identity hash every + // other pinned gate here uses; the sha256 in this test's comment is + // the provenance half. A silent stream swap under the same name + // cannot stay green. + assert_eq!( + fnv1a64(&stream), + 0x2751ccaa079cc422, + "{NAME}: {FILE} bytes drifted from the fnv1a64 pin above (provenance sha256 \ + {SHA}) -- regenerate the stream with the recipe in this test's comment and \ + re-pin the length, the fnv1a64 and the sha256 together" + ); + + let _guard = lock_gate_counters(); + reset_rect_tiled_chroma_grid_hits(); + let dir = std::env::temp_dir().join(format!("ec-av1-{NAME}-{}", std::process::id())); + let _ = std::fs::remove_dir_all(&dir); + std::fs::create_dir_all(&dir).expect("scratch dir"); + let obu = dir.join("in.obu"); + std::fs::write(&obu, &stream).expect("writing the stream"); + let aom_prefix = dir.join("aom"); + let out = Command::new(aomdec_path()) + .args(["--codec=av1", "-o"]) + .arg(dir.join("out.y4m")) + .arg(&obu) + .env("EC_AV1_FINAL_DUMP", &aom_prefix) + .stdin(Stdio::null()) + .stdout(Stdio::piped()) + .stderr(Stdio::piped()) + .output() + .expect("aomdec failed to run"); + assert!( + out.status.success(), + "{NAME}: the oracle aomdec refused the stream: {}", + String::from_utf8_lossy(&out.stderr) + ); + let ours_prefix = dir.join("ours"); + set_final_dump_prefix(Some(ours_prefix.display().to_string())); + if let Err(e) = decode_stream(&stream) { + panic!("{NAME}: this decoder refused the witness: {e}"); + } + set_final_dump_prefix(None); + + // Non-vacuity, in the order the claim depends on it: the walk must + // have reached a 2x1 AND a 1x2 grid, and at least one unit must have + // a per-unit reach that DIFFERS from the block-level one. Without the + // last one the two answers would be interchangeable everywhere and + // the exactness below would be measuring a witness the fix cannot + // touch. (It does not check the argument identity -- see + // `RECT_TILED_CHROMA_UNIT_REACH_HITS`; the exactness assert below is + // what reds when the substitution is deleted.) + let (reach_hits, h2x1, h1x2, h_nxn) = rect_tiled_chroma_grid_hits(); + assert!( + h2x1 >= 4 && h1x2 >= 4, + "{NAME}: the walk reached {h2x1} unit(s) in a 2x1 grid and {h1x2} in a 1x2 grid \ + (other multi-unit shapes: {h_nxn}), expected at least 4 of each -- the witness \ + stopped exercising one of the two grid shapes, so half the claim is vacuous" + ); + assert!( + reach_hits >= 1, + "{NAME}: {reach_hits} chroma unit(s) had a per-unit reach differing from the \ + block-level one, expected at least 1 -- on the unpatched tree every unit took \ + the block's reach, so the exactness below is vacuous" + ); + + let aom_dump = std::fs::read(format!("{}.f0", aom_prefix.display())) + .unwrap_or_else(|e| panic!("{NAME}: oracle dump f0 missing: {e}")); + let our_dump = std::fs::read(format!("{}.f0", ours_prefix.display())) + .unwrap_or_else(|e| panic!("{NAME}: our dump f0 missing: {e}")); + assert_eq!( + our_dump.len(), + 3 * PLANE, + "{NAME}: frame 0 is not 8-bit 4:4:4 256x256" + ); + for (plane, pname) in [(0usize, "Y"), (1, "U"), (2, "V")] { + let at = plane * PLANE; + if our_dump[at..at + PLANE] == aom_dump[at..at + PLANE] { + continue; + } + let first = (0..PLANE) + .find(|&s| our_dump[at + s] != aom_dump[at + s]) + .unwrap_or(PLANE); + let wrong = (0..PLANE) + .filter(|&s| our_dump[at + s] != aom_dump[at + s]) + .count(); + panic!( + "{NAME}: frame 0 plane {pname} is byte-exact nowhere -- first divergence at \ + sample {first} of {PLANE} (x={}, y={}), {wrong} samples wrong. Each unit of \ + this walk must resolve `has_top_right` over ITS OWN extent \ + (reconintra.c:196/1847), not the block's: the seed unit is cu=(0,0) of \ + 64x32 chroma grid at mi=(48,48) px=(192,192), whose right 6 columns are the \ + ones the truncated above row moved.", + first % W, + first / W + ); + } + let _ = std::fs::remove_dir_all(&dir); + } + + /// The UV-PALETTE half of the same class, and the cell + /// `lanes/av1chromadc.report.md` §5 left explicitly UNMEASURED ("every + /// multi-unit walk on this witness is `src=intrabc`; the UV-palette source + /// never reaches a multi-unit chroma walk here, so its arm of the sweep is + /// argued from the shared code path, not witnessed"). This witness is the + /// measurement: it puts a UV-palette block on a 1x2 16x64 chroma grid + /// (`mi=(32,12)`) as well as plenty of non-palette ones. + /// + /// Witness `fixtures/r512_rect1x2_444_palette.obu`, 2250 B, + /// sha256 `fad03c69087f316c1a117e8d8a70769d161b332bce7b2998e646312bb78fb067`: + /// + /// ```text + /// ffmpeg -f lavfi -i testsrc2=size=256x256:rate=1:duration=1 -pix_fmt yuv444p \ + /// -f rawvideo in.yuv + /// aomenc --codec=av1 -w 256 -h 256 --i444 --sb-size=64 --enable-palette=1 \ + /// --enable-rect-partitions=1 --enable-1to4-partitions=1 \ + /// --min-partition-size=16 --cq-level=40 --profile=1 --obu --limit=1 \ + /// -o r512_rect1x2_444_palette.obu in.yuv + /// ``` + /// + /// (`--min-partition-size=16` is what puts the 16x64 chroma grid on a + /// strip at all; at 32 the encoder only ever picks 32x64 / 64x32.) The + /// per-unit reach the fix installs is the same line for the palette and + /// the non-palette unit -- the palette only supplies the PREDICTION + /// (`palette_window`, decode.rs:12784), never the reach -- so this gate + /// exists to pin the prediction source down, not to re-prove the reach. + #[test] + fn a_444_rect_strip_chroma_tiled_1x2_palette_grid_decodes_byte_exact() { + const NAME: &str = "a_444_rect_strip_chroma_tiled_1x2_palette_grid_decodes_byte_exact"; + const FILE: &str = "r512_rect1x2_444_palette.obu"; + const LEN: usize = 2250; + const SHA: &str = "fad03c69087f316c1a117e8d8a70769d161b332bce7b2998e646312bb78fb067"; + const W: usize = 256; + const PLANE: usize = W * W; + let path = + std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR")).join(format!("fixtures/{FILE}")); + let stream = std::fs::read(&path) + .unwrap_or_else(|e| panic!("{NAME}: pinned fixture {FILE} missing: {e}")); + assert_eq!(stream.len(), LEN, "{NAME}: {FILE} length moved"); + assert_444_header(&stream, NAME, 8); + assert_eq!( + fnv1a64(&stream), + 0x7759753a0d3f75a2, + "{NAME}: {FILE} bytes drifted from the fnv1a64 pin above (provenance sha256 \ + {SHA}) -- regenerate the stream with the recipe in this test's comment and \ + re-pin the length, the fnv1a64 and the sha256 together" + ); + + let _guard = lock_gate_counters(); + reset_rect_tiled_chroma_grid_hits(); + let dir = std::env::temp_dir().join(format!("ec-av1-{NAME}-{}", std::process::id())); + let _ = std::fs::remove_dir_all(&dir); + std::fs::create_dir_all(&dir).expect("scratch dir"); + let obu = dir.join("in.obu"); + std::fs::write(&obu, &stream).expect("writing the stream"); + let aom_prefix = dir.join("aom"); + let out = Command::new(aomdec_path()) + .args(["--codec=av1", "-o"]) + .arg(dir.join("out.y4m")) + .arg(&obu) + .env("EC_AV1_FINAL_DUMP", &aom_prefix) + .stdin(Stdio::null()) + .stdout(Stdio::piped()) + .stderr(Stdio::piped()) + .output() + .expect("aomdec failed to run"); + assert!( + out.status.success(), + "{NAME}: the oracle aomdec refused the stream: {}", + String::from_utf8_lossy(&out.stderr) + ); + let ours_prefix = dir.join("ours"); + set_final_dump_prefix(Some(ours_prefix.display().to_string())); + if let Err(e) = decode_stream(&stream) { + panic!("{NAME}: this decoder refused the witness: {e}"); + } + set_final_dump_prefix(None); + + let (_reach_hits, h2x1, h1x2, _h_nxn) = rect_tiled_chroma_grid_hits(); + assert!( + h1x2 >= 4, + "{NAME}: the walk reached {h1x2} unit(s) in a 1x2 grid ({h2x1} in a 2x1), expected \ + at least 4 of the 1x2 -- the witness stopped exercising the arm" + ); + + let aom_dump = std::fs::read(format!("{}.f0", aom_prefix.display())) + .unwrap_or_else(|e| panic!("{NAME}: oracle dump f0 missing: {e}")); + let our_dump = std::fs::read(format!("{}.f0", ours_prefix.display())) + .unwrap_or_else(|e| panic!("{NAME}: our dump f0 missing: {e}")); + assert_eq!( + our_dump.len(), + 3 * PLANE, + "{NAME}: frame 0 is not 8-bit 4:4:4 256x256" + ); + for (plane, pname) in [(0usize, "Y"), (1, "U"), (2, "V")] { + let at = plane * PLANE; + if our_dump[at..at + PLANE] == aom_dump[at..at + PLANE] { + continue; + } + let first = (0..PLANE) + .find(|&s| our_dump[at + s] != aom_dump[at + s]) + .unwrap_or(PLANE); + let wrong = (0..PLANE) + .filter(|&s| our_dump[at + s] != aom_dump[at + s]) + .count(); + panic!( + "{NAME}: frame 0 plane {pname} is byte-exact nowhere -- first divergence at \ + sample {first} of {PLANE} (x={}, y={}), {wrong} samples wrong.", + first % W, + first / W + ); + } + let _ = std::fs::remove_dir_all(&dir); + } } diff --git a/lanes/av1dcunit.report.md b/lanes/av1dcunit.report.md new file mode 100644 index 00000000..e5d8b728 --- /dev/null +++ b/lanes/av1dcunit.report.md @@ -0,0 +1,322 @@ +# lane-av1dcunit — the assigned defect was already fixed; the 2x1/1x2 class cell was not + +Worktree `~/.cache/wt/av1dcunit`, branch `lane-av1dcunit`, base `70ed5601` +("Merge lane-av1txctxband"). Two commits: one read-only verification of the +assigned defect, one fix for the class-sweep cell the verification found. + +## 1. Headline: the assigned defect is NOT on `70ed5601` — it was fixed 55 minutes before this lane started + +`lanes/av1chromarect-r2.report.md` (the ticket's source) measured its 79969 +samples on base `5324a685`. The fix landed on main **after** that base and +**before** the r2 report was even merged: + +| sha | time | what | +| --- | --- | --- | +| `5324a685` | 01:36 | r2's base — 79969 chroma samples wrong | +| `57834ee2` | 01:49 | r2's report merged (numbers measured on `5324a685`) | +| `e05a6ceb` | **02:04** | **the fix**: "4:4:4 2x2 chroma walk: window the intra-BC/palette override per unit" | +| `2c0fd2b9` | 02:12 | merge of `lane-av1chromadc` — 79969 → 0 | +| `70ed5601` | 02:58 | this lane's base | + +`git merge-base --is-ancestor e05a6ceb 5324a685` → false. The r2 report and the +fix were two lanes working the same residual from two bases; the fix won by 15 +minutes. So there was nothing to fix for the ticket as written, and this lane +verified that rather than re-doing it. + +## 2. The assigned defect, re-measured here (red-before included) + +**Mechanism, and it is NOT the one the ticket names.** The ticket (following +r2 §3) says libaom "builds the DC from THAT UNIT's own above row and left +column (`av1_build_dc_predictor_sb`)". For this witness that is wrong, and the +seed proves it: the seed is `skip=1` on an **intra-BC** block, and an intra-BC +block never reaches `av1_predict_intra_block` at all. libaom's decoder routes +it through the inter path instead: + +* `decodeframe.c:1146` — `int inter_block_tx = is_inter_block(mbmi) || is_intrabc_block(mbmi);` +* `decodeframe.c:847` `predict_inter_block` → `decodeframe.c:676` `dec_build_inter_predictor` +* `decodeframe.c:686-688` — one `dec_build_inter_predictors` call per plane with + `bw = xd->plane[plane].width, bh = xd->plane[plane].height`, i.e. the WHOLE + chroma plane block at once, not per transform unit +* `reconinter_template.inc:228` — `const struct buf_2d *const pre_buf = is_intrabc ? dst_buf : &pd->pre[ref];` + the intra-BC reference **is the destination buffer**, so the prediction is a + motion-compensated copy of the current frame's own reconstruction +* the units are then reconstructed in place on top of it, with no edge read + +So there is no per-unit DC and no per-unit above/left on this path. What the +crate's whole-plane-block `PALETTE_PRED` override buffer is, in libaom's terms, +is that single whole-plane-block motion prediction — and +`PlaneBuf::reconstruct` consumes the buffer it is handed as the **unit's own** +`chroma_tx x chroma_tx_h` prediction (`decode.rs:20939` and `21087`, +`let prediction = if let Some(buf) = pred { buf } else { … }`). Handing the whole +buffer to every unit of a 2x2 grid makes all four units predict from the +top-left one. That is the defect, and `e05a6ceb`'s `chroma_window` is the +correct fix for it. + +**Red-before, measured in THIS worktree** by mutating `chroma_window` back to +the pre-fix whole-buffer shape (that is mutation M1 of §5) and running the +landed gate `a_444_skipped_64x64_square_block_windows_its_chroma_override_per_unit`: + +``` +decode-order frame 0 plane U is byte-exact nowhere -- first divergence at +sample 229728 of 262144 (x=352, y=448), 7488 samples wrong. +test result: FAILED. 0 passed; 1 failed +``` + +Full per-plane counts, from my own compare script outside the repo +(`~/.cache/cmp444.py`, reading the `EC_AV1_FINAL_DUMP` dumps of both sides): + +| frame | Y | U | V | +| --- | --- | --- | --- | +| 0 | 0 | **7488** | **8128** | +| 1 | 0 | **22571** | **41782** | +| 2 | 0 | 0 | 0 | + +Total **79969 of 2359296** — r2's number exactly. The three regions the ticket +names, frame 0: + +| region | U wrong | V wrong | first wrong | +| --- | --- | --- | --- | +| seed `[320,384)x[448,512)` | 864 / 2048 | 1024 / 2048 | (352,448) | +| sibling `[384,448)x[448,512)` | 1664 / 4096 | 1984 / 4096 | (416,448) | +| victim `[448,512)x[448,512)` | **4096 / 4096** | **4096 / 4096** | (448,448) | + +f0 U, row y=448, every 16th sample from x=320 (the 2x2 grid boundary is +x = 352 = 320+32): + +``` +oracle: 241 239 202 202 202 202 203 165 166 166 166 166 +ours : 241 239 241 239 202 202 202 202 175 175 171 171 +``` + +The seed's `cu=(1,0)` is a flat 241 — its sibling's value — exactly as the +ticket describes, and the victim is wrong on every sample. + +**After (fix in place, same oracle, same script): 0 wrong on all three planes +of all three frames, 0 of 2359296.** All three named regions are 0/2048 and +0/4096. The f0 U row above matches the oracle in all 12 samples. + +One correction to the ticket's "clean sibling control": `[384,448)x[448,512)` +is **not** clean under this defect — 1664 U and 1984 V samples wrong, first at +(416,448). What r2 measured clean was that block's *edge samples* are all ≈202, +so "any DC rule reproduces the oracle" for it (r2 §3); its pixels still move +because an intra-BC block's reference is the current frame's own +reconstruction, so the seed's error propagates one block to the right. The +first dirty cell is x=416, not x=352, for that block. + +## 3. Acceptance + +1. **Red-before per plane** — §2, 7488 / 8128 / 22571 / 41782, total 79969, + dumped with `EC_AV1_FINAL_DUMP` and compared by `~/.cache/cmp444.py`. +2. **After** — 0 wrong on Y, U, V of all three frames; all three named regions + exact. Nothing remains in the regions the seed/victim cover. +3. **Gate** — `a_444_skipped_64x64_square_block_windows_its_chroma_override_per_unit` + (landed by `e05a6ceb`, aomdec oracle required, no silent skip). Pin + `fixtures/r512.obu`, 6948 B, sha256 + `f587f0f980f149abce905e3ef66f2f1634f050c85430626eafb9c30a1e25bc21`, + already committed — no regeneration needed. +4. **Mutation** — M1 below. +5. **Re-quotes, unchanged** — §4. +6. **Class sweep** — §5, and it found a real second defect, which this lane + fixed. + +## 4. Re-quotes on this branch (nothing in §2's path changed) + +``` +$ cargo check -p ec-av1 --all-targets # 0 errors, 0 warnings +$ cargo test -p ec-av1 --lib -- a_444 lossless_444 intrabc_rect 444_lossless 420_intrabc_rect4 +test result: ok. 39 passed; 0 failed; 0 ignored; 0 measured; 736 filtered out; finished in 12.44s +``` + +The 39 carry the 4:4:4-lossless family (`a_lossless_444_*`, +`a_444_lossless_sb64_intrabc_rect_chroma_walks_4x4_units`, +`a_real_aomenc_lossless_444_key_frame_decodes_sample_exact`), the intrabc_rect +family (`a_444_intrabc_owned_rect_*`, `a_444_intrabc_rect4_*`), and the 4:2:0 +twin (`a_444_intrabc_rect_chroma_plane_block_is_the_block_footprint`, which +runs its `420_intrabc_rect4_witness.obu` sibling through +`decode_all_frames_vs_oracle`). + +Wider family, once per tree, same filter string, same env, private +`CARGO_TARGET_DIR`: + +``` +$ cargo test -p ec-av1 --lib -- rect intrabc ibc chroma 444 420 subsampl +base 70ed5601 (clean, detached) ok. 145 passed; 0 failed; 5 ignored; 0 measured; 623 filtered out; finished in 272.43s +this branch tip ok. 147 passed; 0 failed; 5 ignored; 0 measured; 623 filtered out; finished in 273.28s +``` + +145 -> 147: the delta is exactly this lane's two new gates and nothing else +(`--list` reads 775 tests on both trees). Same 5 `#[ignore]`d in both. **No +test was renamed, dropped or `#[ignore]`d.** **No floor was lowered anywhere**; the only new asserts are the two +gates of §5. + +## 5. Class sweep — and the 2x1 / 1x2 cell was broken + +Every site in the crate that walks a 4:4:4 chroma plane block as a grid of +`Chroma32` units, and what it hands each unit: + +| # | site | grid reachable at 4:4:4 | per-unit **window** | per-unit **reach** | +| --- | --- | --- | --- | --- | +| 1 | `decode_block` skip arm (decode.rs:21897) | 2x2 (NxN) | `chroma_window` — fixed by `e05a6ceb` | `tu_reach_rect` ✓ | +| 2 | `decode_block` coded arm (decode.rs:22182) | 2x2 (NxN) | `palette_window` ✓ | `tu_reach_rect` ✓ | +| 3 | `decode_rect_split` `chroma_tiled` (decode.rs:12721) | **2x1, 1x2, and 2x2** | `palette_window` ✓ | **block `reach` — WRONG** | + +Site 3 is the only one that can produce a **2x1 or 1x2** grid at all, and it +was the only one passing the block's `reach` to every unit. Sites 1 and 2 can +never be 2x1/1x2: a square luma block's chroma plane block has +`chroma_side == chroma_height` at every supported subsampling (4:2:0 → `>>1,>>1`; +4:4:4 → identity; 4:2:2 is the only asymmetric one and is refused by name at +the sequence header, `stream.rs:1783`), and `chroma_tx == chroma_tx_h`, so +`cn_cols == cn_rows` always. A 2x1/1x2 needs a rect luma block, i.e. site 3. + +**The defect, measured.** `decode_rect_split`'s `chroma_tiled` walk passed the +block-level `reach` to every unit. libaom computes `has_top_right` PER +TRANSFORM UNIT — `av1_build_intra_predictors` calls it with the chroma txb +walk's own `blk_col`/`blk_row` (defined `reconintra.c:196`, called from +`av1_build_intra_predictors` at `reconintra.c:1847`), and the `row_off == 0` +arm is `col_off + top_right_count_unit < plane_bw_unit`, so the FIRST unit of a +2-wide grid reads its above-right out of the already-reconstructed block ABOVE +even when the block's own right edge is the frame's. `PlaneBuf::edges` +(`decode.rs:20840`) truncates the above row at `own_across` when +`above_right` is false, so a directional unit whose angle is below 90 +(`need_right`, `intra.rs:546`) predicted from a 32-sample above row where libaom +used 64. + +Witness encoded here (recipe and sha256 in the gate's doc comment): +`fixtures/r512_rect2x1_1x2_444.obu`, 2697 B, sha256 +`a009ec580a1ff24250be53e11b8d09616da71e095cefd5eb621c941d40a8688b` — 4:4:4 8-bit +256x256, one key frame, and it reaches BOTH shapes: a 64x32 chroma plane block +as `nw=2 nh=1` of 32x32 and a 32x64 one as `nw=1 nh=2`. + +Red-before, per plane, my own script: + +``` +f0: Y 0 wrong U 130 wrong V 30 wrong (of 65536 per plane) +``` + +All 160 wrong samples are in the right 6 columns of the `cu=(0,0)` unit at +`mi=(48,48)` `px=(192,192)` — a 64x32 block whose right edge IS the frame's. +Oracle `EC_PRED` for that unit vs ours: + +``` +oracle EC_PRED mi_row=48 mi_col=48 plane=1 row_off=0 col_off=0 txw=32 txh=32 + mode=1 p_angle=84 have_top=1 have_left=1 n_top=32 n_left=32 + n_tr=32 n_bl=-1 bsize=11 part=1 ft=1 +oracle EC_PREDOUT8 ... sum=172662 row0=179,185,190,195,197,198,197,194 col0=179,180,181,181,182,182,183,183 +ours OUR_PRED x=192 y=192 plane=1 side=32 mode=1 ad=-2 ft=1 + sum=171512 row0=[179,185,190,195,197,198,197,194] col0=[179,180,181,181,182,182,183,183] +``` + +`bsize=11` is `BLOCK_64X32`; `n_tr=32` against our `above_right = false` is the +whole defect in one number. `row0` and `col0` match exactly and only the SUM +differs (172662 vs 171512, and 125978 vs 126008 on V), so the divergence is +prediction-side, not entropy. Stage-attributed against the oracle's own rungs: +the same 130/30 wrong appear in `EC_AV1_PREFILT_DUMP` and in +`EC_AV1_FINAL_DUMP` — pre-loop-filter, so not deblock/CDEF/LR. `n_tr=32` also +explains the shape of the error: the U delta per column is +-1, -5, -9, -14, -18, -19, growing monotonically rightward, which is a +directional prediction reaching further right as it goes. + +**The fix.** One expression, both unit readers in the walk (the square +`read_plane` and the rect `push_intra_rect`), each given the unit's own reach: + +```rust +let cu_reach = tu_reach_rect( + bw, bh, + (cu_col * uw) << ss_x(fctx), + (cu_row * uh) << ss_y(fctx), + uw << ss_x(fctx), uh << ss_y(fctx), + reach, px, py, y.width, y.height, fctx, +); +``` + +`tu_reach_rect` is the crate's existing port of the per-unit rule (it is what +sites 1 and 2 already call), so this is site 3 joining the other two, not a new +rule. `cu_reach` is also what `of_tu` needs at 4:4:4: the ss shifts are +identity there and the per-axis spelling is what makes the same call correct at +4:2:0 and at 4:2:2 if 4:2:2 is ever ported. + +**After: 0 wrong on all three planes.** Every region the sweep covers. + +**Gates** (both aomdec-oracle, no silent skip, both with the counters asserted +before a single sample is compared): + +* `a_444_rect_strip_chroma_tiled_2x1_and_1x2_units_take_their_own_above_right_reach` + — asserts `>= 4` units in a 2x1 grid AND `>= 4` in a 1x2 grid, and + `>= 1` unit whose per-unit reach differs from the block's, then full + byte-exactness of all three planes of frame 0. Pin + `fixtures/r512_rect2x1_1x2_444.obu`, fnv1a64 `0x2751ccaa079cc422`, sha256 + `a009ec58…`, recipe in the doc comment. +* `a_444_rect_strip_chroma_tiled_1x2_palette_grid_decodes_byte_exact` + — the **UV-palette cell that `lanes/av1chromadc.report.md` §5 left explicitly + unmeasured** ("every multi-unit walk on this witness is `src=intrabc`; the + UV-palette source never reaches a multi-unit chroma walk here, so its arm of + the sweep is argued from the shared code path, not witnessed"). Pin + `fixtures/r512_rect1x2_444_palette.obu`, fnv1a64 `0x7759753a0d3f75a2`, + sha256 `fad03c69…` — it puts a UV-palette block on a 1x2 16x64 chroma grid at + `mi=(32,12)` (measured with a throwaway probe, since removed) as well as + non-palette ones. + +**Mutation proofs, each reverted:** + +| # | mutation | result | +| --- | --- | --- | +| M1 | both unit readers back to the block `reach` (the pre-fix shape) | **RED** — `frame 0 plane U … first divergence at sample 49374 (x=222, y=192), 130 samples wrong` | +| M2 | `cu_col`/`cu_row` transposed in the `tu_reach_rect` offsets | **GREEN — and this is a real limit of the gate, not a pass** | + +M2 is worth stating plainly. On this witness the second/bottom unit of each +grid sits flush against the frame's right/bottom edge, so +`Reach`'s `.min(self.width)` clamp in `edges`/`edges_rect` truncates the extra +reach back to nothing and the transposition becomes unobservable. The +transposed expression is still wrong, and no witness in this lane distinguishes +it. A gate that claimed to cover it would be a false claim, so neither gate +does: they pin the reach VALUE (M1 bites), not the offset spelling. + +## 6. The other multi-unit `set_palette_pred` sites, for the record + +All 19 `set_palette_pred` call sites were enumerated and each classified by its +enclosing loop. Every one is either already windowed per unit +(`palette_window` at decode.rs:12633, 12784, 16685, 16955; `chroma_window` at +21953/21975) or is a genuinely single-unit read where the whole buffer IS the +unit's window (`decode_block_rect` 15378/15396/15559/15607 and +`decode_leaf_rect` 15996/16014/16175/16220 read `chroma_w x chroma_h` once per +plane; `decode_block_rect4` 16825/16859 loops over PLANES of a 4x4 block, not +units). One site is unwindowed inside a unit loop — +`decode_rect_split` 12525, the `(4,8)` chroma units of a 4:2:2 `BLOCK_INVALID` +plane — and it is unreachable: `chroma_422_oob` and `chroma_422_pair_wide` both +require `ss_x == 1 && ss_y == 0`, i.e. the 4:2:2 that `stream.rs:1783` refuses +by name. + +## 7. Not done + +1. **The 2x1/1x2 offset spelling is unproven** (M2, §5). Closing it needs a + witness whose 2x1/1x2 unit is NOT against a frame edge — a wider frame, or + `--sb-size=128` with a 64x64 mu chunk boundary, where `of_tu`'s `wide` + branch (`col_off % 64`) becomes reachable. Not encoded here. +2. **`decode_rect_split`'s 2x2 / `NxN` cell is unreachable**, so + `RECT_TILED_CHROMA_NXN_HITS` is 0 on every admitted stream. It is kept so + the `match` over grid shapes is exhaustive rather than silently + default-shaped; it is not a coverage claim. +3. **The 4:2:2 `(4,8)` unwindowed site (decode.rs:12525) is argued unreachable, + not proven so** — the argument is the sequence header's named refusal, and I + did not run a 4:2:2 stream through the refusal to watch it fire on this + branch. +4. **No 4:2:2 stream was encoded**, so nothing here re-verifies the + `EC_AV1_ALLOW_422_PROBE` bypass or any 4:2:2 arm. +5. **The 4:4:4-LOSSY 2x2 cell of site 1 and site 2** (i.e. a skipped 64x64 + intra-BC block with a residual rather than pure prediction) is not + distinguished from the skip cell by any pin here; `r512.obu`'s two + multi-unit blocks are both `skip=1`. +6. **`scripts/pin-gate-audit.py` does not see EITHER new gate** (nor the two + pre-existing `r512.obu` gates it sits next to): it recovers a pin name only + from a literal `"/fixtures/..."` string, a `crate_pin("X")` / + `pin_dir().join("X")` call, or a 3+-item list, and this whole family builds + its path as `PathBuf::from(env!("CARGO_MANIFEST_DIR")).join(format!( + "fixtures/{FILE}"))` off a `const FILE`. The audit therefore reports + `total=9 gates / 22 names, uncommitted=0` on this branch and exits 0, which + is a true pass for what it looks at and a SILENT GAP for this family. The + fnv1a64 asserts in both gates are the real pin check and they do run; I did + not widen the audit's detector, because a detector change is its own change + with its own self-test and belongs in a lane that owns the audit. +7. **No server run.** Everything above is local: one gate at a time plus two + ~250 s wide-family runs. Per the project's standing rule the full suite + belongs on the fleet; I did not request or consume a fleet slot.