forge
Explore
Log in

Don't you dare go Hollow

Merge branch 'lane-intersub8' (a5b9770): sub-8x8 inter partitions (SPLIT, HORZ, VERT) lifted and gated

Browse files at this commit

89682ac17ffd25c3bd2027b4e74ab9eb6f5b0119Ahmet Kaan GümüşParent: c4478d5823ca8c
The "an inter partition below 8x8" refusal is gone: the sub-8x8 inter arms decode,
with the CDEF skip band for the 8x4/4x8 pair, and are gated at both bit depths.
Four narrower refusals take its place (intra 4x4 / 8x4 / 4x8 inside the sub-8x8
split, sub-8x8 under a scaled reference, COMPOUND_WEDGE on a non-square block).

Merge resolution: this lane's compound-8x8-leaf interp read is DROPPED -- lane-interp3
landed the same read with the is_nontrans_global_motion suppression term, and keeping
both would have read the switchable_interp symbol twice. The lane's palette-on-1:4
refusal is not carried (lane-kf900 lifted that shape). Trace rungs from both sides kept.

Gates: sub8x8_inter (1), dual_filter_obmc_8x8 (1), obmc (5), refusal_inventory (3),
gate_coverage (9), base_ctx_rect_offsets (1) -- all pass.

12 changed files +2152 -217

