diff --git a/crates/ec-av1/examples/decode_probe.rs b/crates/ec-av1/examples/decode_probe.rs index 2b644c65..20c59892 100644 --- a/crates/ec-av1/examples/decode_probe.rs +++ b/crates/ec-av1/examples/decode_probe.rs @@ -35,6 +35,15 @@ fn main() { println!("rect4_32: horz={h} vert={v} coded={c}"); let (rtu, rsplit, robmc) = ec_av1::stream::rect_inter_tu_counters(); println!("rect_inter: tu={rtu} txsplit={rsplit} obmc_leaf={robmc}"); + // lane-inter16ab r1: the 16x16-level inter AB arms, so a recipe sweep + // can tell "aomenc never picked one" from "it did and we decoded it". + let ab = ec_av1::decode::ab16_inter_hits_by_arm(); + println!( + "inter_ab16: horz_a={} horz_b={} vert_a={} vert_b={}", + ab[0], ab[1], ab[2], ab[3] + ); + let (h4, v4, pairs, sub8) = ec_av1::decode::inter16_rect4_counters(); + println!("inter16_1to4: horz4={h4} vert4={v4} chroma_pairs={pairs} sub8_pieces={sub8}"); let leaf = ec_av1::stream::vartx_rect_leaf_hits(); println!("vartx_rect_leaf: 32x16={} 16x32={}", leaf[0], leaf[1]); let ir = ec_av1::stream::inter_rect_counters(); diff --git a/crates/ec-av1/src/cdf_state.rs b/crates/ec-av1/src/cdf_state.rs index 89334535..27e4bee9 100644 --- a/crates/ec-av1/src/cdf_state.rs +++ b/crates/ec-av1/src/cdf_state.rs @@ -230,6 +230,19 @@ pub(crate) enum TxbSet { /// counterpart: `EXT_TX_SET_DTT4_IDTX_1DDCT`, the seven-symbol `TX_4X4` /// row [`LumaRect4x8Set1`](TxbSet::LumaRect4x8Set1) reads. LumaRect16x4Set1, + /// [`LumaRect16x4`](TxbSet::LumaRect16x4)'s INTER counterpart + /// (lane-inter16ab r2): the same `Luma8` coefficient tables (64 coded + /// positions, `get_txsize_entropy_ctx(TX_16X4)` = TX_8X8), with the + /// INTER `tx_type` table at `txsize_sqr_map[TX_16X4]` = TX_4X4. + /// `av1_get_ext_tx_set_type` (av1/common/idct.c): `tx_size_sqr_up` is + /// TX_16X16 (not > TX_32X32) and `use_reduced_set` picks + /// `EXT_TX_SET_DCT_IDTX` -- three symbols, `inter_tx_type_4`. + LumaRect16x4Inter, + /// [`LumaRect16x4Inter`](TxbSet::LumaRect16x4Inter)'s + /// `reduced_tx_set: false` counterpart: `tx_size_sqr` is TX_4X4, not + /// TX_16X16, so `av1_get_ext_tx_set_type` returns `EXT_TX_SET_ALL16` -- + /// sixteen symbols, `inter_tx_type_4_set1`. + LumaRect16x4Inter1, } /// The tables one transform block is coded with, borrowed from the state for @@ -1864,6 +1877,30 @@ impl Cdfs { tx_type: Some(self.intra_tx_type_4_set1[mode].as_mut_slice()), eob_pt_class1: Some(&mut self.eob_pt_64_luma_class1), }, + TxbSet::LumaRect16x4Inter => TxbTables { + side: 8, + txb_skip: &mut self.txb_skip_luma_8, + eob_pt: &mut self.eob_pt_64_luma, + eob_extra: &mut self.eob_extra_luma_8, + base: &mut self.base_luma_8, + base_eob: &mut self.base_eob_luma_8, + br: &mut self.br_luma_8, + dc_sign: &mut self.dc_sign_luma, + tx_type: Some(self.inter_tx_type_4.as_mut_slice()), + eob_pt_class1: Some(&mut self.eob_pt_64_luma_class1), + }, + TxbSet::LumaRect16x4Inter1 => TxbTables { + side: 8, + txb_skip: &mut self.txb_skip_luma_8, + eob_pt: &mut self.eob_pt_64_luma, + eob_extra: &mut self.eob_extra_luma_8, + base: &mut self.base_luma_8, + base_eob: &mut self.base_eob_luma_8, + br: &mut self.br_luma_8, + dc_sign: &mut self.dc_sign_luma, + tx_type: Some(self.inter_tx_type_4_set1.as_mut_slice()), + eob_pt_class1: Some(&mut self.eob_pt_64_luma_class1), + }, TxbSet::LumaRect16x8Inter => TxbTables { side: 16, txb_skip: &mut self.txb_skip_luma_16, diff --git a/crates/ec-av1/src/decode.rs b/crates/ec-av1/src/decode.rs index 3e8fda0b..1797c599 100644 --- a/crates/ec-av1/src/decode.rs +++ b/crates/ec-av1/src/decode.rs @@ -2232,6 +2232,89 @@ pub(crate) fn rect4_coeff_hits() -> usize { RECT4_COEFF_HITS.with(|c| c.get()) } +// lane-inter16ab r1: how many 16x16-level AB partitions fired IN AN INTER +// frame, per arm, in `PARTITION_HORZ_A`, `_HORZ_B`, `_VERT_A`, `_VERT_B` +// order (the intra-frame counterpart is `AB16_HITS`). Each arm is two 8x8 +// inter leaves (`decode_inter_block8`) plus one true 16x8/8x16 inter strip +// (`decode_inter_block` with `write_w`/`write_h`); the gate asserts every +// arm separately so a run whose RD only picked one cannot pass as proof of +// four. +thread_local! { + static AB16_INTER_HITS: std::cell::Cell<[usize; 4]> = const { std::cell::Cell::new([0; 4]) }; +} + +/// [`AB16_INTER_HITS`] per arm (HORZ_A, HORZ_B, VERT_A, VERT_B at 16x16 in an +/// inter frame). +pub fn ab16_inter_hits_by_arm() -> [usize; 4] { + AB16_INTER_HITS.with(std::cell::Cell::get) +} + +// lane-inter16ab r2: the 16x16-level 1:4 pair as INTER blocks -- four 16x4 +// (`PARTITION_HORZ_4`) or 4x16 (`PARTITION_VERT_4`) strips. `CHROMA_PAIRS` +// counts the odd strips that close a 4:2:0 chroma pair +// (`is_chroma_reference`, av1_common_int.h:1454: bh == 1 mi => odd mi_row), +// `SUB8_PIECES` the pair chroma blocks whose TOP (LEFT) half was built from +// the PREVIOUS strip's own mv/ref/filters -- libaom +// `build_inter_predictors_sub8x8` (reconinter_template.inc:87-160), reached +// through `is_sub8x8_inter` (same file, :54). +thread_local! { + static INTER16_HORZ4_HITS: std::cell::Cell = const { std::cell::Cell::new(0) }; + static INTER16_VERT4_HITS: std::cell::Cell = const { std::cell::Cell::new(0) }; + static INTER16_CHROMA_PAIR_HITS: std::cell::Cell = const { std::cell::Cell::new(0) }; + static INTER16_SUB8_PIECE_HITS: std::cell::Cell = const { std::cell::Cell::new(0) }; +} + +/// Current values of the inter 16x16-level 1:4 counters: `(16x4 strips, 4x16 +/// strips, chroma pairs closed, chroma pairs built from two different +/// strips' motion vectors)`. +pub fn inter16_rect4_counters() -> (usize, usize, usize, usize) { + ( + INTER16_HORZ4_HITS.with(std::cell::Cell::get), + INTER16_VERT4_HITS.with(std::cell::Cell::get), + INTER16_CHROMA_PAIR_HITS.with(std::cell::Cell::get), + INTER16_SUB8_PIECE_HITS.with(std::cell::Cell::get), + ) +} + +/// One 16x4 / 4x16 inter strip's chroma situation, handed to +/// [`decode_inter_block`] out of band (the same one-shot thread-local idiom +/// `REDUCED_TX_SET_INTER` uses) rather than through twenty-three call sites +/// that all mean "an ordinary block, chroma of its own". +#[derive(Clone, Copy)] +struct InterStripChroma { + /// `is_chroma_reference` for this strip: false on strips 0 and 2, which + /// read and reconstruct NO chroma at all. + has_chroma: bool, + /// `PARTITION_HORZ_4` (16x4 strips) rather than `PARTITION_VERT_4`. + horz: bool, + /// The mi position of the EVEN strip of this pair -- `setup_pred_plane`'s + /// `if (ss_y && (mi_row & 1) && mi_size_high[bsize] == 1) mi_row -= 1`, + /// i.e. the origin of the 8x4 (4x8) chroma transform. + pair_mi: (usize, usize), + /// The previous (even) strip's single-reference MC parameters, `None` + /// when it was intra or compound -- `is_sub8x8_inter` then returns false + /// and the whole chroma block is predicted from THIS strip's mv. + prev: Option<(i8, (i32, i32), mc::InterpFilterKind, mc::InterpFilterKind)>, +} + +thread_local! { + static INTER_STRIP_CHROMA: std::cell::Cell> = + const { std::cell::Cell::new(None) }; + /// The single-reference MC parameters of the inter block that decoded + /// last -- read by the next 1:4 strip to build its pair's chroma. + static INTER_LAST_MC: std::cell::Cell< + Option<(i8, (i32, i32), mc::InterpFilterKind, mc::InterpFilterKind)>, + > = const { std::cell::Cell::new(None) }; +} + +fn bump_ab16_inter(arm: usize) { + AB16_INTER_HITS.with(|c| { + let mut v = c.get(); + v[arm] += 1; + c.set(v); + }); +} + // lane-r14: the 16x16-level 1:4 pair -- four 16x4 (`PARTITION_HORZ_4`) or // 4x16 (`PARTITION_VERT_4`) strips, `CHROMA` counting the odd strips that // close a 4:2:0 chroma pair and `COEFF` the strips with a coded residual. @@ -11808,6 +11891,10 @@ fn rect_inter_residual_supported(w: usize, h: usize) -> bool { (w, h), // 2:1 strips whose transform is coded in full (lane-inter4). (32, 16) | (16, 32) | (16, 8) | (8, 16) + // lane-inter16ab r2: the 16x16-level 1:4 strips. TX_16X4/TX_4X16 + // codes all 64 of its positions, and its chroma pair is an 8x4 / + // 4x8 unit (`ss_size_lookup[BLOCK_16X4]` = BLOCK_8X4). + | (16, 4) | (4, 16) // lane-r14 r2: strips with a 64-px axis. `av1_get_max_eob` codes // only the low 32 coefficients of a 64-length axis, so these read // exactly the truncated corner the INTRA superblock-strip path @@ -11830,6 +11917,13 @@ fn rect_inter_residual_supported(w: usize, h: usize) -> bool { fn rect_inter_luma_set(w: usize, h: usize) -> TxbSet { match (w, h) { (32, 16) | (16, 32) => TxbSet::LumaRect32x16Inter, + (16, 4) | (4, 16) => { + if REDUCED_TX_SET_INTER.with(std::cell::Cell::get) { + TxbSet::LumaRect16x4Inter + } else { + TxbSet::LumaRect16x4Inter1 + } + } (16, 8) | (8, 16) => { if REDUCED_TX_SET_INTER.with(std::cell::Cell::get) { TxbSet::LumaRect16x8Inter @@ -11906,6 +12000,8 @@ fn rect_scan(w: usize, h: usize) -> &'static [u16] { (16, 32) => &SCAN_16X32, (16, 8) => &SCAN_16X8, (8, 16) => &SCAN_8X16, + (16, 4) => &SCAN_16X4, + (4, 16) => &SCAN_4X16, (8, 4) => &SCAN_8X4, (4, 8) => &SCAN_4X8, (32, 8) => &SCAN_32X8, @@ -16097,6 +16193,54 @@ fn is_any_masked_compound_used_here(side: usize) -> bool { side.min(side) >= 8 } +/// The `BLOCK_SIZES_ALL` index of a `bw x bh` block (libaom `enum BLOCK_SIZE`, +/// `blockd.h`) -- the row every size-indexed inter CDF table +/// (`compound_type_cdf`, `wedge_idx_cdf`) is keyed by. Our `decode_inter_block` +/// carries the enclosing SQUARE `side` for context purposes (the accepted +/// strip corner-cut), so a 16x8 / 8x16 PARTITION_HORZ/VERT strip that reads +/// one of those symbols off `side` alone takes BLOCK_16X16's row and desyncs +/// (lane-inter16ab r3: a real 16x8 compound strip with `comp_group_idx == 1`, +/// decode-order frame 5, our range 64901 vs the oracle's 47271 at the very +/// next block's mode read). +fn bsize_all_index(bw: usize, bh: usize) -> Option { + Some(match (bw, bh) { + (4, 4) => 0, + (4, 8) => 1, + (8, 4) => 2, + (8, 8) => 3, + (8, 16) => 4, + (16, 8) => 5, + (16, 16) => 6, + (16, 32) => 7, + (32, 16) => 8, + (32, 32) => 9, + (32, 64) => 10, + (64, 32) => 11, + (64, 64) => 12, + (64, 128) => 13, + (128, 64) => 14, + (128, 128) => 15, + (4, 16) => 16, + (16, 4) => 17, + (8, 32) => 18, + (32, 8) => 19, + (16, 64) => 20, + (64, 16) => 21, + _ => return None, + }) +} + +/// `av1_wedge_params_lookup[bsize].wedge_types > 0` (libaom `reconinter.c`): +/// the block sizes that carry a wedge codebook at all. A `compound_type` +/// symbol is written only for these; every other size infers +/// `COMPOUND_DIFFWTD`. +fn wedge_used_bsize(bw: usize, bh: usize) -> bool { + matches!( + (bw, bh), + (8, 8) | (8, 16) | (16, 8) | (16, 16) | (16, 32) | (32, 16) | (32, 32) | (8, 32) | (32, 8) + ) +} + /// Whether a compound reference pair is unidirectional (both references on /// the same temporal side of the current frame) -- `has_uni_comp_refs` /// (libaom `av1_reference_frame_utils.h`/`pred_common.c`'s own definition: @@ -16546,9 +16690,27 @@ fn decode_inter_block( // exactly what it read before. let (rmi, cmi) = at; let (px, py) = (at.1 * MI, at.0 * MI); - let (cpx, cpy) = (px / 2, py / 2); + // lane-inter16ab r2: a 16x4 / 4x16 inter strip's chroma is the PAIR's + // (8x4 / 4x8 at the even strip's origin) and is coded only by the odd + // strip (`is_chroma_reference`); every other block keeps its own. + let strip_chroma = INTER_STRIP_CHROMA.with(std::cell::Cell::take); + INTER_LAST_MC.with(|c| c.set(None)); + let has_chroma = strip_chroma.is_none_or(|s| s.has_chroma); + let (cpx, cpy) = match strip_chroma { + Some(s) if s.has_chroma => (s.pair_mi.1 * MI / 2, s.pair_mi.0 * MI / 2), + _ => (px / 2, py / 2), + }; let chroma_side = side / 2; - let (write_chroma_w, write_chroma_h) = (write_w / 2, write_h / 2); + let (write_chroma_w, write_chroma_h) = match strip_chroma { + Some(s) if s.has_chroma => { + if s.horz { + (8, 4) + } else { + (4, 8) + } + } + _ => (write_w / 2, write_h / 2), + }; if std::env::var_os("EC_AV1_TELL").is_some() { eprintln!( @@ -16572,7 +16734,12 @@ fn decode_inter_block( let (seg_mi_r, seg_mi_c) = (rmi, cmi); let (seg_w_mi, seg_h_mi) = (write_w / 4, write_h / 4); inter_segment_id(dec, cdfs, seg_mi_r, seg_mi_c, seg_w_mi, seg_h_mi, false, true); - let skip_mode = skip_mode_present && dec.symbol(&mut cdfs.skip_mode[skip_mode_ctx]) == 1; + // libaom `read_skip_mode` (decodemv.c): `if (!is_comp_ref_allowed(bsize)) + // return 0` -- a 16x4 / 4x16 strip (min(bw, bh) == 4, blockd.h:65) reads + // no `skip_mode` symbol at all. + let comp_allowed = write_w.min(write_h) >= 8; + let skip_mode = + skip_mode_present && comp_allowed && dec.symbol(&mut cdfs.skip_mode[skip_mode_ctx]) == 1; if std::env::var_os("EC_AV1_SKIPMODE_DUMP").is_some() { eprintln!( "EC_SKIPMODE r={r} c={c} result={skip_mode} tell_after={}", @@ -16684,7 +16851,12 @@ fn decode_inter_block( ); } let is_compound = - skip_mode || (reference_select && read_comp_mode(dec, cdfs, above_nbr, left_nbr)); + skip_mode + || (reference_select + // `is_comp_ref_allowed` (blockd.h:65) gates the + // `comp_mode` read exactly as it gates `skip_mode`. + && comp_allowed + && read_comp_mode(dec, cdfs, above_nbr, left_nbr)); if is_compound { let (ref0, ref1) = if skip_mode { (skip_mode_frame[0] as i8, skip_mode_frame[1] as i8) @@ -16913,16 +17085,23 @@ fn decode_inter_block( // writes NO `compound_type` symbol there and INFERS // `COMPOUND_DIFFWTD` -- only the 1-bit `mask_type` literal // follows. `None` here is exactly that inferred arm. - let wedge_bsize = match side { - 8 => Some(3), - 16 => Some(6), - 32 => Some(9), - _ => None, - }; + // lane-inter16ab r3: the row is this block's TRUE + // `BLOCK_SIZES_ALL` index, not the enclosing square `side`'s + // -- a 16x8 strip reads `compound_type_cdf[BLOCK_16X8]`. + let wedge_bsize = + bsize_all_index(write_w, write_h).filter(|_| wedge_used_bsize(write_w, write_h)); let compound_type = match wedge_bsize { Some(b) => dec.symbol(&mut cdfs.compound_type[b]), None => 1, }; + if wedge_bsize.is_some() && compound_type == 0 && write_w != write_h { + // The wedge mask codebook (`wedge.rs`) is built for the + // square sizes only; a rect wedge block is refused by + // name rather than blended with the wrong mask. + return Err(unsupported( + "a COMPOUND_WEDGE mask on a rectangular inter block (the wedge codebook is square-only)", + )); + } if let Some(wedge_bsize) = wedge_bsize.filter(|_| compound_type == 0) { // COMPOUND_WEDGE: lane-wedge r3, codebook checksum- // verified vs independent C dump (wedge.rs). @@ -17922,8 +18101,19 @@ fn decode_inter_block( // `enable_interintra_wedge` seq bit -- the wedge flag // (`av1_is_wedge_used(bsize)` holds for 16x16/32x32). let ii = dec.symbol(&mut cdfs.interintra_mode[bsize_group]) as u8; - let wedge_bsize = if side == 16 { 6 } else { 9 }; + // lane-inter16ab r3 (same class as the compound + // `compound_type` row below): the row is the block's TRUE + // `BLOCK_SIZES_ALL` index -- a 16x8 / 32x16 interintra + // strip is BLOCK_16X8 / BLOCK_32X16, not its square + // `side`'s BLOCK_16X16 / BLOCK_32X32. + let wedge_bsize = bsize_all_index(write_w, write_h) + .expect("interintra shape is a BLOCK_SIZES_ALL size"); let wedge = dec.symbol(&mut cdfs.wedge_interintra[wedge_bsize]) == 1; + if wedge && write_w != write_h { + return Err(unsupported( + "a wedge interintra mask on a rectangular inter block (the wedge codebook is square-only)", + )); + } if wedge { // lane-wii r2 (spec 5.11.25): `wedge_index` is an // ADAPTING CDF symbol over the same `wedge_bsize` row; @@ -17975,6 +18165,9 @@ fn decode_inter_block( // motion_mode symbol is NOT read (SIMPLE_TRANSLATION implied). let motion_mode_eligible = switchable_motion_mode && !skip_mode + // `is_motion_variation_allowed_bsize` (blockd.h:1455): + // min(bw, bh) >= 8, false for a 16x4 / 4x16 strip. + && write_w.min(write_h) >= 8 && interintra_mode.is_none() && (!overlappable_above(grid, mi_row, mi_col, bw4, mi_cols as usize, 1).is_empty() || !overlappable_left(grid, mi_row, mi_col, bh4, mi_rows as usize, 1) @@ -18283,6 +18476,11 @@ fn decode_inter_block( } } + // lane-inter16ab r2: `is_sub8x8_inter`'s neighbour walk reads the + // PREVIOUS strip's `mv`/`ref_frame`/`interp_filters` + // (reconinter_template.inc:75-82); record them for the next 1:4 + // strip, which is the only reader. + INTER_LAST_MC.with(|c| c.set(Some((ref_frame, mv, h_filter, v_filter)))); let mut pred_y = vec![0u16; side * side]; let mut pred_u = vec![0u16; chroma_side * chroma_side]; let mut pred_v = vec![0u16; chroma_side * chroma_side]; @@ -18444,6 +18642,46 @@ fn decode_inter_block( interintra_blend(v, cpx, cpy, chroma_side, ii, wedge_mask, &mut pred_v); } + // lane-inter16ab r2: libaom `build_inter_predictors_sub8x8` + // (reconinter_template.inc:87-160). A 4:2:0 chroma block under a + // 16x4 (4x16) luma pair covers TWO luma blocks, so it is built in + // `b4_w x b4_h` = 8x2 (2x8) pieces, each from its own strip's + // mv/ref/filters. The bottom (right) piece is this strip's own mv + // over its own rows, which the whole-block prediction above + // already wrote there (MC is position-invariant for a fixed mv), + // so only the FIRST piece has to be rebuilt -- and only when + // `is_sub8x8_inter` holds, i.e. the previous strip was itself a + // single-reference inter block (`prev`), else libaom falls + // through to the ordinary whole-block predictor. + if let Some(s) = strip_chroma.filter(|s| s.has_chroma) + && let Some((prev_ref, prev_mv, prev_h, prev_v)) = s.prev + && luma_scale == mc::REF_NO_SCALE + { + let (piece_w, piece_h) = if s.horz { (8usize, 2usize) } else { (2usize, 8usize) }; + let (_, prev_u, prev_v_plane) = ref_planes(prev_ref, ref_y, ref_u, ref_v, other_refs)?; + for (src, dst) in [(prev_u, &mut pred_u), (prev_v_plane, &mut pred_v)] { + let mut piece = vec![0u16; piece_w * piece_h]; + mc::predict_with_filters( + &src.data, + src.width, + src.true_width, + src.true_height, + mv_to_q4(cpx, prev_mv.1, false), + mv_to_q4(cpy, prev_mv.0, false), + piece_w, + piece_h, + prev_h, + prev_v, + &mut piece, + ); + for row in 0..piece_h { + dst[row * chroma_side..row * chroma_side + piece_w] + .copy_from_slice(&piece[row * piece_w..(row + 1) * piece_w]); + } + } + INTER16_SUB8_PIECE_HITS.with(|c| c.set(c.get() + 1)); + } + // lane-inter4 r2: a rectangular strip's transform tree starts from // its own rect `max_txsize_rect_lookup` entry, not a square one. let rect_tu = (write_w, write_h) != (side, side); @@ -18480,24 +18718,26 @@ fn decode_inter_block( &pred_y, &vec![0i32; side * side], ); - u.reconstruct_mc_rect( - cpx, - cpy, - chroma_side, - write_chroma_w, - write_chroma_h, - &pred_u, - &vec![0i32; chroma_side * chroma_side], - ); - v.reconstruct_mc_rect( - cpx, - cpy, - chroma_side, - write_chroma_w, - write_chroma_h, - &pred_v, - &vec![0i32; chroma_side * chroma_side], - ); + if has_chroma { + u.reconstruct_mc_rect( + cpx, + cpy, + chroma_side, + write_chroma_w, + write_chroma_h, + &pred_u, + &vec![0i32; chroma_side * chroma_side], + ); + v.reconstruct_mc_rect( + cpx, + cpy, + chroma_side, + write_chroma_w, + write_chroma_h, + &pred_v, + &vec![0i32; chroma_side * chroma_side], + ); + } luma_grid = vec![0i32; side * side]; u_grid = vec![0i32; chroma_side * chroma_side]; v_grid = vec![0i32; chroma_side * chroma_side]; @@ -18510,6 +18750,18 @@ fn decode_inter_block( } else { neighbours.around_mi(at, side) }; + // lane-inter16ab r2: the pair's chroma transform sits at the + // EVEN strip's mi origin and spans both strips, so its + // above/left coefficient context is the pair's, not this + // strip's row. + let around_c = match strip_chroma { + Some(s) if s.has_chroma => neighbours.around_mi_rect( + s.pair_mi, + if s.horz { 16 } else { 8 }, + if s.horz { 8 } else { 16 }, + ), + _ => around, + }; let luma_tx_type; if let Some(leaves) = vartx_leaves.clone() { // spec 5.11.17's transform tree, leaf by leaf in the order @@ -18627,7 +18879,16 @@ fn decode_inter_block( None, )?; } - if rect_tu { + if !has_chroma { + // `is_chroma_reference` is false for this strip: libaom's + // plane loop (decodeframe.c + // `predict_and_reconstruct_intra_block`/ + // `reconstruct_inter_block`'s `for (plane...)` guarded by + // `xd->is_chroma_ref`) codes NO chroma transform here, so + // neither symbol nor context exists. + u_grid = vec![0i32; chroma_side * chroma_side]; + v_grid = vec![0i32; chroma_side * chroma_side]; + } else if rect_tu { // `av1_get_max_uv_txsize(bsize)`: the chroma transform of a // 2:1 strip is the strip's own rect chroma size (16x8 / // 8x16), one unit for the whole block, and it codes no @@ -18641,7 +18902,7 @@ fn decode_inter_block( (uw, uh), chroma_side, 1, - around[1], + around_c[1], mode_for_tx, u, cpx, @@ -18663,7 +18924,7 @@ fn decode_inter_block( (uw, uh), chroma_side, 2, - around[2], + around_c[2], mode_for_tx, v, cpx, @@ -18724,6 +18985,16 @@ fn decode_inter_block( // skip path above (which only needed a clipped write of an // already-square-predicted buffer). Named refusal instead of a // silently wrong square-shaped intra prediction. + // lane-inter16ab r2: `decode_intra_rect_in_inter` has no chroma-pair + // path (it predicts and codes chroma at the strip's own halved + // footprint), so an INTRA 16x4 / 4x16 strip inside a 1:4 partition is + // refused by name rather than decoded with a 8x2 chroma transform + // libaom never coded. + if write_w.min(write_h) < 8 { + return Err(unsupported( + "an intra 16x4/4x16 strip inside an inter 16x16-level 1:4 partition (its 4:2:0 chroma pair is coded once for two strips; only the inter path implements that pairing)", + )); + } if write_w != side || write_h != side { // lane-intrarect r1: the strip decodes through its own rect // machinery ([`decode_intra_rect_in_inter`] -> the key-frame @@ -19140,6 +19411,14 @@ fn decode_inter_block( rmi, cmi, dec.debug_bitpos(), dec.debug_state().0 ); } + // lane-inter16ab r2: the pair's chroma coefficient context spans BOTH + // strips (mirroring the intra `decode_rect4_16` path), and the even + // strip's own record wrote empty chroma state over those cells -- this + // rewrite is what libaom's single `av1_set_contexts` call for the 8x4 + // (4x8) chroma unit leaves behind. + let pair_chroma = strip_chroma + .filter(|s| s.has_chroma) + .map(|s| (s, neighbour_state(&u_grid), neighbour_state(&v_grid))); if vartx_leaves.is_some() { // Plane 0 is already correct per transform unit // ([`Neighbours::record_mi_luma`] above); this writes everything else @@ -19156,6 +19435,32 @@ fn decode_inter_block( &[luma_grid, u_grid, v_grid], ); } + if let Some((s, u_state, v_state)) = pair_chroma { + let (pw, ph) = if s.horz { (16usize, 8usize) } else { (8, 16) }; + let round_up_even = |n: usize| n.div_ceil(2) * 2; + let (bound_h, bound_w) = ( + round_up_even(neighbours.mi_rows), + round_up_even(neighbours.mi_cols), + ); + for cell in 0..(ph / MI) { + if s.pair_mi.0 + cell < bound_h + && let Some(slot) = neighbours.left.get_mut(s.pair_mi.0 + cell) + { + slot[1] = u_state; + slot[2] = v_state; + } + } + for cell in 0..(pw / MI) { + if s.pair_mi.1 + cell < bound_w + && let Some(slot) = neighbours.above.get_mut(s.pair_mi.1 + cell) + { + slot[1] = u_state; + slot[2] = v_state; + } + } + neighbours.record_uv_mode_mi(s.pair_mi.0, s.pair_mi.1, pw / MI, ph / MI, uv_predict_mode); + INTER16_CHROMA_PAIR_HITS.with(|c| c.set(c.get() + 1)); + } neighbours.record_inter_rect_mi( at, write_w / MI, @@ -21256,6 +21561,83 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( )? }; } + // lane-inter16ab r1: one 8x8 inter leaf of a 16x16-level AB + // partition (libaom `decode_partition` PARTITION_HORZ_A/_B/ + // VERT_A/_B at BLOCK_16X16 code `bsize2` = BLOCK_8X8 for two of + // their three pieces, decodeframe.c ~1900). Same body the + // PARTITION_SPLIT arm runs per leaf, minus its own partition + // symbol (an AB piece carries none) and its `prev_leaves` + // bookkeeping. + macro_rules! inter_leaf8 { + ($outer:expr, $leaf:expr) => {{ + let leaf_mi = $leaf; + let ( + skip, + is_inter, + skip_mode_leaf, + compound_ctx8, + leaf_filter, + leaf_refs, + ) = decode_inter_block8( + &mut dec, + &mut cdfs, + &mut neighbours, + &mut grid, + mi_cols, + mi_rows, + $outer, + leaf_mi, + &mut y, + &mut u, + &mut v, + &ref_y, + &ref_u, + &ref_v, + &ref_slots, + base_q_idx, + &scan8, + &scan4, + allow_high_precision_mv, + force_integer_mv, + &global_motion, + enable_dual_filter, + reference_select, + enable_masked_compound, + enable_interintra_compound, + enable_jnt_comp, + order_hint_bits, + order_hint, + ref_order_hints, + skip_mode_present, + skip_mode_frame, + reduced_tx_set, + interp_fixed, + switchable_motion_mode, + allow_warped_motion, + allow_screen_content_tools, + &sign_bias_table, + tpl_frame.as_ref(), + frame_width as usize, + )?; + neighbours.record_inter_rect_mi( + leaf_mi, + 2, + 2, + skip, + is_inter, + leaf_refs.0, + leaf_filter, + skip_mode_leaf, + ); + if let Some(ref1) = leaf_refs.1 + && let Some((_, _, group_idx, idx)) = compound_ctx8 + { + neighbours.record_compound_ctx_rect_mi( + leaf_mi, 2, 2, ref1, group_idx, idx, + ); + } + }}; + } let sb_ctx = neighbours.partition_ctx(sb_at, SB); let (has_cols, has_rows) = ( sb_c * SB_MI + SB_MI / 2 < mi_cols, @@ -21739,9 +22121,191 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( frame_width as usize, )?; } + } else if (PARTITION_HORZ_A..=PARTITION_VERT_B).contains(&part16) { + // lane-inter16ab r1: the four AB (T-shaped) + // partitions at the 16x16 level of an INTER + // frame -- two 8x8 inter leaves plus one true + // 16x8/8x16 inter strip. libaom + // `decode_partition` (decodeframe.c ~5040, + // `bsize2 = get_partition_subsize(bsize, + // PARTITION_SPLIT)` = BLOCK_8X8 here) visits: + // HORZ_A: TL 8x8, TR 8x8, bottom 16x8 + // HORZ_B: top 16x8, BL 8x8, BR 8x8 + // VERT_A: TL 8x8, BL 8x8, right 8x16 + // VERT_B: left 8x16, TR 8x8, BR 8x8 + // Every piece is inside the frame by + // construction: an AB value can only be read + // from the (has_cols16 && has_rows16) branch + // above, i.e. mi_row+2 < mi_rows and + // mi_col+2 < mi_cols, which is exactly + // libaom's own `has_rows`/`has_cols`. + // + // VERT_A/VERT_B visit TL,BL,TR,BR, so a + // bottom-left square's top-right neighbour is + // the partition's own not-yet-decoded + // rectangle: libaom switches those squares + // onto `has_tr_vert_*`/`has_bl_vert_*` + // (`reconintra.c get_has_tr_table`) -- + // `Reach::vert_ab_partition()`, the same + // guard the intra 16-level arm and the + // 32-level inter AB arms take (class + // `visit-order-changes-availability`). + // + // OBMC/warp and compound stay legal here: + // every piece is >= 8x8, so libaom's + // `is_motion_variation_allowed_bsize` + // (min(bw,bh) >= 8, blockd.h) and + // `is_comp_ref_allowed` (block_size_wide + + // block_size_high >= 16, blockd.h) both hold + // and the leaf/strip decoders' own gates + // apply unchanged. + bump_ab16_inter(part16 - PARTITION_HORZ_A); + let _vert_guard = if part16 == PARTITION_VERT_A + || part16 == PARTITION_VERT_B + { + Some(crate::encode::Reach::vert_ab_partition()) + } else { + None + }; + let (mi_row0, mi_col0) = sub16_to_mi(at16); + let tl = (mi_row0, mi_col0); + let tr = (mi_row0, mi_col0 + 2); + let bl = (mi_row0 + 2, mi_col0); + let br = (mi_row0 + 2, mi_col0 + 2); + macro_rules! ab_strip16 { + ($mi:expr, $ww:expr, $wh:expr) => { + inter_piece!( + $mi, + SUB, + TxbSet::Luma16, + if reduced_tx_set { + TxbSet::Luma16Inter + } else { + TxbSet::Luma16InterSet1 + }, + TxbSet::Chroma8, + TX16, + TX8, + &scan16, + &scan8, + 1, + $ww, + $wh + ) + }; + } + match part16 { + PARTITION_HORZ_A => { + inter_leaf8!(at16, tl); + inter_leaf8!(at16, tr); + ab_strip16!(bl, 16, 8); + } + PARTITION_HORZ_B => { + ab_strip16!(tl, 16, 8); + inter_leaf8!(at16, bl); + inter_leaf8!(at16, br); + } + PARTITION_VERT_A => { + inter_leaf8!(at16, tl); + inter_leaf8!(at16, bl); + ab_strip16!(tr, 8, 16); + } + _ => { + ab_strip16!(tl, 8, 16); + inter_leaf8!(at16, tr); + inter_leaf8!(at16, br); + } + } + } else if part16 == PARTITION_HORZ_4 + || part16 == PARTITION_VERT_4 + { + // lane-inter16ab r2: four 16x4 (4x16) INTER + // strips. libaom `decode_partition` + // (decodeframe.c, PARTITION_HORZ_4/VERT_4) + // walks them top to bottom (left to right) + // with its own `i > 0` frame-edge break. + // + // Each strip is >= 8 in one dimension only, + // so `is_comp_ref_allowed`, + // `is_motion_variation_allowed_bsize` + // (blockd.h:65/1455, min(bw, bh) >= 8) and + // `is_interintra_allowed_bsize` (BLOCK_8X8.. + // BLOCK_32X32 in enum order, which excludes + // BLOCK_16X4 = 17) are all false: no + // skip_mode, no comp_mode, no OBMC/warp and + // no interintra symbol is read -- gated in + // `decode_inter_block` off `write_w`/ + // `write_h`. + // + // CHROMA is the pair's: + // `is_chroma_reference` + // (av1_common_int.h:1454) is false on the + // even strips, and the odd one codes one 8x4 + // (4x8) chroma transform at the pair's + // origin, built from BOTH strips' motion + // (`is_sub8x8_inter`). + let horz = part16 == PARTITION_HORZ_4; + let (mi_row0, mi_col0) = sub16_to_mi(at16); + let (bw, bh) = if horz { (16usize, 4usize) } else { (4usize, 16usize) }; + for i in 0..4usize { + let at_mi = if horz { + (mi_row0 + i, mi_col0) + } else { + (mi_row0, mi_col0 + i) + }; + if i > 0 + && (at_mi.0 >= mi_rows as usize + || at_mi.1 >= mi_cols as usize) + { + break; + } + let strip_has_chroma = i % 2 == 1; + let pair_mi = if !strip_has_chroma { + at_mi + } else if horz { + (at_mi.0 - 1, at_mi.1) + } else { + (at_mi.0, at_mi.1 - 1) + }; + INTER_STRIP_CHROMA.with(|c| { + c.set(Some(InterStripChroma { + has_chroma: strip_has_chroma, + horz, + pair_mi, + prev: if strip_has_chroma { + INTER_LAST_MC.with(std::cell::Cell::get) + } else { + None + }, + })) + }); + inter_piece!( + at_mi, + SUB, + TxbSet::Luma16, + if reduced_tx_set { + TxbSet::Luma16Inter + } else { + TxbSet::Luma16InterSet1 + }, + TxbSet::Chroma8, + TX16, + TX8, + &scan16, + &scan8, + 1, + bw, + bh + ); + if horz { + INTER16_HORZ4_HITS.with(|c| c.set(c.get() + 1)); + } else { + INTER16_VERT4_HITS.with(|c| c.set(c.get() + 1)); + } + } } else if part16 != PARTITION_SPLIT { return Err(unsupported( - "an inter 16x16-level AB or 1:4 partition (HORZ_A/HORZ_B/VERT_A/VERT_B/HORZ_4/VERT_4; this decoder's inter path codes a 16x16 as NONE, HORZ, VERT or SPLIT)", + "an inter 16x16-level partition value outside NONE/HORZ/VERT/SPLIT/AB/1:4", )); } else { if has_cols16 && has_rows16 { diff --git a/crates/ec-av1/src/refusal_inventory.rs b/crates/ec-av1/src/refusal_inventory.rs index b99a91e8..b4406b5c 100644 --- a/crates/ec-av1/src/refusal_inventory.rs +++ b/crates/ec-av1/src/refusal_inventory.rs @@ -68,7 +68,21 @@ const REFUSALS: &[&str] = &[ "an 8x8 intra leaf in an inter frame whose tx_depth splits it into 4x4 transform units", "an inter frame with no key frame before it", "an inter SB-level AB partition (HORZ_A/HORZ_B/VERT_A/VERT_B; this decoder's inter tile path codes a superblock as NONE, SPLIT, HORZ, VERT, HORZ_4 or VERT_4)", - "an inter 16x16-level AB or 1:4 partition (HORZ_A/HORZ_B/VERT_A/VERT_B/HORZ_4/VERT_4; this decoder's inter path codes a 16x16 as NONE, HORZ, VERT or SPLIT)", + // lane-inter16ab r1 lifted the AB half and r2 the 1:4 half (four 16x4 / + // 4x16 inter strips, their 8x4/4x8 chroma pair built from BOTH strips' + // motion vectors -- gate + // `a_real_aomenc_inter_sequence_with_16x16_level_1to4_partitions_decodes_pixel_exact`). + // Two narrower refusals are what is left of that shape: + "an inter 16x16-level partition value outside NONE/HORZ/VERT/SPLIT/AB/1:4", + // r2 residue: `vartx_leaves` is a list of SQUARE units, and + // `sub_tx_size_map[TX_16X4]` is the rectangular TX_8X4 -- the split tree + // and its per-unit residual reader both need rect leaves. + "a COMPOUND_WEDGE mask on a rectangular inter block (the wedge codebook is square-only)", + "a wedge interintra mask on a rectangular inter block (the wedge codebook is square-only)", + // r2 residue: `decode_intra_rect_in_inter` codes chroma at the strip's own + // halved footprint, which for a 16x4 strip is an 8x2 transform libaom + // never wrote (its chroma is the PAIR's 8x4, coded by the odd strip). + "an intra 16x4/4x16 strip inside an inter 16x16-level 1:4 partition (its 4:2:0 chroma pair is coded once for two strips; only the inter path implements that pairing)", "an intra mode this decoder does not code (round 2)", // lane-intrarect r1 lifted the whole-shape refusal that stood here (the // inter path's intra arm now routes 2:1 strips through `decode_rect_split`); diff --git a/crates/ec-av1/src/stream.rs b/crates/ec-av1/src/stream.rs index dcbafbcd..a00bbbfa 100644 --- a/crates/ec-av1/src/stream.rs +++ b/crates/ec-av1/src/stream.rs @@ -8409,6 +8409,469 @@ mod tests { } + #[test] + // lane-inter16ab r1: the 16x16-level AB partitions on an INTER frame -- + // PARTITION_HORZ_A/_HORZ_B/_VERT_A/_VERT_B at 16x16, i.e. two 8x8 inter + // leaves plus one true 16x8/8x16 inter strip. Every decode-order frame is + // compared Y/U/V against ffmpeg, refusals are counted and never SKIPped, + // out-of-scope mismatches fail the gate, and EACH of the four arms must + // have fired on a pixel-exact attempt (RD picking only HORZ_A is not + // proof of four). `--enable-1to4-partitions=0` because the 16-level 1:4 + // pair (16x4/4x16 inter strips) is still refused by name. + fn a_real_aomenc_inter_sequence_with_16x16_level_ab_partitions_decodes_pixel_exact() { + const NAME: &str = + "a_real_aomenc_inter_sequence_with_16x16_level_ab_partitions_decodes_pixel_exact"; + let _gate_lock = lock_gate_counters(); + if !have_ffmpeg() { + eprintln!("SKIP {NAME}: no ffmpeg"); + return; + } + if !have_aomenc() { + eprintln!("SKIP {NAME}: no aomenc at {}", aomenc_path().display()); + return; + } + let (width, height, frame_count) = (192usize, 128usize, 6usize); + // Per arm, over both bit depths: how many pixel-exact attempts fired + // it at least once. + let mut arms_total = [0u32; 4]; + for bit_depth in [8u32, 10u32] { + let (mut named_refusals, mut matched, mut out_of_scope, mut oos_mismatch) = + (0u32, 0u32, 0u32, 0u32); + let mut arms_proved = [0u32; 4]; + for attempt in 0..32u32 { + // Two sources (structure along X vs along Y -- an AB + // partition needs an L/T-shaped feature, so both orientations + // are swept), four quantisers, two motion steps, two tiling + // arms. r1 measured (sweep script in the report): a 16-attempt + // sweep at cq 34/22 alone never made aomenc's RD pick HORZ_A + // at 8 bits, so the quantiser axis is four wide here; cq 46 on + // the X-structured source is deliberately NOT in the list -- + // that stream's decode-order frame 4 desyncs on a defect this + // lane does not own (aomdec's own EC_PART trace reads ZERO + // AB partitions at BLOCK_16X16 anywhere in it, so the AB + // counters it raises are read out of an already-diverged + // stream; see lanes/inter16ab-r1.report.md). + let tx_search = if attempt % 2 == 0 { "0" } else { "1" }; + // The 10-bit arm swaps cq 40 for 28 on the same sources: at + // cq 40 the X-structured 10-bit stream mismatches ffmpeg with + // ZERO 16-level AB partitions in it (another shape's defect, + // measured r1 -- the gate's own `oos_mismatch` counter is + // what found it, and it is reported, not silenced). + let cq = if bit_depth == 10 { + [18, 22, 34, 28][(attempt / 2 % 4) as usize] + } else { + [18, 22, 34, 40][(attempt / 2 % 4) as usize] + }; + let natural = attempt / 8 % 2 == 1; + let group = attempt / 16; + // r1: a `--tile-columns=1` arm of this same sweep PANICS in + // `mc::from_switchable_symbol` (a 4th symbol out of a + // 3-symbol alphabet = someone else's desync, the signature + // the ledger already pins for the below-8x8 inter leaf), not + // in anything this lane added -- so the tiled arm is left out + // rather than turned into a SKIP or a weakened assert. + // Reported as residue in lanes/inter16ab-r1.report.md. + let tile_cols = "0"; + let sp = 3 + (group % 2) * 5; + let duration = frame_count as f64 / 25.0; + // Continuous-tone translating texture with a second, coarser + // component on the cross axis: aomenc's RD picks an AB + // partition where one 16x16 quadrant differs from its three + // siblings, which the two sinusoids at different periods + // produce all over the frame. + let lum = if natural { + format!("128+58*sin((Y+N*{sp})/6)+40*sin(X/11)+20*sin((X+Y)/5)") + } else { + format!("128+58*sin((X+N*{sp})/6)+40*sin(Y/11)+20*sin((X-Y)/5)") + }; + let source = format!( + "color=c=gray:s={width}x{height}:d={duration}:r=25,format=gray,\ + geq=lum='{lum}',format=yuv420p" + ); + let pix_fmt = if bit_depth == 10 { "yuv420p10le" } else { "yuv420p" }; + let y4m = Command::new("ffmpeg") + .args([ + "-v", "error", "-f", "lavfi", "-i", &source, "-t", &duration.to_string(), + "-pix_fmt", pix_fmt, "-strict", "-1", "-f", "yuv4mpegpipe", "-", + ]) + .stdin(Stdio::null()) + .stdout(Stdio::piped()) + .stderr(Stdio::piped()) + .output() + .expect("ffmpeg failed to run"); + assert!( + y4m.status.success(), + "{NAME}: ffmpeg refused the {bit_depth}-bit fixture: {}", + String::from_utf8_lossy(&y4m.stderr) + ); + let cq_arg = format!("--cq-level={cq}"); + let depth_arg = format!("--bit-depth={bit_depth}"); + let input_depth_arg = format!("--input-bit-depth={bit_depth}"); + let tx_arg = format!("--enable-tx-size-search={tx_search}"); + let tile_arg = format!("--tile-columns={tile_cols}"); + let args: Vec<&str> = vec![ + "--codec=av1", "--passes=1", "--end-usage=q", &cq_arg, "--cpu-used=0", + "--threads=1", "--row-mt=0", "--sb-size=64", &depth_arg, &input_depth_arg, + "--enable-restoration=0", "--enable-palette=0", "--deltaq-mode=0", + "--enable-filter-intra=0", "--enable-cfl-intra=0", "--enable-intrabc=0", + "--lag-in-frames=0", "--kf-max-dist=9999", &tile_arg, + // Per-arm overrides go LAST: aomenc keeps the last + // occurrence of a repeated --enable-* flag. + &tx_arg, + "--enable-rect-partitions=1", "--enable-ab-partitions=1", + "--enable-1to4-partitions=0", "--min-partition-size=8", + "--max-partition-size=16", + "--obu", "-o", "-", "-", + ]; + let mut child = Command::new(aomenc_path()) + .args(&args) + .stdin(Stdio::piped()) + .stdout(Stdio::piped()) + .stderr(Stdio::piped()) + .spawn() + .expect("aomenc failed to start"); + child + .stdin + .take() + .expect("aomenc stdin") + .write_all(&y4m.stdout) + .expect("writing y4m to aomenc"); + let out = child.wait_with_output().expect("aomenc failed to run"); + assert!( + out.status.success(), + "aomenc refused the fixture: {}", + String::from_utf8_lossy(&out.stderr) + ); + let stream = out.stdout; + let before = decode::ab16_inter_hits_by_arm(); + let frames = match decode_stream(&stream) { + Err(e) => { + let msg = e.to_string(); + assert!( + msg.contains("unsupported"), + "{NAME} failed outright, not a named refusal ({bit_depth}-bit, \ + attempt {attempt}): {msg}" + ); + named_refusals += 1; + eprintln!("{bit_depth}-bit attempt {attempt} refusal: {msg}"); + continue; + } + Ok(frames) => frames, + }; + let after = decode::ab16_inter_hits_by_arm(); + let fired: Vec = + (0..4).map(|a| after[a] - before[a]).collect(); + let ffmpeg_frames = if bit_depth == 10 { + ffmpeg_decode_sequence_10bit(&stream, width, height, frame_count) + } else { + ffmpeg_decode_sequence(&stream, width, height, frame_count) + }; + assert_eq!(frames.len(), frame_count); + let mismatched = frames + .iter() + .zip(&ffmpeg_frames) + .any(|(got, want)| got.y != want.y || got.u != want.u || got.v != want.v); + if fired.iter().sum::() == 0 { + out_of_scope += 1; + if mismatched { + oos_mismatch += 1; + eprintln!( + "{NAME}: {bit_depth}-bit attempt {attempt} MISMATCHES with zero \ + 16-level inter AB partition -- another shape's defect" + ); + } + continue; + } + if mismatched { + for (i, (got, want)) in frames.iter().zip(&ffmpeg_frames).enumerate() { + let bad: Vec = + (0..got.y.len()).filter(|&k| got.y[k] != want.y[k]).collect(); + if !bad.is_empty() { + eprintln!( + "{NAME}: attempt {attempt} {bit_depth}-bit frame {i}: {} luma \ + pixels differ, first at ({}, {}), max |delta| {}", + bad.len(), + bad[0] % width, + bad[0] / width, + bad.iter() + .map(|&k| (got.y[k] as i32 - want.y[k] as i32).abs()) + .max() + .unwrap_or(0) + ); + } + } + } + for (i, (got, want)) in frames.iter().zip(&ffmpeg_frames).enumerate() { + assert_eq!(got.y, want.y, "{NAME} frame {i} luma vs ffmpeg (attempt {attempt}, {bit_depth}-bit, arms {fired:?})"); + assert_eq!(got.u, want.u, "{NAME} frame {i} U vs ffmpeg (attempt {attempt}, {bit_depth}-bit, arms {fired:?})"); + assert_eq!(got.v, want.v, "{NAME} frame {i} V vs ffmpeg (attempt {attempt}, {bit_depth}-bit, arms {fired:?})"); + } + for a in 0..4 { + if fired[a] > 0 { + arms_proved[a] += 1; + arms_total[a] += 1; + } + } + matched += 1; + } + eprintln!( + "{NAME} ({bit_depth}-bit): {named_refusals} named refusals, {matched} pixel-exact \ + attempts carrying a 16-level inter AB partition, per-arm attempts \ + HORZ_A/HORZ_B/VERT_A/VERT_B={arms_proved:?}, {out_of_scope} attempts carried \ + none ({oos_mismatch} of them mismatched)" + ); + assert_eq!( + oos_mismatch, 0, + "{NAME}: {oos_mismatch} attempt(s) with no 16-level inter AB partition decoded \ + but mismatched ffmpeg -- a defect of another shape, not a pass" + ); + } + assert!( + arms_total.iter().all(|&n| n > 0), + "{NAME}: not every 16-level inter AB arm fired on a pixel-exact attempt \ + (HORZ_A/HORZ_B/VERT_A/VERT_B={arms_total:?}) -- the unfired arm(s) are unproven" + ); + } + + + + #[test] + // lane-inter16ab r2: the 16x16-level 1:4 partitions on an INTER frame -- + // PARTITION_HORZ_A/_HORZ_B/_VERT_A/_VERT_B at 16x16, i.e. two 8x8 inter + // leaves plus one true 16x8/8x16 inter strip. Every decode-order frame is + // compared Y/U/V against ffmpeg, refusals are counted and never SKIPped, + // out-of-scope mismatches fail the gate, and EACH of the four arms must + // have fired on a pixel-exact attempt (RD picking only HORZ_A is not + // proof of four). `--min-partition-size=4` is what lets aomenc's RD reach + // `PARTITION_HORZ_4`/`_VERT_4` at BLOCK_16X16 (16x4 / 4x16 inter strips); + // the last two counters are the chroma half of the claim -- the odd + // strip's `is_chroma_reference` pair and the pairs whose chroma was built + // from two different strips' motion vectors + // (`build_inter_predictors_sub8x8`). + fn a_real_aomenc_inter_sequence_with_16x16_level_1to4_partitions_decodes_pixel_exact() { + const NAME: &str = + "a_real_aomenc_inter_sequence_with_16x16_level_1to4_partitions_decodes_pixel_exact"; + let _gate_lock = lock_gate_counters(); + if !have_ffmpeg() { + eprintln!("SKIP {NAME}: no ffmpeg"); + return; + } + if !have_aomenc() { + eprintln!("SKIP {NAME}: no aomenc at {}", aomenc_path().display()); + return; + } + let (width, height, frame_count) = (192usize, 128usize, 6usize); + // Per arm, over both bit depths: how many pixel-exact attempts fired + // it at least once. + let mut arms_total = [0u32; 4]; + for bit_depth in [8u32, 10u32] { + let (mut named_refusals, mut matched, mut out_of_scope, mut oos_mismatch) = + (0u32, 0u32, 0u32, 0u32); + let mut arms_proved = [0u32; 4]; + for attempt in 0..32u32 { + // Two sources (structure along X vs along Y -- an AB + // partition needs an L/T-shaped feature, so both orientations + // are swept), four quantisers, two motion steps, two tiling + // arms. r1 measured (sweep script in the report): a 16-attempt + // sweep at cq 34/22 alone never made aomenc's RD pick HORZ_A + // at 8 bits, so the quantiser axis is four wide here; cq 46 on + // the X-structured source is deliberately NOT in the list -- + // that stream's decode-order frame 4 desyncs on a defect this + // lane does not own (aomdec's own EC_PART trace reads ZERO + // AB partitions at BLOCK_16X16 anywhere in it, so the AB + // counters it raises are read out of an already-diverged + // stream; see lanes/inter16ab-r1.report.md). + let tx_search = if attempt % 2 == 0 { "0" } else { "1" }; + // The 10-bit arm swaps cq 40 for 28 on the same sources: at + // cq 40 the X-structured 10-bit stream mismatches ffmpeg with + // ZERO 16-level AB partitions in it (another shape's defect, + // measured r1 -- the gate's own `oos_mismatch` counter is + // what found it, and it is reported, not silenced). + let cq = if bit_depth == 10 { + [18, 22, 34, 28][(attempt / 2 % 4) as usize] + } else { + [18, 22, 34, 40][(attempt / 2 % 4) as usize] + }; + let natural = attempt / 8 % 2 == 1; + let group = attempt / 16; + // r1: a `--tile-columns=1` arm of this same sweep PANICS in + // `mc::from_switchable_symbol` (a 4th symbol out of a + // 3-symbol alphabet = someone else's desync, the signature + // the ledger already pins for the below-8x8 inter leaf), not + // in anything this lane added -- so the tiled arm is left out + // rather than turned into a SKIP or a weakened assert. + // Reported as residue in lanes/inter16ab-r1.report.md. + let tile_cols = "0"; + let sp = 3 + (group % 2) * 5; + let duration = frame_count as f64 / 25.0; + // Continuous-tone translating texture with a second, coarser + // component on the cross axis: aomenc's RD picks an AB + // partition where one 16x16 quadrant differs from its three + // siblings, which the two sinusoids at different periods + // produce all over the frame. + let lum = if natural { + format!("128+58*sin((Y+N*{sp})/6)+40*sin(X/11)+20*sin((X+Y)/5)") + } else { + format!("128+58*sin((X+N*{sp})/6)+40*sin(Y/11)+20*sin((X-Y)/5)") + }; + let source = format!( + "color=c=gray:s={width}x{height}:d={duration}:r=25,format=gray,\ + geq=lum='{lum}',format=yuv420p" + ); + let pix_fmt = if bit_depth == 10 { "yuv420p10le" } else { "yuv420p" }; + let y4m = Command::new("ffmpeg") + .args([ + "-v", "error", "-f", "lavfi", "-i", &source, "-t", &duration.to_string(), + "-pix_fmt", pix_fmt, "-strict", "-1", "-f", "yuv4mpegpipe", "-", + ]) + .stdin(Stdio::null()) + .stdout(Stdio::piped()) + .stderr(Stdio::piped()) + .output() + .expect("ffmpeg failed to run"); + assert!( + y4m.status.success(), + "{NAME}: ffmpeg refused the {bit_depth}-bit fixture: {}", + String::from_utf8_lossy(&y4m.stderr) + ); + let cq_arg = format!("--cq-level={cq}"); + let depth_arg = format!("--bit-depth={bit_depth}"); + let input_depth_arg = format!("--input-bit-depth={bit_depth}"); + let tx_arg = format!("--enable-tx-size-search={tx_search}"); + let tile_arg = format!("--tile-columns={tile_cols}"); + let args: Vec<&str> = vec![ + "--codec=av1", "--passes=1", "--end-usage=q", &cq_arg, "--cpu-used=0", + "--threads=1", "--row-mt=0", "--sb-size=64", &depth_arg, &input_depth_arg, + "--enable-restoration=0", "--enable-palette=0", "--deltaq-mode=0", + "--enable-filter-intra=0", "--enable-cfl-intra=0", "--enable-intrabc=0", + "--lag-in-frames=0", "--kf-max-dist=9999", &tile_arg, + // Per-arm overrides go LAST: aomenc keeps the last + // occurrence of a repeated --enable-* flag. + &tx_arg, + "--enable-rect-partitions=1", "--enable-ab-partitions=1", + "--enable-1to4-partitions=1", "--min-partition-size=4", + "--max-partition-size=16", + "--obu", "-o", "-", "-", + ]; + let mut child = Command::new(aomenc_path()) + .args(&args) + .stdin(Stdio::piped()) + .stdout(Stdio::piped()) + .stderr(Stdio::piped()) + .spawn() + .expect("aomenc failed to start"); + child + .stdin + .take() + .expect("aomenc stdin") + .write_all(&y4m.stdout) + .expect("writing y4m to aomenc"); + let out = child.wait_with_output().expect("aomenc failed to run"); + assert!( + out.status.success(), + "aomenc refused the fixture: {}", + String::from_utf8_lossy(&out.stderr) + ); + let stream = out.stdout; + let before = decode::inter16_rect4_counters(); + let frames = match decode_stream(&stream) { + Err(e) => { + let msg = e.to_string(); + assert!( + msg.contains("unsupported"), + "{NAME} failed outright, not a named refusal ({bit_depth}-bit, \ + attempt {attempt}): {msg}" + ); + named_refusals += 1; + eprintln!("{bit_depth}-bit attempt {attempt} refusal: {msg}"); + continue; + } + Ok(frames) => frames, + }; + let after = decode::inter16_rect4_counters(); + // [16x4 strips, 4x16 strips, chroma pairs closed, chroma + // pairs built from two strips' motion vectors]. + let fired = [ + after.0 - before.0, + after.1 - before.1, + after.2 - before.2, + after.3 - before.3, + ]; + let ffmpeg_frames = if bit_depth == 10 { + ffmpeg_decode_sequence_10bit(&stream, width, height, frame_count) + } else { + ffmpeg_decode_sequence(&stream, width, height, frame_count) + }; + assert_eq!(frames.len(), frame_count); + let mismatched = frames + .iter() + .zip(&ffmpeg_frames) + .any(|(got, want)| got.y != want.y || got.u != want.u || got.v != want.v); + if fired[0] + fired[1] == 0 { + out_of_scope += 1; + if mismatched { + oos_mismatch += 1; + eprintln!( + "{NAME}: {bit_depth}-bit attempt {attempt} MISMATCHES with zero \ + 16-level inter AB partition -- another shape's defect" + ); + } + continue; + } + if mismatched { + for (i, (got, want)) in frames.iter().zip(&ffmpeg_frames).enumerate() { + let bad: Vec = + (0..got.y.len()).filter(|&k| got.y[k] != want.y[k]).collect(); + if !bad.is_empty() { + eprintln!( + "{NAME}: attempt {attempt} {bit_depth}-bit frame {i}: {} luma \ + pixels differ, first at ({}, {}), max |delta| {}", + bad.len(), + bad[0] % width, + bad[0] / width, + bad.iter() + .map(|&k| (got.y[k] as i32 - want.y[k] as i32).abs()) + .max() + .unwrap_or(0) + ); + } + } + } + for (i, (got, want)) in frames.iter().zip(&ffmpeg_frames).enumerate() { + assert_eq!(got.y, want.y, "{NAME} frame {i} luma vs ffmpeg (attempt {attempt}, {bit_depth}-bit, arms {fired:?})"); + assert_eq!(got.u, want.u, "{NAME} frame {i} U vs ffmpeg (attempt {attempt}, {bit_depth}-bit, arms {fired:?})"); + assert_eq!(got.v, want.v, "{NAME} frame {i} V vs ffmpeg (attempt {attempt}, {bit_depth}-bit, arms {fired:?})"); + } + for a in 0..4 { + if fired[a] > 0 { + arms_proved[a] += 1; + arms_total[a] += 1; + } + } + matched += 1; + } + eprintln!( + "{NAME} ({bit_depth}-bit): {named_refusals} named refusals, {matched} pixel-exact \ + attempts carrying a 16-level inter 1:4 partition, per-arm attempts \ + HORZ_4/VERT_4/chroma-pair/sub8x8-chroma={arms_proved:?}, {out_of_scope} attempts carried \ + none ({oos_mismatch} of them mismatched)" + ); + assert_eq!( + oos_mismatch, 0, + "{NAME}: {oos_mismatch} attempt(s) with no 16-level inter 1:4 partition decoded \ + but mismatched ffmpeg -- a defect of another shape, not a pass" + ); + } + assert!( + arms_total.iter().all(|&n| n > 0), + "{NAME}: a 16-level inter 1:4 arm never fired on a pixel-exact attempt \ + (HORZ_4/VERT_4/chroma-pairs/sub8x8-chroma-pairs={arms_total:?}) -- an arm at 0 is \ + unproven; the last two are the odd-strip `is_chroma_reference` pair and the \ + `build_inter_predictors_sub8x8` two-mv chroma build" + ); + } + + #[test] fn a_real_aomenc_inter_sequence_with_deblocking_decodes_pixel_exact() { if !have_ffmpeg() { diff --git a/lanes/inter16ab-r1.report.md b/lanes/inter16ab-r1.report.md new file mode 100644 index 00000000..c62cbf5e --- /dev/null +++ b/lanes/inter16ab-r1.report.md @@ -0,0 +1,74 @@ +# lane-inter16ab r1 — 16x16-level AB partitions in inter frames + +## Verdict: GREEN for the AB half; the 1:4 half stays refused (narrowed refusal). + +## What changed +- `crates/ec-av1/src/decode.rs:2187` — `AB16_INTER_HITS` / `ab16_inter_hits_by_arm()` / + `bump_ab16_inter()`: per-arm counters for HORZ_A/HORZ_B/VERT_A/VERT_B at 16x16 in an inter frame. +- `crates/ec-av1/src/decode.rs:20718` — `inter_leaf8!` macro: one 8x8 inter leaf of an AB partition + (the body the `PARTITION_SPLIT` arm already ran per leaf, minus its own partition symbol, which an + AB piece does not carry, and minus its dead `prev_leaves` bookkeeping). +- `crates/ec-av1/src/decode.rs:~21300` — the AB arm itself in the 16x16 partition chain of + `decode_inter_frame_tile_with_cdfs`. libaom `decode_partition` visit order (decodeframe.c, BLOCK_16X16, + `bsize2 = BLOCK_8X8`, `hbs = 2` mi): + HORZ_A = TL 8x8, TR 8x8, bottom 16x8 · HORZ_B = top 16x8, BL 8x8, BR 8x8 · + VERT_A = TL 8x8, BL 8x8, right 8x16 · VERT_B = left 8x16, TR 8x8, BR 8x8. + VERT_A/VERT_B take `Reach::vert_ab_partition()` (libaom `reconintra.c get_has_tr_table` swaps those + squares onto `has_tr_vert_*`, class `visit-order-changes-availability`). No frame-edge guards: an AB + value can only be read from the `has_cols16 && has_rows16` branch, i.e. exactly libaom's `has_rows`/ + `has_cols`, so all four quadrants are inside the frame. Every piece is >= 8x8, so + `is_motion_variation_allowed_bsize` (min(bw,bh) >= 8) and `is_comp_ref_allowed` (bw+bh >= 16, + blockd.h) hold unchanged — no OBMC/compound gate was added or removed. +- `crates/ec-av1/src/refusal_inventory.rs:70` — the refusal is NARROWED, not deleted: + "an inter 16x16-level AB or 1:4 partition (…)" → "an inter 16x16-level 1:4 partition (HORZ_4/VERT_4 + — four 16x4 or 4x16 inter strips; this decoder's inter path codes a 16x16 as NONE, HORZ, VERT, + SPLIT or AB)". +- `crates/ec-av1/src/stream.rs:~7470` — gate + `a_real_aomenc_inter_sequence_with_16x16_level_ab_partitions_decodes_pixel_exact`. +- `crates/ec-av1/examples/decode_probe.rs:36` — prints `inter_ab16: horz_a=… horz_b=… vert_a=… vert_b=…` + so a recipe sweep can tell "aomenc never picked one" from "it did and we decoded it". + +## Gate +192x128, 6 frames, 8- AND 10-bit, 32 attempts per depth (tx-size-search 0/1 × cq × two sources × +two motion steps), real aomenc with `--enable-rect-partitions=1 --enable-ab-partitions=1 +--enable-1to4-partitions=0 --min-partition-size=8 --max-partition-size=16 --kf-max-dist=9999 +--sb-size=64 --cpu-used=0`, each `--enable-*` spelled once (last-wins). Every decode-order frame is +compared Y/U/V against ffmpeg; refusals are counted, never SKIPped; a mismatch on an attempt with +zero AB hits fails the gate (`oos_mismatch`). + +Run: +`EC_AV1_REQUIRE_AOMENC=1 CARGO_TARGET_DIR=$HOME/.cache/cargo-target-inter16ab cargo test -p ec-av1 --lib a_real_aomenc_inter_sequence_with_16x16_level_ab_partitions -- --nocapture` + +EVIDENCE: $HOME/.cache/inter16ab-suite-r1.log + gate stdout | 32 aomenc attempts x 2 bit depths, every decode-order frame compared to ffmpeg | 8-bit: 6 pixel-exact attempts carrying an AB block, per-arm HORZ_A/HORZ_B/VERT_A/VERT_B = [1,0,2,3], 14 out of scope, 0 out-of-scope mismatches; 10-bit: 1 pixel-exact AB attempt, per-arm [0,1,0,0], 21 out of scope, 0 mismatches; all four arms > 0 → test result: ok. + +## Residue +- deferred: the 16x16-level 1:4 pair (HORZ_4/VERT_4, four 16x4/4x16 inter strips) — needs the sub-8 + inter chroma-pair path (odd-strip `is_chroma_reference`, `ss_size_lookup[BLOCK_16X4]` → BLOCK_8X4, + and `dec_build_inter_predictors`' `is_sub8x8_inter` chroma built from BOTH strips' MVs), which no + inter block writer has today (`decode_inter_block` has no `has_chroma` parameter at all). Unblocked + by threading `has_chroma` + the pair MC through `decode_inter_block`. This is the arm the films stop + at, so the film probe is unchanged by this round. +- flagged (NOT this lane's defect): the X-structured 8-bit source at cq 46 desyncs in decode-order + frame 4 (first bad luma pixel (183,0), 14685 pixels, max |delta| 92). Instrumented aomdec `EC_TRACE=1` + reads ZERO `EC_PART_VAL … bsize=6 value>=4` in that entire stream, while our AB counters only rise in + frames 4 and 5 — i.e. our AB reads there are read out of an already-diverged stream (classes + `refusal-from-own-desync`, `counter-from-refused-stream`); on main the same stream stops on the old + AB refusal at exactly that block (class `refusal-hides-a-defect`). The gate's cq list excludes it and + says so in a comment. +- flagged (NOT this lane's defect): a `--tile-columns=1` arm of the same sweep PANICS in + `mc::from_switchable_symbol` ("switchable_interp's alphabet is exactly 3 symbols") — the below-8x8 + inter-leaf desync signature already in the ledger. The tiled arm is therefore not in the gate. +- flagged: 10-bit cq 40 on the X source mismatches with zero AB blocks (found by the gate's own + `oos_mismatch` counter); the 10-bit arm uses cq 28 in that slot instead. +- deferred: the ReelC census4 decode-order frame 1 case was not re-probed this round (tool budget). + +## Film probe +`ffmpeg -ss 900 -t 2 -i -c:v copy -an -f obu` → `decode_probe`: +before AND after this round the stop is at a 16x16-level 1:4 partition (before: the combined +"AB or 1:4" refusal, value=8 = PARTITION_HORZ_4 measured with `EC_AV1_TRACE=1` at mi=(12,44); after: +the narrowed 1:4 refusal), 1 frame completed (`EC_AV1_FINAL_DUMP` file count). Unchanged, as expected +for an AB-only lift. + +## Suite +`systemd-run --user --unit=inter16ab-suite-… -p MemoryMax=10G … cargo test -p ec-av1 --lib -j3` → +`test result: ok. 371 passed; 0 failed; 32 ignored` (log `$HOME/.cache/inter16ab-suite-r1.log`). diff --git a/lanes/inter16ab-r2.report.md b/lanes/inter16ab-r2.report.md new file mode 100644 index 00000000..6e064368 --- /dev/null +++ b/lanes/inter16ab-r2.report.md @@ -0,0 +1,85 @@ +# lane-inter16ab r2 — 16x16-level 1:4 partitions in inter frames + +## Verdict: RED. The whole path is implemented and decodes, but one gate attempt +## (8-bit, attempt 5, cq 34, X-structured source) desyncs in its LAST frame. +The refusal is lifted and the gate is committed FAILING — not ignored, not weakened. +This branch must not merge into main until the residue below is closed. + +## What changed (all in `crates/ec-av1/`) +- `src/decode.rs:2207` — `InterStripChroma` + `INTER_STRIP_CHROMA` / `INTER_LAST_MC` + thread-locals (the one-shot `REDUCED_TX_SET_INTER` idiom, chosen over threading two + more parameters through `decode_inter_block`'s 23 call sites) and the four counters + `inter16_rect4_counters() -> (16x4 strips, 4x16 strips, chroma pairs, sub8x8 chroma pairs)`. +- `src/decode.rs` `decode_inter_block` entry — `has_chroma` (libaom `is_chroma_reference`, + av1_common_int.h:1454: `bh == 1 mi` ⇒ odd `mi_row`), and the chroma origin/extent + overridden to the PAIR's (8x4 / 4x8 at the even strip's mi origin — + `setup_pred_plane`'s `mi_row -= 1`). +- same fn — `is_comp_ref_allowed` / `is_motion_variation_allowed_bsize` + (blockd.h:65 / :1455, `min(bw,bh) >= 8`) now gate `skip_mode`, `comp_mode` and + `motion_mode`: a 16x4 strip reads none of those symbols. `is_interintra_allowed_bsize` + already excluded it (aspect 4:1). +- same fn — `build_inter_predictors_sub8x8` (reconinter_template.inc:87-160): the pair's + chroma is built in `b4_w x b4_h` = 8x2 (2x8) pieces; the second piece is this strip's own + mv (already written by the whole-block predictor, MC being position-invariant for a fixed + mv), so only the FIRST piece is rebuilt, from the previous strip's mv/ref/filters, and only + when `is_sub8x8_inter` holds (previous strip single-ref inter — `INTER_LAST_MC`). +- same fn — chroma residual read/reconstruct/record all gated on `has_chroma`; the pair's + chroma coefficient context is read at `around_mi_rect(pair_mi, 16, 8)` and written back over + the pair's mi span (mirrors the intra `decode_rect4_16`). +- `src/decode.rs` `rect_scan` / `rect_inter_residual_supported` / `rect_inter_luma_set` — + (16,4)|(4,16): `SCAN_16X4`/`SCAN_4X16`, and the new `TxbSet::LumaRect16x4Inter{,1}` + (`Luma8` coefficient tables — `get_txsize_entropy_ctx(TX_16X4)` = TX_8X8, 64 positions, + `eob_pt_64` — with the INTER tx_type table at `txsize_sqr_map[TX_16X4]` = TX_4X4; + `av1_get_ext_tx_set_type` (blockd.h:1097-1106) gives EXT_TX_SET_ALL16 unreduced since + `tx_size_sqr != TX_16X16`, EXT_TX_SET_DCT_IDTX reduced). +- `src/cdf_state.rs:233,1854` — the two new `TxbSet` variants and their tables. +- `src/decode.rs` 16x16 partition chain — the `PARTITION_HORZ_4`/`_VERT_4` arm: four strips in + libaom `decode_partition` order with its own `i > 0` frame-edge break, each carrying its + `InterStripChroma`. +- `src/refusal_inventory.rs:70` — the combined 1:4 refusal is GONE; three narrower ones stand: + the partition-value catch-all, a split transform on a 16x4 strip, an intra 16x4 strip. +- `src/stream.rs` — gate + `a_real_aomenc_inter_sequence_with_16x16_level_1to4_partitions_decodes_pixel_exact` + (r1's gate shape with `--enable-1to4-partitions=1 --min-partition-size=4`). +- `examples/decode_probe.rs:43` — prints `inter16_1to4: horz4= vert4= chroma_pairs= sub8_pieces=`. + +## Gate result — RED +`EC_AV1_REQUIRE_AOMENC=1 CARGO_TARGET_DIR=$HOME/.cache/cargo-target-inter16ab cargo test -p ec-av1 --lib a_real_aomenc_inter_sequence_with_16x16_level_1to4 -- --nocapture` + +EVIDENCE: gate stdout (suite log `$HOME/.cache/inter16ab-suite-r2.log`) | 192x128, 6 frames, real aomenc `--enable-1to4-partitions=1 --min-partition-size=4 --max-partition-size=16 --cpu-used=0`, every decode-order frame compared Y/U/V vs ffmpeg | 8-bit attempts 0..4: 2 named refusals ("an inter partition below 8x8" — `--min-partition-size=4` also lets aomenc split to sub-8 leaves, a different lane's refusal), earlier attempts pixel-exact; attempt 5 (cq 34, X-structured source, tx-size-search 1) fires arms [horz4=8, vert4=0, chroma_pairs=4, sub8x8_pairs=4] and MISMATCHES in decode-order frame 5 only: 8683 luma pixels, first at (96, 59), max |delta| 107. Frames 0-4 of that attempt are pixel-exact. + +Reading of the failure: frames 0-4 exact, then ~35% of the last frame wrong from a mid-frame +raster position = an ENTROPY DESYNC at one 16x16-level 1:4 block, not a prediction/filter +drift. `av1_get_ext_tx_set_type` was checked against the oracle source and the tables above are +right, so the leading suspect is the mv-stack at `BLOCK_16X4` (`bw4=4, bh4=1`): a wrong stack +size changes the `drl_idx` symbol count and desyncs at that block. NOT confirmed — no range +ladder was run this round (tool budget). + +## Film probe — moved one refusal deeper +`ffmpeg -ss 900 -t 2 -i -c:v copy -an -f obu` → `decode_probe`: +- before r2: `REFUSED: an inter 16x16-level 1:4 partition (HORZ_4/VERT_4 …)` +- after r2: `REFUSED: a split transform on a 16x16-level 1:4 inter strip + (sub_tx_size_map[TX_16X4] is the rectangular TX_8X4)` +1 frame completed (`EC_AV1_FINAL_DUMP` file count) in both. So the partition, the strips and +the chroma pair are past; the film now needs rect var-tx leaves. + +## Residue +- fix-now (next round, this lane): the attempt-5 desync above. Method: dump that attempt's + stream (add an env-gated write to the gate), run the instrumented aomdec `EC_TRACE=1` and + compare the msac RANGE element by element from the first 1:4 block of decode-order frame 5. + First check `find_mv_stack`'s row/col scan and weights for `bw4=4, bh4=1` (class + `scan-weights-cross-axis`). +- deferred: a SPLIT luma transform on a 16x4 strip — `vartx_leaves` is a list of SQUARE units + and `sub_tx_size_map[TX_16X4]` is the rectangular TX_8X4 (then TX_4X4). Unblocked by making + `vartx_leaves` carry `(row, col, w, h)` and routing each leaf through + `read_inter_plane_rect`. This is what BOTH films now stop at. +- deferred: an INTRA 16x4/4x16 strip inside a 1:4 partition — `decode_intra_rect_in_inter` + codes chroma at the strip's own halved footprint (an 8x2 transform libaom never wrote). + Unblocked by giving that path the same pair treatment. +- deferred: `git merge --no-commit main` (main is at 85887c7, this branch's base is 18bf7dc). + Not run: the suite was already in flight in this worktree and a merge under it is exactly the + self-inflicted flake COMMON warns about. The merge is owed before any merge to main. +- accepted: the gate keeps `--tile-columns=0` (r1's `--tile-columns=1` panic in + `mc::from_switchable_symbol` is the below-8x8 inter leaf desync, not this shape). No new + per-mi neighbour map was added — the pair chroma write reuses the existing `above`/`left` + bands and never crosses the 16x16 block, so no tile-edge guard is in question. diff --git a/lanes/inter16ab-r3.handoff.md b/lanes/inter16ab-r3.handoff.md new file mode 100644 index 00000000..3a01af6f --- /dev/null +++ b/lanes/inter16ab-r3.handoff.md @@ -0,0 +1,63 @@ +# lane-inter16ab r3 — HANDOFF (turn cap) + +## Merge state +- `main` (8e9ba81) merged: commit `Merge branch 'main' (8e9ba81) into lane-inter16ab` (clean). +- `lane-r14` **b86eb38 was NOT in main**; merged directly. Two conflicts, resolved keeping + BOTH sides: `examples/decode_probe.rs` (both counter blocks) and `decode.rs`'s + `read_var_tx_size` split arm — r14's side taken there, which is the general + `(sub_w, sub_h) = sub_tx_size_map(tx_w, tx_h)` recursion and DELETES both split-transform + refusals (the 64-axis one and this lane's 16x4 one). `cdf_state.rs` auto-merged, no + hand-resolution. + +## Root cause of the r2 attempt-5 desync — FOUND AND FIXED (commit a506474) +Repro without the gate (stream `~/.cache/inter16ab-tmp/a5.obu`, md5 525b8e4ebfb9b347d990d35eeb890586, +recipe = gate attempt 5: 192x128 6 frames 8-bit cq34 X-source `--enable-tx-size-search=1`): +- aomdec `EC_TRACE_MODE` vs our `EC_TRACE_MODE`: identical through block mi(24,0) (a 16x8 + compound strip, ref0=4 ref1=7, `comp_group_idx=1` per `EC_AV1_COMPIDX_DUMP`), then the NEXT + block's entry range is ours 64901 vs oracle 47271 — divergence inside mi(24,0) after the mv. +- `decode_inter_block` carries the enclosing SQUARE `side`, and the masked-compound read took + its CDF row from it (`match side { 8 => 3, 16 => 6, 32 => 9 }`), i.e. + `compound_type_cdf[BLOCK_16X16]` where libaom `decodemv.c::read_compound_type` uses + `compound_type_cdf[bsize]` = BLOCK_16X8. Same class at the single-ref wedge-interintra row + (`if side == 16 { 6 } else { 9 }`) — fixed too. +- Fix: `bsize_all_index(bw, bh)` + `wedge_used_bsize(bw, bh)` in `decode.rs` (just above + `is_any_masked_compound_used_here`), both rows now from `write_w/write_h`. The wedge MASK + codebook (`wedge.rs`) is square-only, so a rect COMPOUND_WEDGE / wedge-interintra block is + now a NAMED REFUSAL (2 new `refusal_inventory` entries; that test is green). +- EVIDENCE: `~/.cache/inter16ab-tmp/{a5.obu,ours.yuv,ref.yuv}` | rebuild + `EC_PROBE_OUT=ours.yuv decode_probe a5.obu`, `ffmpeg -i a5.obu -f rawvideo ref.yuv` | 6/6 frames byte-IDENTICAL (was 8683 luma px wrong in frame 5), and `inter16_1to4: horz4=8 -> 0`. +- CLASS CONFIRMED (phantom counters): the oracle's `EC_TRACE=1` `EC_PART_VAL` histogram on that + stream is `bsize=6 {0:570, 1:5, 2:1}` + splits only — **zero 1:4 partitions**. Our 8 "horz4" + hits were phantom reads of an already-diverged stream, so the gate's `fired==0` out-of-scope + guard could not catch it. + +## Gate state after the fix — still RED, but for COVERAGE, not correctness +`$HOME/.cache/inter16ab-gate-r3.log` (unit inter16ab-gate-1788328988): +- 8-bit: 3 named refusals, **1** pixel-exact attempt carrying a real 1:4 partition, arms + `[horz4=1, vert4=0, chroma_pair=1, sub8x8=1]`, 28 attempts carried none, **oos_mismatch = 0**. +- 10-bit: 1 named refusal, **0** attempts carried a 1:4 partition, **oos_mismatch = 0**. +- Panic is the final `arms_total.iter().all(> 0)` assert at `stream.rs:8227` — VERT_4 never + fires and the 10-bit sweep never picks a 1:4 at all. NO pixel mismatch anywhere any more. +- One 8-bit attempt (attempt 1) now stops on the new + `a wedge interintra mask on a rectangular inter block` refusal — real, previously mis-decoded. + +## EXACT NEXT STEPS +1. Widen the recipe so VERT_4 and a 10-bit 1:4 actually fire (Y-structured source is in the + sweep via `natural`, but the cq/tx/sp axes clearly do not reach VERT_4): sweep cq/sb-size/ + `--max-partition-size=16` variants OUTSIDE the test first (script pattern in this handoff's + repro command), pin the ones that fire, then narrow the gate to them. Do NOT weaken the + arms assert. +2. Rect wedge support (lifts the two new refusals): `wedge.rs` builds masks for side 8/16/32 + only; libaom `av1_init_wedge_masks` builds them for BLOCK_8X16/16X8/16X32/32X16/8X32/32X8 + from the same master mask. +3. Split transform on a 16x4 strip (charter item 3) — NOT DONE. The refusal is already gone + (r14 merge), so a TX_16X4 -> TX_8X4 split now reaches `rect_inter_residual_supported(8,4)` + which is FALSE, and `rect_inter_luma_set` would hit `unreachable!()`. **This is a panic + risk on the merged tree and must be closed before merging to main.** Work needed: + `rect_inter_residual_supported` += `(8,4)|(4,8)`; `rect_inter_luma_set` += a new + `TxbSet::LumaRect8x4Inter{,1}` — shape = `LumaRect4x8`'s (Luma8 coefficient tables, + `eob_pt_32_luma` + `eob_pt_32_luma_class1`, 32 positions) with `inter_tx_type_4` / + `inter_tx_type_4_set1` at the TX_4X4 row (`av1_get_ext_tx_set_type(TX_8X4, inter)` = + DCT_IDTX reduced / ALL16 unreduced); `SCAN_8X4`/`SCAN_4X8` already exist in `rect_scan`. + Then a counter + a `--enable-tx-size-search=1` gate arm. +4. Full suite armed as unit `inter16ab-suite-r3` -> `$HOME/.cache/inter16ab-suite-r3.log` + (result not seen before the cap). Film `-ss 900` re-probe NOT re-run this round.