forge
Explore
Log in

Don't you dare go Hollow

Merge af47324 (lane-intersub8) into lane-uv8: keep interp3 compound-leaf interp read

Browse files at this commit

3009c584f3bb581468b00c01302a8f2aba6bcc65Ahmet Kaan GümüşParent: 79d795f781507a

11 changed files +2012 -221

crates/ec-av1/examples/decode_probe.rsmodified+3 -0
@@ -35,6 +35,9 @@ fn main() {
3535 println!("rect4_32: horz={h} vert={v} coded={c}");
3636 let (rtu, rsplit, robmc) = ec_av1::stream::rect_inter_tu_counters();
3737 println!("rect_inter: tu={rtu} txsplit={rsplit} obmc_leaf={robmc}");
38+ println!("sub8_inter_split: groups={}", ec_av1::decode::sub8_inter_split_hits());
39+ let (h84, h48) = ec_av1::decode::sub8_inter_rect_hits();
40+ println!("sub8_inter_rect: horz8x4={h84} vert4x8={h48}");
3841 let leaf = ec_av1::stream::vartx_rect_leaf_hits();
3942 println!("vartx_rect_leaf: 32x16={} 16x32={}", leaf[0], leaf[1]);
4043 // lane-inter16ab r1: the 16x16-level inter AB arms, so a recipe sweep
crates/ec-av1/src/cdf_state.rsmodified+40 -0
@@ -230,6 +230,22 @@ pub(crate) enum TxbSet {
230230 /// counterpart: `EXT_TX_SET_DTT4_IDTX_1DDCT`, the seven-symbol `TX_4X4`
231231 /// row [`LumaRect4x8Set1`](TxbSet::LumaRect4x8Set1) reads.
232232 LumaRect16x4Set1,
233+ /// The luma 8x4/4x8 transform of an INTER `PARTITION_HORZ`/`PARTITION_VERT`
234+ /// leaf under an 8x8 block (lane-intersub8 r3): every coefficient table is
235+ /// [`LumaRect4x8`](TxbSet::LumaRect4x8)'s (`get_txsize_entropy_ctx` squares
236+ /// `TX_8X4` up to the 8x8 class, 32-position `eob_pt`), with the INTER
237+ /// `tx_type` alphabet in its place. Under `reduced_tx_set`
238+ /// `av1_get_ext_tx_set_type` (`tx_size_sqr_up == TX_8X8`, `is_inter`)
239+ /// returns `EXT_TX_SET_DCT_IDTX`, whose row is
240+ /// `default_inter_ext_tx_cdf[?][txsize_sqr_map[TX_8X4] == TX_4X4]` -- the
241+ /// same `TX_4X4` inter row [`Luma4Inter`](TxbSet::Luma4Inter) reads.
242+ LumaRect8x4Inter,
243+ /// [`LumaRect8x4Inter`](TxbSet::LumaRect8x4Inter)'s `reduced_tx_set: false`
244+ /// counterpart: `tx_size_sqr == TX_4X4` with `tx_size_sqr_up == TX_8X8`, so
245+ /// `av1_ext_tx_set_lookup[is_inter=1][...]` is `EXT_TX_SET_ALL16` -- sixteen
246+ /// symbols at the `TX_4X4` inter row, the table
247+ /// [`Luma4InterSet1`](TxbSet::Luma4InterSet1) also reads.
248+ LumaRect8x4InterSet1,
233249 }
234250
235251 /// The tables one transform block is coded with, borrowed from the state for
@@ -1792,6 +1808,30 @@ impl Cdfs {
17921808 tx_type: Some(self.intra_tx_type_4[mode].as_mut_slice()),
17931809 eob_pt_class1: Some(&mut self.eob_pt_32_luma_class1),
17941810 },
1811+ TxbSet::LumaRect8x4Inter => TxbTables {
1812+ side: 8,
1813+ txb_skip: &mut self.txb_skip_luma_8,
1814+ eob_pt: &mut self.eob_pt_32_luma,
1815+ eob_extra: &mut self.eob_extra_luma_8,
1816+ base: &mut self.base_luma_8,
1817+ base_eob: &mut self.base_eob_luma_8,
1818+ br: &mut self.br_luma_8,
1819+ dc_sign: &mut self.dc_sign_luma,
1820+ tx_type: Some(self.inter_tx_type_4.as_mut_slice()),
1821+ eob_pt_class1: Some(&mut self.eob_pt_32_luma_class1),
1822+ },
1823+ TxbSet::LumaRect8x4InterSet1 => TxbTables {
1824+ side: 8,
1825+ txb_skip: &mut self.txb_skip_luma_8,
1826+ eob_pt: &mut self.eob_pt_32_luma,
1827+ eob_extra: &mut self.eob_extra_luma_8,
1828+ base: &mut self.base_luma_8,
1829+ base_eob: &mut self.base_eob_luma_8,
1830+ br: &mut self.br_luma_8,
1831+ dc_sign: &mut self.dc_sign_luma,
1832+ tx_type: Some(self.inter_tx_type_4_set1.as_mut_slice()),
1833+ eob_pt_class1: Some(&mut self.eob_pt_32_luma_class1),
1834+ },
17951835 TxbSet::LumaRect4x8Set1 => TxbTables {
17961836 side: 8,
17971837 txb_skip: &mut self.txb_skip_luma_8,
crates/ec-av1/src/decode.rsmodified+1357 -221
@@ -2643,6 +2643,21 @@ pub(crate) fn tx_class1_hits() -> usize {
26432643 // coincidentally landing on `PARTITION_NONE`.
26442644 thread_local! {
26452645 static SUB8_SPLIT_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
2646+ /// How many 8x8 groups an INTER frame split into four BLOCK_4X4 inter
2647+ /// sub-blocks (lane-intersub8).
2648+ static SUB8_INTER_SPLIT_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
2649+ /// How many 8x8 groups an INTER frame split into two rectangular sub-8x8
2650+ /// inter leaves (lane-intersub8 r3), indexed `[0] = HORZ` (two BLOCK_8X4),
2651+ /// `[1] = VERT` (two BLOCK_4X8).
2652+ static SUB8_INTER_RECT_HITS: std::cell::Cell<[usize; 2]> = const { std::cell::Cell::new([0; 2]) };
2653+}
2654+
2655+/// Current value of [`SUB8_INTER_RECT_HITS`]: `(8x4 groups, 4x8 groups)`.
2656+pub fn sub8_inter_rect_hits() -> (usize, usize) {
2657+ SUB8_INTER_RECT_HITS.with(|c| {
2658+ let h = c.get();
2659+ (h[0], h[1])
2660+ })
26462661 }
26472662
26482663 /// Current value of [`SUB8_SPLIT_HITS`].
@@ -2650,6 +2665,11 @@ pub(crate) fn sub8_split_hits() -> usize {
26502665 SUB8_SPLIT_HITS.with(|c| c.get())
26512666 }
26522667
2668+/// Current value of [`SUB8_INTER_SPLIT_HITS`].
2669+pub fn sub8_inter_split_hits() -> usize {
2670+ SUB8_INTER_SPLIT_HITS.with(|c| c.get())
2671+}
2672+
26532673 // How many 4x8 / 8x4 leaves (lane-tx4x8's `PARTITION_VERT`/`PARTITION_HORZ`
26542674 // of an 8x8 block) this thread's decode reconstructed with REAL coefficients
26552675 // -- a skipped leaf exercises the prediction and the mi bookkeeping but never
@@ -15104,6 +15124,12 @@ fn resolve_interp_filter(
1510415124 if enable_dual_filter && sym0 != sym1 {
1510515125 DUAL_FILTER_DIFF_HITS.with(|c| c.set(c.get() + 1));
1510615126 }
15127+ if std::env::var_os("EC_TRACE_MODE").is_some() {
15128+ eprintln!(
15129+ "EC_IF ctx0={ctx0} above={above:?} left={left:?} sym0={sym0} sym1={sym1} rng={}",
15130+ dec.debug_state().0
15131+ );
15132+ }
1510715133 (
1510815134 mc::InterpFilterKind::from_switchable_symbol(sym1 as usize),
1510915135 mc::InterpFilterKind::from_switchable_symbol(sym0 as usize),
@@ -16170,6 +16196,67 @@ fn is_any_masked_compound_used_here(side: usize) -> bool {
1617016196 side.min(side) >= 8
1617116197 }
1617216198
16199+/// libaom's `BLOCK_SIZES_ALL` index of a `w`x`h` block (`common_data.h`'s own
16200+/// enum order) -- the row every bsize-indexed CDF (`compound_type_cdf`,
16201+/// `wedge_idx_cdf`) is read at. lane-intersub8 r4: these two used to be
16202+/// indexed by the caller's SQUARE envelope, so a 16x8 compound block read
16203+/// `BLOCK_16X16`'s row (class table-indexed-by-raw-size) and desynced the
16204+/// tile at its first masked-compound rect block.
16205+fn bsize_index(w: usize, h: usize) -> Option<usize> {
16206+ Some(match (w, h) {
16207+ (4, 4) => 0,
16208+ (4, 8) => 1,
16209+ (8, 4) => 2,
16210+ (8, 8) => 3,
16211+ (8, 16) => 4,
16212+ (16, 8) => 5,
16213+ (16, 16) => 6,
16214+ (16, 32) => 7,
16215+ (32, 16) => 8,
16216+ (32, 32) => 9,
16217+ (32, 64) => 10,
16218+ (64, 32) => 11,
16219+ (64, 64) => 12,
16220+ (64, 128) => 13,
16221+ (128, 64) => 14,
16222+ (128, 128) => 15,
16223+ (4, 16) => 16,
16224+ (16, 4) => 17,
16225+ (8, 32) => 18,
16226+ (32, 8) => 19,
16227+ (16, 64) => 20,
16228+ (64, 16) => 21,
16229+ _ => return None,
16230+ })
16231+}
16232+
16233+/// `is_any_masked_compound_used` (libaom `reconinter.h`) on the block's TRUE
16234+/// footprint: `is_comp_ref_allowed` is `AOMMIN(bw, bh) >= 8`, and every
16235+/// shape that clears it has either a wedge or a DIFFWTD compound available.
16236+fn masked_compound_used_wh(w: usize, h: usize) -> bool {
16237+ w.min(h) >= 8
16238+}
16239+
16240+/// `av1_wedge_params_lookup[bsize].wedge_types > 0` (libaom `reconinter.c`):
16241+/// the shapes whose `compound_type` symbol is really coded. Everything else
16242+/// with a compound mask infers `COMPOUND_DIFFWTD` without a symbol.
16243+fn wedge_used_wh(w: usize, h: usize) -> bool {
16244+ matches!(
16245+ (w, h),
16246+ (8, 8)
16247+ | (8, 16)
16248+ | (16, 8)
16249+ | (16, 16)
16250+ | (16, 32)
16251+ | (32, 16)
16252+ | (32, 32)
16253+ | (8, 32)
16254+ | (32, 8)
16255+ | (16, 64)
16256+ | (64, 16)
16257+ )
16258+}
16259+
1617316260 /// Whether a compound reference pair is unidirectional (both references on
1617416261 /// the same temporal side of the current frame) -- `has_uni_comp_refs`
1617516262 /// (libaom `av1_reference_frame_utils.h`/`pred_common.c`'s own definition:
@@ -16959,12 +17046,18 @@ fn decode_inter_block(
1695917046 let group_ctx = get_comp_group_idx_context(neighbours, (rmi, cmi), side);
1696017047 let comp_group_idx = if !skip_mode
1696117048 && enable_masked_compound
16962- && is_any_masked_compound_used_here(side)
17049+ && masked_compound_used_wh(write_w, write_h)
1696317050 {
1696417051 dec.symbol(&mut cdfs.comp_group_idx[group_ctx])
1696517052 } else {
1696617053 0
1696717054 };
17055+ if std::env::var_os("EC_TRACE_MODE").is_some() {
17056+ eprintln!(
17057+ "EC_CGI mi_row={rmi} mi_col={cmi} ctx={group_ctx} val={comp_group_idx} rng={}",
17058+ dec.debug_state().0
17059+ );
17060+ }
1696817061 // lane-maskcomp r2 / lane-wedge r3: `Some(mask_type)` for a
1696917062 // `COMPOUND_DIFFWTD` block, `Some(mask)` (wedge codebook lookup)
1697017063 // for a `COMPOUND_WEDGE` block -- exactly one of the two is set
@@ -16986,12 +17079,11 @@ fn decode_inter_block(
1698617079 // writes NO `compound_type` symbol there and INFERS
1698717080 // `COMPOUND_DIFFWTD` -- only the 1-bit `mask_type` literal
1698817081 // follows. `None` here is exactly that inferred arm.
16989- let wedge_bsize = match side {
16990- 8 => Some(3),
16991- 16 => Some(6),
16992- 32 => Some(9),
16993- _ => None,
16994- };
17082+ // lane-intersub8 r4: the block's TRUE footprint, not the
17083+ // square envelope -- `compound_type_cdf`/`wedge_idx_cdf` are
17084+ // `BLOCK_SIZES_ALL`-indexed.
17085+ let wedge_bsize =
17086+ bsize_index(write_w, write_h).filter(|_| wedge_used_wh(write_w, write_h));
1699517087 let compound_type = match wedge_bsize {
1699617088 Some(b) => dec.symbol(&mut cdfs.compound_type[b]),
1699717089 None => 1,
@@ -16999,6 +17091,14 @@ fn decode_inter_block(
1699917091 if let Some(wedge_bsize) = wedge_bsize.filter(|_| compound_type == 0) {
1700017092 // COMPOUND_WEDGE: lane-wedge r3, codebook checksum-
1700117093 // verified vs independent C dump (wedge.rs).
17094+ if write_w != write_h {
17095+ // lane-intersub8 r4: the wedge codebook here is built
17096+ // per SQUARE side only; a rect block's own codebook
17097+ // (BLOCK_16X8 etc.) is a different mask set.
17098+ return Err(unsupported(
17099+ "a COMPOUND_WEDGE mask on a non-square inter block (rect wedge codebook unimplemented)",
17100+ ));
17101+ }
1700217102 let wedge_index = dec.symbol(&mut cdfs.wedge_idx[wedge_bsize]);
1700317103 let wedge_sign = dec.literal(1);
1700417104 WEDGE_HITS.with(|c| c.set(c.get() + 1));
@@ -17230,6 +17330,12 @@ fn decode_inter_block(
1723017330 ref_order_hints[(ref1 - LAST_FRAME) as usize],
1723117331 );
1723217332 let idx = dec.symbol(&mut cdfs.compound_idx[idx_ctx]);
17333+ if std::env::var_os("EC_TRACE_MODE").is_some() {
17334+ eprintln!(
17335+ "EC_CIDX mi_row={rmi} mi_col={cmi} ctx={idx_ctx} val={idx} rng={}",
17336+ dec.debug_state().0
17337+ );
17338+ }
1723317339 if idx == 1 {
1723417340 (8, 8, 1u8)
1723517341 } else {
@@ -19267,30 +19373,47 @@ fn decode_inter_block(
1926719373 Ok(())
1926819374 }
1926919375
19270-/// Decodes one 8x8 leaf of a straddling 16x16 inter-frame block
19271-/// (lane-av1inter8), mirroring [`crate::tile::write_inter_frame_leaf8`]'s
19272-/// exact symbol order: its own skip flag, intra/inter choice and (when
19273-/// inter) `NEARESTMV`/`NEWMV` chain against this leaf's own 2x2-mi mv-stack
19274-/// window, or (when intra) `Y_MODE`, then its own luma and two chroma
19275-/// transform blocks through [`TxbSet::Luma8Inter`]/[`TxbSet::Chroma4`],
19276-/// same as [`decode_leaf8`]'s coefficient layer but with
19277-/// motion-compensated prediction instead of intra prediction when inter.
19278-/// `outer_at` (in [`SUB`]-grid units) is the enclosing 16x16 slot's
19279-/// skip/intra-inter context, overridden by `prev_leaf` exactly as
19280-/// [`decode_leaf8`] overrides mode context: `Neighbours`' above/left arrays
19281-/// only resolve to [`SUB`] granularity. Hands back this leaf's own skip flag
19282-/// and intra/inter choice, for the next leaf or the caller's final
19283-/// write-back.
19376+/// Decodes one 8x8 group that an inter frame's `partition_w8` symbol split
19377+/// into four `BLOCK_4X4` inter blocks (lane-intersub8: `PARTITION_SPLIT`
19378+/// below 8x8 -- traced live against the oracle `aomdec`'s own `EC_PART_VAL`,
19379+/// which reads `bsize=3 value=3` on real inter frames, so the refusal this
19380+/// replaces was NOT our own desync).
19381+///
19382+/// The inter counterpart of [`decode_leaf_split4`], and a `BLOCK_4X4`-only
19383+/// cut of [`decode_inter_block8`]: at `min(bw, bh) < 8` libaom switches off
19384+/// half the inter syntax, and every one of those is a symbol NOT read here
19385+/// (`decodemv.c` / `blockd.h`, oracle tree):
19386+/// * `skip_mode`: `read_skip_mode` returns 0 without a symbol when
19387+/// `!is_comp_ref_allowed(bsize)` (`AOMMIN(bw, bh) >= 8`, blockd.h).
19388+/// * `comp_mode`: `read_block_reference_mode` returns `SINGLE_REFERENCE` on
19389+/// the same predicate, so a sub-8x8 block is always single-reference.
19390+/// * `interintra`: `is_interintra_allowed_bsize` starts at `BLOCK_8X8`.
19391+/// * `motion_mode` / `obmc`: `motion_mode_allowed` returns
19392+/// `SIMPLE_TRANSLATION` for `block_size_wide < 8 || block_size_high < 8`,
19393+/// and `is_global_mv_block`'s own size term fails, so no warp either.
19394+/// * tx size: `block_signals_txsize(bsize)` is `bsize > BLOCK_4X4`
19395+/// (blockd.h:1027), so a `BLOCK_4X4` reads neither `tx_depth` nor a
19396+/// `txfm_partition` bit even in `TX_MODE_SELECT` -- the transform is
19397+/// `max_txsize_rect_lookup[BLOCK_4X4]` = `TX_4X4`
19398+/// (`decodeframe.c:1164-1177`).
19399+///
19400+/// Chroma is coded ONCE for the whole 8x8 group, on the last sub-block
19401+/// (`is_chroma_reference`: `(mi_row & 1) && (mi_col & 1)` in 4:2:0), as one
19402+/// `TX_4X4` unit per plane -- same rule and same neighbour-context tail as
19403+/// [`decode_leaf_split4`]. Its PREDICTION is the sub8x8 one
19404+/// (`dec_build_inter_predictors`'s `is_sub8x8` branch, `decodeframe.c`; spec
19405+/// 7.11.3.1's `candRow`/`candCol` loop): four 2x2 chroma pieces, each built
19406+/// from its own luma sub-block's reference, motion vector and interpolation
19407+/// filters, never from the last sub-block's mv alone.
1928419408 #[allow(clippy::too_many_arguments)]
19285-fn decode_inter_block8(
19409+fn decode_inter_sub8_split4(
1928619410 dec: &mut SymbolDecoder,
1928719411 cdfs: &mut Cdfs,
1928819412 neighbours: &mut Neighbours,
1928919413 grid: &mut MiGrid,
19414+ group_mi: (usize, usize),
1929019415 mi_cols: u32,
1929119416 mi_rows: u32,
19292- outer_at: (usize, usize),
19293- leaf_mi: (usize, usize),
1929419417 y: &mut PlaneBuf,
1929519418 u: &mut PlaneBuf,
1929619419 v: &mut PlaneBuf,
@@ -19298,210 +19421,1128 @@ fn decode_inter_block8(
1929819421 ref_u: &PlaneBuf,
1929919422 ref_v: &PlaneBuf,
1930019423 other_refs: &RefSlots,
19424+ sign_bias_table: &SignBiasTable,
19425+ global_motion: &[ec_av1_syntax::WarpParams; 7],
1930119426 base_q_idx: u8,
19302- scan8: &[u16],
1930319427 scan4: &[u16],
1930419428 allow_high_precision_mv: bool,
1930519429 force_integer_mv: bool,
19306- // lane-gmaffine r1: this frame header's own `global_motion` table (spec
19307- // 5.9.24), indexed `[ref_frame - LAST_FRAME]` -- same table
19308- // [`decode_inter_block`] takes, threaded here so the 8x8 leaf can code
19309- // `GLOBALMV` (`gm_get_motion_vector`), fill its mv stack's missing
19310- // candidates with the gm mv (gm r6's root cause) and build a global
19311- // warp prediction.
19312- global_motion: &[ec_av1_syntax::WarpParams; 7],
19313- // lane-gmaffine r1: this sequence header's own `enable_dual_filter` bit,
19314- // for the leaf's own `read_mb_interp_filter` below.
19315- enable_dual_filter: bool,
19316- // lane-av1comp: see [`decode_inter_block`]'s own doc -- this leaf path
19317- // only ever tracks a coarse `LAST_FRAME`-or-intra neighbour shape (no
19318- // per-leaf `above_ref`/`left_ref` array exists here), so `comp_mode`'s
19319- // context uses that same approximation.
19320- reference_select: bool,
19321- enable_masked_compound: bool,
19322- // lane-sb128 r4: see [`decode_inter_block`]'s own doc -- `BLOCK_8X8` is
19323- // always `is_interintra_allowed_bsize`-eligible, so this leaf's own gate
19324- // drops the `side` check entirely.
19325- enable_interintra_compound: bool,
19326- enable_jnt_comp: bool,
19327- order_hint_bits: u32,
19328- order_hint: u32,
19329- ref_order_hints: [u32; 7],
19330- // lane-av1comp round 14: see [`decode_inter_block`]'s own doc -- this
19331- // leaf has no per-leaf `above_skip_mode`/`left_skip_mode` array either,
19332- // so its `skip_mode` context reuses the same [`SUB`]-grid
19333- // `above_skip_mode[cmi]`/`left_skip_mode[rmi]` the enclosing 16x16 slot
19334- // tracks (mirroring `above_skip`/`left_skip`'s own leaf approximation
19335- // just above).
19336- skip_mode_present: bool,
19337- skip_mode_frame: [u8; 2],
19338- // lane-cdffwd2: this frame header's own `reduced_tx_set` bit -- see
19339- // [`decode_inter_frame_tile_with_cdfs`]'s own doc.
19340- reduced_tx_set: bool,
19341- // lane-motionmode round 3: this frame header's own `is_motion_mode_switchable`/
19342- // `allow_warped_motion` bits (spec 5.11.24's `read_motion_mode`), plus
19343- // the fixed/switchable interp filter kind `obmc_blend`'s own neighbour
19344- // reads need (see [`decode_inter_block`]'s own doc) -- this leaf's own
19345- // prediction is always `Regular` (documented corner-cut, `mc::predict`
19346- // has no filter param), but an OBMC neighbour can be a real 16x16+
19347- // block that DID resolve a switchable filter.
1934819430 interp_fixed: Option<mc::InterpFilterKind>,
19349- switchable_motion_mode: bool,
19350- allow_warped_motion: bool,
19351- // lane-av1comp: `Some((ref1, comp_group_idx, compound_idx))` only for a
19352- // real `COMPOUND_REFERENCE` leaf, for the caller's own end-of-16x16
19353- // `record_compound_ctx` call -- mirrors [`decode_inter_block`]'s own
19354- // `compound_ctx` local, just handed back instead of applied here (this
19355- // fn's `neighbours` recording happens once for the whole straddling
19356- // 16x16 block, after every leaf).
19357- // lane-screen r2: see [`decode_inter_block`]'s own copy of this param --
19358- // `BLOCK_8X8` (this leaf's fixed size) is always `av1_allow_palette`-
19359- // eligible (`bsize >= BLOCK_8X8`).
19360- allow_screen_content_tools: bool,
19361- // lane-inter8 r1: the leaf's mv stacks used to be built without the
19362- // frame's sign-bias table (`NO_SIGN_BIAS`), while [`decode_inter_block`]
19363- // one level up passed it -- it changes the candidate list and with it
19364- // `new_mv_ctx`/`ref_mv_ctx`, `drl_ctx` and the number of symbols read.
19365- // Measured: an 8x8 compound NEAR_NEWMV leaf desynced against aomdec's
19366- // EC_MODE ladder at exactly this block (mi 4,14 of the mandelbrot
19367- // 8x8-split gate).
19368- sign_bias_table: &SignBiasTable,
19369- // lane-inter8 r2: the frame's temporal mv field (spec 7.10.2.8), which
19370- // [`decode_inter_block`] one level up has always passed and this leaf
19371- // passed `None` for -- a `use_ref_frame_mvs` frame's stack then holds
19372- // fewer candidates here than in the reference decoder, which changes the
19373- // mode contexts AND the number of `drl_mode` bits read (class parsed
19374- // then discarded).
19431+ enable_dual_filter: bool,
1937519432 tpl_frame: Option<&TplFrameArgs>,
19376- // lane-scaledref r1: this frame's own coded luma width (spec 7.11.3.3),
19377- // for the scaled-reference MC this leaf's own single-ref/compound/OBMC
19378- // predictions take when a stored reference was coded at another width
19379- // (`use_superres`) -- mirrors [`decode_inter_block`]'s own param.
19433+ reduced_tx_set: bool,
1938019434 frame_width: usize,
19381-) -> Result<(bool, bool, bool, Option<(i8, i8, u8, u8)>, [u8; 2], (i8, Option<i8>))> {
19435+) -> Result<()> {
1938219436 const LAST_FRAME: i8 = 1;
19383- // lane-gmaffine r2: the leaf's OWN switchable-filter symbols, handed back
19384- // so the caller stamps them into `Neighbours` instead of the `[3, 3]`
19385- // placeholder. `[3, 3]` is the "intra neighbour, no filter" sentinel: an
19386- // OBMC blend that picks such a neighbour up feeds it to
19387- // `neighbour_filter`, which PANICS on it (`from_switchable_symbol`) --
19388- // that was the warp gate's crash, not an entropy desync. Stays `[3, 3]`
19389- // on the intra and compound paths.
19390- let mut leaf_filter_syms = [3u8; 2];
19391- // lane-gmaffine r1: this leaf's GLOBALMV vector AND the mv stack's
19392- // missing-candidate fallback both come from the frame's global motion
19393- // evaluated at THIS block's centre (gm r6's root cause).
19394- let gm_table = build_gm_mv_table(
19395- global_motion,
19396- leaf_mi.0,
19397- leaf_mi.1,
19398- 2,
19399- 2,
19400- allow_high_precision_mv,
19401- force_integer_mv,
19402- );
19403- /// `Y_MODE`'s size group (`common_data.h`'s `size_group_lookup[BLOCK_8X8]`).
19404- const SIZE_GROUP_8: usize = 1;
19405-
19406- let (px, py) = (leaf_mi.1 * MI, leaf_mi.0 * MI);
19407- let (cpx, cpy) = (px / 2, py / 2);
19408- // lane-txselect: whether this leaf's `TxMode::Select` var-tx tree took
19409- // the one split a `BLOCK_8X8` can take (`read_block_tx_size` below) --
19410- // read back by the luma residual read and the tail's neighbour/loop-filter
19411- // bookkeeping. Always `false` outside a `TxMode::Select` inter frame.
19412- let mut split8 = false;
19413- const SIDE: usize = 8;
19414- const CHROMA_SIDE: usize = 4;
19415-
19416- let (r, c) = outer_at;
19417- // lane-inter8 r2: this leaf's OWN mi cell, not the enclosing 16x16's --
19418- // leaf (mi_r, mi_c + 2)'s left neighbour is leaf (mi_r, mi_c), and the
19419- // left column of a 16x16's second leaf ROW is the previous 16x16 block's
19420- // bottom leaf, neither of which a SUB-grid slot can name.
19421- let (rmi, cmi) = leaf_mi;
19422- // lane-inter8 r2: no sibling-leaf override any more -- each leaf stamps
19423- // its own 2x2-mi span into the bands right after it decodes (the caller's
19424- // `record_inter_rect_mi`), so a plain mi read already names the correct
19425- // neighbour, including one belonging to the previous 16x16 block.
19426- let above_skip = neighbours.above_skip[cmi];
19427- let left_skip = neighbours.left_skip[rmi];
19428- let above_inter = neighbours.above_inter[cmi];
19429- let left_inter = neighbours.left_inter[rmi];
19430- let above_ref0 = neighbours.above_ref[cmi];
19431- let above_ref1 = neighbours.above_ref1[cmi];
19432- let left_ref0 = neighbours.left_ref[rmi];
19433- let left_ref1 = neighbours.left_ref1[rmi];
19434- let skip_mode_ctx =
19435- usize::from(neighbours.above_skip_mode[cmi]) + usize::from(neighbours.left_skip_mode[rmi]);
19436- // Same two `inter_segment_id` positions as [`decode_inter_block`]; this
19437- // leaf is always `BLOCK_8X8`, i.e. 2x2 mi.
19438- inter_segment_id(dec, cdfs, leaf_mi.0, leaf_mi.1, 2, 2, false, true);
19439- let skip_mode = skip_mode_present && dec.symbol(&mut cdfs.skip_mode[skip_mode_ctx]) == 1;
19440- if skip_mode {
19441- SKIP_MODE_HITS.with(|c| c.set(c.get() + 1));
19442- }
19443-
19444- let skip_ctx = usize::from(above_skip) + usize::from(left_skip);
19445- let skip = skip_mode || dec.symbol(&mut cdfs.skip[skip_ctx]) == 1;
19446- inter_segment_id(dec, cdfs, leaf_mi.0, leaf_mi.1, 2, 2, skip, false);
19447- maybe_read_cdef_idx(dec, leaf_mi.0, leaf_mi.1, skip);
19448- // Always a `BLOCK_8X8` leaf here, never the whole superblock.
19449- maybe_read_delta_q(dec, cdfs, leaf_mi.0, leaf_mi.1, false, skip);
19450- maybe_read_delta_lf(dec, cdfs, leaf_mi.0, leaf_mi.1, false, skip);
19451-
19452- let (has_above, has_left) = (
19453- leaf_mi.0 > neighbours.tile_row0_mi,
19454- leaf_mi.1 > neighbours.tile_col0_mi,
19455- );
19456- let ii_ctx = intra_inter_ctx(has_above, has_left, above_inter, left_inter);
19457- let is_inter = skip_mode || dec.symbol(&mut cdfs.intra_inter[ii_ctx]) == 1;
19458- // lane-inter8 r1: mirrors the oracle's `EC_MODE` (instrument rung 4,
19459- // `read_inter_block_mode_info`) so an 8x8 leaf's mode-info range ladder
19460- // diffs line for line against a real aomdec.
19461- if std::env::var_os("EC_TRACE_MODE").is_some() {
19462- eprintln!(
19463- "EC_MODE mi_row={} mi_col={} rng={}",
19464- leaf_mi.0,
19465- leaf_mi.1,
19466- dec.debug_state().0
19437+ const B4: usize = 4;
19438+ SUB8_INTER_SPLIT_HITS.with(|c| c.set(c.get() + 1));
19439+ let (gr, gc) = group_mi;
19440+ let (gpx, gpy) = (gc * MI, gr * MI);
19441+ let (cpx, cpy) = (gpx / 2, gpy / 2);
19442+ // Per-sub-block state the group's chroma prediction needs (spec
19443+ // 7.11.3.1's candRow/candCol loop reads each sub-block's OWN mv/ref/
19444+ // filters), indexed `dr * 2 + dc`.
19445+ let mut piece: [Option<(i8, (i32, i32), mc::InterpFilterKind, mc::InterpFilterKind)>; 4] =
19446+ [None; 4];
19447+ let mut first_tx_type = TxType::DctDct;
19448+ let mut last_skip = true;
19449+ for i in 0..4usize {
19450+ let (dr, dc) = (i / 2, i % 2);
19451+ let lmi = (gr + dr, gc + dc);
19452+ if lmi.0 >= mi_rows as usize || lmi.1 >= mi_cols as usize {
19453+ continue;
19454+ }
19455+ let (rmi, cmi) = lmi;
19456+ let (px, py) = (cmi * MI, rmi * MI);
19457+ inter_segment_id(dec, cdfs, rmi, cmi, 1, 1, false, true);
19458+ // No `skip_mode` symbol: `is_comp_ref_allowed(BLOCK_4X4)` is false.
19459+ let skip_ctx = usize::from(neighbours.above_skip[cmi]) + usize::from(neighbours.left_skip[rmi]);
19460+ let skip = dec.symbol(&mut cdfs.skip[skip_ctx]) == 1;
19461+ inter_segment_id(dec, cdfs, rmi, cmi, 1, 1, skip, false);
19462+ maybe_read_cdef_idx(dec, rmi, cmi, skip);
19463+ maybe_read_delta_q(dec, cdfs, rmi, cmi, false, skip);
19464+ maybe_read_delta_lf(dec, cdfs, rmi, cmi, false, skip);
19465+ let (has_above, has_left) = (
19466+ rmi > neighbours.tile_row0_mi,
19467+ cmi > neighbours.tile_col0_mi,
1946719468 );
19468- }
19469-
19470- let mode_for_tx;
19471- // lane-uv8 r1: this leaf's chroma prediction mode (`get_uv_mode` of the
19472- // coded `uv_mode`), for the neighbour bands at the tail. An INTER leaf
19473- // stores `UV_DC_PRED`, exactly as [`decode_inter_block`] one level up.
19474- let mut uv_predict_mode = DC_PRED;
19475- let (luma_grid, u_grid, v_grid);
19476- let mut compound_ctx8: Option<(i8, i8, u8, u8)> = None;
19477- // lane-inter8 r1: this leaf's own resolved references, handed back so the
19478- // NEXT leaf of the same 16x16 can use them as its real above/left
19479- // neighbour (`Neighbours`' arrays only move once per 16x16 block).
19480- // `(0, None)` is intra.
19481- let mut leaf_refs: (i8, Option<i8>) = (0, None);
19482- if is_inter {
19483- if reference_select || skip_mode {
19484- // lane-inter8 r1: the REAL neighbour references, not a
19485- // `LAST_FRAME`-or-intra stand-in. `av1_get_reference_mode_context`
19486- // and `read_compound_ref_frames`' own contexts both ask whether a
19487- // neighbour is COMPOUND, so pretending every inter neighbour is
19488- // single-ref LAST picked the wrong `comp_mode` CDF row -- measured
19489- // as an 8x8 leaf reading single-ref where aomdec read compound
19490- // NEAR_NEWMV (mi 4,14).
19491- let above_nbr = has_above.then(|| NeighbourRef {
19492- is_inter: above_inter,
19493- ref0: if above_inter { above_ref0 } else { 0 },
19494- ref1: above_ref1,
19495- uni: above_ref1.is_some_and(|r1| is_uni_comp_ref(above_ref0, r1)),
19496- });
19497- let left_nbr = has_left.then(|| NeighbourRef {
19498- is_inter: left_inter,
19499- ref0: if left_inter { left_ref0 } else { 0 },
19500- ref1: left_ref1,
19501- uni: left_ref1.is_some_and(|r1| is_uni_comp_ref(left_ref0, r1)),
19502- });
19503- if skip_mode || read_comp_mode(dec, cdfs, above_nbr, left_nbr) {
19504- let (ref0, ref1) = if skip_mode {
19469+ let ii_ctx = intra_inter_ctx(
19470+ has_above,
19471+ has_left,
19472+ neighbours.above_inter[cmi],
19473+ neighbours.left_inter[rmi],
19474+ );
19475+ let is_inter = dec.symbol(&mut cdfs.intra_inter[ii_ctx]) == 1;
19476+ if !is_inter {
19477+ return Err(unsupported(
19478+ "an intra 4x4 block inside an inter frame's sub-8x8 split (this decoder codes \
19479+ only inter 4x4 sub-blocks there)",
19480+ ));
19481+ }
19482+ // Same print point as the oracle's `EC_MODE` (entry of
19483+ // `read_inter_block_mode_info`, i.e. after skip / is_inter), so the
19484+ // two range ladders line up element for element.
19485+ if std::env::var_os("EC_TRACE_MODE").is_some() {
19486+ eprintln!(
19487+ "EC_MODE mi_row={rmi} mi_col={cmi} rng={}",
19488+ dec.debug_state().0
19489+ );
19490+ }
19491+ let ref_frame = read_single_ref(
19492+ dec,
19493+ cdfs,
19494+ neighbours.above_ref[cmi],
19495+ neighbours.above_ref1[cmi],
19496+ neighbours.left_ref[rmi],
19497+ neighbours.left_ref1[rmi],
19498+ );
19499+ let (sref_y, sref_u, sref_v) = ref_planes(ref_frame, ref_y, ref_u, ref_v, other_refs)?;
19500+ if mc::scale_factor(sref_y.width, frame_width) != mc::REF_NO_SCALE {
19501+ return Err(unsupported(
19502+ "a sub-8x8 inter block under a scaled reference (superres, unimplemented)",
19503+ ));
19504+ }
19505+ let gm_table = build_gm_mv_table(
19506+ global_motion,
19507+ rmi,
19508+ cmi,
19509+ 1,
19510+ 1,
19511+ allow_high_precision_mv,
19512+ force_integer_mv,
19513+ );
19514+ let tpl = tpl_frame.map(|t| crate::mvstack::TplArgs {
19515+ field: t.field,
19516+ cur_offset_0: crate::motion_field::get_relative_dist(
19517+ t.order_hint_bits,
19518+ t.order_hint,
19519+ t.ref_order_hints[(ref_frame - LAST_FRAME) as usize],
19520+ ),
19521+ allow_high_precision_mv,
19522+ });
19523+ let stack = crate::mvstack::find_mv_stack_with_sign_bias(
19524+ grid,
19525+ rmi,
19526+ cmi,
19527+ 1,
19528+ 1,
19529+ ref_frame,
19530+ mi_cols as usize,
19531+ mi_rows as usize,
19532+ sign_bias_table,
19533+ &gm_table,
19534+ tpl,
19535+ );
19536+ let not_new = dec.symbol(&mut cdfs.new_mv[stack.new_mv_ctx]) == 1;
19537+ let mut is_globalmv = false;
19538+ let (mv, is_new_mv) = if !not_new {
19539+ let mut idx = 0usize;
19540+ while idx < 2 && stack.entries.len() > idx + 1 {
19541+ if dec.symbol(&mut cdfs.drl_mode[stack.drl_ctx[idx]]) == 0 {
19542+ break;
19543+ }
19544+ idx += 1;
19545+ }
19546+ let base_mv = stack.entries.get(idx).map_or(stack.pred_mv, |e| e.mv);
19547+ (
19548+ read_mv(
19549+ dec,
19550+ &mut cdfs.mv_comp,
19551+ &mut cdfs.mv_joint,
19552+ base_mv,
19553+ allow_high_precision_mv,
19554+ force_integer_mv,
19555+ ),
19556+ true,
19557+ )
19558+ } else {
19559+ let not_zero = dec.symbol(&mut cdfs.zero_mv[stack.zero_mv_ctx]) == 1;
19560+ is_globalmv = !not_zero;
19561+ let mv = if !not_zero {
19562+ gm_table[(ref_frame - LAST_FRAME) as usize]
19563+ } else {
19564+ let nearest = dec.symbol(&mut cdfs.ref_mv[stack.ref_mv_ctx]) == 0;
19565+ if nearest {
19566+ stack.nearest_mv
19567+ } else {
19568+ let mut idx = 1usize;
19569+ while idx < 3 && stack.entries.len() > idx + 1 {
19570+ if dec.symbol(&mut cdfs.drl_mode[stack.drl_ctx[idx]]) == 0 {
19571+ break;
19572+ }
19573+ idx += 1;
19574+ }
19575+ stack.entries.get(idx).map_or(stack.near_mv, |e| e.mv)
19576+ }
19577+ };
19578+ (mv, false)
19579+ };
19580+ // Same print point as the oracle's `EC_MODE_MV` (right after
19581+ // `assign_mv`), the second rung of the sub-8x8 range ladder.
19582+ if std::env::var_os("EC_TRACE_MODE").is_some() {
19583+ eprintln!(
19584+ "EC_MODE_MV mi_row={rmi} mi_col={cmi} mv0=({},{}) rng={}",
19585+ mv.0,
19586+ mv.1,
19587+ dec.debug_state().0
19588+ );
19589+ }
19590+ // No `interintra` and no `motion_mode`/`obmc` symbol below 8x8 (see
19591+ // this function's own doc); `read_mb_interp_filter` still runs.
19592+ let gm_ref = &global_motion[(ref_frame - LAST_FRAME) as usize];
19593+ let above_filter_ctx = if neighbours.above_ref[cmi] == ref_frame
19594+ || neighbours.above_ref1[cmi] == Some(ref_frame)
19595+ {
19596+ neighbours.above_filter[cmi]
19597+ } else {
19598+ [3, 3]
19599+ };
19600+ let left_filter_ctx = if neighbours.left_ref[rmi] == ref_frame
19601+ || neighbours.left_ref1[rmi] == Some(ref_frame)
19602+ {
19603+ neighbours.left_filter[rmi]
19604+ } else {
19605+ [3, 3]
19606+ };
19607+ if std::env::var_os("EC_AV1_IFDBG").is_some() {
19608+ eprintln!(
19609+ "IFDBG4 mi=({rmi},{cmi}) ref={ref_frame} above_ref={} above_ref1={:?} \
19610+ above_filt={:?} left_ref={} left_ref1={:?} left_filt={:?}",
19611+ neighbours.above_ref[cmi],
19612+ neighbours.above_ref1[cmi],
19613+ neighbours.above_filter[cmi],
19614+ neighbours.left_ref[rmi],
19615+ neighbours.left_ref1[rmi],
19616+ neighbours.left_filter[rmi],
19617+ );
19618+ }
19619+ let gm_nontrans = is_globalmv && gm_ref.model != ec_av1_syntax::WarpModel::Translation;
19620+ let (h_filter, v_filter, resolved_filter) = resolve_interp_filter(
19621+ dec,
19622+ cdfs,
19623+ interp_fixed,
19624+ enable_dual_filter,
19625+ gm_nontrans,
19626+ above_filter_ctx,
19627+ left_filter_ctx,
19628+ false,
19629+ );
19630+ if std::env::var_os("EC_TRACE_MODE").is_some() {
19631+ eprintln!(
19632+ "EC_MODE_VAL4 mi_row={rmi} mi_col={cmi} newmv={is_new_mv} globalmv={is_globalmv} \
19633+ ref0={ref_frame} mv0=({},{}) stack={} rng={}",
19634+ mv.0,
19635+ mv.1,
19636+ stack.entries.len(),
19637+ dec.debug_state().0
19638+ );
19639+ }
19640+ grid.set(
19641+ rmi,
19642+ cmi,
19643+ MiInfo {
19644+ is_inter: true,
19645+ ref_frame,
19646+ ref_frame1: None,
19647+ mv1: None,
19648+ mv,
19649+ is_new_mv,
19650+ size: 1,
19651+ size_h: 1,
19652+ is_global_mv0: false,
19653+ is_global_mv1: false,
19654+ },
19655+ );
19656+ piece[i] = Some((ref_frame, mv, h_filter, v_filter));
19657+ let mut pred_y = vec![0u16; B4 * B4];
19658+ mc::predict_with_filters(
19659+ &sref_y.data,
19660+ sref_y.width,
19661+ sref_y.true_width,
19662+ sref_y.true_height,
19663+ mv_to_q4(px, mv.1, true),
19664+ mv_to_q4(py, mv.0, true),
19665+ B4,
19666+ B4,
19667+ h_filter,
19668+ v_filter,
19669+ &mut pred_y,
19670+ );
19671+ // `BLOCK_4X4` never signals a transform size, so the luma unit is the
19672+ // whole block and `get_txb_ctx` takes its `plane_bsize ==
19673+ // txsize_to_bsize[tx_size]` branch (`txb_skip_ctx = 0`, which
19674+ // `read_inter_plane`'s `plane_idx == 0` arm already assumes).
19675+ if skip {
19676+ y.reconstruct_mc(px, py, B4, &pred_y, &vec![0i32; B4 * B4]);
19677+ neighbours.record_mi_luma_rect(lmi, B4, B4, &vec![0i32; B4 * B4]);
19678+ } else {
19679+ let around = neighbours.around_mi(lmi, B4);
19680+ let (luma_grid, tx_type) = read_inter_plane(
19681+ dec,
19682+ cdfs,
19683+ if reduced_tx_set {
19684+ TxbSet::Luma4Inter
19685+ } else {
19686+ TxbSet::Luma4InterSet1
19687+ },
19688+ scan4,
19689+ 0,
19690+ around[0],
19691+ 0,
19692+ y,
19693+ px,
19694+ py,
19695+ B4,
19696+ base_q_idx,
19697+ &pred_y,
19698+ None,
19699+ None,
19700+ )?;
19701+ if i == 0 {
19702+ // `av1_get_tx_type`: an inter block's chroma inherits the
19703+ // tx_type of the CO-LOCATED luma position, which for the
19704+ // group's one chroma unit is luma (0, 0) -- the FIRST
19705+ // sub-block, not the last.
19706+ first_tx_type = tx_type;
19707+ }
19708+ neighbours.record_mi_luma_rect(lmi, B4, B4, &luma_grid);
19709+ }
19710+ neighbours.record_mode_mi(rmi, cmi, 1, 1, DC_PRED);
19711+ neighbours.record_inter_rect_mi(lmi, 1, 1, skip, true, ref_frame, resolved_filter, false);
19712+ neighbours.fill_skip_grid_rect(lmi, 1, 1, skip);
19713+ neighbours.fill_lf_grid_rect(lmi, 1, 1, B4 as u8, B4 as u8, ref_frame.max(LAST_FRAME));
19714+ last_skip = skip;
19715+ }
19716+ // Chroma, once for the whole group, on the last sub-block's own `skip`
19717+ // flag -- prediction from all four sub-blocks (2x2 pieces), residual as
19718+ // one TX_4X4 unit per plane.
19719+ let mut pred_u = vec![0u16; B4 * B4];
19720+ let mut pred_v = vec![0u16; B4 * B4];
19721+ for i in 0..4usize {
19722+ let (dr, dc) = (i / 2, i % 2);
19723+ let Some((ref_frame, mv, h_filter, v_filter)) = piece[i] else {
19724+ continue;
19725+ };
19726+ let (_, sref_u, sref_v) = ref_planes(ref_frame, ref_y, ref_u, ref_v, other_refs)?;
19727+ let (ox, oy) = (cpx + dc * 2, cpy + dr * 2);
19728+ for (plane, dst) in [(sref_u, &mut pred_u), (sref_v, &mut pred_v)] {
19729+ let mut buf = vec![0u16; 4];
19730+ mc::predict_with_filters(
19731+ &plane.data,
19732+ plane.width,
19733+ plane.true_width,
19734+ plane.true_height,
19735+ mv_to_q4(ox, mv.1, false),
19736+ mv_to_q4(oy, mv.0, false),
19737+ 2,
19738+ 2,
19739+ h_filter,
19740+ v_filter,
19741+ &mut buf,
19742+ );
19743+ for row in 0..2 {
19744+ for col in 0..2 {
19745+ dst[(dr * 2 + row) * B4 + dc * 2 + col] = buf[row * 2 + col];
19746+ }
19747+ }
19748+ }
19749+ }
19750+ let (u_grid, v_grid) = if last_skip {
19751+ u.reconstruct_mc(cpx, cpy, B4, &pred_u, &vec![0i32; B4 * B4]);
19752+ v.reconstruct_mc(cpx, cpy, B4, &pred_v, &vec![0i32; B4 * B4]);
19753+ (vec![0i32; B4 * B4], vec![0i32; B4 * B4])
19754+ } else {
19755+ let around = neighbours.around_mi(group_mi, 8);
19756+ let ug = read_inter_plane(
19757+ dec, cdfs, TxbSet::Chroma4, scan4, 1, around[1], 0, u, cpx, cpy, B4, base_q_idx,
19758+ &pred_u, Some(first_tx_type), None,
19759+ )?
19760+ .0;
19761+ let vg = read_inter_plane(
19762+ dec, cdfs, TxbSet::Chroma4, scan4, 2, around[2], 0, v, cpx, cpy, B4, base_q_idx,
19763+ &pred_v, Some(first_tx_type), None,
19764+ )?
19765+ .0;
19766+ (ug, vg)
19767+ };
19768+ neighbours.record_uv_mode_mi(gr, gc, 2, 2, DC_PRED);
19769+ // Same two neighbour tails [`decode_leaf_split4`] runs: the partition
19770+ // context of a `BLOCK_4X4` subsize (`partition_context_lookup` bit 0 = 1,
19771+ // reached by `side_mi = 4` here) and the group's chroma coefficient state.
19772+ for cell in 0..2usize {
19773+ neighbours.left_side_mi[gr + cell] = 4;
19774+ neighbours.above_side_mi[gc + cell] = 4;
19775+ }
19776+ let round_up_even = |n: usize| n.div_ceil(2) * 2;
19777+ let bound_h = round_up_even(neighbours.mi_rows);
19778+ let bound_w = round_up_even(neighbours.mi_cols);
19779+ let u_state = neighbour_state(&u_grid);
19780+ let v_state = neighbour_state(&v_grid);
19781+ for cell in 0..2usize {
19782+ if cell < 2usize.min(bound_h.saturating_sub(gr)) {
19783+ neighbours.left[gr + cell][1] = u_state;
19784+ neighbours.left[gr + cell][2] = v_state;
19785+ }
19786+ if cell < 2usize.min(bound_w.saturating_sub(gc)) {
19787+ neighbours.above[gc + cell][1] = u_state;
19788+ neighbours.above[gc + cell][2] = v_state;
19789+ }
19790+ }
19791+ Ok(())
19792+}
19793+
19794+/// Decodes a `PARTITION_HORZ`/`PARTITION_VERT` of one 8x8 INTER block into two
19795+/// `BLOCK_8X4`/`BLOCK_4X8` inter leaves (lane-intersub8 r3) -- the inter twin of
19796+/// [`decode_leaf_rect8`] and the rectangular sibling of
19797+/// [`decode_inter_sub8_split4`], whose element order it follows exactly.
19798+/// Per sub-block, in libaom `decodemv.c` `read_inter_frame_mode_info` order:
19799+///
19800+/// * `segment_id`, `skip`, `cdef`/`delta_q`/`delta_lf`, `intra_inter`;
19801+/// * NO `skip_mode` symbol: `is_comp_ref_allowed(BLOCK_8X4)` is false
19802+/// (`av1_is_comp_ref_allowed` needs both sides >= 8), so
19803+/// `read_skip_mode` returns 0 without reading and `comp_mode` is never read
19804+/// either (`read_ref_frames`' `is_comp_ref_allowed` guard) -- single
19805+/// reference only;
19806+/// * NO `interintra` and NO `motion_mode`/OBMC/warp symbol: every one of those
19807+/// gates needs `block_size_wide >= 8 && block_size_high >= 8`
19808+/// (`is_interintra_allowed_bsize`, `motion_mode_allowed`), and one side is 4;
19809+/// * `read_mb_interp_filter` DOES run for both sub-blocks.
19810+///
19811+/// The shape's own differences from the four-way split:
19812+///
19813+/// * `block_signals_txsize(BLOCK_8X4)` is true (`bsize > BLOCK_4X4`,
19814+/// blockd.h:1027), so a non-skipped sub-block reads ONE `txfm_partition`
19815+/// symbol under `TX_MODE_SELECT` at `max_txsize_rect_lookup[BLOCK_8X4] ==
19816+/// TX_8X4` ([`read_var_tx_size`]); split resolves to two `TX_4X4` units
19817+/// (`sub_tx_size_map[TX_8X4] == TX_4X4`, libaom's early return), no split to
19818+/// the whole-leaf `TX_8X4`;
19819+/// * the luma coefficient set is [`TxbSet::LumaRect8x4Inter`] (the 8x8
19820+/// coefficient class with a 32-position `eob_pt` and the INTER `TX_4X4`
19821+/// `tx_type` row) for the whole-leaf unit, and the square
19822+/// [`TxbSet::Luma4Inter`] for a split `TX_4X4` unit;
19823+/// * chroma is coded ONCE, on the sub-block that is the chroma reference:
19824+/// `is_chroma_reference` (`av1_common_int.h`) is
19825+/// `((mi_row & 1) || !(bh4 & 1) || !ss_y) && ((mi_col & 1) || !(bw4 & 1) ||
19826+/// !ss_x)`, i.e. under 4:2:0 the BOTTOM 8x4 (`bh4 == 1`, odd) and the RIGHT
19827+/// 4x8 (`bw4 == 1`) -- always the second sub-block here;
19828+/// * that chroma unit's prediction is the sub8x8 one (`reconinter.c`
19829+/// `build_inter_predictors_sub8x8`: `row_start = -(block_size_high == 4 &&
19830+/// ss_y)`, `col_start = -(block_size_wide == 4 && ss_x)`), two 4x2 (HORZ) or
19831+/// 2x4 (VERT) chroma pieces, each from its OWN sub-block's reference, mv and
19832+/// interpolation filters.
19833+#[allow(clippy::too_many_arguments)]
19834+fn decode_inter_sub8_rect2(
19835+ dec: &mut SymbolDecoder,
19836+ cdfs: &mut Cdfs,
19837+ neighbours: &mut Neighbours,
19838+ grid: &mut MiGrid,
19839+ group_mi: (usize, usize),
19840+ vert: bool,
19841+ mi_cols: u32,
19842+ mi_rows: u32,
19843+ y: &mut PlaneBuf,
19844+ u: &mut PlaneBuf,
19845+ v: &mut PlaneBuf,
19846+ ref_y: &PlaneBuf,
19847+ ref_u: &PlaneBuf,
19848+ ref_v: &PlaneBuf,
19849+ other_refs: &RefSlots,
19850+ sign_bias_table: &SignBiasTable,
19851+ global_motion: &[ec_av1_syntax::WarpParams; 7],
19852+ base_q_idx: u8,
19853+ scan4: &[u16],
19854+ allow_high_precision_mv: bool,
19855+ force_integer_mv: bool,
19856+ interp_fixed: Option<mc::InterpFilterKind>,
19857+ enable_dual_filter: bool,
19858+ tpl_frame: Option<&TplFrameArgs>,
19859+ reduced_tx_set: bool,
19860+ frame_width: usize,
19861+) -> Result<()> {
19862+ const LAST_FRAME: i8 = 1;
19863+ // The 8x8 group's own square stride: both leaves' prediction buffers are
19864+ // laid out at it, as every other rect inter unit here is.
19865+ const SIDE: usize = 8;
19866+ let (bw, bh) = if vert { (4usize, 8usize) } else { (8usize, 4usize) };
19867+ let (w_mi, h_mi) = (bw / MI, bh / MI);
19868+ SUB8_INTER_RECT_HITS.with(|c| {
19869+ let mut h = c.get();
19870+ h[usize::from(vert)] += 1;
19871+ c.set(h);
19872+ });
19873+ let (gr, gc) = group_mi;
19874+ let (gpx, gpy) = (gc * MI, gr * MI);
19875+ let (cpx, cpy) = (gpx / 2, gpy / 2);
19876+ // Per-sub-block state the group's one chroma unit predicts from.
19877+ let mut piece: [Option<(i8, (i32, i32), mc::InterpFilterKind, mc::InterpFilterKind)>; 2] =
19878+ [None; 2];
19879+ let mut first_tx_type = TxType::DctDct;
19880+ let mut last_skip = true;
19881+ for i in 0..2usize {
19882+ let lmi = if vert { (gr, gc + i) } else { (gr + i, gc) };
19883+ if lmi.0 >= mi_rows as usize || lmi.1 >= mi_cols as usize {
19884+ continue;
19885+ }
19886+ let (rmi, cmi) = lmi;
19887+ let (px, py) = (cmi * MI, rmi * MI);
19888+ inter_segment_id(dec, cdfs, rmi, cmi, w_mi, h_mi, false, true);
19889+ let skip_ctx =
19890+ usize::from(neighbours.above_skip[cmi]) + usize::from(neighbours.left_skip[rmi]);
19891+ let skip = dec.symbol(&mut cdfs.skip[skip_ctx]) == 1;
19892+ inter_segment_id(dec, cdfs, rmi, cmi, w_mi, h_mi, skip, false);
19893+ maybe_read_cdef_idx(dec, rmi, cmi, skip);
19894+ maybe_read_delta_q(dec, cdfs, rmi, cmi, false, skip);
19895+ maybe_read_delta_lf(dec, cdfs, rmi, cmi, false, skip);
19896+ let (has_above, has_left) = (
19897+ rmi > neighbours.tile_row0_mi,
19898+ cmi > neighbours.tile_col0_mi,
19899+ );
19900+ let ii_ctx = intra_inter_ctx(
19901+ has_above,
19902+ has_left,
19903+ neighbours.above_inter[cmi],
19904+ neighbours.left_inter[rmi],
19905+ );
19906+ let is_inter = dec.symbol(&mut cdfs.intra_inter[ii_ctx]) == 1;
19907+ if !is_inter {
19908+ return Err(unsupported(
19909+ "an intra 8x4/4x8 block inside an inter frame's sub-8x8 HORZ/VERT partition \
19910+ (this decoder codes only inter sub-blocks there)",
19911+ ));
19912+ }
19913+ if std::env::var_os("EC_TRACE_MODE").is_some() {
19914+ eprintln!(
19915+ "EC_MODE mi_row={rmi} mi_col={cmi} rng={}",
19916+ dec.debug_state().0
19917+ );
19918+ }
19919+ let ref_frame = read_single_ref(
19920+ dec,
19921+ cdfs,
19922+ neighbours.above_ref[cmi],
19923+ neighbours.above_ref1[cmi],
19924+ neighbours.left_ref[rmi],
19925+ neighbours.left_ref1[rmi],
19926+ );
19927+ let (sref_y, _, _) = ref_planes(ref_frame, ref_y, ref_u, ref_v, other_refs)?;
19928+ if mc::scale_factor(sref_y.width, frame_width) != mc::REF_NO_SCALE {
19929+ return Err(unsupported(
19930+ "a sub-8x8 inter block under a scaled reference (superres, unimplemented)",
19931+ ));
19932+ }
19933+ let gm_table = build_gm_mv_table(
19934+ global_motion,
19935+ rmi,
19936+ cmi,
19937+ w_mi,
19938+ h_mi,
19939+ allow_high_precision_mv,
19940+ force_integer_mv,
19941+ );
19942+ let tpl = tpl_frame.map(|t| crate::mvstack::TplArgs {
19943+ field: t.field,
19944+ cur_offset_0: crate::motion_field::get_relative_dist(
19945+ t.order_hint_bits,
19946+ t.order_hint,
19947+ t.ref_order_hints[(ref_frame - LAST_FRAME) as usize],
19948+ ),
19949+ allow_high_precision_mv,
19950+ });
19951+ let stack = crate::mvstack::find_mv_stack_with_sign_bias(
19952+ grid,
19953+ rmi,
19954+ cmi,
19955+ w_mi,
19956+ h_mi,
19957+ ref_frame,
19958+ mi_cols as usize,
19959+ mi_rows as usize,
19960+ sign_bias_table,
19961+ &gm_table,
19962+ tpl,
19963+ );
19964+ let not_new = dec.symbol(&mut cdfs.new_mv[stack.new_mv_ctx]) == 1;
19965+ let mut is_globalmv = false;
19966+ let (mv, is_new_mv) = if !not_new {
19967+ let mut idx = 0usize;
19968+ while idx < 2 && stack.entries.len() > idx + 1 {
19969+ if dec.symbol(&mut cdfs.drl_mode[stack.drl_ctx[idx]]) == 0 {
19970+ break;
19971+ }
19972+ idx += 1;
19973+ }
19974+ let base_mv = stack.entries.get(idx).map_or(stack.pred_mv, |e| e.mv);
19975+ (
19976+ read_mv(
19977+ dec,
19978+ &mut cdfs.mv_comp,
19979+ &mut cdfs.mv_joint,
19980+ base_mv,
19981+ allow_high_precision_mv,
19982+ force_integer_mv,
19983+ ),
19984+ true,
19985+ )
19986+ } else {
19987+ let not_zero = dec.symbol(&mut cdfs.zero_mv[stack.zero_mv_ctx]) == 1;
19988+ is_globalmv = !not_zero;
19989+ let mv = if !not_zero {
19990+ gm_table[(ref_frame - LAST_FRAME) as usize]
19991+ } else {
19992+ let nearest = dec.symbol(&mut cdfs.ref_mv[stack.ref_mv_ctx]) == 0;
19993+ if nearest {
19994+ stack.nearest_mv
19995+ } else {
19996+ let mut idx = 1usize;
19997+ while idx < 3 && stack.entries.len() > idx + 1 {
19998+ if dec.symbol(&mut cdfs.drl_mode[stack.drl_ctx[idx]]) == 0 {
19999+ break;
20000+ }
20001+ idx += 1;
20002+ }
20003+ stack.entries.get(idx).map_or(stack.near_mv, |e| e.mv)
20004+ }
20005+ };
20006+ (mv, false)
20007+ };
20008+ if std::env::var_os("EC_TRACE_MODE").is_some() {
20009+ eprintln!(
20010+ "EC_MODE_MV mi_row={rmi} mi_col={cmi} mv0=({},{}) rng={}",
20011+ mv.0,
20012+ mv.1,
20013+ dec.debug_state().0
20014+ );
20015+ }
20016+ let gm_ref = &global_motion[(ref_frame - LAST_FRAME) as usize];
20017+ let above_filter_ctx = if neighbours.above_ref[cmi] == ref_frame
20018+ || neighbours.above_ref1[cmi] == Some(ref_frame)
20019+ {
20020+ neighbours.above_filter[cmi]
20021+ } else {
20022+ [3, 3]
20023+ };
20024+ let left_filter_ctx = if neighbours.left_ref[rmi] == ref_frame
20025+ || neighbours.left_ref1[rmi] == Some(ref_frame)
20026+ {
20027+ neighbours.left_filter[rmi]
20028+ } else {
20029+ [3, 3]
20030+ };
20031+ let gm_nontrans = is_globalmv && gm_ref.model != ec_av1_syntax::WarpModel::Translation;
20032+ let (h_filter, v_filter, resolved_filter) = resolve_interp_filter(
20033+ dec,
20034+ cdfs,
20035+ interp_fixed,
20036+ enable_dual_filter,
20037+ gm_nontrans,
20038+ above_filter_ctx,
20039+ left_filter_ctx,
20040+ false,
20041+ );
20042+ // `read_block_tx_size` (libaom `decodeframe.c`): unlike a `BLOCK_4X4`,
20043+ // this shape signals its transform size. A non-skipped inter block
20044+ // walks the var-tx tree from `max_txsize_rect_lookup[BLOCK_8X4]`; a
20045+ // skipped one codes nothing and records its BLOCK size in both txfm
20046+ // contexts (`set_txfm_ctxs`' `skip_inter` arm).
20047+ let mut leaves: Vec<(usize, usize, usize, usize)> = Vec::new();
20048+ if TX_SELECT_INTER.with(std::cell::Cell::get) && !skip {
20049+ let max_w_mi = w_mi.min((mi_cols as usize).saturating_sub(cmi));
20050+ let max_h_mi = h_mi.min((mi_rows as usize).saturating_sub(rmi));
20051+ read_var_tx_size(
20052+ dec,
20053+ cdfs,
20054+ neighbours,
20055+ lmi,
20056+ SIDE,
20057+ (max_w_mi, max_h_mi),
20058+ (bw, bh),
20059+ 0,
20060+ 0,
20061+ 0,
20062+ &mut leaves,
20063+ );
20064+ } else {
20065+ leaves.push((0, 0, bw, bh));
20066+ set_txfm_ctxs(neighbours, lmi, bw.max(bh), w_mi, h_mi, skip);
20067+ }
20068+ if std::env::var_os("EC_TRACE_MODE").is_some() {
20069+ eprintln!(
20070+ "EC_MODE_VALR mi_row={rmi} mi_col={cmi} newmv={is_new_mv} globalmv={is_globalmv} \
20071+ ref0={ref_frame} mv0=({},{}) stack={} leaves={} rng={}",
20072+ mv.0,
20073+ mv.1,
20074+ stack.entries.len(),
20075+ leaves.len(),
20076+ dec.debug_state().0
20077+ );
20078+ }
20079+ grid_stamp_rect(grid, rmi, cmi, w_mi, h_mi, ref_frame, mv, is_new_mv);
20080+ piece[i] = Some((ref_frame, mv, h_filter, v_filter));
20081+ // Prediction over the leaf's true footprint, laid out at the group's
20082+ // square stride (what `reconstruct_mc_rect` and `read_inter_plane_rect`
20083+ // index with).
20084+ let mut pred_y = vec![0u16; SIDE * SIDE];
20085+ {
20086+ let mut dense = vec![0u16; bw * bh];
20087+ mc::predict_with_filters(
20088+ &sref_y.data,
20089+ sref_y.width,
20090+ sref_y.true_width,
20091+ sref_y.true_height,
20092+ mv_to_q4(px, mv.1, true),
20093+ mv_to_q4(py, mv.0, true),
20094+ bw,
20095+ bh,
20096+ h_filter,
20097+ v_filter,
20098+ &mut dense,
20099+ );
20100+ for row in 0..bh {
20101+ pred_y[row * SIDE..][..bw].copy_from_slice(&dense[row * bw..][..bw]);
20102+ }
20103+ }
20104+ if skip {
20105+ y.reconstruct_mc_rect(px, py, SIDE, bw, bh, &pred_y, &vec![0i32; SIDE * SIDE]);
20106+ neighbours.record_mi_luma_rect(lmi, bw, bh, &vec![0i32; bw * bh]);
20107+ neighbours.fill_lf_grid_rect(lmi, w_mi, h_mi, bw as u8, bh as u8, ref_frame.max(LAST_FRAME));
20108+ } else {
20109+ let (mut last_tw, mut last_th) = (bw, bh);
20110+ for (idx, &(row, col, tw, th)) in leaves.iter().enumerate() {
20111+ let tu_mi = (rmi + row, cmi + col);
20112+ let (tu_px, tu_py) = (px + col * MI, py + row * MI);
20113+ let (tu_grid, tu_tx_type) = if tw == th {
20114+ // A split `TX_4X4` unit: square reader, its own
20115+ // `get_txb_ctx_general` neighbour context (the unit is
20116+ // smaller than its plane block, so the lone-TU 0 does not
20117+ // apply).
20118+ let mut tu_pred = Vec::with_capacity(tw * th);
20119+ for rr in 0..th {
20120+ let start = (row * MI + rr) * SIDE + col * MI;
20121+ tu_pred.extend_from_slice(&pred_y[start..start + tw]);
20122+ }
20123+ let tu_skip_ctx = neighbours.luma_skip_ctx_rect(tu_mi, tw / MI, th / MI);
20124+ read_inter_plane(
20125+ dec,
20126+ cdfs,
20127+ if reduced_tx_set {
20128+ TxbSet::Luma4Inter
20129+ } else {
20130+ TxbSet::Luma4InterSet1
20131+ },
20132+ scan4,
20133+ 0,
20134+ neighbours.around_mi(tu_mi, tw)[0],
20135+ 0,
20136+ y,
20137+ tu_px,
20138+ tu_py,
20139+ tw,
20140+ base_q_idx,
20141+ &tu_pred,
20142+ None,
20143+ Some(tu_skip_ctx),
20144+ )?
20145+ } else {
20146+ // The whole leaf as one `TX_8X4`/`TX_4X8` unit: it IS the
20147+ // plane block, so `get_txb_ctx_general` fixes `txb_skip_ctx`
20148+ // at 0 (`luma_skip_ctx: None`).
20149+ let start = row * MI * SIDE + col * MI;
20150+ read_inter_plane_rect(
20151+ dec,
20152+ cdfs,
20153+ if reduced_tx_set {
20154+ TxbSet::LumaRect8x4Inter
20155+ } else {
20156+ TxbSet::LumaRect8x4InterSet1
20157+ },
20158+ (tw, th),
20159+ SIDE,
20160+ 0,
20161+ neighbours.around_mi_rect(tu_mi, tw, th)[0],
20162+ 0,
20163+ y,
20164+ tu_px,
20165+ tu_py,
20166+ &pred_y[start..],
20167+ None,
20168+ None,
20169+ )?
20170+ };
20171+ if idx == 0 {
20172+ // `av1_get_tx_type`: the group's one chroma unit scales
20173+ // back to luma (0, 0), i.e. the FIRST sub-block's first
20174+ // transform unit.
20175+ first_tx_type = tu_tx_type;
20176+ }
20177+ neighbours.record_mi_luma_rect(tu_mi, tw, th, &tu_grid);
20178+ (last_tw, last_th) = (tw, th);
20179+ }
20180+ neighbours.fill_lf_grid_rect(
20181+ lmi,
20182+ w_mi,
20183+ h_mi,
20184+ last_tw as u8,
20185+ last_th as u8,
20186+ ref_frame.max(LAST_FRAME),
20187+ );
20188+ }
20189+ neighbours.record_mode_mi(rmi, cmi, w_mi, h_mi, DC_PRED);
20190+ neighbours.record_inter_rect_mi(lmi, w_mi, h_mi, skip, true, ref_frame, resolved_filter, false);
20191+ neighbours.fill_skip_grid_rect(lmi, w_mi, h_mi, skip);
20192+ last_skip = skip;
20193+ }
20194+ // The group's single 4x4 chroma unit per plane, on the chroma-reference
20195+ // (second) sub-block's own skip flag.
20196+ const B4: usize = 4;
20197+ let mut pred_u = vec![0u16; B4 * B4];
20198+ let mut pred_v = vec![0u16; B4 * B4];
20199+ let (piece_w, piece_h) = if vert { (2usize, 4usize) } else { (4usize, 2usize) };
20200+ for i in 0..2usize {
20201+ let Some((ref_frame, mv, h_filter, v_filter)) = piece[i] else {
20202+ continue;
20203+ };
20204+ let (_, sref_u, sref_v) = ref_planes(ref_frame, ref_y, ref_u, ref_v, other_refs)?;
20205+ let (ox, oy) = if vert {
20206+ (cpx + i * piece_w, cpy)
20207+ } else {
20208+ (cpx, cpy + i * piece_h)
20209+ };
20210+ let (dc, dr) = if vert { (i * piece_w, 0) } else { (0, i * piece_h) };
20211+ for (plane, dst) in [(sref_u, &mut pred_u), (sref_v, &mut pred_v)] {
20212+ let mut buf = vec![0u16; piece_w * piece_h];
20213+ mc::predict_with_filters(
20214+ &plane.data,
20215+ plane.width,
20216+ plane.true_width,
20217+ plane.true_height,
20218+ mv_to_q4(ox, mv.1, false),
20219+ mv_to_q4(oy, mv.0, false),
20220+ piece_w,
20221+ piece_h,
20222+ h_filter,
20223+ v_filter,
20224+ &mut buf,
20225+ );
20226+ for row in 0..piece_h {
20227+ for col in 0..piece_w {
20228+ dst[(dr + row) * B4 + dc + col] = buf[row * piece_w + col];
20229+ }
20230+ }
20231+ }
20232+ }
20233+ let (u_grid, v_grid) = if last_skip {
20234+ u.reconstruct_mc(cpx, cpy, B4, &pred_u, &vec![0i32; B4 * B4]);
20235+ v.reconstruct_mc(cpx, cpy, B4, &pred_v, &vec![0i32; B4 * B4]);
20236+ (vec![0i32; B4 * B4], vec![0i32; B4 * B4])
20237+ } else {
20238+ let around = neighbours.around_mi(group_mi, 8);
20239+ let ug = read_inter_plane(
20240+ dec, cdfs, TxbSet::Chroma4, scan4, 1, around[1], 0, u, cpx, cpy, B4, base_q_idx,
20241+ &pred_u, Some(first_tx_type), None,
20242+ )?
20243+ .0;
20244+ let vg = read_inter_plane(
20245+ dec, cdfs, TxbSet::Chroma4, scan4, 2, around[2], 0, v, cpx, cpy, B4, base_q_idx,
20246+ &pred_v, Some(first_tx_type), None,
20247+ )?
20248+ .0;
20249+ (ug, vg)
20250+ };
20251+ neighbours.record_uv_mode_mi(gr, gc, 2, 2, DC_PRED);
20252+ // `update_partition_context` writes `partition_context_lookup[subsize]`
20253+ // over the whole 8x8 span -- BLOCK_4X8's width above and height left, the
20254+ // same values [`decode_leaf_rect8`] writes for the intra shape.
20255+ for cell in 0..2usize {
20256+ neighbours.above_side_mi[gc + cell] = bw;
20257+ neighbours.left_side_mi[gr + cell] = bh;
20258+ }
20259+ let round_up_even = |n: usize| n.div_ceil(2) * 2;
20260+ let bound_h = round_up_even(neighbours.mi_rows);
20261+ let bound_w = round_up_even(neighbours.mi_cols);
20262+ let u_state = neighbour_state(&u_grid);
20263+ let v_state = neighbour_state(&v_grid);
20264+ for cell in 0..2usize {
20265+ if cell < 2usize.min(bound_h.saturating_sub(gr)) {
20266+ neighbours.left[gr + cell][1] = u_state;
20267+ neighbours.left[gr + cell][2] = v_state;
20268+ }
20269+ if cell < 2usize.min(bound_w.saturating_sub(gc)) {
20270+ neighbours.above[gc + cell][1] = u_state;
20271+ neighbours.above[gc + cell][2] = v_state;
20272+ }
20273+ }
20274+ Ok(())
20275+}
20276+
20277+/// Stamps one sub-8x8 inter leaf into every mi cell of its true `w_mi`x`h_mi`
20278+/// footprint (class: a rect block's grid span is its own, never a square guess).
20279+fn grid_stamp_rect(
20280+ grid: &mut MiGrid,
20281+ mi_row: usize,
20282+ mi_col: usize,
20283+ w_mi: usize,
20284+ h_mi: usize,
20285+ ref_frame: i8,
20286+ mv: (i32, i32),
20287+ is_new_mv: bool,
20288+) {
20289+ for dr in 0..h_mi {
20290+ for dc in 0..w_mi {
20291+ grid.set(
20292+ mi_row + dr,
20293+ mi_col + dc,
20294+ MiInfo {
20295+ is_inter: true,
20296+ ref_frame,
20297+ ref_frame1: None,
20298+ mv1: None,
20299+ mv,
20300+ is_new_mv,
20301+ size: w_mi,
20302+ size_h: h_mi,
20303+ is_global_mv0: false,
20304+ is_global_mv1: false,
20305+ },
20306+ );
20307+ }
20308+ }
20309+}
20310+
20311+/// Decodes one 8x8 leaf of a straddling 16x16 inter-frame block
20312+/// (lane-av1inter8), mirroring [`crate::tile::write_inter_frame_leaf8`]'s
20313+/// exact symbol order: its own skip flag, intra/inter choice and (when
20314+/// inter) `NEARESTMV`/`NEWMV` chain against this leaf's own 2x2-mi mv-stack
20315+/// window, or (when intra) `Y_MODE`, then its own luma and two chroma
20316+/// transform blocks through [`TxbSet::Luma8Inter`]/[`TxbSet::Chroma4`],
20317+/// same as [`decode_leaf8`]'s coefficient layer but with
20318+/// motion-compensated prediction instead of intra prediction when inter.
20319+/// `outer_at` (in [`SUB`]-grid units) is the enclosing 16x16 slot's
20320+/// skip/intra-inter context, overridden by `prev_leaf` exactly as
20321+/// [`decode_leaf8`] overrides mode context: `Neighbours`' above/left arrays
20322+/// only resolve to [`SUB`] granularity. Hands back this leaf's own skip flag
20323+/// and intra/inter choice, for the next leaf or the caller's final
20324+/// write-back.
20325+#[allow(clippy::too_many_arguments)]
20326+fn decode_inter_block8(
20327+ dec: &mut SymbolDecoder,
20328+ cdfs: &mut Cdfs,
20329+ neighbours: &mut Neighbours,
20330+ grid: &mut MiGrid,
20331+ mi_cols: u32,
20332+ mi_rows: u32,
20333+ outer_at: (usize, usize),
20334+ leaf_mi: (usize, usize),
20335+ y: &mut PlaneBuf,
20336+ u: &mut PlaneBuf,
20337+ v: &mut PlaneBuf,
20338+ ref_y: &PlaneBuf,
20339+ ref_u: &PlaneBuf,
20340+ ref_v: &PlaneBuf,
20341+ other_refs: &RefSlots,
20342+ base_q_idx: u8,
20343+ scan8: &[u16],
20344+ scan4: &[u16],
20345+ allow_high_precision_mv: bool,
20346+ force_integer_mv: bool,
20347+ // lane-gmaffine r1: this frame header's own `global_motion` table (spec
20348+ // 5.9.24), indexed `[ref_frame - LAST_FRAME]` -- same table
20349+ // [`decode_inter_block`] takes, threaded here so the 8x8 leaf can code
20350+ // `GLOBALMV` (`gm_get_motion_vector`), fill its mv stack's missing
20351+ // candidates with the gm mv (gm r6's root cause) and build a global
20352+ // warp prediction.
20353+ global_motion: &[ec_av1_syntax::WarpParams; 7],
20354+ // lane-gmaffine r1: this sequence header's own `enable_dual_filter` bit,
20355+ // for the leaf's own `read_mb_interp_filter` below.
20356+ enable_dual_filter: bool,
20357+ // lane-av1comp: see [`decode_inter_block`]'s own doc -- this leaf path
20358+ // only ever tracks a coarse `LAST_FRAME`-or-intra neighbour shape (no
20359+ // per-leaf `above_ref`/`left_ref` array exists here), so `comp_mode`'s
20360+ // context uses that same approximation.
20361+ reference_select: bool,
20362+ enable_masked_compound: bool,
20363+ // lane-sb128 r4: see [`decode_inter_block`]'s own doc -- `BLOCK_8X8` is
20364+ // always `is_interintra_allowed_bsize`-eligible, so this leaf's own gate
20365+ // drops the `side` check entirely.
20366+ enable_interintra_compound: bool,
20367+ enable_jnt_comp: bool,
20368+ order_hint_bits: u32,
20369+ order_hint: u32,
20370+ ref_order_hints: [u32; 7],
20371+ // lane-av1comp round 14: see [`decode_inter_block`]'s own doc -- this
20372+ // leaf has no per-leaf `above_skip_mode`/`left_skip_mode` array either,
20373+ // so its `skip_mode` context reuses the same [`SUB`]-grid
20374+ // `above_skip_mode[cmi]`/`left_skip_mode[rmi]` the enclosing 16x16 slot
20375+ // tracks (mirroring `above_skip`/`left_skip`'s own leaf approximation
20376+ // just above).
20377+ skip_mode_present: bool,
20378+ skip_mode_frame: [u8; 2],
20379+ // lane-cdffwd2: this frame header's own `reduced_tx_set` bit -- see
20380+ // [`decode_inter_frame_tile_with_cdfs`]'s own doc.
20381+ reduced_tx_set: bool,
20382+ // lane-motionmode round 3: this frame header's own `is_motion_mode_switchable`/
20383+ // `allow_warped_motion` bits (spec 5.11.24's `read_motion_mode`), plus
20384+ // the fixed/switchable interp filter kind `obmc_blend`'s own neighbour
20385+ // reads need (see [`decode_inter_block`]'s own doc) -- this leaf's own
20386+ // prediction is always `Regular` (documented corner-cut, `mc::predict`
20387+ // has no filter param), but an OBMC neighbour can be a real 16x16+
20388+ // block that DID resolve a switchable filter.
20389+ interp_fixed: Option<mc::InterpFilterKind>,
20390+ switchable_motion_mode: bool,
20391+ allow_warped_motion: bool,
20392+ // lane-av1comp: `Some((ref1, comp_group_idx, compound_idx))` only for a
20393+ // real `COMPOUND_REFERENCE` leaf, for the caller's own end-of-16x16
20394+ // `record_compound_ctx` call -- mirrors [`decode_inter_block`]'s own
20395+ // `compound_ctx` local, just handed back instead of applied here (this
20396+ // fn's `neighbours` recording happens once for the whole straddling
20397+ // 16x16 block, after every leaf).
20398+ // lane-screen r2: see [`decode_inter_block`]'s own copy of this param --
20399+ // `BLOCK_8X8` (this leaf's fixed size) is always `av1_allow_palette`-
20400+ // eligible (`bsize >= BLOCK_8X8`).
20401+ allow_screen_content_tools: bool,
20402+ // lane-inter8 r1: the leaf's mv stacks used to be built without the
20403+ // frame's sign-bias table (`NO_SIGN_BIAS`), while [`decode_inter_block`]
20404+ // one level up passed it -- it changes the candidate list and with it
20405+ // `new_mv_ctx`/`ref_mv_ctx`, `drl_ctx` and the number of symbols read.
20406+ // Measured: an 8x8 compound NEAR_NEWMV leaf desynced against aomdec's
20407+ // EC_MODE ladder at exactly this block (mi 4,14 of the mandelbrot
20408+ // 8x8-split gate).
20409+ sign_bias_table: &SignBiasTable,
20410+ // lane-inter8 r2: the frame's temporal mv field (spec 7.10.2.8), which
20411+ // [`decode_inter_block`] one level up has always passed and this leaf
20412+ // passed `None` for -- a `use_ref_frame_mvs` frame's stack then holds
20413+ // fewer candidates here than in the reference decoder, which changes the
20414+ // mode contexts AND the number of `drl_mode` bits read (class parsed
20415+ // then discarded).
20416+ tpl_frame: Option<&TplFrameArgs>,
20417+ // lane-scaledref r1: this frame's own coded luma width (spec 7.11.3.3),
20418+ // for the scaled-reference MC this leaf's own single-ref/compound/OBMC
20419+ // predictions take when a stored reference was coded at another width
20420+ // (`use_superres`) -- mirrors [`decode_inter_block`]'s own param.
20421+ frame_width: usize,
20422+) -> Result<(bool, bool, bool, Option<(i8, i8, u8, u8)>, [u8; 2], (i8, Option<i8>))> {
20423+ const LAST_FRAME: i8 = 1;
20424+ // lane-gmaffine r2: the leaf's OWN switchable-filter symbols, handed back
20425+ // so the caller stamps them into `Neighbours` instead of the `[3, 3]`
20426+ // placeholder. `[3, 3]` is the "intra neighbour, no filter" sentinel: an
20427+ // OBMC blend that picks such a neighbour up feeds it to
20428+ // `neighbour_filter`, which PANICS on it (`from_switchable_symbol`) --
20429+ // that was the warp gate's crash, not an entropy desync. Stays `[3, 3]`
20430+ // on the intra and compound paths.
20431+ let mut leaf_filter_syms = [3u8; 2];
20432+ // lane-gmaffine r1: this leaf's GLOBALMV vector AND the mv stack's
20433+ // missing-candidate fallback both come from the frame's global motion
20434+ // evaluated at THIS block's centre (gm r6's root cause).
20435+ let gm_table = build_gm_mv_table(
20436+ global_motion,
20437+ leaf_mi.0,
20438+ leaf_mi.1,
20439+ 2,
20440+ 2,
20441+ allow_high_precision_mv,
20442+ force_integer_mv,
20443+ );
20444+ /// `Y_MODE`'s size group (`common_data.h`'s `size_group_lookup[BLOCK_8X8]`).
20445+ const SIZE_GROUP_8: usize = 1;
20446+
20447+ let (px, py) = (leaf_mi.1 * MI, leaf_mi.0 * MI);
20448+ let (cpx, cpy) = (px / 2, py / 2);
20449+ // lane-txselect: whether this leaf's `TxMode::Select` var-tx tree took
20450+ // the one split a `BLOCK_8X8` can take (`read_block_tx_size` below) --
20451+ // read back by the luma residual read and the tail's neighbour/loop-filter
20452+ // bookkeeping. Always `false` outside a `TxMode::Select` inter frame.
20453+ let mut split8 = false;
20454+ const SIDE: usize = 8;
20455+ const CHROMA_SIDE: usize = 4;
20456+
20457+ let (r, c) = outer_at;
20458+ // lane-inter8 r2: this leaf's OWN mi cell, not the enclosing 16x16's --
20459+ // leaf (mi_r, mi_c + 2)'s left neighbour is leaf (mi_r, mi_c), and the
20460+ // left column of a 16x16's second leaf ROW is the previous 16x16 block's
20461+ // bottom leaf, neither of which a SUB-grid slot can name.
20462+ let (rmi, cmi) = leaf_mi;
20463+ // lane-inter8 r2: no sibling-leaf override any more -- each leaf stamps
20464+ // its own 2x2-mi span into the bands right after it decodes (the caller's
20465+ // `record_inter_rect_mi`), so a plain mi read already names the correct
20466+ // neighbour, including one belonging to the previous 16x16 block.
20467+ let above_skip = neighbours.above_skip[cmi];
20468+ let left_skip = neighbours.left_skip[rmi];
20469+ let above_inter = neighbours.above_inter[cmi];
20470+ let left_inter = neighbours.left_inter[rmi];
20471+ let above_ref0 = neighbours.above_ref[cmi];
20472+ let above_ref1 = neighbours.above_ref1[cmi];
20473+ let left_ref0 = neighbours.left_ref[rmi];
20474+ let left_ref1 = neighbours.left_ref1[rmi];
20475+ let skip_mode_ctx =
20476+ usize::from(neighbours.above_skip_mode[cmi]) + usize::from(neighbours.left_skip_mode[rmi]);
20477+ // Same two `inter_segment_id` positions as [`decode_inter_block`]; this
20478+ // leaf is always `BLOCK_8X8`, i.e. 2x2 mi.
20479+ inter_segment_id(dec, cdfs, leaf_mi.0, leaf_mi.1, 2, 2, false, true);
20480+ let skip_mode = skip_mode_present && dec.symbol(&mut cdfs.skip_mode[skip_mode_ctx]) == 1;
20481+ if skip_mode {
20482+ SKIP_MODE_HITS.with(|c| c.set(c.get() + 1));
20483+ }
20484+
20485+ let skip_ctx = usize::from(above_skip) + usize::from(left_skip);
20486+ let skip = skip_mode || dec.symbol(&mut cdfs.skip[skip_ctx]) == 1;
20487+ inter_segment_id(dec, cdfs, leaf_mi.0, leaf_mi.1, 2, 2, skip, false);
20488+ maybe_read_cdef_idx(dec, leaf_mi.0, leaf_mi.1, skip);
20489+ // Always a `BLOCK_8X8` leaf here, never the whole superblock.
20490+ maybe_read_delta_q(dec, cdfs, leaf_mi.0, leaf_mi.1, false, skip);
20491+ maybe_read_delta_lf(dec, cdfs, leaf_mi.0, leaf_mi.1, false, skip);
20492+
20493+ let (has_above, has_left) = (
20494+ leaf_mi.0 > neighbours.tile_row0_mi,
20495+ leaf_mi.1 > neighbours.tile_col0_mi,
20496+ );
20497+ let ii_ctx = intra_inter_ctx(has_above, has_left, above_inter, left_inter);
20498+ let is_inter = skip_mode || dec.symbol(&mut cdfs.intra_inter[ii_ctx]) == 1;
20499+ // lane-inter8 r1: mirrors the oracle's `EC_MODE` (instrument rung 4,
20500+ // `read_inter_block_mode_info`) so an 8x8 leaf's mode-info range ladder
20501+ // diffs line for line against a real aomdec.
20502+ if std::env::var_os("EC_TRACE_MODE").is_some() {
20503+ eprintln!(
20504+ "EC_MODE mi_row={} mi_col={} rng={}",
20505+ leaf_mi.0,
20506+ leaf_mi.1,
20507+ dec.debug_state().0
20508+ );
20509+ }
20510+
20511+ let mode_for_tx;
20512+ // lane-uv8 r1: this leaf's chroma prediction mode (`get_uv_mode` of the
20513+ // coded `uv_mode`), for the neighbour bands at the tail. An INTER leaf
20514+ // stores `UV_DC_PRED`, exactly as [`decode_inter_block`] one level up.
20515+ let mut uv_predict_mode = DC_PRED;
20516+ let (luma_grid, u_grid, v_grid);
20517+ let mut compound_ctx8: Option<(i8, i8, u8, u8)> = None;
20518+ // lane-inter8 r1: this leaf's own resolved references, handed back so the
20519+ // NEXT leaf of the same 16x16 can use them as its real above/left
20520+ // neighbour (`Neighbours`' arrays only move once per 16x16 block).
20521+ // `(0, None)` is intra.
20522+ let mut leaf_refs: (i8, Option<i8>) = (0, None);
20523+ if is_inter {
20524+ if reference_select || skip_mode {
20525+ // lane-inter8 r1: the REAL neighbour references, not a
20526+ // `LAST_FRAME`-or-intra stand-in. `av1_get_reference_mode_context`
20527+ // and `read_compound_ref_frames`' own contexts both ask whether a
20528+ // neighbour is COMPOUND, so pretending every inter neighbour is
20529+ // single-ref LAST picked the wrong `comp_mode` CDF row -- measured
20530+ // as an 8x8 leaf reading single-ref where aomdec read compound
20531+ // NEAR_NEWMV (mi 4,14).
20532+ let above_nbr = has_above.then(|| NeighbourRef {
20533+ is_inter: above_inter,
20534+ ref0: if above_inter { above_ref0 } else { 0 },
20535+ ref1: above_ref1,
20536+ uni: above_ref1.is_some_and(|r1| is_uni_comp_ref(above_ref0, r1)),
20537+ });
20538+ let left_nbr = has_left.then(|| NeighbourRef {
20539+ is_inter: left_inter,
20540+ ref0: if left_inter { left_ref0 } else { 0 },
20541+ ref1: left_ref1,
20542+ uni: left_ref1.is_some_and(|r1| is_uni_comp_ref(left_ref0, r1)),
20543+ });
20544+ if skip_mode || read_comp_mode(dec, cdfs, above_nbr, left_nbr) {
20545+ let (ref0, ref1) = if skip_mode {
1950520546 (skip_mode_frame[0] as i8, skip_mode_frame[1] as i8)
1950620547 } else {
1950720548 // lane-interp3 r2 (class twin-functions-drift): this leaf
@@ -21584,6 +22625,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
2158422625 // instead of silently decoding as SPLIT and desyncing.
2158522626 let part64 = match (has_cols, has_rows) {
2158622627 (true, true) => {
22628+ 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); }
2158722629 let p = dec.symbol(&mut cdfs.partition_w64[sb_ctx]);
2158822630 if std::env::var_os("EC_AV1_TRACE").is_some() {
2158922631 eprintln!(
@@ -21768,6 +22810,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
2176822810 dec.debug_state().0
2176922811 );
2177022812 }
22813+ 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); }
2177122814 let p = dec.symbol(&mut cdfs.partition_w32[ctx32]);
2177222815 if std::env::var_os("EC_AV1_TRACE").is_some() {
2177322816 eprintln!(
@@ -21880,6 +22923,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
2188022923 // inter leaves through the very same loop the
2188122924 // straddling case has always used.
2188222925 let part16 = if has_cols16 && has_rows16 {
22926+ 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); }
2188322927 let p = dec.symbol(&mut cdfs.partition_w16[ctx16]);
2188422928 if std::env::var_os("EC_AV1_TRACE").is_some() {
2188522929 let (rng, _) = dec.debug_state();
@@ -22190,12 +23234,104 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
2219023234 for (mr, mc) in leaf_positions {
2219123235 let leaf_mi = (mr as usize, mc as usize);
2219223236 let leaf_ctx = neighbours.partition_ctx_mi(leaf_mi, 8);
23237+ 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); }
2219323238 let part8 = dec.symbol(&mut cdfs.partition_w8[leaf_ctx]);
22194- if part8 != PARTITION_NONE {
23239+ if part8 == PARTITION_SPLIT {
23240+ // lane-intersub8: four BLOCK_4X4 inter
23241+ // sub-blocks, chroma once per 8x8.
23242+ decode_inter_sub8_split4(
23243+ &mut dec,
23244+ &mut cdfs,
23245+ &mut neighbours,
23246+ &mut grid,
23247+ leaf_mi,
23248+ mi_cols,
23249+ mi_rows,
23250+ &mut y,
23251+ &mut u,
23252+ &mut v,
23253+ &ref_y,
23254+ &ref_u,
23255+ &ref_v,
23256+ &ref_slots,
23257+ &sign_bias_table,
23258+ &global_motion,
23259+ base_q_idx,
23260+ &scan4,
23261+ allow_high_precision_mv,
23262+ force_integer_mv,
23263+ interp_fixed,
23264+ enable_dual_filter,
23265+ tpl_frame.as_ref(),
23266+ reduced_tx_set,
23267+ frame_width as usize,
23268+ )?;
23269+ continue;
23270+ }
23271+ if part8 == PARTITION_HORZ
23272+ && std::env::var_os("EC_AV1_SUB8_HORZ").is_none()
23273+ {
23274+ // lane-intersub8 r4: the r3 desync IS
23275+ // root-caused and fixed (rect masked
23276+ // compound read `BLOCK_16X16`'s
23277+ // `compound_type`/`wedge_idx` CDF row
23278+ // for a 16x8 block); every mode-info
23279+ // range on the 28-arm transposed
23280+ // sweep now matches aomdec element
23281+ // for element. What is left is a
23282+ // POST-ENTROPY pixel band: 3 of 28
23283+ // arms (8-bit cq32 sp9, 10-bit cq12
23284+ // sp3, 10-bit cq16 sp3) differ by
23285+ // |d| <= 2 in luma only, scattered
23286+ // over the bottom-left corner
23287+ // (x < 48, y >= 112) from the first
23288+ // frame that references an 8x4 group
23289+ // -- a filter/reconstruction defect,
23290+ // not a desync. Still refused by name
23291+ // rather than shipped as silent pixel
23292+ // drift; `EC_AV1_SUB8_HORZ=1` decodes
23293+ // it for the r5 bisect.
2219523294 return Err(unsupported(
22196- "an inter partition below 8x8 (this decoder codes no inter leaf smaller than 8x8; lane-sub8 scoped to intra)",
23295+ "an inter 8x8 HORZ partition (two BLOCK_8X4 inter leaves; entropy-exact now, but a measured sweep still drifts |d|<=2 in luma after the filters)",
2219723296 ));
2219823297 }
23298+ if part8 == PARTITION_VERT || part8 == PARTITION_HORZ {
23299+ // lane-intersub8 r3/r4: two BLOCK_8X4
23300+ // (HORZ) / BLOCK_4X8 (VERT) inter
23301+ // leaves, chroma once per 8x8 on the
23302+ // second of them.
23303+ decode_inter_sub8_rect2(
23304+ &mut dec,
23305+ &mut cdfs,
23306+ &mut neighbours,
23307+ &mut grid,
23308+ leaf_mi,
23309+ part8 == PARTITION_VERT,
23310+ mi_cols,
23311+ mi_rows,
23312+ &mut y,
23313+ &mut u,
23314+ &mut v,
23315+ &ref_y,
23316+ &ref_u,
23317+ &ref_v,
23318+ &ref_slots,
23319+ &sign_bias_table,
23320+ &global_motion,
23321+ base_q_idx,
23322+ &scan4,
23323+ allow_high_precision_mv,
23324+ force_integer_mv,
23325+ interp_fixed,
23326+ enable_dual_filter,
23327+ tpl_frame.as_ref(),
23328+ reduced_tx_set,
23329+ frame_width as usize,
23330+ )?;
23331+ continue;
23332+ }
23333+ // `partition_w8` is a 4-symbol alphabet
23334+ // (NONE/HORZ/VERT/SPLIT), all four handled.
2219923335 let (
2220023336 skip,
2220123337 is_inter,
crates/ec-av1/src/refusal_inventory.rsmodified+5 -0
@@ -34,6 +34,11 @@ const REFUSALS: &[&str] = &[
3434 "a split intra strip whose transform unit is {tx_w}x{tx_h} (no luma coefficient tables for that shape here)",
3535 "an inter partition below 8x8 (this decoder codes no inter leaf smaller than 8x8; lane-sub8 scoped to intra)",
3636 "an OBMC neighbour whose interp filter was never recorded (no switchable symbol for that block)",
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+ "an inter 8x8 HORZ partition (two BLOCK_8X4 inter leaves; entropy-exact now, but a measured sweep still drifts |d|<=2 in luma after the filters)",
41+ "a COMPOUND_WEDGE mask on a non-square inter block (rect wedge codebook unimplemented)",
3742 "a 1:4 rect strip that actually uses a palette (reconstruction is not ported at this shape)",
3843 "a 16x16 block whose true edge cuts through both axes needs a rectangular transform this decoder does not code yet",
3944 "a 16x16 inter block whose true edge cuts through both axes needs a rectangular transform this decoder does not code yet",
crates/ec-av1/src/stream.rsmodified+188 -0
@@ -7915,6 +7915,194 @@ mod tests {
79157915 }
79167916 }
79177917
7918+ /// lane-intersub8: `PARTITION_SPLIT` below 8x8 on an INTER frame -- four
7919+ /// `BLOCK_4X4` inter sub-blocks with one shared 4x4 chroma unit per plane,
7920+ /// predicted the sub8x8 way (2x2 chroma piece per luma sub-block mv,
7921+ /// `dec_build_inter_predictors`' `is_sub8x8` branch). Reality of the shape
7922+ /// was established BEFORE the code (class refusal-from-own-desync): the
7923+ /// oracle `aomdec`'s `EC_TRACE` prints `EC_PART_VAL ... bsize=3 value=3`
7924+ /// on this recipe's inter frames.
7925+ ///
7926+ /// Attempts 0..7 run `--enable-rect-partitions=0`, where aomenc can only
7927+ /// pick SPLIT below 8x8; attempts 8..15 repeat the schedule with rect on,
7928+ /// where it picks HORZ/VERT below 8x8 far more often than SPLIT -- the VERT
7929+ /// arm (two `BLOCK_4X8` inter leaves, `decode_inter_sub8_rect2`) is what the
7930+ /// `rect_fired` assert pins. The HORZ twin decodes but is refused by name
7931+ /// (lane-intersub8 r3: a measured sweep desyncs the block to its right).
7932+ #[test]
7933+ fn a_real_aomenc_inter_sequence_with_a_sub8x8_inter_split_decodes_pixel_exact() {
7934+ const NAME: &str =
7935+ "a_real_aomenc_inter_sequence_with_a_sub8x8_inter_split_decodes_pixel_exact";
7936+ let _gate_lock = lock_gate_counters();
7937+ if !have_ffmpeg() {
7938+ eprintln!("SKIP {NAME}: no ffmpeg");
7939+ return;
7940+ }
7941+ if !have_aomenc() {
7942+ eprintln!("SKIP {NAME}: no aomenc at {}", aomenc_path().display());
7943+ return;
7944+ }
7945+ let (width, height, frame_count) = (192usize, 128usize, 6usize);
7946+ let mut fired = 0u32;
7947+ // lane-intersub8 r3: attempts 8..15 repeat the same schedule with
7948+ // `--enable-rect-partitions=1`, where aomenc picks PARTITION_VERT below
7949+ // 8x8 (two BLOCK_4X8 inter leaves, one shared 4x4 chroma unit predicted
7950+ // from BOTH sub-blocks' mvs). The HORZ twin is still refused by name.
7951+ let mut rect_fired = 0u32;
7952+ let mut refusals: Vec<String> = Vec::new();
7953+ let mut out_of_scope_mismatch = 0u32;
7954+ for bit_depth in [8u32, 10u32] {
7955+ for attempt in 0..16u32 {
7956+ let rect = attempt / 8;
7957+ let rect_arg = format!("--enable-rect-partitions={rect}");
7958+ // lane-intersub8 r2, measured schedule (sweep of cq
7959+ // {8,10,12,14,16,18,20} x sp {3,6,9,12} x both depths,
7960+ // `decode_probe`'s `sub8_inter_split:` counter vs an ffmpeg
7961+ // rawvideo compare): sub-8x8 inter SPLIT groups fire at
7962+ // (8-bit, cq 12, sp 3) = 1 group and (10-bit, cq 12, sp 6) =
7963+ // 3 groups, both pixel-exact. cq 8 and 10 are NOT used: at
7964+ // those quantizers this recipe also carries a CDEF defect of
7965+ // another shape -- three luma samples of |d| = 1 on
7966+ // decode-order frames 3/4, zero sub-8x8 inter split groups,
7967+ // and the identical recipe re-encoded with `--enable-cdef=0`
7968+ // decodes all six frames exact. Deferred to a CDEF lane
7969+ // rather than hidden: cq 16..20 are all exact, so this gate
7970+ // is not selecting quantizers that hide a defect of its own
7971+ // shape.
7972+ let cq = [12, 14][(attempt % 2) as usize];
7973+ let sp = 3 + ((attempt % 8) / 2) * 3;
7974+ let duration = frame_count as f64 / 25.0;
7975+ let source = format!(
7976+ "color=c=gray:s={width}x{height}:d={duration}:r=25,format=gray,\
7977+ geq=lum='128+58*sin((X+N*{sp})/6)+18*sin(Y/23)',format=yuv420p"
7978+ );
7979+ let pix_fmt = if bit_depth == 10 { "yuv420p10le" } else { "yuv420p" };
7980+ let y4m = Command::new("ffmpeg")
7981+ .args([
7982+ "-v", "error", "-f", "lavfi", "-i", &source, "-t", &duration.to_string(),
7983+ "-pix_fmt", pix_fmt, "-strict", "-1", "-f", "yuv4mpegpipe", "-",
7984+ ])
7985+ .stdin(Stdio::null())
7986+ .stdout(Stdio::piped())
7987+ .stderr(Stdio::piped())
7988+ .output()
7989+ .expect("ffmpeg failed to run");
7990+ assert!(
7991+ y4m.status.success(),
7992+ "{NAME}: ffmpeg refused the fixture: {}",
7993+ String::from_utf8_lossy(&y4m.stderr)
7994+ );
7995+ let cq_arg = format!("--cq-level={cq}");
7996+ let depth_arg = format!("--bit-depth={bit_depth}");
7997+ let input_depth_arg = format!("--input-bit-depth={bit_depth}");
7998+ let args: Vec<&str> = vec![
7999+ "--codec=av1", "--passes=1", "--end-usage=q", &cq_arg, "--cpu-used=0",
8000+ "--threads=1", "--row-mt=0", "--sb-size=64", &depth_arg, &input_depth_arg,
8001+ "--enable-restoration=0", "--enable-palette=0", "--deltaq-mode=0",
8002+ "--enable-filter-intra=0", "--enable-cfl-intra=0", "--enable-intrabc=0",
8003+ "--lag-in-frames=0", "--enable-obmc=0", "--enable-tx-size-search=1",
8004+ // Per-arm overrides last (aomenc keeps the LAST occurrence).
8005+ "--enable-rect-partitions=0", "--enable-ab-partitions=0",
8006+ "--enable-1to4-partitions=0", "--min-partition-size=4",
8007+ "--max-partition-size=16",
8008+ &rect_arg,
8009+ "--obu", "-o", "-", "-",
8010+ ];
8011+ let mut child = Command::new(aomenc_path())
8012+ .args(&args)
8013+ .stdin(Stdio::piped())
8014+ .stdout(Stdio::piped())
8015+ .stderr(Stdio::piped())
8016+ .spawn()
8017+ .expect("aomenc failed to start");
8018+ child
8019+ .stdin
8020+ .take()
8021+ .expect("aomenc stdin")
8022+ .write_all(&y4m.stdout)
8023+ .expect("writing y4m to aomenc");
8024+ let out = child.wait_with_output().expect("aomenc failed to run");
8025+ assert!(
8026+ out.status.success(),
8027+ "{NAME}: aomenc refused the fixture: {}",
8028+ String::from_utf8_lossy(&out.stderr)
8029+ );
8030+ let stream = out.stdout;
8031+ let before = decode::sub8_inter_split_hits();
8032+ let before_rect = decode::sub8_inter_rect_hits();
8033+ let frames = match decode_stream(&stream) {
8034+ Err(e) => {
8035+ let msg = e.to_string();
8036+ assert!(
8037+ msg.contains("unsupported"),
8038+ "{NAME} failed outright, not a named refusal ({bit_depth}-bit, \
8039+ attempt {attempt}): {msg}"
8040+ );
8041+ refusals.push(format!("{bit_depth}-bit attempt {attempt}: {msg}"));
8042+ continue;
8043+ }
8044+ Ok(frames) => frames,
8045+ };
8046+ let split_groups = decode::sub8_inter_split_hits() - before;
8047+ let rect_now = decode::sub8_inter_rect_hits();
8048+ let rect_groups = (rect_now.0 - before_rect.0) + (rect_now.1 - before_rect.1);
8049+ let groups = split_groups + rect_groups;
8050+ let ffmpeg_frames = if bit_depth == 10 {
8051+ ffmpeg_decode_sequence_10bit(&stream, width, height, frame_count)
8052+ } else {
8053+ ffmpeg_decode_sequence(&stream, width, height, frame_count)
8054+ };
8055+ assert_eq!(frames.len(), frame_count);
8056+ let mismatched = frames
8057+ .iter()
8058+ .zip(&ffmpeg_frames)
8059+ .any(|(got, want)| got.y != want.y || got.u != want.u || got.v != want.v);
8060+ if groups == 0 {
8061+ // Out of scope: no sub-8x8 inter split in this attempt.
8062+ if mismatched {
8063+ out_of_scope_mismatch += 1;
8064+ eprintln!(
8065+ "{NAME}: {bit_depth}-bit attempt {attempt} MISMATCHES with zero \
8066+ sub-8x8 inter group -- another shape's defect"
8067+ );
8068+ }
8069+ refusals.push(format!(
8070+ "{bit_depth}-bit attempt {attempt}: decoded, but no sub-8x8 inter split"
8071+ ));
8072+ continue;
8073+ }
8074+ for (i, (got, want)) in frames.iter().zip(&ffmpeg_frames).enumerate() {
8075+ assert_eq!(
8076+ got.y, want.y,
8077+ "luma frame {i} ({bit_depth}-bit attempt {attempt}, {groups} sub-8x8 \
8078+ inter split groups)"
8079+ );
8080+ assert_eq!(got.u, want.u, "U frame {i} ({bit_depth}-bit attempt {attempt})");
8081+ assert_eq!(got.v, want.v, "V frame {i} ({bit_depth}-bit attempt {attempt})");
8082+ }
8083+ fired += 1;
8084+ if rect_groups > 0 {
8085+ rect_fired += 1;
8086+ }
8087+ }
8088+ }
8089+ assert_eq!(
8090+ out_of_scope_mismatch, 0,
8091+ "{NAME}: attempts mismatched with no sub-8x8 inter group"
8092+ );
8093+ assert!(
8094+ fired >= 2,
8095+ "{NAME}: fewer than 2 firing+pixel-exact attempts:\n{}",
8096+ refusals.join("\n")
8097+ );
8098+ assert!(
8099+ rect_fired >= 2,
8100+ "{NAME}: fewer than 2 firing+pixel-exact attempts with a RECTANGULAR sub-8x8 \
8101+ inter leaf (4x8):\n{}",
8102+ refusals.join("\n")
8103+ );
8104+ }
8105+
79188106 #[test]
79198107 // lane-inter4 r3: the 16x16-level rect INTER leaf -- PARTITION_HORZ /
79208108 // 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).