diff --git a/crates/ec-av1/fixtures/r512.obu b/crates/ec-av1/fixtures/r512.obu new file mode 100644 index 0000000000000000000000000000000000000000..bff992e98d01fed6ec73ed35ddd73f9fa482d19f GIT binary patch literal 6948 zcmV+<8{6a(0165q000a}|Nj5{!7}?06ac0`0Qt{;b12~vj$=Ys&UI-}3BrKXzpP=0 zbS-d~yJz7UG;H`hC@0)jC=}YCtSAJ96YzoUe$#rbx*M{?dIPY8%Ij` z3Yr&{*=tzrKfh#laCZZdUL$vd&FwIbWqeAkZFVTo#ob`L*(!!xgN!VTmI5^F>c;`Q zpTY>@-X)a8+TmFIyXV@I5-kSIk+67n=l(v5NcQk%mC+lJG9r^og*OJq5acTezz8m0lbMfe<|V25nowe)XZrKI+vor z?iKW~Wc70zLjV^~0L2L=!KS1|IpMgw{T_-+*XpN=K|Uq|8@A|4y$Gq8Bjay%?;^}% zcZ90hV}a_c%IqjN-PLVn-;ruTkbNJPT?(@ZX1%&s!v&i6WMVcJvOMC>mXe$s7A2c* z0}^=M!k=WPP5N|A^>y+7WsM`}{w|FE#>k!71+*dJ{6RSaT?d#HOPJN6x;qG!*c9M&S$>7YpR2_VEl`0^!X8Vl)R`!1m*4oZ zC6Ap`2ARB(8u1}GtwYaZjNgzqe;kpqOATH{IeL;Z$$4VLiw2hg1N|5Sn;1t)i2_+n z5FlM*V1B`j!+JP|l`h;pyJy5_AaS(Ps#lH2+eEr{dC18m{}z_Z3># zh}Bq5#e2Wp;iuR5b=~#BuVc9bt~OvavO>V@U1=2PXh zY;q3k$&RtTWn)EeTOcji;H?qiN#S9vY1}-k6xv?^Qaz+yyp=$fJ^qpeIo^&OCh~oB zZHN9#5s!9U{;zj{!L+=k&FmoK3Lj9p4#v>NP`hNQIR63$Tr%CaIae#y6IpHW?+ZyX zGd+({{On@QB#5exif7Ab?us~r(qfJ6cn}ecVz^JH8_eB(HB{3-)&H56AbD#=yI7NM zYCoLQUj)>%!gGRn9BZu9O|T0-cR3CYcr^F%!!l@5;l4+S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}(7AG0r?Q83&iB9;?3y4(oP2eWm!Y6THY4=P&FQ)A=Sk@RBIHxG*MNH}mw%Lg zt@_b2QaIJTSk&dkqO=Dra>tEV*QEMB(&b{X8{ffNZJf%Su2DY7?BO>Wlbrh&bb$%i zjI|UgPtzl7fZ7Qv>s@RXc z`=9dsZa!B-7?4#*FPV1|;c?dDG<0}u`p)OYY~;rJ!OxDAP8319i>Q&XEO>w3!3!i^ z2R*xIkyS9#Xcnl~%3odtrk>2P-ij_F>CA=?q%KTf)-OFrZnGuy!(FqMPt^u>e!52< zIZD%kicT7O+wj4VAlpVjS0y3Z{;AXw+#kqA%`go)g4( zX0LK&(lIZV{>u@+g6$k|(OMZ6*wJK1agHX2M?qw!{nKSOjEA~@7zZeF=ddO-V+WgH q$r{ZasoXJb_Q!ORc;iEOIk#{4w8$ZwCcK6L2dX3;dOly#2k*jC&U#D$ literal 0 HcmV?d00001 diff --git a/crates/ec-av1/src/decode.rs b/crates/ec-av1/src/decode.rs index 19c3dbb5..a0071f8e 100644 --- a/crates/ec-av1/src/decode.rs +++ b/crates/ec-av1/src/decode.rs @@ -4708,6 +4708,16 @@ thread_local! { /// be satisfied by any older route. static INTRABC_RECT_LOSSLESS_CHROMA4_HITS: std::cell::Cell = const { std::cell::Cell::new(0) }; + /// lane-av1chromarect: 128-root intra-BC HORZ/VERT strips + /// ([`decode_intrabc_owned_rect`]) whose chroma plane block was sized + /// `bw >> ss_x` by `bh >> ss_y` -- the 4:4:4 and 4:4:0 cells, where + /// `av1_get_max_uv_txsize` (`ss_size_lookup[bsize]`, blockd.h:1372) applies + /// no halving of its own. At 4:2:0 the two forms are the same arithmetic, + /// so a `>= 1` witness can only come from a stream that is not 4:2:0. + /// EXCLUSIVE to this arm: no other caller sizes a 128-root intra-BC + /// strip's chroma plane block. + static IBC_OWNED_RECT_CHROMA_FOOTPRINT_444_HITS: std::cell::Cell = + const { std::cell::Cell::new(0) }; } /// lane-av1-intrabc r4: coded (`skip == 0`) rect intrabc blocks reconstructed, @@ -4751,6 +4761,18 @@ pub(crate) fn reset_ibc_rect_chroma_footprint_444_hits() { IBC_RECT_CHROMA_FOOTPRINT_444_HITS.with(|c| c.set(0)); } +/// lane-av1chromarect: [`IBC_OWNED_RECT_CHROMA_FOOTPRINT_444_HITS`]. +#[allow(dead_code)] // read only from the `#[cfg(test)]` gates +pub fn ibc_owned_rect_chroma_footprint_444_hits() -> usize { + IBC_OWNED_RECT_CHROMA_FOOTPRINT_444_HITS.with(|c| c.get()) +} + +/// lane-av1chromarect: zeroes [`IBC_OWNED_RECT_CHROMA_FOOTPRINT_444_HITS`]. +#[allow(dead_code)] // read only from the `#[cfg(test)]` gates +pub(crate) fn reset_ibc_owned_rect_chroma_footprint_444_hits() { + IBC_OWNED_RECT_CHROMA_FOOTPRINT_444_HITS.with(|c| c.set(0)); +} + /// lane-whtshape: [`INTRABC_RECT_LOSSLESS_CHROMA4_HITS`]. #[allow(dead_code)] // read only from the `#[cfg(test)]` gates pub fn intrabc_rect_lossless_chroma4_hits() -> usize { @@ -10407,6 +10429,20 @@ impl Neighbours { mode: usize, uv_mode: usize, grids: &[&[i32]; 3], + ) { + self.record_rect_mi_modes(at_mi, w, h, mode, uv_mode); + self.record_mi_rect(at_mi, w, h, grids); + } + + /// [`Self::record_rect_mi`]'s mode and transform-size half, without the + /// coefficient-context stamp. + fn record_rect_mi_modes( + &mut self, + at_mi: (usize, usize), + w: usize, + h: usize, + mode: usize, + uv_mode: usize, ) { let (r, c) = (at_mi.0 / (SUB / MI), at_mi.1 / (SUB / MI)); // lane-inter4 r2: a strip whose own footprint runs past the frame's @@ -10430,7 +10466,28 @@ impl Neighbours { } self.record_mode_mi(at_mi.0, at_mi.1, w / MI, h / MI, mode); self.record_uv_mode_mi(at_mi.0, at_mi.1, w / MI, h / MI, uv_mode); - self.record_mi_rect(at_mi, w, h, grids); + } + + /// lane-av1chromarect: [`Self::record_rect_mi`] for a block whose uv + /// plane block is SEVERAL transform units, each of which stamped its own + /// span through [`Self::record_mi_chroma`]. Writing one whole-block state + /// over them is the `override-slot-on-one-arm` class: libaom keeps the + /// per-unit above/left contexts distinct, and the next block's first + /// unit reads them. The luma plane has one unit here, so it is stamped + /// exactly as the whole-block record stamps it. + fn record_rect_mi_luma_only( + &mut self, + at_mi: (usize, usize), + w: usize, + h: usize, + mode: usize, + uv_mode: usize, + luma_grid: &[i32], + ) { + self.record_rect_mi_modes(at_mi, w, h, mode, uv_mode); + fill_span(&mut self.left_side_mi, at_mi.0, h / MI, h as u8); + fill_span(&mut self.above_side_mi, at_mi.1, w / MI, w as u8); + self.record_mi_luma_rect(at_mi, w, h, luma_grid); } /// The coefficient-context half of [`Self::record`], taking the block's @@ -10630,6 +10687,39 @@ impl Neighbours { mode: usize, uv_mode: usize, chroma_grids: [&[i32]; 2], + ) { + self.record_split_luma_rect_mi_modes(at_mi, w, h, mode, uv_mode); + let (mi_r, _) = at_mi; + let (w_mi, h_mi) = (w / MI, h / MI); + let round_up_even = |n: usize| n.div_ceil(2) * 2; + let (bound_h, bound_w) = (round_up_even(self.mi_rows), round_up_even(self.mi_cols)); + for (plane_idx, grid) in chroma_grids.into_iter().enumerate() { + let plane = plane_idx + 1; + let state = neighbour_state(grid); + for cell in 0..h_mi { + if cell < h_mi.min(bound_h.saturating_sub(mi_r)) { + self.left[mi_r + cell][plane] = state; + } + } + for cell in 0..w_mi { + if cell < w_mi.min(bound_w.saturating_sub(at_mi.1)) { + self.above[at_mi.1 + cell][plane] = state; + } + } + } + } + + /// [`Self::record_split_luma_rect_mi`]'s mode and transform-size half, + /// without the per-plane coefficient stamp -- see + /// [`Self::record_rect_mi_luma_only`] for why a multi-unit chroma block + /// must not take the whole-block stamp. + fn record_split_luma_rect_mi_modes( + &mut self, + at_mi: (usize, usize), + w: usize, + h: usize, + mode: usize, + uv_mode: usize, ) { let (mi_r, mi_c) = at_mi; let (r, c) = (mi_r / (SUB / MI), mi_c / (SUB / MI)); @@ -10655,22 +10745,6 @@ impl Neighbours { self.record_uv_mode_mi(mi_r, mi_c, w_mi, h_mi, uv_mode); fill_span(&mut self.left_side_mi, mi_r, h_mi, h as u8); fill_span(&mut self.above_side_mi, mi_c, w_mi, w as u8); - let round_up_even = |n: usize| n.div_ceil(2) * 2; - let (bound_h, bound_w) = (round_up_even(self.mi_rows), round_up_even(self.mi_cols)); - for (plane_idx, grid) in chroma_grids.into_iter().enumerate() { - let plane = plane_idx + 1; - let state = neighbour_state(grid); - for cell in 0..h_mi { - if cell < h_mi.min(bound_h.saturating_sub(mi_r)) { - self.left[mi_r + cell][plane] = state; - } - } - for cell in 0..w_mi { - if cell < w_mi.min(bound_w.saturating_sub(mi_c)) { - self.above[mi_c + cell][plane] = state; - } - } - } } } @@ -16838,25 +16912,31 @@ fn decode_intrabc_owned_rect( ) -> Result<()> { let _ = base_q_idx; let (px, py) = (mi_c * MI, mi_r * MI); - // lane-av1chromahalvings r5: libaom-WRONG at 4:4:4 -- `av1_get_max_uv_txsize` - // is `ss_size_lookup[bsize]` and `get_vartx_max_txsize` (blockd.h:1447) reads - // that plane block as `max_txsize_rect_lookup[plane_bsize]`, so chroma extent - // == luma extent at ss (0,0) -- and the chroma MV origins below are the - // prediction half of the same defect. MEASURED on the 4:4:4 LOSSY witness - // fixtures/r512.obu, chroma-only, luma byte-exact on both inter frames. - // BLOCKED, not missing: with the ss-derived extent the decode REFUSES -- - // "a rectangular inter chroma transform unit whose shape has no coefficient - // table set here" -- because a 4:4:4 32x64 chroma plane block needs a - // `TxbSet` this crate lacks. The fix is a new coefficient set, not a swap. - // Left as the halving deliberately: turning a decoding stream into a - // refusal is a behaviour change with its own decision. See - // lanes/av1chromahalvings.report.md r5. + // lane-av1chromarect: libaom does NOT halve a 128-root intra-BC strip's + // chroma plane block. `av1_get_max_uv_txsize` (blockd.h:1372) is + // `max_txsize_rect_lookup[get_plane_block_size(bsize, ss_x, ss_y)]` run + // through `av1_get_adjusted_tx_size`, and `get_plane_block_size` is + // `ss_size_lookup[bsize]` -- at 4:4:4 the chroma plane block is the block's + // OWN footprint, so the extent below and the eight chroma MV origin pairs + // that follow must be `>> ss_x` / `>> ss_y`, not `/ 2`. At 4:2:0 + // (`ss_x == ss_y == 1`) the two forms are the same arithmetic. + // MEASURED on the 4:4:4 LOSSY witness `fixtures/r512.obu` (6948 B, 3 + // frames, 5 strips through this function): with the halving, frame 0 + // diverges from the aomdec oracle in 166229 Y / 155383 U / 153498 V + // samples and both later frames keep luma byte-exact while 74708 U + + // 73501 V (f1) and 9216 U + 8192 V (f2) are wrong -- chroma-only, which is + // what makes this a chroma-sizing defect and not a block-geometry one. + // Re-measured by this lane; see lanes/av1chromarect.report.md. if crate::envflags::env_flag!("EC_HALVSWEEP") { eprintln!("EC_HALV ibc_owned mi=({mi_r},{mi_c}) bw={bw} bh={bh} skip={skip}"); } - let (cw, ch) = (bw / 2, bh / 2); + let (cw, ch) = (bw >> ss_x(fctx), bh >> ss_y(fctx)); + let (cpx, cpy) = (px >> ss_x(fctx), py >> ss_y(fctx)); let side = bw.max(bh); let cside = cw.max(ch); + if ss_x(fctx) == 0 && ss_y(fctx) == 0 { + hit!(IBC_OWNED_RECT_CHROMA_FOOTPRINT_444_HITS); + } let saved_reduced = fctx.reduced_tx_set_inter.with(std::cell::Cell::get); let saved_tx = fctx.tx_select_inter.with(std::cell::Cell::get); fctx.reduced_tx_set_inter.with(|c| c.set(reduced_tx_set)); @@ -16871,30 +16951,8 @@ fn decode_intrabc_owned_rect( flush_recon(fctx, y, u, v); let pred_y = predict_intrabc_window(y, px, py, bw, bh, dv_col, dv_row, true, side, fctx); - let pred_u = predict_intrabc_window( - u, - px / 2, - py / 2, - cw, - ch, - dv_col, - dv_row, - false, - cside, - fctx, - ); - let pred_v = predict_intrabc_window( - v, - px / 2, - py / 2, - cw, - ch, - dv_col, - dv_row, - false, - cside, - fctx, - ); + let pred_u = predict_intrabc_window(u, cpx, cpy, cw, ch, dv_col, dv_row, false, cside, fctx); + let pred_v = predict_intrabc_window(v, cpx, cpy, cw, ch, dv_col, dv_row, false, cside, fctx); let mi_cols = 2 * y.true_width.div_ceil(8); let mi_rows = 2 * y.true_height.div_ceil(8); @@ -16928,8 +16986,8 @@ fn decode_intrabc_owned_rect( ); push_mc_rect( 1, - px / 2, - py / 2, + cpx, + cpy, cside, cw, ch, @@ -16939,8 +16997,8 @@ fn decode_intrabc_owned_rect( ); push_mc_rect( 2, - px / 2, - py / 2, + cpx, + cpy, cside, cw, ch, @@ -16976,6 +17034,8 @@ fn decode_intrabc_owned_rect( u_grid = Grid::Zero(cside * cside); v_grid = Grid::Zero(cside * cside); } else if let Some(ls) = leaves.as_ref() { + let mut leaf_types: Vec<(usize, usize, usize, usize, TxType)> = + Vec::with_capacity(ls.len()); for (idx, &(row, col, tw, th)) in ls.iter().enumerate() { let tu_mi = (mi_r + row, mi_c + col); let (tu_px, tu_py) = (px + col * MI, py + row * MI); @@ -17018,6 +17078,7 @@ fn decode_intrabc_owned_rect( fctx, )? }; + leaf_types.push((row, col, tw, th, tt)); if idx == 0 { luma_tx_type = tt; } @@ -17033,43 +17094,66 @@ fn decode_intrabc_owned_rect( } } luma_grid = Grid::Zero(side * side); - let around = neighbours.around_mi_rect((mi_r, mi_c), bw, bh); - let (ug, _) = read_inter_plane_rect( - dec, - cdfs, - rect_inter_chroma_set(cw, ch)?, - (cw, ch), - cside, - 1, - around[1], - 0, - u, - px / 2, - py / 2, - Pred::Inline(&pred_u, cside), - Some(luma_tx_type), - None, - fctx, - )?; - let (vg, _) = read_inter_plane_rect( - dec, - cdfs, - rect_inter_chroma_set(cw, ch)?, - (cw, ch), - cside, - 2, - around[2], - 0, - v, - px / 2, - py / 2, - Pred::Inline(&pred_v, cside), - Some(luma_tx_type), - None, - fctx, - )?; - u_grid = ug; - v_grid = vg; + if cw.min(32) != cw || ch.min(32) != ch { + // lane-av1chromarect: more than one chroma transform unit (the + // 4:4:4 32x64/64x32 plane block). See the helper. + let (ug, vg) = read_intrabc_rect_chroma_split( + dec, + cdfs, + neighbours, + (mi_r, mi_c), + (cpx, cpy), + (cw, ch), + cside, + &pred_u, + &pred_v, + &leaf_types, + luma_tx_type, + u, + v, + fctx, + )?; + u_grid = ug; + v_grid = vg; + } else { + let around = neighbours.around_mi_rect((mi_r, mi_c), bw, bh); + let (ug, _) = read_inter_plane_rect( + dec, + cdfs, + rect_inter_chroma_set(cw, ch)?, + (cw, ch), + cside, + 1, + around[1], + 0, + u, + cpx, + cpy, + Pred::Inline(&pred_u, cside), + Some(luma_tx_type), + None, + fctx, + )?; + let (vg, _) = read_inter_plane_rect( + dec, + cdfs, + rect_inter_chroma_set(cw, ch)?, + (cw, ch), + cside, + 2, + around[2], + 0, + v, + cpx, + cpy, + Pred::Inline(&pred_v, cside), + Some(luma_tx_type), + None, + fctx, + )?; + u_grid = ug; + v_grid = vg; + } } else { let around = neighbours.around_mi_rect((mi_r, mi_c), bw, bh); let (g, tt) = read_inter_plane_rect( @@ -17091,53 +17175,93 @@ fn decode_intrabc_owned_rect( )?; luma_tx_type = tt; luma_grid = g; - let (ug, _) = read_inter_plane_rect( - dec, - cdfs, - rect_inter_chroma_set(cw, ch)?, - (cw, ch), - cside, - 1, - around[1], - 0, - u, - px / 2, - py / 2, - Pred::Inline(&pred_u, cside), - Some(luma_tx_type), - None, - fctx, - )?; - let (vg, _) = read_inter_plane_rect( - dec, - cdfs, - rect_inter_chroma_set(cw, ch)?, - (cw, ch), - cside, - 2, - around[2], - 0, - v, - px / 2, - py / 2, - Pred::Inline(&pred_v, cside), - Some(luma_tx_type), - None, - fctx, - )?; - u_grid = ug; - v_grid = vg; + if cw.min(32) != cw || ch.min(32) != ch { + // lane-av1chromarect: more than one chroma transform unit (the + // 4:4:4 32x64/64x32 plane block). See the helper. + let (ug, vg) = read_intrabc_rect_chroma_split( + dec, + cdfs, + neighbours, + (mi_r, mi_c), + (cpx, cpy), + (cw, ch), + cside, + &pred_u, + &pred_v, + &[], + luma_tx_type, + u, + v, + fctx, + )?; + u_grid = ug; + v_grid = vg; + } else { + let (ug, _) = read_inter_plane_rect( + dec, + cdfs, + rect_inter_chroma_set(cw, ch)?, + (cw, ch), + cside, + 1, + around[1], + 0, + u, + cpx, + cpy, + Pred::Inline(&pred_u, cside), + Some(luma_tx_type), + None, + fctx, + )?; + let (vg, _) = read_inter_plane_rect( + dec, + cdfs, + rect_inter_chroma_set(cw, ch)?, + (cw, ch), + cside, + 2, + around[2], + 0, + v, + cpx, + cpy, + Pred::Inline(&pred_v, cside), + Some(luma_tx_type), + None, + fctx, + )?; + u_grid = ug; + v_grid = vg; + } } drop(restore); + // lane-av1chromarect: when the chroma plane block was walked as SEVERAL + // transform units, each unit stamped its own span through + // `record_mi_chroma` and the whole-block stamp below would overwrite them + // with one state (class `override-slot-on-one-arm`). libaom keeps the + // per-unit above/left contexts distinct; the next block's first unit + // reads them. + // `!skip` matters: a SKIPPED strip reads no chroma unit at all (its whole + // chroma plane block is one `push_mc_rect` of `ZERO_RESIDUAL`), so no + // per-unit `record_mi_chroma` ran and the whole-block chroma stamp below + // is still the only one that happens. + let chroma_split_units = !skip && (cw.min(32) != cw || ch.min(32) != ch); if leaves.is_some() { - neighbours.record_split_luma_rect_mi( - (mi_r, mi_c), - bw, - bh, - DC_PRED, - DC_PRED, - [&u_grid, &v_grid], - ); + if chroma_split_units { + neighbours.record_split_luma_rect_mi_modes((mi_r, mi_c), bw, bh, DC_PRED, DC_PRED); + } else { + neighbours.record_split_luma_rect_mi( + (mi_r, mi_c), + bw, + bh, + DC_PRED, + DC_PRED, + [&u_grid, &v_grid], + ); + } + } else if chroma_split_units { + neighbours.record_rect_mi_luma_only((mi_r, mi_c), bw, bh, DC_PRED, DC_PRED, &luma_grid); } else { neighbours.record_rect_mi( (mi_r, mi_c), @@ -17173,6 +17297,111 @@ fn decode_intrabc_owned_rect( Ok(()) } +/// The chroma plane block of a 128-root intra-BC HORZ/VERT strip when that +/// plane block needs MORE THAN ONE transform unit -- the 4:4:4 cell, and the +/// 4:2:0 cell of a strip with a 128-px axis. +/// +/// libaom never forms a 64-point CHROMA transform. `get_vartx_max_txsize` +/// (blockd.h:1447) returns `av1_get_adjusted_tx_size(max_txsize_rect_lookup +/// [plane_bsize])` and `av1_get_adjusted_tx_size` maps `TX_32X64`/`TX_64X32` +/// to `TX_32X32`; `decode_token_recon_block` (decodeframe.c:994-1004) then +/// steps the plane block by that size's mi units, and +/// `decode_reconstruct_tx`'s `tx_size == plane_tx_size || plane` arm never +/// recurses for chroma -- the same statement from the other side. So a 4:4:4 +/// 32x64 chroma plane block is TWO stacked `TX_32X32` units, each with its +/// own eob, its own scan and its own coefficient context, NOT one 32x64 unit +/// whose coded corner happens to be 32x32: `av1_get_max_eob`'s 64-axis +/// truncation is a LUMA rule, and a chroma plane block is never 64 points +/// long to begin with. +/// +/// That is exactly the tiling [`read_inter_rect_chroma`] implements +/// (`(write_chroma_w.min(32), write_chroma_h.min(32))` and the `nx * ny` +/// walk); this is the same walk for a caller that keeps its own grid +/// assembly and neighbour recording. The single-unit case is deliberately +/// NOT routed through here, so at 4:2:0 and at every 4:4:4 shape below 64 +/// the caller keeps its own one-unit read verbatim. +#[allow(clippy::too_many_arguments)] +fn read_intrabc_rect_chroma_split( + dec: &mut SymbolDecoder, + cdfs: &mut Cdfs, + neighbours: &mut Neighbours, + (mi_r, mi_c): (usize, usize), + (cpx, cpy): (usize, usize), + (cw, ch): (usize, usize), + cside: usize, + pred_u: &[u16], + pred_v: &[u16], + leaf_tx_types: &[(usize, usize, usize, usize, TxType)], + luma_tx_type: TxType, + u: &mut PlaneBuf<'static>, + v: &mut PlaneBuf<'static>, + fctx: &crate::decode::FrameCtx, +) -> Result<(Grid, Grid)> { + let (uw, uh) = (cw.min(32), ch.min(32)); + let (nx, ny) = (cw / uw, ch / uh); + let set = rect_inter_chroma_set(uw, uh)?; + let assembled_h = ch.max(cside); + let mut assembled: [Vec; 2] = [ + vec![0i32; cside * assembled_h], + vec![0i32; cside * assembled_h], + ]; + for plane_idx in 1..=2 { + let (src, buf) = if plane_idx == 1 { + (pred_u, &mut *u) + } else { + (pred_v, &mut *v) + }; + for cu_row in 0..ny { + for cu_col in 0..nx { + let (span_x, span_y) = (uw << ss_x(fctx), uh << ss_y(fctx)); + let cu_mi = (mi_r + cu_row * (span_y / MI), mi_c + cu_col * (span_x / MI)); + let cu_around = neighbours.around_mi_rect(cu_mi, span_x, span_y); + let (cu_x, cu_y) = (cpx + cu_col * uw, cpy + cu_row * uh); + let cu_pred = Pred::Inline(src, cside).offset(cu_row * uh * cside + cu_col * uw); + // libaom's `av1_get_tx_type` (blockd.h:1287) reads + // `xd->tx_type_map` at the chroma unit's OWN position scaled + // back to luma, so a unit sitting over a luma leaf that coded + // nothing takes that leaf's stamp, not the block-level one. + let rel_mi = (cu_mi.0 - mi_r, cu_mi.1 - mi_c); + let inherit_tx_type = + covering_leaf_tx_type(leaf_tx_types, rel_mi).or(Some(luma_tx_type)); + let cu_grid = read_inter_plane_rect( + dec, + cdfs, + set, + (uw, uh), + cside, + plane_idx, + cu_around[plane_idx], + 0, + buf, + cu_x, + cu_y, + cu_pred, + inherit_tx_type, + // `get_txb_ctx`: plus 10 when the plane block is bigger + // than the transform -- the same offset-3 convention + // `read_inter_rect_chroma` passes on this arm. + Some(3), + fctx, + )? + .0; + // Immediately, so the next unit of this block reads this one's + // coefficient context (libaom updates the chroma above/left + // contexts per unit). + neighbours.record_mi_chroma(cu_mi, span_x, span_y, plane_idx, &cu_grid); + let dst = &mut assembled[plane_idx - 1]; + for rr in 0..uh { + let start = (cu_row * uh + rr) * cside + cu_col * uw; + dst[start..start + uw].copy_from_slice(&cu_grid[rr * uw..][..uw]); + } + } + } + } + let [ug, vg] = assembled; + Ok((Grid::Own(ug), Grid::Own(vg))) +} + fn predict_intrabc_window( plane: &PlaneBuf<'_>, px: usize, diff --git a/crates/ec-av1/src/stream.rs b/crates/ec-av1/src/stream.rs index aba2aa92..57ef9a12 100644 --- a/crates/ec-av1/src/stream.rs +++ b/crates/ec-av1/src/stream.rs @@ -140,6 +140,23 @@ pub fn reset_ibc444rect_hits() { crate::decode::reset_ibc444rect_hits() } +/// lane-av1chromarect: 128-root intra-BC HORZ/VERT strips whose chroma plane +/// block was sized `bw >> ss_x` by `bh >> ss_y` rather than the hardcoded +/// 4:2:0 halving -- i.e. the 4:4:4 (and 4:4:0) cells, where +/// `av1_get_max_uv_txsize` (`ss_size_lookup[bsize]`, blockd.h:1372) applies no +/// halving of its own. At 4:2:0 the two forms are the same arithmetic, so a +/// `>= 1` witness can only come from a stream that is not 4:2:0. EXCLUSIVE to +/// `decode_intrabc_owned_rect`: no other caller sizes a 128-root intra-BC +/// strip's chroma plane block. +pub fn ibc_owned_rect_chroma_footprint_444_hits() -> usize { + crate::decode::ibc_owned_rect_chroma_footprint_444_hits() +} + +/// Gate-side reset for the lane-av1chromarect counter above. +pub fn reset_ibc_owned_rect_chroma_footprint_444_hits() { + crate::decode::reset_ibc_owned_rect_chroma_footprint_444_hits() +} + /// `(y, uv)` palette blocks RECONSTRUCTED inside an inter frame (lane-t900 /// r22) -- the counter a screen-content witness gate reads to prove it /// exercises the inter-frame palette path, not the key frame's. @@ -48682,4 +48699,139 @@ pub(crate) mod tests { (lanes/ibc444c.report.md r2), NOT an assertion" ); } + + /// lane-av1chromarect: the 128-root intra-BC HORZ/VERT strip's chroma + /// plane block, on the 4:4:4 LOSSY witness `fixtures/r512.obu` that + /// reaches `decode_intrabc_owned_rect` five times. + /// + /// The extent is the ss-derived one (`bw >> ss_x` by `bh >> ss_y`; + /// `av1_get_max_uv_txsize` = `ss_size_lookup[bsize]`, blockd.h:1372), and + /// the plane block is walked by `get_vartx_max_txsize` steps -- a 4:4:4 + /// 32x64 luma block's chroma plane block is 32x64, which libaom codes as + /// TWO `TX_32X32` units, not as one 32x64 transform. + /// + /// This gate WAS the refusal assertion "a rectangular inter chroma + /// transform unit whose shape has no coefficient table set here", put + /// there one commit earlier so that the day the arm landed it would go + /// RED and force this rewrite. The refusal string is GONE from the + /// witness's decode because nothing reaches it any more, not because it + /// was deleted: `rect_inter_chroma_set` still refuses (32, 64) and the + /// string is still in the source, it is just not on this path any more. + /// + /// The assertion is a per-(frame, plane) EXACT PREFIX against the + /// instrumented aomdec, the same shape as the sibling + /// `a_444_intrabc_rect_chroma_plane_block_is_the_block_footprint`. The + /// floors are MEASURED, and each one only grows: + /// + /// * luma is byte-exact on ALL THREE frames (786432/786432 samples). + /// Before the fix frame 0 luma was 166229 samples wrong from 65728 -- + /// the halving's chroma misread desynced the tile. + /// * frame 2 is byte-exact on all three planes. Before the fix it was + /// 9216 U + 8192 V wrong. + /// * frames 0 and 1 carry an OPEN chroma fork at a DIFFERENT site (see + /// lanes/av1chromarect.report.md); the floors below are the exact + /// prefixes, not a claim that the tail is right. + #[test] + fn a_444_intrabc_owned_rect_strip_sizes_its_chroma_plane_block_and_decodes() { + const NAME: &str = + "a_444_intrabc_owned_rect_strip_sizes_its_chroma_plane_block_and_decodes"; + const FILE: &str = "r512.obu"; + const LEN: usize = 6948; + /// 512x512 8-bit 4:4:4, one plane. + const PLANE: usize = 512 * 512; + /// First differing sample per (frame, plane), decode order. + const EXACT_PREFIX: [[usize; 3]; 3] = [ + [PLANE, 229728, 229728], + [PLANE, 65704, 65704], + [PLANE, PLANE, PLANE], + ]; + let path = + std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR")).join(format!("fixtures/{FILE}")); + let stream = std::fs::read(&path) + .unwrap_or_else(|e| panic!("{NAME}: pinned fixture {FILE} missing: {e}")); + assert_eq!(stream.len(), LEN, "{NAME}: {FILE} length moved"); + assert_444_header(&stream, NAME, 8); + + let _guard = lock_gate_counters(); + reset_ibc_owned_rect_chroma_footprint_444_hits(); + // The refusal this gate used to assert must NOT be what happens now. + let dir = std::env::temp_dir().join(format!("ec-av1-{NAME}-{}", std::process::id())); + let _ = std::fs::remove_dir_all(&dir); + std::fs::create_dir_all(&dir).expect("scratch dir"); + let obu = dir.join("in.obu"); + std::fs::write(&obu, &stream).expect("writing the stream"); + let aom_prefix = dir.join("aom"); + let out = Command::new(aomdec_path()) + .args(["--codec=av1", "-o"]) + .arg(dir.join("out.y4m")) + .arg(&obu) + .env("EC_AV1_FINAL_DUMP", &aom_prefix) + .stdin(Stdio::null()) + .stdout(Stdio::piped()) + .stderr(Stdio::piped()) + .output() + .expect("aomdec failed to run"); + assert!( + out.status.success(), + "{NAME}: the oracle aomdec refused the stream: {}", + String::from_utf8_lossy(&out.stderr) + ); + let ours_prefix = dir.join("ours"); + set_final_dump_prefix(Some(ours_prefix.display().to_string())); + let decoded = decode_stream(&stream); + set_final_dump_prefix(None); + if let Err(e) = decoded { + panic!( + "{NAME}: this decoder refused the witness: {e} -- the chroma plane block is \ + sized ss-wide and walked in `get_vartx_max_txsize` units, so the 4:4:4 32x64 \ + plane block is two TX_32X32 units, NOT the rect unit the refusal named" + ); + } + let hits = ibc_owned_rect_chroma_footprint_444_hits(); + assert_eq!( + hits, 5, + "{NAME}: {hits} 128-root intra-BC strip(s) sized at 4:4:4, not 5 -- the witness \ + stopped exercising the arm" + ); + assert!( + !std::fs::read(format!("{}.f0", ours_prefix.display())) + .unwrap_or_default() + .is_empty(), + "{NAME}: our decoder wrote no frame" + ); + for f in 0..3 { + let aom_dump = std::fs::read(format!("{}.f{f}", aom_prefix.display())) + .unwrap_or_else(|e| panic!("{NAME}: oracle dump f{f} missing: {e}")); + let our_dump = std::fs::read(format!("{}.f{f}", ours_prefix.display())) + .unwrap_or_else(|e| panic!("{NAME}: our dump f{f} missing: {e}")); + assert_eq!( + our_dump.len(), + 3 * PLANE, + "{NAME}: frame {f} is not 8-bit 4:4:4 512x512" + ); + assert_eq!( + our_dump.len(), + aom_dump.len(), + "{NAME}: frame {f} length differs" + ); + for (plane, name) in [(0usize, "Y"), (1, "U"), (2, "V")] { + let at = plane * PLANE; + let floor = EXACT_PREFIX[f][plane]; + if our_dump[at..at + floor] == aom_dump[at..at + floor] { + continue; + } + let first = (0..floor) + .find(|&s| our_dump[at + s] != aom_dump[at + s]) + .unwrap_or(floor); + panic!( + "{NAME}: frame {f} plane {name} diverges from the oracle at sample {first} \ + of {PLANE} (x={}, y={}) -- the exact prefix this gate pins is {floor} and \ + it only grows", + first % 512, + first / 512 + ); + } + } + let _ = std::fs::remove_dir_all(&dir); + } } diff --git a/lanes/av1chromarect.report.md b/lanes/av1chromarect.report.md new file mode 100644 index 00000000..f938e054 --- /dev/null +++ b/lanes/av1chromarect.report.md @@ -0,0 +1,388 @@ +# lane-av1chromarect — 4:4:4 chroma extent + multi-unit walk at the 128-root intra-BC strip + +Worktree `~/.cache/wt/av1chromarect`, branch `lane-av1chromarect`, base +`edffad9e` ("Merge lane-chromahalvings-r5: EC_HALVSWEEP rungs"). All edits are +absolute-pathed inside this worktree; `git -C ~/Documents/Code/Rust/edith_codecs +status --porcelain` printed nothing after every edit batch. + +Target: `decode_intrabc_owned_rect` (`crates/ec-av1/src/decode.rs:16897`) — the +128-root intra-BC HORZ/VERT strip path (`BLOCK_128X64` / `BLOCK_64X128` and the +`decode_block_rect64` strips under them). + +## 0. Provenance of the witness + +`crates/ec-av1/fixtures/r512.obu`, 6948 B, git blob +`bff992e98d01fed6ec73ed35ddd73f9fa482d19f`. It is on **`lane-chromahalvings-r3`** +and on no other ref of that lane (`lane-chromahalvings` and +`lane-chromahalvings-r5` both lack it, and so does `main`): + + $ for r in lane-chromahalvings-r3 lane-chromahalvings lane-chromahalvings-r5 main; do + printf "%s " "$r"; git cat-file -e "$r:crates/ec-av1/fixtures/r512.obu" 2>/dev/null \ + && git rev-parse "$r:crates/ec-av1/fixtures/r512.obu" || echo MISSING; done + lane-chromahalvings-r3 bff992e98d01fed6ec73ed35ddd73f9fa482d19f + lane-chromahalvings MISSING + lane-chromahalvings-r5 MISSING + main MISSING + $ git hash-object crates/ec-av1/fixtures/r512.obu + bff992e98d01fed6ec73ed35ddd73f9fa482d19f + +Recipe (from `lanes/av1chromahalvings.report.md` r4, re-stated so the pin is +reproducible): testsrc2 512x512 yuv444p 8-bit, `--sb-size=128 --enable-intrabc=1 +--enable-palette=1 --cq-level=50 --enable-rect-partitions=1 +--enable-1to4-partitions=1 --min-partition-size=4 --max-partition-size=128 +--tune-content=screen --profile=1 --obu`, 3 frames. + +## 1. The defect, and the red-before MEASURED HERE + +`decode_intrabc_owned_rect` sized its chroma plane block `(bw / 2, bh / 2)` and +passed `px / 2, py / 2` at eight sites as the chroma MV origins. libaom does not +halve there: `av1_get_max_uv_txsize` (blockd.h:1372) is +`av1_get_adjusted_tx_size(max_txsize_rect_lookup[get_plane_block_size(bsize, ss_x, +ss_y)])` and `get_plane_block_size` is `ss_size_lookup[bsize]`, so at ss (0,0) +the chroma plane block **is** the luma footprint. At 4:2:0 (`ss_x == ss_y == 1`) +`>> 1` and `/ 2` are the same arithmetic, which is why the bug was invisible +until a 4:4:4 witness existed. + +Red-before, on the **unpatched** line in this worktree, per-plane sample counts +against the instrumented aomdec (`aomdec --codec=av1` with +`EC_AV1_FINAL_DUMP`, ours with `set_final_dump_prefix`; 512x512 8-bit 4:4:4, +786432 B per frame, three frames, both sides in decode order): + + f0 Y 166229 wrong from 65728 | U 155383 from 32848 | V 153498 from 32848 total 475110 + f1 Y 0 (byte-exact) | U 74708 from 49282 | V 73501 from 49280 total 148209 + f2 Y 0 (byte-exact) | U 9216 from 114880 | V 8192 from 229760 total 17408 + +Luma byte-exact on f1 and f2 while chroma is wrong is the signature that makes +this a chroma-plane sizing defect and not a block-geometry one. The numbers +reproduce the previous lane's r4 measurement exactly. + +## 2. What the blocker's own refusal was actually asking for + +The previous lane's r4/r5 finding was that the ss-derived extent REFUSES +`fixtures/r512.obu` with + + unsupported: AV1 tile (a rectangular inter chroma transform unit whose shape + has no coefficient table set here) + +and concluded the fix needs a new `TxbSet` — `ChromaRect32x64` / `ChromaRect64x32` +— with its own CDF set, `rect_scan` and rect `base_ctx_rect` / `br_ctx_rect`. +**That conclusion is wrong, and the wrongness is the finding.** + +The refusal names the shape the crate HANDED `rect_inter_chroma_set`, not the +shape libaom codes. With the ss extent a 4:4:4 32x64 luma block's chroma plane +block is 32x64, and this crate read it as one rect transform. libaom never forms +a 64-point CHROMA transform: + +* `get_vartx_max_txsize` (blockd.h:1447) — + `return av1_get_adjusted_tx_size(max_txsize_rect_lookup[bsize]);` for `plane != 0`. +* `av1_get_adjusted_tx_size` (blockd.h, just above `av1_get_max_uv_txsize`) maps + `TX_64X32 → TX_32X32` and `TX_32X64 → TX_32X32`, and returns everything else + unchanged. +* `max_txsize_rect_lookup[BLOCK_SIZES_ALL]` (common_data.h:126) has + `BLOCK_32X64 → TX_32X64`, `BLOCK_64X32 → TX_64X32`. +* `decode_token_recon_block` (decodeframe.c:994-1004) steps the plane block by + `tx_size_*_unit[max_tx_size]`, i.e. 4 mi per axis, and + `decode_reconstruct_tx`'s `if (tx_size == plane_tx_size || plane)` arm never + recurses for chroma — the same statement from the other side. + +So a 4:4:4 32x64 chroma plane block is **two stacked `TX_32X32` units**, each +with its own eob, its own scan and its own coefficient context. `TX_32X32` is +already in the crate: `rect_inter_chroma_set(32, 32) → TxbSet::Chroma32` +(decode.rs:28919, the arm `lane-av1-444` added). What was missing was not a +coefficient set but the **walk** that hands the crate `2 x 32x32` instead of +`1 x 32x64`. + +The 64-axis truncation `read_inter_plane_rect` does internally +(`let (cw, ch) = (w.min(32), h.min(32));` + `extend_corner`, decode.rs:29532) is +libaom's `av1_get_max_eob` rule, and that rule is a LUMA rule: a chroma plane +block is never 64 points long in the first place. Routing a 4:4:4 32x64 chroma +plane block through one 32x64 unit would have produced a new `TxbSet` that no +stream can ever exercise — a coefficient table with no bitstream, which is the +worst kind of green. + +### What shipped instead + +* `read_intrabc_rect_chroma_split` (decode.rs, after + `decode_intrabc_owned_rect`): the same `(cw.min(32), ch.min(32))` / `nx * ny` + tiling `read_inter_rect_chroma` already implements for the other rect paths, + for a caller that keeps its own grid assembly and neighbour recording. It is + entered ONLY when `cw.min(32) != cw || ch.min(32) != ch`, so at 4:2:0 and at + every 4:4:4 shape below 64 the caller's own one-unit read is untouched + byte-for-byte. +* Per unit: its own `around_mi_rect(cu_mi, span_x, span_y)` gather, its own + `(cpx + cu_col*uw, cpy + cu_row*uh)` origin, its own prediction slice, its own + `covering_leaf_tx_type(...)` inheritance (`av1_get_tx_type`, blockd.h:1287, + reads `xd->tx_type_map` at the unit's own position), the `get_txb_ctx` plus-10 + offset as `Some(3)`, and `record_mi_chroma` immediately so the next unit + reads this one's context. +* `record_split_luma_rect_mi_modes` / `record_rect_mi_luma_only` (new, extracted + from `record_split_luma_rect_mi` / `record_rect_mi`): when the chroma plane + block was walked as several units, the whole-block coefficient stamp would + overwrite the per-unit spans with one state (the `override-slot-on-one-arm` + class, the same reason the lossless arm sets `mu_chroma = true`). The flag is + `!skip && …`: a SKIPPED strip reads no chroma unit at all (its whole plane + block is one `push_mc_rect` of `ZERO_RESIDUAL`), so no per-unit stamp ran and + the whole-block stamp is still the only one that happens. + +### The two pieces the charter asked for, and why they are not needed + +* **CDF set** — `Chroma32` (`cdf_state.rs`), the exact + `get_txsize_entropy_ctx(TX_32X32)` tables. Nothing new. +* **`rect_scan`** — a `TX_32X32` unit is square, so + `read_inter_plane_rect` takes its `(cw, ch) == (32, 32)` branch and reads + `default_scan(TX32)` (decode.rs:29546); `rect_scan` is never called. Nothing + new. +* **rect `base_ctx_rect` / `br_ctx_rect`** — same reason: those are the rect + forms of the 2:1 and 4:1 nz-map offsets, and no 2:1 or 4:1 chroma unit exists + at 4:4:4 for this block shape. Nothing new. The call the new walk makes is + byte-identical to the one `read_inter_rect_chroma` already makes for the + 4:4:4 four-unit arms proven by `lane-av1chrtx`. + +## 3. Result on the witness, and the OPEN fork that remains + +Same oracle, same comparison, after the fix: + + f0 Y 0 (byte-exact) | U 7488 from 229728 | V 8128 from 229728 total 15616 + f1 Y 0 (byte-exact) | U 22571 from 65704 | V 41782 from 65704 total 64353 + f2 Y 0 (byte-exact) | U 0 | V 0 0 + +Wrong samples over the whole stream: **640727 → 79969** (−87.5 %). Luma is +byte-exact on all three frames (786432/786432 samples; it was 166229 wrong on +f0). Frame 2 is byte-exact on all three planes (it was 9216 U + 8192 V wrong). + +Reach proof for the site, `EC_HALVSWEEP=1` (the rung is main's, merge +`edffad9e`), five strips on this witness, `mi` in 4-px units: + + EC_HALV ibc_owned mi=(32,40) bw=32 bh=64 skip=false + EC_HALV ibc_owned mi=(48,64) bw=32 bh=64 skip=true + EC_HALV ibc_owned mi=(64,108) bw=16 bh=64 skip=true + EC_HALV ibc_owned mi=(112,96) bw=32 bh=64 skip=true + EC_HALV ibc_owned mi=(112,104) bw=32 bh=64 skip=true + +(The previous lane reported 6 and named `mi=(72,32) 64x32 skip=false`. On this +base the count is 5 and that block is not reached. The witness blob is +byte-identical, so the difference is the tree, not the stream — the same +stale-verdict hazard the previous lane's r4 recorded, re-measured rather than +inherited.) + +### The residual is a DIFFERENT site, and it is NOT this lane's + +Both remaining regions are chroma-only, bounded, and luma-clean, so they are +reconstruction defects rather than entropy desyncs: + +* f0: 128 dirty 8x8 cells, bbox x=352..=504, y=448..=504 — the last 64 rows of + the frame. Strip #4's own footprint (x=384..=416) is CLEAN; strip #5's + (x=416..=448) is dirty, and so is everything to its right. +* f1: 362 dirty 8x8 cells (U) / 667 (V), bbox x=128..=368 / 128..=408, + y=128..=504, first dirty cell (168,128) PARTIAL (56 of 64 samples). + +Ruled out by measurement, not by argument: + +* **CfL.** `cfl_ac_q3_at` (decode.rs:20179) is the other `bw / 2, bh / 2` site + in this wave and is out of scope (another agent owns it). A temporary probe at + both its callers (`cfl_ac_q3`, `cfl_ac_q3_rect`) over the whole witness: + + $ EC_ZZCFL=1 cargo test -p ec-av1 --lib -- --nocapture | grep -c ZZCFL + 0 + + The witness codes NO CfL block, so `cfl_ac_q3_at` cannot be the residual. (The + probe was removed before the commit; it is not in the diff.) +* **The skip arm's record.** Forcing `chroma_split_units` true for skipped + strips as well changes neither number — the f0 band and the f1 region are + identical with and without it. +* **This lane's helper.** The per-unit prediction slice's column term + (`cu_col * uw`) is dead on this witness (`nx == 1`), so mutating it leaves the + gate green; the row term does bite (see §5, M5). + +NOT DONE, explicitly: the f0 and f1 chroma residue above. It is not attributable +to `decode_intrabc_owned_rect` from the evidence I have, and I did not identify +its site. It is stated as a measured open fork, with numbers, rather than +absorbed into a "wrong by exactly N" expectation. + +## 4. Gates + +### 4.1 The refusal gate went in FIRST, and it went RED + +Commit 1 (`58629693`) pins the witness, lands the ss-derived extent and the eight +MV origin pairs, and adds +`a_444_intrabc_owned_rect_strip_refuses_the_missing_rect_chroma_coefficient_set` +— which asserts, on purpose, that the witness is REFUSED with the exact string +`a rectangular inter chroma transform unit whose shape has no coefficient table +set here`, and that exactly one strip reached the corrected extent before the +decode stopped. It cites this lane in the test. Without it the witness would be +a pin with nothing watching it. + +Commit 2 replaces that test with +`a_444_intrabc_owned_rect_strip_sizes_its_chroma_plane_block_and_decodes`, the +pixel-exactness assertion the refusal gate was there to force. + +The refusal string is gone from the witness's decode because nothing reaches it, +not because it was deleted: `rect_inter_chroma_set` still refuses `(32, 64)` and +`(64, 32)`, the string is still in `decode.rs:28938` and in +`refusal_inventory.rs:55`, and the gate +`every_rect_transform_shape_the_census_lists_has_a_coefficient_table_and_scan` +(which names all three rect refusals and asserts they are still in the source) +still passes. + +### 4.2 Non-vacuity: the route counter, and three mutations + +`IBC_OWNED_RECT_CHROMA_FOOTPRINT_444_HITS` counts 128-root intra-BC strips whose +chroma plane block was sized at ss (0,0). At 4:2:0 the corrected and halving +forms are identical, so `>= 1` cannot be satisfied by a 4:2:0 stream, and the +arm is exclusive to this function. The gate asserts `hits == 5`. + +Mutation proofs against the gate, each reverted after: + +| # | mutation | result | +| --- | --- | --- | +| M1 | `bw >> ss_x` / `bh >> ss_y` and `px >> ss_x` / `py >> ss_y` back to `/ 2` | **RED** — `assertion left == right failed: 6 128-root intra-BC strip(s) sized at 4:4:4, not 5` (the counter bites: with the halving a sixth strip reaches the arm) | +| M3 | `(nx, ny) = (cw / uw, ch / uh)` → `(ch / uh, cw / uw)` | **RED** — `frame 0 plane Y diverges from the oracle at sample 65728 of 262144 (x=192, y=128)` | +| M5 | `let (cu_x, cu_y) = (cpx + cu_col * uw, cpy + cu_row * uh)` → `(cpx, cpy)` | **RED** — `frame 0 plane U diverges from the oracle at sample 65696 of 262144 (x=160, y=128)` | + +A fourth mutation (dropping the `cu_col * uw` term from the prediction slice) +left the gate GREEN — correctly, because `nx == 1` on this witness makes that +term dead here. Recorded because a green mutation is a fact about coverage, not +about the gate. + +The gate's own shape, per (frame, plane) exact prefix against the oracle, with +the floors it pins: `[[262144, 229728, 229728], [262144, 65704, 65704], +[262144, 262144, 262144]]` — the same honest "exact prefix that only grows" form +as the sibling `a_444_intrabc_rect_chroma_plane_block_is_the_block_footprint`. +It is a floor, not an exactness claim: §3 says exactly what it does not cover. + +## 5. Gate families re-quoted + +`cargo check -p ec-av1 --all-targets` clean (no errors, no warnings) before every +run, on a private `CARGO_TARGET_DIR`; a green gate alongside a build error would +have been a stale binary. + + $ EC_AV1_REQUIRE_AOMDEC=1 EC_AV1_REQUIRE_AOMENC=1 \ + cargo test -p ec-av1 --lib -- a_444 lossless_444 intrabc_rect 444_lossless -- --nocapture + test result: ok. 33 passed; 0 failed; 0 ignored; 0 measured; 730 filtered out + +That set contains the 4:4:4-lossless family (`a_lossless_444_*`, +`a_444_lossless_sb64_intrabc_rect_chroma_walks_4x4_units`, +`a_real_aomenc_lossless_444_key_frame_decodes_sample_exact`), the intrabc_rect +family (`a_444_intrabc_rect4_reads_its_own_chroma_plane_block`, +`a_lossless_444_intrabc_rect_leaf_walks_per_4x4_units`, +`a_lossless_444_intrabc_rect_replay_steps_by_the_units_own_mi_footprint`, +`a_skipped_lossless_intrabc_rect_strip_zeroes_its_entropy_bands`, +`a_coded_rect_intrabc_block_reconstructs_in_both_orientations`) and — the 4:2:0 +identity arm — `a_444_intrabc_rect_chroma_plane_block_is_the_block_footprint`, +which decodes the pinned 4:2:0 twin (`420_intrabc_rect4_witness.obu`) through +`decode_all_frames_vs_oracle`. + +The wider 121-test `rect intrabc ibc chroma 444 420 subsampl` family, tip vs +the base commit, is in §6. + +## 6. 121-test family: tip vs base + +One filtered run per tree, same filter string, same env, separate private +`CARGO_TARGET_DIR` each (a shared-shape target dir is exactly how the previous +lane got a stale verdict): + + $ EC_AV1_REQUIRE_AOMDEC=1 EC_AV1_REQUIRE_AOMENC=1 cargo test -p ec-av1 --lib \ + -- rect intrabc ibc chroma 444 420 subsampl -- --nocapture + +| tree | result | +| --- | --- | +| base `edffad9e` (`~/.cache/wt/av1chromarect-base`, detached) | `ok. 137 passed; 0 failed; 5 ignored; 0 measured; 620 filtered out; finished in 288.38s` | +| tip `lane-av1chromarect` | `ok. 138 passed; 0 failed; 5 ignored; 0 measured; 620 filtered out; finished in 295.84s` | + +The set difference of the two passing-test lists is exactly one line: + + 34a35 + > test stream::tests::a_444_intrabc_owned_rect_strip_sizes_its_chroma_plane_block_and_decodes + +The same 5 tests are `#[ignore]`d in both trees (two superblock-size globals, a +directional sweep, an intrabc probe needing the real-library manifest, and the +rectx recipe sweep). Nothing regressed, nothing was silently dropped. + +Inside that family, the 4:2:0 identity is carried by +`a_444_intrabc_rect_chroma_plane_block_is_the_block_footprint`, which decodes +the pinned 4:2:0 twin `420_intrabc_rect4_witness.obu` through +`decode_all_frames_vs_oracle` (every frame byte-exact vs aomdec) and +`a_444_intrabc_rect4_reads_its_own_chroma_plane_block`; the 4:4:4-lossless arm +by the `a_lossless_444_*` set; the intrabc_rect arm by +`a_lossless_444_intrabc_rect_leaf_walks_per_4x4_units`, +`a_lossless_444_intrabc_rect_replay_steps_by_the_units_own_mi_footprint`, +`a_skipped_lossless_intrabc_rect_strip_zeroes_its_entropy_bands`, +`a_444_lossless_sb64_intrabc_rect_chroma_walks_4x4_units` and +`a_coded_rect_intrabc_block_reconstructs_in_both_orientations`. + +## 7. Gap row — `decode_intra_sub8_leaf` has no `chroma_422` arm + +`crates/ec-av1/src/decode.rs:45594`, body ends at `46422`. It carries a +`chroma_444` branch set and **zero** `chroma_422` mentions inside the body +(`awk 'NR>=45594 && NR<=46422' | grep -c chroma_422` → `0`; the two +`chroma_422` mentions at 45394/45406 belong to the enclosing +`decode_intra_split`, not to this function). + +The 4:4:4 branches it owns, and what each falls back to at 4:2:2: + +| line | what the `chroma_444` arm does | what 4:2:2 gets instead | +| --- | --- | --- | +| 46083 | `let chroma_444 = ss_x == 0 && ss_y == 0` | `false` at (1,0) | +| 46086 | `unit_x, unit_y = (px, py)` | `(cpx, cpy)` — the 4:2:0 double halving; at (1,0) the width halves and the height does not | +| 46088-46093 | `reach_c` = the piece's own rect reach at 4:4:4 | `group_reach` (an 8x8 group reach) | +| 46095 | `band_r, band_c` from `lmi` | from `r, c` (the group) | +| 46101-46102 | `smooth_uv_neighbour` sampled at `lmi` | sampled at `gr, gc` | +| 46115 | `record_uv_mode_mi(lmi, w_mi, h_mi)` | `record_uv_mode_mi(gr, gc, 2, 2)` — a 2x2 group stamp | +| 46122 | `cfl_src_rect(px, py, bw, bh)` | not taken | +| 46134, 46198 | the non-square 4:4:4 unit shape arms | not taken | +| 46340-46341 | chroma per-unit gather at `lmi` with a 4-px step | at `group_mi` with an 8-px step | +| 46399 | the 4:4:4 publish/stamp half | the `!chroma_444 && !chroma_422` fallbacks (45394/45406 in the enclosing `decode_intra_split`) | + +The shape the missing arm would have to be: at 4:2:2 `ss_size_lookup` maps an +8x4 block to `BLOCK_INVALID` (common_data.c:38) and no `TX_4X8` chroma unit +exists, so a 4:2:2 sub-8 leaf's chroma is coded CHUNKED, exactly the +`invalid_ss_plane` case `read_inter_rect_chroma` already special-cases +(decode.rs:29328, `(4, 32)` at ss (1,0) → `(4, 8)` units). + +**Caller set — exactly two sites, and BOTH are already 4:2:2-aware:** + +1. `decode.rs:44724` — the `BLOCK_4X4` leaf of the sub-8x8 intra-in-inter split + arm. It passes + `has_chroma = chroma_444 || (cmi & 1 == 1 && chroma_422) || i == 3` + (libaom's `is_chroma_reference`, `av1_common_int.h:1459`: BOTH odd-column + pieces at 4:2:2). +2. `decode.rs:46610` — the `(bw, bh)` 8x8/4x8/8x4 piece. It passes + `has_chroma = piece_is_chroma_ref(i)`, and `piece_is_chroma_ref` + (decode.rs:46534) has an explicit `else if chroma_422 { !vert || ((gc + i) & 1) == 1 }` + branch. + +So the callers compute the 4:2:2 chroma-reference rule correctly and the leaf +body has no geometry arm to honour it. This is a latent gap, not a live bug: the +crate refuses 4:2:2 by name at the sequence header +(`"a chroma format of 4:2:2 (subsampling_x != subsampling_y): this decoder +decodes 4:2:0 and 4:4:4; 4:2:2 is not ported"`, `refusal_inventory.rs:119`, gate +`a_non_420_subsampled_sequence_header_is_refused_by_name`, stream.rs:2258), so +`chroma_422` is always `false` when this function runs. Not implemented here, by +charter. + +## 8. Scope boundaries, stated + +* `cfl_ac_q3_at` (decode.rs:20179, `let (cw, ch) = (bw / 2, bh / 2);`, no + `fctx`) — **untouched, another lane owns it.** §3 measures that the witness + codes no CfL, so it is not this witness's residual either. +* `suppress_internal_lf_edges` — **not re-fixed.** C1 (wave 3d, on this base) + already threads `fctx` into it and computes `((w_mi * MI) >> ss_x(fctx)).max(4)`. + The earlier "format-blind" claim is retracted upstream; there is nothing here + to change. +* `decode_intrabc_rect` (the non-`owned` sibling, decode.rs:13646) reads its + chroma with the same single-unit `rect_inter_chroma_set(cw, ch)`. It is + ss-correct (lane-ibc444c) and its pinned 4:4:4 witness is 8x16, one unit, so + the multi-unit case is latent there too. I did not widen the fix: this lane's + witness and its gate do not reach it, and a change there would be unmeasured. + Flagged for whoever takes the next 4:4:4 rect cell. + +## 9. What I could not do + +1. The f0/f1 chroma residue of §3 is not identified to a site. 79969 wrong + samples remain out of 2359296 (3.4 %); luma is exact everywhere. +2. The 128-root multi-unit *record* difference in §2 is derived from libaom's + per-unit above/left context update and validated by the gate going from + 640727 wrong samples to 79969 with luma exact; I did not diff our per-unit + above/left contexts against the oracle's rung-by-rung. +3. No heavy encodes were run: the witness was taken from the pin, and the gate + families are fixture-driven. No server fleet run was requested or consumed.