forge
Explore
Log in

Don't you dare go Hollow

lane-av1422llpred2: a chroma plane's reach is answered against the PLANE-SCALED block -- ll422_allintra is byte-exact

Browse files at this commit

8530c0197902fce5c6717e5f9e9086017714ced0Ahmet Kaan GümüşParent: cd17c30
ROOT CAUSE (named expression): libaom computes `bsize = scale_chroma_bsize(mbmi->bsize, ss_x, ss_y)`
(reconintra.c:1649, called from av1_predict_intra_block at :1823), so a CHROMA plane's
has_top_right/has_bottom_left are answered against the PLANE-SCALED block shape, not the luma block's.
At ss (1,0) a BLOCK_4X4 luma leaf is answered as BLOCK_8X4 = 2 mi wide, 1 mi tall.

MECHANISM: that widening puts `blk_col_in_sb = (mi_col & (sb_mi_size - 1)) >> bw_in_mi_log2` at 0
where the one-mi-wide luma BLOCK_4X4 reads column 1 (reconintra.c:421), so libaom takes the
"leftmost column of superblock" arm (reconintra.c:429-435) -- `8 + 0 + 1 < 16 >> 0` is TRUE -- which the
per-block has_bl_4x4 table denies. Ours was `Reach::of(4, px, py, ...)` -> `Reach::bottom_left` ->
has_bl_4x4 at (row 8, col 1, per_side 16), index 257 -> HAS_BOTTOM_LEFT[3][32] = 84 = 0b0101_0100,
bit 1 CLEAR -> below_left = FALSE, so the below-left column was never copied and the directional
predictor's base term came off a replicated tail.

FIX: `Reach::of_tu_chroma(..)` with mi_bw/mi_bh from `chroma_mi_shape(leaf_shape, ss_x, ss_y)`
(encode.rs), the Rust transcription of scale_chroma_bsize -- only the BLOCK_4X4/4X8/8X4/4X16/16X4
family is remapped, every other size passes through, so at ss (0,0) and for any block of 8 or more this
is the block's own (bw/4, bh/4). For the failing unit: bw_log2 = 1, blk_col = (49 & 15) >> 1 = 0,
from_block = 8, sb_height = 16 - 8 = 8, `0 + 4 < 8 << 2 = 32` -> below_left TRUE.

WHY THE SIGNATURE WAS INTERIOR-ONLY: build_directional_and_filter_intra_predictors
(reconintra.c:1150-1158) copies n_left_px into left_col[0..3] and, only `if (n_bottomleft_px > 0)`, the
next n_bottomleft_px into left_col[4..7]; with the reach denied left_col[4..7] is never copied.
av1_dr_prediction_z3_c reads left_col[base]/[base+1] with base = (23*(c+1)+r) >> 6
(dr_intra_derivative[70] = 23). At p_angle 203 row 0 is above-driven and col 0 reads only left_col[0..3],
so row0/col0 stay byte-identical and only the interior base term moves -- coefficients untouched, hence
a bit-identical stream.

PLACEMENT WAS RULED OUT FIRST, not assumed: the oracle's rung reports mi_col=49 while the unit lands at
chroma x 96 -- both are right (49 is the ODD-column chroma-reference leaf, `is_chroma_reference`,
av1_common_int.h:1454, and setup_pred_plane snaps the plane origin back to the even column,
reconinter.h:392-393). Verified placement identical (both U planes agree byte-for-byte at chroma
x 96..99 on the failing rows; 2400 chroma units per plane = a perfect 160x240 tiling on both sides)
BEFORE blaming the reach.

MEASURED BY MAIN on this branch, bypassed release build vs `aomdec --rawvideo`, `cmp`:
- ll422_allintra: BYTE-EXACT (was Y 0 / U 2984 / V 3067); prediction-sum disagreements 453 of 9600 -> 0.
- controls ll420_allintra and ll444_allintra: still BYTE-EXACT.
- W_intrabc (16 frames): Y 917974 / U 474453 / V 487693 (U -53); X_intrabc_tiled: 864325/421720/414871
  (unchanged within a few samples) -- the 16-frame lossless INTER cells are a different mechanism.
Oracle-flip control: one oracle byte rotated moves the count by exactly +1.

