forge
Explore
Log in

Don't you dare go Hollow

Merge lane-av1dcunit: the 2x1/1x2 rect tiled chroma walk must give each unit its OWN above-right reach

Browse files at this commit

73a4a773b666840bd2a421c4ab077dde1dbfbc1bAhmet Kaan GümüşParent: ef95bead06d31f
The assigned defect was already fixed on main (chromadc, e05a6ceb/2c0fd2b9, merged 15 minutes after
the report that spawned the ticket measured on the older base 5324a685), and the ticket's stated
mechanism is wrong for that witness: an intra-BC block never goes through av1_predict_intra_block, so
there is no per-unit DC and no per-unit above/left -- the prediction is ONE whole-plane-block motion
copy (decodeframe.c:686-688, reconinter_template.inc:228 makes the reference the destination itself),
which is exactly what the crate's whole-plane PALETTE_PRED override is.
The class sweep then found the sibling cell genuinely broken: decode_rect_split's chroma walk handed
EVERY unit the block-level reach, so a 2x1/1x2 grid's units resolved has_top_right over the block's
extent instead of their own (reconintra.c:196/1847). Both call sites now pass cu_reach. Verified here
by mutation: restoring the block reach reds the gate at frame 0 plane U sample 49374 (x=222,y=192),
130 samples wrong -- the lane's own numbers. Declared limit: the 1x2 palette gate stays GREEN under
that mutation, so it does not bite on this substitution.
crates/ec-av1/fixtures/r512_rect1x2_444_palette.obuadded+0 -0

Binary file changed

crates/ec-av1/fixtures/r512_rect2x1_1x2_444.obuadded+0 -0

Binary file changed

