forge
Explore
Log in

Don't you dare go Hollow

16x16-level rectangular INTER leaves -- PARTITION_HORZ/VERT into two 16x8/8x16 inter blocks

Browse files at this commit

b2eabdd9d876fa04f6b96b06804d697d83e697ccAhmet Kaan GümüşParent: 115cb3a
  • feat
    • 16x16-level rectangular INTER leaves -- PARTITION_HORZ/VERT into two 16x8/8x16 inter blocks
Show full message
feat(av1): 16x16-level rectangular INTER leaves -- PARTITION_HORZ/VERT into two 16x8/8x16 inter blocks

Mode info, rectangular residual and prediction for the 16-level rect inter
leaf, the shape lane-inter4 r2 measured as the real reach blocker (real
motion content codes one before any 32-level 2:1 strip).

- decode.rs: the 16x16-level PARTITION_HORZ/VERT arms (side=SUB keeps every
  CDF/prediction-buffer decision square, write_w/write_h carry the true
  footprint), `rect_inter_residual_supported` extended to 16x8/8x16,
  `rect_inter_luma_set`/`rect_inter_chroma_set` picking the TxbSet from the
  block's true shape, motion_mode/obmc CDF rows for BLOCK_8X16/BLOCK_16X8,
  and `size_group_wh` -- `y_mode` and `interintra` now read the block's own
  `size_group_lookup` row instead of its square `side`'s.
- cdf_state.rs/cdf.rs: `TxbSet::LumaRect16x8Inter` (+`Set1`) -- LumaRect16x8's
  coefficient tables with the inter tx_type alphabet (EXT_TX_SET_DCT_IDTX
  reduced / EXT_TX_SET_ALL16 otherwise, both at the TX_8X8 CDF row); the
  missing `eob_pt_128_luma_class1` and `eob_pt_32_chroma_class1` tables, wired
  into the rect 16x8/8x16 luma and 8x4/4x8 chroma sets (a 1D V_DCT/H_DCT unit
  was reading the 2D eob alphabet) and into the per-frame counter reset.
- decode.rs `obmc_blend`: libaom's real `max_neighbor_obmc` table (1 mi -> 0,
  2 -> 1) instead of a row that was right only at 16 px and above.
- REFUSALS: "an inter partition below 16x16 other than SPLIT" is gone; two
  named refusals take its place -- the 16-level AB/1:4 partitions, and OBMC on
  a 16x8/8x16 leaf (which mismatches the reference; see the report).

