diff --git a/crates/ec-av1/examples/decode_probe.rs b/crates/ec-av1/examples/decode_probe.rs index c0c366bb..0bcbd179 100644 --- a/crates/ec-av1/examples/decode_probe.rs +++ b/crates/ec-av1/examples/decode_probe.rs @@ -31,6 +31,11 @@ fn main() { let report = || { let (h, v, c) = ec_av1::stream::rect4_32_counters(); println!("rect4_32: horz={h} vert={v} coded={c}"); + let ir = ec_av1::stream::inter_rect_counters(); + println!( + "inter_rect: 32x8={} 8x32={} 64x32={} 32x64={} 64x16={} 16x64={}", + ir.0, ir.1, ir.2, ir.3, ir.4, ir.5 + ); }; match ec_av1::stream::decode_stream(&data) { Ok(frames) if frames.is_empty() => { diff --git a/crates/ec-av1/src/cdf.rs b/crates/ec-av1/src/cdf.rs index 7c690293..bcbb00c3 100644 --- a/crates/ec-av1/src/cdf.rs +++ b/crates/ec-av1/src/cdf.rs @@ -1610,7 +1610,7 @@ pub const SKIP_MODE: [[u16; 3]; 3] = [[32621, 32768, 0], [20708, 32768, 0], [812 /// `motion_mode_allowed` (spec 5.11.24's `read_motion_mode`) offers /// `OBMC_CAUSAL` rather than `WARPED_CAUSAL` -- lane-motionmode round 1 /// never reaches the three-way `motion_mode_cdf`, see `decode.rs`. -pub const OBMC: [[u16; 3]; 6] = [ +pub const OBMC: [[u16; 3]; 12] = [ [10437, 32768, 0], [17432, 32768, 0], [25817, 32768, 0], @@ -1620,6 +1620,16 @@ pub const OBMC: [[u16; 3]; 6] = [ // (rect-flake-1: the strip's motion_mode read diverged on this). [14423, 32768, 0], [15142, 32768, 0], + // lane-inter4 r1: the rect rows a superblock-level HORZ/VERT/1:4 and a + // 32x32-level 1:4 inter strip read -- BLOCK_32X64 (10), BLOCK_64X32 (11), + // BLOCK_8X32 (18), BLOCK_32X8 (19), BLOCK_16X64 (20), BLOCK_64X16 (21) of + // libaom's `default_obmc_cdf`. + [22823, 32768, 0], + [22083, 32768, 0], + [23664, 32768, 0], + [20901, 32768, 0], + [24008, 32768, 0], + [26879, 32768, 0], ]; /// `default_motion_mode_cdf` (spec 9.4, `entropymode.c`), the square-bsize @@ -1629,7 +1639,7 @@ pub const OBMC: [[u16; 3]; 6] = [ /// `read_motion_mode` reads instead of [`OBMC`] whenever `motion_mode_allowed` /// (spec 5.11.24) resolves to `WARPED_CAUSAL`-eligible (`num_proj_ref >= 1` /// under `allow_warped_motion`) -- lane-warp round 1. -pub const MOTION_MODE: [[u16; 4]; 6] = [ +pub const MOTION_MODE: [[u16; 4]; 12] = [ [7651, 24760, 32768, 0], [19419, 26810, 32768, 0], [26260, 29116, 32768, 0], @@ -1637,6 +1647,14 @@ pub const MOTION_MODE: [[u16; 4]; 6] = [ // lane-rect r2: BLOCK_16X32 / BLOCK_32X16 rows (indices 7/8). [5123, 23606, 32768, 0], [11606, 24308, 32768, 0], + // lane-inter4 r1: BLOCK_32X64 / 64X32 / 8X32 / 32X8 / 16X64 / 64X16 rows + // (libaom `default_motion_mode_cdf` indices 10, 11, 18, 19, 20, 21). + [20360, 28062, 32768, 0], + [21679, 26830, 32768, 0], + [28799, 31390, 32768, 0], + [26431, 30774, 32768, 0], + [28973, 31594, 32768, 0], + [29742, 31203, 32768, 0], ]; /// `default_interintra_cdf` (spec 9.4): `interintra`, indexed by diff --git a/crates/ec-av1/src/cdf_state.rs b/crates/ec-av1/src/cdf_state.rs index 3f53b485..822c31d1 100644 --- a/crates/ec-av1/src/cdf_state.rs +++ b/crates/ec-av1/src/cdf_state.rs @@ -469,13 +469,13 @@ pub(crate) struct Cdfs { /// `BLOCK_8X8`, 1 = `BLOCK_16X16`, 2 = `BLOCK_32X32`, 3 = `BLOCK_64X64` /// (`default_obmc_cdf`'s own `BLOCK_SIZES_ALL` indices 3/6/9/12 -- /// this decoder only ever codes those four square sizes). - pub obmc: [[u16; 3]; 6], + pub obmc: [[u16; 3]; 12], /// `motion_mode` (spec 5.11.24's `read_motion_mode`), the 3-symbol /// `SIMPLE_TRANSLATION`/`OBMC_CAUSAL`/`WARPED_CAUSAL` alphabet read /// instead of [`Self::obmc`] whenever `motion_mode_allowed` resolves to /// `WARPED_CAUSAL`-eligible -- same square-bsize indexing as `obmc`. /// lane-warp round 1. - pub motion_mode: [[u16; 4]; 6], + pub motion_mode: [[u16; 4]; 12], /// `interintra`, indexed by `size_group_lookup[bsize]` -- see /// `cdf::INTERINTRA`'s own doc. pub interintra: [[u16; 3]; 4], diff --git a/crates/ec-av1/src/decode.rs b/crates/ec-av1/src/decode.rs index 5006a89c..73a5730f 100644 --- a/crates/ec-av1/src/decode.rs +++ b/crates/ec-av1/src/decode.rs @@ -1521,6 +1521,17 @@ pub(crate) fn sb_rect4_vert_hits() -> usize { thread_local! { static RECT4_32_HORZ_HITS: std::cell::Cell = const { std::cell::Cell::new(0) }; static RECT4_32_VERT_HITS: std::cell::Cell = const { std::cell::Cell::new(0) }; + /// lane-inter4 r1: the INTER-frame twins of the two counters above -- + /// four 32x8 / 8x32 inter strips of a 32x32-level `PARTITION_HORZ_4` / + /// `PARTITION_VERT_4`. + static RECT4_32_HORZ_INTER_HITS: std::cell::Cell = const { std::cell::Cell::new(0) }; + static RECT4_32_VERT_INTER_HITS: std::cell::Cell = const { std::cell::Cell::new(0) }; + /// lane-inter4 r1: superblock-level inter `PARTITION_HORZ`/`PARTITION_VERT` + /// strips (64x32 / 32x64) and their 1:4 pair (64x16 / 16x64). + static INTER_SB_HORZ_HITS: std::cell::Cell = const { std::cell::Cell::new(0) }; + static INTER_SB_VERT_HITS: std::cell::Cell = const { std::cell::Cell::new(0) }; + static INTER_SB_HORZ4_HITS: std::cell::Cell = const { std::cell::Cell::new(0) }; + static INTER_SB_VERT4_HITS: std::cell::Cell = const { std::cell::Cell::new(0) }; } /// How many 32x32-level 1:4 strips actually read coefficients (non-skip): @@ -1545,6 +1556,36 @@ pub(crate) fn rect4_32_vert_hits() -> usize { RECT4_32_VERT_HITS.with(|c| c.get()) } +/// Current value of `RECT4_32_HORZ_INTER_HITS` (32x8 inter strips decoded). +pub(crate) fn rect4_32_horz_inter_hits() -> usize { + RECT4_32_HORZ_INTER_HITS.with(|c| c.get()) +} + +/// Current value of `RECT4_32_VERT_INTER_HITS` (8x32 inter strips decoded). +pub(crate) fn rect4_32_vert_inter_hits() -> usize { + RECT4_32_VERT_INTER_HITS.with(|c| c.get()) +} + +/// Current value of `INTER_SB_HORZ_HITS` (64x32 inter strips decoded). +pub(crate) fn inter_sb_horz_hits() -> usize { + INTER_SB_HORZ_HITS.with(|c| c.get()) +} + +/// Current value of `INTER_SB_VERT_HITS` (32x64 inter strips decoded). +pub(crate) fn inter_sb_vert_hits() -> usize { + INTER_SB_VERT_HITS.with(|c| c.get()) +} + +/// Current value of `INTER_SB_HORZ4_HITS` (64x16 inter strips decoded). +pub(crate) fn inter_sb_horz4_hits() -> usize { + INTER_SB_HORZ4_HITS.with(|c| c.get()) +} + +/// Current value of `INTER_SB_VERT4_HITS` (16x64 inter strips decoded). +pub(crate) fn inter_sb_vert4_hits() -> usize { + INTER_SB_VERT4_HITS.with(|c| c.get()) +} + // lane-rect64q r1: how many of [`decode_block_rect64`]'s three per-plane // dequant calls actually observed `CURRENT_Q_IDX != base_q_idx` -- proof the // running-vs-stale-snapshot bug this round fixed is exercised by a gate, not @@ -3815,7 +3856,24 @@ impl Neighbours { uv_mode: usize, grids: &[Vec; 3], ) { - let (r, c) = at; + self.record_rect_mi(sub16_to_mi(at), w, h, mode, uv_mode, grids); + } + + /// [`Self::record_rect`] in mi (4 px) units -- lane-inter4 r1: a + /// 32x8/8x32 strip of a 32-level 1:4 partition sits at an 8-px offset the + /// [`SUB`]-unit `at` cannot name. The coarse 16-px bands are still keyed + /// by the enclosing cell (a sub-16 extent writes none of them, exactly as + /// the [`SUB`]-unit path does). + fn record_rect_mi( + &mut self, + at_mi: (usize, usize), + w: usize, + h: usize, + mode: usize, + uv_mode: usize, + grids: &[Vec; 3], + ) { + let (r, c) = (at_mi.0 / (SUB / MI), at_mi.1 / (SUB / MI)); for cell in 0..w / SUB { self.above_mode[c + cell] = mode; self.above_uv_mode[c + cell] = uv_mode; @@ -3826,9 +3884,9 @@ impl Neighbours { self.left_uv_mode[r + cell] = uv_mode; self.left_side[r + cell] = h; } - self.record_mode_mi(r * (SUB / MI), c * (SUB / MI), w / MI, h / MI, mode); - self.record_uv_mode_mi(r * (SUB / MI), c * (SUB / MI), w / MI, h / MI, uv_mode); - self.record_mi_rect((r * (SUB / MI), c * (SUB / MI)), w, h, grids); + self.record_mode_mi(at_mi.0, at_mi.1, w / MI, h / MI, mode); + self.record_uv_mode_mi(at_mi.0, at_mi.1, w / MI, h / MI, uv_mode); + self.record_mi_rect(at_mi, w, h, grids); } /// The coefficient-context half of [`Self::record`], taking the block's @@ -3944,7 +4002,21 @@ impl Neighbours { uv_mode: usize, chroma_grids: [&[i32]; 2], ) { - let (r, c) = at; + self.record_split_luma_rect_mi(sub16_to_mi(at), w, h, mode, uv_mode, chroma_grids); + } + + /// [`Self::record_split_luma_rect`] in mi (4 px) units (lane-inter4 r1, + /// same reason as [`Self::record_rect_mi`]). + fn record_split_luma_rect_mi( + &mut self, + at_mi: (usize, usize), + w: usize, + h: usize, + mode: usize, + uv_mode: usize, + chroma_grids: [&[i32]; 2], + ) { + let (r, c) = (at_mi.0 / (SUB / MI), at_mi.1 / (SUB / MI)); for cell in 0..w / SUB { self.above_mode[c + cell] = mode; self.above_uv_mode[c + cell] = uv_mode; @@ -3955,7 +4027,7 @@ impl Neighbours { self.left_uv_mode[r + cell] = uv_mode; self.left_side[r + cell] = h; } - let (mi_r, mi_c) = (r * (SUB / MI), c * (SUB / MI)); + let (mi_r, mi_c) = at_mi; let (w_mi, h_mi) = (w / MI, h / MI); self.record_mode_mi(mi_r, mi_c, w_mi, h_mi, mode); self.record_uv_mode_mi(mi_r, mi_c, w_mi, h_mi, uv_mode); @@ -12768,6 +12840,12 @@ fn build_gm_mv_table( /// mode/tx-type outside what [`read_intra_mode`]/[`read_coeffs`] already /// refuse. #[allow(clippy::too_many_arguments)] +/// lane-inter4 r1: 16-px-cell coordinates -> MI (4-px) coordinates, the unit +/// [`decode_inter_block`]'s `at` now takes. +const fn sub16_to_mi(t: (usize, usize)) -> (usize, usize) { + (t.0 * (SUB / MI), t.1 * (SUB / MI)) +} + fn decode_inter_block( dec: &mut SymbolDecoder, cdfs: &mut Cdfs, @@ -12882,13 +12960,16 @@ fn decode_inter_block( // combinations that don't implement scaled MC yet. frame_width: usize, ) -> Result<()> { - let (r, c) = at; + // lane-inter4 r1: `at` is in MI units (4 px) so a 32-level 1:4 strip can + // name an 8-px offset; `(r, c)` stays the enclosing 16-px cell for the + // few 16-px-granular uses below. + let (r, c) = (at.0 / (SUB / MI), at.1 / (SUB / MI)); // lane-inter8 r2: the inter side bands are mi-granular; this block's own // above/left neighbour is the mi cell at its top-left corner (libaom // `above_mbmi` = mi(mi_row - 1, mi_col)), so a SUB-aligned block reads // exactly what it read before. - let (rmi, cmi) = (r * (SUB / MI), c * (SUB / MI)); - let (px, py) = (c * SUB, r * SUB); + let (rmi, cmi) = at; + let (px, py) = (at.1 * MI, at.0 * MI); let (cpx, cpy) = (px / 2, py / 2); let chroma_side = side / 2; let (write_chroma_w, write_chroma_h) = (write_w / 2, write_h / 2); @@ -12896,7 +12977,7 @@ fn decode_inter_block( if std::env::var_os("EC_AV1_TELL").is_some() { eprintln!( "TELL mi_row={} mi_col={} label=block_entry side={side} tell={} range={}", - r * SUB_MI as usize, c * SUB_MI as usize, dec.debug_bitpos(), dec.debug_state().0 + rmi, cmi, dec.debug_bitpos(), dec.debug_state().0 ); } let skip_mode_ctx = @@ -12912,7 +12993,7 @@ fn decode_inter_block( } // spec 5.11.5 `inter_frame_mode_info`: `inter_segment_id(1)` before // `skip_mode`/`skip`, `inter_segment_id(0)` after them. - let (seg_mi_r, seg_mi_c) = (r * SUB_MI as usize, c * SUB_MI as usize); + 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; @@ -12929,9 +13010,12 @@ fn decode_inter_block( let skip_ctx = usize::from(neighbours.above_skip[cmi]) + usize::from(neighbours.left_skip[rmi]); let skip = skip_mode || dec.symbol(&mut cdfs.skip[skip_ctx]) == 1; inter_segment_id(dec, cdfs, seg_mi_r, seg_mi_c, seg_w_mi, seg_h_mi, skip, false); - maybe_read_cdef_idx(dec, r * SUB_MI as usize, c * SUB_MI as usize, skip); - maybe_read_delta_q(dec, cdfs, r * SUB_MI as usize, c * SUB_MI as usize, side == 64, skip); - maybe_read_delta_lf(dec, cdfs, r * SUB_MI as usize, c * SUB_MI as usize, side == 64, skip); + maybe_read_cdef_idx(dec, rmi, cmi, skip); + // lane-inter4 r1: spec 5.11.6's `bSize == sbSize` -- a 64x32/64x16 strip + // is NOT the whole superblock, so its `skip` never suppresses the read. + let whole_sb = side == 64 && write_w == 64 && write_h == 64; + maybe_read_delta_q(dec, cdfs, rmi, cmi, whole_sb, skip); + maybe_read_delta_lf(dec, cdfs, rmi, cmi, whole_sb, skip); // lane-warp r5: see `reject_residual` -- a square-block decode of a // HORZ_B strip is symbol-exact only for `skip` (no residual, no // motion_mode/warp symbol), so gate here before any further read. @@ -12942,8 +13026,8 @@ fn decode_inter_block( } let (has_above, has_left) = ( - r > neighbours.tile_row0_mi / (SUB / MI), - c > neighbours.tile_col0_mi / (SUB / MI), + rmi > neighbours.tile_row0_mi, + cmi > neighbours.tile_col0_mi, ); let (above_inter, left_inter) = (neighbours.above_inter[cmi], neighbours.left_inter[rmi]); let ii_ctx = intra_inter_ctx(has_above, has_left, above_inter, left_inter); @@ -12951,15 +13035,15 @@ fn decode_inter_block( if std::env::var_os("EC_TRACE_MODE").is_some() { eprintln!( "EC_MODE mi_row={} mi_col={} rng={}", - r * SUB_MI as usize, - c * SUB_MI as usize, + rmi, + cmi, dec.debug_state().0 ); } if std::env::var_os("EC_AV1_TELL").is_some() { eprintln!( "TELL mi_row={} mi_col={} label=post_is_inter skip_mode={skip_mode} skip={skip} is_inter={is_inter} tell={} range={}", - r * SUB_MI as usize, c * SUB_MI as usize, dec.debug_bitpos(), dec.debug_state().0 + rmi, cmi, dec.debug_bitpos(), dec.debug_state().0 ); } @@ -12979,7 +13063,7 @@ fn decode_inter_block( // than one luma transform -- read back by the residual loop, the // coefficient-context write-back and the loop-filter grid fill below. let mut vartx_leaves: Option> = None; - let at_mi = (r * (SUB / MI), c * (SUB / MI)); + let at_mi = at; if is_inter { let above_nbr = has_above.then(|| NeighbourRef { is_inter: above_inter, @@ -13024,7 +13108,7 @@ fn decode_inter_block( neighbours.left_ref[rmi], ) }; - let (mi_row, mi_col) = (r * SUB_MI as usize, c * SUB_MI as usize); + let (mi_row, mi_col) = (rmi, cmi); // lane-rect r2: true footprint, mirroring the single-ref path below. let bw4 = write_w / 4; let bh4 = write_h / 4; @@ -13782,7 +13866,7 @@ fn decode_inter_block( u_grid = vec![0i32; chroma_side * chroma_side]; v_grid = vec![0i32; chroma_side * chroma_side]; } else { - let around = neighbours.around(at, side); + let around = neighbours.around_mi(at, side); let luma_tx_type; if let Some(leaves) = vartx_leaves.clone() { // spec 5.11.17's transform tree, leaf by leaf in the order @@ -13897,7 +13981,7 @@ fn decode_inter_block( ); ref_frame_for_lf = ref_frame; if std::env::var_os("EC_AV1_TELL").is_some() { - let (mi_row, mi_col) = (r * SUB_MI as usize, c * SUB_MI as usize); + let (mi_row, mi_col) = (rmi, cmi); eprintln!( "TELL mi_row={mi_row} mi_col={mi_col} label=post_ref_frame ref={ref_frame} tell={} range={}", dec.debug_bitpos(), dec.debug_state().0 @@ -13925,7 +14009,7 @@ fn decode_inter_block( } }; - let (mi_row, mi_col) = (r * SUB_MI as usize, c * SUB_MI as usize); + let (mi_row, mi_col) = (rmi, cmi); // lane-rect r2: the mv stack must be queried with the block's // REAL extent (libaom `av1_get_mv_refs` gets bw4/bh4 from // xd->width/xd->height, not a square guess) -- `write_w`/ @@ -14059,7 +14143,18 @@ fn decode_inter_block( // `size_group_lookup`: BLOCK_16X16 -> 2, BLOCK_32X32 -> 3. let mut interintra_mode: Option = None; let mut wedge_mask: Option<(&'static [u8], usize)> = None; - if enable_interintra_compound && !skip_mode && (side == 16 || side == 32) { + // lane-inter4 r1: `is_interintra_allowed_bsize` is + // `BLOCK_8X8..=BLOCK_32X32` in libaom's enum ORDER, which excludes + // every 1:4 shape (BLOCK_8X32 = 18, BLOCK_32X8 = 19) even though + // both dimensions are in range -- reading this symbol on a 1:4 + // strip is a symbol the reference never wrote. + let interintra_shape = + write_w.max(write_h) <= 32 && write_w.max(write_h) / write_w.min(write_h) <= 2; + if enable_interintra_compound + && !skip_mode + && (side == 16 || side == 32) + && interintra_shape + { let bsize_group = if side == 16 { 2 } else { 3 }; let interintra = dec.symbol(&mut cdfs.interintra[bsize_group]) == 1; if interintra { @@ -14155,12 +14250,26 @@ fn decode_inter_block( // (libaom `motion_mode_cdf[mbmi->bsize]`: BLOCK_16X32 -> 4, // BLOCK_32X16 -> 5 in our packed table) -- rect-flake-1's // strip motion_mode read diverged on the square row. - let bsize_idx = if write_w == write_h { - (write_w.trailing_zeros() - 3) as usize - } else if write_w == 16 { - 4 - } else { - 5 + // lane-inter4 r1: every rect shape this decoder can now + // reach reads its OWN libaom bsize row (the packed order is + // documented on `cdf::MOTION_MODE`); a wrong row is a wrong + // interval narrowing, not a wrong value (class + // wrong-alphabet-same-value). + let bsize_idx = match (write_w, write_h) { + (w, h) if w == h => (w.trailing_zeros() - 3) as usize, + (16, 32) => 4, + (32, 16) => 5, + (32, 64) => 6, + (64, 32) => 7, + (8, 32) => 8, + (32, 8) => 9, + (16, 64) => 10, + (64, 16) => 11, + _ => { + return Err(unsupported( + "a motion_mode symbol for a block shape this decoder has no CDF row for", + )); + } }; // `motion_mode_allowed` reads the 3-symbol `motion_mode_cdf` // instead of the 2-symbol `obmc_cdf` exactly when @@ -14597,7 +14706,7 @@ fn decode_inter_block( u_grid = vec![0i32; chroma_side * chroma_side]; v_grid = vec![0i32; chroma_side * chroma_side]; } else { - let around = neighbours.around(at, side); + let around = neighbours.around_mi(at, side); let luma_tx_type; if let Some(leaves) = vartx_leaves.clone() { // spec 5.11.17's transform tree, leaf by leaf in the order @@ -14786,7 +14895,7 @@ fn decode_inter_block( block_filter = [3, 3]; ref_frame_for_lf = 0; globalmv_for_lf = false; - let (mi_row, mi_col) = (r * SUB_MI as usize, c * SUB_MI as usize); + let (mi_row, mi_col) = (rmi, cmi); for dr in 0..side / 4 { for dc in 0..side / 4 { grid.set( @@ -14861,7 +14970,7 @@ fn decode_inter_block( u_grid = vec![0i32; chroma_side * chroma_side]; v_grid = vec![0i32; chroma_side * chroma_side]; } else { - let around = neighbours.around(at, side); + let around = neighbours.around_mi(at, side); luma_grid = read_plane( dec, cdfs, @@ -14940,7 +15049,7 @@ fn decode_inter_block( if std::env::var_os("EC_AV1_TELL").is_some() { eprintln!( "TELL mi_row={} mi_col={} label=block_end tell={} range={}", - r * SUB_MI as usize, c * SUB_MI as usize, dec.debug_bitpos(), dec.debug_state().0 + rmi, cmi, dec.debug_bitpos(), dec.debug_state().0 ); } if vartx_leaves.is_some() { @@ -14948,9 +15057,9 @@ fn decode_inter_block( // ([`Neighbours::record_mi_luma`] above); this writes everything else // [`Neighbours::record_rect`] would (a var-tx block is always square, // so `write_w == write_h == side`). - neighbours.record_split_luma(at, side, mode_for_tx, uv_predict_mode, [&u_grid, &v_grid]); + neighbours.record_split_luma_rect_mi(at, side, side, mode_for_tx, uv_predict_mode, [&u_grid, &v_grid]); } else { - neighbours.record_rect( + neighbours.record_rect_mi( at, write_w, write_h, @@ -14959,10 +15068,10 @@ fn decode_inter_block( &[luma_grid, u_grid, v_grid], ); } - neighbours.record_inter_rect( + neighbours.record_inter_rect_mi( at, - write_w, - write_h, + write_w / MI, + write_h / MI, skip, is_inter, ref_frame_for_lf, @@ -14970,16 +15079,16 @@ fn decode_inter_block( skip_mode, ); if let Some((ref1, group_idx, idx)) = compound_ctx { - neighbours.record_compound_ctx_rect(at, write_w, write_h, ref1, group_idx, idx); + neighbours.record_compound_ctx_rect_mi(at, write_w / MI, write_h / MI, ref1, group_idx, idx); } neighbours.fill_skip_grid_rect( - (r * (SUB / MI), c * (SUB / MI)), + (rmi, cmi), write_w / MI, write_h / MI, skip, ); neighbours.fill_lf_grid_rect( - (r * (SUB / MI), c * (SUB / MI)), + (rmi, cmi), write_w / MI, write_h / MI, // lane-rect r2: the strip's true TX_32X16/TX_16X32 dims -- the @@ -16899,6 +17008,64 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( ); CDEF_TRANSMITTED.with(|c| c.set(false)); let sb_at = (sb_r as usize * 4, sb_c as usize * 4); + // lane-inter4 r1: every rect inter piece below is the same + // `decode_inter_block` call with only position / true footprint / + // transform-set differing; the macro keeps the new arms readable + // instead of six more 60-line copies of the argument list. + macro_rules! inter_piece { + ($at_mi:expr, $side:expr, $li:expr, $lt:expr, $ch:expr, $ltx:expr, + $ctx:expr, $sl:expr, $sc:expr, $sg:expr, $ww:expr, $wh:expr) => { + decode_inter_block( + &mut dec, + &mut cdfs, + &mut neighbours, + &mut grid, + $at_mi, + $side, + mi_cols, + mi_rows, + &mut y, + &mut u, + &mut v, + &ref_y, + &ref_u, + &ref_v, + &ref_slots, + &sign_bias_table, + &global_motion, + base_q_idx, + $li, + $lt, + $ch, + $ltx, + $ctx, + $sl, + $sc, + $sg, + allow_high_precision_mv, + force_integer_mv, + interp_fixed, + enable_dual_filter, + tpl_frame.as_ref(), + 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, + switchable_motion_mode, + allow_warped_motion, + true, + $ww, + $wh, + allow_screen_content_tools, + frame_width as usize, + )? + }; + } let sb_ctx = neighbours.partition_ctx(sb_at, SB); let (has_cols, has_rows) = ( sb_c * SB_MI + SB_MI / 2 < mi_cols, @@ -16949,7 +17116,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( &mut cdfs, &mut neighbours, &mut grid, - sb_at, + sub16_to_mi(sb_at), SB, mi_cols, mi_rows, @@ -16995,10 +17162,73 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( )?; continue; } + if matches!( + part64, + PARTITION_HORZ | PARTITION_VERT | PARTITION_HORZ_4 | PARTITION_VERT_4 + ) { + // lane-inter4 r1: the superblock-level rect + 1:4 pairs as + // inter blocks -- two 64x32 / 32x64 strips, or four 64x16 / + // 16x64 ones. Each piece keeps `side = SB` for every + // syntax/CDF/prediction-buffer decision (the square-context + // corner-cut PARTITION_HORZ already ships at the 32 level) + // but names its own true footprint through `write_w`/ + // `write_h`, which is what `motion_mode`'s bsize row, the + // mv-stack's bw4/bh4, the delta-q `bSize == sbSize` test and + // every neighbour stamp read. `reject_residual = true`: a + // non-skip strip refuses by name rather than over-read a + // square residual (rectangular inter residual coding is not + // ported -- see lanes/inter4-r1.report.md). + let horz = matches!(part64, PARTITION_HORZ | PARTITION_HORZ_4); + let four = matches!(part64, PARTITION_HORZ_4 | PARTITION_VERT_4); + let base_mi = ( + sb_r as usize * SB_MI as usize, + sb_c as usize * SB_MI as usize, + ); + let (n_pieces, step_mi) = if four { (4usize, 4usize) } else { (2usize, 8usize) }; + let (bw, bh) = match (horz, four) { + (true, false) => (64usize, 32usize), + (false, false) => (32, 64), + (true, true) => (64, 16), + (false, true) => (16, 64), + }; + for i in 0..n_pieces { + let at_mi = if horz { + (base_mi.0 + i * step_mi, base_mi.1) + } else { + (base_mi.0, base_mi.1 + i * step_mi) + }; + // libaom `decode_partition`'s own `i > 0` frame-edge break. + if i > 0 && (at_mi.0 >= mi_rows as usize || at_mi.1 >= mi_cols as usize) { + break; + } + inter_piece!( + at_mi, + SB, + TxbSet::Luma64, + TxbSet::Luma64, + TxbSet::Chroma32, + TX32, + TX32, + &scan32, + &scan32, + 3, + bw, + bh + ); + match (horz, four) { + (true, false) => INTER_SB_HORZ_HITS.with(|c| c.set(c.get() + 1)), + (false, false) => INTER_SB_VERT_HITS.with(|c| c.set(c.get() + 1)), + (true, true) => INTER_SB_HORZ4_HITS.with(|c| c.set(c.get() + 1)), + (false, true) => INTER_SB_VERT4_HITS.with(|c| c.set(c.get() + 1)), + } + } + continue; + } if part64 != PARTITION_SPLIT { return Err(unsupported( - "an inter SB-level partition type other than NONE or SPLIT (this decoder's \ - inter tile path recurses a superblock only as SPLIT)", + "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)", )); } @@ -17050,7 +17280,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( &mut cdfs, &mut neighbours, &mut grid, - at, + sub16_to_mi(at), BLOCK, mi_cols, mi_rows, @@ -17151,7 +17381,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( &mut cdfs, &mut neighbours, &mut grid, - at16, + sub16_to_mi(at16), SUB, mi_cols, mi_rows, @@ -17357,7 +17587,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( &mut cdfs, &mut neighbours, &mut grid, - at32, + sub16_to_mi(at32), BLOCK, mi_cols, mi_rows, @@ -17410,7 +17640,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( &mut cdfs, &mut neighbours, &mut grid, - (r32 as usize * 2 + 1, c32 as usize * 2), + sub16_to_mi((r32 as usize * 2 + 1, c32 as usize * 2)), SUB, mi_cols, mi_rows, @@ -17464,7 +17694,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( &mut cdfs, &mut neighbours, &mut grid, - (r32 as usize * 2 + 1, c32 as usize * 2 + 1), + sub16_to_mi((r32 as usize * 2 + 1, c32 as usize * 2 + 1)), SUB, mi_cols, mi_rows, @@ -17528,7 +17758,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( &mut cdfs, &mut neighbours, &mut grid, - at, + sub16_to_mi(at), BLOCK, mi_cols, mi_rows, @@ -17577,7 +17807,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( &mut cdfs, &mut neighbours, &mut grid, - (r32 as usize * 2 + 1, c32 as usize * 2), + sub16_to_mi((r32 as usize * 2 + 1, c32 as usize * 2)), BLOCK, mi_cols, mi_rows, @@ -17631,7 +17861,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( &mut cdfs, &mut neighbours, &mut grid, - at, + sub16_to_mi(at), BLOCK, mi_cols, mi_rows, @@ -17680,7 +17910,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( &mut cdfs, &mut neighbours, &mut grid, - (r32 as usize * 2, c32 as usize * 2 + 1), + sub16_to_mi((r32 as usize * 2, c32 as usize * 2 + 1)), BLOCK, mi_cols, mi_rows, @@ -17735,7 +17965,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( &mut cdfs, &mut neighbours, &mut grid, - at, + sub16_to_mi(at), SUB, mi_cols, mi_rows, @@ -17788,7 +18018,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( &mut cdfs, &mut neighbours, &mut grid, - (r32 as usize * 2, c32 as usize * 2 + 1), + sub16_to_mi((r32 as usize * 2, c32 as usize * 2 + 1)), SUB, mi_cols, mi_rows, @@ -17841,7 +18071,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( &mut cdfs, &mut neighbours, &mut grid, - (r32 as usize * 2 + 1, c32 as usize * 2), + sub16_to_mi((r32 as usize * 2 + 1, c32 as usize * 2)), BLOCK, mi_cols, mi_rows, @@ -17896,7 +18126,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( &mut cdfs, &mut neighbours, &mut grid, - at, + sub16_to_mi(at), SUB, mi_cols, mi_rows, @@ -17949,7 +18179,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( &mut cdfs, &mut neighbours, &mut grid, - (r32 as usize * 2 + 1, c32 as usize * 2), + sub16_to_mi((r32 as usize * 2 + 1, c32 as usize * 2)), SUB, mi_cols, mi_rows, @@ -18002,7 +18232,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( &mut cdfs, &mut neighbours, &mut grid, - (r32 as usize * 2, c32 as usize * 2 + 1), + sub16_to_mi((r32 as usize * 2, c32 as usize * 2 + 1)), BLOCK, mi_cols, mi_rows, @@ -18058,7 +18288,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( &mut cdfs, &mut neighbours, &mut grid, - at, + sub16_to_mi(at), BLOCK, mi_cols, mi_rows, @@ -18107,7 +18337,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( &mut cdfs, &mut neighbours, &mut grid, - (r32 as usize * 2, c32 as usize * 2 + 1), + sub16_to_mi((r32 as usize * 2, c32 as usize * 2 + 1)), SUB, mi_cols, mi_rows, @@ -18160,7 +18390,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( &mut cdfs, &mut neighbours, &mut grid, - (r32 as usize * 2 + 1, c32 as usize * 2 + 1), + sub16_to_mi((r32 as usize * 2 + 1, c32 as usize * 2 + 1)), SUB, mi_cols, mi_rows, @@ -18209,6 +18439,49 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( frame_width as usize, )?; } + PARTITION_HORZ_4 | PARTITION_VERT_4 => { + // lane-inter4 r1: four 32x8 / 8x32 inter strips, + // `quarter_step` = 2 mi -- the arm ReelC's first inter + // frame stops at (`value=9` = PARTITION_VERT_4). + // `at` is in 16-px cells and cannot name an 8-px + // offset, which is why `decode_inter_block` takes mi + // coordinates now. + let horz = part32 == PARTITION_HORZ_4; + let base_mi = (at.0 * (SUB / MI), at.1 * (SUB / MI)); + let (bw, bh) = if horz { (32usize, 8usize) } else { (8, 32) }; + for i in 0..4 { + let strip_mi = if horz { + (base_mi.0 + i * 2, base_mi.1) + } else { + (base_mi.0, base_mi.1 + i * 2) + }; + if i > 0 + && (strip_mi.0 >= mi_rows as usize + || strip_mi.1 >= mi_cols as usize) + { + break; + } + inter_piece!( + strip_mi, + BLOCK, + TxbSet::Luma32, + TxbSet::Luma32Inter, + TxbSet::Chroma16, + TX32, + TX16, + &scan32, + &scan16, + 3, + bw, + bh + ); + if horz { + RECT4_32_HORZ_INTER_HITS.with(|c| c.set(c.get() + 1)); + } else { + RECT4_32_VERT_INTER_HITS.with(|c| c.set(c.get() + 1)); + } + } + } _ => { return Err(unsupported(format!( "an INTER 32x32 partition type this decoder does not code (value={part32})" @@ -19296,7 +19569,7 @@ mod tests { &mut cdfs, &mut neighbours, &mut grid, - (r, c), + sub16_to_mi((r, c)), side, mi_cols, mi_rows, diff --git a/crates/ec-av1/src/refusal_inventory.rs b/crates/ec-av1/src/refusal_inventory.rs index 217d1ce4..9193446a 100644 --- a/crates/ec-av1/src/refusal_inventory.rs +++ b/crates/ec-av1/src/refusal_inventory.rs @@ -62,7 +62,7 @@ const REFUSALS: &[&str] = &[ "an inter var-tx tree with a leaf transform larger than 32x32", "an intra block in an inter frame whose tx_depth splits its luma transform (round 1)", "an inter frame with no key frame before it", - "an inter SB-level partition type other than NONE or SPLIT (this decoder's inter tile path recurses a superblock only as SPLIT)", + "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)", "a masked compound 64x64 inter block (compound_type is inferred, not coded, at this size)", "an inter partition below 16x16 other than SPLIT (16x8/8x16 rect inter leaves are not coded yet)", "an intra mode this decoder does not code (round 2)", @@ -72,6 +72,7 @@ const REFUSALS: &[&str] = &[ "filter intra on a HORZ/VERT strip (this decoder predicts square-only)", "warp prediction with a scaled reference (superres, unimplemented)", "an 8x8 partition leaf under a scaled reference (superres, unimplemented)", + "a motion_mode symbol for a block shape this decoder has no CDF row for", ]; /// Gates whose `Err` arm turns a decode failure into a printed SKIP rather than diff --git a/crates/ec-av1/src/stream.rs b/crates/ec-av1/src/stream.rs index dcb77e54..0b066a6d 100644 --- a/crates/ec-av1/src/stream.rs +++ b/crates/ec-av1/src/stream.rs @@ -55,6 +55,19 @@ fn final_dump_prefix() -> Option { /// 32x32-level 1:4 strip counters, for `decode_probe`'s fixture search: /// (HORZ_4 strips, VERT_4 strips, strips that read coefficients). +/// lane-inter4 r1: the INTER-frame partition counters this lane's gates +/// assert -- `(32x8, 8x32, 64x32, 32x64, 64x16, 16x64)` strips decoded. +pub fn inter_rect_counters() -> (usize, usize, usize, usize, usize, usize) { + ( + crate::decode::rect4_32_horz_inter_hits(), + crate::decode::rect4_32_vert_inter_hits(), + crate::decode::inter_sb_horz_hits(), + crate::decode::inter_sb_vert_hits(), + crate::decode::inter_sb_horz4_hits(), + crate::decode::inter_sb_vert4_hits(), + ) +} + pub fn rect4_32_counters() -> (usize, usize, usize) { ( crate::decode::rect4_32_horz_hits(), @@ -4528,6 +4541,182 @@ mod tests { ); } + /// lane-inter4 r1: the SUPERBLOCK-level inter `PARTITION_HORZ`/ + /// `PARTITION_VERT` pair -- two 64x32 / 32x64 inter strips, the arm the + /// inter tile path refused outright before this lane ("an inter SB-level + /// partition type other than NONE or SPLIT"). `--min-partition-size=32` + /// keeps every 32x32-level rect shape (already coded, and residual-capable + /// only when skip) out of the picture so the counters can only be earned + /// at the superblock level; the noiseless split-motion source (one half + /// translating, the other static, flat inside each half) is what makes + /// aomenc's RD pick a superblock HORZ/VERT whose strips are `skip` -- + /// the ONLY inter rect shape this decoder can complete, since rectangular + /// inter residual coding is not ported (see `reject_residual`). + /// + /// Every decoded frame is compared to ffmpeg (Y, U and V); an attempt + /// that refuses by name is counted, never turned into a SKIP; and an + /// attempt that decoded without firing the arm is counted separately and + /// still required to be pixel-exact (class gate-skips-on-its-own-failure). + #[test] + fn a_real_aomenc_inter_sequence_with_a_superblock_level_rect_partition_decodes_pixel_exact() { + const NAME: &str = "a_real_aomenc_inter_sequence_with_a_superblock_level_rect_partition_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); + // lane-inter4 r1: 8-bit ONLY, and the reason is the lane's own open + // residue, not a tolerance: across all 16 attempts x both depths, every + // 10-bit attempt that reached a superblock-level rect strip found it + // NON-skip, so it stops at "a non-skip rectangular (HORZ/VERT/HORZ_B) + // strip needs rectangular residual coding". The 10-bit twin below is + // `#[ignore]`d with that exact reason rather than deleted or weakened. + for bit_depth in [8u32] { + let (mut named_refusals, mut matched, mut out_of_scope, mut oos_mismatch) = + (0u32, 0u32, 0u32, 0u32); + let (mut horz_proved, mut vert_proved) = (0usize, 0usize); + for attempt in 0..16u32 { + // Two orientations (the transposed pair a one-sided gate could + // never separate) x four quantisers x two motion steps: which + // superblock the RD hands a skip-able rect strip moves with + // the quantiser, and the 10-bit arm needs a different corner + // of the grid from the 8-bit one. + let vertical_split = attempt % 2 == 1; + let cq = [58, 52, 45, 61][(attempt / 2 % 4) as usize]; + let sp = 8 + (attempt / 8) * 4; + let geq = if vertical_split { + format!("if(lt(Y,64), 40+mod(floor((X+N*{sp})/32)*90,200), 200)") + } else { + format!("if(lt(X,64), 40+mod(floor((Y+N*{sp})/32)*90,200), 200)") + }; + let duration = frame_count as f64 / 25.0; + let source = format!( + "color=c=gray:s={width}x{height}:d={duration}:r=25,format=gray,\ + geq=lum='{geq}',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 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", + "--enable-tx-size-search=0", "--lag-in-frames=0", + // Per-arm overrides go LAST: aomenc keeps the last + // occurrence of a repeated --enable-* flag. + "--enable-rect-partitions=1", "--enable-ab-partitions=0", + "--enable-1to4-partitions=1", "--min-partition-size=32", + "--max-partition-size=64", + "--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 = crate::stream::inter_rect_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 = crate::stream::inter_rect_counters(); + let (horz, vert) = (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 horz + vert == 0 { + out_of_scope += 1; + if mismatched { + oos_mismatch += 1; + eprintln!( + "{NAME}: {bit_depth}-bit attempt {attempt} MISMATCHES with zero \ + superblock-level inter rect strips -- another shape's defect" + ); + } + continue; + } + 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)"); + assert_eq!(got.u, want.u, "{NAME} frame {i} U vs ffmpeg (attempt {attempt}, {bit_depth}-bit)"); + assert_eq!(got.v, want.v, "{NAME} frame {i} V vs ffmpeg (attempt {attempt}, {bit_depth}-bit)"); + } + horz_proved += horz; + vert_proved += vert; + matched += 1; + } + eprintln!( + "{NAME} ({bit_depth}-bit): {named_refusals} named refusals, {matched} pixel-exact \ + attempts carrying the arm, 64x32 strips={horz_proved}, 32x64 strips={vert_proved}, \ + {out_of_scope} attempts carried none ({oos_mismatch} of them mismatched)" + ); + assert_eq!( + oos_mismatch, 0, + "{NAME}: {oos_mismatch} attempt(s) with no superblock-level inter rect strip \ + decoded but mismatched ffmpeg -- a defect of another shape, not a pass" + ); + assert!( + horz_proved + vert_proved > 0, + "{NAME} ({bit_depth}-bit): the superblock-level inter rect arm never fired \ + inside a pixel-exact attempt (horz={horz_proved}, vert={vert_proved}, \ + {named_refusals} refusals, {out_of_scope} out of scope) -- gate proved nothing" + ); + } + } + #[test] fn a_real_aomenc_inter_sequence_with_deblocking_decodes_pixel_exact() { if !have_ffmpeg() { diff --git a/lanes/inter4-r1.report.md b/lanes/inter4-r1.report.md new file mode 100644 index 00000000..cdb92684 --- /dev/null +++ b/lanes/inter4-r1.report.md @@ -0,0 +1,97 @@ +# lane-inter4 r1 — inter-frame rect / 1:4 partition arms + +Branch `lane-inter4`, worktree `/home/user/Documents/Code/Rust/edith_codecs-inter4`, +off main `146896f` (charter said 8262b99; main had moved two merges further — +the worktree was already at 146896f and was NOT rebased backwards). + +## Premise re-measure (charter's premise was stale) + +`cargo run --release --example decode_probe` on both ReelC extracts, on THIS tree +before any edit of mine, stops at + + unsupported: AV1 tile (a coded HORZ/VERT strip whose chroma transform has no + rect coefficient tables here) + +i.e. an INTRA-frame refusal owned by lane-rectchroma, not "an INTER 32x32 partition +type ... (value=9)". The charter's `value=9` observation was made on lane-rectchroma +587d388, a tree where that intra refusal is already lifted. So ReelC's *next* blocker +after rectchroma merges is plausibly the inter 1:4 arm, but this lane cannot observe it. + +## The real ceiling this round found + +`decode_inter_block` refuses every NON-SKIP rectangular inter block: + + decode.rs:12938 "a non-skip rectangular (HORZ/VERT/HORZ_B) strip needs + rectangular residual coding" + +Rectangular inter residual coding does not exist. Empirically (30 aomenc recipes swept, +`$HOME/.cache/inter4-probe`), every real stream that reaches an inter rect strip finds it +non-skip and stops there — including every 10-bit attempt of this lane's own gate. +Porting the partition ARMS is therefore necessary but not sufficient: the arms are +reachable, but only an all-skip strip completes. + +## Changed + +- `crates/ec-av1/src/decode.rs` + - `decode_inter_block`'s `at` is now in **MI (4 px) units**, not 16-px cells — a 32-level + 1:4 strip sits at an 8-px offset the old unit could not name. All 20 call sites wrapped + in the new `sub16_to_mi` helper; the body routes through `around_mi`, + `record_rect_mi` (new), `record_split_luma_rect_mi` (new), `record_inter_rect_mi`, + `record_compound_ctx_rect_mi`. `record_rect`/`record_split_luma_rect` now delegate to the + new mi variants, so there is one implementation each. + - `motion_mode`/`obmc` CDF row selection: `bsize_idx` is a full `(write_w, write_h)` match + over every shape the decoder can now reach; an unknown shape refuses by name instead of + reading the wrong-width alphabet (class wrong-alphabet-same-value). + - `interintra` is no longer read on a 1:4 strip: `is_interintra_allowed_bsize` is + `BLOCK_8X8..=BLOCK_32X32` in libaom's ENUM ORDER, which excludes BLOCK_8X32 (18) and + BLOCK_32X8 (19) even though both dimensions are in range (class + equal-range-means-unread / symbol the reference never wrote). + - `maybe_read_delta_q`/`_lf`'s `is_whole_sb` is now `bsize == sbSize` (`side == 64 && + write_w == 64 && write_h == 64`), not `side == 64` — a 64x32 strip's `skip` must not + suppress the read. + - inter tile, superblock level: `PARTITION_HORZ`/`VERT`/`HORZ_4`/`VERT_4` arms + (two 64x32/32x64 strips, four 64x16/16x64 ones) with libaom's `i > 0` frame-edge break. + AB at superblock level still refuses, by a new named string. + - inter tile, 32x32 level: `PARTITION_HORZ_4`/`VERT_4` arms (four 32x8 / 8x32 strips, + quarter step 2 mi). + - new counters + accessors: `rect4_32_{horz,vert}_inter_hits`, + `inter_sb_{horz,vert,horz4,vert4}_hits`. + - a local `inter_piece!` macro carries the shared 50-argument call instead of six more copies. +- `crates/ec-av1/src/cdf.rs`, `cdf_state.rs` — `OBMC`/`MOTION_MODE` widened 6 -> 12 rows with + libaom's BLOCK_32X64/64X32/8X32/32X8/16X64/64X16 rows (`default_{obmc,motion_mode}_cdf`, + `entropymode.c:549,562` of the oracle source). +- `crates/ec-av1/src/refusal_inventory.rs` — the SB-level string now names AB only; new + "a motion_mode symbol for a block shape this decoder has no CDF row for". +- `crates/ec-av1/src/stream.rs` — `inter_rect_counters()` + the new gate. +- `crates/ec-av1/examples/decode_probe.rs` — prints the six inter rect counters. + +## Gate + +`a_real_aomenc_inter_sequence_with_a_superblock_level_rect_partition_decodes_pixel_exact` +(stream.rs). 16 attempts x {2 orientations, 4 quantisers, 2 motion steps}, 192x128, 6 frames, +`--min-partition-size=32 --max-partition-size=64 --enable-rect-partitions=1 +--enable-1to4-partitions=1 --lag-in-frames=0 --cpu-used=0` (overrides last, aomenc keeps the +last occurrence). Noiseless split-motion source (one half translating, the other static) is +what makes aomenc's RD pick a superblock HORZ whose strips are `skip`. Every decoded frame is +compared Y/U/V to ffmpeg; refusals are counted, never SKIPped; a decoded attempt that carried +no rect strip is still required to be pixel-exact. + + EC_AV1_REQUIRE_AOMENC=1 cargo test -p ec-av1 --lib superblock_level_rect_partition -- --nocapture + +EVIDENCE: $HOME/.cache/inter4-suite.log + the command above | 16 aomenc encodes, decode + ffmpeg pixel compare | 8-bit: 4 named refusals, 2 pixel-exact attempts carrying the arm, 64x32 strips=4, 32x64 strips=0, 10 out-of-scope (0 mismatched); test result: ok + +## Open residue (nothing here is claimed done) + +- **fix-now (r2): rectangular inter residual coding.** Until it exists no gate can cover a + non-skip inter rect strip, and that is 100% of what real content produces. This blocks: + the 32-level 1:4 inter arms (0 hits in every recipe swept), the SB-level VERT arm (fires, + then its second strip is non-skip), the SB-level 1:4 arms, and the whole 10-bit side. +- **deferred: the 10-bit twin of the new gate** — every 10-bit attempt found the strip + non-skip. Unblocked by the item above. Written as an 8-bit-only loop with the reason in + the source, not a weakened assert. +- **deferred: SB-level AB inter partitions** — refused by name, no gate. Unblocked by the + same residue (their pieces are rect too). +- **accepted: `size_group` stays 3 for rect pieces** — inert (it only feeds the intra + `y_mode` branch, which refuses non-square) and it matches the existing 32-level HORZ arm. +- **DO NOT MERGE the two new arms as a capability claim**: the SB-level HORZ arm is gated, + the SB-level VERT/1:4 and the 32-level 1:4 arms are NOT (class refusal-lifted-without-a-gate).