forge
Explore
Log in

Don't you dare go Hollow

merge: lane-intersub8 a5b9770 into lane-intra14 -- sub-8x8 inter leaves, keep both partition traces

Browse files at this commit

b932b3e884981552463f5d9c9bb2fdc7bc69a1a9Ahmet Kaan GümüşParent: 70abd19823ca8c

12 changed files +2201 -234

crates/ec-av1/examples/decode_probe.rsmodified+3 -0
@@ -41,6 +41,9 @@ fn main() {
4141 "intra_rect4_in_inter: 64x16={} 16x64={} 32x8={} 8x32={}",
4242 i4.0, i4.1, i4.2, i4.3
4343 );
44+ println!("sub8_inter_split: groups={}", ec_av1::decode::sub8_inter_split_hits());
45+ let (h84, h48) = ec_av1::decode::sub8_inter_rect_hits();
46+ println!("sub8_inter_rect: horz8x4={h84} vert4x8={h48}");
4447 let leaf = ec_av1::stream::vartx_rect_leaf_hits();
4548 println!("vartx_rect_leaf: 32x16={} 16x32={}", leaf[0], leaf[1]);
4649 // lane-inter16ab r1: the 16x16-level inter AB arms, so a recipe sweep
crates/ec-av1/src/cdf_state.rsmodified+40 -0
@@ -230,6 +230,22 @@ pub(crate) enum TxbSet {
230230 /// counterpart: `EXT_TX_SET_DTT4_IDTX_1DDCT`, the seven-symbol `TX_4X4`
231231 /// row [`LumaRect4x8Set1`](TxbSet::LumaRect4x8Set1) reads.
232232 LumaRect16x4Set1,
233+ /// The luma 8x4/4x8 transform of an INTER `PARTITION_HORZ`/`PARTITION_VERT`
234+ /// leaf under an 8x8 block (lane-intersub8 r3): every coefficient table is
235+ /// [`LumaRect4x8`](TxbSet::LumaRect4x8)'s (`get_txsize_entropy_ctx` squares
236+ /// `TX_8X4` up to the 8x8 class, 32-position `eob_pt`), with the INTER
237+ /// `tx_type` alphabet in its place. Under `reduced_tx_set`
238+ /// `av1_get_ext_tx_set_type` (`tx_size_sqr_up == TX_8X8`, `is_inter`)
239+ /// returns `EXT_TX_SET_DCT_IDTX`, whose row is
240+ /// `default_inter_ext_tx_cdf[?][txsize_sqr_map[TX_8X4] == TX_4X4]` -- the
241+ /// same `TX_4X4` inter row [`Luma4Inter`](TxbSet::Luma4Inter) reads.
242+ LumaRect8x4Inter,
243+ /// [`LumaRect8x4Inter`](TxbSet::LumaRect8x4Inter)'s `reduced_tx_set: false`
244+ /// counterpart: `tx_size_sqr == TX_4X4` with `tx_size_sqr_up == TX_8X8`, so
245+ /// `av1_ext_tx_set_lookup[is_inter=1][...]` is `EXT_TX_SET_ALL16` -- sixteen
246+ /// symbols at the `TX_4X4` inter row, the table
247+ /// [`Luma4InterSet1`](TxbSet::Luma4InterSet1) also reads.
248+ LumaRect8x4InterSet1,
233249 }
234250
235251 /// The tables one transform block is coded with, borrowed from the state for
@@ -1792,6 +1808,30 @@ impl Cdfs {
17921808 tx_type: Some(self.intra_tx_type_4[mode].as_mut_slice()),
17931809 eob_pt_class1: Some(&mut self.eob_pt_32_luma_class1),
17941810 },
1811+ TxbSet::LumaRect8x4Inter => TxbTables {
1812+ side: 8,
1813+ txb_skip: &mut self.txb_skip_luma_8,
1814+ eob_pt: &mut self.eob_pt_32_luma,
1815+ eob_extra: &mut self.eob_extra_luma_8,
1816+ base: &mut self.base_luma_8,
1817+ base_eob: &mut self.base_eob_luma_8,
1818+ br: &mut self.br_luma_8,
1819+ dc_sign: &mut self.dc_sign_luma,
1820+ tx_type: Some(self.inter_tx_type_4.as_mut_slice()),
1821+ eob_pt_class1: Some(&mut self.eob_pt_32_luma_class1),
1822+ },
1823+ TxbSet::LumaRect8x4InterSet1 => TxbTables {
1824+ side: 8,
1825+ txb_skip: &mut self.txb_skip_luma_8,
1826+ eob_pt: &mut self.eob_pt_32_luma,
1827+ eob_extra: &mut self.eob_extra_luma_8,
1828+ base: &mut self.base_luma_8,
1829+ base_eob: &mut self.base_eob_luma_8,
1830+ br: &mut self.br_luma_8,
1831+ dc_sign: &mut self.dc_sign_luma,
1832+ tx_type: Some(self.inter_tx_type_4_set1.as_mut_slice()),
1833+ eob_pt_class1: Some(&mut self.eob_pt_32_luma_class1),
1834+ },
17951835 TxbSet::LumaRect4x8Set1 => TxbTables {
17961836 side: 8,
17971837 txb_skip: &mut self.txb_skip_luma_8,
crates/ec-av1/src/decode.rsmodified+1404 -233
@@ -1874,6 +1874,21 @@ pub(crate) fn masked_compound_hits() -> usize {
18741874 MASKED_COMPOUND_HITS.with(|c| c.get())
18751875 }
18761876
1877+// lane-intersub8 r4/r5: the NON-SQUARE half of `MASKED_COMPOUND_HITS` -- a
1878+// masked-compound block whose true footprint is rectangular, i.e. the case
1879+// whose `compound_type`/`wedge_idx` CDF row r4 fixed (it used to read the
1880+// square envelope's `BLOCK_SIZES_ALL` index). Square blocks cannot show that
1881+// defect, so a gate asserting `masked_compound_hits` alone stays vacuous for it.
1882+thread_local! {
1883+ static RECT_MASKED_COMPOUND_HITS: std::cell::Cell<usize> =
1884+ const { std::cell::Cell::new(0) };
1885+}
1886+
1887+/// Current value of [`RECT_MASKED_COMPOUND_HITS`].
1888+pub(crate) fn rect_masked_compound_hits() -> usize {
1889+ RECT_MASKED_COMPOUND_HITS.with(|c| c.get())
1890+}
1891+
18771892 // How many blocks decoded a real `COMPOUND_WEDGE` block (`comp_group_idx ==
18781893 // 1`, `compound_type == 0`) -- lane-wedge r3's proof a gate fixture
18791894 // actually exercised the wedge blend, not just the DIFFWTD half of
@@ -2698,6 +2713,21 @@ pub(crate) fn tx_class1_hits() -> usize {
26982713 // coincidentally landing on `PARTITION_NONE`.
26992714 thread_local! {
27002715 static SUB8_SPLIT_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
2716+ /// How many 8x8 groups an INTER frame split into four BLOCK_4X4 inter
2717+ /// sub-blocks (lane-intersub8).
2718+ static SUB8_INTER_SPLIT_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
2719+ /// How many 8x8 groups an INTER frame split into two rectangular sub-8x8
2720+ /// inter leaves (lane-intersub8 r3), indexed `[0] = HORZ` (two BLOCK_8X4),
2721+ /// `[1] = VERT` (two BLOCK_4X8).
2722+ static SUB8_INTER_RECT_HITS: std::cell::Cell<[usize; 2]> = const { std::cell::Cell::new([0; 2]) };
2723+}
2724+
2725+/// Current value of [`SUB8_INTER_RECT_HITS`]: `(8x4 groups, 4x8 groups)`.
2726+pub fn sub8_inter_rect_hits() -> (usize, usize) {
2727+ SUB8_INTER_RECT_HITS.with(|c| {
2728+ let h = c.get();
2729+ (h[0], h[1])
2730+ })
27012731 }
27022732
27032733 // lane-cdef r1: (a) how many 8x8 CDEF units `apply_cdef` EXCLUDED because all
@@ -2740,6 +2770,11 @@ pub(crate) fn sub8_split_hits() -> usize {
27402770 SUB8_SPLIT_HITS.with(|c| c.get())
27412771 }
27422772
2773+/// Current value of [`SUB8_INTER_SPLIT_HITS`].
2774+pub fn sub8_inter_split_hits() -> usize {
2775+ SUB8_INTER_SPLIT_HITS.with(|c| c.get())
2776+}
2777+
27432778 // How many 4x8 / 8x4 leaves (lane-tx4x8's `PARTITION_VERT`/`PARTITION_HORZ`
27442779 // of an 8x8 block) this thread's decode reconstructed with REAL coefficients
27452780 // -- a skipped leaf exercises the prediction and the mi bookkeeping but never
@@ -15792,6 +15827,12 @@ fn resolve_interp_filter(
1579215827 } else {
1579315828 sym0
1579415829 };
15830+ if std::env::var_os("EC_TRACE_MODE").is_some() {
15831+ eprintln!(
15832+ "EC_IF ctx0={ctx0} above={above:?} left={left:?} sym0={sym0} sym1={sym1} rng={}",
15833+ dec.debug_state().0
15834+ );
15835+ }
1579515836 (
1579615837 mc::InterpFilterKind::from_switchable_symbol(sym1 as usize),
1579715838 mc::InterpFilterKind::from_switchable_symbol(sym0 as usize),
@@ -16790,6 +16831,67 @@ fn is_any_masked_compound_used_here(side: usize) -> bool {
1679016831 side.min(side) >= 8
1679116832 }
1679216833
16834+/// libaom's `BLOCK_SIZES_ALL` index of a `w`x`h` block (`common_data.h`'s own
16835+/// enum order) -- the row every bsize-indexed CDF (`compound_type_cdf`,
16836+/// `wedge_idx_cdf`) is read at. lane-intersub8 r4: these two used to be
16837+/// indexed by the caller's SQUARE envelope, so a 16x8 compound block read
16838+/// `BLOCK_16X16`'s row (class table-indexed-by-raw-size) and desynced the
16839+/// tile at its first masked-compound rect block.
16840+fn bsize_index(w: usize, h: usize) -> Option<usize> {
16841+ Some(match (w, h) {
16842+ (4, 4) => 0,
16843+ (4, 8) => 1,
16844+ (8, 4) => 2,
16845+ (8, 8) => 3,
16846+ (8, 16) => 4,
16847+ (16, 8) => 5,
16848+ (16, 16) => 6,
16849+ (16, 32) => 7,
16850+ (32, 16) => 8,
16851+ (32, 32) => 9,
16852+ (32, 64) => 10,
16853+ (64, 32) => 11,
16854+ (64, 64) => 12,
16855+ (64, 128) => 13,
16856+ (128, 64) => 14,
16857+ (128, 128) => 15,
16858+ (4, 16) => 16,
16859+ (16, 4) => 17,
16860+ (8, 32) => 18,
16861+ (32, 8) => 19,
16862+ (16, 64) => 20,
16863+ (64, 16) => 21,
16864+ _ => return None,
16865+ })
16866+}
16867+
16868+/// `is_any_masked_compound_used` (libaom `reconinter.h`) on the block's TRUE
16869+/// footprint: `is_comp_ref_allowed` is `AOMMIN(bw, bh) >= 8`, and every
16870+/// shape that clears it has either a wedge or a DIFFWTD compound available.
16871+fn masked_compound_used_wh(w: usize, h: usize) -> bool {
16872+ w.min(h) >= 8
16873+}
16874+
16875+/// `av1_wedge_params_lookup[bsize].wedge_types > 0` (libaom `reconinter.c`):
16876+/// the shapes whose `compound_type` symbol is really coded. Everything else
16877+/// with a compound mask infers `COMPOUND_DIFFWTD` without a symbol.
16878+fn wedge_used_wh(w: usize, h: usize) -> bool {
16879+ matches!(
16880+ (w, h),
16881+ (8, 8)
16882+ | (8, 16)
16883+ | (16, 8)
16884+ | (16, 16)
16885+ | (16, 32)
16886+ | (32, 16)
16887+ | (32, 32)
16888+ | (8, 32)
16889+ | (32, 8)
16890+ | (16, 64)
16891+ | (64, 16)
16892+ )
16893+}
16894+
1679316895 /// Whether a compound reference pair is unidirectional (both references on
1679416896 /// the same temporal side of the current frame) -- `has_uni_comp_refs`
1679516897 /// (libaom `av1_reference_frame_utils.h`/`pred_common.c`'s own definition:
@@ -17579,12 +17681,18 @@ fn decode_inter_block(
1757917681 let group_ctx = get_comp_group_idx_context(neighbours, (rmi, cmi), side);
1758017682 let comp_group_idx = if !skip_mode
1758117683 && enable_masked_compound
17582- && is_any_masked_compound_used_here(side)
17684+ && masked_compound_used_wh(write_w, write_h)
1758317685 {
1758417686 dec.symbol(&mut cdfs.comp_group_idx[group_ctx])
1758517687 } else {
1758617688 0
1758717689 };
17690+ if std::env::var_os("EC_TRACE_MODE").is_some() {
17691+ eprintln!(
17692+ "EC_CGI mi_row={rmi} mi_col={cmi} ctx={group_ctx} val={comp_group_idx} rng={}",
17693+ dec.debug_state().0
17694+ );
17695+ }
1758817696 // lane-maskcomp r2 / lane-wedge r3: `Some(mask_type)` for a
1758917697 // `COMPOUND_DIFFWTD` block, `Some(mask)` (wedge codebook lookup)
1759017698 // for a `COMPOUND_WEDGE` block -- exactly one of the two is set
@@ -17606,12 +17714,11 @@ fn decode_inter_block(
1760617714 // writes NO `compound_type` symbol there and INFERS
1760717715 // `COMPOUND_DIFFWTD` -- only the 1-bit `mask_type` literal
1760817716 // follows. `None` here is exactly that inferred arm.
17609- let wedge_bsize = match side {
17610- 8 => Some(3),
17611- 16 => Some(6),
17612- 32 => Some(9),
17613- _ => None,
17614- };
17717+ // lane-intersub8 r4: the block's TRUE footprint, not the
17718+ // square envelope -- `compound_type_cdf`/`wedge_idx_cdf` are
17719+ // `BLOCK_SIZES_ALL`-indexed.
17720+ let wedge_bsize =
17721+ bsize_index(write_w, write_h).filter(|_| wedge_used_wh(write_w, write_h));
1761517722 let compound_type = match wedge_bsize {
1761617723 Some(b) => dec.symbol(&mut cdfs.compound_type[b]),
1761717724 None => 1,
@@ -17619,6 +17726,14 @@ fn decode_inter_block(
1761917726 if let Some(wedge_bsize) = wedge_bsize.filter(|_| compound_type == 0) {
1762017727 // COMPOUND_WEDGE: lane-wedge r3, codebook checksum-
1762117728 // verified vs independent C dump (wedge.rs).
17729+ if write_w != write_h {
17730+ // lane-intersub8 r4: the wedge codebook here is built
17731+ // per SQUARE side only; a rect block's own codebook
17732+ // (BLOCK_16X8 etc.) is a different mask set.
17733+ return Err(unsupported(
17734+ "a COMPOUND_WEDGE mask on a non-square inter block (rect wedge codebook unimplemented)",
17735+ ));
17736+ }
1762217737 let wedge_index = dec.symbol(&mut cdfs.wedge_idx[wedge_bsize]);
1762317738 let wedge_sign = dec.literal(1);
1762417739 WEDGE_HITS.with(|c| c.set(c.get() + 1));
@@ -17636,6 +17751,9 @@ fn decode_inter_block(
1763617751 }
1763717752 }
1763817753 MASKED_COMPOUND_HITS.with(|c| c.set(c.get() + 1));
17754+ if write_w != write_h {
17755+ RECT_MASKED_COMPOUND_HITS.with(|c| c.set(c.get() + 1));
17756+ }
1763917757 }
1764017758 // corner-cut (lane-av1comp r16/r17, lane-av1blend r1): r16/r17
1764117759 // called this a `predict_compound_intermediate`/`combine_compound`
@@ -17850,6 +17968,12 @@ fn decode_inter_block(
1785017968 ref_order_hints[(ref1 - LAST_FRAME) as usize],
1785117969 );
1785217970 let idx = dec.symbol(&mut cdfs.compound_idx[idx_ctx]);
17971+ if std::env::var_os("EC_TRACE_MODE").is_some() {
17972+ eprintln!(
17973+ "EC_CIDX mi_row={rmi} mi_col={cmi} ctx={idx_ctx} val={idx} rng={}",
17974+ dec.debug_state().0
17975+ );
17976+ }
1785317977 if idx == 1 {
1785417978 (8, 8, 1u8)
1785517979 } else {
@@ -19907,30 +20031,47 @@ fn decode_inter_block(
1990720031 Ok(())
1990820032 }
1990920033
19910-/// Decodes one 8x8 leaf of a straddling 16x16 inter-frame block
19911-/// (lane-av1inter8), mirroring [`crate::tile::write_inter_frame_leaf8`]'s
19912-/// exact symbol order: its own skip flag, intra/inter choice and (when
19913-/// inter) `NEARESTMV`/`NEWMV` chain against this leaf's own 2x2-mi mv-stack
19914-/// window, or (when intra) `Y_MODE`, then its own luma and two chroma
19915-/// transform blocks through [`TxbSet::Luma8Inter`]/[`TxbSet::Chroma4`],
19916-/// same as [`decode_leaf8`]'s coefficient layer but with
19917-/// motion-compensated prediction instead of intra prediction when inter.
19918-/// `outer_at` (in [`SUB`]-grid units) is the enclosing 16x16 slot's
19919-/// skip/intra-inter context, overridden by `prev_leaf` exactly as
19920-/// [`decode_leaf8`] overrides mode context: `Neighbours`' above/left arrays
19921-/// only resolve to [`SUB`] granularity. Hands back this leaf's own skip flag
19922-/// and intra/inter choice, for the next leaf or the caller's final
19923-/// write-back.
20034+/// Decodes one 8x8 group that an inter frame's `partition_w8` symbol split
20035+/// into four `BLOCK_4X4` inter blocks (lane-intersub8: `PARTITION_SPLIT`
20036+/// below 8x8 -- traced live against the oracle `aomdec`'s own `EC_PART_VAL`,
20037+/// which reads `bsize=3 value=3` on real inter frames, so the refusal this
20038+/// replaces was NOT our own desync).
20039+///
20040+/// The inter counterpart of [`decode_leaf_split4`], and a `BLOCK_4X4`-only
20041+/// cut of [`decode_inter_block8`]: at `min(bw, bh) < 8` libaom switches off
20042+/// half the inter syntax, and every one of those is a symbol NOT read here
20043+/// (`decodemv.c` / `blockd.h`, oracle tree):
20044+/// * `skip_mode`: `read_skip_mode` returns 0 without a symbol when
20045+/// `!is_comp_ref_allowed(bsize)` (`AOMMIN(bw, bh) >= 8`, blockd.h).
20046+/// * `comp_mode`: `read_block_reference_mode` returns `SINGLE_REFERENCE` on
20047+/// the same predicate, so a sub-8x8 block is always single-reference.
20048+/// * `interintra`: `is_interintra_allowed_bsize` starts at `BLOCK_8X8`.
20049+/// * `motion_mode` / `obmc`: `motion_mode_allowed` returns
20050+/// `SIMPLE_TRANSLATION` for `block_size_wide < 8 || block_size_high < 8`,
20051+/// and `is_global_mv_block`'s own size term fails, so no warp either.
20052+/// * tx size: `block_signals_txsize(bsize)` is `bsize > BLOCK_4X4`
20053+/// (blockd.h:1027), so a `BLOCK_4X4` reads neither `tx_depth` nor a
20054+/// `txfm_partition` bit even in `TX_MODE_SELECT` -- the transform is
20055+/// `max_txsize_rect_lookup[BLOCK_4X4]` = `TX_4X4`
20056+/// (`decodeframe.c:1164-1177`).
20057+///
20058+/// Chroma is coded ONCE for the whole 8x8 group, on the last sub-block
20059+/// (`is_chroma_reference`: `(mi_row & 1) && (mi_col & 1)` in 4:2:0), as one
20060+/// `TX_4X4` unit per plane -- same rule and same neighbour-context tail as
20061+/// [`decode_leaf_split4`]. Its PREDICTION is the sub8x8 one
20062+/// (`dec_build_inter_predictors`'s `is_sub8x8` branch, `decodeframe.c`; spec
20063+/// 7.11.3.1's `candRow`/`candCol` loop): four 2x2 chroma pieces, each built
20064+/// from its own luma sub-block's reference, motion vector and interpolation
20065+/// filters, never from the last sub-block's mv alone.
1992420066 #[allow(clippy::too_many_arguments)]
19925-fn decode_inter_block8(
20067+fn decode_inter_sub8_split4(
1992620068 dec: &mut SymbolDecoder,
1992720069 cdfs: &mut Cdfs,
1992820070 neighbours: &mut Neighbours,
1992920071 grid: &mut MiGrid,
20072+ group_mi: (usize, usize),
1993020073 mi_cols: u32,
1993120074 mi_rows: u32,
19932- outer_at: (usize, usize),
19933- leaf_mi: (usize, usize),
1993420075 y: &mut PlaneBuf,
1993520076 u: &mut PlaneBuf,
1993620077 v: &mut PlaneBuf,
@@ -19938,203 +20079,1121 @@ fn decode_inter_block8(
1993820079 ref_u: &PlaneBuf,
1993920080 ref_v: &PlaneBuf,
1994020081 other_refs: &RefSlots,
20082+ sign_bias_table: &SignBiasTable,
20083+ global_motion: &[ec_av1_syntax::WarpParams; 7],
1994120084 base_q_idx: u8,
19942- scan8: &[u16],
1994320085 scan4: &[u16],
1994420086 allow_high_precision_mv: bool,
1994520087 force_integer_mv: bool,
19946- // lane-gmaffine r1: this frame header's own `global_motion` table (spec
19947- // 5.9.24), indexed `[ref_frame - LAST_FRAME]` -- same table
19948- // [`decode_inter_block`] takes, threaded here so the 8x8 leaf can code
19949- // `GLOBALMV` (`gm_get_motion_vector`), fill its mv stack's missing
19950- // candidates with the gm mv (gm r6's root cause) and build a global
19951- // warp prediction.
19952- global_motion: &[ec_av1_syntax::WarpParams; 7],
19953- // lane-gmaffine r1: this sequence header's own `enable_dual_filter` bit,
19954- // for the leaf's own `read_mb_interp_filter` below.
19955- enable_dual_filter: bool,
19956- // lane-av1comp: see [`decode_inter_block`]'s own doc -- this leaf path
19957- // only ever tracks a coarse `LAST_FRAME`-or-intra neighbour shape (no
19958- // per-leaf `above_ref`/`left_ref` array exists here), so `comp_mode`'s
19959- // context uses that same approximation.
19960- reference_select: bool,
19961- enable_masked_compound: bool,
19962- // lane-sb128 r4: see [`decode_inter_block`]'s own doc -- `BLOCK_8X8` is
19963- // always `is_interintra_allowed_bsize`-eligible, so this leaf's own gate
19964- // drops the `side` check entirely.
19965- enable_interintra_compound: bool,
19966- enable_jnt_comp: bool,
19967- order_hint_bits: u32,
19968- order_hint: u32,
19969- ref_order_hints: [u32; 7],
19970- // lane-av1comp round 14: see [`decode_inter_block`]'s own doc -- this
19971- // leaf has no per-leaf `above_skip_mode`/`left_skip_mode` array either,
19972- // so its `skip_mode` context reuses the same [`SUB`]-grid
19973- // `above_skip_mode[cmi]`/`left_skip_mode[rmi]` the enclosing 16x16 slot
19974- // tracks (mirroring `above_skip`/`left_skip`'s own leaf approximation
19975- // just above).
19976- skip_mode_present: bool,
19977- skip_mode_frame: [u8; 2],
19978- // lane-cdffwd2: this frame header's own `reduced_tx_set` bit -- see
19979- // [`decode_inter_frame_tile_with_cdfs`]'s own doc.
19980- reduced_tx_set: bool,
19981- // lane-motionmode round 3: this frame header's own `is_motion_mode_switchable`/
19982- // `allow_warped_motion` bits (spec 5.11.24's `read_motion_mode`), plus
19983- // the fixed/switchable interp filter kind `obmc_blend`'s own neighbour
19984- // reads need (see [`decode_inter_block`]'s own doc) -- this leaf's own
19985- // prediction is always `Regular` (documented corner-cut, `mc::predict`
19986- // has no filter param), but an OBMC neighbour can be a real 16x16+
19987- // block that DID resolve a switchable filter.
1998820088 interp_fixed: Option<mc::InterpFilterKind>,
19989- switchable_motion_mode: bool,
19990- allow_warped_motion: bool,
19991- // lane-av1comp: `Some((ref1, comp_group_idx, compound_idx))` only for a
19992- // real `COMPOUND_REFERENCE` leaf, for the caller's own end-of-16x16
19993- // `record_compound_ctx` call -- mirrors [`decode_inter_block`]'s own
19994- // `compound_ctx` local, just handed back instead of applied here (this
19995- // fn's `neighbours` recording happens once for the whole straddling
19996- // 16x16 block, after every leaf).
19997- // lane-screen r2: see [`decode_inter_block`]'s own copy of this param --
19998- // `BLOCK_8X8` (this leaf's fixed size) is always `av1_allow_palette`-
19999- // eligible (`bsize >= BLOCK_8X8`).
20000- allow_screen_content_tools: bool,
20001- // lane-inter8 r1: the leaf's mv stacks used to be built without the
20002- // frame's sign-bias table (`NO_SIGN_BIAS`), while [`decode_inter_block`]
20003- // one level up passed it -- it changes the candidate list and with it
20004- // `new_mv_ctx`/`ref_mv_ctx`, `drl_ctx` and the number of symbols read.
20005- // Measured: an 8x8 compound NEAR_NEWMV leaf desynced against aomdec's
20006- // EC_MODE ladder at exactly this block (mi 4,14 of the mandelbrot
20007- // 8x8-split gate).
20008- sign_bias_table: &SignBiasTable,
20009- // lane-inter8 r2: the frame's temporal mv field (spec 7.10.2.8), which
20010- // [`decode_inter_block`] one level up has always passed and this leaf
20011- // passed `None` for -- a `use_ref_frame_mvs` frame's stack then holds
20012- // fewer candidates here than in the reference decoder, which changes the
20013- // mode contexts AND the number of `drl_mode` bits read (class parsed
20014- // then discarded).
20089+ enable_dual_filter: bool,
2001520090 tpl_frame: Option<&TplFrameArgs>,
20016- // lane-scaledref r1: this frame's own coded luma width (spec 7.11.3.3),
20017- // for the scaled-reference MC this leaf's own single-ref/compound/OBMC
20018- // predictions take when a stored reference was coded at another width
20019- // (`use_superres`) -- mirrors [`decode_inter_block`]'s own param.
20091+ reduced_tx_set: bool,
2002020092 frame_width: usize,
20021-) -> Result<(bool, bool, bool, Option<(i8, i8, u8, u8)>, [u8; 2], (i8, Option<i8>))> {
20093+) -> Result<()> {
2002220094 const LAST_FRAME: i8 = 1;
20023- // lane-gmaffine r2: the leaf's OWN switchable-filter symbols, handed back
20024- // so the caller stamps them into `Neighbours` instead of the `[3, 3]`
20025- // placeholder. `[3, 3]` is the "intra neighbour, no filter" sentinel: an
20026- // OBMC blend that picks such a neighbour up feeds it to
20027- // `neighbour_filter`, which PANICS on it (`from_switchable_symbol`) --
20028- // that was the warp gate's crash, not an entropy desync. Stays `[3, 3]`
20029- // on the intra and compound paths.
20030- let mut leaf_filter_syms = [3u8; 2];
20031- // lane-gmaffine r1: this leaf's GLOBALMV vector AND the mv stack's
20032- // missing-candidate fallback both come from the frame's global motion
20033- // evaluated at THIS block's centre (gm r6's root cause).
20034- let gm_table = build_gm_mv_table(
20035- global_motion,
20036- leaf_mi.0,
20037- leaf_mi.1,
20038- 2,
20039- 2,
20040- allow_high_precision_mv,
20041- force_integer_mv,
20042- );
20043- /// `Y_MODE`'s size group (`common_data.h`'s `size_group_lookup[BLOCK_8X8]`).
20044- const SIZE_GROUP_8: usize = 1;
20045-
20046- let (px, py) = (leaf_mi.1 * MI, leaf_mi.0 * MI);
20047- let (cpx, cpy) = (px / 2, py / 2);
20048- // lane-txselect: whether this leaf's `TxMode::Select` var-tx tree took
20049- // the one split a `BLOCK_8X8` can take (`read_block_tx_size` below) --
20050- // read back by the luma residual read and the tail's neighbour/loop-filter
20051- // bookkeeping. Always `false` outside a `TxMode::Select` inter frame.
20052- let mut split8 = false;
20053- const SIDE: usize = 8;
20054- const CHROMA_SIDE: usize = 4;
20055-
20056- let (r, c) = outer_at;
20057- let _ = (r, c);
20058- // lane-inter8 r2: this leaf's OWN mi cell, not the enclosing 16x16's --
20059- // leaf (mi_r, mi_c + 2)'s left neighbour is leaf (mi_r, mi_c), and the
20060- // left column of a 16x16's second leaf ROW is the previous 16x16 block's
20061- // bottom leaf, neither of which a SUB-grid slot can name.
20062- let (rmi, cmi) = leaf_mi;
20063- // lane-inter8 r2: no sibling-leaf override any more -- each leaf stamps
20064- // its own 2x2-mi span into the bands right after it decodes (the caller's
20065- // `record_inter_rect_mi`), so a plain mi read already names the correct
20066- // neighbour, including one belonging to the previous 16x16 block.
20067- let above_skip = neighbours.above_skip[cmi];
20068- let left_skip = neighbours.left_skip[rmi];
20069- let above_inter = neighbours.above_inter[cmi];
20070- let left_inter = neighbours.left_inter[rmi];
20071- let above_ref0 = neighbours.above_ref[cmi];
20072- let above_ref1 = neighbours.above_ref1[cmi];
20073- let left_ref0 = neighbours.left_ref[rmi];
20074- let left_ref1 = neighbours.left_ref1[rmi];
20075- let skip_mode_ctx =
20076- usize::from(neighbours.above_skip_mode[cmi]) + usize::from(neighbours.left_skip_mode[rmi]);
20077- // Same two `inter_segment_id` positions as [`decode_inter_block`]; this
20078- // leaf is always `BLOCK_8X8`, i.e. 2x2 mi.
20079- inter_segment_id(dec, cdfs, leaf_mi.0, leaf_mi.1, 2, 2, false, true);
20080- let skip_mode = skip_mode_present && dec.symbol(&mut cdfs.skip_mode[skip_mode_ctx]) == 1;
20081- if skip_mode {
20082- SKIP_MODE_HITS.with(|c| c.set(c.get() + 1));
20083- }
20084-
20085- let skip_ctx = usize::from(above_skip) + usize::from(left_skip);
20086- let skip = skip_mode || dec.symbol(&mut cdfs.skip[skip_ctx]) == 1;
20087- inter_segment_id(dec, cdfs, leaf_mi.0, leaf_mi.1, 2, 2, skip, false);
20088- maybe_read_cdef_idx(dec, leaf_mi.0, leaf_mi.1, skip);
20089- // Always a `BLOCK_8X8` leaf here, never the whole superblock.
20090- maybe_read_delta_q(dec, cdfs, leaf_mi.0, leaf_mi.1, false, skip);
20091- maybe_read_delta_lf(dec, cdfs, leaf_mi.0, leaf_mi.1, false, skip);
20092-
20093- let (has_above, has_left) = (
20094- leaf_mi.0 > neighbours.tile_row0_mi,
20095- leaf_mi.1 > neighbours.tile_col0_mi,
20096- );
20097- let ii_ctx = intra_inter_ctx(has_above, has_left, above_inter, left_inter);
20098- let is_inter = skip_mode || dec.symbol(&mut cdfs.intra_inter[ii_ctx]) == 1;
20099- // lane-inter8 r1: mirrors the oracle's `EC_MODE` (instrument rung 4,
20100- // `read_inter_block_mode_info`) so an 8x8 leaf's mode-info range ladder
20101- // diffs line for line against a real aomdec.
20102- if std::env::var_os("EC_TRACE_MODE").is_some() {
20103- eprintln!(
20104- "EC_MODE mi_row={} mi_col={} rng={}",
20105- leaf_mi.0,
20106- leaf_mi.1,
20107- dec.debug_state().0
20095+ const B4: usize = 4;
20096+ SUB8_INTER_SPLIT_HITS.with(|c| c.set(c.get() + 1));
20097+ let (gr, gc) = group_mi;
20098+ let (gpx, gpy) = (gc * MI, gr * MI);
20099+ let (cpx, cpy) = (gpx / 2, gpy / 2);
20100+ // Per-sub-block state the group's chroma prediction needs (spec
20101+ // 7.11.3.1's candRow/candCol loop reads each sub-block's OWN mv/ref/
20102+ // filters), indexed `dr * 2 + dc`.
20103+ let mut piece: [Option<(i8, (i32, i32), mc::InterpFilterKind, mc::InterpFilterKind)>; 4] =
20104+ [None; 4];
20105+ let mut first_tx_type = TxType::DctDct;
20106+ let mut last_skip = true;
20107+ for i in 0..4usize {
20108+ let (dr, dc) = (i / 2, i % 2);
20109+ let lmi = (gr + dr, gc + dc);
20110+ if lmi.0 >= mi_rows as usize || lmi.1 >= mi_cols as usize {
20111+ continue;
20112+ }
20113+ let (rmi, cmi) = lmi;
20114+ let (px, py) = (cmi * MI, rmi * MI);
20115+ inter_segment_id(dec, cdfs, rmi, cmi, 1, 1, false, true);
20116+ // No `skip_mode` symbol: `is_comp_ref_allowed(BLOCK_4X4)` is false.
20117+ let skip_ctx = usize::from(neighbours.above_skip[cmi]) + usize::from(neighbours.left_skip[rmi]);
20118+ let skip = dec.symbol(&mut cdfs.skip[skip_ctx]) == 1;
20119+ inter_segment_id(dec, cdfs, rmi, cmi, 1, 1, skip, false);
20120+ maybe_read_cdef_idx(dec, rmi, cmi, skip);
20121+ maybe_read_delta_q(dec, cdfs, rmi, cmi, false, skip);
20122+ maybe_read_delta_lf(dec, cdfs, rmi, cmi, false, skip);
20123+ let (has_above, has_left) = (
20124+ rmi > neighbours.tile_row0_mi,
20125+ cmi > neighbours.tile_col0_mi,
2010820126 );
20109- }
20110-
20111- let mode_for_tx;
20112- let (luma_grid, u_grid, v_grid);
20113- let mut compound_ctx8: Option<(i8, i8, u8, u8)> = None;
20114- // lane-inter8 r1: this leaf's own resolved references, handed back so the
20115- // NEXT leaf of the same 16x16 can use them as its real above/left
20116- // neighbour (`Neighbours`' arrays only move once per 16x16 block).
20117- // `(0, None)` is intra.
20118- let mut leaf_refs: (i8, Option<i8>) = (0, None);
20119- if is_inter {
20120- if reference_select || skip_mode {
20121- // lane-inter8 r1: the REAL neighbour references, not a
20122- // `LAST_FRAME`-or-intra stand-in. `av1_get_reference_mode_context`
20123- // and `read_compound_ref_frames`' own contexts both ask whether a
20124- // neighbour is COMPOUND, so pretending every inter neighbour is
20125- // single-ref LAST picked the wrong `comp_mode` CDF row -- measured
20126- // as an 8x8 leaf reading single-ref where aomdec read compound
20127- // NEAR_NEWMV (mi 4,14).
20128- let above_nbr = has_above.then(|| NeighbourRef {
20129- is_inter: above_inter,
20130- ref0: if above_inter { above_ref0 } else { 0 },
20131- ref1: above_ref1,
20132- uni: above_ref1.is_some_and(|r1| is_uni_comp_ref(above_ref0, r1)),
20133- });
20134- let left_nbr = has_left.then(|| NeighbourRef {
20135- is_inter: left_inter,
20136- ref0: if left_inter { left_ref0 } else { 0 },
20137- ref1: left_ref1,
20127+ let ii_ctx = intra_inter_ctx(
20128+ has_above,
20129+ has_left,
20130+ neighbours.above_inter[cmi],
20131+ neighbours.left_inter[rmi],
20132+ );
20133+ let is_inter = dec.symbol(&mut cdfs.intra_inter[ii_ctx]) == 1;
20134+ if !is_inter {
20135+ return Err(unsupported(
20136+ "an intra 4x4 block inside an inter frame's sub-8x8 split (this decoder codes \
20137+ only inter 4x4 sub-blocks there)",
20138+ ));
20139+ }
20140+ // Same print point as the oracle's `EC_MODE` (entry of
20141+ // `read_inter_block_mode_info`, i.e. after skip / is_inter), so the
20142+ // two range ladders line up element for element.
20143+ if std::env::var_os("EC_TRACE_MODE").is_some() {
20144+ eprintln!(
20145+ "EC_MODE mi_row={rmi} mi_col={cmi} rng={}",
20146+ dec.debug_state().0
20147+ );
20148+ }
20149+ let ref_frame = read_single_ref(
20150+ dec,
20151+ cdfs,
20152+ neighbours.above_ref[cmi],
20153+ neighbours.above_ref1[cmi],
20154+ neighbours.left_ref[rmi],
20155+ neighbours.left_ref1[rmi],
20156+ );
20157+ let (sref_y, sref_u, sref_v) = ref_planes(ref_frame, ref_y, ref_u, ref_v, other_refs)?;
20158+ if mc::scale_factor(sref_y.width, frame_width) != mc::REF_NO_SCALE {
20159+ return Err(unsupported(
20160+ "a sub-8x8 inter block under a scaled reference (superres, unimplemented)",
20161+ ));
20162+ }
20163+ let gm_table = build_gm_mv_table(
20164+ global_motion,
20165+ rmi,
20166+ cmi,
20167+ 1,
20168+ 1,
20169+ allow_high_precision_mv,
20170+ force_integer_mv,
20171+ );
20172+ let tpl = tpl_frame.map(|t| crate::mvstack::TplArgs {
20173+ field: t.field,
20174+ cur_offset_0: crate::motion_field::get_relative_dist(
20175+ t.order_hint_bits,
20176+ t.order_hint,
20177+ t.ref_order_hints[(ref_frame - LAST_FRAME) as usize],
20178+ ),
20179+ allow_high_precision_mv,
20180+ });
20181+ let stack = crate::mvstack::find_mv_stack_with_sign_bias(
20182+ grid,
20183+ rmi,
20184+ cmi,
20185+ 1,
20186+ 1,
20187+ ref_frame,
20188+ mi_cols as usize,
20189+ mi_rows as usize,
20190+ sign_bias_table,
20191+ &gm_table,
20192+ tpl,
20193+ );
20194+ let not_new = dec.symbol(&mut cdfs.new_mv[stack.new_mv_ctx]) == 1;
20195+ let mut is_globalmv = false;
20196+ let (mv, is_new_mv) = if !not_new {
20197+ let mut idx = 0usize;
20198+ while idx < 2 && stack.entries.len() > idx + 1 {
20199+ if dec.symbol(&mut cdfs.drl_mode[stack.drl_ctx[idx]]) == 0 {
20200+ break;
20201+ }
20202+ idx += 1;
20203+ }
20204+ let base_mv = stack.entries.get(idx).map_or(stack.pred_mv, |e| e.mv);
20205+ (
20206+ read_mv(
20207+ dec,
20208+ &mut cdfs.mv_comp,
20209+ &mut cdfs.mv_joint,
20210+ base_mv,
20211+ allow_high_precision_mv,
20212+ force_integer_mv,
20213+ ),
20214+ true,
20215+ )
20216+ } else {
20217+ let not_zero = dec.symbol(&mut cdfs.zero_mv[stack.zero_mv_ctx]) == 1;
20218+ is_globalmv = !not_zero;
20219+ let mv = if !not_zero {
20220+ gm_table[(ref_frame - LAST_FRAME) as usize]
20221+ } else {
20222+ let nearest = dec.symbol(&mut cdfs.ref_mv[stack.ref_mv_ctx]) == 0;
20223+ if nearest {
20224+ stack.nearest_mv
20225+ } else {
20226+ let mut idx = 1usize;
20227+ while idx < 3 && stack.entries.len() > idx + 1 {
20228+ if dec.symbol(&mut cdfs.drl_mode[stack.drl_ctx[idx]]) == 0 {
20229+ break;
20230+ }
20231+ idx += 1;
20232+ }
20233+ stack.entries.get(idx).map_or(stack.near_mv, |e| e.mv)
20234+ }
20235+ };
20236+ (mv, false)
20237+ };
20238+ // Same print point as the oracle's `EC_MODE_MV` (right after
20239+ // `assign_mv`), the second rung of the sub-8x8 range ladder.
20240+ if std::env::var_os("EC_TRACE_MODE").is_some() {
20241+ eprintln!(
20242+ "EC_MODE_MV mi_row={rmi} mi_col={cmi} mv0=({},{}) rng={}",
20243+ mv.0,
20244+ mv.1,
20245+ dec.debug_state().0
20246+ );
20247+ }
20248+ // No `interintra` and no `motion_mode`/`obmc` symbol below 8x8 (see
20249+ // this function's own doc); `read_mb_interp_filter` still runs.
20250+ let gm_ref = &global_motion[(ref_frame - LAST_FRAME) as usize];
20251+ let above_filter_ctx = if neighbours.above_ref[cmi] == ref_frame
20252+ || neighbours.above_ref1[cmi] == Some(ref_frame)
20253+ {
20254+ neighbours.above_filter[cmi]
20255+ } else {
20256+ [3, 3]
20257+ };
20258+ let left_filter_ctx = if neighbours.left_ref[rmi] == ref_frame
20259+ || neighbours.left_ref1[rmi] == Some(ref_frame)
20260+ {
20261+ neighbours.left_filter[rmi]
20262+ } else {
20263+ [3, 3]
20264+ };
20265+ if std::env::var_os("EC_AV1_IFDBG").is_some() {
20266+ eprintln!(
20267+ "IFDBG4 mi=({rmi},{cmi}) ref={ref_frame} above_ref={} above_ref1={:?} \
20268+ above_filt={:?} left_ref={} left_ref1={:?} left_filt={:?}",
20269+ neighbours.above_ref[cmi],
20270+ neighbours.above_ref1[cmi],
20271+ neighbours.above_filter[cmi],
20272+ neighbours.left_ref[rmi],
20273+ neighbours.left_ref1[rmi],
20274+ neighbours.left_filter[rmi],
20275+ );
20276+ }
20277+ let gm_nontrans = is_globalmv && gm_ref.model != ec_av1_syntax::WarpModel::Translation;
20278+ let (h_filter, v_filter, resolved_filter) = resolve_interp_filter(
20279+ dec,
20280+ cdfs,
20281+ interp_fixed,
20282+ enable_dual_filter,
20283+ gm_nontrans,
20284+ above_filter_ctx,
20285+ left_filter_ctx,
20286+ false,
20287+ );
20288+ if std::env::var_os("EC_TRACE_MODE").is_some() {
20289+ eprintln!(
20290+ "EC_MODE_VAL4 mi_row={rmi} mi_col={cmi} newmv={is_new_mv} globalmv={is_globalmv} \
20291+ ref0={ref_frame} mv0=({},{}) stack={} rng={}",
20292+ mv.0,
20293+ mv.1,
20294+ stack.entries.len(),
20295+ dec.debug_state().0
20296+ );
20297+ }
20298+ grid.set(
20299+ rmi,
20300+ cmi,
20301+ MiInfo {
20302+ is_inter: true,
20303+ ref_frame,
20304+ ref_frame1: None,
20305+ mv1: None,
20306+ mv,
20307+ is_new_mv,
20308+ size: 1,
20309+ size_h: 1,
20310+ is_global_mv0: false,
20311+ is_global_mv1: false,
20312+ },
20313+ );
20314+ piece[i] = Some((ref_frame, mv, h_filter, v_filter));
20315+ let mut pred_y = vec![0u16; B4 * B4];
20316+ mc::predict_with_filters(
20317+ &sref_y.data,
20318+ sref_y.width,
20319+ sref_y.true_width,
20320+ sref_y.true_height,
20321+ mv_to_q4(px, mv.1, true),
20322+ mv_to_q4(py, mv.0, true),
20323+ B4,
20324+ B4,
20325+ h_filter,
20326+ v_filter,
20327+ &mut pred_y,
20328+ );
20329+ // `BLOCK_4X4` never signals a transform size, so the luma unit is the
20330+ // whole block and `get_txb_ctx` takes its `plane_bsize ==
20331+ // txsize_to_bsize[tx_size]` branch (`txb_skip_ctx = 0`, which
20332+ // `read_inter_plane`'s `plane_idx == 0` arm already assumes).
20333+ if skip {
20334+ y.reconstruct_mc(px, py, B4, &pred_y, &vec![0i32; B4 * B4]);
20335+ neighbours.record_mi_luma_rect(lmi, B4, B4, &vec![0i32; B4 * B4]);
20336+ } else {
20337+ let around = neighbours.around_mi(lmi, B4);
20338+ let (luma_grid, tx_type) = read_inter_plane(
20339+ dec,
20340+ cdfs,
20341+ if reduced_tx_set {
20342+ TxbSet::Luma4Inter
20343+ } else {
20344+ TxbSet::Luma4InterSet1
20345+ },
20346+ scan4,
20347+ 0,
20348+ around[0],
20349+ 0,
20350+ y,
20351+ px,
20352+ py,
20353+ B4,
20354+ base_q_idx,
20355+ &pred_y,
20356+ None,
20357+ None,
20358+ )?;
20359+ if i == 0 {
20360+ // `av1_get_tx_type`: an inter block's chroma inherits the
20361+ // tx_type of the CO-LOCATED luma position, which for the
20362+ // group's one chroma unit is luma (0, 0) -- the FIRST
20363+ // sub-block, not the last.
20364+ first_tx_type = tx_type;
20365+ }
20366+ neighbours.record_mi_luma_rect(lmi, B4, B4, &luma_grid);
20367+ }
20368+ neighbours.record_mode_mi(rmi, cmi, 1, 1, DC_PRED);
20369+ neighbours.record_inter_rect_mi(lmi, 1, 1, skip, true, ref_frame, resolved_filter, false);
20370+ neighbours.fill_skip_grid_rect(lmi, 1, 1, skip);
20371+ neighbours.fill_lf_grid_rect(lmi, 1, 1, B4 as u8, B4 as u8, ref_frame.max(LAST_FRAME));
20372+ last_skip = skip;
20373+ }
20374+ // Chroma, once for the whole group, on the last sub-block's own `skip`
20375+ // flag -- prediction from all four sub-blocks (2x2 pieces), residual as
20376+ // one TX_4X4 unit per plane.
20377+ let mut pred_u = vec![0u16; B4 * B4];
20378+ let mut pred_v = vec![0u16; B4 * B4];
20379+ for i in 0..4usize {
20380+ let (dr, dc) = (i / 2, i % 2);
20381+ let Some((ref_frame, mv, h_filter, v_filter)) = piece[i] else {
20382+ continue;
20383+ };
20384+ let (_, sref_u, sref_v) = ref_planes(ref_frame, ref_y, ref_u, ref_v, other_refs)?;
20385+ let (ox, oy) = (cpx + dc * 2, cpy + dr * 2);
20386+ for (plane, dst) in [(sref_u, &mut pred_u), (sref_v, &mut pred_v)] {
20387+ let mut buf = vec![0u16; 4];
20388+ mc::predict_with_filters(
20389+ &plane.data,
20390+ plane.width,
20391+ plane.true_width,
20392+ plane.true_height,
20393+ mv_to_q4(ox, mv.1, false),
20394+ mv_to_q4(oy, mv.0, false),
20395+ 2,
20396+ 2,
20397+ h_filter,
20398+ v_filter,
20399+ &mut buf,
20400+ );
20401+ for row in 0..2 {
20402+ for col in 0..2 {
20403+ dst[(dr * 2 + row) * B4 + dc * 2 + col] = buf[row * 2 + col];
20404+ }
20405+ }
20406+ }
20407+ }
20408+ let (u_grid, v_grid) = if last_skip {
20409+ u.reconstruct_mc(cpx, cpy, B4, &pred_u, &vec![0i32; B4 * B4]);
20410+ v.reconstruct_mc(cpx, cpy, B4, &pred_v, &vec![0i32; B4 * B4]);
20411+ (vec![0i32; B4 * B4], vec![0i32; B4 * B4])
20412+ } else {
20413+ let around = neighbours.around_mi(group_mi, 8);
20414+ let ug = read_inter_plane(
20415+ dec, cdfs, TxbSet::Chroma4, scan4, 1, around[1], 0, u, cpx, cpy, B4, base_q_idx,
20416+ &pred_u, Some(first_tx_type), None,
20417+ )?
20418+ .0;
20419+ let vg = read_inter_plane(
20420+ dec, cdfs, TxbSet::Chroma4, scan4, 2, around[2], 0, v, cpx, cpy, B4, base_q_idx,
20421+ &pred_v, Some(first_tx_type), None,
20422+ )?
20423+ .0;
20424+ (ug, vg)
20425+ };
20426+ neighbours.record_uv_mode_mi(gr, gc, 2, 2, DC_PRED);
20427+ // Same two neighbour tails [`decode_leaf_split4`] runs: the partition
20428+ // context of a `BLOCK_4X4` subsize (`partition_context_lookup` bit 0 = 1,
20429+ // reached by `side_mi = 4` here) and the group's chroma coefficient state.
20430+ for cell in 0..2usize {
20431+ neighbours.left_side_mi[gr + cell] = 4;
20432+ neighbours.above_side_mi[gc + cell] = 4;
20433+ }
20434+ let round_up_even = |n: usize| n.div_ceil(2) * 2;
20435+ let bound_h = round_up_even(neighbours.mi_rows);
20436+ let bound_w = round_up_even(neighbours.mi_cols);
20437+ let u_state = neighbour_state(&u_grid);
20438+ let v_state = neighbour_state(&v_grid);
20439+ for cell in 0..2usize {
20440+ if cell < 2usize.min(bound_h.saturating_sub(gr)) {
20441+ neighbours.left[gr + cell][1] = u_state;
20442+ neighbours.left[gr + cell][2] = v_state;
20443+ }
20444+ if cell < 2usize.min(bound_w.saturating_sub(gc)) {
20445+ neighbours.above[gc + cell][1] = u_state;
20446+ neighbours.above[gc + cell][2] = v_state;
20447+ }
20448+ }
20449+ Ok(())
20450+}
20451+
20452+/// Decodes a `PARTITION_HORZ`/`PARTITION_VERT` of one 8x8 INTER block into two
20453+/// `BLOCK_8X4`/`BLOCK_4X8` inter leaves (lane-intersub8 r3) -- the inter twin of
20454+/// [`decode_leaf_rect8`] and the rectangular sibling of
20455+/// [`decode_inter_sub8_split4`], whose element order it follows exactly.
20456+/// Per sub-block, in libaom `decodemv.c` `read_inter_frame_mode_info` order:
20457+///
20458+/// * `segment_id`, `skip`, `cdef`/`delta_q`/`delta_lf`, `intra_inter`;
20459+/// * NO `skip_mode` symbol: `is_comp_ref_allowed(BLOCK_8X4)` is false
20460+/// (`av1_is_comp_ref_allowed` needs both sides >= 8), so
20461+/// `read_skip_mode` returns 0 without reading and `comp_mode` is never read
20462+/// either (`read_ref_frames`' `is_comp_ref_allowed` guard) -- single
20463+/// reference only;
20464+/// * NO `interintra` and NO `motion_mode`/OBMC/warp symbol: every one of those
20465+/// gates needs `block_size_wide >= 8 && block_size_high >= 8`
20466+/// (`is_interintra_allowed_bsize`, `motion_mode_allowed`), and one side is 4;
20467+/// * `read_mb_interp_filter` DOES run for both sub-blocks.
20468+///
20469+/// The shape's own differences from the four-way split:
20470+///
20471+/// * `block_signals_txsize(BLOCK_8X4)` is true (`bsize > BLOCK_4X4`,
20472+/// blockd.h:1027), so a non-skipped sub-block reads ONE `txfm_partition`
20473+/// symbol under `TX_MODE_SELECT` at `max_txsize_rect_lookup[BLOCK_8X4] ==
20474+/// TX_8X4` ([`read_var_tx_size`]); split resolves to two `TX_4X4` units
20475+/// (`sub_tx_size_map[TX_8X4] == TX_4X4`, libaom's early return), no split to
20476+/// the whole-leaf `TX_8X4`;
20477+/// * the luma coefficient set is [`TxbSet::LumaRect8x4Inter`] (the 8x8
20478+/// coefficient class with a 32-position `eob_pt` and the INTER `TX_4X4`
20479+/// `tx_type` row) for the whole-leaf unit, and the square
20480+/// [`TxbSet::Luma4Inter`] for a split `TX_4X4` unit;
20481+/// * chroma is coded ONCE, on the sub-block that is the chroma reference:
20482+/// `is_chroma_reference` (`av1_common_int.h`) is
20483+/// `((mi_row & 1) || !(bh4 & 1) || !ss_y) && ((mi_col & 1) || !(bw4 & 1) ||
20484+/// !ss_x)`, i.e. under 4:2:0 the BOTTOM 8x4 (`bh4 == 1`, odd) and the RIGHT
20485+/// 4x8 (`bw4 == 1`) -- always the second sub-block here;
20486+/// * that chroma unit's prediction is the sub8x8 one (`reconinter.c`
20487+/// `build_inter_predictors_sub8x8`: `row_start = -(block_size_high == 4 &&
20488+/// ss_y)`, `col_start = -(block_size_wide == 4 && ss_x)`), two 4x2 (HORZ) or
20489+/// 2x4 (VERT) chroma pieces, each from its OWN sub-block's reference, mv and
20490+/// interpolation filters.
20491+#[allow(clippy::too_many_arguments)]
20492+fn decode_inter_sub8_rect2(
20493+ dec: &mut SymbolDecoder,
20494+ cdfs: &mut Cdfs,
20495+ neighbours: &mut Neighbours,
20496+ grid: &mut MiGrid,
20497+ group_mi: (usize, usize),
20498+ vert: bool,
20499+ mi_cols: u32,
20500+ mi_rows: u32,
20501+ y: &mut PlaneBuf,
20502+ u: &mut PlaneBuf,
20503+ v: &mut PlaneBuf,
20504+ ref_y: &PlaneBuf,
20505+ ref_u: &PlaneBuf,
20506+ ref_v: &PlaneBuf,
20507+ other_refs: &RefSlots,
20508+ sign_bias_table: &SignBiasTable,
20509+ global_motion: &[ec_av1_syntax::WarpParams; 7],
20510+ base_q_idx: u8,
20511+ scan4: &[u16],
20512+ allow_high_precision_mv: bool,
20513+ force_integer_mv: bool,
20514+ interp_fixed: Option<mc::InterpFilterKind>,
20515+ enable_dual_filter: bool,
20516+ tpl_frame: Option<&TplFrameArgs>,
20517+ reduced_tx_set: bool,
20518+ frame_width: usize,
20519+) -> Result<()> {
20520+ const LAST_FRAME: i8 = 1;
20521+ // The 8x8 group's own square stride: both leaves' prediction buffers are
20522+ // laid out at it, as every other rect inter unit here is.
20523+ const SIDE: usize = 8;
20524+ let (bw, bh) = if vert { (4usize, 8usize) } else { (8usize, 4usize) };
20525+ let (w_mi, h_mi) = (bw / MI, bh / MI);
20526+ SUB8_INTER_RECT_HITS.with(|c| {
20527+ let mut h = c.get();
20528+ h[usize::from(vert)] += 1;
20529+ c.set(h);
20530+ });
20531+ let (gr, gc) = group_mi;
20532+ let (gpx, gpy) = (gc * MI, gr * MI);
20533+ let (cpx, cpy) = (gpx / 2, gpy / 2);
20534+ // Per-sub-block state the group's one chroma unit predicts from.
20535+ let mut piece: [Option<(i8, (i32, i32), mc::InterpFilterKind, mc::InterpFilterKind)>; 2] =
20536+ [None; 2];
20537+ let mut first_tx_type = TxType::DctDct;
20538+ let mut last_skip = true;
20539+ for i in 0..2usize {
20540+ let lmi = if vert { (gr, gc + i) } else { (gr + i, gc) };
20541+ if lmi.0 >= mi_rows as usize || lmi.1 >= mi_cols as usize {
20542+ continue;
20543+ }
20544+ let (rmi, cmi) = lmi;
20545+ let (px, py) = (cmi * MI, rmi * MI);
20546+ inter_segment_id(dec, cdfs, rmi, cmi, w_mi, h_mi, false, true);
20547+ let skip_ctx =
20548+ usize::from(neighbours.above_skip[cmi]) + usize::from(neighbours.left_skip[rmi]);
20549+ let skip = dec.symbol(&mut cdfs.skip[skip_ctx]) == 1;
20550+ inter_segment_id(dec, cdfs, rmi, cmi, w_mi, h_mi, skip, false);
20551+ maybe_read_cdef_idx(dec, rmi, cmi, skip);
20552+ maybe_read_delta_q(dec, cdfs, rmi, cmi, false, skip);
20553+ maybe_read_delta_lf(dec, cdfs, rmi, cmi, false, skip);
20554+ let (has_above, has_left) = (
20555+ rmi > neighbours.tile_row0_mi,
20556+ cmi > neighbours.tile_col0_mi,
20557+ );
20558+ let ii_ctx = intra_inter_ctx(
20559+ has_above,
20560+ has_left,
20561+ neighbours.above_inter[cmi],
20562+ neighbours.left_inter[rmi],
20563+ );
20564+ let is_inter = dec.symbol(&mut cdfs.intra_inter[ii_ctx]) == 1;
20565+ if !is_inter {
20566+ return Err(unsupported(
20567+ "an intra 8x4/4x8 block inside an inter frame's sub-8x8 HORZ/VERT partition \
20568+ (this decoder codes only inter sub-blocks there)",
20569+ ));
20570+ }
20571+ if std::env::var_os("EC_TRACE_MODE").is_some() {
20572+ eprintln!(
20573+ "EC_MODE mi_row={rmi} mi_col={cmi} rng={}",
20574+ dec.debug_state().0
20575+ );
20576+ }
20577+ let ref_frame = read_single_ref(
20578+ dec,
20579+ cdfs,
20580+ neighbours.above_ref[cmi],
20581+ neighbours.above_ref1[cmi],
20582+ neighbours.left_ref[rmi],
20583+ neighbours.left_ref1[rmi],
20584+ );
20585+ let (sref_y, _, _) = ref_planes(ref_frame, ref_y, ref_u, ref_v, other_refs)?;
20586+ if mc::scale_factor(sref_y.width, frame_width) != mc::REF_NO_SCALE {
20587+ return Err(unsupported(
20588+ "a sub-8x8 inter block under a scaled reference (superres, unimplemented)",
20589+ ));
20590+ }
20591+ let gm_table = build_gm_mv_table(
20592+ global_motion,
20593+ rmi,
20594+ cmi,
20595+ w_mi,
20596+ h_mi,
20597+ allow_high_precision_mv,
20598+ force_integer_mv,
20599+ );
20600+ let tpl = tpl_frame.map(|t| crate::mvstack::TplArgs {
20601+ field: t.field,
20602+ cur_offset_0: crate::motion_field::get_relative_dist(
20603+ t.order_hint_bits,
20604+ t.order_hint,
20605+ t.ref_order_hints[(ref_frame - LAST_FRAME) as usize],
20606+ ),
20607+ allow_high_precision_mv,
20608+ });
20609+ let stack = crate::mvstack::find_mv_stack_with_sign_bias(
20610+ grid,
20611+ rmi,
20612+ cmi,
20613+ w_mi,
20614+ h_mi,
20615+ ref_frame,
20616+ mi_cols as usize,
20617+ mi_rows as usize,
20618+ sign_bias_table,
20619+ &gm_table,
20620+ tpl,
20621+ );
20622+ let not_new = dec.symbol(&mut cdfs.new_mv[stack.new_mv_ctx]) == 1;
20623+ let mut is_globalmv = false;
20624+ let (mv, is_new_mv) = if !not_new {
20625+ let mut idx = 0usize;
20626+ while idx < 2 && stack.entries.len() > idx + 1 {
20627+ if dec.symbol(&mut cdfs.drl_mode[stack.drl_ctx[idx]]) == 0 {
20628+ break;
20629+ }
20630+ idx += 1;
20631+ }
20632+ let base_mv = stack.entries.get(idx).map_or(stack.pred_mv, |e| e.mv);
20633+ (
20634+ read_mv(
20635+ dec,
20636+ &mut cdfs.mv_comp,
20637+ &mut cdfs.mv_joint,
20638+ base_mv,
20639+ allow_high_precision_mv,
20640+ force_integer_mv,
20641+ ),
20642+ true,
20643+ )
20644+ } else {
20645+ let not_zero = dec.symbol(&mut cdfs.zero_mv[stack.zero_mv_ctx]) == 1;
20646+ is_globalmv = !not_zero;
20647+ let mv = if !not_zero {
20648+ gm_table[(ref_frame - LAST_FRAME) as usize]
20649+ } else {
20650+ let nearest = dec.symbol(&mut cdfs.ref_mv[stack.ref_mv_ctx]) == 0;
20651+ if nearest {
20652+ stack.nearest_mv
20653+ } else {
20654+ let mut idx = 1usize;
20655+ while idx < 3 && stack.entries.len() > idx + 1 {
20656+ if dec.symbol(&mut cdfs.drl_mode[stack.drl_ctx[idx]]) == 0 {
20657+ break;
20658+ }
20659+ idx += 1;
20660+ }
20661+ stack.entries.get(idx).map_or(stack.near_mv, |e| e.mv)
20662+ }
20663+ };
20664+ (mv, false)
20665+ };
20666+ if std::env::var_os("EC_TRACE_MODE").is_some() {
20667+ eprintln!(
20668+ "EC_MODE_MV mi_row={rmi} mi_col={cmi} mv0=({},{}) rng={}",
20669+ mv.0,
20670+ mv.1,
20671+ dec.debug_state().0
20672+ );
20673+ }
20674+ let gm_ref = &global_motion[(ref_frame - LAST_FRAME) as usize];
20675+ let above_filter_ctx = if neighbours.above_ref[cmi] == ref_frame
20676+ || neighbours.above_ref1[cmi] == Some(ref_frame)
20677+ {
20678+ neighbours.above_filter[cmi]
20679+ } else {
20680+ [3, 3]
20681+ };
20682+ let left_filter_ctx = if neighbours.left_ref[rmi] == ref_frame
20683+ || neighbours.left_ref1[rmi] == Some(ref_frame)
20684+ {
20685+ neighbours.left_filter[rmi]
20686+ } else {
20687+ [3, 3]
20688+ };
20689+ let gm_nontrans = is_globalmv && gm_ref.model != ec_av1_syntax::WarpModel::Translation;
20690+ let (h_filter, v_filter, resolved_filter) = resolve_interp_filter(
20691+ dec,
20692+ cdfs,
20693+ interp_fixed,
20694+ enable_dual_filter,
20695+ gm_nontrans,
20696+ above_filter_ctx,
20697+ left_filter_ctx,
20698+ false,
20699+ );
20700+ // `read_block_tx_size` (libaom `decodeframe.c`): unlike a `BLOCK_4X4`,
20701+ // this shape signals its transform size. A non-skipped inter block
20702+ // walks the var-tx tree from `max_txsize_rect_lookup[BLOCK_8X4]`; a
20703+ // skipped one codes nothing and records its BLOCK size in both txfm
20704+ // contexts (`set_txfm_ctxs`' `skip_inter` arm).
20705+ let mut leaves: Vec<(usize, usize, usize, usize)> = Vec::new();
20706+ if TX_SELECT_INTER.with(std::cell::Cell::get) && !skip {
20707+ let max_w_mi = w_mi.min((mi_cols as usize).saturating_sub(cmi));
20708+ let max_h_mi = h_mi.min((mi_rows as usize).saturating_sub(rmi));
20709+ read_var_tx_size(
20710+ dec,
20711+ cdfs,
20712+ neighbours,
20713+ lmi,
20714+ SIDE,
20715+ (max_w_mi, max_h_mi),
20716+ (bw, bh),
20717+ 0,
20718+ 0,
20719+ 0,
20720+ &mut leaves,
20721+ );
20722+ } else {
20723+ leaves.push((0, 0, bw, bh));
20724+ set_txfm_ctxs(neighbours, lmi, bw.max(bh), w_mi, h_mi, skip);
20725+ }
20726+ if std::env::var_os("EC_TRACE_MODE").is_some() {
20727+ eprintln!(
20728+ "EC_MODE_VALR mi_row={rmi} mi_col={cmi} newmv={is_new_mv} globalmv={is_globalmv} \
20729+ ref0={ref_frame} mv0=({},{}) stack={} leaves={} rng={}",
20730+ mv.0,
20731+ mv.1,
20732+ stack.entries.len(),
20733+ leaves.len(),
20734+ dec.debug_state().0
20735+ );
20736+ }
20737+ grid_stamp_rect(grid, rmi, cmi, w_mi, h_mi, ref_frame, mv, is_new_mv);
20738+ piece[i] = Some((ref_frame, mv, h_filter, v_filter));
20739+ // Prediction over the leaf's true footprint, laid out at the group's
20740+ // square stride (what `reconstruct_mc_rect` and `read_inter_plane_rect`
20741+ // index with).
20742+ let mut pred_y = vec![0u16; SIDE * SIDE];
20743+ {
20744+ let mut dense = vec![0u16; bw * bh];
20745+ mc::predict_with_filters(
20746+ &sref_y.data,
20747+ sref_y.width,
20748+ sref_y.true_width,
20749+ sref_y.true_height,
20750+ mv_to_q4(px, mv.1, true),
20751+ mv_to_q4(py, mv.0, true),
20752+ bw,
20753+ bh,
20754+ h_filter,
20755+ v_filter,
20756+ &mut dense,
20757+ );
20758+ for row in 0..bh {
20759+ pred_y[row * SIDE..][..bw].copy_from_slice(&dense[row * bw..][..bw]);
20760+ }
20761+ }
20762+ if skip {
20763+ y.reconstruct_mc_rect(px, py, SIDE, bw, bh, &pred_y, &vec![0i32; SIDE * SIDE]);
20764+ neighbours.record_mi_luma_rect(lmi, bw, bh, &vec![0i32; bw * bh]);
20765+ neighbours.fill_lf_grid_rect(lmi, w_mi, h_mi, bw as u8, bh as u8, ref_frame.max(LAST_FRAME));
20766+ } else {
20767+ let (mut last_tw, mut last_th) = (bw, bh);
20768+ for (idx, &(row, col, tw, th)) in leaves.iter().enumerate() {
20769+ let tu_mi = (rmi + row, cmi + col);
20770+ let (tu_px, tu_py) = (px + col * MI, py + row * MI);
20771+ let (tu_grid, tu_tx_type) = if tw == th {
20772+ // A split `TX_4X4` unit: square reader, its own
20773+ // `get_txb_ctx_general` neighbour context (the unit is
20774+ // smaller than its plane block, so the lone-TU 0 does not
20775+ // apply).
20776+ let mut tu_pred = Vec::with_capacity(tw * th);
20777+ for rr in 0..th {
20778+ let start = (row * MI + rr) * SIDE + col * MI;
20779+ tu_pred.extend_from_slice(&pred_y[start..start + tw]);
20780+ }
20781+ let tu_skip_ctx = neighbours.luma_skip_ctx_rect(tu_mi, tw / MI, th / MI);
20782+ read_inter_plane(
20783+ dec,
20784+ cdfs,
20785+ if reduced_tx_set {
20786+ TxbSet::Luma4Inter
20787+ } else {
20788+ TxbSet::Luma4InterSet1
20789+ },
20790+ scan4,
20791+ 0,
20792+ neighbours.around_mi(tu_mi, tw)[0],
20793+ 0,
20794+ y,
20795+ tu_px,
20796+ tu_py,
20797+ tw,
20798+ base_q_idx,
20799+ &tu_pred,
20800+ None,
20801+ Some(tu_skip_ctx),
20802+ )?
20803+ } else {
20804+ // The whole leaf as one `TX_8X4`/`TX_4X8` unit: it IS the
20805+ // plane block, so `get_txb_ctx_general` fixes `txb_skip_ctx`
20806+ // at 0 (`luma_skip_ctx: None`).
20807+ let start = row * MI * SIDE + col * MI;
20808+ read_inter_plane_rect(
20809+ dec,
20810+ cdfs,
20811+ if reduced_tx_set {
20812+ TxbSet::LumaRect8x4Inter
20813+ } else {
20814+ TxbSet::LumaRect8x4InterSet1
20815+ },
20816+ (tw, th),
20817+ SIDE,
20818+ 0,
20819+ neighbours.around_mi_rect(tu_mi, tw, th)[0],
20820+ 0,
20821+ y,
20822+ tu_px,
20823+ tu_py,
20824+ &pred_y[start..],
20825+ None,
20826+ None,
20827+ )?
20828+ };
20829+ if idx == 0 {
20830+ // `av1_get_tx_type`: the group's one chroma unit scales
20831+ // back to luma (0, 0), i.e. the FIRST sub-block's first
20832+ // transform unit.
20833+ first_tx_type = tu_tx_type;
20834+ }
20835+ neighbours.record_mi_luma_rect(tu_mi, tw, th, &tu_grid);
20836+ (last_tw, last_th) = (tw, th);
20837+ }
20838+ neighbours.fill_lf_grid_rect(
20839+ lmi,
20840+ w_mi,
20841+ h_mi,
20842+ last_tw as u8,
20843+ last_th as u8,
20844+ ref_frame.max(LAST_FRAME),
20845+ );
20846+ }
20847+ neighbours.record_mode_mi(rmi, cmi, w_mi, h_mi, DC_PRED);
20848+ neighbours.record_inter_rect_mi(lmi, w_mi, h_mi, skip, true, ref_frame, resolved_filter, false);
20849+ neighbours.fill_skip_grid_rect(lmi, w_mi, h_mi, skip);
20850+ last_skip = skip;
20851+ }
20852+ // The group's single 4x4 chroma unit per plane, on the chroma-reference
20853+ // (second) sub-block's own skip flag.
20854+ const B4: usize = 4;
20855+ let mut pred_u = vec![0u16; B4 * B4];
20856+ let mut pred_v = vec![0u16; B4 * B4];
20857+ let (piece_w, piece_h) = if vert { (2usize, 4usize) } else { (4usize, 2usize) };
20858+ for i in 0..2usize {
20859+ let Some((ref_frame, mv, h_filter, v_filter)) = piece[i] else {
20860+ continue;
20861+ };
20862+ let (_, sref_u, sref_v) = ref_planes(ref_frame, ref_y, ref_u, ref_v, other_refs)?;
20863+ let (ox, oy) = if vert {
20864+ (cpx + i * piece_w, cpy)
20865+ } else {
20866+ (cpx, cpy + i * piece_h)
20867+ };
20868+ let (dc, dr) = if vert { (i * piece_w, 0) } else { (0, i * piece_h) };
20869+ for (plane, dst) in [(sref_u, &mut pred_u), (sref_v, &mut pred_v)] {
20870+ let mut buf = vec![0u16; piece_w * piece_h];
20871+ mc::predict_with_filters(
20872+ &plane.data,
20873+ plane.width,
20874+ plane.true_width,
20875+ plane.true_height,
20876+ mv_to_q4(ox, mv.1, false),
20877+ mv_to_q4(oy, mv.0, false),
20878+ piece_w,
20879+ piece_h,
20880+ h_filter,
20881+ v_filter,
20882+ &mut buf,
20883+ );
20884+ for row in 0..piece_h {
20885+ for col in 0..piece_w {
20886+ dst[(dr + row) * B4 + dc + col] = buf[row * piece_w + col];
20887+ }
20888+ }
20889+ }
20890+ }
20891+ let (u_grid, v_grid) = if last_skip {
20892+ u.reconstruct_mc(cpx, cpy, B4, &pred_u, &vec![0i32; B4 * B4]);
20893+ v.reconstruct_mc(cpx, cpy, B4, &pred_v, &vec![0i32; B4 * B4]);
20894+ (vec![0i32; B4 * B4], vec![0i32; B4 * B4])
20895+ } else {
20896+ let around = neighbours.around_mi(group_mi, 8);
20897+ let ug = read_inter_plane(
20898+ dec, cdfs, TxbSet::Chroma4, scan4, 1, around[1], 0, u, cpx, cpy, B4, base_q_idx,
20899+ &pred_u, Some(first_tx_type), None,
20900+ )?
20901+ .0;
20902+ let vg = read_inter_plane(
20903+ dec, cdfs, TxbSet::Chroma4, scan4, 2, around[2], 0, v, cpx, cpy, B4, base_q_idx,
20904+ &pred_v, Some(first_tx_type), None,
20905+ )?
20906+ .0;
20907+ (ug, vg)
20908+ };
20909+ neighbours.record_uv_mode_mi(gr, gc, 2, 2, DC_PRED);
20910+ // `update_partition_context` writes `partition_context_lookup[subsize]`
20911+ // over the whole 8x8 span -- BLOCK_4X8's width above and height left, the
20912+ // same values [`decode_leaf_rect8`] writes for the intra shape.
20913+ for cell in 0..2usize {
20914+ neighbours.above_side_mi[gc + cell] = bw;
20915+ neighbours.left_side_mi[gr + cell] = bh;
20916+ }
20917+ let round_up_even = |n: usize| n.div_ceil(2) * 2;
20918+ let bound_h = round_up_even(neighbours.mi_rows);
20919+ let bound_w = round_up_even(neighbours.mi_cols);
20920+ let u_state = neighbour_state(&u_grid);
20921+ let v_state = neighbour_state(&v_grid);
20922+ for cell in 0..2usize {
20923+ if cell < 2usize.min(bound_h.saturating_sub(gr)) {
20924+ neighbours.left[gr + cell][1] = u_state;
20925+ neighbours.left[gr + cell][2] = v_state;
20926+ }
20927+ if cell < 2usize.min(bound_w.saturating_sub(gc)) {
20928+ neighbours.above[gc + cell][1] = u_state;
20929+ neighbours.above[gc + cell][2] = v_state;
20930+ }
20931+ }
20932+ Ok(())
20933+}
20934+
20935+/// Stamps one sub-8x8 inter leaf into every mi cell of its true `w_mi`x`h_mi`
20936+/// footprint (class: a rect block's grid span is its own, never a square guess).
20937+fn grid_stamp_rect(
20938+ grid: &mut MiGrid,
20939+ mi_row: usize,
20940+ mi_col: usize,
20941+ w_mi: usize,
20942+ h_mi: usize,
20943+ ref_frame: i8,
20944+ mv: (i32, i32),
20945+ is_new_mv: bool,
20946+) {
20947+ for dr in 0..h_mi {
20948+ for dc in 0..w_mi {
20949+ grid.set(
20950+ mi_row + dr,
20951+ mi_col + dc,
20952+ MiInfo {
20953+ is_inter: true,
20954+ ref_frame,
20955+ ref_frame1: None,
20956+ mv1: None,
20957+ mv,
20958+ is_new_mv,
20959+ size: w_mi,
20960+ size_h: h_mi,
20961+ is_global_mv0: false,
20962+ is_global_mv1: false,
20963+ },
20964+ );
20965+ }
20966+ }
20967+}
20968+
20969+/// Decodes one 8x8 leaf of a straddling 16x16 inter-frame block
20970+/// (lane-av1inter8), mirroring [`crate::tile::write_inter_frame_leaf8`]'s
20971+/// exact symbol order: its own skip flag, intra/inter choice and (when
20972+/// inter) `NEARESTMV`/`NEWMV` chain against this leaf's own 2x2-mi mv-stack
20973+/// window, or (when intra) `Y_MODE`, then its own luma and two chroma
20974+/// transform blocks through [`TxbSet::Luma8Inter`]/[`TxbSet::Chroma4`],
20975+/// same as [`decode_leaf8`]'s coefficient layer but with
20976+/// motion-compensated prediction instead of intra prediction when inter.
20977+/// `outer_at` (in [`SUB`]-grid units) is the enclosing 16x16 slot's
20978+/// skip/intra-inter context, overridden by `prev_leaf` exactly as
20979+/// [`decode_leaf8`] overrides mode context: `Neighbours`' above/left arrays
20980+/// only resolve to [`SUB`] granularity. Hands back this leaf's own skip flag
20981+/// and intra/inter choice, for the next leaf or the caller's final
20982+/// write-back.
20983+#[allow(clippy::too_many_arguments)]
20984+fn decode_inter_block8(
20985+ dec: &mut SymbolDecoder,
20986+ cdfs: &mut Cdfs,
20987+ neighbours: &mut Neighbours,
20988+ grid: &mut MiGrid,
20989+ mi_cols: u32,
20990+ mi_rows: u32,
20991+ outer_at: (usize, usize),
20992+ leaf_mi: (usize, usize),
20993+ y: &mut PlaneBuf,
20994+ u: &mut PlaneBuf,
20995+ v: &mut PlaneBuf,
20996+ ref_y: &PlaneBuf,
20997+ ref_u: &PlaneBuf,
20998+ ref_v: &PlaneBuf,
20999+ other_refs: &RefSlots,
21000+ base_q_idx: u8,
21001+ scan8: &[u16],
21002+ scan4: &[u16],
21003+ allow_high_precision_mv: bool,
21004+ force_integer_mv: bool,
21005+ // lane-gmaffine r1: this frame header's own `global_motion` table (spec
21006+ // 5.9.24), indexed `[ref_frame - LAST_FRAME]` -- same table
21007+ // [`decode_inter_block`] takes, threaded here so the 8x8 leaf can code
21008+ // `GLOBALMV` (`gm_get_motion_vector`), fill its mv stack's missing
21009+ // candidates with the gm mv (gm r6's root cause) and build a global
21010+ // warp prediction.
21011+ global_motion: &[ec_av1_syntax::WarpParams; 7],
21012+ // lane-gmaffine r1: this sequence header's own `enable_dual_filter` bit,
21013+ // for the leaf's own `read_mb_interp_filter` below.
21014+ enable_dual_filter: bool,
21015+ // lane-av1comp: see [`decode_inter_block`]'s own doc -- this leaf path
21016+ // only ever tracks a coarse `LAST_FRAME`-or-intra neighbour shape (no
21017+ // per-leaf `above_ref`/`left_ref` array exists here), so `comp_mode`'s
21018+ // context uses that same approximation.
21019+ reference_select: bool,
21020+ enable_masked_compound: bool,
21021+ // lane-sb128 r4: see [`decode_inter_block`]'s own doc -- `BLOCK_8X8` is
21022+ // always `is_interintra_allowed_bsize`-eligible, so this leaf's own gate
21023+ // drops the `side` check entirely.
21024+ enable_interintra_compound: bool,
21025+ enable_jnt_comp: bool,
21026+ order_hint_bits: u32,
21027+ order_hint: u32,
21028+ ref_order_hints: [u32; 7],
21029+ // lane-av1comp round 14: see [`decode_inter_block`]'s own doc -- this
21030+ // leaf has no per-leaf `above_skip_mode`/`left_skip_mode` array either,
21031+ // so its `skip_mode` context reuses the same [`SUB`]-grid
21032+ // `above_skip_mode[cmi]`/`left_skip_mode[rmi]` the enclosing 16x16 slot
21033+ // tracks (mirroring `above_skip`/`left_skip`'s own leaf approximation
21034+ // just above).
21035+ skip_mode_present: bool,
21036+ skip_mode_frame: [u8; 2],
21037+ // lane-cdffwd2: this frame header's own `reduced_tx_set` bit -- see
21038+ // [`decode_inter_frame_tile_with_cdfs`]'s own doc.
21039+ reduced_tx_set: bool,
21040+ // lane-motionmode round 3: this frame header's own `is_motion_mode_switchable`/
21041+ // `allow_warped_motion` bits (spec 5.11.24's `read_motion_mode`), plus
21042+ // the fixed/switchable interp filter kind `obmc_blend`'s own neighbour
21043+ // reads need (see [`decode_inter_block`]'s own doc) -- this leaf's own
21044+ // prediction is always `Regular` (documented corner-cut, `mc::predict`
21045+ // has no filter param), but an OBMC neighbour can be a real 16x16+
21046+ // block that DID resolve a switchable filter.
21047+ interp_fixed: Option<mc::InterpFilterKind>,
21048+ switchable_motion_mode: bool,
21049+ allow_warped_motion: bool,
21050+ // lane-av1comp: `Some((ref1, comp_group_idx, compound_idx))` only for a
21051+ // real `COMPOUND_REFERENCE` leaf, for the caller's own end-of-16x16
21052+ // `record_compound_ctx` call -- mirrors [`decode_inter_block`]'s own
21053+ // `compound_ctx` local, just handed back instead of applied here (this
21054+ // fn's `neighbours` recording happens once for the whole straddling
21055+ // 16x16 block, after every leaf).
21056+ // lane-screen r2: see [`decode_inter_block`]'s own copy of this param --
21057+ // `BLOCK_8X8` (this leaf's fixed size) is always `av1_allow_palette`-
21058+ // eligible (`bsize >= BLOCK_8X8`).
21059+ allow_screen_content_tools: bool,
21060+ // lane-inter8 r1: the leaf's mv stacks used to be built without the
21061+ // frame's sign-bias table (`NO_SIGN_BIAS`), while [`decode_inter_block`]
21062+ // one level up passed it -- it changes the candidate list and with it
21063+ // `new_mv_ctx`/`ref_mv_ctx`, `drl_ctx` and the number of symbols read.
21064+ // Measured: an 8x8 compound NEAR_NEWMV leaf desynced against aomdec's
21065+ // EC_MODE ladder at exactly this block (mi 4,14 of the mandelbrot
21066+ // 8x8-split gate).
21067+ sign_bias_table: &SignBiasTable,
21068+ // lane-inter8 r2: the frame's temporal mv field (spec 7.10.2.8), which
21069+ // [`decode_inter_block`] one level up has always passed and this leaf
21070+ // passed `None` for -- a `use_ref_frame_mvs` frame's stack then holds
21071+ // fewer candidates here than in the reference decoder, which changes the
21072+ // mode contexts AND the number of `drl_mode` bits read (class parsed
21073+ // then discarded).
21074+ tpl_frame: Option<&TplFrameArgs>,
21075+ // lane-scaledref r1: this frame's own coded luma width (spec 7.11.3.3),
21076+ // for the scaled-reference MC this leaf's own single-ref/compound/OBMC
21077+ // predictions take when a stored reference was coded at another width
21078+ // (`use_superres`) -- mirrors [`decode_inter_block`]'s own param.
21079+ frame_width: usize,
21080+) -> Result<(bool, bool, bool, Option<(i8, i8, u8, u8)>, [u8; 2], (i8, Option<i8>))> {
21081+ const LAST_FRAME: i8 = 1;
21082+ // lane-gmaffine r2: the leaf's OWN switchable-filter symbols, handed back
21083+ // so the caller stamps them into `Neighbours` instead of the `[3, 3]`
21084+ // placeholder. `[3, 3]` is the "intra neighbour, no filter" sentinel: an
21085+ // OBMC blend that picks such a neighbour up feeds it to
21086+ // `neighbour_filter`, which PANICS on it (`from_switchable_symbol`) --
21087+ // that was the warp gate's crash, not an entropy desync. Stays `[3, 3]`
21088+ // on the intra and compound paths.
21089+ let mut leaf_filter_syms = [3u8; 2];
21090+ // lane-gmaffine r1: this leaf's GLOBALMV vector AND the mv stack's
21091+ // missing-candidate fallback both come from the frame's global motion
21092+ // evaluated at THIS block's centre (gm r6's root cause).
21093+ let gm_table = build_gm_mv_table(
21094+ global_motion,
21095+ leaf_mi.0,
21096+ leaf_mi.1,
21097+ 2,
21098+ 2,
21099+ allow_high_precision_mv,
21100+ force_integer_mv,
21101+ );
21102+ /// `Y_MODE`'s size group (`common_data.h`'s `size_group_lookup[BLOCK_8X8]`).
21103+ const SIZE_GROUP_8: usize = 1;
21104+
21105+ let (px, py) = (leaf_mi.1 * MI, leaf_mi.0 * MI);
21106+ let (cpx, cpy) = (px / 2, py / 2);
21107+ // lane-txselect: whether this leaf's `TxMode::Select` var-tx tree took
21108+ // the one split a `BLOCK_8X8` can take (`read_block_tx_size` below) --
21109+ // read back by the luma residual read and the tail's neighbour/loop-filter
21110+ // bookkeeping. Always `false` outside a `TxMode::Select` inter frame.
21111+ let mut split8 = false;
21112+ const SIDE: usize = 8;
21113+ const CHROMA_SIDE: usize = 4;
21114+
21115+ let (r, c) = outer_at;
21116+ let _ = (r, c);
21117+ // lane-inter8 r2: this leaf's OWN mi cell, not the enclosing 16x16's --
21118+ // leaf (mi_r, mi_c + 2)'s left neighbour is leaf (mi_r, mi_c), and the
21119+ // left column of a 16x16's second leaf ROW is the previous 16x16 block's
21120+ // bottom leaf, neither of which a SUB-grid slot can name.
21121+ let (rmi, cmi) = leaf_mi;
21122+ // lane-inter8 r2: no sibling-leaf override any more -- each leaf stamps
21123+ // its own 2x2-mi span into the bands right after it decodes (the caller's
21124+ // `record_inter_rect_mi`), so a plain mi read already names the correct
21125+ // neighbour, including one belonging to the previous 16x16 block.
21126+ let above_skip = neighbours.above_skip[cmi];
21127+ let left_skip = neighbours.left_skip[rmi];
21128+ let above_inter = neighbours.above_inter[cmi];
21129+ let left_inter = neighbours.left_inter[rmi];
21130+ let above_ref0 = neighbours.above_ref[cmi];
21131+ let above_ref1 = neighbours.above_ref1[cmi];
21132+ let left_ref0 = neighbours.left_ref[rmi];
21133+ let left_ref1 = neighbours.left_ref1[rmi];
21134+ let skip_mode_ctx =
21135+ usize::from(neighbours.above_skip_mode[cmi]) + usize::from(neighbours.left_skip_mode[rmi]);
21136+ // Same two `inter_segment_id` positions as [`decode_inter_block`]; this
21137+ // leaf is always `BLOCK_8X8`, i.e. 2x2 mi.
21138+ inter_segment_id(dec, cdfs, leaf_mi.0, leaf_mi.1, 2, 2, false, true);
21139+ let skip_mode = skip_mode_present && dec.symbol(&mut cdfs.skip_mode[skip_mode_ctx]) == 1;
21140+ if skip_mode {
21141+ SKIP_MODE_HITS.with(|c| c.set(c.get() + 1));
21142+ }
21143+
21144+ let skip_ctx = usize::from(above_skip) + usize::from(left_skip);
21145+ let skip = skip_mode || dec.symbol(&mut cdfs.skip[skip_ctx]) == 1;
21146+ inter_segment_id(dec, cdfs, leaf_mi.0, leaf_mi.1, 2, 2, skip, false);
21147+ maybe_read_cdef_idx(dec, leaf_mi.0, leaf_mi.1, skip);
21148+ // Always a `BLOCK_8X8` leaf here, never the whole superblock.
21149+ maybe_read_delta_q(dec, cdfs, leaf_mi.0, leaf_mi.1, false, skip);
21150+ maybe_read_delta_lf(dec, cdfs, leaf_mi.0, leaf_mi.1, false, skip);
21151+
21152+ let (has_above, has_left) = (
21153+ leaf_mi.0 > neighbours.tile_row0_mi,
21154+ leaf_mi.1 > neighbours.tile_col0_mi,
21155+ );
21156+ let ii_ctx = intra_inter_ctx(has_above, has_left, above_inter, left_inter);
21157+ let is_inter = skip_mode || dec.symbol(&mut cdfs.intra_inter[ii_ctx]) == 1;
21158+ // lane-inter8 r1: mirrors the oracle's `EC_MODE` (instrument rung 4,
21159+ // `read_inter_block_mode_info`) so an 8x8 leaf's mode-info range ladder
21160+ // diffs line for line against a real aomdec.
21161+ if std::env::var_os("EC_TRACE_MODE").is_some() {
21162+ eprintln!(
21163+ "EC_MODE mi_row={} mi_col={} rng={}",
21164+ leaf_mi.0,
21165+ leaf_mi.1,
21166+ dec.debug_state().0
21167+ );
21168+ }
21169+
21170+ let mode_for_tx;
21171+ let (luma_grid, u_grid, v_grid);
21172+ let mut compound_ctx8: Option<(i8, i8, u8, u8)> = None;
21173+ // lane-inter8 r1: this leaf's own resolved references, handed back so the
21174+ // NEXT leaf of the same 16x16 can use them as its real above/left
21175+ // neighbour (`Neighbours`' arrays only move once per 16x16 block).
21176+ // `(0, None)` is intra.
21177+ let mut leaf_refs: (i8, Option<i8>) = (0, None);
21178+ if is_inter {
21179+ if reference_select || skip_mode {
21180+ // lane-inter8 r1: the REAL neighbour references, not a
21181+ // `LAST_FRAME`-or-intra stand-in. `av1_get_reference_mode_context`
21182+ // and `read_compound_ref_frames`' own contexts both ask whether a
21183+ // neighbour is COMPOUND, so pretending every inter neighbour is
21184+ // single-ref LAST picked the wrong `comp_mode` CDF row -- measured
21185+ // as an 8x8 leaf reading single-ref where aomdec read compound
21186+ // NEAR_NEWMV (mi 4,14).
21187+ let above_nbr = has_above.then(|| NeighbourRef {
21188+ is_inter: above_inter,
21189+ ref0: if above_inter { above_ref0 } else { 0 },
21190+ ref1: above_ref1,
21191+ uni: above_ref1.is_some_and(|r1| is_uni_comp_ref(above_ref0, r1)),
21192+ });
21193+ let left_nbr = has_left.then(|| NeighbourRef {
21194+ is_inter: left_inter,
21195+ ref0: if left_inter { left_ref0 } else { 0 },
21196+ ref1: left_ref1,
2013821197 uni: left_ref1.is_some_and(|r1| is_uni_comp_ref(left_ref0, r1)),
2013921198 });
2014021199 if skip_mode || read_comp_mode(dec, cdfs, above_nbr, left_nbr) {
@@ -20367,11 +21426,43 @@ fn decode_inter_block8(
2036721426 }
2036821427 mode_for_tx = 0;
2036921428
20370- // lane-av1comp corner-cut, matching this leaf's single-ref
20371- // arm below (`mc::predict`'s own fixed-Regular default):
20372- // `decode_inter_block8` never resolves a switchable filter,
20373- // so both compound taps use `Regular` too.
20374- use mc::InterpFilterKind::Regular;
21429+ // lane-intersub8 r2: the compound 8x8 leaf used to hard-code
21430+ // `Regular` and leave `leaf_filter_syms` at the `[3, 3]`
21431+ // "no filter" sentinel. libaom reads `read_mb_interp_filter`
21432+ // here for EVERY inter block (`decodemv.c`
21433+ // `read_inter_block_mode_info`, right after
21434+ // `read_compound_type`), and when `av1_is_interp_needed` is 0
21435+ // -- `skip_mode`, or a non-translational GLOBALMV --
21436+ // `set_default_interp_filters` stores EIGHTTAP_REGULAR (0),
21437+ // NOT a sentinel. A later block whose ref matches this one
21438+ // then reads `av1_get_pred_context_switchable_interp` off
21439+ // that stored 0, so recording `[3, 3]` shifted its
21440+ // `switchable_interp` context and desynced the tile.
21441+ let above_filter_ctx = if neighbours.above_ref[cmi] == ref0
21442+ || neighbours.above_ref1[cmi] == Some(ref0)
21443+ {
21444+ neighbours.above_filter[cmi]
21445+ } else {
21446+ [3, 3]
21447+ };
21448+ let left_filter_ctx = if neighbours.left_ref[rmi] == ref0
21449+ || neighbours.left_ref1[rmi] == Some(ref0)
21450+ {
21451+ neighbours.left_filter[rmi]
21452+ } else {
21453+ [3, 3]
21454+ };
21455+ let (h_filter, v_filter, resolved_filter) = resolve_interp_filter(
21456+ dec,
21457+ cdfs,
21458+ interp_fixed,
21459+ enable_dual_filter,
21460+ skip_mode,
21461+ above_filter_ctx,
21462+ left_filter_ctx,
21463+ true,
21464+ );
21465+ leaf_filter_syms = resolved_filter;
2037521466 let mut inter0_y = vec![0i32; SIDE * SIDE];
2037621467 mc::predict_compound_intermediate(
2037721468 &py0.data,
@@ -20383,8 +21474,8 @@ fn decode_inter_block8(
2038321474 scale0,
2038421475 SIDE,
2038521476 SIDE,
20386- Regular,
20387- Regular,
21477+ h_filter,
21478+ v_filter,
2038821479 &mut inter0_y,
2038921480 );
2039021481 let mut inter1_y = vec![0i32; SIDE * SIDE];
@@ -20398,8 +21489,8 @@ fn decode_inter_block8(
2039821489 scale1,
2039921490 SIDE,
2040021491 SIDE,
20401- Regular,
20402- Regular,
21492+ h_filter,
21493+ v_filter,
2040321494 &mut inter1_y,
2040421495 );
2040521496 let mut pred_y = vec![0u16; SIDE * SIDE];
@@ -20431,8 +21522,8 @@ fn decode_inter_block8(
2043121522 scale0,
2043221523 CHROMA_SIDE,
2043321524 CHROMA_SIDE,
20434- Regular,
20435- Regular,
21525+ h_filter,
21526+ v_filter,
2043621527 &mut inter0_u,
2043721528 );
2043821529 let mut inter1_u = vec![0i32; CHROMA_SIDE * CHROMA_SIDE];
@@ -20446,8 +21537,8 @@ fn decode_inter_block8(
2044621537 scale1,
2044721538 CHROMA_SIDE,
2044821539 CHROMA_SIDE,
20449- Regular,
20450- Regular,
21540+ h_filter,
21541+ v_filter,
2045121542 &mut inter1_u,
2045221543 );
2045321544 let mut pred_u = vec![0u16; CHROMA_SIDE * CHROMA_SIDE];
@@ -20477,8 +21568,8 @@ fn decode_inter_block8(
2047721568 scale0,
2047821569 CHROMA_SIDE,
2047921570 CHROMA_SIDE,
20480- Regular,
20481- Regular,
21571+ h_filter,
21572+ v_filter,
2048221573 &mut inter0_v,
2048321574 );
2048421575 let mut inter1_v = vec![0i32; CHROMA_SIDE * CHROMA_SIDE];
@@ -20492,8 +21583,8 @@ fn decode_inter_block8(
2049221583 scale1,
2049321584 CHROMA_SIDE,
2049421585 CHROMA_SIDE,
20495- Regular,
20496- Regular,
21586+ h_filter,
21587+ v_filter,
2049721588 &mut inter1_v,
2049821589 );
2049921590 let mut pred_v = vec![0u16; CHROMA_SIDE * CHROMA_SIDE];
@@ -21425,6 +22516,12 @@ fn decode_inter_block8(
2142522516 // lane-cdef r1: the fall-through twin of the compound arm's skip-band
2142622517 // write above -- `skip` is one flag for the whole 8x8 leaf (read at
2142722518 // `decode.rs`'s `skip_ctx` site), `split8` only splits its transform.
22519+ // lane-intersub8 r5: ... and it counts too. r1 incremented the counter in
22520+ // the COMPOUND early-return arm only, so the gate's assert really read
22521+ // "a COMPOUND 8x8 leaf wrote the band"; once main's inter16ab/r14 routing
22522+ // landed, the 10-bit cq12 arm's leaves come through here instead and the
22523+ // gate failed on an instrumentation gap, with the band written either way.
22524+ INTER8_SKIP_BAND_HITS.with(|c| c.set(c.get() + 1));
2142822525 neighbours.fill_skip_grid(leaf_mi, 2, skip);
2142922526 neighbours.fill_lf_grid(
2143022527 leaf_mi,
@@ -22064,6 +23161,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
2206423161 let part64 = match (has_cols, has_rows) {
2206523162 (true, true) => {
2206623163 let pre_rng = dec.debug_state().0;
23164+ 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, pre_rng); }
2206723165 let p = dec.symbol(&mut cdfs.partition_w64[sb_ctx]);
2206823166 if std::env::var_os("EC_AV1_TRACE").is_some() {
2206923167 eprintln!(
@@ -22254,6 +23352,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
2225423352 dec.debug_state().0
2225523353 );
2225623354 }
23355+ 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); }
2225723356 let p = dec.symbol(&mut cdfs.partition_w32[ctx32]);
2225823357 if std::env::var_os("EC_AV1_TRACE").is_some() {
2225923358 eprintln!(
@@ -22374,6 +23473,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
2237423473 // inter leaves through the very same loop the
2237523474 // straddling case has always used.
2237623475 let part16 = if has_cols16 && has_rows16 {
23476+ 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); }
2237723477 let p = dec.symbol(&mut cdfs.partition_w16[ctx16]);
2237823478 if std::env::var_os("EC_AV1_TRACE").is_some() {
2237923479 let (rng, _) = dec.debug_state();
@@ -22684,12 +23784,83 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
2268423784 for (mr, mc) in leaf_positions {
2268523785 let leaf_mi = (mr as usize, mc as usize);
2268623786 let leaf_ctx = neighbours.partition_ctx_mi(leaf_mi, 8);
23787+ 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); }
2268723788 let part8 = dec.symbol(&mut cdfs.partition_w8[leaf_ctx]);
22688- if part8 != PARTITION_NONE {
22689- return Err(unsupported(
22690- "an inter partition below 8x8 (this decoder codes no inter leaf smaller than 8x8; lane-sub8 scoped to intra)",
22691- ));
23789+ if part8 == PARTITION_SPLIT {
23790+ // lane-intersub8: four BLOCK_4X4 inter
23791+ // sub-blocks, chroma once per 8x8.
23792+ decode_inter_sub8_split4(
23793+ &mut dec,
23794+ &mut cdfs,
23795+ &mut neighbours,
23796+ &mut grid,
23797+ leaf_mi,
23798+ mi_cols,
23799+ mi_rows,
23800+ &mut y,
23801+ &mut u,
23802+ &mut v,
23803+ &ref_y,
23804+ &ref_u,
23805+ &ref_v,
23806+ &ref_slots,
23807+ &sign_bias_table,
23808+ &global_motion,
23809+ base_q_idx,
23810+ &scan4,
23811+ allow_high_precision_mv,
23812+ force_integer_mv,
23813+ interp_fixed,
23814+ enable_dual_filter,
23815+ tpl_frame.as_ref(),
23816+ reduced_tx_set,
23817+ frame_width as usize,
23818+ )?;
23819+ continue;
23820+ }
23821+ if part8 == PARTITION_VERT || part8 == PARTITION_HORZ {
23822+ // lane-intersub8 r3/r4/r5: two
23823+ // BLOCK_8X4 (HORZ) / BLOCK_4X8 (VERT)
23824+ // inter leaves, chroma once per 8x8 on
23825+ // the second of them. HORZ was refused
23826+ // by name through r4 over a |d| <= 2
23827+ // luma band; r5 merged lane-cdef
23828+ // 8c6065e, whose `decode_inter_block8`
23829+ // skip-band write is that band's root
23830+ // cause, and the 56-arm sweep went 3
23831+ // mismatching arms -> 0.
23832+ decode_inter_sub8_rect2(
23833+ &mut dec,
23834+ &mut cdfs,
23835+ &mut neighbours,
23836+ &mut grid,
23837+ leaf_mi,
23838+ part8 == PARTITION_VERT,
23839+ mi_cols,
23840+ mi_rows,
23841+ &mut y,
23842+ &mut u,
23843+ &mut v,
23844+ &ref_y,
23845+ &ref_u,
23846+ &ref_v,
23847+ &ref_slots,
23848+ &sign_bias_table,
23849+ &global_motion,
23850+ base_q_idx,
23851+ &scan4,
23852+ allow_high_precision_mv,
23853+ force_integer_mv,
23854+ interp_fixed,
23855+ enable_dual_filter,
23856+ tpl_frame.as_ref(),
23857+ reduced_tx_set,
23858+ frame_width as usize,
23859+ )?;
23860+ continue;
2269223861 }
23862+ // `partition_w8` is a 4-symbol alphabet
23863+ // (NONE/HORZ/VERT/SPLIT), all four handled.
2269323864 let (
2269423865 skip,
2269523866 is_inter,
crates/ec-av1/src/refusal_inventory.rsmodified+4 -1
@@ -33,8 +33,11 @@ const REFUSALS: &[&str] = &[
3333 "a nonzero angle delta on an 8x8 intra leaf in an inter frame (no gate reaches this leaf with one; the >=16x16 arm decodes deltas)",
3434 "a coded HORZ/VERT strip whose chroma transform has no rect coefficient tables here",
3535 "a split intra strip whose transform unit is {tx_w}x{tx_h} (no luma coefficient tables for that shape here)",
36- "an inter partition below 8x8 (this decoder codes no inter leaf smaller than 8x8; lane-sub8 scoped to intra)",
3736 "an OBMC neighbour whose switchable interp filter was never recorded",
37+ "an intra 4x4 block inside an inter frame's sub-8x8 split (this decoder codes only inter 4x4 sub-blocks there)",
38+ "an intra 8x4/4x8 block inside an inter frame's sub-8x8 HORZ/VERT partition (this decoder codes only inter sub-blocks there)",
39+ "a sub-8x8 inter block under a scaled reference (superres, unimplemented)",
40+ "a COMPOUND_WEDGE mask on a non-square inter block (rect wedge codebook unimplemented)",
3841 "a 16x16 block whose true edge cuts through both axes needs a rectangular transform this decoder does not code yet",
3942 "a 16x16 inter block whose true edge cuts through both axes needs a rectangular transform this decoder does not code yet",
4043 "a 32x32 partition type this decoder does not code (value={part32})",
crates/ec-av1/src/stream.rsmodified+252 -0
@@ -8858,6 +8858,258 @@ mod tests {
88588858 }
88598859 }
88608860
8861+ /// lane-intersub8: `PARTITION_SPLIT` below 8x8 on an INTER frame -- four
8862+ /// `BLOCK_4X4` inter sub-blocks with one shared 4x4 chroma unit per plane,
8863+ /// predicted the sub8x8 way (2x2 chroma piece per luma sub-block mv,
8864+ /// `dec_build_inter_predictors`' `is_sub8x8` branch). Reality of the shape
8865+ /// was established BEFORE the code (class refusal-from-own-desync): the
8866+ /// oracle `aomdec`'s `EC_TRACE` prints `EC_PART_VAL ... bsize=3 value=3`
8867+ /// on this recipe's inter frames.
8868+ ///
8869+ /// Attempts 0..7 run `--enable-rect-partitions=0`, where aomenc can only
8870+ /// pick SPLIT below 8x8; attempts 8..15 repeat the schedule with rect on,
8871+ /// where it picks HORZ/VERT below 8x8 far more often than SPLIT -- the VERT
8872+ /// arm (two `BLOCK_4X8` inter leaves, `decode_inter_sub8_rect2`) is what the
8873+ /// `rect_fired` assert pins. The HORZ twin decodes but is refused by name
8874+ /// (lane-intersub8 r3: a measured sweep desyncs the block to its right).
8875+ #[test]
8876+ fn a_real_aomenc_inter_sequence_with_a_sub8x8_inter_split_decodes_pixel_exact() {
8877+ const NAME: &str =
8878+ "a_real_aomenc_inter_sequence_with_a_sub8x8_inter_split_decodes_pixel_exact";
8879+ let _gate_lock = lock_gate_counters();
8880+ if !have_ffmpeg() {
8881+ eprintln!("SKIP {NAME}: no ffmpeg");
8882+ return;
8883+ }
8884+ if !have_aomenc() {
8885+ eprintln!("SKIP {NAME}: no aomenc at {}", aomenc_path().display());
8886+ return;
8887+ }
8888+ let (width, height, frame_count) = (192usize, 128usize, 6usize);
8889+ let mut fired = 0u32;
8890+ // lane-intersub8 r3: attempts 8..15 repeat the same schedule with
8891+ // `--enable-rect-partitions=1`, where aomenc picks PARTITION_VERT below
8892+ // 8x8 (two BLOCK_4X8 inter leaves, one shared 4x4 chroma unit predicted
8893+ // from BOTH sub-blocks' mvs). The HORZ twin is still refused by name.
8894+ let mut rect_fired = 0u32;
8895+ // lane-intersub8 r5: the two rect axes counted apart. Attempts 16..23
8896+ // are the same recipe family with the geq source TRANSPOSED (the sine
8897+ // that moves runs along Y, not X): measured over a 56-arm sweep
8898+ // (~/.cache/intersub8-sweep-r5.log, cq {8,12,14,16,20,26,32} x sp
8899+ // {3,6,9,12} x both depths, rect on), aomenc picks PARTITION_HORZ
8900+ // below 8x8 on that source and PARTITION_VERT on the untransposed one
8901+ // -- neither schedule reaches the other axis, so both are needed.
8902+ let (mut horz_fired, mut vert_fired) = (0u32, 0u32);
8903+ // Rect (non-square) masked-compound blocks on attempts that DECODED
8904+ // and were pixel-compared -- never off a refused stream (class
8905+ // counter-from-refused-stream). This is the shape whose
8906+ // `compound_type`/`wedge_idx` CDF row lane-intersub8 r4 fixed.
8907+ let mut rect_masked = 0usize;
8908+ let mut refusals: Vec<String> = Vec::new();
8909+ let mut out_of_scope_mismatch = 0u32;
8910+ for bit_depth in [8u32, 10u32] {
8911+ for attempt in 0..24u32 {
8912+ let rect = if attempt >= 16 { 1 } else { attempt / 8 };
8913+ let rect_arg = format!("--enable-rect-partitions={rect}");
8914+ // lane-intersub8 r2, measured schedule (sweep of cq
8915+ // {8,10,12,14,16,18,20} x sp {3,6,9,12} x both depths,
8916+ // `decode_probe`'s `sub8_inter_split:` counter vs an ffmpeg
8917+ // rawvideo compare): sub-8x8 inter SPLIT groups fire at
8918+ // (8-bit, cq 12, sp 3) = 1 group and (10-bit, cq 12, sp 6) =
8919+ // 3 groups, both pixel-exact. cq 8 and 10 are NOT used: at
8920+ // those quantizers this recipe also carries a CDEF defect of
8921+ // another shape -- three luma samples of |d| = 1 on
8922+ // decode-order frames 3/4, zero sub-8x8 inter split groups,
8923+ // and the identical recipe re-encoded with `--enable-cdef=0`
8924+ // decodes all six frames exact. Deferred to a CDEF lane
8925+ // rather than hidden: cq 16..20 are all exact, so this gate
8926+ // is not selecting quantizers that hide a defect of its own
8927+ // shape.
8928+ // Attempts 16..23: the (cq, sp) pairs the r5 sweep measured
8929+ // as HORZ-firing on the transposed source -- 8-bit
8930+ // (14,3)/(20,3)/(32,9), 10-bit (12,3)/(16,3); the rest of the
8931+ // eight are non-firing neighbours kept so a schedule that
8932+ // stops firing shows up as out-of-scope, not as a silent pass.
8933+ const HORZ_SCHEDULE: [(u32, u32); 8] =
8934+ [(14, 3), (20, 3), (32, 9), (12, 3), (16, 3), (12, 9), (14, 9), (26, 3)];
8935+ let (cq, sp) = if attempt >= 16 {
8936+ HORZ_SCHEDULE[(attempt - 16) as usize]
8937+ } else {
8938+ ([12, 14][(attempt % 2) as usize], 3 + ((attempt % 8) / 2) * 3)
8939+ };
8940+ let duration = frame_count as f64 / 25.0;
8941+ let source = if attempt >= 16 {
8942+ format!(
8943+ "color=c=gray:s={width}x{height}:d={duration}:r=25,format=gray,\
8944+ geq=lum='128+58*sin((Y+N*{sp})/6)+18*sin(X/23)',format=yuv420p"
8945+ )
8946+ } else {
8947+ format!(
8948+ "color=c=gray:s={width}x{height}:d={duration}:r=25,format=gray,\
8949+ geq=lum='128+58*sin((X+N*{sp})/6)+18*sin(Y/23)',format=yuv420p"
8950+ )
8951+ };
8952+ let pix_fmt = if bit_depth == 10 { "yuv420p10le" } else { "yuv420p" };
8953+ let y4m = Command::new("ffmpeg")
8954+ .args([
8955+ "-v", "error", "-f", "lavfi", "-i", &source, "-t", &duration.to_string(),
8956+ "-pix_fmt", pix_fmt, "-strict", "-1", "-f", "yuv4mpegpipe", "-",
8957+ ])
8958+ .stdin(Stdio::null())
8959+ .stdout(Stdio::piped())
8960+ .stderr(Stdio::piped())
8961+ .output()
8962+ .expect("ffmpeg failed to run");
8963+ assert!(
8964+ y4m.status.success(),
8965+ "{NAME}: ffmpeg refused the fixture: {}",
8966+ String::from_utf8_lossy(&y4m.stderr)
8967+ );
8968+ let cq_arg = format!("--cq-level={cq}");
8969+ let depth_arg = format!("--bit-depth={bit_depth}");
8970+ let input_depth_arg = format!("--input-bit-depth={bit_depth}");
8971+ let args: Vec<&str> = vec![
8972+ "--codec=av1", "--passes=1", "--end-usage=q", &cq_arg, "--cpu-used=0",
8973+ "--threads=1", "--row-mt=0", "--sb-size=64", &depth_arg, &input_depth_arg,
8974+ "--enable-restoration=0", "--enable-palette=0", "--deltaq-mode=0",
8975+ "--enable-filter-intra=0", "--enable-cfl-intra=0", "--enable-intrabc=0",
8976+ "--lag-in-frames=0", "--enable-obmc=0", "--enable-tx-size-search=1",
8977+ // Per-arm overrides last (aomenc keeps the LAST occurrence).
8978+ "--enable-rect-partitions=0", "--enable-ab-partitions=0",
8979+ "--enable-1to4-partitions=0", "--min-partition-size=4",
8980+ "--max-partition-size=16",
8981+ &rect_arg,
8982+ "--obu", "-o", "-", "-",
8983+ ];
8984+ let mut child = Command::new(aomenc_path())
8985+ .args(&args)
8986+ .stdin(Stdio::piped())
8987+ .stdout(Stdio::piped())
8988+ .stderr(Stdio::piped())
8989+ .spawn()
8990+ .expect("aomenc failed to start");
8991+ child
8992+ .stdin
8993+ .take()
8994+ .expect("aomenc stdin")
8995+ .write_all(&y4m.stdout)
8996+ .expect("writing y4m to aomenc");
8997+ let out = child.wait_with_output().expect("aomenc failed to run");
8998+ assert!(
8999+ out.status.success(),
9000+ "{NAME}: aomenc refused the fixture: {}",
9001+ String::from_utf8_lossy(&out.stderr)
9002+ );
9003+ let stream = out.stdout;
9004+ let before = decode::sub8_inter_split_hits();
9005+ let before_rect = decode::sub8_inter_rect_hits();
9006+ let before_masked = decode::rect_masked_compound_hits();
9007+ let frames = match decode_stream(&stream) {
9008+ Err(e) => {
9009+ let msg = e.to_string();
9010+ assert!(
9011+ msg.contains("unsupported"),
9012+ "{NAME} failed outright, not a named refusal ({bit_depth}-bit, \
9013+ attempt {attempt}): {msg}"
9014+ );
9015+ refusals.push(format!("{bit_depth}-bit attempt {attempt}: {msg}"));
9016+ continue;
9017+ }
9018+ Ok(frames) => frames,
9019+ };
9020+ let split_groups = decode::sub8_inter_split_hits() - before;
9021+ let rect_now = decode::sub8_inter_rect_hits();
9022+ let rect_groups = (rect_now.0 - before_rect.0) + (rect_now.1 - before_rect.1);
9023+ let groups = split_groups + rect_groups;
9024+ let ffmpeg_frames = if bit_depth == 10 {
9025+ ffmpeg_decode_sequence_10bit(&stream, width, height, frame_count)
9026+ } else {
9027+ ffmpeg_decode_sequence(&stream, width, height, frame_count)
9028+ };
9029+ assert_eq!(frames.len(), frame_count);
9030+ let mismatched = frames
9031+ .iter()
9032+ .zip(&ffmpeg_frames)
9033+ .any(|(got, want)| got.y != want.y || got.u != want.u || got.v != want.v);
9034+ if groups == 0 {
9035+ // Out of scope: no sub-8x8 inter split in this attempt.
9036+ if mismatched {
9037+ out_of_scope_mismatch += 1;
9038+ eprintln!(
9039+ "{NAME}: {bit_depth}-bit attempt {attempt} MISMATCHES with zero \
9040+ sub-8x8 inter group -- another shape's defect"
9041+ );
9042+ }
9043+ refusals.push(format!(
9044+ "{bit_depth}-bit attempt {attempt}: decoded, but no sub-8x8 inter split"
9045+ ));
9046+ continue;
9047+ }
9048+ for (i, (got, want)) in frames.iter().zip(&ffmpeg_frames).enumerate() {
9049+ assert_eq!(
9050+ got.y, want.y,
9051+ "luma frame {i} ({bit_depth}-bit attempt {attempt}, {groups} sub-8x8 \
9052+ inter split groups)"
9053+ );
9054+ assert_eq!(got.u, want.u, "U frame {i} ({bit_depth}-bit attempt {attempt})");
9055+ assert_eq!(got.v, want.v, "V frame {i} ({bit_depth}-bit attempt {attempt})");
9056+ }
9057+ fired += 1;
9058+ if rect_groups > 0 {
9059+ rect_fired += 1;
9060+ }
9061+ if rect_now.0 - before_rect.0 > 0 {
9062+ horz_fired += 1;
9063+ }
9064+ if rect_now.1 - before_rect.1 > 0 {
9065+ vert_fired += 1;
9066+ }
9067+ // Only now, past the pixel compare, is this attempt's
9068+ // masked-compound count admissible.
9069+ rect_masked += decode::rect_masked_compound_hits() - before_masked;
9070+ }
9071+ }
9072+ eprintln!(
9073+ "{NAME}: fired={fired} horz={horz_fired} vert={vert_fired} rect_masked={rect_masked}"
9074+ );
9075+ assert_eq!(
9076+ out_of_scope_mismatch, 0,
9077+ "{NAME}: attempts mismatched with no sub-8x8 inter group"
9078+ );
9079+ assert!(
9080+ fired >= 2,
9081+ "{NAME}: fewer than 2 firing+pixel-exact attempts:\n{}",
9082+ refusals.join("\n")
9083+ );
9084+ assert!(
9085+ rect_fired >= 2,
9086+ "{NAME}: fewer than 2 firing+pixel-exact attempts with a RECTANGULAR sub-8x8 \
9087+ inter leaf (4x8):\n{}",
9088+ refusals.join("\n")
9089+ );
9090+ assert!(
9091+ vert_fired >= 2,
9092+ "{NAME}: fewer than 2 firing+pixel-exact attempts with a sub-8x8 inter VERT \
9093+ pair (two BLOCK_4X8 leaves):\n{}",
9094+ refusals.join("\n")
9095+ );
9096+ // lane-intersub8 r5, measured `rect_masked=2` over the 48 attempts:
9097+ // the rect masked-compound blocks whose `compound_type`/`wedge_idx`
9098+ // CDF row r4 corrected, counted only on pixel-compared attempts.
9099+ assert!(
9100+ rect_masked >= 1,
9101+ "{NAME}: no RECTANGULAR masked-compound block on any pixel-compared attempt -- \
9102+ the r4 compound_type/wedge_idx CDF-row fix is unexercised:\n{}",
9103+ refusals.join("\n")
9104+ );
9105+ assert!(
9106+ horz_fired >= 2,
9107+ "{NAME}: fewer than 2 firing+pixel-exact attempts with a sub-8x8 inter HORZ \
9108+ pair (two BLOCK_8X4 leaves):\n{}",
9109+ refusals.join("\n")
9110+ );
9111+ }
9112+
88619113 #[test]
88629114 // lane-inter4 r3: the 16x16-level rect INTER leaf -- PARTITION_HORZ /
88639115 // PARTITION_VERT at 16x16 on an inter frame, i.e. two 16x8 / 8x16 inter
lanes/intersub8-r1.handoff.mdadded+64 -0
@@ -0,0 +1,64 @@
1+# lane-intersub8 r1 — HANDOFF (RED, code committed, gate red)
2+
3+## 1. The refusal is REAL, not our desync (settled, do not re-litigate)
4+`aomenc` genuinely writes sub-8x8 partitions on INTER frames.
5+Recipe (192x128, 6 frames, gray ramp `128+58*sin((X+N*8)/6)+18*sin(Y/23)`, cq 8,
6+`--min-partition-size=4 --max-partition-size=16 --enable-rect-partitions=1
7+--enable-ab-partitions=0 --enable-1to4-partitions=0 --enable-obmc=0
8+--enable-tx-size-search=1 --sb-size=64 --lag-in-frames=0`), oracle:
9+`EC_TRACE=1 ~/.cache/aom-oracle/build/aomdec --rawvideo -o /dev/null u8_8.obu 2>ec.log`
10+`EC_PART_VAL bsize=3` histogram: **v0=68 NONE, v1=28 HORZ, v2=49 VERT, v3=3 SPLIT**.
11+So 8x4/4x8 dominate; 4x4 SPLIT is rare. `--enable-rect-partitions=0` removes
12+HORZ/VERT below 8x8 and still yields SPLIT groups (2 per stream at cq 8).
13+
14+Side fact worth a sweep: the SAME trace shows `bsize=6 value=6/7` (VERT_A/VERT_B at
15+16x16) even though `--enable-ab-partitions=0` was on the command line — that is what
16+the "inter 16x16-level AB or 1:4 partition" refusal fires on for recipes with
17+`--min-partition-size=4`. Either the flag is not honoured at that size or the
18+refusal is itself hallucinated; lane-inter16ab should check with this trace.
19+
20+## 2. What landed (compiles, `cargo check` clean)
21+* `crates/ec-av1/src/decode.rs` `decode_inter_sub8_split4` (new fn, above
22+ `decode_inter_block8`): four `BLOCK_4X4` inter sub-blocks of one 8x8 group.
23+ Symbols deliberately NOT read below 8x8, with libaom citations in the doc
24+ comment: `skip_mode` / `comp_mode` (`is_comp_ref_allowed`, blockd.h),
25+ `interintra` (`is_interintra_allowed_bsize`), `motion_mode`/`obmc`
26+ (`motion_mode_allowed`), tx size (`block_signals_txsize`, blockd.h:1027 —
27+ `bsize > BLOCK_4X4`, so `BLOCK_4X4` reads NO tx symbol even in TX_MODE_SELECT,
28+ decodeframe.c:1164-1177). Chroma once per 8x8 on the last sub-block, 4x4 TX,
29+ prediction = four 2x2 chroma pieces each from its own sub-block's mv/ref/filters
30+ (`dec_build_inter_predictors` is_sub8x8; spec 7.11.3.1). Chroma tx_type inherits
31+ the FIRST sub-block's luma tx_type (`av1_get_tx_type` co-located luma 0,0).
32+* call site: `decode.rs` ~21834, `part8 == PARTITION_SPLIT` dispatches; HORZ/VERT
33+ now refuse under a NARROWED string (rect sub-8x8 inter transform unimplemented).
34+* counter `SUB8_INTER_SPLIT_HITS` / `decode::sub8_inter_split_hits()`.
35+* `refusal_inventory.rs`: old string replaced by the 3 new ones.
36+* gate `stream.rs::a_real_aomenc_inter_sequence_with_a_sub8x8_inter_split_decodes_pixel_exact`.
37+
38+## 3. Gate result: RED (two separate failures)
39+`cargo test -p ec-av1 --lib sub8x8_inter_split`
40+* 8-bit attempt 0 (cq 8, sp 3): **MISMATCHES with ZERO sub-8x8 inter split groups**
41+ → a defect this lane did not introduce and does not own (out-of-scope arm).
42+ Suspect: the oracle's 2 `bsize=3 value=3` in that stream are on the KEY frame
43+ (intra `decode_leaf_split4`), i.e. a pre-existing intra sub-8x8 defect on this
44+ recipe, OR our partition read desyncs before reaching them. CHECK FIRST: run the
45+ oracle trace on that exact stream and print the frame index of each b3 v3.
46+* 8-bit attempt 1 (cq 12, sp 3): 1 split group, luma **frame 5** mismatches.
47+ Frames 0..4 are exact, so the group is late in the sequence — bisect with
48+ `EC_TRACE_MODE` (`EC_MODE_VAL4` line added for the 4x4 sub-block) against the
49+ oracle's `EC_MODE`/`EC_MODE_VAL` at the same mi, comparing msac RANGE.
50+ Prime suspects, in order: (a) the sub-block `skip` context — I used the
51+ mi-granular `above_skip[cmi]`/`left_skip[rmi]` pair like `decode_inter_block8`,
52+ libaom uses `av1_get_skip_txfm_context`; (b) the chroma 2x2 piece offsets /
53+ which sub-block's filters each piece uses; (c) `record_mi_luma_rect` per 4x4 vs
54+ the group-level chroma neighbour tail; (d) `first_tx_type` when sub-block 0 is
55+ skip (libaom memsets tx_type_map to DCT_DCT for skip — we leave DctDct: OK).
56+
57+## 4. Still refused after this round
58+`an inter 8x8 HORZ/VERT partition (8x4/4x8 inter leaves...)` — needs (1) INTER
59+TxbSet twins for 4x8/8x4 (`LumaRect4x8Inter`/`Set1`: side 8 tables +
60+`inter_tx_type_4`, copy `LumaRect4x8` and swap the tx_type slice), (2) a
61+rectangular var-tx read: for BLOCK_8X4/4X8, TX_MODE_SELECT + !skip reads exactly
62+ONE `txfm_partition` symbol (max_txsize_rect_lookup = TX_8X4/TX_4X8; split →
63+TX_4X4), our `read_block_tx_size`/`read_var_tx_size` are square-only.
64+That is the bulk of the remaining work and is why r1 scoped to SPLIT.
lanes/intersub8-r2.handoff.mdadded+66 -0
@@ -0,0 +1,66 @@
1+# lane-intersub8 r2 — HANDOFF (gate GREEN, 8x4/4x8 not started)
2+
3+## Merge state
4+* `c048e29` main (8e9ba81) merged — no conflicts, `cdf.rs` untouched.
5+* `e8bb7e7` lane-r14 **b86eb38 merged** (it was NOT on main: main only carries the earlier
6+ `6699ce6`/`a2e2e29`). So `read_var_tx_size` here is `(tx_w,tx_h)`-general with the full
7+ `sub_tx_size_map`, and `read_inter_plane_rect` is available.
8+ NOTE (ledger, lane-inter16ab r3): that merge deletes the "split transform on a 16x16-level
9+ 1:4 inter strip" refusal, so a TX_16X4→TX_8X4 split can reach
10+ `rect_inter_residual_supported(8,4)==false` / `rect_inter_luma_set` `unreachable!()`.
11+ The `LumaRect8x4Inter`/`LumaRect4x8Inter` TxbSets (step 3 below) close that too.
12+
13+## Attempt-0 (cq 8) zero-group mismatch — ROOT CAUSE IDENTIFIED, out of scope
14+Not a sub-8x8 defect: **CDEF**. 3 luma samples `|d|=1`, decode-order frames 3 and 4
15+(x=189 resp. 186, y=116/120/124), zero sub-8x8 inter split groups in those frames; the
16+identical recipe re-encoded with `--enable-cdef=0` decodes all six frames pixel-exact
17+(`~/.cache/intersub8-tmp/gen.sh 8 3 8 a0_nocdef.obu --enable-cdef=0`, then `cmp.py`).
18+Also reproduces at cq 10. Deferred to a CDEF lane. The gate moved to cq {12,14} instead of
19+switching CDEF off (cdef=0 changes aomenc RD and then NO attempt fires a split group).
20+
21+## Attempt-1 frame-5 ladder — FIXED (`96eff0c`)
22+First diverging element: the **switchable interp filter** of the 4x4 sub-block mi(14,46).
23+Ladder vs aomdec `EC_TRACE_MODE` on `~/.cache/intersub8-tmp/a1_8.obu`:
24+entry `39095` = , post-`assign_mv` `60392` = , after interp filter ours `51740` vs oracle `57815`.
25+Cause: the **compound 8x8 inter leaf never called `resolve_interp_filter`** — it hard-coded
26+`Regular` and recorded the `[3, 3]` sentinel in the neighbour filter band. libaom calls
27+`read_mb_interp_filter` for every inter block right after `read_compound_type`, and when
28+`av1_is_interp_needed()==0` (`skip_mode`) `set_default_interp_filters` stores
29+EIGHTTAP_REGULAR **0**. The left neighbour here was a skip_mode compound 8x8 leaf, so our
30+`av1_get_pred_context_switchable_interp` used 3 instead of 0 → wrong CDF row → desync.
31+Fix reads the symbols, uses `h_filter`/`v_filter` in all six `predict_compound_*` calls of
32+that branch, records the real syms. This also removes the old lane-av1comp corner-cut
33+(a NON-skip compound 8x8 leaf used to skip the symbol entirely = latent desync).
34+New rungs for the next hunt: `EC_TRACE_MODE` now prints `EC_MODE` + `EC_MODE_MV` on the
35+sub-8x8 path at the oracle's two print points, and `EC_AV1_IFDBG` prints `IFDBG4` with the
36+neighbour ref/filter bands.
37+
38+## 8x4/4x8 (charter step 3) — NOT STARTED
39+Still refused by name: `an inter 8x8 HORZ/VERT partition (8x4/4x8 inter leaves; the 4x4
40+SPLIT arm decodes, but a rectangular sub-8x8 inter transform is unimplemented)`.
41+Remaining pieces: `TxbSet::LumaRect8x4Inter{,1}` / `LumaRect4x8Inter{,1}` (copy the key-frame
42+8x4/4x8 intra sets' scan/ctx, swap in `inter_tx_type_4`; `av1_get_ext_tx_set_type` →
43+EXT_TX_SET_ALL16 for inter with `sqr_up == TX_8X8`), ONE `txfm_partition` bit at max
44+TX_8X4/TX_4X8 (r14's general `read_var_tx_size` handles it once max=(8,4)), mode info per
45+sub-block, chroma once on the LAST sub-block as 4x4 with 2 sub8x8 pieces, per-mi neighbour
46+writes. Gate arm: same recipe with `--enable-rect-partitions=1` (oracle histogram on the r1
47+recipe: bsize=3 v1=28 HORZ, v2=49 VERT, v3=3 SPLIT).
48+
49+## Gate state
50+`cargo test -p ec-av1 --lib sub8x8_inter_split` → **ok, 1 passed / 0 failed** (414 filtered).
51+Schedule measured by a 56-encode sweep (`~/.cache/intersub8-tmp/sweep.sh`): cq {12,14} ×
52+sp {3,6,9,12} × 8/10-bit. Firing: 8-bit cq12/sp3 = 1 group, 10-bit cq12/sp6 = 3 groups, both
53+pixel-exact; `out_of_scope_mismatch == 0`; every decode-order frame compared Y/U/V.
54+`decode_probe` now prints `sub8_inter_split: groups=N`.
55+`fixtures/realworld/reelb.obu` now stops at the 8x4/4x8 refusal (was: the SPLIT one).
56+
57+## Suite
58+Unit `intersub8-suite-1788328909.service`, log `$HOME/.cache/intersub8-suite-r2.log`.
59+FINISHED GREEN after this handoff was first written:
60+`test result: ok. 382 passed; 0 failed; 33 ignored; 0 measured; 0 filtered out; finished in 1018.88s`.
61+That run IS the sibling sweep for the interp-filter fix (it touches every compound 8x8 leaf).
62+
63+## Exact next step
64+1. Read the suite log (above). 2. Build `LumaRect8x4Inter`/`LumaRect4x8Inter` TxbSets and the
65+8x4/4x8 leaf, add the `--enable-rect-partitions=1` gate arm plus a `--tile-columns=1` arm
66+(COMMON neighbour-map rule, still owed), then drop the 8x4/4x8 refusal + inventory line.
lanes/intersub8-r2.report.mdadded+70 -0
@@ -0,0 +1,70 @@
1+# lane-intersub8 r2 — GREEN gate, one root cause, 8x4/4x8 deferred
2+
3+## 1. Merges
4+* `c048e29` main (8e9ba81) into lane-intersub8 — no conflicts, `cdf.rs` untouched.
5+* `e8bb7e7` lane-r14 (b86eb38) — `read_var_tx_size` is now `(tx_w,tx_h)`-general with the
6+ full `sub_tx_size_map`, plus `read_inter_plane_rect`. `b86eb38` was NOT on main
7+ (`git merge-base --is-ancestor b86eb38 main` → false; main only has the earlier
8+ `6699ce6` merge of `a2e2e29`).
9+
10+## 2. Root cause of the frame-5 red (fixed, `96eff0c`)
11+`crates/ec-av1/src/decode.rs` (8x8 inter leaf, compound arm, ~19940): the branch
12+**never called `resolve_interp_filter`**. It hard-coded `Regular` for both taps and left
13+`leaf_filter_syms` at the `[3, 3]` "no filter" sentinel that `Neighbours::record_inter*`
14+then stored. libaom reads `read_mb_interp_filter` for every inter block right after
15+`read_compound_type` (`decodemv.c` `read_inter_block_mode_info`), and when
16+`av1_is_interp_needed` is 0 (`skip_mode`, `WARPED_CAUSAL`, non-translational GLOBALMV)
17+`set_default_interp_filters` stores **EIGHTTAP_REGULAR (0)**, not a sentinel. Any later
18+block whose `ref_frame[0]` matches that leaf's ref0 **or ref1** then computes
19+`av1_get_pred_context_switchable_interp` from 3 instead of 0 → wrong `switchable_interp`
20+CDF row → tile desync.
21+
22+Bisection (class *compare range not tell*): on `a1_8.obu` (192x128, 8-bit, cq 12, sp 3)
23+the 4x4 sub-block at mi(14,46) matched the oracle at both of aomdec's own print points —
24+entry `rng=39095`, post-`assign_mv` `rng=60392` — and diverged only across the interp
25+filter read: ours `51740` vs aomdec `57815`. `IFDBG4` showed `left_ref=1 left_ref1=Some(4)
26+ref=4 left_filt=[3,3]`: the left neighbour was a **skip_mode compound 8x8 leaf** (its own
27+`EC_MODE` → `EC_MODE_VAL` range never moved, i.e. zero symbols).
28+
29+Fix reads the filter properly (`skip_mode` → `force_regular`, ctx from the same ref-match
30+rule the other leaves use), feeds `h_filter`/`v_filter` to all six `predict_compound_*`
31+calls of that branch and records the real symbols. This also removes the long-standing
32+`lane-av1comp` corner-cut: a **non-skip** compound 8x8 leaf used to skip the symbol
33+entirely, which was a latent desync for any stream that codes one.
34+
35+## 3. Out-of-scope defect found and named (NOT hidden)
36+Same recipe at **cq 8 / cq 10**: three luma samples of `|d| = 1` on decode-order frames 3
37+and 4 (x=189 resp. 186, y=116/120/124), with **zero** sub-8x8 inter split groups in those
38+frames. Re-encoding the identical recipe with `--enable-cdef=0` decodes all six frames
39+pixel-exact ⇒ a **CDEF** defect of another shape.
40+`deferred: CDEF ±1 luma at cq 8/10 on the 192x128 min-partition-4 recipe — belongs to a
41+CDEF lane, not to sub-8x8 partitions — unblocked by a CDEF-focused gate`.
42+The gate does not switch CDEF off (that changes aomenc's RD and kills every firing
43+attempt); it moves to cq {12,14}, where a full sweep shows no mismatch at all.
44+
45+## 4. Gate
46+`cargo test -p ec-av1 --lib sub8x8_inter_split` →
47+`test result: ok. 1 passed; 0 failed` (414 filtered out).
48+Schedule measured, not guessed: sweep of cq {8,10,12,14,16,18,20} × sp {3,6,9,12} × 8/10-bit
49+(`decode_probe`'s new `sub8_inter_split:` counter + an ffmpeg rawvideo compare).
50+Firing attempts: 8-bit cq12/sp3 = 1 group, 10-bit cq12/sp6 = 3 groups, both pixel-exact,
51+every decode-order frame compared Y/U/V; `out_of_scope_mismatch == 0`.
52+
53+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)
54+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
55+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
56+
57+## 4b. Suite
58+`intersub8-suite-1788328909.service`, log `$HOME/.cache/intersub8-suite-r2.log`:
59+`test result: ok. 382 passed; 0 failed; 33 ignored; 0 measured; 0 filtered out; finished in 1018.88s`.
60+This is the sibling sweep the interp-filter fix owes: it touches every compound 8x8 inter leaf.
61+
62+## 5. Not done this round
63+`deferred: 8x4/4x8 inter leaves (charter step 3) — the turn budget went to the root-cause
64+hunt and the gate schedule — unblocked by a fresh round on this branch; r14's general
65+read_var_tx_size is now merged here, so the remaining pieces are the LumaRect8x4Inter /
66+LumaRect4x8Inter TxbSets (EXT_TX_SET_ALL16, sqr_up TX_8X8) and the 2-sub-block chroma`.
67+`deferred: a --tile-columns=1 arm on this gate (COMMON neighbour-map rule) — same budget —
68+unblocked by the next round`.
69+The `an inter 8x8 HORZ/VERT partition ...` refusal therefore STAYS; no refusal string was
70+removed this round, and `refusal_inventory`/`gate_coverage` are unchanged.
lanes/intersub8-r3.handoff.mdadded+79 -0
@@ -0,0 +1,79 @@
1+# lane-intersub8 r3 — HANDOFF (4x8 gated GREEN, 8x4 implemented but refused)
2+
3+## What is wired (decode.rs `decode_inter_sub8_rect2`, ~line 19100)
4+One function serves both shapes (`vert: bool`); the call site
5+(`part8 == PARTITION_VERT` arm of the sub-16 SPLIT leaf loop, ~decode.rs:22630) currently
6+only reaches it with `vert = true`.
7+* mode info per sub-block in `decodemv.c` `read_inter_frame_mode_info` order: segment_id,
8+ skip, cdef/dq/dlf, intra_inter, single ref only (`is_comp_ref_allowed(BLOCK_8X4)` false ->
9+ no skip_mode, no comp_mode), no interintra / motion_mode / OBMC / warp (all need min dim 8),
10+ `read_mb_interp_filter` DOES run.
11+* tx: `block_signals_txsize(BLOCK_8X4)` true (blockd.h:1027) -> ONE `txfm_partition` symbol
12+ under TX_MODE_SELECT at `max_txsize_rect_lookup[BLOCK_8X4] = TX_8X4`, through r14's general
13+ `read_var_tx_size` with max `(bw,bh)` and `blk_max_px = 8`; `sub_tx_size_map[TX_8X4]=TX_4X4`
14+ so a split resolves to two TX_4X4 units (libaom's early return). Skip -> `set_txfm_ctxs`
15+ skip_inter arm.
16+* luma sets NEW in cdf_state.rs: `TxbSet::LumaRect8x4Inter` / `LumaRect8x4InterSet1` =
17+ `LumaRect4x8`'s tables (8x8 coefficient class, 32-position eob_pt) with `inter_tx_type_4` /
18+ `inter_tx_type_4_set1` (EXT_TX_SET_ALL16 at the TX_4X4 inter row). Split TX_4X4 units read
19+ `Luma4Inter{,Set1}`. Whole-leaf unit passes `luma_skip_ctx: None` (it IS the plane block,
20+ `get_txb_ctx_general` fixes 0); split units pass `luma_skip_ctx_rect`.
21+* chroma once, on the SECOND sub-block (`is_chroma_reference` under 4:2:0: bottom 8x4 /
22+ right 4x8), as one TX_4X4 per plane (`TxbSet::Chroma4`), inheriting the FIRST luma TU's
23+ tx_type; prediction is the sub8x8 one (`reconinter.c build_inter_predictors_sub8x8`,
24+ `row_start = -(block_size_high==4 && ss_y)`): two 4x2 (HORZ) / 2x4 (VERT) pieces, each from
25+ its own sub-block's ref/mv/filters.
26+* neighbour writes per mi: `grid_stamp_rect` (size=w_mi, size_h=h_mi over the true span),
27+ `record_mode_mi`, `record_inter_rect_mi`, `fill_skip_grid_rect`, `fill_lf_grid_rect`,
28+ `record_mi_luma_rect` per TU; partition tail `above_side_mi = bw`, `left_side_mi = bh`.
29+
30+## The 8x4 defect (refused by name, NOT fixed)
31+Stream: `~/.cache/intersub8-tmp/gen_t.sh 14 3 8 d1.obu --enable-rect-partitions=1`
32+(transposed-structure geq source: `128+58*sin((Y+N*3)/6)+18*sin(X/23)`, 192x128, 6 frames).
33+Decode-order frame 5 mismatches; frames 0..4 exact. 4 HORZ groups, all at mi rows 30/31,
34+cols 4 and 6.
35+Range ladder (`EC_TRACE_PART=1` ours, new gated print at each partition read, vs aomdec
36+`EC_TRACE=1` `EC_PART`; and `EC_TRACE_MODE` `EC_MODE`; and `EC_TRACE_COEFF` `tag=all_zero`):
37+* every element matches through the 16x16 partition read at mi(28,8) (ctx 2 == oracle's 6,
38+ entry rng 37489 both) and through `EC_MODE mi_row=30 mi_col=8 rng=46505` (both);
39+* that slot is PARTITION_HORZ -> two BLOCK_16X8 at (28,8) and (30,8);
40+* block (30,8)'s LEFT neighbour is our HORZ 8x4 group at (30,6);
41+* first divergence is INSIDE (30,8)'s mode info, AFTER its `EC_MODE` print (so skip and
42+ intra_inter are still right) and BEFORE its first coefficient TU: our TU entry rng 54923 vs
43+ oracle 61760 (`EC_COEFF plane=0 tx_size=8` = TX_16X8, all_zero=0 both). all_zero #468 of
44+ 470/473.
45+=> some per-ROW neighbour band our HORZ group leaves at rows 30/31 is wrong. Remaining
46+suspects, in read order after the print: `left_ref[30]`, the mv stack (MiGrid cells (30,7)/
47+(31,7)), `left_filter[30]`, `left_txfm[30]`. All four were transcribed against libaom and
48+looked right on inspection -- not bisected. NOTE ledger: this oracle's
49+`EC_AV1_PREFILT_DUMP` is already post-deblock, so pixel-stage bisection is confounded; use
50+the range ladder only.
51+
52+## Provable vs not
53+* PROVABLE (gated): two-BLOCK_4X8 (PARTITION_VERT) inter leaves. Sweep
54+ `~/.cache/intersub8-tmp/sweep2.sh` (28 arms, cq {8,12,14,16,20,26,32} x sp {3,6,9,12} x
55+ 8/10-bit, original source, rect on): every arm with `vert4x8 > 0` outside the known-bad
56+ cq8 band decoded pixel-exact; the two cq8 mismatches are r2's CDEF |d|=1 defect.
57+* NOT PROVABLE: 8x4 (HORZ). `sweep3.sh` (transposed source): 4 of 28 arms mismatch with
58+ `horz8x4 > 0` at cq 12/14/16/32, i.e. outside the CDEF band. Refused by name.
59+
60+## Gate
61+`cargo test -p ec-av1 --lib sub8x8_inter_split` -> ok, 1 passed / 0 failed (414 filtered),
62+28.94s. The test now runs 16 attempts per depth: 0..7 `--enable-rect-partitions=0` (SPLIT),
63+8..15 `=1` (VERT). Asserts `fired >= 2`, NEW `rect_fired >= 2`, `out_of_scope_mismatch == 0`,
64+every decode-order frame Y/U/V. `refusal_inventory` 3/3 ok, `gate_coverage` 9/9 ok.
65+
66+## Not done
67+* Full `cargo test -p ec-av1 --lib` suite: NOT RUN this round (turn cap). r2's unit
68+ `intersub8-suite-1788328909` was still running on a stale binary at round start and is now
69+ gone from the unit list; `$HOME/.cache/intersub8-suite-r2.log` has 218 ok / 0 FAILED and no
70+ `test result:` line. Start r3's suite per COMMON's SUITE RUNS recipe, log
71+ `$HOME/.cache/intersub8-suite-r3.log`.
72+* HG film probe: not run.
73+* `--tile-columns=1` gate arm: still owed (no NEW per-mi band was added, all reused).
74+
75+## Exact next step
76+1. Start the r3 suite. 2. Bisect the 8x4 defect on `d1.obu` frame 5 block (30,8) by dumping,
77+one at a time, the four left-band values our HORZ group writes at rows 30/31 and comparing
78+against an instrumented aomdec print of `xd->left_mbmi`/`left_txfm_context[0]` at that block.
79+3. Lift the HORZ refusal with a `sweep3.sh`-based arm once green.
lanes/intersub8-r4.handoff.mdadded+70 -0
@@ -0,0 +1,70 @@
1+# lane-intersub8 r4 — RED on the HORZ lift, GREEN on its root cause
2+
3+## What changed
4+* `crates/ec-av1/src/decode.rs:15981+` — new `bsize_index(w,h)` (libaom `BLOCK_SIZES_ALL`
5+ order), `masked_compound_used_wh`, `wedge_used_wh`.
6+* `crates/ec-av1/src/decode.rs` (`decode_inter_block`, comp-type block) — `comp_group_idx`'s
7+ gate and the `compound_type` / `wedge_idx` CDF ROWS now come from the block's true
8+ `(write_w, write_h)`, not the caller's square `side`. A 16x8 masked-compound block used to
9+ read `BLOCK_16X16`'s row (index 6) where libaom reads `BLOCK_16X8`'s (index 5).
10+ Class: table-indexed-by-raw-size / CDF-row-held-constant.
11+* Same site — `COMPOUND_WEDGE` on a non-square block is refused by name (the wedge codebook
12+ here is built per square side only); listed in `refusal_inventory.rs`.
13+* `crates/ec-av1/src/decode.rs` — `EC_TRACE_MODE` gains `EC_CGI` / `EC_CIDX` / `EC_IF`
14+ (comp_group_idx, compound_idx, interp filter: ctx + value + range). These are the rungs
15+ that localized the defect; the oracle has no per-symbol print between `EC_MODE_MV` and
16+ `EC_MODE_VAL`, so ours had to be split.
17+* Sub-8x8 HORZ call site — still refused, refusal text rewritten to the measured residue,
18+ and `EC_AV1_SUB8_HORZ=1` decodes it anyway for the next round's bisect.
19+
20+## Root cause (r3's open defect), proven
21+`~/.cache/intersub8-tmp/d1.obu` (192x128, 6 frames, 8-bit, transposed geq source, cq14 sp3,
22+`--enable-rect-partitions=1`), decode-order frame 5, `BLOCK_16X8` at mi(30,8):
23+| rung | ours before | ours after | aomdec |
24+|---|---|---|---|
25+| `EC_MODE` entry | 46505 | 46505 | 46505 |
26+| after mv (`EC_MODE_MV`) | 58288 | 58288 | 58288 |
27+| end of mode info (`EC_MODE_VAL`) | 54923 | **61760** | **61760** |
28+| next block `EC_MODE` mi(28,12) | 33919 | **60694** | **60694** |
29+The block reads `comp_group_idx=1` (ctx 0, correct — a ctx sweep 0..5 never reproduced the
30+oracle), then `compound_type` from the wrong CDF row. The 8x4 group to its left was innocent:
31+it only changed which value `comp_group_idx` took.
32+
33+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
34+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
35+
36+## Why the HORZ refusal did NOT lift (RED)
37+3 of 28 arms still mismatch with `horz8x4 > 0`: 8-bit cq32 sp9 (horz=3), 10-bit cq12 sp3
38+(horz=5), 10-bit cq16 sp3 (horz=2). On the 10-bit cq12 sp3 stream the ENTROPY IS EXACT — the
39+full `EC_MODE` range ladder is identical to aomdec's element for element (the only diff is two
40+extra `EC_MODE` prints for blocks aomdec's instrumentation does not print). The mismatch is
41+post-entropy: luma only, `|d| <= 2`, confined to x < 48 / y >= 112 (mi rows 28..31, mi cols
42+0..11), first appearing on decode-order frame 3 and propagating. Shape says filter (CDEF or
43+the deblock of the internal 8x4 edge), not reconstruction of the coefficients.
44+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
45+
46+## Gates
47+* `sub8x8_inter_split` (the r3 gate, SPLIT + VERT arms) unchanged — HORZ arm NOT added, since
48+ the shape is still refused.
49+* No new gate for the masked-compound fix: measured, the only streams that reach a rect
50+ masked-compound block are HORZ ones, which the refusal blocks. `deferred: gate for the rect
51+ compound_type/wedge_idx row — no non-HORZ recipe found that produces a rect block with
52+ comp_group_idx==1 — unblocked by either the HORZ lift or a `--enable-masked-comp` sweep on
53+ rect-heavy square-only content.`
54+* Full suite: unit `intersub8-suite-r4-1788331918.service` -> `$HOME/.cache/intersub8-suite-r4.log`,
55+ STILL RUNNING at hand-off (74 ok, 0 FAILED, no `test result:` line yet). NOT a green claim.
56+ r3's unit (`intersub8-suite-1788331066`) was stopped as charter-ordered; its log had 73 ok /
57+ 0 FAILED and no `test result:` line at stop time.
58+
59+## Film probe
60+0.4 s copy-extract at 0 s of the 2160p 10-bit HDR AV1 film yields only 1817 bytes (one OBU
61+set, no full frame); the probe returns counters (`horz8x4=0`) and no refusal, so the census's
62+start_s=0 refusal ("an inter partition below 8x8") is NOT reproduced by that extract.
63+`deferred: HG below-8x8 census probe — the bounded extract is too small to reach the block —
64+unblocked by extracting from a keyframe offset (census4 reelb4.tsv start_s column).`
65+
66+## Residue
67+* fix-now(next round): the |d|<=2 luma band under HORZ. Reproduce with
68+ `EC_AV1_SUB8_HORZ=1` on `~/.cache/intersub8-tmp/t_10_12_3.obu` (regenerate:
69+ `./gen_t.sh 12 3 10 m1.obu --enable-rect-partitions=1`).
70+* accepted: `COMPOUND_WEDGE` on a rect block refused (rect wedge codebooks unimplemented).
lanes/intersub8-r4.report.mdadded+70 -0
@@ -0,0 +1,70 @@
1+# lane-intersub8 r4 — RED on the HORZ lift, GREEN on its root cause
2+
3+## What changed
4+* `crates/ec-av1/src/decode.rs:15981+` — new `bsize_index(w,h)` (libaom `BLOCK_SIZES_ALL`
5+ order), `masked_compound_used_wh`, `wedge_used_wh`.
6+* `crates/ec-av1/src/decode.rs` (`decode_inter_block`, comp-type block) — `comp_group_idx`'s
7+ gate and the `compound_type` / `wedge_idx` CDF ROWS now come from the block's true
8+ `(write_w, write_h)`, not the caller's square `side`. A 16x8 masked-compound block used to
9+ read `BLOCK_16X16`'s row (index 6) where libaom reads `BLOCK_16X8`'s (index 5).
10+ Class: table-indexed-by-raw-size / CDF-row-held-constant.
11+* Same site — `COMPOUND_WEDGE` on a non-square block is refused by name (the wedge codebook
12+ here is built per square side only); listed in `refusal_inventory.rs`.
13+* `crates/ec-av1/src/decode.rs` — `EC_TRACE_MODE` gains `EC_CGI` / `EC_CIDX` / `EC_IF`
14+ (comp_group_idx, compound_idx, interp filter: ctx + value + range). These are the rungs
15+ that localized the defect; the oracle has no per-symbol print between `EC_MODE_MV` and
16+ `EC_MODE_VAL`, so ours had to be split.
17+* Sub-8x8 HORZ call site — still refused, refusal text rewritten to the measured residue,
18+ and `EC_AV1_SUB8_HORZ=1` decodes it anyway for the next round's bisect.
19+
20+## Root cause (r3's open defect), proven
21+`~/.cache/intersub8-tmp/d1.obu` (192x128, 6 frames, 8-bit, transposed geq source, cq14 sp3,
22+`--enable-rect-partitions=1`), decode-order frame 5, `BLOCK_16X8` at mi(30,8):
23+| rung | ours before | ours after | aomdec |
24+|---|---|---|---|
25+| `EC_MODE` entry | 46505 | 46505 | 46505 |
26+| after mv (`EC_MODE_MV`) | 58288 | 58288 | 58288 |
27+| end of mode info (`EC_MODE_VAL`) | 54923 | **61760** | **61760** |
28+| next block `EC_MODE` mi(28,12) | 33919 | **60694** | **60694** |
29+The block reads `comp_group_idx=1` (ctx 0, correct — a ctx sweep 0..5 never reproduced the
30+oracle), then `compound_type` from the wrong CDF row. The 8x4 group to its left was innocent:
31+it only changed which value `comp_group_idx` took.
32+
33+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
34+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
35+
36+## Why the HORZ refusal did NOT lift (RED)
37+3 of 28 arms still mismatch with `horz8x4 > 0`: 8-bit cq32 sp9 (horz=3), 10-bit cq12 sp3
38+(horz=5), 10-bit cq16 sp3 (horz=2). On the 10-bit cq12 sp3 stream the ENTROPY IS EXACT — the
39+full `EC_MODE` range ladder is identical to aomdec's element for element (the only diff is two
40+extra `EC_MODE` prints for blocks aomdec's instrumentation does not print). The mismatch is
41+post-entropy: luma only, `|d| <= 2`, confined to x < 48 / y >= 112 (mi rows 28..31, mi cols
42+0..11), first appearing on decode-order frame 3 and propagating. Shape says filter (CDEF or
43+the deblock of the internal 8x4 edge), not reconstruction of the coefficients.
44+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
45+
46+## Gates
47+* `sub8x8_inter_split` (the r3 gate, SPLIT + VERT arms) unchanged — HORZ arm NOT added, since
48+ the shape is still refused.
49+* No new gate for the masked-compound fix: measured, the only streams that reach a rect
50+ masked-compound block are HORZ ones, which the refusal blocks. `deferred: gate for the rect
51+ compound_type/wedge_idx row — no non-HORZ recipe found that produces a rect block with
52+ comp_group_idx==1 — unblocked by either the HORZ lift or a `--enable-masked-comp` sweep on
53+ rect-heavy square-only content.`
54+* Full suite: unit `intersub8-suite-r4-1788331918.service` -> `$HOME/.cache/intersub8-suite-r4.log`,
55+ STILL RUNNING at hand-off (74 ok, 0 FAILED, no `test result:` line yet). NOT a green claim.
56+ r3's unit (`intersub8-suite-1788331066`) was stopped as charter-ordered; its log had 73 ok /
57+ 0 FAILED and no `test result:` line at stop time.
58+
59+## Film probe
60+0.4 s copy-extract at 0 s of the 2160p 10-bit HDR AV1 film yields only 1817 bytes (one OBU
61+set, no full frame); the probe returns counters (`horz8x4=0`) and no refusal, so the census's
62+start_s=0 refusal ("an inter partition below 8x8") is NOT reproduced by that extract.
63+`deferred: HG below-8x8 census probe — the bounded extract is too small to reach the block —
64+unblocked by extracting from a keyframe offset (census4 reelb4.tsv start_s column).`
65+
66+## Residue
67+* fix-now(next round): the |d|<=2 luma band under HORZ. Reproduce with
68+ `EC_AV1_SUB8_HORZ=1` on `~/.cache/intersub8-tmp/t_10_12_3.obu` (regenerate:
69+ `./gen_t.sh 12 3 10 m1.obu --enable-rect-partitions=1`).
70+* accepted: `COMPOUND_WEDGE` on a rect block refused (rect wedge codebooks unimplemented).
lanes/intersub8-r5.report.mdadded+79 -0
@@ -0,0 +1,79 @@
1+# lane-intersub8 r5 — GREEN: the sub-8x8 inter HORZ refusal is lifted
2+
3+## What changed
4+* **Merged `lane-cdef` 8c6065e** (`5c9cccd`, merge commit, not on main at the time).
5+ Its `decode_inter_block8` skip-band write IS the root cause of this lane's r4 residue.
6+* `crates/ec-av1/src/decode.rs` (`decode_tile`'s 8x8 partition switch) — the
7+ `PARTITION_HORZ` refusal and its `EC_AV1_SUB8_HORZ` escape hatch are **deleted**; HORZ and
8+ VERT now both fall into `decode_inter_sub8_rect2`.
9+* `crates/ec-av1/src/decode.rs:1841+` — new `RECT_MASKED_COMPOUND_HITS` /
10+ `rect_masked_compound_hits()`, incremented at the `comp_group_idx == 1` site when
11+ `write_w != write_h`: the non-square half of `MASKED_COMPOUND_HITS`, i.e. exactly the shape
12+ whose `compound_type`/`wedge_idx` CDF row r4 fixed. Square blocks cannot show that defect, so
13+ a gate asserting `masked_compound_hits` alone stayed vacuous for it.
14+* `crates/ec-av1/src/refusal_inventory.rs` — the HORZ entry removed (47 -> 46 in this tree's list).
15+* `crates/ec-av1/src/stream.rs` — gate
16+ `a_real_aomenc_inter_sequence_with_a_sub8x8_inter_split_decodes_pixel_exact` grows attempts
17+ 16..23: `--enable-rect-partitions=1` with the geq source **transposed** (the moving sine runs
18+ along Y), the schedule aomenc actually picks HORZ on. The two axes are counted apart
19+ (`horz_fired` / `vert_fired`, each `>= 2` asserted), `rect_masked >= 1` is asserted, and every
20+ counter is taken only across a **pixel-compared** attempt (class counter-from-refused-stream).
21+ `out_of_scope_mismatch == 0` unchanged. Both bit depths, 48 attempts.
22+* `bb59012` — `git merge main` (aa83400). Clean; `cdf.rs` byte-identical to main's; exactly one
23+ `bsize_index` and one `compound_type`/`wedge_idx` read site survive, so main's inter16ab copy
24+ of the rect CDF-row fix and this lane's r4 copy did not duplicate.
25+
26+## Root cause of the r4 residue (charter hypothesis (a) was stale, (b) never applied)
27+The charter asked for the 8x4 pair to write the 8x8 CDEF skip band and the internal-edge lf
28+grid. Measured: `decode_inter_sub8_rect2` **already** wrote both per leaf
29+(`fill_skip_grid_rect(lmi, w_mi, h_mi, skip)` at `decode.rs:20071`, `fill_lf_grid_rect` at
30+`:19987`/`:20060`), and the skip grid is per-4x4-mi with `is_skip_txfm` gathering all four cells
31+— two 8x4 leaves cover all four. The missing writer was the **8x8 square leaf next door**
32+(`decode_inter_block8`), fixed by lane-cdef. Merging it alone, with no further edit, turned all
33+three red arms exact.
34+
35+## Gate results
36+Command (worktree, `CARGO_TARGET_DIR=$HOME/.cache/cargo-target-intersub8`):
37+`EC_AV1_REQUIRE_AOMENC=1 cargo test -p ec-av1 --lib -j3 sub8x8_inter_split -- --nocapture`
38+
39+EVIDENCE: ~/.cache/intersub8-gate-r5.log | re-run at b64da0d: `cargo test -p ec-av1 --lib -j3 -- --nocapture sub8x8_inter_split cdef_and_sub16_inter_leaves refusal_inventory gate_coverage` | `fired=10 horz=5 vert=3 rect_masked=2` (both axes fire, `out_of_scope_mismatch == 0` asserted at stream.rs:7769), cdef sub16 gate now ok, `test result: ok. 14 passed; 0 failed` in 13.39s
40+EVIDENCE: gate stdout (r5 first run) | 48 real-aomenc attempts (2 depths x 24), each decoded and Y/U/V-compared vs ffmpeg | `fired=10 horz=5 vert=3 rect_masked=2`, `test result: ok. 1 passed; 0 failed` in 42.90s
41+EVIDENCE: ~/.cache/intersub8-sweep-r5.log | 56-arm sweep (cq {8,12,14,16,20,26,32} x sp {3,6,9,12} x {8,10}-bit, transposed source, rect on) re-run after the cdef merge with the HORZ path live | **zero MISMATCH arms**; every `horz8x4>0` arm is EXACT (8-bit cq14 sp3 h=4, cq20 sp3 h=4, cq32 sp9 h=3; 10-bit cq12 sp3 h=5, cq16 sp3 h=2) or stops at another lane's named refusal (8-bit cq12 sp6 h=1 -> the rect COMPOUND_WEDGE refusal, 10-bit cq8 sp12 h=2 -> non-DC chroma on an 8x8 inter leaf). r4 had 3 mismatching arms.
42+EVIDENCE: same log, 3 targeted arms re-run individually | `gen_t.sh` + probe under `systemd-run --scope -p MemoryMax=6G`, compared to `ffmpeg -pix_fmt yuv420p{,10le}` | 8-bit cq32 sp9, 10-bit cq12 sp3, 10-bit cq16 sp3: MISMATCH (r4) -> EXACT, with the cdef merge as the only change
43+
44+`refusal_inventory` (2 tests) and `gate_coverage` (10 tests) green after the lift:
45+`test result: ok. 12 passed; 0 failed`.
46+
47+## Full suite
48+The first r5 unit (`intersub8-suite-r5-1788332492`) finished **FAILED. 384 passed; 1 failed;
49+33 ignored** — the single failure was `a_real_aomenc_stream_with_cdef_and_sub16_inter_leaves`
50+panicking `no sub-16x16 inter leaf wrote the CDEF skip band (depth=10 cq=12)`: an
51+INSTRUMENTATION gap, the hit counter sat only in `decode_inter_block8`'s compound early-return
52+arm and not in its fall-through twin. `b64da0d` counts both. The unit had been started 2 minutes
53+before that commit, so it measured the pre-fix tree.
54+
55+Re-run after `b64da0d`: unit `intersub8-suite-r5b-1788345925` -> `$HOME/.cache/intersub8-suite-r5.log`.
56+**`test result: ok. 385 passed; 0 failed; 33 ignored; 0 measured; 0 filtered out` in 1489.80s.**
57+
58+EVIDENCE: $HOME/.cache/intersub8-suite-r5.log | `cargo test -p ec-av1 --lib -j3` under user unit `intersub8-suite-r5b-1788345925` (MemoryMax=10G, nice 10, EC_AV1_REQUIRE_AOMENC=1), full re-run at b64da0d | 385/0 — the one r5 failure (cdef sub16 counter) is gone, no new red
59+
60+r4's unit (`intersub8-suite-r4-1788331918`) was stopped as charter-ordered: **187 ok, 0 FAILED,
61+no `test result:` line** at stop time — recorded, not a green claim.
62+
63+## Film probe
64+CORRECTION to the r5 first draft: `census4/reelb4.tsv` DOES exist, under this session's
65+scratchpad (`.../b6d8a07f-.../scratchpad/census4/reelb4.tsv`), not under `~/.cache`. Its row
66+that refused below-8x8 is **ss=0** (`nd=30`), and `run4.sh` extracts with `-t 2`, not 0.5.
67+
68+EVIDENCE: ~/.cache/intersub8-tmp/reelb_0b.obu + reelb_0b.log | `ffmpeg -ss 0 -t 2 -c:v copy -an -f obu` on the 3840x1608 10-bit AV1 film, then `decode_probe` with `EC_AV1_FINAL_DUMP` under a 6G scope | 30 frames dumped (same count as the census row), counters `sub8_inter_split: groups=1`, `sub8_inter_rect: horz8x4=8 vert4x8=9` -- the below-8x8 partitions are now DECODED, and the segment stops one refusal later, at "a non-DC chroma mode on an 8x8 inter-frame leaf", instead of "an inter partition below 8x8".
69+
70+### Earlier (mis-sourced) offsets, kept for the record
71+
72+EVIDENCE: ~/.cache/intersub8-tmp/reelb_{300,1200,1800}.obu | `ffmpeg -ss <s> -t 0.5 -c:v copy -an -f obu` then `decode_probe` under a 6G scope | ss=300 stops at "a split intra strip whose transform unit is 32x64"; ss=1200 and ss=1800 both stop at "a split (nonzero tx_depth) transform on an intra HORZ/VERT strip in an inter frame". `sub8_inter_split`/`sub8_inter_rect` counters are 0 at all three — **the below-8x8 refusal is no longer this film's frontier at these offsets**; two intra-strip transform refusals (other lanes) are hit first.
73+
74+## Residue
75+* accepted: `COMPOUND_WEDGE` on a rect block still refused (rect wedge codebooks unimplemented);
76+ the 8-bit cq12 sp6 sweep arm is the witness that a real encoder reaches it.
77+* deferred: the two intra-strip transform refusals that now front the film — owned by the
78+ intra-strip lanes — unblocked by rect/split luma coefficient tables for 32x64 and for a
79+ nonzero-tx_depth intra strip in an inter frame.