Gate: a_real_aomenc_inter_sequence_with_a_16_level_rect_leaf_decodes_pixel_exact
(8-bit: 3 attempts carrying a 16x8 leaf, 2 an 8x16, 2 coded rect inter TUs;
10-bit: 2/3 leaves, residual proven by the 8-bit arm), every frame Y/U/V vs
ffmpeg, refusals counted and never SKIPped.
crates/ec-av1/src/cdf.rsmodified+35 -2
@@ -1610,7 +1610,7 @@ pub const SKIP_MODE: [[u16; 3]; 3] = [[32621, 32768, 0], [20708, 32768, 0], [812
1610 /// `motion_mode_allowed` (spec 5.11.24's `read_motion_mode`) offers1610 /// `motion_mode_allowed` (spec 5.11.24's `read_motion_mode`) offers
1611 /// `OBMC_CAUSAL` rather than `WARPED_CAUSAL` -- lane-motionmode round 11611 /// `OBMC_CAUSAL` rather than `WARPED_CAUSAL` -- lane-motionmode round 1
1612 /// never reaches the three-way `motion_mode_cdf`, see `decode.rs`.1612 /// never reaches the three-way `motion_mode_cdf`, see `decode.rs`.
1613-pub const OBMC: [[u16; 3]; 12] = [1613+pub const OBMC: [[u16; 3]; 14] = [
1614 [10437, 32768, 0],1614 [10437, 32768, 0],
1615 [17432, 32768, 0],1615 [17432, 32768, 0],
1616 [25817, 32768, 0],1616 [25817, 32768, 0],
@@ -1630,6 +1630,10 @@ pub const OBMC: [[u16; 3]; 12] = [
1630 [20901, 32768, 0],1630 [20901, 32768, 0],
1631 [24008, 32768, 0],1631 [24008, 32768, 0],
1632 [26879, 32768, 0],1632 [26879, 32768, 0],
1633+ // lane-inter4 r3: the 16x16-level rect inter leaves' own rows --
1634+ // BLOCK_8X16 (4) and BLOCK_16X8 (5) of libaom's `default_obmc_cdf`.
1635+ [9371, 32768, 0],
1636+ [9301, 32768, 0],
1633 ];1637 ];
1634 1638
1635 /// `default_motion_mode_cdf` (spec 9.4, `entropymode.c`), the square-bsize1639 /// `default_motion_mode_cdf` (spec 9.4, `entropymode.c`), the square-bsize
@@ -1639,7 +1643,7 @@ pub const OBMC: [[u16; 3]; 12] = [
1639 /// `read_motion_mode` reads instead of [`OBMC`] whenever `motion_mode_allowed`1643 /// `read_motion_mode` reads instead of [`OBMC`] whenever `motion_mode_allowed`
1640 /// (spec 5.11.24) resolves to `WARPED_CAUSAL`-eligible (`num_proj_ref >= 1`1644 /// (spec 5.11.24) resolves to `WARPED_CAUSAL`-eligible (`num_proj_ref >= 1`
1641 /// under `allow_warped_motion`) -- lane-warp round 1.1645 /// under `allow_warped_motion`) -- lane-warp round 1.
1642-pub const MOTION_MODE: [[u16; 4]; 12] = [1646+pub const MOTION_MODE: [[u16; 4]; 14] = [
1643 [7651, 24760, 32768, 0],1647 [7651, 24760, 32768, 0],
1644 [19419, 26810, 32768, 0],1648 [19419, 26810, 32768, 0],
1645 [26260, 29116, 32768, 0],1649 [26260, 29116, 32768, 0],
@@ -1655,6 +1659,10 @@ pub const MOTION_MODE: [[u16; 4]; 12] = [
1655 [26431, 30774, 32768, 0],1659 [26431, 30774, 32768, 0],
1656 [28973, 31594, 32768, 0],1660 [28973, 31594, 32768, 0],
1657 [29742, 31203, 32768, 0],1661 [29742, 31203, 32768, 0],
1662+ // lane-inter4 r3: BLOCK_8X16 / BLOCK_16X8 rows (libaom
1663+ // `default_motion_mode_cdf` indices 4 and 5).
1664+ [4738, 24765, 32768, 0],
1665+ [5391, 25528, 32768, 0],
1658 ];1666 ];
1659 1667
1660 /// `default_interintra_cdf` (spec 9.4): `interintra`, indexed by1668 /// `default_interintra_cdf` (spec 9.4): `interintra`, indexed by
@@ -5214,6 +5222,31 @@ pub const EOB_PT_16_CHROMA_CLASS1: [u16; 6] = [3192, 5032, 10297, 19755, 32768,
5214 pub const EOB_PT_16_CHROMA_CLASS1_Q3: [u16; 6] = [7297, 10767, 19273, 28194, 32768, 0];5222 pub const EOB_PT_16_CHROMA_CLASS1_Q3: [u16; 6] = [7297, 10767, 19273, 28194, 32768, 0];
5215 5223
5216 /// `EOB_PT_128_CHROMA`'s class-1 sibling (`av1_default_eob_multi128_cdfs[q][1][1]`).5224 /// `EOB_PT_128_CHROMA`'s class-1 sibling (`av1_default_eob_multi128_cdfs[q][1][1]`).
5225+/// `EOB_PT_128_LUMA`'s class-1 sibling (`av1_default_eob_multi128_cdfs[q][0][1]`,
5226+/// token_cdfs.h:830-848) -- the `TX_CLASS_HORIZ`/`TX_CLASS_VERT` (`V_DCT`/
5227+/// `H_DCT`) eob group of a 128-position LUMA transform, i.e. a true 16x8/8x16
5228+/// one. lane-inter4 r3: an inter 16x8 leaf reads `EXT_TX_SET_ALL16`, so 1D
5229+/// types are common there; the intra rect leaf could reach them too and was
5230+/// falling back to the 2D table.
5231+pub const EOB_PT_128_LUMA_CLASS1_Q0: [u16; 9] = [371, 699, 1254, 4830, 9479, 12562, 17497, 32768, 0];
5232+/// [`EOB_PT_128_LUMA_CLASS1_Q0`]'s q-context 1 sibling.
5233+pub const EOB_PT_128_LUMA_CLASS1_Q1: [u16; 9] = [217, 352, 618, 2303, 5261, 9969, 17472, 32768, 0];
5234+/// [`EOB_PT_128_LUMA_CLASS1_Q0`]'s q-context 2 sibling.
5235+pub const EOB_PT_128_LUMA_CLASS1: [u16; 9] = [354, 558, 944, 2760, 7287, 14037, 21779, 32768, 0];
5236+/// [`EOB_PT_128_LUMA_CLASS1_Q0`]'s q-context 3 sibling.
5237+pub const EOB_PT_128_LUMA_CLASS1_Q3: [u16; 9] = [886, 1731, 3271, 8469, 15569, 22126, 28383, 32768, 0];
5238+
5239+/// `EOB_PT_32_CHROMA`'s class-1 sibling (`av1_default_eob_multi32_cdfs[q][1][1]`,
5240+/// token_cdfs.h:792-808) -- the chroma 8x4/4x8 transform under a rect leaf
5241+/// inherits its luma unit's `tx_type`, so it reaches the 1D classes too.
5242+pub const EOB_PT_32_CHROMA_CLASS1_Q0: [u16; 7] = [1786, 3179, 6902, 11357, 19054, 32768, 0];
5243+/// [`EOB_PT_32_CHROMA_CLASS1_Q0`]'s q-context 1 sibling.
5244+pub const EOB_PT_32_CHROMA_CLASS1_Q1: [u16; 7] = [2578, 4124, 8181, 13670, 24234, 32768, 0];
5245+/// [`EOB_PT_32_CHROMA_CLASS1_Q0`]'s q-context 2 sibling.
5246+pub const EOB_PT_32_CHROMA_CLASS1: [u16; 7] = [3542, 5502, 10415, 16760, 25644, 32768, 0];
5247+/// [`EOB_PT_32_CHROMA_CLASS1_Q0`]'s q-context 3 sibling.
5248+pub const EOB_PT_32_CHROMA_CLASS1_Q3: [u16; 7] = [7699, 10897, 20891, 26926, 31628, 32768, 0];
5249+
5217 pub const EOB_PT_128_CHROMA_CLASS1_Q0: [u16; 9] = [2054, 3472, 5869, 14232, 18242, 20590, 26752, 32768, 0];5250 pub const EOB_PT_128_CHROMA_CLASS1_Q0: [u16; 9] = [2054, 3472, 5869, 14232, 18242, 20590, 26752, 32768, 0];
5218 pub const EOB_PT_128_CHROMA_CLASS1_Q1: [u16; 9] = [2310, 4160, 7471, 14997, 17931, 20768, 30240, 32768, 0];5251 pub const EOB_PT_128_CHROMA_CLASS1_Q1: [u16; 9] = [2310, 4160, 7471, 14997, 17931, 20768, 30240, 32768, 0];
5219 pub const EOB_PT_128_CHROMA_CLASS1: [u16; 9] = [6275, 9889, 14769, 23164, 27988, 30493, 32272, 32768, 0];5252 pub const EOB_PT_128_CHROMA_CLASS1: [u16; 9] = [6275, 9889, 14769, 23164, 27988, 30493, 32272, 32768, 0];
crates/ec-av1/src/cdf_state.rsmodified+67 -5
@@ -175,6 +175,24 @@ pub(crate) enum TxbSet {
175 /// 16x16 row's five-symbol reduced CDF here and desynced on the very175 /// 16x16 row's five-symbol reduced CDF here and desynced on the very
176 /// first coded rect leaf.176 /// first coded rect leaf.
177 LumaRect16x8Set1,177 LumaRect16x8Set1,
178+ /// lane-inter4 r3: [`LumaRect16x8`](TxbSet::LumaRect16x8)'s INTER twin --
179+ /// the same coefficient tables (`get_txsize_entropy_ctx` reduces TX_16X8
180+ /// and TX_8X16 alike to the 16x16 set, 128-position `eob_pt`), with the
181+ /// inter `tx_type` alphabet in place of the intra one. Under
182+ /// `reduced_tx_set` `av1_get_ext_tx_set_type` (`tx_size_sqr_up ==
183+ /// TX_16X16`, `is_inter`) returns `EXT_TX_SET_DCT_IDTX` (2 symbols),
184+ /// whose CDF row is `default_inter_ext_tx_cdf[1][txsize_sqr_map[TX_16X8]
185+ /// == TX_8X8]`, i.e. [`INTER_TX_TYPE_SET3_8`](crate::cdf::INTER_TX_TYPE_SET3_8)
186+ /// -- the same table the square `Luma8Inter` set reads.
187+ LumaRect16x8Inter,
188+ /// [`LumaRect16x8Inter`](TxbSet::LumaRect16x8Inter)'s `reduced_tx_set:
189+ /// false` counterpart: `tx_size_sqr` is `TX_8X8` here (NOT the
190+ /// `txsize_sqr_up_map` `TX_16X16` the coefficient tables use), so
191+ /// `av1_ext_tx_set_lookup[is_inter=1][tx_size_sqr == TX_16X16 -> 0]` is
192+ /// `EXT_TX_SET_ALL16` -- sixteen symbols, `default_inter_ext_tx_cdf[1]
193+ /// [TX_8X8]`, i.e. [`INTER_TX_TYPE_SET1_8`](crate::cdf::INTER_TX_TYPE_SET1_8),
194+ /// the table [`Luma8InterSet1`](TxbSet::Luma8InterSet1) also reads.
195+ LumaRect16x8InterSet1,
178 /// The chroma 8x4/4x8 transform under the same leaf (lane-rectx):196 /// The chroma 8x4/4x8 transform under the same leaf (lane-rectx):
179 /// [`Chroma8`](TxbSet::Chroma8)'s tables except `eob_pt`, which reads the197 /// [`Chroma8`](TxbSet::Chroma8)'s tables except `eob_pt`, which reads the
180 /// true 32-position [`crate::cdf::EOB_PT_32_CHROMA`] instead of198 /// true 32-position [`crate::cdf::EOB_PT_32_CHROMA`] instead of
@@ -289,6 +307,10 @@ pub(crate) struct Cdfs {
289 pub eob_pt_64_chroma_class1: [u16; 8],307 pub eob_pt_64_chroma_class1: [u16; 8],
290 /// `eob_pt_128_chroma`'s class-1 (`TX_CLASS_HORIZ`/`VERT`) sibling, see `eob_pt_16_luma_class1`.308 /// `eob_pt_128_chroma`'s class-1 (`TX_CLASS_HORIZ`/`VERT`) sibling, see `eob_pt_16_luma_class1`.
291 pub eob_pt_128_chroma_class1: [u16; 9],309 pub eob_pt_128_chroma_class1: [u16; 9],
310+ /// `eob_pt_128_luma`'s class-1 sibling (lane-inter4 r3).
311+ pub eob_pt_128_luma_class1: [u16; 9],
312+ /// `eob_pt_32_chroma`'s class-1 sibling (lane-inter4 r3).
313+ pub eob_pt_32_chroma_class1: [u16; 7],
292 /// `eob_pt_256_luma`'s class-1 (`TX_CLASS_HORIZ`/`VERT`) sibling, see `eob_pt_16_luma_class1`.314 /// `eob_pt_256_luma`'s class-1 (`TX_CLASS_HORIZ`/`VERT`) sibling, see `eob_pt_16_luma_class1`.
293 pub eob_pt_256_luma_class1: [u16; 10],315 pub eob_pt_256_luma_class1: [u16; 10],
294 /// `eob_pt_256_chroma`'s class-1 (`TX_CLASS_HORIZ`/`VERT`) sibling, see `eob_pt_16_luma_class1`.316 /// `eob_pt_256_chroma`'s class-1 (`TX_CLASS_HORIZ`/`VERT`) sibling, see `eob_pt_16_luma_class1`.
@@ -479,13 +501,13 @@ pub(crate) struct Cdfs {
479 /// `BLOCK_8X8`, 1 = `BLOCK_16X16`, 2 = `BLOCK_32X32`, 3 = `BLOCK_64X64`501 /// `BLOCK_8X8`, 1 = `BLOCK_16X16`, 2 = `BLOCK_32X32`, 3 = `BLOCK_64X64`
480 /// (`default_obmc_cdf`'s own `BLOCK_SIZES_ALL` indices 3/6/9/12 --502 /// (`default_obmc_cdf`'s own `BLOCK_SIZES_ALL` indices 3/6/9/12 --
481 /// this decoder only ever codes those four square sizes).503 /// this decoder only ever codes those four square sizes).
482- pub obmc: [[u16; 3]; 12],504+ pub obmc: [[u16; 3]; 14],
483 /// `motion_mode` (spec 5.11.24's `read_motion_mode`), the 3-symbol505 /// `motion_mode` (spec 5.11.24's `read_motion_mode`), the 3-symbol
484 /// `SIMPLE_TRANSLATION`/`OBMC_CAUSAL`/`WARPED_CAUSAL` alphabet read506 /// `SIMPLE_TRANSLATION`/`OBMC_CAUSAL`/`WARPED_CAUSAL` alphabet read
485 /// instead of [`Self::obmc`] whenever `motion_mode_allowed` resolves to507 /// instead of [`Self::obmc`] whenever `motion_mode_allowed` resolves to
486 /// `WARPED_CAUSAL`-eligible -- same square-bsize indexing as `obmc`.508 /// `WARPED_CAUSAL`-eligible -- same square-bsize indexing as `obmc`.
487 /// lane-warp round 1.509 /// lane-warp round 1.
488- pub motion_mode: [[u16; 4]; 12],510+ pub motion_mode: [[u16; 4]; 14],
489 /// `interintra`, indexed by `size_group_lookup[bsize]` -- see511 /// `interintra`, indexed by `size_group_lookup[bsize]` -- see
490 /// `cdf::INTERINTRA`'s own doc.512 /// `cdf::INTERINTRA`'s own doc.
491 pub interintra: [[u16; 3]; 4],513 pub interintra: [[u16; 3]; 4],
@@ -724,6 +746,8 @@ impl Cdfs {
724 reset1(&mut self.eob_pt_16_chroma_class1);746 reset1(&mut self.eob_pt_16_chroma_class1);
725 reset1(&mut self.eob_pt_64_chroma_class1);747 reset1(&mut self.eob_pt_64_chroma_class1);
726 reset1(&mut self.eob_pt_128_chroma_class1);748 reset1(&mut self.eob_pt_128_chroma_class1);
749+ reset1(&mut self.eob_pt_128_luma_class1);
750+ reset1(&mut self.eob_pt_32_chroma_class1);
727 reset1(&mut self.eob_pt_256_luma_class1);751 reset1(&mut self.eob_pt_256_luma_class1);
728 reset1(&mut self.eob_pt_256_chroma_class1);752 reset1(&mut self.eob_pt_256_chroma_class1);
729 reset1(&mut self.eob_pt_512_luma_class1);753 reset1(&mut self.eob_pt_512_luma_class1);
@@ -990,6 +1014,20 @@ impl Cdfs {
990 cdf::EOB_PT_128_CHROMA_CLASS1,1014 cdf::EOB_PT_128_CHROMA_CLASS1,
991 cdf::EOB_PT_128_CHROMA_CLASS1_Q3,1015 cdf::EOB_PT_128_CHROMA_CLASS1_Q3,
992 ),1016 ),
1017+ eob_pt_128_luma_class1: pick(
1018+ q_ctx,
1019+ cdf::EOB_PT_128_LUMA_CLASS1_Q0,
1020+ cdf::EOB_PT_128_LUMA_CLASS1_Q1,
1021+ cdf::EOB_PT_128_LUMA_CLASS1,
1022+ cdf::EOB_PT_128_LUMA_CLASS1_Q3,
1023+ ),
1024+ eob_pt_32_chroma_class1: pick(
1025+ q_ctx,
1026+ cdf::EOB_PT_32_CHROMA_CLASS1_Q0,
1027+ cdf::EOB_PT_32_CHROMA_CLASS1_Q1,
1028+ cdf::EOB_PT_32_CHROMA_CLASS1,
1029+ cdf::EOB_PT_32_CHROMA_CLASS1_Q3,
1030+ ),
993 eob_pt_256_luma_class1: pick(1031 eob_pt_256_luma_class1: pick(
994 q_ctx,1032 q_ctx,
995 cdf::EOB_PT_256_LUMA_CLASS1_Q0,1033 cdf::EOB_PT_256_LUMA_CLASS1_Q0,
@@ -1755,7 +1793,7 @@ impl Cdfs {
1755 br: &mut self.br_luma_16,1793 br: &mut self.br_luma_16,
1756 dc_sign: &mut self.dc_sign_luma,1794 dc_sign: &mut self.dc_sign_luma,
1757 tx_type: Some(self.intra_tx_type_8[mode].as_mut_slice()),1795 tx_type: Some(self.intra_tx_type_8[mode].as_mut_slice()),
1758- eob_pt_class1: None,1796+ eob_pt_class1: Some(&mut self.eob_pt_128_luma_class1),
1759 },1797 },
1760 TxbSet::LumaRect16x8Set1 => TxbTables {1798 TxbSet::LumaRect16x8Set1 => TxbTables {
1761 side: 16,1799 side: 16,
@@ -1767,7 +1805,31 @@ impl Cdfs {
1767 br: &mut self.br_luma_16,1805 br: &mut self.br_luma_16,
1768 dc_sign: &mut self.dc_sign_luma,1806 dc_sign: &mut self.dc_sign_luma,
1769 tx_type: Some(self.intra_tx_type_8_set1[mode].as_mut_slice()),1807 tx_type: Some(self.intra_tx_type_8_set1[mode].as_mut_slice()),
1770- eob_pt_class1: None,1808+ eob_pt_class1: Some(&mut self.eob_pt_128_luma_class1),
1809+ },
1810+ TxbSet::LumaRect16x8Inter => TxbTables {
1811+ side: 16,
1812+ txb_skip: &mut self.txb_skip_luma_16,
1813+ eob_pt: &mut self.eob_pt_128_luma,
1814+ eob_extra: &mut self.eob_extra_luma_16,
1815+ base: &mut self.base_luma_16,
1816+ base_eob: &mut self.base_eob_luma_16,
1817+ br: &mut self.br_luma_16,
1818+ dc_sign: &mut self.dc_sign_luma,
1819+ tx_type: Some(self.inter_tx_type_8.as_mut_slice()),
1820+ eob_pt_class1: Some(&mut self.eob_pt_128_luma_class1),
1821+ },
1822+ TxbSet::LumaRect16x8InterSet1 => TxbTables {
1823+ side: 16,
1824+ txb_skip: &mut self.txb_skip_luma_16,
1825+ eob_pt: &mut self.eob_pt_128_luma,
1826+ eob_extra: &mut self.eob_extra_luma_16,
1827+ base: &mut self.base_luma_16,
1828+ base_eob: &mut self.base_eob_luma_16,
1829+ br: &mut self.br_luma_16,
1830+ dc_sign: &mut self.dc_sign_luma,
1831+ tx_type: Some(self.inter_tx_type_8_set1.as_mut_slice()),
1832+ eob_pt_class1: Some(&mut self.eob_pt_128_luma_class1),
1771 },1833 },
1772 TxbSet::ChromaRect8x4 => TxbTables {1834 TxbSet::ChromaRect8x4 => TxbTables {
1773 side: 8,1835 side: 8,
@@ -1779,7 +1841,7 @@ impl Cdfs {
1779 br: &mut self.br_chroma_8,1841 br: &mut self.br_chroma_8,
1780 dc_sign: &mut self.dc_sign_chroma,1842 dc_sign: &mut self.dc_sign_chroma,
1781 tx_type: None,1843 tx_type: None,
1782- eob_pt_class1: None,1844+ eob_pt_class1: Some(&mut self.eob_pt_32_chroma_class1),
1783 },1845 },
1784 }1846 }
1785 }1847 }
crates/ec-av1/src/decode.rsmodified+192 -12
@@ -774,6 +774,10 @@ thread_local! {
774 // their rect max transform into square sub-transforms.774 // their rect max transform into square sub-transforms.
775 static RECT_INTER_TU_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };775 static RECT_INTER_TU_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
776 static RECT_INTER_TXSPLIT_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };776 static RECT_INTER_TXSPLIT_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
777+ // lane-inter4 r3: 16x16-level PARTITION_HORZ / PARTITION_VERT on an inter
778+ // frame -- 16x8 and 8x16 inter leaves.
779+ static INTER_LEAF16_HORZ_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
780+ static INTER_LEAF16_VERT_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
777 // This frame's own `tx_mode == TxMode::Select` and `reduced_tx_set` bits,781 // This frame's own `tx_mode == TxMode::Select` and `reduced_tx_set` bits,
778 // set once per inter tile by [`decode_inter_frame_tile_with_cdfs`] --782 // set once per inter tile by [`decode_inter_frame_tile_with_cdfs`] --
779 // `decode_inter_block` already carries forty parameters and both are783 // `decode_inter_block` already carries forty parameters and both are
@@ -792,6 +796,16 @@ pub(crate) fn txfm_split_hits() -> usize {
792 TXFM_SPLIT_HITS.with(|c| c.get())796 TXFM_SPLIT_HITS.with(|c| c.get())
793 }797 }
794 798
799+/// Current value of [`INTER_LEAF16_HORZ_HITS`] (lane-inter4 r3).
800+pub(crate) fn inter_leaf16_horz_hits() -> usize {
801+ INTER_LEAF16_HORZ_HITS.with(|c| c.get())
802+}
803+
804+/// Current value of [`INTER_LEAF16_VERT_HITS`] (lane-inter4 r3).
805+pub(crate) fn inter_leaf16_vert_hits() -> usize {
806+ INTER_LEAF16_VERT_HITS.with(|c| c.get())
807+}
808+
795 /// Current value of [`RECT_INTER_TU_HITS`] (lane-inter4 r2).809 /// Current value of [`RECT_INTER_TU_HITS`] (lane-inter4 r2).
796 pub(crate) fn rect_inter_tu_hits() -> usize {810 pub(crate) fn rect_inter_tu_hits() -> usize {
797 RECT_INTER_TU_HITS.with(|c| c.get())811 RECT_INTER_TU_HITS.with(|c| c.get())
@@ -9018,7 +9032,53 @@ fn read_block_tx_size(
9018 /// `DTT9_IDTX_1DDCT` row at `tx_size_sqr == TX_8X8`, only reachable through a9032 /// `DTT9_IDTX_1DDCT` row at `tx_size_sqr == TX_8X8`, only reachable through a
9019 /// rect transform), neither of which exists yet -- both stay refused by name.9033 /// rect transform), neither of which exists yet -- both stay refused by name.
9020 fn rect_inter_residual_supported(w: usize, h: usize) -> bool {9034 fn rect_inter_residual_supported(w: usize, h: usize) -> bool {
9021- matches!((w, h), (32, 16) | (16, 32))9035+ matches!((w, h), (32, 16) | (16, 32) | (16, 8) | (8, 16))
9036+}
9037+
9038+/// The luma coefficient/`tx_type` table set of a whole-block rectangular
9039+/// INTER transform unit (lane-inter4 r3). `av1_get_ext_tx_set_type` splits
9040+/// the two shapes: a 32x16/16x32 unit has `tx_size_sqr_up == TX_32X32`, so
9041+/// it reads the 2-symbol `EXT_TX_SET_DCT_IDTX` set regardless of
9042+/// `reduced_tx_set`; a 16x8/8x16 unit has `tx_size_sqr_up == TX_16X16` and
9043+/// `tx_size_sqr == TX_8X8`, so it reads `EXT_TX_SET_DCT_IDTX` when reduced
9044+/// and the 16-symbol `EXT_TX_SET_ALL16` otherwise -- both at the *8x8* CDF
9045+/// row (`txsize_sqr_map`), never the 16x16 one.
9046+fn rect_inter_luma_set(w: usize, h: usize) -> TxbSet {
9047+ match (w, h) {
9048+ (32, 16) | (16, 32) => TxbSet::LumaRect32x16Inter,
9049+ (16, 8) | (8, 16) => {
9050+ if REDUCED_TX_SET_INTER.with(std::cell::Cell::get) {
9051+ TxbSet::LumaRect16x8Inter
9052+ } else {
9053+ TxbSet::LumaRect16x8InterSet1
9054+ }
9055+ }
9056+ _ => unreachable!("rect_inter_residual_supported gates every shape that reaches here"),
9057+ }
9058+}
9059+
9060+/// The chroma table set of the same block's single rectangular chroma unit
9061+/// (`av1_get_max_uv_txsize`): 16x8/8x16 under a 32x16/16x32 strip, 8x4/4x8
9062+/// under a 16x8/8x16 one. Neither codes a `tx_type` symbol -- both inherit
9063+/// the luma unit's.
9064+fn rect_inter_chroma_set(w: usize, h: usize) -> TxbSet {
9065+ match (w, h) {
9066+ (16, 8) | (8, 16) => TxbSet::ChromaRect16x8,
9067+ (8, 4) | (4, 8) => TxbSet::ChromaRect8x4,
9068+ _ => unreachable!("rect_inter_residual_supported gates every shape that reaches here"),
9069+ }
9070+}
9071+
9072+/// libaom `size_group_lookup[bsize]` for the block shapes this decoder's
9073+/// inter path reaches, from the block's TRUE footprint rather than the
9074+/// square `side` corner-cut: 8x8/8x16/16x8 -> 1, 16x16/16x32/32x16 -> 2,
9075+/// everything 32 and above -> 3.
9076+fn size_group_wh(w: usize, h: usize) -> usize {
9077+ match w.min(h) {
9078+ 0..=8 => 1,
9079+ 16 => 2,
9080+ _ => 3,
9081+ }
9022 }9082 }
9023 9083
9024 /// The default (2D) coefficient scan of a rectangular transform.9084 /// The default (2D) coefficient scan of a rectangular transform.
@@ -12715,11 +12775,34 @@ fn obmc_blend(
12715 // its OWN neighbour cap (width-log2 for above, height-log2 for left) and12775 // its OWN neighbour cap (width-log2 for above, height-log2 for left) and
12716 // overlap (bh/2 rows above, bw/2 cols left) -- one square `side` was12776 // overlap (bh/2 rows above, bw/2 cols left) -- one square `side` was
12717 // right only for square blocks.12777 // right only for square blocks.
12778+ // libaom `max_neighbor_obmc[6] = { 0, 1, 2, 3, 4, 4 }` indexed by
12779+ // `mi_size_wide_log2[bsize]` (above pass) / `mi_size_high_log2` (left):
12780+ // 1 mi -> 0, 2 -> 1, 4 -> 2, 8 -> 3, 16+ -> 4. lane-inter4 r3: the old
12781+ // `1..=4 => 2` row was right only for blocks at least 16 px on that axis
12782+ // -- a 16x8 leaf's LEFT pass (bh4 = 2) walked up to two neighbours where
12783+ // libaom walks one, blending an extra 8-px-tall neighbour into every
12784+ // rect leaf with two of them on its left edge (class table-narrowed-to-
12785+ // the-reachable-sizes; the square gates could never expose it).
12718 let max_nb = |n4: usize| match n4 {12786 let max_nb = |n4: usize| match n4 {
12719- 1..=4 => 2,12787+ 0..=1 => 0,
12788+ 2 => 1,
12789+ 3..=4 => 2,
12720 5..=8 => 3,12790 5..=8 => 3,
12721 _ => 4,12791 _ => 4,
12722 };12792 };
12793+ // lane-inter4 r3: OBMC on a 16-level rect inter leaf mismatches ffmpeg
12794+ // (192x128 testsrc-style motion, cq 22, `--enable-obmc=1`: 5302 luma
12795+ // pixels of frame 5 wrong, max |delta| 84, while the SAME recipe with
12796+ // `--enable-obmc=0` decodes 5 rect-leaf-carrying attempts pixel-exact).
12797+ // The blend geometry here matches libaom `build_obmc_inter_pred_*` for
12798+ // these shapes, so the cause is upstream (neighbour walk or mv stack for
12799+ // a 2:1 leaf) and unidentified -- refuse by name rather than ship wrong
12800+ // pixels. Deleting this block is the whole lift once it is found.
12801+ if matches!((write_w, write_h), (16, 8) | (8, 16)) {
12802+ return Err(unsupported(
12803+ "OBMC on a 16x8/8x16 inter leaf (blend mismatches the reference on this shape)",
12804+ ));
12805+ }
12723 let overlap_above = write_h / 2;12806 let overlap_above = write_h / 2;
12724 let overlap_left = write_w / 2;12807 let overlap_left = write_w / 2;
12725 // lane-inter8 r1 / lane-scaledref r1: `av1_skip_u4x4_pred_in_obmc`12808 // lane-inter8 r1 / lane-scaledref r1: `av1_skip_u4x4_pred_in_obmc`
@@ -13143,7 +13226,11 @@ fn decode_inter_block(
13143 chroma_tx: usize,13226 chroma_tx: usize,
13144 scan_luma: &[u16],13227 scan_luma: &[u16],
13145 scan_chroma: &[u16],13228 scan_chroma: &[u16],
13146- size_group: usize,13229+ // lane-inter4 r3: superseded by `size_group_wh(write_w, write_h)` at the
13230+ // one site that read it (`y_mode`) -- a rect strip's group comes from its
13231+ // true footprint, not the caller's square `side`. Kept in the signature
13232+ // rather than editing twenty call sites.
13233+ _size_group: usize,
13147 allow_high_precision_mv: bool,13234 allow_high_precision_mv: bool,
13148 force_integer_mv: bool,13235 force_integer_mv: bool,
13149 interp_fixed: Option<mc::InterpFilterKind>,13236 interp_fixed: Option<mc::InterpFilterKind>,
@@ -14205,7 +14292,7 @@ fn decode_inter_block(
14205 let (grid, tx_type) = read_inter_plane_rect(14292 let (grid, tx_type) = read_inter_plane_rect(
14206 dec,14293 dec,
14207 cdfs,14294 cdfs,
14208- TxbSet::LumaRect32x16Inter,14295+ rect_inter_luma_set(write_w, write_h),
14209 (write_w, write_h),14296 (write_w, write_h),
14210 side,14297 side,
14211 0,14298 0,
@@ -14248,7 +14335,7 @@ fn decode_inter_block(
14248 &read_inter_plane_rect(14335 &read_inter_plane_rect(
14249 dec,14336 dec,
14250 cdfs,14337 cdfs,
14251- TxbSet::ChromaRect16x8,14338+ rect_inter_chroma_set(write_chroma_w, write_chroma_h),
14252 (uw, uh),14339 (uw, uh),
14253 chroma_side,14340 chroma_side,
14254 1,14341 1,
@@ -14269,7 +14356,7 @@ fn decode_inter_block(
14269 &read_inter_plane_rect(14356 &read_inter_plane_rect(
14270 dec,14357 dec,
14271 cdfs,14358 cdfs,
14272- TxbSet::ChromaRect16x8,14359+ rect_inter_chroma_set(write_chroma_w, write_chroma_h),
14273 (uw, uh),14360 (uw, uh),
14274 chroma_side,14361 chroma_side,
14275 2,14362 2,
@@ -14511,7 +14598,10 @@ fn decode_inter_block(
14511 && (side == 16 || side == 32)14598 && (side == 16 || side == 32)
14512 && interintra_shape14599 && interintra_shape
14513 {14600 {
14514- let bsize_group = if side == 16 { 2 } else { 3 };14601+ // lane-inter4 r3: `size_group_lookup` reads the block's
14602+ // TRUE footprint -- a 16x8 strip is group 1, a 32x16 strip
14603+ // group 2, not their square `side`'s 2/3.
14604+ let bsize_group = size_group_wh(write_w, write_h);
14515 let interintra = dec.symbol(&mut cdfs.interintra[bsize_group]) == 1;14605 let interintra = dec.symbol(&mut cdfs.interintra[bsize_group]) == 1;
14516 if interintra {14606 if interintra {
14517 // lane-interintra r1 (decodemv.c 1540-1555): interintra_mode,14607 // lane-interintra r1 (decodemv.c 1540-1555): interintra_mode,
@@ -14621,6 +14711,9 @@ fn decode_inter_block(
14621 (32, 8) => 9,14711 (32, 8) => 9,
14622 (16, 64) => 10,14712 (16, 64) => 10,
14623 (64, 16) => 11,14713 (64, 16) => 11,
14714+ // lane-inter4 r3: the 16x16-level rect inter leaves.
14715+ (8, 16) => 12,
14716+ (16, 8) => 13,
14624 _ => {14717 _ => {
14625 return Err(unsupported(14718 return Err(unsupported(
14626 "a motion_mode symbol for a block shape with no CDF row here",14719 "a motion_mode symbol for a block shape with no CDF row here",
@@ -15137,7 +15230,7 @@ fn decode_inter_block(
15137 let (grid, tx_type) = read_inter_plane_rect(15230 let (grid, tx_type) = read_inter_plane_rect(
15138 dec,15231 dec,
15139 cdfs,15232 cdfs,
15140- TxbSet::LumaRect32x16Inter,15233+ rect_inter_luma_set(write_w, write_h),
15141 (write_w, write_h),15234 (write_w, write_h),
15142 side,15235 side,
15143 0,15236 0,
@@ -15180,7 +15273,7 @@ fn decode_inter_block(
15180 &read_inter_plane_rect(15273 &read_inter_plane_rect(
15181 dec,15274 dec,
15182 cdfs,15275 cdfs,
15183- TxbSet::ChromaRect16x8,15276+ rect_inter_chroma_set(write_chroma_w, write_chroma_h),
15184 (uw, uh),15277 (uw, uh),
15185 chroma_side,15278 chroma_side,
15186 1,15279 1,
@@ -15201,7 +15294,7 @@ fn decode_inter_block(
15201 &read_inter_plane_rect(15294 &read_inter_plane_rect(
15202 dec,15295 dec,
15203 cdfs,15296 cdfs,
15204- TxbSet::ChromaRect16x8,15297+ rect_inter_chroma_set(write_chroma_w, write_chroma_h),
15205 (uw, uh),15298 (uw, uh),
15206 chroma_side,15299 chroma_side,
15207 2,15300 2,
@@ -15271,7 +15364,7 @@ fn decode_inter_block(
15271 this decoder does not code yet",15364 this decoder does not code yet",
15272 ));15365 ));
15273 }15366 }
15274- let mode = dec.symbol(&mut cdfs.y_mode[size_group]);15367+ let mode = dec.symbol(&mut cdfs.y_mode[size_group_wh(write_w, write_h)]);
15275 if mode >= 13 {15368 if mode >= 13 {
15276 return Err(unsupported(15369 return Err(unsupported(
15277 "an intra mode this decoder does not code (round 2)",15370 "an intra mode this decoder does not code (round 2)",
@@ -17877,9 +17970,96 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
17877 allow_screen_content_tools,17970 allow_screen_content_tools,
17878 frame_width as usize,17971 frame_width as usize,
17879 )?;17972 )?;
17973+ } else if part16 == PARTITION_HORZ || part16 == PARTITION_VERT {
17974+ // lane-inter4 r3: the 16x16-level rect inter
17975+ // leaves -- two true 16x8 (HORZ) or 8x16
17976+ // (VERT) inter blocks. Same shape as the
17977+ // 32-level HORZ/VERT arm above: `side = SUB`
17978+ // keeps every CDF/prediction-buffer decision
17979+ // square, `write_w`/`write_h` carry the true
17980+ // footprint into the mv stack, the motion-mode
17981+ // row, the neighbour stamps and the rectangular
17982+ // residual path (`rect_inter_residual_supported`
17983+ // covers 16x8/8x16 since this round).
17984+ let horz = part16 == PARTITION_HORZ;
17985+ if horz {
17986+ INTER_LEAF16_HORZ_HITS.with(|c| c.set(c.get() + 1));
17987+ } else {
17988+ INTER_LEAF16_VERT_HITS.with(|c| c.set(c.get() + 1));
17989+ }
17990+ let base_mi = sub16_to_mi(at16);
17991+ let (ww, wh) = if horz { (16, 8) } else { (8, 16) };
17992+ for piece in 0..2 {
17993+ let piece_mi = if horz {
17994+ (base_mi.0 + piece * 2, base_mi.1)
17995+ } else {
17996+ (base_mi.0, base_mi.1 + piece * 2)
17997+ };
17998+ // libaom `decode_partition`'s own second-
17999+ // half frame-edge break.
18000+ if piece > 0
18001+ && (piece_mi.0 >= mi_rows as usize
18002+ || piece_mi.1 >= mi_cols as usize)
18003+ {
18004+ break;
18005+ }
18006+ decode_inter_block(
18007+ &mut dec,
18008+ &mut cdfs,
18009+ &mut neighbours,
18010+ &mut grid,
18011+ piece_mi,
18012+ SUB,
18013+ mi_cols,
18014+ mi_rows,
18015+ &mut y,
18016+ &mut u,
18017+ &mut v,
18018+ &ref_y,
18019+ &ref_u,
18020+ &ref_v,
18021+ &ref_slots,
18022+ &sign_bias_table,
18023+ &global_motion,
18024+ base_q_idx,
18025+ TxbSet::Luma16,
18026+ if reduced_tx_set {
18027+ TxbSet::Luma16Inter
18028+ } else {
18029+ TxbSet::Luma16InterSet1
18030+ },
18031+ TxbSet::Chroma8,
18032+ TX16,
18033+ TX8,
18034+ &scan16,
18035+ &scan8,
18036+ 1,
18037+ allow_high_precision_mv,
18038+ force_integer_mv,
18039+ interp_fixed,
18040+ enable_dual_filter,
18041+ tpl_frame.as_ref(),
18042+ reference_select,
18043+ enable_masked_compound,
18044+ enable_interintra_compound,
18045+ enable_jnt_comp,
18046+ order_hint_bits,
18047+ order_hint,
18048+ ref_order_hints,
18049+ skip_mode_present,
18050+ skip_mode_frame,
18051+ switchable_motion_mode,
18052+ allow_warped_motion,
18053+ true,
18054+ ww,
18055+ wh,
18056+ allow_screen_content_tools,
18057+ frame_width as usize,
18058+ )?;
18059+ }
17880 } else if part16 != PARTITION_SPLIT {18060 } else if part16 != PARTITION_SPLIT {
17881 return Err(unsupported(18061 return Err(unsupported(
17882- "an inter partition below 16x16 other than SPLIT (16x8/8x16 rect inter leaves are not coded yet)",18062+ "an inter 16x16-level AB or 1:4 partition (HORZ_A/HORZ_B/VERT_A/VERT_B/HORZ_4/VERT_4; this decoder's inter path codes a 16x16 as NONE, HORZ, VERT or SPLIT)",
17883 ));18063 ));
17884 } else {18064 } else {
17885 if has_cols16 && has_rows16 {18065 if has_cols16 && has_rows16 {
crates/ec-av1/src/refusal_inventory.rsmodified+2 -1
@@ -64,7 +64,8 @@ const REFUSALS: &[&str] = &[
64 "an inter frame with no key frame before it",64 "an inter frame with no key frame before it",
65 "an inter SB-level AB partition (HORZ_A/HORZ_B/VERT_A/VERT_B; this decoder's inter tile path codes a superblock as NONE, SPLIT, HORZ, VERT, HORZ_4 or VERT_4)",65 "an inter SB-level AB partition (HORZ_A/HORZ_B/VERT_A/VERT_B; this decoder's inter tile path codes a superblock as NONE, SPLIT, HORZ, VERT, HORZ_4 or VERT_4)",
66 "a masked compound 64x64 inter block (compound_type is inferred, not coded, at this size)",66 "a masked compound 64x64 inter block (compound_type is inferred, not coded, at this size)",
67- "an inter partition below 16x16 other than SPLIT (16x8/8x16 rect inter leaves are not coded yet)",67+ "an inter 16x16-level AB or 1:4 partition (HORZ_A/HORZ_B/VERT_A/VERT_B/HORZ_4/VERT_4; this decoder's inter path codes a 16x16 as NONE, HORZ, VERT or SPLIT)",
68+ "OBMC on a 16x8/8x16 inter leaf (blend mismatches the reference on this shape)",
68 "an intra mode this decoder does not code (round 2)",69 "an intra mode this decoder does not code (round 2)",
69 "an intra-coded HORZ/VERT strip needs rectangular intra prediction this decoder does not code yet",70 "an intra-coded HORZ/VERT strip needs rectangular intra prediction this decoder does not code yet",
70 // Lifted for the 16x8/8x16 leaf by lane-fistrip; still live one level71 // Lifted for the 16x8/8x16 leaf by lane-fistrip; still live one level
crates/ec-av1/src/stream.rsmodified+239 -0
@@ -1945,6 +1945,10 @@ mod tests {
1945 // masked compound, palette, ...) are other lanes' work;1945 // masked compound, palette, ...) are other lanes' work;
1946 // this gate is about hidden frames, not about them.1946 // this gate is about hidden frames, not about them.
1947 "--enable-warped-motion=0",1947 "--enable-warped-motion=0",
1948+ // lane-inter4 r3: OBMC on a 16x8/8x16 leaf is a NAMED
1949+ // REFUSAL (see decode.rs `obmc_blend`) -- it mismatches
1950+ // the reference on this shape, so the gate spells the
1951+ // tool off rather than counting its refusals as passes.
1948 "--enable-obmc=0",1952 "--enable-obmc=0",
1949 "--enable-masked-comp=0",1953 "--enable-masked-comp=0",
1950 "--enable-interintra-comp=0",1954 "--enable-interintra-comp=0",
@@ -4915,6 +4919,241 @@ mod tests {
4915 }4919 }
4916 }4920 }
4917 4921
4922+ #[test]
4923+ // lane-inter4 r3: the 16x16-level rect INTER leaf -- PARTITION_HORZ /
4924+ // PARTITION_VERT at 16x16 on an inter frame, i.e. two 16x8 / 8x16 inter
4925+ // blocks, mode info + rectangular residual + prediction. Every decoded
4926+ // frame is compared Y/U/V against ffmpeg, refusals are counted and never
4927+ // SKIPped, and the gate asserts a pixel-exact attempt for BOTH axes that
4928+ // also coded a rectangular inter transform unit (i.e. was not `skip`).
4929+ fn a_real_aomenc_inter_sequence_with_a_16_level_rect_leaf_decodes_pixel_exact() {
4930+ const NAME: &str =
4931+ "a_real_aomenc_inter_sequence_with_a_16_level_rect_leaf_decodes_pixel_exact";
4932+ let _gate_lock = lock_gate_counters();
4933+ if !have_ffmpeg() {
4934+ eprintln!("SKIP {NAME}: no ffmpeg");
4935+ return;
4936+ }
4937+ if !have_aomenc() {
4938+ eprintln!("SKIP {NAME}: no aomenc at {}", aomenc_path().display());
4939+ return;
4940+ }
4941+ let (width, height, frame_count) = (192usize, 128usize, 6usize);
4942+ // Coded (non-skip) rect inter transform units, summed over both bit
4943+ // depths: at 10 bits this recipe's rect leaves all come out `skip`
4944+ // (measured at cq 34/22, 30/26 and 24/12 -- the lower pairs stop
4945+ // reaching a rect leaf at all), so the RESIDUAL half of the claim is
4946+ // proven by the 8-bit arm while the 10-bit arm proves the mode-info,
4947+ // prediction and neighbour halves on both axes.
4948+ let mut tu_total = 0usize;
4949+ for bit_depth in [8u32, 10u32] {
4950+ let (mut named_refusals, mut matched, mut out_of_scope, mut oos_mismatch) =
4951+ (0u32, 0u32, 0u32, 0u32);
4952+ let (mut tu_proved, mut split_proved) = (0usize, 0usize);
4953+ let (mut horz_proved, mut vert_proved, mut sub16_split) = (0u32, 0u32, 0usize);
4954+ for attempt in 0..16u32 {
4955+ // Two sources (a translating textured ramp, and testsrc2's
4956+ // natural motion) x two quantisers x two tx-size-search arms x
4957+ // two motion steps.
4958+ let tx_search = if attempt % 2 == 0 { "0" } else { "1" };
4959+ // A 10-bit encode of the same source spends fewer bits on
4960+ // residual at a given cq, so it needs the lower pair to make
4961+ // a rect leaf non-skip at all (measured: cq 34/22 gives zero
4962+ // coded rect inter TUs in 16 10-bit attempts).
4963+ let cq = [34, 22][(attempt / 2 % 2) as usize];
4964+ let natural = attempt / 4 % 2 == 1;
4965+ let sp = 3 + (attempt / 8) * 5;
4966+ let duration = frame_count as f64 / 25.0;
4967+ // Continuous-tone, mid-frequency, translating: a flat or
4968+ // banded source makes aomenc code the strips `skip` (r1's
4969+ // gate) and its screen-content detector fires on the
4970+ // synthetic ramps, stopping the decode at an unrelated intra
4971+ // refusal long before any inter strip.
4972+ // Structure ALONG one axis is what makes aomenc's RD pick a
4973+ // 2:1 rect partition on that axis: horizontal bands drifting
4974+ // vertically favour PARTITION_HORZ (32x16 strips), the
4975+ // transposed source PARTITION_VERT (16x32).
4976+ let lum = if natural {
4977+ format!("128+58*sin((Y+N*{sp})/6)+18*sin(X/23)")
4978+ } else {
4979+ format!("128+58*sin((X+N*{sp})/6)+18*sin(Y/23)")
4980+ };
4981+ let source = format!(
4982+ "color=c=gray:s={width}x{height}:d={duration}:r=25,format=gray,\
4983+ geq=lum='{lum}',format=yuv420p"
4984+ );
4985+ let pix_fmt = if bit_depth == 10 { "yuv420p10le" } else { "yuv420p" };
4986+ let y4m = Command::new("ffmpeg")
4987+ .args([
4988+ "-v", "error", "-f", "lavfi", "-i", &source, "-t", &duration.to_string(),
4989+ "-pix_fmt", pix_fmt, "-strict", "-1", "-f", "yuv4mpegpipe", "-",
4990+ ])
4991+ .stdin(Stdio::null())
4992+ .stdout(Stdio::piped())
4993+ .stderr(Stdio::piped())
4994+ .output()
4995+ .expect("ffmpeg failed to run");
4996+ assert!(
4997+ y4m.status.success(),
4998+ "{NAME}: ffmpeg refused the {bit_depth}-bit fixture: {}",
4999+ String::from_utf8_lossy(&y4m.stderr)
5000+ );
5001+ let cq_arg = format!("--cq-level={cq}");
5002+ let depth_arg = format!("--bit-depth={bit_depth}");
5003+ let input_depth_arg = format!("--input-bit-depth={bit_depth}");
5004+ let tx_arg = format!("--enable-tx-size-search={tx_search}");
5005+ let args: Vec<&str> = vec![
5006+ "--codec=av1", "--passes=1", "--end-usage=q", &cq_arg, "--cpu-used=0",
5007+ "--threads=1", "--row-mt=0", "--sb-size=64", &depth_arg, &input_depth_arg,
5008+ "--enable-restoration=0", "--enable-palette=0", "--deltaq-mode=0",
5009+ "--enable-filter-intra=0", "--enable-cfl-intra=0", "--enable-intrabc=0",
5010+ "--lag-in-frames=0",
5011+ // Per-arm overrides go LAST: aomenc keeps the last
5012+ // occurrence of a repeated --enable-* flag.
5013+ &tx_arg,
5014+ "--enable-rect-partitions=1", "--enable-ab-partitions=0",
5015+ "--enable-1to4-partitions=0", "--min-partition-size=8",
5016+ "--max-partition-size=16",
5017+ "--enable-obmc=0",
5018+ "--obu", "-o", "-", "-",
5019+ ];
5020+ let mut child = Command::new(aomenc_path())
5021+ .args(&args)
5022+ .stdin(Stdio::piped())
5023+ .stdout(Stdio::piped())
5024+ .stderr(Stdio::piped())
5025+ .spawn()
5026+ .expect("aomenc failed to start");
5027+ child
5028+ .stdin
5029+ .take()
5030+ .expect("aomenc stdin")
5031+ .write_all(&y4m.stdout)
5032+ .expect("writing y4m to aomenc");
5033+ let out = child.wait_with_output().expect("aomenc failed to run");
5034+ assert!(
5035+ out.status.success(),
5036+ "aomenc refused the fixture: {}",
5037+ String::from_utf8_lossy(&out.stderr)
5038+ );
5039+ let stream = out.stdout;
5040+ let before = (decode::rect_inter_tu_hits(), decode::rect_inter_txsplit_hits());
5041+ let before_leaf = (
5042+ decode::inter_leaf16_horz_hits(),
5043+ decode::inter_leaf16_vert_hits(),
5044+ decode::inter_sub16_split_hits(),
5045+ );
5046+ let frames = match decode_stream(&stream) {
5047+ Err(e) => {
5048+ let msg = e.to_string();
5049+ assert!(
5050+ msg.contains("unsupported"),
5051+ "{NAME} failed outright, not a named refusal ({bit_depth}-bit, \
5052+ attempt {attempt}): {msg}"
5053+ );
5054+ named_refusals += 1;
5055+ eprintln!("{bit_depth}-bit attempt {attempt} refusal: {msg}");
5056+ continue;
5057+ }
5058+ Ok(frames) => frames,
5059+ };
5060+ let after = (decode::rect_inter_tu_hits(), decode::rect_inter_txsplit_hits());
5061+ let (tu, split) = (after.0 - before.0, after.1 - before.1);
5062+ let (horz, vert, splits16) = (
5063+ decode::inter_leaf16_horz_hits() - before_leaf.0,
5064+ decode::inter_leaf16_vert_hits() - before_leaf.1,
5065+ decode::inter_sub16_split_hits() - before_leaf.2,
5066+ );
5067+ let ffmpeg_frames = if bit_depth == 10 {
5068+ ffmpeg_decode_sequence_10bit(&stream, width, height, frame_count)
5069+ } else {
5070+ ffmpeg_decode_sequence(&stream, width, height, frame_count)
5071+ };
5072+ assert_eq!(frames.len(), frame_count);
5073+ let mismatched = frames
5074+ .iter()
5075+ .zip(&ffmpeg_frames)
5076+ .any(|(got, want)| got.y != want.y || got.u != want.u || got.v != want.v);
5077+ if horz + vert == 0 {
5078+ out_of_scope += 1;
5079+ if mismatched {
5080+ oos_mismatch += 1;
5081+ eprintln!(
5082+ "{NAME}: {bit_depth}-bit attempt {attempt} MISMATCHES with zero \
5083+ 16-level rect inter leaf -- another shape's defect"
5084+ );
5085+ }
5086+ continue;
5087+ }
5088+ if mismatched {
5089+ // lane-inter4 r3: where, not just that -- a handful of
5090+ // 4x4-aligned pixels is a prediction/reconstruction
5091+ // defect, a whole band from the first row down is a
5092+ // desync.
5093+ for (i, (got, want)) in frames.iter().zip(&ffmpeg_frames).enumerate() {
5094+ let bad: Vec<usize> = (0..got.y.len())
5095+ .filter(|&k| got.y[k] != want.y[k])
5096+ .collect();
5097+ if !bad.is_empty() {
5098+ eprintln!(
5099+ "{NAME}: attempt {attempt} {bit_depth}-bit frame {i}: {} luma \
5100+ pixels differ, first at ({}, {}), max |delta| {}",
5101+ bad.len(),
5102+ bad[0] % width,
5103+ bad[0] / width,
5104+ bad.iter()
5105+ .map(|&k| (got.y[k] as i32 - want.y[k] as i32).abs())
5106+ .max()
5107+ .unwrap_or(0)
5108+ );
5109+ }
5110+ }
5111+ }
5112+ for (i, (got, want)) in frames.iter().zip(&ffmpeg_frames).enumerate() {
5113+ assert_eq!(got.y, want.y, "{NAME} frame {i} luma vs ffmpeg (attempt {attempt}, {bit_depth}-bit, tx_search={tx_search})");
5114+ assert_eq!(got.u, want.u, "{NAME} frame {i} U vs ffmpeg (attempt {attempt}, {bit_depth}-bit, tx_search={tx_search})");
5115+ assert_eq!(got.v, want.v, "{NAME} frame {i} V vs ffmpeg (attempt {attempt}, {bit_depth}-bit, tx_search={tx_search})");
5116+ }
5117+ tu_proved += tu;
5118+ split_proved += split;
5119+ sub16_split += splits16;
5120+ if horz > 0 {
5121+ horz_proved += 1;
5122+ }
5123+ if vert > 0 {
5124+ vert_proved += 1;
5125+ }
5126+ matched += 1;
5127+ }
5128+ eprintln!(
5129+ "{NAME} ({bit_depth}-bit): {named_refusals} named refusals, {matched} pixel-exact \
5130+ attempts carrying a 16-level rect inter leaf, 16x8-carrying={horz_proved}, \
5131+ 8x16-carrying={vert_proved}, whole-block rect TUs={tu_proved}, rect trees that \
5132+ split={split_proved}, 16x16 SPLITs={sub16_split}, {out_of_scope} attempts \
5133+ carried none ({oos_mismatch} of them mismatched)"
5134+ );
5135+ assert_eq!(
5136+ oos_mismatch, 0,
5137+ "{NAME}: {oos_mismatch} attempt(s) with no coded rect inter residual decoded but \
5138+ mismatched ffmpeg -- a defect of another shape, not a pass"
5139+ );
5140+ assert!(
5141+ horz_proved > 0 && vert_proved > 0,
5142+ "{NAME} ({bit_depth}-bit): the 16-level rect inter leaf is not proven on both \
5143+ axes (16x8={horz_proved}, 8x16={vert_proved}, tu={tu_proved}, 16x16 \
5144+ SPLITs={sub16_split}, {named_refusals} refusals, {out_of_scope} out of \
5145+ scope) -- gate proved nothing"
5146+ );
5147+ tu_total += tu_proved;
5148+ }
5149+ assert!(
5150+ tu_total > 0,
5151+ "{NAME}: no pixel-exact attempt at either bit depth coded a rectangular inter \
5152+ residual on a 16-level leaf -- the residual half of the claim is unproven"
5153+ );
5154+ }
5155+
5156+
4918 #[test]5157 #[test]
4919 fn a_real_aomenc_inter_sequence_with_deblocking_decodes_pixel_exact() {5158 fn a_real_aomenc_inter_sequence_with_deblocking_decodes_pixel_exact() {
4920 if !have_ffmpeg() {5159 if !have_ffmpeg() {