diff --git a/crates/ec-av1/examples/decode_probe.rs b/crates/ec-av1/examples/decode_probe.rs index 3a78f5fc..a857dc00 100644 --- a/crates/ec-av1/examples/decode_probe.rs +++ b/crates/ec-av1/examples/decode_probe.rs @@ -35,6 +35,9 @@ 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}"); + println!("sub8_inter_split: groups={}", ec_av1::decode::sub8_inter_split_hits()); + let (h84, h48) = ec_av1::decode::sub8_inter_rect_hits(); + println!("sub8_inter_rect: horz8x4={h84} vert4x8={h48}"); let leaf = ec_av1::stream::vartx_rect_leaf_hits(); println!("vartx_rect_leaf: 32x16={} 16x32={}", leaf[0], leaf[1]); // lane-inter16ab r1: the 16x16-level inter AB arms, so a recipe sweep diff --git a/crates/ec-av1/src/cdf_state.rs b/crates/ec-av1/src/cdf_state.rs index 89334535..19c9b910 100644 --- a/crates/ec-av1/src/cdf_state.rs +++ b/crates/ec-av1/src/cdf_state.rs @@ -230,6 +230,22 @@ pub(crate) enum TxbSet { /// counterpart: `EXT_TX_SET_DTT4_IDTX_1DDCT`, the seven-symbol `TX_4X4` /// row [`LumaRect4x8Set1`](TxbSet::LumaRect4x8Set1) reads. LumaRect16x4Set1, + /// The luma 8x4/4x8 transform of an INTER `PARTITION_HORZ`/`PARTITION_VERT` + /// leaf under an 8x8 block (lane-intersub8 r3): every coefficient table is + /// [`LumaRect4x8`](TxbSet::LumaRect4x8)'s (`get_txsize_entropy_ctx` squares + /// `TX_8X4` up to the 8x8 class, 32-position `eob_pt`), with the INTER + /// `tx_type` alphabet in its place. Under `reduced_tx_set` + /// `av1_get_ext_tx_set_type` (`tx_size_sqr_up == TX_8X8`, `is_inter`) + /// returns `EXT_TX_SET_DCT_IDTX`, whose row is + /// `default_inter_ext_tx_cdf[?][txsize_sqr_map[TX_8X4] == TX_4X4]` -- the + /// same `TX_4X4` inter row [`Luma4Inter`](TxbSet::Luma4Inter) reads. + LumaRect8x4Inter, + /// [`LumaRect8x4Inter`](TxbSet::LumaRect8x4Inter)'s `reduced_tx_set: false` + /// counterpart: `tx_size_sqr == TX_4X4` with `tx_size_sqr_up == TX_8X8`, so + /// `av1_ext_tx_set_lookup[is_inter=1][...]` is `EXT_TX_SET_ALL16` -- sixteen + /// symbols at the `TX_4X4` inter row, the table + /// [`Luma4InterSet1`](TxbSet::Luma4InterSet1) also reads. + LumaRect8x4InterSet1, } /// The tables one transform block is coded with, borrowed from the state for @@ -1792,6 +1808,30 @@ impl Cdfs { tx_type: Some(self.intra_tx_type_4[mode].as_mut_slice()), eob_pt_class1: Some(&mut self.eob_pt_32_luma_class1), }, + TxbSet::LumaRect8x4Inter => TxbTables { + side: 8, + txb_skip: &mut self.txb_skip_luma_8, + eob_pt: &mut self.eob_pt_32_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_32_luma_class1), + }, + TxbSet::LumaRect8x4InterSet1 => TxbTables { + side: 8, + txb_skip: &mut self.txb_skip_luma_8, + eob_pt: &mut self.eob_pt_32_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_32_luma_class1), + }, TxbSet::LumaRect4x8Set1 => TxbTables { side: 8, txb_skip: &mut self.txb_skip_luma_8, diff --git a/crates/ec-av1/src/decode.rs b/crates/ec-av1/src/decode.rs index cf1cede3..2bd277ca 100644 --- a/crates/ec-av1/src/decode.rs +++ b/crates/ec-av1/src/decode.rs @@ -2643,6 +2643,21 @@ pub(crate) fn tx_class1_hits() -> usize { // coincidentally landing on `PARTITION_NONE`. thread_local! { static SUB8_SPLIT_HITS: std::cell::Cell = const { std::cell::Cell::new(0) }; + /// How many 8x8 groups an INTER frame split into four BLOCK_4X4 inter + /// sub-blocks (lane-intersub8). + static SUB8_INTER_SPLIT_HITS: std::cell::Cell = const { std::cell::Cell::new(0) }; + /// How many 8x8 groups an INTER frame split into two rectangular sub-8x8 + /// inter leaves (lane-intersub8 r3), indexed `[0] = HORZ` (two BLOCK_8X4), + /// `[1] = VERT` (two BLOCK_4X8). + static SUB8_INTER_RECT_HITS: std::cell::Cell<[usize; 2]> = const { std::cell::Cell::new([0; 2]) }; +} + +/// Current value of [`SUB8_INTER_RECT_HITS`]: `(8x4 groups, 4x8 groups)`. +pub fn sub8_inter_rect_hits() -> (usize, usize) { + SUB8_INTER_RECT_HITS.with(|c| { + let h = c.get(); + (h[0], h[1]) + }) } /// Current value of [`SUB8_SPLIT_HITS`]. @@ -2650,6 +2665,11 @@ pub(crate) fn sub8_split_hits() -> usize { SUB8_SPLIT_HITS.with(|c| c.get()) } +/// Current value of [`SUB8_INTER_SPLIT_HITS`]. +pub fn sub8_inter_split_hits() -> usize { + SUB8_INTER_SPLIT_HITS.with(|c| c.get()) +} + // How many 4x8 / 8x4 leaves (lane-tx4x8's `PARTITION_VERT`/`PARTITION_HORZ` // of an 8x8 block) this thread's decode reconstructed with REAL coefficients // -- a skipped leaf exercises the prediction and the mi bookkeeping but never @@ -15104,6 +15124,12 @@ fn resolve_interp_filter( if enable_dual_filter && sym0 != sym1 { DUAL_FILTER_DIFF_HITS.with(|c| c.set(c.get() + 1)); } + if std::env::var_os("EC_TRACE_MODE").is_some() { + eprintln!( + "EC_IF ctx0={ctx0} above={above:?} left={left:?} sym0={sym0} sym1={sym1} rng={}", + dec.debug_state().0 + ); + } ( mc::InterpFilterKind::from_switchable_symbol(sym1 as usize), mc::InterpFilterKind::from_switchable_symbol(sym0 as usize), @@ -16170,6 +16196,67 @@ fn is_any_masked_compound_used_here(side: usize) -> bool { side.min(side) >= 8 } +/// libaom's `BLOCK_SIZES_ALL` index of a `w`x`h` block (`common_data.h`'s own +/// enum order) -- the row every bsize-indexed CDF (`compound_type_cdf`, +/// `wedge_idx_cdf`) is read at. lane-intersub8 r4: these two used to be +/// indexed by the caller's SQUARE envelope, so a 16x8 compound block read +/// `BLOCK_16X16`'s row (class table-indexed-by-raw-size) and desynced the +/// tile at its first masked-compound rect block. +fn bsize_index(w: usize, h: usize) -> Option { + Some(match (w, h) { + (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, + }) +} + +/// `is_any_masked_compound_used` (libaom `reconinter.h`) on the block's TRUE +/// footprint: `is_comp_ref_allowed` is `AOMMIN(bw, bh) >= 8`, and every +/// shape that clears it has either a wedge or a DIFFWTD compound available. +fn masked_compound_used_wh(w: usize, h: usize) -> bool { + w.min(h) >= 8 +} + +/// `av1_wedge_params_lookup[bsize].wedge_types > 0` (libaom `reconinter.c`): +/// the shapes whose `compound_type` symbol is really coded. Everything else +/// with a compound mask infers `COMPOUND_DIFFWTD` without a symbol. +fn wedge_used_wh(w: usize, h: usize) -> bool { + matches!( + (w, h), + (8, 8) + | (8, 16) + | (16, 8) + | (16, 16) + | (16, 32) + | (32, 16) + | (32, 32) + | (8, 32) + | (32, 8) + | (16, 64) + | (64, 16) + ) +} + /// 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: @@ -16959,12 +17046,18 @@ fn decode_inter_block( let group_ctx = get_comp_group_idx_context(neighbours, (rmi, cmi), side); let comp_group_idx = if !skip_mode && enable_masked_compound - && is_any_masked_compound_used_here(side) + && masked_compound_used_wh(write_w, write_h) { dec.symbol(&mut cdfs.comp_group_idx[group_ctx]) } else { 0 }; + if std::env::var_os("EC_TRACE_MODE").is_some() { + eprintln!( + "EC_CGI mi_row={rmi} mi_col={cmi} ctx={group_ctx} val={comp_group_idx} rng={}", + dec.debug_state().0 + ); + } // lane-maskcomp r2 / lane-wedge r3: `Some(mask_type)` for a // `COMPOUND_DIFFWTD` block, `Some(mask)` (wedge codebook lookup) // for a `COMPOUND_WEDGE` block -- exactly one of the two is set @@ -16986,12 +17079,11 @@ 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-intersub8 r4: the block's TRUE footprint, not the + // square envelope -- `compound_type_cdf`/`wedge_idx_cdf` are + // `BLOCK_SIZES_ALL`-indexed. + let wedge_bsize = + bsize_index(write_w, write_h).filter(|_| wedge_used_wh(write_w, write_h)); let compound_type = match wedge_bsize { Some(b) => dec.symbol(&mut cdfs.compound_type[b]), None => 1, @@ -16999,6 +17091,14 @@ fn decode_inter_block( 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). + if write_w != write_h { + // lane-intersub8 r4: the wedge codebook here is built + // per SQUARE side only; a rect block's own codebook + // (BLOCK_16X8 etc.) is a different mask set. + return Err(unsupported( + "a COMPOUND_WEDGE mask on a non-square inter block (rect wedge codebook unimplemented)", + )); + } let wedge_index = dec.symbol(&mut cdfs.wedge_idx[wedge_bsize]); let wedge_sign = dec.literal(1); WEDGE_HITS.with(|c| c.set(c.get() + 1)); @@ -17230,6 +17330,12 @@ fn decode_inter_block( ref_order_hints[(ref1 - LAST_FRAME) as usize], ); let idx = dec.symbol(&mut cdfs.compound_idx[idx_ctx]); + if std::env::var_os("EC_TRACE_MODE").is_some() { + eprintln!( + "EC_CIDX mi_row={rmi} mi_col={cmi} ctx={idx_ctx} val={idx} rng={}", + dec.debug_state().0 + ); + } if idx == 1 { (8, 8, 1u8) } else { @@ -19267,30 +19373,47 @@ fn decode_inter_block( Ok(()) } -/// Decodes one 8x8 leaf of a straddling 16x16 inter-frame block -/// (lane-av1inter8), mirroring [`crate::tile::write_inter_frame_leaf8`]'s -/// exact symbol order: its own skip flag, intra/inter choice and (when -/// inter) `NEARESTMV`/`NEWMV` chain against this leaf's own 2x2-mi mv-stack -/// window, or (when intra) `Y_MODE`, then its own luma and two chroma -/// transform blocks through [`TxbSet::Luma8Inter`]/[`TxbSet::Chroma4`], -/// same as [`decode_leaf8`]'s coefficient layer but with -/// motion-compensated prediction instead of intra prediction when inter. -/// `outer_at` (in [`SUB`]-grid units) is the enclosing 16x16 slot's -/// skip/intra-inter context, overridden by `prev_leaf` exactly as -/// [`decode_leaf8`] overrides mode context: `Neighbours`' above/left arrays -/// only resolve to [`SUB`] granularity. Hands back this leaf's own skip flag -/// and intra/inter choice, for the next leaf or the caller's final -/// write-back. +/// Decodes one 8x8 group that an inter frame's `partition_w8` symbol split +/// into four `BLOCK_4X4` inter blocks (lane-intersub8: `PARTITION_SPLIT` +/// below 8x8 -- traced live against the oracle `aomdec`'s own `EC_PART_VAL`, +/// which reads `bsize=3 value=3` on real inter frames, so the refusal this +/// replaces was NOT our own desync). +/// +/// The inter counterpart of [`decode_leaf_split4`], and a `BLOCK_4X4`-only +/// cut of [`decode_inter_block8`]: at `min(bw, bh) < 8` libaom switches off +/// half the inter syntax, and every one of those is a symbol NOT read here +/// (`decodemv.c` / `blockd.h`, oracle tree): +/// * `skip_mode`: `read_skip_mode` returns 0 without a symbol when +/// `!is_comp_ref_allowed(bsize)` (`AOMMIN(bw, bh) >= 8`, blockd.h). +/// * `comp_mode`: `read_block_reference_mode` returns `SINGLE_REFERENCE` on +/// the same predicate, so a sub-8x8 block is always single-reference. +/// * `interintra`: `is_interintra_allowed_bsize` starts at `BLOCK_8X8`. +/// * `motion_mode` / `obmc`: `motion_mode_allowed` returns +/// `SIMPLE_TRANSLATION` for `block_size_wide < 8 || block_size_high < 8`, +/// and `is_global_mv_block`'s own size term fails, so no warp either. +/// * tx size: `block_signals_txsize(bsize)` is `bsize > BLOCK_4X4` +/// (blockd.h:1027), so a `BLOCK_4X4` reads neither `tx_depth` nor a +/// `txfm_partition` bit even in `TX_MODE_SELECT` -- the transform is +/// `max_txsize_rect_lookup[BLOCK_4X4]` = `TX_4X4` +/// (`decodeframe.c:1164-1177`). +/// +/// Chroma is coded ONCE for the whole 8x8 group, on the last sub-block +/// (`is_chroma_reference`: `(mi_row & 1) && (mi_col & 1)` in 4:2:0), as one +/// `TX_4X4` unit per plane -- same rule and same neighbour-context tail as +/// [`decode_leaf_split4`]. Its PREDICTION is the sub8x8 one +/// (`dec_build_inter_predictors`'s `is_sub8x8` branch, `decodeframe.c`; spec +/// 7.11.3.1's `candRow`/`candCol` loop): four 2x2 chroma pieces, each built +/// from its own luma sub-block's reference, motion vector and interpolation +/// filters, never from the last sub-block's mv alone. #[allow(clippy::too_many_arguments)] -fn decode_inter_block8( +fn decode_inter_sub8_split4( dec: &mut SymbolDecoder, cdfs: &mut Cdfs, neighbours: &mut Neighbours, grid: &mut MiGrid, + group_mi: (usize, usize), mi_cols: u32, mi_rows: u32, - outer_at: (usize, usize), - leaf_mi: (usize, usize), y: &mut PlaneBuf, u: &mut PlaneBuf, v: &mut PlaneBuf, @@ -19298,210 +19421,1128 @@ fn decode_inter_block8( ref_u: &PlaneBuf, ref_v: &PlaneBuf, other_refs: &RefSlots, + sign_bias_table: &SignBiasTable, + global_motion: &[ec_av1_syntax::WarpParams; 7], base_q_idx: u8, - scan8: &[u16], scan4: &[u16], allow_high_precision_mv: bool, force_integer_mv: bool, - // lane-gmaffine r1: this frame header's own `global_motion` table (spec - // 5.9.24), indexed `[ref_frame - LAST_FRAME]` -- same table - // [`decode_inter_block`] takes, threaded here so the 8x8 leaf can code - // `GLOBALMV` (`gm_get_motion_vector`), fill its mv stack's missing - // candidates with the gm mv (gm r6's root cause) and build a global - // warp prediction. - global_motion: &[ec_av1_syntax::WarpParams; 7], - // lane-gmaffine r1: this sequence header's own `enable_dual_filter` bit, - // for the leaf's own `read_mb_interp_filter` below. - enable_dual_filter: bool, - // lane-av1comp: see [`decode_inter_block`]'s own doc -- this leaf path - // only ever tracks a coarse `LAST_FRAME`-or-intra neighbour shape (no - // per-leaf `above_ref`/`left_ref` array exists here), so `comp_mode`'s - // context uses that same approximation. - reference_select: bool, - enable_masked_compound: bool, - // lane-sb128 r4: see [`decode_inter_block`]'s own doc -- `BLOCK_8X8` is - // always `is_interintra_allowed_bsize`-eligible, so this leaf's own gate - // drops the `side` check entirely. - enable_interintra_compound: bool, - enable_jnt_comp: bool, - order_hint_bits: u32, - order_hint: u32, - ref_order_hints: [u32; 7], - // lane-av1comp round 14: see [`decode_inter_block`]'s own doc -- this - // leaf has no per-leaf `above_skip_mode`/`left_skip_mode` array either, - // so its `skip_mode` context reuses the same [`SUB`]-grid - // `above_skip_mode[cmi]`/`left_skip_mode[rmi]` the enclosing 16x16 slot - // tracks (mirroring `above_skip`/`left_skip`'s own leaf approximation - // just above). - skip_mode_present: bool, - skip_mode_frame: [u8; 2], - // lane-cdffwd2: this frame header's own `reduced_tx_set` bit -- see - // [`decode_inter_frame_tile_with_cdfs`]'s own doc. - reduced_tx_set: bool, - // lane-motionmode round 3: this frame header's own `is_motion_mode_switchable`/ - // `allow_warped_motion` bits (spec 5.11.24's `read_motion_mode`), plus - // the fixed/switchable interp filter kind `obmc_blend`'s own neighbour - // reads need (see [`decode_inter_block`]'s own doc) -- this leaf's own - // prediction is always `Regular` (documented corner-cut, `mc::predict` - // has no filter param), but an OBMC neighbour can be a real 16x16+ - // block that DID resolve a switchable filter. interp_fixed: Option, - switchable_motion_mode: bool, - allow_warped_motion: bool, - // lane-av1comp: `Some((ref1, comp_group_idx, compound_idx))` only for a - // real `COMPOUND_REFERENCE` leaf, for the caller's own end-of-16x16 - // `record_compound_ctx` call -- mirrors [`decode_inter_block`]'s own - // `compound_ctx` local, just handed back instead of applied here (this - // fn's `neighbours` recording happens once for the whole straddling - // 16x16 block, after every leaf). - // lane-screen r2: see [`decode_inter_block`]'s own copy of this param -- - // `BLOCK_8X8` (this leaf's fixed size) is always `av1_allow_palette`- - // eligible (`bsize >= BLOCK_8X8`). - allow_screen_content_tools: bool, - // lane-inter8 r1: the leaf's mv stacks used to be built without the - // frame's sign-bias table (`NO_SIGN_BIAS`), while [`decode_inter_block`] - // one level up passed it -- it changes the candidate list and with it - // `new_mv_ctx`/`ref_mv_ctx`, `drl_ctx` and the number of symbols read. - // Measured: an 8x8 compound NEAR_NEWMV leaf desynced against aomdec's - // EC_MODE ladder at exactly this block (mi 4,14 of the mandelbrot - // 8x8-split gate). - sign_bias_table: &SignBiasTable, - // lane-inter8 r2: the frame's temporal mv field (spec 7.10.2.8), which - // [`decode_inter_block`] one level up has always passed and this leaf - // passed `None` for -- a `use_ref_frame_mvs` frame's stack then holds - // fewer candidates here than in the reference decoder, which changes the - // mode contexts AND the number of `drl_mode` bits read (class parsed - // then discarded). + enable_dual_filter: bool, tpl_frame: Option<&TplFrameArgs>, - // lane-scaledref r1: this frame's own coded luma width (spec 7.11.3.3), - // for the scaled-reference MC this leaf's own single-ref/compound/OBMC - // predictions take when a stored reference was coded at another width - // (`use_superres`) -- mirrors [`decode_inter_block`]'s own param. + reduced_tx_set: bool, frame_width: usize, -) -> Result<(bool, bool, bool, Option<(i8, i8, u8, u8)>, [u8; 2], (i8, Option))> { +) -> Result<()> { const LAST_FRAME: i8 = 1; - // lane-gmaffine r2: the leaf's OWN switchable-filter symbols, handed back - // so the caller stamps them into `Neighbours` instead of the `[3, 3]` - // placeholder. `[3, 3]` is the "intra neighbour, no filter" sentinel: an - // OBMC blend that picks such a neighbour up feeds it to - // `neighbour_filter`, which PANICS on it (`from_switchable_symbol`) -- - // that was the warp gate's crash, not an entropy desync. Stays `[3, 3]` - // on the intra and compound paths. - let mut leaf_filter_syms = [3u8; 2]; - // lane-gmaffine r1: this leaf's GLOBALMV vector AND the mv stack's - // missing-candidate fallback both come from the frame's global motion - // evaluated at THIS block's centre (gm r6's root cause). - let gm_table = build_gm_mv_table( - global_motion, - leaf_mi.0, - leaf_mi.1, - 2, - 2, - allow_high_precision_mv, - force_integer_mv, - ); - /// `Y_MODE`'s size group (`common_data.h`'s `size_group_lookup[BLOCK_8X8]`). - const SIZE_GROUP_8: usize = 1; - - let (px, py) = (leaf_mi.1 * MI, leaf_mi.0 * MI); - let (cpx, cpy) = (px / 2, py / 2); - // lane-txselect: whether this leaf's `TxMode::Select` var-tx tree took - // the one split a `BLOCK_8X8` can take (`read_block_tx_size` below) -- - // read back by the luma residual read and the tail's neighbour/loop-filter - // bookkeeping. Always `false` outside a `TxMode::Select` inter frame. - let mut split8 = false; - const SIDE: usize = 8; - const CHROMA_SIDE: usize = 4; - - let (r, c) = outer_at; - // lane-inter8 r2: this leaf's OWN mi cell, not the enclosing 16x16's -- - // leaf (mi_r, mi_c + 2)'s left neighbour is leaf (mi_r, mi_c), and the - // left column of a 16x16's second leaf ROW is the previous 16x16 block's - // bottom leaf, neither of which a SUB-grid slot can name. - let (rmi, cmi) = leaf_mi; - // lane-inter8 r2: no sibling-leaf override any more -- each leaf stamps - // its own 2x2-mi span into the bands right after it decodes (the caller's - // `record_inter_rect_mi`), so a plain mi read already names the correct - // neighbour, including one belonging to the previous 16x16 block. - let above_skip = neighbours.above_skip[cmi]; - let left_skip = neighbours.left_skip[rmi]; - let above_inter = neighbours.above_inter[cmi]; - let left_inter = neighbours.left_inter[rmi]; - let above_ref0 = neighbours.above_ref[cmi]; - let above_ref1 = neighbours.above_ref1[cmi]; - let left_ref0 = neighbours.left_ref[rmi]; - let left_ref1 = neighbours.left_ref1[rmi]; - let skip_mode_ctx = - usize::from(neighbours.above_skip_mode[cmi]) + usize::from(neighbours.left_skip_mode[rmi]); - // Same two `inter_segment_id` positions as [`decode_inter_block`]; this - // leaf is always `BLOCK_8X8`, i.e. 2x2 mi. - inter_segment_id(dec, cdfs, leaf_mi.0, leaf_mi.1, 2, 2, false, true); - let skip_mode = skip_mode_present && dec.symbol(&mut cdfs.skip_mode[skip_mode_ctx]) == 1; - if skip_mode { - SKIP_MODE_HITS.with(|c| c.set(c.get() + 1)); - } - - let skip_ctx = usize::from(above_skip) + usize::from(left_skip); - let skip = skip_mode || dec.symbol(&mut cdfs.skip[skip_ctx]) == 1; - inter_segment_id(dec, cdfs, leaf_mi.0, leaf_mi.1, 2, 2, skip, false); - maybe_read_cdef_idx(dec, leaf_mi.0, leaf_mi.1, skip); - // Always a `BLOCK_8X8` leaf here, never the whole superblock. - maybe_read_delta_q(dec, cdfs, leaf_mi.0, leaf_mi.1, false, skip); - maybe_read_delta_lf(dec, cdfs, leaf_mi.0, leaf_mi.1, false, skip); - - let (has_above, has_left) = ( - leaf_mi.0 > neighbours.tile_row0_mi, - leaf_mi.1 > neighbours.tile_col0_mi, - ); - let ii_ctx = intra_inter_ctx(has_above, has_left, above_inter, left_inter); - let is_inter = skip_mode || dec.symbol(&mut cdfs.intra_inter[ii_ctx]) == 1; - // lane-inter8 r1: mirrors the oracle's `EC_MODE` (instrument rung 4, - // `read_inter_block_mode_info`) so an 8x8 leaf's mode-info range ladder - // diffs line for line against a real aomdec. - if std::env::var_os("EC_TRACE_MODE").is_some() { - eprintln!( - "EC_MODE mi_row={} mi_col={} rng={}", - leaf_mi.0, - leaf_mi.1, - dec.debug_state().0 + const B4: usize = 4; + SUB8_INTER_SPLIT_HITS.with(|c| c.set(c.get() + 1)); + let (gr, gc) = group_mi; + let (gpx, gpy) = (gc * MI, gr * MI); + let (cpx, cpy) = (gpx / 2, gpy / 2); + // Per-sub-block state the group's chroma prediction needs (spec + // 7.11.3.1's candRow/candCol loop reads each sub-block's OWN mv/ref/ + // filters), indexed `dr * 2 + dc`. + let mut piece: [Option<(i8, (i32, i32), mc::InterpFilterKind, mc::InterpFilterKind)>; 4] = + [None; 4]; + let mut first_tx_type = TxType::DctDct; + let mut last_skip = true; + for i in 0..4usize { + let (dr, dc) = (i / 2, i % 2); + let lmi = (gr + dr, gc + dc); + if lmi.0 >= mi_rows as usize || lmi.1 >= mi_cols as usize { + continue; + } + let (rmi, cmi) = lmi; + let (px, py) = (cmi * MI, rmi * MI); + inter_segment_id(dec, cdfs, rmi, cmi, 1, 1, false, true); + // No `skip_mode` symbol: `is_comp_ref_allowed(BLOCK_4X4)` is false. + let skip_ctx = usize::from(neighbours.above_skip[cmi]) + usize::from(neighbours.left_skip[rmi]); + let skip = dec.symbol(&mut cdfs.skip[skip_ctx]) == 1; + inter_segment_id(dec, cdfs, rmi, cmi, 1, 1, skip, false); + maybe_read_cdef_idx(dec, rmi, cmi, skip); + maybe_read_delta_q(dec, cdfs, rmi, cmi, false, skip); + maybe_read_delta_lf(dec, cdfs, rmi, cmi, false, skip); + let (has_above, has_left) = ( + rmi > neighbours.tile_row0_mi, + cmi > neighbours.tile_col0_mi, ); - } - - let mode_for_tx; - // lane-uv8 r1: this leaf's chroma prediction mode (`get_uv_mode` of the - // coded `uv_mode`), for the neighbour bands at the tail. An INTER leaf - // stores `UV_DC_PRED`, exactly as [`decode_inter_block`] one level up. - let mut uv_predict_mode = DC_PRED; - let (luma_grid, u_grid, v_grid); - let mut compound_ctx8: Option<(i8, i8, u8, u8)> = None; - // lane-inter8 r1: this leaf's own resolved references, handed back so the - // NEXT leaf of the same 16x16 can use them as its real above/left - // neighbour (`Neighbours`' arrays only move once per 16x16 block). - // `(0, None)` is intra. - let mut leaf_refs: (i8, Option) = (0, None); - if is_inter { - if reference_select || skip_mode { - // lane-inter8 r1: the REAL neighbour references, not a - // `LAST_FRAME`-or-intra stand-in. `av1_get_reference_mode_context` - // and `read_compound_ref_frames`' own contexts both ask whether a - // neighbour is COMPOUND, so pretending every inter neighbour is - // single-ref LAST picked the wrong `comp_mode` CDF row -- measured - // as an 8x8 leaf reading single-ref where aomdec read compound - // NEAR_NEWMV (mi 4,14). - let above_nbr = has_above.then(|| NeighbourRef { - is_inter: above_inter, - ref0: if above_inter { above_ref0 } else { 0 }, - ref1: above_ref1, - uni: above_ref1.is_some_and(|r1| is_uni_comp_ref(above_ref0, r1)), - }); - let left_nbr = has_left.then(|| NeighbourRef { - is_inter: left_inter, - ref0: if left_inter { left_ref0 } else { 0 }, - ref1: left_ref1, - uni: left_ref1.is_some_and(|r1| is_uni_comp_ref(left_ref0, r1)), - }); - if skip_mode || read_comp_mode(dec, cdfs, above_nbr, left_nbr) { - let (ref0, ref1) = if skip_mode { + let ii_ctx = intra_inter_ctx( + has_above, + has_left, + neighbours.above_inter[cmi], + neighbours.left_inter[rmi], + ); + let is_inter = dec.symbol(&mut cdfs.intra_inter[ii_ctx]) == 1; + if !is_inter { + return Err(unsupported( + "an intra 4x4 block inside an inter frame's sub-8x8 split (this decoder codes \ + only inter 4x4 sub-blocks there)", + )); + } + // Same print point as the oracle's `EC_MODE` (entry of + // `read_inter_block_mode_info`, i.e. after skip / is_inter), so the + // two range ladders line up element for element. + if std::env::var_os("EC_TRACE_MODE").is_some() { + eprintln!( + "EC_MODE mi_row={rmi} mi_col={cmi} rng={}", + dec.debug_state().0 + ); + } + let ref_frame = read_single_ref( + dec, + cdfs, + neighbours.above_ref[cmi], + neighbours.above_ref1[cmi], + neighbours.left_ref[rmi], + neighbours.left_ref1[rmi], + ); + let (sref_y, sref_u, sref_v) = ref_planes(ref_frame, ref_y, ref_u, ref_v, other_refs)?; + if mc::scale_factor(sref_y.width, frame_width) != mc::REF_NO_SCALE { + return Err(unsupported( + "a sub-8x8 inter block under a scaled reference (superres, unimplemented)", + )); + } + let gm_table = build_gm_mv_table( + global_motion, + rmi, + cmi, + 1, + 1, + allow_high_precision_mv, + force_integer_mv, + ); + let tpl = tpl_frame.map(|t| crate::mvstack::TplArgs { + field: t.field, + cur_offset_0: crate::motion_field::get_relative_dist( + t.order_hint_bits, + t.order_hint, + t.ref_order_hints[(ref_frame - LAST_FRAME) as usize], + ), + allow_high_precision_mv, + }); + let stack = crate::mvstack::find_mv_stack_with_sign_bias( + grid, + rmi, + cmi, + 1, + 1, + ref_frame, + mi_cols as usize, + mi_rows as usize, + sign_bias_table, + &gm_table, + tpl, + ); + let not_new = dec.symbol(&mut cdfs.new_mv[stack.new_mv_ctx]) == 1; + let mut is_globalmv = false; + let (mv, is_new_mv) = if !not_new { + let mut idx = 0usize; + while idx < 2 && stack.entries.len() > idx + 1 { + if dec.symbol(&mut cdfs.drl_mode[stack.drl_ctx[idx]]) == 0 { + break; + } + idx += 1; + } + let base_mv = stack.entries.get(idx).map_or(stack.pred_mv, |e| e.mv); + ( + read_mv( + dec, + &mut cdfs.mv_comp, + &mut cdfs.mv_joint, + base_mv, + allow_high_precision_mv, + force_integer_mv, + ), + true, + ) + } else { + let not_zero = dec.symbol(&mut cdfs.zero_mv[stack.zero_mv_ctx]) == 1; + is_globalmv = !not_zero; + let mv = if !not_zero { + gm_table[(ref_frame - LAST_FRAME) as usize] + } else { + let nearest = dec.symbol(&mut cdfs.ref_mv[stack.ref_mv_ctx]) == 0; + if nearest { + stack.nearest_mv + } else { + let mut idx = 1usize; + while idx < 3 && stack.entries.len() > idx + 1 { + if dec.symbol(&mut cdfs.drl_mode[stack.drl_ctx[idx]]) == 0 { + break; + } + idx += 1; + } + stack.entries.get(idx).map_or(stack.near_mv, |e| e.mv) + } + }; + (mv, false) + }; + // Same print point as the oracle's `EC_MODE_MV` (right after + // `assign_mv`), the second rung of the sub-8x8 range ladder. + if std::env::var_os("EC_TRACE_MODE").is_some() { + eprintln!( + "EC_MODE_MV mi_row={rmi} mi_col={cmi} mv0=({},{}) rng={}", + mv.0, + mv.1, + dec.debug_state().0 + ); + } + // No `interintra` and no `motion_mode`/`obmc` symbol below 8x8 (see + // this function's own doc); `read_mb_interp_filter` still runs. + let gm_ref = &global_motion[(ref_frame - LAST_FRAME) as usize]; + let above_filter_ctx = if neighbours.above_ref[cmi] == ref_frame + || neighbours.above_ref1[cmi] == Some(ref_frame) + { + neighbours.above_filter[cmi] + } else { + [3, 3] + }; + let left_filter_ctx = if neighbours.left_ref[rmi] == ref_frame + || neighbours.left_ref1[rmi] == Some(ref_frame) + { + neighbours.left_filter[rmi] + } else { + [3, 3] + }; + if std::env::var_os("EC_AV1_IFDBG").is_some() { + eprintln!( + "IFDBG4 mi=({rmi},{cmi}) ref={ref_frame} above_ref={} above_ref1={:?} \ + above_filt={:?} left_ref={} left_ref1={:?} left_filt={:?}", + neighbours.above_ref[cmi], + neighbours.above_ref1[cmi], + neighbours.above_filter[cmi], + neighbours.left_ref[rmi], + neighbours.left_ref1[rmi], + neighbours.left_filter[rmi], + ); + } + let gm_nontrans = is_globalmv && gm_ref.model != ec_av1_syntax::WarpModel::Translation; + let (h_filter, v_filter, resolved_filter) = resolve_interp_filter( + dec, + cdfs, + interp_fixed, + enable_dual_filter, + gm_nontrans, + above_filter_ctx, + left_filter_ctx, + false, + ); + if std::env::var_os("EC_TRACE_MODE").is_some() { + eprintln!( + "EC_MODE_VAL4 mi_row={rmi} mi_col={cmi} newmv={is_new_mv} globalmv={is_globalmv} \ + ref0={ref_frame} mv0=({},{}) stack={} rng={}", + mv.0, + mv.1, + stack.entries.len(), + dec.debug_state().0 + ); + } + grid.set( + rmi, + cmi, + MiInfo { + is_inter: true, + ref_frame, + ref_frame1: None, + mv1: None, + mv, + is_new_mv, + size: 1, + size_h: 1, + is_global_mv0: false, + is_global_mv1: false, + }, + ); + piece[i] = Some((ref_frame, mv, h_filter, v_filter)); + let mut pred_y = vec![0u16; B4 * B4]; + mc::predict_with_filters( + &sref_y.data, + sref_y.width, + sref_y.true_width, + sref_y.true_height, + mv_to_q4(px, mv.1, true), + mv_to_q4(py, mv.0, true), + B4, + B4, + h_filter, + v_filter, + &mut pred_y, + ); + // `BLOCK_4X4` never signals a transform size, so the luma unit is the + // whole block and `get_txb_ctx` takes its `plane_bsize == + // txsize_to_bsize[tx_size]` branch (`txb_skip_ctx = 0`, which + // `read_inter_plane`'s `plane_idx == 0` arm already assumes). + if skip { + y.reconstruct_mc(px, py, B4, &pred_y, &vec![0i32; B4 * B4]); + neighbours.record_mi_luma_rect(lmi, B4, B4, &vec![0i32; B4 * B4]); + } else { + let around = neighbours.around_mi(lmi, B4); + let (luma_grid, tx_type) = read_inter_plane( + dec, + cdfs, + if reduced_tx_set { + TxbSet::Luma4Inter + } else { + TxbSet::Luma4InterSet1 + }, + scan4, + 0, + around[0], + 0, + y, + px, + py, + B4, + base_q_idx, + &pred_y, + None, + None, + )?; + if i == 0 { + // `av1_get_tx_type`: an inter block's chroma inherits the + // tx_type of the CO-LOCATED luma position, which for the + // group's one chroma unit is luma (0, 0) -- the FIRST + // sub-block, not the last. + first_tx_type = tx_type; + } + neighbours.record_mi_luma_rect(lmi, B4, B4, &luma_grid); + } + neighbours.record_mode_mi(rmi, cmi, 1, 1, DC_PRED); + neighbours.record_inter_rect_mi(lmi, 1, 1, skip, true, ref_frame, resolved_filter, false); + neighbours.fill_skip_grid_rect(lmi, 1, 1, skip); + neighbours.fill_lf_grid_rect(lmi, 1, 1, B4 as u8, B4 as u8, ref_frame.max(LAST_FRAME)); + last_skip = skip; + } + // Chroma, once for the whole group, on the last sub-block's own `skip` + // flag -- prediction from all four sub-blocks (2x2 pieces), residual as + // one TX_4X4 unit per plane. + let mut pred_u = vec![0u16; B4 * B4]; + let mut pred_v = vec![0u16; B4 * B4]; + for i in 0..4usize { + let (dr, dc) = (i / 2, i % 2); + let Some((ref_frame, mv, h_filter, v_filter)) = piece[i] else { + continue; + }; + let (_, sref_u, sref_v) = ref_planes(ref_frame, ref_y, ref_u, ref_v, other_refs)?; + let (ox, oy) = (cpx + dc * 2, cpy + dr * 2); + for (plane, dst) in [(sref_u, &mut pred_u), (sref_v, &mut pred_v)] { + let mut buf = vec![0u16; 4]; + mc::predict_with_filters( + &plane.data, + plane.width, + plane.true_width, + plane.true_height, + mv_to_q4(ox, mv.1, false), + mv_to_q4(oy, mv.0, false), + 2, + 2, + h_filter, + v_filter, + &mut buf, + ); + for row in 0..2 { + for col in 0..2 { + dst[(dr * 2 + row) * B4 + dc * 2 + col] = buf[row * 2 + col]; + } + } + } + } + let (u_grid, v_grid) = if last_skip { + u.reconstruct_mc(cpx, cpy, B4, &pred_u, &vec![0i32; B4 * B4]); + v.reconstruct_mc(cpx, cpy, B4, &pred_v, &vec![0i32; B4 * B4]); + (vec![0i32; B4 * B4], vec![0i32; B4 * B4]) + } else { + let around = neighbours.around_mi(group_mi, 8); + let ug = read_inter_plane( + dec, cdfs, TxbSet::Chroma4, scan4, 1, around[1], 0, u, cpx, cpy, B4, base_q_idx, + &pred_u, Some(first_tx_type), None, + )? + .0; + let vg = read_inter_plane( + dec, cdfs, TxbSet::Chroma4, scan4, 2, around[2], 0, v, cpx, cpy, B4, base_q_idx, + &pred_v, Some(first_tx_type), None, + )? + .0; + (ug, vg) + }; + neighbours.record_uv_mode_mi(gr, gc, 2, 2, DC_PRED); + // Same two neighbour tails [`decode_leaf_split4`] runs: the partition + // context of a `BLOCK_4X4` subsize (`partition_context_lookup` bit 0 = 1, + // reached by `side_mi = 4` here) and the group's chroma coefficient state. + for cell in 0..2usize { + neighbours.left_side_mi[gr + cell] = 4; + neighbours.above_side_mi[gc + cell] = 4; + } + let round_up_even = |n: usize| n.div_ceil(2) * 2; + let bound_h = round_up_even(neighbours.mi_rows); + let bound_w = round_up_even(neighbours.mi_cols); + let u_state = neighbour_state(&u_grid); + let v_state = neighbour_state(&v_grid); + for cell in 0..2usize { + if cell < 2usize.min(bound_h.saturating_sub(gr)) { + neighbours.left[gr + cell][1] = u_state; + neighbours.left[gr + cell][2] = v_state; + } + if cell < 2usize.min(bound_w.saturating_sub(gc)) { + neighbours.above[gc + cell][1] = u_state; + neighbours.above[gc + cell][2] = v_state; + } + } + Ok(()) +} + +/// Decodes a `PARTITION_HORZ`/`PARTITION_VERT` of one 8x8 INTER block into two +/// `BLOCK_8X4`/`BLOCK_4X8` inter leaves (lane-intersub8 r3) -- the inter twin of +/// [`decode_leaf_rect8`] and the rectangular sibling of +/// [`decode_inter_sub8_split4`], whose element order it follows exactly. +/// Per sub-block, in libaom `decodemv.c` `read_inter_frame_mode_info` order: +/// +/// * `segment_id`, `skip`, `cdef`/`delta_q`/`delta_lf`, `intra_inter`; +/// * NO `skip_mode` symbol: `is_comp_ref_allowed(BLOCK_8X4)` is false +/// (`av1_is_comp_ref_allowed` needs both sides >= 8), so +/// `read_skip_mode` returns 0 without reading and `comp_mode` is never read +/// either (`read_ref_frames`' `is_comp_ref_allowed` guard) -- single +/// reference only; +/// * NO `interintra` and NO `motion_mode`/OBMC/warp symbol: every one of those +/// gates needs `block_size_wide >= 8 && block_size_high >= 8` +/// (`is_interintra_allowed_bsize`, `motion_mode_allowed`), and one side is 4; +/// * `read_mb_interp_filter` DOES run for both sub-blocks. +/// +/// The shape's own differences from the four-way split: +/// +/// * `block_signals_txsize(BLOCK_8X4)` is true (`bsize > BLOCK_4X4`, +/// blockd.h:1027), so a non-skipped sub-block reads ONE `txfm_partition` +/// symbol under `TX_MODE_SELECT` at `max_txsize_rect_lookup[BLOCK_8X4] == +/// TX_8X4` ([`read_var_tx_size`]); split resolves to two `TX_4X4` units +/// (`sub_tx_size_map[TX_8X4] == TX_4X4`, libaom's early return), no split to +/// the whole-leaf `TX_8X4`; +/// * the luma coefficient set is [`TxbSet::LumaRect8x4Inter`] (the 8x8 +/// coefficient class with a 32-position `eob_pt` and the INTER `TX_4X4` +/// `tx_type` row) for the whole-leaf unit, and the square +/// [`TxbSet::Luma4Inter`] for a split `TX_4X4` unit; +/// * chroma is coded ONCE, on the sub-block that is the chroma reference: +/// `is_chroma_reference` (`av1_common_int.h`) is +/// `((mi_row & 1) || !(bh4 & 1) || !ss_y) && ((mi_col & 1) || !(bw4 & 1) || +/// !ss_x)`, i.e. under 4:2:0 the BOTTOM 8x4 (`bh4 == 1`, odd) and the RIGHT +/// 4x8 (`bw4 == 1`) -- always the second sub-block here; +/// * that chroma unit's prediction is the sub8x8 one (`reconinter.c` +/// `build_inter_predictors_sub8x8`: `row_start = -(block_size_high == 4 && +/// ss_y)`, `col_start = -(block_size_wide == 4 && ss_x)`), two 4x2 (HORZ) or +/// 2x4 (VERT) chroma pieces, each from its OWN sub-block's reference, mv and +/// interpolation filters. +#[allow(clippy::too_many_arguments)] +fn decode_inter_sub8_rect2( + dec: &mut SymbolDecoder, + cdfs: &mut Cdfs, + neighbours: &mut Neighbours, + grid: &mut MiGrid, + group_mi: (usize, usize), + vert: bool, + mi_cols: u32, + mi_rows: u32, + y: &mut PlaneBuf, + u: &mut PlaneBuf, + v: &mut PlaneBuf, + ref_y: &PlaneBuf, + ref_u: &PlaneBuf, + ref_v: &PlaneBuf, + other_refs: &RefSlots, + sign_bias_table: &SignBiasTable, + global_motion: &[ec_av1_syntax::WarpParams; 7], + base_q_idx: u8, + scan4: &[u16], + allow_high_precision_mv: bool, + force_integer_mv: bool, + interp_fixed: Option, + enable_dual_filter: bool, + tpl_frame: Option<&TplFrameArgs>, + reduced_tx_set: bool, + frame_width: usize, +) -> Result<()> { + const LAST_FRAME: i8 = 1; + // The 8x8 group's own square stride: both leaves' prediction buffers are + // laid out at it, as every other rect inter unit here is. + const SIDE: usize = 8; + let (bw, bh) = if vert { (4usize, 8usize) } else { (8usize, 4usize) }; + let (w_mi, h_mi) = (bw / MI, bh / MI); + SUB8_INTER_RECT_HITS.with(|c| { + let mut h = c.get(); + h[usize::from(vert)] += 1; + c.set(h); + }); + let (gr, gc) = group_mi; + let (gpx, gpy) = (gc * MI, gr * MI); + let (cpx, cpy) = (gpx / 2, gpy / 2); + // Per-sub-block state the group's one chroma unit predicts from. + let mut piece: [Option<(i8, (i32, i32), mc::InterpFilterKind, mc::InterpFilterKind)>; 2] = + [None; 2]; + let mut first_tx_type = TxType::DctDct; + let mut last_skip = true; + for i in 0..2usize { + let lmi = if vert { (gr, gc + i) } else { (gr + i, gc) }; + if lmi.0 >= mi_rows as usize || lmi.1 >= mi_cols as usize { + continue; + } + let (rmi, cmi) = lmi; + let (px, py) = (cmi * MI, rmi * MI); + inter_segment_id(dec, cdfs, rmi, cmi, w_mi, h_mi, false, true); + let skip_ctx = + usize::from(neighbours.above_skip[cmi]) + usize::from(neighbours.left_skip[rmi]); + let skip = dec.symbol(&mut cdfs.skip[skip_ctx]) == 1; + inter_segment_id(dec, cdfs, rmi, cmi, w_mi, h_mi, skip, false); + maybe_read_cdef_idx(dec, rmi, cmi, skip); + maybe_read_delta_q(dec, cdfs, rmi, cmi, false, skip); + maybe_read_delta_lf(dec, cdfs, rmi, cmi, false, skip); + let (has_above, has_left) = ( + rmi > neighbours.tile_row0_mi, + cmi > neighbours.tile_col0_mi, + ); + let ii_ctx = intra_inter_ctx( + has_above, + has_left, + neighbours.above_inter[cmi], + neighbours.left_inter[rmi], + ); + let is_inter = dec.symbol(&mut cdfs.intra_inter[ii_ctx]) == 1; + if !is_inter { + return Err(unsupported( + "an intra 8x4/4x8 block inside an inter frame's sub-8x8 HORZ/VERT partition \ + (this decoder codes only inter sub-blocks there)", + )); + } + if std::env::var_os("EC_TRACE_MODE").is_some() { + eprintln!( + "EC_MODE mi_row={rmi} mi_col={cmi} rng={}", + dec.debug_state().0 + ); + } + let ref_frame = read_single_ref( + dec, + cdfs, + neighbours.above_ref[cmi], + neighbours.above_ref1[cmi], + neighbours.left_ref[rmi], + neighbours.left_ref1[rmi], + ); + let (sref_y, _, _) = ref_planes(ref_frame, ref_y, ref_u, ref_v, other_refs)?; + if mc::scale_factor(sref_y.width, frame_width) != mc::REF_NO_SCALE { + return Err(unsupported( + "a sub-8x8 inter block under a scaled reference (superres, unimplemented)", + )); + } + let gm_table = build_gm_mv_table( + global_motion, + rmi, + cmi, + w_mi, + h_mi, + allow_high_precision_mv, + force_integer_mv, + ); + let tpl = tpl_frame.map(|t| crate::mvstack::TplArgs { + field: t.field, + cur_offset_0: crate::motion_field::get_relative_dist( + t.order_hint_bits, + t.order_hint, + t.ref_order_hints[(ref_frame - LAST_FRAME) as usize], + ), + allow_high_precision_mv, + }); + let stack = crate::mvstack::find_mv_stack_with_sign_bias( + grid, + rmi, + cmi, + w_mi, + h_mi, + ref_frame, + mi_cols as usize, + mi_rows as usize, + sign_bias_table, + &gm_table, + tpl, + ); + let not_new = dec.symbol(&mut cdfs.new_mv[stack.new_mv_ctx]) == 1; + let mut is_globalmv = false; + let (mv, is_new_mv) = if !not_new { + let mut idx = 0usize; + while idx < 2 && stack.entries.len() > idx + 1 { + if dec.symbol(&mut cdfs.drl_mode[stack.drl_ctx[idx]]) == 0 { + break; + } + idx += 1; + } + let base_mv = stack.entries.get(idx).map_or(stack.pred_mv, |e| e.mv); + ( + read_mv( + dec, + &mut cdfs.mv_comp, + &mut cdfs.mv_joint, + base_mv, + allow_high_precision_mv, + force_integer_mv, + ), + true, + ) + } else { + let not_zero = dec.symbol(&mut cdfs.zero_mv[stack.zero_mv_ctx]) == 1; + is_globalmv = !not_zero; + let mv = if !not_zero { + gm_table[(ref_frame - LAST_FRAME) as usize] + } else { + let nearest = dec.symbol(&mut cdfs.ref_mv[stack.ref_mv_ctx]) == 0; + if nearest { + stack.nearest_mv + } else { + let mut idx = 1usize; + while idx < 3 && stack.entries.len() > idx + 1 { + if dec.symbol(&mut cdfs.drl_mode[stack.drl_ctx[idx]]) == 0 { + break; + } + idx += 1; + } + stack.entries.get(idx).map_or(stack.near_mv, |e| e.mv) + } + }; + (mv, false) + }; + if std::env::var_os("EC_TRACE_MODE").is_some() { + eprintln!( + "EC_MODE_MV mi_row={rmi} mi_col={cmi} mv0=({},{}) rng={}", + mv.0, + mv.1, + dec.debug_state().0 + ); + } + let gm_ref = &global_motion[(ref_frame - LAST_FRAME) as usize]; + let above_filter_ctx = if neighbours.above_ref[cmi] == ref_frame + || neighbours.above_ref1[cmi] == Some(ref_frame) + { + neighbours.above_filter[cmi] + } else { + [3, 3] + }; + let left_filter_ctx = if neighbours.left_ref[rmi] == ref_frame + || neighbours.left_ref1[rmi] == Some(ref_frame) + { + neighbours.left_filter[rmi] + } else { + [3, 3] + }; + let gm_nontrans = is_globalmv && gm_ref.model != ec_av1_syntax::WarpModel::Translation; + let (h_filter, v_filter, resolved_filter) = resolve_interp_filter( + dec, + cdfs, + interp_fixed, + enable_dual_filter, + gm_nontrans, + above_filter_ctx, + left_filter_ctx, + false, + ); + // `read_block_tx_size` (libaom `decodeframe.c`): unlike a `BLOCK_4X4`, + // this shape signals its transform size. A non-skipped inter block + // walks the var-tx tree from `max_txsize_rect_lookup[BLOCK_8X4]`; a + // skipped one codes nothing and records its BLOCK size in both txfm + // contexts (`set_txfm_ctxs`' `skip_inter` arm). + let mut leaves: Vec<(usize, usize, usize, usize)> = Vec::new(); + if TX_SELECT_INTER.with(std::cell::Cell::get) && !skip { + let max_w_mi = w_mi.min((mi_cols as usize).saturating_sub(cmi)); + let max_h_mi = h_mi.min((mi_rows as usize).saturating_sub(rmi)); + read_var_tx_size( + dec, + cdfs, + neighbours, + lmi, + SIDE, + (max_w_mi, max_h_mi), + (bw, bh), + 0, + 0, + 0, + &mut leaves, + ); + } else { + leaves.push((0, 0, bw, bh)); + set_txfm_ctxs(neighbours, lmi, bw.max(bh), w_mi, h_mi, skip); + } + if std::env::var_os("EC_TRACE_MODE").is_some() { + eprintln!( + "EC_MODE_VALR mi_row={rmi} mi_col={cmi} newmv={is_new_mv} globalmv={is_globalmv} \ + ref0={ref_frame} mv0=({},{}) stack={} leaves={} rng={}", + mv.0, + mv.1, + stack.entries.len(), + leaves.len(), + dec.debug_state().0 + ); + } + grid_stamp_rect(grid, rmi, cmi, w_mi, h_mi, ref_frame, mv, is_new_mv); + piece[i] = Some((ref_frame, mv, h_filter, v_filter)); + // Prediction over the leaf's true footprint, laid out at the group's + // square stride (what `reconstruct_mc_rect` and `read_inter_plane_rect` + // index with). + let mut pred_y = vec![0u16; SIDE * SIDE]; + { + let mut dense = vec![0u16; bw * bh]; + mc::predict_with_filters( + &sref_y.data, + sref_y.width, + sref_y.true_width, + sref_y.true_height, + mv_to_q4(px, mv.1, true), + mv_to_q4(py, mv.0, true), + bw, + bh, + h_filter, + v_filter, + &mut dense, + ); + for row in 0..bh { + pred_y[row * SIDE..][..bw].copy_from_slice(&dense[row * bw..][..bw]); + } + } + if skip { + y.reconstruct_mc_rect(px, py, SIDE, bw, bh, &pred_y, &vec![0i32; SIDE * SIDE]); + neighbours.record_mi_luma_rect(lmi, bw, bh, &vec![0i32; bw * bh]); + neighbours.fill_lf_grid_rect(lmi, w_mi, h_mi, bw as u8, bh as u8, ref_frame.max(LAST_FRAME)); + } else { + let (mut last_tw, mut last_th) = (bw, bh); + for (idx, &(row, col, tw, th)) in leaves.iter().enumerate() { + let tu_mi = (rmi + row, cmi + col); + let (tu_px, tu_py) = (px + col * MI, py + row * MI); + let (tu_grid, tu_tx_type) = if tw == th { + // A split `TX_4X4` unit: square reader, its own + // `get_txb_ctx_general` neighbour context (the unit is + // smaller than its plane block, so the lone-TU 0 does not + // apply). + let mut tu_pred = Vec::with_capacity(tw * th); + for rr in 0..th { + let start = (row * MI + rr) * SIDE + col * MI; + tu_pred.extend_from_slice(&pred_y[start..start + tw]); + } + let tu_skip_ctx = neighbours.luma_skip_ctx_rect(tu_mi, tw / MI, th / MI); + read_inter_plane( + dec, + cdfs, + if reduced_tx_set { + TxbSet::Luma4Inter + } else { + TxbSet::Luma4InterSet1 + }, + scan4, + 0, + neighbours.around_mi(tu_mi, tw)[0], + 0, + y, + tu_px, + tu_py, + tw, + base_q_idx, + &tu_pred, + None, + Some(tu_skip_ctx), + )? + } else { + // The whole leaf as one `TX_8X4`/`TX_4X8` unit: it IS the + // plane block, so `get_txb_ctx_general` fixes `txb_skip_ctx` + // at 0 (`luma_skip_ctx: None`). + let start = row * MI * SIDE + col * MI; + read_inter_plane_rect( + dec, + cdfs, + if reduced_tx_set { + TxbSet::LumaRect8x4Inter + } else { + TxbSet::LumaRect8x4InterSet1 + }, + (tw, th), + SIDE, + 0, + neighbours.around_mi_rect(tu_mi, tw, th)[0], + 0, + y, + tu_px, + tu_py, + &pred_y[start..], + None, + None, + )? + }; + if idx == 0 { + // `av1_get_tx_type`: the group's one chroma unit scales + // back to luma (0, 0), i.e. the FIRST sub-block's first + // transform unit. + first_tx_type = tu_tx_type; + } + neighbours.record_mi_luma_rect(tu_mi, tw, th, &tu_grid); + (last_tw, last_th) = (tw, th); + } + neighbours.fill_lf_grid_rect( + lmi, + w_mi, + h_mi, + last_tw as u8, + last_th as u8, + ref_frame.max(LAST_FRAME), + ); + } + neighbours.record_mode_mi(rmi, cmi, w_mi, h_mi, DC_PRED); + neighbours.record_inter_rect_mi(lmi, w_mi, h_mi, skip, true, ref_frame, resolved_filter, false); + neighbours.fill_skip_grid_rect(lmi, w_mi, h_mi, skip); + last_skip = skip; + } + // The group's single 4x4 chroma unit per plane, on the chroma-reference + // (second) sub-block's own skip flag. + const B4: usize = 4; + let mut pred_u = vec![0u16; B4 * B4]; + let mut pred_v = vec![0u16; B4 * B4]; + let (piece_w, piece_h) = if vert { (2usize, 4usize) } else { (4usize, 2usize) }; + for i in 0..2usize { + let Some((ref_frame, mv, h_filter, v_filter)) = piece[i] else { + continue; + }; + let (_, sref_u, sref_v) = ref_planes(ref_frame, ref_y, ref_u, ref_v, other_refs)?; + let (ox, oy) = if vert { + (cpx + i * piece_w, cpy) + } else { + (cpx, cpy + i * piece_h) + }; + let (dc, dr) = if vert { (i * piece_w, 0) } else { (0, i * piece_h) }; + for (plane, dst) in [(sref_u, &mut pred_u), (sref_v, &mut pred_v)] { + let mut buf = vec![0u16; piece_w * piece_h]; + mc::predict_with_filters( + &plane.data, + plane.width, + plane.true_width, + plane.true_height, + mv_to_q4(ox, mv.1, false), + mv_to_q4(oy, mv.0, false), + piece_w, + piece_h, + h_filter, + v_filter, + &mut buf, + ); + for row in 0..piece_h { + for col in 0..piece_w { + dst[(dr + row) * B4 + dc + col] = buf[row * piece_w + col]; + } + } + } + } + let (u_grid, v_grid) = if last_skip { + u.reconstruct_mc(cpx, cpy, B4, &pred_u, &vec![0i32; B4 * B4]); + v.reconstruct_mc(cpx, cpy, B4, &pred_v, &vec![0i32; B4 * B4]); + (vec![0i32; B4 * B4], vec![0i32; B4 * B4]) + } else { + let around = neighbours.around_mi(group_mi, 8); + let ug = read_inter_plane( + dec, cdfs, TxbSet::Chroma4, scan4, 1, around[1], 0, u, cpx, cpy, B4, base_q_idx, + &pred_u, Some(first_tx_type), None, + )? + .0; + let vg = read_inter_plane( + dec, cdfs, TxbSet::Chroma4, scan4, 2, around[2], 0, v, cpx, cpy, B4, base_q_idx, + &pred_v, Some(first_tx_type), None, + )? + .0; + (ug, vg) + }; + neighbours.record_uv_mode_mi(gr, gc, 2, 2, DC_PRED); + // `update_partition_context` writes `partition_context_lookup[subsize]` + // over the whole 8x8 span -- BLOCK_4X8's width above and height left, the + // same values [`decode_leaf_rect8`] writes for the intra shape. + for cell in 0..2usize { + neighbours.above_side_mi[gc + cell] = bw; + neighbours.left_side_mi[gr + cell] = bh; + } + let round_up_even = |n: usize| n.div_ceil(2) * 2; + let bound_h = round_up_even(neighbours.mi_rows); + let bound_w = round_up_even(neighbours.mi_cols); + let u_state = neighbour_state(&u_grid); + let v_state = neighbour_state(&v_grid); + for cell in 0..2usize { + if cell < 2usize.min(bound_h.saturating_sub(gr)) { + neighbours.left[gr + cell][1] = u_state; + neighbours.left[gr + cell][2] = v_state; + } + if cell < 2usize.min(bound_w.saturating_sub(gc)) { + neighbours.above[gc + cell][1] = u_state; + neighbours.above[gc + cell][2] = v_state; + } + } + Ok(()) +} + +/// Stamps one sub-8x8 inter leaf into every mi cell of its true `w_mi`x`h_mi` +/// footprint (class: a rect block's grid span is its own, never a square guess). +fn grid_stamp_rect( + grid: &mut MiGrid, + mi_row: usize, + mi_col: usize, + w_mi: usize, + h_mi: usize, + ref_frame: i8, + mv: (i32, i32), + is_new_mv: bool, +) { + for dr in 0..h_mi { + for dc in 0..w_mi { + grid.set( + mi_row + dr, + mi_col + dc, + MiInfo { + is_inter: true, + ref_frame, + ref_frame1: None, + mv1: None, + mv, + is_new_mv, + size: w_mi, + size_h: h_mi, + is_global_mv0: false, + is_global_mv1: false, + }, + ); + } + } +} + +/// Decodes one 8x8 leaf of a straddling 16x16 inter-frame block +/// (lane-av1inter8), mirroring [`crate::tile::write_inter_frame_leaf8`]'s +/// exact symbol order: its own skip flag, intra/inter choice and (when +/// inter) `NEARESTMV`/`NEWMV` chain against this leaf's own 2x2-mi mv-stack +/// window, or (when intra) `Y_MODE`, then its own luma and two chroma +/// transform blocks through [`TxbSet::Luma8Inter`]/[`TxbSet::Chroma4`], +/// same as [`decode_leaf8`]'s coefficient layer but with +/// motion-compensated prediction instead of intra prediction when inter. +/// `outer_at` (in [`SUB`]-grid units) is the enclosing 16x16 slot's +/// skip/intra-inter context, overridden by `prev_leaf` exactly as +/// [`decode_leaf8`] overrides mode context: `Neighbours`' above/left arrays +/// only resolve to [`SUB`] granularity. Hands back this leaf's own skip flag +/// and intra/inter choice, for the next leaf or the caller's final +/// write-back. +#[allow(clippy::too_many_arguments)] +fn decode_inter_block8( + dec: &mut SymbolDecoder, + cdfs: &mut Cdfs, + neighbours: &mut Neighbours, + grid: &mut MiGrid, + mi_cols: u32, + mi_rows: u32, + outer_at: (usize, usize), + leaf_mi: (usize, usize), + y: &mut PlaneBuf, + u: &mut PlaneBuf, + v: &mut PlaneBuf, + ref_y: &PlaneBuf, + ref_u: &PlaneBuf, + ref_v: &PlaneBuf, + other_refs: &RefSlots, + base_q_idx: u8, + scan8: &[u16], + scan4: &[u16], + allow_high_precision_mv: bool, + force_integer_mv: bool, + // lane-gmaffine r1: this frame header's own `global_motion` table (spec + // 5.9.24), indexed `[ref_frame - LAST_FRAME]` -- same table + // [`decode_inter_block`] takes, threaded here so the 8x8 leaf can code + // `GLOBALMV` (`gm_get_motion_vector`), fill its mv stack's missing + // candidates with the gm mv (gm r6's root cause) and build a global + // warp prediction. + global_motion: &[ec_av1_syntax::WarpParams; 7], + // lane-gmaffine r1: this sequence header's own `enable_dual_filter` bit, + // for the leaf's own `read_mb_interp_filter` below. + enable_dual_filter: bool, + // lane-av1comp: see [`decode_inter_block`]'s own doc -- this leaf path + // only ever tracks a coarse `LAST_FRAME`-or-intra neighbour shape (no + // per-leaf `above_ref`/`left_ref` array exists here), so `comp_mode`'s + // context uses that same approximation. + reference_select: bool, + enable_masked_compound: bool, + // lane-sb128 r4: see [`decode_inter_block`]'s own doc -- `BLOCK_8X8` is + // always `is_interintra_allowed_bsize`-eligible, so this leaf's own gate + // drops the `side` check entirely. + enable_interintra_compound: bool, + enable_jnt_comp: bool, + order_hint_bits: u32, + order_hint: u32, + ref_order_hints: [u32; 7], + // lane-av1comp round 14: see [`decode_inter_block`]'s own doc -- this + // leaf has no per-leaf `above_skip_mode`/`left_skip_mode` array either, + // so its `skip_mode` context reuses the same [`SUB`]-grid + // `above_skip_mode[cmi]`/`left_skip_mode[rmi]` the enclosing 16x16 slot + // tracks (mirroring `above_skip`/`left_skip`'s own leaf approximation + // just above). + skip_mode_present: bool, + skip_mode_frame: [u8; 2], + // lane-cdffwd2: this frame header's own `reduced_tx_set` bit -- see + // [`decode_inter_frame_tile_with_cdfs`]'s own doc. + reduced_tx_set: bool, + // lane-motionmode round 3: this frame header's own `is_motion_mode_switchable`/ + // `allow_warped_motion` bits (spec 5.11.24's `read_motion_mode`), plus + // the fixed/switchable interp filter kind `obmc_blend`'s own neighbour + // reads need (see [`decode_inter_block`]'s own doc) -- this leaf's own + // prediction is always `Regular` (documented corner-cut, `mc::predict` + // has no filter param), but an OBMC neighbour can be a real 16x16+ + // block that DID resolve a switchable filter. + interp_fixed: Option, + switchable_motion_mode: bool, + allow_warped_motion: bool, + // lane-av1comp: `Some((ref1, comp_group_idx, compound_idx))` only for a + // real `COMPOUND_REFERENCE` leaf, for the caller's own end-of-16x16 + // `record_compound_ctx` call -- mirrors [`decode_inter_block`]'s own + // `compound_ctx` local, just handed back instead of applied here (this + // fn's `neighbours` recording happens once for the whole straddling + // 16x16 block, after every leaf). + // lane-screen r2: see [`decode_inter_block`]'s own copy of this param -- + // `BLOCK_8X8` (this leaf's fixed size) is always `av1_allow_palette`- + // eligible (`bsize >= BLOCK_8X8`). + allow_screen_content_tools: bool, + // lane-inter8 r1: the leaf's mv stacks used to be built without the + // frame's sign-bias table (`NO_SIGN_BIAS`), while [`decode_inter_block`] + // one level up passed it -- it changes the candidate list and with it + // `new_mv_ctx`/`ref_mv_ctx`, `drl_ctx` and the number of symbols read. + // Measured: an 8x8 compound NEAR_NEWMV leaf desynced against aomdec's + // EC_MODE ladder at exactly this block (mi 4,14 of the mandelbrot + // 8x8-split gate). + sign_bias_table: &SignBiasTable, + // lane-inter8 r2: the frame's temporal mv field (spec 7.10.2.8), which + // [`decode_inter_block`] one level up has always passed and this leaf + // passed `None` for -- a `use_ref_frame_mvs` frame's stack then holds + // fewer candidates here than in the reference decoder, which changes the + // mode contexts AND the number of `drl_mode` bits read (class parsed + // then discarded). + tpl_frame: Option<&TplFrameArgs>, + // lane-scaledref r1: this frame's own coded luma width (spec 7.11.3.3), + // for the scaled-reference MC this leaf's own single-ref/compound/OBMC + // predictions take when a stored reference was coded at another width + // (`use_superres`) -- mirrors [`decode_inter_block`]'s own param. + frame_width: usize, +) -> Result<(bool, bool, bool, Option<(i8, i8, u8, u8)>, [u8; 2], (i8, Option))> { + const LAST_FRAME: i8 = 1; + // lane-gmaffine r2: the leaf's OWN switchable-filter symbols, handed back + // so the caller stamps them into `Neighbours` instead of the `[3, 3]` + // placeholder. `[3, 3]` is the "intra neighbour, no filter" sentinel: an + // OBMC blend that picks such a neighbour up feeds it to + // `neighbour_filter`, which PANICS on it (`from_switchable_symbol`) -- + // that was the warp gate's crash, not an entropy desync. Stays `[3, 3]` + // on the intra and compound paths. + let mut leaf_filter_syms = [3u8; 2]; + // lane-gmaffine r1: this leaf's GLOBALMV vector AND the mv stack's + // missing-candidate fallback both come from the frame's global motion + // evaluated at THIS block's centre (gm r6's root cause). + let gm_table = build_gm_mv_table( + global_motion, + leaf_mi.0, + leaf_mi.1, + 2, + 2, + allow_high_precision_mv, + force_integer_mv, + ); + /// `Y_MODE`'s size group (`common_data.h`'s `size_group_lookup[BLOCK_8X8]`). + const SIZE_GROUP_8: usize = 1; + + let (px, py) = (leaf_mi.1 * MI, leaf_mi.0 * MI); + let (cpx, cpy) = (px / 2, py / 2); + // lane-txselect: whether this leaf's `TxMode::Select` var-tx tree took + // the one split a `BLOCK_8X8` can take (`read_block_tx_size` below) -- + // read back by the luma residual read and the tail's neighbour/loop-filter + // bookkeeping. Always `false` outside a `TxMode::Select` inter frame. + let mut split8 = false; + const SIDE: usize = 8; + const CHROMA_SIDE: usize = 4; + + let (r, c) = outer_at; + // lane-inter8 r2: this leaf's OWN mi cell, not the enclosing 16x16's -- + // leaf (mi_r, mi_c + 2)'s left neighbour is leaf (mi_r, mi_c), and the + // left column of a 16x16's second leaf ROW is the previous 16x16 block's + // bottom leaf, neither of which a SUB-grid slot can name. + let (rmi, cmi) = leaf_mi; + // lane-inter8 r2: no sibling-leaf override any more -- each leaf stamps + // its own 2x2-mi span into the bands right after it decodes (the caller's + // `record_inter_rect_mi`), so a plain mi read already names the correct + // neighbour, including one belonging to the previous 16x16 block. + let above_skip = neighbours.above_skip[cmi]; + let left_skip = neighbours.left_skip[rmi]; + let above_inter = neighbours.above_inter[cmi]; + let left_inter = neighbours.left_inter[rmi]; + let above_ref0 = neighbours.above_ref[cmi]; + let above_ref1 = neighbours.above_ref1[cmi]; + let left_ref0 = neighbours.left_ref[rmi]; + let left_ref1 = neighbours.left_ref1[rmi]; + let skip_mode_ctx = + usize::from(neighbours.above_skip_mode[cmi]) + usize::from(neighbours.left_skip_mode[rmi]); + // Same two `inter_segment_id` positions as [`decode_inter_block`]; this + // leaf is always `BLOCK_8X8`, i.e. 2x2 mi. + inter_segment_id(dec, cdfs, leaf_mi.0, leaf_mi.1, 2, 2, false, true); + let skip_mode = skip_mode_present && dec.symbol(&mut cdfs.skip_mode[skip_mode_ctx]) == 1; + if skip_mode { + SKIP_MODE_HITS.with(|c| c.set(c.get() + 1)); + } + + let skip_ctx = usize::from(above_skip) + usize::from(left_skip); + let skip = skip_mode || dec.symbol(&mut cdfs.skip[skip_ctx]) == 1; + inter_segment_id(dec, cdfs, leaf_mi.0, leaf_mi.1, 2, 2, skip, false); + maybe_read_cdef_idx(dec, leaf_mi.0, leaf_mi.1, skip); + // Always a `BLOCK_8X8` leaf here, never the whole superblock. + maybe_read_delta_q(dec, cdfs, leaf_mi.0, leaf_mi.1, false, skip); + maybe_read_delta_lf(dec, cdfs, leaf_mi.0, leaf_mi.1, false, skip); + + let (has_above, has_left) = ( + leaf_mi.0 > neighbours.tile_row0_mi, + leaf_mi.1 > neighbours.tile_col0_mi, + ); + let ii_ctx = intra_inter_ctx(has_above, has_left, above_inter, left_inter); + let is_inter = skip_mode || dec.symbol(&mut cdfs.intra_inter[ii_ctx]) == 1; + // lane-inter8 r1: mirrors the oracle's `EC_MODE` (instrument rung 4, + // `read_inter_block_mode_info`) so an 8x8 leaf's mode-info range ladder + // diffs line for line against a real aomdec. + if std::env::var_os("EC_TRACE_MODE").is_some() { + eprintln!( + "EC_MODE mi_row={} mi_col={} rng={}", + leaf_mi.0, + leaf_mi.1, + dec.debug_state().0 + ); + } + + let mode_for_tx; + // lane-uv8 r1: this leaf's chroma prediction mode (`get_uv_mode` of the + // coded `uv_mode`), for the neighbour bands at the tail. An INTER leaf + // stores `UV_DC_PRED`, exactly as [`decode_inter_block`] one level up. + let mut uv_predict_mode = DC_PRED; + let (luma_grid, u_grid, v_grid); + let mut compound_ctx8: Option<(i8, i8, u8, u8)> = None; + // lane-inter8 r1: this leaf's own resolved references, handed back so the + // NEXT leaf of the same 16x16 can use them as its real above/left + // neighbour (`Neighbours`' arrays only move once per 16x16 block). + // `(0, None)` is intra. + let mut leaf_refs: (i8, Option) = (0, None); + if is_inter { + if reference_select || skip_mode { + // lane-inter8 r1: the REAL neighbour references, not a + // `LAST_FRAME`-or-intra stand-in. `av1_get_reference_mode_context` + // and `read_compound_ref_frames`' own contexts both ask whether a + // neighbour is COMPOUND, so pretending every inter neighbour is + // single-ref LAST picked the wrong `comp_mode` CDF row -- measured + // as an 8x8 leaf reading single-ref where aomdec read compound + // NEAR_NEWMV (mi 4,14). + let above_nbr = has_above.then(|| NeighbourRef { + is_inter: above_inter, + ref0: if above_inter { above_ref0 } else { 0 }, + ref1: above_ref1, + uni: above_ref1.is_some_and(|r1| is_uni_comp_ref(above_ref0, r1)), + }); + let left_nbr = has_left.then(|| NeighbourRef { + is_inter: left_inter, + ref0: if left_inter { left_ref0 } else { 0 }, + ref1: left_ref1, + uni: left_ref1.is_some_and(|r1| is_uni_comp_ref(left_ref0, r1)), + }); + if skip_mode || read_comp_mode(dec, cdfs, above_nbr, left_nbr) { + let (ref0, ref1) = if skip_mode { (skip_mode_frame[0] as i8, skip_mode_frame[1] as i8) } else { // lane-interp3 r2 (class twin-functions-drift): this leaf @@ -21584,6 +22625,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( // instead of silently decoding as SPLIT and desyncing. let part64 = match (has_cols, has_rows) { (true, true) => { + if std::env::var_os("EC_TRACE_PART").is_some() { eprintln!("EC_PART mi_row={} mi_col={} bsize=12 ctx={} rng={}", sb_r as usize * SB_MI as usize, sb_c as usize * SB_MI as usize, sb_ctx, dec.debug_state().0); } let p = dec.symbol(&mut cdfs.partition_w64[sb_ctx]); if std::env::var_os("EC_AV1_TRACE").is_some() { eprintln!( @@ -21768,6 +22810,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( dec.debug_state().0 ); } + if std::env::var_os("EC_TRACE_PART").is_some() { eprintln!("EC_PART mi_row={} mi_col={} bsize=9 ctx={} rng={}", (r32 as usize), (c32 as usize), ctx32, dec.debug_state().0); } let p = dec.symbol(&mut cdfs.partition_w32[ctx32]); if std::env::var_os("EC_AV1_TRACE").is_some() { eprintln!( @@ -21880,6 +22923,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( // inter leaves through the very same loop the // straddling case has always used. let part16 = if has_cols16 && has_rows16 { + if std::env::var_os("EC_TRACE_PART").is_some() { eprintln!("EC_PART mi_row={} mi_col={} bsize=6 ctx={} rng={}", (sr as usize*SUB_MI as usize), (sc as usize*SUB_MI as usize), ctx16, dec.debug_state().0); } let p = dec.symbol(&mut cdfs.partition_w16[ctx16]); if std::env::var_os("EC_AV1_TRACE").is_some() { let (rng, _) = dec.debug_state(); @@ -22190,12 +23234,104 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( for (mr, mc) in leaf_positions { let leaf_mi = (mr as usize, mc as usize); let leaf_ctx = neighbours.partition_ctx_mi(leaf_mi, 8); + if std::env::var_os("EC_TRACE_PART").is_some() { eprintln!("EC_PART mi_row={} mi_col={} bsize=3 ctx={} rng={}", leaf_mi.0, leaf_mi.1, leaf_ctx, dec.debug_state().0); } let part8 = dec.symbol(&mut cdfs.partition_w8[leaf_ctx]); - if part8 != PARTITION_NONE { + if part8 == PARTITION_SPLIT { + // lane-intersub8: four BLOCK_4X4 inter + // sub-blocks, chroma once per 8x8. + decode_inter_sub8_split4( + &mut dec, + &mut cdfs, + &mut neighbours, + &mut grid, + leaf_mi, + 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, + &scan4, + allow_high_precision_mv, + force_integer_mv, + interp_fixed, + enable_dual_filter, + tpl_frame.as_ref(), + reduced_tx_set, + frame_width as usize, + )?; + continue; + } + if part8 == PARTITION_HORZ + && std::env::var_os("EC_AV1_SUB8_HORZ").is_none() + { + // lane-intersub8 r4: the r3 desync IS + // root-caused and fixed (rect masked + // compound read `BLOCK_16X16`'s + // `compound_type`/`wedge_idx` CDF row + // for a 16x8 block); every mode-info + // range on the 28-arm transposed + // sweep now matches aomdec element + // for element. What is left is a + // POST-ENTROPY pixel band: 3 of 28 + // arms (8-bit cq32 sp9, 10-bit cq12 + // sp3, 10-bit cq16 sp3) differ by + // |d| <= 2 in luma only, scattered + // over the bottom-left corner + // (x < 48, y >= 112) from the first + // frame that references an 8x4 group + // -- a filter/reconstruction defect, + // not a desync. Still refused by name + // rather than shipped as silent pixel + // drift; `EC_AV1_SUB8_HORZ=1` decodes + // it for the r5 bisect. return Err(unsupported( - "an inter partition below 8x8 (this decoder codes no inter leaf smaller than 8x8; lane-sub8 scoped to intra)", + "an inter 8x8 HORZ partition (two BLOCK_8X4 inter leaves; entropy-exact now, but a measured sweep still drifts |d|<=2 in luma after the filters)", )); } + if part8 == PARTITION_VERT || part8 == PARTITION_HORZ { + // lane-intersub8 r3/r4: two BLOCK_8X4 + // (HORZ) / BLOCK_4X8 (VERT) inter + // leaves, chroma once per 8x8 on the + // second of them. + decode_inter_sub8_rect2( + &mut dec, + &mut cdfs, + &mut neighbours, + &mut grid, + leaf_mi, + part8 == PARTITION_VERT, + 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, + &scan4, + allow_high_precision_mv, + force_integer_mv, + interp_fixed, + enable_dual_filter, + tpl_frame.as_ref(), + reduced_tx_set, + frame_width as usize, + )?; + continue; + } + // `partition_w8` is a 4-symbol alphabet + // (NONE/HORZ/VERT/SPLIT), all four handled. let ( skip, is_inter, diff --git a/crates/ec-av1/src/refusal_inventory.rs b/crates/ec-av1/src/refusal_inventory.rs index 59d9414f..a69a15f4 100644 --- a/crates/ec-av1/src/refusal_inventory.rs +++ b/crates/ec-av1/src/refusal_inventory.rs @@ -34,6 +34,11 @@ const REFUSALS: &[&str] = &[ "a split intra strip whose transform unit is {tx_w}x{tx_h} (no luma coefficient tables for that shape here)", "an inter partition below 8x8 (this decoder codes no inter leaf smaller than 8x8; lane-sub8 scoped to intra)", "an OBMC neighbour whose interp filter was never recorded (no switchable symbol for that block)", + "an intra 4x4 block inside an inter frame's sub-8x8 split (this decoder codes only inter 4x4 sub-blocks there)", + "an intra 8x4/4x8 block inside an inter frame's sub-8x8 HORZ/VERT partition (this decoder codes only inter sub-blocks there)", + "a sub-8x8 inter block under a scaled reference (superres, unimplemented)", + "an inter 8x8 HORZ partition (two BLOCK_8X4 inter leaves; entropy-exact now, but a measured sweep still drifts |d|<=2 in luma after the filters)", + "a COMPOUND_WEDGE mask on a non-square inter block (rect wedge codebook unimplemented)", "a 1:4 rect strip that actually uses a palette (reconstruction is not ported at this shape)", "a 16x16 block whose true edge cuts through both axes needs a rectangular transform this decoder does not code yet", "a 16x16 inter block whose true edge cuts through both axes needs a rectangular transform this decoder does not code yet", diff --git a/crates/ec-av1/src/stream.rs b/crates/ec-av1/src/stream.rs index 0860b313..62296df9 100644 --- a/crates/ec-av1/src/stream.rs +++ b/crates/ec-av1/src/stream.rs @@ -7915,6 +7915,194 @@ mod tests { } } + /// lane-intersub8: `PARTITION_SPLIT` below 8x8 on an INTER frame -- four + /// `BLOCK_4X4` inter sub-blocks with one shared 4x4 chroma unit per plane, + /// predicted the sub8x8 way (2x2 chroma piece per luma sub-block mv, + /// `dec_build_inter_predictors`' `is_sub8x8` branch). Reality of the shape + /// was established BEFORE the code (class refusal-from-own-desync): the + /// oracle `aomdec`'s `EC_TRACE` prints `EC_PART_VAL ... bsize=3 value=3` + /// on this recipe's inter frames. + /// + /// Attempts 0..7 run `--enable-rect-partitions=0`, where aomenc can only + /// pick SPLIT below 8x8; attempts 8..15 repeat the schedule with rect on, + /// where it picks HORZ/VERT below 8x8 far more often than SPLIT -- the VERT + /// arm (two `BLOCK_4X8` inter leaves, `decode_inter_sub8_rect2`) is what the + /// `rect_fired` assert pins. The HORZ twin decodes but is refused by name + /// (lane-intersub8 r3: a measured sweep desyncs the block to its right). + #[test] + fn a_real_aomenc_inter_sequence_with_a_sub8x8_inter_split_decodes_pixel_exact() { + const NAME: &str = + "a_real_aomenc_inter_sequence_with_a_sub8x8_inter_split_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); + let mut fired = 0u32; + // lane-intersub8 r3: attempts 8..15 repeat the same schedule with + // `--enable-rect-partitions=1`, where aomenc picks PARTITION_VERT below + // 8x8 (two BLOCK_4X8 inter leaves, one shared 4x4 chroma unit predicted + // from BOTH sub-blocks' mvs). The HORZ twin is still refused by name. + let mut rect_fired = 0u32; + let mut refusals: Vec = Vec::new(); + let mut out_of_scope_mismatch = 0u32; + for bit_depth in [8u32, 10u32] { + for attempt in 0..16u32 { + let rect = attempt / 8; + let rect_arg = format!("--enable-rect-partitions={rect}"); + // lane-intersub8 r2, measured schedule (sweep of cq + // {8,10,12,14,16,18,20} x sp {3,6,9,12} x both depths, + // `decode_probe`'s `sub8_inter_split:` counter vs an ffmpeg + // rawvideo compare): sub-8x8 inter SPLIT groups fire at + // (8-bit, cq 12, sp 3) = 1 group and (10-bit, cq 12, sp 6) = + // 3 groups, both pixel-exact. cq 8 and 10 are NOT used: at + // those quantizers this recipe also carries a CDEF defect of + // another shape -- three luma samples of |d| = 1 on + // decode-order frames 3/4, zero sub-8x8 inter split groups, + // and the identical recipe re-encoded with `--enable-cdef=0` + // decodes all six frames exact. Deferred to a CDEF lane + // rather than hidden: cq 16..20 are all exact, so this gate + // is not selecting quantizers that hide a defect of its own + // shape. + let cq = [12, 14][(attempt % 2) as usize]; + let sp = 3 + ((attempt % 8) / 2) * 3; + 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='128+58*sin((X+N*{sp})/6)+18*sin(Y/23)',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 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", + "--lag-in-frames=0", "--enable-obmc=0", "--enable-tx-size-search=1", + // Per-arm overrides last (aomenc keeps the LAST occurrence). + "--enable-rect-partitions=0", "--enable-ab-partitions=0", + "--enable-1to4-partitions=0", "--min-partition-size=4", + "--max-partition-size=16", + &rect_arg, + "--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(), + "{NAME}: aomenc refused the fixture: {}", + String::from_utf8_lossy(&out.stderr) + ); + let stream = out.stdout; + let before = decode::sub8_inter_split_hits(); + let before_rect = decode::sub8_inter_rect_hits(); + 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}" + ); + refusals.push(format!("{bit_depth}-bit attempt {attempt}: {msg}")); + continue; + } + Ok(frames) => frames, + }; + let split_groups = decode::sub8_inter_split_hits() - before; + let rect_now = decode::sub8_inter_rect_hits(); + let rect_groups = (rect_now.0 - before_rect.0) + (rect_now.1 - before_rect.1); + let groups = split_groups + rect_groups; + 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 groups == 0 { + // Out of scope: no sub-8x8 inter split in this attempt. + if mismatched { + out_of_scope_mismatch += 1; + eprintln!( + "{NAME}: {bit_depth}-bit attempt {attempt} MISMATCHES with zero \ + sub-8x8 inter group -- another shape's defect" + ); + } + refusals.push(format!( + "{bit_depth}-bit attempt {attempt}: decoded, but no sub-8x8 inter split" + )); + continue; + } + for (i, (got, want)) in frames.iter().zip(&ffmpeg_frames).enumerate() { + assert_eq!( + got.y, want.y, + "luma frame {i} ({bit_depth}-bit attempt {attempt}, {groups} sub-8x8 \ + inter split groups)" + ); + assert_eq!(got.u, want.u, "U frame {i} ({bit_depth}-bit attempt {attempt})"); + assert_eq!(got.v, want.v, "V frame {i} ({bit_depth}-bit attempt {attempt})"); + } + fired += 1; + if rect_groups > 0 { + rect_fired += 1; + } + } + } + assert_eq!( + out_of_scope_mismatch, 0, + "{NAME}: attempts mismatched with no sub-8x8 inter group" + ); + assert!( + fired >= 2, + "{NAME}: fewer than 2 firing+pixel-exact attempts:\n{}", + refusals.join("\n") + ); + assert!( + rect_fired >= 2, + "{NAME}: fewer than 2 firing+pixel-exact attempts with a RECTANGULAR sub-8x8 \ + inter leaf (4x8):\n{}", + refusals.join("\n") + ); + } + #[test] // lane-inter4 r3: the 16x16-level rect INTER leaf -- PARTITION_HORZ / // PARTITION_VERT at 16x16 on an inter frame, i.e. two 16x8 / 8x16 inter diff --git a/lanes/intersub8-r1.handoff.md b/lanes/intersub8-r1.handoff.md new file mode 100644 index 00000000..57bfe716 --- /dev/null +++ b/lanes/intersub8-r1.handoff.md @@ -0,0 +1,64 @@ +# lane-intersub8 r1 — HANDOFF (RED, code committed, gate red) + +## 1. The refusal is REAL, not our desync (settled, do not re-litigate) +`aomenc` genuinely writes sub-8x8 partitions on INTER frames. +Recipe (192x128, 6 frames, gray ramp `128+58*sin((X+N*8)/6)+18*sin(Y/23)`, cq 8, +`--min-partition-size=4 --max-partition-size=16 --enable-rect-partitions=1 +--enable-ab-partitions=0 --enable-1to4-partitions=0 --enable-obmc=0 +--enable-tx-size-search=1 --sb-size=64 --lag-in-frames=0`), oracle: +`EC_TRACE=1 ~/.cache/aom-oracle/build/aomdec --rawvideo -o /dev/null u8_8.obu 2>ec.log` +`EC_PART_VAL bsize=3` histogram: **v0=68 NONE, v1=28 HORZ, v2=49 VERT, v3=3 SPLIT**. +So 8x4/4x8 dominate; 4x4 SPLIT is rare. `--enable-rect-partitions=0` removes +HORZ/VERT below 8x8 and still yields SPLIT groups (2 per stream at cq 8). + +Side fact worth a sweep: the SAME trace shows `bsize=6 value=6/7` (VERT_A/VERT_B at +16x16) even though `--enable-ab-partitions=0` was on the command line — that is what +the "inter 16x16-level AB or 1:4 partition" refusal fires on for recipes with +`--min-partition-size=4`. Either the flag is not honoured at that size or the +refusal is itself hallucinated; lane-inter16ab should check with this trace. + +## 2. What landed (compiles, `cargo check` clean) +* `crates/ec-av1/src/decode.rs` `decode_inter_sub8_split4` (new fn, above + `decode_inter_block8`): four `BLOCK_4X4` inter sub-blocks of one 8x8 group. + Symbols deliberately NOT read below 8x8, with libaom citations in the doc + comment: `skip_mode` / `comp_mode` (`is_comp_ref_allowed`, blockd.h), + `interintra` (`is_interintra_allowed_bsize`), `motion_mode`/`obmc` + (`motion_mode_allowed`), tx size (`block_signals_txsize`, blockd.h:1027 — + `bsize > BLOCK_4X4`, so `BLOCK_4X4` reads NO tx symbol even in TX_MODE_SELECT, + decodeframe.c:1164-1177). Chroma once per 8x8 on the last sub-block, 4x4 TX, + prediction = four 2x2 chroma pieces each from its own sub-block's mv/ref/filters + (`dec_build_inter_predictors` is_sub8x8; spec 7.11.3.1). Chroma tx_type inherits + the FIRST sub-block's luma tx_type (`av1_get_tx_type` co-located luma 0,0). +* call site: `decode.rs` ~21834, `part8 == PARTITION_SPLIT` dispatches; HORZ/VERT + now refuse under a NARROWED string (rect sub-8x8 inter transform unimplemented). +* counter `SUB8_INTER_SPLIT_HITS` / `decode::sub8_inter_split_hits()`. +* `refusal_inventory.rs`: old string replaced by the 3 new ones. +* gate `stream.rs::a_real_aomenc_inter_sequence_with_a_sub8x8_inter_split_decodes_pixel_exact`. + +## 3. Gate result: RED (two separate failures) +`cargo test -p ec-av1 --lib sub8x8_inter_split` +* 8-bit attempt 0 (cq 8, sp 3): **MISMATCHES with ZERO sub-8x8 inter split groups** + → a defect this lane did not introduce and does not own (out-of-scope arm). + Suspect: the oracle's 2 `bsize=3 value=3` in that stream are on the KEY frame + (intra `decode_leaf_split4`), i.e. a pre-existing intra sub-8x8 defect on this + recipe, OR our partition read desyncs before reaching them. CHECK FIRST: run the + oracle trace on that exact stream and print the frame index of each b3 v3. +* 8-bit attempt 1 (cq 12, sp 3): 1 split group, luma **frame 5** mismatches. + Frames 0..4 are exact, so the group is late in the sequence — bisect with + `EC_TRACE_MODE` (`EC_MODE_VAL4` line added for the 4x4 sub-block) against the + oracle's `EC_MODE`/`EC_MODE_VAL` at the same mi, comparing msac RANGE. + Prime suspects, in order: (a) the sub-block `skip` context — I used the + mi-granular `above_skip[cmi]`/`left_skip[rmi]` pair like `decode_inter_block8`, + libaom uses `av1_get_skip_txfm_context`; (b) the chroma 2x2 piece offsets / + which sub-block's filters each piece uses; (c) `record_mi_luma_rect` per 4x4 vs + the group-level chroma neighbour tail; (d) `first_tx_type` when sub-block 0 is + skip (libaom memsets tx_type_map to DCT_DCT for skip — we leave DctDct: OK). + +## 4. Still refused after this round +`an inter 8x8 HORZ/VERT partition (8x4/4x8 inter leaves...)` — needs (1) INTER +TxbSet twins for 4x8/8x4 (`LumaRect4x8Inter`/`Set1`: side 8 tables + +`inter_tx_type_4`, copy `LumaRect4x8` and swap the tx_type slice), (2) a +rectangular var-tx read: for BLOCK_8X4/4X8, TX_MODE_SELECT + !skip reads exactly +ONE `txfm_partition` symbol (max_txsize_rect_lookup = TX_8X4/TX_4X8; split → +TX_4X4), our `read_block_tx_size`/`read_var_tx_size` are square-only. +That is the bulk of the remaining work and is why r1 scoped to SPLIT. diff --git a/lanes/intersub8-r2.handoff.md b/lanes/intersub8-r2.handoff.md new file mode 100644 index 00000000..4a1cc7c0 --- /dev/null +++ b/lanes/intersub8-r2.handoff.md @@ -0,0 +1,66 @@ +# lane-intersub8 r2 — HANDOFF (gate GREEN, 8x4/4x8 not started) + +## Merge state +* `c048e29` main (8e9ba81) merged — no conflicts, `cdf.rs` untouched. +* `e8bb7e7` lane-r14 **b86eb38 merged** (it was NOT on main: main only carries the earlier + `6699ce6`/`a2e2e29`). So `read_var_tx_size` here is `(tx_w,tx_h)`-general with the full + `sub_tx_size_map`, and `read_inter_plane_rect` is available. + NOTE (ledger, lane-inter16ab r3): that merge deletes the "split transform on a 16x16-level + 1:4 inter strip" refusal, so a TX_16X4→TX_8X4 split can reach + `rect_inter_residual_supported(8,4)==false` / `rect_inter_luma_set` `unreachable!()`. + The `LumaRect8x4Inter`/`LumaRect4x8Inter` TxbSets (step 3 below) close that too. + +## Attempt-0 (cq 8) zero-group mismatch — ROOT CAUSE IDENTIFIED, out of scope +Not a sub-8x8 defect: **CDEF**. 3 luma samples `|d|=1`, decode-order frames 3 and 4 +(x=189 resp. 186, y=116/120/124), zero sub-8x8 inter split groups in those frames; the +identical recipe re-encoded with `--enable-cdef=0` decodes all six frames pixel-exact +(`~/.cache/intersub8-tmp/gen.sh 8 3 8 a0_nocdef.obu --enable-cdef=0`, then `cmp.py`). +Also reproduces at cq 10. Deferred to a CDEF lane. The gate moved to cq {12,14} instead of +switching CDEF off (cdef=0 changes aomenc RD and then NO attempt fires a split group). + +## Attempt-1 frame-5 ladder — FIXED (`96eff0c`) +First diverging element: the **switchable interp filter** of the 4x4 sub-block mi(14,46). +Ladder vs aomdec `EC_TRACE_MODE` on `~/.cache/intersub8-tmp/a1_8.obu`: +entry `39095` = , post-`assign_mv` `60392` = , after interp filter ours `51740` vs oracle `57815`. +Cause: the **compound 8x8 inter leaf never called `resolve_interp_filter`** — it hard-coded +`Regular` and recorded the `[3, 3]` sentinel in the neighbour filter band. libaom calls +`read_mb_interp_filter` for every inter block right after `read_compound_type`, and when +`av1_is_interp_needed()==0` (`skip_mode`) `set_default_interp_filters` stores +EIGHTTAP_REGULAR **0**. The left neighbour here was a skip_mode compound 8x8 leaf, so our +`av1_get_pred_context_switchable_interp` used 3 instead of 0 → wrong CDF row → desync. +Fix reads the symbols, uses `h_filter`/`v_filter` in all six `predict_compound_*` calls of +that branch, records the real syms. This also removes the old lane-av1comp corner-cut +(a NON-skip compound 8x8 leaf used to skip the symbol entirely = latent desync). +New rungs for the next hunt: `EC_TRACE_MODE` now prints `EC_MODE` + `EC_MODE_MV` on the +sub-8x8 path at the oracle's two print points, and `EC_AV1_IFDBG` prints `IFDBG4` with the +neighbour ref/filter bands. + +## 8x4/4x8 (charter step 3) — NOT STARTED +Still refused by name: `an inter 8x8 HORZ/VERT partition (8x4/4x8 inter leaves; the 4x4 +SPLIT arm decodes, but a rectangular sub-8x8 inter transform is unimplemented)`. +Remaining pieces: `TxbSet::LumaRect8x4Inter{,1}` / `LumaRect4x8Inter{,1}` (copy the key-frame +8x4/4x8 intra sets' scan/ctx, swap in `inter_tx_type_4`; `av1_get_ext_tx_set_type` → +EXT_TX_SET_ALL16 for inter with `sqr_up == TX_8X8`), ONE `txfm_partition` bit at max +TX_8X4/TX_4X8 (r14's general `read_var_tx_size` handles it once max=(8,4)), mode info per +sub-block, chroma once on the LAST sub-block as 4x4 with 2 sub8x8 pieces, per-mi neighbour +writes. Gate arm: same recipe with `--enable-rect-partitions=1` (oracle histogram on the r1 +recipe: bsize=3 v1=28 HORZ, v2=49 VERT, v3=3 SPLIT). + +## Gate state +`cargo test -p ec-av1 --lib sub8x8_inter_split` → **ok, 1 passed / 0 failed** (414 filtered). +Schedule measured by a 56-encode sweep (`~/.cache/intersub8-tmp/sweep.sh`): cq {12,14} × +sp {3,6,9,12} × 8/10-bit. Firing: 8-bit cq12/sp3 = 1 group, 10-bit cq12/sp6 = 3 groups, both +pixel-exact; `out_of_scope_mismatch == 0`; every decode-order frame compared Y/U/V. +`decode_probe` now prints `sub8_inter_split: groups=N`. +`fixtures/realworld/reelb.obu` now stops at the 8x4/4x8 refusal (was: the SPLIT one). + +## Suite +Unit `intersub8-suite-1788328909.service`, log `$HOME/.cache/intersub8-suite-r2.log`. +FINISHED GREEN after this handoff was first written: +`test result: ok. 382 passed; 0 failed; 33 ignored; 0 measured; 0 filtered out; finished in 1018.88s`. +That run IS the sibling sweep for the interp-filter fix (it touches every compound 8x8 leaf). + +## Exact next step +1. Read the suite log (above). 2. Build `LumaRect8x4Inter`/`LumaRect4x8Inter` TxbSets and the +8x4/4x8 leaf, add the `--enable-rect-partitions=1` gate arm plus a `--tile-columns=1` arm +(COMMON neighbour-map rule, still owed), then drop the 8x4/4x8 refusal + inventory line. diff --git a/lanes/intersub8-r2.report.md b/lanes/intersub8-r2.report.md new file mode 100644 index 00000000..59520396 --- /dev/null +++ b/lanes/intersub8-r2.report.md @@ -0,0 +1,70 @@ +# lane-intersub8 r2 — GREEN gate, one root cause, 8x4/4x8 deferred + +## 1. Merges +* `c048e29` main (8e9ba81) into lane-intersub8 — no conflicts, `cdf.rs` untouched. +* `e8bb7e7` lane-r14 (b86eb38) — `read_var_tx_size` is now `(tx_w,tx_h)`-general with the + full `sub_tx_size_map`, plus `read_inter_plane_rect`. `b86eb38` was NOT on main + (`git merge-base --is-ancestor b86eb38 main` → false; main only has the earlier + `6699ce6` merge of `a2e2e29`). + +## 2. Root cause of the frame-5 red (fixed, `96eff0c`) +`crates/ec-av1/src/decode.rs` (8x8 inter leaf, compound arm, ~19940): the branch +**never called `resolve_interp_filter`**. It hard-coded `Regular` for both taps and left +`leaf_filter_syms` at the `[3, 3]` "no filter" sentinel that `Neighbours::record_inter*` +then stored. libaom reads `read_mb_interp_filter` for every inter block right after +`read_compound_type` (`decodemv.c` `read_inter_block_mode_info`), and when +`av1_is_interp_needed` is 0 (`skip_mode`, `WARPED_CAUSAL`, non-translational GLOBALMV) +`set_default_interp_filters` stores **EIGHTTAP_REGULAR (0)**, not a sentinel. Any later +block whose `ref_frame[0]` matches that leaf's ref0 **or ref1** then computes +`av1_get_pred_context_switchable_interp` from 3 instead of 0 → wrong `switchable_interp` +CDF row → tile desync. + +Bisection (class *compare range not tell*): on `a1_8.obu` (192x128, 8-bit, cq 12, sp 3) +the 4x4 sub-block at mi(14,46) matched the oracle at both of aomdec's own print points — +entry `rng=39095`, post-`assign_mv` `rng=60392` — and diverged only across the interp +filter read: ours `51740` vs aomdec `57815`. `IFDBG4` showed `left_ref=1 left_ref1=Some(4) +ref=4 left_filt=[3,3]`: the left neighbour was a **skip_mode compound 8x8 leaf** (its own +`EC_MODE` → `EC_MODE_VAL` range never moved, i.e. zero symbols). + +Fix reads the filter properly (`skip_mode` → `force_regular`, ctx from the same ref-match +rule the other leaves use), feeds `h_filter`/`v_filter` to all six `predict_compound_*` +calls of that branch and records the real symbols. This also removes the long-standing +`lane-av1comp` corner-cut: a **non-skip** compound 8x8 leaf used to skip the symbol +entirely, which was a latent desync for any stream that codes one. + +## 3. Out-of-scope defect found and named (NOT hidden) +Same recipe at **cq 8 / cq 10**: three luma samples of `|d| = 1` on decode-order frames 3 +and 4 (x=189 resp. 186, y=116/120/124), with **zero** sub-8x8 inter split groups in those +frames. Re-encoding the identical recipe with `--enable-cdef=0` decodes all six frames +pixel-exact ⇒ a **CDEF** defect of another shape. +`deferred: CDEF ±1 luma at cq 8/10 on the 192x128 min-partition-4 recipe — belongs to a +CDEF lane, not to sub-8x8 partitions — unblocked by a CDEF-focused gate`. +The gate does not switch CDEF off (that changes aomenc's RD and kills every firing +attempt); it moves to cq {12,14}, where a full sweep shows no mismatch at all. + +## 4. Gate +`cargo test -p ec-av1 --lib sub8x8_inter_split` → +`test result: ok. 1 passed; 0 failed` (414 filtered out). +Schedule measured, not guessed: sweep of cq {8,10,12,14,16,18,20} × sp {3,6,9,12} × 8/10-bit +(`decode_probe`'s new `sub8_inter_split:` counter + an ffmpeg rawvideo compare). +Firing attempts: 8-bit cq12/sp3 = 1 group, 10-bit cq12/sp6 = 3 groups, both pixel-exact, +every decode-order frame compared Y/U/V; `out_of_scope_mismatch == 0`. + +EVIDENCE: ~/.cache/intersub8-tmp/a1_8.obu + ours.if.log + oracle.mode.log | aomenc 192x128 8-bit cq12 min-partition-size=4, our EC_MODE/EC_MODE_MV rungs vs aomdec EC_TRACE_MODE range ladder at mi(14,46), then a full-frame ffmpeg compare | ladder diverged at the interp filter (51740 vs 57815); after the fix all 6 frames byte-identical (`cmp.py` frames 0..5 exact) +EVIDENCE: ~/.cache/intersub8-tmp/sweep.sh output (56 encodes) | cq×sp×depth sweep, decode_probe counter + ffmpeg compare | 2 firing attempts both EXACT, all cq≥12 attempts EXACT or named-refusal, cq 8/10 carry the CDEF ±1 +EVIDENCE: fixtures/realworld/reelb.obu | decode_probe on the merged tree | now stops at "an inter 8x8 HORZ/VERT partition (8x4/4x8 inter leaves...)" — the sub-8x8 SPLIT refusal no longer blocks it + +## 4b. Suite +`intersub8-suite-1788328909.service`, log `$HOME/.cache/intersub8-suite-r2.log`: +`test result: ok. 382 passed; 0 failed; 33 ignored; 0 measured; 0 filtered out; finished in 1018.88s`. +This is the sibling sweep the interp-filter fix owes: it touches every compound 8x8 inter leaf. + +## 5. Not done this round +`deferred: 8x4/4x8 inter leaves (charter step 3) — the turn budget went to the root-cause +hunt and the gate schedule — unblocked by a fresh round on this branch; r14's general +read_var_tx_size is now merged here, so the remaining pieces are the LumaRect8x4Inter / +LumaRect4x8Inter TxbSets (EXT_TX_SET_ALL16, sqr_up TX_8X8) and the 2-sub-block chroma`. +`deferred: a --tile-columns=1 arm on this gate (COMMON neighbour-map rule) — same budget — +unblocked by the next round`. +The `an inter 8x8 HORZ/VERT partition ...` refusal therefore STAYS; no refusal string was +removed this round, and `refusal_inventory`/`gate_coverage` are unchanged. diff --git a/lanes/intersub8-r3.handoff.md b/lanes/intersub8-r3.handoff.md new file mode 100644 index 00000000..c60f00d8 --- /dev/null +++ b/lanes/intersub8-r3.handoff.md @@ -0,0 +1,79 @@ +# lane-intersub8 r3 — HANDOFF (4x8 gated GREEN, 8x4 implemented but refused) + +## What is wired (decode.rs `decode_inter_sub8_rect2`, ~line 19100) +One function serves both shapes (`vert: bool`); the call site +(`part8 == PARTITION_VERT` arm of the sub-16 SPLIT leaf loop, ~decode.rs:22630) currently +only reaches it with `vert = true`. +* mode info per sub-block in `decodemv.c` `read_inter_frame_mode_info` order: segment_id, + skip, cdef/dq/dlf, intra_inter, single ref only (`is_comp_ref_allowed(BLOCK_8X4)` false -> + no skip_mode, no comp_mode), no interintra / motion_mode / OBMC / warp (all need min dim 8), + `read_mb_interp_filter` DOES run. +* tx: `block_signals_txsize(BLOCK_8X4)` true (blockd.h:1027) -> ONE `txfm_partition` symbol + under TX_MODE_SELECT at `max_txsize_rect_lookup[BLOCK_8X4] = TX_8X4`, through r14's general + `read_var_tx_size` with max `(bw,bh)` and `blk_max_px = 8`; `sub_tx_size_map[TX_8X4]=TX_4X4` + so a split resolves to two TX_4X4 units (libaom's early return). Skip -> `set_txfm_ctxs` + skip_inter arm. +* luma sets NEW in cdf_state.rs: `TxbSet::LumaRect8x4Inter` / `LumaRect8x4InterSet1` = + `LumaRect4x8`'s tables (8x8 coefficient class, 32-position eob_pt) with `inter_tx_type_4` / + `inter_tx_type_4_set1` (EXT_TX_SET_ALL16 at the TX_4X4 inter row). Split TX_4X4 units read + `Luma4Inter{,Set1}`. Whole-leaf unit passes `luma_skip_ctx: None` (it IS the plane block, + `get_txb_ctx_general` fixes 0); split units pass `luma_skip_ctx_rect`. +* chroma once, on the SECOND sub-block (`is_chroma_reference` under 4:2:0: bottom 8x4 / + right 4x8), as one TX_4X4 per plane (`TxbSet::Chroma4`), inheriting the FIRST luma TU's + tx_type; prediction is the sub8x8 one (`reconinter.c build_inter_predictors_sub8x8`, + `row_start = -(block_size_high==4 && ss_y)`): two 4x2 (HORZ) / 2x4 (VERT) pieces, each from + its own sub-block's ref/mv/filters. +* neighbour writes per mi: `grid_stamp_rect` (size=w_mi, size_h=h_mi over the true span), + `record_mode_mi`, `record_inter_rect_mi`, `fill_skip_grid_rect`, `fill_lf_grid_rect`, + `record_mi_luma_rect` per TU; partition tail `above_side_mi = bw`, `left_side_mi = bh`. + +## The 8x4 defect (refused by name, NOT fixed) +Stream: `~/.cache/intersub8-tmp/gen_t.sh 14 3 8 d1.obu --enable-rect-partitions=1` +(transposed-structure geq source: `128+58*sin((Y+N*3)/6)+18*sin(X/23)`, 192x128, 6 frames). +Decode-order frame 5 mismatches; frames 0..4 exact. 4 HORZ groups, all at mi rows 30/31, +cols 4 and 6. +Range ladder (`EC_TRACE_PART=1` ours, new gated print at each partition read, vs aomdec +`EC_TRACE=1` `EC_PART`; and `EC_TRACE_MODE` `EC_MODE`; and `EC_TRACE_COEFF` `tag=all_zero`): +* every element matches through the 16x16 partition read at mi(28,8) (ctx 2 == oracle's 6, + entry rng 37489 both) and through `EC_MODE mi_row=30 mi_col=8 rng=46505` (both); +* that slot is PARTITION_HORZ -> two BLOCK_16X8 at (28,8) and (30,8); +* block (30,8)'s LEFT neighbour is our HORZ 8x4 group at (30,6); +* first divergence is INSIDE (30,8)'s mode info, AFTER its `EC_MODE` print (so skip and + intra_inter are still right) and BEFORE its first coefficient TU: our TU entry rng 54923 vs + oracle 61760 (`EC_COEFF plane=0 tx_size=8` = TX_16X8, all_zero=0 both). all_zero #468 of + 470/473. +=> some per-ROW neighbour band our HORZ group leaves at rows 30/31 is wrong. Remaining +suspects, in read order after the print: `left_ref[30]`, the mv stack (MiGrid cells (30,7)/ +(31,7)), `left_filter[30]`, `left_txfm[30]`. All four were transcribed against libaom and +looked right on inspection -- not bisected. NOTE ledger: this oracle's +`EC_AV1_PREFILT_DUMP` is already post-deblock, so pixel-stage bisection is confounded; use +the range ladder only. + +## Provable vs not +* PROVABLE (gated): two-BLOCK_4X8 (PARTITION_VERT) inter leaves. Sweep + `~/.cache/intersub8-tmp/sweep2.sh` (28 arms, cq {8,12,14,16,20,26,32} x sp {3,6,9,12} x + 8/10-bit, original source, rect on): every arm with `vert4x8 > 0` outside the known-bad + cq8 band decoded pixel-exact; the two cq8 mismatches are r2's CDEF |d|=1 defect. +* NOT PROVABLE: 8x4 (HORZ). `sweep3.sh` (transposed source): 4 of 28 arms mismatch with + `horz8x4 > 0` at cq 12/14/16/32, i.e. outside the CDEF band. Refused by name. + +## Gate +`cargo test -p ec-av1 --lib sub8x8_inter_split` -> ok, 1 passed / 0 failed (414 filtered), +28.94s. The test now runs 16 attempts per depth: 0..7 `--enable-rect-partitions=0` (SPLIT), +8..15 `=1` (VERT). Asserts `fired >= 2`, NEW `rect_fired >= 2`, `out_of_scope_mismatch == 0`, +every decode-order frame Y/U/V. `refusal_inventory` 3/3 ok, `gate_coverage` 9/9 ok. + +## Not done +* Full `cargo test -p ec-av1 --lib` suite: NOT RUN this round (turn cap). r2's unit + `intersub8-suite-1788328909` was still running on a stale binary at round start and is now + gone from the unit list; `$HOME/.cache/intersub8-suite-r2.log` has 218 ok / 0 FAILED and no + `test result:` line. Start r3's suite per COMMON's SUITE RUNS recipe, log + `$HOME/.cache/intersub8-suite-r3.log`. +* HG film probe: not run. +* `--tile-columns=1` gate arm: still owed (no NEW per-mi band was added, all reused). + +## Exact next step +1. Start the r3 suite. 2. Bisect the 8x4 defect on `d1.obu` frame 5 block (30,8) by dumping, +one at a time, the four left-band values our HORZ group writes at rows 30/31 and comparing +against an instrumented aomdec print of `xd->left_mbmi`/`left_txfm_context[0]` at that block. +3. Lift the HORZ refusal with a `sweep3.sh`-based arm once green. diff --git a/lanes/intersub8-r4.handoff.md b/lanes/intersub8-r4.handoff.md new file mode 100644 index 00000000..e6888e98 --- /dev/null +++ b/lanes/intersub8-r4.handoff.md @@ -0,0 +1,70 @@ +# lane-intersub8 r4 — RED on the HORZ lift, GREEN on its root cause + +## What changed +* `crates/ec-av1/src/decode.rs:15981+` — new `bsize_index(w,h)` (libaom `BLOCK_SIZES_ALL` + order), `masked_compound_used_wh`, `wedge_used_wh`. +* `crates/ec-av1/src/decode.rs` (`decode_inter_block`, comp-type block) — `comp_group_idx`'s + gate and the `compound_type` / `wedge_idx` CDF ROWS now come from the block's true + `(write_w, write_h)`, not the caller's square `side`. A 16x8 masked-compound block used to + read `BLOCK_16X16`'s row (index 6) where libaom reads `BLOCK_16X8`'s (index 5). + Class: table-indexed-by-raw-size / CDF-row-held-constant. +* Same site — `COMPOUND_WEDGE` on a non-square block is refused by name (the wedge codebook + here is built per square side only); listed in `refusal_inventory.rs`. +* `crates/ec-av1/src/decode.rs` — `EC_TRACE_MODE` gains `EC_CGI` / `EC_CIDX` / `EC_IF` + (comp_group_idx, compound_idx, interp filter: ctx + value + range). These are the rungs + that localized the defect; the oracle has no per-symbol print between `EC_MODE_MV` and + `EC_MODE_VAL`, so ours had to be split. +* Sub-8x8 HORZ call site — still refused, refusal text rewritten to the measured residue, + and `EC_AV1_SUB8_HORZ=1` decodes it anyway for the next round's bisect. + +## Root cause (r3's open defect), proven +`~/.cache/intersub8-tmp/d1.obu` (192x128, 6 frames, 8-bit, transposed geq source, cq14 sp3, +`--enable-rect-partitions=1`), decode-order frame 5, `BLOCK_16X8` at mi(30,8): +| rung | ours before | ours after | aomdec | +|---|---|---|---| +| `EC_MODE` entry | 46505 | 46505 | 46505 | +| after mv (`EC_MODE_MV`) | 58288 | 58288 | 58288 | +| end of mode info (`EC_MODE_VAL`) | 54923 | **61760** | **61760** | +| next block `EC_MODE` mi(28,12) | 33919 | **60694** | **60694** | +The block reads `comp_group_idx=1` (ctx 0, correct — a ctx sweep 0..5 never reproduced the +oracle), then `compound_type` from the wrong CDF row. The 8x4 group to its left was innocent: +it only changed which value `comp_group_idx` took. + +EVIDENCE: ~/.cache/intersub8-tmp/{o5b.log,o6.log,r4.log} | EC_TRACE_MODE ladder on d1.obu before/after the fix vs instrumented aomdec | end-of-mode-info rng 54923 -> 61760 == oracle, and `cmp` of the probe output vs `ffmpeg -pix_fmt yuv420p` is byte-identical for all 6 frames +EVIDENCE: ~/.cache/intersub8-tmp/sweep3.sh output (28 arms, transposed source, cq {8,12,14,16,20,26,32} x sp {3,6,9,12} x 8/10-bit, rect on) | full re-run under `systemd-run --scope` | mismatching arms with horz8x4>0: 4 (r3) -> 3; 8-bit cq14 sp3 (horz=4) and cq20 sp3 (horz=4) went MISMATCH -> EXACT + +## Why the HORZ refusal did NOT lift (RED) +3 of 28 arms still mismatch with `horz8x4 > 0`: 8-bit cq32 sp9 (horz=3), 10-bit cq12 sp3 +(horz=5), 10-bit cq16 sp3 (horz=2). On the 10-bit cq12 sp3 stream the ENTROPY IS EXACT — the +full `EC_MODE` range ladder is identical to aomdec's element for element (the only diff is two +extra `EC_MODE` prints for blocks aomdec's instrumentation does not print). The mismatch is +post-entropy: luma only, `|d| <= 2`, confined to x < 48 / y >= 112 (mi rows 28..31, mi cols +0..11), first appearing on decode-order frame 3 and propagating. Shape says filter (CDEF or +the deblock of the internal 8x4 edge), not reconstruction of the coefficients. +EVIDENCE: ~/.cache/intersub8-tmp/{a.txt,b.txt,m1.ours,m1.ref} | `diff` of the two EC_MODE ladders + per-frame python pixel diff | ladder diff = 2 extra lines, 0 range mismatches; frame 3: 125 differing luma samples, max |d| = 2, all in x<48 y>=112 + +## Gates +* `sub8x8_inter_split` (the r3 gate, SPLIT + VERT arms) unchanged — HORZ arm NOT added, since + the shape is still refused. +* No new gate for the masked-compound fix: measured, the only streams that reach a rect + masked-compound block are HORZ ones, which the refusal blocks. `deferred: gate for the rect + compound_type/wedge_idx row — no non-HORZ recipe found that produces a rect block with + comp_group_idx==1 — unblocked by either the HORZ lift or a `--enable-masked-comp` sweep on + rect-heavy square-only content.` +* Full suite: unit `intersub8-suite-r4-1788331918.service` -> `$HOME/.cache/intersub8-suite-r4.log`, + STILL RUNNING at hand-off (74 ok, 0 FAILED, no `test result:` line yet). NOT a green claim. + r3's unit (`intersub8-suite-1788331066`) was stopped as charter-ordered; its log had 73 ok / + 0 FAILED and no `test result:` line at stop time. + +## Film probe +0.4 s copy-extract at 0 s of the 2160p 10-bit HDR AV1 film yields only 1817 bytes (one OBU +set, no full frame); the probe returns counters (`horz8x4=0`) and no refusal, so the census's +start_s=0 refusal ("an inter partition below 8x8") is NOT reproduced by that extract. +`deferred: HG below-8x8 census probe — the bounded extract is too small to reach the block — +unblocked by extracting from a keyframe offset (census4 reelb4.tsv start_s column).` + +## Residue +* fix-now(next round): the |d|<=2 luma band under HORZ. Reproduce with + `EC_AV1_SUB8_HORZ=1` on `~/.cache/intersub8-tmp/t_10_12_3.obu` (regenerate: + `./gen_t.sh 12 3 10 m1.obu --enable-rect-partitions=1`). +* accepted: `COMPOUND_WEDGE` on a rect block refused (rect wedge codebooks unimplemented). diff --git a/lanes/intersub8-r4.report.md b/lanes/intersub8-r4.report.md new file mode 100644 index 00000000..e6888e98 --- /dev/null +++ b/lanes/intersub8-r4.report.md @@ -0,0 +1,70 @@ +# lane-intersub8 r4 — RED on the HORZ lift, GREEN on its root cause + +## What changed +* `crates/ec-av1/src/decode.rs:15981+` — new `bsize_index(w,h)` (libaom `BLOCK_SIZES_ALL` + order), `masked_compound_used_wh`, `wedge_used_wh`. +* `crates/ec-av1/src/decode.rs` (`decode_inter_block`, comp-type block) — `comp_group_idx`'s + gate and the `compound_type` / `wedge_idx` CDF ROWS now come from the block's true + `(write_w, write_h)`, not the caller's square `side`. A 16x8 masked-compound block used to + read `BLOCK_16X16`'s row (index 6) where libaom reads `BLOCK_16X8`'s (index 5). + Class: table-indexed-by-raw-size / CDF-row-held-constant. +* Same site — `COMPOUND_WEDGE` on a non-square block is refused by name (the wedge codebook + here is built per square side only); listed in `refusal_inventory.rs`. +* `crates/ec-av1/src/decode.rs` — `EC_TRACE_MODE` gains `EC_CGI` / `EC_CIDX` / `EC_IF` + (comp_group_idx, compound_idx, interp filter: ctx + value + range). These are the rungs + that localized the defect; the oracle has no per-symbol print between `EC_MODE_MV` and + `EC_MODE_VAL`, so ours had to be split. +* Sub-8x8 HORZ call site — still refused, refusal text rewritten to the measured residue, + and `EC_AV1_SUB8_HORZ=1` decodes it anyway for the next round's bisect. + +## Root cause (r3's open defect), proven +`~/.cache/intersub8-tmp/d1.obu` (192x128, 6 frames, 8-bit, transposed geq source, cq14 sp3, +`--enable-rect-partitions=1`), decode-order frame 5, `BLOCK_16X8` at mi(30,8): +| rung | ours before | ours after | aomdec | +|---|---|---|---| +| `EC_MODE` entry | 46505 | 46505 | 46505 | +| after mv (`EC_MODE_MV`) | 58288 | 58288 | 58288 | +| end of mode info (`EC_MODE_VAL`) | 54923 | **61760** | **61760** | +| next block `EC_MODE` mi(28,12) | 33919 | **60694** | **60694** | +The block reads `comp_group_idx=1` (ctx 0, correct — a ctx sweep 0..5 never reproduced the +oracle), then `compound_type` from the wrong CDF row. The 8x4 group to its left was innocent: +it only changed which value `comp_group_idx` took. + +EVIDENCE: ~/.cache/intersub8-tmp/{o5b.log,o6.log,r4.log} | EC_TRACE_MODE ladder on d1.obu before/after the fix vs instrumented aomdec | end-of-mode-info rng 54923 -> 61760 == oracle, and `cmp` of the probe output vs `ffmpeg -pix_fmt yuv420p` is byte-identical for all 6 frames +EVIDENCE: ~/.cache/intersub8-tmp/sweep3.sh output (28 arms, transposed source, cq {8,12,14,16,20,26,32} x sp {3,6,9,12} x 8/10-bit, rect on) | full re-run under `systemd-run --scope` | mismatching arms with horz8x4>0: 4 (r3) -> 3; 8-bit cq14 sp3 (horz=4) and cq20 sp3 (horz=4) went MISMATCH -> EXACT + +## Why the HORZ refusal did NOT lift (RED) +3 of 28 arms still mismatch with `horz8x4 > 0`: 8-bit cq32 sp9 (horz=3), 10-bit cq12 sp3 +(horz=5), 10-bit cq16 sp3 (horz=2). On the 10-bit cq12 sp3 stream the ENTROPY IS EXACT — the +full `EC_MODE` range ladder is identical to aomdec's element for element (the only diff is two +extra `EC_MODE` prints for blocks aomdec's instrumentation does not print). The mismatch is +post-entropy: luma only, `|d| <= 2`, confined to x < 48 / y >= 112 (mi rows 28..31, mi cols +0..11), first appearing on decode-order frame 3 and propagating. Shape says filter (CDEF or +the deblock of the internal 8x4 edge), not reconstruction of the coefficients. +EVIDENCE: ~/.cache/intersub8-tmp/{a.txt,b.txt,m1.ours,m1.ref} | `diff` of the two EC_MODE ladders + per-frame python pixel diff | ladder diff = 2 extra lines, 0 range mismatches; frame 3: 125 differing luma samples, max |d| = 2, all in x<48 y>=112 + +## Gates +* `sub8x8_inter_split` (the r3 gate, SPLIT + VERT arms) unchanged — HORZ arm NOT added, since + the shape is still refused. +* No new gate for the masked-compound fix: measured, the only streams that reach a rect + masked-compound block are HORZ ones, which the refusal blocks. `deferred: gate for the rect + compound_type/wedge_idx row — no non-HORZ recipe found that produces a rect block with + comp_group_idx==1 — unblocked by either the HORZ lift or a `--enable-masked-comp` sweep on + rect-heavy square-only content.` +* Full suite: unit `intersub8-suite-r4-1788331918.service` -> `$HOME/.cache/intersub8-suite-r4.log`, + STILL RUNNING at hand-off (74 ok, 0 FAILED, no `test result:` line yet). NOT a green claim. + r3's unit (`intersub8-suite-1788331066`) was stopped as charter-ordered; its log had 73 ok / + 0 FAILED and no `test result:` line at stop time. + +## Film probe +0.4 s copy-extract at 0 s of the 2160p 10-bit HDR AV1 film yields only 1817 bytes (one OBU +set, no full frame); the probe returns counters (`horz8x4=0`) and no refusal, so the census's +start_s=0 refusal ("an inter partition below 8x8") is NOT reproduced by that extract. +`deferred: HG below-8x8 census probe — the bounded extract is too small to reach the block — +unblocked by extracting from a keyframe offset (census4 reelb4.tsv start_s column).` + +## Residue +* fix-now(next round): the |d|<=2 luma band under HORZ. Reproduce with + `EC_AV1_SUB8_HORZ=1` on `~/.cache/intersub8-tmp/t_10_12_3.obu` (regenerate: + `./gen_t.sh 12 3 10 m1.obu --enable-rect-partitions=1`). +* accepted: `COMPOUND_WEDGE` on a rect block refused (rect wedge codebooks unimplemented).