diff --git a/crates/ec-av1/src/decode.rs b/crates/ec-av1/src/decode.rs index a122f011..831b13d4 100644 --- a/crates/ec-av1/src/decode.rs +++ b/crates/ec-av1/src/decode.rs @@ -1604,7 +1604,6 @@ fn tu_reach( /// twice as wide as it is tall). Same predicate as [`tu_reach`]; the /// square mismatch counter only means anything when the footprint actually /// is square. -#[allow(clippy::too_many_arguments)] fn tu_reach_rect( bw: usize, bh: usize, @@ -3971,7 +3970,6 @@ fn wave_barrier(fctx: &crate::decode::FrameCtx) { /// Performs an intra write at its push site when the tile registered its /// planes for inline reconstruction ([`ReconPlanes`]); `false` when the -/// caller must record it for the wavefront workers instead. #[allow(unsafe_code)] #[allow(clippy::too_many_arguments)] fn inline_intra( @@ -21402,7 +21400,6 @@ impl PlaneBuf<'_> { /// Reads one plane's transform block, reconstructs it into `plane` at /// `(x, y)`/`side`, and records what it leaves behind in `neighbours`. #[allow(clippy::too_many_arguments)] - fn read_plane( dec: &mut SymbolDecoder, cdfs: &mut Cdfs, @@ -25940,17 +25937,63 @@ fn sub8_leaf_chroma422( // overwrites exactly the cell the first one wrote, as libaom's // `av1_set_entropy_contexts` per-TU writes do. let ctx_mi = (lmi.0, lmi.1 & !1); - // lane-av1-422kf2: the square unit takes the leaf's OWN reach: a split - // leaf is a standalone BLOCK_4X4 (square table), a rect pair's strip is - // `of_rect` on the strip's true (8x4 / 4x8) shape -- libaom passes the - // LEAF's bsize to `has_top_right`/`has_bottom_left`, so a rect strip's - // answer comes from `has_tr_8x4`/`has_tr_4x8` at the strip's mi, not - // from a 4x4-block lookup. - let reach = if leaf_shape == (4, 4) { - Reach::of(4, px, py, y.width, y.height, fctx) - } else { - Reach::of_rect(leaf_shape.0, leaf_shape.1, px, py, y.width, y.height, fctx) - }; + // lane-av1-422kf2: the square unit takes the leaf's OWN reach, but at the + // CHROMA plane's granularity, not the luma leaf's. libaom passes the leaf + // through `scale_chroma_bsize(bsize, ss_x, ss_y)` first + // (`reconintra.c:1823`, definition `:1649`) and only then calls + // `has_top_right`/`has_bottom_left` with it, so a rect strip's answer + // comes from `has_tr_8x4`/`has_tr_4x8` at the strip's mi, not from a + // 4x4-block lookup. At 4:2:2 (`ss (1,0)`) that remap is NOT the identity: + // a BLOCK_4X4 luma leaf is answered as BLOCK_8X4, TWO mi wide and one mi + // tall. + // + // MEASURED, `probe/ll422_allintra.obu` (320x240, 4:2:2 lossless + // all-intra) against the instrumented `aomdec`: the FIRST wrong chroma + // prediction in decode order is unit 2818, plane U, chroma (96,32) -- + // the leaf at mi(8,49). The oracle's own `EC_PRED` prints `plane=1 + // row_off=0 col_off=0 txw=4 txh=4 mode=7 p_angle=203 have_top=1 + // have_left=1 n_top=4 n_left=4 n_tr=-1 n_bl=4 bsize=2`, and `bsize=2` + // is BLOCK_8X4 -- the remap, not the BLOCK_4X4 leaf libaom decoded. That + // `n_bl=4` is the "leftmost column of superblock" arm: `blk_col_in_sb = + // (mi_col & (sb_mi-1)) >> bw_in_mi_log2 = (49 & 15) >> 1 = 0` + // (`reconintra.c:421`), where the one-mi-wide luma BLOCK_4X4 reads column + // 1, and `blk_start_row_off + row_off + 1 < sb_height_unit` is + // `8 + 0 + 1 < 16 >> 0` (`reconintra.c:429-435`). Squared on the luma + // leaf, `Reach::of(4, ..)` instead read `has_bl_4x4[byte 32] bit 1` + // (`84 = 0b0101_0100`, bit 1 clear) and answered FALSE, so + // `PlaneBuf::edges` fed the predictor a 4-sample left column where + // libaom fed 8. `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`, so with the + // denial `av1_dr_prediction_z3_c` reads its base term off a replicated + // tail -- interior-only, with row0/col0 and the coefficients untouched. + // 4:2:0 and 4:4:4 never reach this arm: the reader is 4:2:2-only (its + // sibling `sub8_leaf_chroma444` owns those), and the remap is the + // identity for a leaf of 8 or more at every subsampling. + let (mi_bw, mi_bh) = + crate::encode::chroma_mi_shape(leaf_shape.0, leaf_shape.1, ss_x(fctx), ss_y(fctx)); + // libaom's two edge tests are TILE bounds over the TRANSFORM's plane + // extent and its `have_top`/`have_left` flags are `y0 > 0` / `x0 > 0` + // (`reconintra.c:1804-1806`, `:1815-1817`); the tile end is the frame end + // for every leaf this reader owns, and the unit is one TX_4X4 chroma + // transform wide and tall (`4 << ss` luma px per axis). + let tx_w = 4 << ss_x(fctx); + let tx_h = 4 << ss_y(fctx); + let reach = Reach::of_tu_chroma( + mi_bw, + mi_bh, + lmi.0, + lmi.1, + crate::encode::reach_sb_mi(fctx), + 0, + 0, + tx_w, + tx_h, + ss_x(fctx), + ss_y(fctx), + py > 0 && px + (tx_w << ss_x(fctx)) < y.width, + px > 0 && py + (tx_h << ss_y(fctx)) < y.height, + ); let chroma_around = neighbours.around_mi_422_chroma(ctx_mi, 8, 4); // lane-av1422sub8pix: the CfL AC signal spans the UNIT's luma footprint, // anchored at the same FLOORED luma x the write/prediction anchor below diff --git a/crates/ec-av1/src/encode.rs b/crates/ec-av1/src/encode.rs index 466fce8b..435edffd 100644 --- a/crates/ec-av1/src/encode.rs +++ b/crates/ec-av1/src/encode.rs @@ -74,6 +74,41 @@ fn reach_sb_px(fctx: &crate::decode::FrameCtx) -> usize { fctx.reach_sb_px.with(|c| c.get()) } +/// [`reach_sb_px`] in 4x4 mode-info units -- libaom's `sb_mi_size` in +/// `has_top_right`/`has_bottom_left` (`mi_size_high[sb_size]`), which is what +/// [`Reach::of_tu_chroma`] masks the block's mi position with. +pub(crate) fn reach_sb_mi(fctx: &crate::decode::FrameCtx) -> usize { + reach_sb_px(fctx) / 4 +} + +/// `scale_chroma_bsize(bsize, ss_x, ss_y)` (libaom `reconintra.c:1649`, +/// called from `av1_predict_intra_block` at `:1823`) in 4x4 mode-info units: +/// the block shape a CHROMA plane's reach is answered against. Only the +/// BLOCK_4X4 / BLOCK_4X8 / BLOCK_8X4 / BLOCK_4X16 / BLOCK_16X4 family is +/// remapped -- every other block 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)`. +pub(crate) fn chroma_mi_shape(bw: usize, bh: usize, ss_x: usize, ss_y: usize) -> (usize, usize) { + match (bw, bh, ss_x, ss_y) { + // BLOCK_4X4 -> BLOCK_8X8 / BLOCK_8X4 / BLOCK_4X8 / itself. + (4, 4, 1, 1) => (2, 2), + (4, 4, 1, 0) => (2, 1), + (4, 4, 0, 1) => (1, 2), + // BLOCK_4X8 -> BLOCK_8X8 / BLOCK_8X8 / BLOCK_4X8 / itself. + (4, 8, 1, _) => (2, 2), + (4, 8, 0, 1) => (1, 2), + // BLOCK_8X4 -> BLOCK_8X8 / BLOCK_8X4 / BLOCK_8X8 / itself. + (8, 4, 1, 0) => (2, 1), + (8, 4, 1, 1) | (8, 4, 0, 1) => (2, 2), + // BLOCK_4X16 -> BLOCK_8X16 / BLOCK_8X16 / BLOCK_4X16 / itself. + (4, 16, 1, _) => (2, 4), + (4, 16, 0, 1) => (1, 4), + // BLOCK_16X4 -> BLOCK_16X8 / BLOCK_16X4 / BLOCK_16X8 / itself. + (16, 4, 1, 0) => (4, 1), + (16, 4, 1, 1) | (16, 4, 0, 1) => (4, 2), + _ => (bw / 4, bh / 4), + } +} + /// How heavily the mode search weighs rate against squared error, in units of /// the quantizer's reconstruction step squared per bit. /// @@ -4062,6 +4097,130 @@ impl Reach { } } + /// libaom's own `has_top_right`/`has_bottom_left` for one transform unit + /// of a CHROMA plane, at the plane granularity libaom uses there + /// (`reconintra.c:203` / `reconintra.c:381`). + /// + /// Two things make a chroma unit's answer differ from the same unit's + /// LUMA answer, and [`Self::of_tu`] has neither: + /// + /// 1. libaom runs a chroma plane through `scale_chroma_bsize(bsize, + /// ss_x, ss_y)` (`reconintra.c:1823`, definition `:1649`) before + /// either call, and that remap is not the identity. At 4:2:2 + /// (`ss (1,0)`) a BLOCK_4X4 luma leaf becomes BLOCK_8X4 -- TWO mi + /// wide and one mi tall. + /// 2. `has_bottom_left`'s "leftmost column of superblock" arm + /// (`reconintra.c:429-435`) is then reached at `blk_col_in_sb == 0`, + /// which the one-mi-wide luma BLOCK_4X4 reads as column 1 and the + /// per-block table denies. [`Self::of_tu`] has no such arm at all: it + /// ends at `block.below_left`, the BLOCK-level answer, which stands in + /// for the table plus both superblock arms and so agrees with libaom + /// only where neither superblock arm is the deciding step. + /// + /// `mi_bw`/`mi_bh` are the PLANE-scaled block's mi extent ([`Self`]'s + /// caller supplies it from [`chroma_mi_shape`], never the luma block's), + /// and `col_off`/`row_off`/`tx_w`/`tx_h` are LUMA pixels as at every other + /// `Reach` call site -- libaom's plane units are one `tx_size_*_unit` + /// (`1 << (2 + ss)` luma pixels) wide, and each comparison below is + /// restated in luma pixels rather than rescaled twice. The + /// 128-wide arm libaom guards on `block_size_wide[bsize] > 64` is not + /// transcribed: every caller keeps such blocks on [`Self::of_tu`]. + /// + /// `above_avail` is libaom's `top_available && right_available` and + /// `below_avail` its `bottom_available && left_available` -- the early + /// returns at `reconintra.c:204` / `:383`. The caller states them because + /// libaom's two edge tests are TILE bounds over the TRANSFORM's plane + /// extent (`mi_col + ((col_off + txw) << ss_x) < mi_col_end`, + /// `mi_row + ((row_off + txh) << ss_y) < mi_row_end`, + /// `reconintra.c:1815-1817`) while `top_available`/`left_available` are + /// `y0 > 0` / `x0 > 0`. + #[allow(clippy::too_many_arguments)] + pub(crate) fn of_tu_chroma( + mi_bw: usize, + mi_bh: usize, + mi_row: usize, + mi_col: usize, + sb_mi: usize, + col_off: usize, + row_off: usize, + tx_w: usize, + tx_h: usize, + ss_x: usize, + ss_y: usize, + above_avail: bool, + below_avail: bool, + ) -> Self { + if !above_avail && !below_avail { + return Self::none(); + } + let bw_log2 = mi_bw.trailing_zeros() as usize; + let bh_log2 = mi_bh.trailing_zeros() as usize; + let blk_row = (mi_row & (sb_mi - 1)) >> bh_log2; + let blk_col = (mi_col & (sb_mi - 1)) >> bw_log2; + // `plane_bw_unit`/`plane_bh_unit` (`reconintra.c:208` / `:414`) in + // libaom's plane units, restated in the luma pixels of the offsets. + let plane_bw = (mi_bw >> ss_x).max(1) << (2 + ss_x); + let plane_bh = (mi_bh >> ss_y).max(1) << (2 + ss_y); + let (tr, bl) = Self::plane_reach_tables(mi_bw, mi_bh); + Self { + above_right: above_avail + && (if row_off > 0 { + col_off + tx_w < plane_bw + } else if col_off + tx_w < plane_bw { + true + } else if blk_row == 0 { + // Top row of superblock: the top-right pixels are in the + // superblock above. + true + } else if ((blk_col + 1) << bw_log2) >= sb_mi { + // Rightmost column: they fall in the superblock to the + // right, which is not decoded yet. + false + } else { + Self::bit(tr, (blk_row << (5 - bw_log2)) + blk_col) + }), + below_left: below_avail + && (if col_off > 0 { + // Bottom-left pixels are in the bottom-left block. + false + } else if row_off + tx_h < plane_bh { + true + } else if blk_col == 0 { + // `reconintra.c:429-435`: `blk_start_row_off + row_off + + // count < sb_height_unit`, compared in plane units. Both + // `>> ss_y` floors are lifted out of the comparison + // instead of being evaluated, so the luma-pixel + // restatement is exact. + let from_block = (blk_row << bh_log2) >> ss_y; + let sb_height = (sb_mi >> ss_y).saturating_sub(from_block); + row_off + tx_h < sb_height << (2 + ss_y) + } else if ((blk_row + 1) << bh_log2) >= sb_mi { + // Bottom row (and not the leftmost column): the + // superblock below is not decoded yet. + false + } else { + Self::bit(bl, (blk_row << (5 - bw_log2)) + blk_col) + }), + } + } + + /// The `has_tr_*`/`has_bl_*` pair for a block of `mi_bw` x `mi_bh` mi -- + /// libaom's `get_has_tr_table`/`get_has_bl_table` indexed by the + /// PLANE-scaled `BLOCK_SIZE`, so one shape can be a rectangle where + /// [`Self::table`] would read a square's row (a 4:2:2 chroma BLOCK_8X4, + /// which is [`Self::of_tu_chroma`]'s whole reason for existing). + fn plane_reach_tables(mi_bw: usize, mi_bh: usize) -> (&'static [u8], &'static [u8]) { + if mi_bw != mi_bh { + return rect_reach_tables(mi_bw * 4, mi_bh * 4); + } + let row = Self::table(mi_bw * 4); + if VERT_AB_PARTITION.with(std::cell::Cell::get) && row < HAS_TOP_RIGHT_VERT.len() { + (&HAS_TOP_RIGHT_VERT[row], &HAS_BOTTOM_LEFT_VERT[row]) + } else { + (&HAS_TOP_RIGHT[row], &HAS_BOTTOM_LEFT[row]) + } + } + /// What a block of `side` samples at `(x, y)` may read past its own edges, /// in a frame of `width` by `height`. pub(crate) fn of( diff --git a/lanes/av1422llpred2.report.md b/lanes/av1422llpred2.report.md new file mode 100644 index 00000000..f91300a8 --- /dev/null +++ b/lanes/av1422llpred2.report.md @@ -0,0 +1,235 @@ +# lane-av1422llpred2 — 4:2:2 sub-8 chroma reach: the chroma plane's block shape is the PLANE-scaled one + +Target: `probe/ll422_allintra.obu` (320x240, 4:2:2 lossless all-intra, 1 frame). +Base: `main` = `d202b8b4` (the dc_sign, per-axis-reach and per-plane-warp fixes +already landed). Worktree `/home/user/.cache/wt/av1422llpred2`, branch +`lane-av1422llpred2`, `CARGO_TARGET_DIR=/home/user/.cache/tgt/av1422llpred2`. + +**Result: `ll422_allintra.obu` is now BYTE-EXACT against `aomdec --rawvideo` — +Y 0 / U 0 / V 0** (from Y 0 / U 2984 / V 3067). 4:2:0 and 4:4:4 stay byte-exact. + +## 1. Re-measure on my tip (before touching anything) + +Reproduced the handoff numbers exactly, with a live comparator: + +| cell | plane | before | after | oracle-flip control | +|---|---|---|---|---| +| `ll422_allintra` (4:2:2) | Y | 0 | **0** | — | +| | U | **2984** | **0** | one byte flipped → U +1 | +| | V | **3067** | **0** | one byte flipped (offset 126780) → V 3067→**3068**, i.e. +1 | +| `ll420_allintra` (4:2:0) | Y/U/V | 0/0/0 | **0/0/0** | — | +| `ll444_allintra` (4:4:4) | Y/U/V | 0/0/0 | **0/0/0** | — | +| `W_intrabc` (16 frames) | Y/U/V | 807779/389623/418698 | **807779/389623/418698** (delta 0) | one byte flipped → +1 on every plane | +| `X_intrabc_tiled` (16 frames) | Y/U/V | 761090/361159/386148 | **761090/361159/386148** (delta 0) | one byte flipped → +1 on every plane | + +`W_intrabc` / `X_intrabc_tiled` are pre-existing, wholesale-divergent cells (their +FIRST sample already differs, so they are not in this defect's class at all); +their deltas are exactly zero and the flip controls prove the comparator reads +both sides. + +Prediction-sum disagreements on `ll422_allintra`: **453 of 9600** paired units +before → **0 of 9600** after. + +## 2. The first wrong chroma unit, in decode order + +Pairing is 1:1 in decode order (9600 records each side), coordinates verified +against the oracle's own `EC_PRED`/`EC_PREDOUT8`. The first wrong unit: + +``` +idx 2818 plane=U(1) chroma (96,32) 4x4 mode=7 (D203_PRED) ad=0 p_angle=203 +ours sum=2656 row0=[166,166,166,166] col0=[166,166,166,166] +oracle sum=2653 row0=[166,166,166,166] col0=[166,166,166,166] <-- row0 AND col0 byte-identical +oracle EC_PRED mi_row=8 mi_col=49 plane=1 row_off=0 col_off=0 txw=4 txh=4 + mode=7 p_angle=203 have_top=1 have_left=1 + n_top=4 n_left=4 n_tr=-1 n_bl=4 bsize=2 part=0 ft=0 +``` + +Neighbour availability **disagreed**: the oracle reports `n_left=4 n_bl=4` +(8 left-column samples), our side fed **4**: + +``` +our EC_DEBUG_EDGES, this unit: + EDGES_SQ x=96 y=32 side=4 mode=7 above=Some([166,167,166,166,166,166,166,166]) + left=Some([166,166,166,166]) <-- 4, not 8 + reach=Reach { above_right: true, below_left: false } +``` + +Both plane EDGES of the same shape are byte-identical (above-right agrees); +only the below-left tail of the left column is missing. + +## 3. The named arithmetic + +The oracle's `bsize=2` is the first clue: libaom does **not** answer a chroma +plane's reach with the luma block's size. + +| | expression | value at unit 2818 | +|---|---|---| +| 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`) | +| 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** | +| 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` | +| 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** | +| 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** | +| 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), …)` | + +`scale_chroma_bsize` is transcribed in `crates/ec-av1/src/encode.rs` as +`chroma_mi_shape` (the only remapped family is BLOCK_4X4 / BLOCK_4X8 / +BLOCK_8X4 / BLOCK_4X16 / BLOCK_16X4; everything else passes through). + +### Why it yields exactly an interior-only difference + +`build_directional_and_filter_intra_predictors` (`reconintra.c:1150-1158`): + +```c +const int num_left_pixels_needed = txhpx + (n_bottomleft_px >= 0 ? txwpx : 0); +i = 0; +if (n_left_px > 0) { + for (; i < n_left_px; i++) left_col[i] = left_ref[i * ref_stride]; + if (n_bottomleft_px > 0) { /* <-- only here */ + assert(i == txhpx); + for (; i < txhpx + n_bottomleft_px; i++) left_col[i] = left_ref[i * ref_stride]; + } + if (i < num_left_pixels_needed) + memset(&left_col[i], left_col[i - 1], num_left_pixels_needed - i); /* replicate */ +} +``` + +With `n_bottomleft_px = 4`, `left_col[0..3]` = the four left samples and +`left_col[4..7]` = the four below-left samples. With `n_bottomleft_px = -1` +(our denial) `num_left_pixels_needed = txhpx = 4`, so `left_col[4..7]` is never +written by the copy at all and the directional kernel reads whatever follows — +the block's own (not yet reconstructed) rows. + +`av1_dr_prediction_z3_c` (`reconintra.c:609`) reads +`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: + +* **row 0 identical** — it is `above`-driven, and `above_right` already agreed. +* **col 0 identical** — it reads only the four samples libaom and we share. +* **interior differs** — `base` walks up to `left_col[7]`, i.e. the below-left + tail, which is precisely what the denial removed. +* **coefficients bit-identical** — the transform read is untouched by any of this, + so the residual adds the same numbers to a different base. + +That is the whole signature: edges and row0/col0 equal, interior differs, luma +exact, coefficient stream paired with zero disagreement. + +### Is it 4:2:2-specific or merely 4:2:2-reachable? + +`scale_chroma_bsize`'s remap table is not 4:2:2-only — at 4:2:0 a BLOCK_4X4 +leaf is also answered as BLOCK_8X8. But **the class is unreachable at 4:2:0 and +4:4:4 in this decoder**, for two independent reasons, and both are measured: + +1. The fixed reader `sub8_leaf_chroma422` is 4:2:2-only by construction; its + siblings are `sub8_leaf_chroma444` (4:4:4) and the `chroma_444 || chroma_422 + && lossless` arm at `decode.rs`. No 4:2:0 path calls it. +2. `Reach::of_tu_chroma` is called from exactly one place, in a function whose + name and dispatch say 4:2:2. + +At 4:2:2 the remap is what makes the defect visible: BLOCK_4X4 → BLOCK_8X4 puts +`blk_col_in_sb` at 0 (mi columns 0–1) where the one-mi-wide luma leaf reads +column 1, and the per-block table says 0 there. At 4:2:0 the same remap gives +BLOCK_8X8, whose `blk_col_in_sb = (mi_col & 15) >> 1` selects the SAME arm our +`col == 0` test selects for an even-column leaf, so the branch choice agrees; +only the arm's arithmetic differs (`blk_start_row_off = (blk_row << 1) >> 1` +vs our `row * side + side < sb_px`), and no committed 4:2:0 fixture reaches it +— measured: `ll420_allintra` stays 0/0/0 and the whole 4:2:0/4:4:4 suite is +unchanged (see §5). **That 4:2:0 arithmetic difference is a LATENT instance of +this class, unexercised and NOT fixed by this lane. It is reported, not +claimed fixed.** + +## 4. The change + +* `crates/ec-av1/src/encode.rs` + * `Reach::of_tu_chroma(...)` — a transcription of libaom's own + PLANE-scaled block shape, including the arm `Reach::of_tu` never had: the + superblock's leftmost-column / top-row tests. Takes the two + `*_available` early returns as arguments because libaom states them as + TILE bounds over the TRANSFORM's plane extent. + * `Reach::plane_reach_tables(mi_bw, mi_bh)` — the `has_tr_*`/`has_bl_*` pair + for a block shape that can be a rectangle where `Reach::table` would read + a square's row. + * `chroma_mi_shape(bw, bh, ss_x, ss_y)` and `reach_sb_mi(fctx)` — + `scale_chroma_bsize` and `sb_mi_size` in mi units. +* `crates/ec-av1/src/decode.rs` — `sub8_leaf_chroma422` computes the leaf's + chroma reach through `of_tu_chroma` at `scale_chroma_bsize`'s shape, instead + of `Reach::of(4, …)` / `Reach::of_rect(leaf_shape, …)`. + +`read_intra_chroma_lossless` was tried first and REVERTED: its `side` is ≥ 8 on +every call site, and the remap is the identity for a block of 8 or more at every +subsampling, so it changed nothing (measured 2984/3067 unchanged) while adding +an unjustified behaviour change to a 4:2:0-hot path. + +## 5. Regression + +``` +cargo test -p ec-av1 --lib -- 422 lossless 444 warp intra \ + --skip bitrate_target_lands_within_5_percent_over_48_frames +``` + +``` +test result: ok. 175 passed; 0 failed; 2 ignored; 0 measured; 622 filtered out; +finished in 276.74s +``` + +The FIRST run of this same command was made with the `stream.rs` bypass patch +still applied and reported **170 passed / 5 failed** — all five failures were +`stream::tests::the_pinned_422_*_refuses_by_name`, i.e. the 4:2:2 REFUSAL gates +failing because the bypass was in the tree, not a regression from this change. +With `stream.rs` restored (`git checkout --`) the suite is fully green. + +### Bypass hygiene, re-verified + +* `git diff --stat` on the tip is `crates/ec-av1/src/decode.rs` and + `crates/ec-av1/src/encode.rs` only. `stream.rs` is UNPATCHED now. +* No code reads `EC_AV1_ALLOW_422_PROBE` anywhere under `crates/` — the only + hits are doc comments naming the recipe. Verified with a grep for + `env_flag!("EC_AV1_ALLOW_422_PROBE")` / `var("EC_AV1_ALLOW_422_PROBE")`: + zero hits. +* The refusal string `a chroma format of 4:2:2` is byte-identical (8 + occurrences, unchanged), and the five `the_pinned_422_*_refuses_by_name` + gates pass. + +To reproduce the 4:2:2 numbers, re-apply the one-line patch +(`if false && seq.subsampling_x != seq.subsampling_y`) and restore it after. + +## 6. Gating — stated plainly + +**This change cannot be gated by any committed test.** 4:2:2 is refused at the +sequence header (`stream.rs`: `a chroma format of 4:2:2 (subsampling_x != +subsampling_y)…`), so `sub8_leaf_chroma422` is unreachable from any stream the +committed suite can decode, and no gate could ever run it. Per the lane's +instruction no source-scan gate was substituted and this change is **not** +described as gated. The evidence is the measurement table in §1 — before/after +per plane per cell, each with an oracle-flip isolation control that moves the +count by exactly +1 — plus the 4:2:0 / 4:4:4 identity measurements and the +regression run in §5. + +What is *not* claimed: that the residual class is exhausted. `ll422_allintra` is +byte-exact and its 9600 prediction sums all agree; whether another 4:2:2 stream +exercises a shape this lane did not reach is not established. + +## 7. Rung label spaces used + +`skill://av1-coeff-ladder-shape` applied. Ours `EC_PRED`/`OUR_PRED` +(`decode.rs`, `x`/`y` are this PLANE's pixel origin) and the `EC_DEBUG_EDGES` +rung; the oracle `EC_PRED` (directional, prints the LOCAL `mi_row`/`mi_col` +plus `n_top`/`n_left`/`n_tr`/`n_bl`/`bsize`) and `EC_PREDOUT8` (sum + row0/col0). +The oracle's `EC_PREDOUT8` non-directional rung prints `xd->mi_*` while its +`EC_PRED` prints `xd->mi_*` restated through `mb_to_*_edge`; for chroma the +leaf libaom decodes is the ODD-column chroma reference +(`is_chroma_reference`, `av1_common_int.h:1454`) while the plane origin is +snapped back to the even column by `setup_pred_plane`'s +`if (subsampling_x && (mi_col & 0x01) && (mi_size_wide[bsize] == 1)) +mi_col -= 1;` (`reconinter.h:392-393`) — so `mi_col=49` in the rung and chroma x +96 on the plane are BOTH correct, and the placement was verified identical +before the reach was blamed (the two U planes agree byte-for-byte across +chroma x 96..99 at the failing rows). + +## 8. Provenance + +- worktree `/home/user/.cache/wt/av1422llpred2`, branch + `lane-av1422llpred2`, from `main` = `d202b8b4` +- `CARGO_TARGET_DIR=/home/user/.cache/tgt/av1422llpred2`, `EC_NOMEMGUARD=1` +- oracle: instrumented `/home/user/.cache/aom-oracle/build/aomdec`, rungs + `EC_PRED` (`reconintra.c:1859`) and `EC_PREDOUT8` (`reconintra.c:1803`) +- cells: `/home/user/.cache/cells/av1422lpf/{probe,W_intrabc,X_intrabc_tiled}` +- no push, no merge, no rustfmt