forge
Explore
Log in

Don't you dare go Hollow

Merge branch 'lane-rectx': coded (non-skip) 16x8/8x16 strips with TX_16X8/8X16 luma and 8x4/4x8 chroma coefficient paths (ReelC blocker)

Browse files at this commit

e47e7ce471b7cc013f3dacfb8231c3a52243407fAhmet Kaan GümüşParent: 9c1c99feb6a140
Conflict resolution: cdf.rs/cdf_state.rs take the union (lane's EOB_PT_128_LUMA*
/EOB_PT_32_CHROMA* tables + main's q-dependent EOB_PT_512_CHROMA row);
decode.rs keeps main's sub8 mi-exact neighbour maps and its Option<prev_leaf>
decode_leaf8 (lane's prev_leaves/write_back_split_modes duplicate of the same
fix dropped), lane's coded rect leaf path, both scan-table families;
encode.rs keeps main's VERT_A/B Reach tables with the table_row naming.

10 changed files +1254 -113

crates/ec-av1/src/cdf.rsmodified+45 -1
@@ -293,6 +293,42 @@ pub const EOB_PT_128_CHROMA_Q3: [u16; 9] = [
293293 24313, 26062, 28385, 30107, 31217, 31898, 32345, 32768, 0,
294294 ];
295295
296+/// `av1_default_eob_multi128_cdfs[2][0][0]` (`token_cdfs.h:830-849`,
297+/// lane-rectx): the end-of-block group of a LUMA transform with 128 coded
298+/// positions -- what a true 16x8/8x16 rectangular transform has
299+/// (`decode_leaf_rect`'s own leaf, one level below [`EOB_PT_512_LUMA`]'s
300+/// 32x16/16x32), distinct from [`EOB_PT_256_LUMA`]'s 256-position group a
301+/// *square* 16x16 reads. Read straight from the plane-0 half of the same
302+/// `token_cdfs.h` table [`EOB_PT_128_CHROMA`] reads its plane-1 half from.
303+pub const EOB_PT_128_LUMA: [u16; 9] = [
304+ 1366, 1738, 2527, 5016, 9355, 15797, 24643, 32768, 0,
305+];
306+/// [`EOB_PT_128_LUMA`], q-context 0.
307+pub const EOB_PT_128_LUMA_Q0: [u16; 9] = [
308+ 219, 482, 1140, 2091, 3680, 6028, 12586, 32768, 0,
309+];
310+/// [`EOB_PT_128_LUMA`], q-context 1.
311+pub const EOB_PT_128_LUMA_Q1: [u16; 9] = [
312+ 685, 933, 1488, 2714, 4766, 8562, 19254, 32768, 0,
313+];
314+/// [`EOB_PT_128_LUMA`], q-context 3.
315+pub const EOB_PT_128_LUMA_Q3: [u16; 9] = [
316+ 3472, 4885, 7489, 12481, 18517, 24536, 29635, 32768, 0,
317+];
318+
319+/// `av1_default_eob_multi32_cdfs[2][1][0]` (`token_cdfs.h:792-808`,
320+/// lane-rectx): the end-of-block group of a CHROMA transform with 32 coded
321+/// positions -- what a true 8x4/4x8 rectangular transform has (the chroma
322+/// plane of a [`decode_leaf_rect`] 16x8/8x16 luma strip), distinct from
323+/// [`EOB_PT_16_CHROMA`]'s 16-position group a *square* 4x4 reads.
324+pub const EOB_PT_32_CHROMA: [u16; 7] = [13468, 16303, 20361, 25105, 29281, 32768, 0];
325+/// [`EOB_PT_32_CHROMA`], q-context 0.
326+pub const EOB_PT_32_CHROMA_Q0: [u16; 7] = [2636, 4273, 7588, 11794, 20401, 32768, 0];
327+/// [`EOB_PT_32_CHROMA`], q-context 1.
328+pub const EOB_PT_32_CHROMA_Q1: [u16; 7] = [8394, 10352, 13932, 18855, 26014, 32768, 0];
329+/// [`EOB_PT_32_CHROMA`], q-context 3.
330+pub const EOB_PT_32_CHROMA_Q3: [u16; 7] = [22086, 24282, 27010, 29770, 31743, 32768, 0];
331+
296332 /// `av1_default_eob_multi512_cdfs[2][1][0]` (`token_cdfs.h:874-901`,
297333 /// lane-part32 r4): the end-of-block group of a CHROMA transform with 512
298334 /// coded positions -- what a 32x16/16x32 chroma transform has (the chroma
@@ -421,13 +457,21 @@ pub const CFL_SIGN: [u16; 9] = [1418, 2123, 13340, 18405, 26972, 28343, 32294, 3
421457 /// (12756/14301, `default_filter_intra_cdfs` index 8/7) -- the two rect
422458 /// strips `PARTITION_HORZ`/`PARTITION_VERT` decode, each with its own
423459 /// distinct default probability from every square class above.
424-pub const FILTER_INTRA: [[u16; 3]; 6] = [
460+/// `[6]`/`[7]` (lane-rectx r3) add `BLOCK_16X8`/`BLOCK_8X16`'s own rows
461+/// (9394/12551, `default_filter_intra_cdfs` index 5/4) -- the 16x8/8x16
462+/// strips [`crate::decode`]'s `decode_leaf_rect` codes. Missing them meant
463+/// the flag was never read at that size at all (libaom reads it for every
464+/// DC_PRED block whose sides are both <= 32), so every DC_PRED 16x8 strip
465+/// dropped one symbol and desynced the tile from that block on.
466+pub const FILTER_INTRA: [[u16; 3]; 8] = [
425467 [4621, 32768, 0],
426468 [7866, 32768, 0],
427469 [12408, 32768, 0],
428470 [22343, 32768, 0],
429471 [12756, 32768, 0],
430472 [14301, 32768, 0],
473+ [9394, 32768, 0],
474+ [12551, 32768, 0],
431475 ];
432476 /// `default_filter_intra_mode_cdf` (entropymode.c): which of the five
433477 /// `FILTER_INTRA_MODES` a `use_filter_intra` block picks.
crates/ec-av1/src/cdf_state.rsmodified+96 -2
@@ -127,6 +127,41 @@ pub(crate) enum TxbSet {
127127 /// different existing sets is why this variant exists at all rather than
128128 /// reusing [`LumaRect32x16`](TxbSet::LumaRect32x16)'s chroma sibling.
129129 ChromaRect32x16,
130+ /// The luma 16x8/8x16 transform of a `PARTITION_HORZ`/`VERT` intra strip
131+ /// below 16x16 (lane-rectx, `decode_leaf_rect`'s own leaf, one level
132+ /// under [`LumaRect32x16`](TxbSet::LumaRect32x16)): `get_txsize_entropy_ctx`
133+ /// reduces this 2:1 rect size to `TX_16X16` too, so this shares every
134+ /// table [`Luma16`](TxbSet::Luma16) does except two: its mode-indexed
135+ /// `tx_type` CDF, which is the *8x8* row's (see
136+ /// [`LumaRect16x8Set1`](TxbSet::LumaRect16x8Set1)), and `eob_pt`, which
137+ /// reads the true 128-position [`crate::cdf::EOB_PT_128_LUMA`] rather
138+ /// than `Luma16`'s 256-position one. Unlike
139+ /// [`LumaRect32x16`](TxbSet::LumaRect32x16), this size DOES carry a
140+ /// `tx_type` symbol: `av1_get_ext_tx_set_type` (`av1/common/blockd.h`)
141+ /// sees `tx_size_sqr_up == TX_16X16`, so intra reads
142+ /// `EXT_TX_SET_DTT4_IDTX` under `reduced_tx_set` and
143+ /// `EXT_TX_SET_DTT4_IDTX_1DDCT` without it (`tx_size_sqr` is `TX_8X8`
144+ /// here, not `TX_16X16`) -- this variant is the reduced arm, its
145+ /// `Set1` sibling the other.
146+ LumaRect16x8,
147+ /// [`LumaRect16x8`](TxbSet::LumaRect16x8)'s `reduced_tx_set: false`
148+ /// counterpart (lane-rectx r3), the same split
149+ /// [`Luma8Set1`](TxbSet::Luma8Set1) has to [`Luma8`](TxbSet::Luma8) --
150+ /// and it is deliberately those two tables, not the 16x16 row: libaom's
151+ /// `read_tx_type` indexes `intra_ext_tx_cdf[eset][square_tx_size]` with
152+ /// `square_tx_size = txsize_sqr_map[tx_size]`, which for `TX_16X8`/
153+ /// `TX_8X16` is `TX_8X8`, NOT the `txsize_sqr_up_map` `TX_16X16` the
154+ /// txb-skip/base/br tables use (`get_txsize_entropy_ctx`). r2 read the
155+ /// 16x16 row's five-symbol reduced CDF here and desynced on the very
156+ /// first coded rect leaf.
157+ LumaRect16x8Set1,
158+ /// The chroma 8x4/4x8 transform under the same leaf (lane-rectx):
159+ /// [`Chroma8`](TxbSet::Chroma8)'s tables except `eob_pt`, which reads the
160+ /// true 32-position [`crate::cdf::EOB_PT_32_CHROMA`] instead of
161+ /// `Chroma8`'s 64-position one -- the same square-up relationship
162+ /// [`ChromaRect16x8`](TxbSet::ChromaRect16x8) has to `Chroma16`, one size
163+ /// class down.
164+ ChromaRect8x4,
130165 }
131166
132167 /// The tables one transform block is coded with, borrowed from the state for
@@ -301,6 +336,12 @@ pub(crate) struct Cdfs {
301336 /// The end-of-block group of a true 32x16/16x32 rect CHROMA transform
302337 /// (lane-sbpart), see [`TxbSet::ChromaRect32x16`].
303338 pub eob_pt_512_chroma: [u16; 11],
339+ /// The end-of-block group of a true 16x8/8x16 rect LUMA transform
340+ /// (lane-rectx), see [`TxbSet::LumaRect16x8`].
341+ pub eob_pt_128_luma: [u16; 9],
342+ /// The end-of-block group of a true 8x4/4x8 rect CHROMA transform
343+ /// (lane-rectx), see [`TxbSet::ChromaRect8x4`].
344+ pub eob_pt_32_chroma: [u16; 7],
304345 /// The end-of-block offset bit, per table set.
305346 pub eob_extra_luma_32: [[u16; 3]; 9],
306347 /// The same, for a 64x64 luma transform.
@@ -464,9 +505,10 @@ pub(crate) struct Cdfs {
464505 /// [`Self::dv_joint`]'s per-component half.
465506 pub dv_comp: [MvComponentCdfs; 2],
466507 /// The `use_filter_intra` flag, indexed by block-size class (`[0]`=4x4,
467- /// `[1]`=8x8, `[2]`=16x16, `[3]`=32x32, `[4]`=32x16, `[5]`=16x32) --
508+ /// `[1]`=8x8, `[2]`=16x16, `[3]`=32x32, `[4]`=32x16, `[5]`=16x32,
509+ /// `[6]`=16x8, `[7]`=8x16) --
468510 /// see [`cdf::FILTER_INTRA`].
469- pub filter_intra: [[u16; 3]; 6],
511+ pub filter_intra: [[u16; 3]; 8],
470512 /// Which `FILTER_INTRA_MODES` entry a `use_filter_intra` block picks.
471513 pub filter_intra_mode: [u16; 6],
472514 /// `TxMode::Select`'s `tx_depth` flag at an 8x8 block, by `tx_size_context`
@@ -681,6 +723,8 @@ impl Cdfs {
681723 reset1(&mut self.eob_pt_512_luma);
682724 reset1(&mut self.eob_pt_128_chroma);
683725 reset1(&mut self.eob_pt_512_chroma);
726+ reset1(&mut self.eob_pt_128_luma);
727+ reset1(&mut self.eob_pt_32_chroma);
684728 reset2(&mut self.eob_extra_luma_32);
685729 reset2(&mut self.eob_extra_luma_64);
686730 reset2(&mut self.eob_extra_chroma_16);
@@ -1138,6 +1182,20 @@ impl Cdfs {
11381182 cdf::EOB_PT_128_CHROMA,
11391183 cdf::EOB_PT_128_CHROMA_Q3,
11401184 ),
1185+ eob_pt_128_luma: pick(
1186+ q_ctx,
1187+ cdf::EOB_PT_128_LUMA_Q0,
1188+ cdf::EOB_PT_128_LUMA_Q1,
1189+ cdf::EOB_PT_128_LUMA,
1190+ cdf::EOB_PT_128_LUMA_Q3,
1191+ ),
1192+ eob_pt_32_chroma: pick(
1193+ q_ctx,
1194+ cdf::EOB_PT_32_CHROMA_Q0,
1195+ cdf::EOB_PT_32_CHROMA_Q1,
1196+ cdf::EOB_PT_32_CHROMA,
1197+ cdf::EOB_PT_32_CHROMA_Q3,
1198+ ),
11411199 eob_pt_512_chroma: pick(
11421200 q_ctx,
11431201 cdf::EOB_PT_512_CHROMA_Q0,
@@ -1584,6 +1642,42 @@ impl Cdfs {
15841642 tx_type: None,
15851643 eob_pt_class1: Some(&mut self.eob_pt_512_chroma_class1),
15861644 },
1645+ TxbSet::LumaRect16x8 => TxbTables {
1646+ side: 16,
1647+ txb_skip: &mut self.txb_skip_luma_16,
1648+ eob_pt: &mut self.eob_pt_128_luma,
1649+ eob_extra: &mut self.eob_extra_luma_16,
1650+ base: &mut self.base_luma_16,
1651+ base_eob: &mut self.base_eob_luma_16,
1652+ br: &mut self.br_luma_16,
1653+ dc_sign: &mut self.dc_sign_luma,
1654+ tx_type: Some(self.intra_tx_type_8[mode].as_mut_slice()),
1655+ eob_pt_class1: None,
1656+ },
1657+ TxbSet::LumaRect16x8Set1 => TxbTables {
1658+ side: 16,
1659+ txb_skip: &mut self.txb_skip_luma_16,
1660+ eob_pt: &mut self.eob_pt_128_luma,
1661+ eob_extra: &mut self.eob_extra_luma_16,
1662+ base: &mut self.base_luma_16,
1663+ base_eob: &mut self.base_eob_luma_16,
1664+ br: &mut self.br_luma_16,
1665+ dc_sign: &mut self.dc_sign_luma,
1666+ tx_type: Some(self.intra_tx_type_8_set1[mode].as_mut_slice()),
1667+ eob_pt_class1: None,
1668+ },
1669+ TxbSet::ChromaRect8x4 => TxbTables {
1670+ side: 8,
1671+ txb_skip: &mut self.txb_skip_chroma_8,
1672+ eob_pt: &mut self.eob_pt_32_chroma,
1673+ eob_extra: &mut self.eob_extra_chroma_8,
1674+ base: &mut self.base_chroma_8,
1675+ base_eob: &mut self.base_eob_chroma_8,
1676+ br: &mut self.br_chroma_8,
1677+ dc_sign: &mut self.dc_sign_chroma,
1678+ tx_type: None,
1679+ eob_pt_class1: None,
1680+ },
15871681 }
15881682 }
15891683 }
crates/ec-av1/src/decode.rsmodified+323 -88
@@ -1384,6 +1384,33 @@ pub(crate) fn rect_coeff_hits() -> usize {
13841384 RECT_COEFF_HITS.with(|c| c.get())
13851385 }
13861386
1387+// lane-rectx r1: how many below-16x16 HORZ/VERT leaves ([`decode_leaf_rect`])
1388+// decoded real (non-skip) TX_16X8/TX_8X16 coefficients -- the counter the
1389+// charter's real-aomenc gate hard-asserts.
1390+thread_local! {
1391+ static RECT_LEAF_COEFF_HITS: std::cell::Cell<usize> =
1392+ const { std::cell::Cell::new(0) };
1393+}
1394+
1395+/// Current value of [`RECT_LEAF_COEFF_HITS`].
1396+pub(crate) fn rect_leaf_coeff_hits() -> usize {
1397+ RECT_LEAF_COEFF_HITS.with(|c| c.get())
1398+}
1399+
1400+// lane-rectx r5: how many times a NON-strip `kf_y_mode` reader
1401+// ([`decode_block`], [`decode_block_rect`], [`decode_block_rect64`]) took an
1402+// above/left mode from the mi-exact map that DIFFERS from its coarse 16x16
1403+// slot -- i.e. how often the r5 defect would have picked the wrong CDF row.
1404+thread_local! {
1405+ static MODE_MI_OVERRIDE_HITS: std::cell::Cell<usize> =
1406+ const { std::cell::Cell::new(0) };
1407+}
1408+
1409+/// Current value of [`MODE_MI_OVERRIDE_HITS`].
1410+pub(crate) fn mode_mi_override_hits() -> usize {
1411+ MODE_MI_OVERRIDE_HITS.with(|c| c.get())
1412+}
1413+
13871414 // lane-sbpart r2: how many superblock-level `PARTITION_HORZ`/`PARTITION_VERT`
13881415 // blocks (two true 64x32/32x64 strips, [`decode_block_rect64`]) fired -- the
13891416 // gate's proof this round's arms actually reached a real block, not just
@@ -2029,6 +2056,25 @@ const SCAN_8X32: [u16; 256] = [
20292056 228, 235, 242, 249, 215, 222, 229, 236, 243, 250, 223, 230, 237, 244, 251, 231, 238, 245, 252,
20302057 239, 246, 253, 247, 254, 255,
20312058 ];
2059+/// `Default_Scan_8x4` (lane-rectx, see [`SCAN_32X16`]'s doc comment for the
2060+/// transposition rule this repo's `SCAN_WxH` names follow): this repo's
2061+/// `(w=8, h=4)` reads libaom's own `default_scan_4x8` verbatim -- the same
2062+/// axis swap [`SCAN_16X8`]/[`SCAN_8X16`] already carry one size class up
2063+/// (repo `SCAN_16X8` == libaom `default_scan_8x16`, repo `SCAN_8X16` ==
2064+/// libaom `default_scan_16x8`), checked against `scan.c` before landing
2065+/// rather than re-deriving the zigzag formula.
2066+const SCAN_8X4: [u16; 32] = [
2067+ 0, 8, 1, 16, 9, 2, 24, 17, 10, 3, 25, 18, 11, 4, 26, 19, 12, 5, 27, 20, 13, 6, 28, 21, 14, 7,
2068+ 29, 22, 15, 30, 23, 31,
2069+];
2070+
2071+/// `Default_Scan_4x8` (lane-rectx): this repo's `(w=4, h=8)` reads libaom's
2072+/// own `default_scan_8x4` verbatim, the same transposition [`SCAN_8X4`]'s
2073+/// doc comment explains.
2074+const SCAN_4X8: [u16; 32] = [
2075+ 0, 1, 4, 2, 5, 8, 3, 6, 9, 12, 7, 10, 13, 16, 11, 14, 17, 20, 15, 18, 21, 24, 19, 22, 25, 28,
2076+ 23, 26, 29, 27, 30, 31,
2077+];
20322078
20332079 /// [`neighbour`] with independent `w` (row stride)/`h` (row-bound) extents
20342080 /// (lane-rectwire, mirrors [`record_rect`](Neighbours::record_rect)'s
@@ -2415,12 +2461,14 @@ fn read_coeffs(
24152461 Ok((grid, tx_type))
24162462 }
24172463
2418-/// [`read_coeffs`] widened to `(w, h)` (lane-rectwire), restricted to
2419-/// `TxClass::TwoD` -- the only class either rect size pair this decoder codes
2420-/// can ever produce (see [`decode_block_rect`]'s doc comment): refuses by
2421-/// name rather than guess-decode if a `tx_type` symbol or non-2D class ever
2422-/// shows up here, since neither `base_ctx_rect`/`br_ctx_rect` nor
2423-/// [`class_scan_table`] have a rect form for those.
2464+/// [`read_coeffs`] widened to `(w, h)` (lane-rectwire; lane-rectx added the
2465+/// `tx_type` read [`TxbSet::LumaRect16x8`] needs), restricted to
2466+/// `TxClass::TwoD` -- the only class any rect size pair this decoder codes
2467+/// can ever produce, since every `tx_type` this decoder's rect sets can read
2468+/// (`EXT_TX_SET_DTT4_IDTX`'s five members) is itself 2D: refuses by name
2469+/// rather than guess-decode if a non-2D class ever shows up here, since
2470+/// neither `base_ctx_rect`/`br_ctx_rect` nor [`class_scan_table`] have a rect
2471+/// form for those.
24242472 fn read_coeffs_rect(
24252473 dec: &mut SymbolDecoder,
24262474 coding: &mut TxbTables,
@@ -2433,6 +2481,7 @@ fn read_coeffs_rect(
24332481 ) -> Result<(Vec<i32>, TxType)> {
24342482 let ec_trace_coeff = std::env::var_os("EC_TRACE_COEFF").is_some();
24352483 let mut grid = vec![0i32; w * h];
2484+ let entry_rng = dec.debug_state().0;
24362485 let all_zero = dec.symbol(&mut coding.txb_skip[skip_ctx]) == 1;
24372486 if ec_trace_coeff {
24382487 let (rng, _) = dec.debug_state();
@@ -2444,17 +2493,35 @@ fn read_coeffs_rect(
24442493 if all_zero {
24452494 return Ok((grid, TxType::DctDct));
24462495 }
2447- if coding.tx_type.is_some() {
2448- return Err(unsupported(
2449- "a tx_type symbol on a rectangular transform (never expected at this size)",
2450- ));
2496+ let trace = std::env::var_os("EC_TRACE_COEFF").is_some();
2497+ if trace {
2498+ let (rng, _) = dec.debug_state();
2499+ eprintln!("EC_COEFF_STEP tag=all_zero ctx={skip_ctx} all_zero=0 rng={rng}");
2500+ }
2501+ let mut tx_type = default_tx_type;
2502+ if let Some(tx_type_cdf) = coding.tx_type.as_deref_mut() {
2503+ // Mirrors [`read_coeffs`]'s own `tx_type` read: the CDF row's width
2504+ // names its set (lane-rectx, `TxbSet::LumaRect16x8` -- the one rect
2505+ // set here that carries a `tx_type` symbol at all).
2506+ let len = tx_type_cdf.len();
2507+ let t = dec.symbol(tx_type_cdf);
2508+ tx_type = match len {
2509+ 17 => TxType::from_symbol_all16(t),
2510+ 13 => TxType::from_symbol_set2_12(t),
2511+ 8 => TxType::from_symbol_set1(t),
2512+ _ => TxType::from_symbol(t),
2513+ }
2514+ .ok_or_else(|| unsupported(format!("a tx_type symbol outside its CDF's own set: {t}")))?;
24512515 }
2452- let tx_type = default_tx_type;
24532516 if TxClass::of(tx_type) != TxClass::TwoD {
24542517 return Err(unsupported(
24552518 "a non-2D tx class on a rectangular transform (never expected at this size)",
24562519 ));
24572520 }
2521+ if trace {
2522+ let (rng, _) = dec.debug_state();
2523+ eprintln!("EC_COEFF_STEP tag=tx_type rng={rng}");
2524+ }
24582525 let eob = read_eob(dec, coding, TxClass::TwoD);
24592526 if ec_trace_coeff {
24602527 let (rng, _) = dec.debug_state();
@@ -2509,6 +2576,10 @@ fn read_coeffs_rect(
25092576 level
25102577 };
25112578 levels[pos] = level;
2579+ if trace {
2580+ let (rng, _) = dec.debug_state();
2581+ eprintln!("EC_COEFF_STEP tag=base c={scan_idx} pos={pos} level={level} rng={rng}");
2582+ }
25122583 }
25132584 if ec_trace_coeff {
25142585 let (rng, _) = dec.debug_state();
@@ -2524,6 +2595,10 @@ fn read_coeffs_rect(
25242595 } else {
25252596 dec.literal(1) == 1
25262597 };
2598+ if trace {
2599+ let (rng, _) = dec.debug_state();
2600+ eprintln!("EC_COEFF_STEP tag=sign_rect pos={pos} sign={} rng={rng}", u8::from(negative));
2601+ }
25272602 let level = if level.abs_diff(0) as i32 > MAX_BR_LEVEL {
25282603 let g = read_golomb(dec)?;
25292604 level + g as i32
@@ -3507,6 +3582,25 @@ impl Neighbours {
35073582 is_smooth_mode(above) || is_smooth_mode(left)
35083583 }
35093584
3585+ /// The above/left luma modes libaom's `above_mi`/`left_mi` really see for a
3586+ /// block at coarse [`SUB`]-grid `(r, c)`. lane-rectx r5: the coarse
3587+ /// `above_mode`/`left_mode` slots are written in 16x16 cells, so a
3588+ /// sub-16x16 neighbour (a 16x8 rect leaf, an 8x8 split cell) leaves them
3589+ /// holding an OLDER, larger block's mode -- it only ever recorded into the
3590+ /// mi-exact map. Every `kf_y_mode` reader goes through here, not just the
3591+ /// strip path ([`decode_leaf_rect`] took this override in r4; a 32x16 strip
3592+ /// whose left neighbour was a 16x8 leaf still read the stale row and picked
3593+ /// a different CDF for the same mode value).
3594+ fn modes_above_left(&self, r: usize, c: usize) -> (usize, usize) {
3595+ let (mi_r, mi_c) = (r * (SUB / MI), c * (SUB / MI));
3596+ let above = self.mode_above_mi(mi_r, mi_c).unwrap_or(self.above_mode[c]);
3597+ let left = self.mode_left_mi(mi_r, mi_c).unwrap_or(self.left_mode[r]);
3598+ if above != self.above_mode[c] || left != self.left_mode[r] {
3599+ MODE_MI_OVERRIDE_HITS.with(|h| h.set(h.get() + 1));
3600+ }
3601+ (above, left)
3602+ }
3603+
35103604 fn record_rect(
35113605 &mut self,
35123606 at: (usize, usize),
@@ -3716,6 +3810,13 @@ fn filter_intra_size_class_rect(bw: usize, bh: usize) -> Option<usize> {
37163810 match (bw, bh) {
37173811 (32, 16) => Some(4),
37183812 (16, 32) => Some(5),
3813+ // lane-rectx r3: `av1_filter_intra_allowed_bsize` is "both sides <=
3814+ // 32", so a 16x8/8x16 strip reads the flag too -- returning `None`
3815+ // here dropped that symbol on every DC_PRED strip of that size and
3816+ // desynced the tile (caught against an aomdec EC_TRACE_COEFF ladder:
3817+ // identical mode/uv_mode values, range 34808 vs the oracle's 40668).
3818+ (16, 8) => Some(6),
3819+ (8, 16) => Some(7),
37193820 _ if bw == bh => filter_intra_size_class(bw),
37203821 _ => None,
37213822 }
@@ -4492,12 +4593,13 @@ fn decode_block_rect(
44924593 ) -> Result<()> {
44934594 let (r, c) = at;
44944595 let (px, py) = (c * SUB, r * SUB);
4596+ let (nb_above_mode, nb_left_mode) = neighbours.modes_above_left(r, c);
44954597 let (skip, mode, angle_delta_y, uv_mode, angle_delta_uv, alpha, filter_intra) =
44964598 read_intra_mode_rect(
44974599 dec,
44984600 cdfs,
4499- neighbours.above_mode[c],
4500- neighbours.left_mode[r],
4601+ nb_above_mode,
4602+ nb_left_mode,
45014603 true,
45024604 bw,
45034605 bh,
@@ -4507,8 +4609,7 @@ fn decode_block_rect(
45074609 r * (SUB / MI),
45084610 c * (SUB / MI),
45094611 )?;
4510- let smooth_neighbor =
4511- is_smooth_mode(neighbours.above_mode[c]) || is_smooth_mode(neighbours.left_mode[r]);
4612+ let smooth_neighbor = is_smooth_mode(nb_above_mode) || is_smooth_mode(nb_left_mode);
45124613 if smooth_neighbor {
45134614 SMOOTH_LUMA_HITS.with(|c| c.set(c.get() + 1));
45144615 }
@@ -4849,9 +4950,10 @@ fn decode_block_rect(
48494950 /// writers (`record_mi_rect`, `fill_skip_grid_rect`, `fill_lf_grid_rect`) at
48504951 /// this strip's real position, never the coarse `record_rect` (which the
48514952 /// caller uses once, after both strips, exactly like the `VERT_B` arm next
4852-/// to it). Only the skip case is ported -- see [`decode_block_rect`]'s own
4853-/// doc for why a coded rect strip below 16x16 has no coefficient tables here
4854-/// yet.
4953+/// to it). The non-skip case (lane-rectx) reads real `TX_16X8`/`TX_8X16`
4954+/// luma coefficients (`TxbSet::LumaRect16x8`) and their `TX_8X4`/`TX_4X8`
4955+/// chroma half (`TxbSet::ChromaRect8x4`), the two size classes one level
4956+/// under [`decode_block_rect`]'s own 32x16/16x32 strip.
48554957 #[allow(clippy::too_many_arguments)]
48564958 fn decode_leaf_rect(
48574959 dec: &mut SymbolDecoder,
@@ -4869,8 +4971,15 @@ fn decode_leaf_rect(
48694971 allow_screen_content_tools: bool,
48704972 base_q_idx: u8,
48714973 tx_select: bool,
4974+ reduced_tx_set: bool,
48724975 ) -> Result<usize> {
48734976 let _ = base_q_idx;
4977+ if std::env::var_os("EC_AV1_RECTX_TRACE").is_some() {
4978+ eprintln!(
4979+ "decode_leaf_rect: leaf_mi={leaf_mi:?} bw={bw} bh={bh} outer_at={outer_at:?} rng={}",
4980+ dec.debug_state().0
4981+ );
4982+ }
48744983 let (r, c) = outer_at;
48754984 let mut above_mode = neighbours.above_mode[c];
48764985 let mut left_mode = neighbours.left_mode[r];
@@ -4882,6 +4991,16 @@ fn decode_leaf_rect(
48824991 left_mode = pmode;
48834992 }
48844993 }
4994+ // Same mi-exact override [`decode_leaf8`] takes: one coarse 16x16 slot
4995+ // cannot hold the modes a split (or a pair of strips) leaves behind, so
4996+ // when the map holds the block at exactly this strip's above/left mi it
4997+ // is the neighbour libaom's `above_mi`/`left_mi` reads.
4998+ if let Some(m) = neighbours.mode_above_mi(leaf_mi.0, leaf_mi.1) {
4999+ above_mode = m;
5000+ }
5001+ if let Some(m) = neighbours.mode_left_mi(leaf_mi.0, leaf_mi.1) {
5002+ left_mode = m;
5003+ }
48855004 let smooth_neighbor =
48865005 is_smooth_mode(above_mode) || is_smooth_mode(left_mode);
48875006 if smooth_neighbor {
@@ -4902,6 +5021,9 @@ fn decode_leaf_rect(
49025021 leaf_mi.0,
49035022 leaf_mi.1,
49045023 )?;
5024+ if std::env::var_os("EC_AV1_RECTX_TRACE").is_some() {
5025+ eprintln!(" skip={skip} mode={mode} angle_delta_y={angle_delta_y} uv_mode={uv_mode}");
5026+ }
49055027 if filter_intra.is_some() {
49065028 return Err(unsupported(
49075029 "filter intra on a HORZ/VERT strip (this decoder predicts square-only)",
@@ -4920,73 +5042,105 @@ fn decode_leaf_rect(
49205042 prediction is not ported)",
49215043 ));
49225044 }
4923- if !skip {
4924- return Err(unsupported(
4925- "a coded (non-skip) HORZ/VERT rect strip below 16x16 (this decoder ports only \
4926- the skip case at this size)",
4927- ));
4928- }
49295045 let (px, py) = (leaf_mi.1 * MI, leaf_mi.0 * MI);
49305046 let reach = Reach::of_rect(bw, bh, px, py, y.width, y.height);
49315047 let (cpx, cpy) = (px / 2, py / 2);
49325048 let (chroma_w, chroma_h) = (bw / 2, bh / 2);
4933- y.reconstruct_rect(
4934- px,
4935- py,
4936- bw,
4937- bh,
4938- mode,
4939- angle_delta_y,
4940- reach,
4941- &vec![0i32; bw * bh],
4942- None,
4943- filter_intra,
4944- smooth_neighbor,
4945- );
4946- let ac = alpha.map(|_| cfl_ac_q3_rect(y, px, py, bw, bh));
4947- u.reconstruct_rect(
4948- cpx,
4949- cpy,
4950- chroma_w,
4951- chroma_h,
4952- uv_predict_mode,
4953- angle_delta_uv,
4954- reach,
4955- &vec![0i32; chroma_w * chroma_h],
4956- alpha.zip(ac.as_deref()).map(|((au, _), ac)| (au, ac)),
4957- None,
4958- false,
4959- );
4960- v.reconstruct_rect(
4961- cpx,
4962- cpy,
4963- chroma_w,
4964- chroma_h,
4965- uv_predict_mode,
4966- angle_delta_uv,
4967- reach,
4968- &vec![0i32; chroma_w * chroma_h],
4969- alpha.zip(ac.as_deref()).map(|((_, av), ac)| (av, ac)),
4970- None,
4971- false,
4972- );
4973- neighbours.record_mi_rect(
4974- leaf_mi,
4975- bw,
4976- bh,
4977- &[
4978- vec![0i32; bw * bh],
4979- vec![0i32; chroma_w * chroma_h],
4980- vec![0i32; chroma_w * chroma_h],
4981- ],
4982- );
4983- // lane-sub8 r6: the caller patches only the coarse `above_mode`/
4984- // `left_mode` slot (one value for the whole 16x16), so record this
4985- // strip's own span mi-exactly like every square leaf does.
4986- neighbours.record_mode_mi(leaf_mi.0, leaf_mi.1, mi_w, mi_h, mode);
4987- neighbours.record_uv_mode_mi(leaf_mi.0, leaf_mi.1, mi_w, mi_h, uv_predict_mode);
5049+ let (luma_levels, u_levels, v_levels);
5050+ if skip {
5051+ luma_levels = vec![0i32; bw * bh];
5052+ u_levels = vec![0i32; chroma_w * chroma_h];
5053+ v_levels = vec![0i32; chroma_w * chroma_h];
5054+ y.reconstruct_rect(
5055+ px, py, bw, bh, mode, angle_delta_y, reach, &luma_levels, None, filter_intra,
5056+ smooth_neighbor,
5057+ );
5058+ let ac = alpha.map(|_| cfl_ac_q3_rect(y, px, py, bw, bh));
5059+ u.reconstruct_rect(
5060+ cpx, cpy, chroma_w, chroma_h, uv_predict_mode, angle_delta_uv, reach, &u_levels,
5061+ alpha.zip(ac.as_deref()).map(|((au, _), ac)| (au, ac)), None, false,
5062+ );
5063+ v.reconstruct_rect(
5064+ cpx, cpy, chroma_w, chroma_h, uv_predict_mode, angle_delta_uv, reach, &v_levels,
5065+ alpha.zip(ac.as_deref()).map(|((_, av), ac)| (av, ac)), None, false,
5066+ );
5067+ } else {
5068+ // lane-rectx: a genuine 16x8/8x16 luma transform (`TxbSet::LumaRect16x8`,
5069+ // real `EOB_PT_128_LUMA` alphabet + the same mode-indexed `tx_type`
5070+ // symbol the square `Luma16` set reads -- `get_ext_tx_set_type`'s
5071+ // `use_reduced_set` branch returns `EXT_TX_SET_DTT4_IDTX` at
5072+ // `tx_size_sqr_up == TX_16X16` regardless of the true, non-square
5073+ // `tx_size`) and its chroma half (8x4/4x8, `TxbSet::ChromaRect8x4`).
5074+ let (luma_scan, chroma_scan): (&[u16], &[u16]) = if bw == 16 {
5075+ (&SCAN_16X8, &SCAN_8X4)
5076+ } else {
5077+ (&SCAN_8X16, &SCAN_4X8)
5078+ };
5079+ let around = neighbours.around_mi_rect(leaf_mi, bw, bh);
5080+ let luma_set = if reduced_tx_set {
5081+ TxbSet::LumaRect16x8
5082+ } else {
5083+ TxbSet::LumaRect16x8Set1
5084+ };
5085+ let mut luma_coding = cdfs.txb(luma_set, mode);
5086+ let (l_levels, luma_tx_type) = read_coeffs_rect(
5087+ dec, &mut luma_coding, luma_scan, bw, bh, 0, dc_sign_ctx(around[0].2), TxType::DctDct,
5088+ )?;
5089+ if std::env::var_os("EC_AV1_RECTX_TRACE").is_some() {
5090+ let nz: Vec<(usize, i32)> = l_levels.iter().copied().enumerate().filter(|(_, v)| *v != 0).collect();
5091+ eprintln!(" luma_tx_type={luma_tx_type:?} nz_levels={nz:?}");
5092+ }
5093+ luma_levels = l_levels;
5094+ let luma_residual = dequant_and_inverse_typed_wh(
5095+ &luma_levels, bw, bh, crate::decode::bit_depth(),
5096+ CURRENT_Q_IDX.with(|c| c.get()), plane_q_delta(0).0, plane_q_delta(0).1, luma_tx_type,
5097+ );
5098+ y.reconstruct_rect(
5099+ px, py, bw, bh, mode, angle_delta_y, reach, &luma_residual, None, filter_intra,
5100+ smooth_neighbor,
5101+ );
5102+ let ac = alpha.map(|_| cfl_ac_q3_rect(y, px, py, bw, bh));
5103+ let u_default_tx = default_intra_tx_type(uv_predict_mode as u8);
5104+ let u_skip_ctx = usize::from(around[1].0) + usize::from(around[1].1);
5105+ let mut u_coding = cdfs.txb(TxbSet::ChromaRect8x4, uv_predict_mode);
5106+ let (u_l, u_tx_type) = read_coeffs_rect(
5107+ dec, &mut u_coding, chroma_scan, chroma_w, chroma_h, u_skip_ctx,
5108+ dc_sign_ctx(around[1].2), u_default_tx,
5109+ )?;
5110+ u_levels = u_l;
5111+ let u_residual = dequant_and_inverse_typed_wh(
5112+ &u_levels, chroma_w, chroma_h, crate::decode::bit_depth(),
5113+ CURRENT_Q_IDX.with(|c| c.get()), plane_q_delta(1).0, plane_q_delta(1).1, u_tx_type,
5114+ );
5115+ u.reconstruct_rect(
5116+ cpx, cpy, chroma_w, chroma_h, uv_predict_mode, angle_delta_uv, reach, &u_residual,
5117+ alpha.zip(ac.as_deref()).map(|((au, _), ac)| (au, ac)), None, false,
5118+ );
5119+ let v_default_tx = default_intra_tx_type(uv_predict_mode as u8);
5120+ let v_skip_ctx = usize::from(around[2].0) + usize::from(around[2].1);
5121+ let mut v_coding = cdfs.txb(TxbSet::ChromaRect8x4, uv_predict_mode);
5122+ let (v_l, v_tx_type) = read_coeffs_rect(
5123+ dec, &mut v_coding, chroma_scan, chroma_w, chroma_h, v_skip_ctx,
5124+ dc_sign_ctx(around[2].2), v_default_tx,
5125+ )?;
5126+ v_levels = v_l;
5127+ let v_residual = dequant_and_inverse_typed_wh(
5128+ &v_levels, chroma_w, chroma_h, crate::decode::bit_depth(),
5129+ CURRENT_Q_IDX.with(|c| c.get()), plane_q_delta(2).0, plane_q_delta(2).1, v_tx_type,
5130+ );
5131+ v.reconstruct_rect(
5132+ cpx, cpy, chroma_w, chroma_h, uv_predict_mode, angle_delta_uv, reach, &v_residual,
5133+ alpha.zip(ac.as_deref()).map(|((_, av), ac)| (av, ac)), None, false,
5134+ );
5135+ RECT_LEAF_COEFF_HITS.with(|c| c.set(c.get() + 1));
5136+ }
5137+ neighbours.record_mi_rect(leaf_mi, bw, bh, &[luma_levels, u_levels, v_levels]);
49885138 neighbours.fill_skip_grid_rect(leaf_mi, mi_w, mi_h, skip);
49895139 neighbours.fill_lf_grid_rect(leaf_mi, mi_w, mi_h, bw as u8, bh as u8, 0);
5140+ // A rect leaf spans mi_w x mi_h, so its mode reaches several columns and
5141+ // rows -- record the whole span, not one cell.
5142+ neighbours.record_mode_mi(leaf_mi.0, leaf_mi.1, mi_w, mi_h, mode);
5143+ neighbours.record_uv_mode_mi(leaf_mi.0, leaf_mi.1, mi_w, mi_h, uv_predict_mode);
49905144 Ok(mode)
49915145 }
49925146
@@ -5026,12 +5180,13 @@ fn decode_block_rect64(
50265180 ) -> Result<()> {
50275181 let (r, c) = at;
50285182 let (px, py) = (c * SUB, r * SUB);
5183+ let (nb_above_mode, nb_left_mode) = neighbours.modes_above_left(r, c);
50295184 let (skip, mode, angle_delta_y, uv_mode, angle_delta_uv, alpha, filter_intra) =
50305185 read_intra_mode_rect(
50315186 dec,
50325187 cdfs,
5033- neighbours.above_mode[c],
5034- neighbours.left_mode[r],
5188+ nb_above_mode,
5189+ nb_left_mode,
50355190 // `is_cfl_allowed` (spec 5.11.5) caps CFL at <=32x32; these
50365191 // superblock-level HORZ/VERT strips are 64x32/32x64, so unlike
50375192 // `decode_block_rect`'s own 32x16/16x32 strips (where `true` is
@@ -5048,8 +5203,7 @@ fn decode_block_rect64(
50485203 r * (SUB / MI),
50495204 c * (SUB / MI),
50505205 )?;
5051- let smooth_neighbor =
5052- is_smooth_mode(neighbours.above_mode[c]) || is_smooth_mode(neighbours.left_mode[r]);
5206+ let smooth_neighbor = is_smooth_mode(nb_above_mode) || is_smooth_mode(nb_left_mode);
50535207 if smooth_neighbor {
50545208 SMOOTH_LUMA_HITS.with(|c| c.set(c.get() + 1));
50555209 }
@@ -6260,12 +6414,13 @@ fn decode_block(
62606414 let (px, py) = (c * SUB, r * SUB);
62616415 let (palette_ctx, palette_cache) = neighbours.palette_ctx_and_cache(at);
62626416 let palette_uv_cache = neighbours.palette_uv_cache(at);
6417+ let (nb_above_mode, nb_left_mode) = neighbours.modes_above_left(r, c);
62636418 let (skip, mode, angle_delta_y, uv_mode, angle_delta_uv, alpha, filter_intra, palette_y, palette_uv) =
62646419 read_intra_mode(
62656420 dec,
62666421 cdfs,
6267- neighbours.above_mode[c],
6268- neighbours.left_mode[r],
6422+ nb_above_mode,
6423+ nb_left_mode,
62696424 cfl,
62706425 side,
62716426 enable_filter_intra,
@@ -6295,8 +6450,7 @@ fn decode_block(
62956450 } else {
62966451 uv_mode
62976452 };
6298- let smooth_neighbor =
6299- is_smooth_mode(neighbours.above_mode[c]) || is_smooth_mode(neighbours.left_mode[r]);
6453+ let smooth_neighbor = is_smooth_mode(nb_above_mode) || is_smooth_mode(nb_left_mode);
63006454 if smooth_neighbor {
63016455 SMOOTH_LUMA_HITS.with(|c| c.set(c.get() + 1));
63026456 }
@@ -6686,6 +6840,17 @@ fn decode_block(
66866840 /// at. Returns the mode this leaf decoded, for the caller's own
66876841 /// `prev_leaf`/final mode-writeback bookkeeping.
66886842 #[allow(clippy::too_many_arguments)]
6843+/// The coarse 16x16 `above_mode`/`left_mode` cells a four-way SPLIT of one
6844+/// 16x16 parent leaves behind (lane-rectx r3). The next block DOWN reads
6845+/// `above_mode[col]`, and its true above neighbour is the mi directly above
6846+/// its own top-left corner -- the parent's BOTTOM-LEFT leaf, not the last one
6847+/// decoded; the next block RIGHT reads `left_mode[row]`, whose true left
6848+/// neighbour is the parent's TOP-RIGHT leaf. Writing the z-order last leaf
6849+/// (bottom-right) into both, as this path did, is right only when all four
6850+/// leaves happen to share a mode. `done` may be short at the true frame edge
6851+/// (the straddle caller filters positions off the frame), so each side falls
6852+/// back to the last leaf actually decoded.
6853+
66896854 fn decode_leaf8(
66906855 dec: &mut SymbolDecoder,
66916856 cdfs: &mut Cdfs,
@@ -9305,6 +9470,7 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
93059470 allow_screen_content_tools,
93069471 base_q_idx,
93079472 tx_select,
9473+ reduced_tx_set,
93089474 )?;
93099475 let mode_bot = decode_leaf_rect(
93109476 &mut dec,
@@ -9322,6 +9488,7 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
93229488 allow_screen_content_tools,
93239489 base_q_idx,
93249490 tx_select,
9491+ reduced_tx_set,
93259492 )?;
93269493 neighbours.above_mode[sc] = mode_bot;
93279494 neighbours.left_mode[sr] = mode_bot;
@@ -9351,6 +9518,7 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
93519518 allow_screen_content_tools,
93529519 base_q_idx,
93539520 tx_select,
9521+ reduced_tx_set,
93549522 )?;
93559523 let mode_right = decode_leaf_rect(
93569524 &mut dec,
@@ -9368,6 +9536,7 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
93689536 allow_screen_content_tools,
93699537 base_q_idx,
93709538 tx_select,
9539+ reduced_tx_set,
93719540 )?;
93729541 neighbours.above_mode[sc] = mode_right;
93739542 neighbours.left_mode[sr] = mode_right;
@@ -9401,7 +9570,7 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
94019570 // around each leaf call and restored
94029571 // after; the loop tail writes the last
94039572 // leaf's mode as before.
9404- let mut sib_modes: [Option<(usize, usize)>; 4] = [None; 4];
9573+ let mut sib_modes: [Option<(usize, usize)>; 4] = [None; 4];
94059574 for i in 0..4 {
94069575 let (mr, mc) =
94079576 (mi_row0 + (i / 2) * 2, mi_col0 + (i % 2) * 2);
@@ -17298,6 +17467,72 @@ mod tests {
1729817467 // this decoder's one target, and the round-trip test below is against
1729917468 // that path with real quantised residual, not a synthetic all-DC frame.
1730017469
17470+ /// [`SCAN_8X4`]/[`SCAN_4X8`] (lane-rectx r2): a bijection check alone
17471+ /// cannot catch a transposed pair -- a swap of two orientation tables is
17472+ /// still a bijection over the same 32 positions. This pins BOTH arrays
17473+ /// at once, element-for-element, against literal transcriptions of
17474+ /// libaom's real `default_scan_4x8`/`default_scan_8x4` in
17475+ /// `av1/common/scan.c` (`~/.cache/aom-oracle/src`, read directly for
17476+ /// this test, not re-derived from the zigzag formula). The two source
17477+ /// sequences are themselves different in their own right (not equal to
17478+ /// each other), so this is asymmetric in the two axes: if the repo's
17479+ /// `SCAN_8X4`/`SCAN_4X8` were swapped with each other, one side of this
17480+ /// assert pair would fail even though each individual array would still
17481+ /// pass a same-orientation bijection test.
17482+ #[test]
17483+ fn scan_8x4_and_4x8_are_not_transposed_against_each_other() {
17484+ // libaom `default_scan_4x8` verbatim (scan.c:29-32) -- this repo
17485+ // names it `SCAN_8X4` under the established w/h axis swap (see
17486+ // `SCAN_8X4`'s own doc comment).
17487+ const LIBAOM_DEFAULT_SCAN_4X8: [u16; 32] = [
17488+ 0, 8, 1, 16, 9, 2, 24, 17, 10, 3, 25, 18, 11, 4, 26, 19, 12, 5, 27, 20, 13, 6, 28, 21,
17489+ 14, 7, 29, 22, 15, 30, 23, 31,
17490+ ];
17491+ // libaom `default_scan_8x4` verbatim (scan.c:44-47) -- this repo's
17492+ // `SCAN_4X8`.
17493+ const LIBAOM_DEFAULT_SCAN_8X4: [u16; 32] = [
17494+ 0, 1, 4, 2, 5, 8, 3, 6, 9, 12, 7, 10, 13, 16, 11, 14, 17, 20, 15, 18, 21, 24, 19, 22,
17495+ 25, 28, 23, 26, 29, 27, 30, 31,
17496+ ];
17497+ assert_ne!(
17498+ LIBAOM_DEFAULT_SCAN_4X8, LIBAOM_DEFAULT_SCAN_8X4,
17499+ "the two libaom source sequences must differ, or this pin would \
17500+ pass regardless of a swap"
17501+ );
17502+ assert_eq!(SCAN_8X4, LIBAOM_DEFAULT_SCAN_4X8, "SCAN_8X4 vs libaom default_scan_4x8");
17503+ assert_eq!(SCAN_4X8, LIBAOM_DEFAULT_SCAN_8X4, "SCAN_4X8 vs libaom default_scan_8x4");
17504+ }
17505+
17506+ /// lane-rectx r3: `av1_filter_intra_allowed_bsize` is "both sides <= 32",
17507+ /// so a DC_PRED 16x8/8x16 strip reads a `use_filter_intra` flag exactly
17508+ /// like a square 16x16 does. [`filter_intra_size_class_rect`] returned
17509+ /// `None` at those two sizes, so the symbol was never read and the tile
17510+ /// desynced from that block on (root-caused against an instrumented
17511+ /// aomdec `EC_TRACE_COEFF` ladder on a real stream: identical `mode=0`/
17512+ /// `uv_mode=9` values, our range 34808 vs the oracle's 40668 at the very
17513+ /// next transform block).
17514+ ///
17515+ /// The two rows are ASYMMETRIC (9394 for 16x8, 12551 for 8x16), so this
17516+ /// pin fails if the pair is ever transposed -- the shape the repo's
17517+ /// scan tables already carry (`SCAN_8X4` == libaom `default_scan_4x8`).
17518+ #[test]
17519+ fn a_rect_strip_below_16x16_reads_its_own_filter_intra_cdf_row() {
17520+ // `default_filter_intra_cdfs` (entropymode.c), indexed by BLOCK_SIZES_ALL:
17521+ // [4] = BLOCK_8X16, [5] = BLOCK_16X8, [7] = BLOCK_16X32, [8] = BLOCK_32X16.
17522+ const LIBAOM_8X16: u16 = 12551;
17523+ const LIBAOM_16X8: u16 = 9394;
17524+ let c16x8 = filter_intra_size_class_rect(16, 8).expect("16x8 reads use_filter_intra");
17525+ let c8x16 = filter_intra_size_class_rect(8, 16).expect("8x16 reads use_filter_intra");
17526+ assert_ne!(c16x8, c8x16, "the two orientations must not share a CDF row");
17527+ assert_eq!(cdf::FILTER_INTRA[c16x8][0], LIBAOM_16X8, "16x8 filter_intra row");
17528+ assert_eq!(cdf::FILTER_INTRA[c8x16][0], LIBAOM_8X16, "8x16 filter_intra row");
17529+ // The sizes one class up keep their own distinct rows (lane-intradisp).
17530+ assert_eq!(cdf::FILTER_INTRA[filter_intra_size_class_rect(32, 16).unwrap()][0], 12756);
17531+ assert_eq!(cdf::FILTER_INTRA[filter_intra_size_class_rect(16, 32).unwrap()][0], 14301);
17532+ // A size with a side over 32 is genuinely not allowed the flag.
17533+ assert_eq!(filter_intra_size_class_rect(64, 32), None);
17534+ }
17535+
1730117536 /// `is_uni_comp_ref` (lane-av1comp): a pair is unidirectional exactly
1730217537 /// when both references sit on the same temporal side -- the three
1730317538 /// `uni_comp_ref` bitstream pairs (LAST/LAST2, LAST/LAST3, LAST/GOLDEN)
crates/ec-av1/src/encode.rsmodified+119 -20
@@ -1131,6 +1131,38 @@ const HAS_TOP_RIGHT_RECT: [&[u8]; 2] = [&[15, 5, 7, 5], &[255, 119, 127, 119]];
11311131 /// `has_bl_32x16`/`has_bl_16x32`, same source, same order.
11321132 const HAS_BOTTOM_LEFT_RECT: [&[u8]; 2] = [&[78, 14, 78, 14], &[16, 0, 16, 0]];
11331133
1134+/// libaom `reconintra.c`'s `has_tr_*`/`has_bl_*` for the four rectangular
1135+/// block sizes this decoder codes, transcribed verbatim (lane-rectx r4).
1136+/// The 16x8/8x16 rows are what the 32x16/16x32 pair above cannot stand in
1137+/// for: they are 16 bytes, not 4, and their bit pattern is a different
1138+/// coding order entirely -- reading the 16x32 table for a 16x8 block gave
1139+/// the wrong bottom-left availability and a directional (D203) strip whose
1140+/// prediction diverged exactly where it starts reading below its own height.
1141+/// `has_tr_vert_tables`/`has_bl_vert_tables` hold the SAME pointers as these
1142+/// for every W<H entry, and are NULL for W>H (no VERT_A/B ever produces one),
1143+/// so the partition type does not select a different table at these sizes.
1144+fn has_tr_rect_table(bw: usize, bh: usize) -> &'static [u8] {
1145+ match (bw, bh) {
1146+ (16, 8) => &[255, 0, 85, 0, 119, 0, 85, 0, 127, 0, 85, 0, 119, 0, 85, 0],
1147+ (8, 16) => &[255, 255, 119, 119, 127, 127, 119, 119, 255, 127, 119, 119, 127, 127, 119, 119],
1148+ (32, 16) => &[15, 5, 7, 5],
1149+ (16, 32) => &[255, 119, 127, 119],
1150+ (64, 32) => &[19],
1151+ _ => &[127],
1152+ }
1153+}
1154+
1155+fn has_bl_rect_table(bw: usize, bh: usize) -> &'static [u8] {
1156+ match (bw, bh) {
1157+ (16, 8) => &[254, 84, 254, 16, 254, 84, 254, 0, 254, 84, 254, 16, 254, 84, 254, 0],
1158+ (8, 16) => &[16, 17, 0, 1, 16, 17, 0, 0, 16, 17, 0, 1, 16, 17, 0, 0],
1159+ (32, 16) => &[78, 14, 78, 14],
1160+ (16, 32) => &[16, 0, 16, 0],
1161+ (64, 32) => &[34],
1162+ _ => &[0],
1163+ }
1164+}
1165+
11341166 impl Reach {
11351167 /// What a block of `side` samples at `(x, y)` may read past its own edges,
11361168 /// in a frame of `width` by `height`.
@@ -1160,37 +1192,61 @@ impl Reach {
11601192 }
11611193 }
11621194
1163- fn position_rect(bw: usize, bh: usize, x: usize, y: usize) -> (usize, usize, usize, usize) {
1164- (
1165- (y % SUPERBLOCK) / bh,
1166- (x % SUPERBLOCK) / bw,
1167- SUPERBLOCK / bh,
1168- SUPERBLOCK / bw,
1169- )
1170- }
1171-
1195+ /// libaom `has_top_right` at block granularity (`row_off`/`col_off` 0,
1196+ /// the transform covering the whole block, luma): everything before the
1197+ /// table lookup is that function's own early-exit ladder.
11721198 fn top_right_rect(bw: usize, bh: usize, x: usize, y: usize) -> bool {
1173- let (row, col, _per_row, per_col) = Self::position_rect(bw, bh, x, y);
1174- if row == 0 {
1199+ const SB_MI: usize = SUPERBLOCK / 4;
1200+ let (mi_row, mi_col) = (y / 4, x / 4);
1201+ let bw_log2 = (bw / 4).trailing_zeros() as usize;
1202+ let bh_log2 = (bh / 4).trailing_zeros() as usize;
1203+ let blk_row = (mi_row & (SB_MI - 1)) >> bh_log2;
1204+ let blk_col = (mi_col & (SB_MI - 1)) >> bw_log2;
1205+ // Top row of the superblock: the top-right pixels are in the (already
1206+ // decoded) superblock above.
1207+ if blk_row == 0 {
11751208 return true;
11761209 }
1177- if col + 1 == per_col {
1210+ // Rightmost column: they fall in the superblock to the right.
1211+ if ((blk_col + 1) << bw_log2) >= SB_MI {
11781212 return false;
11791213 }
1180- let table = HAS_TOP_RIGHT_RECT[usize::from(bw == 16)];
1181- Self::bit(table, (row * Self::table_stride(bw) + col) % (table.len() * 8))
1214+ let table = has_tr_rect_table(bw, bh);
1215+ Self::bit(table, Self::rect_table_index(bw_log2, blk_row, blk_col))
1216+ }
1217+
1218+ /// libaom `has_top_right`'s own index arithmetic:
1219+ /// `(blk_row << (MAX_MIB_SIZE_LOG2 - bw_in_mi_log2)) + blk_col`, and
1220+ /// `MAX_MIB_SIZE_LOG2` is 5 (`enums.h`: libaom's tables are laid out for a
1221+ /// 128x128 superblock = 32 mi), NOT this crate's 64x64 = 16. lane-rectx r5:
1222+ /// r4 wrote `4 - bw_log2`, halving the row stride -- every table row but
1223+ /// the first then read the wrong byte (16x8 wrong at 80 mi positions in a
1224+ /// 64-wide SB, 8x16 at 16, 32x16 at 64, a regression against main).
1225+ /// [`tests::rect_reach_tables_are_indexed_with_a_32_mi_row_stride`] pins it.
1226+ fn rect_table_index(bw_log2: usize, blk_row: usize, blk_col: usize) -> usize {
1227+ (blk_row << (5 - bw_log2)) + blk_col
11821228 }
11831229
1230+ /// libaom `has_bottom_left`, same granularity as [`Self::top_right_rect`].
11841231 fn bottom_left_rect(bw: usize, bh: usize, x: usize, y: usize) -> bool {
1185- let (row, col, per_row, _per_col) = Self::position_rect(bw, bh, x, y);
1186- if col == 0 {
1187- return row * bh + bh < SUPERBLOCK;
1232+ const SB_MI: usize = SUPERBLOCK / 4;
1233+ let (mi_row, mi_col) = (y / 4, x / 4);
1234+ let bw_log2 = (bw / 4).trailing_zeros() as usize;
1235+ let bh_log2 = (bh / 4).trailing_zeros() as usize;
1236+ let blk_row = (mi_row & (SB_MI - 1)) >> bh_log2;
1237+ let blk_col = (mi_col & (SB_MI - 1)) >> bw_log2;
1238+ // Leftmost column of the superblock: the bottom-left pixels are in
1239+ // the left superblock iff they stay inside its height.
1240+ if blk_col == 0 {
1241+ return (blk_row << bh_log2) + (bh / 4) < SB_MI;
11881242 }
1189- if row + 1 == per_row {
1243+ // Bottom row (and not the leftmost column): they fall in the
1244+ // superblock below, which is not decoded yet.
1245+ if ((blk_row + 1) << bh_log2) >= SB_MI {
11901246 return false;
11911247 }
1192- let table = HAS_BOTTOM_LEFT_RECT[usize::from(bw == 16)];
1193- Self::bit(table, (row * Self::table_stride(bw) + col) % (table.len() * 8))
1248+ let table = has_bl_rect_table(bw, bh);
1249+ Self::bit(table, Self::rect_table_index(bw_log2, blk_row, blk_col))
11941250 }
11951251
11961252 /// Marks every [`Reach::of`] made until the returned guard drops as being
@@ -3169,6 +3225,49 @@ pub fn encode_sequence(
31693225
31703226 #[cfg(test)]
31713227 mod tests {
3228+
3229+ /// lane-rectx r5: libaom lays `has_tr_*`/`has_bl_*` out row-major for a
3230+ /// 128x128 superblock -- `MAX_MIB_SIZE_LOG2 = 5` mi columns per row, so a
3231+ /// row holds `32 >> bw_in_mi_log2` bits and the table holds
3232+ /// `32 >> bh_in_mi_log2` such rows. Walking every block position of that
3233+ /// superblock must therefore hit every bit of the table EXACTLY ONCE.
3234+ /// r4's `4 - bw_log2` index halved the row stride: the walk then covered
3235+ /// only a quarter of the 16x8 table and read the wrong byte for every
3236+ /// block row but the first (silently wrong above-right/below-left
3237+ /// availability -- wrong pixels, no error).
3238+ #[test]
3239+ fn rect_reach_tables_are_indexed_with_a_32_mi_row_stride() {
3240+ for (bw, bh) in [(16usize, 8usize), (8, 16), (32, 16), (16, 32), (64, 32), (32, 64)] {
3241+ let (bw_log2, bh_log2) =
3242+ ((bw / 4).trailing_zeros() as usize, (bh / 4).trailing_zeros() as usize);
3243+ let (rows, cols) = (32 >> bh_log2, 32 >> bw_log2);
3244+ for (name, table) in
3245+ [("has_tr", has_tr_rect_table(bw, bh)), ("has_bl", has_bl_rect_table(bw, bh))]
3246+ {
3247+ assert_eq!(
3248+ table.len() * 8,
3249+ rows * cols,
3250+ "{name}_{bw}x{bh}: libaom's table is {rows} rows of {cols} bits"
3251+ );
3252+ let mut seen = vec![0u32; table.len() * 8];
3253+ for blk_row in 0..rows {
3254+ for blk_col in 0..cols {
3255+ let idx = Reach::rect_table_index(bw_log2, blk_row, blk_col);
3256+ assert!(
3257+ idx < seen.len(),
3258+ "{name}_{bw}x{bh}: index {idx} past the table at ({blk_row},{blk_col})"
3259+ );
3260+ seen[idx] += 1;
3261+ }
3262+ }
3263+ assert!(
3264+ seen.iter().all(|&n| n == 1),
3265+ "{name}_{bw}x{bh}: the block walk is not a bijection onto the table's bits \
3266+ (row stride is not {cols})"
3267+ );
3268+ }
3269+ }
3270+ }
31723271 use super::*;
31733272 use crate::intra::{D45_PRED, D135_PRED, H_PRED, KEY_FRAME_MODES, NON_DIRECTIONAL, V_PRED};
31743273 use std::io::Write;
crates/ec-av1/src/refusal_inventory.rsmodified+0 -2
@@ -28,13 +28,11 @@ const CAPABILITY_CLAIMS: &[&str] = &[
2828 "a non-2D tx class on a rectangular transform (never expected at this size)",
2929 "a non-DC chroma mode on an 8x8 inter-frame leaf (this encoder never writes one)",
3030 "a nonzero angle delta (this encoder never writes one)",
31- "a tx_type symbol on a rectangular transform (never expected at this size)",
3231 ];
3332
3433 #[cfg(test)]
3534 const REFUSALS: &[&str] = &[
3635 "a coded (non-skip) HORZ_B/VERT_B rect strip below 16x16 (this decoder ports only the skip case at this size)",
37- "a coded (non-skip) HORZ/VERT rect strip below 16x16 (this decoder ports only the skip case at this size)",
3836 "a coded HORZ/VERT strip whose chroma transform has no rect coefficient tables here",
3937 "a HORZ/VERT intra strip below 16x16 with a split transform (per-unit rect prediction is not ported)",
4038 "a HORZ_A/HORZ_B/VERT_A partition below 16x16 (this decoder codes only the square arms, HORZ, VERT, VERT_B, and a clean split below 16x16)",
crates/ec-av1/src/stream.rsmodified+324 -0
@@ -7924,6 +7924,330 @@ mod tests {
79247924 result.as_ref().map(|f| f.len()).map_err(|e| e.to_string())
79257925 );
79267926 }
7927+ /// lane-rectx r3: a real `aomenc` stream whose 16x16-level
7928+ /// `PARTITION_HORZ`/`PARTITION_VERT` strips are CODED (non-skip), i.e.
7929+ /// carry genuine `TX_16X8`/`TX_8X16` luma coefficients and their
7930+ /// `TX_8X4`/`TX_4X8` chroma halves through [`decode_leaf_rect`]'s
7931+ /// lane-rectx arm -- the refusal "a coded (non-skip) HORZ/VERT rect strip
7932+ /// below 16x16" this round lifts. `--min-partition-size=8
7933+ /// --max-partition-size=32 --enable-rect-partitions=1` is what makes
7934+ /// aomenc reach for a 16x8 leaf at all; mandelbrot at `cq-level=24` is
7935+ /// what makes those leaves non-skip (a gradient fixture codes them all
7936+ /// away). `--reduced-tx-type-set=1` pins the five-symbol
7937+ /// `EXT_TX_SET_DTT4_IDTX` alphabet: without it aomenc also writes
7938+ /// `V_DCT`/`H_DCT`, whose 1D tx classes [`read_coeffs_rect`] still
7939+ /// refuses by name (see the r3 report's open residue), so a `=0` run
7940+ /// would prove nothing about the 2D path it does support.
7941+ ///
7942+ /// r2 shipped this path unproven; it was wrong. `TxbSet::LumaRect16x8`
7943+ /// read its `tx_type` symbol from the 16x16 row, but libaom's
7944+ /// `read_tx_type` indexes `intra_ext_tx_cdf[eset][txsize_sqr_map[tx_size]]`
7945+ /// and `txsize_sqr_map[TX_16X8] == TX_8X8` -- a five-symbol CDF where a
7946+ /// seven-symbol one belonged, desyncing at the FIRST coded rect leaf
7947+ /// (whole frame wrong from pixel (0,0)).
7948+ #[test]
7949+ fn a_real_aomenc_stream_with_a_coded_rect_strip_below_16x16_decodes_pixel_exact() {
7950+ const NAME: &str =
7951+ "a_real_aomenc_stream_with_a_coded_rect_strip_below_16x16_decodes_pixel_exact";
7952+ let _gate_lock = lock_gate_counters();
7953+ if !have_ffmpeg() {
7954+ eprintln!("SKIP {NAME}: no ffmpeg");
7955+ return;
7956+ }
7957+ if !have_aomenc() {
7958+ eprintln!("SKIP {NAME}: no aomenc at {}", aomenc_path().display());
7959+ return;
7960+ }
7961+ let (width, height) = (64usize, 64usize);
7962+ let y4m = Command::new("ffmpeg")
7963+ .args([
7964+ "-v",
7965+ "error",
7966+ "-f",
7967+ "lavfi",
7968+ "-i",
7969+ &format!("mandelbrot=size={width}x{height}:start_x=-0.6"),
7970+ "-pix_fmt",
7971+ "yuv420p",
7972+ "-t",
7973+ "1",
7974+ "-vframes",
7975+ "1",
7976+ "-f",
7977+ "yuv4mpegpipe",
7978+ "-",
7979+ ])
7980+ .stdin(Stdio::null())
7981+ .stdout(Stdio::piped())
7982+ .stderr(Stdio::piped())
7983+ .output()
7984+ .expect("ffmpeg failed to run");
7985+ assert!(y4m.status.success(), "ffmpeg fixture: {}", String::from_utf8_lossy(&y4m.stderr));
7986+ let encode = || {
7987+ let mut child = Command::new(aomenc_path())
7988+ .args([
7989+ "--codec=av1",
7990+ "--passes=1",
7991+ "--end-usage=q",
7992+ "--cq-level=16",
7993+ "--cpu-used=4",
7994+ "--threads=1",
7995+ "--row-mt=0",
7996+ "--sb-size=64",
7997+ "--kf-max-dist=0",
7998+ "--enable-rect-partitions=1",
7999+ "--enable-ab-partitions=0",
8000+ "--enable-1to4-partitions=0",
8001+ "--enable-tx-size-search=0",
8002+ // Filter intra on a strip is a separate, still-refused
8003+ // predictor (`filter intra on a HORZ/VERT strip`); this
8004+ // gate is about the rect RESIDUAL path, so it is off here
8005+ // and covered by the square filter-intra gate instead.
8006+ "--enable-filter-intra=0",
8007+ "--reduced-tx-type-set=1",
8008+ "--min-partition-size=8",
8009+ "--max-partition-size=32",
8010+ "--obu",
8011+ "-o",
8012+ "-",
8013+ "-",
8014+ ])
8015+ .stdin(Stdio::piped())
8016+ .stdout(Stdio::piped())
8017+ .stderr(Stdio::piped())
8018+ .spawn()
8019+ .expect("aomenc failed to start");
8020+ child
8021+ .stdin
8022+ .take()
8023+ .expect("aomenc stdin")
8024+ .write_all(&y4m.stdout)
8025+ .expect("writing y4m to aomenc");
8026+ let out = child.wait_with_output().expect("aomenc failed to run");
8027+ assert!(
8028+ out.status.success(),
8029+ "aomenc refused the fixture: {}",
8030+ String::from_utf8_lossy(&out.stderr)
8031+ );
8032+ out.stdout
8033+ };
8034+ // The fixture rule: an encoder output is only a pin if it reproduces.
8035+ let stream = encode();
8036+ assert_eq!(stream, encode(), "{NAME}: aomenc output is not reproducible for this recipe");
8037+ let before = crate::decode::rect_leaf_coeff_hits();
8038+ let frames = decode_stream(&stream)
8039+ .unwrap_or_else(|e| panic!("{NAME}: decode failed, not a pixel mismatch: {e}"));
8040+ let fired = crate::decode::rect_leaf_coeff_hits() - before;
8041+ assert!(
8042+ fired > 0,
8043+ "{NAME}: the stream decoded but no coded (non-skip) rect leaf fired -- \
8044+ the gate proves nothing"
8045+ );
8046+ let ffmpeg_frames = ffmpeg_decode_sequence(&stream, width, height, frames.len());
8047+ assert_eq!(frames.len(), 1, "{NAME}: expected one key frame");
8048+ assert_eq!(ffmpeg_frames.len(), frames.len(), "{NAME}: ffmpeg frame count");
8049+ for (i, (got, want)) in frames.iter().zip(&ffmpeg_frames).enumerate() {
8050+ assert_eq!(got.y, want.y, "{NAME} frame {i} luma vs ffmpeg ({fired} coded rect leaves)");
8051+ assert_eq!(got.u, want.u, "{NAME} frame {i} U vs ffmpeg");
8052+ assert_eq!(got.v, want.v, "{NAME} frame {i} V vs ffmpeg");
8053+ }
8054+ eprintln!("{NAME}: pixel-exact, rect_leaf_coeff_hits={fired}");
8055+ }
8056+
8057+ /// lane-rectx r5: the same 16x8/8x16 rect leaves, but this time proving
8058+ /// what a LATER, non-strip block reads from them. `decode_leaf_rect` took
8059+ /// the mi-exact intra mode map in r4; `decode_block`/`decode_block_rect`/
8060+ /// `decode_block_rect64` did not, so a 32x16 strip whose left neighbour was
8061+ /// a 16x8 leaf still read the coarse per-16x16 `left_mode` slot -- which no
8062+ /// sub-16x16 block ever writes -- and picked a DIFFERENT `kf_y_mode` CDF row
8063+ /// for the same decoded mode value. The stream stayed in sync through mode
8064+ /// info (`EC_TRACE_MODE_STEP` ranges match up to that symbol) and then
8065+ /// diverged inside the block's own coefficients: the whole bottom-right
8066+ /// 32x32 quadrant of this fixture decoded wrong (1650 bytes) while the
8067+ /// three earlier quadrants were exact -- wrong pixels returned as success.
8068+ /// `mode_mi_override_hits` counts exactly the reads where the mi-exact
8069+ /// neighbour disagrees with the coarse slot, so a regression that drops the
8070+ /// override again fails the counter as well as the pixels.
8071+ #[test]
8072+ fn a_real_aomenc_stream_whose_square_block_reads_a_sub16_neighbours_mode_decodes_pixel_exact() {
8073+ const NAME: &str =
8074+ "a_real_aomenc_stream_whose_square_block_reads_a_sub16_neighbours_mode_decodes_pixel_exact";
8075+ let _gate_lock = lock_gate_counters();
8076+ if !have_ffmpeg() {
8077+ eprintln!("SKIP {NAME}: no ffmpeg");
8078+ return;
8079+ }
8080+ if !have_aomenc() {
8081+ eprintln!("SKIP {NAME}: no aomenc at {}", aomenc_path().display());
8082+ return;
8083+ }
8084+ let (width, height) = (64usize, 64usize);
8085+ let y4m = Command::new("ffmpeg")
8086+ .args([
8087+ "-v", "error", "-f", "lavfi", "-i",
8088+ &format!("rgbtestsrc=size={width}x{height}"),
8089+ "-pix_fmt", "yuv420p", "-t", "1", "-vframes", "1", "-f", "yuv4mpegpipe", "-",
8090+ ])
8091+ .stdin(Stdio::null())
8092+ .stdout(Stdio::piped())
8093+ .stderr(Stdio::piped())
8094+ .output()
8095+ .expect("ffmpeg failed to run");
8096+ assert!(y4m.status.success(), "ffmpeg fixture: {}", String::from_utf8_lossy(&y4m.stderr));
8097+ // Two swept cells of the r4 sweep that decoded to completion with
8098+ // WRONG pixels (1714 and 1650 bytes): `--reduced-tx-type-set` and
8099+ // `--enable-filter-intra` are the two axes that move which block sizes
8100+ // aomenc reaches for here; both arms are pinned.
8101+ let mut total_overrides = 0usize;
8102+ for (rtx, filter_intra) in [("1", "0"), ("0", "1")] {
8103+ let encode = || {
8104+ let mut child = Command::new(aomenc_path())
8105+ .args([
8106+ "--codec=av1", "--passes=1", "--end-usage=q", "--cq-level=32",
8107+ "--cpu-used=4", "--threads=1", "--row-mt=0", "--sb-size=64",
8108+ "--kf-max-dist=0", "--enable-rect-partitions=1",
8109+ "--enable-ab-partitions=0", "--enable-1to4-partitions=0",
8110+ "--enable-tx-size-search=0", "--enable-cdef=0",
8111+ "--enable-restoration=0",
8112+ &format!("--enable-filter-intra={filter_intra}"),
8113+ &format!("--reduced-tx-type-set={rtx}"),
8114+ "--min-partition-size=8", "--max-partition-size=32",
8115+ "--obu", "-o", "-", "-",
8116+ ])
8117+ .stdin(Stdio::piped())
8118+ .stdout(Stdio::piped())
8119+ .stderr(Stdio::piped())
8120+ .spawn()
8121+ .expect("aomenc failed to start");
8122+ child
8123+ .stdin
8124+ .take()
8125+ .expect("aomenc stdin")
8126+ .write_all(&y4m.stdout)
8127+ .expect("writing y4m to aomenc");
8128+ let out = child.wait_with_output().expect("aomenc failed to run");
8129+ assert!(
8130+ out.status.success(),
8131+ "aomenc refused the fixture: {}",
8132+ String::from_utf8_lossy(&out.stderr)
8133+ );
8134+ out.stdout
8135+ };
8136+ let stream = encode();
8137+ assert_eq!(
8138+ stream,
8139+ encode(),
8140+ "{NAME}: aomenc output is not reproducible (rtx={rtx} filter_intra={filter_intra})"
8141+ );
8142+ let before = crate::decode::mode_mi_override_hits();
8143+ let frames = decode_stream(&stream).unwrap_or_else(|e| {
8144+ panic!("{NAME}: decode failed (rtx={rtx} filter_intra={filter_intra}): {e}")
8145+ });
8146+ // Counted only on an attempt that actually decoded AND is compared
8147+ // below -- a refusal never contributes to the firing assert.
8148+ let overrides = crate::decode::mode_mi_override_hits() - before;
8149+ let ffmpeg_frames = ffmpeg_decode_sequence(&stream, width, height, frames.len());
8150+ assert_eq!(frames.len(), 1, "{NAME}: expected one key frame");
8151+ assert_eq!(ffmpeg_frames.len(), frames.len(), "{NAME}: ffmpeg frame count");
8152+ for (i, (got, want)) in frames.iter().zip(&ffmpeg_frames).enumerate() {
8153+ assert_eq!(
8154+ got.y, want.y,
8155+ "{NAME} frame {i} luma vs ffmpeg (rtx={rtx} filter_intra={filter_intra}, \
8156+ {overrides} mi-exact mode overrides)"
8157+ );
8158+ assert_eq!(got.u, want.u, "{NAME} frame {i} U vs ffmpeg (rtx={rtx})");
8159+ assert_eq!(got.v, want.v, "{NAME} frame {i} V vs ffmpeg (rtx={rtx})");
8160+ }
8161+ total_overrides += overrides;
8162+ }
8163+ assert!(
8164+ total_overrides > 0,
8165+ "{NAME}: no non-strip block ever read a mi-exact neighbour that disagreed with its \
8166+ coarse slot -- the gate proves nothing"
8167+ );
8168+ eprintln!("{NAME}: pixel-exact, mode_mi_override_hits={total_overrides}");
8169+ }
8170+
8171+ #[test]
8172+ #[ignore = "lane-rectx r3 scratch sweep"]
8173+ fn sweep_rectx_recipes() {
8174+ let _gate_lock = lock_gate_counters();
8175+ let srcs: Vec<String> = vec![
8176+ "mandelbrot=size=64x64:start_x=0.4".into(),
8177+ "mandelbrot=size=64x64:start_x=-0.6".into(),
8178+ "mandelbrot=size=64x64:start_x=0.1".into(),
8179+ "mandelbrot=size=128x128:start_x=0.4".into(),
8180+ "mandelbrot=size=128x128:start_x=-0.6".into(),
8181+ "testsrc2=size=64x64".into(),
8182+ "testsrc2=size=128x128".into(),
8183+ "rgbtestsrc=size=64x64".into(),
8184+ "smptebars=size=128x128".into(),
8185+ ];
8186+ for start_x in srcs {
8187+ let y4m = Command::new("ffmpeg")
8188+ .args([
8189+ "-v", "error", "-f", "lavfi", "-i",
8190+ &start_x,
8191+ "-pix_fmt", "yuv420p", "-t", "1", "-vframes", "1", "-f", "yuv4mpegpipe", "-",
8192+ ])
8193+ .stdin(Stdio::null()).stdout(Stdio::piped()).stderr(Stdio::piped())
8194+ .output().expect("ffmpeg");
8195+ assert!(y4m.status.success());
8196+ let (width, height) = if start_x.contains("128x128") { (128usize, 128usize) } else { (64usize, 64usize) };
8197+ for cq in [16u32, 20, 24, 28, 32, 40, 50] {
8198+ for rtx in ["0", "1"] {
8199+ let mut child = Command::new(aomenc_path())
8200+ .args([
8201+ "--codec=av1", "--passes=1", "--end-usage=q",
8202+ &format!("--cq-level={cq}"), "--cpu-used=4", "--threads=1",
8203+ "--row-mt=0", "--sb-size=64", "--kf-max-dist=0",
8204+ "--enable-rect-partitions=1", "--enable-ab-partitions=0",
8205+ "--enable-1to4-partitions=0", "--enable-tx-size-search=0",
8206+ "--enable-cdef=0", "--enable-restoration=0",
8207+ &format!("--reduced-tx-type-set={rtx}"),
8208+ "--min-partition-size=8", "--max-partition-size=32",
8209+ "--obu", "-o", "-", "-",
8210+ ])
8211+ .stdin(Stdio::piped()).stdout(Stdio::piped()).stderr(Stdio::piped())
8212+ .spawn().expect("aomenc");
8213+ child.stdin.take().unwrap().write_all(&y4m.stdout).unwrap();
8214+ let out = child.wait_with_output().unwrap();
8215+ assert!(out.status.success());
8216+ let stream = out.stdout;
8217+ let before = crate::decode::rect_leaf_coeff_hits();
8218+ let res = decode_stream(&stream);
8219+ let fired = crate::decode::rect_leaf_coeff_hits() - before;
8220+ match res {
8221+ Err(e) => eprintln!("x={start_x} cq={cq} rtx={rtx} fired={fired} REFUSED {e}"),
8222+ Ok(frames) => {
8223+ let want = ffmpeg_decode_sequence(&stream, width, height, frames.len());
8224+ let bad = frames.iter().zip(&want)
8225+ .filter(|(g, w)| g.y != w.y || g.u != w.u || g.v != w.v).count();
8226+ eprintln!("x={start_x} cq={cq} rtx={rtx} fired={fired} frames={} mismatched={bad}", frames.len());
8227+ if bad == 0 { continue; }
8228+ let (g, w) = (&frames[0], &want[0]);
8229+ for br in 0..height / 8 {
8230+ let mut line = String::new();
8231+ for bc in 0..width / 8 {
8232+ let mut n = 0;
8233+ for row in br * 8..br * 8 + 8 {
8234+ for col in bc * 8..bc * 8 + 8 {
8235+ if g.y[row * width + col] != w.y[row * width + col] {
8236+ n += 1;
8237+ }
8238+ }
8239+ }
8240+ line.push_str(&format!("{n:4}"));
8241+ }
8242+ eprintln!(" blk8 row{br}: {line}");
8243+ }
8244+ }
8245+ }
8246+ }
8247+ }
8248+ }
8249+ }
8250+
79278251 /// lane-rectgate r1: every prior gate pins `--enable-rect-partitions=0
79288252 /// --enable-ab-partitions=0 --min/max-partition-size=32` so aomenc never
79298253 /// gets to choose a real rect/ab split. This charter's premise ("rect
lanes/rectx-r3.handoff.mdadded+54 -0
@@ -0,0 +1,54 @@
1+# lane-rectx r3 handoff — one defect fixed, one precisely located
2+
3+TOTALS `EC_AV1_REQUIRE_AOMENC=1 cargo test -p ec-av1 --lib` (CARGO_TARGET_DIR=~/.cache/cargo-target-rectx):
4+**269 passed, 1 failed, 24 ignored** (1042s). The single failure is this lane's own gate,
5+`stream::tests::a_real_aomenc_stream_with_a_coded_rect_strip_below_16x16_decodes_pixel_exact`;
6+it now stops on an unrelated third blocker ("a 32x32 partition type this decoder does not code
7+(value=7)" = PARTITION_VERT_B at 32x32) with the recipe as written. No other test regressed
8+(268 -> 269 passed is this round's new pin).
9+
10+## Do next, in this order
11+
12+1. **Per-mi y-mode neighbour grid.** `Neighbours::above_mode` (decode.rs:1806) / `left_mode`
13+ are per-16x16 cell; libaom reads `above_mi`/`left_mi` off the real mi grid. Reproduce in
14+ one command:
15+ - stream: `ffmpeg -v error -f lavfi -i rgbtestsrc=size=64x64 -pix_fmt yuv420p -t 1 -vframes 1
16+ -f yuv4mpegpipe g.y4m` then `aomenc --codec=av1 --passes=1 --end-usage=q --cq-level=50
17+ --cpu-used=4 --threads=1 --row-mt=0 --sb-size=64 --kf-max-dist=0 --enable-rect-partitions=1
18+ --enable-ab-partitions=0 --enable-1to4-partitions=0 --enable-tx-size-search=0
19+ --enable-cdef=0 --enable-restoration=0 --reduced-tx-type-set=1 --min-partition-size=8
20+ --max-partition-size=32 --obu -o t.obu g.y4m`
21+ - ours: `EC_TRACE_COEFF=1 EC_AV1_RECTX_TRACE=1 EC_TRACE_MODE_STEP=1
22+ target/debug/examples/decode_probe t.obu`
23+ - oracle: `EC_TRACE_COEFF=1 EC_TRACE_MODE=1 ~/.cache/aom-oracle/build/aomdec --rawvideo
24+ -o /dev/null t.obu`
25+ - THE ELEMENT: leaf `mi=(4,12)`, bw=16 bh=8, outer_at=(1,3). Both enter at range **59792**.
26+ Oracle `EC_IMODE_VAL mode=2 uv_mode=2 skip=0 -> rng=49036`; ours `mode=0 uv_mode=13 ->
27+ rng=47236`. First 15 transform blocks of the frame are bit-exact before it.
28+ - Fix shape: a per-mi mode grid written wherever `fill_skip_grid`/`fill_skip_grid_rect`
29+ (13 sites) is written, read by `read_intra_mode*`'s `above_ctx`/`left_ctx`.
30+2. **Then re-pick the gate recipe.** `stream::tests::sweep_rectx_recipes` (`#[ignore]`,
31+ `--nocapture`) sweeps 9 lavfi sources x 7 cq x reduced-tx-type-set 0/1 and prints
32+ `fired=`/refusal/`mismatched=` per cell plus an 8x8 mismatch map. After the filter_intra fix
33+ exactly one cell decodes to completion (rgbtestsrc cq=50 rtx=1, fired=4) and it mismatches
34+ on defect (1). Every other cell refuses; the dominant refusal is
35+ "a HORZ_A/HORZ_B/VERT_A partition below 16x16" — this aomenc build writes AB partitions
36+ below 16x16 even with `--enable-ab-partitions=0` (126/126 cells swept; same quirk the ledger
37+ records at SB level). Wiring HORZ_A/HORZ_B/VERT_A below 16x16 may be the cheaper route to a
38+ green gate than recipe hunting.
39+3. Only then lift "a coded (non-skip) HORZ/VERT rect strip below 16x16" and "a non-skip
40+ rectangular (HORZ/VERT/HORZ_B) strip needs rectangular residual coding" in
41+ `refusal_inventory.rs` + `gate_coverage.rs`. NOT lifted this round.
42+
43+## Do NOT re-do
44+
45+- The r2 coefficient path (scans, `EOB_PT_128_LUMA`/`EOB_PT_32_CHROMA`, txb sets, nz-map/br
46+ ctx, DC-sign ctx) is range-exact against aomdec for a real non-skip TX_16X8 leaf + both
47+ TX_8X4 chroma halves. Don't re-derive it.
48+- `base_ctx_rect`'s 11/16 rect nz-map offsets are CORRECT as written (display-orientation
49+ convention: our (row,col) are display row/col, libaom's flat `av1_nz_map_ctx_offset` tables
50+ are column-major so their INDEX packing, not their rule, is what differs). Swapping the two
51+ constants was tried this round: the 126-cell sweep went from 2 full decodes to 0 (every cell
52+ refused). Dead end.
53+- `SCAN_8X4`/`SCAN_4X8` were re-checked verbatim against
54+ `~/.cache/aom-oracle/src/av1/common/scan.c` this round. They are right.
lanes/rectx-r3.report.mdadded+88 -0
@@ -0,0 +1,88 @@
1+# lane-rectx r3 — the rect leaf was bit-exact; the block AFTER it was not
2+
3+Branch `lane-rectx`, on top of `main` 3808cf8 (`git merge-base --is-ancestor main HEAD` = OK,
4+no rebase needed). Prior state: r1/r2 landed non-skip TX_16X8/TX_8X16 rect-leaf coefficient
5+decode (`decode_leaf_rect`'s lane-rectx arm, `read_coeffs_rect`, `TxbSet::LumaRect16x8{,Set1}`
6+/`ChromaRect8x4`, `EOB_PT_128_LUMA`/`EOB_PT_32_CHROMA`, `SCAN_8X4`/`SCAN_4X8`) UNPROVEN, with
7+the lane's own gate red.
8+
9+## What this round proved
10+
11+1. **The r2 coefficient path is right.** Against the instrumented oracle
12+ (`~/.cache/aom-oracle/build/aomdec`, `EC_TRACE_COEFF=1`) on a real aomenc stream, a
13+ non-skip `TX_16X8` luma leaf plus both its `TX_8X4` chroma halves decode with an
14+ IDENTICAL msac range at every element (`all_zero` 37445, `tx_type` 55512, `eob`=1 41024,
15+ `base_eob` pos 0 level 1 64544, DC sign 37072, chroma `all_zero`=1 40760 / 47390).
16+ Scans, eob CDF alphabet, txb sets, nz-map/br contexts and the DC-sign context at this size
17+ are all confirmed by that ladder, not by argument.
18+2. **`SCAN_8X4`/`SCAN_4X8` re-checked against the real `scan.c`** (not a memory of it):
19+ `~/.cache/aom-oracle/src/av1/common/scan.c` `default_scan_4x8` == our `SCAN_8X4` and
20+ `default_scan_8x4` == our `SCAN_4X8`, verbatim, which is what
21+ `decode.rs::tests::the_rect_scan_tables_match_libaom...` already pins (asymmetric pair, a
22+ swap fails it).
23+3. **Root cause of the desync (FIXED): the `use_filter_intra` flag was never read at
24+ 16x8/8x16.** `av1_filter_intra_allowed_bsize` is "both sides <= 32", so libaom reads the
25+ flag for every DC_PRED 16x8/8x16 block; `filter_intra_size_class_rect` returned `None`
26+ there, so we dropped one symbol per DC_PRED strip and desynced the tile from that block on
27+ — silently, with a full-frame pixel mismatch and no error. Ladder evidence: leaf mi=(2,4),
28+ we and the oracle both decode `mode=0 uv_mode=9 skip=0`, but our post-mode range is 34808
29+ where the oracle's is 40668 (value-equal narrowing drift). After the fix our range at that
30+ point is 40668 and the next transform block's `all_zero` reads 40269 — bit-identical to the
31+ oracle.
32+
33+## Files changed
34+
35+- `crates/ec-av1/src/cdf.rs:415` — `FILTER_INTRA` 6 -> 8 rows, adding `default_filter_intra_cdfs`
36+ index 5 (BLOCK_16X8, 9394) and 4 (BLOCK_8X16, 12551).
37+- `crates/ec-av1/src/cdf_state.rs:467` — the field's type/doc follow.
38+- `crates/ec-av1/src/decode.rs` `filter_intra_size_class_rect` — `(16,8) => Some(6)`,
39+ `(8,16) => Some(7)`; the actual fix.
40+- `crates/ec-av1/src/decode.rs` `read_coeffs_rect` — three env-gated trace prints
41+ (`tag=all_zero_rect` with the pre-symbol range, `tag=sign_rect`) under the existing
42+ `EC_TRACE_COEFF`, plus the entry range on the `EC_AV1_RECTX_TRACE` line; these are what made
43+ the cross-decoder bisection possible and are kept for the successor.
44+- `crates/ec-av1/src/decode.rs` tests — new
45+ `a_rect_strip_below_16x16_reads_its_own_filter_intra_cdf_row`.
46+- `crates/ec-av1/src/stream.rs` `sweep_rectx_recipes` (scratch, `#[ignore]`) — also sweeps
47+ `--reduced-tx-type-set=1`, and only dumps the 8x8 mismatch map when there IS a mismatch.
48+
49+## Checks
50+
51+- `cargo test -p ec-av1 --lib -- filter_intra scan_` -> 8 passed, 0 failed (includes the new pin
52+ and the existing `a_real_aomenc_filter_intra_stream_decodes_pixel_exact`).
53+- `EC_AV1_REQUIRE_AOMENC=1 cargo test -p ec-av1 --lib` -> see TOTALS below.
54+- EVIDENCE: /tmp/claude-1000/.../scratchpad/{s.obu,aom.log,ours.log} | ffmpeg mandelbrot 64x64
55+ start_x=-0.6 -> aomenc cq16 --enable-rect-partitions=1 --min-partition-size=8
56+ --max-partition-size=32; instrumented aomdec `EC_TRACE_COEFF=1` vs
57+ `examples/decode_probe` `EC_TRACE_COEFF=1` | first divergence moved from the transform block
58+ after leaf mi=(2,4) (ours 34467 vs oracle 40269) to none at that point (both 40269) after the
59+ fix.
60+
61+## Open residue
62+
63+- **fix-now (next round, out of this round's tool budget): the rect leaf's `kf_y_mode`
64+ context is read from the coarse 16x16 neighbour grid.** Second, independent defect, found
65+ by the same ladder on `rgbtestsrc=size=64x64` cq=50 `--reduced-tx-type-set=1`: at leaf
66+ mi=(4,12) (`decode_leaf_rect`, bw=16 bh=8, outer_at=(1,3)) we and the oracle ENTER the block
67+ at the same range 59792, and then we decode `mode=0` where the oracle decodes `mode=2`
68+ (H_PRED) — a wrong CDF row, not a wrong value. `Neighbours::above_mode`/`left_mode`
69+ (decode.rs:1806) are per-16x16-cell; libaom takes `above_mi`/`left_mi` from the real mi grid,
70+ so when the cell above was split into 8x8 leaves our slot holds the last-written leaf's mode
71+ (bottom-RIGHT) instead of the true above neighbour (bottom-LEFT at mi col 12). Known class:
72+ "context read from one cell". The fix is a per-mi mode grid alongside the existing per-mi
73+ `skip_grid`/`lf_grid` — 13 `fill_skip_grid*` call sites would gain a mode write. It affects
74+ every intra path, not just rect leaves.
75+- **deferred(the mode-grid fix above): the lane gate
76+ `a_real_aomenc_stream_with_a_coded_rect_strip_below_16x16_decodes_pixel_exact` is still RED**,
77+ and its two refusals are NOT lifted. Its current recipe fails on a third, unrelated blocker
78+ ("a HORZ_A/HORZ_B/VERT_A partition below 16x16"): a 126-cell sweep (9 lavfi sources x 7
79+ cq x reduced-tx-type-set 0/1, `sweep_rectx_recipes`) found aomenc writes AB partitions below
80+ 16x16 despite `--enable-ab-partitions=0` in most cells — same aomenc quirk the ledger already
81+ records one level up. After the filter_intra fix the sweep has exactly ONE cell that decodes
82+ to completion (rgbtestsrc cq=50 rtx=1, 4 rect leaves fired) and it mismatches on the mode-ctx
83+ defect above. So there is currently no recipe that can turn the gate green; a green gate
84+ needs the mode-grid fix first.
85+- accepted: `read_coeffs_rect` still refuses `V_DCT`/`H_DCT` ("a non-2D tx class on a
86+ rectangular transform"), which is why the gate recipe pins `--reduced-tx-type-set=1`.
87+
88+TOTALS: see lanes/rectx-r3.handoff.md.
lanes/rectx-r4.report.mdadded+89 -0
@@ -0,0 +1,89 @@
1+# lane-rectx r4 — the gate is GREEN: two defects, one cherry-picked, one found here
2+
3+Branch `lane-rectx`, commits on top of `main` 3808cf8. Round 3 left the lane's own gate red
4+with the mode-neighbour defect precisely located; this round fixed it and one more.
5+
6+## What changed
7+
8+1. **Cherry-picked lane-sub8 `1841406`** (mi-exact intra mode neighbours + `has_tr_4x4`/
9+ `has_bl_4x4`): `Neighbours::sub8_mode_col/row`, `record_mode_mi`, `mode_above_mi`/
10+ `mode_left_mi` (`crates/ec-av1/src/decode.rs` ~1830, ~2533-2570), written by `record_rect`
11+ and `record_split_luma`/`decode_leaf8`, plus `crates/ec-av1/src/encode.rs`'s reach rows.
12+ The commit's `decode_leaf_split4`/`read_intra_mode_sub8` hunks were dropped — those
13+ functions exist only on lane-sub8.
14+2. **`decode_leaf_rect` joins that map** (`decode.rs` ~3644 read, ~3786 write): it now reads
15+ `mode_above_mi`/`mode_left_mi` after the `prev_leaf` override and records its own
16+ `mi_w x mi_h` span, not one cell. This is r3's located defect (leaf mi=(4,12) read
17+ `kf_y_mode` from the coarse 16x16 slot, decoding `mode=0` where the oracle decodes
18+ `mode=2`).
19+3. **ROOT CAUSE FOUND THIS ROUND — the rect reach tables were the wrong block size.**
20+ `Reach::of_rect` (`encode.rs` ~1096) indexed `HAS_TOP_RIGHT_RECT`/`HAS_BOTTOM_LEFT_RECT`
21+ by `bw == 16`; both arrays only ever held the 32x16/16x32 rows (lane-intradisp's sizes).
22+ A 16x8 block read `has_tr_16x32`/`has_bl_16x32` (4 bytes) where libaom reads
23+ `has_tr_16x8`/`has_bl_16x8` (16 bytes), an 8x16 read the 32x16 rows, and the index
24+ arithmetic (`table_stride = 128/side`, `% (len*8)`) was not libaom's either.
25+ `top_right_rect`/`bottom_left_rect` are now libaom `has_top_right`/`has_bottom_left`
26+ verbatim at block granularity (`row_off`/`col_off` 0, luma), with `has_tr_rect_table`/
27+ `has_bl_rect_table` carrying 16x8, 8x16, 32x16, 16x32, 64x32 and 32x64 transcribed from
28+ `~/.cache/aom-oracle/src/av1/common/reconintra.c`. (`has_tr_vert_tables`/`has_bl_vert_tables`
29+ hold the SAME pointers for every W<H entry and NULL for W>H, so the partition type selects
30+ no different table at these sizes.)
31+4. Gate recipe (`stream.rs` ~5366): mandelbrot `start_x=-0.6`, `--cq-level=16`, and
32+ `--enable-filter-intra=0` added (filter intra ON a strip is a separate, still-refused
33+ predictor).
34+5. `examples/decode_probe.rs`: lane-sub8's optional second arg dumping raw yuv420p, which is
35+ what made the ffmpeg pixel diff a one-liner outside the test harness.
36+
37+## Evidence
38+
39+EVIDENCE: /tmp/claude-1000/.../scratchpad/{x.obu,pre_a.yuv.f0,pre_o.yuv.f0} | ffmpeg lavfi
40+rgbtestsrc 64x64 -> aomenc cq50 --enable-rect-partitions=1 --enable-ab-partitions=0
41+--enable-filter-intra=0 --reduced-tx-type-set=1 --min-partition-size=8 --max-partition-size=32;
42+`EC_AV1_PREFILT_DUMP` on instrumented aomdec vs `examples/decode_probe` | pre-loop-filter luma
43+diffs 1440 -> 0, final vs `ffmpeg -f rawvideo` 1567 -> 0 bytes. The 1440 luma diffs were a
44+D203 (`mode=7`) 16x8 strip at mi=(4,8): exact for the first rows, first mismatch at pixel
45+(44,18) with a diagonal wavefront — the signature of a ray that has started reading BELOW the
46+block's own height, i.e. wrong bottom-left availability.
47+
48+EVIDENCE: gate `a_real_aomenc_stream_with_a_coded_rect_strip_below_16x16_decodes_pixel_exact` |
49+`EC_AV1_REQUIRE_AOMENC=1 cargo test -p ec-av1 --lib -- a_real_aomenc_stream_with_a_coded_rect_strip_below_16x16 --nocapture` |
50+`pixel-exact, rect_leaf_coeff_hits=8`; the stream's own symbol trace shows 6 non-skip TX_16X8
51+luma leaves + 1 non-skip TX_8X16 (both orientations), 9 non-skip TX_8X4 and 3 non-skip TX_4X8
52+chroma halves.
53+
54+## Refusals
55+
56+- `a coded (non-skip) HORZ/VERT rect strip below 16x16` — the string was already removed from
57+ `decode.rs` in r2 (never in `refusal_inventory::REFUSALS`); this round is what finally PROVES
58+ it, with the gate above. Nothing to delete, the inventory test stays green.
59+- `a non-skip rectangular (HORZ/VERT/HORZ_B) strip needs rectangular residual coding`
60+ (`decode.rs:9138`) — **NOT lifted.** It sits in the INTER square-block path
61+ (`reject_residual`, lane-warp r5), which this key-frame gate never reaches. Lifting it needs
62+ an inter gate.
63+- `a coded (non-skip) HORZ_B/VERT_B rect strip below 16x16` — **NOT lifted**, HORZ_B/VERT_B
64+ never fired in the gate stream.
65+
66+## Open residue
67+
68+- accepted: `read_coeffs_rect` still refuses `V_DCT`/`H_DCT` (`a non-2D tx class on a
69+ rectangular transform`), hence `--reduced-tx-type-set=1` in the gate.
70+- deferred(a lane for AB partitions below 16x16): the dominant refusal across the recipe sweep
71+ is still `a HORZ_A/HORZ_B/VERT_A partition below 16x16`. NOTE: unlike r3's premise, this
72+ survives the mode-grid fix, so at THIS size it is not (only) our own desync — 8 of 24 swept
73+ cells still refuse on it after both fixes.
74+- fix-now(next round): two swept cells decode to completion but are NOT pixel-exact
75+ (rgbtestsrc cq24 3540 bytes, cq32 1714; mandelbrot start_x=-0.6 cq16 with
76+ `--enable-filter-intra=1` 126). Same ladder applies; the gate's own cell is exact.
77+
78+## Totals
79+
80+`EC_AV1_REQUIRE_AOMENC=1 cargo test -p ec-av1 --lib` (CARGO_TARGET_DIR=~/.cache/cargo-target-rectx):
81+**270 passed, 0 failed, 24 ignored** (738.88s) — r3's single failure (this lane's own gate) is
82+gone and nothing regressed (269 -> 270 passed is exactly this gate).
83+
84+That full run was built BEFORE the last hunk (the explicit 64x32/32x64 rows in
85+`has_tr_rect_table`/`has_bl_rect_table`, which previously fell through to the 16x32 row).
86+On the final build the four gates that can see those sizes were re-run:
87+`a_real_aomenc_stream_with_a_superblock_level_horz_vert_partition_decodes_pixel_exact`,
88+`..._with_mandelbrot_fires_the_vert_b_partition_arm`, `..._with_directional_chroma_...` and
89+this lane's own gate — 4 passed, 0 failed, 1 ignored (21.26s).
lanes/rectx-r5.report.mdadded+116 -0
@@ -0,0 +1,116 @@
1+# lane-rectx r5 -- three "decodes fine, wrong pixels" cells: one root cause, luma now exact in all three
2+
3+Branch `lane-rectx`, on top of r4's `fad4d5a`. r4 left three swept cells decoding to
4+completion with WRONG pixels (the worst class). All three had the SAME root cause; after the
5+fix two are byte-exact and all three are LUMA-exact, with a chroma-only residue below.
6+
7+## Root cause (found this round)
8+
9+`decode_leaf_rect` took the mi-exact intra-mode neighbour map in r4 (`mode_above_mi` /
10+`mode_left_mi`). The three OTHER `kf_y_mode` readers did not:
11+`decode_block` (square, `decode.rs` ~4960), `decode_block_rect` (32x16/16x32, ~3274) and
12+`decode_block_rect64` (64x32/32x64, ~3850) each read the COARSE per-16x16 `above_mode[c]` /
13+`left_mode[r]` slots -- which no sub-16x16 block ever writes (`record_rect` loops
14+`w / SUB` = 0 cells for a 16x8). So a 32x16 strip whose left neighbour was a 16x8 rect leaf
15+read an older, larger block's mode, indexed a DIFFERENT `kf_y_mode` CDF row, decoded the same
16+mode VALUE off a different distribution, and desynced from that block's first coefficient on.
17+This is the memory class "context read from one cell" / "CDF row held constant", one level up
18+from r4's own instance.
19+
20+Fix (`decode.rs`): one `Neighbours::modes_above_left(r, c)` helper (mi-exact if the map holds
21+exactly this block's above/left mi, else the coarse slot) used by all three readers, for the
22+mode CDF row AND for `smooth_neighbor` (libaom's `get_filt_type` reads the same `above_mi`/
23+`left_mi`). New `MODE_MI_OVERRIDE_HITS` counter (`decode.rs` ~760) counts the reads where the
24+two disagree.
25+
26+Also applied here, per the coordinator's mid-round correction (defect found by lane-sub8's
27+verifier in the code r4 cherry-picked from that lane): `mode_above_mi`/`mode_left_mi` guarded
28+availability with `mi_r > 0`/`mi_c > 0` instead of the tile-relative
29+`mi_r > tile_row0_mi`/`mi_c > tile_col0_mi`, and the maps were never reset -- `start_tile` now
30+clears `sub8_mode_col` over the tile's mi columns and `start_row` clears `sub8_mode_row`,
31+exactly like every other neighbour array beside them. (This lane's sweep is single-tile, so
32+that half is code-verified here, not gate-proven; lane-sub8 r6 owns the multi-tile gate.)
33+
34+## Evidence
35+
36+EVIDENCE: /tmp/.../scratchpad/rx/{rgb240.obu,pre_a.f0,pre_o.f0,o.step.txt,a.step.txt} |
37+ffmpeg lavfi `rgbtestsrc=size=64x64` -> aomenc `--cq-level=24 --reduced-tx-type-set=0
38+--enable-rect-partitions=1 --min-partition-size=8 --max-partition-size=32
39+--enable-filter-intra=0 --enable-cdef=0 --enable-restoration=0` (sha256
40+22113636b7ab950b5d1a175a60b9e01251dcead819f99a9ef14dcd1378ccfad6, reproducible across two
41+encodes); `EC_TRACE_MODE_STEP` ladder ours vs instrumented aomdec, `EC_AV1_PREFILT_DUMP` both |
42+first divergent element = `mi_row=8 mi_col=8 name=mode val=2` at range 53452 (oracle) vs 33402
43+(ours) -- same value, different CDF row, entry ranges equal (56121) so it is the ROW not the
44+symbol; that block's left neighbour is the 16x8 leaf at mi(8,4) mode=12. Pre-filter luma diff
45+1006 -> 0, total 1650 -> 12 bytes (all chroma).
46+
47+EVIDENCE: gate `a_real_aomenc_stream_whose_square_block_reads_a_sub16_neighbours_mode_decodes_pixel_exact`
48+(`stream.rs` ~5460) | `EC_AV1_REQUIRE_AOMENC=1 cargo test -p ec-av1 --lib -- a_real_aomenc_stream_whose_square_block_reads_a_sub16 --nocapture` |
49+`pixel-exact, mode_mi_override_hits=2`, two pinned arms (`rgbtestsrc` 64x64 cq32 with
50+`--reduced-tx-type-set=1 --enable-filter-intra=0` and with `=0 --enable-filter-intra=1`), each
51+encoded twice and byte-compared before decode; the counter is read only on an attempt that
52+decoded AND is pixel-compared.
53+
54+EVIDENCE: /tmp/.../scratchpad/rx/{rgb240,rgb241,rgb321,mandfi161}.{obu,ours.yuv,ref.yuv} |
55+`examples/decode_probe <obu> <yuv>` vs `ffmpeg -i <obu> -f rawvideo`, per-plane byte diff |
56+per cell, before -> after this round: rgbtestsrc cq24 rtx=0 1650 -> 12 (luma 1118 -> 0);
57+rgbtestsrc cq24 rtx=1 3461 -> 14 (luma 2304 -> 0); rgbtestsrc cq32 rtx=1 1622 -> 0;
58+rgbtestsrc cq32 `--enable-filter-intra=1` rtx=0 -> 0; mandelbrot start_x=-0.6 cq16
59+`--enable-filter-intra=1` rtx=1 126 -> 123 (luma 0, U 40, V 83).
60+
61+## Second defect this round (coordinator-reported, verified and fixed)
62+
63+`Reach::top_right_rect`/`bottom_left_rect` (`encode.rs` ~1162/~1196) indexed the rect
64+`has_tr_*`/`has_bl_*` tables with `(blk_row << (4 - bw_log2)) + blk_col`. libaom's
65+`has_top_right` uses `MAX_MIB_SIZE_LOG2` = **5** (`enums.h`; its tables are laid out for a
66+128x128 = 32-mi superblock), so r4 halved the row stride and every table row but the first
67+read the wrong byte -- 16x8 wrong at 80 mi positions in a 64-wide SB, 8x16 at 16, 32x16 at 64
68+(a regression against `main`). Fixed via a named `Reach::rect_table_index` used by both.
69+
70+EVIDENCE: `cargo test -p ec-av1 --lib -- rect_reach_tables_are_indexed --nocapture` |
71+new `encode::tests::rect_reach_tables_are_indexed_with_a_32_mi_row_stride` walks every block
72+position of a 32-mi superblock for all six rect sizes and asserts the index set is a BIJECTION
73+onto the table's bits (plus `len * 8 == rows * cols`) | passes with the shift at 5; with r4's
74+`4 - bw_log2` the walk covers a quarter of the 16x8 table and the assert fails. No pixel change
75+in the five swept cells (they are all luma-exact either way), so this fix is table-verified,
76+not gate-differentiated.
77+
78+## Open residue
79+
80+- fix-now(next round, needs its own lane -- it is a CHROMA PREDICTION defect, not a rect one):
81+ every remaining mismatch is chroma-only with luma byte-exact and the entropy ladder
82+ IDENTICAL end to end (`diff` of the two `EC_ISTEP` traces on mandfi161 is empty apart from
83+ two `use_filter_intra` lines the oracle prints and we do not -- ranges match, so the symbol
84+ is consumed). Localised per 4x4 chroma block on mandelbrot cq16 fi=1: the three FULLY wrong
85+ blocks (16/16 samples) are mi(10,4) V, mi(10,6) V, mi(12,12) U -- all three `uv_mode=13`
86+ (`UV_CFL_PRED`), one plane wrong while the other is exact, i.e. the per-plane CFL alpha, not
87+ the shared luma AC. The partially wrong blocks (1-13 samples, max delta 9) are all
88+ directional chroma with a NON-ZERO `angle_uv` (mi(8,12) uv=4 delta -3, mi(10,2) uv=4 delta 3,
89+ mi(12,8) uv=6 delta -3, ...), i.e. the chroma intra-edge filter/upsample path. Ruled out this
90+ round by experiment: `smooth_neighbor_uv` is NOT the cause -- forcing it true and false
91+ globally leaves the diff at 123 bytes either way (rgb240: 12/13/12).
92+- deferred(a lane for AB partitions below 16x16): unchanged from r4, `a HORZ_A/HORZ_B/VERT_A
93+ partition below 16x16` still dominates the refusals in the sweep.
94+- accepted: `read_coeffs_rect` still refuses `V_DCT`/`H_DCT` on a rect transform
95+ (`--reduced-tx-type-set=0` cells can hit it: rgbtestsrc cq32 rtx=0 fi=0 refuses by name).
96+- accepted: `filter intra on a HORZ/VERT strip` still refuses (4 of the 6 filter-intra cells
97+ swept above stop there, non-silently).
98+- deferred(the rect `predict_filter_intra` predictor): the coordinator asked for a gate arm
99+ asserting a counter of `use_filter_intra` reads on 16x8/8x16 leaves. It cannot exist yet --
100+ every recipe where aomenc puts filter intra ON a rect leaf hits exactly that refusal
101+ (`filter intra on a HORZ/VERT strip`, 4 of 6 cells), and the two `--enable-filter-intra=1`
102+ recipes that DO decode (`rgbtestsrc` cq32 rtx=0, now a pinned arm of the new gate) contain no
103+ such leaf, so the counter would assert 0. A gate for those CDF rows unblocks when
104+ `predict_filter_intra` grows a rectangular arm; the r4 refusal is what holds the line
105+ meanwhile.
106+
107+## Refusals
108+
109+None lifted or added this round; `refusal_inventory` and `gate_coverage` unchanged and green.
110+
111+## Totals
112+
113+`EC_AV1_REQUIRE_AOMENC=1 cargo test -p ec-av1 --lib` (CARGO_TARGET_DIR=~/.cache/cargo-target-rectx,
114+final commit): **272 passed, 0 failed, 24 ignored** (825.42s) -- r4's 270 plus the two tests
115+added this round (`a_real_aomenc_stream_whose_square_block_reads_a_sub16_neighbours_mode_decodes_pixel_exact`,
116+`rect_reach_tables_are_indexed_with_a_32_mi_row_stride`); nothing regressed.