Merge branch 'lane-tx4x8': 4x8/8x4 leaves read tx_depth (TX_MODE_SELECT) and code TX_4X8/8X4 (ReelB head blocker); every rect shape carries its own libaom reach row
Browse files at this commit10 changed files +1644 -131
- crates/ec-av1/src/cdf.rs +24 -0
- crates/ec-av1/src/cdf_state.rs +59 -0
- crates/ec-av1/src/decode.rs +629 -86
- crates/ec-av1/src/encode.rs +202 -39
- crates/ec-av1/src/gate_coverage.rs +0 -4
- crates/ec-av1/src/refusal_inventory.rs +0 -2
- crates/ec-av1/src/stream.rs +443 -0
- lanes/tx4x8-r1.report.md +92 -0
- lanes/tx4x8-r2.report.md +79 -0
- lanes/tx4x8-r3.report.md +116 -0
crates/ec-av1/src/cdf.rsmodified+24 -0
| @@ -4749,6 +4749,30 @@ pub const EOB_PT_16_LUMA_Q3: [u16; 6] = [6708, 8958, 14746, 22133, 32768, 0]; | |||
| 4749 | /// `V_DCT`/`H_DCT` (lane-av1tx4 r5: the class dimension libaom always keeps, | 4749 | /// `V_DCT`/`H_DCT` (lane-av1tx4 r5: the class dimension libaom always keeps, |
| 4750 | /// this crate never carried at all until a real aomdec trace showed the | 4750 | /// this crate never carried at all until a real aomdec trace showed the |
| 4751 | /// desync starting exactly at this read). | 4751 | /// desync starting exactly at this read). |
| 4752 | +/// `av1_default_eob_multi32_cdfs` (libaom `token_cdfs.h`), luma plane, 2D tx | ||
| 4753 | +/// class: the end-of-block group of a 32-position transform -- the | ||
| 4754 | +/// `TX_4X8`/`TX_8X4` pair this decoder reaches through | ||
| 4755 | +/// [`crate::cdf_state::TxbSet::LumaRect4x8`] (lane-tx4x8). Q-context 2 | ||
| 4756 | +/// (`base_q_idx` 61..=120) is the unsuffixed name, as everywhere else here. | ||
| 4757 | +pub const EOB_PT_32_LUMA_Q0: [u16; 7] = [400, 520, 977, 2102, 6542, 32768, 0]; | ||
| 4758 | +/// [`EOB_PT_32_LUMA_Q0`]'s q-context 1 (`base_q_idx` 21..=60) sibling. | ||
| 4759 | +pub const EOB_PT_32_LUMA_Q1: [u16; 7] = [989, 1249, 2019, 4151, 10785, 32768, 0]; | ||
| 4760 | +/// [`EOB_PT_32_LUMA_Q0`]'s q-context 2 (`base_q_idx` 61..=120) sibling. | ||
| 4761 | +pub const EOB_PT_32_LUMA: [u16; 7] = [2515, 3003, 4452, 8162, 16041, 32768, 0]; | ||
| 4762 | +/// [`EOB_PT_32_LUMA_Q0`]'s q-context 3 (`base_q_idx` 121..=255) sibling. | ||
| 4763 | +pub const EOB_PT_32_LUMA_Q3: [u16; 7] = [4617, 5709, 8446, 13584, 23135, 32768, 0]; | ||
| 4764 | +/// [`EOB_PT_32_LUMA`]'s `TX_CLASS_HORIZ`/`TX_CLASS_VERT` sibling (the `[1]` | ||
| 4765 | +/// row of the same libaom table), read instead whenever the TU's `tx_type` | ||
| 4766 | +/// is `V_DCT`/`H_DCT` -- reachable at 4x8/8x4 because that size's intra | ||
| 4767 | +/// `tx_type` set is `EXT_TX_SET_DTT4_IDTX_1DDCT`, which carries both. | ||
| 4768 | +pub const EOB_PT_32_LUMA_CLASS1_Q0: [u16; 7] = [210, 405, 1315, 3326, 7537, 32768, 0]; | ||
| 4769 | +/// [`EOB_PT_32_LUMA_CLASS1_Q0`]'s q-context 1 sibling. | ||
| 4770 | +pub const EOB_PT_32_LUMA_CLASS1_Q1: [u16; 7] = [313, 441, 1099, 2917, 8562, 32768, 0]; | ||
| 4771 | +/// [`EOB_PT_32_LUMA_CLASS1_Q0`]'s q-context 2 sibling. | ||
| 4772 | +pub const EOB_PT_32_LUMA_CLASS1: [u16; 7] = [574, 821, 1836, 5089, 13128, 32768, 0]; | ||
| 4773 | +/// [`EOB_PT_32_LUMA_CLASS1_Q0`]'s q-context 3 sibling. | ||
| 4774 | +pub const EOB_PT_32_LUMA_CLASS1_Q3: [u16; 7] = [1156, 1702, 3675, 9274, 20539, 32768, 0]; | ||
| 4775 | + | ||
| 4752 | pub const EOB_PT_16_LUMA_CLASS1_Q0: [u16; 6] = [370, 671, 1883, 4471, 32768, 0]; | 4776 | pub const EOB_PT_16_LUMA_CLASS1_Q0: [u16; 6] = [370, 671, 1883, 4471, 32768, 0]; |
| 4753 | pub const EOB_PT_16_LUMA_CLASS1_Q1: [u16; 6] = [513, 765, 1859, 6339, 32768, 0]; | 4777 | pub const EOB_PT_16_LUMA_CLASS1_Q1: [u16; 6] = [513, 765, 1859, 6339, 32768, 0]; |
| 4754 | pub const EOB_PT_16_LUMA_CLASS1: [u16; 6] = [716, 1105, 2646, 10056, 32768, 0]; | 4778 | pub const EOB_PT_16_LUMA_CLASS1: [u16; 6] = [716, 1105, 2646, 10056, 32768, 0]; |
crates/ec-av1/src/cdf_state.rsmodified+59 -0
| @@ -172,6 +172,20 @@ pub(crate) enum TxbSet { | |||
| 172 | /// [`ChromaRect16x8`](TxbSet::ChromaRect16x8) has to `Chroma16`, one size | 172 | /// [`ChromaRect16x8`](TxbSet::ChromaRect16x8) has to `Chroma16`, one size |
| 173 | /// class down. | 173 | /// class down. |
| 174 | ChromaRect8x4, | 174 | ChromaRect8x4, |
| 175 | + /// The luma 4x8/8x4 transform of a `PARTITION_VERT`/`HORZ` leaf under an | ||
| 176 | + /// 8x8 block (lane-tx4x8), under this encoder's `reduced_tx_set`. | ||
| 177 | + /// `get_txsize_entropy_ctx` ((`txsize_sqr_map` + `txsize_sqr_up_map` + 1) | ||
| 178 | + /// >> 1) resolves `TX_4X8` to `TX_8X8`, so every coefficient table here is | ||
| 179 | + /// [`Luma8`](TxbSet::Luma8)'s -- except `eob_pt`, a true 32-position | ||
| 180 | + /// alphabet ([`crate::cdf::EOB_PT_32_LUMA`]), and `tx_type`, whose CDF row | ||
| 181 | + /// is `txsize_sqr_map[TX_4X8]` = `TX_4X4` (libaom `read_tx_type`'s | ||
| 182 | + /// `square_tx_size`), i.e. [`Luma4`](TxbSet::Luma4)'s own table. | ||
| 183 | + LumaRect4x8, | ||
| 184 | + /// [`LumaRect4x8`](TxbSet::LumaRect4x8)'s `reduced_tx_set: false` | ||
| 185 | + /// counterpart: `av1_get_ext_tx_set_type` at `tx_size_sqr_up == TX_8X8`, | ||
| 186 | + /// `tx_size_sqr == TX_4X4`, intra returns `EXT_TX_SET_DTT4_IDTX_1DDCT`, | ||
| 187 | + /// the same seven-symbol set (and same `TX_4X4` row) `Luma4Set1` reads. | ||
| 188 | + LumaRect4x8Set1, | ||
| 175 | } | 189 | } |
| 176 | 190 | ||
| 177 | /// The tables one transform block is coded with, borrowed from the state for | 191 | /// The tables one transform block is coded with, borrowed from the state for |
| @@ -277,6 +291,11 @@ pub(crate) struct Cdfs { | |||
| 277 | pub eob_pt_1024_luma_class1: [u16; 12], | 291 | pub eob_pt_1024_luma_class1: [u16; 12], |
| 278 | /// `eob_pt_1024_chroma`'s class-1 (`TX_CLASS_HORIZ`/`VERT`) sibling, see `eob_pt_16_luma_class1`. | 292 | /// `eob_pt_1024_chroma`'s class-1 (`TX_CLASS_HORIZ`/`VERT`) sibling, see `eob_pt_16_luma_class1`. |
| 279 | pub eob_pt_1024_chroma_class1: [u16; 12], | 293 | pub eob_pt_1024_chroma_class1: [u16; 12], |
| 294 | + /// The end-of-block group of a 32-position (4x8/8x4) luma transform | ||
| 295 | + /// (lane-tx4x8). | ||
| 296 | + pub eob_pt_32_luma: [u16; 7], | ||
| 297 | + /// `eob_pt_32_luma`'s class-1 sibling, see `eob_pt_16_luma_class1`. | ||
| 298 | + pub eob_pt_32_luma_class1: [u16; 7], | ||
| 280 | /// The end-of-block offset bit of a 16x16 luma transform. | 299 | /// The end-of-block offset bit of a 16x16 luma transform. |
| 281 | pub eob_extra_luma_16: [[u16; 3]; 9], | 300 | pub eob_extra_luma_16: [[u16; 3]; 9], |
| 282 | /// The same, for an 8x8 luma transform. | 301 | /// The same, for an 8x8 luma transform. |
| @@ -701,6 +720,8 @@ impl Cdfs { | |||
| 701 | reset1(&mut self.eob_pt_512_chroma_class1); | 720 | reset1(&mut self.eob_pt_512_chroma_class1); |
| 702 | reset1(&mut self.eob_pt_1024_luma_class1); | 721 | reset1(&mut self.eob_pt_1024_luma_class1); |
| 703 | reset1(&mut self.eob_pt_1024_chroma_class1); | 722 | reset1(&mut self.eob_pt_1024_chroma_class1); |
| 723 | + reset1(&mut self.eob_pt_32_luma); | ||
| 724 | + reset1(&mut self.eob_pt_32_luma_class1); | ||
| 704 | reset2(&mut self.eob_extra_luma_16); | 725 | reset2(&mut self.eob_extra_luma_16); |
| 705 | reset2(&mut self.eob_extra_luma_8); | 726 | reset2(&mut self.eob_extra_luma_8); |
| 706 | reset2(&mut self.eob_extra_luma_4); | 727 | reset2(&mut self.eob_extra_luma_4); |
| @@ -917,6 +938,20 @@ impl Cdfs { | |||
| 917 | cdf::EOB_PT_16_LUMA_CLASS1, | 938 | cdf::EOB_PT_16_LUMA_CLASS1, |
| 918 | cdf::EOB_PT_16_LUMA_CLASS1_Q3, | 939 | cdf::EOB_PT_16_LUMA_CLASS1_Q3, |
| 919 | ), | 940 | ), |
| 941 | + eob_pt_32_luma: pick( | ||
| 942 | + q_ctx, | ||
| 943 | + cdf::EOB_PT_32_LUMA_Q0, | ||
| 944 | + cdf::EOB_PT_32_LUMA_Q1, | ||
| 945 | + cdf::EOB_PT_32_LUMA, | ||
| 946 | + cdf::EOB_PT_32_LUMA_Q3, | ||
| 947 | + ), | ||
| 948 | + eob_pt_32_luma_class1: pick( | ||
| 949 | + q_ctx, | ||
| 950 | + cdf::EOB_PT_32_LUMA_CLASS1_Q0, | ||
| 951 | + cdf::EOB_PT_32_LUMA_CLASS1_Q1, | ||
| 952 | + cdf::EOB_PT_32_LUMA_CLASS1, | ||
| 953 | + cdf::EOB_PT_32_LUMA_CLASS1_Q3, | ||
| 954 | + ), | ||
| 920 | eob_pt_64_luma_class1: pick( | 955 | eob_pt_64_luma_class1: pick( |
| 921 | q_ctx, | 956 | q_ctx, |
| 922 | cdf::EOB_PT_64_LUMA_CLASS1_Q0, | 957 | cdf::EOB_PT_64_LUMA_CLASS1_Q0, |
| @@ -1652,6 +1687,30 @@ impl Cdfs { | |||
| 1652 | tx_type: None, | 1687 | tx_type: None, |
| 1653 | eob_pt_class1: Some(&mut self.eob_pt_128_chroma_class1), | 1688 | eob_pt_class1: Some(&mut self.eob_pt_128_chroma_class1), |
| 1654 | }, | 1689 | }, |
| 1690 | + TxbSet::LumaRect4x8 => TxbTables { | ||
| 1691 | + side: 8, | ||
| 1692 | + txb_skip: &mut self.txb_skip_luma_8, | ||
| 1693 | + eob_pt: &mut self.eob_pt_32_luma, | ||
| 1694 | + eob_extra: &mut self.eob_extra_luma_8, | ||
| 1695 | + base: &mut self.base_luma_8, | ||
| 1696 | + base_eob: &mut self.base_eob_luma_8, | ||
| 1697 | + br: &mut self.br_luma_8, | ||
| 1698 | + dc_sign: &mut self.dc_sign_luma, | ||
| 1699 | + tx_type: Some(self.intra_tx_type_4[mode].as_mut_slice()), | ||
| 1700 | + eob_pt_class1: Some(&mut self.eob_pt_32_luma_class1), | ||
| 1701 | + }, | ||
| 1702 | + TxbSet::LumaRect4x8Set1 => TxbTables { | ||
| 1703 | + side: 8, | ||
| 1704 | + txb_skip: &mut self.txb_skip_luma_8, | ||
| 1705 | + eob_pt: &mut self.eob_pt_32_luma, | ||
| 1706 | + eob_extra: &mut self.eob_extra_luma_8, | ||
| 1707 | + base: &mut self.base_luma_8, | ||
| 1708 | + base_eob: &mut self.base_eob_luma_8, | ||
| 1709 | + br: &mut self.br_luma_8, | ||
| 1710 | + dc_sign: &mut self.dc_sign_luma, | ||
| 1711 | + tx_type: Some(self.intra_tx_type_4_set1[mode].as_mut_slice()), | ||
| 1712 | + eob_pt_class1: Some(&mut self.eob_pt_32_luma_class1), | ||
| 1713 | + }, | ||
| 1655 | TxbSet::ChromaRect32x16 => TxbTables { | 1714 | TxbSet::ChromaRect32x16 => TxbTables { |
| 1656 | side: 32, | 1715 | side: 32, |
| 1657 | txb_skip: &mut self.txb_skip_chroma_32, | 1716 | txb_skip: &mut self.txb_skip_chroma_32, |
crates/ec-av1/src/decode.rsmodified+629 -86
| @@ -1713,6 +1713,54 @@ thread_local! { | |||
| 1713 | pub(crate) fn sub8_split_hits() -> usize { | 1713 | pub(crate) fn sub8_split_hits() -> usize { |
| 1714 | SUB8_SPLIT_HITS.with(|c| c.get()) | 1714 | SUB8_SPLIT_HITS.with(|c| c.get()) |
| 1715 | } | 1715 | } |
| 1716 | + | ||
| 1717 | +// How many 4x8 / 8x4 leaves (lane-tx4x8's `PARTITION_VERT`/`PARTITION_HORZ` | ||
| 1718 | +// of an 8x8 block) this thread's decode reconstructed with REAL coefficients | ||
| 1719 | +// -- a skipped leaf exercises the prediction and the mi bookkeeping but never | ||
| 1720 | +// the rect transform, the 32-position `eob_pt` or the rect scan, so the gate | ||
| 1721 | +// asserts on these two rather than a plain leaf count. | ||
| 1722 | +thread_local! { | ||
| 1723 | + static TX4X8_CODED_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) }; | ||
| 1724 | + static TX8X4_CODED_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) }; | ||
| 1725 | + /// Sub-8x8 rect leaves whose `tx_depth` symbol resolved to 1 -- the leaf's | ||
| 1726 | + /// two 4x4 transform units, predicted one after the other. A separate | ||
| 1727 | + /// counter from [`TX_DEPTH_HITS`] (which every square path also bumps) so | ||
| 1728 | + /// the gate can prove THIS path fired. | ||
| 1729 | + static RECT8_SPLIT_TX_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) }; | ||
| 1730 | + /// 16x8/8x16 intra strips whose prediction actually read past the block's | ||
| 1731 | + /// own width (above-right) or height (below-left) -- the samples | ||
| 1732 | + /// `Reach::of_rect` decides on, and the only ones a wrong `has_tr_*`/ | ||
| 1733 | + /// `has_bl_*` table row can corrupt (lane-tx4x8 r3). | ||
| 1734 | + static RECT_STRIP_REACH_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) }; | ||
| 1735 | + /// Every 16x8/8x16 intra strip predicted, reaching or not -- the | ||
| 1736 | + /// denominator [`RECT_STRIP_REACH_HITS`] is a fraction of. | ||
| 1737 | + static RECT_STRIP_PRED_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) }; | ||
| 1738 | +} | ||
| 1739 | + | ||
| 1740 | +/// Current value of [`RECT8_SPLIT_TX_HITS`]. | ||
| 1741 | +pub(crate) fn rect8_split_tx_hits() -> usize { | ||
| 1742 | + RECT8_SPLIT_TX_HITS.with(|c| c.get()) | ||
| 1743 | +} | ||
| 1744 | + | ||
| 1745 | +/// Current value of [`RECT_STRIP_PRED_HITS`]. | ||
| 1746 | +pub(crate) fn rect_strip_pred_hits() -> usize { | ||
| 1747 | + RECT_STRIP_PRED_HITS.with(|c| c.get()) | ||
| 1748 | +} | ||
| 1749 | + | ||
| 1750 | +/// Current value of [`RECT_STRIP_REACH_HITS`]. | ||
| 1751 | +pub(crate) fn rect_strip_reach_hits() -> usize { | ||
| 1752 | + RECT_STRIP_REACH_HITS.with(|c| c.get()) | ||
| 1753 | +} | ||
| 1754 | + | ||
| 1755 | +/// Current value of [`TX4X8_CODED_HITS`]. | ||
| 1756 | +pub(crate) fn tx4x8_coded_hits() -> usize { | ||
| 1757 | + TX4X8_CODED_HITS.with(|c| c.get()) | ||
| 1758 | +} | ||
| 1759 | + | ||
| 1760 | +/// Current value of [`TX8X4_CODED_HITS`]. | ||
| 1761 | +pub(crate) fn tx8x4_coded_hits() -> usize { | ||
| 1762 | + TX8X4_CODED_HITS.with(|c| c.get()) | ||
| 1763 | +} | ||
| 1716 | const SUB_MI: u32 = 4; | 1764 | const SUB_MI: u32 = 4; |
| 1717 | const MI: usize = 4; | 1765 | const MI: usize = 4; |
| 1718 | const SB: usize = 64; | 1766 | const SB: usize = 64; |
| @@ -1808,10 +1856,20 @@ fn default_scan(side: usize) -> Vec<u16> { | |||
| 1808 | /// `0..side*side` in our own indexing — and `Mcol_Scan` is that walk | 1856 | /// `0..side*side` in our own indexing — and `Mcol_Scan` is that walk |
| 1809 | /// transposed (column 0 down every row, then column 1, ...). | 1857 | /// transposed (column 0 down every row, then column 1, ...). |
| 1810 | fn class_scan_table(side: usize, class: TxClass) -> Vec<u16> { | 1858 | fn class_scan_table(side: usize, class: TxClass) -> Vec<u16> { |
| 1859 | + class_scan_table_wh(side, side, class) | ||
| 1860 | +} | ||
| 1861 | + | ||
| 1862 | +/// [`class_scan_table`] widened to `(w, h)` (lane-tx4x8). Checked against | ||
| 1863 | +/// libaom's own `mrow_scan_4x8`/`mcol_scan_4x8`/`mrow_scan_8x4`/ | ||
| 1864 | +/// `mcol_scan_8x4` (`scan.c`) converted out of their column-major encoding | ||
| 1865 | +/// by `(p % h) * w + p / h`, the same conversion [`SCAN_16X8`] was | ||
| 1866 | +/// transcribed with -- `mrow` is the plain row-major raster in our indexing | ||
| 1867 | +/// and `mcol` its transpose, at rect sizes exactly as at square ones. | ||
| 1868 | +fn class_scan_table_wh(w: usize, h: usize, class: TxClass) -> Vec<u16> { | ||
| 1811 | match class { | 1869 | match class { |
| 1812 | - TxClass::Vert => (0..(side * side) as u16).collect(), | 1870 | + TxClass::Vert => (0..(w * h) as u16).collect(), |
| 1813 | - TxClass::Horiz => (0..side) | 1871 | + TxClass::Horiz => (0..w) |
| 1814 | - .flat_map(|col| (0..side).map(move |row| (row * side + col) as u16)) | 1872 | + .flat_map(|col| (0..h).map(move |row| (row * w + col) as u16)) |
| 1815 | .collect(), | 1873 | .collect(), |
| 1816 | TxClass::TwoD => unreachable!("class_scan is only for V_DCT/H_DCT"), | 1874 | TxClass::TwoD => unreachable!("class_scan is only for V_DCT/H_DCT"), |
| 1817 | } | 1875 | } |
| @@ -2025,6 +2083,21 @@ const SCAN_16X32: [u16; 512] = [ | |||
| 2025 | 491, 506, 447, 462, 477, 492, 507, 463, 478, 493, 508, 479, 494, 509, 495, 510, 511, | 2083 | 491, 506, 447, 462, 477, 492, 507, 463, 478, 493, 508, 479, 494, 509, 495, 510, 511, |
| 2026 | ]; | 2084 | ]; |
| 2027 | 2085 | ||
| 2086 | +/// `Default_Scan_4x8` (libaom `scan.c`), this decoder's own row-major | ||
| 2087 | +/// transcription (see [`SCAN_32X16`]'s doc comment for the conversion, which | ||
| 2088 | +/// was re-verified this lane by regenerating [`SCAN_16X8`]/[`SCAN_8X16`] from | ||
| 2089 | +/// the same source). | ||
| 2090 | +const SCAN_4X8: [u16; 32] = [ | ||
| 2091 | + 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, | ||
| 2092 | + 23, 26, 29, 27, 30, 31, | ||
| 2093 | +]; | ||
| 2094 | + | ||
| 2095 | +/// `Default_Scan_8x4`, same source and conversion as [`SCAN_4X8`]. | ||
| 2096 | +const SCAN_8X4: [u16; 32] = [ | ||
| 2097 | + 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, | ||
| 2098 | + 29, 22, 15, 30, 23, 31, | ||
| 2099 | +]; | ||
| 2100 | + | ||
| 2028 | /// `Default_Scan_16x8`, this decoder's own row-major transcription (see | 2101 | /// `Default_Scan_16x8`, this decoder's own row-major transcription (see |
| 2029 | /// [`SCAN_32X16`]'s doc comment). | 2102 | /// [`SCAN_32X16`]'s doc comment). |
| 2030 | const SCAN_16X8: [u16; 128] = [ | 2103 | const SCAN_16X8: [u16; 128] = [ |
| @@ -2086,26 +2159,6 @@ const SCAN_8X32: [u16; 256] = [ | |||
| 2086 | 228, 235, 242, 249, 215, 222, 229, 236, 243, 250, 223, 230, 237, 244, 251, 231, 238, 245, 252, | 2159 | 228, 235, 242, 249, 215, 222, 229, 236, 243, 250, 223, 230, 237, 244, 251, 231, 238, 245, 252, |
| 2087 | 239, 246, 253, 247, 254, 255, | 2160 | 239, 246, 253, 247, 254, 255, |
| 2088 | ]; | 2161 | ]; |
| 2089 | -/// `Default_Scan_8x4` (lane-rectx, see [`SCAN_32X16`]'s doc comment for the | ||
| 2090 | -/// transposition rule this repo's `SCAN_WxH` names follow): this repo's | ||
| 2091 | -/// `(w=8, h=4)` reads libaom's own `default_scan_4x8` verbatim -- the same | ||
| 2092 | -/// axis swap [`SCAN_16X8`]/[`SCAN_8X16`] already carry one size class up | ||
| 2093 | -/// (repo `SCAN_16X8` == libaom `default_scan_8x16`, repo `SCAN_8X16` == | ||
| 2094 | -/// libaom `default_scan_16x8`), checked against `scan.c` before landing | ||
| 2095 | -/// rather than re-deriving the zigzag formula. | ||
| 2096 | -const SCAN_8X4: [u16; 32] = [ | ||
| 2097 | - 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, | ||
| 2098 | - 29, 22, 15, 30, 23, 31, | ||
| 2099 | -]; | ||
| 2100 | - | ||
| 2101 | -/// `Default_Scan_4x8` (lane-rectx): this repo's `(w=4, h=8)` reads libaom's | ||
| 2102 | -/// own `default_scan_8x4` verbatim, the same transposition [`SCAN_8X4`]'s | ||
| 2103 | -/// doc comment explains. | ||
| 2104 | -const SCAN_4X8: [u16; 32] = [ | ||
| 2105 | - 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, | ||
| 2106 | - 23, 26, 29, 27, 30, 31, | ||
| 2107 | -]; | ||
| 2108 | - | ||
| 2109 | /// `Default_Scan_16x4`, this decoder's own row-major transcription of | 2162 | /// `Default_Scan_16x4`, this decoder's own row-major transcription of |
| 2110 | /// libaom's column-major `default_scan_16x4` (`scan.c:66`) -- the CHROMA | 2163 | /// libaom's column-major `default_scan_16x4` (`scan.c:66`) -- the CHROMA |
| 2111 | /// plane of a 32x8 `PARTITION_HORZ_4` strip at the 32x32 level | 2164 | /// plane of a 32x8 `PARTITION_HORZ_4` strip at the 32x32 level |
| @@ -2144,30 +2197,63 @@ fn neighbour_rect(grid: &[i32], w: usize, h: usize, row: usize, col: usize) -> i | |||
| 2144 | /// same [`cdf::NZ_MAP_CTX_OFFSET_32`] table when `w == h`. Never called for | 2197 | /// same [`cdf::NZ_MAP_CTX_OFFSET_32`] table when `w == h`. Never called for |
| 2145 | /// `V_DCT`/`H_DCT` -- geometrically impossible at the two size pairs | 2198 | /// `V_DCT`/`H_DCT` -- geometrically impossible at the two size pairs |
| 2146 | /// [`decode_block_rect`] codes (see that function's own doc comment). | 2199 | /// [`decode_block_rect`] codes (see that function's own doc comment). |
| 2147 | -fn base_ctx_rect(grid: &[i32], w: usize, h: usize, row: usize, col: usize) -> usize { | 2200 | +fn base_ctx_rect( |
| 2148 | - if row == 0 && col == 0 { | 2201 | + grid: &[i32], |
| 2202 | + w: usize, | ||
| 2203 | + h: usize, | ||
| 2204 | + row: usize, | ||
| 2205 | + col: usize, | ||
| 2206 | + class: TxClass, | ||
| 2207 | +) -> usize { | ||
| 2208 | + // Same `(tx_class | coeff_idx) == 0` guard [`base_ctx`] documents: only | ||
| 2209 | + // the 2D class short-circuits the DC position. | ||
| 2210 | + if class == TxClass::TwoD && row == 0 && col == 0 { | ||
| 2149 | return 0; | 2211 | return 0; |
| 2150 | } | 2212 | } |
| 2151 | - const OFFSETS: [(usize, usize); 5] = [(1, 0), (0, 1), (1, 1), (2, 0), (0, 2)]; | 2213 | + let offsets: [(usize, usize); 5] = match class { |
| 2152 | - let mag: i32 = OFFSETS | 2214 | + TxClass::TwoD => [(1, 0), (0, 1), (1, 1), (2, 0), (0, 2)], |
| 2215 | + TxClass::Horiz => [(1, 0), (0, 1), (0, 2), (0, 3), (0, 4)], | ||
| 2216 | + TxClass::Vert => [(1, 0), (0, 1), (2, 0), (3, 0), (4, 0)], | ||
| 2217 | + }; | ||
| 2218 | + let mag: i32 = offsets | ||
| 2153 | .iter() | 2219 | .iter() |
| 2154 | .map(|&(dr, dc)| neighbour_rect(grid, w, h, row + dr, col + dc).abs().min(3)) | 2220 | .map(|&(dr, dc)| neighbour_rect(grid, w, h, row + dr, col + dc).abs().min(3)) |
| 2155 | .sum(); | 2221 | .sum(); |
| 2156 | let ctx = ((mag + 1) >> 1).min(4) as usize; | 2222 | let ctx = ((mag + 1) >> 1).min(4) as usize; |
| 2157 | - if w < h && row < 2 { | 2223 | + match class { |
| 2158 | - return ctx + 11; | 2224 | + TxClass::TwoD => { |
| 2159 | - } | 2225 | + if w < h && row < 2 { |
| 2160 | - if w > h && col < 2 { | 2226 | + return ctx + 11; |
| 2161 | - return ctx + 16; | 2227 | + } |
| 2228 | + if w > h && col < 2 { | ||
| 2229 | + return ctx + 16; | ||
| 2230 | + } | ||
| 2231 | + ctx + cdf::NZ_MAP_CTX_OFFSET_32[row.min(4)][col.min(4)] as usize | ||
| 2232 | + } | ||
| 2233 | + // Shape-independent in libaom too (`get_nz_map_ctx_from_stats`'s | ||
| 2234 | + // `TX_CLASS_HORIZ`/`VERT` arms index `nz_map_ctx_offset_1d` by the | ||
| 2235 | + // position along one axis only). | ||
| 2236 | + TxClass::Horiz => ctx + nz_map_ctx_offset_1d(col.min(31)), | ||
| 2237 | + TxClass::Vert => ctx + nz_map_ctx_offset_1d(row.min(31)), | ||
| 2162 | } | 2238 | } |
| 2163 | - ctx + cdf::NZ_MAP_CTX_OFFSET_32[row.min(4)][col.min(4)] as usize | ||
| 2164 | } | 2239 | } |
| 2165 | 2240 | ||
| 2166 | /// [`br_ctx`]'s `TxClass::TwoD` arm widened to `(w, h)` (lane-rectwire): the | 2241 | /// [`br_ctx`]'s `TxClass::TwoD` arm widened to `(w, h)` (lane-rectwire): the |
| 2167 | /// neighbour-offset math itself is shape-independent, only the boundary | 2242 | /// neighbour-offset math itself is shape-independent, only the boundary |
| 2168 | /// clamp needs the real bound in each axis. | 2243 | /// clamp needs the real bound in each axis. |
| 2169 | -fn br_ctx_rect(grid: &[i32], w: usize, h: usize, row: usize, col: usize) -> usize { | 2244 | +fn br_ctx_rect( |
| 2170 | - let extra = neighbour_rect(grid, w, h, row + 1, col + 1).abs(); | 2245 | + grid: &[i32], |
| 2246 | + w: usize, | ||
| 2247 | + h: usize, | ||
| 2248 | + row: usize, | ||
| 2249 | + col: usize, | ||
| 2250 | + class: TxClass, | ||
| 2251 | +) -> usize { | ||
| 2252 | + let extra = match class { | ||
| 2253 | + TxClass::TwoD => neighbour_rect(grid, w, h, row + 1, col + 1).abs(), | ||
| 2254 | + TxClass::Horiz => neighbour_rect(grid, w, h, row, col + 2).abs(), | ||
| 2255 | + TxClass::Vert => neighbour_rect(grid, w, h, row + 2, col).abs(), | ||
| 2256 | + }; | ||
| 2171 | let mag = neighbour_rect(grid, w, h, row + 1, col).abs() | 2257 | let mag = neighbour_rect(grid, w, h, row + 1, col).abs() |
| 2172 | + neighbour_rect(grid, w, h, row, col + 1).abs() | 2258 | + neighbour_rect(grid, w, h, row, col + 1).abs() |
| 2173 | + extra; | 2259 | + extra; |
| @@ -2175,7 +2261,12 @@ fn br_ctx_rect(grid: &[i32], w: usize, h: usize, row: usize, col: usize) -> usiz | |||
| 2175 | if row == 0 && col == 0 { | 2261 | if row == 0 && col == 0 { |
| 2176 | return mag; | 2262 | return mag; |
| 2177 | } | 2263 | } |
| 2178 | - if row < 2 && col < 2 { mag + 7 } else { mag + 14 } | 2264 | + let near_origin = match class { |
| 2265 | + TxClass::TwoD => row < 2 && col < 2, | ||
| 2266 | + TxClass::Horiz => col == 0, | ||
| 2267 | + TxClass::Vert => row == 0, | ||
| 2268 | + }; | ||
| 2269 | + if near_origin { mag + 7 } else { mag + 14 } | ||
| 2179 | } | 2270 | } |
| 2180 | 2271 | ||
| 2181 | fn dc_vote(dc: Option<bool>) -> i32 { | 2272 | fn dc_vote(dc: Option<bool>) -> i32 { |
| @@ -2530,30 +2621,28 @@ fn read_coeffs_rect( | |||
| 2530 | sign_ctx: usize, | 2621 | sign_ctx: usize, |
| 2531 | default_tx_type: TxType, | 2622 | default_tx_type: TxType, |
| 2532 | ) -> Result<(Vec<i32>, TxType)> { | 2623 | ) -> Result<(Vec<i32>, TxType)> { |
| 2533 | - let ec_trace_coeff = std::env::var_os("EC_TRACE_COEFF").is_some(); | 2624 | + let rect_trace = std::env::var_os("EC_TRACE_COEFF").is_some(); |
| 2534 | let mut grid = vec![0i32; w * h]; | 2625 | let mut grid = vec![0i32; w * h]; |
| 2535 | let entry_rng = dec.debug_state().0; | 2626 | let entry_rng = dec.debug_state().0; |
| 2536 | let all_zero = dec.symbol(&mut coding.txb_skip[skip_ctx]) == 1; | 2627 | let all_zero = dec.symbol(&mut coding.txb_skip[skip_ctx]) == 1; |
| 2537 | - if ec_trace_coeff { | 2628 | + if rect_trace { |
| 2538 | - let (rng, _) = dec.debug_state(); | ||
| 2539 | eprintln!( | 2629 | eprintln!( |
| 2540 | - "EC_COEFF_STEP tag=all_zero ctx={skip_ctx} all_zero={} rng={rng}", | 2630 | + "EC_COEFF_STEP tag=all_zero plane=0 ctx={skip_ctx} all_zero={} rng={}", |
| 2541 | - all_zero as i32 | 2631 | + all_zero as i32, |
| 2632 | + dec.debug_state().0 | ||
| 2542 | ); | 2633 | ); |
| 2543 | } | 2634 | } |
| 2544 | if all_zero { | 2635 | if all_zero { |
| 2545 | return Ok((grid, TxType::DctDct)); | 2636 | return Ok((grid, TxType::DctDct)); |
| 2546 | } | 2637 | } |
| 2547 | - let trace = std::env::var_os("EC_TRACE_COEFF").is_some(); | 2638 | + // lane-tx4x8: a 4x8/8x4 luma TU DOES carry a `tx_type` symbol (its set is |
| 2548 | - if trace { | 2639 | + // `EXT_TX_SET_DTT4_IDTX(_1DDCT)`, `tx_size_sqr_up == TX_8X8`), including |
| 2549 | - let (rng, _) = dec.debug_state(); | 2640 | + // the `V_DCT`/`H_DCT` members whose 1D tx class needs its own scan and |
| 2550 | - eprintln!("EC_COEFF_STEP tag=all_zero ctx={skip_ctx} all_zero=0 rng={rng}"); | 2641 | + // context offsets -- both of which now have rect forms |
| 2551 | - } | 2642 | + // ([`class_scan_table_wh`], [`base_ctx_rect`]/[`br_ctx_rect`]'s `class`). |
| 2643 | + // The rect sets that carry no symbol at all still pass `None` here. | ||
| 2552 | let mut tx_type = default_tx_type; | 2644 | let mut tx_type = default_tx_type; |
| 2553 | if let Some(tx_type_cdf) = coding.tx_type.as_deref_mut() { | 2645 | if let Some(tx_type_cdf) = coding.tx_type.as_deref_mut() { |
| 2554 | - // Mirrors [`read_coeffs`]'s own `tx_type` read: the CDF row's width | ||
| 2555 | - // names its set (lane-rectx, `TxbSet::LumaRect16x8` -- the one rect | ||
| 2556 | - // set here that carries a `tx_type` symbol at all). | ||
| 2557 | let len = tx_type_cdf.len(); | 2646 | let len = tx_type_cdf.len(); |
| 2558 | let t = dec.symbol(tx_type_cdf); | 2647 | let t = dec.symbol(tx_type_cdf); |
| 2559 | tx_type = match len { | 2648 | tx_type = match len { |
| @@ -2563,21 +2652,25 @@ fn read_coeffs_rect( | |||
| 2563 | _ => TxType::from_symbol(t), | 2652 | _ => TxType::from_symbol(t), |
| 2564 | } | 2653 | } |
| 2565 | .ok_or_else(|| unsupported(format!("a tx_type symbol outside its CDF's own set: {t}")))?; | 2654 | .ok_or_else(|| unsupported(format!("a tx_type symbol outside its CDF's own set: {t}")))?; |
| 2655 | + if rect_trace { | ||
| 2656 | + eprintln!("EC_COEFF_STEP tag=tx_type plane=0 rng={}", dec.debug_state().0); | ||
| 2657 | + } | ||
| 2566 | } | 2658 | } |
| 2567 | - if TxClass::of(tx_type) != TxClass::TwoD { | 2659 | + let class = TxClass::of(tx_type); |
| 2568 | - return Err(unsupported( | 2660 | + if class != TxClass::TwoD { |
| 2569 | - "a non-2D tx class on a rectangular transform (never expected at this size)", | 2661 | + TX_CLASS1_HITS.with(|c| c.set(c.get() + 1)); |
| 2570 | - )); | ||
| 2571 | - } | ||
| 2572 | - if trace { | ||
| 2573 | - let (rng, _) = dec.debug_state(); | ||
| 2574 | - eprintln!("EC_COEFF_STEP tag=tx_type rng={rng}"); | ||
| 2575 | } | 2662 | } |
| 2576 | - let eob = read_eob(dec, coding, TxClass::TwoD); | 2663 | + let eob = read_eob(dec, coding, class); |
| 2577 | - if ec_trace_coeff { | 2664 | + if rect_trace { |
| 2578 | - let (rng, _) = dec.debug_state(); | 2665 | + eprintln!("EC_COEFF_STEP tag=eob eob={eob} rng={}", dec.debug_state().0); |
| 2579 | - eprintln!("EC_COEFF_STEP tag=eob eob={eob} rng={rng}"); | ||
| 2580 | } | 2666 | } |
| 2667 | + let class_scan; | ||
| 2668 | + let scan: &[u16] = if class == TxClass::TwoD { | ||
| 2669 | + scan | ||
| 2670 | + } else { | ||
| 2671 | + class_scan = class_scan_table_wh(w, h, class); | ||
| 2672 | + &class_scan | ||
| 2673 | + }; | ||
| 2581 | let mut levels = vec![0i32; w * h]; | 2674 | let mut levels = vec![0i32; w * h]; |
| 2582 | for scan_idx in (0..eob).rev() { | 2675 | for scan_idx in (0..eob).rev() { |
| 2583 | let pos = scan[scan_idx] as usize; | 2676 | let pos = scan[scan_idx] as usize; |
| @@ -2586,36 +2679,35 @@ fn read_coeffs_rect( | |||
| 2586 | let apos = col * h + row; | 2679 | let apos = col * h + row; |
| 2587 | let level = if scan_idx == eob - 1 { | 2680 | let level = if scan_idx == eob - 1 { |
| 2588 | let ctx = eob_coeff_ctx(scan_idx, w * h); | 2681 | let ctx = eob_coeff_ctx(scan_idx, w * h); |
| 2589 | - let l = dec.symbol(&mut coding.base_eob[ctx]) as i32 + 1; | 2682 | + let v = dec.symbol(&mut coding.base_eob[ctx]) as i32 + 1; |
| 2590 | - if ec_trace_coeff { | 2683 | + if rect_trace { |
| 2591 | - let (rng, _) = dec.debug_state(); | ||
| 2592 | eprintln!( | 2684 | eprintln!( |
| 2593 | - "EC_COEFF_STEP tag=base_eob c={scan_idx} pos={pos} ctx={ctx} level={} rng={rng}", | 2685 | + "EC_COEFF_STEP tag=base_eob c={scan_idx} pos={pos} ctx={ctx} level={v} rng={}", |
| 2594 | - l - 1 | 2686 | + dec.debug_state().0 |
| 2595 | ); | 2687 | ); |
| 2596 | } | 2688 | } |
| 2597 | - l | 2689 | + v |
| 2598 | } else { | 2690 | } else { |
| 2599 | - let ctx = base_ctx_rect(&levels, w, h, row, col); | 2691 | + let ctx = base_ctx_rect(&levels, w, h, row, col, class); |
| 2600 | - let l = dec.symbol(&mut coding.base[ctx]) as i32; | 2692 | + let v = dec.symbol(&mut coding.base[ctx]) as i32; |
| 2601 | - if ec_trace_coeff { | 2693 | + if rect_trace { |
| 2602 | - let (rng, _) = dec.debug_state(); | ||
| 2603 | eprintln!( | 2694 | eprintln!( |
| 2604 | - "EC_COEFF_STEP tag=base c={scan_idx} pos={pos} ctx={ctx} level={l} rng={rng}" | 2695 | + "EC_COEFF_STEP tag=base c={scan_idx} pos={pos} ctx={ctx} level={v} rng={}", |
| 2696 | + dec.debug_state().0 | ||
| 2605 | ); | 2697 | ); |
| 2606 | } | 2698 | } |
| 2607 | - l | 2699 | + v |
| 2608 | }; | 2700 | }; |
| 2609 | let level = if level > NUM_BASE_LEVELS { | 2701 | let level = if level > NUM_BASE_LEVELS { |
| 2610 | - let ctx = br_ctx_rect(&levels, w, h, row, col); | 2702 | + let ctx = br_ctx_rect(&levels, w, h, row, col, class); |
| 2611 | let mut level = level; | 2703 | let mut level = level; |
| 2612 | let mut sent = 0; | 2704 | let mut sent = 0; |
| 2613 | loop { | 2705 | loop { |
| 2614 | let k = dec.symbol(&mut coding.br[ctx]) as i32; | 2706 | let k = dec.symbol(&mut coding.br[ctx]) as i32; |
| 2615 | - if ec_trace_coeff { | 2707 | + if rect_trace { |
| 2616 | - let (rng, _) = dec.debug_state(); | ||
| 2617 | eprintln!( | 2708 | eprintln!( |
| 2618 | - "EC_COEFF_STEP tag=br c={scan_idx} pos={pos} ctx={ctx} k={k} rng={rng}" | 2709 | + "EC_COEFF_STEP tag=br c={scan_idx} pos={pos} ctx={ctx} k={k} rng={}", |
| 2710 | + dec.debug_state().0 | ||
| 2619 | ); | 2711 | ); |
| 2620 | } | 2712 | } |
| 2621 | level += k; | 2713 | level += k; |
| @@ -2629,12 +2721,12 @@ fn read_coeffs_rect( | |||
| 2629 | level | 2721 | level |
| 2630 | }; | 2722 | }; |
| 2631 | levels[pos] = level; | 2723 | levels[pos] = level; |
| 2632 | - if trace { | 2724 | + if rect_trace { |
| 2633 | let (rng, _) = dec.debug_state(); | 2725 | let (rng, _) = dec.debug_state(); |
| 2634 | eprintln!("EC_COEFF_STEP tag=base c={scan_idx} pos={pos} level={level} rng={rng}"); | 2726 | eprintln!("EC_COEFF_STEP tag=base c={scan_idx} pos={pos} level={level} rng={rng}"); |
| 2635 | } | 2727 | } |
| 2636 | } | 2728 | } |
| 2637 | - if ec_trace_coeff { | 2729 | + if rect_trace { |
| 2638 | let (rng, _) = dec.debug_state(); | 2730 | let (rng, _) = dec.debug_state(); |
| 2639 | eprintln!("EC_COEFF_STEP tag=after_bases rng={rng}"); | 2731 | eprintln!("EC_COEFF_STEP tag=after_bases rng={rng}"); |
| 2640 | } | 2732 | } |
| @@ -2648,7 +2740,7 @@ fn read_coeffs_rect( | |||
| 2648 | } else { | 2740 | } else { |
| 2649 | dec.literal(1) == 1 | 2741 | dec.literal(1) == 1 |
| 2650 | }; | 2742 | }; |
| 2651 | - if trace { | 2743 | + if rect_trace { |
| 2652 | let (rng, _) = dec.debug_state(); | 2744 | let (rng, _) = dec.debug_state(); |
| 2653 | eprintln!("EC_COEFF_STEP tag=sign_rect pos={pos} sign={} rng={rng}", u8::from(negative)); | 2745 | eprintln!("EC_COEFF_STEP tag=sign_rect pos={pos} sign={} rng={rng}", u8::from(negative)); |
| 2654 | } | 2746 | } |
| @@ -6430,6 +6522,12 @@ impl PlaneBuf { | |||
| 6430 | }); | 6522 | }); |
| 6431 | let corner = | 6523 | let corner = |
| 6432 | (x > self.tile_x0 && y > self.tile_y0).then(|| self.data[(y - 1) * self.width + x - 1]); | 6524 | (x > self.tile_x0 && y > self.tile_y0).then(|| self.data[(y - 1) * self.width + x - 1]); |
| 6525 | + if matches!((bw, bh), (16, 8) | (8, 16)) { | ||
| 6526 | + RECT_STRIP_PRED_HITS.with(|h| h.set(h.get() + 1)); | ||
| 6527 | + if across > own_across || down > own_down { | ||
| 6528 | + RECT_STRIP_REACH_HITS.with(|h| h.set(h.get() + 1)); | ||
| 6529 | + } | ||
| 6530 | + } | ||
| 6433 | (above, left, corner) | 6531 | (above, left, corner) |
| 6434 | } | 6532 | } |
| 6435 | 6533 | ||
| @@ -7803,6 +7901,327 @@ fn decode_leaf_split4( | |||
| 7803 | Ok((leaf_modes[2], leaf_modes[1])) | 7901 | Ok((leaf_modes[2], leaf_modes[1])) |
| 7804 | } | 7902 | } |
| 7805 | 7903 | ||
| 7904 | +/// Decodes a `PARTITION_VERT`/`PARTITION_HORZ` of one 8x8 block into two | ||
| 7905 | +/// `BLOCK_4X8`/`BLOCK_8X4` leaves (lane-tx4x8), the last partition shape | ||
| 7906 | +/// below 8x8 this decoder refused. Mirrors [`decode_leaf_split4`] element for | ||
| 7907 | +/// element -- same mode reads ([`read_intra_mode_sub8`]: no angle delta, no | ||
| 7908 | +/// tx-depth symbol below 8x8), same "chroma once, on the last sub-block, at | ||
| 7909 | +/// the whole 8x8 group's 4x4 unit" rule (`is_chroma_reference` is false for | ||
| 7910 | +/// every sub-block one mi wide or high but the last) -- differing only where | ||
| 7911 | +/// the shape does: | ||
| 7912 | +/// | ||
| 7913 | +/// * the transform is a true `TX_4X8`/`TX_8X4` | ||
| 7914 | +/// ([`dequant_and_inverse_typed_wh`], whose `abs(rect_type) == 1` scale and | ||
| 7915 | +/// `av1_inv_txfm_shift_ls` row already cover this size pair); | ||
| 7916 | +/// * the CDF set is [`TxbSet::LumaRect4x8`] (`get_txsize_entropy_ctx` squares | ||
| 7917 | +/// up to `TX_8X8`) with a 32-position `eob_pt` and the `TX_4X4` `tx_type` | ||
| 7918 | +/// row -- see that variant's doc comment; | ||
| 7919 | +/// * the scan is [`SCAN_4X8`]/[`SCAN_8X4`], or their `mrow`/`mcol` siblings | ||
| 7920 | +/// ([`class_scan_table_wh`]) when the coded `tx_type` is `V_DCT`/`H_DCT`; | ||
| 7921 | +/// * `Reach` comes from libaom's own `has_tr_4x8`/`has_bl_8x4` rows | ||
| 7922 | +/// ([`Reach::of_rect`]); | ||
| 7923 | +/// * `update_partition_context` writes `partition_context_lookup[BLOCK_4X8]` | ||
| 7924 | +/// = `{31, 30}` (width 4 above, height 8 left), not the `{31, 31}` a | ||
| 7925 | +/// `BLOCK_4X4` split writes. | ||
| 7926 | +/// | ||
| 7927 | +/// Filter intra on one of these leaves is refused by name: `predict_filter_intra` | ||
| 7928 | +/// is square-only in this decoder (the same refusal the 16x16-level rect | ||
| 7929 | +/// strips already carry). | ||
| 7930 | +#[allow(clippy::too_many_arguments)] | ||
| 7931 | +fn decode_leaf_rect8( | ||
| 7932 | + dec: &mut SymbolDecoder, | ||
| 7933 | + cdfs: &mut Cdfs, | ||
| 7934 | + neighbours: &mut Neighbours, | ||
| 7935 | + outer_at: (usize, usize), | ||
| 7936 | + leaf_mi: (usize, usize), | ||
| 7937 | + vert: bool, | ||
| 7938 | + scan4: &[u16], | ||
| 7939 | + y: &mut PlaneBuf, | ||
| 7940 | + u: &mut PlaneBuf, | ||
| 7941 | + v: &mut PlaneBuf, | ||
| 7942 | + base_q_idx: u8, | ||
| 7943 | + enable_filter_intra: bool, | ||
| 7944 | + allow_intrabc: bool, | ||
| 7945 | + tx_select: bool, | ||
| 7946 | + reduced_tx_set: bool, | ||
| 7947 | +) -> Result<(usize, usize)> { | ||
| 7948 | + let (r, c) = outer_at; | ||
| 7949 | + let above_mode = neighbours.above_mode[c]; | ||
| 7950 | + let left_mode = neighbours.left_mode[r]; | ||
| 7951 | + let smooth_neighbor_uv = neighbours.smooth_uv_neighbour(leaf_mi.0, leaf_mi.1, r, c); | ||
| 7952 | + let (bw, bh) = if vert { (4, 8) } else { (8, 4) }; | ||
| 7953 | + let (w_mi, h_mi) = (bw / MI, bh / MI); | ||
| 7954 | + let scan: &[u16] = if vert { &SCAN_4X8 } else { &SCAN_8X4 }; | ||
| 7955 | + let mut leaf_modes = [0usize; 2]; | ||
| 7956 | + let mut leaf_skips = [false; 2]; | ||
| 7957 | + let mut last_uv: Option<(usize, i32, Option<(i32, i32)>)> = None; | ||
| 7958 | + for i in 0..2usize { | ||
| 7959 | + let lmi = if vert { | ||
| 7960 | + (leaf_mi.0, leaf_mi.1 + i) | ||
| 7961 | + } else { | ||
| 7962 | + (leaf_mi.0 + i, leaf_mi.1) | ||
| 7963 | + }; | ||
| 7964 | + // Inside the pair the sibling is the neighbour on the split axis; | ||
| 7965 | + // outside it the mi-granular map, else the coarse 16x16 slot. | ||
| 7966 | + let leaf_above = if !vert && i == 1 { | ||
| 7967 | + leaf_modes[0] | ||
| 7968 | + } else { | ||
| 7969 | + neighbours.mode_above_mi(lmi.0, lmi.1).unwrap_or(above_mode) | ||
| 7970 | + }; | ||
| 7971 | + let leaf_left = if vert && i == 1 { | ||
| 7972 | + leaf_modes[0] | ||
| 7973 | + } else { | ||
| 7974 | + neighbours.mode_left_mi(lmi.0, lmi.1).unwrap_or(left_mode) | ||
| 7975 | + }; | ||
| 7976 | + let has_chroma = i == 1; | ||
| 7977 | + let skip_ctx = neighbours.skip_txfm_ctx(lmi.0, lmi.1); | ||
| 7978 | + let (skip, mode, angle_delta_y, chroma, filter_intra) = read_intra_mode_sub8( | ||
| 7979 | + dec, cdfs, leaf_above, leaf_left, has_chroma, enable_filter_intra, skip_ctx, | ||
| 7980 | + allow_intrabc, lmi.0, lmi.1, | ||
| 7981 | + )?; | ||
| 7982 | + if filter_intra.is_some() { | ||
| 7983 | + return Err(unsupported( | ||
| 7984 | + "filter intra on a HORZ/VERT strip (this decoder predicts square-only)", | ||
| 7985 | + )); | ||
| 7986 | + } | ||
| 7987 | + // `TxMode::Select`'s `tx_depth` (spec 5.11.16) exists at a 4x8/8x4 | ||
| 7988 | + // leaf too, and is read for every intra block, skipped or not. Its | ||
| 7989 | + // category is libaom's `bsize_to_tx_size_cat(BLOCK_4X8) == 0` -- | ||
| 7990 | + // `sub_tx_size_map[TX_4X8] == TX_4X4` is a single step, so it is the | ||
| 7991 | + // same 2-symbol `tx_size_cat0` an 8x8 uses, not the 3-symbol | ||
| 7992 | + // `tx_size_cat2` the 32x16 strips read -- with the rect context | ||
| 7993 | + // (`get_tx_size_context`'s `max_tx_wide`/`max_tx_high` = bw/bh). | ||
| 7994 | + // Missing this read consumed one symbol fewer than the encoder wrote | ||
| 7995 | + // and desynced the tile at the very first rect leaf (class | ||
| 7996 | + // `symbol-consumption-gap`). | ||
| 7997 | + let depth = if tx_select { | ||
| 7998 | + let ctx = tx_size_context_rect(neighbours, lmi, bw, bh); | ||
| 7999 | + dec.symbol(&mut cdfs.tx_size_cat0[ctx]) | ||
| 8000 | + } else { | ||
| 8001 | + 0 | ||
| 8002 | + }; | ||
| 8003 | + if depth != 0 { | ||
| 8004 | + TX_DEPTH_HITS.with(|c| c.set(c.get() + 1)); | ||
| 8005 | + RECT8_SPLIT_TX_HITS.with(|c| c.set(c.get() + 1)); | ||
| 8006 | + } | ||
| 8007 | + leaf_modes[i] = mode; | ||
| 8008 | + leaf_skips[i] = skip; | ||
| 8009 | + neighbours.record_mode_mi(lmi.0, lmi.1, w_mi, h_mi, mode); | ||
| 8010 | + let smooth_neighbor = is_smooth_mode(leaf_above) || is_smooth_mode(leaf_left); | ||
| 8011 | + if smooth_neighbor { | ||
| 8012 | + SMOOTH_LUMA_HITS.with(|c| c.set(c.get() + 1)); | ||
| 8013 | + } | ||
| 8014 | + let (px, py) = (lmi.1 * MI, lmi.0 * MI); | ||
| 8015 | + let reach = Reach::of_rect(bw, bh, px, py, y.width, y.height); | ||
| 8016 | + // `sub_tx_size_map[TX_4X8] == TX_4X4`: depth 1 splits the leaf into | ||
| 8017 | + // two 4x4 transform units along its long axis, each predicted from | ||
| 8018 | + // the previous unit's reconstruction and reading its own `txb_skip` | ||
| 8019 | + // context -- `decode_leaf8`'s own depth-1 loop, two units instead of | ||
| 8020 | + // four. The per-TU path writes its own neighbour state, so the | ||
| 8021 | + // block-level write below is skipped for it. | ||
| 8022 | + let split = depth != 0; | ||
| 8023 | + if split { | ||
| 8024 | + let mut done = 0usize; | ||
| 8025 | + for tu in 0..2usize { | ||
| 8026 | + let tu_mi = if vert { | ||
| 8027 | + (lmi.0 + tu, lmi.1) | ||
| 8028 | + } else { | ||
| 8029 | + (lmi.0, lmi.1 + tu) | ||
| 8030 | + }; | ||
| 8031 | + let (tu_px, tu_py) = (tu_mi.1 * MI, tu_mi.0 * MI); | ||
| 8032 | + let tu_around = neighbours.around_mi(tu_mi, 4)[0]; | ||
| 8033 | + let tu_reach = Reach::of(4, tu_px, tu_py, y.width, y.height); | ||
| 8034 | + let tu_skip_ctx = neighbours.luma_skip_ctx(tu_mi, 1); | ||
| 8035 | + if skip { | ||
| 8036 | + // A skipped leaf still predicts per transform unit: the | ||
| 8037 | + // second 4x4 takes its above/left edge from the first | ||
| 8038 | + // one's reconstruction, which is NOT what a single 4x8 | ||
| 8039 | + // prediction of the same mode produces. | ||
| 8040 | + let zeros = vec![0i32; 16]; | ||
| 8041 | + y.reconstruct( | ||
| 8042 | + tu_px, tu_py, 4, mode, angle_delta_y, tu_reach, &zeros, None, None, | ||
| 8043 | + smooth_neighbor, | ||
| 8044 | + ); | ||
| 8045 | + neighbours.record_mi_luma(tu_mi, 4, &zeros); | ||
| 8046 | + continue; | ||
| 8047 | + } | ||
| 8048 | + let tu_grid = read_plane( | ||
| 8049 | + dec, | ||
| 8050 | + cdfs, | ||
| 8051 | + if reduced_tx_set { | ||
| 8052 | + TxbSet::Luma4 | ||
| 8053 | + } else { | ||
| 8054 | + TxbSet::Luma4Set1 | ||
| 8055 | + }, | ||
| 8056 | + scan4, | ||
| 8057 | + 0, | ||
| 8058 | + tu_around, | ||
| 8059 | + mode, | ||
| 8060 | + mode, | ||
| 8061 | + angle_delta_y, | ||
| 8062 | + tu_reach, | ||
| 8063 | + y, | ||
| 8064 | + tu_px, | ||
| 8065 | + tu_py, | ||
| 8066 | + 4, | ||
| 8067 | + TX4, | ||
| 8068 | + base_q_idx, | ||
| 8069 | + None, | ||
| 8070 | + None, | ||
| 8071 | + Some(tu_skip_ctx), | ||
| 8072 | + smooth_neighbor, | ||
| 8073 | + )?; | ||
| 8074 | + if tu_grid.iter().any(|&l| l != 0) { | ||
| 8075 | + done += 1; | ||
| 8076 | + } | ||
| 8077 | + neighbours.record_mi_luma(tu_mi, 4, &tu_grid); | ||
| 8078 | + } | ||
| 8079 | + if done > 0 { | ||
| 8080 | + if vert { | ||
| 8081 | + TX4X8_CODED_HITS.with(|h| h.set(h.get() + 1)); | ||
| 8082 | + } else { | ||
| 8083 | + TX8X4_CODED_HITS.with(|h| h.set(h.get() + 1)); | ||
| 8084 | + } | ||
| 8085 | + } | ||
| 8086 | + neighbours.fill_skip_grid_rect(lmi, w_mi, h_mi, skip); | ||
| 8087 | + neighbours.fill_lf_grid_rect(lmi, w_mi, h_mi, 4, 4, 0); | ||
| 8088 | + if has_chroma { | ||
| 8089 | + last_uv = chroma; | ||
| 8090 | + } | ||
| 8091 | + continue; | ||
| 8092 | + } | ||
| 8093 | + let grid = if skip { | ||
| 8094 | + let zeros = vec![0i32; bw * bh]; | ||
| 8095 | + y.reconstruct_rect( | ||
| 8096 | + px, py, bw, bh, mode, angle_delta_y, reach, &zeros, None, None, smooth_neighbor, | ||
| 8097 | + ); | ||
| 8098 | + zeros | ||
| 8099 | + } else { | ||
| 8100 | + // `plane_bsize == txsize_to_bsize[tx_size]` here too (the leaf's | ||
| 8101 | + // luma TU *is* the leaf), so `get_txb_ctx` fixes `txb_skip_ctx` | ||
| 8102 | + // at 0 -- see `decode_leaf_split4`'s own note. | ||
| 8103 | + let around = neighbours.around_mi_rect(lmi, bw, bh)[0]; | ||
| 8104 | + let set = if reduced_tx_set { | ||
| 8105 | + TxbSet::LumaRect4x8 | ||
| 8106 | + } else { | ||
| 8107 | + TxbSet::LumaRect4x8Set1 | ||
| 8108 | + }; | ||
| 8109 | + let mut coding = cdfs.txb(set, mode); | ||
| 8110 | + let (levels, tx_type) = read_coeffs_rect( | ||
| 8111 | + dec, | ||
| 8112 | + &mut coding, | ||
| 8113 | + scan, | ||
| 8114 | + bw, | ||
| 8115 | + bh, | ||
| 8116 | + 0, | ||
| 8117 | + dc_sign_ctx(around.2), | ||
| 8118 | + TxType::DctDct, | ||
| 8119 | + )?; | ||
| 8120 | + if levels.iter().any(|&l| l != 0) { | ||
| 8121 | + if vert { | ||
| 8122 | + TX4X8_CODED_HITS.with(|h| h.set(h.get() + 1)); | ||
| 8123 | + } else { | ||
| 8124 | + TX8X4_CODED_HITS.with(|h| h.set(h.get() + 1)); | ||
| 8125 | + } | ||
| 8126 | + } | ||
| 8127 | + let residual = dequant_and_inverse_typed_wh( | ||
| 8128 | + &levels, | ||
| 8129 | + bw, | ||
| 8130 | + bh, | ||
| 8131 | + crate::decode::bit_depth(), | ||
| 8132 | + CURRENT_Q_IDX.with(|q| q.get()), | ||
| 8133 | + plane_q_delta(0).0, | ||
| 8134 | + plane_q_delta(0).1, | ||
| 8135 | + tx_type, | ||
| 8136 | + ); | ||
| 8137 | + y.reconstruct_rect( | ||
| 8138 | + px, py, bw, bh, mode, angle_delta_y, reach, &residual, None, None, smooth_neighbor, | ||
| 8139 | + ); | ||
| 8140 | + levels | ||
| 8141 | + }; | ||
| 8142 | + // Plane 0's per-TU coefficient context over this leaf's own mi span | ||
| 8143 | + // (`record_mi_luma`'s rect twin -- the chroma planes are written once | ||
| 8144 | + // for the whole 8x8 group below). | ||
| 8145 | + let state = neighbour_state(&grid); | ||
| 8146 | + for cell in 0..h_mi { | ||
| 8147 | + if lmi.0 + cell < neighbours.mi_rows { | ||
| 8148 | + neighbours.left[lmi.0 + cell][0] = state; | ||
| 8149 | + } | ||
| 8150 | + } | ||
| 8151 | + for cell in 0..w_mi { | ||
| 8152 | + if lmi.1 + cell < neighbours.mi_cols { | ||
| 8153 | + neighbours.above[lmi.1 + cell][0] = state; | ||
| 8154 | + } | ||
| 8155 | + } | ||
| 8156 | + neighbours.fill_skip_grid_rect(lmi, w_mi, h_mi, skip); | ||
| 8157 | + let (tx_w, tx_h) = if split { (4, 4) } else { (bw as u8, bh as u8) }; | ||
| 8158 | + neighbours.fill_lf_grid_rect(lmi, w_mi, h_mi, tx_w, tx_h, 0); | ||
| 8159 | + if has_chroma { | ||
| 8160 | + last_uv = chroma; | ||
| 8161 | + } | ||
| 8162 | + } | ||
| 8163 | + let (gpx, gpy) = (leaf_mi.1 * MI, leaf_mi.0 * MI); | ||
| 8164 | + let (cpx, cpy) = (gpx / 2, gpy / 2); | ||
| 8165 | + let group_reach = Reach::of(8, gpx, gpy, y.width, y.height); | ||
| 8166 | + let (uv_mode, angle_delta_uv, alpha) = | ||
| 8167 | + last_uv.expect("i==1 always sets has_chroma, so chroma is always Some"); | ||
| 8168 | + let uv_predict_mode = if uv_mode == UV_CFL_PRED { DC_PRED } else { uv_mode }; | ||
| 8169 | + neighbours.above_uv_mode[c] = uv_predict_mode; | ||
| 8170 | + neighbours.left_uv_mode[r] = uv_predict_mode; | ||
| 8171 | + neighbours.record_uv_mode_mi(leaf_mi.0, leaf_mi.1, 2, 2, uv_predict_mode); | ||
| 8172 | + let (u_grid, v_grid): (Vec<i32>, Vec<i32>) = if leaf_skips[1] { | ||
| 8173 | + u.reconstruct(cpx, cpy, 4, uv_predict_mode, angle_delta_uv, group_reach, &vec![0i32; 16], None, None, smooth_neighbor_uv); | ||
| 8174 | + v.reconstruct(cpx, cpy, 4, uv_predict_mode, angle_delta_uv, group_reach, &vec![0i32; 16], None, None, smooth_neighbor_uv); | ||
| 8175 | + (vec![0i32; 16], vec![0i32; 16]) | ||
| 8176 | + } else { | ||
| 8177 | + let ac = alpha.map(|_| cfl_ac_q3(y, gpx, gpy, 8)); | ||
| 8178 | + let chroma_around = neighbours.around_mi(leaf_mi, 8); | ||
| 8179 | + let ug = read_plane( | ||
| 8180 | + dec, cdfs, TxbSet::Chroma4, scan4, 1, chroma_around[1], uv_mode, uv_predict_mode, | ||
| 8181 | + angle_delta_uv, group_reach, u, cpx, cpy, 4, TX4, base_q_idx, | ||
| 8182 | + alpha.zip(ac.as_deref()).map(|((au, _), ac)| (au, ac)), None, None, smooth_neighbor_uv, | ||
| 8183 | + )?; | ||
| 8184 | + let vg = read_plane( | ||
| 8185 | + dec, cdfs, TxbSet::Chroma4, scan4, 2, chroma_around[2], uv_mode, uv_predict_mode, | ||
| 8186 | + angle_delta_uv, group_reach, v, cpx, cpy, 4, TX4, base_q_idx, | ||
| 8187 | + alpha.zip(ac.as_deref()).map(|((_, av), ac)| (av, ac)), None, None, smooth_neighbor_uv, | ||
| 8188 | + )?; | ||
| 8189 | + (ug, vg) | ||
| 8190 | + }; | ||
| 8191 | + // `update_partition_context` at the 8x8 level writes | ||
| 8192 | + // `partition_context_lookup[subsize]` over the whole 8x8 span: BLOCK_4X8 | ||
| 8193 | + // is `{31, 30}` (bit0 set on the above half only), BLOCK_8X4 `{30, 31}` | ||
| 8194 | + // -- the mirror of `decode_leaf_split4`'s `{31, 31}`, which | ||
| 8195 | + // `partition_ctx_mi` reads back off these side values. | ||
| 8196 | + for cell in 0..2 { | ||
| 8197 | + neighbours.above_side_mi[leaf_mi.1 + cell] = bw; | ||
| 8198 | + neighbours.left_side_mi[leaf_mi.0 + cell] = bh; | ||
| 8199 | + } | ||
| 8200 | + let round_up_even = |n: usize| n.div_ceil(2) * 2; | ||
| 8201 | + let bound_h = round_up_even(neighbours.mi_rows); | ||
| 8202 | + let bound_w = round_up_even(neighbours.mi_cols); | ||
| 8203 | + let u_state = neighbour_state(&u_grid); | ||
| 8204 | + let v_state = neighbour_state(&v_grid); | ||
| 8205 | + for cell in 0..2usize { | ||
| 8206 | + if cell < 2usize.min(bound_h.saturating_sub(leaf_mi.0)) { | ||
| 8207 | + neighbours.left[leaf_mi.0 + cell][1] = u_state; | ||
| 8208 | + neighbours.left[leaf_mi.0 + cell][2] = v_state; | ||
| 8209 | + } | ||
| 8210 | + if cell < 2usize.min(bound_w.saturating_sub(leaf_mi.1)) { | ||
| 8211 | + neighbours.above[leaf_mi.1 + cell][1] = u_state; | ||
| 8212 | + neighbours.above[leaf_mi.1 + cell][2] = v_state; | ||
| 8213 | + } | ||
| 8214 | + } | ||
| 8215 | + // `(below_mode, right_mode)`: the sub-block a neighbour below sees is the | ||
| 8216 | + // bottom one (the second under HORZ, the left one under VERT), the one a | ||
| 8217 | + // neighbour to the right sees is the top-right (the second under VERT). | ||
| 8218 | + Ok(if vert { | ||
| 8219 | + (leaf_modes[0], leaf_modes[1]) | ||
| 8220 | + } else { | ||
| 8221 | + (leaf_modes[1], leaf_modes[0]) | ||
| 8222 | + }) | ||
| 8223 | +} | ||
| 8224 | + | ||
| 7806 | /// Spec 7.15.3's `Cdef_Directions`: `(row, col)` offsets for the two primary | 8225 | /// Spec 7.15.3's `Cdef_Directions`: `(row, col)` offsets for the two primary |
| 7807 | /// taps of each of the eight directions; the secondary taps at `dir+2`/`dir-2` | 8226 | /// taps of each of the eight directions; the secondary taps at `dir+2`/`dir-2` |
| 7808 | /// (mod 8) reuse the same table. | 8227 | /// (mod 8) reuse the same table. |
| @@ -9965,10 +10384,28 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( | |||
| 9965 | allow_intrabc, | 10384 | allow_intrabc, |
| 9966 | reduced_tx_set, | 10385 | reduced_tx_set, |
| 9967 | )? | 10386 | )? |
| 10387 | + } else if part8 == PARTITION_HORZ | ||
| 10388 | + || part8 == PARTITION_VERT | ||
| 10389 | + { | ||
| 10390 | + decode_leaf_rect8( | ||
| 10391 | + &mut dec, | ||
| 10392 | + &mut cdfs, | ||
| 10393 | + &mut neighbours, | ||
| 10394 | + at16, | ||
| 10395 | + leaf_mi, | ||
| 10396 | + part8 == PARTITION_VERT, | ||
| 10397 | + &scan4, | ||
| 10398 | + &mut y, | ||
| 10399 | + &mut u, | ||
| 10400 | + &mut v, | ||
| 10401 | + base_q_idx, | ||
| 10402 | + enable_filter_intra, | ||
| 10403 | + allow_intrabc, | ||
| 10404 | + tx_select, | ||
| 10405 | + reduced_tx_set, | ||
| 10406 | + )? | ||
| 9968 | } else { | 10407 | } else { |
| 9969 | - return Err(unsupported( | 10408 | + unreachable!("partition_w8 is a 4-symbol CDF: NONE/HORZ/VERT/SPLIT only"); |
| 9970 | - "a HORZ/VERT partition below 8x8 (this decoder's transform primitive is square-only; 4x8/8x4 need a real rectangular transform)", | ||
| 9971 | - )); | ||
| 9972 | }; | 10409 | }; |
| 9973 | neighbours.above_mode[sc] = saved_modes.0; | 10410 | neighbours.above_mode[sc] = saved_modes.0; |
| 9974 | neighbours.left_mode[sr] = saved_modes.1; | 10411 | neighbours.left_mode[sr] = saved_modes.1; |
| @@ -10074,10 +10511,28 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( | |||
| 10074 | allow_intrabc, | 10511 | allow_intrabc, |
| 10075 | reduced_tx_set, | 10512 | reduced_tx_set, |
| 10076 | )? | 10513 | )? |
| 10514 | + } else if part8 == PARTITION_HORZ | ||
| 10515 | + || part8 == PARTITION_VERT | ||
| 10516 | + { | ||
| 10517 | + decode_leaf_rect8( | ||
| 10518 | + &mut dec, | ||
| 10519 | + &mut cdfs, | ||
| 10520 | + &mut neighbours, | ||
| 10521 | + at16, | ||
| 10522 | + leaf_mi, | ||
| 10523 | + part8 == PARTITION_VERT, | ||
| 10524 | + &scan4, | ||
| 10525 | + &mut y, | ||
| 10526 | + &mut u, | ||
| 10527 | + &mut v, | ||
| 10528 | + base_q_idx, | ||
| 10529 | + enable_filter_intra, | ||
| 10530 | + allow_intrabc, | ||
| 10531 | + tx_select, | ||
| 10532 | + reduced_tx_set, | ||
| 10533 | + )? | ||
| 10077 | } else { | 10534 | } else { |
| 10078 | - return Err(unsupported( | 10535 | + unreachable!("partition_w8 is a 4-symbol CDF: NONE/HORZ/VERT/SPLIT only"); |
| 10079 | - "a HORZ/VERT partition below 8x8 (this decoder's transform primitive is square-only; 4x8/8x4 need a real rectangular transform)", | ||
| 10080 | - )); | ||
| 10081 | }; | 10536 | }; |
| 10082 | neighbours.above_mode[sc] = saved_modes.0; | 10537 | neighbours.above_mode[sc] = saved_modes.0; |
| 10083 | neighbours.left_mode[sr] = saved_modes.1; | 10538 | neighbours.left_mode[sr] = saved_modes.1; |
| @@ -18810,3 +19265,91 @@ mod tests { | |||
| 18810 | } | 19265 | } |
| 18811 | } | 19266 | } |
| 18812 | } | 19267 | } |
| 19268 | + | ||
| 19269 | +#[cfg(test)] | ||
| 19270 | +mod tx4x8_table_tests { | ||
| 19271 | + use super::*; | ||
| 19272 | + | ||
| 19273 | + /// Asymmetric gate on the two new scan tables (class | ||
| 19274 | + /// `reference-layout-not-spec`): a transposed pair of tables passes any | ||
| 19275 | + /// "is a permutation" check, so this pins the pair AGAINST each other -- | ||
| 19276 | + /// `SCAN_8X4[k]` must be `SCAN_4X8[k]` reflected across the diagonal, and | ||
| 19277 | + /// both must be bijections of `0..32` in our own row-major indexing. | ||
| 19278 | + #[test] | ||
| 19279 | + fn the_rect_4x8_scans_are_each_other_transposed() { | ||
| 19280 | + let mut seen_a = [false; 32]; | ||
| 19281 | + let mut seen_b = [false; 32]; | ||
| 19282 | + for k in 0..32usize { | ||
| 19283 | + let a = SCAN_4X8[k] as usize; | ||
| 19284 | + let b = SCAN_8X4[k] as usize; | ||
| 19285 | + assert!(!seen_a[a] && !seen_b[b], "scan position {k} repeats"); | ||
| 19286 | + seen_a[a] = true; | ||
| 19287 | + seen_b[b] = true; | ||
| 19288 | + let (row, col) = (a / 4, a % 4); | ||
| 19289 | + assert_eq!(b, col * 8 + row, "SCAN_8X4[{k}] is not SCAN_4X8[{k}] transposed"); | ||
| 19290 | + } | ||
| 19291 | + assert!(seen_a.iter().all(|&s| s) && seen_b.iter().all(|&s| s)); | ||
| 19292 | + } | ||
| 19293 | + | ||
| 19294 | + /// `mrow_scan_4x8`/`mcol_scan_4x8`/`mrow_scan_8x4`/`mcol_scan_8x4` | ||
| 19295 | + /// (libaom `scan.c`), converted out of their column-major encoding by | ||
| 19296 | + /// `(p % h) * w + p / h` -- the head of each, pinned so the rect | ||
| 19297 | + /// `V_DCT`/`H_DCT` walk cannot silently transpose. | ||
| 19298 | + #[test] | ||
| 19299 | + fn the_rect_class1_scans_match_libaom() { | ||
| 19300 | + assert_eq!( | ||
| 19301 | + class_scan_table_wh(4, 8, TxClass::Vert), | ||
| 19302 | + (0..32u16).collect::<Vec<_>>() | ||
| 19303 | + ); | ||
| 19304 | + assert_eq!( | ||
| 19305 | + &class_scan_table_wh(4, 8, TxClass::Horiz)[..8], | ||
| 19306 | + &[0u16, 4, 8, 12, 16, 20, 24, 28] | ||
| 19307 | + ); | ||
| 19308 | + assert_eq!( | ||
| 19309 | + class_scan_table_wh(8, 4, TxClass::Vert), | ||
| 19310 | + (0..32u16).collect::<Vec<_>>() | ||
| 19311 | + ); | ||
| 19312 | + assert_eq!( | ||
| 19313 | + &class_scan_table_wh(8, 4, TxClass::Horiz)[..8], | ||
| 19314 | + &[0u16, 8, 16, 24, 1, 9, 17, 25] | ||
| 19315 | + ); | ||
| 19316 | + } | ||
| 19317 | + | ||
| 19318 | + /// The 32-position `eob_pt` alphabet: six symbols (one more than the | ||
| 19319 | + /// 16-position table, one fewer than the 64-position one), strictly | ||
| 19320 | + /// increasing, terminated at 32768 with the adaptation counter after it. | ||
| 19321 | + #[test] | ||
| 19322 | + fn the_32_position_eob_tables_are_well_formed() { | ||
| 19323 | + for table in [ | ||
| 19324 | + &cdf::EOB_PT_32_LUMA_Q0, | ||
| 19325 | + &cdf::EOB_PT_32_LUMA_Q1, | ||
| 19326 | + &cdf::EOB_PT_32_LUMA, | ||
| 19327 | + &cdf::EOB_PT_32_LUMA_Q3, | ||
| 19328 | + &cdf::EOB_PT_32_LUMA_CLASS1_Q0, | ||
| 19329 | + &cdf::EOB_PT_32_LUMA_CLASS1_Q1, | ||
| 19330 | + &cdf::EOB_PT_32_LUMA_CLASS1, | ||
| 19331 | + &cdf::EOB_PT_32_LUMA_CLASS1_Q3, | ||
| 19332 | + ] { | ||
| 19333 | + assert_eq!(table.len(), 7); | ||
| 19334 | + assert_eq!(table[5], 32768); | ||
| 19335 | + assert_eq!(table[6], 0); | ||
| 19336 | + for w in table[..6].windows(2) { | ||
| 19337 | + assert!(w[0] < w[1], "{table:?} is not increasing"); | ||
| 19338 | + } | ||
| 19339 | + } | ||
| 19340 | + } | ||
| 19341 | + | ||
| 19342 | + /// `Reach::of_rect` must read libaom's own `has_tr_4x8`/`has_tr_8x4` | ||
| 19343 | + /// rows, not the 32x16 pair the two existing rect strips use: the two | ||
| 19344 | + /// shapes disagree at a position inside the superblock, which is what | ||
| 19345 | + /// makes this an asymmetric check rather than a tautology. | ||
| 19346 | + #[test] | ||
| 19347 | + fn the_sub8_rect_reach_tables_are_shape_specific() { | ||
| 19348 | + let a = Reach::of_rect(4, 8, 4, 8, 64, 64); | ||
| 19349 | + let b = Reach::of_rect(8, 4, 8, 4, 64, 64); | ||
| 19350 | + assert!( | ||
| 19351 | + a.above_right != b.above_right || a.below_left != b.below_left, | ||
| 19352 | + "4x8 and 8x4 reach identically at mirrored positions -- one table is unused" | ||
| 19353 | + ); | ||
| 19354 | + } | ||
| 19355 | +} | ||
crates/ec-av1/src/encode.rsmodified+202 -39
| @@ -1123,43 +1123,94 @@ impl Drop for VertAbGuard { | |||
| 1123 | } | 1123 | } |
| 1124 | } | 1124 | } |
| 1125 | 1125 | ||
| 1126 | -/// libaom `reconintra.c`'s `has_tr_*`/`has_bl_*` for the four rectangular | 1126 | +/// The `has_tr_*` / `has_bl_*` tables for every rectangular shape this |
| 1127 | -/// block sizes this decoder codes, transcribed verbatim (lane-rectx r4). | 1127 | +/// decoder codes (libaom `reconintra.c`, generated from the oracle's source |
| 1128 | -/// The 16x8/8x16 rows are what the 32x16/16x32 pair above cannot stand in | 1128 | +/// so no byte is retyped). Each is indexed by |
| 1129 | -/// for: they are 16 bytes, not 4, and their bit pattern is a different | 1129 | +/// `(blk_row_in_sb << (5 - log2(bw / 4))) + blk_col_in_sb`, i.e. row stride |
| 1130 | -/// coding order entirely -- reading the 16x32 table for a 16x8 block gave | 1130 | +/// `128 / bw` bits ([`Reach::table_stride`]) on libaom's 128-pixel |
| 1131 | -/// the wrong bottom-left availability and a directional (D203) strip whose | 1131 | +/// superblock grid; on this crate's 64-pixel superblock the highest index a |
| 1132 | -/// prediction diverged exactly where it starts reading below its own height. | 1132 | +/// shape can reach stays inside its own table, so no wrap is involved. |
| 1133 | -/// `has_tr_vert_tables`/`has_bl_vert_tables` hold the SAME pointers as these | 1133 | +/// |
| 1134 | -/// for every W<H entry, and are NULL for W>H (no VERT_A/B ever produces one), | 1134 | +/// lane-tx4x8 r3: the previous two-row `HAS_TOP_RIGHT_RECT`/ |
| 1135 | -/// so the partition type does not select a different table at these sizes. | 1135 | +/// `HAS_BOTTOM_LEFT_RECT` pair held 32x16/16x32 only and a `_` arm routed |
| 1136 | -fn has_tr_rect_table(bw: usize, bh: usize) -> &'static [u8] { | 1136 | +/// every other shape -- 16x8 strips among them -- to the 32x16 row, wrong at |
| 1137 | - match (bw, bh) { | 1137 | +/// 10 of the 21 reachable superblock positions for above-right and 7 for |
| 1138 | - (16, 8) => &[255, 0, 85, 0, 119, 0, 85, 0, 127, 0, 85, 0, 119, 0, 85, 0], | 1138 | +/// below-left. |
| 1139 | - (8, 16) => &[255, 255, 119, 119, 127, 127, 119, 119, 255, 127, 119, 119, 127, 127, 119, 119], | 1139 | +/// `has_tr_4x8` (`reconintra.c`), transcribed verbatim: 64 bytes, row stride 32 bits (`128 / 4`). |
| 1140 | - (32, 16) => &[15, 5, 7, 5], | 1140 | +const HAS_TR_4X8: [u8; 64] = [255, 255, 255, 255, 119, 119, 119, 119, 127, 127, 127, 127, 119, 119, 119, 119, 255, 127, 255, 127, 119, 119, 119, 119, 127, 127, 127, 127, 119, 119, 119, 119, 255, 255, 255, 127, 119, 119, 119, 119, 127, 127, 127, 127, 119, 119, 119, 119, 255, 127, 255, 127, 119, 119, 119, 119, 127, 127, 127, 127, 119, 119, 119, 119]; |
| 1141 | - (16, 32) => &[255, 119, 127, 119], | 1141 | +/// `has_bl_4x8` (`reconintra.c`), transcribed verbatim: 64 bytes, row stride 32 bits (`128 / 4`). |
| 1142 | - (64, 32) => &[19], | 1142 | +const HAS_BL_4X8: [u8; 64] = [16, 17, 17, 17, 0, 1, 1, 1, 16, 17, 17, 17, 0, 0, 1, 0, 16, 17, 17, 17, 0, 1, 1, 1, 16, 17, 17, 17, 0, 0, 0, 0, 16, 17, 17, 17, 0, 1, 1, 1, 16, 17, 17, 17, 0, 0, 1, 0, 16, 17, 17, 17, 0, 1, 1, 1, 16, 17, 17, 17, 0, 0, 0, 0]; |
| 1143 | - // lane-tx64x16 r3: `has_tr_32x8` / `has_tr_8x32` | 1143 | +/// `has_tr_8x4` (`reconintra.c`), transcribed verbatim: 64 bytes, row stride 16 bits (`128 / 8`). |
| 1144 | - // (`reconintra.c:122-127`), the 4:1 strips of a 32x32-level | 1144 | +const HAS_TR_8X4: [u8; 64] = [255, 255, 0, 0, 85, 85, 0, 0, 119, 119, 0, 0, 85, 85, 0, 0, 127, 127, 0, 0, 85, 85, 0, 0, 119, 119, 0, 0, 85, 85, 0, 0, 255, 127, 0, 0, 85, 85, 0, 0, 119, 119, 0, 0, 85, 85, 0, 0, 127, 127, 0, 0, 85, 85, 0, 0, 119, 119, 0, 0, 85, 85, 0, 0]; |
| 1145 | - // `PARTITION_HORZ_4`/`VERT_4`. | 1145 | +/// `has_bl_8x4` (`reconintra.c`), transcribed verbatim: 64 bytes, row stride 16 bits (`128 / 8`). |
| 1146 | - (32, 8) => &[15, 0, 5, 0, 7, 0, 5, 0], | 1146 | +const HAS_BL_8X4: [u8; 64] = [254, 255, 84, 85, 254, 255, 16, 17, 254, 255, 84, 85, 254, 255, 0, 1, 254, 255, 84, 85, 254, 255, 16, 17, 254, 255, 84, 85, 254, 255, 0, 0, 254, 255, 84, 85, 254, 255, 16, 17, 254, 255, 84, 85, 254, 255, 0, 1, 254, 255, 84, 85, 254, 255, 16, 17, 254, 255, 84, 85, 254, 255, 0, 0]; |
| 1147 | - (8, 32) => &[255, 255, 127, 127, 255, 127, 127, 127], | 1147 | +/// `has_tr_8x16` (`reconintra.c`), transcribed verbatim: 16 bytes, row stride 16 bits (`128 / 8`). |
| 1148 | - _ => &[127], | 1148 | +const HAS_TR_8X16: [u8; 16] = [255, 255, 119, 119, 127, 127, 119, 119, 255, 127, 119, 119, 127, 127, 119, 119]; |
| 1149 | - } | 1149 | +/// `has_bl_8x16` (`reconintra.c`), transcribed verbatim: 16 bytes, row stride 16 bits (`128 / 8`). |
| 1150 | -} | 1150 | +const HAS_BL_8X16: [u8; 16] = [16, 17, 0, 1, 16, 17, 0, 0, 16, 17, 0, 1, 16, 17, 0, 0]; |
| 1151 | - | 1151 | +/// `has_tr_16x8` (`reconintra.c`), transcribed verbatim: 16 bytes, row stride 8 bits (`128 / 16`). |
| 1152 | -fn has_bl_rect_table(bw: usize, bh: usize) -> &'static [u8] { | 1152 | +const HAS_TR_16X8: [u8; 16] = [255, 0, 85, 0, 119, 0, 85, 0, 127, 0, 85, 0, 119, 0, 85, 0]; |
| 1153 | +/// `has_bl_16x8` (`reconintra.c`), transcribed verbatim: 16 bytes, row stride 8 bits (`128 / 16`). | ||
| 1154 | +const HAS_BL_16X8: [u8; 16] = [254, 84, 254, 16, 254, 84, 254, 0, 254, 84, 254, 16, 254, 84, 254, 0]; | ||
| 1155 | +/// `has_tr_16x32` (`reconintra.c`), transcribed verbatim: 4 bytes, row stride 8 bits (`128 / 16`). | ||
| 1156 | +const HAS_TR_16X32: [u8; 4] = [255, 119, 127, 119]; | ||
| 1157 | +/// `has_bl_16x32` (`reconintra.c`), transcribed verbatim: 4 bytes, row stride 8 bits (`128 / 16`). | ||
| 1158 | +const HAS_BL_16X32: [u8; 4] = [16, 0, 16, 0]; | ||
| 1159 | +/// `has_tr_32x16` (`reconintra.c`), transcribed verbatim: 4 bytes, row stride 4 bits (`128 / 32`). | ||
| 1160 | +const HAS_TR_32X16: [u8; 4] = [15, 5, 7, 5]; | ||
| 1161 | +/// `has_bl_32x16` (`reconintra.c`), transcribed verbatim: 4 bytes, row stride 4 bits (`128 / 32`). | ||
| 1162 | +const HAS_BL_32X16: [u8; 4] = [78, 14, 78, 14]; | ||
| 1163 | +/// `has_tr_32x64` (`reconintra.c`), transcribed verbatim: 1 bytes, row stride 4 bits (`128 / 32`). | ||
| 1164 | +const HAS_TR_32X64: [u8; 1] = [127]; | ||
| 1165 | +/// `has_bl_32x64` (`reconintra.c`), transcribed verbatim: 1 bytes, row stride 4 bits (`128 / 32`). | ||
| 1166 | +const HAS_BL_32X64: [u8; 1] = [0]; | ||
| 1167 | +/// `has_tr_64x32` (`reconintra.c`), transcribed verbatim: 1 bytes, row stride 2 bits (`128 / 64`). | ||
| 1168 | +const HAS_TR_64X32: [u8; 1] = [19]; | ||
| 1169 | +/// `has_bl_64x32` (`reconintra.c`), transcribed verbatim: 1 bytes, row stride 2 bits (`128 / 64`). | ||
| 1170 | +const HAS_BL_64X32: [u8; 1] = [34]; | ||
| 1171 | +/// `has_tr_4x16` (`reconintra.c`), transcribed verbatim: 32 bytes, row stride 32 bits (`128 / 4`). | ||
| 1172 | +const HAS_TR_4X16: [u8; 32] = [255, 255, 255, 255, 127, 127, 127, 127, 255, 127, 255, 127, 127, 127, 127, 127, 255, 255, 255, 127, 127, 127, 127, 127, 255, 127, 255, 127, 127, 127, 127, 127]; | ||
| 1173 | +/// `has_bl_4x16` (`reconintra.c`), transcribed verbatim: 32 bytes, row stride 32 bits (`128 / 4`). | ||
| 1174 | +const HAS_BL_4X16: [u8; 32] = [0, 1, 1, 1, 0, 0, 1, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 1, 0, 0, 1, 1, 1, 0, 0, 0, 0]; | ||
| 1175 | +/// `has_tr_16x4` (`reconintra.c`), transcribed verbatim: 32 bytes, row stride 8 bits (`128 / 16`). | ||
| 1176 | +const HAS_TR_16X4: [u8; 32] = [255, 0, 0, 0, 85, 0, 0, 0, 119, 0, 0, 0, 85, 0, 0, 0, 127, 0, 0, 0, 85, 0, 0, 0, 119, 0, 0, 0, 85, 0, 0, 0]; | ||
| 1177 | +/// `has_bl_16x4` (`reconintra.c`), transcribed verbatim: 32 bytes, row stride 8 bits (`128 / 16`). | ||
| 1178 | +const HAS_BL_16X4: [u8; 32] = [254, 254, 254, 84, 254, 254, 254, 16, 254, 254, 254, 84, 254, 254, 254, 0, 254, 254, 254, 84, 254, 254, 254, 16, 254, 254, 254, 84, 254, 254, 254, 0]; | ||
| 1179 | +/// `has_tr_8x32` (`reconintra.c`), transcribed verbatim: 8 bytes, row stride 16 bits (`128 / 8`). | ||
| 1180 | +const HAS_TR_8X32: [u8; 8] = [255, 255, 127, 127, 255, 127, 127, 127]; | ||
| 1181 | +/// `has_bl_8x32` (`reconintra.c`), transcribed verbatim: 8 bytes, row stride 16 bits (`128 / 8`). | ||
| 1182 | +const HAS_BL_8X32: [u8; 8] = [0, 1, 0, 0, 0, 1, 0, 0]; | ||
| 1183 | +/// `has_tr_32x8` (`reconintra.c`), transcribed verbatim: 8 bytes, row stride 4 bits (`128 / 32`). | ||
| 1184 | +const HAS_TR_32X8: [u8; 8] = [15, 0, 5, 0, 7, 0, 5, 0]; | ||
| 1185 | +/// `has_bl_32x8` (`reconintra.c`), transcribed verbatim: 8 bytes, row stride 4 bits (`128 / 32`). | ||
| 1186 | +const HAS_BL_32X8: [u8; 8] = [238, 78, 238, 14, 238, 78, 238, 14]; | ||
| 1187 | +/// `has_tr_16x64` (`reconintra.c`), transcribed verbatim: 2 bytes, row stride 8 bits (`128 / 16`). | ||
| 1188 | +const HAS_TR_16X64: [u8; 2] = [255, 127]; | ||
| 1189 | +/// `has_bl_16x64` (`reconintra.c`), transcribed verbatim: 2 bytes, row stride 8 bits (`128 / 16`). | ||
| 1190 | +const HAS_BL_16X64: [u8; 2] = [0, 0]; | ||
| 1191 | +/// `has_tr_64x16` (`reconintra.c`), transcribed verbatim: 2 bytes, row stride 2 bits (`128 / 64`). | ||
| 1192 | +const HAS_TR_64X16: [u8; 2] = [3, 1]; | ||
| 1193 | +/// `has_bl_64x16` (`reconintra.c`), transcribed verbatim: 2 bytes, row stride 2 bits (`128 / 64`). | ||
| 1194 | +const HAS_BL_64X16: [u8; 2] = [42, 42]; | ||
| 1195 | + | ||
| 1196 | +/// The `has_tr_*`/`has_bl_*` row for one rectangular block shape. | ||
| 1197 | +fn rect_reach_tables(bw: usize, bh: usize) -> (&'static [u8], &'static [u8]) { | ||
| 1153 | match (bw, bh) { | 1198 | match (bw, bh) { |
| 1154 | - (16, 8) => &[254, 84, 254, 16, 254, 84, 254, 0, 254, 84, 254, 16, 254, 84, 254, 0], | 1199 | + (4, 8) => (&HAS_TR_4X8, &HAS_BL_4X8), |
| 1155 | - (8, 16) => &[16, 17, 0, 1, 16, 17, 0, 0, 16, 17, 0, 1, 16, 17, 0, 0], | 1200 | + (8, 4) => (&HAS_TR_8X4, &HAS_BL_8X4), |
| 1156 | - (32, 16) => &[78, 14, 78, 14], | 1201 | + (8, 16) => (&HAS_TR_8X16, &HAS_BL_8X16), |
| 1157 | - (16, 32) => &[16, 0, 16, 0], | 1202 | + (16, 8) => (&HAS_TR_16X8, &HAS_BL_16X8), |
| 1158 | - (64, 32) => &[34], | 1203 | + (16, 32) => (&HAS_TR_16X32, &HAS_BL_16X32), |
| 1159 | - // `has_bl_32x8` / `has_bl_8x32` (`reconintra.c:305-310`). | 1204 | + (32, 16) => (&HAS_TR_32X16, &HAS_BL_32X16), |
| 1160 | - (32, 8) => &[238, 78, 238, 14, 238, 78, 238, 14], | 1205 | + (32, 64) => (&HAS_TR_32X64, &HAS_BL_32X64), |
| 1161 | - (8, 32) => &[0, 1, 0, 0, 0, 1, 0, 0], | 1206 | + (64, 32) => (&HAS_TR_64X32, &HAS_BL_64X32), |
| 1162 | - _ => &[0], | 1207 | + (4, 16) => (&HAS_TR_4X16, &HAS_BL_4X16), |
| 1208 | + (16, 4) => (&HAS_TR_16X4, &HAS_BL_16X4), | ||
| 1209 | + (8, 32) => (&HAS_TR_8X32, &HAS_BL_8X32), | ||
| 1210 | + (32, 8) => (&HAS_TR_32X8, &HAS_BL_32X8), | ||
| 1211 | + (16, 64) => (&HAS_TR_16X64, &HAS_BL_16X64), | ||
| 1212 | + (64, 16) => (&HAS_TR_64X16, &HAS_BL_64X16), | ||
| 1213 | + _ => unreachable!("no libaom has_tr/has_bl table for a {bw}x{bh} block"), | ||
| 1163 | } | 1214 | } |
| 1164 | } | 1215 | } |
| 1165 | 1216 | ||
| @@ -1211,7 +1262,7 @@ impl Reach { | |||
| 1211 | if ((blk_col + 1) << bw_log2) >= SB_MI { | 1262 | if ((blk_col + 1) << bw_log2) >= SB_MI { |
| 1212 | return false; | 1263 | return false; |
| 1213 | } | 1264 | } |
| 1214 | - let table = has_tr_rect_table(bw, bh); | 1265 | + let table = rect_reach_tables(bw, bh).0; |
| 1215 | Self::bit(table, Self::rect_table_index(bw_log2, blk_row, blk_col)) | 1266 | Self::bit(table, Self::rect_table_index(bw_log2, blk_row, blk_col)) |
| 1216 | } | 1267 | } |
| 1217 | 1268 | ||
| @@ -1245,7 +1296,7 @@ impl Reach { | |||
| 1245 | if ((blk_row + 1) << bh_log2) >= SB_MI { | 1296 | if ((blk_row + 1) << bh_log2) >= SB_MI { |
| 1246 | return false; | 1297 | return false; |
| 1247 | } | 1298 | } |
| 1248 | - let table = has_bl_rect_table(bw, bh); | 1299 | + let table = rect_reach_tables(bw, bh).1; |
| 1249 | Self::bit(table, Self::rect_table_index(bw_log2, blk_row, blk_col)) | 1300 | Self::bit(table, Self::rect_table_index(bw_log2, blk_row, blk_col)) |
| 1250 | } | 1301 | } |
| 1251 | 1302 | ||
| @@ -3242,7 +3293,7 @@ mod tests { | |||
| 3242 | ((bw / 4).trailing_zeros() as usize, (bh / 4).trailing_zeros() as usize); | 3293 | ((bw / 4).trailing_zeros() as usize, (bh / 4).trailing_zeros() as usize); |
| 3243 | let (rows, cols) = (32 >> bh_log2, 32 >> bw_log2); | 3294 | let (rows, cols) = (32 >> bh_log2, 32 >> bw_log2); |
| 3244 | for (name, table) in | 3295 | for (name, table) in |
| 3245 | - [("has_tr", has_tr_rect_table(bw, bh)), ("has_bl", has_bl_rect_table(bw, bh))] | 3296 | + [("has_tr", rect_reach_tables(bw, bh).0), ("has_bl", rect_reach_tables(bw, bh).1)] |
| 3246 | { | 3297 | { |
| 3247 | assert_eq!( | 3298 | assert_eq!( |
| 3248 | table.len() * 8, | 3299 | table.len() * 8, |
| @@ -3273,6 +3324,118 @@ mod tests { | |||
| 3273 | use std::io::Write; | 3324 | use std::io::Write; |
| 3274 | use std::process::{Command, Stdio}; | 3325 | use std::process::{Command, Stdio}; |
| 3275 | 3326 | ||
| 3327 | + /// Every rectangular shape this decoder codes, at every position a block | ||
| 3328 | + /// of that shape can sit inside a 64x64 superblock: [`Reach::of_rect`] | ||
| 3329 | + /// must answer exactly what libaom's `has_top_right`/`has_bottom_left` | ||
| 3330 | + /// (`reconintra.c`) answer, whose bodies are ported below. | ||
| 3331 | + /// | ||
| 3332 | + /// lane-tx4x8 r3 ([[enumerate-table-domain]], [[tool-disabled-in-every-gate]]): | ||
| 3333 | + /// `rect_reach_tables` used to route every shape but 4x8/8x4/16x32 to the | ||
| 3334 | + /// 32x16 row, so live 16x8 strips read the wrong bit at 10 (above-right) | ||
| 3335 | + /// and 7 (below-left) of the 21 reachable positions with no gate seeing | ||
| 3336 | + /// it. The per-shape `(len, byte sum)` fingerprints below come from the | ||
| 3337 | + /// oracle's own arrays, so a re-routed or truncated table fails here even | ||
| 3338 | + /// where the two rows happen to agree. | ||
| 3339 | + /// | ||
| 3340 | + /// Not covered (no parameter for either on `of_rect`): chroma `ss_x`/ | ||
| 3341 | + /// `ss_y`, and sub-block transforms (`row_off`/`col_off` > 0), which the | ||
| 3342 | + /// callers handle by predicting each transform unit as its own block. | ||
| 3343 | + /// `PARTITION_VERT_A`/`VERT_B` need no arm either: libaom's | ||
| 3344 | + /// `has_tr_vert_tables`/`has_bl_vert_tables` entry for every RECT bsize is | ||
| 3345 | + /// either the plain table itself (4x8, 8x16, 16x32, 32x64) or NULL | ||
| 3346 | + /// (the horizontal shapes, which those partitions never produce). | ||
| 3347 | + #[test] | ||
| 3348 | + fn every_rect_shape_reaches_what_libaom_says_over_the_whole_superblock() { | ||
| 3349 | + // (bw, bh, has_tr len, has_tr byte sum, has_bl len, has_bl byte sum). | ||
| 3350 | + const SHAPES: [(usize, usize, usize, u32, usize, u32); 14] = [ | ||
| 3351 | + (4, 8, 64, 9280, 64, 550), | ||
| 3352 | + (8, 4, 64, 3712, 64, 9630), | ||
| 3353 | + (8, 16, 16, 2352, 16, 134), | ||
| 3354 | + (16, 8, 16, 960, 16, 2400), | ||
| 3355 | + (16, 32, 4, 620, 4, 32), | ||
| 3356 | + (32, 16, 4, 32, 4, 184), | ||
| 3357 | + (32, 64, 1, 127, 1, 0), | ||
| 3358 | + (64, 32, 1, 19, 1, 34), | ||
| 3359 | + (4, 16, 32, 5472, 32, 14), | ||
| 3360 | + (16, 4, 32, 960, 32, 6464), | ||
| 3361 | + (8, 32, 8, 1400, 8, 2), | ||
| 3362 | + (32, 8, 8, 32, 8, 1136), | ||
| 3363 | + (16, 64, 2, 382, 2, 0), | ||
| 3364 | + (64, 16, 2, 4, 2, 84), | ||
| 3365 | + ]; | ||
| 3366 | + /// libaom `reconintra.c` `has_top_right`/`has_bottom_left`, ported for | ||
| 3367 | + /// a block whose transform covers it whole (`row_off == col_off == 0`, | ||
| 3368 | + /// `tx_size == bsize`) and luma (`ss_x == ss_y == 0`) on a 64-pixel | ||
| 3369 | + /// superblock (`sb_mi_size == 16`). | ||
| 3370 | + fn libaom_reach( | ||
| 3371 | + bw: usize, | ||
| 3372 | + bh: usize, | ||
| 3373 | + x: usize, | ||
| 3374 | + y: usize, | ||
| 3375 | + width: usize, | ||
| 3376 | + height: usize, | ||
| 3377 | + ) -> (bool, bool) { | ||
| 3378 | + let (bw_log2, bh_log2) = ((bw / 4).ilog2() as usize, (bh / 4).ilog2() as usize); | ||
| 3379 | + let (_bw_unit, bh_unit) = (bw / 4, bh / 4); | ||
| 3380 | + let sb_mi_size = 16usize; | ||
| 3381 | + let blk_row_in_sb = ((y / 4) & (sb_mi_size - 1)) >> bh_log2; | ||
| 3382 | + let blk_col_in_sb = ((x / 4) & (sb_mi_size - 1)) >> bw_log2; | ||
| 3383 | + let this_blk_index = (blk_row_in_sb << (5 - bw_log2)) + blk_col_in_sb; | ||
| 3384 | + let (tr_table, bl_table) = rect_reach_tables(bw, bh); | ||
| 3385 | + let bit = |t: &[u8]| (t[this_blk_index / 8] >> (this_blk_index % 8)) & 1 != 0; | ||
| 3386 | + // has_top_right: top_available && right_available, then row_off == 0. | ||
| 3387 | + let top_right = if y == 0 || x + bw >= width { | ||
| 3388 | + false | ||
| 3389 | + } else if blk_row_in_sb == 0 { | ||
| 3390 | + // (`col_off + tx_wide_unit < plane_bw_unit` above this is | ||
| 3391 | + // `bw_unit < bw_unit`, false for a whole-block transform.) | ||
| 3392 | + true | ||
| 3393 | + } else if ((blk_col_in_sb + 1) << bw_log2) >= sb_mi_size { | ||
| 3394 | + false | ||
| 3395 | + } else { | ||
| 3396 | + bit(tr_table) | ||
| 3397 | + }; | ||
| 3398 | + // has_bottom_left: bottom_available && left_available, col_off == 0. | ||
| 3399 | + let bottom_left = if x == 0 || y + bh >= height { | ||
| 3400 | + false | ||
| 3401 | + } else if blk_col_in_sb == 0 { | ||
| 3402 | + // (`row_off + tx_high_unit < plane_bh_unit` is likewise false.) | ||
| 3403 | + (blk_row_in_sb << bh_log2) + bh_unit < sb_mi_size | ||
| 3404 | + } else if ((blk_row_in_sb + 1) << bh_log2) >= sb_mi_size { | ||
| 3405 | + false | ||
| 3406 | + } else { | ||
| 3407 | + bit(bl_table) | ||
| 3408 | + }; | ||
| 3409 | + (top_right, bottom_left) | ||
| 3410 | + } | ||
| 3411 | + for (bw, bh, tr_len, tr_sum, bl_len, bl_sum) in SHAPES { | ||
| 3412 | + let (tr, bl) = rect_reach_tables(bw, bh); | ||
| 3413 | + let sum = |t: &[u8]| t.iter().map(|&b| u32::from(b)).sum::<u32>(); | ||
| 3414 | + assert_eq!( | ||
| 3415 | + (tr.len(), sum(tr), bl.len(), sum(bl)), | ||
| 3416 | + (tr_len, tr_sum, bl_len, bl_sum), | ||
| 3417 | + "rect_reach_tables({bw}, {bh}) is not libaom's has_tr_{bw}x{bh}/has_bl_{bw}x{bh}" | ||
| 3418 | + ); | ||
| 3419 | + // Two superblocks across and down, so the superblock-relative | ||
| 3420 | + // position (and not the frame position) is what decides. | ||
| 3421 | + for sb_y in [0usize, 64] { | ||
| 3422 | + for sb_x in [0usize, 64] { | ||
| 3423 | + for y in (sb_y..sb_y + 64).step_by(bh) { | ||
| 3424 | + for x in (sb_x..sb_x + 64).step_by(bw) { | ||
| 3425 | + let got = Reach::of_rect(bw, bh, x, y, 256, 256); | ||
| 3426 | + let want = libaom_reach(bw, bh, x, y, 256, 256); | ||
| 3427 | + assert_eq!( | ||
| 3428 | + (got.above_right, got.below_left), | ||
| 3429 | + want, | ||
| 3430 | + "{bw}x{bh} at ({x}, {y})" | ||
| 3431 | + ); | ||
| 3432 | + } | ||
| 3433 | + } | ||
| 3434 | + } | ||
| 3435 | + } | ||
| 3436 | + } | ||
| 3437 | + } | ||
| 3438 | + | ||
| 3276 | /// Whether ffmpeg is on PATH. Absence normally SKIPs, but | 3439 | /// Whether ffmpeg is on PATH. Absence normally SKIPs, but |
| 3277 | /// `EC_AV1_REQUIRE_FFMPEG=1` -- or `EC_AV1_REQUIRE_AOMENC=1`, since every | 3440 | /// `EC_AV1_REQUIRE_FFMPEG=1` -- or `EC_AV1_REQUIRE_AOMENC=1`, since every |
| 3278 | /// aomenc gate decodes its stream through ffmpeg and is meaningless | 3441 | /// aomenc gate decodes its stream through ffmpeg and is meaningless |
crates/ec-av1/src/gate_coverage.rsmodified+0 -4
| @@ -284,10 +284,6 @@ const NEVER_ON_10BIT: &[(&str, &str)] = &[ | |||
| 284 | "enable-tx-size-search", | 284 | "enable-tx-size-search", |
| 285 | "hole at both depths, see the 8-bit list (11 of 15 pin =0)", | 285 | "hole at both depths, see the 8-bit list (11 of 15 pin =0)", |
| 286 | ), | 286 | ), |
| 287 | - ( | ||
| 288 | - "multi-tile", | ||
| 289 | - "on in no 10-bit gate: all 15 leave --tile-columns/--tile-rows defaulted at 0, so every 10-bit stream is single-tile and no tile edge or per-tile CDF reset is checked at high bit depth", | ||
| 290 | - ), | ||
| 291 | ]; | 287 | ]; |
| 292 | 288 | ||
| 293 | #[cfg(test)] | 289 | #[cfg(test)] |
crates/ec-av1/src/refusal_inventory.rsmodified+0 -2
| @@ -25,7 +25,6 @@ | |||
| 25 | #[cfg(test)] | 25 | #[cfg(test)] |
| 26 | const CAPABILITY_CLAIMS: &[&str] = &[ | 26 | const CAPABILITY_CLAIMS: &[&str] = &[ |
| 27 | "filter intra on a superblock-level HORZ/VERT strip (never expected -- av1_filter_intra_allowed_bsize caps at 32x32)", | 27 | "filter intra on a superblock-level HORZ/VERT strip (never expected -- av1_filter_intra_allowed_bsize caps at 32x32)", |
| 28 | - "a non-2D tx class on a rectangular transform (never expected at this size)", | ||
| 29 | "a non-DC chroma mode on an 8x8 inter-frame leaf (this encoder never writes one)", | 28 | "a non-DC chroma mode on an 8x8 inter-frame leaf (this encoder never writes one)", |
| 30 | "a nonzero angle delta (this encoder never writes one)", | 29 | "a nonzero angle delta (this encoder never writes one)", |
| 31 | ]; | 30 | ]; |
| @@ -36,7 +35,6 @@ const REFUSALS: &[&str] = &[ | |||
| 36 | "a coded HORZ/VERT strip whose chroma transform has no rect coefficient tables here", | 35 | "a coded HORZ/VERT strip whose chroma transform has no rect coefficient tables here", |
| 37 | "a HORZ/VERT intra strip below 16x16 with a split transform (per-unit rect prediction is not ported)", | 36 | "a HORZ/VERT intra strip below 16x16 with a split transform (per-unit rect prediction is not ported)", |
| 38 | "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)", | 37 | "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)", |
| 39 | - "a HORZ/VERT partition below 8x8 (this decoder's transform primitive is square-only; 4x8/8x4 need a real rectangular transform)", | ||
| 40 | "an inter partition below 8x8 (this decoder codes no inter leaf smaller than 8x8; lane-sub8 scoped to intra)", | 38 | "an inter partition below 8x8 (this decoder codes no inter leaf smaller than 8x8; lane-sub8 scoped to intra)", |
| 41 | "a 16x16 block whose true edge cuts through both axes needs a rectangular transform this decoder does not code yet", | 39 | "a 16x16 block whose true edge cuts through both axes needs a rectangular transform this decoder does not code yet", |
| 42 | "a 16x16 inter block whose true edge cuts through both axes needs a rectangular transform this decoder does not code yet", | 40 | "a 16x16 inter block whose true edge cuts through both axes needs a rectangular transform this decoder does not code yet", |
crates/ec-av1/src/stream.rsmodified+443 -0
| @@ -10647,6 +10647,449 @@ mod tests { | |||
| 10647 | } | 10647 | } |
| 10648 | } | 10648 | } |
| 10649 | 10649 | ||
| 10650 | + /// lane-tx4x8: `--enable-rect-partitions=1` with `--min-partition-size=4 | ||
| 10651 | + /// --max-partition-size=8` on fine-detail noisy gradients makes aomenc | ||
| 10652 | + /// pick `PARTITION_VERT`/`PARTITION_HORZ` at the 8x8 level -- two | ||
| 10653 | + /// `BLOCK_4X8`/`BLOCK_8X4` leaves, the last sub-8x8 shape this decoder | ||
| 10654 | + /// refused (it needed a real `TX_4X8`/`TX_8X4`: rect scan, 32-position | ||
| 10655 | + /// `eob_pt`, `TX_4X4` `tx_type` row over `TX_8X8` coefficient tables). | ||
| 10656 | + /// Both [`decode::tx4x8_coded_hits`] and [`decode::tx8x4_coded_hits`] are | ||
| 10657 | + /// hard-asserted per firing attempt so neither orientation can ride along | ||
| 10658 | + /// on the other ([[gate-blind-to-feature]]), and only leaves that coded | ||
| 10659 | + /// REAL coefficients count -- a skipped leaf never runs the transform. | ||
| 10660 | + /// Arms: 8-bit 16x16, an 8-bit `--tile-columns=1` 128x16 (the mi-granular | ||
| 10661 | + /// mode maps are per tile), and a 10-bit 16x16 -- 16-pixel fixtures, for | ||
| 10662 | + /// the reason the comment inside the loop gives. | ||
| 10663 | + #[test] | ||
| 10664 | + fn a_real_aomenc_stream_with_a_sub8_rect_leaf_decodes_pixel_exact() { | ||
| 10665 | + const NAME: &str = "a_real_aomenc_stream_with_a_sub8_rect_leaf_decodes_pixel_exact"; | ||
| 10666 | + if !have_ffmpeg() { | ||
| 10667 | + eprintln!("SKIP {NAME}: no ffmpeg"); | ||
| 10668 | + return; | ||
| 10669 | + } | ||
| 10670 | + if !have_aomenc() { | ||
| 10671 | + let msg = format!("no aomenc at {}", aomenc_path().display()); | ||
| 10672 | + assert!( | ||
| 10673 | + std::env::var_os("EC_AV1_REQUIRE_AOMENC").is_none(), | ||
| 10674 | + "EC_AV1_REQUIRE_AOMENC is set but {msg}" | ||
| 10675 | + ); | ||
| 10676 | + eprintln!("SKIP {NAME}: {msg}"); | ||
| 10677 | + return; | ||
| 10678 | + } | ||
| 10679 | + // 16-pixel-tall/wide fixtures on purpose: at 64x64 EVERY attempt | ||
| 10680 | + // dies on a 16x16-LEVEL rect refusal belonging to other lanes | ||
| 10681 | + // ("a HORZ/VERT intra strip with a split transform", "a coded | ||
| 10682 | + // (non-skip) HORZ/VERT rect strip below 16x16", "a HORZ_A/HORZ_B/ | ||
| 10683 | + // VERT_A partition below 16x16") -- `--max-partition-size=8` does | ||
| 10684 | + // NOT stop aomenc coding a 16x16 as two 16x8 strips, measured | ||
| 10685 | + // 39/40 attempts refused. A 16x16 frame is one 16x16 block, so the | ||
| 10686 | + // encoder either splits it to 8x8s (this lane's path) or codes it | ||
| 10687 | + // whole; measured 12/12 attempts decoding, 3/12 with BOTH | ||
| 10688 | + // orientations coded. | ||
| 10689 | + for (width, height, tile_args, bit_depth) in [ | ||
| 10690 | + (16usize, 16usize, &[][..], 8u8), | ||
| 10691 | + (128usize, 16usize, &["--tile-columns=1"][..], 8u8), | ||
| 10692 | + (16usize, 16usize, &[][..], 10u8), | ||
| 10693 | + ] { | ||
| 10694 | + let mut refusals = Vec::new(); | ||
| 10695 | + let mut fired_runs = 0u32; | ||
| 10696 | + let mut split_tx = 0usize; | ||
| 10697 | + for attempt in 0..40u32 { | ||
| 10698 | + let seed = 300 + attempt; | ||
| 10699 | + let cq = 6 + (attempt % 4) * 2; | ||
| 10700 | + let pix_fmt = if bit_depth == 10 { | ||
| 10701 | + "yuv420p10le" | ||
| 10702 | + } else { | ||
| 10703 | + "yuv420p" | ||
| 10704 | + }; | ||
| 10705 | + let y4m = Command::new("ffmpeg") | ||
| 10706 | + .args([ | ||
| 10707 | + "-v", | ||
| 10708 | + "error", | ||
| 10709 | + "-f", | ||
| 10710 | + "lavfi", | ||
| 10711 | + "-i", | ||
| 10712 | + &format!("testsrc2=size={width}x{height}:rate=25"), | ||
| 10713 | + "-vf", | ||
| 10714 | + &format!("noise=alls=40:allf=t:all_seed={seed},format={pix_fmt}"), | ||
| 10715 | + "-strict", | ||
| 10716 | + "-1", | ||
| 10717 | + "-t", | ||
| 10718 | + "0.04", | ||
| 10719 | + "-f", | ||
| 10720 | + "yuv4mpegpipe", | ||
| 10721 | + "-", | ||
| 10722 | + ]) | ||
| 10723 | + .stdin(Stdio::null()) | ||
| 10724 | + .stdout(Stdio::piped()) | ||
| 10725 | + .stderr(Stdio::piped()) | ||
| 10726 | + .output() | ||
| 10727 | + .expect("ffmpeg failed to run"); | ||
| 10728 | + assert!( | ||
| 10729 | + y4m.status.success(), | ||
| 10730 | + "ffmpeg fixture: {}", | ||
| 10731 | + String::from_utf8_lossy(&y4m.stderr) | ||
| 10732 | + ); | ||
| 10733 | + let mut child = Command::new(aomenc_path()) | ||
| 10734 | + .args([ | ||
| 10735 | + "--codec=av1", | ||
| 10736 | + "--passes=1", | ||
| 10737 | + "--end-usage=q", | ||
| 10738 | + &format!("--cq-level={cq}"), | ||
| 10739 | + "--cpu-used=0", | ||
| 10740 | + "--threads=1", | ||
| 10741 | + "--row-mt=0", | ||
| 10742 | + "--sb-size=64", | ||
| 10743 | + "--min-partition-size=4", | ||
| 10744 | + "--max-partition-size=8", | ||
| 10745 | + // The tool under test: rect partitions ON, at a size | ||
| 10746 | + // where the only rect shapes are 4x8 and 8x4. | ||
| 10747 | + "--enable-rect-partitions=1", | ||
| 10748 | + "--enable-ab-partitions=0", | ||
| 10749 | + "--enable-1to4-partitions=0", | ||
| 10750 | + "--enable-palette=0", | ||
| 10751 | + "--enable-intrabc=0", | ||
| 10752 | + "--enable-restoration=0", | ||
| 10753 | + "--enable-cdef=0", | ||
| 10754 | + "--loopfilter-control=0", | ||
| 10755 | + "--enable-ref-frame-mvs=0", | ||
| 10756 | + // Filter intra on a 4x8/8x4 leaf is refused by name | ||
| 10757 | + // (`predict_filter_intra` is square-only in this | ||
| 10758 | + // decoder, the same refusal the 16x16-level strips | ||
| 10759 | + // carry); with it on, that refusal -- not this | ||
| 10760 | + // lane's path -- is what most attempts hit. | ||
| 10761 | + "--enable-filter-intra=0", | ||
| 10762 | + "--limit=1", | ||
| 10763 | + "--obu", | ||
| 10764 | + "-o", | ||
| 10765 | + "-", | ||
| 10766 | + "-", | ||
| 10767 | + ]) | ||
| 10768 | + .args(if bit_depth == 10 { | ||
| 10769 | + &["--input-bit-depth=10", "--bit-depth=10"][..] | ||
| 10770 | + } else { | ||
| 10771 | + &[][..] | ||
| 10772 | + }) | ||
| 10773 | + .args(tile_args) | ||
| 10774 | + .stdin(Stdio::piped()) | ||
| 10775 | + .stdout(Stdio::piped()) | ||
| 10776 | + .stderr(Stdio::piped()) | ||
| 10777 | + .spawn() | ||
| 10778 | + .expect("aomenc failed to start"); | ||
| 10779 | + child | ||
| 10780 | + .stdin | ||
| 10781 | + .take() | ||
| 10782 | + .expect("aomenc stdin") | ||
| 10783 | + .write_all(&y4m.stdout) | ||
| 10784 | + .expect("writing y4m to aomenc"); | ||
| 10785 | + let out = child.wait_with_output().expect("aomenc failed to run"); | ||
| 10786 | + if !out.status.success() { | ||
| 10787 | + refusals.push(format!( | ||
| 10788 | + "seed={seed} cq={cq}: aomenc itself refused the fixture" | ||
| 10789 | + )); | ||
| 10790 | + continue; | ||
| 10791 | + } | ||
| 10792 | + let stream = out.stdout; | ||
| 10793 | + let vert_before = decode::tx4x8_coded_hits(); | ||
| 10794 | + let horz_before = decode::tx8x4_coded_hits(); | ||
| 10795 | + let split_before = decode::rect8_split_tx_hits(); | ||
| 10796 | + let tiles_before = decode::tile_hits(); | ||
| 10797 | + let frames = match decode_stream(&stream) { | ||
| 10798 | + Ok(frames) => frames, | ||
| 10799 | + Err(e) => { | ||
| 10800 | + let msg = e.to_string(); | ||
| 10801 | + assert!( | ||
| 10802 | + msg.starts_with("unsupported: "), | ||
| 10803 | + "decode error that is not a named refusal \ | ||
| 10804 | + (seed={seed} cq={cq} depth={bit_depth} tiles={tile_args:?}): {msg}" | ||
| 10805 | + ); | ||
| 10806 | + refusals.push(format!("seed={seed} cq={cq}: {msg}")); | ||
| 10807 | + continue; | ||
| 10808 | + } | ||
| 10809 | + }; | ||
| 10810 | + assert!( | ||
| 10811 | + tile_args.is_empty() || decode::tile_hits() - tiles_before >= 2, | ||
| 10812 | + "tiles={tile_args:?} decoded only {} tile(s) (seed={seed} cq={cq})", | ||
| 10813 | + decode::tile_hits() - tiles_before | ||
| 10814 | + ); | ||
| 10815 | + let vert = decode::tx4x8_coded_hits() - vert_before; | ||
| 10816 | + let horz = decode::tx8x4_coded_hits() - horz_before; | ||
| 10817 | + if vert == 0 || horz == 0 { | ||
| 10818 | + refusals.push(format!( | ||
| 10819 | + "seed={seed} cq={cq}: decoded, but coded 4x8={vert} 8x4={horz} leaves" | ||
| 10820 | + )); | ||
| 10821 | + continue; | ||
| 10822 | + } | ||
| 10823 | + let ffmpeg_frames = if bit_depth == 10 { | ||
| 10824 | + ffmpeg_decode_sequence_10bit(&stream, width, height, 1) | ||
| 10825 | + } else { | ||
| 10826 | + ffmpeg_decode_sequence(&stream, width, height, 1) | ||
| 10827 | + }; | ||
| 10828 | + assert_eq!( | ||
| 10829 | + frames[0].y, ffmpeg_frames[0].y, | ||
| 10830 | + "luma vs ffmpeg (seed={seed} cq={cq} depth={bit_depth} tiles={tile_args:?})" | ||
| 10831 | + ); | ||
| 10832 | + assert_eq!( | ||
| 10833 | + frames[0].u, ffmpeg_frames[0].u, | ||
| 10834 | + "U vs ffmpeg (seed={seed} cq={cq} depth={bit_depth})" | ||
| 10835 | + ); | ||
| 10836 | + assert_eq!( | ||
| 10837 | + frames[0].v, ffmpeg_frames[0].v, | ||
| 10838 | + "V vs ffmpeg (seed={seed} cq={cq} depth={bit_depth})" | ||
| 10839 | + ); | ||
| 10840 | + fired_runs += 1; | ||
| 10841 | + split_tx += decode::rect8_split_tx_hits() - split_before; | ||
| 10842 | + if fired_runs >= 4 { | ||
| 10843 | + break; | ||
| 10844 | + } | ||
| 10845 | + } | ||
| 10846 | + assert!( | ||
| 10847 | + fired_runs >= 4, | ||
| 10848 | + "fewer than 4 firing+pixel-exact runs out of 40 attempts \ | ||
| 10849 | + ({width}x{height} depth={bit_depth} tiles={tile_args:?}):\n{}", | ||
| 10850 | + refusals.join("\n") | ||
| 10851 | + ); | ||
| 10852 | + // aomenc's default `--enable-tx-size-search=1` makes TX_MODE_SELECT | ||
| 10853 | + // the frame's tx mode, so every sub-8x8 rect leaf carries a | ||
| 10854 | + // `tx_depth` symbol; depth 1 (two 4x4 transform units predicted one | ||
| 10855 | + // after the other) is the half of that path a whole-leaf transform | ||
| 10856 | + // would silently get wrong, so the gate proves it fired. | ||
| 10857 | + assert!( | ||
| 10858 | + split_tx > 0, | ||
| 10859 | + "no sub-8x8 rect leaf used a split (depth-1) transform in the \ | ||
| 10860 | + {fired_runs} pixel-exact runs ({width}x{height} depth={bit_depth})" | ||
| 10861 | + ); | ||
| 10862 | + } | ||
| 10863 | + } | ||
| 10864 | + | ||
| 10865 | + /// lane-tx4x8 r3 ([[enumerate-table-domain]], [[tool-disabled-in-every-gate]]): | ||
| 10866 | + /// a 16x8/8x16 intra strip whose DIRECTIONAL mode reads above-right or | ||
| 10867 | + /// below-left samples. Which of those the decoder may read is | ||
| 10868 | + /// `Reach::of_rect`'s answer, and until this round `rect_reach_tables` | ||
| 10869 | + /// had no 16x8 row at all -- every 16x8 strip read libaom's `has_tr_32x16` | ||
| 10870 | + /// row instead of `has_tr_16x8`, wrong at 10 of the 21 reachable | ||
| 10871 | + /// superblock positions for above-right and 7 for below-left. No gate saw | ||
| 10872 | + /// it: the sibling strip gate (`coded_rect_strip_below_16x16`) runs with | ||
| 10873 | + /// smooth/paeth/DC modes, which never read past the block, so the wrong | ||
| 10874 | + /// bit changed no pixel there. | ||
| 10875 | + /// | ||
| 10876 | + /// So this gate turns every non-directional intra tool OFF | ||
| 10877 | + /// (`--enable-smooth-intra=0 --enable-paeth-intra=0 | ||
| 10878 | + /// --enable-filter-intra=0`) at `--min-partition-size=8 | ||
| 10879 | + /// --max-partition-size=16 --enable-rect-partitions=1`, and counts, per | ||
| 10880 | + /// attempt, the 16x8/8x16 strips whose prediction actually reached past | ||
| 10881 | + /// their own width or height ([`decode::rect_strip_reach_hits`], recorded | ||
| 10882 | + /// in the predictor's edge fetch). An attempt only counts when that | ||
| 10883 | + /// counter moved AND the frame is pixel-exact against ffmpeg. | ||
| 10884 | + /// | ||
| 10885 | + /// BLOCKED, and `#[ignore]`d for it, not skipped from inside | ||
| 10886 | + /// ([[gate-skips-on-its-own-failure]]): the 16x16-level strip decoder | ||
| 10887 | + /// refuses every NON-SKIP 16x8/8x16 strip ("a coded (non-skip) HORZ/VERT | ||
| 10888 | + /// rect strip below 16x16", `decode.rs`), and that is what real streams | ||
| 10889 | + /// contain -- measured on this exact recipe, 38 of 40 attempts died on | ||
| 10890 | + /// that refusal and 2 on a sub-16x16 AB partition, at cq 30/45/58 and at | ||
| 10891 | + /// `--min-partition-size=16` (which yields no 16x8 at all, aomenc bounds a | ||
| 10892 | + /// rect shape by its smaller side). What unblocks it: the lane that ports | ||
| 10893 | + /// the coded 16x16-level strip; then drop this attribute. Until then the | ||
| 10894 | + /// table routing is pinned by the domain test | ||
| 10895 | + /// `encode::tests::every_rect_shape_reaches_what_libaom_says_over_the_whole_superblock` | ||
| 10896 | + /// against libaom's own `has_tr_*`/`has_bl_*` arrays. | ||
| 10897 | + #[test] | ||
| 10898 | + #[ignore = "the coded 16x8/8x16 strip is a live refusal; see the doc above"] | ||
| 10899 | + fn a_directional_16x8_strip_reads_the_right_above_right_samples() { | ||
| 10900 | + const NAME: &str = "a_directional_16x8_strip_reads_the_right_above_right_samples"; | ||
| 10901 | + if !have_ffmpeg() { | ||
| 10902 | + eprintln!("SKIP {NAME}: no ffmpeg"); | ||
| 10903 | + return; | ||
| 10904 | + } | ||
| 10905 | + if !have_aomenc() { | ||
| 10906 | + let msg = format!("no aomenc at {}", aomenc_path().display()); | ||
| 10907 | + assert!( | ||
| 10908 | + std::env::var_os("EC_AV1_REQUIRE_AOMENC").is_none(), | ||
| 10909 | + "EC_AV1_REQUIRE_AOMENC is set but {msg}" | ||
| 10910 | + ); | ||
| 10911 | + eprintln!("SKIP {NAME}: {msg}"); | ||
| 10912 | + return; | ||
| 10913 | + } | ||
| 10914 | + // 64x16, not 64x64: a 16-tall frame is a single row of 16x16 blocks, | ||
| 10915 | + // so a HORZ arm is a 16x8 strip at column 0..3 of the superblock -- | ||
| 10916 | + // exactly the positions whose `has_tr_16x8`/`has_bl_16x8` bit the old | ||
| 10917 | + // routing got wrong -- while the frame is too short for aomenc to | ||
| 10918 | + // build the deep sub-16x16 partitions other lanes still refuse. It | ||
| 10919 | + // must also be WIDER than one block: at width 16 the block is the | ||
| 10920 | + // frame, and `x + bw < width` kills above-right before any table. | ||
| 10921 | + for (width, height, bit_depth) in [(64usize, 16usize, 8u8), (64, 16, 10u8)] { | ||
| 10922 | + let mut refusals = Vec::new(); | ||
| 10923 | + let mut fired_runs = 0u32; | ||
| 10924 | + let mut reach_hits = 0usize; | ||
| 10925 | + for attempt in 0..40u32 { | ||
| 10926 | + let seed = 700 + attempt; | ||
| 10927 | + // Coarse quantisers on lightly-dithered content: fine detail | ||
| 10928 | + // at low cq makes aomenc build the sub-16x16 partitions other | ||
| 10929 | + // lanes refuse, and 40/40 attempts died there. | ||
| 10930 | + let cq = 45 + (attempt % 4); | ||
| 10931 | + let half = height / 2; | ||
| 10932 | + let pix_fmt = if bit_depth == 10 { | ||
| 10933 | + "yuv420p10le" | ||
| 10934 | + } else { | ||
| 10935 | + "yuv420p" | ||
| 10936 | + }; | ||
| 10937 | + let y4m = Command::new("ffmpeg") | ||
| 10938 | + .args([ | ||
| 10939 | + "-v", | ||
| 10940 | + "error", | ||
| 10941 | + "-f", | ||
| 10942 | + "lavfi", | ||
| 10943 | + "-i", | ||
| 10944 | + &format!("testsrc2=size={width}x{half}:rate=25"), | ||
| 10945 | + "-f", | ||
| 10946 | + "lavfi", | ||
| 10947 | + "-i", | ||
| 10948 | + &format!("color=c=gray:s={width}x{half}:rate=25"), | ||
| 10949 | + "-filter_complex", | ||
| 10950 | + &format!( | ||
| 10951 | + "[0]noise=alls=8:allf=t:all_seed={seed}[t];[t][1]vstack,\ | ||
| 10952 | + format={pix_fmt}" | ||
| 10953 | + ), | ||
| 10954 | + "-strict", | ||
| 10955 | + "-1", | ||
| 10956 | + "-t", | ||
| 10957 | + "0.04", | ||
| 10958 | + "-f", | ||
| 10959 | + "yuv4mpegpipe", | ||
| 10960 | + "-", | ||
| 10961 | + ]) | ||
| 10962 | + .stdin(Stdio::null()) | ||
| 10963 | + .stdout(Stdio::piped()) | ||
| 10964 | + .stderr(Stdio::piped()) | ||
| 10965 | + .output() | ||
| 10966 | + .expect("ffmpeg failed to run"); | ||
| 10967 | + assert!( | ||
| 10968 | + y4m.status.success(), | ||
| 10969 | + "ffmpeg fixture: {}", | ||
| 10970 | + String::from_utf8_lossy(&y4m.stderr) | ||
| 10971 | + ); | ||
| 10972 | + let mut child = Command::new(aomenc_path()) | ||
| 10973 | + .args([ | ||
| 10974 | + "--codec=av1", | ||
| 10975 | + "--passes=1", | ||
| 10976 | + "--end-usage=q", | ||
| 10977 | + &format!("--cq-level={cq}"), | ||
| 10978 | + "--cpu-used=0", | ||
| 10979 | + "--threads=1", | ||
| 10980 | + "--row-mt=0", | ||
| 10981 | + "--sb-size=64", | ||
| 10982 | + // The tool under test: 16x8/8x16 strips, predicted by | ||
| 10983 | + // a mode that reads beyond the block. | ||
| 10984 | + // aomenc bounds a RECT shape by its smaller side, so | ||
| 10985 | + // `--min-partition-size=16` yields no 16x8 at all | ||
| 10986 | + // (measured: 0 strips in 40 attempts); 8 is the | ||
| 10987 | + // smallest value that lets a 16x16 split HORZ/VERT. | ||
| 10988 | + "--min-partition-size=8", | ||
| 10989 | + "--max-partition-size=16", | ||
| 10990 | + // Largest transform per block: a split (depth-1) rect | ||
| 10991 | + // strip is a named refusal of another lane, and it | ||
| 10992 | + // ate every attempt while it was on. | ||
| 10993 | + "--enable-tx-size-search=0", | ||
| 10994 | + "--enable-rect-partitions=1", | ||
| 10995 | + "--enable-directional-intra=1", | ||
| 10996 | + "--enable-smooth-intra=0", | ||
| 10997 | + "--enable-paeth-intra=0", | ||
| 10998 | + "--enable-filter-intra=0", | ||
| 10999 | + "--enable-ab-partitions=0", | ||
| 11000 | + "--enable-1to4-partitions=0", | ||
| 11001 | + "--enable-palette=0", | ||
| 11002 | + "--enable-intrabc=0", | ||
| 11003 | + "--enable-restoration=0", | ||
| 11004 | + "--enable-cdef=0", | ||
| 11005 | + "--loopfilter-control=0", | ||
| 11006 | + "--enable-ref-frame-mvs=0", | ||
| 11007 | + "--limit=1", | ||
| 11008 | + "--obu", | ||
| 11009 | + "-o", | ||
| 11010 | + "-", | ||
| 11011 | + "-", | ||
| 11012 | + ]) | ||
| 11013 | + .args(if bit_depth == 10 { | ||
| 11014 | + &["--input-bit-depth=10", "--bit-depth=10"][..] | ||
| 11015 | + } else { | ||
| 11016 | + &[][..] | ||
| 11017 | + }) | ||
| 11018 | + .stdin(Stdio::piped()) | ||
| 11019 | + .stdout(Stdio::piped()) | ||
| 11020 | + .stderr(Stdio::piped()) | ||
| 11021 | + .spawn() | ||
| 11022 | + .expect("aomenc failed to start"); | ||
| 11023 | + child | ||
| 11024 | + .stdin | ||
| 11025 | + .take() | ||
| 11026 | + .expect("aomenc stdin") | ||
| 11027 | + .write_all(&y4m.stdout) | ||
| 11028 | + .expect("writing y4m to aomenc"); | ||
| 11029 | + let out = child.wait_with_output().expect("aomenc failed to run"); | ||
| 11030 | + if !out.status.success() { | ||
| 11031 | + refusals.push(format!( | ||
| 11032 | + "seed={seed} cq={cq}: aomenc itself refused the fixture" | ||
| 11033 | + )); | ||
| 11034 | + continue; | ||
| 11035 | + } | ||
| 11036 | + let stream = out.stdout; | ||
| 11037 | + let reach_before = decode::rect_strip_reach_hits(); | ||
| 11038 | + let pred_before = decode::rect_strip_pred_hits(); | ||
| 11039 | + let frames = match decode_stream(&stream) { | ||
| 11040 | + Ok(frames) => frames, | ||
| 11041 | + Err(e) => { | ||
| 11042 | + let msg = e.to_string(); | ||
| 11043 | + assert!( | ||
| 11044 | + msg.starts_with("unsupported: "), | ||
| 11045 | + "decode error that is not a named refusal \ | ||
| 11046 | + (seed={seed} cq={cq} depth={bit_depth}): {msg}" | ||
| 11047 | + ); | ||
| 11048 | + refusals.push(format!("seed={seed} cq={cq}: {msg}")); | ||
| 11049 | + continue; | ||
| 11050 | + } | ||
| 11051 | + }; | ||
| 11052 | + let reached = decode::rect_strip_reach_hits() - reach_before; | ||
| 11053 | + let predicted = decode::rect_strip_pred_hits() - pred_before; | ||
| 11054 | + if predicted == 0 { | ||
| 11055 | + refusals.push(format!( | ||
| 11056 | + "seed={seed} cq={cq}: decoded, but no 16x8/8x16 strip in the frame" | ||
| 11057 | + )); | ||
| 11058 | + continue; | ||
| 11059 | + } | ||
| 11060 | + let ffmpeg_frames = if bit_depth == 10 { | ||
| 11061 | + ffmpeg_decode_sequence_10bit(&stream, width, height, 1) | ||
| 11062 | + } else { | ||
| 11063 | + ffmpeg_decode_sequence(&stream, width, height, 1) | ||
| 11064 | + }; | ||
| 11065 | + assert_eq!( | ||
| 11066 | + frames[0].y, ffmpeg_frames[0].y, | ||
| 11067 | + "luma vs ffmpeg (seed={seed} cq={cq} depth={bit_depth}, {predicted} strips, \ | ||
| 11068 | + {reached} of them reaching)" | ||
| 11069 | + ); | ||
| 11070 | + assert_eq!( | ||
| 11071 | + frames[0].u, ffmpeg_frames[0].u, | ||
| 11072 | + "U vs ffmpeg (seed={seed} cq={cq} depth={bit_depth})" | ||
| 11073 | + ); | ||
| 11074 | + assert_eq!( | ||
| 11075 | + frames[0].v, ffmpeg_frames[0].v, | ||
| 11076 | + "V vs ffmpeg (seed={seed} cq={cq} depth={bit_depth})" | ||
| 11077 | + ); | ||
| 11078 | + fired_runs += 1; | ||
| 11079 | + reach_hits += reached; | ||
| 11080 | + if fired_runs >= 4 { | ||
| 11081 | + break; | ||
| 11082 | + } | ||
| 11083 | + } | ||
| 11084 | + assert!( | ||
| 11085 | + fired_runs >= 4, | ||
| 11086 | + "fewer than 4 firing+pixel-exact runs out of 40 attempts \ | ||
| 11087 | + ({width}x{height} depth={bit_depth}, {reach_hits} reaching strips):\n{}", | ||
| 11088 | + refusals.join("\n") | ||
| 11089 | + ); | ||
| 11090 | + } | ||
| 11091 | + } | ||
| 11092 | + | ||
| 10650 | /// lane-av1golden7 r9's decisive fixture: a real aomenc stream (seed 59, | 11093 | /// lane-av1golden7 r9's decisive fixture: a real aomenc stream (seed 59, |
| 10651 | /// `--tune-content=film`, GOLDEN_FRAME firing downstream) whose frame-0 | 11094 | /// `--tune-content=film`, GOLDEN_FRAME firing downstream) whose frame-0 |
| 10652 | /// *intra keyframe* mismatched ffmpeg on 3855/4096 luma pixels -- traced | 11095 | /// *intra keyframe* mismatched ffmpeg on 3855/4096 luma pixels -- traced |
lanes/tx4x8-r1.report.mdadded+92 -0
| @@ -0,0 +1,92 @@ | |||
| 1 | +# lane-tx4x8 round 1 — TX_4X8/TX_8X4 end to end (gate RED, first divergence not yet isolated) | ||
| 2 | + | ||
| 3 | +Branch `lane-tx4x8` off `lane-sub8` b500160. NOT rebased onto main (charter order). | ||
| 4 | + | ||
| 5 | +## What changed | ||
| 6 | + | ||
| 7 | +* `crates/ec-av1/src/cdf.rs` — `EOB_PT_32_LUMA{,_Q0,_Q1,_Q3}` + `_CLASS1` siblings, | ||
| 8 | + transcribed from `av1_default_eob_multi32_cdfs` (`token_cdfs.h:792`), luma plane, both | ||
| 9 | + tx-class rows. Format cross-checked against the already-pinned `EOB_PT_16_LUMA_CLASS1_Q0`. | ||
| 10 | +* `crates/ec-av1/src/cdf_state.rs` — `eob_pt_32_luma{,_class1}` state + q-ctx `pick` + counter | ||
| 11 | + reset; `TxbSet::LumaRect4x8`/`LumaRect4x8Set1`. Derivation: `get_txsize_entropy_ctx(TX_4X8)` | ||
| 12 | + = `(txsize_sqr_map=TX_4X4 + txsize_sqr_up_map=TX_8X8 + 1) >> 1` = **TX_8X8**, so every | ||
| 13 | + coefficient table is `Luma8`'s; `read_tx_type`'s CDF row is `txsize_sqr_map[TX_4X8]` = | ||
| 14 | + **TX_4X4**, so the `tx_type` table is `Luma4`/`Luma4Set1`'s; `eob_pt` is the true | ||
| 15 | + 32-position table (`txsize_log2_minus4[TX_4X8] == 1` -> `eob_flag_cdf32`). | ||
| 16 | + (class `table-indexed-by-raw-size`: three different size keys in one variant.) | ||
| 17 | +* `crates/ec-av1/src/decode.rs` — | ||
| 18 | + - `SCAN_4X8`/`SCAN_8X4` (libaom `default_scan_4x8`/`8x4`), `class_scan_table_wh` | ||
| 19 | + (`mrow`/`mcol` at rect sizes). Conversion `(p % h) * w + p / h` **re-proved first** by | ||
| 20 | + regenerating the committed `SCAN_16X8`/`SCAN_8X16` from the same source (heads matched). | ||
| 21 | + - `base_ctx_rect`/`br_ctx_rect` gained a `TxClass` (the 1D-class arms are shape-independent | ||
| 22 | + in libaom's `get_nz_map_ctx_from_stats`; no new `av1_nz_map_ctx_offset_*` table is needed — | ||
| 23 | + the `w<h -> 11+ctx` / `w>h -> 16+ctx` rule already in `base_ctx_rect` IS that table). | ||
| 24 | + - `read_coeffs_rect` now reads a real `tx_type` symbol and honours `V_DCT`/`H_DCT` | ||
| 25 | + (rect class scan + class contexts + `eob_pt_class1`). Two capability-claim refusals | ||
| 26 | + deleted. | ||
| 27 | + - `decode_leaf_rect8` — the `PARTITION_HORZ`/`VERT` leaf of an 8x8: two `BLOCK_8X4`/`4X8` | ||
| 28 | + sub-blocks, mode reads via `read_intra_mode_sub8`, chroma once on the last sub-block at the | ||
| 29 | + group's 4x4 unit, `dequant_and_inverse_typed_wh` (the rect transform primitive, its | ||
| 30 | + `abs(rect_type)==1` `NewInvSqrt2` scale and `av1_inv_txfm_shift_ls[TX_4X8]` row, already | ||
| 31 | + existed and needed no change), `Reach::of_rect`, `fill_lf_grid_rect(bw, bh)` for the | ||
| 32 | + deblock grid, `partition_context_lookup[BLOCK_4X8] = {31,30}` / `[BLOCK_8X4] = {30,31}`. | ||
| 33 | + Wired at BOTH sub-8x8 partition sites; the leftover `else` is now `unreachable!` | ||
| 34 | + (`partition_w8` is a 4-symbol CDF). | ||
| 35 | + - counters `tx4x8_coded_hits`/`tx8x4_coded_hits` (leaves with REAL coefficients only). | ||
| 36 | + - 4 new table tests (transposed-pair scan gate, class-1 scan pins, eob table shape, | ||
| 37 | + shape-specific reach). | ||
| 38 | +* `crates/ec-av1/src/encode.rs` — `has_tr_4x8`/`has_tr_8x4`/`has_bl_4x8`/`has_bl_8x4` | ||
| 39 | + transcribed verbatim; `rect_reach_tables(bw, bh)` replaces the `bw == 16` two-way pick. | ||
| 40 | +* `crates/ec-av1/src/refusal_inventory.rs` — three refusals removed: the 4x8/8x4 partition | ||
| 41 | + refusal and the two rect `tx_type`/`tx class` capability claims. | ||
| 42 | +* `crates/ec-av1/src/stream.rs` — gate | ||
| 43 | + `a_real_aomenc_stream_with_a_sub8_rect_leaf_decodes_pixel_exact`, three arms | ||
| 44 | + (8-bit 16x16, 8-bit 128x16 `--tile-columns=1`, 10-bit 16x16), `--enable-rect-partitions=1 | ||
| 45 | + --min-partition-size=4 --max-partition-size=8`, per-attempt hard assert that BOTH | ||
| 46 | + `tx4x8_coded_hits` and `tx8x4_coded_hits` moved, named refusals only, no SKIP on error. | ||
| 47 | + | ||
| 48 | +## Gate: RED | ||
| 49 | + | ||
| 50 | +`EC_AV1_REQUIRE_AOMENC=1 cargo test -p ec-av1 --lib sub8_rect_leaf` | ||
| 51 | +-> `luma vs ffmpeg (seed=303 cq=12 depth=8 tiles=[])`, mismatch from sample 0 of a 16x16 | ||
| 52 | +frame; ours is near-flat (126..142), ffmpeg's is full-range (0..229). The decode does not | ||
| 53 | +error, so this is wrong coefficients/reconstruction (or an entropy divergence inside the | ||
| 54 | +first rect leaf), not a refusal. | ||
| 55 | + | ||
| 56 | +EVIDENCE: cargo test output above | 40 attempts x 3 arms, aomenc --enable-rect-partitions=1 | ||
| 57 | +--min-partition-size=4 --max-partition-size=8 --enable-filter-intra=0 on testsrc2+noise 16x16 | | ||
| 58 | +first firing attempt (seed 303) mismatches luma at index 0; 291 other lib tests unaffected at | ||
| 59 | +the time of the run. | ||
| 60 | + | ||
| 61 | +EVIDENCE: probe sweep with examples/decode_probe + EC_AV1_TRACE=1 | 12 seeds x 16x16, 12 x | ||
| 62 | +32x32, --enable-filter-intra=0 | 16x16: 12/12 decode without any refusal, 3/12 code BOTH | ||
| 63 | +orientations, 9/12 at least one; 32x32: 1/12 (11 die on 16x16-LEVEL rect refusals owned by | ||
| 64 | +other lanes) — this is why the gate uses 16x16/128x16 fixtures. | ||
| 65 | + | ||
| 66 | +## Recipe findings (cite before reusing) | ||
| 67 | + | ||
| 68 | +* `--max-partition-size=8` does NOT stop aomenc coding a 16x16 block as two 16x8 strips: at | ||
| 69 | + 64x64, 39/40 attempts refuse on 16x16-level rect gaps ("a HORZ/VERT intra strip with a split | ||
| 70 | + transform", "a coded (non-skip) HORZ/VERT rect strip below 16x16", "a HORZ_A/HORZ_B/VERT_A | ||
| 71 | + partition below 16x16"). Only a 16-pixel frame dimension isolates the 8x8 level. | ||
| 72 | +* With `--enable-filter-intra=1`, most attempts die on the pre-existing square-only filter-intra | ||
| 73 | + refusal, which `decode_leaf_rect8` re-raises by name for a 4x8 leaf. | ||
| 74 | +* A probe sweep whose binary path was wrong reported "OK, 0 hits" for every cell | ||
| 75 | + (class `stale-output-faked-measurement`): always `ls -l` the probe binary in the lane's own | ||
| 76 | + `CARGO_TARGET_DIR` first. The first sweep in this round was invalid for exactly that reason. | ||
| 77 | + | ||
| 78 | +## Residue | ||
| 79 | + | ||
| 80 | +* fix-now (next round): the pixel mismatch. Nothing in the ladder below was disproved this | ||
| 81 | + round, ranked by suspicion: | ||
| 82 | + 1. an entropy divergence at the FIRST rect leaf (range ladder vs instrumented aomdec, | ||
| 83 | + `EC_TRACE_COEFF`, on the pinned seed-303 stream) — ours decoding a near-flat frame is | ||
| 84 | + consistent with an `eob`/`all_zero` read off the wrong table; | ||
| 85 | + 2. `TxbSet::LumaRect4x8`'s three-way table split (coeff tables TX_8X8 / tx_type row TX_4X4 / | ||
| 86 | + eob 32) — verify each against `read_coeffs_txb` live, not against my derivation; | ||
| 87 | + 3. `dequant_wh` / the rect transform at (4,8) — never exercised below 16x8 before this lane; | ||
| 88 | + 4. `Reach::of_rect` at 4x8/8x4 (localized errors only — would not explain sample 0). | ||
| 89 | +* deferred: `--tile-columns=1` arm result — not separable while arm 1 is red — unblocked by | ||
| 90 | + the fix above. | ||
| 91 | +* deferred: filter intra on a 4x8/8x4 leaf — `predict_filter_intra` is square-only — unblocked | ||
| 92 | + by a rect filter-intra predictor (same refusal the 16x16-level strips carry). | ||
lanes/tx4x8-r2.report.mdadded+79 -0
| @@ -0,0 +1,79 @@ | |||
| 1 | +# lane-tx4x8 round 2 — the RED gate's root cause: a tx_depth symbol never read | ||
| 2 | + | ||
| 3 | +Branch `lane-tx4x8`, commit `3677783` off r1's `efed7ee` (not rebased onto main, charter order). | ||
| 4 | + | ||
| 5 | +## Root cause | ||
| 6 | + | ||
| 7 | +`decode_leaf_rect8` (decode.rs:6081) read `skip`/`y_mode`/`uv_mode` and went straight to the | ||
| 8 | +leaf's coefficients. libaom's `av1_read_tx_size` writes a `tx_depth` symbol for every intra | ||
| 9 | +block with `block_signals_txsize(bsize)` — true for `BLOCK_4X8`/`BLOCK_8X4` — whenever the | ||
| 10 | +frame's tx mode is `TX_MODE_SELECT`, which aomenc's **default** `--enable-tx-size-search=1` | ||
| 11 | +selects and no gate recipe turns off. We consumed one symbol fewer than the encoder wrote, so | ||
| 12 | +the tile desynced at the very first rect leaf and every later symbol read garbage that | ||
| 13 | +decoded as near-zero residual (hence "near-flat 126..142 from sample 0, no decode error"). | ||
| 14 | +Class `symbol-consumption-gap`; the 16x16-level strip path (decode.rs:3473) already carries a | ||
| 15 | +comment about being bitten by exactly this. | ||
| 16 | + | ||
| 17 | +Decisive measurement (range ladder, not tell()): our post-`y_mode` range equalled the | ||
| 18 | +oracle's (38104), but the oracle then entered its first coefficient read at rng=46600 — one | ||
| 19 | +symbol's narrowing + renorm that we had not performed. | ||
| 20 | + | ||
| 21 | +## What changed (`crates/ec-av1/src/`) | ||
| 22 | + | ||
| 23 | +* `decode.rs:6081` `decode_leaf_rect8` — new `tx_select` parameter (threaded at both call | ||
| 24 | + sites, decode.rs:8019 / 8146). Per sub-block, after the mode read and the filter-intra | ||
| 25 | + refusal: `tx_size_cat0[tx_size_context_rect(lmi, bw, bh)]`. | ||
| 26 | + `bsize_to_tx_size_cat(BLOCK_4X8) == 0` because `sub_tx_size_map[TX_4X8] == TX_4X4` is a | ||
| 27 | + single step — the same 2-symbol category an 8x8 uses, **not** the 3-symbol `tx_size_cat2` | ||
| 28 | + the 32x16 strips read (class `table-indexed-by-raw-size` avoided). | ||
| 29 | +* `decode.rs` same function — depth 1 ported, not refused: two 4x4 transform units along the | ||
| 30 | + leaf's long axis (`decode_leaf8`'s own depth-1 loop with two units instead of four), each | ||
| 31 | + predicted from the previous unit's reconstruction, each with its own | ||
| 32 | + `luma_skip_ctx`/`around_mi`/`TxbSet::Luma4(Set1)`. **Skipped** leaves take the per-unit path | ||
| 33 | + too: a skipped 4x8 predicted in one shot is a different picture from two chained 4x4 | ||
| 34 | + predictions. `fill_lf_grid_rect` records tx 4x4 in that case so the next block's | ||
| 35 | + `tx_size_context` reads the coded size. | ||
| 36 | +* `decode.rs:944` — `RECT8_SPLIT_TX_HITS` + `rect8_split_tx_hits()`; separate from | ||
| 37 | + `TX_DEPTH_HITS`, which every square path also bumps. | ||
| 38 | +* `decode.rs` `read_coeffs_rect` — `read_coeffs`'s `EC_TRACE_COEFF` range ladder | ||
| 39 | + (`all_zero`/`tx_type`/`eob`/`base_eob`/`base`/`br`) in the oracle's own tag format. This was | ||
| 40 | + the missing instrument: r1 could not compare rect coefficients element by element at all. | ||
| 41 | +* `stream.rs:7429` gate — per-arm hard assert `split_tx > 0` on top of the existing | ||
| 42 | + 4x8/8x4 coded-leaf asserts. | ||
| 43 | + | ||
| 44 | +No refusal string added or removed this round (`refusal_inventory` / `gate_coverage` | ||
| 45 | +unchanged; r1 already removed the three this lane owns). The 16x16-level | ||
| 46 | +"a HORZ/VERT intra strip with a split transform" refusal stays — it guards the 32x16 strips, | ||
| 47 | +a different path. | ||
| 48 | + | ||
| 49 | +## Gate: GREEN (3 arms) | ||
| 50 | + | ||
| 51 | +`EC_AV1_REQUIRE_AOMENC=1 CARGO_TARGET_DIR=$HOME/.cache/cargo-target-tx4x8 cargo test -p ec-av1 --lib sub8_rect_leaf` | ||
| 52 | +-> `test result: ok. 1 passed; 0 failed` (32.5s), arms 16x16 8-bit / 128x16 8-bit | ||
| 53 | +`--tile-columns=1` / 16x16 10-bit, each with >=4 firing pixel-exact runs and >=1 split-tx leaf. | ||
| 54 | + | ||
| 55 | +EVIDENCE: /tmp/.../scratchpad/s303a.obu (sha256 272ff85db3409432619b5e7ca8fefdde50616c08b4576b1e37823e2cd7912e95, regenerated twice, identical) | aomenc seed=303 cq=12 16x16 testsrc2+noise with the gate's own flags; `decode_probe s303a.obu ours.yuv` vs `ffmpeg -i s303a.obu -f rawvideo ref.yuv` | `cmp` byte-identical 384/384 bytes (was: mismatch at sample 0, ours 126 vs ref 76) | ||
| 56 | + | ||
| 57 | +EVIDENCE: EC_TRACE_COEFF ladder, ours vs instrumented aomdec, first rect leaf of s303a.obu | `EC_TRACE_COEFF=1 decode_probe` vs `EC_TRACE_COEFF=1 EC_TRACE_MODE=1 aomdec` | before: first `all_zero` rng 36990 vs oracle 45231 (diverged at the first coefficient symbol); after: 45231 / 54240 / eob=30 / 62552 / 63488 / 59248 / 46438 / 45648 / 49904 / 35324 / 32812 — every element equal. Positions differ only by the known layout convention (oracle prints `scan[c]` in an 8-wide grid, ours in a 4-wide one: oracle 30/15/22/29 = ours 27/29/26/23 transposed — the same coefficients). | ||
| 58 | + | ||
| 59 | +EVIDENCE: $HOME/.cache/tx4x8-suite.log | `EC_AV1_REQUIRE_AOMENC=1 CARGO_TARGET_DIR=$HOME/.cache/cargo-target-tx4x8 cargo test -p ec-av1 --lib -j3` (full lib suite, aomenc required so an absent oracle fails) | `test result: ok. 274 passed; 0 failed; 22 ignored; 0 measured; 0 filtered out; finished in 768.55s` -- every sibling gate (sub8, tiny sweep, coded_rect_strip_below_16x16, refusal_inventory, gate_coverage) is in that run and green | ||
| 60 | + | ||
| 61 | +## Film probe (charter recipe, `ffmpeg -t 0.4 -c:v copy -f obu`) | ||
| 62 | + | ||
| 63 | +* ReelB (2160p 10-bit): `REFUSED: filter intra on a HORZ/VERT strip (this decoder | ||
| 64 | + predicts square-only)`. | ||
| 65 | +* ReelC (1080p 10-bit): `REFUSED: a 32x32 partition type this decoder does not code (value=4)` | ||
| 66 | + (HORZ_A/HORZ_B/VERT_A). | ||
| 67 | + | ||
| 68 | +Measured only AFTER the fix — r1 recorded no before-value for these extracts, so no | ||
| 69 | +"advanced from X to Y" claim is made. | ||
| 70 | + | ||
| 71 | +## Residue | ||
| 72 | + | ||
| 73 | +* deferred: rect filter-intra prediction (`predict_filter_intra` is square-only) — blocks the | ||
| 74 | + ReelB head — unblocked by a rect filter-intra predictor, which the 16x16-level strips | ||
| 75 | + need identically; one lane should own both. | ||
| 76 | +* deferred: 32-level `PARTITION_HORZ_A/B/VERT_A` (ReelC's stop) — other lane's cluster. | ||
| 77 | +* accepted: `read_coeffs_rect`'s trace prints `pos` in our own row-major-by-`w` layout, which | ||
| 78 | + is the transpose of the oracle's for rect sizes. Documented here rather than "fixed", because | ||
| 79 | + changing it would make our trace disagree with our own `read_coeffs`. | ||
lanes/tx4x8-r3.report.mdadded+116 -0
| @@ -0,0 +1,116 @@ | |||
| 1 | +# lane-tx4x8 r3 -- every rect shape gets its own has_tr/has_bl row | ||
| 2 | + | ||
| 3 | +## Root cause (verifier's finding, confirmed) | ||
| 4 | + | ||
| 5 | +`encode.rs` `rect_reach_tables(bw, bh)` had rows for 4x8, 8x4 and 16x32 only and | ||
| 6 | +a `_` arm that routed **every other rectangular shape** to libaom's | ||
| 7 | +`has_tr_32x16`/`has_bl_32x16`. 16x8 strips are live (`decode_leaf_rect`, | ||
| 8 | +`decode.rs`), and neither the old `HAS_TOP_RIGHT_RECT[bw == 16]` selection nor | ||
| 9 | +the r2 `_` arm matches `has_tr_16x8`/`has_bl_16x8` (`reconintra.c:96` / `:282`, | ||
| 10 | +16 bytes each): over the 21 reachable superblock positions, has_tr was wrong at | ||
| 11 | +14 (old) / 10 (r2) and has_bl at 14 / 7. Class: | ||
| 12 | +[[enumerate-table-domain]] + [[tool-disabled-in-every-gate]]. | ||
| 13 | + | ||
| 14 | +## Fix | ||
| 15 | + | ||
| 16 | +* `encode.rs`: all 14 rect shapes this decoder codes or will code (4x8, 8x4, | ||
| 17 | + 8x16, 16x8, 16x32, 32x16, 32x64, 64x32, 4x16, 16x4, 8x32, 32x8, 16x64, 64x16) | ||
| 18 | + now have their own `HAS_TR_*`/`HAS_BL_*` const, **generated** from | ||
| 19 | + `~/.cache/aom-oracle/src/av1/common/reconintra.c` (no byte retyped), and | ||
| 20 | + `rect_reach_tables` is an exhaustive match ending in | ||
| 21 | + `unreachable!("no libaom has_tr/has_bl table for a {bw}x{bh} block")`. | ||
| 22 | +* Index rule verified per shape: libaom's | ||
| 23 | + `(blk_row_in_sb << (5 - bw_in_mi_log2)) + blk_col_in_sb` == row stride | ||
| 24 | + `128 / bw` == the existing `Reach::table_stride(bw)`. For a 64-pixel | ||
| 25 | + superblock the largest index any shape can produce is | ||
| 26 | + `(64/bh - 1) * (128/bw) + (64/bw - 1)`, which is inside every one of the 14 | ||
| 27 | + oracle tables -- so the `% (table.len() * 8)` wrap the rect path used to | ||
| 28 | + apply is not just unnecessary, it was masking exactly this kind of | ||
| 29 | + mis-routing; it is gone (the square path keeps its own). | ||
| 30 | + | ||
| 31 | +## Check 1 -- domain test (runnable, green) | ||
| 32 | + | ||
| 33 | +`encode::tests::every_rect_shape_reaches_what_libaom_says_over_the_whole_superblock`: | ||
| 34 | +for all 14 shapes, at every position a block of that shape can sit in a 64x64 | ||
| 35 | +superblock (and in a second superblock at (64,64), so SB-relative position is | ||
| 36 | +what decides), `Reach::of_rect` == a port of libaom's `has_top_right` / | ||
| 37 | +`has_bottom_left` bodies incl. every early exit (top/right/bottom/left | ||
| 38 | +availability, `blk_row_in_sb == 0`, rightmost column, leftmost column's | ||
| 39 | +`row_off_in_sb + count < sb_height_unit`, bottom row). Each shape's table is | ||
| 40 | +additionally pinned by a `(len, byte sum)` fingerprint taken from the oracle's | ||
| 41 | +arrays, so a re-routed or truncated row fails even where two rows agree. | ||
| 42 | + | ||
| 43 | +Not covered, stated rather than implied: chroma `ss_x`/`ss_y` and sub-block | ||
| 44 | +transforms (`row_off`/`col_off` > 0) -- `of_rect` takes neither parameter | ||
| 45 | +(callers predict each transform unit as its own block); `PARTITION_VERT_A/B` | ||
| 46 | +needs no arm because libaom's `has_tr_vert_tables` entry for every *rect* bsize | ||
| 47 | +is either the plain table (4x8, 8x16, 16x32, 32x64) or NULL. | ||
| 48 | + | ||
| 49 | + cd /home/user/Documents/Code/Rust/edith_codecs-tx4x8 | ||
| 50 | + CARGO_TARGET_DIR=$HOME/.cache/cargo-target-tx4x8 EC_NOMEMGUARD=1 \ | ||
| 51 | + cargo test -p ec-av1 --lib -j3 every_rect_shape | ||
| 52 | + | ||
| 53 | +EVIDENCE: $HOME/.cache/tx4x8-suite-r3.log | cargo test -p ec-av1 --lib every_rect_shape | 1 passed, 0 failed | ||
| 54 | + | ||
| 55 | +MUTATION (the check that says the test has teeth): restoring r2's routing for | ||
| 56 | +one shape -- `(16, 8) => (&HAS_TR_32X16, &HAS_BL_32X16)` -- fails it: | ||
| 57 | + | ||
| 58 | + assertion `left == right` failed: rect_reach_tables(16, 8) is not libaom's has_tr_16x8/has_bl_16x8 | ||
| 59 | + left: (4, 32, 4, 184) | ||
| 60 | + right: (16, 960, 16, 2400) | ||
| 61 | + | ||
| 62 | +## Check 2 -- the asymmetric strip stream gate: BLOCKED, `#[ignore]`d | ||
| 63 | + | ||
| 64 | +`stream::tests::a_directional_16x8_strip_reads_the_right_above_right_samples` | ||
| 65 | +is written in full (directional-only intra: `--enable-smooth-intra=0 | ||
| 66 | +--enable-paeth-intra=0 --enable-filter-intra=0 --enable-directional-intra=1 | ||
| 67 | +--enable-rect-partitions=1 --enable-ab-partitions=0`, 64x16 fixture whose | ||
| 68 | +bottom half is flat so a HORZ arm can be a skip strip, 8-bit and 10-bit arms, | ||
| 69 | +per-attempt counters `decode::rect_strip_pred_hits` / `rect_strip_reach_hits` | ||
| 70 | +recorded in the predictor's edge fetch, pixel-exact vs ffmpeg) but it cannot | ||
| 71 | +pass today and is `#[ignore]`d with the reason in its doc rather than skipping | ||
| 72 | +from inside ([[gate-skips-on-its-own-failure]]). | ||
| 73 | + | ||
| 74 | +Why: the 16x16-level strip decoder refuses every **non-skip** 16x8/8x16 strip | ||
| 75 | +("a coded (non-skip) HORZ/VERT rect strip below 16x16"), which is what real | ||
| 76 | +streams contain. Measured on this recipe, per 40 attempts: | ||
| 77 | + | ||
| 78 | +| recipe | outcome | | ||
| 79 | +| --- | --- | | ||
| 80 | +| `--min-partition-size=16 --max-partition-size=16` | 40/40 decode, **0** 16x8/8x16 strips (aomenc bounds a rect shape by its smaller side, so 16x8 is never searched) | | ||
| 81 | +| `--min-partition-size=8`, cq 8..20, noise 30, 64x64 | 40/40 refused (split-transform strip / non-skip strip / sub-16x16 AB) | | ||
| 82 | +| `--min-partition-size=8 --enable-tx-size-search=0`, cq 30/45/55/62, noise 4 and 15, 64x16 | 0 firing; at cq 45 with the half-flat fixture: **38/40 "coded (non-skip) rect strip below 16x16"**, 2/40 sub-16x16 AB | | ||
| 83 | + | ||
| 84 | +MUTATION for this gate is therefore not reportable at stream level: with the | ||
| 85 | +old `_` routing the gate fails for the same reason it fails with the fix (no | ||
| 86 | +attempt gets past the refusal). The mutation evidence for the fix is the | ||
| 87 | +domain-test one above. | ||
| 88 | + | ||
| 89 | +deferred: the stream-level pixel gate for 16x8/8x16 reach -- blocked by the | ||
| 90 | +live "coded (non-skip) HORZ/VERT rect strip below 16x16" refusal -- unblocked | ||
| 91 | +by the lane that ports the coded 16x16-level strip; then delete the | ||
| 92 | +`#[ignore]` attribute (nothing else in the test changes). | ||
| 93 | + | ||
| 94 | +## Also | ||
| 95 | + | ||
| 96 | +* `stream.rs` doc of the sub-8x8 rect gate said "Arms: 8-bit 64x64, ... 128x64, | ||
| 97 | + ... 10-bit 64x64"; the arms are 16x16 / 128x16 / 16x16. Fixed. | ||
| 98 | +* New counters `rect_strip_pred_hits` / `rect_strip_reach_hits` in `decode.rs` | ||
| 99 | + (bumped in `Plane::edges_rect`) are the instrument the blocked gate needs the | ||
| 100 | + day the refusal lifts. | ||
| 101 | + | ||
| 102 | +## Suite | ||
| 103 | + | ||
| 104 | + CARGO_TARGET_DIR=$HOME/.cache/cargo-target-tx4x8 EC_NOMEMGUARD=1 \ | ||
| 105 | + EC_AV1_REQUIRE_AOMENC=1 cargo test -p ec-av1 -j3 | ||
| 106 | + | ||
| 107 | +275 passed, 0 failed, 23 ignored (r2: 274 / 0 / 22 -- +1 = the domain test, | ||
| 108 | ++1 ignored = the blocked gate). Log: `$HOME/.cache/tx4x8-suite-r3.log`. | ||
| 109 | + | ||
| 110 | +## Merge note | ||
| 111 | + | ||
| 112 | +This round deletes `HAS_TOP_RIGHT_RECT` / `HAS_BOTTOM_LEFT_RECT` (the 2-row | ||
| 113 | +arrays lane-tx64x16 r3 extends to 4 rows with its own 32x8/8x32 entries). On a | ||
| 114 | +merge, keep this branch's per-shape consts -- `HAS_TR_32X8` / `HAS_BL_32X8` / | ||
| 115 | +`HAS_TR_8X32` / `HAS_BL_8X32` are already here, byte-identical to the oracle -- | ||
| 116 | +and drop the array form together with `Reach::rect_table`. | ||