crates/ec-av1/examples/decode_probe.rsmodified+3 -0
@@ -36,6 +36,9 @@ fn main() {
36 println!("rect_intrabc_reads: {}", ec_av1::stream::rect_intrabc_reads());36 println!("rect_intrabc_reads: {}", ec_av1::stream::rect_intrabc_reads());
37 let (rtu, rsplit, robmc) = ec_av1::stream::rect_inter_tu_counters();37 let (rtu, rsplit, robmc) = ec_av1::stream::rect_inter_tu_counters();
38 println!("rect_inter: tu={rtu} txsplit={rsplit} obmc_leaf={robmc}");38 println!("rect_inter: tu={rtu} txsplit={rsplit} obmc_leaf={robmc}");
39+ println!("sub8_inter_split: groups={}", ec_av1::decode::sub8_inter_split_hits());
40+ let (h84, h48) = ec_av1::decode::sub8_inter_rect_hits();
41+ println!("sub8_inter_rect: horz8x4={h84} vert4x8={h48}");
39 let leaf = ec_av1::stream::vartx_rect_leaf_hits();42 let leaf = ec_av1::stream::vartx_rect_leaf_hits();
40 println!("vartx_rect_leaf: 32x16={} 16x32={}", leaf[0], leaf[1]);43 println!("vartx_rect_leaf: 32x16={} 16x32={}", leaf[0], leaf[1]);
41 // lane-inter16ab r1: the 16x16-level inter AB arms, so a recipe sweep44 // 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 {
230 /// counterpart: `EXT_TX_SET_DTT4_IDTX_1DDCT`, the seven-symbol `TX_4X4`230 /// counterpart: `EXT_TX_SET_DTT4_IDTX_1DDCT`, the seven-symbol `TX_4X4`
231 /// row [`LumaRect4x8Set1`](TxbSet::LumaRect4x8Set1) reads.231 /// row [`LumaRect4x8Set1`](TxbSet::LumaRect4x8Set1) reads.
232 LumaRect16x4Set1,232 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,
233 }249 }
234 250
235 /// The tables one transform block is coded with, borrowed from the state for251 /// The tables one transform block is coded with, borrowed from the state for
@@ -1792,6 +1808,30 @@ impl Cdfs {
1792 tx_type: Some(self.intra_tx_type_4[mode].as_mut_slice()),1808 tx_type: Some(self.intra_tx_type_4[mode].as_mut_slice()),
1793 eob_pt_class1: Some(&mut self.eob_pt_32_luma_class1),1809 eob_pt_class1: Some(&mut self.eob_pt_32_luma_class1),
1794 },1810 },
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+ },
1795 TxbSet::LumaRect4x8Set1 => TxbTables {1835 TxbSet::LumaRect4x8Set1 => TxbTables {
1796 side: 8,1836 side: 8,
1797 txb_skip: &mut self.txb_skip_luma_8,1837 txb_skip: &mut self.txb_skip_luma_8,
crates/ec-av1/src/decode.rsmodified+1355 -216
@@ -1944,6 +1944,21 @@ pub(crate) fn masked_compound_hits() -> usize {
1944 MASKED_COMPOUND_HITS.with(|c| c.get())1944 MASKED_COMPOUND_HITS.with(|c| c.get())
1945 }1945 }
1946 1946
1947+// lane-intersub8 r4/r5: the NON-SQUARE half of `MASKED_COMPOUND_HITS` -- a
1948+// masked-compound block whose true footprint is rectangular, i.e. the case
1949+// whose `compound_type`/`wedge_idx` CDF row r4 fixed (it used to read the
1950+// square envelope's `BLOCK_SIZES_ALL` index). Square blocks cannot show that
1951+// defect, so a gate asserting `masked_compound_hits` alone stays vacuous for it.
1952+thread_local! {
1953+ static RECT_MASKED_COMPOUND_HITS: std::cell::Cell<usize> =
1954+ const { std::cell::Cell::new(0) };
1955+}
1956+
1957+/// Current value of [`RECT_MASKED_COMPOUND_HITS`].
1958+pub(crate) fn rect_masked_compound_hits() -> usize {
1959+ RECT_MASKED_COMPOUND_HITS.with(|c| c.get())
1960+}
1961+
1947 // How many blocks decoded a real `COMPOUND_WEDGE` block (`comp_group_idx ==1962 // How many blocks decoded a real `COMPOUND_WEDGE` block (`comp_group_idx ==
1948 // 1`, `compound_type == 0`) -- lane-wedge r3's proof a gate fixture1963 // 1`, `compound_type == 0`) -- lane-wedge r3's proof a gate fixture
1949 // actually exercised the wedge blend, not just the DIFFWTD half of1964 // actually exercised the wedge blend, not just the DIFFWTD half of
@@ -2741,6 +2756,21 @@ pub(crate) fn tx_class1_hits() -> usize {
2741 // coincidentally landing on `PARTITION_NONE`.2756 // coincidentally landing on `PARTITION_NONE`.
2742 thread_local! {2757 thread_local! {
2743 static SUB8_SPLIT_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };2758 static SUB8_SPLIT_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
2759+ /// How many 8x8 groups an INTER frame split into four BLOCK_4X4 inter
2760+ /// sub-blocks (lane-intersub8).
2761+ static SUB8_INTER_SPLIT_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
2762+ /// How many 8x8 groups an INTER frame split into two rectangular sub-8x8
2763+ /// inter leaves (lane-intersub8 r3), indexed `[0] = HORZ` (two BLOCK_8X4),
2764+ /// `[1] = VERT` (two BLOCK_4X8).
2765+ static SUB8_INTER_RECT_HITS: std::cell::Cell<[usize; 2]> = const { std::cell::Cell::new([0; 2]) };
2766+}
2767+
2768+/// Current value of [`SUB8_INTER_RECT_HITS`]: `(8x4 groups, 4x8 groups)`.
2769+pub fn sub8_inter_rect_hits() -> (usize, usize) {
2770+ SUB8_INTER_RECT_HITS.with(|c| {
2771+ let h = c.get();
2772+ (h[0], h[1])
2773+ })
2744 }2774 }
2745 2775
2746 // lane-cdef r1: (a) how many 8x8 CDEF units `apply_cdef` EXCLUDED because all2776 // lane-cdef r1: (a) how many 8x8 CDEF units `apply_cdef` EXCLUDED because all
@@ -2783,6 +2813,11 @@ pub(crate) fn sub8_split_hits() -> usize {
2783 SUB8_SPLIT_HITS.with(|c| c.get())2813 SUB8_SPLIT_HITS.with(|c| c.get())
2784 }2814 }
2785 2815
2816+/// Current value of [`SUB8_INTER_SPLIT_HITS`].
2817+pub fn sub8_inter_split_hits() -> usize {
2818+ SUB8_INTER_SPLIT_HITS.with(|c| c.get())
2819+}
2820+
2786 // How many 4x8 / 8x4 leaves (lane-tx4x8's `PARTITION_VERT`/`PARTITION_HORZ`2821 // How many 4x8 / 8x4 leaves (lane-tx4x8's `PARTITION_VERT`/`PARTITION_HORZ`
2787 // of an 8x8 block) this thread's decode reconstructed with REAL coefficients2822 // of an 8x8 block) this thread's decode reconstructed with REAL coefficients
2788 // -- a skipped leaf exercises the prediction and the mi bookkeeping but never2823 // -- a skipped leaf exercises the prediction and the mi bookkeeping but never
@@ -15754,6 +15789,12 @@ fn resolve_interp_filter(
15754 if enable_dual_filter && sym0 != sym1 {15789 if enable_dual_filter && sym0 != sym1 {
15755 DUAL_FILTER_DIFF_HITS.with(|c| c.set(c.get() + 1));15790 DUAL_FILTER_DIFF_HITS.with(|c| c.set(c.get() + 1));
15756 }15791 }
15792+ if std::env::var_os("EC_TRACE_MODE").is_some() {
15793+ eprintln!(
15794+ "EC_IF ctx0={ctx0} above={above:?} left={left:?} sym0={sym0} sym1={sym1} rng={}",
15795+ dec.debug_state().0
15796+ );
15797+ }
15757 (15798 (
15758 mc::InterpFilterKind::from_switchable_symbol(sym1 as usize),15799 mc::InterpFilterKind::from_switchable_symbol(sym1 as usize),
15759 mc::InterpFilterKind::from_switchable_symbol(sym0 as usize),15800 mc::InterpFilterKind::from_switchable_symbol(sym0 as usize),
@@ -16819,6 +16860,67 @@ fn is_any_masked_compound_used_here(side: usize) -> bool {
16819 side.min(side) >= 816860 side.min(side) >= 8
16820 }16861 }
16821 16862
16863+/// libaom's `BLOCK_SIZES_ALL` index of a `w`x`h` block (`common_data.h`'s own
16864+/// enum order) -- the row every bsize-indexed CDF (`compound_type_cdf`,
16865+/// `wedge_idx_cdf`) is read at. lane-intersub8 r4: these two used to be
16866+/// indexed by the caller's SQUARE envelope, so a 16x8 compound block read
16867+/// `BLOCK_16X16`'s row (class table-indexed-by-raw-size) and desynced the
16868+/// tile at its first masked-compound rect block.
16869+fn bsize_index(w: usize, h: usize) -> Option<usize> {
16870+ Some(match (w, h) {
16871+ (4, 4) => 0,
16872+ (4, 8) => 1,
16873+ (8, 4) => 2,
16874+ (8, 8) => 3,
16875+ (8, 16) => 4,
16876+ (16, 8) => 5,
16877+ (16, 16) => 6,
16878+ (16, 32) => 7,
16879+ (32, 16) => 8,
16880+ (32, 32) => 9,
16881+ (32, 64) => 10,
16882+ (64, 32) => 11,
16883+ (64, 64) => 12,
16884+ (64, 128) => 13,
16885+ (128, 64) => 14,
16886+ (128, 128) => 15,
16887+ (4, 16) => 16,
16888+ (16, 4) => 17,
16889+ (8, 32) => 18,
16890+ (32, 8) => 19,
16891+ (16, 64) => 20,
16892+ (64, 16) => 21,
16893+ _ => return None,
16894+ })
16895+}
16896+
16897+/// `is_any_masked_compound_used` (libaom `reconinter.h`) on the block's TRUE
16898+/// footprint: `is_comp_ref_allowed` is `AOMMIN(bw, bh) >= 8`, and every
16899+/// shape that clears it has either a wedge or a DIFFWTD compound available.
16900+fn masked_compound_used_wh(w: usize, h: usize) -> bool {
16901+ w.min(h) >= 8
16902+}
16903+
16904+/// `av1_wedge_params_lookup[bsize].wedge_types > 0` (libaom `reconinter.c`):
16905+/// the shapes whose `compound_type` symbol is really coded. Everything else
16906+/// with a compound mask infers `COMPOUND_DIFFWTD` without a symbol.
16907+fn wedge_used_wh(w: usize, h: usize) -> bool {
16908+ matches!(
16909+ (w, h),
16910+ (8, 8)
16911+ | (8, 16)
16912+ | (16, 8)
16913+ | (16, 16)
16914+ | (16, 32)
16915+ | (32, 16)
16916+ | (32, 32)
16917+ | (8, 32)
16918+ | (32, 8)
16919+ | (16, 64)
16920+ | (64, 16)
16921+ )
16922+}
16923+
16822 /// Whether a compound reference pair is unidirectional (both references on16924 /// Whether a compound reference pair is unidirectional (both references on
16823 /// the same temporal side of the current frame) -- `has_uni_comp_refs`16925 /// the same temporal side of the current frame) -- `has_uni_comp_refs`
16824 /// (libaom `av1_reference_frame_utils.h`/`pred_common.c`'s own definition:16926 /// (libaom `av1_reference_frame_utils.h`/`pred_common.c`'s own definition:
@@ -17608,12 +17710,18 @@ fn decode_inter_block(
17608 let group_ctx = get_comp_group_idx_context(neighbours, (rmi, cmi), side);17710 let group_ctx = get_comp_group_idx_context(neighbours, (rmi, cmi), side);
17609 let comp_group_idx = if !skip_mode17711 let comp_group_idx = if !skip_mode
17610 && enable_masked_compound17712 && enable_masked_compound
17611- && is_any_masked_compound_used_here(side)17713+ && masked_compound_used_wh(write_w, write_h)
17612 {17714 {
17613 dec.symbol(&mut cdfs.comp_group_idx[group_ctx])17715 dec.symbol(&mut cdfs.comp_group_idx[group_ctx])
17614 } else {17716 } else {
17615 017717 0
17616 };17718 };
17719+ if std::env::var_os("EC_TRACE_MODE").is_some() {
17720+ eprintln!(
17721+ "EC_CGI mi_row={rmi} mi_col={cmi} ctx={group_ctx} val={comp_group_idx} rng={}",
17722+ dec.debug_state().0
17723+ );
17724+ }
17617 // lane-maskcomp r2 / lane-wedge r3: `Some(mask_type)` for a17725 // lane-maskcomp r2 / lane-wedge r3: `Some(mask_type)` for a
17618 // `COMPOUND_DIFFWTD` block, `Some(mask)` (wedge codebook lookup)17726 // `COMPOUND_DIFFWTD` block, `Some(mask)` (wedge codebook lookup)
17619 // for a `COMPOUND_WEDGE` block -- exactly one of the two is set17727 // for a `COMPOUND_WEDGE` block -- exactly one of the two is set
@@ -17635,12 +17743,11 @@ fn decode_inter_block(
17635 // writes NO `compound_type` symbol there and INFERS17743 // writes NO `compound_type` symbol there and INFERS
17636 // `COMPOUND_DIFFWTD` -- only the 1-bit `mask_type` literal17744 // `COMPOUND_DIFFWTD` -- only the 1-bit `mask_type` literal
17637 // follows. `None` here is exactly that inferred arm.17745 // follows. `None` here is exactly that inferred arm.
17638- let wedge_bsize = match side {17746+ // lane-intersub8 r4: the block's TRUE footprint, not the
17639- 8 => Some(3),17747+ // square envelope -- `compound_type_cdf`/`wedge_idx_cdf` are
17640- 16 => Some(6),17748+ // `BLOCK_SIZES_ALL`-indexed.
17641- 32 => Some(9),17749+ let wedge_bsize =
17642- _ => None,17750+ bsize_index(write_w, write_h).filter(|_| wedge_used_wh(write_w, write_h));
17643- };
17644 let compound_type = match wedge_bsize {17751 let compound_type = match wedge_bsize {
17645 Some(b) => dec.symbol(&mut cdfs.compound_type[b]),17752 Some(b) => dec.symbol(&mut cdfs.compound_type[b]),
17646 None => 1,17753 None => 1,
@@ -17648,6 +17755,14 @@ fn decode_inter_block(
17648 if let Some(wedge_bsize) = wedge_bsize.filter(|_| compound_type == 0) {17755 if let Some(wedge_bsize) = wedge_bsize.filter(|_| compound_type == 0) {
17649 // COMPOUND_WEDGE: lane-wedge r3, codebook checksum-17756 // COMPOUND_WEDGE: lane-wedge r3, codebook checksum-
17650 // verified vs independent C dump (wedge.rs).17757 // verified vs independent C dump (wedge.rs).
17758+ if write_w != write_h {
17759+ // lane-intersub8 r4: the wedge codebook here is built
17760+ // per SQUARE side only; a rect block's own codebook
17761+ // (BLOCK_16X8 etc.) is a different mask set.
17762+ return Err(unsupported(
17763+ "a COMPOUND_WEDGE mask on a non-square inter block (rect wedge codebook unimplemented)",
17764+ ));
17765+ }
17651 let wedge_index = dec.symbol(&mut cdfs.wedge_idx[wedge_bsize]);17766 let wedge_index = dec.symbol(&mut cdfs.wedge_idx[wedge_bsize]);
17652 let wedge_sign = dec.literal(1);17767 let wedge_sign = dec.literal(1);
17653 WEDGE_HITS.with(|c| c.set(c.get() + 1));17768 WEDGE_HITS.with(|c| c.set(c.get() + 1));
@@ -17665,6 +17780,9 @@ fn decode_inter_block(
17665 }17780 }
17666 }17781 }
17667 MASKED_COMPOUND_HITS.with(|c| c.set(c.get() + 1));17782 MASKED_COMPOUND_HITS.with(|c| c.set(c.get() + 1));
17783+ if write_w != write_h {
17784+ RECT_MASKED_COMPOUND_HITS.with(|c| c.set(c.get() + 1));
17785+ }
17668 }17786 }
17669 // corner-cut (lane-av1comp r16/r17, lane-av1blend r1): r16/r1717787 // corner-cut (lane-av1comp r16/r17, lane-av1blend r1): r16/r17
17670 // called this a `predict_compound_intermediate`/`combine_compound`17788 // called this a `predict_compound_intermediate`/`combine_compound`
@@ -17879,6 +17997,12 @@ fn decode_inter_block(
17879 ref_order_hints[(ref1 - LAST_FRAME) as usize],17997 ref_order_hints[(ref1 - LAST_FRAME) as usize],
17880 );17998 );
17881 let idx = dec.symbol(&mut cdfs.compound_idx[idx_ctx]);17999 let idx = dec.symbol(&mut cdfs.compound_idx[idx_ctx]);
18000+ if std::env::var_os("EC_TRACE_MODE").is_some() {
18001+ eprintln!(
18002+ "EC_CIDX mi_row={rmi} mi_col={cmi} ctx={idx_ctx} val={idx} rng={}",
18003+ dec.debug_state().0
18004+ );
18005+ }
17882 if idx == 1 {18006 if idx == 1 {
17883 (8, 8, 1u8)18007 (8, 8, 1u8)
17884 } else {18008 } else {
@@ -19960,30 +20084,47 @@ fn decode_inter_block(
19960 Ok(())20084 Ok(())
19961 }20085 }
19962 20086
19963-/// Decodes one 8x8 leaf of a straddling 16x16 inter-frame block20087+/// Decodes one 8x8 group that an inter frame's `partition_w8` symbol split
19964-/// (lane-av1inter8), mirroring [`crate::tile::write_inter_frame_leaf8`]'s20088+/// into four `BLOCK_4X4` inter blocks (lane-intersub8: `PARTITION_SPLIT`
19965-/// exact symbol order: its own skip flag, intra/inter choice and (when20089+/// below 8x8 -- traced live against the oracle `aomdec`'s own `EC_PART_VAL`,
19966-/// inter) `NEARESTMV`/`NEWMV` chain against this leaf's own 2x2-mi mv-stack20090+/// which reads `bsize=3 value=3` on real inter frames, so the refusal this
19967-/// window, or (when intra) `Y_MODE`, then its own luma and two chroma20091+/// replaces was NOT our own desync).
19968-/// transform blocks through [`TxbSet::Luma8Inter`]/[`TxbSet::Chroma4`],20092+///
19969-/// same as [`decode_leaf8`]'s coefficient layer but with20093+/// The inter counterpart of [`decode_leaf_split4`], and a `BLOCK_4X4`-only
19970-/// motion-compensated prediction instead of intra prediction when inter.20094+/// cut of [`decode_inter_block8`]: at `min(bw, bh) < 8` libaom switches off
19971-/// `outer_at` (in [`SUB`]-grid units) is the enclosing 16x16 slot's20095+/// half the inter syntax, and every one of those is a symbol NOT read here
19972-/// skip/intra-inter context, overridden by `prev_leaf` exactly as20096+/// (`decodemv.c` / `blockd.h`, oracle tree):
19973-/// [`decode_leaf8`] overrides mode context: `Neighbours`' above/left arrays20097+/// * `skip_mode`: `read_skip_mode` returns 0 without a symbol when
19974-/// only resolve to [`SUB`] granularity. Hands back this leaf's own skip flag20098+/// `!is_comp_ref_allowed(bsize)` (`AOMMIN(bw, bh) >= 8`, blockd.h).
19975-/// and intra/inter choice, for the next leaf or the caller's final20099+/// * `comp_mode`: `read_block_reference_mode` returns `SINGLE_REFERENCE` on
19976-/// write-back.20100+/// the same predicate, so a sub-8x8 block is always single-reference.
20101+/// * `interintra`: `is_interintra_allowed_bsize` starts at `BLOCK_8X8`.
20102+/// * `motion_mode` / `obmc`: `motion_mode_allowed` returns
20103+/// `SIMPLE_TRANSLATION` for `block_size_wide < 8 || block_size_high < 8`,
20104+/// and `is_global_mv_block`'s own size term fails, so no warp either.
20105+/// * tx size: `block_signals_txsize(bsize)` is `bsize > BLOCK_4X4`
20106+/// (blockd.h:1027), so a `BLOCK_4X4` reads neither `tx_depth` nor a
20107+/// `txfm_partition` bit even in `TX_MODE_SELECT` -- the transform is
20108+/// `max_txsize_rect_lookup[BLOCK_4X4]` = `TX_4X4`
20109+/// (`decodeframe.c:1164-1177`).
20110+///
20111+/// Chroma is coded ONCE for the whole 8x8 group, on the last sub-block
20112+/// (`is_chroma_reference`: `(mi_row & 1) && (mi_col & 1)` in 4:2:0), as one
20113+/// `TX_4X4` unit per plane -- same rule and same neighbour-context tail as
20114+/// [`decode_leaf_split4`]. Its PREDICTION is the sub8x8 one
20115+/// (`dec_build_inter_predictors`'s `is_sub8x8` branch, `decodeframe.c`; spec
20116+/// 7.11.3.1's `candRow`/`candCol` loop): four 2x2 chroma pieces, each built
20117+/// from its own luma sub-block's reference, motion vector and interpolation
20118+/// filters, never from the last sub-block's mv alone.
19977 #[allow(clippy::too_many_arguments)]20119 #[allow(clippy::too_many_arguments)]
19978-fn decode_inter_block8(20120+fn decode_inter_sub8_split4(
19979 dec: &mut SymbolDecoder,20121 dec: &mut SymbolDecoder,
19980 cdfs: &mut Cdfs,20122 cdfs: &mut Cdfs,
19981 neighbours: &mut Neighbours,20123 neighbours: &mut Neighbours,
19982 grid: &mut MiGrid,20124 grid: &mut MiGrid,
20125+ group_mi: (usize, usize),
19983 mi_cols: u32,20126 mi_cols: u32,
19984 mi_rows: u32,20127 mi_rows: u32,
19985- outer_at: (usize, usize),
19986- leaf_mi: (usize, usize),
19987 y: &mut PlaneBuf,20128 y: &mut PlaneBuf,
19988 u: &mut PlaneBuf,20129 u: &mut PlaneBuf,
19989 v: &mut PlaneBuf,20130 v: &mut PlaneBuf,
@@ -19991,203 +20132,1121 @@ fn decode_inter_block8(
19991 ref_u: &PlaneBuf,20132 ref_u: &PlaneBuf,
19992 ref_v: &PlaneBuf,20133 ref_v: &PlaneBuf,
19993 other_refs: &RefSlots,20134 other_refs: &RefSlots,
20135+ sign_bias_table: &SignBiasTable,
20136+ global_motion: &[ec_av1_syntax::WarpParams; 7],
19994 base_q_idx: u8,20137 base_q_idx: u8,
19995- scan8: &[u16],
19996 scan4: &[u16],20138 scan4: &[u16],
19997 allow_high_precision_mv: bool,20139 allow_high_precision_mv: bool,
19998 force_integer_mv: bool,20140 force_integer_mv: bool,
19999- // lane-gmaffine r1: this frame header's own `global_motion` table (spec
20000- // 5.9.24), indexed `[ref_frame - LAST_FRAME]` -- same table
20001- // [`decode_inter_block`] takes, threaded here so the 8x8 leaf can code
20002- // `GLOBALMV` (`gm_get_motion_vector`), fill its mv stack's missing
20003- // candidates with the gm mv (gm r6's root cause) and build a global
20004- // warp prediction.
20005- global_motion: &[ec_av1_syntax::WarpParams; 7],
20006- // lane-gmaffine r1: this sequence header's own `enable_dual_filter` bit,
20007- // for the leaf's own `read_mb_interp_filter` below.
20008- enable_dual_filter: bool,
20009- // lane-av1comp: see [`decode_inter_block`]'s own doc -- this leaf path
20010- // only ever tracks a coarse `LAST_FRAME`-or-intra neighbour shape (no
20011- // per-leaf `above_ref`/`left_ref` array exists here), so `comp_mode`'s
20012- // context uses that same approximation.
20013- reference_select: bool,
20014- enable_masked_compound: bool,
20015- // lane-sb128 r4: see [`decode_inter_block`]'s own doc -- `BLOCK_8X8` is
20016- // always `is_interintra_allowed_bsize`-eligible, so this leaf's own gate
20017- // drops the `side` check entirely.
20018- enable_interintra_compound: bool,
20019- enable_jnt_comp: bool,
20020- order_hint_bits: u32,
20021- order_hint: u32,
20022- ref_order_hints: [u32; 7],
20023- // lane-av1comp round 14: see [`decode_inter_block`]'s own doc -- this
20024- // leaf has no per-leaf `above_skip_mode`/`left_skip_mode` array either,
20025- // so its `skip_mode` context reuses the same [`SUB`]-grid
20026- // `above_skip_mode[cmi]`/`left_skip_mode[rmi]` the enclosing 16x16 slot
20027- // tracks (mirroring `above_skip`/`left_skip`'s own leaf approximation
20028- // just above).
20029- skip_mode_present: bool,
20030- skip_mode_frame: [u8; 2],
20031- // lane-cdffwd2: this frame header's own `reduced_tx_set` bit -- see
20032- // [`decode_inter_frame_tile_with_cdfs`]'s own doc.
20033- reduced_tx_set: bool,
20034- // lane-motionmode round 3: this frame header's own `is_motion_mode_switchable`/
20035- // `allow_warped_motion` bits (spec 5.11.24's `read_motion_mode`), plus
20036- // the fixed/switchable interp filter kind `obmc_blend`'s own neighbour
20037- // reads need (see [`decode_inter_block`]'s own doc) -- this leaf's own
20038- // prediction is always `Regular` (documented corner-cut, `mc::predict`
20039- // has no filter param), but an OBMC neighbour can be a real 16x16+
20040- // block that DID resolve a switchable filter.
20041 interp_fixed: Option<mc::InterpFilterKind>,20141 interp_fixed: Option<mc::InterpFilterKind>,
20042- switchable_motion_mode: bool,20142+ enable_dual_filter: bool,
20043- allow_warped_motion: bool,
20044- // lane-av1comp: `Some((ref1, comp_group_idx, compound_idx))` only for a
20045- // real `COMPOUND_REFERENCE` leaf, for the caller's own end-of-16x16
20046- // `record_compound_ctx` call -- mirrors [`decode_inter_block`]'s own
20047- // `compound_ctx` local, just handed back instead of applied here (this
20048- // fn's `neighbours` recording happens once for the whole straddling
20049- // 16x16 block, after every leaf).
20050- // lane-screen r2: see [`decode_inter_block`]'s own copy of this param --
20051- // `BLOCK_8X8` (this leaf's fixed size) is always `av1_allow_palette`-
20052- // eligible (`bsize >= BLOCK_8X8`).
20053- allow_screen_content_tools: bool,
20054- // lane-inter8 r1: the leaf's mv stacks used to be built without the
20055- // frame's sign-bias table (`NO_SIGN_BIAS`), while [`decode_inter_block`]
20056- // one level up passed it -- it changes the candidate list and with it
20057- // `new_mv_ctx`/`ref_mv_ctx`, `drl_ctx` and the number of symbols read.
20058- // Measured: an 8x8 compound NEAR_NEWMV leaf desynced against aomdec's
20059- // EC_MODE ladder at exactly this block (mi 4,14 of the mandelbrot
20060- // 8x8-split gate).
20061- sign_bias_table: &SignBiasTable,
20062- // lane-inter8 r2: the frame's temporal mv field (spec 7.10.2.8), which
20063- // [`decode_inter_block`] one level up has always passed and this leaf
20064- // passed `None` for -- a `use_ref_frame_mvs` frame's stack then holds
20065- // fewer candidates here than in the reference decoder, which changes the
20066- // mode contexts AND the number of `drl_mode` bits read (class parsed
20067- // then discarded).
20068 tpl_frame: Option<&TplFrameArgs>,20143 tpl_frame: Option<&TplFrameArgs>,
20069- // lane-scaledref r1: this frame's own coded luma width (spec 7.11.3.3),20144+ reduced_tx_set: bool,
20070- // for the scaled-reference MC this leaf's own single-ref/compound/OBMC
20071- // predictions take when a stored reference was coded at another width
20072- // (`use_superres`) -- mirrors [`decode_inter_block`]'s own param.
20073 frame_width: usize,20145 frame_width: usize,
20074-) -> Result<(bool, bool, bool, Option<(i8, i8, u8, u8)>, [u8; 2], (i8, Option<i8>))> {20146+) -> Result<()> {
20075 const LAST_FRAME: i8 = 1;20147 const LAST_FRAME: i8 = 1;
20076- // lane-gmaffine r2: the leaf's OWN switchable-filter symbols, handed back20148+ const B4: usize = 4;
20077- // so the caller stamps them into `Neighbours` instead of the `[3, 3]`20149+ SUB8_INTER_SPLIT_HITS.with(|c| c.set(c.get() + 1));
20078- // placeholder. `[3, 3]` is the "intra neighbour, no filter" sentinel: an20150+ let (gr, gc) = group_mi;
20079- // OBMC blend that picks such a neighbour up feeds it to20151+ let (gpx, gpy) = (gc * MI, gr * MI);
20080- // `neighbour_filter`, which PANICS on it (`from_switchable_symbol`) --20152+ let (cpx, cpy) = (gpx / 2, gpy / 2);
20081- // that was the warp gate's crash, not an entropy desync. Stays `[3, 3]`20153+ // Per-sub-block state the group's chroma prediction needs (spec
20082- // on the intra and compound paths.20154+ // 7.11.3.1's candRow/candCol loop reads each sub-block's OWN mv/ref/
20083- let mut leaf_filter_syms = [3u8; 2];20155+ // filters), indexed `dr * 2 + dc`.
20084- // lane-gmaffine r1: this leaf's GLOBALMV vector AND the mv stack's20156+ let mut piece: [Option<(i8, (i32, i32), mc::InterpFilterKind, mc::InterpFilterKind)>; 4] =
20085- // missing-candidate fallback both come from the frame's global motion20157+ [None; 4];
20086- // evaluated at THIS block's centre (gm r6's root cause).20158+ let mut first_tx_type = TxType::DctDct;
20087- let gm_table = build_gm_mv_table(20159+ let mut last_skip = true;
20088- global_motion,20160+ for i in 0..4usize {
20089- leaf_mi.0,20161+ let (dr, dc) = (i / 2, i % 2);
20090- leaf_mi.1,20162+ let lmi = (gr + dr, gc + dc);
20091- 2,20163+ if lmi.0 >= mi_rows as usize || lmi.1 >= mi_cols as usize {
20092- 2,20164+ continue;
20093- allow_high_precision_mv,20165+ }
20094- force_integer_mv,20166+ let (rmi, cmi) = lmi;
20095- );20167+ let (px, py) = (cmi * MI, rmi * MI);
20096- /// `Y_MODE`'s size group (`common_data.h`'s `size_group_lookup[BLOCK_8X8]`).20168+ inter_segment_id(dec, cdfs, rmi, cmi, 1, 1, false, true);
20097- const SIZE_GROUP_8: usize = 1;20169+ // No `skip_mode` symbol: `is_comp_ref_allowed(BLOCK_4X4)` is false.
20098-20170+ let skip_ctx = usize::from(neighbours.above_skip[cmi]) + usize::from(neighbours.left_skip[rmi]);
20099- let (px, py) = (leaf_mi.1 * MI, leaf_mi.0 * MI);20171+ let skip = dec.symbol(&mut cdfs.skip[skip_ctx]) == 1;
20100- let (cpx, cpy) = (px / 2, py / 2);20172+ inter_segment_id(dec, cdfs, rmi, cmi, 1, 1, skip, false);
20101- // lane-txselect: whether this leaf's `TxMode::Select` var-tx tree took20173+ maybe_read_cdef_idx(dec, rmi, cmi, skip);
20102- // the one split a `BLOCK_8X8` can take (`read_block_tx_size` below) --20174+ maybe_read_delta_q(dec, cdfs, rmi, cmi, false, skip);
20103- // read back by the luma residual read and the tail's neighbour/loop-filter20175+ maybe_read_delta_lf(dec, cdfs, rmi, cmi, false, skip);
20104- // bookkeeping. Always `false` outside a `TxMode::Select` inter frame.20176+ let (has_above, has_left) = (
20105- let mut split8 = false;20177+ rmi > neighbours.tile_row0_mi,
20106- const SIDE: usize = 8;20178+ cmi > neighbours.tile_col0_mi,
20107- const CHROMA_SIDE: usize = 4;
20108-
20109- let (r, c) = outer_at;
20110- let _ = (r, c);
20111- // lane-inter8 r2: this leaf's OWN mi cell, not the enclosing 16x16's --
20112- // leaf (mi_r, mi_c + 2)'s left neighbour is leaf (mi_r, mi_c), and the
20113- // left column of a 16x16's second leaf ROW is the previous 16x16 block's
20114- // bottom leaf, neither of which a SUB-grid slot can name.
20115- let (rmi, cmi) = leaf_mi;
20116- // lane-inter8 r2: no sibling-leaf override any more -- each leaf stamps
20117- // its own 2x2-mi span into the bands right after it decodes (the caller's
20118- // `record_inter_rect_mi`), so a plain mi read already names the correct
20119- // neighbour, including one belonging to the previous 16x16 block.
20120- let above_skip = neighbours.above_skip[cmi];
20121- let left_skip = neighbours.left_skip[rmi];
20122- let above_inter = neighbours.above_inter[cmi];
20123- let left_inter = neighbours.left_inter[rmi];
20124- let above_ref0 = neighbours.above_ref[cmi];
20125- let above_ref1 = neighbours.above_ref1[cmi];
20126- let left_ref0 = neighbours.left_ref[rmi];
20127- let left_ref1 = neighbours.left_ref1[rmi];
20128- let skip_mode_ctx =
20129- usize::from(neighbours.above_skip_mode[cmi]) + usize::from(neighbours.left_skip_mode[rmi]);
20130- // Same two `inter_segment_id` positions as [`decode_inter_block`]; this
20131- // leaf is always `BLOCK_8X8`, i.e. 2x2 mi.
20132- inter_segment_id(dec, cdfs, leaf_mi.0, leaf_mi.1, 2, 2, false, true);
20133- let skip_mode = skip_mode_present && dec.symbol(&mut cdfs.skip_mode[skip_mode_ctx]) == 1;
20134- if skip_mode {
20135- SKIP_MODE_HITS.with(|c| c.set(c.get() + 1));
20136- }
20137-
20138- let skip_ctx = usize::from(above_skip) + usize::from(left_skip);
20139- let skip = skip_mode || dec.symbol(&mut cdfs.skip[skip_ctx]) == 1;
20140- inter_segment_id(dec, cdfs, leaf_mi.0, leaf_mi.1, 2, 2, skip, false);
20141- maybe_read_cdef_idx(dec, leaf_mi.0, leaf_mi.1, skip);
20142- // Always a `BLOCK_8X8` leaf here, never the whole superblock.
20143- maybe_read_delta_q(dec, cdfs, leaf_mi.0, leaf_mi.1, false, skip);
20144- maybe_read_delta_lf(dec, cdfs, leaf_mi.0, leaf_mi.1, false, skip);
20145-
20146- let (has_above, has_left) = (
20147- leaf_mi.0 > neighbours.tile_row0_mi,
20148- leaf_mi.1 > neighbours.tile_col0_mi,
20149- );
20150- let ii_ctx = intra_inter_ctx(has_above, has_left, above_inter, left_inter);
20151- let is_inter = skip_mode || dec.symbol(&mut cdfs.intra_inter[ii_ctx]) == 1;
20152- // lane-inter8 r1: mirrors the oracle's `EC_MODE` (instrument rung 4,
20153- // `read_inter_block_mode_info`) so an 8x8 leaf's mode-info range ladder
20154- // diffs line for line against a real aomdec.
20155- if std::env::var_os("EC_TRACE_MODE").is_some() {
20156- eprintln!(
20157- "EC_MODE mi_row={} mi_col={} rng={}",
20158- leaf_mi.0,
20159- leaf_mi.1,
20160- dec.debug_state().0
20161 );20179 );
20162- }20180+ let ii_ctx = intra_inter_ctx(
20163-20181+ has_above,
20164- let mode_for_tx;20182+ has_left,
20165- let (luma_grid, u_grid, v_grid);20183+ neighbours.above_inter[cmi],
20166- let mut compound_ctx8: Option<(i8, i8, u8, u8)> = None;20184+ neighbours.left_inter[rmi],
20167- // lane-inter8 r1: this leaf's own resolved references, handed back so the20185+ );
20168- // NEXT leaf of the same 16x16 can use them as its real above/left20186+ let is_inter = dec.symbol(&mut cdfs.intra_inter[ii_ctx]) == 1;
20169- // neighbour (`Neighbours`' arrays only move once per 16x16 block).20187+ if !is_inter {
20170- // `(0, None)` is intra.20188+ return Err(unsupported(
20171- let mut leaf_refs: (i8, Option<i8>) = (0, None);20189+ "an intra 4x4 block inside an inter frame's sub-8x8 split (this decoder codes \
20172- if is_inter {20190+ only inter 4x4 sub-blocks there)",
20173- if reference_select || skip_mode {20191+ ));
20174- // lane-inter8 r1: the REAL neighbour references, not a20192+ }
20175- // `LAST_FRAME`-or-intra stand-in. `av1_get_reference_mode_context`20193+ // Same print point as the oracle's `EC_MODE` (entry of
20176- // and `read_compound_ref_frames`' own contexts both ask whether a20194+ // `read_inter_block_mode_info`, i.e. after skip / is_inter), so the
20177- // neighbour is COMPOUND, so pretending every inter neighbour is20195+ // two range ladders line up element for element.
20178- // single-ref LAST picked the wrong `comp_mode` CDF row -- measured20196+ if std::env::var_os("EC_TRACE_MODE").is_some() {
20179- // as an 8x8 leaf reading single-ref where aomdec read compound20197+ eprintln!(
20180- // NEAR_NEWMV (mi 4,14).20198+ "EC_MODE mi_row={rmi} mi_col={cmi} rng={}",
20181- let above_nbr = has_above.then(|| NeighbourRef {20199+ dec.debug_state().0
20182- is_inter: above_inter,20200+ );
20183- ref0: if above_inter { above_ref0 } else { 0 },20201+ }
20184- ref1: above_ref1,20202+ let ref_frame = read_single_ref(
20185- uni: above_ref1.is_some_and(|r1| is_uni_comp_ref(above_ref0, r1)),20203+ dec,
20186- });20204+ cdfs,
20187- let left_nbr = has_left.then(|| NeighbourRef {20205+ neighbours.above_ref[cmi],
20188- is_inter: left_inter,20206+ neighbours.above_ref1[cmi],
20189- ref0: if left_inter { left_ref0 } else { 0 },20207+ neighbours.left_ref[rmi],
20190- ref1: left_ref1,20208+ neighbours.left_ref1[rmi],
20209+ );
20210+ let (sref_y, sref_u, sref_v) = ref_planes(ref_frame, ref_y, ref_u, ref_v, other_refs)?;
20211+ if mc::scale_factor(sref_y.width, frame_width) != mc::REF_NO_SCALE {
20212+ return Err(unsupported(
20213+ "a sub-8x8 inter block under a scaled reference (superres, unimplemented)",
20214+ ));
20215+ }
20216+ let gm_table = build_gm_mv_table(
20217+ global_motion,
20218+ rmi,
20219+ cmi,
20220+ 1,
20221+ 1,
20222+ allow_high_precision_mv,
20223+ force_integer_mv,
20224+ );
20225+ let tpl = tpl_frame.map(|t| crate::mvstack::TplArgs {
20226+ field: t.field,
20227+ cur_offset_0: crate::motion_field::get_relative_dist(
20228+ t.order_hint_bits,
20229+ t.order_hint,
20230+ t.ref_order_hints[(ref_frame - LAST_FRAME) as usize],
20231+ ),
20232+ allow_high_precision_mv,
20233+ });
20234+ let stack = crate::mvstack::find_mv_stack_with_sign_bias(
20235+ grid,
20236+ rmi,
20237+ cmi,
20238+ 1,
20239+ 1,
20240+ ref_frame,
20241+ mi_cols as usize,
20242+ mi_rows as usize,
20243+ sign_bias_table,
20244+ &gm_table,
20245+ tpl,
20246+ );
20247+ let not_new = dec.symbol(&mut cdfs.new_mv[stack.new_mv_ctx]) == 1;
20248+ let mut is_globalmv = false;
20249+ let (mv, is_new_mv) = if !not_new {
20250+ let mut idx = 0usize;
20251+ while idx < 2 && stack.entries.len() > idx + 1 {
20252+ if dec.symbol(&mut cdfs.drl_mode[stack.drl_ctx[idx]]) == 0 {
20253+ break;
20254+ }
20255+ idx += 1;
20256+ }
20257+ let base_mv = stack.entries.get(idx).map_or(stack.pred_mv, |e| e.mv);
20258+ (
20259+ read_mv(
20260+ dec,
20261+ &mut cdfs.mv_comp,
20262+ &mut cdfs.mv_joint,
20263+ base_mv,
20264+ allow_high_precision_mv,
20265+ force_integer_mv,
20266+ ),
20267+ true,
20268+ )
20269+ } else {
20270+ let not_zero = dec.symbol(&mut cdfs.zero_mv[stack.zero_mv_ctx]) == 1;
20271+ is_globalmv = !not_zero;
20272+ let mv = if !not_zero {
20273+ gm_table[(ref_frame - LAST_FRAME) as usize]
20274+ } else {
20275+ let nearest = dec.symbol(&mut cdfs.ref_mv[stack.ref_mv_ctx]) == 0;
20276+ if nearest {
20277+ stack.nearest_mv
20278+ } else {
20279+ let mut idx = 1usize;
20280+ while idx < 3 && stack.entries.len() > idx + 1 {
20281+ if dec.symbol(&mut cdfs.drl_mode[stack.drl_ctx[idx]]) == 0 {
20282+ break;
20283+ }
20284+ idx += 1;
20285+ }
20286+ stack.entries.get(idx).map_or(stack.near_mv, |e| e.mv)
20287+ }
20288+ };
20289+ (mv, false)
20290+ };
20291+ // Same print point as the oracle's `EC_MODE_MV` (right after
20292+ // `assign_mv`), the second rung of the sub-8x8 range ladder.
20293+ if std::env::var_os("EC_TRACE_MODE").is_some() {
20294+ eprintln!(
20295+ "EC_MODE_MV mi_row={rmi} mi_col={cmi} mv0=({},{}) rng={}",
20296+ mv.0,
20297+ mv.1,
20298+ dec.debug_state().0
20299+ );
20300+ }
20301+ // No `interintra` and no `motion_mode`/`obmc` symbol below 8x8 (see
20302+ // this function's own doc); `read_mb_interp_filter` still runs.
20303+ let gm_ref = &global_motion[(ref_frame - LAST_FRAME) as usize];
20304+ let above_filter_ctx = if neighbours.above_ref[cmi] == ref_frame
20305+ || neighbours.above_ref1[cmi] == Some(ref_frame)
20306+ {
20307+ neighbours.above_filter[cmi]
20308+ } else {
20309+ [3, 3]
20310+ };
20311+ let left_filter_ctx = if neighbours.left_ref[rmi] == ref_frame
20312+ || neighbours.left_ref1[rmi] == Some(ref_frame)
20313+ {
20314+ neighbours.left_filter[rmi]
20315+ } else {
20316+ [3, 3]
20317+ };
20318+ if std::env::var_os("EC_AV1_IFDBG").is_some() {
20319+ eprintln!(
20320+ "IFDBG4 mi=({rmi},{cmi}) ref={ref_frame} above_ref={} above_ref1={:?} \
20321+ above_filt={:?} left_ref={} left_ref1={:?} left_filt={:?}",
20322+ neighbours.above_ref[cmi],
20323+ neighbours.above_ref1[cmi],
20324+ neighbours.above_filter[cmi],
20325+ neighbours.left_ref[rmi],
20326+ neighbours.left_ref1[rmi],
20327+ neighbours.left_filter[rmi],
20328+ );
20329+ }
20330+ let gm_nontrans = is_globalmv && gm_ref.model != ec_av1_syntax::WarpModel::Translation;
20331+ let (h_filter, v_filter, resolved_filter) = resolve_interp_filter(
20332+ dec,
20333+ cdfs,
20334+ interp_fixed,
20335+ enable_dual_filter,
20336+ gm_nontrans,
20337+ above_filter_ctx,
20338+ left_filter_ctx,
20339+ false,
20340+ );
20341+ if std::env::var_os("EC_TRACE_MODE").is_some() {
20342+ eprintln!(
20343+ "EC_MODE_VAL4 mi_row={rmi} mi_col={cmi} newmv={is_new_mv} globalmv={is_globalmv} \
20344+ ref0={ref_frame} mv0=({},{}) stack={} rng={}",
20345+ mv.0,
20346+ mv.1,
20347+ stack.entries.len(),
20348+ dec.debug_state().0
20349+ );
20350+ }
20351+ grid.set(
20352+ rmi,
20353+ cmi,
20354+ MiInfo {
20355+ is_inter: true,
20356+ ref_frame,
20357+ ref_frame1: None,
20358+ mv1: None,
20359+ mv,
20360+ is_new_mv,
20361+ size: 1,
20362+ size_h: 1,
20363+ is_global_mv0: false,
20364+ is_global_mv1: false,
20365+ },
20366+ );
20367+ piece[i] = Some((ref_frame, mv, h_filter, v_filter));
20368+ let mut pred_y = vec![0u16; B4 * B4];
20369+ mc::predict_with_filters(
20370+ &sref_y.data,
20371+ sref_y.width,
20372+ sref_y.true_width,
20373+ sref_y.true_height,
20374+ mv_to_q4(px, mv.1, true),
20375+ mv_to_q4(py, mv.0, true),
20376+ B4,
20377+ B4,
20378+ h_filter,
20379+ v_filter,
20380+ &mut pred_y,
20381+ );
20382+ // `BLOCK_4X4` never signals a transform size, so the luma unit is the
20383+ // whole block and `get_txb_ctx` takes its `plane_bsize ==
20384+ // txsize_to_bsize[tx_size]` branch (`txb_skip_ctx = 0`, which
20385+ // `read_inter_plane`'s `plane_idx == 0` arm already assumes).
20386+ if skip {
20387+ y.reconstruct_mc(px, py, B4, &pred_y, &vec![0i32; B4 * B4]);
20388+ neighbours.record_mi_luma_rect(lmi, B4, B4, &vec![0i32; B4 * B4]);
20389+ } else {
20390+ let around = neighbours.around_mi(lmi, B4);
20391+ let (luma_grid, tx_type) = read_inter_plane(
20392+ dec,
20393+ cdfs,
20394+ if reduced_tx_set {
20395+ TxbSet::Luma4Inter
20396+ } else {
20397+ TxbSet::Luma4InterSet1
20398+ },
20399+ scan4,
20400+ 0,
20401+ around[0],
20402+ 0,
20403+ y,
20404+ px,
20405+ py,
20406+ B4,
20407+ base_q_idx,
20408+ &pred_y,
20409+ None,
20410+ None,
20411+ )?;
20412+ if i == 0 {
20413+ // `av1_get_tx_type`: an inter block's chroma inherits the
20414+ // tx_type of the CO-LOCATED luma position, which for the
20415+ // group's one chroma unit is luma (0, 0) -- the FIRST
20416+ // sub-block, not the last.
20417+ first_tx_type = tx_type;
20418+ }
20419+ neighbours.record_mi_luma_rect(lmi, B4, B4, &luma_grid);
20420+ }
20421+ neighbours.record_mode_mi(rmi, cmi, 1, 1, DC_PRED);
20422+ neighbours.record_inter_rect_mi(lmi, 1, 1, skip, true, ref_frame, resolved_filter, false);
20423+ neighbours.fill_skip_grid_rect(lmi, 1, 1, skip);
20424+ neighbours.fill_lf_grid_rect(lmi, 1, 1, B4 as u8, B4 as u8, ref_frame.max(LAST_FRAME));
20425+ last_skip = skip;
20426+ }
20427+ // Chroma, once for the whole group, on the last sub-block's own `skip`
20428+ // flag -- prediction from all four sub-blocks (2x2 pieces), residual as
20429+ // one TX_4X4 unit per plane.
20430+ let mut pred_u = vec![0u16; B4 * B4];
20431+ let mut pred_v = vec![0u16; B4 * B4];
20432+ for i in 0..4usize {
20433+ let (dr, dc) = (i / 2, i % 2);
20434+ let Some((ref_frame, mv, h_filter, v_filter)) = piece[i] else {
20435+ continue;
20436+ };
20437+ let (_, sref_u, sref_v) = ref_planes(ref_frame, ref_y, ref_u, ref_v, other_refs)?;
20438+ let (ox, oy) = (cpx + dc * 2, cpy + dr * 2);
20439+ for (plane, dst) in [(sref_u, &mut pred_u), (sref_v, &mut pred_v)] {
20440+ let mut buf = vec![0u16; 4];
20441+ mc::predict_with_filters(
20442+ &plane.data,
20443+ plane.width,
20444+ plane.true_width,
20445+ plane.true_height,
20446+ mv_to_q4(ox, mv.1, false),
20447+ mv_to_q4(oy, mv.0, false),
20448+ 2,
20449+ 2,
20450+ h_filter,
20451+ v_filter,
20452+ &mut buf,
20453+ );
20454+ for row in 0..2 {
20455+ for col in 0..2 {
20456+ dst[(dr * 2 + row) * B4 + dc * 2 + col] = buf[row * 2 + col];
20457+ }
20458+ }
20459+ }
20460+ }
20461+ let (u_grid, v_grid) = if last_skip {
20462+ u.reconstruct_mc(cpx, cpy, B4, &pred_u, &vec![0i32; B4 * B4]);
20463+ v.reconstruct_mc(cpx, cpy, B4, &pred_v, &vec![0i32; B4 * B4]);
20464+ (vec![0i32; B4 * B4], vec![0i32; B4 * B4])
20465+ } else {
20466+ let around = neighbours.around_mi(group_mi, 8);
20467+ let ug = read_inter_plane(
20468+ dec, cdfs, TxbSet::Chroma4, scan4, 1, around[1], 0, u, cpx, cpy, B4, base_q_idx,
20469+ &pred_u, Some(first_tx_type), None,
20470+ )?
20471+ .0;
20472+ let vg = read_inter_plane(
20473+ dec, cdfs, TxbSet::Chroma4, scan4, 2, around[2], 0, v, cpx, cpy, B4, base_q_idx,
20474+ &pred_v, Some(first_tx_type), None,
20475+ )?
20476+ .0;
20477+ (ug, vg)
20478+ };
20479+ neighbours.record_uv_mode_mi(gr, gc, 2, 2, DC_PRED);
20480+ // Same two neighbour tails [`decode_leaf_split4`] runs: the partition
20481+ // context of a `BLOCK_4X4` subsize (`partition_context_lookup` bit 0 = 1,
20482+ // reached by `side_mi = 4` here) and the group's chroma coefficient state.
20483+ for cell in 0..2usize {
20484+ neighbours.left_side_mi[gr + cell] = 4;
20485+ neighbours.above_side_mi[gc + cell] = 4;
20486+ }
20487+ let round_up_even = |n: usize| n.div_ceil(2) * 2;
20488+ let bound_h = round_up_even(neighbours.mi_rows);
20489+ let bound_w = round_up_even(neighbours.mi_cols);
20490+ let u_state = neighbour_state(&u_grid);
20491+ let v_state = neighbour_state(&v_grid);
20492+ for cell in 0..2usize {
20493+ if cell < 2usize.min(bound_h.saturating_sub(gr)) {
20494+ neighbours.left[gr + cell][1] = u_state;
20495+ neighbours.left[gr + cell][2] = v_state;
20496+ }
20497+ if cell < 2usize.min(bound_w.saturating_sub(gc)) {
20498+ neighbours.above[gc + cell][1] = u_state;
20499+ neighbours.above[gc + cell][2] = v_state;
20500+ }
20501+ }
20502+ Ok(())
20503+}
20504+
20505+/// Decodes a `PARTITION_HORZ`/`PARTITION_VERT` of one 8x8 INTER block into two
20506+/// `BLOCK_8X4`/`BLOCK_4X8` inter leaves (lane-intersub8 r3) -- the inter twin of
20507+/// [`decode_leaf_rect8`] and the rectangular sibling of
20508+/// [`decode_inter_sub8_split4`], whose element order it follows exactly.
20509+/// Per sub-block, in libaom `decodemv.c` `read_inter_frame_mode_info` order:
20510+///
20511+/// * `segment_id`, `skip`, `cdef`/`delta_q`/`delta_lf`, `intra_inter`;
20512+/// * NO `skip_mode` symbol: `is_comp_ref_allowed(BLOCK_8X4)` is false
20513+/// (`av1_is_comp_ref_allowed` needs both sides >= 8), so
20514+/// `read_skip_mode` returns 0 without reading and `comp_mode` is never read
20515+/// either (`read_ref_frames`' `is_comp_ref_allowed` guard) -- single
20516+/// reference only;
20517+/// * NO `interintra` and NO `motion_mode`/OBMC/warp symbol: every one of those
20518+/// gates needs `block_size_wide >= 8 && block_size_high >= 8`
20519+/// (`is_interintra_allowed_bsize`, `motion_mode_allowed`), and one side is 4;
20520+/// * `read_mb_interp_filter` DOES run for both sub-blocks.
20521+///
20522+/// The shape's own differences from the four-way split:
20523+///
20524+/// * `block_signals_txsize(BLOCK_8X4)` is true (`bsize > BLOCK_4X4`,
20525+/// blockd.h:1027), so a non-skipped sub-block reads ONE `txfm_partition`
20526+/// symbol under `TX_MODE_SELECT` at `max_txsize_rect_lookup[BLOCK_8X4] ==
20527+/// TX_8X4` ([`read_var_tx_size`]); split resolves to two `TX_4X4` units
20528+/// (`sub_tx_size_map[TX_8X4] == TX_4X4`, libaom's early return), no split to
20529+/// the whole-leaf `TX_8X4`;
20530+/// * the luma coefficient set is [`TxbSet::LumaRect8x4Inter`] (the 8x8
20531+/// coefficient class with a 32-position `eob_pt` and the INTER `TX_4X4`
20532+/// `tx_type` row) for the whole-leaf unit, and the square
20533+/// [`TxbSet::Luma4Inter`] for a split `TX_4X4` unit;
20534+/// * chroma is coded ONCE, on the sub-block that is the chroma reference:
20535+/// `is_chroma_reference` (`av1_common_int.h`) is
20536+/// `((mi_row & 1) || !(bh4 & 1) || !ss_y) && ((mi_col & 1) || !(bw4 & 1) ||
20537+/// !ss_x)`, i.e. under 4:2:0 the BOTTOM 8x4 (`bh4 == 1`, odd) and the RIGHT
20538+/// 4x8 (`bw4 == 1`) -- always the second sub-block here;
20539+/// * that chroma unit's prediction is the sub8x8 one (`reconinter.c`
20540+/// `build_inter_predictors_sub8x8`: `row_start = -(block_size_high == 4 &&
20541+/// ss_y)`, `col_start = -(block_size_wide == 4 && ss_x)`), two 4x2 (HORZ) or
20542+/// 2x4 (VERT) chroma pieces, each from its OWN sub-block's reference, mv and
20543+/// interpolation filters.
20544+#[allow(clippy::too_many_arguments)]
20545+fn decode_inter_sub8_rect2(
20546+ dec: &mut SymbolDecoder,
20547+ cdfs: &mut Cdfs,
20548+ neighbours: &mut Neighbours,
20549+ grid: &mut MiGrid,
20550+ group_mi: (usize, usize),
20551+ vert: bool,
20552+ mi_cols: u32,
20553+ mi_rows: u32,
20554+ y: &mut PlaneBuf,
20555+ u: &mut PlaneBuf,
20556+ v: &mut PlaneBuf,
20557+ ref_y: &PlaneBuf,
20558+ ref_u: &PlaneBuf,
20559+ ref_v: &PlaneBuf,
20560+ other_refs: &RefSlots,
20561+ sign_bias_table: &SignBiasTable,
20562+ global_motion: &[ec_av1_syntax::WarpParams; 7],
20563+ base_q_idx: u8,
20564+ scan4: &[u16],
20565+ allow_high_precision_mv: bool,
20566+ force_integer_mv: bool,
20567+ interp_fixed: Option<mc::InterpFilterKind>,
20568+ enable_dual_filter: bool,
20569+ tpl_frame: Option<&TplFrameArgs>,
20570+ reduced_tx_set: bool,
20571+ frame_width: usize,
20572+) -> Result<()> {
20573+ const LAST_FRAME: i8 = 1;
20574+ // The 8x8 group's own square stride: both leaves' prediction buffers are
20575+ // laid out at it, as every other rect inter unit here is.
20576+ const SIDE: usize = 8;
20577+ let (bw, bh) = if vert { (4usize, 8usize) } else { (8usize, 4usize) };
20578+ let (w_mi, h_mi) = (bw / MI, bh / MI);
20579+ SUB8_INTER_RECT_HITS.with(|c| {
20580+ let mut h = c.get();
20581+ h[usize::from(vert)] += 1;
20582+ c.set(h);
20583+ });
20584+ let (gr, gc) = group_mi;
20585+ let (gpx, gpy) = (gc * MI, gr * MI);
20586+ let (cpx, cpy) = (gpx / 2, gpy / 2);
20587+ // Per-sub-block state the group's one chroma unit predicts from.
20588+ let mut piece: [Option<(i8, (i32, i32), mc::InterpFilterKind, mc::InterpFilterKind)>; 2] =
20589+ [None; 2];
20590+ let mut first_tx_type = TxType::DctDct;
20591+ let mut last_skip = true;
20592+ for i in 0..2usize {
20593+ let lmi = if vert { (gr, gc + i) } else { (gr + i, gc) };
20594+ if lmi.0 >= mi_rows as usize || lmi.1 >= mi_cols as usize {
20595+ continue;
20596+ }
20597+ let (rmi, cmi) = lmi;
20598+ let (px, py) = (cmi * MI, rmi * MI);
20599+ inter_segment_id(dec, cdfs, rmi, cmi, w_mi, h_mi, false, true);
20600+ let skip_ctx =
20601+ usize::from(neighbours.above_skip[cmi]) + usize::from(neighbours.left_skip[rmi]);
20602+ let skip = dec.symbol(&mut cdfs.skip[skip_ctx]) == 1;
20603+ inter_segment_id(dec, cdfs, rmi, cmi, w_mi, h_mi, skip, false);
20604+ maybe_read_cdef_idx(dec, rmi, cmi, skip);
20605+ maybe_read_delta_q(dec, cdfs, rmi, cmi, false, skip);
20606+ maybe_read_delta_lf(dec, cdfs, rmi, cmi, false, skip);
20607+ let (has_above, has_left) = (
20608+ rmi > neighbours.tile_row0_mi,
20609+ cmi > neighbours.tile_col0_mi,
20610+ );
20611+ let ii_ctx = intra_inter_ctx(
20612+ has_above,
20613+ has_left,
20614+ neighbours.above_inter[cmi],
20615+ neighbours.left_inter[rmi],
20616+ );
20617+ let is_inter = dec.symbol(&mut cdfs.intra_inter[ii_ctx]) == 1;
20618+ if !is_inter {
20619+ return Err(unsupported(
20620+ "an intra 8x4/4x8 block inside an inter frame's sub-8x8 HORZ/VERT partition \
20621+ (this decoder codes only inter sub-blocks there)",
20622+ ));
20623+ }
20624+ if std::env::var_os("EC_TRACE_MODE").is_some() {
20625+ eprintln!(
20626+ "EC_MODE mi_row={rmi} mi_col={cmi} rng={}",
20627+ dec.debug_state().0
20628+ );
20629+ }
20630+ let ref_frame = read_single_ref(
20631+ dec,
20632+ cdfs,
20633+ neighbours.above_ref[cmi],
20634+ neighbours.above_ref1[cmi],
20635+ neighbours.left_ref[rmi],
20636+ neighbours.left_ref1[rmi],
20637+ );
20638+ let (sref_y, _, _) = ref_planes(ref_frame, ref_y, ref_u, ref_v, other_refs)?;
20639+ if mc::scale_factor(sref_y.width, frame_width) != mc::REF_NO_SCALE {
20640+ return Err(unsupported(
20641+ "a sub-8x8 inter block under a scaled reference (superres, unimplemented)",
20642+ ));
20643+ }
20644+ let gm_table = build_gm_mv_table(
20645+ global_motion,
20646+ rmi,
20647+ cmi,
20648+ w_mi,
20649+ h_mi,
20650+ allow_high_precision_mv,
20651+ force_integer_mv,
20652+ );
20653+ let tpl = tpl_frame.map(|t| crate::mvstack::TplArgs {
20654+ field: t.field,
20655+ cur_offset_0: crate::motion_field::get_relative_dist(
20656+ t.order_hint_bits,
20657+ t.order_hint,
20658+ t.ref_order_hints[(ref_frame - LAST_FRAME) as usize],
20659+ ),
20660+ allow_high_precision_mv,
20661+ });
20662+ let stack = crate::mvstack::find_mv_stack_with_sign_bias(
20663+ grid,
20664+ rmi,
20665+ cmi,
20666+ w_mi,
20667+ h_mi,
20668+ ref_frame,
20669+ mi_cols as usize,
20670+ mi_rows as usize,
20671+ sign_bias_table,
20672+ &gm_table,
20673+ tpl,
20674+ );
20675+ let not_new = dec.symbol(&mut cdfs.new_mv[stack.new_mv_ctx]) == 1;
20676+ let mut is_globalmv = false;
20677+ let (mv, is_new_mv) = if !not_new {
20678+ let mut idx = 0usize;
20679+ while idx < 2 && stack.entries.len() > idx + 1 {
20680+ if dec.symbol(&mut cdfs.drl_mode[stack.drl_ctx[idx]]) == 0 {
20681+ break;
20682+ }
20683+ idx += 1;
20684+ }
20685+ let base_mv = stack.entries.get(idx).map_or(stack.pred_mv, |e| e.mv);
20686+ (
20687+ read_mv(
20688+ dec,
20689+ &mut cdfs.mv_comp,
20690+ &mut cdfs.mv_joint,
20691+ base_mv,
20692+ allow_high_precision_mv,
20693+ force_integer_mv,
20694+ ),
20695+ true,
20696+ )
20697+ } else {
20698+ let not_zero = dec.symbol(&mut cdfs.zero_mv[stack.zero_mv_ctx]) == 1;
20699+ is_globalmv = !not_zero;
20700+ let mv = if !not_zero {
20701+ gm_table[(ref_frame - LAST_FRAME) as usize]
20702+ } else {
20703+ let nearest = dec.symbol(&mut cdfs.ref_mv[stack.ref_mv_ctx]) == 0;
20704+ if nearest {
20705+ stack.nearest_mv
20706+ } else {
20707+ let mut idx = 1usize;
20708+ while idx < 3 && stack.entries.len() > idx + 1 {
20709+ if dec.symbol(&mut cdfs.drl_mode[stack.drl_ctx[idx]]) == 0 {
20710+ break;
20711+ }
20712+ idx += 1;
20713+ }
20714+ stack.entries.get(idx).map_or(stack.near_mv, |e| e.mv)
20715+ }
20716+ };
20717+ (mv, false)
20718+ };
20719+ if std::env::var_os("EC_TRACE_MODE").is_some() {
20720+ eprintln!(
20721+ "EC_MODE_MV mi_row={rmi} mi_col={cmi} mv0=({},{}) rng={}",
20722+ mv.0,
20723+ mv.1,
20724+ dec.debug_state().0
20725+ );
20726+ }
20727+ let gm_ref = &global_motion[(ref_frame - LAST_FRAME) as usize];
20728+ let above_filter_ctx = if neighbours.above_ref[cmi] == ref_frame
20729+ || neighbours.above_ref1[cmi] == Some(ref_frame)
20730+ {
20731+ neighbours.above_filter[cmi]
20732+ } else {
20733+ [3, 3]
20734+ };
20735+ let left_filter_ctx = if neighbours.left_ref[rmi] == ref_frame
20736+ || neighbours.left_ref1[rmi] == Some(ref_frame)
20737+ {
20738+ neighbours.left_filter[rmi]
20739+ } else {
20740+ [3, 3]
20741+ };
20742+ let gm_nontrans = is_globalmv && gm_ref.model != ec_av1_syntax::WarpModel::Translation;
20743+ let (h_filter, v_filter, resolved_filter) = resolve_interp_filter(
20744+ dec,
20745+ cdfs,
20746+ interp_fixed,
20747+ enable_dual_filter,
20748+ gm_nontrans,
20749+ above_filter_ctx,
20750+ left_filter_ctx,
20751+ false,
20752+ );
20753+ // `read_block_tx_size` (libaom `decodeframe.c`): unlike a `BLOCK_4X4`,
20754+ // this shape signals its transform size. A non-skipped inter block
20755+ // walks the var-tx tree from `max_txsize_rect_lookup[BLOCK_8X4]`; a
20756+ // skipped one codes nothing and records its BLOCK size in both txfm
20757+ // contexts (`set_txfm_ctxs`' `skip_inter` arm).
20758+ let mut leaves: Vec<(usize, usize, usize, usize)> = Vec::new();
20759+ if TX_SELECT_INTER.with(std::cell::Cell::get) && !skip {
20760+ let max_w_mi = w_mi.min((mi_cols as usize).saturating_sub(cmi));
20761+ let max_h_mi = h_mi.min((mi_rows as usize).saturating_sub(rmi));
20762+ read_var_tx_size(
20763+ dec,
20764+ cdfs,
20765+ neighbours,
20766+ lmi,
20767+ SIDE,
20768+ (max_w_mi, max_h_mi),
20769+ (bw, bh),
20770+ 0,
20771+ 0,
20772+ 0,
20773+ &mut leaves,
20774+ );
20775+ } else {
20776+ leaves.push((0, 0, bw, bh));
20777+ set_txfm_ctxs(neighbours, lmi, bw.max(bh), w_mi, h_mi, skip);
20778+ }
20779+ if std::env::var_os("EC_TRACE_MODE").is_some() {
20780+ eprintln!(
20781+ "EC_MODE_VALR mi_row={rmi} mi_col={cmi} newmv={is_new_mv} globalmv={is_globalmv} \
20782+ ref0={ref_frame} mv0=({},{}) stack={} leaves={} rng={}",
20783+ mv.0,
20784+ mv.1,
20785+ stack.entries.len(),
20786+ leaves.len(),
20787+ dec.debug_state().0
20788+ );
20789+ }
20790+ grid_stamp_rect(grid, rmi, cmi, w_mi, h_mi, ref_frame, mv, is_new_mv);
20791+ piece[i] = Some((ref_frame, mv, h_filter, v_filter));
20792+ // Prediction over the leaf's true footprint, laid out at the group's
20793+ // square stride (what `reconstruct_mc_rect` and `read_inter_plane_rect`
20794+ // index with).
20795+ let mut pred_y = vec![0u16; SIDE * SIDE];
20796+ {
20797+ let mut dense = vec![0u16; bw * bh];
20798+ mc::predict_with_filters(
20799+ &sref_y.data,
20800+ sref_y.width,
20801+ sref_y.true_width,
20802+ sref_y.true_height,
20803+ mv_to_q4(px, mv.1, true),
20804+ mv_to_q4(py, mv.0, true),
20805+ bw,
20806+ bh,
20807+ h_filter,
20808+ v_filter,
20809+ &mut dense,
20810+ );
20811+ for row in 0..bh {
20812+ pred_y[row * SIDE..][..bw].copy_from_slice(&dense[row * bw..][..bw]);
20813+ }
20814+ }
20815+ if skip {
20816+ y.reconstruct_mc_rect(px, py, SIDE, bw, bh, &pred_y, &vec![0i32; SIDE * SIDE]);
20817+ neighbours.record_mi_luma_rect(lmi, bw, bh, &vec![0i32; bw * bh]);
20818+ neighbours.fill_lf_grid_rect(lmi, w_mi, h_mi, bw as u8, bh as u8, ref_frame.max(LAST_FRAME));
20819+ } else {
20820+ let (mut last_tw, mut last_th) = (bw, bh);
20821+ for (idx, &(row, col, tw, th)) in leaves.iter().enumerate() {
20822+ let tu_mi = (rmi + row, cmi + col);
20823+ let (tu_px, tu_py) = (px + col * MI, py + row * MI);
20824+ let (tu_grid, tu_tx_type) = if tw == th {
20825+ // A split `TX_4X4` unit: square reader, its own
20826+ // `get_txb_ctx_general` neighbour context (the unit is
20827+ // smaller than its plane block, so the lone-TU 0 does not
20828+ // apply).
20829+ let mut tu_pred = Vec::with_capacity(tw * th);
20830+ for rr in 0..th {
20831+ let start = (row * MI + rr) * SIDE + col * MI;
20832+ tu_pred.extend_from_slice(&pred_y[start..start + tw]);
20833+ }
20834+ let tu_skip_ctx = neighbours.luma_skip_ctx_rect(tu_mi, tw / MI, th / MI);
20835+ read_inter_plane(
20836+ dec,
20837+ cdfs,
20838+ if reduced_tx_set {
20839+ TxbSet::Luma4Inter
20840+ } else {
20841+ TxbSet::Luma4InterSet1
20842+ },
20843+ scan4,
20844+ 0,
20845+ neighbours.around_mi(tu_mi, tw)[0],
20846+ 0,
20847+ y,
20848+ tu_px,
20849+ tu_py,
20850+ tw,
20851+ base_q_idx,
20852+ &tu_pred,
20853+ None,
20854+ Some(tu_skip_ctx),
20855+ )?
20856+ } else {
20857+ // The whole leaf as one `TX_8X4`/`TX_4X8` unit: it IS the
20858+ // plane block, so `get_txb_ctx_general` fixes `txb_skip_ctx`
20859+ // at 0 (`luma_skip_ctx: None`).
20860+ let start = row * MI * SIDE + col * MI;
20861+ read_inter_plane_rect(
20862+ dec,
20863+ cdfs,
20864+ if reduced_tx_set {
20865+ TxbSet::LumaRect8x4Inter
20866+ } else {
20867+ TxbSet::LumaRect8x4InterSet1
20868+ },
20869+ (tw, th),
20870+ SIDE,
20871+ 0,
20872+ neighbours.around_mi_rect(tu_mi, tw, th)[0],
20873+ 0,
20874+ y,
20875+ tu_px,
20876+ tu_py,
20877+ &pred_y[start..],
20878+ None,
20879+ None,
20880+ )?
20881+ };
20882+ if idx == 0 {
20883+ // `av1_get_tx_type`: the group's one chroma unit scales
20884+ // back to luma (0, 0), i.e. the FIRST sub-block's first
20885+ // transform unit.
20886+ first_tx_type = tu_tx_type;
20887+ }
20888+ neighbours.record_mi_luma_rect(tu_mi, tw, th, &tu_grid);
20889+ (last_tw, last_th) = (tw, th);
20890+ }
20891+ neighbours.fill_lf_grid_rect(
20892+ lmi,
20893+ w_mi,
20894+ h_mi,
20895+ last_tw as u8,
20896+ last_th as u8,
20897+ ref_frame.max(LAST_FRAME),
20898+ );
20899+ }
20900+ neighbours.record_mode_mi(rmi, cmi, w_mi, h_mi, DC_PRED);
20901+ neighbours.record_inter_rect_mi(lmi, w_mi, h_mi, skip, true, ref_frame, resolved_filter, false);
20902+ neighbours.fill_skip_grid_rect(lmi, w_mi, h_mi, skip);
20903+ last_skip = skip;
20904+ }
20905+ // The group's single 4x4 chroma unit per plane, on the chroma-reference
20906+ // (second) sub-block's own skip flag.
20907+ const B4: usize = 4;
20908+ let mut pred_u = vec![0u16; B4 * B4];
20909+ let mut pred_v = vec![0u16; B4 * B4];
20910+ let (piece_w, piece_h) = if vert { (2usize, 4usize) } else { (4usize, 2usize) };
20911+ for i in 0..2usize {
20912+ let Some((ref_frame, mv, h_filter, v_filter)) = piece[i] else {
20913+ continue;
20914+ };
20915+ let (_, sref_u, sref_v) = ref_planes(ref_frame, ref_y, ref_u, ref_v, other_refs)?;
20916+ let (ox, oy) = if vert {
20917+ (cpx + i * piece_w, cpy)
20918+ } else {
20919+ (cpx, cpy + i * piece_h)
20920+ };
20921+ let (dc, dr) = if vert { (i * piece_w, 0) } else { (0, i * piece_h) };
20922+ for (plane, dst) in [(sref_u, &mut pred_u), (sref_v, &mut pred_v)] {
20923+ let mut buf = vec![0u16; piece_w * piece_h];
20924+ mc::predict_with_filters(
20925+ &plane.data,
20926+ plane.width,
20927+ plane.true_width,
20928+ plane.true_height,
20929+ mv_to_q4(ox, mv.1, false),
20930+ mv_to_q4(oy, mv.0, false),
20931+ piece_w,
20932+ piece_h,
20933+ h_filter,
20934+ v_filter,
20935+ &mut buf,
20936+ );
20937+ for row in 0..piece_h {
20938+ for col in 0..piece_w {
20939+ dst[(dr + row) * B4 + dc + col] = buf[row * piece_w + col];
20940+ }
20941+ }
20942+ }
20943+ }
20944+ let (u_grid, v_grid) = if last_skip {
20945+ u.reconstruct_mc(cpx, cpy, B4, &pred_u, &vec![0i32; B4 * B4]);
20946+ v.reconstruct_mc(cpx, cpy, B4, &pred_v, &vec![0i32; B4 * B4]);
20947+ (vec![0i32; B4 * B4], vec![0i32; B4 * B4])
20948+ } else {
20949+ let around = neighbours.around_mi(group_mi, 8);
20950+ let ug = read_inter_plane(
20951+ dec, cdfs, TxbSet::Chroma4, scan4, 1, around[1], 0, u, cpx, cpy, B4, base_q_idx,
20952+ &pred_u, Some(first_tx_type), None,
20953+ )?
20954+ .0;
20955+ let vg = read_inter_plane(
20956+ dec, cdfs, TxbSet::Chroma4, scan4, 2, around[2], 0, v, cpx, cpy, B4, base_q_idx,
20957+ &pred_v, Some(first_tx_type), None,
20958+ )?
20959+ .0;
20960+ (ug, vg)
20961+ };
20962+ neighbours.record_uv_mode_mi(gr, gc, 2, 2, DC_PRED);
20963+ // `update_partition_context` writes `partition_context_lookup[subsize]`
20964+ // over the whole 8x8 span -- BLOCK_4X8's width above and height left, the
20965+ // same values [`decode_leaf_rect8`] writes for the intra shape.
20966+ for cell in 0..2usize {
20967+ neighbours.above_side_mi[gc + cell] = bw;
20968+ neighbours.left_side_mi[gr + cell] = bh;
20969+ }
20970+ let round_up_even = |n: usize| n.div_ceil(2) * 2;
20971+ let bound_h = round_up_even(neighbours.mi_rows);
20972+ let bound_w = round_up_even(neighbours.mi_cols);
20973+ let u_state = neighbour_state(&u_grid);
20974+ let v_state = neighbour_state(&v_grid);
20975+ for cell in 0..2usize {
20976+ if cell < 2usize.min(bound_h.saturating_sub(gr)) {
20977+ neighbours.left[gr + cell][1] = u_state;
20978+ neighbours.left[gr + cell][2] = v_state;
20979+ }
20980+ if cell < 2usize.min(bound_w.saturating_sub(gc)) {
20981+ neighbours.above[gc + cell][1] = u_state;
20982+ neighbours.above[gc + cell][2] = v_state;
20983+ }
20984+ }
20985+ Ok(())
20986+}
20987+
20988+/// Stamps one sub-8x8 inter leaf into every mi cell of its true `w_mi`x`h_mi`
20989+/// footprint (class: a rect block's grid span is its own, never a square guess).
20990+fn grid_stamp_rect(
20991+ grid: &mut MiGrid,
20992+ mi_row: usize,
20993+ mi_col: usize,
20994+ w_mi: usize,
20995+ h_mi: usize,
20996+ ref_frame: i8,
20997+ mv: (i32, i32),
20998+ is_new_mv: bool,
20999+) {
21000+ for dr in 0..h_mi {
21001+ for dc in 0..w_mi {
21002+ grid.set(
21003+ mi_row + dr,
21004+ mi_col + dc,
21005+ MiInfo {
21006+ is_inter: true,
21007+ ref_frame,
21008+ ref_frame1: None,
21009+ mv1: None,
21010+ mv,
21011+ is_new_mv,
21012+ size: w_mi,
21013+ size_h: h_mi,
21014+ is_global_mv0: false,
21015+ is_global_mv1: false,
21016+ },
21017+ );
21018+ }
21019+ }
21020+}
21021+
21022+/// Decodes one 8x8 leaf of a straddling 16x16 inter-frame block
21023+/// (lane-av1inter8), mirroring [`crate::tile::write_inter_frame_leaf8`]'s
21024+/// exact symbol order: its own skip flag, intra/inter choice and (when
21025+/// inter) `NEARESTMV`/`NEWMV` chain against this leaf's own 2x2-mi mv-stack
21026+/// window, or (when intra) `Y_MODE`, then its own luma and two chroma
21027+/// transform blocks through [`TxbSet::Luma8Inter`]/[`TxbSet::Chroma4`],
21028+/// same as [`decode_leaf8`]'s coefficient layer but with
21029+/// motion-compensated prediction instead of intra prediction when inter.
21030+/// `outer_at` (in [`SUB`]-grid units) is the enclosing 16x16 slot's
21031+/// skip/intra-inter context, overridden by `prev_leaf` exactly as
21032+/// [`decode_leaf8`] overrides mode context: `Neighbours`' above/left arrays
21033+/// only resolve to [`SUB`] granularity. Hands back this leaf's own skip flag
21034+/// and intra/inter choice, for the next leaf or the caller's final
21035+/// write-back.
21036+#[allow(clippy::too_many_arguments)]
21037+fn decode_inter_block8(
21038+ dec: &mut SymbolDecoder,
21039+ cdfs: &mut Cdfs,
21040+ neighbours: &mut Neighbours,
21041+ grid: &mut MiGrid,
21042+ mi_cols: u32,
21043+ mi_rows: u32,
21044+ outer_at: (usize, usize),
21045+ leaf_mi: (usize, usize),
21046+ y: &mut PlaneBuf,
21047+ u: &mut PlaneBuf,
21048+ v: &mut PlaneBuf,
21049+ ref_y: &PlaneBuf,
21050+ ref_u: &PlaneBuf,
21051+ ref_v: &PlaneBuf,
21052+ other_refs: &RefSlots,
21053+ base_q_idx: u8,
21054+ scan8: &[u16],
21055+ scan4: &[u16],
21056+ allow_high_precision_mv: bool,
21057+ force_integer_mv: bool,
21058+ // lane-gmaffine r1: this frame header's own `global_motion` table (spec
21059+ // 5.9.24), indexed `[ref_frame - LAST_FRAME]` -- same table
21060+ // [`decode_inter_block`] takes, threaded here so the 8x8 leaf can code
21061+ // `GLOBALMV` (`gm_get_motion_vector`), fill its mv stack's missing
21062+ // candidates with the gm mv (gm r6's root cause) and build a global
21063+ // warp prediction.
21064+ global_motion: &[ec_av1_syntax::WarpParams; 7],
21065+ // lane-gmaffine r1: this sequence header's own `enable_dual_filter` bit,
21066+ // for the leaf's own `read_mb_interp_filter` below.
21067+ enable_dual_filter: bool,
21068+ // lane-av1comp: see [`decode_inter_block`]'s own doc -- this leaf path
21069+ // only ever tracks a coarse `LAST_FRAME`-or-intra neighbour shape (no
21070+ // per-leaf `above_ref`/`left_ref` array exists here), so `comp_mode`'s
21071+ // context uses that same approximation.
21072+ reference_select: bool,
21073+ enable_masked_compound: bool,
21074+ // lane-sb128 r4: see [`decode_inter_block`]'s own doc -- `BLOCK_8X8` is
21075+ // always `is_interintra_allowed_bsize`-eligible, so this leaf's own gate
21076+ // drops the `side` check entirely.
21077+ enable_interintra_compound: bool,
21078+ enable_jnt_comp: bool,
21079+ order_hint_bits: u32,
21080+ order_hint: u32,
21081+ ref_order_hints: [u32; 7],
21082+ // lane-av1comp round 14: see [`decode_inter_block`]'s own doc -- this
21083+ // leaf has no per-leaf `above_skip_mode`/`left_skip_mode` array either,
21084+ // so its `skip_mode` context reuses the same [`SUB`]-grid
21085+ // `above_skip_mode[cmi]`/`left_skip_mode[rmi]` the enclosing 16x16 slot
21086+ // tracks (mirroring `above_skip`/`left_skip`'s own leaf approximation
21087+ // just above).
21088+ skip_mode_present: bool,
21089+ skip_mode_frame: [u8; 2],
21090+ // lane-cdffwd2: this frame header's own `reduced_tx_set` bit -- see
21091+ // [`decode_inter_frame_tile_with_cdfs`]'s own doc.
21092+ reduced_tx_set: bool,
21093+ // lane-motionmode round 3: this frame header's own `is_motion_mode_switchable`/
21094+ // `allow_warped_motion` bits (spec 5.11.24's `read_motion_mode`), plus
21095+ // the fixed/switchable interp filter kind `obmc_blend`'s own neighbour
21096+ // reads need (see [`decode_inter_block`]'s own doc) -- this leaf's own
21097+ // prediction is always `Regular` (documented corner-cut, `mc::predict`
21098+ // has no filter param), but an OBMC neighbour can be a real 16x16+
21099+ // block that DID resolve a switchable filter.
21100+ interp_fixed: Option<mc::InterpFilterKind>,
21101+ switchable_motion_mode: bool,
21102+ allow_warped_motion: bool,
21103+ // lane-av1comp: `Some((ref1, comp_group_idx, compound_idx))` only for a
21104+ // real `COMPOUND_REFERENCE` leaf, for the caller's own end-of-16x16
21105+ // `record_compound_ctx` call -- mirrors [`decode_inter_block`]'s own
21106+ // `compound_ctx` local, just handed back instead of applied here (this
21107+ // fn's `neighbours` recording happens once for the whole straddling
21108+ // 16x16 block, after every leaf).
21109+ // lane-screen r2: see [`decode_inter_block`]'s own copy of this param --
21110+ // `BLOCK_8X8` (this leaf's fixed size) is always `av1_allow_palette`-
21111+ // eligible (`bsize >= BLOCK_8X8`).
21112+ allow_screen_content_tools: bool,
21113+ // lane-inter8 r1: the leaf's mv stacks used to be built without the
21114+ // frame's sign-bias table (`NO_SIGN_BIAS`), while [`decode_inter_block`]
21115+ // one level up passed it -- it changes the candidate list and with it
21116+ // `new_mv_ctx`/`ref_mv_ctx`, `drl_ctx` and the number of symbols read.
21117+ // Measured: an 8x8 compound NEAR_NEWMV leaf desynced against aomdec's
21118+ // EC_MODE ladder at exactly this block (mi 4,14 of the mandelbrot
21119+ // 8x8-split gate).
21120+ sign_bias_table: &SignBiasTable,
21121+ // lane-inter8 r2: the frame's temporal mv field (spec 7.10.2.8), which
21122+ // [`decode_inter_block`] one level up has always passed and this leaf
21123+ // passed `None` for -- a `use_ref_frame_mvs` frame's stack then holds
21124+ // fewer candidates here than in the reference decoder, which changes the
21125+ // mode contexts AND the number of `drl_mode` bits read (class parsed
21126+ // then discarded).
21127+ tpl_frame: Option<&TplFrameArgs>,
21128+ // lane-scaledref r1: this frame's own coded luma width (spec 7.11.3.3),
21129+ // for the scaled-reference MC this leaf's own single-ref/compound/OBMC
21130+ // predictions take when a stored reference was coded at another width
21131+ // (`use_superres`) -- mirrors [`decode_inter_block`]'s own param.
21132+ frame_width: usize,
21133+) -> Result<(bool, bool, bool, Option<(i8, i8, u8, u8)>, [u8; 2], (i8, Option<i8>))> {
21134+ const LAST_FRAME: i8 = 1;
21135+ // lane-gmaffine r2: the leaf's OWN switchable-filter symbols, handed back
21136+ // so the caller stamps them into `Neighbours` instead of the `[3, 3]`
21137+ // placeholder. `[3, 3]` is the "intra neighbour, no filter" sentinel: an
21138+ // OBMC blend that picks such a neighbour up feeds it to
21139+ // `neighbour_filter`, which PANICS on it (`from_switchable_symbol`) --
21140+ // that was the warp gate's crash, not an entropy desync. Stays `[3, 3]`
21141+ // on the intra and compound paths.
21142+ let mut leaf_filter_syms = [3u8; 2];
21143+ // lane-gmaffine r1: this leaf's GLOBALMV vector AND the mv stack's
21144+ // missing-candidate fallback both come from the frame's global motion
21145+ // evaluated at THIS block's centre (gm r6's root cause).
21146+ let gm_table = build_gm_mv_table(
21147+ global_motion,
21148+ leaf_mi.0,
21149+ leaf_mi.1,
21150+ 2,
21151+ 2,
21152+ allow_high_precision_mv,
21153+ force_integer_mv,
21154+ );
21155+ /// `Y_MODE`'s size group (`common_data.h`'s `size_group_lookup[BLOCK_8X8]`).
21156+ const SIZE_GROUP_8: usize = 1;
21157+
21158+ let (px, py) = (leaf_mi.1 * MI, leaf_mi.0 * MI);
21159+ let (cpx, cpy) = (px / 2, py / 2);
21160+ // lane-txselect: whether this leaf's `TxMode::Select` var-tx tree took
21161+ // the one split a `BLOCK_8X8` can take (`read_block_tx_size` below) --
21162+ // read back by the luma residual read and the tail's neighbour/loop-filter
21163+ // bookkeeping. Always `false` outside a `TxMode::Select` inter frame.
21164+ let mut split8 = false;
21165+ const SIDE: usize = 8;
21166+ const CHROMA_SIDE: usize = 4;
21167+
21168+ let (r, c) = outer_at;
21169+ let _ = (r, c);
21170+ // lane-inter8 r2: this leaf's OWN mi cell, not the enclosing 16x16's --
21171+ // leaf (mi_r, mi_c + 2)'s left neighbour is leaf (mi_r, mi_c), and the
21172+ // left column of a 16x16's second leaf ROW is the previous 16x16 block's
21173+ // bottom leaf, neither of which a SUB-grid slot can name.
21174+ let (rmi, cmi) = leaf_mi;
21175+ // lane-inter8 r2: no sibling-leaf override any more -- each leaf stamps
21176+ // its own 2x2-mi span into the bands right after it decodes (the caller's
21177+ // `record_inter_rect_mi`), so a plain mi read already names the correct
21178+ // neighbour, including one belonging to the previous 16x16 block.
21179+ let above_skip = neighbours.above_skip[cmi];
21180+ let left_skip = neighbours.left_skip[rmi];
21181+ let above_inter = neighbours.above_inter[cmi];
21182+ let left_inter = neighbours.left_inter[rmi];
21183+ let above_ref0 = neighbours.above_ref[cmi];
21184+ let above_ref1 = neighbours.above_ref1[cmi];
21185+ let left_ref0 = neighbours.left_ref[rmi];
21186+ let left_ref1 = neighbours.left_ref1[rmi];
21187+ let skip_mode_ctx =
21188+ usize::from(neighbours.above_skip_mode[cmi]) + usize::from(neighbours.left_skip_mode[rmi]);
21189+ // Same two `inter_segment_id` positions as [`decode_inter_block`]; this
21190+ // leaf is always `BLOCK_8X8`, i.e. 2x2 mi.
21191+ inter_segment_id(dec, cdfs, leaf_mi.0, leaf_mi.1, 2, 2, false, true);
21192+ let skip_mode = skip_mode_present && dec.symbol(&mut cdfs.skip_mode[skip_mode_ctx]) == 1;
21193+ if skip_mode {
21194+ SKIP_MODE_HITS.with(|c| c.set(c.get() + 1));
21195+ }
21196+
21197+ let skip_ctx = usize::from(above_skip) + usize::from(left_skip);
21198+ let skip = skip_mode || dec.symbol(&mut cdfs.skip[skip_ctx]) == 1;
21199+ inter_segment_id(dec, cdfs, leaf_mi.0, leaf_mi.1, 2, 2, skip, false);
21200+ maybe_read_cdef_idx(dec, leaf_mi.0, leaf_mi.1, skip);
21201+ // Always a `BLOCK_8X8` leaf here, never the whole superblock.
21202+ maybe_read_delta_q(dec, cdfs, leaf_mi.0, leaf_mi.1, false, skip);
21203+ maybe_read_delta_lf(dec, cdfs, leaf_mi.0, leaf_mi.1, false, skip);
21204+
21205+ let (has_above, has_left) = (
21206+ leaf_mi.0 > neighbours.tile_row0_mi,
21207+ leaf_mi.1 > neighbours.tile_col0_mi,
21208+ );
21209+ let ii_ctx = intra_inter_ctx(has_above, has_left, above_inter, left_inter);
21210+ let is_inter = skip_mode || dec.symbol(&mut cdfs.intra_inter[ii_ctx]) == 1;
21211+ // lane-inter8 r1: mirrors the oracle's `EC_MODE` (instrument rung 4,
21212+ // `read_inter_block_mode_info`) so an 8x8 leaf's mode-info range ladder
21213+ // diffs line for line against a real aomdec.
21214+ if std::env::var_os("EC_TRACE_MODE").is_some() {
21215+ eprintln!(
21216+ "EC_MODE mi_row={} mi_col={} rng={}",
21217+ leaf_mi.0,
21218+ leaf_mi.1,
21219+ dec.debug_state().0
21220+ );
21221+ }
21222+
21223+ let mode_for_tx;
21224+ let (luma_grid, u_grid, v_grid);
21225+ let mut compound_ctx8: Option<(i8, i8, u8, u8)> = None;
21226+ // lane-inter8 r1: this leaf's own resolved references, handed back so the
21227+ // NEXT leaf of the same 16x16 can use them as its real above/left
21228+ // neighbour (`Neighbours`' arrays only move once per 16x16 block).
21229+ // `(0, None)` is intra.
21230+ let mut leaf_refs: (i8, Option<i8>) = (0, None);
21231+ if is_inter {
21232+ if reference_select || skip_mode {
21233+ // lane-inter8 r1: the REAL neighbour references, not a
21234+ // `LAST_FRAME`-or-intra stand-in. `av1_get_reference_mode_context`
21235+ // and `read_compound_ref_frames`' own contexts both ask whether a
21236+ // neighbour is COMPOUND, so pretending every inter neighbour is
21237+ // single-ref LAST picked the wrong `comp_mode` CDF row -- measured
21238+ // as an 8x8 leaf reading single-ref where aomdec read compound
21239+ // NEAR_NEWMV (mi 4,14).
21240+ let above_nbr = has_above.then(|| NeighbourRef {
21241+ is_inter: above_inter,
21242+ ref0: if above_inter { above_ref0 } else { 0 },
21243+ ref1: above_ref1,
21244+ uni: above_ref1.is_some_and(|r1| is_uni_comp_ref(above_ref0, r1)),
21245+ });
21246+ let left_nbr = has_left.then(|| NeighbourRef {
21247+ is_inter: left_inter,
21248+ ref0: if left_inter { left_ref0 } else { 0 },
21249+ ref1: left_ref1,
20191 uni: left_ref1.is_some_and(|r1| is_uni_comp_ref(left_ref0, r1)),21250 uni: left_ref1.is_some_and(|r1| is_uni_comp_ref(left_ref0, r1)),
20192 });21251 });
20193 if skip_mode || read_comp_mode(dec, cdfs, above_nbr, left_nbr) {21252 if skip_mode || read_comp_mode(dec, cdfs, above_nbr, left_nbr) {
@@ -21601,6 +22660,12 @@ fn decode_inter_block8(
21601 // lane-cdef r1: the fall-through twin of the compound arm's skip-band22660 // lane-cdef r1: the fall-through twin of the compound arm's skip-band
21602 // write above -- `skip` is one flag for the whole 8x8 leaf (read at22661 // write above -- `skip` is one flag for the whole 8x8 leaf (read at
21603 // `decode.rs`'s `skip_ctx` site), `split8` only splits its transform.22662 // `decode.rs`'s `skip_ctx` site), `split8` only splits its transform.
22663+ // lane-intersub8 r5: ... and it counts too. r1 incremented the counter in
22664+ // the COMPOUND early-return arm only, so the gate's assert really read
22665+ // "a COMPOUND 8x8 leaf wrote the band"; once main's inter16ab/r14 routing
22666+ // landed, the 10-bit cq12 arm's leaves come through here instead and the
22667+ // gate failed on an instrumentation gap, with the band written either way.
22668+ INTER8_SKIP_BAND_HITS.with(|c| c.set(c.get() + 1));
21604 neighbours.fill_skip_grid(leaf_mi, 2, skip);22669 neighbours.fill_skip_grid(leaf_mi, 2, skip);
21605 neighbours.fill_lf_grid(22670 neighbours.fill_lf_grid(
21606 leaf_mi,22671 leaf_mi,
@@ -22240,6 +23305,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
22240 let part64 = match (has_cols, has_rows) {23305 let part64 = match (has_cols, has_rows) {
22241 (true, true) => {23306 (true, true) => {
22242 let pre_rng = dec.debug_state().0;23307 let pre_rng = dec.debug_state().0;
23308+ if std::env::var_os("EC_TRACE_PART").is_some() { eprintln!("EC_PART mi_row={} mi_col={} bsize=12 ctx={} rng={}", sb_r as usize * SB_MI as usize, sb_c as usize * SB_MI as usize, sb_ctx, dec.debug_state().0); }
22243 let p = dec.symbol(&mut cdfs.partition_w64[sb_ctx]);23309 let p = dec.symbol(&mut cdfs.partition_w64[sb_ctx]);
22244 if std::env::var_os("EC_AV1_TRACE").is_some() {23310 if std::env::var_os("EC_AV1_TRACE").is_some() {
22245 eprintln!(23311 eprintln!(
@@ -22433,6 +23499,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
22433 dec.debug_state().023499 dec.debug_state().0
22434 );23500 );
22435 }23501 }
23502+ 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); }
22436 let p = dec.symbol(&mut cdfs.partition_w32[ctx32]);23503 let p = dec.symbol(&mut cdfs.partition_w32[ctx32]);
22437 if std::env::var_os("EC_AV1_TRACE").is_some() {23504 if std::env::var_os("EC_AV1_TRACE").is_some() {
22438 eprintln!(23505 eprintln!(
@@ -22553,6 +23620,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
22553 // inter leaves through the very same loop the23620 // inter leaves through the very same loop the
22554 // straddling case has always used.23621 // straddling case has always used.
22555 let part16 = if has_cols16 && has_rows16 {23622 let part16 = if has_cols16 && has_rows16 {
23623+ 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); }
22556 let p = dec.symbol(&mut cdfs.partition_w16[ctx16]);23624 let p = dec.symbol(&mut cdfs.partition_w16[ctx16]);
22557 if std::env::var_os("EC_AV1_TRACE").is_some() {23625 if std::env::var_os("EC_AV1_TRACE").is_some() {
22558 let (rng, _) = dec.debug_state();23626 let (rng, _) = dec.debug_state();
@@ -22864,12 +23932,83 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
22864 for (mr, mc) in leaf_positions {23932 for (mr, mc) in leaf_positions {
22865 let leaf_mi = (mr as usize, mc as usize);23933 let leaf_mi = (mr as usize, mc as usize);
22866 let leaf_ctx = neighbours.partition_ctx_mi(leaf_mi, 8);23934 let leaf_ctx = neighbours.partition_ctx_mi(leaf_mi, 8);
23935+ 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); }
22867 let part8 = dec.symbol(&mut cdfs.partition_w8[leaf_ctx]);23936 let part8 = dec.symbol(&mut cdfs.partition_w8[leaf_ctx]);
22868- if part8 != PARTITION_NONE {23937+ if part8 == PARTITION_SPLIT {
22869- return Err(unsupported(23938+ // lane-intersub8: four BLOCK_4X4 inter
22870- "an inter partition below 8x8 (this decoder codes no inter leaf smaller than 8x8; lane-sub8 scoped to intra)",23939+ // sub-blocks, chroma once per 8x8.
22871- ));23940+ decode_inter_sub8_split4(
23941+ &mut dec,
23942+ &mut cdfs,
23943+ &mut neighbours,
23944+ &mut grid,
23945+ leaf_mi,
23946+ mi_cols,
23947+ mi_rows,
23948+ &mut y,
23949+ &mut u,
23950+ &mut v,
23951+ &ref_y,
23952+ &ref_u,
23953+ &ref_v,
23954+ &ref_slots,
23955+ &sign_bias_table,
23956+ &global_motion,
23957+ base_q_idx,
23958+ &scan4,
23959+ allow_high_precision_mv,
23960+ force_integer_mv,
23961+ interp_fixed,
23962+ enable_dual_filter,
23963+ tpl_frame.as_ref(),
23964+ reduced_tx_set,
23965+ frame_width as usize,
23966+ )?;
23967+ continue;
23968+ }
23969+ if part8 == PARTITION_VERT || part8 == PARTITION_HORZ {
23970+ // lane-intersub8 r3/r4/r5: two
23971+ // BLOCK_8X4 (HORZ) / BLOCK_4X8 (VERT)
23972+ // inter leaves, chroma once per 8x8 on
23973+ // the second of them. HORZ was refused
23974+ // by name through r4 over a |d| <= 2
23975+ // luma band; r5 merged lane-cdef
23976+ // 8c6065e, whose `decode_inter_block8`
23977+ // skip-band write is that band's root
23978+ // cause, and the 56-arm sweep went 3
23979+ // mismatching arms -> 0.
23980+ decode_inter_sub8_rect2(
23981+ &mut dec,
23982+ &mut cdfs,
23983+ &mut neighbours,
23984+ &mut grid,
23985+ leaf_mi,
23986+ part8 == PARTITION_VERT,
23987+ mi_cols,
23988+ mi_rows,
23989+ &mut y,
23990+ &mut u,
23991+ &mut v,
23992+ &ref_y,
23993+ &ref_u,
23994+ &ref_v,
23995+ &ref_slots,
23996+ &sign_bias_table,
23997+ &global_motion,
23998+ base_q_idx,
23999+ &scan4,
24000+ allow_high_precision_mv,
24001+ force_integer_mv,
24002+ interp_fixed,
24003+ enable_dual_filter,
24004+ tpl_frame.as_ref(),
24005+ reduced_tx_set,
24006+ frame_width as usize,
24007+ )?;
24008+ continue;
22872 }24009 }
24010+ // `partition_w8` is a 4-symbol alphabet
24011+ // (NONE/HORZ/VERT/SPLIT), all four handled.
22873 let (24012 let (
22874 skip,24013 skip,
22875 is_inter,24014 is_inter,
crates/ec-av1/src/refusal_inventory.rsmodified+4 -1
@@ -33,8 +33,11 @@ const REFUSALS: &[&str] = &[
33 "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)",33 "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)",
34 "a coded HORZ/VERT strip whose chroma transform has no rect coefficient tables here",34 "a coded HORZ/VERT strip whose chroma transform has no rect coefficient tables here",
35 "a split intra strip whose transform unit is {tx_w}x{tx_h} (no luma coefficient tables for that shape here)",35 "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)",
37 "an OBMC neighbour whose switchable interp filter was never recorded",36 "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)",
38 "a 16x16 block whose true edge cuts through both axes needs a rectangular transform this decoder does not code yet",41 "a 16x16 block whose true edge cuts through both axes needs a rectangular transform this decoder does not code yet",
39 "a 16x16 inter block whose true edge cuts through both axes needs a rectangular transform this decoder does not code yet",42 "a 16x16 inter block whose true edge cuts through both axes needs a rectangular transform this decoder does not code yet",
40 "a 32x32 partition type this decoder does not code (value={part32})",43 "a 32x32 partition type this decoder does not code (value={part32})",
crates/ec-av1/src/stream.rsmodified+252 -0
@@ -8683,6 +8683,258 @@ mod tests {
8683 }8683 }
8684 }8684 }
8685 8685
8686+ /// lane-intersub8: `PARTITION_SPLIT` below 8x8 on an INTER frame -- four
8687+ /// `BLOCK_4X4` inter sub-blocks with one shared 4x4 chroma unit per plane,
8688+ /// predicted the sub8x8 way (2x2 chroma piece per luma sub-block mv,
8689+ /// `dec_build_inter_predictors`' `is_sub8x8` branch). Reality of the shape
8690+ /// was established BEFORE the code (class refusal-from-own-desync): the
8691+ /// oracle `aomdec`'s `EC_TRACE` prints `EC_PART_VAL ... bsize=3 value=3`
8692+ /// on this recipe's inter frames.
8693+ ///
8694+ /// Attempts 0..7 run `--enable-rect-partitions=0`, where aomenc can only
8695+ /// pick SPLIT below 8x8; attempts 8..15 repeat the schedule with rect on,
8696+ /// where it picks HORZ/VERT below 8x8 far more often than SPLIT -- the VERT
8697+ /// arm (two `BLOCK_4X8` inter leaves, `decode_inter_sub8_rect2`) is what the
8698+ /// `rect_fired` assert pins. The HORZ twin decodes but is refused by name
8699+ /// (lane-intersub8 r3: a measured sweep desyncs the block to its right).
8700+ #[test]
8701+ fn a_real_aomenc_inter_sequence_with_a_sub8x8_inter_split_decodes_pixel_exact() {
8702+ const NAME: &str =
8703+ "a_real_aomenc_inter_sequence_with_a_sub8x8_inter_split_decodes_pixel_exact";
8704+ let _gate_lock = lock_gate_counters();
8705+ if !have_ffmpeg() {
8706+ eprintln!("SKIP {NAME}: no ffmpeg");
8707+ return;
8708+ }
8709+ if !have_aomenc() {
8710+ eprintln!("SKIP {NAME}: no aomenc at {}", aomenc_path().display());
8711+ return;
8712+ }
8713+ let (width, height, frame_count) = (192usize, 128usize, 6usize);
8714+ let mut fired = 0u32;
8715+ // lane-intersub8 r3: attempts 8..15 repeat the same schedule with
8716+ // `--enable-rect-partitions=1`, where aomenc picks PARTITION_VERT below
8717+ // 8x8 (two BLOCK_4X8 inter leaves, one shared 4x4 chroma unit predicted
8718+ // from BOTH sub-blocks' mvs). The HORZ twin is still refused by name.
8719+ let mut rect_fired = 0u32;
8720+ // lane-intersub8 r5: the two rect axes counted apart. Attempts 16..23
8721+ // are the same recipe family with the geq source TRANSPOSED (the sine
8722+ // that moves runs along Y, not X): measured over a 56-arm sweep
8723+ // (~/.cache/intersub8-sweep-r5.log, cq {8,12,14,16,20,26,32} x sp
8724+ // {3,6,9,12} x both depths, rect on), aomenc picks PARTITION_HORZ
8725+ // below 8x8 on that source and PARTITION_VERT on the untransposed one
8726+ // -- neither schedule reaches the other axis, so both are needed.
8727+ let (mut horz_fired, mut vert_fired) = (0u32, 0u32);
8728+ // Rect (non-square) masked-compound blocks on attempts that DECODED
8729+ // and were pixel-compared -- never off a refused stream (class
8730+ // counter-from-refused-stream). This is the shape whose
8731+ // `compound_type`/`wedge_idx` CDF row lane-intersub8 r4 fixed.
8732+ let mut rect_masked = 0usize;
8733+ let mut refusals: Vec<String> = Vec::new();
8734+ let mut out_of_scope_mismatch = 0u32;
8735+ for bit_depth in [8u32, 10u32] {
8736+ for attempt in 0..24u32 {
8737+ let rect = if attempt >= 16 { 1 } else { attempt / 8 };
8738+ let rect_arg = format!("--enable-rect-partitions={rect}");
8739+ // lane-intersub8 r2, measured schedule (sweep of cq
8740+ // {8,10,12,14,16,18,20} x sp {3,6,9,12} x both depths,
8741+ // `decode_probe`'s `sub8_inter_split:` counter vs an ffmpeg
8742+ // rawvideo compare): sub-8x8 inter SPLIT groups fire at
8743+ // (8-bit, cq 12, sp 3) = 1 group and (10-bit, cq 12, sp 6) =
8744+ // 3 groups, both pixel-exact. cq 8 and 10 are NOT used: at
8745+ // those quantizers this recipe also carries a CDEF defect of
8746+ // another shape -- three luma samples of |d| = 1 on
8747+ // decode-order frames 3/4, zero sub-8x8 inter split groups,
8748+ // and the identical recipe re-encoded with `--enable-cdef=0`
8749+ // decodes all six frames exact. Deferred to a CDEF lane
8750+ // rather than hidden: cq 16..20 are all exact, so this gate
8751+ // is not selecting quantizers that hide a defect of its own
8752+ // shape.
8753+ // Attempts 16..23: the (cq, sp) pairs the r5 sweep measured
8754+ // as HORZ-firing on the transposed source -- 8-bit
8755+ // (14,3)/(20,3)/(32,9), 10-bit (12,3)/(16,3); the rest of the
8756+ // eight are non-firing neighbours kept so a schedule that
8757+ // stops firing shows up as out-of-scope, not as a silent pass.
8758+ const HORZ_SCHEDULE: [(u32, u32); 8] =
8759+ [(14, 3), (20, 3), (32, 9), (12, 3), (16, 3), (12, 9), (14, 9), (26, 3)];
8760+ let (cq, sp) = if attempt >= 16 {
8761+ HORZ_SCHEDULE[(attempt - 16) as usize]
8762+ } else {
8763+ ([12, 14][(attempt % 2) as usize], 3 + ((attempt % 8) / 2) * 3)
8764+ };
8765+ let duration = frame_count as f64 / 25.0;
8766+ let source = if attempt >= 16 {
8767+ format!(
8768+ "color=c=gray:s={width}x{height}:d={duration}:r=25,format=gray,\
8769+ geq=lum='128+58*sin((Y+N*{sp})/6)+18*sin(X/23)',format=yuv420p"
8770+ )
8771+ } else {
8772+ format!(
8773+ "color=c=gray:s={width}x{height}:d={duration}:r=25,format=gray,\
8774+ geq=lum='128+58*sin((X+N*{sp})/6)+18*sin(Y/23)',format=yuv420p"
8775+ )
8776+ };
8777+ let pix_fmt = if bit_depth == 10 { "yuv420p10le" } else { "yuv420p" };
8778+ let y4m = Command::new("ffmpeg")
8779+ .args([
8780+ "-v", "error", "-f", "lavfi", "-i", &source, "-t", &duration.to_string(),
8781+ "-pix_fmt", pix_fmt, "-strict", "-1", "-f", "yuv4mpegpipe", "-",
8782+ ])
8783+ .stdin(Stdio::null())
8784+ .stdout(Stdio::piped())
8785+ .stderr(Stdio::piped())
8786+ .output()
8787+ .expect("ffmpeg failed to run");
8788+ assert!(
8789+ y4m.status.success(),
8790+ "{NAME}: ffmpeg refused the fixture: {}",
8791+ String::from_utf8_lossy(&y4m.stderr)
8792+ );
8793+ let cq_arg = format!("--cq-level={cq}");
8794+ let depth_arg = format!("--bit-depth={bit_depth}");
8795+ let input_depth_arg = format!("--input-bit-depth={bit_depth}");
8796+ let args: Vec<&str> = vec![
8797+ "--codec=av1", "--passes=1", "--end-usage=q", &cq_arg, "--cpu-used=0",
8798+ "--threads=1", "--row-mt=0", "--sb-size=64", &depth_arg, &input_depth_arg,
8799+ "--enable-restoration=0", "--enable-palette=0", "--deltaq-mode=0",
8800+ "--enable-filter-intra=0", "--enable-cfl-intra=0", "--enable-intrabc=0",
8801+ "--lag-in-frames=0", "--enable-obmc=0", "--enable-tx-size-search=1",
8802+ // Per-arm overrides last (aomenc keeps the LAST occurrence).
8803+ "--enable-rect-partitions=0", "--enable-ab-partitions=0",
8804+ "--enable-1to4-partitions=0", "--min-partition-size=4",
8805+ "--max-partition-size=16",
8806+ &rect_arg,
8807+ "--obu", "-o", "-", "-",
8808+ ];
8809+ let mut child = Command::new(aomenc_path())
8810+ .args(&args)
8811+ .stdin(Stdio::piped())
8812+ .stdout(Stdio::piped())
8813+ .stderr(Stdio::piped())
8814+ .spawn()
8815+ .expect("aomenc failed to start");
8816+ child
8817+ .stdin
8818+ .take()
8819+ .expect("aomenc stdin")
8820+ .write_all(&y4m.stdout)
8821+ .expect("writing y4m to aomenc");
8822+ let out = child.wait_with_output().expect("aomenc failed to run");
8823+ assert!(
8824+ out.status.success(),
8825+ "{NAME}: aomenc refused the fixture: {}",
8826+ String::from_utf8_lossy(&out.stderr)
8827+ );
8828+ let stream = out.stdout;
8829+ let before = decode::sub8_inter_split_hits();
8830+ let before_rect = decode::sub8_inter_rect_hits();
8831+ let before_masked = decode::rect_masked_compound_hits();
8832+ let frames = match decode_stream(&stream) {
8833+ Err(e) => {
8834+ let msg = e.to_string();
8835+ assert!(
8836+ msg.contains("unsupported"),
8837+ "{NAME} failed outright, not a named refusal ({bit_depth}-bit, \
8838+ attempt {attempt}): {msg}"
8839+ );
8840+ refusals.push(format!("{bit_depth}-bit attempt {attempt}: {msg}"));
8841+ continue;
8842+ }
8843+ Ok(frames) => frames,
8844+ };
8845+ let split_groups = decode::sub8_inter_split_hits() - before;
8846+ let rect_now = decode::sub8_inter_rect_hits();
8847+ let rect_groups = (rect_now.0 - before_rect.0) + (rect_now.1 - before_rect.1);
8848+ let groups = split_groups + rect_groups;
8849+ let ffmpeg_frames = if bit_depth == 10 {
8850+ ffmpeg_decode_sequence_10bit(&stream, width, height, frame_count)
8851+ } else {
8852+ ffmpeg_decode_sequence(&stream, width, height, frame_count)
8853+ };
8854+ assert_eq!(frames.len(), frame_count);
8855+ let mismatched = frames
8856+ .iter()
8857+ .zip(&ffmpeg_frames)
8858+ .any(|(got, want)| got.y != want.y || got.u != want.u || got.v != want.v);
8859+ if groups == 0 {
8860+ // Out of scope: no sub-8x8 inter split in this attempt.
8861+ if mismatched {
8862+ out_of_scope_mismatch += 1;
8863+ eprintln!(
8864+ "{NAME}: {bit_depth}-bit attempt {attempt} MISMATCHES with zero \
8865+ sub-8x8 inter group -- another shape's defect"
8866+ );
8867+ }
8868+ refusals.push(format!(
8869+ "{bit_depth}-bit attempt {attempt}: decoded, but no sub-8x8 inter split"
8870+ ));
8871+ continue;
8872+ }
8873+ for (i, (got, want)) in frames.iter().zip(&ffmpeg_frames).enumerate() {
8874+ assert_eq!(
8875+ got.y, want.y,
8876+ "luma frame {i} ({bit_depth}-bit attempt {attempt}, {groups} sub-8x8 \
8877+ inter split groups)"
8878+ );
8879+ assert_eq!(got.u, want.u, "U frame {i} ({bit_depth}-bit attempt {attempt})");
8880+ assert_eq!(got.v, want.v, "V frame {i} ({bit_depth}-bit attempt {attempt})");
8881+ }
8882+ fired += 1;
8883+ if rect_groups > 0 {
8884+ rect_fired += 1;
8885+ }
8886+ if rect_now.0 - before_rect.0 > 0 {
8887+ horz_fired += 1;
8888+ }
8889+ if rect_now.1 - before_rect.1 > 0 {
8890+ vert_fired += 1;
8891+ }
8892+ // Only now, past the pixel compare, is this attempt's
8893+ // masked-compound count admissible.
8894+ rect_masked += decode::rect_masked_compound_hits() - before_masked;
8895+ }
8896+ }
8897+ eprintln!(
8898+ "{NAME}: fired={fired} horz={horz_fired} vert={vert_fired} rect_masked={rect_masked}"
8899+ );
8900+ assert_eq!(
8901+ out_of_scope_mismatch, 0,
8902+ "{NAME}: attempts mismatched with no sub-8x8 inter group"
8903+ );
8904+ assert!(
8905+ fired >= 2,
8906+ "{NAME}: fewer than 2 firing+pixel-exact attempts:\n{}",
8907+ refusals.join("\n")
8908+ );
8909+ assert!(
8910+ rect_fired >= 2,
8911+ "{NAME}: fewer than 2 firing+pixel-exact attempts with a RECTANGULAR sub-8x8 \
8912+ inter leaf (4x8):\n{}",
8913+ refusals.join("\n")
8914+ );
8915+ assert!(
8916+ vert_fired >= 2,
8917+ "{NAME}: fewer than 2 firing+pixel-exact attempts with a sub-8x8 inter VERT \
8918+ pair (two BLOCK_4X8 leaves):\n{}",
8919+ refusals.join("\n")
8920+ );
8921+ // lane-intersub8 r5, measured `rect_masked=2` over the 48 attempts:
8922+ // the rect masked-compound blocks whose `compound_type`/`wedge_idx`
8923+ // CDF row r4 corrected, counted only on pixel-compared attempts.
8924+ assert!(
8925+ rect_masked >= 1,
8926+ "{NAME}: no RECTANGULAR masked-compound block on any pixel-compared attempt -- \
8927+ the r4 compound_type/wedge_idx CDF-row fix is unexercised:\n{}",
8928+ refusals.join("\n")
8929+ );
8930+ assert!(
8931+ horz_fired >= 2,
8932+ "{NAME}: fewer than 2 firing+pixel-exact attempts with a sub-8x8 inter HORZ \
8933+ pair (two BLOCK_8X4 leaves):\n{}",
8934+ refusals.join("\n")
8935+ );
8936+ }
8937+
8686 #[test]8938 #[test]
8687 // lane-inter4 r3: the 16x16-level rect INTER leaf -- PARTITION_HORZ /8939 // lane-inter4 r3: the 16x16-level rect INTER leaf -- PARTITION_HORZ /
8688 // PARTITION_VERT at 16x16 on an inter frame, i.e. two 16x8 / 8x16 inter8940 // 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.