ec-av1: lane-av1-422f r1 -- square-block chroma is the plane block's own rect unit, behind the header refusal
Browse files at this commit4f08853afaf02da0ad73c77e7bf7601707abde66Parent: 7607f603 changed files +413 -55
- crates/ec-av1/examples/decode_probe.rs +1 -0
- crates/ec-av1/src/decode.rs +297 -55
- lanes/av1422f.report.md +115 -0
crates/ec-av1/examples/decode_probe.rsmodified+1 -0
| @@ -40,6 +40,7 @@ fn main() { | ||
| 40 | 40 | "chroma422_square: {}", |
| 41 | 41 | ec_av1::decode::chroma422_square_hits() |
| 42 | 42 | ); |
| 43 | + println!("chroma422_rect: {}", ec_av1::decode::chroma422_rect_hits()); | |
| 43 | 44 | let (h, v, c) = ec_av1::stream::rect4_32_counters(); |
| 44 | 45 | println!("rect4_32: horz={h} vert={v} coded={c}"); |
| 45 | 46 | println!( |
crates/ec-av1/src/decode.rsmodified+297 -55
| @@ -2038,6 +2038,22 @@ pub fn chroma422_square_hits() -> usize { | ||
| 2038 | 2038 | CHROMA422_SQUARE_HITS.with(|c| c.get()) |
| 2039 | 2039 | } |
| 2040 | 2040 | |
| 2041 | +// lane-av1-422f: how many RECT chroma coefficient units the square-block | |
| 2042 | +// path read on a 4:2:2 frame (ss 1,0) -- TX_4X8 / TX_8X16 / TX_16X32, the | |
| 2043 | +// plane block's own half-width, unhalved-height shape. A 4:2:0 or 4:4:4 | |
| 2044 | +// frame never takes the rect branch (their units are square | |
| 2045 | +// `chroma_tx == chroma_tx_h`), so a witness gate reading 0 here proves the | |
| 2046 | +// model reverted to squares. | |
| 2047 | +thread_local! { | |
| 2048 | + static CHROMA422_RECT_HITS: std::cell::Cell<usize> = | |
| 2049 | + const { std::cell::Cell::new(0) }; | |
| 2050 | +} | |
| 2051 | + | |
| 2052 | +/// Current value of [`CHROMA422_RECT_HITS`]. | |
| 2053 | +pub fn chroma422_rect_hits() -> usize { | |
| 2054 | + CHROMA422_RECT_HITS.with(|c| c.get()) | |
| 2055 | +} | |
| 2056 | + | |
| 2041 | 2057 | // How many HORZ/VERT intra strips actually predicted with filter intra |
| 2042 | 2058 | // (lane-rectsplit r1) -- the case `decode_block_rect` refused by name |
| 2043 | 2059 | // ("this decoder predicts square-only") until `predict_filter_intra` took |
| @@ -8485,6 +8501,46 @@ impl Neighbours { | ||
| 8485 | 8501 | out |
| 8486 | 8502 | } |
| 8487 | 8503 | |
| 8504 | + /// [`Self::around_mi_rect`] for the CHROMA planes of a 4:2:2 frame | |
| 8505 | + /// (lane-av1-422f): libaom `get_txb_ctx_general` reads its above votes | |
| 8506 | + /// over `txb_w_unit` CHROMA 4-px cells, and at ss_x 1 one chroma cell | |
| 8507 | + /// spans TWO luma mi columns. Both cells of a column carry the covering | |
| 8508 | + /// unit's whole-unit dc sign (the same value libaom stores), so the | |
| 8509 | + /// per-luma-mi sum counts each chroma column twice -- and | |
| 8510 | + /// `dc_sign_ctx`'s signum flips whenever the above and left votes have | |
| 8511 | + /// opposite signs with equal magnitude (measured at mi(4,4) plane 1 of | |
| 8512 | + /// the t422 fixture: ours read `dc_sign_cdf[1]`, the oracle row 0). | |
| 8513 | + /// Sampling every second above cell counts each chroma column once, | |
| 8514 | + /// which IS libaom's sum. The left extent is unsubsquared at ss_y 0, so | |
| 8515 | + /// its per-mi cells already line up one-to-one. The level booleans are | |
| 8516 | + /// ORs over duplicated cells, so the sampling cannot change them. | |
| 8517 | + fn around_mi_422_chroma( | |
| 8518 | + &self, | |
| 8519 | + (mi_r, mi_c): (usize, usize), | |
| 8520 | + w: usize, | |
| 8521 | + h: usize, | |
| 8522 | + ) -> [(bool, bool, i32); 3] { | |
| 8523 | + let (w_mi, h_mi) = (w / MI, h / MI); | |
| 8524 | + let above_mi = w_mi.min(self.mi_cols.saturating_sub(mi_c)); | |
| 8525 | + let left_mi = h_mi.min(self.mi_rows.saturating_sub(mi_r)); | |
| 8526 | + let mut out = [(false, false, 0i32); 3]; | |
| 8527 | + for cell in (0..above_mi).step_by(2) { | |
| 8528 | + let above = &self.above[mi_c + cell]; | |
| 8529 | + for (plane, o) in out.iter_mut().enumerate() { | |
| 8530 | + o.0 |= above[plane].level != 0; | |
| 8531 | + o.2 += dc_vote(above[plane].dc); | |
| 8532 | + } | |
| 8533 | + } | |
| 8534 | + for cell in 0..left_mi { | |
| 8535 | + let left = &self.left[mi_r + cell]; | |
| 8536 | + for (plane, o) in out.iter_mut().enumerate() { | |
| 8537 | + o.1 |= left[plane].level != 0; | |
| 8538 | + o.2 += dc_vote(left[plane].dc); | |
| 8539 | + } | |
| 8540 | + } | |
| 8541 | + out | |
| 8542 | + } | |
| 8543 | + | |
| 8488 | 8544 | /// [`Self::around`] with independent above (`w`)/left (`h`) extents, in |
| 8489 | 8545 | /// pixels -- lane-rectwire, mirrors [`Self::record_rect`]'s asymmetric |
| 8490 | 8546 | /// extent pattern for a true rectangular strip's own coefficient context. |
| @@ -16620,6 +16676,100 @@ fn read_plane( | ||
| 16620 | 16676 | Ok(levels) |
| 16621 | 16677 | } |
| 16622 | 16678 | |
| 16679 | +/// [`push_intra`] when the unit is square, [`push_intra_rect`] when it is a | |
| 16680 | +/// rect (lane-av1-422f): a 4:2:2 square-block chroma unit is the plane | |
| 16681 | +/// block's own rect shape, and the `rect` flag selects | |
| 16682 | +/// [`PlaneBuf::reconstruct_rect`]'s two-dimensional loop. | |
| 16683 | +#[allow(clippy::too_many_arguments)] | |
| 16684 | +fn push_intra_unit( | |
| 16685 | + plane: usize, | |
| 16686 | + x: usize, | |
| 16687 | + y: usize, | |
| 16688 | + w: usize, | |
| 16689 | + h: usize, | |
| 16690 | + mode: usize, | |
| 16691 | + angle_delta: i32, | |
| 16692 | + reach: Reach, | |
| 16693 | + residual: &[i32], | |
| 16694 | + cfl: Option<(i32, CflSrc)>, | |
| 16695 | + filter_intra: Option<usize>, | |
| 16696 | + smooth_neighbor: bool, fctx: &crate::decode::FrameCtx, | |
| 16697 | +) { | |
| 16698 | + if w == h { | |
| 16699 | + push_intra(plane, x, y, w, mode, angle_delta, reach, residual, cfl, | |
| 16700 | + filter_intra, smooth_neighbor, fctx); | |
| 16701 | + } else { | |
| 16702 | + push_intra_rect(plane, x, y, w, h, mode, angle_delta, reach, residual, cfl, | |
| 16703 | + filter_intra, smooth_neighbor, fctx); | |
| 16704 | + } | |
| 16705 | +} | |
| 16706 | + | |
| 16707 | +/// ONE RECT chroma transform unit of a square block's uv plane | |
| 16708 | +/// (lane-av1-422f) -- a 4:2:2 frame's plane block is `(side/2, side)` and | |
| 16709 | +/// `av1_get_max_uv_txsize` fills it with a single rect unit below side 64 | |
| 16710 | +/// (TX_4X8 / TX_8X16 / TX_16X32), which the square-shaped [`read_plane`] | |
| 16711 | +/// cannot express. Same shape as [`leaf8_chroma422_unit`]'s proven read: the | |
| 16712 | +/// [`TxbSet`] whose entropy class the unit squares up to, the unit-shaped | |
| 16713 | +/// scan, `txb_skip_ctx` = above + left in the offset-7 rows (the unit covers | |
| 16714 | +/// the plane block exactly, so no `+3` bigger-plane term -- that one lives in | |
| 16715 | +/// the square multi-unit walks' `chroma_ctx_offset`), and the plane's | |
| 16716 | +/// predicted mode supplies the mode-derived default `tx_type` unless an armed | |
| 16717 | +/// [`INTRABC_CHROMA_TX`] slot carries the intrabc luma's own -- except at an | |
| 16718 | +/// entropy class of 32x32 and up, where the spec forces `DCT_DCT` | |
| 16719 | +/// ([`read_plane`]'s `side >= 32` clamp). | |
| 16720 | +#[allow(clippy::too_many_arguments)] | |
| 16721 | +fn read_rect_chroma_unit( | |
| 16722 | + dec: &mut SymbolDecoder, | |
| 16723 | + cdfs: &mut Cdfs, | |
| 16724 | + set: TxbSet, | |
| 16725 | + scan: &[u16], | |
| 16726 | + w: usize, | |
| 16727 | + h: usize, | |
| 16728 | + plane_idx: usize, | |
| 16729 | + around: (bool, bool, i32), | |
| 16730 | + uv_predict_mode: usize, | |
| 16731 | + angle_delta_uv: i32, | |
| 16732 | + reach: Reach, | |
| 16733 | + // Unread, like [`read_plane`]'s own: the borrow proves the caller holds | |
| 16734 | + // the plane exclusively while the unit's coefficients are parsed. | |
| 16735 | + _plane: &mut PlaneBuf<'static>, | |
| 16736 | + x: usize, | |
| 16737 | + y: usize, | |
| 16738 | + // Signature parity with [`read_plane`]; the dequant reads its q index | |
| 16739 | + // off `block_q_idx(fctx)` like every other reader here. | |
| 16740 | + _base_q_idx: u8, | |
| 16741 | + cfl: Option<(i32, CflSrc)>, | |
| 16742 | + smooth_neighbor_uv: bool, fctx: &crate::decode::FrameCtx, | |
| 16743 | +) -> Result<Grid> { | |
| 16744 | + if ss_x(fctx) == 1 && ss_y(fctx) == 0 && w != h { | |
| 16745 | + hit!(CHROMA422_RECT_HITS); | |
| 16746 | + } | |
| 16747 | + let default_tx = if w.max(h) >= 32 { | |
| 16748 | + TxType::DctDct | |
| 16749 | + } else { | |
| 16750 | + fctx | |
| 16751 | + .intrabc_chroma_tx | |
| 16752 | + .with(std::cell::Cell::get) | |
| 16753 | + .unwrap_or_else(|| default_intra_tx_type(uv_predict_mode as u8)) | |
| 16754 | + }; | |
| 16755 | + let mut coding = cdfs.txb(set, uv_predict_mode); | |
| 16756 | + let (levels, tx_type) = read_coeffs_rect( | |
| 16757 | + dec, &mut coding, scan, w, h, | |
| 16758 | + usize::from(around.0) + usize::from(around.1), | |
| 16759 | + dc_sign_ctx(around.2), default_tx, | |
| 16760 | + )?; | |
| 16761 | + let residual = dequant_and_inverse_typed_wh( | |
| 16762 | + &levels, w, h, crate::decode::bit_depth(fctx), block_q_idx(fctx), | |
| 16763 | + plane_q_delta(plane_idx, fctx).0, plane_q_delta(plane_idx, fctx).1, | |
| 16764 | + tx_type, block_iqmatrix(fctx, plane_idx, w, h, tx_type), | |
| 16765 | + ); | |
| 16766 | + push_intra_rect( | |
| 16767 | + plane_idx, x, y, w, h, uv_predict_mode, angle_delta_uv, reach, | |
| 16768 | + &residual, cfl, None, smooth_neighbor_uv, fctx, | |
| 16769 | + ); | |
| 16770 | + Ok(levels) | |
| 16771 | +} | |
| 16772 | + | |
| 16623 | 16773 | /// Decodes one whole-block coded superblock/quadrant/leaf: its mode, then its |
| 16624 | 16774 | /// three planes, reconstructing them into `y`/`u`/`v` and updating |
| 16625 | 16775 | /// `neighbours`. |
| @@ -16690,8 +16840,8 @@ fn decode_block( | ||
| 16690 | 16840 | // rewrite (which sat above `read_intra_mode`) rides along here -- same |
| 16691 | 16841 | // per-frame `ss_x`/`ss_y` condition, now resolved against the block's own |
| 16692 | 16842 | // segment like the lossless arm above it. |
| 16693 | - let (luma_set, chroma_set, luma_tx, chroma_tx, scans) = if lossless(fctx) { | |
| 16694 | - (TxbSet::Luma4, TxbSet::Chroma4, 4, 4, (scan4, scan4)) | |
| 16843 | + let (luma_set, chroma_set, luma_tx, chroma_tx, chroma_tx_h, scans) = if lossless(fctx) { | |
| 16844 | + (TxbSet::Luma4, TxbSet::Chroma4, 4, 4, 4, (scan4, scan4)) | |
| 16695 | 16845 | } else if ss_x(fctx) == 0 && ss_y(fctx) == 0 { |
| 16696 | 16846 | let tx = if side >= 64 { 32 } else { side }; |
| 16697 | 16847 | let (set, scan): (TxbSet, &[u16]) = match tx { |
| @@ -16700,27 +16850,39 @@ fn decode_block( | ||
| 16700 | 16850 | 8 => (TxbSet::Chroma8, scan8), |
| 16701 | 16851 | _ => (TxbSet::Chroma4, scan4), |
| 16702 | 16852 | }; |
| 16703 | - (luma_set, set, luma_tx, tx, (scans.0, scan)) | |
| 16853 | + (luma_set, set, luma_tx, tx, tx, (scans.0, scan)) | |
| 16704 | 16854 | } else if ss_x(fctx) == 1 && ss_y(fctx) == 0 { |
| 16705 | - // lane-av1-422b: the uv plane block is (side/2, side) | |
| 16706 | - // (`ss_size_lookup[..][1][0]`), so `av1_get_max_uv_txsize` is the | |
| 16707 | - // SQUARE transform of the smaller dimension, capped at TX_32X32 | |
| 16708 | - // (`av1_get_adjusted_tx_size` only ever shrinks): 4 -> TX_4X4 (the | |
| 16709 | - // 2x4 plane rounds up to BLOCK_4X4), 8 -> TX_4X4 (BLOCK_4X8), | |
| 16710 | - // 16 -> TX_8X8 (BLOCK_8X16), 32 -> TX_16X16, 64 -> TX_32X32 | |
| 16711 | - // (BLOCK_32X64), 128 -> TX_32X32 (BLOCK_64X128 adjusts TX_64X64 | |
| 16712 | - // down). The units stay square; the UNIT GRID is (side/2)/tx wide | |
| 16713 | - // by side/tx tall -- never square above a 4x4 luma block. | |
| 16714 | - let tx = if side >= 64 { 32 } else { (side / 2).max(4) }; | |
| 16715 | - let (set, scan): (TxbSet, &[u16]) = match tx { | |
| 16716 | - 32 => (TxbSet::Chroma32, scan32), | |
| 16717 | - 16 => (TxbSet::Chroma16, scan16), | |
| 16718 | - 8 => (TxbSet::Chroma8, scan8), | |
| 16719 | - _ => (TxbSet::Chroma4, scan4), | |
| 16855 | + // lane-av1-422f: the uv plane block is the (side/2, side) rect | |
| 16856 | + // (`ss_size_lookup[..][1][0]`), and `av1_get_max_uv_txsize` is | |
| 16857 | + // `av1_get_adjusted_tx_size(max_txsize_rect_lookup[plane_bsize])` -- | |
| 16858 | + // the RECT that fills the plane block, NOT the square transform of | |
| 16859 | + // the smaller side (the oracle reads ONE TX_8X16 for a 16x16 block's | |
| 16860 | + // 8x16 plane where the old model read two 8x8 units): 4 -> TX_4X4 | |
| 16861 | + // (the 2x4 plane rounds up to BLOCK_4X4), 8 -> TX_4X8, 16 -> | |
| 16862 | + // TX_8X16, 32 -> TX_16X32 (one unit per plane, the whole plane | |
| 16863 | + // block), 64 -> TX_32X64 adjusts to TX_32X32 and 128 -> TX_64X64 | |
| 16864 | + // adjusts to TX_32X32 (square units, a 1x2 / 2x4 grid). | |
| 16865 | + // `chroma_tx` is the unit WIDTH, `chroma_tx_h` its HEIGHT; the | |
| 16866 | + // chroma walks below read one (chroma_tx, chroma_tx_h) unit per grid | |
| 16867 | + // cell and key their rect reads on `chroma_tx != chroma_tx_h`. | |
| 16868 | + let (tx_w, tx_h) = match side { | |
| 16869 | + 4 => (4, 4), | |
| 16870 | + 8 => (4, 8), | |
| 16871 | + 16 => (8, 16), | |
| 16872 | + 32 => (16, 32), | |
| 16873 | + // 64 and 128: TX_32X64 / TX_64X64 adjust down to TX_32X32. | |
| 16874 | + _ => (32, 32), | |
| 16875 | + }; | |
| 16876 | + let (set, scan): (TxbSet, &[u16]) = match side { | |
| 16877 | + 4 => (TxbSet::Chroma4, scan4), | |
| 16878 | + 8 => (TxbSet::ChromaRect8x4, &SCAN_4X8[..]), | |
| 16879 | + 16 => (TxbSet::ChromaRect16x8, &SCAN_8X16[..]), | |
| 16880 | + 32 => (TxbSet::ChromaRect32x16, &SCAN_16X32[..]), | |
| 16881 | + _ => (TxbSet::Chroma32, scan32), | |
| 16720 | 16882 | }; |
| 16721 | - (luma_set, set, luma_tx, tx, (scans.0, scan)) | |
| 16883 | + (luma_set, set, luma_tx, tx_w, tx_h, (scans.0, scan)) | |
| 16722 | 16884 | } else { |
| 16723 | - (luma_set, chroma_set, luma_tx, chroma_tx, scans) | |
| 16885 | + (luma_set, chroma_set, luma_tx, chroma_tx, chroma_tx, scans) | |
| 16724 | 16886 | }; |
| 16725 | 16887 | let intrabc_dv = fctx.intrabc_dv.with(|c| c.take()); |
| 16726 | 16888 | // `predict` panics outside `DC_PRED..=PAETH_PRED` (0..=12); `UV_CFL_PRED` |
| @@ -17020,11 +17182,13 @@ fn decode_block( | ||
| 17020 | 17182 | // square at 4:2:0/4:4:4, at 4:2:2 `(side/2)/tx` units wide by |
| 17021 | 17183 | // `side/tx` tall (the plane block is (side/2, side)). A unit's LUMA |
| 17022 | 17184 | // anchor follows the per-axis shifts: `chroma_tx << ss_x` wide, |
| 17023 | - // `chroma_tx << ss_y` tall. | |
| 17185 | + // `chroma_tx_h << ss_y` tall (lane-av1-422f: the unit itself is the | |
| 17186 | + // (chroma_tx, chroma_tx_h) rect, so a 4:2:2 frame below side 64 | |
| 17187 | + // reads ONE unit per plane, the whole plane block). | |
| 17024 | 17188 | let cn_cols = (chroma_side / chroma_tx).max(1); |
| 17025 | - let cn_rows = (chroma_height / chroma_tx).max(1); | |
| 17189 | + let cn_rows = (chroma_height / chroma_tx_h).max(1); | |
| 17026 | 17190 | let luma_span_x = chroma_tx << ss_x(fctx); |
| 17027 | - let luma_span_y = chroma_tx << ss_y(fctx); | |
| 17191 | + let luma_span_y = chroma_tx_h << ss_y(fctx); | |
| 17028 | 17192 | for cu_row in 0..cn_rows { |
| 17029 | 17193 | for cu_col in 0..cn_cols { |
| 17030 | 17194 | let cu_r = if cn_rows == 1 && cn_cols == 1 { |
| @@ -17036,18 +17200,19 @@ fn decode_block( | ||
| 17036 | 17200 | reach, px, py, y.width, y.height, fctx, |
| 17037 | 17201 | ) |
| 17038 | 17202 | }; |
| 17039 | - let (cu_x, cu_y) = (cpx + cu_col * chroma_tx, cpy + cu_row * chroma_tx); | |
| 17203 | + let (cu_x, cu_y) = (cpx + cu_col * chroma_tx, cpy + cu_row * chroma_tx_h); | |
| 17040 | 17204 | if let Some((ub, _)) = &palette_uv_bufs { |
| 17041 | 17205 | set_palette_pred(ub.clone(), fctx); |
| 17042 | 17206 | } |
| 17043 | - push_intra(1, | |
| 17207 | + push_intra_unit(1, | |
| 17044 | 17208 | cu_x, |
| 17045 | 17209 | cu_y, |
| 17046 | 17210 | chroma_tx, |
| 17211 | + chroma_tx_h, | |
| 17047 | 17212 | uv_predict_mode, |
| 17048 | 17213 | angle_delta_uv, |
| 17049 | 17214 | cu_r, |
| 17050 | - &ZERO_RESIDUAL[..chroma_tx * chroma_tx], | |
| 17215 | + &ZERO_RESIDUAL[..chroma_tx * chroma_tx_h], | |
| 17051 | 17216 | alpha.zip(ac).map(|((au, _), ac)| (au, ac)), |
| 17052 | 17217 | None, |
| 17053 | 17218 | smooth_neighbor_uv, fctx, |
| @@ -17055,14 +17220,15 @@ fn decode_block( | ||
| 17055 | 17220 | if let Some((_, vb)) = &palette_uv_bufs { |
| 17056 | 17221 | set_palette_pred(vb.clone(), fctx); |
| 17057 | 17222 | } |
| 17058 | - push_intra(2, | |
| 17223 | + push_intra_unit(2, | |
| 17059 | 17224 | cu_x, |
| 17060 | 17225 | cu_y, |
| 17061 | 17226 | chroma_tx, |
| 17227 | + chroma_tx_h, | |
| 17062 | 17228 | uv_predict_mode, |
| 17063 | 17229 | angle_delta_uv, |
| 17064 | 17230 | cu_r, |
| 17065 | - &ZERO_RESIDUAL[..chroma_tx * chroma_tx], | |
| 17231 | + &ZERO_RESIDUAL[..chroma_tx * chroma_tx_h], | |
| 17066 | 17232 | alpha.zip(ac).map(|((_, av), ac)| (av, ac)), |
| 17067 | 17233 | None, |
| 17068 | 17234 | smooth_neighbor_uv, fctx, |
| @@ -17120,11 +17286,15 @@ fn decode_block( | ||
| 17120 | 17286 | // At 4:2:0 `chroma_side == chroma_tx`, so it stays one read. |
| 17121 | 17287 | // lane-av1-422b: 4:2:2 never collapses to one read above a 4x4 luma |
| 17122 | 17288 | // block -- the unit grid is `(side/2)/tx` wide by `side/tx` tall. |
| 17289 | + // lane-av1-422f: `chroma_tx` is the unit WIDTH and `chroma_tx_h` its | |
| 17290 | + // HEIGHT, so below side 64 a 4:2:2 frame's grid is 1x1 and the one | |
| 17291 | + // unit is the plane block's own rect. | |
| 17123 | 17292 | let cn_cols = (chroma_side / chroma_tx).max(1); |
| 17124 | - let cn_rows = (chroma_height / chroma_tx).max(1); | |
| 17293 | + let cn_rows = (chroma_height / chroma_tx_h).max(1); | |
| 17125 | 17294 | let luma_span_x = chroma_tx << ss_x(fctx); |
| 17126 | - let luma_span_y = chroma_tx << ss_y(fctx); | |
| 17295 | + let luma_span_y = chroma_tx_h << ss_y(fctx); | |
| 17127 | 17296 | let (u_grid, v_grid, chroma_units) = if cn_rows == 1 && cn_cols == 1 { |
| 17297 | + if chroma_tx == chroma_tx_h { | |
| 17128 | 17298 | if let Some((ub, _)) = &palette_uv_bufs { |
| 17129 | 17299 | set_palette_pred(ub.clone(), fctx); |
| 17130 | 17300 | } |
| @@ -17182,6 +17352,37 @@ fn decode_block( | ||
| 17182 | 17352 | smooth_neighbor_uv, fctx, |
| 17183 | 17353 | )?; |
| 17184 | 17354 | (u_grid, v_grid, Vec::new()) |
| 17355 | + } else { | |
| 17356 | + // lane-av1-422f: the one unit is a RECT filling the plane | |
| 17357 | + // block -- the square-shaped [`read_plane`] cannot express | |
| 17358 | + // it, so both planes go through [`read_rect_chroma_unit`] | |
| 17359 | + // (U, then V, the same order the square arm reads). The | |
| 17360 | + // chroma context reads per chroma 4-px cell (see | |
| 17361 | + // [`Neighbours::around_mi_422_chroma`]). | |
| 17362 | + let chroma_around = | |
| 17363 | + neighbours.around_mi_422_chroma((mi_r, mi_c), side, side); | |
| 17364 | + if let Some((ub, _)) = &palette_uv_bufs { | |
| 17365 | + set_palette_pred(ub.clone(), fctx); | |
| 17366 | + } | |
| 17367 | + let u_grid = read_rect_chroma_unit( | |
| 17368 | + dec, cdfs, chroma_set, scans.1, chroma_tx, chroma_tx_h, 1, | |
| 17369 | + chroma_around[1], uv_predict_mode, angle_delta_uv, reach, u, | |
| 17370 | + cpx, cpy, base_q_idx, | |
| 17371 | + alpha.zip(ac).map(|((au, _), ac)| (au, ac)), | |
| 17372 | + smooth_neighbor_uv, fctx, | |
| 17373 | + )?; | |
| 17374 | + if let Some((_, vb)) = &palette_uv_bufs { | |
| 17375 | + set_palette_pred(vb.clone(), fctx); | |
| 17376 | + } | |
| 17377 | + let v_grid = read_rect_chroma_unit( | |
| 17378 | + dec, cdfs, chroma_set, scans.1, chroma_tx, chroma_tx_h, 2, | |
| 17379 | + chroma_around[2], uv_predict_mode, angle_delta_uv, reach, v, | |
| 17380 | + cpx, cpy, base_q_idx, | |
| 17381 | + alpha.zip(ac).map(|((_, av), ac)| (av, ac)), | |
| 17382 | + smooth_neighbor_uv, fctx, | |
| 17383 | + )?; | |
| 17384 | + (u_grid, v_grid, Vec::new()) | |
| 17385 | + } | |
| 17185 | 17386 | } else { |
| 17186 | 17387 | let chroma_ctx_offset = Some(3); |
| 17187 | 17388 | let mut u_pass: Vec<Grid> = Vec::new(); |
| @@ -17195,8 +17396,13 @@ fn decode_block( | ||
| 17195 | 17396 | mi_r + cu_row * (luma_span_y / MI), |
| 17196 | 17397 | mi_c + cu_col * (luma_span_x / MI), |
| 17197 | 17398 | ); |
| 17198 | - let cu_around = | |
| 17199 | - neighbours.around_mi_rect(cu_mi, luma_span_x, luma_span_y); | |
| 17399 | + let cu_around = if ss_x(fctx) == 1 && ss_y(fctx) == 0 { | |
| 17400 | + // lane-av1-422f: chroma-only loop; per-chroma-cell | |
| 17401 | + // above votes (see [`Neighbours::around_mi_422_chroma`]). | |
| 17402 | + neighbours.around_mi_422_chroma(cu_mi, luma_span_x, luma_span_y) | |
| 17403 | + } else { | |
| 17404 | + neighbours.around_mi_rect(cu_mi, luma_span_x, luma_span_y) | |
| 17405 | + }; | |
| 17200 | 17406 | let cu_reach = tu_reach_rect( |
| 17201 | 17407 | side, |
| 17202 | 17408 | side, |
| @@ -17210,13 +17416,14 @@ fn decode_block( | ||
| 17210 | 17416 | y.width, |
| 17211 | 17417 | y.height, fctx, |
| 17212 | 17418 | ); |
| 17213 | - let (cu_x, cu_y) = (cpx + cu_col * chroma_tx, cpy + cu_row * chroma_tx); | |
| 17419 | + let (cu_x, cu_y) = | |
| 17420 | + (cpx + cu_col * chroma_tx, cpy + cu_row * chroma_tx_h); | |
| 17214 | 17421 | if let Some((ub, vb)) = &palette_uv_bufs { |
| 17215 | 17422 | let pbuf = if plane_pass == 1 { ub } else { vb }; |
| 17216 | 17423 | set_palette_pred( |
| 17217 | 17424 | palette_window( |
| 17218 | - pbuf, chroma_side, cu_col * chroma_tx, cu_row * chroma_tx, | |
| 17219 | - chroma_tx, chroma_tx, | |
| 17425 | + pbuf, chroma_side, cu_col * chroma_tx, | |
| 17426 | + cu_row * chroma_tx_h, chroma_tx, chroma_tx_h, | |
| 17220 | 17427 | ), |
| 17221 | 17428 | fctx, |
| 17222 | 17429 | ); |
| @@ -17270,10 +17477,13 @@ fn decode_block( | ||
| 17270 | 17477 | // the earlier tiles in this same block already wrote -- the same |
| 17271 | 17478 | // per-TU pattern [`decode_leaf8`] already runs for an 8x8 leaf. |
| 17272 | 17479 | let n_axis = side / logical_tx; |
| 17480 | + // lane-av1-422f: unit width/height per axis, like walk 2 above -- | |
| 17481 | + // a 4:2:2 frame below side 64 reads ONE rect unit per plane per | |
| 17482 | + // chunk, the whole plane block. | |
| 17273 | 17483 | let cn_cols = (chroma_side / chroma_tx).max(1); |
| 17274 | - let cn_rows = (chroma_height / chroma_tx).max(1); | |
| 17484 | + let cn_rows = (chroma_height / chroma_tx_h).max(1); | |
| 17275 | 17485 | let luma_span_x = chroma_tx << ss_x(fctx); |
| 17276 | - let luma_span_y = chroma_tx << ss_y(fctx); | |
| 17486 | + let luma_span_y = chroma_tx_h << ss_y(fctx); | |
| 17277 | 17487 | // libaom's transform-block loop is over 64x64 luma "mu" chunks |
| 17278 | 17488 | // (`decode_token_recon_block`: `mu_blocks_wide/high` = |
| 17279 | 17489 | // `mi_size_wide[BLOCK_64X64]`), and it codes EVERY PLANE of a chunk |
| @@ -17473,22 +17683,38 @@ fn decode_block( | ||
| 17473 | 17683 | (2 * y.true_height.div_ceil(8)) as i32 - mi_r as i32 - span_mi as i32; |
| 17474 | 17684 | let plane_px = ((span_mi * 2).max(4)) as i32; |
| 17475 | 17685 | let max_units_w = ((plane_px + 2 * over_w_mi.min(0)) >> 2).max(0) as usize; |
| 17476 | - let max_units_h = ((plane_px + 2 * over_h_mi.min(0)) >> 2).max(0) as usize; | |
| 17477 | - let unit = chroma_tx / 4; // TU side in 4x4 chroma units | |
| 17478 | - if cu_col * unit >= max_units_w || cu_row * unit >= max_units_h { | |
| 17686 | + // lane-av1-422f: the shared halved formula below the `else` | |
| 17687 | + // counts the plane span in 4-px units through the 2-px-per-mi | |
| 17688 | + // subsampled height, which a 4:2:2 plane does not have (ss_y | |
| 17689 | + // 0) -- its span is the full luma mi count, so a keyed | |
| 17690 | + // formula clips the same units libaom's `max_block_high` | |
| 17691 | + // does. 4:2:0 and 4:4:4 keep the proven shared rows. | |
| 17692 | + let max_units_h = if ss_x(fctx) == 1 && ss_y(fctx) == 0 { | |
| 17693 | + (span_mi as i32 + over_h_mi.min(0)).max(0) as usize | |
| 17694 | + } else { | |
| 17695 | + ((plane_px + 2 * over_h_mi.min(0)) >> 2).max(0) as usize | |
| 17696 | + }; | |
| 17697 | + let (unit_w, unit_h) = (chroma_tx / 4, chroma_tx_h / 4); | |
| 17698 | + if cu_col * unit_w >= max_units_w || cu_row * unit_h >= max_units_h { | |
| 17479 | 17699 | hit!(CHROMA_EDGE_TU_CLIP_HITS); |
| 17480 | 17700 | continue; |
| 17481 | 17701 | } |
| 17482 | 17702 | // The chroma context arrays are indexed in LUMA mi, so this |
| 17483 | 17703 | // unit's anchor is its own luma quadrant (lane-av1-422b: the |
| 17484 | 17704 | // quadrant spans `chroma_tx << ss_x` luma px wide by |
| 17485 | - // `chroma_tx << ss_y` tall -- at 4:2:2 a rect twice as wide | |
| 17486 | - // as it is tall). | |
| 17705 | + // `chroma_tx_h << ss_y` tall -- at 4:2:2 below side 64 the | |
| 17706 | + // one unit's quadrant is the whole block). | |
| 17487 | 17707 | let cu_mi = ( |
| 17488 | 17708 | mi_r + cu_row * (luma_span_y / MI), |
| 17489 | 17709 | mi_c + cu_col * (luma_span_x / MI), |
| 17490 | 17710 | ); |
| 17491 | - let cu_around = neighbours.around_mi_rect(cu_mi, luma_span_x, luma_span_y); | |
| 17711 | + let cu_around = if ss_x(fctx) == 1 && ss_y(fctx) == 0 { | |
| 17712 | + // lane-av1-422f: chroma-only loop; per-chroma-cell above | |
| 17713 | + // votes (see [`Neighbours::around_mi_422_chroma`]). | |
| 17714 | + neighbours.around_mi_422_chroma(cu_mi, luma_span_x, luma_span_y) | |
| 17715 | + } else { | |
| 17716 | + neighbours.around_mi_rect(cu_mi, luma_span_x, luma_span_y) | |
| 17717 | + }; | |
| 17492 | 17718 | let cu_reach = if cn_rows == 1 && cn_cols == 1 { |
| 17493 | 17719 | reach |
| 17494 | 17720 | } else { |
| @@ -17498,28 +17724,44 @@ fn decode_block( | ||
| 17498 | 17724 | reach, px, py, y.width, y.height, fctx, |
| 17499 | 17725 | ) |
| 17500 | 17726 | }; |
| 17501 | - let (cu_x, cu_y) = (cpx + cu_col * chroma_tx, cpy + cu_row * chroma_tx); | |
| 17727 | + let (cu_x, cu_y) = | |
| 17728 | + (cpx + cu_col * chroma_tx, cpy + cu_row * chroma_tx_h); | |
| 17502 | 17729 | if let Some((ub, vb)) = &palette_uv_bufs { |
| 17503 | 17730 | let pbuf = if plane_pass == 1 { ub } else { vb }; |
| 17504 | 17731 | set_palette_pred( |
| 17505 | 17732 | palette_window( |
| 17506 | - pbuf, chroma_side, cu_col * chroma_tx, cu_row * chroma_tx, | |
| 17507 | - chroma_tx, chroma_tx, | |
| 17733 | + pbuf, chroma_side, cu_col * chroma_tx, | |
| 17734 | + cu_row * chroma_tx_h, chroma_tx, chroma_tx_h, | |
| 17508 | 17735 | ), |
| 17509 | 17736 | fctx, |
| 17510 | 17737 | ); |
| 17511 | 17738 | } |
| 17512 | 17739 | let buf: &mut PlaneBuf<'static> = |
| 17513 | 17740 | if plane_pass == 1 { &mut *u } else { &mut *v }; |
| 17514 | - let cu_grid = read_plane( | |
| 17515 | - dec, cdfs, chroma_set, scans.1, plane_pass, cu_around[plane_pass], mode, | |
| 17516 | - uv_predict_mode, angle_delta_uv, cu_reach, buf, cu_x, cu_y, | |
| 17517 | - chroma_tx, chroma_tx, base_q_idx, | |
| 17518 | - alpha.zip(ac).map(|((au, av), ac)| { | |
| 17519 | - (if plane_pass == 1 { au } else { av }, ac) | |
| 17520 | - }), | |
| 17521 | - None, chroma_ctx_offset, smooth_neighbor_uv, fctx, | |
| 17522 | - )?; | |
| 17741 | + let cu_grid = if chroma_tx == chroma_tx_h { | |
| 17742 | + read_plane( | |
| 17743 | + dec, cdfs, chroma_set, scans.1, plane_pass, cu_around[plane_pass], mode, | |
| 17744 | + uv_predict_mode, angle_delta_uv, cu_reach, buf, cu_x, cu_y, | |
| 17745 | + chroma_tx, chroma_tx, base_q_idx, | |
| 17746 | + alpha.zip(ac).map(|((au, av), ac)| { | |
| 17747 | + (if plane_pass == 1 { au } else { av }, ac) | |
| 17748 | + }), | |
| 17749 | + None, chroma_ctx_offset, smooth_neighbor_uv, fctx, | |
| 17750 | + )? | |
| 17751 | + } else { | |
| 17752 | + // lane-av1-422f: the whole plane block as one rect unit; | |
| 17753 | + // `chroma_ctx_offset` is `None` there (the unit covers | |
| 17754 | + // the plane block, so the offset-7 skip rows are right). | |
| 17755 | + read_rect_chroma_unit( | |
| 17756 | + dec, cdfs, chroma_set, scans.1, chroma_tx, chroma_tx_h, plane_pass, | |
| 17757 | + cu_around[plane_pass], uv_predict_mode, angle_delta_uv, cu_reach, buf, | |
| 17758 | + cu_x, cu_y, base_q_idx, | |
| 17759 | + alpha.zip(ac).map(|((au, av), ac)| { | |
| 17760 | + (if plane_pass == 1 { au } else { av }, ac) | |
| 17761 | + }), | |
| 17762 | + smooth_neighbor_uv, fctx, | |
| 17763 | + )? | |
| 17764 | + }; | |
| 17523 | 17765 | if cn_rows * cn_cols > 1 { |
| 17524 | 17766 | hit!(CHROMA_SPLIT_TX_HITS); |
| 17525 | 17767 | if ss_x(fctx) == 1 && ss_y(fctx) == 0 { |
lanes/av1422f.report.mdadded+115 -0
| @@ -0,0 +1,115 @@ | ||
| 1 | +# lane-av1-422f — square-block chroma is the plane block's own rect unit; refusal stays | |
| 2 | + | |
| 3 | +## Outcome | |
| 4 | + | |
| 5 | +STOP with the 4:2:2 header refusal in place, byte-identical (probe refuses | |
| 6 | +without the env; the local bypass was reverted before commit). The | |
| 7 | +square-block path (decode.rs's `(luma_set, chroma_set, luma_tx, chroma_tx, | |
| 8 | +scans)` selection, formerly 16704-16721) now models `av1_get_max_uv_txsize` | |
| 9 | +as `av1_get_adjusted_tx_size(max_txsize_rect_lookup[plane_bsize])` — the RECT | |
| 10 | +that fills the (side/2, side) plane block — and all three chroma walks read | |
| 11 | +one `(chroma_tx, chroma_tx_h)` unit per grid cell, keyed on ss (1,0). The | |
| 12 | +av1422e first miss (mi(4,4) side 16: ours two 8x8 units, oracle one TX_8X16) | |
| 13 | +is gone, and the decode now aligns with the oracle unit-for-unit through 117 | |
| 14 | +coefficient units — every 16x16 block's U/V TX_8X16 pair, every 8x8 leaf's | |
| 15 | +U/V TX_4X8 pair, every 16x8 strip's 8x8-square chroma — with equal entry rngs | |
| 16 | +wherever ours prints them. The stream is not pixel-exact: the next divergence | |
| 17 | +is the sub-8x8 4x4-leaf chroma at 4:2:2 (TX_4X4 units, one per even-column | |
| 18 | +leaf), which lives in `decode_leaf_split4`/`decode_leaf8` — other lanes — so | |
| 19 | +the refusal is retained. | |
| 20 | + | |
| 21 | +## Change (decode.rs + decode_probe.rs only) | |
| 22 | + | |
| 23 | +- Selection arm at ss (1,0): per-axis unit dims `chroma_tx` (width) x | |
| 24 | + `chroma_tx_h` (height) — 4 -> (4,4), 8 -> (4,8), 16 -> (8,16), 32 -> | |
| 25 | + (16,32), 64/128 -> (32,32) — with the unit's TxbSet/scan: | |
| 26 | + `ChromaRect8x4`+`SCAN_4X8`, `ChromaRect16x8`+`SCAN_8X16`, | |
| 27 | + `ChromaRect32x16`+`SCAN_16X32`, `Chroma32`+scan32. The destructure gains | |
| 28 | + `chroma_tx_h`; 4:2:0/4:4:4/lossless arms carry `chroma_tx` twice, so their | |
| 29 | + walks are untouched. | |
| 30 | +- New `read_rect_chroma_unit`: one rect chroma unit via the | |
| 31 | + `read_coeffs_rect` route (the `chroma_tiled` arm's and | |
| 32 | + `leaf8_chroma422_unit`'s proven shape): `txb_skip_ctx` = above+left in the | |
| 33 | + offset-7 rows (the unit covers the plane block exactly, so no +3), the | |
| 34 | + mode-derived default `tx_type` unless `INTRABC_CHROMA_TX` is armed, the | |
| 35 | + `side >= 32` DCT_DCT clamp, `dequant_and_inverse_typed_wh` + | |
| 36 | + `push_intra_rect`. Bumps the new `CHROMA422_RECT_HITS` witness counter | |
| 37 | + (keyed ss (1,0), unit w != h). | |
| 38 | +- New `push_intra_unit`: `push_intra` when square, `push_intra_rect` when | |
| 39 | + rect — used by the skip walk. | |
| 40 | +- All three chroma walks (skip, single-TU, chunked) key on the per-axis | |
| 41 | + unit dims: `cn_rows = chroma_height / chroma_tx_h`, `luma_span_y = | |
| 42 | + chroma_tx_h << ss_y`, per-axis cu positions and palette windows. Below | |
| 43 | + side 64 a 4:2:2 frame's grid is 1x1 and the one unit is the whole plane | |
| 44 | + block. The chunked walk's edge clip computes `max_units_h` per axis at | |
| 45 | + ss (1,0) (the shared halved formula assumes a subsampled height and would | |
| 46 | + clip units libaom codes); the shared rows stay for 4:2:0/4:4:4. | |
| 47 | +- New `Neighbours::around_mi_422_chroma` for the square path's chroma context | |
| 48 | + reads: libaom `get_txb_ctx_general` sums its dc-sign votes over | |
| 49 | + `txb_w_unit` CHROMA 4-px cells, and at ss_x 1 one chroma cell spans TWO | |
| 50 | + luma mi columns — the per-luma-mi sum double-counts the above votes and | |
| 51 | + flips `dc_sign_ctx` when the above and left votes have opposite signs | |
| 52 | + (measured at mi(4,4) plane 1: ours read `dc_sign_cdf[1]`, the oracle row | |
| 53 | + 0). Sampling every second above cell counts each chroma column once, which | |
| 54 | + is exactly libaom's sum; the level booleans are ORs over duplicated cells | |
| 55 | + and cannot change. Used by the single-TU walk's rect branch and both | |
| 56 | + multi-unit loops at ss (1,0) only; 4:2:0/4:4:4 keep `around_mi_rect`. | |
| 57 | +- `examples/decode_probe.rs`: prints `chroma422_rect`. | |
| 58 | + | |
| 59 | +Untouched: `decode_leaf8`, `decode_leaf_split4`, `decode_rect4_16_strip`, | |
| 60 | +`decode_block_128rect`, `decode_rect_split`, the resize header reader, the | |
| 61 | +frame-9 filter path, and refusal_inventory.rs (the refusal string is | |
| 62 | +byte-identical; the gate stays green). | |
| 63 | + | |
| 64 | +## Measurement | |
| 65 | + | |
| 66 | +Fixture `/tmp/t422.obu`, sha256 | |
| 67 | +`d3fa4beeb1309033e4a03f5ae5c431c8fa8386ba1ada088684710423c7938129` (reused by | |
| 68 | +hash, 256x144, 22 frames). Oracle `$HOME/.cache/aom-oracle/build/aomdec` | |
| 69 | +`EC_TRACE=1 EC_TRACE_MODE_STEP=1 EC_TRACE_COEFF=1`; ours `decode_probe` | |
| 70 | +(debug, `gate-counters`, private target dir) with a LOCAL | |
| 71 | +`EC_AV1_ALLOW_422_PROBE` env-gated bypass at the stream.rs refusal — | |
| 72 | +reverted before commit, and the refusal re-proven to fire without the env. | |
| 73 | + | |
| 74 | +- Unit-level: 117 consecutive units with equal ENTRY rngs (rect reads print | |
| 75 | + `entry=`; the first entry mismatch is unit #117), identical unit order and | |
| 76 | + shapes: 16x16 blocks read ONE TX_8X16 per plane (mi(4,4): U entry 44042, | |
| 77 | + all_zero ctx row 2 = libaom ctx 9, post-rng 36040, eob 3 — the av1422e | |
| 78 | + first miss, now exact), 8x8 leaves ONE TX_4X8 per plane, 16x8 strips the | |
| 79 | + 8x8 square, 8x16 strips 4x16. | |
| 80 | +- Symbol-level: the deduplicated rng trajectories match value-for-value | |
| 81 | + through the mi(8,0) leaf's V (ours state 1100), modulo four | |
| 82 | + oracle-instrumentation print gaps (sub-reads libaom's patched print does | |
| 83 | + not emit; the trajectories re-align around each). | |
| 84 | +- Counters: `chroma422_rect: 28`, `chroma422_square: 23` — 28 rect chroma | |
| 85 | + units ran on the 4:2:2 frame (a 4:2:0/4:4:4 frame cannot increment it; the | |
| 86 | + counter reads 0 under the old square model). | |
| 87 | + | |
| 88 | +## First remaining divergence (named next site, with oracle evidence) | |
| 89 | + | |
| 90 | +At the 8x8 sub8 group whose leaves sit at mi(8,10)/(8,11)/(9,10)/(9,11): the | |
| 91 | +oracle's 4x4 LEAVES at even mi columns are chroma references at 4:2:2 and | |
| 92 | +each codes a TX_4X4 chroma unit (mi(9,10) plane 1, 38 steps, after only its | |
| 93 | +own luma) — `ss_size_lookup[BLOCK_4X4][1][0]` is BLOCK_4X4, so the 2x4 plane | |
| 94 | +rounds up and reads as TX_4X4. Ours reads the leaf's second luma TX_4X4 as | |
| 95 | +all-zero where the oracle codes coefficients (oracle 16 steps, ours 1), the | |
| 96 | +first value-level divergence, and everything after is desynced; the run then | |
| 97 | +ends at `decode_rect4_16_strip`'s closed-shape panic (shape-driven, reached | |
| 98 | +by the same partition walk). Both sites live in `decode_leaf_split4` / | |
| 99 | +`decode_leaf8` / `decode_rect4_16_strip` — other lanes. The sub-8x8 4:2:2 | |
| 100 | +model needs the is_chroma_ref rule `!(mi_col & ss_x)` (every even-column | |
| 101 | +leaf, not 4:2:0's single bottom-right leaf) plus the TX_4X4 chroma shape. | |
| 102 | + | |
| 103 | +## State | |
| 104 | + | |
| 105 | +- Refusal `a chroma format of 4:2:2 (subsampling_x != subsampling_y)...` | |
| 106 | + byte-identical (bypass reverted; `git diff` touches only decode.rs and | |
| 107 | + decode_probe.rs; probe refuses without the env). | |
| 108 | +- `cargo check -p ec-av1` (private target dir | |
| 109 | + `$HOME/.cache/cargo-target-av1422f`): 0 warnings. | |
| 110 | +- 420 gates green: `a_real_aomenc_stream_with_a_skipped_8x8_intra_leaf_ | |
| 111 | + whose_tx_split_decodes_pixel_exact` + its 10-bit twin — 2/2 pass (the new | |
| 112 | + arms are unreachable at 420 by their ss condition; `chroma_tx == chroma_tx_h` | |
| 113 | + on every 4:2:0/4:4:4 path). Refusal gate | |
| 114 | + `a_non_420_subsampled_sequence_header_is_refused_by_name` green. | |
| 115 | +- No push. Traces left at /tmp/ours422f.txt and /tmp/oracle422.txt. |