NOT GATEABLE, stated plainly: 4:2:2 is refused at the sequence header, so no committed test build can
reach the fixed path; the evidence is the measurement table plus the flip control, and this change is
NOT described as gated. Regression: 420/422/444/lossless/warp/intra -- see the merge message.
crates/ec-av1/src/decode.rsmodified+61 -15
@@ -1604,7 +1604,6 @@ fn tu_reach(
1604 /// twice as wide as it is tall). Same predicate as [`tu_reach`]; the1604 /// twice as wide as it is tall). Same predicate as [`tu_reach`]; the
1605 /// square mismatch counter only means anything when the footprint actually1605 /// square mismatch counter only means anything when the footprint actually
1606 /// is square.1606 /// is square.
1607-#[allow(clippy::too_many_arguments)]
1608 fn tu_reach_rect(1607 fn tu_reach_rect(
1609 bw: usize,1608 bw: usize,
1610 bh: usize,1609 bh: usize,
@@ -3971,7 +3970,6 @@ fn wave_barrier(fctx: &crate::decode::FrameCtx) {
3971 3970
3972 /// Performs an intra write at its push site when the tile registered its3971 /// Performs an intra write at its push site when the tile registered its
3973 /// planes for inline reconstruction ([`ReconPlanes`]); `false` when the3972 /// planes for inline reconstruction ([`ReconPlanes`]); `false` when the
3974-/// caller must record it for the wavefront workers instead.
3975 #[allow(unsafe_code)]3973 #[allow(unsafe_code)]
3976 #[allow(clippy::too_many_arguments)]3974 #[allow(clippy::too_many_arguments)]
3977 fn inline_intra(3975 fn inline_intra(
@@ -8749,7 +8747,10 @@ fn read_coeffs_rect(
8749 // the pairing had to guess whether a golomb had been read. This8747 // the pairing had to guess whether a golomb had been read. This
8750 // rung reads no bits: it prints the state after the read it labels.8748 // rung reads no bits: it prints the state after the read it labels.
8751 let (rng, _) = dec.debug_state();8749 let (rng, _) = dec.debug_state();
8752- eprintln!("EC_COEFF_STEP tag=post_golomb c={} pos={pos} level={level} rng={rng}", (packed >> 4));8750+ eprintln!(
8751+ "EC_COEFF_STEP tag=post_golomb c={} pos={pos} level={level} rng={rng}",
8752+ (packed >> 4)
8753+ );
8753 }8754 }
8754 grid[pos] = if negative { -level } else { level };8755 grid[pos] = if negative { -level } else { level };
8755 }8756 }
@@ -21327,7 +21328,6 @@ impl PlaneBuf<'_> {
21327 /// Reads one plane's transform block, reconstructs it into `plane` at21328 /// Reads one plane's transform block, reconstructs it into `plane` at
21328 /// `(x, y)`/`side`, and records what it leaves behind in `neighbours`.21329 /// `(x, y)`/`side`, and records what it leaves behind in `neighbours`.
21329 #[allow(clippy::too_many_arguments)]21330 #[allow(clippy::too_many_arguments)]
21330-
21331 fn read_plane(21331 fn read_plane(
21332 dec: &mut SymbolDecoder,21332 dec: &mut SymbolDecoder,
21333 cdfs: &mut Cdfs,21333 cdfs: &mut Cdfs,
@@ -25865,17 +25865,63 @@ fn sub8_leaf_chroma422(
25865 // overwrites exactly the cell the first one wrote, as libaom's25865 // overwrites exactly the cell the first one wrote, as libaom's
25866 // `av1_set_entropy_contexts` per-TU writes do.25866 // `av1_set_entropy_contexts` per-TU writes do.
25867 let ctx_mi = (lmi.0, lmi.1 & !1);25867 let ctx_mi = (lmi.0, lmi.1 & !1);
25868- // lane-av1-422kf2: the square unit takes the leaf's OWN reach: a split25868+ // lane-av1-422kf2: the square unit takes the leaf's OWN reach, but at the
25869- // leaf is a standalone BLOCK_4X4 (square table), a rect pair's strip is25869+ // CHROMA plane's granularity, not the luma leaf's. libaom passes the leaf
25870- // `of_rect` on the strip's true (8x4 / 4x8) shape -- libaom passes the25870+ // through `scale_chroma_bsize(bsize, ss_x, ss_y)` first
25871- // LEAF's bsize to `has_top_right`/`has_bottom_left`, so a rect strip's25871+ // (`reconintra.c:1823`, definition `:1649`) and only then calls
25872- // answer comes from `has_tr_8x4`/`has_tr_4x8` at the strip's mi, not25872+ // `has_top_right`/`has_bottom_left` with it, so a rect strip's answer
25873- // from a 4x4-block lookup.25873+ // comes from `has_tr_8x4`/`has_tr_4x8` at the strip's mi, not from a
25874- let reach = if leaf_shape == (4, 4) {25874+ // 4x4-block lookup. At 4:2:2 (`ss (1,0)`) that remap is NOT the identity:
25875- Reach::of(4, px, py, y.width, y.height, fctx)25875+ // a BLOCK_4X4 luma leaf is answered as BLOCK_8X4, TWO mi wide and one mi
25876- } else {25876+ // tall.
25877- Reach::of_rect(leaf_shape.0, leaf_shape.1, px, py, y.width, y.height, fctx)25877+ //
25878- };25878+ // MEASURED, `probe/ll422_allintra.obu` (320x240, 4:2:2 lossless
25879+ // all-intra) against the instrumented `aomdec`: the FIRST wrong chroma
25880+ // prediction in decode order is unit 2818, plane U, chroma (96,32) --
25881+ // the leaf at mi(8,49). The oracle's own `EC_PRED` prints `plane=1
25882+ // row_off=0 col_off=0 txw=4 txh=4 mode=7 p_angle=203 have_top=1
25883+ // have_left=1 n_top=4 n_left=4 n_tr=-1 n_bl=4 bsize=2`, and `bsize=2`
25884+ // is BLOCK_8X4 -- the remap, not the BLOCK_4X4 leaf libaom decoded. That
25885+ // `n_bl=4` is the "leftmost column of superblock" arm: `blk_col_in_sb =
25886+ // (mi_col & (sb_mi-1)) >> bw_in_mi_log2 = (49 & 15) >> 1 = 0`
25887+ // (`reconintra.c:421`), where the one-mi-wide luma BLOCK_4X4 reads column
25888+ // 1, and `blk_start_row_off + row_off + 1 < sb_height_unit` is
25889+ // `8 + 0 + 1 < 16 >> 0` (`reconintra.c:429-435`). Squared on the luma
25890+ // leaf, `Reach::of(4, ..)` instead read `has_bl_4x4[byte 32] bit 1`
25891+ // (`84 = 0b0101_0100`, bit 1 clear) and answered FALSE, so
25892+ // `PlaneBuf::edges` fed the predictor a 4-sample left column where
25893+ // libaom fed 8. `build_directional_and_filter_intra_predictors`
25894+ // (`reconintra.c:1150-1158`) copies `n_left_px` into `left_col[0..3]` and
25895+ // only `if (n_bottomleft_px > 0)` the next `n_bottomleft_px`, so with the
25896+ // denial `av1_dr_prediction_z3_c` reads its base term off a replicated
25897+ // tail -- interior-only, with row0/col0 and the coefficients untouched.
25898+ // 4:2:0 and 4:4:4 never reach this arm: the reader is 4:2:2-only (its
25899+ // sibling `sub8_leaf_chroma444` owns those), and the remap is the
25900+ // identity for a leaf of 8 or more at every subsampling.
25901+ let (mi_bw, mi_bh) =
25902+ crate::encode::chroma_mi_shape(leaf_shape.0, leaf_shape.1, ss_x(fctx), ss_y(fctx));
25903+ // libaom's two edge tests are TILE bounds over the TRANSFORM's plane
25904+ // extent and its `have_top`/`have_left` flags are `y0 > 0` / `x0 > 0`
25905+ // (`reconintra.c:1804-1806`, `:1815-1817`); the tile end is the frame end
25906+ // for every leaf this reader owns, and the unit is one TX_4X4 chroma
25907+ // transform wide and tall (`4 << ss` luma px per axis).
25908+ let tx_w = 4 << ss_x(fctx);
25909+ let tx_h = 4 << ss_y(fctx);
25910+ let reach = Reach::of_tu_chroma(
25911+ mi_bw,
25912+ mi_bh,
25913+ lmi.0,
25914+ lmi.1,
25915+ crate::encode::reach_sb_mi(fctx),
25916+ 0,
25917+ 0,
25918+ tx_w,
25919+ tx_h,
25920+ ss_x(fctx),
25921+ ss_y(fctx),
25922+ py > 0 && px + (tx_w << ss_x(fctx)) < y.width,
25923+ px > 0 && py + (tx_h << ss_y(fctx)) < y.height,
25924+ );
25879 let chroma_around = neighbours.around_mi_422_chroma(ctx_mi, 8, 4);25925 let chroma_around = neighbours.around_mi_422_chroma(ctx_mi, 8, 4);
25880 // lane-av1422sub8pix: the CfL AC signal spans the UNIT's luma footprint,25926 // lane-av1422sub8pix: the CfL AC signal spans the UNIT's luma footprint,
25881 // anchored at the same FLOORED luma x the write/prediction anchor below25927 // anchored at the same FLOORED luma x the write/prediction anchor below
crates/ec-av1/src/encode.rsmodified+159 -0
@@ -74,6 +74,41 @@ fn reach_sb_px(fctx: &crate::decode::FrameCtx) -> usize {
74 fctx.reach_sb_px.with(|c| c.get())74 fctx.reach_sb_px.with(|c| c.get())
75 }75 }
76 76
77+/// [`reach_sb_px`] in 4x4 mode-info units -- libaom's `sb_mi_size` in
78+/// `has_top_right`/`has_bottom_left` (`mi_size_high[sb_size]`), which is what
79+/// [`Reach::of_tu_chroma`] masks the block's mi position with.
80+pub(crate) fn reach_sb_mi(fctx: &crate::decode::FrameCtx) -> usize {
81+ reach_sb_px(fctx) / 4
82+}
83+
84+/// `scale_chroma_bsize(bsize, ss_x, ss_y)` (libaom `reconintra.c:1649`,
85+/// called from `av1_predict_intra_block` at `:1823`) in 4x4 mode-info units:
86+/// the block shape a CHROMA plane's reach is answered against. Only the
87+/// BLOCK_4X4 / BLOCK_4X8 / BLOCK_8X4 / BLOCK_4X16 / BLOCK_16X4 family is
88+/// remapped -- every other block size passes through, so at `ss (0,0)` and
89+/// for any block of 8 or more this is the block's own `(bw/4, bh/4)`.
90+pub(crate) fn chroma_mi_shape(bw: usize, bh: usize, ss_x: usize, ss_y: usize) -> (usize, usize) {
91+ match (bw, bh, ss_x, ss_y) {
92+ // BLOCK_4X4 -> BLOCK_8X8 / BLOCK_8X4 / BLOCK_4X8 / itself.
93+ (4, 4, 1, 1) => (2, 2),
94+ (4, 4, 1, 0) => (2, 1),
95+ (4, 4, 0, 1) => (1, 2),
96+ // BLOCK_4X8 -> BLOCK_8X8 / BLOCK_8X8 / BLOCK_4X8 / itself.
97+ (4, 8, 1, _) => (2, 2),
98+ (4, 8, 0, 1) => (1, 2),
99+ // BLOCK_8X4 -> BLOCK_8X8 / BLOCK_8X4 / BLOCK_8X8 / itself.
100+ (8, 4, 1, 0) => (2, 1),
101+ (8, 4, 1, 1) | (8, 4, 0, 1) => (2, 2),
102+ // BLOCK_4X16 -> BLOCK_8X16 / BLOCK_8X16 / BLOCK_4X16 / itself.
103+ (4, 16, 1, _) => (2, 4),
104+ (4, 16, 0, 1) => (1, 4),
105+ // BLOCK_16X4 -> BLOCK_16X8 / BLOCK_16X4 / BLOCK_16X8 / itself.
106+ (16, 4, 1, 0) => (4, 1),
107+ (16, 4, 1, 1) | (16, 4, 0, 1) => (4, 2),
108+ _ => (bw / 4, bh / 4),
109+ }
110+}
111+
77 /// How heavily the mode search weighs rate against squared error, in units of112 /// How heavily the mode search weighs rate against squared error, in units of
78 /// the quantizer's reconstruction step squared per bit.113 /// the quantizer's reconstruction step squared per bit.
79 ///114 ///
@@ -4062,6 +4097,130 @@ impl Reach {
4062 }4097 }
4063 }4098 }
4064 4099
4100+ /// libaom's own `has_top_right`/`has_bottom_left` for one transform unit
4101+ /// of a CHROMA plane, at the plane granularity libaom uses there
4102+ /// (`reconintra.c:203` / `reconintra.c:381`).
4103+ ///
4104+ /// Two things make a chroma unit's answer differ from the same unit's
4105+ /// LUMA answer, and [`Self::of_tu`] has neither:
4106+ ///
4107+ /// 1. libaom runs a chroma plane through `scale_chroma_bsize(bsize,
4108+ /// ss_x, ss_y)` (`reconintra.c:1823`, definition `:1649`) before
4109+ /// either call, and that remap is not the identity. At 4:2:2
4110+ /// (`ss (1,0)`) a BLOCK_4X4 luma leaf becomes BLOCK_8X4 -- TWO mi
4111+ /// wide and one mi tall.
4112+ /// 2. `has_bottom_left`'s "leftmost column of superblock" arm
4113+ /// (`reconintra.c:429-435`) is then reached at `blk_col_in_sb == 0`,
4114+ /// which the one-mi-wide luma BLOCK_4X4 reads as column 1 and the
4115+ /// per-block table denies. [`Self::of_tu`] has no such arm at all: it
4116+ /// ends at `block.below_left`, the BLOCK-level answer, which stands in
4117+ /// for the table plus both superblock arms and so agrees with libaom
4118+ /// only where neither superblock arm is the deciding step.
4119+ ///
4120+ /// `mi_bw`/`mi_bh` are the PLANE-scaled block's mi extent ([`Self`]'s
4121+ /// caller supplies it from [`chroma_mi_shape`], never the luma block's),
4122+ /// and `col_off`/`row_off`/`tx_w`/`tx_h` are LUMA pixels as at every other
4123+ /// `Reach` call site -- libaom's plane units are one `tx_size_*_unit`
4124+ /// (`1 << (2 + ss)` luma pixels) wide, and each comparison below is
4125+ /// restated in luma pixels rather than rescaled twice. The
4126+ /// 128-wide arm libaom guards on `block_size_wide[bsize] > 64` is not
4127+ /// transcribed: every caller keeps such blocks on [`Self::of_tu`].
4128+ ///
4129+ /// `above_avail` is libaom's `top_available && right_available` and
4130+ /// `below_avail` its `bottom_available && left_available` -- the early
4131+ /// returns at `reconintra.c:204` / `:383`. The caller states them because
4132+ /// libaom's two edge tests are TILE bounds over the TRANSFORM's plane
4133+ /// extent (`mi_col + ((col_off + txw) << ss_x) < mi_col_end`,
4134+ /// `mi_row + ((row_off + txh) << ss_y) < mi_row_end`,
4135+ /// `reconintra.c:1815-1817`) while `top_available`/`left_available` are
4136+ /// `y0 > 0` / `x0 > 0`.
4137+ #[allow(clippy::too_many_arguments)]
4138+ pub(crate) fn of_tu_chroma(
4139+ mi_bw: usize,
4140+ mi_bh: usize,
4141+ mi_row: usize,
4142+ mi_col: usize,
4143+ sb_mi: usize,
4144+ col_off: usize,
4145+ row_off: usize,
4146+ tx_w: usize,
4147+ tx_h: usize,
4148+ ss_x: usize,
4149+ ss_y: usize,
4150+ above_avail: bool,
4151+ below_avail: bool,
4152+ ) -> Self {
4153+ if !above_avail && !below_avail {
4154+ return Self::none();
4155+ }
4156+ let bw_log2 = mi_bw.trailing_zeros() as usize;
4157+ let bh_log2 = mi_bh.trailing_zeros() as usize;
4158+ let blk_row = (mi_row & (sb_mi - 1)) >> bh_log2;
4159+ let blk_col = (mi_col & (sb_mi - 1)) >> bw_log2;
4160+ // `plane_bw_unit`/`plane_bh_unit` (`reconintra.c:208` / `:414`) in
4161+ // libaom's plane units, restated in the luma pixels of the offsets.
4162+ let plane_bw = (mi_bw >> ss_x).max(1) << (2 + ss_x);
4163+ let plane_bh = (mi_bh >> ss_y).max(1) << (2 + ss_y);
4164+ let (tr, bl) = Self::plane_reach_tables(mi_bw, mi_bh);
4165+ Self {
4166+ above_right: above_avail
4167+ && (if row_off > 0 {
4168+ col_off + tx_w < plane_bw
4169+ } else if col_off + tx_w < plane_bw {
4170+ true
4171+ } else if blk_row == 0 {
4172+ // Top row of superblock: the top-right pixels are in the
4173+ // superblock above.
4174+ true
4175+ } else if ((blk_col + 1) << bw_log2) >= sb_mi {
4176+ // Rightmost column: they fall in the superblock to the
4177+ // right, which is not decoded yet.
4178+ false
4179+ } else {
4180+ Self::bit(tr, (blk_row << (5 - bw_log2)) + blk_col)
4181+ }),
4182+ below_left: below_avail
4183+ && (if col_off > 0 {
4184+ // Bottom-left pixels are in the bottom-left block.
4185+ false
4186+ } else if row_off + tx_h < plane_bh {
4187+ true
4188+ } else if blk_col == 0 {
4189+ // `reconintra.c:429-435`: `blk_start_row_off + row_off +
4190+ // count < sb_height_unit`, compared in plane units. Both
4191+ // `>> ss_y` floors are lifted out of the comparison
4192+ // instead of being evaluated, so the luma-pixel
4193+ // restatement is exact.
4194+ let from_block = (blk_row << bh_log2) >> ss_y;
4195+ let sb_height = (sb_mi >> ss_y).saturating_sub(from_block);
4196+ row_off + tx_h < sb_height << (2 + ss_y)
4197+ } else if ((blk_row + 1) << bh_log2) >= sb_mi {
4198+ // Bottom row (and not the leftmost column): the
4199+ // superblock below is not decoded yet.
4200+ false
4201+ } else {
4202+ Self::bit(bl, (blk_row << (5 - bw_log2)) + blk_col)
4203+ }),
4204+ }
4205+ }
4206+
4207+ /// The `has_tr_*`/`has_bl_*` pair for a block of `mi_bw` x `mi_bh` mi --
4208+ /// libaom's `get_has_tr_table`/`get_has_bl_table` indexed by the
4209+ /// PLANE-scaled `BLOCK_SIZE`, so one shape can be a rectangle where
4210+ /// [`Self::table`] would read a square's row (a 4:2:2 chroma BLOCK_8X4,
4211+ /// which is [`Self::of_tu_chroma`]'s whole reason for existing).
4212+ fn plane_reach_tables(mi_bw: usize, mi_bh: usize) -> (&'static [u8], &'static [u8]) {
4213+ if mi_bw != mi_bh {
4214+ return rect_reach_tables(mi_bw * 4, mi_bh * 4);
4215+ }
4216+ let row = Self::table(mi_bw * 4);
4217+ if VERT_AB_PARTITION.with(std::cell::Cell::get) && row < HAS_TOP_RIGHT_VERT.len() {
4218+ (&HAS_TOP_RIGHT_VERT[row], &HAS_BOTTOM_LEFT_VERT[row])
4219+ } else {
4220+ (&HAS_TOP_RIGHT[row], &HAS_BOTTOM_LEFT[row])
4221+ }
4222+ }
4223+
4065 /// What a block of `side` samples at `(x, y)` may read past its own edges,4224 /// What a block of `side` samples at `(x, y)` may read past its own edges,
4066 /// in a frame of `width` by `height`.4225 /// in a frame of `width` by `height`.
4067 pub(crate) fn of(4226 pub(crate) fn of(
lanes/av1422llpred2.report.mdadded+235 -0
@@ -0,0 +1,235 @@
1+# lane-av1422llpred2 — 4:2:2 sub-8 chroma reach: the chroma plane's block shape is the PLANE-scaled one
2+
3+Target: `probe/ll422_allintra.obu` (320x240, 4:2:2 lossless all-intra, 1 frame).
4+Base: `main` = `d202b8b4` (the dc_sign, per-axis-reach and per-plane-warp fixes
5+already landed). Worktree `/home/user/.cache/wt/av1422llpred2`, branch
6+`lane-av1422llpred2`, `CARGO_TARGET_DIR=/home/user/.cache/tgt/av1422llpred2`.
7+
8+**Result: `ll422_allintra.obu` is now BYTE-EXACT against `aomdec --rawvideo` —
9+Y 0 / U 0 / V 0** (from Y 0 / U 2984 / V 3067). 4:2:0 and 4:4:4 stay byte-exact.
10+
11+## 1. Re-measure on my tip (before touching anything)
12+
13+Reproduced the handoff numbers exactly, with a live comparator:
14+
15+| cell | plane | before | after | oracle-flip control |
16+|---|---|---|---|---|
17+| `ll422_allintra` (4:2:2) | Y | 0 | **0** | — |
18+| | U | **2984** | **0** | one byte flipped → U +1 |
19+| | V | **3067** | **0** | one byte flipped (offset 126780) → V 3067→**3068**, i.e. +1 |
20+| `ll420_allintra` (4:2:0) | Y/U/V | 0/0/0 | **0/0/0** | — |
21+| `ll444_allintra` (4:4:4) | Y/U/V | 0/0/0 | **0/0/0** | — |
22+| `W_intrabc` (16 frames) | Y/U/V | 807779/389623/418698 | **807779/389623/418698** (delta 0) | one byte flipped → +1 on every plane |
23+| `X_intrabc_tiled` (16 frames) | Y/U/V | 761090/361159/386148 | **761090/361159/386148** (delta 0) | one byte flipped → +1 on every plane |
24+
25+`W_intrabc` / `X_intrabc_tiled` are pre-existing, wholesale-divergent cells (their
26+FIRST sample already differs, so they are not in this defect's class at all);
27+their deltas are exactly zero and the flip controls prove the comparator reads
28+both sides.
29+
30+Prediction-sum disagreements on `ll422_allintra`: **453 of 9600** paired units
31+before → **0 of 9600** after.
32+
33+## 2. The first wrong chroma unit, in decode order
34+
35+Pairing is 1:1 in decode order (9600 records each side), coordinates verified
36+against the oracle's own `EC_PRED`/`EC_PREDOUT8`. The first wrong unit:
37+
38+```
39+idx 2818 plane=U(1) chroma (96,32) 4x4 mode=7 (D203_PRED) ad=0 p_angle=203
40+ours sum=2656 row0=[166,166,166,166] col0=[166,166,166,166]
41+oracle sum=2653 row0=[166,166,166,166] col0=[166,166,166,166] <-- row0 AND col0 byte-identical
42+oracle EC_PRED mi_row=8 mi_col=49 plane=1 row_off=0 col_off=0 txw=4 txh=4
43+ mode=7 p_angle=203 have_top=1 have_left=1
44+ n_top=4 n_left=4 n_tr=-1 n_bl=4 bsize=2 part=0 ft=0
45+```
46+
47+Neighbour availability **disagreed**: the oracle reports `n_left=4 n_bl=4`
48+(8 left-column samples), our side fed **4**:
49+
50+```
51+our EC_DEBUG_EDGES, this unit:
52+ EDGES_SQ x=96 y=32 side=4 mode=7 above=Some([166,167,166,166,166,166,166,166])
53+ left=Some([166,166,166,166]) <-- 4, not 8
54+ reach=Reach { above_right: true, below_left: false }
55+```
56+
57+Both plane EDGES of the same shape are byte-identical (above-right agrees);
58+only the below-left tail of the left column is missing.
59+
60+## 3. The named arithmetic
61+
62+The oracle's `bsize=2` is the first clue: libaom does **not** answer a chroma
63+plane's reach with the luma block's size.
64+
65+| | expression | value at unit 2818 |
66+|---|---|---|
67+| libaom, shape | `bsize = scale_chroma_bsize(mbmi->bsize, ss_x, ss_y)` — `reconintra.c:1823`, definition `reconintra.c:1649` | leaf is BLOCK_4X4, `ss (1,0)` → `bs = BLOCK_8X4` = **2 mi wide, 1 mi tall** (`mi_size_wide[BLOCK_8X4]=2`, `mi_size_high[BLOCK_8X4]=1`) |
68+| libaom, in-block early return | `row_off + tx_size_high_unit[TX_4X4] < AOMMAX(mi_size_high[bsize] >> ss_y, 1)` — `reconintra.c:412-417` | `0 + 1 < AOMMAX(1>>0, 1) = 1` → **false** |
69+| libaom, leftmost-SB-column arm | `blk_col_in_sb = (mi_col & (sb_mi_size-1)) >> bw_in_mi_log2` — `reconintra.c:421`; then `row_off_in_sb + count < sb_height_unit` — `reconintra.c:429-435` | `(49 & 15) >> 1 = 0` → arm taken; `(8<<0)>>0 + 0 + 1 < 16>>0` = `9 < 16` → **1** ⇒ `n_bl = AOMMIN(txhpx, yd) = 4` |
70+| ours (was) | `Reach::of(4, px, py, …)` — `crates/ec-av1/src/encode.rs`, `Reach::of` → `bottom_left(4, …)` → `has_bl_4x4` lookup: `position(4, 196, 32)` = `((32%64)/4, (196%64)/4, 16)` = `(8, 1, 16)`; index `row*32 + col = 257` → `HAS_BOTTOM_LEFT[3][32] = 84 = 0b0101_0100`, bit 1 clear | `col != 0`, `row+1 != 16` → table read → **false** |
71+| ours (now) | `Reach::of_tu_chroma(mi_bw, mi_bh, mi_row, mi_col, sb_mi, col_off, row_off, tx_w, tx_h, ss_x, ss_y, above_avail, below_avail)` — `crates/ec-av1/src/encode.rs`, a transcription of `has_top_right`/`has_bottom_left` | `bw_log2 = 1`, `bh_log2 = 0`; `blk_col = (49&15)>>1 = 0`; `from_block = 8`, `sb_height = 16-8 = 8`; `0 + 4 < 8<<2 = 32` → **true** |
72+| call site | `crates/ec-av1/src/decode.rs`, `sub8_leaf_chroma422` (the 4:2:2 sub-8 leaf's own chroma TX_4X4 reader) | `reach = Reach::of_tu_chroma(chroma_mi_shape(leaf_shape.0, leaf_shape.1, ss_x, ss_y), …)` |
73+
74+`scale_chroma_bsize` is transcribed in `crates/ec-av1/src/encode.rs` as
75+`chroma_mi_shape` (the only remapped family is BLOCK_4X4 / BLOCK_4X8 /
76+BLOCK_8X4 / BLOCK_4X16 / BLOCK_16X4; everything else passes through).
77+
78+### Why it yields exactly an interior-only difference
79+
80+`build_directional_and_filter_intra_predictors` (`reconintra.c:1150-1158`):
81+
82+```c
83+const int num_left_pixels_needed = txhpx + (n_bottomleft_px >= 0 ? txwpx : 0);
84+i = 0;
85+if (n_left_px > 0) {
86+ for (; i < n_left_px; i++) left_col[i] = left_ref[i * ref_stride];
87+ if (n_bottomleft_px > 0) { /* <-- only here */
88+ assert(i == txhpx);
89+ for (; i < txhpx + n_bottomleft_px; i++) left_col[i] = left_ref[i * ref_stride];
90+ }
91+ if (i < num_left_pixels_needed)
92+ memset(&left_col[i], left_col[i - 1], num_left_pixels_needed - i); /* replicate */
93+}
94+```
95+
96+With `n_bottomleft_px = 4`, `left_col[0..3]` = the four left samples and
97+`left_col[4..7]` = the four below-left samples. With `n_bottomleft_px = -1`
98+(our denial) `num_left_pixels_needed = txhpx = 4`, so `left_col[4..7]` is never
99+written by the copy at all and the directional kernel reads whatever follows —
100+the block's own (not yet reconstructed) rows.
101+
102+`av1_dr_prediction_z3_c` (`reconintra.c:609`) reads
103+`left_col[base]`/`left_col[base+1]` with `base = (dr_intra_derivative[70] * (c+1) + r) >> 6`, `dr_intra_derivative[70] = 23` (`reconintra.h:81`/`:122`). At `p_angle = 203` (`need_left`, `need_above = 0`) row 0 of the block never reads `left_col` at all, and column 0 reads only the `base` values that land on `left_col[0..3]`. So:
104+
105+* **row 0 identical** — it is `above`-driven, and `above_right` already agreed.
106+* **col 0 identical** — it reads only the four samples libaom and we share.
107+* **interior differs** — `base` walks up to `left_col[7]`, i.e. the below-left
108+ tail, which is precisely what the denial removed.
109+* **coefficients bit-identical** — the transform read is untouched by any of this,
110+ so the residual adds the same numbers to a different base.
111+
112+That is the whole signature: edges and row0/col0 equal, interior differs, luma
113+exact, coefficient stream paired with zero disagreement.
114+
115+### Is it 4:2:2-specific or merely 4:2:2-reachable?
116+
117+`scale_chroma_bsize`'s remap table is not 4:2:2-only — at 4:2:0 a BLOCK_4X4
118+leaf is also answered as BLOCK_8X8. But **the class is unreachable at 4:2:0 and
119+4:4:4 in this decoder**, for two independent reasons, and both are measured:
120+
121+1. The fixed reader `sub8_leaf_chroma422` is 4:2:2-only by construction; its
122+ siblings are `sub8_leaf_chroma444` (4:4:4) and the `chroma_444 || chroma_422
123+ && lossless` arm at `decode.rs`. No 4:2:0 path calls it.
124+2. `Reach::of_tu_chroma` is called from exactly one place, in a function whose
125+ name and dispatch say 4:2:2.
126+
127+At 4:2:2 the remap is what makes the defect visible: BLOCK_4X4 → BLOCK_8X4 puts
128+`blk_col_in_sb` at 0 (mi columns 0–1) where the one-mi-wide luma leaf reads
129+column 1, and the per-block table says 0 there. At 4:2:0 the same remap gives
130+BLOCK_8X8, whose `blk_col_in_sb = (mi_col & 15) >> 1` selects the SAME arm our
131+`col == 0` test selects for an even-column leaf, so the branch choice agrees;
132+only the arm's arithmetic differs (`blk_start_row_off = (blk_row << 1) >> 1`
133+vs our `row * side + side < sb_px`), and no committed 4:2:0 fixture reaches it
134+— measured: `ll420_allintra` stays 0/0/0 and the whole 4:2:0/4:4:4 suite is
135+unchanged (see §5). **That 4:2:0 arithmetic difference is a LATENT instance of
136+this class, unexercised and NOT fixed by this lane. It is reported, not
137+claimed fixed.**
138+
139+## 4. The change
140+
141+* `crates/ec-av1/src/encode.rs`
142+ * `Reach::of_tu_chroma(...)` — a transcription of libaom's own
143+ PLANE-scaled block shape, including the arm `Reach::of_tu` never had: the
144+ superblock's leftmost-column / top-row tests. Takes the two
145+ `*_available` early returns as arguments because libaom states them as
146+ TILE bounds over the TRANSFORM's plane extent.
147+ * `Reach::plane_reach_tables(mi_bw, mi_bh)` — the `has_tr_*`/`has_bl_*` pair
148+ for a block shape that can be a rectangle where `Reach::table` would read
149+ a square's row.
150+ * `chroma_mi_shape(bw, bh, ss_x, ss_y)` and `reach_sb_mi(fctx)` —
151+ `scale_chroma_bsize` and `sb_mi_size` in mi units.
152+* `crates/ec-av1/src/decode.rs` — `sub8_leaf_chroma422` computes the leaf's
153+ chroma reach through `of_tu_chroma` at `scale_chroma_bsize`'s shape, instead
154+ of `Reach::of(4, …)` / `Reach::of_rect(leaf_shape, …)`.
155+
156+`read_intra_chroma_lossless` was tried first and REVERTED: its `side` is ≥ 8 on
157+every call site, and the remap is the identity for a block of 8 or more at every
158+subsampling, so it changed nothing (measured 2984/3067 unchanged) while adding
159+an unjustified behaviour change to a 4:2:0-hot path.
160+
161+## 5. Regression
162+
163+```
164+cargo test -p ec-av1 --lib -- 422 lossless 444 warp intra \
165+ --skip bitrate_target_lands_within_5_percent_over_48_frames
166+```
167+
168+```
169+test result: ok. 175 passed; 0 failed; 2 ignored; 0 measured; 622 filtered out;
170+finished in 276.74s
171+```
172+
173+The FIRST run of this same command was made with the `stream.rs` bypass patch
174+still applied and reported **170 passed / 5 failed** — all five failures were
175+`stream::tests::the_pinned_422_*_refuses_by_name`, i.e. the 4:2:2 REFUSAL gates
176+failing because the bypass was in the tree, not a regression from this change.
177+With `stream.rs` restored (`git checkout --`) the suite is fully green.
178+
179+### Bypass hygiene, re-verified
180+
181+* `git diff --stat` on the tip is `crates/ec-av1/src/decode.rs` and
182+ `crates/ec-av1/src/encode.rs` only. `stream.rs` is UNPATCHED now.
183+* No code reads `EC_AV1_ALLOW_422_PROBE` anywhere under `crates/` — the only
184+ hits are doc comments naming the recipe. Verified with a grep for
185+ `env_flag!("EC_AV1_ALLOW_422_PROBE")` / `var("EC_AV1_ALLOW_422_PROBE")`:
186+ zero hits.
187+* The refusal string `a chroma format of 4:2:2` is byte-identical (8
188+ occurrences, unchanged), and the five `the_pinned_422_*_refuses_by_name`
189+ gates pass.
190+
191+To reproduce the 4:2:2 numbers, re-apply the one-line patch
192+(`if false && seq.subsampling_x != seq.subsampling_y`) and restore it after.
193+
194+## 6. Gating — stated plainly
195+
196+**This change cannot be gated by any committed test.** 4:2:2 is refused at the
197+sequence header (`stream.rs`: `a chroma format of 4:2:2 (subsampling_x !=
198+subsampling_y)…`), so `sub8_leaf_chroma422` is unreachable from any stream the
199+committed suite can decode, and no gate could ever run it. Per the lane's
200+instruction no source-scan gate was substituted and this change is **not**
201+described as gated. The evidence is the measurement table in §1 — before/after
202+per plane per cell, each with an oracle-flip isolation control that moves the
203+count by exactly +1 — plus the 4:2:0 / 4:4:4 identity measurements and the
204+regression run in §5.
205+
206+What is *not* claimed: that the residual class is exhausted. `ll422_allintra` is
207+byte-exact and its 9600 prediction sums all agree; whether another 4:2:2 stream
208+exercises a shape this lane did not reach is not established.
209+
210+## 7. Rung label spaces used
211+
212+`skill://av1-coeff-ladder-shape` applied. Ours `EC_PRED`/`OUR_PRED`
213+(`decode.rs`, `x`/`y` are this PLANE's pixel origin) and the `EC_DEBUG_EDGES`
214+rung; the oracle `EC_PRED` (directional, prints the LOCAL `mi_row`/`mi_col`
215+plus `n_top`/`n_left`/`n_tr`/`n_bl`/`bsize`) and `EC_PREDOUT8` (sum + row0/col0).
216+The oracle's `EC_PREDOUT8` non-directional rung prints `xd->mi_*` while its
217+`EC_PRED` prints `xd->mi_*` restated through `mb_to_*_edge`; for chroma the
218+leaf libaom decodes is the ODD-column chroma reference
219+(`is_chroma_reference`, `av1_common_int.h:1454`) while the plane origin is
220+snapped back to the even column by `setup_pred_plane`'s
221+`if (subsampling_x && (mi_col & 0x01) && (mi_size_wide[bsize] == 1))
222+mi_col -= 1;` (`reconinter.h:392-393`) — so `mi_col=49` in the rung and chroma x
223+96 on the plane are BOTH correct, and the placement was verified identical
224+before the reach was blamed (the two U planes agree byte-for-byte across
225+chroma x 96..99 at the failing rows).
226+
227+## 8. Provenance
228+
229+- worktree `/home/user/.cache/wt/av1422llpred2`, branch
230+ `lane-av1422llpred2`, from `main` = `d202b8b4`
231+- `CARGO_TARGET_DIR=/home/user/.cache/tgt/av1422llpred2`, `EC_NOMEMGUARD=1`
232+- oracle: instrumented `/home/user/.cache/aom-oracle/build/aomdec`, rungs
233+ `EC_PRED` (`reconintra.c:1859`) and `EC_PREDOUT8` (`reconintra.c:1803`)
234+- cells: `/home/user/.cache/cells/av1422lpf/{probe,W_intrabc,X_intrabc_tiled}`
235+- no push, no merge, no rustfmt