crates/ec-av1/src/decode.rsmodified+105 -2
@@ -2743,6 +2743,57 @@ pub(crate) fn reset_palette_sb_strip_hits() {
2743 PALETTE_SB_STRIP_HITS.with(|c| c.set(0));2743 PALETTE_SB_STRIP_HITS.with(|c| c.set(0));
2744 }2744 }
2745 2745
2746+thread_local! {
2747+ /// lane-av1rectreach: units of `decode_rect_split`'s `chroma_tiled` walk
2748+ /// whose PER-UNIT reach ([`tu_reach_rect`], libaom's per-unit
2749+ /// `has_top_right` / `has_bottom_left`) DIFFERS from the block-level
2750+ /// `reach` this walk used to hand every unit -- i.e. units for which the
2751+ /// two answers are not interchangeable. This is what a gate needs before
2752+ /// it compares the walk byte-exactly: if the two agreed everywhere, the
2753+ /// substitution could not change a single predicted sample and the
2754+ /// exactness assert would be measuring a witness the fix cannot touch.
2755+ ///
2756+ /// What it does NOT prove is that the argument handed to the unit reader
2757+ /// is the per-unit one -- the count is taken from the same expression
2758+ /// either way, so deleting the substitution reds the exactness assert
2759+ /// rather than this counter. That is the right way round: the assert is
2760+ /// the claim, this is only the floor under it.
2761+ static RECT_TILED_CHROMA_UNIT_REACH_HITS: std::cell::Cell<usize> =
2762+ const { std::cell::Cell::new(0) };
2763+ /// Chroma units of the same walk whose grid is exactly 2x1 (a 4:4:4
2764+ /// 64x32 chroma plane block as two 32x32 units).
2765+ static RECT_TILED_CHROMA_2X1_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
2766+ /// Chroma units of the same walk whose grid is exactly 1x2 (4:4:4 32x64,
2767+ /// or 16x64 as two 16x32s).
2768+ static RECT_TILED_CHROMA_1X2_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
2769+ /// Chroma units of the same walk in any other multi-unit grid (2x2 and up
2770+ /// -- only reachable at 4:2:2, which is refused, so this stays 0 on
2771+ /// every admitted stream; kept so the match above is exhaustive).
2772+ static RECT_TILED_CHROMA_NXN_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
2773+}
2774+
2775+/// Current values of the four `RECT_TILED_CHROMA_*` counters, in the order
2776+/// `(unit_reach_differs, 2x1, 1x2, other multi-unit)`.
2777+#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
2778+pub(crate) fn rect_tiled_chroma_grid_hits() -> (usize, usize, usize, usize) {
2779+ (
2780+ RECT_TILED_CHROMA_UNIT_REACH_HITS.with(|c| c.get()),
2781+ RECT_TILED_CHROMA_2X1_HITS.with(|c| c.get()),
2782+ RECT_TILED_CHROMA_1X2_HITS.with(|c| c.get()),
2783+ RECT_TILED_CHROMA_NXN_HITS.with(|c| c.get()),
2784+ )
2785+}
2786+
2787+/// Zeroes the four `RECT_TILED_CHROMA_*` counters (gate tests call this
2788+/// before their own decode).
2789+#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
2790+pub(crate) fn reset_rect_tiled_chroma_grid_hits() {
2791+ RECT_TILED_CHROMA_UNIT_REACH_HITS.with(|c| c.set(0));
2792+ RECT_TILED_CHROMA_2X1_HITS.with(|c| c.set(0));
2793+ RECT_TILED_CHROMA_1X2_HITS.with(|c| c.set(0));
2794+ RECT_TILED_CHROMA_NXN_HITS.with(|c| c.set(0));
2795+}
2796+
2746 // lane-t900 r22: palette blocks reconstructed inside an INTER frame (the2797 // lane-t900 r22: palette blocks reconstructed inside an INTER frame (the
2747 // intra-in-inter path, `decode_inter_block`/`decode_inter_block8`) -- counted2798 // intra-in-inter path, `decode_inter_block`/`decode_inter_block8`) -- counted
2748 // apart from [`PALETTE_HITS`] so a witness gate can prove the INTER-frame2799 // apart from [`PALETTE_HITS`] so a witness gate can prove the INTER-frame
@@ -12786,6 +12837,58 @@ fn decode_rect_split(
12786 fctx,12837 fctx,
12787 );12838 );
12788 }12839 }
12840+ // libaom computes `has_top_right` PER TRANSFORM UNIT (defined
12841+ // reconintra.c:196, called from `av1_build_intra_predictors` at
12842+ // reconintra.c:1847 with the txb walk's own
12843+ // `blk_col`/`blk_row`), never per block: the
12844+ // `row_off == 0` arm asks `col_off + top_right_count_unit
12845+ // < plane_bw_unit`, so the FIRST unit of a 2-wide chroma
12846+ // grid reads its above-right out of the already-reconstructed
12847+ // block ABOVE even when the block's own right edge is the
12848+ // frame's. Passing this walk's block-level `reach` gave
12849+ // every unit the same answer, and `PlaneBuf::edges`
12850+ // (decode.rs:20840) truncates the above row at
12851+ // `own_across` when `above_right` is false -- so a
12852+ // directional unit whose angle is below 90
12853+ // (`need_right`, intra.rs:546) predicted with a 32-sample
12854+ // above row where libaom used 64.
12855+ // MEASURED on `fixtures/r512_rect2x1_1x2_444.obu`
12856+ // (4:4:4 8-bit 256x256, one frame): frame 0 plane U 130
12857+ // samples and plane V 30 samples wrong, every one of them
12858+ // in the right 6 columns of the `cu=(0,0)` unit at
12859+ // `mi=(48,48)` `px=(192,192)` -- the unit whose above-right
12860+ // the block reach denied. Row0 and col0 of the prediction
12861+ // matched the oracle exactly and the prediction SUM did
12862+ // not (172662 vs 171512 on U, 125978 vs 126008 on V), so
12863+ // the residual read is bit-identical and the divergence is
12864+ // prediction-side, not entropy. Gate:
12865+ // `a_444_rect_strip_chroma_tiled_2x1_and_1x2_units_take_their_own_above_right_reach`.
12866+ let cu_reach = tu_reach_rect(
12867+ bw,
12868+ bh,
12869+ (cu_col * uw) << ss_x(fctx),
12870+ (cu_row * uh) << ss_y(fctx),
12871+ uw << ss_x(fctx),
12872+ uh << ss_y(fctx),
12873+ reach,
12874+ px,
12875+ py,
12876+ y.width,
12877+ y.height,
12878+ fctx,
12879+ );
12880+ if cu_reach.above_right != reach.above_right
12881+ || cu_reach.below_left != reach.below_left
12882+ {
12883+ hit!(RECT_TILED_CHROMA_UNIT_REACH_HITS);
12884+ }
12885+ if nw * nh > 1 {
12886+ match (nw, nh) {
12887+ (2, 1) => hit!(RECT_TILED_CHROMA_2X1_HITS),
12888+ (1, 2) => hit!(RECT_TILED_CHROMA_1X2_HITS),
12889+ _ => hit!(RECT_TILED_CHROMA_NXN_HITS),
12890+ }
12891+ }
12789 // 32x32 does not fit read_coeffs_rect's scratch (768). The12892 // 32x32 does not fit read_coeffs_rect's scratch (768). The
12790 // square reader is the path every other 32x32 chroma unit uses.12893 // square reader is the path every other 32x32 chroma unit uses.
12791 let levels = if uw == uh {12894 let levels = if uw == uh {
@@ -12800,7 +12903,7 @@ fn decode_rect_split(
12800 m.mode,12903 m.mode,
12801 m.uv_predict_mode,12904 m.uv_predict_mode,
12802 m.angle_delta_uv,12905 m.angle_delta_uv,
12803- reach,12906+ cu_reach,
12804 plane,12907 plane,
12805 cu_x,12908 cu_x,
12806 cu_y,12909 cu_y,
@@ -12848,7 +12951,7 @@ fn decode_rect_split(
12848 uh,12951 uh,
12849 m.uv_predict_mode,12952 m.uv_predict_mode,
12850 m.angle_delta_uv,12953 m.angle_delta_uv,
12851- reach,12954+ cu_reach,
12852 &residual,12955 &residual,
12853 cfl,12956 cfl,
12854 None,12957 None,
crates/ec-av1/src/stream.rsmodified+279 -0
@@ -171,6 +171,18 @@ pub fn reset_skip_chroma_override_window_hits() {
171 crate::decode::reset_skip_chroma_override_window_hits()171 crate::decode::reset_skip_chroma_override_window_hits()
172 }172 }
173 173
174+/// lane-av1rectreach: the `chroma_tiled` walk's per-unit reach and grid-shape
175+/// counters, as `(unit_reach_differs_from_block, 2x1 units, 1x2 units, other
176+/// multi-unit units)`. See [`crate::decode::rect_tiled_chroma_grid_hits`].
177+pub fn rect_tiled_chroma_grid_hits() -> (usize, usize, usize, usize) {
178+ crate::decode::rect_tiled_chroma_grid_hits()
179+}
180+
181+/// Gate-side reset for the lane-av1rectreach counters above.
182+pub fn reset_rect_tiled_chroma_grid_hits() {
183+ crate::decode::reset_rect_tiled_chroma_grid_hits()
184+}
185+
174 /// `(y, uv)` palette blocks RECONSTRUCTED inside an inter frame (lane-t900186 /// `(y, uv)` palette blocks RECONSTRUCTED inside an inter frame (lane-t900
175 /// r22) -- the counter a screen-content witness gate reads to prove it187 /// r22) -- the counter a screen-content witness gate reads to prove it
176 /// exercises the inter-frame palette path, not the key frame's.188 /// exercises the inter-frame palette path, not the key frame's.
@@ -50333,4 +50345,271 @@ pub(crate) mod tests {
50333 }50345 }
50334 let _ = std::fs::remove_dir_all(&dir);50346 let _ = std::fs::remove_dir_all(&dir);
50335 }50347 }
50348+
50349+ /// lane-av1rectreach, the 2x1 / 1x2 half of the class sweep
50350+ /// `a_444_skipped_64x64_square_block_windows_its_chroma_override_per_unit`
50351+ /// opened: `decode_rect_split`'s `chroma_tiled` walk is the THIRD site that
50352+ /// walks a 4:4:4 chroma plane block as a grid of Chroma32 units, and the
50353+ /// only one that handed every unit the BLOCK's reach.
50354+ ///
50355+ /// The other two are already per-unit and are not touched by this gate:
50356+ /// `decode_block`'s skip arm (`chroma_window`, lane-av1chromadc) and
50357+ /// `decode_block`'s coded arm (its own `tu_reach_rect`) both resolve
50358+ /// `has_top_right` per transform unit, the way libaom's
50359+ /// `av1_build_intra_predictors` does
50360+ /// (`has_top_right`, defined reconintra.c:196, called from
50361+ /// `av1_build_intra_predictors` at reconintra.c:1847),
50362+ /// fed the chroma txb walk's own `blk_col`/`blk_row`).
50363+ ///
50364+ /// Witness `fixtures/r512_rect2x1_1x2_444.obu`, 2697 B,
50365+ /// sha256 `a009ec580a1ff24250be53e11b8d09616da71e095cefd5eb621c941d40a8688b`:
50366+ ///
50367+ /// ```text
50368+ /// ffmpeg -f lavfi -i testsrc2=size=256x256:rate=1:duration=1 -pix_fmt yuv444p \
50369+ /// -f rawvideo in.yuv
50370+ /// aomenc --codec=av1 -w 256 -h 256 --i444 --sb-size=64 --enable-palette=1 \
50371+ /// --enable-rect-partitions=1 --enable-1to4-partitions=1 \
50372+ /// --min-partition-size=32 --cq-level=40 --profile=1 --obu --limit=1 \
50373+ /// -o r512_rect2x1_1x2_444.obu in.yuv
50374+ /// ```
50375+ ///
50376+ /// (aom-affine aomenc, one key frame, 4:4:4 8-bit 256x256.) It reaches
50377+ /// BOTH grid shapes: a 64x32 chroma plane block as `nw=2 nh=1` of 32x32
50378+ /// and a 32x64 one as `nw=1 nh=2`.
50379+ ///
50380+ /// RED-BEFORE, on the unpatched tree, measured with `EC_AV1_FINAL_DUMP`
50381+ /// (aomdec) against `set_final_dump_prefix` (ours), 786432 B per frame:
50382+ /// frame 0 plane Y 0 wrong, plane U 130 wrong, plane V 30 wrong -- all of
50383+ /// them in the right 6 columns of the `cu=(0,0)` unit at `mi=(48,48)`
50384+ /// `px=(192,192)`, a 64x32 block whose right edge IS the frame's, so the
50385+ /// block-level reach denied an above-right that libaom's per-unit
50386+ /// `col_off + top_right_count_unit < plane_bw_unit` (0 + 8 < 16) grants.
50387+ /// After: 0 wrong on all three planes.
50388+ #[test]
50389+ fn a_444_rect_strip_chroma_tiled_2x1_and_1x2_units_take_their_own_above_right_reach() {
50390+ const NAME: &str =
50391+ "a_444_rect_strip_chroma_tiled_2x1_and_1x2_units_take_their_own_above_right_reach";
50392+ const FILE: &str = "r512_rect2x1_1x2_444.obu";
50393+ const LEN: usize = 2697;
50394+ const SHA: &str = "a009ec580a1ff24250be53e11b8d09616da71e095cefd5eb621c941d40a8688b";
50395+ const W: usize = 256;
50396+ const PLANE: usize = W * W;
50397+ let path =
50398+ std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR")).join(format!("fixtures/{FILE}"));
50399+ let stream = std::fs::read(&path)
50400+ .unwrap_or_else(|e| panic!("{NAME}: pinned fixture {FILE} missing: {e}"));
50401+ assert_eq!(stream.len(), LEN, "{NAME}: {FILE} length moved");
50402+ assert_444_header(&stream, NAME, 8);
50403+ // The byte pin is fnv1a64, the same load-bearing-identity hash every
50404+ // other pinned gate here uses; the sha256 in this test's comment is
50405+ // the provenance half. A silent stream swap under the same name
50406+ // cannot stay green.
50407+ assert_eq!(
50408+ fnv1a64(&stream),
50409+ 0x2751ccaa079cc422,
50410+ "{NAME}: {FILE} bytes drifted from the fnv1a64 pin above (provenance sha256 \
50411+ {SHA}) -- regenerate the stream with the recipe in this test's comment and \
50412+ re-pin the length, the fnv1a64 and the sha256 together"
50413+ );
50414+
50415+ let _guard = lock_gate_counters();
50416+ reset_rect_tiled_chroma_grid_hits();
50417+ let dir = std::env::temp_dir().join(format!("ec-av1-{NAME}-{}", std::process::id()));
50418+ let _ = std::fs::remove_dir_all(&dir);
50419+ std::fs::create_dir_all(&dir).expect("scratch dir");
50420+ let obu = dir.join("in.obu");
50421+ std::fs::write(&obu, &stream).expect("writing the stream");
50422+ let aom_prefix = dir.join("aom");
50423+ let out = Command::new(aomdec_path())
50424+ .args(["--codec=av1", "-o"])
50425+ .arg(dir.join("out.y4m"))
50426+ .arg(&obu)
50427+ .env("EC_AV1_FINAL_DUMP", &aom_prefix)
50428+ .stdin(Stdio::null())
50429+ .stdout(Stdio::piped())
50430+ .stderr(Stdio::piped())
50431+ .output()
50432+ .expect("aomdec failed to run");
50433+ assert!(
50434+ out.status.success(),
50435+ "{NAME}: the oracle aomdec refused the stream: {}",
50436+ String::from_utf8_lossy(&out.stderr)
50437+ );
50438+ let ours_prefix = dir.join("ours");
50439+ set_final_dump_prefix(Some(ours_prefix.display().to_string()));
50440+ if let Err(e) = decode_stream(&stream) {
50441+ panic!("{NAME}: this decoder refused the witness: {e}");
50442+ }
50443+ set_final_dump_prefix(None);
50444+
50445+ // Non-vacuity, in the order the claim depends on it: the walk must
50446+ // have reached a 2x1 AND a 1x2 grid, and at least one unit must have
50447+ // a per-unit reach that DIFFERS from the block-level one. Without the
50448+ // last one the two answers would be interchangeable everywhere and
50449+ // the exactness below would be measuring a witness the fix cannot
50450+ // touch. (It does not check the argument identity -- see
50451+ // `RECT_TILED_CHROMA_UNIT_REACH_HITS`; the exactness assert below is
50452+ // what reds when the substitution is deleted.)
50453+ let (reach_hits, h2x1, h1x2, h_nxn) = rect_tiled_chroma_grid_hits();
50454+ assert!(
50455+ h2x1 >= 4 && h1x2 >= 4,
50456+ "{NAME}: the walk reached {h2x1} unit(s) in a 2x1 grid and {h1x2} in a 1x2 grid \
50457+ (other multi-unit shapes: {h_nxn}), expected at least 4 of each -- the witness \
50458+ stopped exercising one of the two grid shapes, so half the claim is vacuous"
50459+ );
50460+ assert!(
50461+ reach_hits >= 1,
50462+ "{NAME}: {reach_hits} chroma unit(s) had a per-unit reach differing from the \
50463+ block-level one, expected at least 1 -- on the unpatched tree every unit took \
50464+ the block's reach, so the exactness below is vacuous"
50465+ );
50466+
50467+ let aom_dump = std::fs::read(format!("{}.f0", aom_prefix.display()))
50468+ .unwrap_or_else(|e| panic!("{NAME}: oracle dump f0 missing: {e}"));
50469+ let our_dump = std::fs::read(format!("{}.f0", ours_prefix.display()))
50470+ .unwrap_or_else(|e| panic!("{NAME}: our dump f0 missing: {e}"));
50471+ assert_eq!(
50472+ our_dump.len(),
50473+ 3 * PLANE,
50474+ "{NAME}: frame 0 is not 8-bit 4:4:4 256x256"
50475+ );
50476+ for (plane, pname) in [(0usize, "Y"), (1, "U"), (2, "V")] {
50477+ let at = plane * PLANE;
50478+ if our_dump[at..at + PLANE] == aom_dump[at..at + PLANE] {
50479+ continue;
50480+ }
50481+ let first = (0..PLANE)
50482+ .find(|&s| our_dump[at + s] != aom_dump[at + s])
50483+ .unwrap_or(PLANE);
50484+ let wrong = (0..PLANE)
50485+ .filter(|&s| our_dump[at + s] != aom_dump[at + s])
50486+ .count();
50487+ panic!(
50488+ "{NAME}: frame 0 plane {pname} is byte-exact nowhere -- first divergence at \
50489+ sample {first} of {PLANE} (x={}, y={}), {wrong} samples wrong. Each unit of \
50490+ this walk must resolve `has_top_right` over ITS OWN extent \
50491+ (reconintra.c:196/1847), not the block's: the seed unit is cu=(0,0) of \
50492+ 64x32 chroma grid at mi=(48,48) px=(192,192), whose right 6 columns are the \
50493+ ones the truncated above row moved.",
50494+ first % W,
50495+ first / W
50496+ );
50497+ }
50498+ let _ = std::fs::remove_dir_all(&dir);
50499+ }
50500+
50501+ /// The UV-PALETTE half of the same class, and the cell
50502+ /// `lanes/av1chromadc.report.md` §5 left explicitly UNMEASURED ("every
50503+ /// multi-unit walk on this witness is `src=intrabc`; the UV-palette source
50504+ /// never reaches a multi-unit chroma walk here, so its arm of the sweep is
50505+ /// argued from the shared code path, not witnessed"). This witness is the
50506+ /// measurement: it puts a UV-palette block on a 1x2 16x64 chroma grid
50507+ /// (`mi=(32,12)`) as well as plenty of non-palette ones.
50508+ ///
50509+ /// Witness `fixtures/r512_rect1x2_444_palette.obu`, 2250 B,
50510+ /// sha256 `fad03c69087f316c1a117e8d8a70769d161b332bce7b2998e646312bb78fb067`:
50511+ ///
50512+ /// ```text
50513+ /// ffmpeg -f lavfi -i testsrc2=size=256x256:rate=1:duration=1 -pix_fmt yuv444p \
50514+ /// -f rawvideo in.yuv
50515+ /// aomenc --codec=av1 -w 256 -h 256 --i444 --sb-size=64 --enable-palette=1 \
50516+ /// --enable-rect-partitions=1 --enable-1to4-partitions=1 \
50517+ /// --min-partition-size=16 --cq-level=40 --profile=1 --obu --limit=1 \
50518+ /// -o r512_rect1x2_444_palette.obu in.yuv
50519+ /// ```
50520+ ///
50521+ /// (`--min-partition-size=16` is what puts the 16x64 chroma grid on a
50522+ /// strip at all; at 32 the encoder only ever picks 32x64 / 64x32.) The
50523+ /// per-unit reach the fix installs is the same line for the palette and
50524+ /// the non-palette unit -- the palette only supplies the PREDICTION
50525+ /// (`palette_window`, decode.rs:12784), never the reach -- so this gate
50526+ /// exists to pin the prediction source down, not to re-prove the reach.
50527+ #[test]
50528+ fn a_444_rect_strip_chroma_tiled_1x2_palette_grid_decodes_byte_exact() {
50529+ const NAME: &str = "a_444_rect_strip_chroma_tiled_1x2_palette_grid_decodes_byte_exact";
50530+ const FILE: &str = "r512_rect1x2_444_palette.obu";
50531+ const LEN: usize = 2250;
50532+ const SHA: &str = "fad03c69087f316c1a117e8d8a70769d161b332bce7b2998e646312bb78fb067";
50533+ const W: usize = 256;
50534+ const PLANE: usize = W * W;
50535+ let path =
50536+ std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR")).join(format!("fixtures/{FILE}"));
50537+ let stream = std::fs::read(&path)
50538+ .unwrap_or_else(|e| panic!("{NAME}: pinned fixture {FILE} missing: {e}"));
50539+ assert_eq!(stream.len(), LEN, "{NAME}: {FILE} length moved");
50540+ assert_444_header(&stream, NAME, 8);
50541+ assert_eq!(
50542+ fnv1a64(&stream),
50543+ 0x7759753a0d3f75a2,
50544+ "{NAME}: {FILE} bytes drifted from the fnv1a64 pin above (provenance sha256 \
50545+ {SHA}) -- regenerate the stream with the recipe in this test's comment and \
50546+ re-pin the length, the fnv1a64 and the sha256 together"
50547+ );
50548+
50549+ let _guard = lock_gate_counters();
50550+ reset_rect_tiled_chroma_grid_hits();
50551+ let dir = std::env::temp_dir().join(format!("ec-av1-{NAME}-{}", std::process::id()));
50552+ let _ = std::fs::remove_dir_all(&dir);
50553+ std::fs::create_dir_all(&dir).expect("scratch dir");
50554+ let obu = dir.join("in.obu");
50555+ std::fs::write(&obu, &stream).expect("writing the stream");
50556+ let aom_prefix = dir.join("aom");
50557+ let out = Command::new(aomdec_path())
50558+ .args(["--codec=av1", "-o"])
50559+ .arg(dir.join("out.y4m"))
50560+ .arg(&obu)
50561+ .env("EC_AV1_FINAL_DUMP", &aom_prefix)
50562+ .stdin(Stdio::null())
50563+ .stdout(Stdio::piped())
50564+ .stderr(Stdio::piped())
50565+ .output()
50566+ .expect("aomdec failed to run");
50567+ assert!(
50568+ out.status.success(),
50569+ "{NAME}: the oracle aomdec refused the stream: {}",
50570+ String::from_utf8_lossy(&out.stderr)
50571+ );
50572+ let ours_prefix = dir.join("ours");
50573+ set_final_dump_prefix(Some(ours_prefix.display().to_string()));
50574+ if let Err(e) = decode_stream(&stream) {
50575+ panic!("{NAME}: this decoder refused the witness: {e}");
50576+ }
50577+ set_final_dump_prefix(None);
50578+
50579+ let (_reach_hits, h2x1, h1x2, _h_nxn) = rect_tiled_chroma_grid_hits();
50580+ assert!(
50581+ h1x2 >= 4,
50582+ "{NAME}: the walk reached {h1x2} unit(s) in a 1x2 grid ({h2x1} in a 2x1), expected \
50583+ at least 4 of the 1x2 -- the witness stopped exercising the arm"
50584+ );
50585+
50586+ let aom_dump = std::fs::read(format!("{}.f0", aom_prefix.display()))
50587+ .unwrap_or_else(|e| panic!("{NAME}: oracle dump f0 missing: {e}"));
50588+ let our_dump = std::fs::read(format!("{}.f0", ours_prefix.display()))
50589+ .unwrap_or_else(|e| panic!("{NAME}: our dump f0 missing: {e}"));
50590+ assert_eq!(
50591+ our_dump.len(),
50592+ 3 * PLANE,
50593+ "{NAME}: frame 0 is not 8-bit 4:4:4 256x256"
50594+ );
50595+ for (plane, pname) in [(0usize, "Y"), (1, "U"), (2, "V")] {
50596+ let at = plane * PLANE;
50597+ if our_dump[at..at + PLANE] == aom_dump[at..at + PLANE] {
50598+ continue;
50599+ }
50600+ let first = (0..PLANE)
50601+ .find(|&s| our_dump[at + s] != aom_dump[at + s])
50602+ .unwrap_or(PLANE);
50603+ let wrong = (0..PLANE)
50604+ .filter(|&s| our_dump[at + s] != aom_dump[at + s])
50605+ .count();
50606+ panic!(
50607+ "{NAME}: frame 0 plane {pname} is byte-exact nowhere -- first divergence at \
50608+ sample {first} of {PLANE} (x={}, y={}), {wrong} samples wrong.",
50609+ first % W,
50610+ first / W
50611+ );
50612+ }
50613+ let _ = std::fs::remove_dir_all(&dir);
50614+ }
50336 }50615 }
lanes/av1dcunit.report.mdadded+322 -0
@@ -0,0 +1,322 @@
1+# lane-av1dcunit — the assigned defect was already fixed; the 2x1/1x2 class cell was not
2+
3+Worktree `~/.cache/wt/av1dcunit`, branch `lane-av1dcunit`, base `70ed5601`
4+("Merge lane-av1txctxband"). Two commits: one read-only verification of the
5+assigned defect, one fix for the class-sweep cell the verification found.
6+
7+## 1. Headline: the assigned defect is NOT on `70ed5601` — it was fixed 55 minutes before this lane started
8+
9+`lanes/av1chromarect-r2.report.md` (the ticket's source) measured its 79969
10+samples on base `5324a685`. The fix landed on main **after** that base and
11+**before** the r2 report was even merged:
12+
13+| sha | time | what |
14+| --- | --- | --- |
15+| `5324a685` | 01:36 | r2's base — 79969 chroma samples wrong |
16+| `57834ee2` | 01:49 | r2's report merged (numbers measured on `5324a685`) |
17+| `e05a6ceb` | **02:04** | **the fix**: "4:4:4 2x2 chroma walk: window the intra-BC/palette override per unit" |
18+| `2c0fd2b9` | 02:12 | merge of `lane-av1chromadc` — 79969 → 0 |
19+| `70ed5601` | 02:58 | this lane's base |
20+
21+`git merge-base --is-ancestor e05a6ceb 5324a685` → false. The r2 report and the
22+fix were two lanes working the same residual from two bases; the fix won by 15
23+minutes. So there was nothing to fix for the ticket as written, and this lane
24+verified that rather than re-doing it.
25+
26+## 2. The assigned defect, re-measured here (red-before included)
27+
28+**Mechanism, and it is NOT the one the ticket names.** The ticket (following
29+r2 §3) says libaom "builds the DC from THAT UNIT's own above row and left
30+column (`av1_build_dc_predictor_sb`)". For this witness that is wrong, and the
31+seed proves it: the seed is `skip=1` on an **intra-BC** block, and an intra-BC
32+block never reaches `av1_predict_intra_block` at all. libaom's decoder routes
33+it through the inter path instead:
34+
35+* `decodeframe.c:1146` — `int inter_block_tx = is_inter_block(mbmi) || is_intrabc_block(mbmi);`
36+* `decodeframe.c:847` `predict_inter_block` → `decodeframe.c:676` `dec_build_inter_predictor`
37+* `decodeframe.c:686-688` — one `dec_build_inter_predictors` call per plane with
38+ `bw = xd->plane[plane].width, bh = xd->plane[plane].height`, i.e. the WHOLE
39+ chroma plane block at once, not per transform unit
40+* `reconinter_template.inc:228` — `const struct buf_2d *const pre_buf = is_intrabc ? dst_buf : &pd->pre[ref];`
41+ the intra-BC reference **is the destination buffer**, so the prediction is a
42+ motion-compensated copy of the current frame's own reconstruction
43+* the units are then reconstructed in place on top of it, with no edge read
44+
45+So there is no per-unit DC and no per-unit above/left on this path. What the
46+crate's whole-plane-block `PALETTE_PRED` override buffer is, in libaom's terms,
47+is that single whole-plane-block motion prediction — and
48+`PlaneBuf::reconstruct` consumes the buffer it is handed as the **unit's own**
49+`chroma_tx x chroma_tx_h` prediction (`decode.rs:20939` and `21087`,
50+`let prediction = if let Some(buf) = pred { buf } else { … }`). Handing the whole
51+buffer to every unit of a 2x2 grid makes all four units predict from the
52+top-left one. That is the defect, and `e05a6ceb`'s `chroma_window` is the
53+correct fix for it.
54+
55+**Red-before, measured in THIS worktree** by mutating `chroma_window` back to
56+the pre-fix whole-buffer shape (that is mutation M1 of §5) and running the
57+landed gate `a_444_skipped_64x64_square_block_windows_its_chroma_override_per_unit`:
58+
59+```
60+decode-order frame 0 plane U is byte-exact nowhere -- first divergence at
61+sample 229728 of 262144 (x=352, y=448), 7488 samples wrong.
62+test result: FAILED. 0 passed; 1 failed
63+```
64+
65+Full per-plane counts, from my own compare script outside the repo
66+(`~/.cache/cmp444.py`, reading the `EC_AV1_FINAL_DUMP` dumps of both sides):
67+
68+| frame | Y | U | V |
69+| --- | --- | --- | --- |
70+| 0 | 0 | **7488** | **8128** |
71+| 1 | 0 | **22571** | **41782** |
72+| 2 | 0 | 0 | 0 |
73+
74+Total **79969 of 2359296** — r2's number exactly. The three regions the ticket
75+names, frame 0:
76+
77+| region | U wrong | V wrong | first wrong |
78+| --- | --- | --- | --- |
79+| seed `[320,384)x[448,512)` | 864 / 2048 | 1024 / 2048 | (352,448) |
80+| sibling `[384,448)x[448,512)` | 1664 / 4096 | 1984 / 4096 | (416,448) |
81+| victim `[448,512)x[448,512)` | **4096 / 4096** | **4096 / 4096** | (448,448) |
82+
83+f0 U, row y=448, every 16th sample from x=320 (the 2x2 grid boundary is
84+x = 352 = 320+32):
85+
86+```
87+oracle: 241 239 202 202 202 202 203 165 166 166 166 166
88+ours : 241 239 241 239 202 202 202 202 175 175 171 171
89+```
90+
91+The seed's `cu=(1,0)` is a flat 241 — its sibling's value — exactly as the
92+ticket describes, and the victim is wrong on every sample.
93+
94+**After (fix in place, same oracle, same script): 0 wrong on all three planes
95+of all three frames, 0 of 2359296.** All three named regions are 0/2048 and
96+0/4096. The f0 U row above matches the oracle in all 12 samples.
97+
98+One correction to the ticket's "clean sibling control": `[384,448)x[448,512)`
99+is **not** clean under this defect — 1664 U and 1984 V samples wrong, first at
100+(416,448). What r2 measured clean was that block's *edge samples* are all ≈202,
101+so "any DC rule reproduces the oracle" for it (r2 §3); its pixels still move
102+because an intra-BC block's reference is the current frame's own
103+reconstruction, so the seed's error propagates one block to the right. The
104+first dirty cell is x=416, not x=352, for that block.
105+
106+## 3. Acceptance
107+
108+1. **Red-before per plane** — §2, 7488 / 8128 / 22571 / 41782, total 79969,
109+ dumped with `EC_AV1_FINAL_DUMP` and compared by `~/.cache/cmp444.py`.
110+2. **After** — 0 wrong on Y, U, V of all three frames; all three named regions
111+ exact. Nothing remains in the regions the seed/victim cover.
112+3. **Gate** — `a_444_skipped_64x64_square_block_windows_its_chroma_override_per_unit`
113+ (landed by `e05a6ceb`, aomdec oracle required, no silent skip). Pin
114+ `fixtures/r512.obu`, 6948 B, sha256
115+ `f587f0f980f149abce905e3ef66f2f1634f050c85430626eafb9c30a1e25bc21`,
116+ already committed — no regeneration needed.
117+4. **Mutation** — M1 below.
118+5. **Re-quotes, unchanged** — §4.
119+6. **Class sweep** — §5, and it found a real second defect, which this lane
120+ fixed.
121+
122+## 4. Re-quotes on this branch (nothing in §2's path changed)
123+
124+```
125+$ cargo check -p ec-av1 --all-targets # 0 errors, 0 warnings
126+$ cargo test -p ec-av1 --lib -- a_444 lossless_444 intrabc_rect 444_lossless 420_intrabc_rect4
127+test result: ok. 39 passed; 0 failed; 0 ignored; 0 measured; 736 filtered out; finished in 12.44s
128+```
129+
130+The 39 carry the 4:4:4-lossless family (`a_lossless_444_*`,
131+`a_444_lossless_sb64_intrabc_rect_chroma_walks_4x4_units`,
132+`a_real_aomenc_lossless_444_key_frame_decodes_sample_exact`), the intrabc_rect
133+family (`a_444_intrabc_owned_rect_*`, `a_444_intrabc_rect4_*`), and the 4:2:0
134+twin (`a_444_intrabc_rect_chroma_plane_block_is_the_block_footprint`, which
135+runs its `420_intrabc_rect4_witness.obu` sibling through
136+`decode_all_frames_vs_oracle`).
137+
138+Wider family, once per tree, same filter string, same env, private
139+`CARGO_TARGET_DIR`:
140+
141+```
142+$ cargo test -p ec-av1 --lib -- rect intrabc ibc chroma 444 420 subsampl
143+base 70ed5601 (clean, detached) ok. 145 passed; 0 failed; 5 ignored; 0 measured; 623 filtered out; finished in 272.43s
144+this branch tip ok. 147 passed; 0 failed; 5 ignored; 0 measured; 623 filtered out; finished in 273.28s
145+```
146+
147+145 -> 147: the delta is exactly this lane's two new gates and nothing else
148+(`--list` reads 775 tests on both trees). Same 5 `#[ignore]`d in both. **No
149+test was renamed, dropped or `#[ignore]`d.** **No floor was lowered anywhere**; the only new asserts are the two
150+gates of §5.
151+
152+## 5. Class sweep — and the 2x1 / 1x2 cell was broken
153+
154+Every site in the crate that walks a 4:4:4 chroma plane block as a grid of
155+`Chroma32` units, and what it hands each unit:
156+
157+| # | site | grid reachable at 4:4:4 | per-unit **window** | per-unit **reach** |
158+| --- | --- | --- | --- | --- |
159+| 1 | `decode_block` skip arm (decode.rs:21897) | 2x2 (NxN) | `chroma_window` — fixed by `e05a6ceb` | `tu_reach_rect` ✓ |
160+| 2 | `decode_block` coded arm (decode.rs:22182) | 2x2 (NxN) | `palette_window` ✓ | `tu_reach_rect` ✓ |
161+| 3 | `decode_rect_split` `chroma_tiled` (decode.rs:12721) | **2x1, 1x2, and 2x2** | `palette_window` ✓ | **block `reach` — WRONG** |
162+
163+Site 3 is the only one that can produce a **2x1 or 1x2** grid at all, and it
164+was the only one passing the block's `reach` to every unit. Sites 1 and 2 can
165+never be 2x1/1x2: a square luma block's chroma plane block has
166+`chroma_side == chroma_height` at every supported subsampling (4:2:0 → `>>1,>>1`;
167+4:4:4 → identity; 4:2:2 is the only asymmetric one and is refused by name at
168+the sequence header, `stream.rs:1783`), and `chroma_tx == chroma_tx_h`, so
169+`cn_cols == cn_rows` always. A 2x1/1x2 needs a rect luma block, i.e. site 3.
170+
171+**The defect, measured.** `decode_rect_split`'s `chroma_tiled` walk passed the
172+block-level `reach` to every unit. libaom computes `has_top_right` PER
173+TRANSFORM UNIT — `av1_build_intra_predictors` calls it with the chroma txb
174+walk's own `blk_col`/`blk_row` (defined `reconintra.c:196`, called from
175+`av1_build_intra_predictors` at `reconintra.c:1847`), and the `row_off == 0`
176+arm is `col_off + top_right_count_unit < plane_bw_unit`, so the FIRST unit of a
177+2-wide grid reads its above-right out of the already-reconstructed block ABOVE
178+even when the block's own right edge is the frame's. `PlaneBuf::edges`
179+(`decode.rs:20840`) truncates the above row at `own_across` when
180+`above_right` is false, so a directional unit whose angle is below 90
181+(`need_right`, `intra.rs:546`) predicted from a 32-sample above row where libaom
182+used 64.
183+
184+Witness encoded here (recipe and sha256 in the gate's doc comment):
185+`fixtures/r512_rect2x1_1x2_444.obu`, 2697 B, sha256
186+`a009ec580a1ff24250be53e11b8d09616da71e095cefd5eb621c941d40a8688b` — 4:4:4 8-bit
187+256x256, one key frame, and it reaches BOTH shapes: a 64x32 chroma plane block
188+as `nw=2 nh=1` of 32x32 and a 32x64 one as `nw=1 nh=2`.
189+
190+Red-before, per plane, my own script:
191+
192+```
193+f0: Y 0 wrong U 130 wrong V 30 wrong (of 65536 per plane)
194+```
195+
196+All 160 wrong samples are in the right 6 columns of the `cu=(0,0)` unit at
197+`mi=(48,48)` `px=(192,192)` — a 64x32 block whose right edge IS the frame's.
198+Oracle `EC_PRED` for that unit vs ours:
199+
200+```
201+oracle EC_PRED mi_row=48 mi_col=48 plane=1 row_off=0 col_off=0 txw=32 txh=32
202+ mode=1 p_angle=84 have_top=1 have_left=1 n_top=32 n_left=32
203+ n_tr=32 n_bl=-1 bsize=11 part=1 ft=1
204+oracle EC_PREDOUT8 ... sum=172662 row0=179,185,190,195,197,198,197,194 col0=179,180,181,181,182,182,183,183
205+ours OUR_PRED x=192 y=192 plane=1 side=32 mode=1 ad=-2 ft=1
206+ sum=171512 row0=[179,185,190,195,197,198,197,194] col0=[179,180,181,181,182,182,183,183]
207+```
208+
209+`bsize=11` is `BLOCK_64X32`; `n_tr=32` against our `above_right = false` is the
210+whole defect in one number. `row0` and `col0` match exactly and only the SUM
211+differs (172662 vs 171512, and 125978 vs 126008 on V), so the divergence is
212+prediction-side, not entropy. Stage-attributed against the oracle's own rungs:
213+the same 130/30 wrong appear in `EC_AV1_PREFILT_DUMP` and in
214+`EC_AV1_FINAL_DUMP` — pre-loop-filter, so not deblock/CDEF/LR. `n_tr=32` also
215+explains the shape of the error: the U delta per column is
216+-1, -5, -9, -14, -18, -19, growing monotonically rightward, which is a
217+directional prediction reaching further right as it goes.
218+
219+**The fix.** One expression, both unit readers in the walk (the square
220+`read_plane` and the rect `push_intra_rect`), each given the unit's own reach:
221+
222+```rust
223+let cu_reach = tu_reach_rect(
224+ bw, bh,
225+ (cu_col * uw) << ss_x(fctx),
226+ (cu_row * uh) << ss_y(fctx),
227+ uw << ss_x(fctx), uh << ss_y(fctx),
228+ reach, px, py, y.width, y.height, fctx,
229+);
230+```
231+
232+`tu_reach_rect` is the crate's existing port of the per-unit rule (it is what
233+sites 1 and 2 already call), so this is site 3 joining the other two, not a new
234+rule. `cu_reach` is also what `of_tu` needs at 4:4:4: the ss shifts are
235+identity there and the per-axis spelling is what makes the same call correct at
236+4:2:0 and at 4:2:2 if 4:2:2 is ever ported.
237+
238+**After: 0 wrong on all three planes.** Every region the sweep covers.
239+
240+**Gates** (both aomdec-oracle, no silent skip, both with the counters asserted
241+before a single sample is compared):
242+
243+* `a_444_rect_strip_chroma_tiled_2x1_and_1x2_units_take_their_own_above_right_reach`
244+ — asserts `>= 4` units in a 2x1 grid AND `>= 4` in a 1x2 grid, and
245+ `>= 1` unit whose per-unit reach differs from the block's, then full
246+ byte-exactness of all three planes of frame 0. Pin
247+ `fixtures/r512_rect2x1_1x2_444.obu`, fnv1a64 `0x2751ccaa079cc422`, sha256
248+ `a009ec58…`, recipe in the doc comment.
249+* `a_444_rect_strip_chroma_tiled_1x2_palette_grid_decodes_byte_exact`
250+ — the **UV-palette cell that `lanes/av1chromadc.report.md` §5 left explicitly
251+ unmeasured** ("every multi-unit walk on this witness is `src=intrabc`; the
252+ UV-palette source never reaches a multi-unit chroma walk here, so its arm of
253+ the sweep is argued from the shared code path, not witnessed"). Pin
254+ `fixtures/r512_rect1x2_444_palette.obu`, fnv1a64 `0x7759753a0d3f75a2`,
255+ sha256 `fad03c69…` — it puts a UV-palette block on a 1x2 16x64 chroma grid at
256+ `mi=(32,12)` (measured with a throwaway probe, since removed) as well as
257+ non-palette ones.
258+
259+**Mutation proofs, each reverted:**
260+
261+| # | mutation | result |
262+| --- | --- | --- |
263+| 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` |
264+| 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** |
265+
266+M2 is worth stating plainly. On this witness the second/bottom unit of each
267+grid sits flush against the frame's right/bottom edge, so
268+`Reach`'s `.min(self.width)` clamp in `edges`/`edges_rect` truncates the extra
269+reach back to nothing and the transposition becomes unobservable. The
270+transposed expression is still wrong, and no witness in this lane distinguishes
271+it. A gate that claimed to cover it would be a false claim, so neither gate
272+does: they pin the reach VALUE (M1 bites), not the offset spelling.
273+
274+## 6. The other multi-unit `set_palette_pred` sites, for the record
275+
276+All 19 `set_palette_pred` call sites were enumerated and each classified by its
277+enclosing loop. Every one is either already windowed per unit
278+(`palette_window` at decode.rs:12633, 12784, 16685, 16955; `chroma_window` at
279+21953/21975) or is a genuinely single-unit read where the whole buffer IS the
280+unit's window (`decode_block_rect` 15378/15396/15559/15607 and
281+`decode_leaf_rect` 15996/16014/16175/16220 read `chroma_w x chroma_h` once per
282+plane; `decode_block_rect4` 16825/16859 loops over PLANES of a 4x4 block, not
283+units). One site is unwindowed inside a unit loop —
284+`decode_rect_split` 12525, the `(4,8)` chroma units of a 4:2:2 `BLOCK_INVALID`
285+plane — and it is unreachable: `chroma_422_oob` and `chroma_422_pair_wide` both
286+require `ss_x == 1 && ss_y == 0`, i.e. the 4:2:2 that `stream.rs:1783` refuses
287+by name.
288+
289+## 7. Not done
290+
291+1. **The 2x1/1x2 offset spelling is unproven** (M2, §5). Closing it needs a
292+ witness whose 2x1/1x2 unit is NOT against a frame edge — a wider frame, or
293+ `--sb-size=128` with a 64x64 mu chunk boundary, where `of_tu`'s `wide`
294+ branch (`col_off % 64`) becomes reachable. Not encoded here.
295+2. **`decode_rect_split`'s 2x2 / `NxN` cell is unreachable**, so
296+ `RECT_TILED_CHROMA_NXN_HITS` is 0 on every admitted stream. It is kept so
297+ the `match` over grid shapes is exhaustive rather than silently
298+ default-shaped; it is not a coverage claim.
299+3. **The 4:2:2 `(4,8)` unwindowed site (decode.rs:12525) is argued unreachable,
300+ not proven so** — the argument is the sequence header's named refusal, and I
301+ did not run a 4:2:2 stream through the refusal to watch it fire on this
302+ branch.
303+4. **No 4:2:2 stream was encoded**, so nothing here re-verifies the
304+ `EC_AV1_ALLOW_422_PROBE` bypass or any 4:2:2 arm.
305+5. **The 4:4:4-LOSSY 2x2 cell of site 1 and site 2** (i.e. a skipped 64x64
306+ intra-BC block with a residual rather than pure prediction) is not
307+ distinguished from the skip cell by any pin here; `r512.obu`'s two
308+ multi-unit blocks are both `skip=1`.
309+6. **`scripts/pin-gate-audit.py` does not see EITHER new gate** (nor the two
310+ pre-existing `r512.obu` gates it sits next to): it recovers a pin name only
311+ from a literal `"/fixtures/..."` string, a `crate_pin("X")` /
312+ `pin_dir().join("X")` call, or a 3+-item list, and this whole family builds
313+ its path as `PathBuf::from(env!("CARGO_MANIFEST_DIR")).join(format!(
314+ "fixtures/{FILE}"))` off a `const FILE`. The audit therefore reports
315+ `total=9 gates / 22 names, uncommitted=0` on this branch and exits 0, which
316+ is a true pass for what it looks at and a SILENT GAP for this family. The
317+ fnv1a64 asserts in both gates are the real pin check and they do run; I did
318+ not widen the audit's detector, because a detector change is its own change
319+ with its own self-test and belongs in a lane that owns the audit.
320+7. **No server run.** Everything above is local: one gate at a time plus two
321+ ~250 s wide-family runs. Per the project's standing rule the full suite
322+ belongs on the fleet; I did not request or consume a fleet slot.