Merge branch 'main' into lane-sb128; the 128x128-superblock refusal main added (lane-oddh 866cbb1) is deleted and its gate flipped from "refused by name" to pixel-exact
Browse files at this commit21 changed files +4344 -295
- crates/ec-av1/examples/decode_probe.rs +20 -0
- crates/ec-av1/fixtures/reelb_head_key_frame.obu +0 -0
- crates/ec-av1/src/cdf.rs +28 -2
- crates/ec-av1/src/cdf_state.rs +66 -2
- crates/ec-av1/src/decode.rs +1378 -206
- crates/ec-av1/src/gate_coverage.rs +0 -16
- crates/ec-av1/src/motion_field.rs +84 -7
- crates/ec-av1/src/refusal_inventory.rs +4 -3
- crates/ec-av1/src/stream.rs +1544 -59
- lanes/angleinter-r1.report.md +105 -0
- lanes/band63-r1.report.md +119 -0
- lanes/golomb-r1.report.md +47 -0
- lanes/inter4-r1.report.md +97 -0
- lanes/inter4-r2.report.md +128 -0
- lanes/inter4-r3.report.md +125 -0
- lanes/inter4-r4.report.md +142 -0
- lanes/interbis-r1.report.md +129 -0
- lanes/oddh-r1.report.md +76 -0
- lanes/oddh-r2.report.md +97 -0
- lanes/refstamp-r1.report.md +84 -0
- scripts/instrument-aom-oracle.sh +71 -0
crates/ec-av1/examples/decode_probe.rsmodified+20 -0
| @@ -31,6 +31,13 @@ fn main() { | |||
| 31 | let report = || { | 31 | let report = || { |
| 32 | let (h, v, c) = ec_av1::stream::rect4_32_counters(); | 32 | let (h, v, c) = ec_av1::stream::rect4_32_counters(); |
| 33 | println!("rect4_32: horz={h} vert={v} coded={c}"); | 33 | println!("rect4_32: horz={h} vert={v} coded={c}"); |
| 34 | + let (rtu, rsplit, robmc) = ec_av1::stream::rect_inter_tu_counters(); | ||
| 35 | + println!("rect_inter: tu={rtu} txsplit={rsplit} obmc_leaf={robmc}"); | ||
| 36 | + let ir = ec_av1::stream::inter_rect_counters(); | ||
| 37 | + println!( | ||
| 38 | + "inter_rect: 32x8={} 8x32={} 64x32={} 32x64={} 64x16={} 16x64={}", | ||
| 39 | + ir.0, ir.1, ir.2, ir.3, ir.4, ir.5 | ||
| 40 | + ); | ||
| 34 | }; | 41 | }; |
| 35 | // lane-tiles: the tiling a real stream actually uses is a decision input | 42 | // lane-tiles: the tiling a real stream actually uses is a decision input |
| 36 | // (every gate in `stream.rs` picks its own `--tile-columns`), so report it | 43 | // (every gate in `stream.rs` picks its own `--tile-columns`), so report it |
| @@ -76,6 +83,19 @@ fn main() { | |||
| 76 | // Optional second arg, or EC_PROBE_OUT=<path>: dump the decoded | 83 | // Optional second arg, or EC_PROBE_OUT=<path>: dump the decoded |
| 77 | // planes as raw yuv420p so a pixel diff against `ffmpeg -i s.obu | 84 | // planes as raw yuv420p so a pixel diff against `ffmpeg -i s.obu |
| 78 | // -f rawvideo` needs no test harness. | 85 | // -f rawvideo` needs no test harness. |
| 86 | + // 10-bit streams: EC_PROBE_OUT16 dumps the planes as little-endian | ||
| 87 | + // u16 (yuv420p10le), the only form a pixel diff against | ||
| 88 | + // `ffmpeg -pix_fmt yuv420p10le` can use (lane-band63). | ||
| 89 | + if let Ok(out) = std::env::var("EC_PROBE_OUT16") { | ||
| 90 | + let mut buf: Vec<u8> = Vec::new(); | ||
| 91 | + for f in &frames { | ||
| 92 | + for p in [&f.y, &f.u, &f.v] { | ||
| 93 | + buf.extend(p.iter().flat_map(|&s| s.to_le_bytes())); | ||
| 94 | + } | ||
| 95 | + } | ||
| 96 | + std::fs::write(&out, &buf).expect("writing raw planes"); | ||
| 97 | + println!("wrote {} bytes of yuv420p10le to {out}", buf.len()); | ||
| 98 | + } | ||
| 79 | let out = std::env::args().nth(2).or_else(|| std::env::var("EC_PROBE_OUT").ok()); | 99 | let out = std::env::args().nth(2).or_else(|| std::env::var("EC_PROBE_OUT").ok()); |
| 80 | if let Some(out) = out { | 100 | if let Some(out) = out { |
| 81 | // 8-bit only: planes are u16, take the low byte. | 101 | // 8-bit only: planes are u16, take the low byte. |
crates/ec-av1/fixtures/reelb_head_key_frame.obuadded+0 -0
Binary file changed
crates/ec-av1/src/cdf.rsmodified+28 -2
| @@ -1639,7 +1639,7 @@ pub const SKIP_MODE: [[u16; 3]; 3] = [[32621, 32768, 0], [20708, 32768, 0], [812 | |||
| 1639 | /// `motion_mode_allowed` (spec 5.11.24's `read_motion_mode`) offers | 1639 | /// `motion_mode_allowed` (spec 5.11.24's `read_motion_mode`) offers |
| 1640 | /// `OBMC_CAUSAL` rather than `WARPED_CAUSAL` -- lane-motionmode round 1 | 1640 | /// `OBMC_CAUSAL` rather than `WARPED_CAUSAL` -- lane-motionmode round 1 |
| 1641 | /// never reaches the three-way `motion_mode_cdf`, see `decode.rs`. | 1641 | /// never reaches the three-way `motion_mode_cdf`, see `decode.rs`. |
| 1642 | -pub const OBMC: [[u16; 3]; 6] = [ | 1642 | +pub const OBMC: [[u16; 3]; 14] = [ |
| 1643 | [10437, 32768, 0], | 1643 | [10437, 32768, 0], |
| 1644 | [17432, 32768, 0], | 1644 | [17432, 32768, 0], |
| 1645 | [25817, 32768, 0], | 1645 | [25817, 32768, 0], |
| @@ -1649,6 +1649,20 @@ pub const OBMC: [[u16; 3]; 6] = [ | |||
| 1649 | // (rect-flake-1: the strip's motion_mode read diverged on this). | 1649 | // (rect-flake-1: the strip's motion_mode read diverged on this). |
| 1650 | [14423, 32768, 0], | 1650 | [14423, 32768, 0], |
| 1651 | [15142, 32768, 0], | 1651 | [15142, 32768, 0], |
| 1652 | + // lane-inter4 r1: the rect rows a superblock-level HORZ/VERT/1:4 and a | ||
| 1653 | + // 32x32-level 1:4 inter strip read -- BLOCK_32X64 (10), BLOCK_64X32 (11), | ||
| 1654 | + // BLOCK_8X32 (18), BLOCK_32X8 (19), BLOCK_16X64 (20), BLOCK_64X16 (21) of | ||
| 1655 | + // libaom's `default_obmc_cdf`. | ||
| 1656 | + [22823, 32768, 0], | ||
| 1657 | + [22083, 32768, 0], | ||
| 1658 | + [23664, 32768, 0], | ||
| 1659 | + [20901, 32768, 0], | ||
| 1660 | + [24008, 32768, 0], | ||
| 1661 | + [26879, 32768, 0], | ||
| 1662 | + // lane-inter4 r3: the 16x16-level rect inter leaves' own rows -- | ||
| 1663 | + // BLOCK_8X16 (4) and BLOCK_16X8 (5) of libaom's `default_obmc_cdf`. | ||
| 1664 | + [9371, 32768, 0], | ||
| 1665 | + [9301, 32768, 0], | ||
| 1652 | ]; | 1666 | ]; |
| 1653 | 1667 | ||
| 1654 | /// `default_motion_mode_cdf` (spec 9.4, `entropymode.c`), the square-bsize | 1668 | /// `default_motion_mode_cdf` (spec 9.4, `entropymode.c`), the square-bsize |
| @@ -1658,7 +1672,7 @@ pub const OBMC: [[u16; 3]; 6] = [ | |||
| 1658 | /// `read_motion_mode` reads instead of [`OBMC`] whenever `motion_mode_allowed` | 1672 | /// `read_motion_mode` reads instead of [`OBMC`] whenever `motion_mode_allowed` |
| 1659 | /// (spec 5.11.24) resolves to `WARPED_CAUSAL`-eligible (`num_proj_ref >= 1` | 1673 | /// (spec 5.11.24) resolves to `WARPED_CAUSAL`-eligible (`num_proj_ref >= 1` |
| 1660 | /// under `allow_warped_motion`) -- lane-warp round 1. | 1674 | /// under `allow_warped_motion`) -- lane-warp round 1. |
| 1661 | -pub const MOTION_MODE: [[u16; 4]; 6] = [ | 1675 | +pub const MOTION_MODE: [[u16; 4]; 14] = [ |
| 1662 | [7651, 24760, 32768, 0], | 1676 | [7651, 24760, 32768, 0], |
| 1663 | [19419, 26810, 32768, 0], | 1677 | [19419, 26810, 32768, 0], |
| 1664 | [26260, 29116, 32768, 0], | 1678 | [26260, 29116, 32768, 0], |
| @@ -1666,6 +1680,18 @@ pub const MOTION_MODE: [[u16; 4]; 6] = [ | |||
| 1666 | // lane-rect r2: BLOCK_16X32 / BLOCK_32X16 rows (indices 7/8). | 1680 | // lane-rect r2: BLOCK_16X32 / BLOCK_32X16 rows (indices 7/8). |
| 1667 | [5123, 23606, 32768, 0], | 1681 | [5123, 23606, 32768, 0], |
| 1668 | [11606, 24308, 32768, 0], | 1682 | [11606, 24308, 32768, 0], |
| 1683 | + // lane-inter4 r1: BLOCK_32X64 / 64X32 / 8X32 / 32X8 / 16X64 / 64X16 rows | ||
| 1684 | + // (libaom `default_motion_mode_cdf` indices 10, 11, 18, 19, 20, 21). | ||
| 1685 | + [20360, 28062, 32768, 0], | ||
| 1686 | + [21679, 26830, 32768, 0], | ||
| 1687 | + [28799, 31390, 32768, 0], | ||
| 1688 | + [26431, 30774, 32768, 0], | ||
| 1689 | + [28973, 31594, 32768, 0], | ||
| 1690 | + [29742, 31203, 32768, 0], | ||
| 1691 | + // lane-inter4 r3: BLOCK_8X16 / BLOCK_16X8 rows (libaom | ||
| 1692 | + // `default_motion_mode_cdf` indices 4 and 5). | ||
| 1693 | + [4738, 24765, 32768, 0], | ||
| 1694 | + [5391, 25528, 32768, 0], | ||
| 1669 | ]; | 1695 | ]; |
| 1670 | 1696 | ||
| 1671 | /// `default_interintra_cdf` (spec 9.4): `interintra`, indexed by | 1697 | /// `default_interintra_cdf` (spec 9.4): `interintra`, indexed by |
crates/ec-av1/src/cdf_state.rsmodified+66 -2
| @@ -119,6 +119,16 @@ pub(crate) enum TxbSet { | |||
| 119 | /// [`LumaRect32x16`](TxbSet::LumaRect32x16) has none). | 119 | /// [`LumaRect32x16`](TxbSet::LumaRect32x16) has none). |
| 120 | LumaRect32x8, | 120 | LumaRect32x8, |
| 121 | LumaRect32x16, | 121 | LumaRect32x16, |
| 122 | + /// lane-inter4 r2: [`LumaRect32x16`](TxbSet::LumaRect32x16)'s INTER twin -- | ||
| 123 | + /// same coefficient tables (`get_txsize_entropy_ctx` reduces TX_32X16 and | ||
| 124 | + /// TX_16X32 alike to the 32x32 set, 512-coefficient `eob_pt`), but an | ||
| 125 | + /// inter block DOES code a `tx_type` symbol here: `av1_get_ext_tx_set_type` | ||
| 126 | + /// with `tx_size_sqr_up == TX_32X32` and `is_inter` returns | ||
| 127 | + /// `EXT_TX_SET_DCT_IDTX` (2 symbols), whose CDF is | ||
| 128 | + /// `default_inter_ext_tx_cdf[3][txsize_sqr_map[TX_32X16] == TX_16X16]`, | ||
| 129 | + /// i.e. exactly [`INTER_TX_TYPE_SET3_16`](crate::cdf::INTER_TX_TYPE_SET3_16) | ||
| 130 | + /// -- the same table the square `Luma16Inter` set reads. | ||
| 131 | + LumaRect32x16Inter, | ||
| 122 | /// The chroma 16x8/8x16 transform under the same strip (lane-rectwire): | 132 | /// The chroma 16x8/8x16 transform under the same strip (lane-rectwire): |
| 123 | /// [`Chroma16`](TxbSet::Chroma16)'s tables except `eob_pt`, which reads | 133 | /// [`Chroma16`](TxbSet::Chroma16)'s tables except `eob_pt`, which reads |
| 124 | /// the true 128-position [`crate::cdf::EOB_PT_128_CHROMA`] instead of | 134 | /// the true 128-position [`crate::cdf::EOB_PT_128_CHROMA`] instead of |
| @@ -165,6 +175,24 @@ pub(crate) enum TxbSet { | |||
| 165 | /// 16x16 row's five-symbol reduced CDF here and desynced on the very | 175 | /// 16x16 row's five-symbol reduced CDF here and desynced on the very |
| 166 | /// first coded rect leaf. | 176 | /// first coded rect leaf. |
| 167 | LumaRect16x8Set1, | 177 | LumaRect16x8Set1, |
| 178 | + /// lane-inter4 r3: [`LumaRect16x8`](TxbSet::LumaRect16x8)'s INTER twin -- | ||
| 179 | + /// the same coefficient tables (`get_txsize_entropy_ctx` reduces TX_16X8 | ||
| 180 | + /// and TX_8X16 alike to the 16x16 set, 128-position `eob_pt`), with the | ||
| 181 | + /// inter `tx_type` alphabet in place of the intra one. Under | ||
| 182 | + /// `reduced_tx_set` `av1_get_ext_tx_set_type` (`tx_size_sqr_up == | ||
| 183 | + /// TX_16X16`, `is_inter`) returns `EXT_TX_SET_DCT_IDTX` (2 symbols), | ||
| 184 | + /// whose CDF row is `default_inter_ext_tx_cdf[1][txsize_sqr_map[TX_16X8] | ||
| 185 | + /// == TX_8X8]`, i.e. [`INTER_TX_TYPE_SET3_8`](crate::cdf::INTER_TX_TYPE_SET3_8) | ||
| 186 | + /// -- the same table the square `Luma8Inter` set reads. | ||
| 187 | + LumaRect16x8Inter, | ||
| 188 | + /// [`LumaRect16x8Inter`](TxbSet::LumaRect16x8Inter)'s `reduced_tx_set: | ||
| 189 | + /// false` counterpart: `tx_size_sqr` is `TX_8X8` here (NOT the | ||
| 190 | + /// `txsize_sqr_up_map` `TX_16X16` the coefficient tables use), so | ||
| 191 | + /// `av1_ext_tx_set_lookup[is_inter=1][tx_size_sqr == TX_16X16 -> 0]` is | ||
| 192 | + /// `EXT_TX_SET_ALL16` -- sixteen symbols, `default_inter_ext_tx_cdf[1] | ||
| 193 | + /// [TX_8X8]`, i.e. [`INTER_TX_TYPE_SET1_8`](crate::cdf::INTER_TX_TYPE_SET1_8), | ||
| 194 | + /// the table [`Luma8InterSet1`](TxbSet::Luma8InterSet1) also reads. | ||
| 195 | + LumaRect16x8InterSet1, | ||
| 168 | /// The chroma 8x4/4x8 transform under the same leaf (lane-rectx): | 196 | /// The chroma 8x4/4x8 transform under the same leaf (lane-rectx): |
| 169 | /// [`Chroma8`](TxbSet::Chroma8)'s tables except `eob_pt`, which reads the | 197 | /// [`Chroma8`](TxbSet::Chroma8)'s tables except `eob_pt`, which reads the |
| 170 | /// true 32-position [`crate::cdf::EOB_PT_32_CHROMA`] instead of | 198 | /// true 32-position [`crate::cdf::EOB_PT_32_CHROMA`] instead of |
| @@ -475,13 +503,13 @@ pub(crate) struct Cdfs { | |||
| 475 | /// `BLOCK_8X8`, 1 = `BLOCK_16X16`, 2 = `BLOCK_32X32`, 3 = `BLOCK_64X64` | 503 | /// `BLOCK_8X8`, 1 = `BLOCK_16X16`, 2 = `BLOCK_32X32`, 3 = `BLOCK_64X64` |
| 476 | /// (`default_obmc_cdf`'s own `BLOCK_SIZES_ALL` indices 3/6/9/12 -- | 504 | /// (`default_obmc_cdf`'s own `BLOCK_SIZES_ALL` indices 3/6/9/12 -- |
| 477 | /// this decoder only ever codes those four square sizes). | 505 | /// this decoder only ever codes those four square sizes). |
| 478 | - pub obmc: [[u16; 3]; 6], | 506 | + pub obmc: [[u16; 3]; 14], |
| 479 | /// `motion_mode` (spec 5.11.24's `read_motion_mode`), the 3-symbol | 507 | /// `motion_mode` (spec 5.11.24's `read_motion_mode`), the 3-symbol |
| 480 | /// `SIMPLE_TRANSLATION`/`OBMC_CAUSAL`/`WARPED_CAUSAL` alphabet read | 508 | /// `SIMPLE_TRANSLATION`/`OBMC_CAUSAL`/`WARPED_CAUSAL` alphabet read |
| 481 | /// instead of [`Self::obmc`] whenever `motion_mode_allowed` resolves to | 509 | /// instead of [`Self::obmc`] whenever `motion_mode_allowed` resolves to |
| 482 | /// `WARPED_CAUSAL`-eligible -- same square-bsize indexing as `obmc`. | 510 | /// `WARPED_CAUSAL`-eligible -- same square-bsize indexing as `obmc`. |
| 483 | /// lane-warp round 1. | 511 | /// lane-warp round 1. |
| 484 | - pub motion_mode: [[u16; 4]; 6], | 512 | + pub motion_mode: [[u16; 4]; 14], |
| 485 | /// `interintra`, indexed by `size_group_lookup[bsize]` -- see | 513 | /// `interintra`, indexed by `size_group_lookup[bsize]` -- see |
| 486 | /// `cdf::INTERINTRA`'s own doc. | 514 | /// `cdf::INTERINTRA`'s own doc. |
| 487 | pub interintra: [[u16; 3]; 4], | 515 | pub interintra: [[u16; 3]; 4], |
| @@ -1687,6 +1715,18 @@ impl Cdfs { | |||
| 1687 | tx_type: None, | 1715 | tx_type: None, |
| 1688 | eob_pt_class1: Some(&mut self.eob_pt_256_luma_class1), | 1716 | eob_pt_class1: Some(&mut self.eob_pt_256_luma_class1), |
| 1689 | }, | 1717 | }, |
| 1718 | + TxbSet::LumaRect32x16Inter => TxbTables { | ||
| 1719 | + side: 32, | ||
| 1720 | + txb_skip: &mut self.txb_skip_luma_32, | ||
| 1721 | + eob_pt: &mut self.eob_pt_512_luma, | ||
| 1722 | + eob_extra: &mut self.eob_extra_luma_32, | ||
| 1723 | + base: &mut self.base_luma_32, | ||
| 1724 | + base_eob: &mut self.base_eob_luma_32, | ||
| 1725 | + br: &mut self.br_luma_32, | ||
| 1726 | + dc_sign: &mut self.dc_sign_luma, | ||
| 1727 | + tx_type: Some(self.inter_tx_type_16.as_mut_slice()), | ||
| 1728 | + eob_pt_class1: Some(&mut self.eob_pt_512_luma_class1), | ||
| 1729 | + }, | ||
| 1690 | TxbSet::LumaRect32x16 => TxbTables { | 1730 | TxbSet::LumaRect32x16 => TxbTables { |
| 1691 | side: 32, | 1731 | side: 32, |
| 1692 | txb_skip: &mut self.txb_skip_luma_32, | 1732 | txb_skip: &mut self.txb_skip_luma_32, |
| @@ -1771,6 +1811,30 @@ impl Cdfs { | |||
| 1771 | tx_type: Some(self.intra_tx_type_8_set1[mode].as_mut_slice()), | 1811 | tx_type: Some(self.intra_tx_type_8_set1[mode].as_mut_slice()), |
| 1772 | eob_pt_class1: Some(&mut self.eob_pt_128_luma_class1), | 1812 | eob_pt_class1: Some(&mut self.eob_pt_128_luma_class1), |
| 1773 | }, | 1813 | }, |
| 1814 | + TxbSet::LumaRect16x8Inter => TxbTables { | ||
| 1815 | + side: 16, | ||
| 1816 | + txb_skip: &mut self.txb_skip_luma_16, | ||
| 1817 | + eob_pt: &mut self.eob_pt_128_luma, | ||
| 1818 | + eob_extra: &mut self.eob_extra_luma_16, | ||
| 1819 | + base: &mut self.base_luma_16, | ||
| 1820 | + base_eob: &mut self.base_eob_luma_16, | ||
| 1821 | + br: &mut self.br_luma_16, | ||
| 1822 | + dc_sign: &mut self.dc_sign_luma, | ||
| 1823 | + tx_type: Some(self.inter_tx_type_8.as_mut_slice()), | ||
| 1824 | + eob_pt_class1: Some(&mut self.eob_pt_128_luma_class1), | ||
| 1825 | + }, | ||
| 1826 | + TxbSet::LumaRect16x8InterSet1 => TxbTables { | ||
| 1827 | + side: 16, | ||
| 1828 | + txb_skip: &mut self.txb_skip_luma_16, | ||
| 1829 | + eob_pt: &mut self.eob_pt_128_luma, | ||
| 1830 | + eob_extra: &mut self.eob_extra_luma_16, | ||
| 1831 | + base: &mut self.base_luma_16, | ||
| 1832 | + base_eob: &mut self.base_eob_luma_16, | ||
| 1833 | + br: &mut self.br_luma_16, | ||
| 1834 | + dc_sign: &mut self.dc_sign_luma, | ||
| 1835 | + tx_type: Some(self.inter_tx_type_8_set1.as_mut_slice()), | ||
| 1836 | + eob_pt_class1: Some(&mut self.eob_pt_128_luma_class1), | ||
| 1837 | + }, | ||
| 1774 | TxbSet::ChromaRect8x4 => TxbTables { | 1838 | TxbSet::ChromaRect8x4 => TxbTables { |
| 1775 | side: 8, | 1839 | side: 8, |
| 1776 | txb_skip: &mut self.txb_skip_chroma_8, | 1840 | txb_skip: &mut self.txb_skip_chroma_8, |
crates/ec-av1/src/decode.rsmodified+1378 -206
Diff too large; view file
| @@ -142,6 +142,27 @@ pub(crate) fn intra_in_inter_filter_intra_hits() -> usize { | |||
| 142 | INTRA_IN_INTER_FILTER_INTRA_HITS.with(|c| c.get()) | 142 | INTRA_IN_INTER_FILTER_INTRA_HITS.with(|c| c.get()) |
| 143 | } | 143 | } |
| 144 | 144 | ||
| 145 | +// lane-angleinter r1: how many INTRA blocks inside an INTER frame carried a | ||
| 146 | +// nonzero `angle_delta_y` / `angle_delta_uv` (`read_intra_angle_info`). Both | ||
| 147 | +// arms refused a nonzero luma delta before this round, and no inter gate | ||
| 148 | +// enabled `--enable-angle-delta` (aomenc's own default is 1). | ||
| 149 | +thread_local! { | ||
| 150 | + static INTRA_IN_INTER_ANGLE_DELTA_Y_HITS: std::cell::Cell<usize> = | ||
| 151 | + const { std::cell::Cell::new(0) }; | ||
| 152 | + static INTRA_IN_INTER_ANGLE_DELTA_UV_HITS: std::cell::Cell<usize> = | ||
| 153 | + const { std::cell::Cell::new(0) }; | ||
| 154 | +} | ||
| 155 | + | ||
| 156 | +/// Current value of [`INTRA_IN_INTER_ANGLE_DELTA_Y_HITS`]. | ||
| 157 | +pub(crate) fn intra_in_inter_angle_delta_y_hits() -> usize { | ||
| 158 | + INTRA_IN_INTER_ANGLE_DELTA_Y_HITS.with(|c| c.get()) | ||
| 159 | +} | ||
| 160 | + | ||
| 161 | +/// Current value of [`INTRA_IN_INTER_ANGLE_DELTA_UV_HITS`]. | ||
| 162 | +pub(crate) fn intra_in_inter_angle_delta_uv_hits() -> usize { | ||
| 163 | + INTRA_IN_INTER_ANGLE_DELTA_UV_HITS.with(|c| c.get()) | ||
| 164 | +} | ||
| 165 | + | ||
| 145 | // lane-realworld r1: this frame's `cdef.bits` (spec 5.9.19), threaded into | 166 | // lane-realworld r1: this frame's `cdef.bits` (spec 5.9.19), threaded into |
| 146 | // [`maybe_read_cdef_idx`] the same way [`ENABLE_EDGE_FILTER`] threads a | 167 | // [`maybe_read_cdef_idx`] the same way [`ENABLE_EDGE_FILTER`] threads a |
| 147 | // frame-level flag through the recursive block decode -- `0` (the default) | 168 | // frame-level flag through the recursive block decode -- `0` (the default) |
| @@ -955,6 +976,15 @@ pub(crate) fn tx_depth_hits() -> usize { | |||
| 955 | thread_local! { | 976 | thread_local! { |
| 956 | static TXFM_SPLIT_READS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) }; | 977 | static TXFM_SPLIT_READS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) }; |
| 957 | static TXFM_SPLIT_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) }; | 978 | static TXFM_SPLIT_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) }; |
| 979 | + // lane-inter4 r2: rectangular INTER residual coding -- how many rect | ||
| 980 | + // strips coded one whole-block rect transform unit, and how many split | ||
| 981 | + // their rect max transform into square sub-transforms. | ||
| 982 | + static RECT_INTER_TU_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) }; | ||
| 983 | + static RECT_INTER_TXSPLIT_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) }; | ||
| 984 | + // lane-inter4 r3: 16x16-level PARTITION_HORZ / PARTITION_VERT on an inter | ||
| 985 | + // frame -- 16x8 and 8x16 inter leaves. | ||
| 986 | + static INTER_LEAF16_HORZ_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) }; | ||
| 987 | + static INTER_LEAF16_VERT_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) }; | ||
| 958 | // This frame's own `tx_mode == TxMode::Select` and `reduced_tx_set` bits, | 988 | // This frame's own `tx_mode == TxMode::Select` and `reduced_tx_set` bits, |
| 959 | // set once per inter tile by [`decode_inter_frame_tile_with_cdfs`] -- | 989 | // set once per inter tile by [`decode_inter_frame_tile_with_cdfs`] -- |
| 960 | // `decode_inter_block` already carries forty parameters and both are | 990 | // `decode_inter_block` already carries forty parameters and both are |
| @@ -978,6 +1008,26 @@ pub(crate) fn txfm_split_hits() -> usize { | |||
| 978 | TXFM_SPLIT_HITS.with(|c| c.get()) | 1008 | TXFM_SPLIT_HITS.with(|c| c.get()) |
| 979 | } | 1009 | } |
| 980 | 1010 | ||
| 1011 | +/// Current value of [`INTER_LEAF16_HORZ_HITS`] (lane-inter4 r3). | ||
| 1012 | +pub(crate) fn inter_leaf16_horz_hits() -> usize { | ||
| 1013 | + INTER_LEAF16_HORZ_HITS.with(|c| c.get()) | ||
| 1014 | +} | ||
| 1015 | + | ||
| 1016 | +/// Current value of [`INTER_LEAF16_VERT_HITS`] (lane-inter4 r3). | ||
| 1017 | +pub(crate) fn inter_leaf16_vert_hits() -> usize { | ||
| 1018 | + INTER_LEAF16_VERT_HITS.with(|c| c.get()) | ||
| 1019 | +} | ||
| 1020 | + | ||
| 1021 | +/// Current value of [`RECT_INTER_TU_HITS`] (lane-inter4 r2). | ||
| 1022 | +pub(crate) fn rect_inter_tu_hits() -> usize { | ||
| 1023 | + RECT_INTER_TU_HITS.with(|c| c.get()) | ||
| 1024 | +} | ||
| 1025 | + | ||
| 1026 | +/// Current value of [`RECT_INTER_TXSPLIT_HITS`] (lane-inter4 r2). | ||
| 1027 | +pub(crate) fn rect_inter_txsplit_hits() -> usize { | ||
| 1028 | + RECT_INTER_TXSPLIT_HITS.with(|c| c.get()) | ||
| 1029 | +} | ||
| 1030 | + | ||
| 981 | /// Sets the current thread's [`TX_SELECT_INTER`]/[`REDUCED_TX_SET_INTER`]/ | 1031 | /// Sets the current thread's [`TX_SELECT_INTER`]/[`REDUCED_TX_SET_INTER`]/ |
| 982 | /// [`ENABLE_FILTER_INTRA_INTER`]. | 1032 | /// [`ENABLE_FILTER_INTRA_INTER`]. |
| 983 | pub(crate) fn set_inter_tx_mode( | 1033 | pub(crate) fn set_inter_tx_mode( |
| @@ -1059,6 +1109,21 @@ pub(crate) fn horz_vert_intra_hits() -> usize { | |||
| 1059 | HORZ_VERT_INTRA_HITS.with(|c| c.get()) | 1109 | HORZ_VERT_INTRA_HITS.with(|c| c.get()) |
| 1060 | } | 1110 | } |
| 1061 | 1111 | ||
| 1112 | +// How many blocks were decoded as a frame-edge rect strip -- the single | ||
| 1113 | +// coded half of a `PARTITION_HORZ`/`PARTITION_VERT` at the true frame edge | ||
| 1114 | +// (lane-oddh r1), i.e. a block living inside the 8px band of a frame whose | ||
| 1115 | +// height or width is 8 mod 16 (the user's 3840x1608 film). Intra and inter | ||
| 1116 | +// paths share the counter. | ||
| 1117 | +thread_local! { | ||
| 1118 | + static EDGE_RECT_STRIP_HITS: std::cell::Cell<usize> = | ||
| 1119 | + const { std::cell::Cell::new(0) }; | ||
| 1120 | +} | ||
| 1121 | + | ||
| 1122 | +/// Current value of [`EDGE_RECT_STRIP_HITS`]. | ||
| 1123 | +pub(crate) fn edge_rect_strip_hits() -> usize { | ||
| 1124 | + EDGE_RECT_STRIP_HITS.with(|c| c.get()) | ||
| 1125 | +} | ||
| 1126 | + | ||
| 1062 | // How many HORZ/VERT intra strips resolved a SPLIT luma transform | 1127 | // How many HORZ/VERT intra strips resolved a SPLIT luma transform |
| 1063 | // (`tx_depth != 0`) and decoded it per transform unit (lane-rectsplit r1) -- | 1128 | // (`tx_depth != 0`) and decoded it per transform unit (lane-rectsplit r1) -- |
| 1064 | // the case every rect path here refused by name before, and the first | 1129 | // the case every rect path here refused by name before, and the first |
| @@ -1745,6 +1810,19 @@ pub(crate) fn wii_hits() -> usize { | |||
| 1745 | WII_HITS.with(|c| c.get()) | 1810 | WII_HITS.with(|c| c.get()) |
| 1746 | } | 1811 | } |
| 1747 | 1812 | ||
| 1813 | +// lane-inter4 r4: how many 16x8/8x16 INTER LEAVES actually ran the OBMC | ||
| 1814 | +// blend -- the gate's proof that `--enable-obmc=1` reached this shape (the | ||
| 1815 | +// r3 refusal's replacement: prefilt frames are bit-exact vs an instrumented | ||
| 1816 | +// aomdec, neighbour list included). | ||
| 1817 | +thread_local! { | ||
| 1818 | + static OBMC_RECT_LEAF_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) }; | ||
| 1819 | +} | ||
| 1820 | + | ||
| 1821 | +/// Current value of [`OBMC_RECT_LEAF_HITS`]. | ||
| 1822 | +pub(crate) fn obmc_rect_leaf_hits() -> usize { | ||
| 1823 | + OBMC_RECT_LEAF_HITS.with(|c| c.get()) | ||
| 1824 | +} | ||
| 1825 | + | ||
| 1748 | /// Current value of [`OBMC_HITS_8`]. | 1826 | /// Current value of [`OBMC_HITS_8`]. |
| 1749 | pub(crate) fn obmc_hits_8() -> usize { | 1827 | pub(crate) fn obmc_hits_8() -> usize { |
| 1750 | OBMC_HITS_8.with(|c| c.get()) | 1828 | OBMC_HITS_8.with(|c| c.get()) |
| @@ -1979,6 +2057,17 @@ pub(crate) fn sb_rect4_vert_hits() -> usize { | |||
| 1979 | thread_local! { | 2057 | thread_local! { |
| 1980 | static RECT4_32_HORZ_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) }; | 2058 | static RECT4_32_HORZ_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) }; |
| 1981 | static RECT4_32_VERT_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) }; | 2059 | static RECT4_32_VERT_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) }; |
| 2060 | + /// lane-inter4 r1: the INTER-frame twins of the two counters above -- | ||
| 2061 | + /// four 32x8 / 8x32 inter strips of a 32x32-level `PARTITION_HORZ_4` / | ||
| 2062 | + /// `PARTITION_VERT_4`. | ||
| 2063 | + static RECT4_32_HORZ_INTER_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) }; | ||
| 2064 | + static RECT4_32_VERT_INTER_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) }; | ||
| 2065 | + /// lane-inter4 r1: superblock-level inter `PARTITION_HORZ`/`PARTITION_VERT` | ||
| 2066 | + /// strips (64x32 / 32x64) and their 1:4 pair (64x16 / 16x64). | ||
| 2067 | + static INTER_SB_HORZ_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) }; | ||
| 2068 | + static INTER_SB_VERT_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) }; | ||
| 2069 | + static INTER_SB_HORZ4_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) }; | ||
| 2070 | + static INTER_SB_VERT4_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) }; | ||
| 1982 | } | 2071 | } |
| 1983 | 2072 | ||
| 1984 | /// How many 32x32-level 1:4 strips actually read coefficients (non-skip): | 2073 | /// How many 32x32-level 1:4 strips actually read coefficients (non-skip): |
| @@ -2027,6 +2116,36 @@ pub(crate) fn rect4_32_vert_hits() -> usize { | |||
| 2027 | RECT4_32_VERT_HITS.with(|c| c.get()) | 2116 | RECT4_32_VERT_HITS.with(|c| c.get()) |
| 2028 | } | 2117 | } |
| 2029 | 2118 | ||
| 2119 | +/// Current value of `RECT4_32_HORZ_INTER_HITS` (32x8 inter strips decoded). | ||
| 2120 | +pub(crate) fn rect4_32_horz_inter_hits() -> usize { | ||
| 2121 | + RECT4_32_HORZ_INTER_HITS.with(|c| c.get()) | ||
| 2122 | +} | ||
| 2123 | + | ||
| 2124 | +/// Current value of `RECT4_32_VERT_INTER_HITS` (8x32 inter strips decoded). | ||
| 2125 | +pub(crate) fn rect4_32_vert_inter_hits() -> usize { | ||
| 2126 | + RECT4_32_VERT_INTER_HITS.with(|c| c.get()) | ||
| 2127 | +} | ||
| 2128 | + | ||
| 2129 | +/// Current value of `INTER_SB_HORZ_HITS` (64x32 inter strips decoded). | ||
| 2130 | +pub(crate) fn inter_sb_horz_hits() -> usize { | ||
| 2131 | + INTER_SB_HORZ_HITS.with(|c| c.get()) | ||
| 2132 | +} | ||
| 2133 | + | ||
| 2134 | +/// Current value of `INTER_SB_VERT_HITS` (32x64 inter strips decoded). | ||
| 2135 | +pub(crate) fn inter_sb_vert_hits() -> usize { | ||
| 2136 | + INTER_SB_VERT_HITS.with(|c| c.get()) | ||
| 2137 | +} | ||
| 2138 | + | ||
| 2139 | +/// Current value of `INTER_SB_HORZ4_HITS` (64x16 inter strips decoded). | ||
| 2140 | +pub(crate) fn inter_sb_horz4_hits() -> usize { | ||
| 2141 | + INTER_SB_HORZ4_HITS.with(|c| c.get()) | ||
| 2142 | +} | ||
| 2143 | + | ||
| 2144 | +/// Current value of `INTER_SB_VERT4_HITS` (16x64 inter strips decoded). | ||
| 2145 | +pub(crate) fn inter_sb_vert4_hits() -> usize { | ||
| 2146 | + INTER_SB_VERT4_HITS.with(|c| c.get()) | ||
| 2147 | +} | ||
| 2148 | + | ||
| 2030 | // lane-rect64q r1: how many of [`decode_block_rect64`]'s three per-plane | 2149 | // lane-rect64q r1: how many of [`decode_block_rect64`]'s three per-plane |
| 2031 | // dequant calls actually observed `CURRENT_Q_IDX != base_q_idx` -- proof the | 2150 | // dequant calls actually observed `CURRENT_Q_IDX != base_q_idx` -- proof the |
| 2032 | // running-vs-stale-snapshot bug this round fixed is exercised by a gate, not | 2151 | // running-vs-stale-snapshot bug this round fixed is exercised by a gate, not |
| @@ -2156,25 +2275,67 @@ pub(crate) fn build_motion_field( | |||
| 2156 | mi_cols: usize, | 2275 | mi_cols: usize, |
| 2157 | mi_rows: usize, | 2276 | mi_rows: usize, |
| 2158 | order_hint: u32, | 2277 | order_hint: u32, |
| 2278 | + order_hint_bits: u32, | ||
| 2159 | ref_order_hints: [u32; 7], | 2279 | ref_order_hints: [u32; 7], |
| 2160 | ) -> crate::motion_field::MotionField { | 2280 | ) -> crate::motion_field::MotionField { |
| 2161 | let mut field = | 2281 | let mut field = |
| 2162 | - crate::motion_field::MotionField::new(mi_cols, mi_rows, order_hint, ref_order_hints); | 2282 | + crate::motion_field::MotionField::new(mi_cols, mi_rows, order_hint, ref_order_hints, false); |
| 2283 | + // lane-interbis r1: libaom `av1_calculate_ref_frame_side` -- a reference | ||
| 2284 | + // whose OrderHint is AHEAD of (or equal to) this frame's is "on the other | ||
| 2285 | + // side", and `av1_copy_frame_mvs` skips it entirely, so a compound block | ||
| 2286 | + // referencing one stores only its OTHER side's mv. With | ||
| 2287 | + // `enable_order_hint` off (`order_hint_bits == 0`) every side is 0 and | ||
| 2288 | + // nothing is skipped. | ||
| 2289 | + let other_side = |rf: i8| -> bool { | ||
| 2290 | + if order_hint_bits == 0 { | ||
| 2291 | + return false; | ||
| 2292 | + } | ||
| 2293 | + let oh = ref_order_hints[(rf - LAST_FRAME) as usize]; | ||
| 2294 | + crate::motion_field::get_relative_dist(order_hint_bits, oh, order_hint) > 0 | ||
| 2295 | + || oh == order_hint | ||
| 2296 | + }; | ||
| 2297 | + // libaom `REFMVS_LIMIT` (`mvref_common.h`): a stored motion field mv is | ||
| 2298 | + // capped at 12 bits per component; a longer one is not stored at all. | ||
| 2299 | + const REFMVS_LIMIT: i32 = (1 << 12) - 1; | ||
| 2163 | for row in 0..mi_rows { | 2300 | for row in 0..mi_rows { |
| 2164 | for col in 0..mi_cols { | 2301 | for col in 0..mi_cols { |
| 2165 | - if let Some(info) = grid.get(row, col) | 2302 | + let Some(info) = grid.get(row, col) else { |
| 2166 | - && info.is_inter | 2303 | + continue; |
| 2167 | - && info.ref_frame > 0 | 2304 | + }; |
| 2168 | - { | 2305 | + // `av1_copy_frame_mvs` runs for EVERY block of an inter frame and |
| 2169 | - field.set( | 2306 | + // CLEARS the cells it covers first (`mv->ref_frame = NONE_FRAME`), |
| 2170 | - row, | 2307 | + // so an intra block -- or an inter block whose every slot is on the |
| 2171 | - col, | 2308 | + // other side / over the limit -- wipes what an earlier block wrote |
| 2172 | - crate::motion_field::SavedMv { | 2309 | + // into the same 8x8 cell (only reachable from sub-8x8 leaves, which |
| 2173 | - mv: info.mv, | 2310 | + // share a cell). |
| 2174 | - ref_frame: info.ref_frame, | 2311 | + if !info.is_inter { |
| 2175 | - }, | 2312 | + field.set(row, col, None); |
| 2176 | - ); | 2313 | + continue; |
| 2314 | + } | ||
| 2315 | + // `av1_copy_frame_mvs` walks BOTH reference slots and the LAST | ||
| 2316 | + // qualifying one wins -- a compound block stores its second | ||
| 2317 | + // reference's mv, never its first (unless the second is on the | ||
| 2318 | + // other side or over the limit). Storing slot 0 unconditionally | ||
| 2319 | + // put the wrong (mv, ref_frame_offset) pair in every compound | ||
| 2320 | + // block's cell, which a later frame's temporal candidate then | ||
| 2321 | + // projected with the wrong reference distance. | ||
| 2322 | + let mut saved: Option<crate::motion_field::SavedMv> = None; | ||
| 2323 | + for (rf, mv) in [ | ||
| 2324 | + (info.ref_frame, Some(info.mv)), | ||
| 2325 | + (info.ref_frame1.unwrap_or(0), info.mv1), | ||
| 2326 | + ] { | ||
| 2327 | + let (Some(mv), true) = (mv, rf > 0) else { | ||
| 2328 | + continue; | ||
| 2329 | + }; | ||
| 2330 | + if other_side(rf) { | ||
| 2331 | + continue; | ||
| 2332 | + } | ||
| 2333 | + if mv.0.abs() > REFMVS_LIMIT || mv.1.abs() > REFMVS_LIMIT { | ||
| 2334 | + continue; | ||
| 2335 | + } | ||
| 2336 | + saved = Some(crate::motion_field::SavedMv { mv, ref_frame: rf }); | ||
| 2177 | } | 2337 | } |
| 2338 | + field.set(row, col, saved); | ||
| 2178 | } | 2339 | } |
| 2179 | } | 2340 | } |
| 2180 | field | 2341 | field |
| @@ -4476,20 +4637,46 @@ impl Neighbours { | |||
| 4476 | uv_mode: usize, | 4637 | uv_mode: usize, |
| 4477 | grids: &[Vec<i32>; 3], | 4638 | grids: &[Vec<i32>; 3], |
| 4478 | ) { | 4639 | ) { |
| 4479 | - let (r, c) = at; | 4640 | + self.record_rect_mi(sub16_to_mi(at), w, h, mode, uv_mode, grids); |
| 4641 | + } | ||
| 4642 | + | ||
| 4643 | + /// [`Self::record_rect`] in mi (4 px) units -- lane-inter4 r1: a | ||
| 4644 | + /// 32x8/8x32 strip of a 32-level 1:4 partition sits at an 8-px offset the | ||
| 4645 | + /// [`SUB`]-unit `at` cannot name. The coarse 16-px bands are still keyed | ||
| 4646 | + /// by the enclosing cell (a sub-16 extent writes none of them, exactly as | ||
| 4647 | + /// the [`SUB`]-unit path does). | ||
| 4648 | + fn record_rect_mi( | ||
| 4649 | + &mut self, | ||
| 4650 | + at_mi: (usize, usize), | ||
| 4651 | + w: usize, | ||
| 4652 | + h: usize, | ||
| 4653 | + mode: usize, | ||
| 4654 | + uv_mode: usize, | ||
| 4655 | + grids: &[Vec<i32>; 3], | ||
| 4656 | + ) { | ||
| 4657 | + let (r, c) = (at_mi.0 / (SUB / MI), at_mi.1 / (SUB / MI)); | ||
| 4658 | + // lane-inter4 r2: a strip whose own footprint runs past the frame's | ||
| 4659 | + // last 16-px column/row stamps only the cells that exist (libaom's | ||
| 4660 | + // arrays are padded past the frame and those cells are never read). | ||
| 4480 | for cell in 0..w / SUB { | 4661 | for cell in 0..w / SUB { |
| 4662 | + if c + cell >= self.above_mode.len() { | ||
| 4663 | + break; | ||
| 4664 | + } | ||
| 4481 | self.above_mode[c + cell] = mode; | 4665 | self.above_mode[c + cell] = mode; |
| 4482 | self.above_uv_mode[c + cell] = uv_mode; | 4666 | self.above_uv_mode[c + cell] = uv_mode; |
| 4483 | self.above_side[c + cell] = w; | 4667 | self.above_side[c + cell] = w; |
| 4484 | } | 4668 | } |
| 4485 | for cell in 0..h / SUB { | 4669 | for cell in 0..h / SUB { |
| 4670 | + if r + cell >= self.left_mode.len() { | ||
| 4671 | + break; | ||
| 4672 | + } | ||
| 4486 | self.left_mode[r + cell] = mode; | 4673 | self.left_mode[r + cell] = mode; |
| 4487 | self.left_uv_mode[r + cell] = uv_mode; | 4674 | self.left_uv_mode[r + cell] = uv_mode; |
| 4488 | self.left_side[r + cell] = h; | 4675 | self.left_side[r + cell] = h; |
| 4489 | } | 4676 | } |
| 4490 | - self.record_mode_mi(r * (SUB / MI), c * (SUB / MI), w / MI, h / MI, mode); | 4677 | + self.record_mode_mi(at_mi.0, at_mi.1, w / MI, h / MI, mode); |
| 4491 | - self.record_uv_mode_mi(r * (SUB / MI), c * (SUB / MI), w / MI, h / MI, uv_mode); | 4678 | + self.record_uv_mode_mi(at_mi.0, at_mi.1, w / MI, h / MI, uv_mode); |
| 4492 | - self.record_mi_rect((r * (SUB / MI), c * (SUB / MI)), w, h, grids); | 4679 | + self.record_mi_rect(at_mi, w, h, grids); |
| 4493 | } | 4680 | } |
| 4494 | 4681 | ||
| 4495 | /// The coefficient-context half of [`Self::record`], taking the block's | 4682 | /// The coefficient-context half of [`Self::record`], taking the block's |
| @@ -4513,10 +4700,14 @@ impl Neighbours { | |||
| 4513 | let states: [Neighbour; 3] = std::array::from_fn(|plane| neighbour_state(&grids[plane])); | 4700 | let states: [Neighbour; 3] = std::array::from_fn(|plane| neighbour_state(&grids[plane])); |
| 4514 | let (w_mi, h_mi) = (w / MI, h / MI); | 4701 | let (w_mi, h_mi) = (w / MI, h / MI); |
| 4515 | for cell in 0..h_mi { | 4702 | for cell in 0..h_mi { |
| 4516 | - self.left_side_mi[mi_r + cell] = h; | 4703 | + if let Some(slot) = self.left_side_mi.get_mut(mi_r + cell) { |
| 4704 | + *slot = h; | ||
| 4705 | + } | ||
| 4517 | } | 4706 | } |
| 4518 | for cell in 0..w_mi { | 4707 | for cell in 0..w_mi { |
| 4519 | - self.above_side_mi[mi_c + cell] = w; | 4708 | + if let Some(slot) = self.above_side_mi.get_mut(mi_c + cell) { |
| 4709 | + *slot = w; | ||
| 4710 | + } | ||
| 4520 | } | 4711 | } |
| 4521 | // A chroma 4x4 unit straddling the true luma edge is still whole in | 4712 | // A chroma 4x4 unit straddling the true luma edge is still whole in |
| 4522 | // chroma's own halved grid, so libaom rounds the luma bound up to the | 4713 | // chroma's own halved grid, so libaom rounds the luma bound up to the |
| @@ -4647,23 +4838,34 @@ impl Neighbours { | |||
| 4647 | let (mi_r, mi_c) = at_mi; | 4838 | let (mi_r, mi_c) = at_mi; |
| 4648 | let (r, c) = (mi_r / (SUB / MI), mi_c / (SUB / MI)); | 4839 | let (r, c) = (mi_r / (SUB / MI), mi_c / (SUB / MI)); |
| 4649 | for cell in 0..w.div_ceil(SUB) { | 4840 | for cell in 0..w.div_ceil(SUB) { |
| 4841 | + if c + cell >= self.above_mode.len() { | ||
| 4842 | + break; | ||
| 4843 | + } | ||
| 4650 | self.above_mode[c + cell] = mode; | 4844 | self.above_mode[c + cell] = mode; |
| 4651 | self.above_uv_mode[c + cell] = uv_mode; | 4845 | self.above_uv_mode[c + cell] = uv_mode; |
| 4652 | self.above_side[c + cell] = w; | 4846 | self.above_side[c + cell] = w; |
| 4653 | } | 4847 | } |
| 4654 | for cell in 0..h.div_ceil(SUB) { | 4848 | for cell in 0..h.div_ceil(SUB) { |
| 4849 | + if r + cell >= self.left_mode.len() { | ||
| 4850 | + break; | ||
| 4851 | + } | ||
| 4655 | self.left_mode[r + cell] = mode; | 4852 | self.left_mode[r + cell] = mode; |
| 4656 | self.left_uv_mode[r + cell] = uv_mode; | 4853 | self.left_uv_mode[r + cell] = uv_mode; |
| 4657 | self.left_side[r + cell] = h; | 4854 | self.left_side[r + cell] = h; |
| 4658 | } | 4855 | } |
| 4856 | + | ||
| 4659 | let (w_mi, h_mi) = (w / MI, h / MI); | 4857 | let (w_mi, h_mi) = (w / MI, h / MI); |
| 4660 | self.record_mode_mi(mi_r, mi_c, w_mi, h_mi, mode); | 4858 | self.record_mode_mi(mi_r, mi_c, w_mi, h_mi, mode); |
| 4661 | self.record_uv_mode_mi(mi_r, mi_c, w_mi, h_mi, uv_mode); | 4859 | self.record_uv_mode_mi(mi_r, mi_c, w_mi, h_mi, uv_mode); |
| 4662 | for cell in 0..h_mi { | 4860 | for cell in 0..h_mi { |
| 4663 | - self.left_side_mi[mi_r + cell] = h; | 4861 | + if let Some(slot) = self.left_side_mi.get_mut(mi_r + cell) { |
| 4862 | + *slot = h; | ||
| 4863 | + } | ||
| 4664 | } | 4864 | } |
| 4665 | for cell in 0..w_mi { | 4865 | for cell in 0..w_mi { |
| 4666 | - self.above_side_mi[mi_c + cell] = w; | 4866 | + if let Some(slot) = self.above_side_mi.get_mut(mi_c + cell) { |
| 4867 | + *slot = w; | ||
| 4868 | + } | ||
| 4667 | } | 4869 | } |
| 4668 | let round_up_even = |n: usize| n.div_ceil(2) * 2; | 4870 | let round_up_even = |n: usize| n.div_ceil(2) * 2; |
| 4669 | let (bound_h, bound_w) = (round_up_even(self.mi_rows), round_up_even(self.mi_cols)); | 4871 | let (bound_h, bound_w) = (round_up_even(self.mi_rows), round_up_even(self.mi_cols)); |
| @@ -10013,8 +10215,25 @@ fn read_tx_size( | |||
| 10013 | /// the two neighbour terms (whether the transform last written above/left of | 10215 | /// the two neighbour terms (whether the transform last written above/left of |
| 10014 | /// this unit is narrower/shorter than the unit itself). | 10216 | /// this unit is narrower/shorter than the unit itself). |
| 10015 | fn txfm_partition_ctx(above_px: u8, left_px: u8, blk_max_px: usize, tx_px: usize) -> usize { | 10217 | fn txfm_partition_ctx(above_px: u8, left_px: u8, blk_max_px: usize, tx_px: usize) -> usize { |
| 10016 | - let above = usize::from(usize::from(above_px) < tx_px); | 10218 | + txfm_partition_ctx_rect(above_px, left_px, blk_max_px, tx_px, tx_px) |
| 10017 | - let left = usize::from(usize::from(left_px) < tx_px); | 10219 | +} |
| 10220 | + | ||
| 10221 | +/// [`txfm_partition_ctx`] for a *rectangular* transform (lane-inter4 r2): | ||
| 10222 | +/// libaom's `txfm_partition_context` compares the above context against | ||
| 10223 | +/// `tx_size_wide` and the left one against `tx_size_high`, and takes its | ||
| 10224 | +/// category from `txsize_sqr_up_map[tx_size]` -- all three collapse to one | ||
| 10225 | +/// side for a square transform, which is why the square form above is a | ||
| 10226 | +/// special case of this one. | ||
| 10227 | +fn txfm_partition_ctx_rect( | ||
| 10228 | + above_px: u8, | ||
| 10229 | + left_px: u8, | ||
| 10230 | + blk_max_px: usize, | ||
| 10231 | + tx_w: usize, | ||
| 10232 | + tx_h: usize, | ||
| 10233 | +) -> usize { | ||
| 10234 | + let above = usize::from(usize::from(above_px) < tx_w); | ||
| 10235 | + let left = usize::from(usize::from(left_px) < tx_h); | ||
| 10236 | + let tx_px = tx_w.max(tx_h); | ||
| 10018 | // `get_sqr_tx_size(max(block_size_wide, block_size_high))`, capped at the | 10237 | // `get_sqr_tx_size(max(block_size_wide, block_size_high))`, capped at the |
| 10019 | // largest transform (`TX_64X64`); `TX_4X4`..`TX_64X64` index as | 10238 | // largest transform (`TX_64X64`); `TX_4X4`..`TX_64X64` index as |
| 10020 | // `log2(px) - 2`. | 10239 | // `log2(px) - 2`. |
| @@ -10029,16 +10248,30 @@ fn txfm_partition_ctx(above_px: u8, left_px: u8, blk_max_px: usize, tx_px: usize | |||
| 10029 | /// resolved transform's own size. | 10248 | /// resolved transform's own size. |
| 10030 | fn txfm_partition_update( | 10249 | fn txfm_partition_update( |
| 10031 | n: &mut Neighbours, | 10250 | n: &mut Neighbours, |
| 10032 | - (mi_r, mi_c): (usize, usize), | 10251 | + at_mi: (usize, usize), |
| 10033 | tx_px: usize, | 10252 | tx_px: usize, |
| 10034 | txb_px: usize, | 10253 | txb_px: usize, |
| 10035 | ) { | 10254 | ) { |
| 10036 | - for i in 0..txb_px / MI { | 10255 | + txfm_partition_update_rect(n, at_mi, (tx_px, tx_px), (txb_px, txb_px)); |
| 10256 | +} | ||
| 10257 | + | ||
| 10258 | +/// [`txfm_partition_update`] for a rectangular transform (lane-inter4 r2): | ||
| 10259 | +/// the left column records `tx_size_high` over the parent's own height and | ||
| 10260 | +/// the above row records `tx_size_wide` over its width. | ||
| 10261 | +fn txfm_partition_update_rect( | ||
| 10262 | + n: &mut Neighbours, | ||
| 10263 | + (mi_r, mi_c): (usize, usize), | ||
| 10264 | + (tx_w, tx_h): (usize, usize), | ||
| 10265 | + (txb_w, txb_h): (usize, usize), | ||
| 10266 | +) { | ||
| 10267 | + for i in 0..txb_h / MI { | ||
| 10037 | if let Some(cell) = n.left_txfm.get_mut(mi_r + i) { | 10268 | if let Some(cell) = n.left_txfm.get_mut(mi_r + i) { |
| 10038 | - *cell = tx_px as u8; | 10269 | + *cell = tx_h as u8; |
| 10039 | } | 10270 | } |
| 10271 | + } | ||
| 10272 | + for i in 0..txb_w / MI { | ||
| 10040 | if let Some(cell) = n.above_txfm.get_mut(mi_c + i) { | 10273 | if let Some(cell) = n.above_txfm.get_mut(mi_c + i) { |
| 10041 | - *cell = tx_px as u8; | 10274 | + *cell = tx_w as u8; |
| 10042 | } | 10275 | } |
| 10043 | } | 10276 | } |
| 10044 | } | 10277 | } |
| @@ -10260,6 +10493,264 @@ fn read_block_tx_size( | |||
| 10260 | Ok((tx, None)) | 10493 | Ok((tx, None)) |
| 10261 | } | 10494 | } |
| 10262 | 10495 | ||
| 10496 | +/// lane-inter4 r2: the shapes whose *rectangular inter* residual this | ||
| 10497 | +/// decoder codes -- a 2:1 strip whose own max rect transform | ||
| 10498 | +/// (`max_txsize_rect_lookup[BLOCK_32X16] == TX_32X16`) has both a | ||
| 10499 | +/// coefficient table set ([`TxbSet::LumaRect32x16Inter`], 512-coefficient | ||
| 10500 | +/// `eob_pt`) and a `tx_type` alphabet here. 64x32/64x16 strips would need a | ||
| 10501 | +/// 64-point rect transform, and 16x8/8x16 needs | ||
| 10502 | +/// `default_inter_ext_tx_cdf[2][TX_8X8]` (the 12-symbol | ||
| 10503 | +/// `DTT9_IDTX_1DDCT` row at `tx_size_sqr == TX_8X8`, only reachable through a | ||
| 10504 | +/// rect transform), neither of which exists yet -- both stay refused by name. | ||
| 10505 | +fn rect_inter_residual_supported(w: usize, h: usize) -> bool { | ||
| 10506 | + matches!((w, h), (32, 16) | (16, 32) | (16, 8) | (8, 16)) | ||
| 10507 | +} | ||
| 10508 | + | ||
| 10509 | +/// The luma coefficient/`tx_type` table set of a whole-block rectangular | ||
| 10510 | +/// INTER transform unit (lane-inter4 r3). `av1_get_ext_tx_set_type` splits | ||
| 10511 | +/// the two shapes: a 32x16/16x32 unit has `tx_size_sqr_up == TX_32X32`, so | ||
| 10512 | +/// it reads the 2-symbol `EXT_TX_SET_DCT_IDTX` set regardless of | ||
| 10513 | +/// `reduced_tx_set`; a 16x8/8x16 unit has `tx_size_sqr_up == TX_16X16` and | ||
| 10514 | +/// `tx_size_sqr == TX_8X8`, so it reads `EXT_TX_SET_DCT_IDTX` when reduced | ||
| 10515 | +/// and the 16-symbol `EXT_TX_SET_ALL16` otherwise -- both at the *8x8* CDF | ||
| 10516 | +/// row (`txsize_sqr_map`), never the 16x16 one. | ||
| 10517 | +fn rect_inter_luma_set(w: usize, h: usize) -> TxbSet { | ||
| 10518 | + match (w, h) { | ||
| 10519 | + (32, 16) | (16, 32) => TxbSet::LumaRect32x16Inter, | ||
| 10520 | + (16, 8) | (8, 16) => { | ||
| 10521 | + if REDUCED_TX_SET_INTER.with(std::cell::Cell::get) { | ||
| 10522 | + TxbSet::LumaRect16x8Inter | ||
| 10523 | + } else { | ||
| 10524 | + TxbSet::LumaRect16x8InterSet1 | ||
| 10525 | + } | ||
| 10526 | + } | ||
| 10527 | + _ => unreachable!("rect_inter_residual_supported gates every shape that reaches here"), | ||
| 10528 | + } | ||
| 10529 | +} | ||
| 10530 | + | ||
| 10531 | +/// The chroma table set of the same block's single rectangular chroma unit | ||
| 10532 | +/// (`av1_get_max_uv_txsize`): 16x8/8x16 under a 32x16/16x32 strip, 8x4/4x8 | ||
| 10533 | +/// under a 16x8/8x16 one. Neither codes a `tx_type` symbol -- both inherit | ||
| 10534 | +/// the luma unit's. | ||
| 10535 | +fn rect_inter_chroma_set(w: usize, h: usize) -> TxbSet { | ||
| 10536 | + match (w, h) { | ||
| 10537 | + (16, 8) | (8, 16) => TxbSet::ChromaRect16x8, | ||
| 10538 | + (8, 4) | (4, 8) => TxbSet::ChromaRect8x4, | ||
| 10539 | + _ => unreachable!("rect_inter_residual_supported gates every shape that reaches here"), | ||
| 10540 | + } | ||
| 10541 | +} | ||
| 10542 | + | ||
| 10543 | +/// libaom `size_group_lookup[bsize]` for the block shapes this decoder's | ||
| 10544 | +/// inter path reaches, from the block's TRUE footprint rather than the | ||
| 10545 | +/// square `side` corner-cut: 8x8/8x16/16x8 -> 1, 16x16/16x32/32x16 -> 2, | ||
| 10546 | +/// everything 32 and above -> 3. | ||
| 10547 | +fn size_group_wh(w: usize, h: usize) -> usize { | ||
| 10548 | + // lane-inter4 r4: `size_group_lookup[BLOCK_SIZES_ALL]` (libaom | ||
| 10549 | + // `common_data.h:60`) is 0 for every block with a 4-px side | ||
| 10550 | + // (4x4/4x8/8x4/4x16/16x4), 1 for min side 8, 2 for 16, 3 above -- the old | ||
| 10551 | + // `0..=8 => 1` row gave a sub-8 leaf group 1 where libaom says 0. | ||
| 10552 | + match w.min(h) { | ||
| 10553 | + 0..=4 => 0, | ||
| 10554 | + 8 => 1, | ||
| 10555 | + 16 => 2, | ||
| 10556 | + _ => 3, | ||
| 10557 | + } | ||
| 10558 | +} | ||
| 10559 | + | ||
| 10560 | +#[test] | ||
| 10561 | +fn size_group_wh_matches_libaom_size_group_lookup() { | ||
| 10562 | + // `BLOCK_SIZES_ALL` in libaom's own order, with `size_group_lookup`'s | ||
| 10563 | + // transcribed values (common_data.h:60-62). | ||
| 10564 | + const TABLE: [((usize, usize), usize); 22] = [ | ||
| 10565 | + ((4, 4), 0), ((4, 8), 0), ((8, 4), 0), ((8, 8), 1), ((8, 16), 1), ((16, 8), 1), | ||
| 10566 | + ((16, 16), 2), ((16, 32), 2), ((32, 16), 2), ((32, 32), 3), ((32, 64), 3), | ||
| 10567 | + ((64, 32), 3), ((64, 64), 3), ((64, 128), 3), ((128, 64), 3), ((128, 128), 3), | ||
| 10568 | + ((4, 16), 0), ((16, 4), 0), ((8, 32), 1), ((32, 8), 1), ((16, 64), 2), ((64, 16), 2), | ||
| 10569 | + ]; | ||
| 10570 | + for ((w, h), want) in TABLE { | ||
| 10571 | + assert_eq!(size_group_wh(w, h), want, "size_group_wh({w}, {h})"); | ||
| 10572 | + } | ||
| 10573 | +} | ||
| 10574 | + | ||
| 10575 | +/// The default (2D) coefficient scan of a rectangular transform. | ||
| 10576 | +fn rect_scan(w: usize, h: usize) -> &'static [u16] { | ||
| 10577 | + match (w, h) { | ||
| 10578 | + (32, 16) => &SCAN_32X16, | ||
| 10579 | + (16, 32) => &SCAN_16X32, | ||
| 10580 | + (16, 8) => &SCAN_16X8, | ||
| 10581 | + (8, 16) => &SCAN_8X16, | ||
| 10582 | + (8, 4) => &SCAN_8X4, | ||
| 10583 | + (4, 8) => &SCAN_4X8, | ||
| 10584 | + _ => unreachable!("rect_inter_residual_supported gates every shape that reaches here"), | ||
| 10585 | + } | ||
| 10586 | +} | ||
| 10587 | + | ||
| 10588 | +/// [`read_block_tx_size`] for a rectangular inter block (lane-inter4 r2): | ||
| 10589 | +/// spec 5.11.17 / libaom `read_tx_size_vartx` starting from the block's own | ||
| 10590 | +/// `max_txsize_rect_lookup` entry, which for a 2:1 strip IS rectangular. The | ||
| 10591 | +/// depth-0 `txfm_partition` symbol reads its context off the rect transform's | ||
| 10592 | +/// own width/height; a `0` leaves one whole-block rect transform unit | ||
| 10593 | +/// (`None`), and a `1` splits it into `sub_tx_size_map`'s two SQUARE | ||
| 10594 | +/// sub-transforms (`sub_tx_size_map[TX_32X16] == TX_16X16`), from which the | ||
| 10595 | +/// ordinary square [`read_var_tx_size`] recursion continues at depth 1 -- so | ||
| 10596 | +/// every leaf of a split rect block is square and the existing square leaf | ||
| 10597 | +/// loop reconstructs it unchanged. | ||
| 10598 | +#[allow(clippy::too_many_arguments)] | ||
| 10599 | +fn read_block_tx_size_rect( | ||
| 10600 | + dec: &mut SymbolDecoder, | ||
| 10601 | + cdfs: &mut Cdfs, | ||
| 10602 | + n: &mut Neighbours, | ||
| 10603 | + at_mi: (usize, usize), | ||
| 10604 | + (bw, bh): (usize, usize), | ||
| 10605 | + (mi_cols, mi_rows): (usize, usize), | ||
| 10606 | + skip: bool, | ||
| 10607 | +) -> Result<Option<Vec<(usize, usize, usize)>>> { | ||
| 10608 | + if skip { | ||
| 10609 | + // `set_txfm_ctxs(.., skip && is_inter)`: a skipped inter block records | ||
| 10610 | + // its own BLOCK size -- width above, height left -- not a transform. | ||
| 10611 | + txfm_partition_update_rect(n, at_mi, (bw, bh), (bw, bh)); | ||
| 10612 | + return Ok(None); | ||
| 10613 | + } | ||
| 10614 | + // `max_txsize_rect_lookup` is the block's own size, capped at 64 -- and | ||
| 10615 | + // `rect_inter_residual_supported` has already excluded everything above 32. | ||
| 10616 | + let (tx_w, tx_h) = (bw, bh); | ||
| 10617 | + if !TX_SELECT_INTER.with(std::cell::Cell::get) { | ||
| 10618 | + // `TX_MODE_LARGEST`: no symbol at all, the whole block is one | ||
| 10619 | + // transform, and `set_txfm_ctxs` records exactly what | ||
| 10620 | + // `txfm_partition_update` would for that same unit. | ||
| 10621 | + txfm_partition_update_rect(n, at_mi, (tx_w, tx_h), (bw, bh)); | ||
| 10622 | + RECT_INTER_TU_HITS.with(|c| c.set(c.get() + 1)); | ||
| 10623 | + return Ok(None); | ||
| 10624 | + } | ||
| 10625 | + let ctx = txfm_partition_ctx_rect( | ||
| 10626 | + n.above_txfm[at_mi.1], | ||
| 10627 | + n.left_txfm[at_mi.0], | ||
| 10628 | + bw.max(bh), | ||
| 10629 | + tx_w, | ||
| 10630 | + tx_h, | ||
| 10631 | + ); | ||
| 10632 | + let split = dec.symbol(&mut cdfs.txfm_partition[ctx]) == 1; | ||
| 10633 | + TXFM_SPLIT_READS.with(|c| c.set(c.get() + 1)); | ||
| 10634 | + if std::env::var_os("EC_TRACE_MODE_STEP").is_some() { | ||
| 10635 | + let (rng, _) = dec.debug_state(); | ||
| 10636 | + eprintln!( | ||
| 10637 | + "EC_ISTEP mi_row={} mi_col={} name=txfm_split_rect val={} ctx={ctx} rng={rng}", | ||
| 10638 | + at_mi.0, | ||
| 10639 | + at_mi.1, | ||
| 10640 | + u8::from(split) | ||
| 10641 | + ); | ||
| 10642 | + } | ||
| 10643 | + if !split { | ||
| 10644 | + txfm_partition_update_rect(n, at_mi, (tx_w, tx_h), (bw, bh)); | ||
| 10645 | + RECT_INTER_TU_HITS.with(|c| c.set(c.get() + 1)); | ||
| 10646 | + return Ok(None); | ||
| 10647 | + } | ||
| 10648 | + TXFM_SPLIT_HITS.with(|c| c.set(c.get() + 1)); | ||
| 10649 | + RECT_INTER_TXSPLIT_HITS.with(|c| c.set(c.get() + 1)); | ||
| 10650 | + let sub = tx_w.min(tx_h); | ||
| 10651 | + let max_w_mi = (bw / MI).min(mi_cols.saturating_sub(at_mi.1)); | ||
| 10652 | + let max_h_mi = (bh / MI).min(mi_rows.saturating_sub(at_mi.0)); | ||
| 10653 | + let mut leaves = Vec::new(); | ||
| 10654 | + for row in (0..bh / MI).step_by(sub / MI) { | ||
| 10655 | + for col in (0..bw / MI).step_by(sub / MI) { | ||
| 10656 | + read_var_tx_size( | ||
| 10657 | + dec, | ||
| 10658 | + cdfs, | ||
| 10659 | + n, | ||
| 10660 | + at_mi, | ||
| 10661 | + bw.max(bh), | ||
| 10662 | + (max_w_mi, max_h_mi), | ||
| 10663 | + sub, | ||
| 10664 | + 1, | ||
| 10665 | + row, | ||
| 10666 | + col, | ||
| 10667 | + &mut leaves, | ||
| 10668 | + ); | ||
| 10669 | + } | ||
| 10670 | + } | ||
| 10671 | + Ok(Some(leaves)) | ||
| 10672 | +} | ||
| 10673 | + | ||
| 10674 | +/// [`read_inter_plane`] for a rectangular transform unit (lane-inter4 r2): | ||
| 10675 | +/// the coefficients are read with the rect coefficient machinery | ||
| 10676 | +/// ([`read_coeffs_rect`], whose `TxClass` handling covers the 1D `V_*`/`H_*` | ||
| 10677 | +/// types), inverted with the rect inverse transform | ||
| 10678 | +/// ([`dequant_and_inverse_typed_wh`], which carries the 2:1 `sqrt2` scale), | ||
| 10679 | +/// and added onto the top-left `w x h` of the block's own square-strided | ||
| 10680 | +/// motion-compensated prediction buffer. Returns the *rect* coefficient grid | ||
| 10681 | +/// and the coded `tx_type`. | ||
| 10682 | +/// | ||
| 10683 | +/// `txb_skip_ctx` is 0 for luma: this unit covers the whole block, i.e. | ||
| 10684 | +/// `get_txb_ctx`'s `plane_bsize == txsize_to_bsize[tx_size]` branch. | ||
| 10685 | +#[allow(clippy::too_many_arguments)] | ||
| 10686 | +fn read_inter_plane_rect( | ||
| 10687 | + dec: &mut SymbolDecoder, | ||
| 10688 | + cdfs: &mut Cdfs, | ||
| 10689 | + set: TxbSet, | ||
| 10690 | + (w, h): (usize, usize), | ||
| 10691 | + stride: usize, | ||
| 10692 | + plane_idx: usize, | ||
| 10693 | + around: (bool, bool, i32), | ||
| 10694 | + tx_mode: usize, | ||
| 10695 | + plane: &mut PlaneBuf, | ||
| 10696 | + x: usize, | ||
| 10697 | + y: usize, | ||
| 10698 | + prediction: &[u16], | ||
| 10699 | + inherited_luma_tx_type: Option<TxType>, | ||
| 10700 | +) -> Result<(Vec<i32>, TxType)> { | ||
| 10701 | + let skip_ctx = if plane_idx == 0 { | ||
| 10702 | + 0 | ||
| 10703 | + } else { | ||
| 10704 | + usize::from(around.0) + usize::from(around.1) | ||
| 10705 | + }; | ||
| 10706 | + let mut coding = cdfs.txb(set, tx_mode); | ||
| 10707 | + // `av1_get_ext_tx_set_type`'s DCT-only clamp is on `tx_size_sqr_up`, i.e. | ||
| 10708 | + // the *longer* side of this rect transform. | ||
| 10709 | + let default_tx_type = match inherited_luma_tx_type { | ||
| 10710 | + Some(t) if w.max(h) < 32 => t, | ||
| 10711 | + _ => TxType::DctDct, | ||
| 10712 | + }; | ||
| 10713 | + let (grid, tx_type) = read_coeffs_rect( | ||
| 10714 | + dec, | ||
| 10715 | + &mut coding, | ||
| 10716 | + rect_scan(w, h), | ||
| 10717 | + w, | ||
| 10718 | + h, | ||
| 10719 | + skip_ctx, | ||
| 10720 | + dc_sign_ctx(around.2), | ||
| 10721 | + default_tx_type, | ||
| 10722 | + )?; | ||
| 10723 | + let (dc_delta, ac_delta) = plane_q_delta(plane_idx); | ||
| 10724 | + let residual = dequant_and_inverse_typed_wh( | ||
| 10725 | + &grid, | ||
| 10726 | + w, | ||
| 10727 | + h, | ||
| 10728 | + bit_depth(), | ||
| 10729 | + block_q_idx(), | ||
| 10730 | + dc_delta, | ||
| 10731 | + ac_delta, | ||
| 10732 | + tx_type, | ||
| 10733 | + ); | ||
| 10734 | + // `reconstruct_mc_rect` reads both buffers at the square prediction | ||
| 10735 | + // stride, so the dense `w x h` residual is re-laid at that stride first. | ||
| 10736 | + let mut strided = vec![0i32; stride * stride]; | ||
| 10737 | + for row in 0..h { | ||
| 10738 | + strided[row * stride..][..w].copy_from_slice(&residual[row * w..][..w]); | ||
| 10739 | + } | ||
| 10740 | + plane.reconstruct_mc_rect(x, y, stride, w, h, prediction, &strided); | ||
| 10741 | + Ok((grid, tx_type)) | ||
| 10742 | +} | ||
| 10743 | + | ||
| 10744 | +/// A rect coefficient grid re-laid into the square `stride x stride` grid the | ||
| 10745 | +/// neighbour/deblock stamps downstream of the residual expect. | ||
| 10746 | +fn embed_rect_grid(grid: &[i32], w: usize, h: usize, stride: usize) -> Vec<i32> { | ||
| 10747 | + let mut full = vec![0i32; stride * stride]; | ||
| 10748 | + for row in 0..h { | ||
| 10749 | + full[row * stride..][..w].copy_from_slice(&grid[row * w..][..w]); | ||
| 10750 | + } | ||
| 10751 | + full | ||
| 10752 | +} | ||
| 10753 | + | ||
| 10263 | /// One 8x8 inter leaf's luma residual (lane-txselect): either the whole-8x8 | 10754 | /// One 8x8 inter leaf's luma residual (lane-txselect): either the whole-8x8 |
| 10264 | /// transform, or -- when [`read_block_tx_size`]'s var-tx tree took the single | 10755 | /// transform, or -- when [`read_block_tx_size`]'s var-tx tree took the single |
| 10265 | /// split a `BLOCK_8X8` can take (`split`) -- the four 4x4 transform units in | 10756 | /// split a `BLOCK_8X8` can take (`split`) -- the four 4x4 transform units in |
| @@ -11539,16 +12030,31 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( | |||
| 11539 | } | 12030 | } |
| 11540 | p | 12031 | p |
| 11541 | } else { | 12032 | } else { |
| 12033 | + // lane-golomb r1 (class `parsed-then-discarded`): the gathered | ||
| 12034 | + // bit is the answer, not a formality -- libaom's | ||
| 12035 | + // `ec_read_partition_impl` returns `PARTITION_HORZ` (resp. | ||
| 12036 | + // `PARTITION_VERT`) when it reads 0, and only `PARTITION_SPLIT` | ||
| 12037 | + // when it reads 1. Forcing SPLIT here desynced the last | ||
| 12038 | + // superblock row of every frame whose height is not a multiple | ||
| 12039 | + // of 64 -- the ReelB head (3840x1608) diverges at | ||
| 12040 | + // mi_row=400 mi_col=0, the first block of that row. | ||
| 11542 | match (has_cols, has_rows) { | 12041 | match (has_cols, has_rows) { |
| 11543 | (true, false) => { | 12042 | (true, false) => { |
| 11544 | - dec.symbol_fixed(&gather(&cdfs.partition_w64[ctx], VERT_ALIKE)); | 12043 | + if dec.symbol_fixed(&gather(&cdfs.partition_w64[ctx], VERT_ALIKE)) == 1 { |
| 12044 | + PARTITION_SPLIT | ||
| 12045 | + } else { | ||
| 12046 | + PARTITION_HORZ | ||
| 12047 | + } | ||
| 11545 | } | 12048 | } |
| 11546 | (false, true) => { | 12049 | (false, true) => { |
| 11547 | - dec.symbol_fixed(&gather(&cdfs.partition_w64[ctx], HORZ_ALIKE)); | 12050 | + if dec.symbol_fixed(&gather(&cdfs.partition_w64[ctx], HORZ_ALIKE)) == 1 { |
| 12051 | + PARTITION_SPLIT | ||
| 12052 | + } else { | ||
| 12053 | + PARTITION_VERT | ||
| 12054 | + } | ||
| 11548 | } | 12055 | } |
| 11549 | - _ => {} | 12056 | + _ => PARTITION_SPLIT, |
| 11550 | } | 12057 | } |
| 11551 | - PARTITION_SPLIT | ||
| 11552 | }; | 12058 | }; |
| 11553 | match part { | 12059 | match part { |
| 11554 | PARTITION_NONE => { | 12060 | PARTITION_NONE => { |
| @@ -11605,20 +12111,27 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( | |||
| 11605 | } else { | 12111 | } else { |
| 11606 | match (has_cols32, has_rows32) { | 12112 | match (has_cols32, has_rows32) { |
| 11607 | (true, false) => { | 12113 | (true, false) => { |
| 11608 | - dec.symbol_fixed(&gather( | 12114 | + // lane-golomb r1 (class `parsed-then-discarded`): the gathered |
| 11609 | - &cdfs.partition_w32[ctx32], | 12115 | + // bit IS the partition -- 0 means PARTITION_HORZ, only 1 means SPLIT |
| 11610 | - VERT_ALIKE, | 12116 | + // (libaom `ec_read_partition_impl`). |
| 11611 | - )); | 12117 | + if dec.symbol_fixed(&gather(&cdfs.partition_w32[ctx32], VERT_ALIKE)) == 1 { |
| 12118 | + PARTITION_SPLIT | ||
| 12119 | + } else { | ||
| 12120 | + PARTITION_HORZ | ||
| 12121 | + } | ||
| 11612 | } | 12122 | } |
| 11613 | (false, true) => { | 12123 | (false, true) => { |
| 11614 | - dec.symbol_fixed(&gather( | 12124 | + // lane-golomb r1 (class `parsed-then-discarded`): the gathered |
| 11615 | - &cdfs.partition_w32[ctx32], | 12125 | + // bit IS the partition -- 0 means PARTITION_VERT, only 1 means SPLIT |
| 11616 | - HORZ_ALIKE, | 12126 | + // (libaom `ec_read_partition_impl`). |
| 11617 | - )); | 12127 | + if dec.symbol_fixed(&gather(&cdfs.partition_w32[ctx32], HORZ_ALIKE)) == 1 { |
| 12128 | + PARTITION_SPLIT | ||
| 12129 | + } else { | ||
| 12130 | + PARTITION_VERT | ||
| 12131 | + } | ||
| 11618 | } | 12132 | } |
| 11619 | - _ => {} | 12133 | + _ => PARTITION_SPLIT, |
| 11620 | } | 12134 | } |
| 11621 | - PARTITION_SPLIT | ||
| 11622 | }; | 12135 | }; |
| 11623 | match part32 { | 12136 | match part32 { |
| 11624 | PARTITION_NONE => { | 12137 | PARTITION_NONE => { |
| @@ -12057,16 +12570,63 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( | |||
| 12057 | does not code yet", | 12570 | does not code yet", |
| 12058 | )); | 12571 | )); |
| 12059 | } | 12572 | } |
| 12060 | - if has_cols16 { | 12573 | + // lane-golomb r1 (class |
| 12574 | + // `parsed-then-discarded`): the gathered | ||
| 12575 | + // bit IS the partition -- 0 names | ||
| 12576 | + // PARTITION_HORZ (resp. VERT), only 1 is | ||
| 12577 | + // SPLIT (libaom `ec_read_partition_impl`). | ||
| 12578 | + // This path can only walk the four SPLIT | ||
| 12579 | + // leaves, so a 0 refuses by name instead | ||
| 12580 | + // of desyncing. | ||
| 12581 | + let edge_split = if has_cols16 { | ||
| 12061 | dec.symbol_fixed(&gather( | 12582 | dec.symbol_fixed(&gather( |
| 12062 | &cdfs.partition_w16[ctx16], | 12583 | &cdfs.partition_w16[ctx16], |
| 12063 | VERT_ALIKE, | 12584 | VERT_ALIKE, |
| 12064 | - )); | 12585 | + )) |
| 12065 | } else { | 12586 | } else { |
| 12066 | dec.symbol_fixed(&gather( | 12587 | dec.symbol_fixed(&gather( |
| 12067 | &cdfs.partition_w16[ctx16], | 12588 | &cdfs.partition_w16[ctx16], |
| 12068 | HORZ_ALIKE, | 12589 | HORZ_ALIKE, |
| 12069 | - )); | 12590 | + )) |
| 12591 | + }; | ||
| 12592 | + if edge_split == 0 { | ||
| 12593 | + // lane-oddh r1: the strip IS decodable | ||
| 12594 | + // -- libaom's `decode_partition` codes | ||
| 12595 | + // only the FIRST half of an edge | ||
| 12596 | + // HORZ/VERT (the second call is | ||
| 12597 | + // guarded by the same has_rows/ | ||
| 12598 | + // has_cols test that made the | ||
| 12599 | + // partition non-square), so one | ||
| 12600 | + // 16x8 (resp. 8x16) strip covers the | ||
| 12601 | + // whole visible band of a frame whose | ||
| 12602 | + // height (resp. width) is 8 mod 16 -- | ||
| 12603 | + // the user's 3840x1608 film. | ||
| 12604 | + HORZ_VERT_INTRA_HITS.with(|c| c.set(c.get() + 1)); | ||
| 12605 | + EDGE_RECT_STRIP_HITS.with(|c| c.set(c.get() + 1)); | ||
| 12606 | + let (mi_row0, mi_col0) = | ||
| 12607 | + (sr as u32 * SUB_MI, sc as u32 * SUB_MI); | ||
| 12608 | + let (bw, bh) = if has_cols16 { (16, 8) } else { (8, 16) }; | ||
| 12609 | + let mode = decode_leaf_rect( | ||
| 12610 | + &mut dec, | ||
| 12611 | + &mut cdfs, | ||
| 12612 | + &mut neighbours, | ||
| 12613 | + at16, | ||
| 12614 | + (mi_row0 as usize, mi_col0 as usize), | ||
| 12615 | + bw, | ||
| 12616 | + bh, | ||
| 12617 | + None, | ||
| 12618 | + &mut y, | ||
| 12619 | + &mut u, | ||
| 12620 | + &mut v, | ||
| 12621 | + enable_filter_intra, | ||
| 12622 | + allow_screen_content_tools, | ||
| 12623 | + base_q_idx, | ||
| 12624 | + tx_select, | ||
| 12625 | + reduced_tx_set, | ||
| 12626 | + )?; | ||
| 12627 | + neighbours.above_mode[sc] = mode; | ||
| 12628 | + neighbours.left_mode[sr] = mode; | ||
| 12629 | + continue; | ||
| 12070 | } | 12630 | } |
| 12071 | let (mi_row0, mi_col0) = | 12631 | let (mi_row0, mi_col0) = |
| 12072 | (sr as u32 * SUB_MI, sc as u32 * SUB_MI); | 12632 | (sr as u32 * SUB_MI, sc as u32 * SUB_MI); |
| @@ -12616,22 +13176,27 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( | |||
| 12616 | tx_select, | 13176 | tx_select, |
| 12617 | reduced_tx_set, | 13177 | reduced_tx_set, |
| 12618 | )?; | 13178 | )?; |
| 12619 | - decode_block_rect64( | 13179 | + // lane-golomb r1: at the frame edge only the first half of the |
| 12620 | - &mut dec, | 13180 | + // strip is coded (libaom `decode_partition` guards the second |
| 12621 | - &mut cdfs, | 13181 | + // with the same has_rows test that made this partition non-square). |
| 12622 | - &mut neighbours, | 13182 | + if has_rows { |
| 12623 | - (at.0 + 2, at.1), | 13183 | + decode_block_rect64( |
| 12624 | - 64, | 13184 | + &mut dec, |
| 12625 | - 32, | 13185 | + &mut cdfs, |
| 12626 | - &mut y, | 13186 | + &mut neighbours, |
| 12627 | - &mut u, | 13187 | + (at.0 + 2, at.1), |
| 12628 | - &mut v, | 13188 | + 64, |
| 12629 | - enable_filter_intra, | 13189 | + 32, |
| 12630 | - allow_screen_content_tools, | 13190 | + &mut y, |
| 12631 | - base_q_idx, | 13191 | + &mut u, |
| 12632 | - tx_select, | 13192 | + &mut v, |
| 12633 | - reduced_tx_set, | 13193 | + enable_filter_intra, |
| 12634 | - )?; | 13194 | + allow_screen_content_tools, |
| 13195 | + base_q_idx, | ||
| 13196 | + tx_select, | ||
| 13197 | + reduced_tx_set, | ||
| 13198 | + )?; | ||
| 13199 | + } | ||
| 12635 | } | 13200 | } |
| 12636 | PARTITION_VERT => { | 13201 | PARTITION_VERT => { |
| 12637 | // lane-sbpart r2: mirror of PARTITION_HORZ above with | 13202 | // lane-sbpart r2: mirror of PARTITION_HORZ above with |
| @@ -12652,22 +13217,27 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( | |||
| 12652 | tx_select, | 13217 | tx_select, |
| 12653 | reduced_tx_set, | 13218 | reduced_tx_set, |
| 12654 | )?; | 13219 | )?; |
| 12655 | - decode_block_rect64( | 13220 | + // lane-golomb r1: at the frame edge only the first half of the |
| 12656 | - &mut dec, | 13221 | + // strip is coded (libaom `decode_partition` guards the second |
| 12657 | - &mut cdfs, | 13222 | + // with the same has_cols test that made this partition non-square). |
| 12658 | - &mut neighbours, | 13223 | + if has_cols { |
| 12659 | - (at.0, at.1 + 2), | 13224 | + decode_block_rect64( |
| 12660 | - 32, | 13225 | + &mut dec, |
| 12661 | - 64, | 13226 | + &mut cdfs, |
| 12662 | - &mut y, | 13227 | + &mut neighbours, |
| 12663 | - &mut u, | 13228 | + (at.0, at.1 + 2), |
| 12664 | - &mut v, | 13229 | + 32, |
| 12665 | - enable_filter_intra, | 13230 | + 64, |
| 12666 | - allow_screen_content_tools, | 13231 | + &mut y, |
| 12667 | - base_q_idx, | 13232 | + &mut u, |
| 12668 | - tx_select, | 13233 | + &mut v, |
| 12669 | - reduced_tx_set, | 13234 | + enable_filter_intra, |
| 12670 | - )?; | 13235 | + allow_screen_content_tools, |
| 13236 | + base_q_idx, | ||
| 13237 | + tx_select, | ||
| 13238 | + reduced_tx_set, | ||
| 13239 | + )?; | ||
| 13240 | + } | ||
| 12671 | } | 13241 | } |
| 12672 | PARTITION_HORZ_A | PARTITION_HORZ_B | PARTITION_VERT_A | PARTITION_VERT_B => { | 13242 | PARTITION_HORZ_A | PARTITION_HORZ_B | PARTITION_VERT_A | PARTITION_VERT_B => { |
| 12673 | // lane-part32 r4: the four superblock-level AB arms, each | 13243 | // lane-part32 r4: the four superblock-level AB arms, each |
| @@ -13916,11 +14486,33 @@ fn obmc_blend( | |||
| 13916 | // its OWN neighbour cap (width-log2 for above, height-log2 for left) and | 14486 | // its OWN neighbour cap (width-log2 for above, height-log2 for left) and |
| 13917 | // overlap (bh/2 rows above, bw/2 cols left) -- one square `side` was | 14487 | // overlap (bh/2 rows above, bw/2 cols left) -- one square `side` was |
| 13918 | // right only for square blocks. | 14488 | // right only for square blocks. |
| 14489 | + // libaom `max_neighbor_obmc[6] = { 0, 1, 2, 3, 4, 4 }` indexed by | ||
| 14490 | + // `mi_size_wide_log2[bsize]` (above pass) / `mi_size_high_log2` (left): | ||
| 14491 | + // 1 mi -> 0, 2 -> 1, 4 -> 2, 8 -> 3, 16+ -> 4. lane-inter4 r3: the old | ||
| 14492 | + // `1..=4 => 2` row was right only for blocks at least 16 px on that axis | ||
| 14493 | + // -- a 16x8 leaf's LEFT pass (bh4 = 2) walked up to two neighbours where | ||
| 14494 | + // libaom walks one, blending an extra 8-px-tall neighbour into every | ||
| 14495 | + // rect leaf with two of them on its left edge (class table-narrowed-to- | ||
| 14496 | + // the-reachable-sizes; the square gates could never expose it). | ||
| 13919 | let max_nb = |n4: usize| match n4 { | 14497 | let max_nb = |n4: usize| match n4 { |
| 13920 | - 1..=4 => 2, | 14498 | + 0..=1 => 0, |
| 14499 | + 2 => 1, | ||
| 14500 | + 3..=4 => 2, | ||
| 13921 | 5..=8 => 3, | 14501 | 5..=8 => 3, |
| 13922 | _ => 4, | 14502 | _ => 4, |
| 13923 | }; | 14503 | }; |
| 14504 | + // lane-inter4 r4: r3 refused OBMC on a 16x8/8x16 leaf (5302 luma pixels | ||
| 14505 | + // of one frame wrong). Re-measured on this tree with an `EC_OBMC` rung in | ||
| 14506 | + // both decoders on that exact stream: the neighbour lists agree entry for | ||
| 14507 | + // entry (position, span, mv, ref, size, filter) and all six pre-filter | ||
| 14508 | + // frames are byte-identical to the instrumented aomdec's. The refusal is | ||
| 14509 | + // gone; the counter below is what the gate's `--enable-obmc=1` arm reads. | ||
| 14510 | + // The only decode-path change between r3's measurement and this one is the | ||
| 14511 | + // lane-interbis merge (`build_motion_field`'s compound slot walk), which | ||
| 14512 | + // moves temporal MV candidates -- not bisected further. | ||
| 14513 | + if matches!((write_w, write_h), (16, 8) | (8, 16)) { | ||
| 14514 | + OBMC_RECT_LEAF_HITS.with(|c| c.set(c.get() + 1)); | ||
| 14515 | + } | ||
| 13924 | let overlap_above = write_h / 2; | 14516 | let overlap_above = write_h / 2; |
| 13925 | let overlap_left = write_w / 2; | 14517 | let overlap_left = write_w / 2; |
| 13926 | // lane-inter8 r1 / lane-scaledref r1: `av1_skip_u4x4_pred_in_obmc` | 14518 | // lane-inter8 r1 / lane-scaledref r1: `av1_skip_u4x4_pred_in_obmc` |
| @@ -14303,6 +14895,12 @@ fn build_gm_mv_table( | |||
| 14303 | /// mode/tx-type outside what [`read_intra_mode`]/[`read_coeffs`] already | 14895 | /// mode/tx-type outside what [`read_intra_mode`]/[`read_coeffs`] already |
| 14304 | /// refuse. | 14896 | /// refuse. |
| 14305 | #[allow(clippy::too_many_arguments)] | 14897 | #[allow(clippy::too_many_arguments)] |
| 14898 | +/// lane-inter4 r1: 16-px-cell coordinates -> MI (4-px) coordinates, the unit | ||
| 14899 | +/// [`decode_inter_block`]'s `at` now takes. | ||
| 14900 | +const fn sub16_to_mi(t: (usize, usize)) -> (usize, usize) { | ||
| 14901 | + (t.0 * (SUB / MI), t.1 * (SUB / MI)) | ||
| 14902 | +} | ||
| 14903 | + | ||
| 14306 | fn decode_inter_block( | 14904 | fn decode_inter_block( |
| 14307 | dec: &mut SymbolDecoder, | 14905 | dec: &mut SymbolDecoder, |
| 14308 | cdfs: &mut Cdfs, | 14906 | cdfs: &mut Cdfs, |
| @@ -14339,7 +14937,11 @@ fn decode_inter_block( | |||
| 14339 | chroma_tx: usize, | 14937 | chroma_tx: usize, |
| 14340 | scan_luma: &[u16], | 14938 | scan_luma: &[u16], |
| 14341 | scan_chroma: &[u16], | 14939 | scan_chroma: &[u16], |
| 14342 | - size_group: usize, | 14940 | + // lane-inter4 r3: superseded by `size_group_wh(write_w, write_h)` at the |
| 14941 | + // one site that read it (`y_mode`) -- a rect strip's group comes from its | ||
| 14942 | + // true footprint, not the caller's square `side`. Kept in the signature | ||
| 14943 | + // rather than editing twenty call sites. | ||
| 14944 | + _size_group: usize, | ||
| 14343 | allow_high_precision_mv: bool, | 14945 | allow_high_precision_mv: bool, |
| 14344 | force_integer_mv: bool, | 14946 | force_integer_mv: bool, |
| 14345 | interp_fixed: Option<mc::InterpFilterKind>, | 14947 | interp_fixed: Option<mc::InterpFilterKind>, |
| @@ -14417,13 +15019,16 @@ fn decode_inter_block( | |||
| 14417 | // combinations that don't implement scaled MC yet. | 15019 | // combinations that don't implement scaled MC yet. |
| 14418 | frame_width: usize, | 15020 | frame_width: usize, |
| 14419 | ) -> Result<()> { | 15021 | ) -> Result<()> { |
| 14420 | - let (r, c) = at; | 15022 | + // lane-inter4 r1: `at` is in MI units (4 px) so a 32-level 1:4 strip can |
| 15023 | + // name an 8-px offset; `(r, c)` stays the enclosing 16-px cell for the | ||
| 15024 | + // few 16-px-granular uses below. | ||
| 15025 | + let (r, c) = (at.0 / (SUB / MI), at.1 / (SUB / MI)); | ||
| 14421 | // lane-inter8 r2: the inter side bands are mi-granular; this block's own | 15026 | // lane-inter8 r2: the inter side bands are mi-granular; this block's own |
| 14422 | // above/left neighbour is the mi cell at its top-left corner (libaom | 15027 | // above/left neighbour is the mi cell at its top-left corner (libaom |
| 14423 | // `above_mbmi` = mi(mi_row - 1, mi_col)), so a SUB-aligned block reads | 15028 | // `above_mbmi` = mi(mi_row - 1, mi_col)), so a SUB-aligned block reads |
| 14424 | // exactly what it read before. | 15029 | // exactly what it read before. |
| 14425 | - let (rmi, cmi) = (r * (SUB / MI), c * (SUB / MI)); | 15030 | + let (rmi, cmi) = at; |
| 14426 | - let (px, py) = (c * SUB, r * SUB); | 15031 | + let (px, py) = (at.1 * MI, at.0 * MI); |
| 14427 | let (cpx, cpy) = (px / 2, py / 2); | 15032 | let (cpx, cpy) = (px / 2, py / 2); |
| 14428 | let chroma_side = side / 2; | 15033 | let chroma_side = side / 2; |
| 14429 | let (write_chroma_w, write_chroma_h) = (write_w / 2, write_h / 2); | 15034 | let (write_chroma_w, write_chroma_h) = (write_w / 2, write_h / 2); |
| @@ -14431,7 +15036,7 @@ fn decode_inter_block( | |||
| 14431 | if std::env::var_os("EC_AV1_TELL").is_some() { | 15036 | if std::env::var_os("EC_AV1_TELL").is_some() { |
| 14432 | eprintln!( | 15037 | eprintln!( |
| 14433 | "TELL mi_row={} mi_col={} label=block_entry side={side} tell={} range={}", | 15038 | "TELL mi_row={} mi_col={} label=block_entry side={side} tell={} range={}", |
| 14434 | - r * SUB_MI as usize, c * SUB_MI as usize, dec.debug_bitpos(), dec.debug_state().0 | 15039 | + rmi, cmi, dec.debug_bitpos(), dec.debug_state().0 |
| 14435 | ); | 15040 | ); |
| 14436 | } | 15041 | } |
| 14437 | let skip_mode_ctx = | 15042 | let skip_mode_ctx = |
| @@ -14447,7 +15052,7 @@ fn decode_inter_block( | |||
| 14447 | } | 15052 | } |
| 14448 | // spec 5.11.5 `inter_frame_mode_info`: `inter_segment_id(1)` before | 15053 | // spec 5.11.5 `inter_frame_mode_info`: `inter_segment_id(1)` before |
| 14449 | // `skip_mode`/`skip`, `inter_segment_id(0)` after them. | 15054 | // `skip_mode`/`skip`, `inter_segment_id(0)` after them. |
| 14450 | - let (seg_mi_r, seg_mi_c) = (r * SUB_MI as usize, c * SUB_MI as usize); | 15055 | + let (seg_mi_r, seg_mi_c) = (rmi, cmi); |
| 14451 | let (seg_w_mi, seg_h_mi) = (write_w / 4, write_h / 4); | 15056 | let (seg_w_mi, seg_h_mi) = (write_w / 4, write_h / 4); |
| 14452 | inter_segment_id(dec, cdfs, seg_mi_r, seg_mi_c, seg_w_mi, seg_h_mi, false, true); | 15057 | inter_segment_id(dec, cdfs, seg_mi_r, seg_mi_c, seg_w_mi, seg_h_mi, false, true); |
| 14453 | let skip_mode = skip_mode_present && dec.symbol(&mut cdfs.skip_mode[skip_mode_ctx]) == 1; | 15058 | let skip_mode = skip_mode_present && dec.symbol(&mut cdfs.skip_mode[skip_mode_ctx]) == 1; |
| @@ -14464,21 +15069,27 @@ fn decode_inter_block( | |||
| 14464 | let skip_ctx = usize::from(neighbours.above_skip[cmi]) + usize::from(neighbours.left_skip[rmi]); | 15069 | let skip_ctx = usize::from(neighbours.above_skip[cmi]) + usize::from(neighbours.left_skip[rmi]); |
| 14465 | let skip = skip_mode || dec.symbol(&mut cdfs.skip[skip_ctx]) == 1; | 15070 | let skip = skip_mode || dec.symbol(&mut cdfs.skip[skip_ctx]) == 1; |
| 14466 | inter_segment_id(dec, cdfs, seg_mi_r, seg_mi_c, seg_w_mi, seg_h_mi, skip, false); | 15071 | inter_segment_id(dec, cdfs, seg_mi_r, seg_mi_c, seg_w_mi, seg_h_mi, skip, false); |
| 14467 | - maybe_read_cdef_idx(dec, r * SUB_MI as usize, c * SUB_MI as usize, skip); | 15072 | + maybe_read_cdef_idx(dec, rmi, cmi, skip); |
| 14468 | - maybe_read_delta_q(dec, cdfs, r * SUB_MI as usize, c * SUB_MI as usize, side == 64, skip); | 15073 | + // lane-inter4 r1: spec 5.11.6's `bSize == sbSize` -- a 64x32/64x16 strip |
| 14469 | - maybe_read_delta_lf(dec, cdfs, r * SUB_MI as usize, c * SUB_MI as usize, side == 64, skip); | 15074 | + // is NOT the whole superblock, so its `skip` never suppresses the read. |
| 15075 | + let whole_sb = side == 64 && write_w == 64 && write_h == 64; | ||
| 15076 | + maybe_read_delta_q(dec, cdfs, rmi, cmi, whole_sb, skip); | ||
| 15077 | + maybe_read_delta_lf(dec, cdfs, rmi, cmi, whole_sb, skip); | ||
| 14470 | // lane-warp r5: see `reject_residual` -- a square-block decode of a | 15078 | // lane-warp r5: see `reject_residual` -- a square-block decode of a |
| 14471 | // HORZ_B strip is symbol-exact only for `skip` (no residual, no | 15079 | // HORZ_B strip is symbol-exact only for `skip` (no residual, no |
| 14472 | // motion_mode/warp symbol), so gate here before any further read. | 15080 | // motion_mode/warp symbol), so gate here before any further read. |
| 14473 | - if reject_residual && !skip { | 15081 | + if reject_residual && !skip && !rect_inter_residual_supported(write_w, write_h) { |
| 15082 | + if std::env::var_os("EC_AV1_RECT_DUMP").is_some() { | ||
| 15083 | + eprintln!("EC_RECT_REFUSE mi_row={rmi} mi_col={cmi} w={write_w} h={write_h} side={side}"); | ||
| 15084 | + } | ||
| 14474 | return Err(unsupported( | 15085 | return Err(unsupported( |
| 14475 | "a non-skip rectangular (HORZ/VERT/HORZ_B) strip needs rectangular residual coding", | 15086 | "a non-skip rectangular (HORZ/VERT/HORZ_B) strip needs rectangular residual coding", |
| 14476 | )); | 15087 | )); |
| 14477 | } | 15088 | } |
| 14478 | 15089 | ||
| 14479 | let (has_above, has_left) = ( | 15090 | let (has_above, has_left) = ( |
| 14480 | - r > neighbours.tile_row0_mi / (SUB / MI), | 15091 | + rmi > neighbours.tile_row0_mi, |
| 14481 | - c > neighbours.tile_col0_mi / (SUB / MI), | 15092 | + cmi > neighbours.tile_col0_mi, |
| 14482 | ); | 15093 | ); |
| 14483 | let (above_inter, left_inter) = (neighbours.above_inter[cmi], neighbours.left_inter[rmi]); | 15094 | let (above_inter, left_inter) = (neighbours.above_inter[cmi], neighbours.left_inter[rmi]); |
| 14484 | let ii_ctx = intra_inter_ctx(has_above, has_left, above_inter, left_inter); | 15095 | let ii_ctx = intra_inter_ctx(has_above, has_left, above_inter, left_inter); |
| @@ -14486,15 +15097,15 @@ fn decode_inter_block( | |||
| 14486 | if std::env::var_os("EC_TRACE_MODE").is_some() { | 15097 | if std::env::var_os("EC_TRACE_MODE").is_some() { |
| 14487 | eprintln!( | 15098 | eprintln!( |
| 14488 | "EC_MODE mi_row={} mi_col={} rng={}", | 15099 | "EC_MODE mi_row={} mi_col={} rng={}", |
| 14489 | - r * SUB_MI as usize, | 15100 | + rmi, |
| 14490 | - c * SUB_MI as usize, | 15101 | + cmi, |
| 14491 | dec.debug_state().0 | 15102 | dec.debug_state().0 |
| 14492 | ); | 15103 | ); |
| 14493 | } | 15104 | } |
| 14494 | if std::env::var_os("EC_AV1_TELL").is_some() { | 15105 | if std::env::var_os("EC_AV1_TELL").is_some() { |
| 14495 | eprintln!( | 15106 | eprintln!( |
| 14496 | "TELL mi_row={} mi_col={} label=post_is_inter skip_mode={skip_mode} skip={skip} is_inter={is_inter} tell={} range={}", | 15107 | "TELL mi_row={} mi_col={} label=post_is_inter skip_mode={skip_mode} skip={skip} is_inter={is_inter} tell={} range={}", |
| 14497 | - r * SUB_MI as usize, c * SUB_MI as usize, dec.debug_bitpos(), dec.debug_state().0 | 15108 | + rmi, cmi, dec.debug_bitpos(), dec.debug_state().0 |
| 14498 | ); | 15109 | ); |
| 14499 | } | 15110 | } |
| 14500 | 15111 | ||
| @@ -14514,7 +15125,7 @@ fn decode_inter_block( | |||
| 14514 | // than one luma transform -- read back by the residual loop, the | 15125 | // than one luma transform -- read back by the residual loop, the |
| 14515 | // coefficient-context write-back and the loop-filter grid fill below. | 15126 | // coefficient-context write-back and the loop-filter grid fill below. |
| 14516 | let mut vartx_leaves: Option<Vec<(usize, usize, usize)>> = None; | 15127 | let mut vartx_leaves: Option<Vec<(usize, usize, usize)>> = None; |
| 14517 | - let at_mi = (r * (SUB / MI), c * (SUB / MI)); | 15128 | + let at_mi = at; |
| 14518 | if is_inter { | 15129 | if is_inter { |
| 14519 | let above_nbr = has_above.then(|| NeighbourRef { | 15130 | let above_nbr = has_above.then(|| NeighbourRef { |
| 14520 | is_inter: above_inter, | 15131 | is_inter: above_inter, |
| @@ -14559,7 +15170,7 @@ fn decode_inter_block( | |||
| 14559 | neighbours.left_ref[rmi], | 15170 | neighbours.left_ref[rmi], |
| 14560 | ) | 15171 | ) |
| 14561 | }; | 15172 | }; |
| 14562 | - let (mi_row, mi_col) = (r * SUB_MI as usize, c * SUB_MI as usize); | 15173 | + let (mi_row, mi_col) = (rmi, cmi); |
| 14563 | // lane-rect r2: true footprint, mirroring the single-ref path below. | 15174 | // lane-rect r2: true footprint, mirroring the single-ref path below. |
| 14564 | let bw4 = write_w / 4; | 15175 | let bw4 = write_w / 4; |
| 14565 | let bh4 = write_h / 4; | 15176 | let bh4 = write_h / 4; |
| @@ -15293,17 +15904,32 @@ fn decode_inter_block( | |||
| 15293 | mc::combine_compound(&inter0_v, &inter1_v, fwd_offset, bck_offset, &mut pred_v); | 15904 | mc::combine_compound(&inter0_v, &inter1_v, fwd_offset, bck_offset, &mut pred_v); |
| 15294 | } | 15905 | } |
| 15295 | 15906 | ||
| 15296 | - vartx_leaves = read_block_tx_size( | 15907 | + // lane-inter4 r2: a rectangular strip's transform tree starts from |
| 15297 | - dec, | 15908 | + // its own rect `max_txsize_rect_lookup` entry, not a square one. |
| 15298 | - cdfs, | 15909 | + let rect_tu = (write_w, write_h) != (side, side); |
| 15299 | - neighbours, | 15910 | + vartx_leaves = if rect_tu { |
| 15300 | - at_mi, | 15911 | + read_block_tx_size_rect( |
| 15301 | - side, | 15912 | + dec, |
| 15302 | - (mi_cols as usize, mi_rows as usize), | 15913 | + cdfs, |
| 15303 | - true, | 15914 | + neighbours, |
| 15304 | - skip, | 15915 | + at_mi, |
| 15305 | - )? | 15916 | + (write_w, write_h), |
| 15306 | - .1; | 15917 | + (mi_cols as usize, mi_rows as usize), |
| 15918 | + skip, | ||
| 15919 | + )? | ||
| 15920 | + } else { | ||
| 15921 | + read_block_tx_size( | ||
| 15922 | + dec, | ||
| 15923 | + cdfs, | ||
| 15924 | + neighbours, | ||
| 15925 | + at_mi, | ||
| 15926 | + side, | ||
| 15927 | + (mi_cols as usize, mi_rows as usize), | ||
| 15928 | + true, | ||
| 15929 | + skip, | ||
| 15930 | + )? | ||
| 15931 | + .1 | ||
| 15932 | + }; | ||
| 15307 | if skip { | 15933 | if skip { |
| 15308 | y.reconstruct_mc_rect( | 15934 | y.reconstruct_mc_rect( |
| 15309 | px, | 15935 | px, |
| @@ -15336,7 +15962,14 @@ fn decode_inter_block( | |||
| 15336 | u_grid = vec![0i32; chroma_side * chroma_side]; | 15962 | u_grid = vec![0i32; chroma_side * chroma_side]; |
| 15337 | v_grid = vec![0i32; chroma_side * chroma_side]; | 15963 | v_grid = vec![0i32; chroma_side * chroma_side]; |
| 15338 | } else { | 15964 | } else { |
| 15339 | - let around = neighbours.around(at, side); | 15965 | + // lane-inter4 r2: a rect strip's coefficient context spans its |
| 15966 | + // OWN width above and height left -- reading `side` cells both | ||
| 15967 | + // ways indexes past the tile's last mi row for a bottom strip. | ||
| 15968 | + let around = if rect_tu { | ||
| 15969 | + neighbours.around_mi_rect(at_mi, write_w, write_h) | ||
| 15970 | + } else { | ||
| 15971 | + neighbours.around_mi(at, side) | ||
| 15972 | + }; | ||
| 15340 | let luma_tx_type; | 15973 | let luma_tx_type; |
| 15341 | if let Some(leaves) = vartx_leaves.clone() { | 15974 | if let Some(leaves) = vartx_leaves.clone() { |
| 15342 | // spec 5.11.17's transform tree, leaf by leaf in the order | 15975 | // spec 5.11.17's transform tree, leaf by leaf in the order |
| @@ -15383,6 +16016,26 @@ fn decode_inter_block( | |||
| 15383 | // inherits the *first* (top-left) luma unit's coded type. | 16016 | // inherits the *first* (top-left) luma unit's coded type. |
| 15384 | luma_tx_type = first_tx_type; | 16017 | luma_tx_type = first_tx_type; |
| 15385 | luma_grid = vec![0i32; side * side]; | 16018 | luma_grid = vec![0i32; side * side]; |
| 16019 | + } else if rect_tu { | ||
| 16020 | + // The whole-block rectangular transform unit | ||
| 16021 | + // (`txfm_partition` said 0 at depth 0). | ||
| 16022 | + let (grid, tx_type) = read_inter_plane_rect( | ||
| 16023 | + dec, | ||
| 16024 | + cdfs, | ||
| 16025 | + rect_inter_luma_set(write_w, write_h), | ||
| 16026 | + (write_w, write_h), | ||
| 16027 | + side, | ||
| 16028 | + 0, | ||
| 16029 | + around[0], | ||
| 16030 | + mode_for_tx, | ||
| 16031 | + y, | ||
| 16032 | + px, | ||
| 16033 | + py, | ||
| 16034 | + &pred_y, | ||
| 16035 | + None, | ||
| 16036 | + )?; | ||
| 16037 | + luma_tx_type = tx_type; | ||
| 16038 | + luma_grid = embed_rect_grid(&grid, write_w, write_h, side); | ||
| 15386 | } else { | 16039 | } else { |
| 15387 | (luma_grid, luma_tx_type) = read_inter_plane( | 16040 | (luma_grid, luma_tx_type) = read_inter_plane( |
| 15388 | dec, | 16041 | dec, |
| @@ -15402,6 +16055,55 @@ fn decode_inter_block( | |||
| 15402 | None, | 16055 | None, |
| 15403 | )?; | 16056 | )?; |
| 15404 | } | 16057 | } |
| 16058 | + if rect_tu { | ||
| 16059 | + // `av1_get_max_uv_txsize(bsize)`: the chroma transform of a | ||
| 16060 | + // 2:1 strip is the strip's own rect chroma size (16x8 / | ||
| 16061 | + // 8x16), one unit for the whole block, and it codes no | ||
| 16062 | + // `tx_type` symbol -- it inherits the luma unit's. | ||
| 16063 | + let (uw, uh) = (write_chroma_w, write_chroma_h); | ||
| 16064 | + u_grid = embed_rect_grid( | ||
| 16065 | + &read_inter_plane_rect( | ||
| 16066 | + dec, | ||
| 16067 | + cdfs, | ||
| 16068 | + rect_inter_chroma_set(write_chroma_w, write_chroma_h), | ||
| 16069 | + (uw, uh), | ||
| 16070 | + chroma_side, | ||
| 16071 | + 1, | ||
| 16072 | + around[1], | ||
| 16073 | + mode_for_tx, | ||
| 16074 | + u, | ||
| 16075 | + cpx, | ||
| 16076 | + cpy, | ||
| 16077 | + &pred_u, | ||
| 16078 | + Some(luma_tx_type), | ||
| 16079 | + )? | ||
| 16080 | + .0, | ||
| 16081 | + uw, | ||
| 16082 | + uh, | ||
| 16083 | + chroma_side, | ||
| 16084 | + ); | ||
| 16085 | + v_grid = embed_rect_grid( | ||
| 16086 | + &read_inter_plane_rect( | ||
| 16087 | + dec, | ||
| 16088 | + cdfs, | ||
| 16089 | + rect_inter_chroma_set(write_chroma_w, write_chroma_h), | ||
| 16090 | + (uw, uh), | ||
| 16091 | + chroma_side, | ||
| 16092 | + 2, | ||
| 16093 | + around[2], | ||
| 16094 | + mode_for_tx, | ||
| 16095 | + v, | ||
| 16096 | + cpx, | ||
| 16097 | + cpy, | ||
| 16098 | + &pred_v, | ||
| 16099 | + Some(luma_tx_type), | ||
| 16100 | + )? | ||
| 16101 | + .0, | ||
| 16102 | + uw, | ||
| 16103 | + uh, | ||
| 16104 | + chroma_side, | ||
| 16105 | + ); | ||
| 16106 | + } else { | ||
| 15405 | u_grid = read_inter_plane( | 16107 | u_grid = read_inter_plane( |
| 15406 | dec, | 16108 | dec, |
| 15407 | cdfs, | 16109 | cdfs, |
| @@ -15438,6 +16140,7 @@ fn decode_inter_block( | |||
| 15438 | None, | 16140 | None, |
| 15439 | )? | 16141 | )? |
| 15440 | .0; | 16142 | .0; |
| 16143 | + } | ||
| 15441 | } | 16144 | } |
| 15442 | } else { | 16145 | } else { |
| 15443 | let ref_frame = | 16146 | let ref_frame = |
| @@ -15451,7 +16154,7 @@ fn decode_inter_block( | |||
| 15451 | ); | 16154 | ); |
| 15452 | ref_frame_for_lf = ref_frame; | 16155 | ref_frame_for_lf = ref_frame; |
| 15453 | if std::env::var_os("EC_AV1_TELL").is_some() { | 16156 | if std::env::var_os("EC_AV1_TELL").is_some() { |
| 15454 | - let (mi_row, mi_col) = (r * SUB_MI as usize, c * SUB_MI as usize); | 16157 | + let (mi_row, mi_col) = (rmi, cmi); |
| 15455 | eprintln!( | 16158 | eprintln!( |
| 15456 | "TELL mi_row={mi_row} mi_col={mi_col} label=post_ref_frame ref={ref_frame} tell={} range={}", | 16159 | "TELL mi_row={mi_row} mi_col={mi_col} label=post_ref_frame ref={ref_frame} tell={} range={}", |
| 15457 | dec.debug_bitpos(), dec.debug_state().0 | 16160 | dec.debug_bitpos(), dec.debug_state().0 |
| @@ -15479,7 +16182,7 @@ fn decode_inter_block( | |||
| 15479 | } | 16182 | } |
| 15480 | }; | 16183 | }; |
| 15481 | 16184 | ||
| 15482 | - let (mi_row, mi_col) = (r * SUB_MI as usize, c * SUB_MI as usize); | 16185 | + let (mi_row, mi_col) = (rmi, cmi); |
| 15483 | // lane-rect r2: the mv stack must be queried with the block's | 16186 | // lane-rect r2: the mv stack must be queried with the block's |
| 15484 | // REAL extent (libaom `av1_get_mv_refs` gets bw4/bh4 from | 16187 | // REAL extent (libaom `av1_get_mv_refs` gets bw4/bh4 from |
| 15485 | // xd->width/xd->height, not a square guess) -- `write_w`/ | 16188 | // xd->width/xd->height, not a square guess) -- `write_w`/ |
| @@ -15526,6 +16229,10 @@ fn decode_inter_block( | |||
| 15526 | ); | 16229 | ); |
| 15527 | let not_new = dec.symbol(&mut cdfs.new_mv[stack.new_mv_ctx]) == 1; | 16230 | let not_new = dec.symbol(&mut cdfs.new_mv[stack.new_mv_ctx]) == 1; |
| 15528 | let mut is_globalmv = false; | 16231 | let mut is_globalmv = false; |
| 16232 | + // lane-interbis r1: which single-ref mode this block resolved to, | ||
| 16233 | + // in the oracle's own numbering (NEARESTMV=13 .. NEWMV=16), for | ||
| 16234 | + // the `EC_MODE_VAL` value ladder below. | ||
| 16235 | + let mut dbg_mode = 16u32; | ||
| 15529 | let (mv, is_new_mv) = if !not_new { | 16236 | let (mv, is_new_mv) = if !not_new { |
| 15530 | // NEWMV (spec 5.11.24's `read_drl_idx`, `RefMvIdx` starting at 0): | 16237 | // NEWMV (spec 5.11.24's `read_drl_idx`, `RefMvIdx` starting at 0): |
| 15531 | // read at most two `drl_mode` bits, one per stack entry past the | 16238 | // read at most two `drl_mode` bits, one per stack entry past the |
| @@ -15558,9 +16265,11 @@ fn decode_inter_block( | |||
| 15558 | let mv = if !not_zero { | 16265 | let mv = if !not_zero { |
| 15559 | // GLOBALMV: `gm_get_motion_vector` (spec 7.10.2.1), already | 16266 | // GLOBALMV: `gm_get_motion_vector` (spec 7.10.2.1), already |
| 15560 | // computed at this block's own position in `gm_table`. | 16267 | // computed at this block's own position in `gm_table`. |
| 16268 | + dbg_mode = 15; | ||
| 15561 | gm_table[(ref_frame - LAST_FRAME) as usize] | 16269 | gm_table[(ref_frame - LAST_FRAME) as usize] |
| 15562 | } else { | 16270 | } else { |
| 15563 | let nearest = dec.symbol(&mut cdfs.ref_mv[stack.ref_mv_ctx]) == 0; | 16271 | let nearest = dec.symbol(&mut cdfs.ref_mv[stack.ref_mv_ctx]) == 0; |
| 16272 | + dbg_mode = if nearest { 13 } else { 14 }; | ||
| 15564 | if nearest { | 16273 | if nearest { |
| 15565 | stack.nearest_mv | 16274 | stack.nearest_mv |
| 15566 | } else { | 16275 | } else { |
| @@ -15582,6 +16291,21 @@ fn decode_inter_block( | |||
| 15582 | }; | 16291 | }; |
| 15583 | (mv, false) | 16292 | (mv, false) |
| 15584 | }; | 16293 | }; |
| 16294 | + if std::env::var_os("EC_TRACE_MODE").is_some() { | ||
| 16295 | + for (i, e) in stack.entries.iter().enumerate() { | ||
| 16296 | + eprintln!( | ||
| 16297 | + "EC_STACK mi_row={mi_row} mi_col={mi_col} ref={ref_frame} i={i} this=({},{}) comp=(0,0) w={}", | ||
| 16298 | + e.mv.0, e.mv.1, e.weight | ||
| 16299 | + ); | ||
| 16300 | + } | ||
| 16301 | + eprintln!( | ||
| 16302 | + "EC_MODE_VAL mi_row={mi_row} mi_col={mi_col} mode={dbg_mode} ref0={ref_frame} ref1=-1 mv0=({},{}) stack={} rng={}", | ||
| 16303 | + mv.0, | ||
| 16304 | + mv.1, | ||
| 16305 | + stack.entries.len(), | ||
| 16306 | + dec.debug_state().0 | ||
| 16307 | + ); | ||
| 16308 | + } | ||
| 15585 | // lane-gm r2: the two libaom predicates single-ref GLOBALMV | 16309 | // lane-gm r2: the two libaom predicates single-ref GLOBALMV |
| 15586 | // blocks need -- `is_global_mv_block` (blockd.h:421-429, mode | 16310 | // blocks need -- `is_global_mv_block` (blockd.h:421-429, mode |
| 15587 | // GLOBAL* AND model > TRANSLATION AND min(bw,bh) >= 8px, gating | 16311 | // GLOBAL* AND model > TRANSLATION AND min(bw,bh) >= 8px, gating |
| @@ -15613,8 +16337,22 @@ fn decode_inter_block( | |||
| 15613 | // `size_group_lookup`: BLOCK_16X16 -> 2, BLOCK_32X32 -> 3. | 16337 | // `size_group_lookup`: BLOCK_16X16 -> 2, BLOCK_32X32 -> 3. |
| 15614 | let mut interintra_mode: Option<u8> = None; | 16338 | let mut interintra_mode: Option<u8> = None; |
| 15615 | let mut wedge_mask: Option<(&'static [u8], usize)> = None; | 16339 | let mut wedge_mask: Option<(&'static [u8], usize)> = None; |
| 15616 | - if enable_interintra_compound && !skip_mode && (side == 16 || side == 32) { | 16340 | + // lane-inter4 r1: `is_interintra_allowed_bsize` is |
| 15617 | - let bsize_group = if side == 16 { 2 } else { 3 }; | 16341 | + // `BLOCK_8X8..=BLOCK_32X32` in libaom's enum ORDER, which excludes |
| 16342 | + // every 1:4 shape (BLOCK_8X32 = 18, BLOCK_32X8 = 19) even though | ||
| 16343 | + // both dimensions are in range -- reading this symbol on a 1:4 | ||
| 16344 | + // strip is a symbol the reference never wrote. | ||
| 16345 | + let interintra_shape = | ||
| 16346 | + write_w.max(write_h) <= 32 && write_w.max(write_h) / write_w.min(write_h) <= 2; | ||
| 16347 | + if enable_interintra_compound | ||
| 16348 | + && !skip_mode | ||
| 16349 | + && (side == 16 || side == 32) | ||
| 16350 | + && interintra_shape | ||
| 16351 | + { | ||
| 16352 | + // lane-inter4 r3: `size_group_lookup` reads the block's | ||
| 16353 | + // TRUE footprint -- a 16x8 strip is group 1, a 32x16 strip | ||
| 16354 | + // group 2, not their square `side`'s 2/3. | ||
| 16355 | + let bsize_group = size_group_wh(write_w, write_h); | ||
| 15618 | let interintra = dec.symbol(&mut cdfs.interintra[bsize_group]) == 1; | 16356 | let interintra = dec.symbol(&mut cdfs.interintra[bsize_group]) == 1; |
| 15619 | if interintra { | 16357 | if interintra { |
| 15620 | // lane-interintra r1 (decodemv.c 1540-1555): interintra_mode, | 16358 | // lane-interintra r1 (decodemv.c 1540-1555): interintra_mode, |
| @@ -15709,12 +16447,29 @@ fn decode_inter_block( | |||
| 15709 | // (libaom `motion_mode_cdf[mbmi->bsize]`: BLOCK_16X32 -> 4, | 16447 | // (libaom `motion_mode_cdf[mbmi->bsize]`: BLOCK_16X32 -> 4, |
| 15710 | // BLOCK_32X16 -> 5 in our packed table) -- rect-flake-1's | 16448 | // BLOCK_32X16 -> 5 in our packed table) -- rect-flake-1's |
| 15711 | // strip motion_mode read diverged on the square row. | 16449 | // strip motion_mode read diverged on the square row. |
| 15712 | - let bsize_idx = if write_w == write_h { | 16450 | + // lane-inter4 r1: every rect shape this decoder can now |
| 15713 | - (write_w.trailing_zeros() - 3) as usize | 16451 | + // reach reads its OWN libaom bsize row (the packed order is |
| 15714 | - } else if write_w == 16 { | 16452 | + // documented on `cdf::MOTION_MODE`); a wrong row is a wrong |
| 15715 | - 4 | 16453 | + // interval narrowing, not a wrong value (class |
| 15716 | - } else { | 16454 | + // wrong-alphabet-same-value). |
| 15717 | - 5 | 16455 | + let bsize_idx = match (write_w, write_h) { |
| 16456 | + (w, h) if w == h => (w.trailing_zeros() - 3) as usize, | ||
| 16457 | + (16, 32) => 4, | ||
| 16458 | + (32, 16) => 5, | ||
| 16459 | + (32, 64) => 6, | ||
| 16460 | + (64, 32) => 7, | ||
| 16461 | + (8, 32) => 8, | ||
| 16462 | + (32, 8) => 9, | ||
| 16463 | + (16, 64) => 10, | ||
| 16464 | + (64, 16) => 11, | ||
| 16465 | + // lane-inter4 r3: the 16x16-level rect inter leaves. | ||
| 16466 | + (8, 16) => 12, | ||
| 16467 | + (16, 8) => 13, | ||
| 16468 | + _ => { | ||
| 16469 | + return Err(unsupported( | ||
| 16470 | + "a motion_mode symbol for a block shape with no CDF row here", | ||
| 16471 | + )); | ||
| 16472 | + } | ||
| 15718 | }; | 16473 | }; |
| 15719 | // `motion_mode_allowed` reads the 3-symbol `motion_mode_cdf` | 16474 | // `motion_mode_allowed` reads the 3-symbol `motion_mode_cdf` |
| 15720 | // instead of the 2-symbol `obmc_cdf` exactly when | 16475 | // instead of the 2-symbol `obmc_cdf` exactly when |
| @@ -16127,17 +16882,32 @@ fn decode_inter_block( | |||
| 16127 | interintra_blend(v, cpx, cpy, chroma_side, ii, wedge_mask, &mut pred_v); | 16882 | interintra_blend(v, cpx, cpy, chroma_side, ii, wedge_mask, &mut pred_v); |
| 16128 | } | 16883 | } |
| 16129 | 16884 | ||
| 16130 | - vartx_leaves = read_block_tx_size( | 16885 | + // lane-inter4 r2: a rectangular strip's transform tree starts from |
| 16131 | - dec, | 16886 | + // its own rect `max_txsize_rect_lookup` entry, not a square one. |
| 16132 | - cdfs, | 16887 | + let rect_tu = (write_w, write_h) != (side, side); |
| 16133 | - neighbours, | 16888 | + vartx_leaves = if rect_tu { |
| 16134 | - at_mi, | 16889 | + read_block_tx_size_rect( |
| 16135 | - side, | 16890 | + dec, |
| 16136 | - (mi_cols as usize, mi_rows as usize), | 16891 | + cdfs, |
| 16137 | - true, | 16892 | + neighbours, |
| 16138 | - skip, | 16893 | + at_mi, |
| 16139 | - )? | 16894 | + (write_w, write_h), |
| 16140 | - .1; | 16895 | + (mi_cols as usize, mi_rows as usize), |
| 16896 | + skip, | ||
| 16897 | + )? | ||
| 16898 | + } else { | ||
| 16899 | + read_block_tx_size( | ||
| 16900 | + dec, | ||
| 16901 | + cdfs, | ||
| 16902 | + neighbours, | ||
| 16903 | + at_mi, | ||
| 16904 | + side, | ||
| 16905 | + (mi_cols as usize, mi_rows as usize), | ||
| 16906 | + true, | ||
| 16907 | + skip, | ||
| 16908 | + )? | ||
| 16909 | + .1 | ||
| 16910 | + }; | ||
| 16141 | if skip { | 16911 | if skip { |
| 16142 | y.reconstruct_mc_rect( | 16912 | y.reconstruct_mc_rect( |
| 16143 | px, | 16913 | px, |
| @@ -16170,7 +16940,14 @@ fn decode_inter_block( | |||
| 16170 | u_grid = vec![0i32; chroma_side * chroma_side]; | 16940 | u_grid = vec![0i32; chroma_side * chroma_side]; |
| 16171 | v_grid = vec![0i32; chroma_side * chroma_side]; | 16941 | v_grid = vec![0i32; chroma_side * chroma_side]; |
| 16172 | } else { | 16942 | } else { |
| 16173 | - let around = neighbours.around(at, side); | 16943 | + // lane-inter4 r2: a rect strip's coefficient context spans its |
| 16944 | + // OWN width above and height left -- reading `side` cells both | ||
| 16945 | + // ways indexes past the tile's last mi row for a bottom strip. | ||
| 16946 | + let around = if rect_tu { | ||
| 16947 | + neighbours.around_mi_rect(at_mi, write_w, write_h) | ||
| 16948 | + } else { | ||
| 16949 | + neighbours.around_mi(at, side) | ||
| 16950 | + }; | ||
| 16174 | let luma_tx_type; | 16951 | let luma_tx_type; |
| 16175 | if let Some(leaves) = vartx_leaves.clone() { | 16952 | if let Some(leaves) = vartx_leaves.clone() { |
| 16176 | // spec 5.11.17's transform tree, leaf by leaf in the order | 16953 | // spec 5.11.17's transform tree, leaf by leaf in the order |
| @@ -16217,6 +16994,26 @@ fn decode_inter_block( | |||
| 16217 | // inherits the *first* (top-left) luma unit's coded type. | 16994 | // inherits the *first* (top-left) luma unit's coded type. |
| 16218 | luma_tx_type = first_tx_type; | 16995 | luma_tx_type = first_tx_type; |
| 16219 | luma_grid = vec![0i32; side * side]; | 16996 | luma_grid = vec![0i32; side * side]; |
| 16997 | + } else if rect_tu { | ||
| 16998 | + // The whole-block rectangular transform unit | ||
| 16999 | + // (`txfm_partition` said 0 at depth 0). | ||
| 17000 | + let (grid, tx_type) = read_inter_plane_rect( | ||
| 17001 | + dec, | ||
| 17002 | + cdfs, | ||
| 17003 | + rect_inter_luma_set(write_w, write_h), | ||
| 17004 | + (write_w, write_h), | ||
| 17005 | + side, | ||
| 17006 | + 0, | ||
| 17007 | + around[0], | ||
| 17008 | + mode_for_tx, | ||
| 17009 | + y, | ||
| 17010 | + px, | ||
| 17011 | + py, | ||
| 17012 | + &pred_y, | ||
| 17013 | + None, | ||
| 17014 | + )?; | ||
| 17015 | + luma_tx_type = tx_type; | ||
| 17016 | + luma_grid = embed_rect_grid(&grid, write_w, write_h, side); | ||
| 16220 | } else { | 17017 | } else { |
| 16221 | (luma_grid, luma_tx_type) = read_inter_plane( | 17018 | (luma_grid, luma_tx_type) = read_inter_plane( |
| 16222 | dec, | 17019 | dec, |
| @@ -16236,6 +17033,55 @@ fn decode_inter_block( | |||
| 16236 | None, | 17033 | None, |
| 16237 | )?; | 17034 | )?; |
| 16238 | } | 17035 | } |
| 17036 | + if rect_tu { | ||
| 17037 | + // `av1_get_max_uv_txsize(bsize)`: the chroma transform of a | ||
| 17038 | + // 2:1 strip is the strip's own rect chroma size (16x8 / | ||
| 17039 | + // 8x16), one unit for the whole block, and it codes no | ||
| 17040 | + // `tx_type` symbol -- it inherits the luma unit's. | ||
| 17041 | + let (uw, uh) = (write_chroma_w, write_chroma_h); | ||
| 17042 | + u_grid = embed_rect_grid( | ||
| 17043 | + &read_inter_plane_rect( | ||
| 17044 | + dec, | ||
| 17045 | + cdfs, | ||
| 17046 | + rect_inter_chroma_set(write_chroma_w, write_chroma_h), | ||
| 17047 | + (uw, uh), | ||
| 17048 | + chroma_side, | ||
| 17049 | + 1, | ||
| 17050 | + around[1], | ||
| 17051 | + mode_for_tx, | ||
| 17052 | + u, | ||
| 17053 | + cpx, | ||
| 17054 | + cpy, | ||
| 17055 | + &pred_u, | ||
| 17056 | + Some(luma_tx_type), | ||
| 17057 | + )? | ||
| 17058 | + .0, | ||
| 17059 | + uw, | ||
| 17060 | + uh, | ||
| 17061 | + chroma_side, | ||
| 17062 | + ); | ||
| 17063 | + v_grid = embed_rect_grid( | ||
| 17064 | + &read_inter_plane_rect( | ||
| 17065 | + dec, | ||
| 17066 | + cdfs, | ||
| 17067 | + rect_inter_chroma_set(write_chroma_w, write_chroma_h), | ||
| 17068 | + (uw, uh), | ||
| 17069 | + chroma_side, | ||
| 17070 | + 2, | ||
| 17071 | + around[2], | ||
| 17072 | + mode_for_tx, | ||
| 17073 | + v, | ||
| 17074 | + cpx, | ||
| 17075 | + cpy, | ||
| 17076 | + &pred_v, | ||
| 17077 | + Some(luma_tx_type), | ||
| 17078 | + )? | ||
| 17079 | + .0, | ||
| 17080 | + uw, | ||
| 17081 | + uh, | ||
| 17082 | + chroma_side, | ||
| 17083 | + ); | ||
| 17084 | + } else { | ||
| 16239 | u_grid = read_inter_plane( | 17085 | u_grid = read_inter_plane( |
| 16240 | dec, | 17086 | dec, |
| 16241 | cdfs, | 17087 | cdfs, |
| @@ -16272,6 +17118,7 @@ fn decode_inter_block( | |||
| 16272 | None, | 17118 | None, |
| 16273 | )? | 17119 | )? |
| 16274 | .0; | 17120 | .0; |
| 17121 | + } | ||
| 16275 | } | 17122 | } |
| 16276 | } | 17123 | } |
| 16277 | } else { | 17124 | } else { |
| @@ -16287,20 +17134,35 @@ fn decode_inter_block( | |||
| 16287 | this decoder does not code yet", | 17134 | this decoder does not code yet", |
| 16288 | )); | 17135 | )); |
| 16289 | } | 17136 | } |
| 16290 | - let mode = dec.symbol(&mut cdfs.y_mode[size_group]); | 17137 | + let mode = dec.symbol(&mut cdfs.y_mode[size_group_wh(write_w, write_h)]); |
| 16291 | if mode >= 13 { | 17138 | if mode >= 13 { |
| 16292 | return Err(unsupported( | 17139 | return Err(unsupported( |
| 16293 | "an intra mode this decoder does not code (round 2)", | 17140 | "an intra mode this decoder does not code (round 2)", |
| 16294 | )); | 17141 | )); |
| 16295 | } | 17142 | } |
| 16296 | - if (V_PRED..=D67_PRED).contains(&mode) { | 17143 | + // lane-angleinter r1: `read_intra_angle_info` (libaom `decodemv.c`, |
| 16297 | - let angle = dec.symbol(&mut cdfs.angle_delta[mode - V_PRED]); | 17144 | + // inside `read_intra_block_mode_info`) -- an intra block in an inter |
| 16298 | - if angle != ANGLE_DELTA_ZERO { | 17145 | + // frame reads `angle_delta_y` off the same |
| 16299 | - return Err(unsupported( | 17146 | + // `angle_delta_cdf[mode - V_PRED]` row a key-frame block does, and |
| 16300 | - "a nonzero angle delta (this encoder never writes one)", | 17147 | + // the delta feeds the directional predictor (and the edge |
| 16301 | - )); | 17148 | + // filter/upsample decision derived from the delta'd angle) unchanged. |
| 16302 | - } | 17149 | + // The symbol was read and then refused before this round even though |
| 16303 | - } | 17150 | + // aomenc enables `--enable-angle-delta` by default. |
| 17151 | + let angle_delta_y = if (V_PRED..=D67_PRED).contains(&mode) { | ||
| 17152 | + read_angle_delta(dec, &mut cdfs.angle_delta[mode - V_PRED]) | ||
| 17153 | + } else { | ||
| 17154 | + 0 | ||
| 17155 | + }; | ||
| 17156 | + if angle_delta_y != 0 { | ||
| 17157 | + INTRA_IN_INTER_ANGLE_DELTA_Y_HITS.with(|c| c.set(c.get() + 1)); | ||
| 17158 | + } | ||
| 17159 | + // The delta'd angle decides whether the intra edge filter runs at | ||
| 17160 | + // all, so this block needs the same luma edge-filter-type neighbour | ||
| 17161 | + // check a key-frame block does (`get_intra_edge_filter_type`, spec | ||
| 17162 | + // 7.11.2) -- this arm passed a hardcoded `false` while every | ||
| 17163 | + // directional intra-in-inter block was refused above. | ||
| 17164 | + let (nb_above_mode, nb_left_mode) = neighbours.modes_above_left(r, c); | ||
| 17165 | + let smooth_neighbor = is_smooth_mode(nb_above_mode) || is_smooth_mode(nb_left_mode); | ||
| 16304 | let uv_mode = dec.symbol(&mut cdfs.uv_mode_cfl[mode]); | 17166 | let uv_mode = dec.symbol(&mut cdfs.uv_mode_cfl[mode]); |
| 16305 | if (9..=12).contains(&uv_mode) { | 17167 | if (9..=12).contains(&uv_mode) { |
| 16306 | SMOOTH_UV_HITS.with(|c| c.set(c.get() + 1)); | 17168 | SMOOTH_UV_HITS.with(|c| c.set(c.get() + 1)); |
| @@ -16324,6 +17186,7 @@ fn decode_inter_block( | |||
| 16324 | }; | 17186 | }; |
| 16325 | if angle_delta_uv != 0 { | 17187 | if angle_delta_uv != 0 { |
| 16326 | UV_ANGLE_DELTA_HITS.with(|c| c.set(c.get() + 1)); | 17188 | UV_ANGLE_DELTA_HITS.with(|c| c.set(c.get() + 1)); |
| 17189 | + INTRA_IN_INTER_ANGLE_DELTA_UV_HITS.with(|c| c.set(c.get() + 1)); | ||
| 16327 | } | 17190 | } |
| 16328 | uv_predict_mode = if uv_mode == UV_CFL_PRED { | 17191 | uv_predict_mode = if uv_mode == UV_CFL_PRED { |
| 16329 | DC_PRED | 17192 | DC_PRED |
| @@ -16377,7 +17240,7 @@ fn decode_inter_block( | |||
| 16377 | block_filter = [3, 3]; | 17240 | block_filter = [3, 3]; |
| 16378 | ref_frame_for_lf = 0; | 17241 | ref_frame_for_lf = 0; |
| 16379 | globalmv_for_lf = false; | 17242 | globalmv_for_lf = false; |
| 16380 | - let (mi_row, mi_col) = (r * SUB_MI as usize, c * SUB_MI as usize); | 17243 | + let (mi_row, mi_col) = (rmi, cmi); |
| 16381 | for dr in 0..side / 4 { | 17244 | for dr in 0..side / 4 { |
| 16382 | for dc in 0..side / 4 { | 17245 | for dc in 0..side / 4 { |
| 16383 | grid.set( | 17246 | grid.set( |
| @@ -16435,12 +17298,12 @@ fn decode_inter_block( | |||
| 16435 | tu_py, | 17298 | tu_py, |
| 16436 | tx_px, | 17299 | tx_px, |
| 16437 | mode, | 17300 | mode, |
| 16438 | - 0, | 17301 | + angle_delta_y, |
| 16439 | tu_reach, | 17302 | tu_reach, |
| 16440 | &vec![0i32; tx_px * tx_px], | 17303 | &vec![0i32; tx_px * tx_px], |
| 16441 | None, | 17304 | None, |
| 16442 | filter_intra, | 17305 | filter_intra, |
| 16443 | - false, | 17306 | + smooth_neighbor, |
| 16444 | ); | 17307 | ); |
| 16445 | vec![0i32; tx_px * tx_px] | 17308 | vec![0i32; tx_px * tx_px] |
| 16446 | } else { | 17309 | } else { |
| @@ -16457,7 +17320,7 @@ fn decode_inter_block( | |||
| 16457 | neighbours.around_mi(tu_mi, tx_px)[0], | 17320 | neighbours.around_mi(tu_mi, tx_px)[0], |
| 16458 | mode, | 17321 | mode, |
| 16459 | mode, | 17322 | mode, |
| 16460 | - 0, | 17323 | + angle_delta_y, |
| 16461 | tu_reach, | 17324 | tu_reach, |
| 16462 | y, | 17325 | y, |
| 16463 | tu_px, | 17326 | tu_px, |
| @@ -16468,7 +17331,7 @@ fn decode_inter_block( | |||
| 16468 | None, | 17331 | None, |
| 16469 | filter_intra, | 17332 | filter_intra, |
| 16470 | Some(tu_skip_ctx), | 17333 | Some(tu_skip_ctx), |
| 16471 | - false, | 17334 | + smooth_neighbor, |
| 16472 | )? | 17335 | )? |
| 16473 | }; | 17336 | }; |
| 16474 | neighbours.record_mi_luma(tu_mi, tx_px, &tu_grid); | 17337 | neighbours.record_mi_luma(tu_mi, tx_px, &tu_grid); |
| @@ -16481,12 +17344,12 @@ fn decode_inter_block( | |||
| 16481 | py, | 17344 | py, |
| 16482 | side, | 17345 | side, |
| 16483 | mode, | 17346 | mode, |
| 16484 | - 0, | 17347 | + angle_delta_y, |
| 16485 | reach, | 17348 | reach, |
| 16486 | &vec![0i32; side * side], | 17349 | &vec![0i32; side * side], |
| 16487 | None, | 17350 | None, |
| 16488 | filter_intra, | 17351 | filter_intra, |
| 16489 | - false, | 17352 | + smooth_neighbor, |
| 16490 | ); | 17353 | ); |
| 16491 | } | 17354 | } |
| 16492 | let ac = alpha.map(|_| cfl_ac_q3(y, px, py, side)); | 17355 | let ac = alpha.map(|_| cfl_ac_q3(y, px, py, side)); |
| @@ -16518,7 +17381,7 @@ fn decode_inter_block( | |||
| 16518 | u_grid = vec![0i32; chroma_side * chroma_side]; | 17381 | u_grid = vec![0i32; chroma_side * chroma_side]; |
| 16519 | v_grid = vec![0i32; chroma_side * chroma_side]; | 17382 | v_grid = vec![0i32; chroma_side * chroma_side]; |
| 16520 | } else { | 17383 | } else { |
| 16521 | - let around = neighbours.around(at, side); | 17384 | + let around = neighbours.around_mi(at, side); |
| 16522 | luma_grid = if split_luma { | 17385 | luma_grid = if split_luma { |
| 16523 | // Already coded and reconstructed unit by unit above; the | 17386 | // Already coded and reconstructed unit by unit above; the |
| 16524 | // block-level grid is only the neighbour write-back's input, | 17387 | // block-level grid is only the neighbour write-back's input, |
| @@ -16534,7 +17397,7 @@ fn decode_inter_block( | |||
| 16534 | around[0], | 17397 | around[0], |
| 16535 | mode, | 17398 | mode, |
| 16536 | mode, | 17399 | mode, |
| 16537 | - 0, | 17400 | + angle_delta_y, |
| 16538 | reach, | 17401 | reach, |
| 16539 | y, | 17402 | y, |
| 16540 | px, | 17403 | px, |
| @@ -16545,7 +17408,7 @@ fn decode_inter_block( | |||
| 16545 | None, | 17408 | None, |
| 16546 | filter_intra, | 17409 | filter_intra, |
| 16547 | None, | 17410 | None, |
| 16548 | - false, | 17411 | + smooth_neighbor, |
| 16549 | )? | 17412 | )? |
| 16550 | }; | 17413 | }; |
| 16551 | let ac = alpha.map(|_| cfl_ac_q3(y, px, py, side)); | 17414 | let ac = alpha.map(|_| cfl_ac_q3(y, px, py, side)); |
| @@ -16604,7 +17467,7 @@ fn decode_inter_block( | |||
| 16604 | if std::env::var_os("EC_AV1_TELL").is_some() { | 17467 | if std::env::var_os("EC_AV1_TELL").is_some() { |
| 16605 | eprintln!( | 17468 | eprintln!( |
| 16606 | "TELL mi_row={} mi_col={} label=block_end tell={} range={}", | 17469 | "TELL mi_row={} mi_col={} label=block_end tell={} range={}", |
| 16607 | - r * SUB_MI as usize, c * SUB_MI as usize, dec.debug_bitpos(), dec.debug_state().0 | 17470 | + rmi, cmi, dec.debug_bitpos(), dec.debug_state().0 |
| 16608 | ); | 17471 | ); |
| 16609 | } | 17472 | } |
| 16610 | if vartx_leaves.is_some() { | 17473 | if vartx_leaves.is_some() { |
| @@ -16612,9 +17475,9 @@ fn decode_inter_block( | |||
| 16612 | // ([`Neighbours::record_mi_luma`] above); this writes everything else | 17475 | // ([`Neighbours::record_mi_luma`] above); this writes everything else |
| 16613 | // [`Neighbours::record_rect`] would (a var-tx block is always square, | 17476 | // [`Neighbours::record_rect`] would (a var-tx block is always square, |
| 16614 | // so `write_w == write_h == side`). | 17477 | // so `write_w == write_h == side`). |
| 16615 | - neighbours.record_split_luma(at, side, mode_for_tx, uv_predict_mode, [&u_grid, &v_grid]); | 17478 | + neighbours.record_split_luma_rect_mi(at, side, side, mode_for_tx, uv_predict_mode, [&u_grid, &v_grid]); |
| 16616 | } else { | 17479 | } else { |
| 16617 | - neighbours.record_rect( | 17480 | + neighbours.record_rect_mi( |
| 16618 | at, | 17481 | at, |
| 16619 | write_w, | 17482 | write_w, |
| 16620 | write_h, | 17483 | write_h, |
| @@ -16623,10 +17486,10 @@ fn decode_inter_block( | |||
| 16623 | &[luma_grid, u_grid, v_grid], | 17486 | &[luma_grid, u_grid, v_grid], |
| 16624 | ); | 17487 | ); |
| 16625 | } | 17488 | } |
| 16626 | - neighbours.record_inter_rect( | 17489 | + neighbours.record_inter_rect_mi( |
| 16627 | at, | 17490 | at, |
| 16628 | - write_w, | 17491 | + write_w / MI, |
| 16629 | - write_h, | 17492 | + write_h / MI, |
| 16630 | skip, | 17493 | skip, |
| 16631 | is_inter, | 17494 | is_inter, |
| 16632 | ref_frame_for_lf, | 17495 | ref_frame_for_lf, |
| @@ -16634,16 +17497,16 @@ fn decode_inter_block( | |||
| 16634 | skip_mode, | 17497 | skip_mode, |
| 16635 | ); | 17498 | ); |
| 16636 | if let Some((ref1, group_idx, idx)) = compound_ctx { | 17499 | if let Some((ref1, group_idx, idx)) = compound_ctx { |
| 16637 | - neighbours.record_compound_ctx_rect(at, write_w, write_h, ref1, group_idx, idx); | 17500 | + neighbours.record_compound_ctx_rect_mi(at, write_w / MI, write_h / MI, ref1, group_idx, idx); |
| 16638 | } | 17501 | } |
| 16639 | neighbours.fill_skip_grid_rect( | 17502 | neighbours.fill_skip_grid_rect( |
| 16640 | - (r * (SUB / MI), c * (SUB / MI)), | 17503 | + (rmi, cmi), |
| 16641 | write_w / MI, | 17504 | write_w / MI, |
| 16642 | write_h / MI, | 17505 | write_h / MI, |
| 16643 | skip, | 17506 | skip, |
| 16644 | ); | 17507 | ); |
| 16645 | neighbours.fill_lf_grid_rect( | 17508 | neighbours.fill_lf_grid_rect( |
| 16646 | - (r * (SUB / MI), c * (SUB / MI)), | 17509 | + (rmi, cmi), |
| 16647 | write_w / MI, | 17510 | write_w / MI, |
| 16648 | write_h / MI, | 17511 | write_h / MI, |
| 16649 | // lane-rect r2: the strip's true TX_32X16/TX_16X32 dims -- the | 17512 | // lane-rect r2: the strip's true TX_32X16/TX_16X32 dims -- the |
| @@ -17934,13 +18797,33 @@ fn decode_inter_block8( | |||
| 17934 | "an intra mode this decoder does not code (round 2)", | 18797 | "an intra mode this decoder does not code (round 2)", |
| 17935 | )); | 18798 | )); |
| 17936 | } | 18799 | } |
| 17937 | - if (V_PRED..=D67_PRED).contains(&mode) { | 18800 | + // lane-angleinter r1: `read_intra_angle_info` (libaom `decodemv.c`, |
| 17938 | - let angle = dec.symbol(&mut cdfs.angle_delta[mode - V_PRED]); | 18801 | + // inside `read_intra_block_mode_info`) -- an intra block in an inter |
| 17939 | - if angle != ANGLE_DELTA_ZERO { | 18802 | + // frame reads `angle_delta_y` off the same |
| 17940 | - return Err(unsupported( | 18803 | + // `angle_delta_cdf[mode - V_PRED]` row a key-frame block does, and |
| 17941 | - "a nonzero angle delta (this encoder never writes one)", | 18804 | + // the delta feeds the directional predictor (and the edge |
| 17942 | - )); | 18805 | + // filter/upsample decision derived from the delta'd angle) unchanged. |
| 17943 | - } | 18806 | + // The symbol was read and then refused before this round even though |
| 18807 | + // aomenc enables `--enable-angle-delta` by default. | ||
| 18808 | + let angle_delta_y = if (V_PRED..=D67_PRED).contains(&mode) { | ||
| 18809 | + read_angle_delta(dec, &mut cdfs.angle_delta[mode - V_PRED]) | ||
| 18810 | + } else { | ||
| 18811 | + 0 | ||
| 18812 | + }; | ||
| 18813 | + if angle_delta_y != 0 { | ||
| 18814 | + INTRA_IN_INTER_ANGLE_DELTA_Y_HITS.with(|c| c.set(c.get() + 1)); | ||
| 18815 | + // lane-angleinter r1: the >=16x16 arm's lift is gated by a real | ||
| 18816 | + // aomenc stream; this leaf's is NOT -- 80 attempts across two | ||
| 18817 | + // sizes and five quantisers never produced an 8x8 intra leaf with | ||
| 18818 | + // a nonzero delta (the leaf's own sibling refusals -- non-DC | ||
| 18819 | + // chroma, the TX_4X4 split, sub-16 rect inter leaves -- fire | ||
| 18820 | + // first). The prediction below would handle it; refusing keeps | ||
| 18821 | + // the rule that no lift ships ungated. Note the claim is about | ||
| 18822 | + // THIS DECODER's gate coverage, not about what an encoder writes. | ||
| 18823 | + return Err(unsupported( | ||
| 18824 | + "a nonzero angle delta on an 8x8 intra leaf in an inter frame (no gate reaches \ | ||
| 18825 | + this leaf with one; the >=16x16 arm decodes deltas)", | ||
| 18826 | + )); | ||
| 17944 | } | 18827 | } |
| 17945 | let uv_mode = dec.symbol(&mut cdfs.uv_mode_cfl[mode]); | 18828 | let uv_mode = dec.symbol(&mut cdfs.uv_mode_cfl[mode]); |
| 17946 | if uv_mode != DC_PRED { | 18829 | if uv_mode != DC_PRED { |
| @@ -18035,7 +18918,7 @@ fn decode_inter_block8( | |||
| 18035 | py, | 18918 | py, |
| 18036 | SIDE, | 18919 | SIDE, |
| 18037 | mode, | 18920 | mode, |
| 18038 | - 0, | 18921 | + angle_delta_y, |
| 18039 | reach, | 18922 | reach, |
| 18040 | &vec![0i32; SIDE * SIDE], | 18923 | &vec![0i32; SIDE * SIDE], |
| 18041 | None, | 18924 | None, |
| @@ -18080,7 +18963,7 @@ fn decode_inter_block8( | |||
| 18080 | around[0], | 18963 | around[0], |
| 18081 | mode, | 18964 | mode, |
| 18082 | mode, | 18965 | mode, |
| 18083 | - 0, | 18966 | + angle_delta_y, |
| 18084 | reach, | 18967 | reach, |
| 18085 | y, | 18968 | y, |
| 18086 | px, | 18969 | px, |
| @@ -18637,6 +19520,64 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( | |||
| 18637 | } | 19520 | } |
| 18638 | CDEF_TRANSMITTED.with(|c| c.set(false)); | 19521 | CDEF_TRANSMITTED.with(|c| c.set(false)); |
| 18639 | let sb_at = (sb_r as usize * 4, sb_c as usize * 4); | 19522 | let sb_at = (sb_r as usize * 4, sb_c as usize * 4); |
| 19523 | + // lane-inter4 r1: every rect inter piece below is the same | ||
| 19524 | + // `decode_inter_block` call with only position / true footprint / | ||
| 19525 | + // transform-set differing; the macro keeps the new arms readable | ||
| 19526 | + // instead of six more 60-line copies of the argument list. | ||
| 19527 | + macro_rules! inter_piece { | ||
| 19528 | + ($at_mi:expr, $side:expr, $li:expr, $lt:expr, $ch:expr, $ltx:expr, | ||
| 19529 | + $ctx:expr, $sl:expr, $sc:expr, $sg:expr, $ww:expr, $wh:expr) => { | ||
| 19530 | + decode_inter_block( | ||
| 19531 | + &mut dec, | ||
| 19532 | + &mut cdfs, | ||
| 19533 | + &mut neighbours, | ||
| 19534 | + &mut grid, | ||
| 19535 | + $at_mi, | ||
| 19536 | + $side, | ||
| 19537 | + mi_cols, | ||
| 19538 | + mi_rows, | ||
| 19539 | + &mut y, | ||
| 19540 | + &mut u, | ||
| 19541 | + &mut v, | ||
| 19542 | + &ref_y, | ||
| 19543 | + &ref_u, | ||
| 19544 | + &ref_v, | ||
| 19545 | + &ref_slots, | ||
| 19546 | + &sign_bias_table, | ||
| 19547 | + &global_motion, | ||
| 19548 | + base_q_idx, | ||
| 19549 | + $li, | ||
| 19550 | + $lt, | ||
| 19551 | + $ch, | ||
| 19552 | + $ltx, | ||
| 19553 | + $ctx, | ||
| 19554 | + $sl, | ||
| 19555 | + $sc, | ||
| 19556 | + $sg, | ||
| 19557 | + allow_high_precision_mv, | ||
| 19558 | + force_integer_mv, | ||
| 19559 | + interp_fixed, | ||
| 19560 | + enable_dual_filter, | ||
| 19561 | + tpl_frame.as_ref(), | ||
| 19562 | + reference_select, | ||
| 19563 | + enable_masked_compound, | ||
| 19564 | + enable_interintra_compound, | ||
| 19565 | + enable_jnt_comp, | ||
| 19566 | + order_hint_bits, | ||
| 19567 | + order_hint, | ||
| 19568 | + ref_order_hints, | ||
| 19569 | + skip_mode_present, | ||
| 19570 | + skip_mode_frame, | ||
| 19571 | + switchable_motion_mode, | ||
| 19572 | + allow_warped_motion, | ||
| 19573 | + true, | ||
| 19574 | + $ww, | ||
| 19575 | + $wh, | ||
| 19576 | + allow_screen_content_tools, | ||
| 19577 | + frame_width as usize, | ||
| 19578 | + )? | ||
| 19579 | + }; | ||
| 19580 | + } | ||
| 18640 | let sb_ctx = neighbours.partition_ctx(sb_at, SB); | 19581 | let sb_ctx = neighbours.partition_ctx(sb_at, SB); |
| 18641 | let (has_cols, has_rows) = ( | 19582 | let (has_cols, has_rows) = ( |
| 18642 | sb_c * SB_MI + SB_MI / 2 < mi_cols, | 19583 | sb_c * SB_MI + SB_MI / 2 < mi_cols, |
| @@ -18662,12 +19603,24 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( | |||
| 18662 | p | 19603 | p |
| 18663 | } | 19604 | } |
| 18664 | (true, false) => { | 19605 | (true, false) => { |
| 18665 | - dec.symbol_fixed(&gather(&cdfs.partition_w64[sb_ctx], VERT_ALIKE)); | 19606 | + // lane-golomb r1 (class `parsed-then-discarded`): the gathered |
| 18666 | - PARTITION_SPLIT | 19607 | + // bit IS the partition -- 0 means PARTITION_HORZ, only 1 means SPLIT |
| 19608 | + // (libaom `ec_read_partition_impl`). | ||
| 19609 | + if dec.symbol_fixed(&gather(&cdfs.partition_w64[sb_ctx], VERT_ALIKE)) == 1 { | ||
| 19610 | + PARTITION_SPLIT | ||
| 19611 | + } else { | ||
| 19612 | + PARTITION_HORZ | ||
| 19613 | + } | ||
| 18667 | } | 19614 | } |
| 18668 | (false, true) => { | 19615 | (false, true) => { |
| 18669 | - dec.symbol_fixed(&gather(&cdfs.partition_w64[sb_ctx], HORZ_ALIKE)); | 19616 | + // lane-golomb r1 (class `parsed-then-discarded`): the gathered |
| 18670 | - PARTITION_SPLIT | 19617 | + // bit IS the partition -- 0 means PARTITION_VERT, only 1 means SPLIT |
| 19618 | + // (libaom `ec_read_partition_impl`). | ||
| 19619 | + if dec.symbol_fixed(&gather(&cdfs.partition_w64[sb_ctx], HORZ_ALIKE)) == 1 { | ||
| 19620 | + PARTITION_SPLIT | ||
| 19621 | + } else { | ||
| 19622 | + PARTITION_VERT | ||
| 19623 | + } | ||
| 18671 | } | 19624 | } |
| 18672 | (false, false) => PARTITION_SPLIT, | 19625 | (false, false) => PARTITION_SPLIT, |
| 18673 | }; | 19626 | }; |
| @@ -18687,7 +19640,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( | |||
| 18687 | &mut cdfs, | 19640 | &mut cdfs, |
| 18688 | &mut neighbours, | 19641 | &mut neighbours, |
| 18689 | &mut grid, | 19642 | &mut grid, |
| 18690 | - sb_at, | 19643 | + sub16_to_mi(sb_at), |
| 18691 | SB, | 19644 | SB, |
| 18692 | mi_cols, | 19645 | mi_cols, |
| 18693 | mi_rows, | 19646 | mi_rows, |
| @@ -18733,10 +19686,73 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( | |||
| 18733 | )?; | 19686 | )?; |
| 18734 | continue; | 19687 | continue; |
| 18735 | } | 19688 | } |
| 19689 | + if matches!( | ||
| 19690 | + part64, | ||
| 19691 | + PARTITION_HORZ | PARTITION_VERT | PARTITION_HORZ_4 | PARTITION_VERT_4 | ||
| 19692 | + ) { | ||
| 19693 | + // lane-inter4 r1: the superblock-level rect + 1:4 pairs as | ||
| 19694 | + // inter blocks -- two 64x32 / 32x64 strips, or four 64x16 / | ||
| 19695 | + // 16x64 ones. Each piece keeps `side = SB` for every | ||
| 19696 | + // syntax/CDF/prediction-buffer decision (the square-context | ||
| 19697 | + // corner-cut PARTITION_HORZ already ships at the 32 level) | ||
| 19698 | + // but names its own true footprint through `write_w`/ | ||
| 19699 | + // `write_h`, which is what `motion_mode`'s bsize row, the | ||
| 19700 | + // mv-stack's bw4/bh4, the delta-q `bSize == sbSize` test and | ||
| 19701 | + // every neighbour stamp read. `reject_residual = true`: a | ||
| 19702 | + // non-skip strip refuses by name rather than over-read a | ||
| 19703 | + // square residual (rectangular inter residual coding is not | ||
| 19704 | + // ported -- see lanes/inter4-r1.report.md). | ||
| 19705 | + let horz = matches!(part64, PARTITION_HORZ | PARTITION_HORZ_4); | ||
| 19706 | + let four = matches!(part64, PARTITION_HORZ_4 | PARTITION_VERT_4); | ||
| 19707 | + let base_mi = ( | ||
| 19708 | + sb_r as usize * SB_MI as usize, | ||
| 19709 | + sb_c as usize * SB_MI as usize, | ||
| 19710 | + ); | ||
| 19711 | + let (n_pieces, step_mi) = if four { (4usize, 4usize) } else { (2usize, 8usize) }; | ||
| 19712 | + let (bw, bh) = match (horz, four) { | ||
| 19713 | + (true, false) => (64usize, 32usize), | ||
| 19714 | + (false, false) => (32, 64), | ||
| 19715 | + (true, true) => (64, 16), | ||
| 19716 | + (false, true) => (16, 64), | ||
| 19717 | + }; | ||
| 19718 | + for i in 0..n_pieces { | ||
| 19719 | + let at_mi = if horz { | ||
| 19720 | + (base_mi.0 + i * step_mi, base_mi.1) | ||
| 19721 | + } else { | ||
| 19722 | + (base_mi.0, base_mi.1 + i * step_mi) | ||
| 19723 | + }; | ||
| 19724 | + // libaom `decode_partition`'s own `i > 0` frame-edge break. | ||
| 19725 | + if i > 0 && (at_mi.0 >= mi_rows as usize || at_mi.1 >= mi_cols as usize) { | ||
| 19726 | + break; | ||
| 19727 | + } | ||
| 19728 | + inter_piece!( | ||
| 19729 | + at_mi, | ||
| 19730 | + SB, | ||
| 19731 | + TxbSet::Luma64, | ||
| 19732 | + TxbSet::Luma64, | ||
| 19733 | + TxbSet::Chroma32, | ||
| 19734 | + TX32, | ||
| 19735 | + TX32, | ||
| 19736 | + &scan32, | ||
| 19737 | + &scan32, | ||
| 19738 | + 3, | ||
| 19739 | + bw, | ||
| 19740 | + bh | ||
| 19741 | + ); | ||
| 19742 | + match (horz, four) { | ||
| 19743 | + (true, false) => INTER_SB_HORZ_HITS.with(|c| c.set(c.get() + 1)), | ||
| 19744 | + (false, false) => INTER_SB_VERT_HITS.with(|c| c.set(c.get() + 1)), | ||
| 19745 | + (true, true) => INTER_SB_HORZ4_HITS.with(|c| c.set(c.get() + 1)), | ||
| 19746 | + (false, true) => INTER_SB_VERT4_HITS.with(|c| c.set(c.get() + 1)), | ||
| 19747 | + } | ||
| 19748 | + } | ||
| 19749 | + continue; | ||
| 19750 | + } | ||
| 18736 | if part64 != PARTITION_SPLIT { | 19751 | if part64 != PARTITION_SPLIT { |
| 18737 | return Err(unsupported( | 19752 | return Err(unsupported( |
| 18738 | - "an inter SB-level partition type other than NONE or SPLIT (this decoder's \ | 19753 | + "an inter SB-level AB partition (HORZ_A/HORZ_B/VERT_A/VERT_B; this \ |
| 18739 | - inter tile path recurses a superblock only as SPLIT)", | 19754 | + decoder's inter tile path codes a superblock as NONE, SPLIT, HORZ, \ |
| 19755 | + VERT, HORZ_4 or VERT_4)", | ||
| 18740 | )); | 19756 | )); |
| 18741 | } | 19757 | } |
| 18742 | 19758 | ||
| @@ -18772,14 +19788,27 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( | |||
| 18772 | } else { | 19788 | } else { |
| 18773 | match (has_cols32, has_rows32) { | 19789 | match (has_cols32, has_rows32) { |
| 18774 | (true, false) => { | 19790 | (true, false) => { |
| 18775 | - dec.symbol_fixed(&gather(&cdfs.partition_w32[ctx32], VERT_ALIKE)); | 19791 | + // lane-golomb r1 (class `parsed-then-discarded`): the gathered |
| 19792 | + // bit IS the partition -- 0 means PARTITION_HORZ, only 1 means SPLIT | ||
| 19793 | + // (libaom `ec_read_partition_impl`). | ||
| 19794 | + if dec.symbol_fixed(&gather(&cdfs.partition_w32[ctx32], VERT_ALIKE)) == 1 { | ||
| 19795 | + PARTITION_SPLIT | ||
| 19796 | + } else { | ||
| 19797 | + PARTITION_HORZ | ||
| 19798 | + } | ||
| 18776 | } | 19799 | } |
| 18777 | (false, true) => { | 19800 | (false, true) => { |
| 18778 | - dec.symbol_fixed(&gather(&cdfs.partition_w32[ctx32], HORZ_ALIKE)); | 19801 | + // lane-golomb r1 (class `parsed-then-discarded`): the gathered |
| 19802 | + // bit IS the partition -- 0 means PARTITION_VERT, only 1 means SPLIT | ||
| 19803 | + // (libaom `ec_read_partition_impl`). | ||
| 19804 | + if dec.symbol_fixed(&gather(&cdfs.partition_w32[ctx32], HORZ_ALIKE)) == 1 { | ||
| 19805 | + PARTITION_SPLIT | ||
| 19806 | + } else { | ||
| 19807 | + PARTITION_VERT | ||
| 19808 | + } | ||
| 18779 | } | 19809 | } |
| 18780 | - _ => {} | 19810 | + _ => PARTITION_SPLIT, |
| 18781 | } | 19811 | } |
| 18782 | - PARTITION_SPLIT | ||
| 18783 | }; | 19812 | }; |
| 18784 | match part32 { | 19813 | match part32 { |
| 18785 | PARTITION_NONE => { | 19814 | PARTITION_NONE => { |
| @@ -18788,7 +19817,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( | |||
| 18788 | &mut cdfs, | 19817 | &mut cdfs, |
| 18789 | &mut neighbours, | 19818 | &mut neighbours, |
| 18790 | &mut grid, | 19819 | &mut grid, |
| 18791 | - at, | 19820 | + sub16_to_mi(at), |
| 18792 | BLOCK, | 19821 | BLOCK, |
| 18793 | mi_cols, | 19822 | mi_cols, |
| 18794 | mi_rows, | 19823 | mi_rows, |
| @@ -18871,17 +19900,24 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( | |||
| 18871 | p | 19900 | p |
| 18872 | } else { | 19901 | } else { |
| 18873 | if has_cols16 { | 19902 | if has_cols16 { |
| 18874 | - dec.symbol_fixed(&gather( | 19903 | + // lane-golomb r1 (class `parsed-then-discarded`): the gathered |
| 18875 | - &cdfs.partition_w16[ctx16], | 19904 | + // bit IS the partition -- 0 means PARTITION_HORZ, only 1 means SPLIT |
| 18876 | - VERT_ALIKE, | 19905 | + // (libaom `ec_read_partition_impl`). |
| 18877 | - )); | 19906 | + if dec.symbol_fixed(&gather(&cdfs.partition_w16[ctx16], VERT_ALIKE)) == 1 { |
| 19907 | + PARTITION_SPLIT | ||
| 19908 | + } else { | ||
| 19909 | + PARTITION_HORZ | ||
| 19910 | + } | ||
| 18878 | } else { | 19911 | } else { |
| 18879 | - dec.symbol_fixed(&gather( | 19912 | + // lane-golomb r1 (class `parsed-then-discarded`): the gathered |
| 18880 | - &cdfs.partition_w16[ctx16], | 19913 | + // bit IS the partition -- 0 means PARTITION_VERT, only 1 means SPLIT |
| 18881 | - HORZ_ALIKE, | 19914 | + // (libaom `ec_read_partition_impl`). |
| 18882 | - )); | 19915 | + if dec.symbol_fixed(&gather(&cdfs.partition_w16[ctx16], HORZ_ALIKE)) == 1 { |
| 19916 | + PARTITION_SPLIT | ||
| 19917 | + } else { | ||
| 19918 | + PARTITION_VERT | ||
| 19919 | + } | ||
| 18883 | } | 19920 | } |
| 18884 | - PARTITION_SPLIT | ||
| 18885 | }; | 19921 | }; |
| 18886 | if part16 == PARTITION_NONE { | 19922 | if part16 == PARTITION_NONE { |
| 18887 | decode_inter_block( | 19923 | decode_inter_block( |
| @@ -18889,7 +19925,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( | |||
| 18889 | &mut cdfs, | 19925 | &mut cdfs, |
| 18890 | &mut neighbours, | 19926 | &mut neighbours, |
| 18891 | &mut grid, | 19927 | &mut grid, |
| 18892 | - at16, | 19928 | + sub16_to_mi(at16), |
| 18893 | SUB, | 19929 | SUB, |
| 18894 | mi_cols, | 19930 | mi_cols, |
| 18895 | mi_rows, | 19931 | mi_rows, |
| @@ -18937,9 +19973,96 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( | |||
| 18937 | allow_screen_content_tools, | 19973 | allow_screen_content_tools, |
| 18938 | frame_width as usize, | 19974 | frame_width as usize, |
| 18939 | )?; | 19975 | )?; |
| 19976 | + } else if part16 == PARTITION_HORZ || part16 == PARTITION_VERT { | ||
| 19977 | + // lane-inter4 r3: the 16x16-level rect inter | ||
| 19978 | + // leaves -- two true 16x8 (HORZ) or 8x16 | ||
| 19979 | + // (VERT) inter blocks. Same shape as the | ||
| 19980 | + // 32-level HORZ/VERT arm above: `side = SUB` | ||
| 19981 | + // keeps every CDF/prediction-buffer decision | ||
| 19982 | + // square, `write_w`/`write_h` carry the true | ||
| 19983 | + // footprint into the mv stack, the motion-mode | ||
| 19984 | + // row, the neighbour stamps and the rectangular | ||
| 19985 | + // residual path (`rect_inter_residual_supported` | ||
| 19986 | + // covers 16x8/8x16 since this round). | ||
| 19987 | + let horz = part16 == PARTITION_HORZ; | ||
| 19988 | + if horz { | ||
| 19989 | + INTER_LEAF16_HORZ_HITS.with(|c| c.set(c.get() + 1)); | ||
| 19990 | + } else { | ||
| 19991 | + INTER_LEAF16_VERT_HITS.with(|c| c.set(c.get() + 1)); | ||
| 19992 | + } | ||
| 19993 | + let base_mi = sub16_to_mi(at16); | ||
| 19994 | + let (ww, wh) = if horz { (16, 8) } else { (8, 16) }; | ||
| 19995 | + for piece in 0..2 { | ||
| 19996 | + let piece_mi = if horz { | ||
| 19997 | + (base_mi.0 + piece * 2, base_mi.1) | ||
| 19998 | + } else { | ||
| 19999 | + (base_mi.0, base_mi.1 + piece * 2) | ||
| 20000 | + }; | ||
| 20001 | + // libaom `decode_partition`'s own second- | ||
| 20002 | + // half frame-edge break. | ||
| 20003 | + if piece > 0 | ||
| 20004 | + && (piece_mi.0 >= mi_rows as usize | ||
| 20005 | + || piece_mi.1 >= mi_cols as usize) | ||
| 20006 | + { | ||
| 20007 | + break; | ||
| 20008 | + } | ||
| 20009 | + decode_inter_block( | ||
| 20010 | + &mut dec, | ||
| 20011 | + &mut cdfs, | ||
| 20012 | + &mut neighbours, | ||
| 20013 | + &mut grid, | ||
| 20014 | + piece_mi, | ||
| 20015 | + SUB, | ||
| 20016 | + mi_cols, | ||
| 20017 | + mi_rows, | ||
| 20018 | + &mut y, | ||
| 20019 | + &mut u, | ||
| 20020 | + &mut v, | ||
| 20021 | + &ref_y, | ||
| 20022 | + &ref_u, | ||
crates/ec-av1/src/gate_coverage.rsmodified+0 -16
| @@ -148,10 +148,6 @@ const ALIASES: &[(&str, &str)] = &[("superres-mode", "enable-superres")]; | |||
| 148 | /// depth retires the entry, and this test fails until it is deleted. | 148 | /// depth retires the entry, and this test fails until it is deleted. |
| 149 | #[cfg(test)] | 149 | #[cfg(test)] |
| 150 | const NEVER_EXERCISED_8BIT: &[(&str, &str)] = &[ | 150 | const NEVER_EXERCISED_8BIT: &[(&str, &str)] = &[ |
| 151 | - ( | ||
| 152 | - "enable-angle-delta", | ||
| 153 | - "off in 36 gates, on in none: the directional-intra gates pin it off to isolate the base modes", | ||
| 154 | - ), | ||
| 155 | ( | 151 | ( |
| 156 | "enable-cfl-intra", | 152 | "enable-cfl-intra", |
| 157 | "off in 41 gates, on in none: chroma-from-luma prediction is unimplemented", | 153 | "off in 41 gates, on in none: chroma-from-luma prediction is unimplemented", |
| @@ -180,10 +176,6 @@ const NEVER_EXERCISED_8BIT: &[(&str, &str)] = &[ | |||
| 180 | "enable-rect-tx", | 176 | "enable-rect-tx", |
| 181 | "never spelled; rect transforms reach the decoder only through partition shape, never through a gate that names the tool", | 177 | "never spelled; rect transforms reach the decoder only through partition shape, never through a gate that names the tool", |
| 182 | ), | 178 | ), |
| 183 | - ( | ||
| 184 | - "enable-ref-frame-mvs", | ||
| 185 | - "off in 27 gates, on in none: temporal MV projection is unimplemented", | ||
| 186 | - ), | ||
| 187 | ( | 179 | ( |
| 188 | "enable-tx64", | 180 | "enable-tx64", |
| 189 | "never spelled; TX_64X64 appears only where aomenc's default picks it, which is unknown per stream", | 181 | "never spelled; TX_64X64 appears only where aomenc's default picks it, which is unknown per stream", |
| @@ -214,10 +206,6 @@ const NEVER_EXERCISED_10BIT: &[(&str, &str)] = &[ // lane-cwarp's 10-bit comp | |||
| 214 | // gate passes `=1` for both. `enable-1to4-partitions` left it on 2026-09-02: | 206 | // gate passes `=1` for both. `enable-1to4-partitions` left it on 2026-09-02: |
| 215 | // lane-tx64x16 r4's 32-level 1:4 gate has a 10-bit arm that asserts both | 207 | // lane-tx64x16 r4's 32-level 1:4 gate has a 10-bit arm that asserts both |
| 216 | // orientations and coded strips inside pixel-exact attempts. | 208 | // orientations and coded strips inside pixel-exact attempts. |
| 217 | - ( | ||
| 218 | - "enable-angle-delta", | ||
| 219 | - "hole at both depths, see the 8-bit list", | ||
| 220 | - ), | ||
| 221 | ( | 209 | ( |
| 222 | "enable-cfl-intra", | 210 | "enable-cfl-intra", |
| 223 | "hole at both depths, see the 8-bit list", | 211 | "hole at both depths, see the 8-bit list", |
| @@ -234,10 +222,6 @@ const NEVER_EXERCISED_10BIT: &[(&str, &str)] = &[ // lane-cwarp's 10-bit comp | |||
| 234 | // 1D tx class). | 222 | // 1D tx class). |
| 235 | ("enable-intrabc", "hole at both depths, see the 8-bit list"), | 223 | ("enable-intrabc", "hole at both depths, see the 8-bit list"), |
| 236 | ("enable-rect-tx", "hole at both depths, see the 8-bit list"), | 224 | ("enable-rect-tx", "hole at both depths, see the 8-bit list"), |
| 237 | - ( | ||
| 238 | - "enable-ref-frame-mvs", | ||
| 239 | - "hole at both depths, see the 8-bit list", | ||
| 240 | - ), | ||
| 241 | ("enable-tx64", "hole at both depths, see the 8-bit list"), | 225 | ("enable-tx64", "hole at both depths, see the 8-bit list"), |
| 242 | ]; | 226 | ]; |
| 243 | 227 | ||
crates/ec-av1/src/motion_field.rsmodified+84 -7
| @@ -31,13 +31,23 @@ pub struct MotionField { | |||
| 31 | cells: Vec<Option<SavedMv>>, | 31 | cells: Vec<Option<SavedMv>>, |
| 32 | pub order_hint: u32, | 32 | pub order_hint: u32, |
| 33 | pub ref_order_hints: [u32; 7], | 33 | pub ref_order_hints: [u32; 7], |
| 34 | + /// libaom `motion_field_projection`'s own first test: a start frame whose | ||
| 35 | + /// `frame_type` is `KEY_FRAME`/`INTRA_ONLY_FRAME` is never projected at | ||
| 36 | + /// all (`return 0`), so it also never spends a `ref_stamp` slot. | ||
| 37 | + pub is_intra: bool, | ||
| 34 | } | 38 | } |
| 35 | 39 | ||
| 36 | impl MotionField { | 40 | impl MotionField { |
| 37 | /// A field sized for an `mi_cols` by `mi_rows` frame, all cells | 41 | /// A field sized for an `mi_cols` by `mi_rows` frame, all cells |
| 38 | /// initially unset (spec 7.9's own reset to `-1`/invalid before any | 42 | /// initially unset (spec 7.9's own reset to `-1`/invalid before any |
| 39 | /// block writes into it). | 43 | /// block writes into it). |
| 40 | - pub fn new(mi_cols: usize, mi_rows: usize, order_hint: u32, ref_order_hints: [u32; 7]) -> Self { | 44 | + pub fn new( |
| 45 | + mi_cols: usize, | ||
| 46 | + mi_rows: usize, | ||
| 47 | + order_hint: u32, | ||
| 48 | + ref_order_hints: [u32; 7], | ||
| 49 | + is_intra: bool, | ||
| 50 | + ) -> Self { | ||
| 41 | let cols = mi_cols.div_ceil(2); | 51 | let cols = mi_cols.div_ceil(2); |
| 42 | let rows = mi_rows.div_ceil(2); | 52 | let rows = mi_rows.div_ceil(2); |
| 43 | Self { | 53 | Self { |
| @@ -46,6 +56,7 @@ impl MotionField { | |||
| 46 | cells: vec![None; cols * rows], | 56 | cells: vec![None; cols * rows], |
| 47 | order_hint, | 57 | order_hint, |
| 48 | ref_order_hints, | 58 | ref_order_hints, |
| 59 | + is_intra, | ||
| 49 | } | 60 | } |
| 50 | } | 61 | } |
| 51 | 62 | ||
| @@ -53,10 +64,14 @@ impl MotionField { | |||
| 53 | /// mi_col)` — every `MiInfo` inside one 8x8 cell shares a single | 64 | /// mi_col)` — every `MiInfo` inside one 8x8 cell shares a single |
| 54 | /// motion-field entry, matching `av1_copy_frame_mvs`'s own half-resolution | 65 | /// motion-field entry, matching `av1_copy_frame_mvs`'s own half-resolution |
| 55 | /// write. | 66 | /// write. |
| 56 | - pub fn set(&mut self, mi_row: usize, mi_col: usize, saved: SavedMv) { | 67 | + /// `saved == None` is `av1_copy_frame_mvs`'s own leading clear |
| 68 | + /// (`mv->ref_frame = NONE_FRAME; mv->mv.as_int = 0;`), which every block | ||
| 69 | + /// of an inter frame performs -- an intra (or nothing-to-store) block | ||
| 70 | + /// sharing an 8x8 cell with an earlier inter one wipes that cell. | ||
| 71 | + pub fn set(&mut self, mi_row: usize, mi_col: usize, saved: Option<SavedMv>) { | ||
| 57 | let (r, c) = (mi_row / 2, mi_col / 2); | 72 | let (r, c) = (mi_row / 2, mi_col / 2); |
| 58 | if r < self.rows && c < self.cols { | 73 | if r < self.rows && c < self.cols { |
| 59 | - self.cells[r * self.cols + c] = Some(saved); | 74 | + self.cells[r * self.cols + c] = saved; |
| 60 | } | 75 | } |
| 61 | } | 76 | } |
| 62 | 77 | ||
| @@ -217,6 +232,14 @@ fn motion_field_projection( | |||
| 217 | dir: u8, | 232 | dir: u8, |
| 218 | tpl_cells: &mut [Option<((i32, i32), i32)>], | 233 | tpl_cells: &mut [Option<((i32, i32), i32)>], |
| 219 | ) -> bool { | 234 | ) -> bool { |
| 235 | + // libaom's own first two `return 0`s, in order: a key/intra-only start | ||
| 236 | + // frame is never projected (and so never spends a `ref_stamp` slot -- | ||
| 237 | + // returning `true` here made a forward key frame, `--enable-fwd-kf=1`, | ||
| 238 | + // consume the slot ALTREF/LAST2 should have had), then the frame-size | ||
| 239 | + // test. | ||
| 240 | + if start.is_intra { | ||
| 241 | + return false; | ||
| 242 | + } | ||
| 220 | let mvs_rows = mi_rows.div_ceil(2); | 243 | let mvs_rows = mi_rows.div_ceil(2); |
| 221 | let mvs_cols = mi_cols.div_ceil(2); | 244 | let mvs_cols = mi_cols.div_ceil(2); |
| 222 | if start.rows != mvs_rows || start.cols != mvs_cols { | 245 | if start.rows != mvs_rows || start.cols != mvs_cols { |
| @@ -264,6 +287,24 @@ fn motion_field_projection( | |||
| 264 | true | 287 | true |
| 265 | } | 288 | } |
| 266 | 289 | ||
| 290 | +thread_local! { | ||
| 291 | + /// Frames whose `av1_setup_motion_field` saw at least one forward | ||
| 292 | + /// references holding a key/intra-only frame -- the `ref_stamp` path | ||
| 293 | + /// [`motion_field_projection`]'s intra early return governs. | ||
| 294 | + static REFSTAMP_INTRA_FRAMES: std::cell::Cell<usize> = const { std::cell::Cell::new(0) }; | ||
| 295 | + /// The subset of those frames with TWO or more such references. | ||
| 296 | + static REFSTAMP_INTRA2_FRAMES: std::cell::Cell<usize> = const { std::cell::Cell::new(0) }; | ||
| 297 | +} | ||
| 298 | + | ||
| 299 | +/// Reads the counter above (gate | ||
| 300 | +/// `a_real_aomenc_inter_sequence_with_forward_keyframes_and_temporal_mvs_decodes_pixel_exact`). | ||
| 301 | +pub fn refstamp_intra_frames() -> (usize, usize) { | ||
| 302 | + ( | ||
| 303 | + REFSTAMP_INTRA_FRAMES.with(std::cell::Cell::get), | ||
| 304 | + REFSTAMP_INTRA2_FRAMES.with(std::cell::Cell::get), | ||
| 305 | + ) | ||
| 306 | +} | ||
| 307 | + | ||
| 267 | /// `av1_setup_motion_field` (spec 7.9.2's own driver): scans up to | 308 | /// `av1_setup_motion_field` (spec 7.9.2's own driver): scans up to |
| 268 | /// [`MFMV_STACK_SIZE`]`= 3` reference-frame slots in libaom's fixed order | 309 | /// [`MFMV_STACK_SIZE`]`= 3` reference-frame slots in libaom's fixed order |
| 269 | /// (`LAST_FRAME`, then `BWDREF_FRAME`/`ALTREF2_FRAME`/`ALTREF_FRAME` when | 310 | /// (`LAST_FRAME`, then `BWDREF_FRAME`/`ALTREF2_FRAME`/`ALTREF_FRAME` when |
| @@ -287,6 +328,11 @@ pub fn setup_motion_field( | |||
| 287 | let cols = mi_cols.div_ceil(2); | 328 | let cols = mi_cols.div_ceil(2); |
| 288 | let rows = mi_rows.div_ceil(2); | 329 | let rows = mi_rows.div_ceil(2); |
| 289 | let mut cells = vec![None; cols * rows]; | 330 | let mut cells = vec![None; cols * rows]; |
| 331 | + // `av1_setup_motion_field`'s own head: `if (!enable_order_hint) return;` | ||
| 332 | + // leaves every `tpl_mvs` cell INVALID. | ||
| 333 | + if order_hint_bits == 0 { | ||
| 334 | + return TplField { cols, rows, cells }; | ||
| 335 | + } | ||
| 290 | 336 | ||
| 291 | let slot_of = | 337 | let slot_of = |
| 292 | |ref_frame: i8| slots[ref_frame_idx[(ref_frame - LAST_FRAME) as usize] as usize].as_ref(); | 338 | |ref_frame: i8| slots[ref_frame_idx[(ref_frame - LAST_FRAME) as usize] as usize].as_ref(); |
| @@ -294,6 +340,27 @@ pub fn setup_motion_field( | |||
| 294 | 340 | ||
| 295 | let mut ref_stamp = 2i32; // MFMV_STACK_SIZE - 1 | 341 | let mut ref_stamp = 2i32; // MFMV_STACK_SIZE - 1 |
| 296 | 342 | ||
| 343 | + // Gate counter (lane-refstamp): frames whose forward references include at | ||
| 344 | + // least two key/intra-only frames, i.e. exactly the `ref_stamp` path the | ||
| 345 | + // early return above fixes. | ||
| 346 | + let intra_forward_refs = [ | ||
| 347 | + BWDREF_FRAME, | ||
| 348 | + crate::mvstack::ALTREF2_FRAME, | ||
| 349 | + ALTREF_FRAME, | ||
| 350 | + ] | ||
| 351 | + .into_iter() | ||
| 352 | + .filter(|&rf| { | ||
| 353 | + get_relative_dist(order_hint_bits, order_hint_of(rf), cur_order_hint) > 0 | ||
| 354 | + && slot_of(rf).is_some_and(|m| m.is_intra) | ||
| 355 | + }) | ||
| 356 | + .count(); | ||
| 357 | + if intra_forward_refs >= 1 { | ||
| 358 | + REFSTAMP_INTRA_FRAMES.with(|c| c.set(c.get() + 1)); | ||
| 359 | + } | ||
| 360 | + if intra_forward_refs >= 2 { | ||
| 361 | + REFSTAMP_INTRA2_FRAMES.with(|c| c.set(c.get() + 1)); | ||
| 362 | + } | ||
| 363 | + | ||
| 297 | if let Some(last) = slot_of(LAST_FRAME) { | 364 | if let Some(last) = slot_of(LAST_FRAME) { |
| 298 | let alt_of_lst = last.ref_order_hints[(ALTREF_FRAME - LAST_FRAME) as usize]; | 365 | let alt_of_lst = last.ref_order_hints[(ALTREF_FRAME - LAST_FRAME) as usize]; |
| 299 | let is_lst_overlay = alt_of_lst == order_hint_of(GOLDEN_FRAME); | 366 | let is_lst_overlay = alt_of_lst == order_hint_of(GOLDEN_FRAME); |
| @@ -420,7 +487,17 @@ pub fn add_tpl_ref_mv( | |||
| 420 | if row8 < 0 || col8 < 0 { | 487 | if row8 < 0 || col8 < 0 { |
| 421 | return None; | 488 | return None; |
| 422 | } | 489 | } |
| 423 | - let (fwd_mv, ref_frame_offset) = tpl.get(row8 as usize / 2, col8 as usize / 2)?; | 490 | + let probe = tpl.get(row8 as usize / 2, col8 as usize / 2); |
| 491 | + if std::env::var_os("EC_TRACE_TPL").is_some() { | ||
| 492 | + match probe { | ||
| 493 | + None => eprintln!("EC_TPL mi_row={mi_row} mi_col={mi_col} blk=({blk_row},{blk_col}) INVALID"), | ||
| 494 | + Some((m, rfo)) => eprintln!( | ||
| 495 | + "EC_TPL mi_row={mi_row} mi_col={mi_col} blk=({blk_row},{blk_col}) mfmv0=({},{}) rfo={rfo}", | ||
| 496 | + m.0, m.1 | ||
| 497 | + ), | ||
| 498 | + } | ||
| 499 | + } | ||
| 500 | + let (fwd_mv, ref_frame_offset) = probe?; | ||
| 424 | let projected = get_mv_projection(fwd_mv, cur_offset_0, ref_frame_offset); | 501 | let projected = get_mv_projection(fwd_mv, cur_offset_0, ref_frame_offset); |
| 425 | let mv = lower_mv_precision(projected, allow_high_precision_mv); | 502 | let mv = lower_mv_precision(projected, allow_high_precision_mv); |
| 426 | Some(TplCandidate { mv }) | 503 | Some(TplCandidate { mv }) |
| @@ -454,14 +531,14 @@ mod tests { | |||
| 454 | // A slot-0 inter frame (order_hint 2) that coded one 8x8 cell's MV | 531 | // A slot-0 inter frame (order_hint 2) that coded one 8x8 cell's MV |
| 455 | // against its own LAST_FRAME (order_hint 1). The current frame | 532 | // against its own LAST_FRAME (order_hint 1). The current frame |
| 456 | // (order_hint 4) names that same slot as *its* LAST_FRAME. | 533 | // (order_hint 4) names that same slot as *its* LAST_FRAME. |
| 457 | - let mut mf = MotionField::new(16, 16, 2, [1, 0, 0, 0, 0, 0, 0]); | 534 | + let mut mf = MotionField::new(16, 16, 2, [1, 0, 0, 0, 0, 0, 0], false); |
| 458 | mf.set( | 535 | mf.set( |
| 459 | 0, | 536 | 0, |
| 460 | 0, | 537 | 0, |
| 461 | - SavedMv { | 538 | + Some(SavedMv { |
| 462 | mv: (-64, 0), | 539 | mv: (-64, 0), |
| 463 | ref_frame: LAST_FRAME, | 540 | ref_frame: LAST_FRAME, |
| 464 | - }, | 541 | + }), |
| 465 | ); | 542 | ); |
| 466 | let slots: [Option<MotionField>; 8] = | 543 | let slots: [Option<MotionField>; 8] = |
| 467 | std::array::from_fn(|i| if i == 0 { Some(mf.clone()) } else { None }); | 544 | std::array::from_fn(|i| if i == 0 { Some(mf.clone()) } else { None }); |
crates/ec-av1/src/refusal_inventory.rsmodified+4 -3
| @@ -26,11 +26,11 @@ | |||
| 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-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)", |
| 29 | - "a nonzero angle delta (this encoder never writes one)", | ||
| 30 | ]; | 29 | ]; |
| 31 | 30 | ||
| 32 | #[cfg(test)] | 31 | #[cfg(test)] |
| 33 | const REFUSALS: &[&str] = &[ | 32 | const REFUSALS: &[&str] = &[ |
| 33 | + "a nonzero angle delta on an 8x8 intra leaf in an inter frame (no gate reaches this leaf with one; the >=16x16 arm decodes deltas)", | ||
| 34 | "a coded HORZ/VERT strip whose chroma transform has no rect coefficient tables here", | 34 | "a coded HORZ/VERT strip whose chroma transform has no rect coefficient tables here", |
| 35 | "a split intra strip whose transform unit is {tx_w}x{tx_h} (no luma coefficient tables for that shape here)", | 35 | "a split intra strip whose transform unit is {tx_w}x{tx_h} (no luma coefficient tables for that shape here)", |
| 36 | "an inter partition below 8x8 (this decoder codes no inter leaf smaller than 8x8; lane-sub8 scoped to intra)", | 36 | "an inter partition below 8x8 (this decoder codes no inter leaf smaller than 8x8; lane-sub8 scoped to intra)", |
| @@ -67,12 +67,13 @@ const REFUSALS: &[&str] = &[ | |||
| 67 | // the 8x8 leaf's TX_4X4 2x2 grid is still refused here. | 67 | // the 8x8 leaf's TX_4X4 2x2 grid is still refused here. |
| 68 | "an 8x8 intra leaf in an inter frame whose tx_depth splits it into 4x4 transform units", | 68 | "an 8x8 intra leaf in an inter frame whose tx_depth splits it into 4x4 transform units", |
| 69 | "an inter frame with no key frame before it", | 69 | "an inter frame with no key frame before it", |
| 70 | - "an inter SB-level partition type other than NONE or SPLIT (this decoder's inter tile path recurses a superblock only as SPLIT)", | 70 | + "an inter SB-level AB partition (HORZ_A/HORZ_B/VERT_A/VERT_B; this decoder's inter tile path codes a superblock as NONE, SPLIT, HORZ, VERT, HORZ_4 or VERT_4)", |
| 71 | - "an inter partition below 16x16 other than SPLIT (16x8/8x16 rect inter leaves are not coded yet)", | 71 | + "an inter 16x16-level AB or 1:4 partition (HORZ_A/HORZ_B/VERT_A/VERT_B/HORZ_4/VERT_4; this decoder's inter path codes a 16x16 as NONE, HORZ, VERT or SPLIT)", |
| 72 | "an intra mode this decoder does not code (round 2)", | 72 | "an intra mode this decoder does not code (round 2)", |
| 73 | "an intra-coded HORZ/VERT strip needs rectangular intra prediction this decoder does not code yet", | 73 | "an intra-coded HORZ/VERT strip needs rectangular intra prediction this decoder does not code yet", |
| 74 | "warp prediction with a scaled reference (superres, unimplemented)", | 74 | "warp prediction with a scaled reference (superres, unimplemented)", |
| 75 | "an 8x8 partition leaf under a scaled reference (superres, unimplemented)", | 75 | "an 8x8 partition leaf under a scaled reference (superres, unimplemented)", |
| 76 | + "a motion_mode symbol for a block shape with no CDF row here", | ||
| 76 | ]; | 77 | ]; |
| 77 | 78 | ||
| 78 | /// Gates whose `Err` arm turns a decode failure into a printed SKIP rather than | 79 | /// Gates whose `Err` arm turns a decode failure into a printed SKIP rather than |
crates/ec-av1/src/stream.rsmodified+1544 -59
| @@ -55,6 +55,19 @@ fn final_dump_prefix() -> Option<String> { | |||
| 55 | 55 | ||
| 56 | /// 32x32-level 1:4 strip counters, for `decode_probe`'s fixture search: | 56 | /// 32x32-level 1:4 strip counters, for `decode_probe`'s fixture search: |
| 57 | /// (HORZ_4 strips, VERT_4 strips, strips that read coefficients). | 57 | /// (HORZ_4 strips, VERT_4 strips, strips that read coefficients). |
| 58 | +/// lane-inter4 r1: the INTER-frame partition counters this lane's gates | ||
| 59 | +/// assert -- `(32x8, 8x32, 64x32, 32x64, 64x16, 16x64)` strips decoded. | ||
| 60 | +pub fn inter_rect_counters() -> (usize, usize, usize, usize, usize, usize) { | ||
| 61 | + ( | ||
| 62 | + crate::decode::rect4_32_horz_inter_hits(), | ||
| 63 | + crate::decode::rect4_32_vert_inter_hits(), | ||
| 64 | + crate::decode::inter_sb_horz_hits(), | ||
| 65 | + crate::decode::inter_sb_vert_hits(), | ||
| 66 | + crate::decode::inter_sb_horz4_hits(), | ||
| 67 | + crate::decode::inter_sb_vert4_hits(), | ||
| 68 | + ) | ||
| 69 | +} | ||
| 70 | + | ||
| 58 | pub fn rect4_32_counters() -> (usize, usize, usize) { | 71 | pub fn rect4_32_counters() -> (usize, usize, usize) { |
| 59 | ( | 72 | ( |
| 60 | crate::decode::rect4_32_horz_hits(), | 73 | crate::decode::rect4_32_horz_hits(), |
| @@ -63,6 +76,17 @@ pub fn rect4_32_counters() -> (usize, usize, usize) { | |||
| 63 | ) | 76 | ) |
| 64 | } | 77 | } |
| 65 | 78 | ||
| 79 | +/// lane-inter4 r4: rectangular inter transform units coded whole, rect | ||
| 80 | +/// var-tx trees that split, and OBMC blends run on a 16x8/8x16 leaf -- the | ||
| 81 | +/// three counters a recipe sweep needs to see from outside the crate. | ||
| 82 | +pub fn rect_inter_tu_counters() -> (usize, usize, usize) { | ||
| 83 | + ( | ||
| 84 | + crate::decode::rect_inter_tu_hits(), | ||
| 85 | + crate::decode::rect_inter_txsplit_hits(), | ||
| 86 | + crate::decode::obmc_rect_leaf_hits(), | ||
| 87 | + ) | ||
| 88 | +} | ||
| 89 | + | ||
| 66 | /// Decode every frame in a raw AV1 OBU stream, in coding order. | 90 | /// Decode every frame in a raw AV1 OBU stream, in coding order. |
| 67 | /// | 91 | /// |
| 68 | /// A key frame becomes the reference for the inter frames that follow it, | 92 | /// A key frame becomes the reference for the inter frames that follow it, |
| @@ -615,6 +639,9 @@ pub fn decode_stream(data: &[u8]) -> Result<Vec<Picture>> { | |||
| 615 | header.mi_rows as usize, | 639 | header.mi_rows as usize, |
| 616 | header.order_hint, | 640 | header.order_hint, |
| 617 | ref_order_hints, | 641 | ref_order_hints, |
| 642 | + // `frame_type` for the DPB slot: a key (or intra-only) frame is | ||
| 643 | + // never a projection source, and never spends a `ref_stamp`. | ||
| 644 | + true, | ||
| 618 | ); | 645 | ); |
| 619 | (picture, end_cdfs, motion_field) | 646 | (picture, end_cdfs, motion_field) |
| 620 | } else { | 647 | } else { |
| @@ -921,6 +948,208 @@ mod tests { | |||
| 921 | ); | 948 | ); |
| 922 | } | 949 | } |
| 923 | 950 | ||
| 951 | + /// lane-oddh r2 GATE: the frame-edge half-strip arms r1 added (a 64x32 / | ||
| 952 | + /// 32x64 superblock-level or 16x8 / 8x16 16-level INTER block where the | ||
| 953 | + /// frame's true edge cuts the strip in half) actually fire and decode | ||
| 954 | + /// pixel-exact, at both bit depths. 160 = two full superblock rows plus | ||
| 955 | + /// 32 pixels, so every superblock in the last row is a half strip; without | ||
| 956 | + /// r1's arms these attempts refused outright, which is why this gate | ||
| 957 | + /// asserts a nonzero `edge_rect_strip_hits` DELTA on attempts that were | ||
| 958 | + /// actually compared -- a refused attempt's hits would prove nothing | ||
| 959 | + /// (class "counter from refused stream"). | ||
| 960 | + #[test] | ||
| 961 | + #[ignore = "2026-09-02 lane-oddh r2: no aomenc recipe reaches the INTER edge half-strip arm yet -- rect partitions OFF makes the encoder answer the forced gathered edge symbol SPLIT every time (both bit depths decode 192x160 pixel-exact, edge_rect_strip_hits=0), and rect ON stops at three other lanes' gaps first: at cq 40 'a non-skip rectangular (HORZ/VERT/HORZ_B) strip needs rectangular residual coding', at cq 62 'an INTER 32x32 partition type this decoder does not code (value=8/9)' (HORZ_4/VERT_4 even with --enable-1to4-partitions=0), and at min-partition 16 'a HORZ/VERT intra strip below 16x16 with a split transform'. The KEY-frame half of the same edge is gated: the tiny size sweep now covers 64x72/72x64/64x136/136x64/192x136"] | ||
| 962 | + fn a_real_aomenc_inter_frame_edge_half_strip_decodes_pixel_exact() { | ||
| 963 | + const NAME: &str = "a_real_aomenc_inter_frame_edge_half_strip_decodes_pixel_exact"; | ||
| 964 | + let _gate_lock = lock_gate_counters(); | ||
| 965 | + if !have_ffmpeg() || !have_aomenc() { | ||
| 966 | + eprintln!("SKIP {NAME}: no ffmpeg/aomenc"); | ||
| 967 | + return; | ||
| 968 | + } | ||
| 969 | + let (width, height, frames) = (192usize, 160usize, 6usize); | ||
| 970 | + let mut compared = 0u32; | ||
| 971 | + let mut strip_hits = 0usize; | ||
| 972 | + let mut refused = 0u32; | ||
| 973 | + for bit_depth in [8u32, 10u32] { | ||
| 974 | + let duration = frames as f64 / 25.0; | ||
| 975 | + let source = format!("testsrc2=size={width}x{height}:duration={duration}:rate=25"); | ||
| 976 | + let pix_fmt = if bit_depth == 10 { "yuv420p10le" } else { "yuv420p" }; | ||
| 977 | + let y4m = Command::new("ffmpeg") | ||
| 978 | + .args([ | ||
| 979 | + "-v", "error", "-f", "lavfi", "-i", &source, "-t", &duration.to_string(), | ||
| 980 | + "-pix_fmt", pix_fmt, "-strict", "-1", "-f", "yuv4mpegpipe", "-", | ||
| 981 | + ]) | ||
| 982 | + .stdin(Stdio::null()) | ||
| 983 | + .stdout(Stdio::piped()) | ||
| 984 | + .stderr(Stdio::piped()) | ||
| 985 | + .output() | ||
| 986 | + .expect("ffmpeg failed to run"); | ||
| 987 | + assert!( | ||
| 988 | + y4m.status.success(), | ||
| 989 | + "{NAME}: ffmpeg refused the {bit_depth}-bit fixture: {}", | ||
| 990 | + String::from_utf8_lossy(&y4m.stderr) | ||
| 991 | + ); | ||
| 992 | + let depth_arg = format!("--bit-depth={bit_depth}"); | ||
| 993 | + let input_depth_arg = format!("--input-bit-depth={bit_depth}"); | ||
| 994 | + let mut child = Command::new(aomenc_path()) | ||
| 995 | + .args([ | ||
| 996 | + "--codec=av1", "--passes=1", "--end-usage=q", "--cq-level=62", | ||
| 997 | + // cpu-used >= 1 keeps libaom on 64x64 superblocks at this | ||
| 998 | + // size (`av1_select_sb_size`: speed >= 1 and <= 480p). | ||
| 999 | + "--cpu-used=4", "--threads=1", "--row-mt=0", "--kf-max-dist=1000", | ||
| 1000 | + &depth_arg, &input_depth_arg, | ||
| 1001 | + // The tool set every sibling inter gate pins; the edge | ||
| 1002 | + // strip itself needs rect partitions left ON. | ||
| 1003 | + "--enable-warped-motion=0", "--enable-obmc=0", "--enable-masked-comp=0", | ||
| 1004 | + "--enable-interintra-comp=0", "--enable-onesided-comp=0", | ||
| 1005 | + "--enable-interintra-wedge=0", "--enable-smooth-interintra=0", | ||
| 1006 | + // Rect partitions stay ON: the edge strip is a FORCED | ||
| 1007 | + // (gathered) HORZ at the boundary, but with rect coding | ||
| 1008 | + // off the encoder answers that gathered symbol SPLIT every | ||
| 1009 | + // time and the arm never fires (measured, r2). | ||
| 1010 | + "--enable-ab-partitions=0", "--enable-1to4-partitions=0", | ||
| 1011 | + "--enable-palette=0", "--enable-intrabc=0", "--enable-cdef=0", | ||
| 1012 | + "--enable-restoration=0", "--enable-ref-frame-mvs=0", | ||
| 1013 | + "--enable-tx-size-search=0", "--enable-filter-intra=0", | ||
| 1014 | + "--enable-smooth-intra=0", "--enable-paeth-intra=0", | ||
| 1015 | + "--enable-directional-intra=0", "--enable-angle-delta=0", | ||
| 1016 | + "--enable-cfl-intra=0", | ||
| 1017 | + // 16 is the smallest leaf this decoder codes rect strips | ||
| 1018 | + // at; below it the sub-16 strip/1:4 refusals fire first | ||
| 1019 | + // and the gate never reaches the edge arm. | ||
| 1020 | + // 160 = two full superblock rows plus 32, so the forced | ||
| 1021 | + // HORZ at the last row is a 64x32 -- the superblock-level | ||
| 1022 | + // arm -- and a 32 floor keeps the run out of the sub-16 | ||
| 1023 | + // rect-strip gap another lane owns. | ||
| 1024 | + "--min-partition-size=32", "--max-partition-size=64", | ||
| 1025 | + "--obu", "-o", "-", "-", | ||
| 1026 | + ]) | ||
| 1027 | + .stdin(Stdio::piped()) | ||
| 1028 | + .stdout(Stdio::piped()) | ||
| 1029 | + .stderr(Stdio::piped()) | ||
| 1030 | + .spawn() | ||
| 1031 | + .expect("aomenc failed to start"); | ||
| 1032 | + child.stdin.take().expect("aomenc stdin").write_all(&y4m.stdout).expect("write y4m"); | ||
| 1033 | + let out = child.wait_with_output().expect("aomenc failed to run"); | ||
| 1034 | + assert!(out.status.success(), "aomenc refused: {}", String::from_utf8_lossy(&out.stderr)); | ||
| 1035 | + let stream = out.stdout; | ||
| 1036 | + | ||
| 1037 | + let before = crate::decode::edge_rect_strip_hits(); | ||
| 1038 | + let decoded = match decode_stream(&stream) { | ||
| 1039 | + Ok(f) => f, | ||
| 1040 | + Err(e) => { | ||
| 1041 | + let msg = e.to_string(); | ||
| 1042 | + assert!( | ||
| 1043 | + msg.contains("unsupported"), | ||
| 1044 | + "{NAME}: {bit_depth}-bit failed outright, not a named refusal: {msg}" | ||
| 1045 | + ); | ||
| 1046 | + eprintln!("{NAME}: {bit_depth}-bit REFUSED {msg}"); | ||
| 1047 | + refused += 1; | ||
| 1048 | + continue; | ||
| 1049 | + } | ||
| 1050 | + }; | ||
| 1051 | + let reference = if bit_depth == 10 { | ||
| 1052 | + ffmpeg_decode_sequence_10bit(&stream, width, height, frames) | ||
| 1053 | + } else { | ||
| 1054 | + ffmpeg_decode_sequence(&stream, width, height, frames) | ||
| 1055 | + }; | ||
| 1056 | + assert_eq!( | ||
| 1057 | + decoded.len(), | ||
| 1058 | + reference.len(), | ||
| 1059 | + "{NAME}: {bit_depth}-bit frame count" | ||
| 1060 | + ); | ||
| 1061 | + for (i, (ours, theirs)) in decoded.iter().zip(&reference).enumerate() { | ||
| 1062 | + let nd = |a: &[u16], b: &[u16]| a.iter().zip(b).filter(|(x, y)| x != y).count(); | ||
| 1063 | + assert_eq!( | ||
| 1064 | + (nd(&ours.y, &theirs.y), nd(&ours.u, &theirs.u), nd(&ours.v, &theirs.v)), | ||
| 1065 | + (0, 0, 0), | ||
| 1066 | + "{NAME}: {bit_depth}-bit frame {i} differs from ffmpeg" | ||
| 1067 | + ); | ||
| 1068 | + } | ||
| 1069 | + compared += 1; | ||
| 1070 | + strip_hits += crate::decode::edge_rect_strip_hits() - before; | ||
| 1071 | + } | ||
| 1072 | + assert!(compared > 0, "{NAME}: every attempt refused ({refused}) -- gate proved nothing"); | ||
| 1073 | + assert!( | ||
| 1074 | + strip_hits > 0, | ||
| 1075 | + "{NAME}: {compared} attempts decoded pixel-exact but not one frame-edge half strip \ | ||
| 1076 | + fired -- the recipe no longer reaches the arm this gate exists for" | ||
| 1077 | + ); | ||
| 1078 | + eprintln!("{NAME}: {compared} attempts pixel-exact, edge_rect_strip_hits={strip_hits}, {refused} refusals"); | ||
| 1079 | + } | ||
| 1080 | + | ||
| 1081 | + /// lane-sb128 r4 GATE (was lane-oddh r2's refusal gate): the SAME real | ||
| 1082 | + /// aomenc 64x72 `--cpu-used=0 --sb-size=128` stream that once desynced at | ||
| 1083 | + /// the very first symbol now decodes PIXEL-EXACT against aomdec. mi_rows | ||
| 1084 | + /// = 18 > 16, so the BLOCK_128X128 root reads a real gathered partition | ||
| 1085 | + /// symbol (2 symbols: has_cols false, has_rows true) -- exactly the case | ||
| 1086 | + /// r1 mis-read as a 10-symbol BLOCK_64X64 partition. | ||
| 1087 | + /// | ||
| 1088 | + /// The `use_128x128_superblock` assert is the "knob reached the tool" | ||
| 1089 | + /// half: without it an aomenc that ignored `--sb-size=128` would leave | ||
| 1090 | + /// the gate proving nothing about 128 superblocks. | ||
| 1091 | + #[test] | ||
| 1092 | + fn a_real_aomenc_128x128_superblock_stream_decodes_pixel_exact() { | ||
| 1093 | + if !have_ffmpeg() || !have_aomenc() { | ||
| 1094 | + eprintln!("SKIP: no ffmpeg/aomenc"); | ||
| 1095 | + return; | ||
| 1096 | + } | ||
| 1097 | + let (width, height) = (64usize, 72usize); | ||
| 1098 | + let y4m = Command::new("ffmpeg") | ||
| 1099 | + .args([ | ||
| 1100 | + "-v", "error", "-f", "lavfi", "-i", | ||
| 1101 | + "mandelbrot=size=64x72:rate=25:start_x=-0.6:start_y=-0.4", "-t", "0.04", | ||
| 1102 | + "-pix_fmt", "yuv420p", "-f", "yuv4mpegpipe", "-", | ||
| 1103 | + ]) | ||
| 1104 | + .stdin(Stdio::null()) | ||
| 1105 | + .stdout(Stdio::piped()) | ||
| 1106 | + .stderr(Stdio::piped()) | ||
| 1107 | + .output() | ||
| 1108 | + .expect("ffmpeg failed to run"); | ||
| 1109 | + assert!(y4m.status.success(), "ffmpeg fixture: {}", String::from_utf8_lossy(&y4m.stderr)); | ||
| 1110 | + let mut child = Command::new(aomenc_path()) | ||
| 1111 | + .args([ | ||
| 1112 | + "--codec=av1", "--passes=1", "--end-usage=q", "--cq-level=32", | ||
| 1113 | + "--cpu-used=0", "--sb-size=128", "--kf-max-dist=0", "--limit=1", | ||
| 1114 | + "--threads=1", "--row-mt=0", "--obu", "-o", "-", "-", | ||
| 1115 | + ]) | ||
| 1116 | + .stdin(Stdio::piped()) | ||
| 1117 | + .stdout(Stdio::piped()) | ||
| 1118 | + .stderr(Stdio::piped()) | ||
| 1119 | + .spawn() | ||
| 1120 | + .expect("aomenc failed to start"); | ||
| 1121 | + child.stdin.take().expect("aomenc stdin").write_all(&y4m.stdout).expect("write y4m"); | ||
| 1122 | + let out = child.wait_with_output().expect("aomenc failed to run"); | ||
| 1123 | + assert!(out.status.success(), "aomenc refused: {}", String::from_utf8_lossy(&out.stderr)); | ||
| 1124 | + let stream = out.stdout; | ||
| 1125 | + | ||
| 1126 | + // The knob actually arrived: this stream's sequence header codes | ||
| 1127 | + // `use_128x128_superblock = 1`. | ||
| 1128 | + let mut parser = Av1Parser::new(); | ||
| 1129 | + let mut pos = 0usize; | ||
| 1130 | + let mut sb128 = false; | ||
| 1131 | + while pos < stream.len() { | ||
| 1132 | + let Ok(obu) = parser.parse_obu(&stream[pos..]) else { | ||
| 1133 | + break; | ||
| 1134 | + }; | ||
| 1135 | + pos += obu.total_size.max(1); | ||
| 1136 | + if let Some(seq) = parser.sequence_header() { | ||
| 1137 | + sb128 = seq.use_128x128_superblock; | ||
| 1138 | + break; | ||
| 1139 | + } | ||
| 1140 | + } | ||
| 1141 | + assert!(sb128, "aomenc ignored --sb-size=128: this stream is 64x64-superblock"); | ||
| 1142 | + | ||
| 1143 | + let _guard = lock_gate_counters(); | ||
| 1144 | + let (frames, hidden) = | ||
| 1145 | + decode_all_frames_vs_oracle(&stream, "sb128-oddh-64x72"); | ||
| 1146 | + assert!(frames > 0, "no frames decoded for {width}x{height}"); | ||
| 1147 | + eprintln!( | ||
| 1148 | + "a_real_aomenc_128x128_superblock_stream_decodes_pixel_exact: \ | ||
| 1149 | + {frames} frames pixel-exact ({hidden} hidden) at {width}x{height}" | ||
| 1150 | + ); | ||
| 1151 | + } | ||
| 1152 | + | ||
| 924 | /// `decode_stream` on a lone key frame's stream matches both the tile | 1153 | /// `decode_stream` on a lone key frame's stream matches both the tile |
| 925 | /// path (`decode_key_frame_tile` called directly on `Encoded::tile`) and | 1154 | /// path (`decode_key_frame_tile` called directly on `Encoded::tile`) and |
| 926 | /// the encoder's own reconstruction, at an even and an odd size. | 1155 | /// the encoder's own reconstruction, at an even and an odd size. |
| @@ -1965,6 +2194,10 @@ mod tests { | |||
| 1965 | // masked compound, palette, ...) are other lanes' work; | 2194 | // masked compound, palette, ...) are other lanes' work; |
| 1966 | // this gate is about hidden frames, not about them. | 2195 | // this gate is about hidden frames, not about them. |
| 1967 | "--enable-warped-motion=0", | 2196 | "--enable-warped-motion=0", |
| 2197 | + // OBMC stays off HERE (this gate is about hidden frames); | ||
| 2198 | + // the tool's own coverage is the `obmc*` gates and, on a | ||
| 2199 | + // 16x8/8x16 leaf, the `--enable-obmc=1` arm of | ||
| 2200 | + // `..._with_a_16_level_rect_leaf_...` (lane-inter4 r4). | ||
| 1968 | "--enable-obmc=0", | 2201 | "--enable-obmc=0", |
| 1969 | "--enable-masked-comp=0", | 2202 | "--enable-masked-comp=0", |
| 1970 | "--enable-interintra-comp=0", | 2203 | "--enable-interintra-comp=0", |
| @@ -2685,6 +2918,41 @@ mod tests { | |||
| 2685 | eprintln!("{NAME}: pixel-exact, grain_hits={}", crate::film_grain::grain_hits()); | 2918 | eprintln!("{NAME}: pixel-exact, grain_hits={}", crate::film_grain::grain_hits()); |
| 2686 | } | 2919 | } |
| 2687 | 2920 | ||
| 2921 | + /// lane-golomb r1: THE FILM ITSELF. `crates/ec-av1/fixtures/reelb_head_key_frame.obu` | ||
| 2922 | + /// is the first frame of the user's ReelB AV1 release (3840x1608 | ||
| 2923 | + /// yuv420p10le, `ffmpeg -i <mkv> -c copy -frames:v 1 -f obu`, 147 bytes) -- | ||
| 2924 | + /// a real 10-bit key frame whose height is NOT a multiple of the 64-pixel | ||
| 2925 | + /// superblock, so its last superblock row (mi_row=400 of 402) carries the | ||
| 2926 | + /// edge partition symbol this lane fixed: libaom's `ec_read_partition_impl` | ||
| 2927 | + /// returns `PARTITION_HORZ` when the gathered `split_or_horz` bit is 0, and | ||
| 2928 | + /// this decoder used to READ that bit and throw it away, forcing SPLIT | ||
| 2929 | + /// (class `parsed-then-discarded`). The desync surfaced two rows later as | ||
| 2930 | + /// "a Golomb tail longer than this decoder reads" -- a refusal naming the | ||
| 2931 | + /// symptom, never the cause. | ||
| 2932 | + #[test] | ||
| 2933 | + fn the_reelb_head_key_frame_decodes_pixel_exact() { | ||
| 2934 | + const NAME: &str = "the_reelb_head_key_frame_decodes_pixel_exact"; | ||
| 2935 | + if !have_ffmpeg() { | ||
| 2936 | + eprintln!("SKIP {NAME}: no ffmpeg"); | ||
| 2937 | + return; | ||
| 2938 | + } | ||
| 2939 | + let path = std::path::Path::new(env!("CARGO_MANIFEST_DIR")) | ||
| 2940 | + .join("fixtures/reelb_head_key_frame.obu"); | ||
| 2941 | + let stream = std::fs::read(&path) | ||
| 2942 | + .unwrap_or_else(|e| panic!("{NAME}: reading {}: {e}", path.display())); | ||
| 2943 | + let (width, height) = (3840usize, 1608usize); | ||
| 2944 | + let frames = match decode_stream(&stream) { | ||
| 2945 | + Ok(frames) => frames, | ||
| 2946 | + Err(e) => panic!("{NAME}: decode_stream refused: {e}"), | ||
| 2947 | + }; | ||
| 2948 | + assert_eq!(frames.len(), 1, "{NAME}: one key frame"); | ||
| 2949 | + assert_eq!((frames[0].width, frames[0].height), (width, height)); | ||
| 2950 | + let ffmpeg_frames = ffmpeg_decode_sequence_10bit(&stream, width, height, 1); | ||
| 2951 | + assert_eq!(frames[0].y, ffmpeg_frames[0].y, "{NAME}: luma vs ffmpeg"); | ||
| 2952 | + assert_eq!(frames[0].u, ffmpeg_frames[0].u, "{NAME}: U vs ffmpeg"); | ||
| 2953 | + assert_eq!(frames[0].v, ffmpeg_frames[0].v, "{NAME}: V vs ffmpeg"); | ||
| 2954 | + } | ||
| 2955 | + | ||
| 2688 | /// lane-hbd10 r1: a real `aomenc --bit-depth=10 --superres-mode=1 | 2956 | /// lane-hbd10 r1: a real `aomenc --bit-depth=10 --superres-mode=1 |
| 2689 | /// --superres-denominator=12` key frame, decoded pixel-exact against | 2957 | /// --superres-denominator=12` key frame, decoded pixel-exact against |
| 2690 | /// ffmpeg's own 10-bit decode. Proves `superres::upscale_row`'s | 2958 | /// ffmpeg's own 10-bit decode. Proves `superres::upscale_row`'s |
| @@ -4699,38 +4967,63 @@ mod tests { | |||
| 4699 | ); | 4967 | ); |
| 4700 | } | 4968 | } |
| 4701 | 4969 | ||
| 4702 | - /// lane-chroma r2 stage 1: a real aomenc key frame with | 4970 | + /// lane-angleinter r1 (class [[refusal-strings-are-claims]] + |
| 4703 | - /// `--enable-smooth-intra=1` (opposite of every sibling recipe's `=0`) | 4971 | + /// [[tool-disabled-in-every-gate]]): a real aomenc inter sequence with |
| 4704 | - /// and `--enable-paeth-intra=0` -- paeth chroma stays off so the still- | 4972 | + /// `--enable-angle-delta=1` and `--enable-directional-intra=1` (aomenc's |
| 4705 | - /// refused smooth/paeth `uv_mode` (round-2, unrelated to this gate) never | 4973 | + /// own defaults; every inter gate before this one pinned BOTH off) in |
| 4706 | - /// fires; smooth *luma* neighbours are exactly what this gate wants to | 4974 | + /// which the RD gives an INTRA block inside an inter frame a directional |
| 4707 | - /// exercise, proving [`decode::smooth_luma_hits`] actually landed a | 4975 | + /// luma mode with a nonzero `angle_delta_y`. Both intra-in-inter arms |
| 4708 | - /// directional block next to a smooth-predicted one and decoded | 4976 | + /// read that symbol and then REFUSED it as "this encoder never writes |
| 4709 | - /// pixel-exact (the [`PlaneBuf::reconstruct`] `smooth_neighbor` fix). | 4977 | + /// one" -- the claim is false, `read_intra_angle_info` writes it exactly |
| 4978 | + /// as a key frame does. Hard-asserts | ||
| 4979 | + /// [`decode::intra_in_inter_angle_delta_y_hits`]; an attempt that never | ||
| 4980 | + /// produced one proves nothing, and exhausting every attempt is a | ||
| 4981 | + /// FAILURE, not a SKIP. | ||
| 4710 | #[test] | 4982 | #[test] |
| 4711 | - fn a_real_aomenc_stream_with_smooth_luma_neighbour_decodes_pixel_exact() { | 4983 | + fn a_real_aomenc_inter_sequence_with_a_directional_intra_block_with_angle_delta_decodes_pixel_exact() |
| 4984 | + { | ||
| 4985 | + angle_delta_in_inter_gate(8, "--min-partition-size=16"); | ||
| 4986 | + } | ||
| 4987 | + | ||
| 4988 | + /// The 10-bit arm (both of the user's films are `yuv420p10le`). | ||
| 4989 | + #[test] | ||
| 4990 | + fn a_real_aomenc_10bit_inter_sequence_with_a_directional_intra_block_with_angle_delta_decodes_pixel_exact() | ||
| 4991 | + { | ||
| 4992 | + angle_delta_in_inter_gate(10, "--min-partition-size=16"); | ||
| 4993 | + } | ||
| 4994 | + | ||
| 4995 | + fn angle_delta_in_inter_gate(bit_depth: u32, min_partition: &str) { | ||
| 4996 | + let name = format!("angle_delta_in_inter_gate({bit_depth}, min={min_partition})"); | ||
| 4997 | + let leaf8 = min_partition.ends_with('8'); | ||
| 4998 | + assert!(!leaf8, "the 8x8-leaf arm keeps its refusal; see the module note"); | ||
| 4712 | if !have_ffmpeg() { | 4999 | if !have_ffmpeg() { |
| 4713 | - eprintln!( | 5000 | + eprintln!("SKIP {name}: no ffmpeg"); |
| 4714 | - "SKIP a_real_aomenc_stream_with_smooth_luma_neighbour_decodes_pixel_exact: no ffmpeg" | ||
| 4715 | - ); | ||
| 4716 | return; | 5001 | return; |
| 4717 | } | 5002 | } |
| 4718 | if !have_aomenc() { | 5003 | if !have_aomenc() { |
| 4719 | - eprintln!( | 5004 | + eprintln!("SKIP {name}: no aomenc at {}", aomenc_path().display()); |
| 4720 | - "SKIP a_real_aomenc_stream_with_smooth_luma_neighbour_decodes_pixel_exact: no aomenc at {}", | ||
| 4721 | - aomenc_path().display() | ||
| 4722 | - ); | ||
| 4723 | return; | 5005 | return; |
| 4724 | } | 5006 | } |
| 4725 | - let (width, height) = (64usize, 64usize); | 5007 | + let (width, height, frame_count) = (64usize, 64usize, 8usize); |
| 4726 | let mut refusals = Vec::new(); | 5008 | let mut refusals = Vec::new(); |
| 4727 | - let mut fired_runs = 0u32; | ||
| 4728 | let mut uncounted_exact = 0u32; | 5009 | let mut uncounted_exact = 0u32; |
| 4729 | for attempt in 0..40u32 { | 5010 | for attempt in 0..40u32 { |
| 4730 | let seed = 42 + attempt; | 5011 | let seed = 42 + attempt; |
| 5012 | + // A zooming fractal: every frame moves (so the sequence is | ||
| 5013 | + // genuinely inter-coded) and keeps sharp new detail entering at | ||
| 5014 | + // the borders, which is what makes aomenc's RD choose an INTRA | ||
| 5015 | + // block inside an inter frame -- and then split its transform. | ||
| 5016 | + // A zooming fractal with a hard CUT halfway (`overlay` switching | ||
| 5017 | + // a second, unrelated fractal on at frame 4): after the cut every | ||
| 5018 | + // block is unpredictable from the reference, which is what makes | ||
| 5019 | + // aomenc code INTRA blocks inside an inter frame -- and at this | ||
| 5020 | + // cq the RD then splits their transforms. | ||
| 4731 | let source = format!( | 5021 | let source = format!( |
| 4732 | - "mandelbrot=size=64x64:start_scale={}:rate=25", | 5022 | + "mandelbrot=size={width}x{height}:start_scale={}:rate=25[a];\ |
| 4733 | - 5.0 - f64::from(attempt) * 0.06 | 5023 | + mandelbrot=size={width}x{height}:start_scale={}:rate=25[b];\ |
| 5024 | + [a][b]overlay=enable='gte(n,4)'", | ||
| 5025 | + 5.0 - f64::from(attempt) * 0.06, | ||
| 5026 | + 0.9 + f64::from(attempt) * 0.11 | ||
| 4734 | ); | 5027 | ); |
| 4735 | let y4m = Command::new("ffmpeg") | 5028 | let y4m = Command::new("ffmpeg") |
| 4736 | .args([ | 5029 | .args([ |
| @@ -4740,12 +5033,21 @@ mod tests { | |||
| 4740 | "lavfi", | 5033 | "lavfi", |
| 4741 | "-i", | 5034 | "-i", |
| 4742 | &source, | 5035 | &source, |
| 5036 | + // Desaturated chroma keeps `uv_mode` on DC_PRED, so the | ||
| 5037 | + // still-refused directional-chroma gaps never fire and | ||
| 5038 | + // luma detail alone drives the transform split. | ||
| 5039 | + "-vf", | ||
| 5040 | + "hue=s=0", | ||
| 4743 | "-pix_fmt", | 5041 | "-pix_fmt", |
| 4744 | - "yuv420p", | 5042 | + if bit_depth == 10 { "yuv420p10le" } else { "yuv420p" }, |
| 5043 | + "-strict", | ||
| 5044 | + "-1", | ||
| 4745 | "-t", | 5045 | "-t", |
| 4746 | - "0.04", | 5046 | + "0.32", |
| 4747 | "-f", | 5047 | "-f", |
| 4748 | "yuv4mpegpipe", | 5048 | "yuv4mpegpipe", |
| 5049 | + "-strict", | ||
| 5050 | + "-1", | ||
| 4749 | "-", | 5051 | "-", |
| 4750 | ]) | 5052 | ]) |
| 4751 | .stdin(Stdio::null()) | 5053 | .stdin(Stdio::null()) |
| @@ -4758,32 +5060,72 @@ mod tests { | |||
| 4758 | "ffmpeg fixture: {}", | 5060 | "ffmpeg fixture: {}", |
| 4759 | String::from_utf8_lossy(&y4m.stderr) | 5061 | String::from_utf8_lossy(&y4m.stderr) |
| 4760 | ); | 5062 | ); |
| 5063 | + // The 8x8-leaf arm is fenced by three sibling refusals (non-DC | ||
| 5064 | + // chroma on an 8x8 leaf, its TX_4X4 split, sub-16 rect inter | ||
| 5065 | + // leaves), so it sweeps the quantiser as well as the source: a | ||
| 5066 | + // coarser q is what pushes the RD to directional intra at 8x8. | ||
| 5067 | + let cq = if leaf8 { | ||
| 5068 | + format!("--cq-level={}", 20 + (attempt % 5) * 10) | ||
| 5069 | + } else { | ||
| 5070 | + "--cq-level=30".to_string() | ||
| 5071 | + }; | ||
| 5072 | + let depth_args: &[&str] = if bit_depth == 10 { | ||
| 5073 | + &["-b", "10", "--input-bit-depth=10"] | ||
| 5074 | + } else { | ||
| 5075 | + &[] | ||
| 5076 | + }; | ||
| 4761 | let mut child = Command::new(aomenc_path()) | 5077 | let mut child = Command::new(aomenc_path()) |
| 5078 | + .args(depth_args) | ||
| 4762 | .args([ | 5079 | .args([ |
| 4763 | "--codec=av1", | 5080 | "--codec=av1", |
| 4764 | "--passes=1", | 5081 | "--passes=1", |
| 4765 | "--end-usage=q", | 5082 | "--end-usage=q", |
| 4766 | - "--cq-level=45", | 5083 | + &cq, |
| 4767 | "--cpu-used=0", | 5084 | "--cpu-used=0", |
| 4768 | - "--enable-rect-partitions=0", | 5085 | + "--lag-in-frames=0", |
| 5086 | + "--auto-alt-ref=0", | ||
| 5087 | + // One key frame only: every later frame is an inter frame, | ||
| 5088 | + // which is where this gate's intra blocks must sit. The | ||
| 5089 | + // MIN distance is what stops aomenc's scene-cut detector | ||
| 5090 | + // from inserting a second key frame at the cut this gate's | ||
| 5091 | + // source deliberately contains. | ||
| 5092 | + "--kf-max-dist=1000", | ||
| 5093 | + "--kf-min-dist=1000", | ||
| 5094 | + "--threads=1", | ||
| 5095 | + "--row-mt=0", | ||
| 5096 | + "--enable-order-hint=0", | ||
| 5097 | + "--enable-warped-motion=0", | ||
| 5098 | + "--enable-obmc=0", | ||
| 5099 | + "--enable-masked-comp=0", | ||
| 5100 | + "--enable-interintra-comp=0", | ||
| 5101 | + "--enable-dist-wtd-comp=0", | ||
| 5102 | + "--enable-diff-wtd-comp=0", | ||
| 5103 | + "--enable-onesided-comp=0", | ||
| 5104 | + "--enable-interintra-wedge=0", | ||
| 5105 | + "--enable-smooth-interintra=0", | ||
| 4769 | "--enable-ab-partitions=0", | 5106 | "--enable-ab-partitions=0", |
| 4770 | "--enable-1to4-partitions=0", | 5107 | "--enable-1to4-partitions=0", |
| 4771 | - "--enable-filter-intra=0", | 5108 | + "--enable-smooth-intra=0", |
| 4772 | - "--enable-smooth-intra=1", | ||
| 4773 | - // Smooth/paeth chroma is a still-refused, separate | ||
| 4774 | - // round-2 gap -- off so no attempt trips it while this | ||
| 4775 | - // gate is purely about luma's edge-filter fix. | ||
| 4776 | "--enable-paeth-intra=0", | 5109 | "--enable-paeth-intra=0", |
| 4777 | - "--enable-tx-size-search=0", | 5110 | + "--enable-directional-intra=1", |
| 5111 | + "--enable-angle-delta=1", | ||
| 4778 | "--enable-cdef=0", | 5112 | "--enable-cdef=0", |
| 4779 | "--enable-restoration=0", | 5113 | "--enable-restoration=0", |
| 4780 | - "--enable-intra-edge-filter=1", | ||
| 4781 | - "--max-partition-size=32", | ||
| 4782 | - "--min-partition-size=16", | ||
| 4783 | "--enable-palette=0", | 5114 | "--enable-palette=0", |
| 4784 | "--enable-intrabc=0", | 5115 | "--enable-intrabc=0", |
| 4785 | "--enable-cfl-intra=0", | 5116 | "--enable-cfl-intra=0", |
| 4786 | "--enable-ref-frame-mvs=0", | 5117 | "--enable-ref-frame-mvs=0", |
| 5118 | + // Per-arm overrides go LAST (aomenc keeps the last | ||
| 5119 | + // occurrence of a repeated --enable-* flag): the intra | ||
| 5120 | + // tx_depth symbol only exists under TX_MODE_SELECT, and | ||
| 5121 | + // rect partitions are a separate named refusal. | ||
| 5122 | + "--enable-filter-intra=1", | ||
| 5123 | + "--enable-tx-size-search=1", | ||
| 5124 | + "--enable-rect-partitions=0", | ||
| 5125 | + "--max-partition-size=32", | ||
| 5126 | + // Sub-16 inter partitions are a separate named refusal, | ||
| 5127 | + // as is the 8x8 intra leaf's own TX_4X4 split. | ||
| 5128 | + min_partition, | ||
| 4787 | "--obu", | 5129 | "--obu", |
| 4788 | "-o", | 5130 | "-o", |
| 4789 | "-", | 5131 | "-", |
| @@ -4807,21 +5149,214 @@ mod tests { | |||
| 4807 | String::from_utf8_lossy(&out.stderr) | 5149 | String::from_utf8_lossy(&out.stderr) |
| 4808 | ); | 5150 | ); |
| 4809 | let stream = out.stdout; | 5151 | let stream = out.stdout; |
| 4810 | - let smooth_before = decode::smooth_luma_hits(); | 5152 | + let before = decode::intra_in_inter_angle_delta_y_hits(); |
| 5153 | + let before_uv = decode::intra_in_inter_angle_delta_uv_hits(); | ||
| 4811 | let frames = match decode_stream(&stream) { | 5154 | let frames = match decode_stream(&stream) { |
| 4812 | Ok(frames) => frames, | 5155 | Ok(frames) => frames, |
| 4813 | Err(e) => { | 5156 | Err(e) => { |
| 4814 | - refusals.push(format!("seed {seed}: {e}")); | 5157 | + let msg = e.to_string(); |
| 5158 | + assert!( | ||
| 5159 | + msg.contains("unsupported"), | ||
| 5160 | + "{name} decode failed outright (seed {seed}): {msg}" | ||
| 5161 | + ); | ||
| 5162 | + refusals.push(format!("seed {seed}: {msg}")); | ||
| 4815 | continue; | 5163 | continue; |
| 4816 | } | 5164 | } |
| 4817 | }; | 5165 | }; |
| 4818 | - // class [[gate-skips-on-its-own-failure]]: a decode that succeeded | 5166 | + let fired = decode::intra_in_inter_angle_delta_y_hits() - before; |
| 4819 | - // is ALWAYS pixel-compared below; the hit counter only decides whether | 5167 | + let fired_uv = decode::intra_in_inter_angle_delta_uv_hits() - before_uv; |
| 4820 | - // the attempt counts toward the firing total. | 5168 | + // class [[gate-skips-on-its-own-failure]]: a decode that |
| 4821 | - let counted = decode::smooth_luma_hits() != smooth_before; | 5169 | + // succeeded is ALWAYS pixel-compared below; the counter only |
| 4822 | - if counted { | 5170 | + // decides whether the attempt counts as firing. |
| 4823 | - fired_runs += 1; | 5171 | + let counted = fired != 0; |
| 4824 | - } else { | 5172 | + if !counted { |
| 5173 | + uncounted_exact += 1; | ||
| 5174 | + refusals.push(format!( | ||
| 5175 | + "seed {seed}: decoded and pixel-compared, but no intra block in an inter \ | ||
| 5176 | + frame carried a nonzero angle_delta_y" | ||
| 5177 | + )); | ||
| 5178 | + } | ||
| 5179 | + let ffmpeg_frames = if bit_depth == 10 { | ||
| 5180 | + ffmpeg_decode_sequence_10bit(&stream, width, height, frame_count) | ||
| 5181 | + } else { | ||
| 5182 | + ffmpeg_decode_sequence(&stream, width, height, frame_count) | ||
| 5183 | + }; | ||
| 5184 | + assert_eq!(frames.len(), frame_count); | ||
| 5185 | + eprintln!( | ||
| 5186 | + "{name} seed={seed}: intra-in-inter blocks with a nonzero angle_delta_y = \ | ||
| 5187 | + {fired}, angle_delta_uv = {fired_uv}" | ||
| 5188 | + ); | ||
| 5189 | + for (i, (got, want)) in frames.iter().zip(&ffmpeg_frames).enumerate() { | ||
| 5190 | + for (plane, (g, w)) in [ | ||
| 5191 | + ("Y", (&got.y, &want.y)), | ||
| 5192 | + ("U", (&got.u, &want.u)), | ||
| 5193 | + ("V", (&got.v, &want.v)), | ||
| 5194 | + ] { | ||
| 5195 | + let stride = if plane == "Y" { width } else { width / 2 }; | ||
| 5196 | + if let Some(at) = g.iter().zip(w.iter()).position(|(a, b)| a != b) { | ||
| 5197 | + eprintln!( | ||
| 5198 | + "{name} seed={seed}: frame {i} {plane} first diff at ({}, {}) got {} \ | ||
| 5199 | + want {} ({} samples differ)", | ||
| 5200 | + at % stride, | ||
| 5201 | + at / stride, | ||
| 5202 | + g[at], | ||
| 5203 | + w[at], | ||
| 5204 | + g.iter().zip(w.iter()).filter(|(a, b)| a != b).count(), | ||
| 5205 | + ); | ||
| 5206 | + } | ||
| 5207 | + } | ||
| 5208 | + } | ||
| 5209 | + for (i, (got, want)) in frames.iter().zip(&ffmpeg_frames).enumerate() { | ||
| 5210 | + assert_eq!(got.y, want.y, "frame {i} luma vs ffmpeg (seed {seed})"); | ||
| 5211 | + assert_eq!(got.u, want.u, "frame {i} U vs ffmpeg (seed {seed})"); | ||
| 5212 | + assert_eq!(got.v, want.v, "frame {i} V vs ffmpeg (seed {seed})"); | ||
| 5213 | + } | ||
| 5214 | + if counted { | ||
| 5215 | + gate_buckets( | ||
| 5216 | + &name, | ||
| 5217 | + 1, | ||
| 5218 | + uncounted_exact, | ||
| 5219 | + refusals.len() - uncounted_exact as usize, | ||
| 5220 | + ); | ||
| 5221 | + return; | ||
| 5222 | + } | ||
| 5223 | + } | ||
| 5224 | + gate_buckets( | ||
| 5225 | + &name, | ||
| 5226 | + 0, | ||
| 5227 | + uncounted_exact, | ||
| 5228 | + refusals.len() - uncounted_exact as usize, | ||
| 5229 | + ); | ||
| 5230 | + panic!( | ||
| 5231 | + "{name} never observed a nonzero angle delta on an intra block in an inter \ | ||
| 5232 | + frame:\n{}", | ||
| 5233 | + refusals.join("\n") | ||
| 5234 | + ); | ||
| 5235 | + } | ||
| 5236 | + | ||
| 5237 | + /// lane-chroma r2 stage 1: a real aomenc key frame with | ||
| 5238 | + /// `--enable-smooth-intra=1` (opposite of every sibling recipe's `=0`) | ||
| 5239 | + /// and `--enable-paeth-intra=0` -- paeth chroma stays off so the still- | ||
| 5240 | + /// refused smooth/paeth `uv_mode` (round-2, unrelated to this gate) never | ||
| 5241 | + /// fires; smooth *luma* neighbours are exactly what this gate wants to | ||
| 5242 | + /// exercise, proving [`decode::smooth_luma_hits`] actually landed a | ||
| 5243 | + /// directional block next to a smooth-predicted one and decoded | ||
| 5244 | + /// pixel-exact (the [`PlaneBuf::reconstruct`] `smooth_neighbor` fix). | ||
| 5245 | + #[test] | ||
| 5246 | + fn a_real_aomenc_stream_with_smooth_luma_neighbour_decodes_pixel_exact() { | ||
| 5247 | + if !have_ffmpeg() { | ||
| 5248 | + eprintln!( | ||
| 5249 | + "SKIP a_real_aomenc_stream_with_smooth_luma_neighbour_decodes_pixel_exact: no ffmpeg" | ||
| 5250 | + ); | ||
| 5251 | + return; | ||
| 5252 | + } | ||
| 5253 | + if !have_aomenc() { | ||
| 5254 | + eprintln!( | ||
| 5255 | + "SKIP a_real_aomenc_stream_with_smooth_luma_neighbour_decodes_pixel_exact: no aomenc at {}", | ||
| 5256 | + aomenc_path().display() | ||
| 5257 | + ); | ||
| 5258 | + return; | ||
| 5259 | + } | ||
| 5260 | + let (width, height) = (64usize, 64usize); | ||
| 5261 | + let mut refusals = Vec::new(); | ||
| 5262 | + let mut fired_runs = 0u32; | ||
| 5263 | + let mut uncounted_exact = 0u32; | ||
| 5264 | + for attempt in 0..40u32 { | ||
| 5265 | + let seed = 42 + attempt; | ||
| 5266 | + let source = format!( | ||
| 5267 | + "mandelbrot=size=64x64:start_scale={}:rate=25", | ||
| 5268 | + 5.0 - f64::from(attempt) * 0.06 | ||
| 5269 | + ); | ||
| 5270 | + let y4m = Command::new("ffmpeg") | ||
| 5271 | + .args([ | ||
| 5272 | + "-v", | ||
| 5273 | + "error", | ||
| 5274 | + "-f", | ||
| 5275 | + "lavfi", | ||
| 5276 | + "-i", | ||
| 5277 | + &source, | ||
| 5278 | + "-pix_fmt", | ||
| 5279 | + "yuv420p", | ||
| 5280 | + "-t", | ||
| 5281 | + "0.04", | ||
| 5282 | + "-f", | ||
| 5283 | + "yuv4mpegpipe", | ||
| 5284 | + "-", | ||
| 5285 | + ]) | ||
| 5286 | + .stdin(Stdio::null()) | ||
| 5287 | + .stdout(Stdio::piped()) | ||
| 5288 | + .stderr(Stdio::piped()) | ||
| 5289 | + .output() | ||
| 5290 | + .expect("ffmpeg failed to run"); | ||
| 5291 | + assert!( | ||
| 5292 | + y4m.status.success(), | ||
| 5293 | + "ffmpeg fixture: {}", | ||
| 5294 | + String::from_utf8_lossy(&y4m.stderr) | ||
| 5295 | + ); | ||
| 5296 | + let mut child = Command::new(aomenc_path()) | ||
| 5297 | + .args([ | ||
| 5298 | + "--codec=av1", | ||
| 5299 | + "--passes=1", | ||
| 5300 | + "--end-usage=q", | ||
| 5301 | + "--cq-level=45", | ||
| 5302 | + "--cpu-used=0", | ||
| 5303 | + "--enable-rect-partitions=0", | ||
| 5304 | + "--enable-ab-partitions=0", | ||
| 5305 | + "--enable-1to4-partitions=0", | ||
| 5306 | + "--enable-filter-intra=0", | ||
| 5307 | + "--enable-smooth-intra=1", | ||
| 5308 | + // Smooth/paeth chroma is a still-refused, separate | ||
| 5309 | + // round-2 gap -- off so no attempt trips it while this | ||
| 5310 | + // gate is purely about luma's edge-filter fix. | ||
| 5311 | + "--enable-paeth-intra=0", | ||
| 5312 | + "--enable-tx-size-search=0", | ||
| 5313 | + "--enable-cdef=0", | ||
| 5314 | + "--enable-restoration=0", | ||
| 5315 | + "--enable-intra-edge-filter=1", | ||
| 5316 | + "--max-partition-size=32", | ||
| 5317 | + "--min-partition-size=16", | ||
| 5318 | + "--enable-palette=0", | ||
| 5319 | + "--enable-intrabc=0", | ||
| 5320 | + "--enable-cfl-intra=0", | ||
| 5321 | + "--enable-ref-frame-mvs=0", | ||
| 5322 | + "--obu", | ||
| 5323 | + "-o", | ||
| 5324 | + "-", | ||
| 5325 | + "-", | ||
| 5326 | + ]) | ||
| 5327 | + .stdin(Stdio::piped()) | ||
| 5328 | + .stdout(Stdio::piped()) | ||
| 5329 | + .stderr(Stdio::piped()) | ||
| 5330 | + .spawn() | ||
| 5331 | + .expect("aomenc failed to start"); | ||
| 5332 | + child | ||
| 5333 | + .stdin | ||
| 5334 | + .take() | ||
| 5335 | + .expect("aomenc stdin") | ||
| 5336 | + .write_all(&y4m.stdout) | ||
| 5337 | + .expect("writing y4m to aomenc"); | ||
| 5338 | + let out = child.wait_with_output().expect("aomenc failed to run"); | ||
| 5339 | + assert!( | ||
| 5340 | + out.status.success(), | ||
| 5341 | + "aomenc refused the fixture: {}", | ||
| 5342 | + String::from_utf8_lossy(&out.stderr) | ||
| 5343 | + ); | ||
| 5344 | + let stream = out.stdout; | ||
| 5345 | + let smooth_before = decode::smooth_luma_hits(); | ||
| 5346 | + let frames = match decode_stream(&stream) { | ||
| 5347 | + Ok(frames) => frames, | ||
| 5348 | + Err(e) => { | ||
| 5349 | + refusals.push(format!("seed {seed}: {e}")); | ||
| 5350 | + continue; | ||
| 5351 | + } | ||
| 5352 | + }; | ||
| 5353 | + // class [[gate-skips-on-its-own-failure]]: a decode that succeeded | ||
| 5354 | + // is ALWAYS pixel-compared below; the hit counter only decides whether | ||
| 5355 | + // the attempt counts toward the firing total. | ||
| 5356 | + let counted = decode::smooth_luma_hits() != smooth_before; | ||
| 5357 | + if counted { | ||
| 5358 | + fired_runs += 1; | ||
| 5359 | + } else { | ||
| 4825 | uncounted_exact += 1; | 5360 | uncounted_exact += 1; |
| 4826 | refusals.push(format!( | 5361 | refusals.push(format!( |
| 4827 | "seed {seed}: decoded and pixel-compared, but no smooth-luma-neighbour block \ | 5362 | "seed {seed}: decoded and pixel-compared, but no smooth-luma-neighbour block \ |
| @@ -5623,27 +6158,951 @@ mod tests { | |||
| 5623 | ); | 6158 | ); |
| 5624 | } | 6159 | } |
| 5625 | } | 6160 | } |
| 5626 | - return; | 6161 | + return; |
| 6162 | + } | ||
| 6163 | + panic!("{name}: no attempt fired a class-1 chroma eob: {refusals:?}"); | ||
| 6164 | + } | ||
| 6165 | + | ||
| 6166 | + #[test] | ||
| 6167 | + fn a_real_aomenc_inter_sequence_with_a_class1_chroma_eob_decodes_pixel_exact() { | ||
| 6168 | + chroma_class1_eob_gate( | ||
| 6169 | + "a_real_aomenc_inter_sequence_with_a_class1_chroma_eob_decodes_pixel_exact", | ||
| 6170 | + false, | ||
| 6171 | + ); | ||
| 6172 | + } | ||
| 6173 | + | ||
| 6174 | + #[test] | ||
| 6175 | + fn a_real_aomenc_10bit_inter_sequence_with_a_class1_chroma_eob_decodes_pixel_exact() { | ||
| 6176 | + chroma_class1_eob_gate( | ||
| 6177 | + "a_real_aomenc_10bit_inter_sequence_with_a_class1_chroma_eob_decodes_pixel_exact", | ||
| 6178 | + true, | ||
| 6179 | + ); | ||
| 6180 | + } | ||
| 6181 | + | ||
| 6182 | + /// lane-inter4 r1: the SUPERBLOCK-level inter `PARTITION_HORZ`/ | ||
| 6183 | + /// `PARTITION_VERT` pair -- two 64x32 / 32x64 inter strips, the arm the | ||
| 6184 | + /// inter tile path refused outright before this lane ("an inter SB-level | ||
| 6185 | + /// partition type other than NONE or SPLIT"). `--min-partition-size=32` | ||
| 6186 | + /// keeps every 32x32-level rect shape (already coded, and residual-capable | ||
| 6187 | + /// only when skip) out of the picture so the counters can only be earned | ||
| 6188 | + /// at the superblock level; the noiseless split-motion source (one half | ||
| 6189 | + /// translating, the other static, flat inside each half) is what makes | ||
| 6190 | + /// aomenc's RD pick a superblock HORZ/VERT whose strips are `skip` -- | ||
| 6191 | + /// the ONLY inter rect shape this decoder can complete, since rectangular | ||
| 6192 | + /// inter residual coding is not ported (see `reject_residual`). | ||
| 6193 | + /// | ||
| 6194 | + /// Every decoded frame is compared to ffmpeg (Y, U and V); an attempt | ||
| 6195 | + /// that refuses by name is counted, never turned into a SKIP; and an | ||
| 6196 | + /// attempt that decoded without firing the arm is counted separately and | ||
| 6197 | + /// still required to be pixel-exact (class gate-skips-on-its-own-failure). | ||
| 6198 | + #[test] | ||
| 6199 | + fn a_real_aomenc_inter_sequence_with_a_superblock_level_rect_partition_decodes_pixel_exact() { | ||
| 6200 | + const NAME: &str = "a_real_aomenc_inter_sequence_with_a_superblock_level_rect_partition_decodes_pixel_exact"; | ||
| 6201 | + let _gate_lock = lock_gate_counters(); | ||
| 6202 | + if !have_ffmpeg() { | ||
| 6203 | + eprintln!("SKIP {NAME}: no ffmpeg"); | ||
| 6204 | + return; | ||
| 6205 | + } | ||
| 6206 | + if !have_aomenc() { | ||
| 6207 | + eprintln!("SKIP {NAME}: no aomenc at {}", aomenc_path().display()); | ||
| 6208 | + return; | ||
| 6209 | + } | ||
| 6210 | + let (width, height, frame_count) = (192usize, 128usize, 6usize); | ||
| 6211 | + // lane-inter4 r1: 8-bit ONLY, and the reason is the lane's own open | ||
| 6212 | + // residue, not a tolerance: across all 16 attempts x both depths, every | ||
| 6213 | + // 10-bit attempt that reached a superblock-level rect strip found it | ||
| 6214 | + // NON-skip, so it stops at "a non-skip rectangular (HORZ/VERT/HORZ_B) | ||
| 6215 | + // strip needs rectangular residual coding". The 10-bit twin below is | ||
| 6216 | + // `#[ignore]`d with that exact reason rather than deleted or weakened. | ||
| 6217 | + for bit_depth in [8u32] { | ||
| 6218 | + let (mut named_refusals, mut matched, mut out_of_scope, mut oos_mismatch) = | ||
| 6219 | + (0u32, 0u32, 0u32, 0u32); | ||
| 6220 | + let (mut horz_proved, mut vert_proved) = (0usize, 0usize); | ||
| 6221 | + for attempt in 0..16u32 { | ||
| 6222 | + // Two orientations (the transposed pair a one-sided gate could | ||
| 6223 | + // never separate) x four quantisers x two motion steps: which | ||
| 6224 | + // superblock the RD hands a skip-able rect strip moves with | ||
| 6225 | + // the quantiser, and the 10-bit arm needs a different corner | ||
| 6226 | + // of the grid from the 8-bit one. | ||
| 6227 | + let vertical_split = attempt % 2 == 1; | ||
| 6228 | + let cq = [58, 52, 45, 61][(attempt / 2 % 4) as usize]; | ||
| 6229 | + let sp = 8 + (attempt / 8) * 4; | ||
| 6230 | + let geq = if vertical_split { | ||
| 6231 | + format!("if(lt(Y,64), 40+mod(floor((X+N*{sp})/32)*90,200), 200)") | ||
| 6232 | + } else { | ||
| 6233 | + format!("if(lt(X,64), 40+mod(floor((Y+N*{sp})/32)*90,200), 200)") | ||
| 6234 | + }; | ||
| 6235 | + let duration = frame_count as f64 / 25.0; | ||
| 6236 | + let source = format!( | ||
| 6237 | + "color=c=gray:s={width}x{height}:d={duration}:r=25,format=gray,\ | ||
| 6238 | + geq=lum='{geq}',format=yuv420p" | ||
| 6239 | + ); | ||
| 6240 | + let pix_fmt = if bit_depth == 10 { "yuv420p10le" } else { "yuv420p" }; | ||
| 6241 | + let y4m = Command::new("ffmpeg") | ||
| 6242 | + .args([ | ||
| 6243 | + "-v", "error", "-f", "lavfi", "-i", &source, "-t", &duration.to_string(), | ||
| 6244 | + "-pix_fmt", pix_fmt, "-strict", "-1", "-f", "yuv4mpegpipe", "-", | ||
| 6245 | + ]) | ||
| 6246 | + .stdin(Stdio::null()) | ||
| 6247 | + .stdout(Stdio::piped()) | ||
| 6248 | + .stderr(Stdio::piped()) | ||
| 6249 | + .output() | ||
| 6250 | + .expect("ffmpeg failed to run"); | ||
| 6251 | + assert!( | ||
| 6252 | + y4m.status.success(), | ||
| 6253 | + "{NAME}: ffmpeg refused the {bit_depth}-bit fixture: {}", | ||
| 6254 | + String::from_utf8_lossy(&y4m.stderr) | ||
| 6255 | + ); | ||
| 6256 | + let cq_arg = format!("--cq-level={cq}"); | ||
| 6257 | + let depth_arg = format!("--bit-depth={bit_depth}"); | ||
| 6258 | + let input_depth_arg = format!("--input-bit-depth={bit_depth}"); | ||
| 6259 | + let args: Vec<&str> = vec![ | ||
| 6260 | + "--codec=av1", "--passes=1", "--end-usage=q", &cq_arg, "--cpu-used=0", | ||
| 6261 | + "--threads=1", "--row-mt=0", "--sb-size=64", &depth_arg, &input_depth_arg, | ||
| 6262 | + "--enable-restoration=0", "--enable-palette=0", "--deltaq-mode=0", | ||
| 6263 | + "--enable-filter-intra=0", "--enable-cfl-intra=0", "--enable-intrabc=0", | ||
| 6264 | + "--enable-tx-size-search=0", "--lag-in-frames=0", | ||
| 6265 | + // Per-arm overrides go LAST: aomenc keeps the last | ||
| 6266 | + // occurrence of a repeated --enable-* flag. | ||
| 6267 | + "--enable-rect-partitions=1", "--enable-ab-partitions=0", | ||
| 6268 | + "--enable-1to4-partitions=1", "--min-partition-size=32", | ||
| 6269 | + "--max-partition-size=64", | ||
| 6270 | + "--obu", "-o", "-", "-", | ||
| 6271 | + ]; | ||
| 6272 | + let mut child = Command::new(aomenc_path()) | ||
| 6273 | + .args(&args) | ||
| 6274 | + .stdin(Stdio::piped()) | ||
| 6275 | + .stdout(Stdio::piped()) | ||
| 6276 | + .stderr(Stdio::piped()) | ||
| 6277 | + .spawn() | ||
| 6278 | + .expect("aomenc failed to start"); | ||
| 6279 | + child | ||
| 6280 | + .stdin | ||
| 6281 | + .take() | ||
| 6282 | + .expect("aomenc stdin") | ||
| 6283 | + .write_all(&y4m.stdout) | ||
| 6284 | + .expect("writing y4m to aomenc"); | ||
| 6285 | + let out = child.wait_with_output().expect("aomenc failed to run"); | ||
| 6286 | + assert!( | ||
| 6287 | + out.status.success(), | ||
| 6288 | + "aomenc refused the fixture: {}", | ||
| 6289 | + String::from_utf8_lossy(&out.stderr) | ||
| 6290 | + ); | ||
| 6291 | + let stream = out.stdout; | ||
| 6292 | + let before = crate::stream::inter_rect_counters(); | ||
| 6293 | + let frames = match decode_stream(&stream) { | ||
| 6294 | + Err(e) => { | ||
| 6295 | + let msg = e.to_string(); | ||
| 6296 | + assert!( | ||
| 6297 | + msg.contains("unsupported"), | ||
| 6298 | + "{NAME} failed outright, not a named refusal ({bit_depth}-bit, \ | ||
| 6299 | + attempt {attempt}): {msg}" | ||
| 6300 | + ); | ||
| 6301 | + named_refusals += 1; | ||
| 6302 | + eprintln!("{bit_depth}-bit attempt {attempt} refusal: {msg}"); | ||
| 6303 | + continue; | ||
| 6304 | + } | ||
| 6305 | + Ok(frames) => frames, | ||
| 6306 | + }; | ||
| 6307 | + let after = crate::stream::inter_rect_counters(); | ||
| 6308 | + let (horz, vert) = (after.2 - before.2, after.3 - before.3); | ||
| 6309 | + let ffmpeg_frames = if bit_depth == 10 { | ||
| 6310 | + ffmpeg_decode_sequence_10bit(&stream, width, height, frame_count) | ||
| 6311 | + } else { | ||
| 6312 | + ffmpeg_decode_sequence(&stream, width, height, frame_count) | ||
| 6313 | + }; | ||
| 6314 | + assert_eq!(frames.len(), frame_count); | ||
| 6315 | + let mismatched = frames | ||
| 6316 | + .iter() | ||
| 6317 | + .zip(&ffmpeg_frames) | ||
| 6318 | + .any(|(got, want)| got.y != want.y || got.u != want.u || got.v != want.v); | ||
| 6319 | + if horz + vert == 0 { | ||
| 6320 | + out_of_scope += 1; | ||
| 6321 | + if mismatched { | ||
| 6322 | + oos_mismatch += 1; | ||
| 6323 | + eprintln!( | ||
| 6324 | + "{NAME}: {bit_depth}-bit attempt {attempt} MISMATCHES with zero \ | ||
| 6325 | + superblock-level inter rect strips -- another shape's defect" | ||
| 6326 | + ); | ||
| 6327 | + } | ||
| 6328 | + continue; | ||
| 6329 | + } | ||
| 6330 | + for (i, (got, want)) in frames.iter().zip(&ffmpeg_frames).enumerate() { | ||
| 6331 | + assert_eq!(got.y, want.y, "{NAME} frame {i} luma vs ffmpeg (attempt {attempt}, {bit_depth}-bit)"); | ||
| 6332 | + assert_eq!(got.u, want.u, "{NAME} frame {i} U vs ffmpeg (attempt {attempt}, {bit_depth}-bit)"); | ||
| 6333 | + assert_eq!(got.v, want.v, "{NAME} frame {i} V vs ffmpeg (attempt {attempt}, {bit_depth}-bit)"); | ||
| 6334 | + } | ||
| 6335 | + horz_proved += horz; | ||
| 6336 | + vert_proved += vert; | ||
| 6337 | + matched += 1; | ||
| 6338 | + } | ||
| 6339 | + eprintln!( | ||
| 6340 | + "{NAME} ({bit_depth}-bit): {named_refusals} named refusals, {matched} pixel-exact \ | ||
| 6341 | + attempts carrying the arm, 64x32 strips={horz_proved}, 32x64 strips={vert_proved}, \ | ||
| 6342 | + {out_of_scope} attempts carried none ({oos_mismatch} of them mismatched)" | ||
| 6343 | + ); | ||
| 6344 | + assert_eq!( | ||
| 6345 | + oos_mismatch, 0, | ||
| 6346 | + "{NAME}: {oos_mismatch} attempt(s) with no superblock-level inter rect strip \ | ||
| 6347 | + decoded but mismatched ffmpeg -- a defect of another shape, not a pass" | ||
| 6348 | + ); | ||
| 6349 | + assert!( | ||
| 6350 | + horz_proved + vert_proved > 0, | ||
| 6351 | + "{NAME} ({bit_depth}-bit): the superblock-level inter rect arm never fired \ | ||
| 6352 | + inside a pixel-exact attempt (horz={horz_proved}, vert={vert_proved}, \ | ||
| 6353 | + {named_refusals} refusals, {out_of_scope} out of scope) -- gate proved nothing" | ||
| 6354 | + ); | ||
| 6355 | + } | ||
| 6356 | + } | ||
| 6357 | + | ||
| 6358 | + /// lane-inter4 r2: the 32x32-level inter `PARTITION_HORZ`/`PARTITION_VERT` | ||
| 6359 | + /// strips (32x16 / 16x32) carrying a REAL residual -- the capability r1 | ||
| 6360 | + /// found missing ("a non-skip rectangular (HORZ/VERT/HORZ_B) strip needs | ||
| 6361 | + /// rectangular residual coding"). The strip's own rectangular max | ||
| 6362 | + /// transform (`TX_32X16`/`TX_16X32`) is read through the rect var-tx tree, | ||
| 6363 | + /// its coefficients through [`TxbSet::LumaRect32x16Inter`] / | ||
| 6364 | + /// `ChromaRect16x8`, and inverted with the rect (sqrt2-scaled) inverse | ||
| 6365 | + /// transform. | ||
| 6366 | + /// | ||
| 6367 | + /// `--min-partition-size=16 --max-partition-size=32` keeps the superblock | ||
| 6368 | + /// level (64x32, still refused -- no 64-point rect transform) out, so | ||
| 6369 | + /// every counted hit is a 32-level strip. The source is textured and | ||
| 6370 | + /// translating precisely so the strips are NOT skip: a flat source (r1's) | ||
| 6371 | + /// makes aomenc code them skip and proves nothing about the residual. | ||
| 6372 | + /// Both `--enable-tx-size-search` arms run: `=0` exercises the | ||
| 6373 | + /// whole-block rect transform with no `txfm_partition` symbol at all, | ||
| 6374 | + /// `=1` the rect var-tx tree (no-split rect unit, or the split into square | ||
| 6375 | + /// sub-transforms). | ||
| 6376 | + /// | ||
| 6377 | + /// 8-bit AND 10-bit. Every decoded frame is compared to ffmpeg on Y, U and | ||
| 6378 | + /// V; a refusal is counted, never SKIPped; an attempt that carried no rect | ||
| 6379 | + /// inter residual is counted separately and still required pixel-exact. | ||
| 6380 | + /// Temporal (MFMV) motion-vector candidates, on a real aomenc stream | ||
| 6381 | + /// whose compound blocks feed the next frame's motion field | ||
| 6382 | + /// (`av1_copy_frame_mvs` -> `av1_setup_motion_field` -> `add_tpl_ref_mv`). | ||
| 6383 | + /// | ||
| 6384 | + /// lane-interbis r1 pinned this recipe because it is the one the rect | ||
| 6385 | + /// gate's attempt 1 decoded FULLY and still mismatched ffmpeg (a | ||
| 6386 | + /// 32x32 NEARESTMV block at mi (24, 40) of decode-order frame 5 took its | ||
| 6387 | + /// nearest candidate from a temporal cell holding the wrong reference: | ||
| 6388 | + /// `build_motion_field` stored a compound block's FIRST reference where | ||
| 6389 | + /// libaom stores its second). Every fully decoded attempt is compared | ||
| 6390 | + /// plane by plane; a refusal is counted, never SKIPped; the temporal | ||
| 6391 | + /// candidate counter must fire on a compared attempt, or the gate proves | ||
| 6392 | + /// nothing. | ||
| 6393 | + #[test] | ||
| 6394 | + fn a_real_aomenc_inter_sequence_with_temporal_mv_candidates_decodes_pixel_exact() { | ||
| 6395 | + const NAME: &str = | ||
| 6396 | + "a_real_aomenc_inter_sequence_with_temporal_mv_candidates_decodes_pixel_exact"; | ||
| 6397 | + let _gate_lock = lock_gate_counters(); | ||
| 6398 | + if !have_ffmpeg() { | ||
| 6399 | + eprintln!("SKIP {NAME}: no ffmpeg"); | ||
| 6400 | + return; | ||
| 6401 | + } | ||
| 6402 | + if !have_aomenc() { | ||
| 6403 | + eprintln!("SKIP {NAME}: no aomenc at {}", aomenc_path().display()); | ||
| 6404 | + return; | ||
| 6405 | + } | ||
| 6406 | + let (width, height, frame_count) = (192usize, 128usize, 6usize); | ||
| 6407 | + for bit_depth in [8u32, 10u32] { | ||
| 6408 | + let (mut named_refusals, mut compared, mut tmv_proved) = (0u32, 0u32, 0usize); | ||
| 6409 | + for attempt in 0..2u32 { | ||
| 6410 | + let tx_search = if attempt == 0 { "0" } else { "1" }; | ||
| 6411 | + let duration = frame_count as f64 / 25.0; | ||
| 6412 | + // The pinned source: horizontal structure translating along X | ||
| 6413 | + // at 3 px/frame, which makes aomenc code compound LAST+GOLDEN | ||
| 6414 | + // blocks whose stored motion field the last frame reads back. | ||
| 6415 | + let source = format!( | ||
| 6416 | + "color=c=gray:s={width}x{height}:d={duration}:r=25,format=gray,\ | ||
| 6417 | + geq=lum='128+58*sin((X+N*3)/6)+18*sin(Y/23)',format=yuv420p" | ||
| 6418 | + ); | ||
| 6419 | + let pix_fmt = if bit_depth == 10 { "yuv420p10le" } else { "yuv420p" }; | ||
| 6420 | + let y4m = Command::new("ffmpeg") | ||
| 6421 | + .args([ | ||
| 6422 | + "-v", "error", "-f", "lavfi", "-i", &source, "-t", &duration.to_string(), | ||
| 6423 | + "-pix_fmt", pix_fmt, "-strict", "-1", "-f", "yuv4mpegpipe", "-", | ||
| 6424 | + ]) | ||
| 6425 | + .stdin(Stdio::null()) | ||
| 6426 | + .stdout(Stdio::piped()) | ||
| 6427 | + .stderr(Stdio::piped()) | ||
| 6428 | + .output() | ||
| 6429 | + .expect("ffmpeg failed to run"); | ||
| 6430 | + assert!( | ||
| 6431 | + y4m.status.success(), | ||
| 6432 | + "{NAME}: ffmpeg refused the {bit_depth}-bit fixture: {}", | ||
| 6433 | + String::from_utf8_lossy(&y4m.stderr) | ||
| 6434 | + ); | ||
| 6435 | + let depth_arg = format!("--bit-depth={bit_depth}"); | ||
| 6436 | + let input_depth_arg = format!("--input-bit-depth={bit_depth}"); | ||
| 6437 | + let tx_arg = format!("--enable-tx-size-search={tx_search}"); | ||
| 6438 | + let args: Vec<&str> = vec![ | ||
| 6439 | + "--codec=av1", "--passes=1", "--end-usage=q", "--cq-level=34", "--cpu-used=0", | ||
| 6440 | + "--threads=1", "--row-mt=0", "--sb-size=64", &depth_arg, &input_depth_arg, | ||
| 6441 | + "--enable-restoration=0", "--enable-palette=0", "--deltaq-mode=0", | ||
| 6442 | + "--enable-filter-intra=0", "--enable-cfl-intra=0", "--enable-intrabc=0", | ||
| 6443 | + "--lag-in-frames=0", | ||
| 6444 | + // Per-arm overrides go LAST (aomenc keeps the last | ||
| 6445 | + // occurrence of a repeated --enable-* flag). | ||
| 6446 | + &tx_arg, | ||
| 6447 | + "--enable-rect-partitions=1", "--enable-ab-partitions=0", | ||
| 6448 | + "--enable-1to4-partitions=0", "--min-partition-size=16", | ||
| 6449 | + "--max-partition-size=32", | ||
| 6450 | + "--obu", "-o", "-", "-", | ||
| 6451 | + ]; | ||
| 6452 | + let mut child = Command::new(aomenc_path()) | ||
| 6453 | + .args(&args) | ||
| 6454 | + .stdin(Stdio::piped()) | ||
| 6455 | + .stdout(Stdio::piped()) | ||
| 6456 | + .stderr(Stdio::piped()) | ||
| 6457 | + .spawn() | ||
| 6458 | + .expect("aomenc failed to start"); | ||
| 6459 | + child | ||
| 6460 | + .stdin | ||
| 6461 | + .take() | ||
| 6462 | + .expect("aomenc stdin") | ||
| 6463 | + .write_all(&y4m.stdout) | ||
| 6464 | + .expect("writing y4m to aomenc"); | ||
| 6465 | + let out = child.wait_with_output().expect("aomenc failed to run"); | ||
| 6466 | + assert!( | ||
| 6467 | + out.status.success(), | ||
| 6468 | + "aomenc refused the fixture: {}", | ||
| 6469 | + String::from_utf8_lossy(&out.stderr) | ||
| 6470 | + ); | ||
| 6471 | + let stream = out.stdout; | ||
| 6472 | + let before = decode::tmv_hits(); | ||
| 6473 | + let frames = match decode_stream(&stream) { | ||
| 6474 | + Err(e) => { | ||
| 6475 | + let msg = e.to_string(); | ||
| 6476 | + assert!( | ||
| 6477 | + msg.contains("unsupported"), | ||
| 6478 | + "{NAME} failed outright, not a named refusal ({bit_depth}-bit, \ | ||
| 6479 | + attempt {attempt}): {msg}" | ||
| 6480 | + ); | ||
| 6481 | + named_refusals += 1; | ||
| 6482 | + eprintln!("{bit_depth}-bit attempt {attempt} refusal: {msg}"); | ||
| 6483 | + continue; | ||
| 6484 | + } | ||
| 6485 | + Ok(frames) => frames, | ||
| 6486 | + }; | ||
| 6487 | + let tmv = decode::tmv_hits() - before; | ||
| 6488 | + let ffmpeg_frames = if bit_depth == 10 { | ||
| 6489 | + ffmpeg_decode_sequence_10bit(&stream, width, height, frame_count) | ||
| 6490 | + } else { | ||
| 6491 | + ffmpeg_decode_sequence(&stream, width, height, frame_count) | ||
| 6492 | + }; | ||
| 6493 | + assert_eq!(frames.len(), frame_count); | ||
| 6494 | + for (i, (got, want)) in frames.iter().zip(&ffmpeg_frames).enumerate() { | ||
| 6495 | + assert_eq!(got.y, want.y, "{NAME} frame {i} luma vs ffmpeg (attempt {attempt}, {bit_depth}-bit)"); | ||
| 6496 | + assert_eq!(got.u, want.u, "{NAME} frame {i} U vs ffmpeg (attempt {attempt}, {bit_depth}-bit)"); | ||
| 6497 | + assert_eq!(got.v, want.v, "{NAME} frame {i} V vs ffmpeg (attempt {attempt}, {bit_depth}-bit)"); | ||
| 6498 | + } | ||
| 6499 | + compared += 1; | ||
| 6500 | + tmv_proved += tmv; | ||
| 6501 | + } | ||
| 6502 | + eprintln!( | ||
| 6503 | + "{NAME} ({bit_depth}-bit): {named_refusals} named refusals, {compared} \ | ||
| 6504 | + pixel-exact attempts, blocks with a temporal MV candidate={tmv_proved}" | ||
| 6505 | + ); | ||
| 6506 | + assert!( | ||
| 6507 | + compared > 0, | ||
| 6508 | + "{NAME} ({bit_depth}-bit): every attempt refused -- gate proved nothing" | ||
| 6509 | + ); | ||
| 6510 | + assert!( | ||
| 6511 | + tmv_proved > 0, | ||
| 6512 | + "{NAME} ({bit_depth}-bit): no compared attempt ever folded a temporal MV \ | ||
| 6513 | + candidate into a block's stack -- gate proved nothing" | ||
| 6514 | + ); | ||
| 6515 | + } | ||
| 6516 | + } | ||
| 6517 | + | ||
| 6518 | + /// lane-refstamp r1: `av1_setup_motion_field`'s `ref_stamp` budget in the | ||
| 6519 | + /// presence of FORWARD KEY FRAMES (`--enable-fwd-kf=1`), which is the only | ||
| 6520 | + /// configuration where a *forward* reference slot (BWDREF/ALTREF2/ALTREF) | ||
| 6521 | + /// holds a key frame while temporal MV projection runs. libaom's | ||
| 6522 | + /// `motion_field_projection` returns 0 for such a start frame, so it costs | ||
| 6523 | + /// no `ref_stamp`; ours used to project the (empty) field and report | ||
| 6524 | + /// success, spending the slot ALTREF/LAST2 should have had and losing | ||
| 6525 | + /// their temporal candidates. | ||
| 6526 | + /// | ||
| 6527 | + /// Both bit depths; EVERY decoded frame (including the hidden alt-refs) | ||
| 6528 | + /// compared to the oracle in decode order; a refusal is counted, never | ||
| 6529 | + /// SKIPped. Two hard counters make the gate non-vacuous: frames that | ||
| 6530 | + /// actually took the >=2-intra-forward-refs `ref_stamp` path, and blocks | ||
| 6531 | + /// that folded a temporal MV candidate into their stack. | ||
| 6532 | + #[test] | ||
| 6533 | + fn a_real_aomenc_inter_sequence_with_forward_keyframes_and_temporal_mvs_decodes_pixel_exact() { | ||
| 6534 | + const NAME: &str = "a_real_aomenc_inter_sequence_with_forward_keyframes_and_temporal_mvs_decodes_pixel_exact"; | ||
| 6535 | + let _gate_lock = lock_gate_counters(); | ||
| 6536 | + if !have_ffmpeg() { | ||
| 6537 | + eprintln!("SKIP {NAME}: no ffmpeg"); | ||
| 6538 | + return; | ||
| 6539 | + } | ||
| 6540 | + if !have_aomenc() { | ||
| 6541 | + eprintln!("SKIP {NAME}: no aomenc at {}", aomenc_path().display()); | ||
| 6542 | + return; | ||
| 6543 | + } | ||
| 6544 | + let (width, height, frame_count) = (192usize, 128usize, 24usize); | ||
| 6545 | + for bit_depth in [8u32, 10u32] { | ||
| 6546 | + let (mut named_refusals, mut compared, mut tmv_proved, mut stamp_proved) = | ||
| 6547 | + (0u32, 0u32, 0usize, 0usize); | ||
| 6548 | + let mut stamp2_proved = 0usize; | ||
| 6549 | + for attempt in 0..2u32 { | ||
| 6550 | + let duration = frame_count as f64 / 25.0; | ||
| 6551 | + // Natural-ish motion: structure translating along X at 3 px per | ||
| 6552 | + // frame plus a slow vertical drift, the source family the | ||
| 6553 | + // temporal-MV gate already decodes fully. | ||
| 6554 | + let source = format!( | ||
| 6555 | + "color=c=gray:s={width}x{height}:d={duration}:r=25,format=gray,\ | ||
| 6556 | + geq=lum='128+58*sin((X+N*3)/6)+18*sin((Y+N*2)/23)',format=yuv420p" | ||
| 6557 | + ); | ||
| 6558 | + let pix_fmt = if bit_depth == 10 { "yuv420p10le" } else { "yuv420p" }; | ||
| 6559 | + let y4m = Command::new("ffmpeg") | ||
| 6560 | + .args([ | ||
| 6561 | + "-v", "error", "-f", "lavfi", "-i", &source, "-t", &duration.to_string(), | ||
| 6562 | + "-pix_fmt", pix_fmt, "-strict", "-1", "-f", "yuv4mpegpipe", "-", | ||
| 6563 | + ]) | ||
| 6564 | + .stdin(Stdio::null()) | ||
| 6565 | + .stdout(Stdio::piped()) | ||
| 6566 | + .stderr(Stdio::piped()) | ||
| 6567 | + .output() | ||
| 6568 | + .expect("ffmpeg failed to run"); | ||
| 6569 | + assert!( | ||
| 6570 | + y4m.status.success(), | ||
| 6571 | + "{NAME}: ffmpeg refused the {bit_depth}-bit fixture: {}", | ||
| 6572 | + String::from_utf8_lossy(&y4m.stderr) | ||
| 6573 | + ); | ||
| 6574 | + let depth_arg = format!("--bit-depth={bit_depth}"); | ||
| 6575 | + let input_depth_arg = format!("--input-bit-depth={bit_depth}"); | ||
| 6576 | + let cq_arg = format!("--cq-level={}", if attempt == 0 { 34 } else { 45 }); | ||
| 6577 | + let args: Vec<&str> = vec![ | ||
| 6578 | + "--codec=av1", "--passes=1", "--end-usage=q", &cq_arg, "--cpu-used=0", | ||
| 6579 | + "--threads=1", "--row-mt=0", "--sb-size=64", &depth_arg, &input_depth_arg, | ||
| 6580 | + "--enable-restoration=0", "--enable-palette=0", "--deltaq-mode=0", | ||
| 6581 | + "--enable-filter-intra=0", "--enable-cfl-intra=0", "--enable-intrabc=0", | ||
| 6582 | + "--enable-rect-partitions=1", "--enable-ab-partitions=0", | ||
| 6583 | + "--enable-1to4-partitions=0", "--min-partition-size=16", | ||
| 6584 | + "--max-partition-size=32", | ||
| 6585 | + // Per-arm/feature overrides go LAST (aomenc keeps the LAST | ||
| 6586 | + // occurrence of a repeated --enable-* flag). | ||
| 6587 | + "--enable-order-hint=1", "--enable-ref-frame-mvs=1", | ||
| 6588 | + "--enable-fwd-kf=1", "--fwd-kf-dist=8", "--kf-max-dist=1000", | ||
| 6589 | + "--lag-in-frames=16", "--auto-alt-ref=1", "--arnr-maxframes=0", | ||
| 6590 | + "--obu", "-o", "-", "-", | ||
| 6591 | + ]; | ||
| 6592 | + let mut child = Command::new(aomenc_path()) | ||
| 6593 | + .args(&args) | ||
| 6594 | + .stdin(Stdio::piped()) | ||
| 6595 | + .stdout(Stdio::piped()) | ||
| 6596 | + .stderr(Stdio::piped()) | ||
| 6597 | + .spawn() | ||
| 6598 | + .expect("aomenc failed to start"); | ||
| 6599 | + child | ||
| 6600 | + .stdin | ||
| 6601 | + .take() | ||
| 6602 | + .expect("aomenc stdin") | ||
| 6603 | + .write_all(&y4m.stdout) | ||
| 6604 | + .expect("writing y4m to aomenc"); | ||
| 6605 | + let out = child.wait_with_output().expect("aomenc failed to run"); | ||
| 6606 | + assert!( | ||
| 6607 | + out.status.success(), | ||
| 6608 | + "aomenc refused the fixture: {}", | ||
| 6609 | + String::from_utf8_lossy(&out.stderr) | ||
| 6610 | + ); | ||
| 6611 | + let stream = out.stdout; | ||
| 6612 | + let before_tmv = decode::tmv_hits(); | ||
| 6613 | + let before_stamp = crate::motion_field::refstamp_intra_frames(); | ||
| 6614 | + if let Err(e) = decode_stream(&stream) { | ||
| 6615 | + let msg = e.to_string(); | ||
| 6616 | + assert!( | ||
| 6617 | + msg.contains("unsupported"), | ||
| 6618 | + "{NAME} failed outright, not a named refusal ({bit_depth}-bit, \ | ||
| 6619 | + attempt {attempt}): {msg}" | ||
| 6620 | + ); | ||
| 6621 | + named_refusals += 1; | ||
| 6622 | + eprintln!("{bit_depth}-bit attempt {attempt} refusal: {msg}"); | ||
| 6623 | + continue; | ||
| 6624 | + } | ||
| 6625 | + let tmv = decode::tmv_hits() - before_tmv; | ||
| 6626 | + let stamp = crate::motion_field::refstamp_intra_frames().0 - before_stamp.0; | ||
| 6627 | + let stamp2 = crate::motion_field::refstamp_intra_frames().1 - before_stamp.1; | ||
| 6628 | + // Every frame, hidden ones included, compared in DECODE order. | ||
| 6629 | + let (total, hidden) = decode_all_frames_vs_oracle( | ||
| 6630 | + &stream, | ||
| 6631 | + &format!("{NAME}-{bit_depth}bit-attempt{attempt}"), | ||
| 6632 | + ); | ||
| 6633 | + eprintln!( | ||
| 6634 | + "{NAME} ({bit_depth}-bit attempt {attempt}): {total} frames decoded \ | ||
| 6635 | + ({hidden} hidden), temporal candidates={tmv}, frames with a key/intra \ | ||
| 6636 | + forward ref={stamp} (two or more: {stamp2})" | ||
| 6637 | + ); | ||
| 6638 | + compared += 1; | ||
| 6639 | + tmv_proved += tmv; | ||
| 6640 | + stamp_proved += stamp; | ||
| 6641 | + stamp2_proved += stamp2; | ||
| 6642 | + } | ||
| 6643 | + assert!( | ||
| 6644 | + compared > 0, | ||
| 6645 | + "{NAME} ({bit_depth}-bit): every attempt refused ({named_refusals}) -- gate \ | ||
| 6646 | + proved nothing" | ||
| 6647 | + ); | ||
| 6648 | + assert!( | ||
| 6649 | + tmv_proved > 0, | ||
| 6650 | + "{NAME} ({bit_depth}-bit): no compared attempt folded a temporal MV candidate \ | ||
| 6651 | + into a block's stack -- gate proved nothing" | ||
| 6652 | + ); | ||
| 6653 | + assert!( | ||
| 6654 | + stamp_proved > 0, | ||
| 6655 | + "{NAME} ({bit_depth}-bit): no compared attempt ever had a forward reference \ | ||
| 6656 | + holding a key/intra frame ({stamp2_proved} frames had two) -- the ref_stamp \ | ||
| 6657 | + path this gate exists for never ran" | ||
| 6658 | + ); | ||
| 5627 | } | 6659 | } |
| 5628 | - panic!("{name}: no attempt fired a class-1 chroma eob: {refusals:?}"); | ||
| 5629 | } | 6660 | } |
| 5630 | 6661 | ||
| 5631 | #[test] | 6662 | #[test] |
| 5632 | - fn a_real_aomenc_inter_sequence_with_a_class1_chroma_eob_decodes_pixel_exact() { | 6663 | + // lane-inter4 r2: RED, kept (not weakened, not deleted) -- the rect inter |
| 5633 | - chroma_class1_eob_gate( | 6664 | + // residual path IS implemented and reached, but no aomenc recipe swept |
| 5634 | - "a_real_aomenc_inter_sequence_with_a_class1_chroma_eob_decodes_pixel_exact", | 6665 | + // this round produced a stream whose FIRST rect inter block is a 32x16 / |
| 5635 | - false, | 6666 | + // 16x32 one: real motion content always codes a 16x8/8x16 inter leaf (or |
| 5636 | - ); | 6667 | + // an intra rect strip) earlier in the tile, and both of those still refuse |
| 6668 | + // by name, so the decode stops before any 32-level 2:1 strip. The 16x8 | ||
| 6669 | + // shape additionally needs `default_inter_ext_tx_cdf[2][TX_8X8]` (the | ||
| 6670 | + // 12-symbol DTT9_IDTX_1DDCT row, only reachable through a rect | ||
| 6671 | + // transform), which this round did not add. See lanes/inter4-r2.report.md. | ||
| 6672 | + // lane-inter4 r4 re-measured after the 16-level rect inter leaf shipped | ||
| 6673 | + // (r3): STILL RED, and the blocker moved -- 12 named refusals over 16 | ||
| 6674 | + // 8-bit attempts, 10 of them "an intra-coded HORZ/VERT strip needs | ||
| 6675 | + // rectangular intra prediction this decoder does not code yet" and 2 the | ||
| 6676 | + // 16-level AB/1:4 inter refusal; 4 attempts decoded with no rect inter | ||
| 6677 | + // residual at all and none of them mismatched (tu=0, split=0). Neither | ||
| 6678 | + // remaining blocker is this lane's: the gate un-ignores when the intra | ||
| 6679 | + // rect strip lands. | ||
| 6680 | + #[ignore = "lane-inter4 r4 (re-measured): 12/16 8-bit attempts stop at the intra-rect-strip (10) or 16-level inter AB/1:4 (2) refusal, the other 4 code no rect inter residual -- tu=0, split=0; blocked on rectangular INTRA prediction, not on this lane"] | ||
| 6681 | + fn a_real_aomenc_inter_sequence_with_a_coded_rectangular_residual_decodes_pixel_exact() { | ||
| 6682 | + const NAME: &str = | ||
| 6683 | + "a_real_aomenc_inter_sequence_with_a_coded_rectangular_residual_decodes_pixel_exact"; | ||
| 6684 | + let _gate_lock = lock_gate_counters(); | ||
| 6685 | + if !have_ffmpeg() { | ||
| 6686 | + eprintln!("SKIP {NAME}: no ffmpeg"); | ||
| 6687 | + return; | ||
| 6688 | + } | ||
| 6689 | + if !have_aomenc() { | ||
| 6690 | + eprintln!("SKIP {NAME}: no aomenc at {}", aomenc_path().display()); | ||
| 6691 | + return; | ||
| 6692 | + } | ||
| 6693 | + let (width, height, frame_count) = (192usize, 128usize, 6usize); | ||
| 6694 | + for bit_depth in [8u32, 10u32] { | ||
| 6695 | + let (mut named_refusals, mut matched, mut out_of_scope, mut oos_mismatch) = | ||
| 6696 | + (0u32, 0u32, 0u32, 0u32); | ||
| 6697 | + let (mut tu_proved, mut split_proved) = (0usize, 0usize); | ||
| 6698 | + for attempt in 0..16u32 { | ||
| 6699 | + // Two sources (a translating textured ramp, and testsrc2's | ||
| 6700 | + // natural motion) x two quantisers x two tx-size-search arms x | ||
| 6701 | + // two motion steps. | ||
| 6702 | + let tx_search = if attempt % 2 == 0 { "0" } else { "1" }; | ||
| 6703 | + let cq = [34, 22][(attempt / 2 % 2) as usize]; | ||
| 6704 | + let natural = attempt / 4 % 2 == 1; | ||
| 6705 | + let sp = 3 + (attempt / 8) * 5; | ||
| 6706 | + let duration = frame_count as f64 / 25.0; | ||
| 6707 | + // Continuous-tone, mid-frequency, translating: a flat or | ||
| 6708 | + // banded source makes aomenc code the strips `skip` (r1's | ||
| 6709 | + // gate) and its screen-content detector fires on the | ||
| 6710 | + // synthetic ramps, stopping the decode at an unrelated intra | ||
| 6711 | + // refusal long before any inter strip. | ||
| 6712 | + // Structure ALONG one axis is what makes aomenc's RD pick a | ||
| 6713 | + // 2:1 rect partition on that axis: horizontal bands drifting | ||
| 6714 | + // vertically favour PARTITION_HORZ (32x16 strips), the | ||
| 6715 | + // transposed source PARTITION_VERT (16x32). | ||
| 6716 | + let lum = if natural { | ||
| 6717 | + format!("128+58*sin((Y+N*{sp})/6)+18*sin(X/23)") | ||
| 6718 | + } else { | ||
| 6719 | + format!("128+58*sin((X+N*{sp})/6)+18*sin(Y/23)") | ||
| 6720 | + }; | ||
| 6721 | + let source = format!( | ||
| 6722 | + "color=c=gray:s={width}x{height}:d={duration}:r=25,format=gray,\ | ||
| 6723 | + geq=lum='{lum}',format=yuv420p" | ||
| 6724 | + ); | ||
| 6725 | + let pix_fmt = if bit_depth == 10 { "yuv420p10le" } else { "yuv420p" }; | ||
| 6726 | + let y4m = Command::new("ffmpeg") | ||
| 6727 | + .args([ | ||
| 6728 | + "-v", "error", "-f", "lavfi", "-i", &source, "-t", &duration.to_string(), | ||
| 6729 | + "-pix_fmt", pix_fmt, "-strict", "-1", "-f", "yuv4mpegpipe", "-", | ||
| 6730 | + ]) | ||
| 6731 | + .stdin(Stdio::null()) | ||
| 6732 | + .stdout(Stdio::piped()) | ||
| 6733 | + .stderr(Stdio::piped()) | ||
| 6734 | + .output() | ||
| 6735 | + .expect("ffmpeg failed to run"); | ||
| 6736 | + assert!( | ||
| 6737 | + y4m.status.success(), | ||
| 6738 | + "{NAME}: ffmpeg refused the {bit_depth}-bit fixture: {}", | ||
| 6739 | + String::from_utf8_lossy(&y4m.stderr) | ||
| 6740 | + ); | ||
| 6741 | + let cq_arg = format!("--cq-level={cq}"); | ||
| 6742 | + let depth_arg = format!("--bit-depth={bit_depth}"); | ||
| 6743 | + let input_depth_arg = format!("--input-bit-depth={bit_depth}"); | ||
| 6744 | + let tx_arg = format!("--enable-tx-size-search={tx_search}"); | ||
| 6745 | + let args: Vec<&str> = vec![ | ||
| 6746 | + "--codec=av1", "--passes=1", "--end-usage=q", &cq_arg, "--cpu-used=0", | ||
| 6747 | + "--threads=1", "--row-mt=0", "--sb-size=64", &depth_arg, &input_depth_arg, | ||
| 6748 | + "--enable-restoration=0", "--enable-palette=0", "--deltaq-mode=0", | ||
| 6749 | + "--enable-filter-intra=0", "--enable-cfl-intra=0", "--enable-intrabc=0", | ||
| 6750 | + "--lag-in-frames=0", | ||
| 6751 | + // Per-arm overrides go LAST: aomenc keeps the last | ||
| 6752 | + // occurrence of a repeated --enable-* flag. | ||
| 6753 | + &tx_arg, | ||
| 6754 | + "--enable-rect-partitions=1", "--enable-ab-partitions=0", | ||
| 6755 | + "--enable-1to4-partitions=0", "--min-partition-size=16", | ||
| 6756 | + "--max-partition-size=32", | ||
| 6757 | + "--obu", "-o", "-", "-", | ||
| 6758 | + ]; | ||
| 6759 | + let mut child = Command::new(aomenc_path()) | ||
| 6760 | + .args(&args) | ||
| 6761 | + .stdin(Stdio::piped()) | ||
| 6762 | + .stdout(Stdio::piped()) | ||
| 6763 | + .stderr(Stdio::piped()) | ||
| 6764 | + .spawn() | ||
| 6765 | + .expect("aomenc failed to start"); | ||
| 6766 | + child | ||
| 6767 | + .stdin | ||
| 6768 | + .take() | ||
| 6769 | + .expect("aomenc stdin") | ||
| 6770 | + .write_all(&y4m.stdout) | ||
| 6771 | + .expect("writing y4m to aomenc"); | ||
| 6772 | + let out = child.wait_with_output().expect("aomenc failed to run"); | ||
| 6773 | + assert!( | ||
| 6774 | + out.status.success(), | ||
| 6775 | + "aomenc refused the fixture: {}", | ||
| 6776 | + String::from_utf8_lossy(&out.stderr) | ||
| 6777 | + ); | ||
| 6778 | + let stream = out.stdout; | ||
| 6779 | + let before = (decode::rect_inter_tu_hits(), decode::rect_inter_txsplit_hits()); | ||
| 6780 | + let frames = match decode_stream(&stream) { | ||
| 6781 | + Err(e) => { | ||
| 6782 | + let msg = e.to_string(); | ||
| 6783 | + assert!( | ||
| 6784 | + msg.contains("unsupported"), | ||
| 6785 | + "{NAME} failed outright, not a named refusal ({bit_depth}-bit, \ | ||
| 6786 | + attempt {attempt}): {msg}" | ||
| 6787 | + ); | ||
| 6788 | + named_refusals += 1; | ||
| 6789 | + eprintln!("{bit_depth}-bit attempt {attempt} refusal: {msg}"); | ||
| 6790 | + continue; | ||
| 6791 | + } | ||
| 6792 | + Ok(frames) => frames, | ||
| 6793 | + }; | ||
| 6794 | + let after = (decode::rect_inter_tu_hits(), decode::rect_inter_txsplit_hits()); | ||
| 6795 | + let (tu, split) = (after.0 - before.0, after.1 - before.1); | ||
| 6796 | + let ffmpeg_frames = if bit_depth == 10 { | ||
| 6797 | + ffmpeg_decode_sequence_10bit(&stream, width, height, frame_count) | ||
| 6798 | + } else { | ||
| 6799 | + ffmpeg_decode_sequence(&stream, width, height, frame_count) | ||
| 6800 | + }; | ||
| 6801 | + assert_eq!(frames.len(), frame_count); | ||
| 6802 | + let mismatched = frames | ||
| 6803 | + .iter() | ||
| 6804 | + .zip(&ffmpeg_frames) | ||
| 6805 | + .any(|(got, want)| got.y != want.y || got.u != want.u || got.v != want.v); | ||
| 6806 | + if tu + split == 0 { | ||
| 6807 | + out_of_scope += 1; | ||
| 6808 | + if mismatched { | ||
| 6809 | + oos_mismatch += 1; | ||
| 6810 | + eprintln!( | ||
| 6811 | + "{NAME}: {bit_depth}-bit attempt {attempt} MISMATCHES with zero \ | ||
| 6812 | + coded rect inter transform units -- another shape's defect" | ||
| 6813 | + ); | ||
| 6814 | + } | ||
| 6815 | + continue; | ||
| 6816 | + } | ||
| 6817 | + for (i, (got, want)) in frames.iter().zip(&ffmpeg_frames).enumerate() { | ||
| 6818 | + assert_eq!(got.y, want.y, "{NAME} frame {i} luma vs ffmpeg (attempt {attempt}, {bit_depth}-bit, tx_search={tx_search})"); | ||
| 6819 | + assert_eq!(got.u, want.u, "{NAME} frame {i} U vs ffmpeg (attempt {attempt}, {bit_depth}-bit, tx_search={tx_search})"); | ||
| 6820 | + assert_eq!(got.v, want.v, "{NAME} frame {i} V vs ffmpeg (attempt {attempt}, {bit_depth}-bit, tx_search={tx_search})"); | ||
| 6821 | + } | ||
| 6822 | + tu_proved += tu; | ||
| 6823 | + split_proved += split; | ||
| 6824 | + matched += 1; | ||
| 6825 | + } | ||
| 6826 | + eprintln!( | ||
| 6827 | + "{NAME} ({bit_depth}-bit): {named_refusals} named refusals, {matched} pixel-exact \ | ||
| 6828 | + attempts carrying a coded rect inter residual, whole-block rect TUs={tu_proved}, \ | ||
| 6829 | + rect trees that split={split_proved}, {out_of_scope} attempts carried none \ | ||
| 6830 | + ({oos_mismatch} of them mismatched)" | ||
| 6831 | + ); | ||
| 6832 | + assert_eq!( | ||
| 6833 | + oos_mismatch, 0, | ||
| 6834 | + "{NAME}: {oos_mismatch} attempt(s) with no coded rect inter residual decoded but \ | ||
| 6835 | + mismatched ffmpeg -- a defect of another shape, not a pass" | ||
| 6836 | + ); | ||
| 6837 | + assert!( | ||
| 6838 | + tu_proved > 0, | ||
| 6839 | + "{NAME} ({bit_depth}-bit): no pixel-exact attempt ever coded a rectangular inter \ | ||
| 6840 | + residual (tu={tu_proved}, split={split_proved}, {named_refusals} refusals, \ | ||
| 6841 | + {out_of_scope} out of scope) -- gate proved nothing" | ||
| 6842 | + ); | ||
| 6843 | + } | ||
| 5637 | } | 6844 | } |
| 5638 | 6845 | ||
| 5639 | #[test] | 6846 | #[test] |
| 5640 | - fn a_real_aomenc_10bit_inter_sequence_with_a_class1_chroma_eob_decodes_pixel_exact() { | 6847 | + // lane-inter4 r3: the 16x16-level rect INTER leaf -- PARTITION_HORZ / |
| 5641 | - chroma_class1_eob_gate( | 6848 | + // PARTITION_VERT at 16x16 on an inter frame, i.e. two 16x8 / 8x16 inter |
| 5642 | - "a_real_aomenc_10bit_inter_sequence_with_a_class1_chroma_eob_decodes_pixel_exact", | 6849 | + // blocks, mode info + rectangular residual + prediction. Every decoded |
| 5643 | - true, | 6850 | + // frame is compared Y/U/V against ffmpeg, refusals are counted and never |
| 6851 | + // SKIPped, and the gate asserts a pixel-exact attempt for BOTH axes that | ||
| 6852 | + // also coded a rectangular inter transform unit (i.e. was not `skip`). | ||
| 6853 | + fn a_real_aomenc_inter_sequence_with_a_16_level_rect_leaf_decodes_pixel_exact() { | ||
| 6854 | + const NAME: &str = | ||
| 6855 | + "a_real_aomenc_inter_sequence_with_a_16_level_rect_leaf_decodes_pixel_exact"; | ||
| 6856 | + let _gate_lock = lock_gate_counters(); | ||
| 6857 | + if !have_ffmpeg() { | ||
| 6858 | + eprintln!("SKIP {NAME}: no ffmpeg"); | ||
| 6859 | + return; | ||
| 6860 | + } | ||
| 6861 | + if !have_aomenc() { | ||
| 6862 | + eprintln!("SKIP {NAME}: no aomenc at {}", aomenc_path().display()); | ||
| 6863 | + return; | ||
| 6864 | + } | ||
| 6865 | + let (width, height, frame_count) = (192usize, 128usize, 6usize); | ||
| 6866 | + // Coded (non-skip) rect inter transform units, summed over both bit | ||
| 6867 | + // depths: at 10 bits this recipe's rect leaves all come out `skip` | ||
| 6868 | + // (measured at cq 34/22, 30/26 and 24/12 -- the lower pairs stop | ||
| 6869 | + // reaching a rect leaf at all), so the RESIDUAL half of the claim is | ||
| 6870 | + // proven by the 8-bit arm while the 10-bit arm proves the mode-info, | ||
| 6871 | + // prediction and neighbour halves on both axes. | ||
| 6872 | + let mut tu_total = 0usize; | ||
| 6873 | + for bit_depth in [8u32, 10u32] { | ||
| 6874 | + let (mut named_refusals, mut matched, mut out_of_scope, mut oos_mismatch) = | ||
| 6875 | + (0u32, 0u32, 0u32, 0u32); | ||
| 6876 | + let (mut tu_proved, mut split_proved) = (0usize, 0usize); | ||
| 6877 | + let (mut horz_proved, mut vert_proved, mut sub16_split) = (0u32, 0u32, 0usize); | ||
| 6878 | + // lane-inter4 r4, measured residue of this recipe family (sweep | ||
| 6879 | + // over cq {8,12,16,22} x {both axes} x both depths, tx-size-search | ||
| 6880 | + // on, via `decode_probe`'s `rect_inter:` counters): the rect | ||
| 6881 | + // var-tx SPLIT arm never fires (txsplit=0 everywhere) and a 10-bit | ||
| 6882 | + // rect leaf is always `skip` (tu=0 at every cq that decodes) -- | ||
| 6883 | + // below cq 22 every attempt stops at another lane's intra refusal | ||
| 6884 | + // ("a HORZ/VERT intra strip below 16x16 with a split transform"). | ||
| 6885 | + // Both are asserted here only where they DO fire (8-bit tu>0); | ||
| 6886 | + // shipped-but-unexercised, see lanes/inter4-r4.report.md. | ||
| 6887 | + // lane-inter4 r4: attempts 16..32 repeat the same sweep with | ||
| 6888 | + // `--enable-obmc=1`. r3 refused OBMC on this shape; r4's | ||
| 6889 | + // instrumented-aomdec comparison showed the neighbour list AND | ||
| 6890 | + // every pre-filter frame bit-exact, so the arm is a gate now. | ||
| 6891 | + let mut obmc_leaf_proved = 0usize; | ||
| 6892 | + for attempt in 0..32u32 { | ||
| 6893 | + let obmc_arg = if attempt >= 16 { "--enable-obmc=1" } else { "--enable-obmc=0" }; | ||
| 6894 | + let attempt = attempt % 16; | ||
| 6895 | + // Two sources (a translating textured ramp, and testsrc2's | ||
| 6896 | + // natural motion) x two quantisers x two tx-size-search arms x | ||
| 6897 | + // two motion steps. | ||
| 6898 | + let tx_search = if attempt % 2 == 0 { "0" } else { "1" }; | ||
| 6899 | + // A 10-bit encode of the same source spends fewer bits on | ||
| 6900 | + // residual at a given cq, so it needs the lower pair to make | ||
| 6901 | + // a rect leaf non-skip at all (measured: cq 34/22 gives zero | ||
| 6902 | + // coded rect inter TUs in 16 10-bit attempts). | ||
| 6903 | + let cq = [34, 22][(attempt / 2 % 2) as usize]; | ||
| 6904 | + let natural = attempt / 4 % 2 == 1; | ||
| 6905 | + let sp = 3 + (attempt / 8) * 5; | ||
| 6906 | + let duration = frame_count as f64 / 25.0; | ||
| 6907 | + // Continuous-tone, mid-frequency, translating: a flat or | ||
| 6908 | + // banded source makes aomenc code the strips `skip` (r1's | ||
| 6909 | + // gate) and its screen-content detector fires on the | ||
| 6910 | + // synthetic ramps, stopping the decode at an unrelated intra | ||
| 6911 | + // refusal long before any inter strip. | ||
| 6912 | + // Structure ALONG one axis is what makes aomenc's RD pick a | ||
| 6913 | + // 2:1 rect partition on that axis: horizontal bands drifting | ||
| 6914 | + // vertically favour PARTITION_HORZ (32x16 strips), the | ||
| 6915 | + // transposed source PARTITION_VERT (16x32). | ||
| 6916 | + let lum = if natural { | ||
| 6917 | + format!("128+58*sin((Y+N*{sp})/6)+18*sin(X/23)") | ||
| 6918 | + } else { | ||
| 6919 | + format!("128+58*sin((X+N*{sp})/6)+18*sin(Y/23)") | ||
| 6920 | + }; | ||
| 6921 | + let source = format!( | ||
| 6922 | + "color=c=gray:s={width}x{height}:d={duration}:r=25,format=gray,\ | ||
| 6923 | + geq=lum='{lum}',format=yuv420p" | ||
| 6924 | + ); | ||
| 6925 | + let pix_fmt = if bit_depth == 10 { "yuv420p10le" } else { "yuv420p" }; | ||
| 6926 | + let y4m = Command::new("ffmpeg") | ||
| 6927 | + .args([ | ||
| 6928 | + "-v", "error", "-f", "lavfi", "-i", &source, "-t", &duration.to_string(), | ||
| 6929 | + "-pix_fmt", pix_fmt, "-strict", "-1", "-f", "yuv4mpegpipe", "-", | ||
| 6930 | + ]) | ||
| 6931 | + .stdin(Stdio::null()) | ||
| 6932 | + .stdout(Stdio::piped()) | ||
| 6933 | + .stderr(Stdio::piped()) | ||
| 6934 | + .output() | ||
| 6935 | + .expect("ffmpeg failed to run"); | ||
| 6936 | + assert!( | ||
| 6937 | + y4m.status.success(), | ||
| 6938 | + "{NAME}: ffmpeg refused the {bit_depth}-bit fixture: {}", | ||
| 6939 | + String::from_utf8_lossy(&y4m.stderr) | ||
| 6940 | + ); | ||
| 6941 | + let cq_arg = format!("--cq-level={cq}"); | ||
| 6942 | + let depth_arg = format!("--bit-depth={bit_depth}"); | ||
| 6943 | + let input_depth_arg = format!("--input-bit-depth={bit_depth}"); | ||
| 6944 | + let tx_arg = format!("--enable-tx-size-search={tx_search}"); | ||
| 6945 | + let args: Vec<&str> = vec![ | ||
| 6946 | + "--codec=av1", "--passes=1", "--end-usage=q", &cq_arg, "--cpu-used=0", | ||
| 6947 | + "--threads=1", "--row-mt=0", "--sb-size=64", &depth_arg, &input_depth_arg, | ||
| 6948 | + "--enable-restoration=0", "--enable-palette=0", "--deltaq-mode=0", | ||
| 6949 | + "--enable-filter-intra=0", "--enable-cfl-intra=0", "--enable-intrabc=0", | ||
| 6950 | + "--lag-in-frames=0", | ||
| 6951 | + // Per-arm overrides go LAST: aomenc keeps the last | ||
| 6952 | + // occurrence of a repeated --enable-* flag. | ||
| 6953 | + &tx_arg, | ||
| 6954 | + "--enable-rect-partitions=1", "--enable-ab-partitions=0", | ||
| 6955 | + "--enable-1to4-partitions=0", "--min-partition-size=8", | ||
| 6956 | + "--max-partition-size=16", | ||
| 6957 | + obmc_arg, | ||
| 6958 | + "--obu", "-o", "-", "-", | ||
| 6959 | + ]; | ||
| 6960 | + let mut child = Command::new(aomenc_path()) | ||
| 6961 | + .args(&args) | ||
| 6962 | + .stdin(Stdio::piped()) | ||
| 6963 | + .stdout(Stdio::piped()) | ||
| 6964 | + .stderr(Stdio::piped()) | ||
| 6965 | + .spawn() | ||
| 6966 | + .expect("aomenc failed to start"); | ||
| 6967 | + child | ||
| 6968 | + .stdin | ||
| 6969 | + .take() | ||
| 6970 | + .expect("aomenc stdin") | ||
| 6971 | + .write_all(&y4m.stdout) | ||
| 6972 | + .expect("writing y4m to aomenc"); | ||
| 6973 | + let out = child.wait_with_output().expect("aomenc failed to run"); | ||
| 6974 | + assert!( | ||
| 6975 | + out.status.success(), | ||
| 6976 | + "aomenc refused the fixture: {}", | ||
| 6977 | + String::from_utf8_lossy(&out.stderr) | ||
| 6978 | + ); | ||
| 6979 | + let stream = out.stdout; | ||
| 6980 | + let before = (decode::rect_inter_tu_hits(), decode::rect_inter_txsplit_hits()); | ||
| 6981 | + let before_obmc_leaf = decode::obmc_rect_leaf_hits(); | ||
| 6982 | + let before_leaf = ( | ||
| 6983 | + decode::inter_leaf16_horz_hits(), | ||
| 6984 | + decode::inter_leaf16_vert_hits(), | ||
| 6985 | + decode::inter_sub16_split_hits(), | ||
| 6986 | + ); | ||
| 6987 | + let frames = match decode_stream(&stream) { | ||
| 6988 | + Err(e) => { | ||
| 6989 | + let msg = e.to_string(); | ||
| 6990 | + assert!( | ||
| 6991 | + msg.contains("unsupported"), | ||
| 6992 | + "{NAME} failed outright, not a named refusal ({bit_depth}-bit, \ | ||
| 6993 | + attempt {attempt}): {msg}" | ||
| 6994 | + ); | ||
| 6995 | + named_refusals += 1; | ||
| 6996 | + eprintln!("{bit_depth}-bit attempt {attempt} refusal: {msg}"); | ||
| 6997 | + continue; | ||
| 6998 | + } | ||
| 6999 | + Ok(frames) => frames, | ||
| 7000 | + }; | ||
| 7001 | + let after = (decode::rect_inter_tu_hits(), decode::rect_inter_txsplit_hits()); | ||
| 7002 | + let (tu, split) = (after.0 - before.0, after.1 - before.1); | ||
| 7003 | + let obmc_leaf = decode::obmc_rect_leaf_hits() - before_obmc_leaf; | ||
| 7004 | + let (horz, vert, splits16) = ( | ||
| 7005 | + decode::inter_leaf16_horz_hits() - before_leaf.0, | ||
| 7006 | + decode::inter_leaf16_vert_hits() - before_leaf.1, | ||
| 7007 | + decode::inter_sub16_split_hits() - before_leaf.2, | ||
| 7008 | + ); | ||
| 7009 | + let ffmpeg_frames = if bit_depth == 10 { | ||
| 7010 | + ffmpeg_decode_sequence_10bit(&stream, width, height, frame_count) | ||
| 7011 | + } else { | ||
| 7012 | + ffmpeg_decode_sequence(&stream, width, height, frame_count) | ||
| 7013 | + }; | ||
| 7014 | + assert_eq!(frames.len(), frame_count); | ||
| 7015 | + let mismatched = frames | ||
| 7016 | + .iter() | ||
| 7017 | + .zip(&ffmpeg_frames) | ||
| 7018 | + .any(|(got, want)| got.y != want.y || got.u != want.u || got.v != want.v); | ||
| 7019 | + if horz + vert == 0 { | ||
| 7020 | + out_of_scope += 1; | ||
| 7021 | + if mismatched { | ||
| 7022 | + oos_mismatch += 1; | ||
| 7023 | + eprintln!( | ||
| 7024 | + "{NAME}: {bit_depth}-bit attempt {attempt} MISMATCHES with zero \ | ||
| 7025 | + 16-level rect inter leaf -- another shape's defect" | ||
| 7026 | + ); | ||
| 7027 | + } | ||
| 7028 | + continue; | ||
| 7029 | + } | ||
| 7030 | + if mismatched { | ||
| 7031 | + // lane-inter4 r3: where, not just that -- a handful of | ||
| 7032 | + // 4x4-aligned pixels is a prediction/reconstruction | ||
| 7033 | + // defect, a whole band from the first row down is a | ||
| 7034 | + // desync. | ||
| 7035 | + for (i, (got, want)) in frames.iter().zip(&ffmpeg_frames).enumerate() { | ||
| 7036 | + let bad: Vec<usize> = (0..got.y.len()) | ||
| 7037 | + .filter(|&k| got.y[k] != want.y[k]) | ||
| 7038 | + .collect(); | ||
| 7039 | + if !bad.is_empty() { | ||
| 7040 | + eprintln!( | ||
| 7041 | + "{NAME}: attempt {attempt} {bit_depth}-bit frame {i}: {} luma \ | ||
| 7042 | + pixels differ, first at ({}, {}), max |delta| {}", | ||
| 7043 | + bad.len(), | ||
| 7044 | + bad[0] % width, | ||
| 7045 | + bad[0] / width, | ||
| 7046 | + bad.iter() | ||
| 7047 | + .map(|&k| (got.y[k] as i32 - want.y[k] as i32).abs()) | ||
| 7048 | + .max() | ||
| 7049 | + .unwrap_or(0) | ||
| 7050 | + ); | ||
| 7051 | + } | ||
| 7052 | + } | ||
| 7053 | + } | ||
| 7054 | + for (i, (got, want)) in frames.iter().zip(&ffmpeg_frames).enumerate() { | ||
| 7055 | + assert_eq!(got.y, want.y, "{NAME} frame {i} luma vs ffmpeg (attempt {attempt}, {bit_depth}-bit, tx_search={tx_search})"); | ||
| 7056 | + assert_eq!(got.u, want.u, "{NAME} frame {i} U vs ffmpeg (attempt {attempt}, {bit_depth}-bit, tx_search={tx_search})"); | ||
| 7057 | + assert_eq!(got.v, want.v, "{NAME} frame {i} V vs ffmpeg (attempt {attempt}, {bit_depth}-bit, tx_search={tx_search})"); | ||
| 7058 | + } | ||
| 7059 | + tu_proved += tu; | ||
| 7060 | + obmc_leaf_proved += obmc_leaf; | ||
| 7061 | + split_proved += split; | ||
| 7062 | + sub16_split += splits16; | ||
| 7063 | + if horz > 0 { | ||
| 7064 | + horz_proved += 1; | ||
| 7065 | + } | ||
| 7066 | + if vert > 0 { | ||
| 7067 | + vert_proved += 1; | ||
| 7068 | + } | ||
| 7069 | + matched += 1; | ||
| 7070 | + } | ||
| 7071 | + eprintln!( | ||
| 7072 | + "{NAME} ({bit_depth}-bit): {named_refusals} named refusals, {matched} pixel-exact \ | ||
| 7073 | + attempts carrying a 16-level rect inter leaf, 16x8-carrying={horz_proved}, \ | ||
| 7074 | + 8x16-carrying={vert_proved}, whole-block rect TUs={tu_proved}, rect trees that \ | ||
| 7075 | + split={split_proved}, 16x16 SPLITs={sub16_split}, OBMC blends on a rect \ | ||
| 7076 | + leaf={obmc_leaf_proved}, {out_of_scope} attempts \ | ||
| 7077 | + carried none ({oos_mismatch} of them mismatched)" | ||
| 7078 | + ); | ||
| 7079 | + assert_eq!( | ||
| 7080 | + oos_mismatch, 0, | ||
| 7081 | + "{NAME}: {oos_mismatch} attempt(s) with no coded rect inter residual decoded but \ | ||
| 7082 | + mismatched ffmpeg -- a defect of another shape, not a pass" | ||
| 7083 | + ); | ||
| 7084 | + assert!( | ||
| 7085 | + horz_proved > 0 && vert_proved > 0, | ||
| 7086 | + "{NAME} ({bit_depth}-bit): the 16-level rect inter leaf is not proven on both \ | ||
| 7087 | + axes (16x8={horz_proved}, 8x16={vert_proved}, tu={tu_proved}, 16x16 \ | ||
| 7088 | + SPLITs={sub16_split}, {named_refusals} refusals, {out_of_scope} out of \ | ||
| 7089 | + scope) -- gate proved nothing" | ||
| 7090 | + ); | ||
| 7091 | + assert!( | ||
| 7092 | + obmc_leaf_proved > 0, | ||
| 7093 | + "{NAME} ({bit_depth}-bit): no pixel-exact attempt ever ran the OBMC blend on a \ | ||
| 7094 | + 16x8/8x16 inter leaf -- the `--enable-obmc=1` arm proved nothing" | ||
| 7095 | + ); | ||
| 7096 | + tu_total += tu_proved; | ||
| 7097 | + } | ||
| 7098 | + assert!( | ||
| 7099 | + tu_total > 0, | ||
| 7100 | + "{NAME}: no pixel-exact attempt at either bit depth coded a rectangular inter \ | ||
| 7101 | + residual on a 16-level leaf -- the residual half of the claim is unproven" | ||
| 5644 | ); | 7102 | ); |
| 5645 | } | 7103 | } |
| 5646 | 7104 | ||
| 7105 | + | ||
| 5647 | #[test] | 7106 | #[test] |
| 5648 | fn a_real_aomenc_inter_sequence_with_deblocking_decodes_pixel_exact() { | 7107 | fn a_real_aomenc_inter_sequence_with_deblocking_decodes_pixel_exact() { |
| 5649 | if !have_ffmpeg() { | 7108 | if !have_ffmpeg() { |
| @@ -11957,8 +13416,26 @@ mod tests { | |||
| 11957 | eprintln!("SKIP: no ffmpeg/aomenc"); | 13416 | eprintln!("SKIP: no ffmpeg/aomenc"); |
| 11958 | return; | 13417 | return; |
| 11959 | } | 13418 | } |
| 11960 | - let sizes: &[(usize, usize)] = | 13419 | + // lane-oddh r2: the second half of this list is the odd-height / |
| 11961 | - &[(8, 8), (16, 16), (32, 32), (16, 32), (32, 16), (64, 64), (48, 48), (24, 24)]; | 13420 | + // odd-width ladder -- frame sizes whose last superblock row or column |
| 13421 | + // is a partial 64 (72 = one full SB plus 8 rows, 136 = two plus 8), | ||
| 13422 | + // which is where the frame-edge half-strip path r1 added is the only | ||
| 13423 | + // way to code the edge. 192x136 is the inter-sized member. | ||
| 13424 | + let sizes: &[(usize, usize)] = &[ | ||
| 13425 | + (8, 8), | ||
| 13426 | + (16, 16), | ||
| 13427 | + (32, 32), | ||
| 13428 | + (16, 32), | ||
| 13429 | + (32, 16), | ||
| 13430 | + (64, 64), | ||
| 13431 | + (48, 48), | ||
| 13432 | + (24, 24), | ||
| 13433 | + (64, 72), | ||
| 13434 | + (72, 64), | ||
| 13435 | + (64, 136), | ||
| 13436 | + (136, 64), | ||
| 13437 | + (192, 136), | ||
| 13438 | + ]; | ||
| 11962 | let mut total_exact = 0u32; | 13439 | let mut total_exact = 0u32; |
| 11963 | for &(width, height) in sizes { | 13440 | for &(width, height) in sizes { |
| 11964 | let mut ok = 0u32; | 13441 | let mut ok = 0u32; |
| @@ -12076,12 +13553,12 @@ mod tests { | |||
| 12076 | } | 13553 | } |
| 12077 | // Hit counter: the sweep proved nothing unless every size x seed | 13554 | // Hit counter: the sweep proved nothing unless every size x seed |
| 12078 | // attempt really ran end to end (aomenc -> us -> ffmpeg compare). | 13555 | // attempt really ran end to end (aomenc -> us -> ffmpeg compare). |
| 12079 | - // Floor (hit counter): 7 of the 8 sizes must decode all 10 seeds | 13556 | + // Floor (hit counter): 12 of the 13 sizes must decode all 10 seeds |
| 12080 | // pixel-exact -- only 8x8 is allowed to refuse outright today. If a | 13557 | // pixel-exact -- only 8x8 is allowed to refuse outright today. If a |
| 12081 | // future change makes sizes refuse instead of decode, this fails | 13558 | // future change makes sizes refuse instead of decode, this fails |
| 12082 | // rather than passing on refusals alone. | 13559 | // rather than passing on refusals alone. |
| 12083 | assert!( | 13560 | assert!( |
| 12084 | - total_exact >= 70, | 13561 | + total_exact >= 120, |
| 12085 | "tiny sweep only reached {total_exact} pixel-exact attempts (floor 70) -- \ | 13562 | "tiny sweep only reached {total_exact} pixel-exact attempts (floor 70) -- \ |
| 12086 | refusals cannot substitute for decodes" | 13563 | refusals cannot substitute for decodes" |
| 12087 | ); | 13564 | ); |
| @@ -18672,12 +20149,16 @@ mod tests { | |||
| 18672 | geq=lum='mod(floor({axis}/8)*{step},256)',\ | 20149 | geq=lum='mod(floor({axis}/8)*{step},256)',\ |
| 18673 | noise=alls={noise}:all_seed={seed},format=yuv420p" | 20150 | noise=alls={noise}:all_seed={seed},format=yuv420p" |
| 18674 | ); | 20151 | ); |
| 20152 | + // lane-band63: the second cq is 63, not 45 -- a near-max | ||
| 20153 | + // quantiser is where deblock/CDEF do the most work and where a | ||
| 20154 | + // 1:4 strip is most often skip; all 16 streams of this family at | ||
| 20155 | + // cq 63 (8- and 10-bit) decode pixel-exact. | ||
| 18675 | let cq_level = if tx_search { | 20156 | let cq_level = if tx_search { |
| 18676 | // 12..28: the window measured to fire both split depths on | 20157 | // 12..28: the window measured to fire both split depths on |
| 18677 | // this fixture (lanes/tx64x16-r4.handoff.md). | 20158 | // this fixture (lanes/tx64x16-r4.handoff.md). |
| 18678 | format!("--cq-level={}", 12 + (attempt % 4) * 5) | 20159 | format!("--cq-level={}", 12 + (attempt % 4) * 5) |
| 18679 | } else { | 20160 | } else { |
| 18680 | - format!("--cq-level={}", if attempt % 4 < 2 { 32 } else { 45 }) | 20161 | + format!("--cq-level={}", if attempt % 4 < 2 { 32 } else { 63 }) |
| 18681 | }; | 20162 | }; |
| 18682 | let pix_fmt = if bit_depth == 10 { "yuv420p10le" } else { "yuv420p" }; | 20163 | let pix_fmt = if bit_depth == 10 { "yuv420p10le" } else { "yuv420p" }; |
| 18683 | let y4m = Command::new("ffmpeg") | 20164 | let y4m = Command::new("ffmpeg") |
| @@ -18941,7 +20422,11 @@ mod tests { | |||
| 18941 | geq=lum='mod(floor({axis}/8)*{step},256)',\ | 20422 | geq=lum='mod(floor({axis}/8)*{step},256)',\ |
| 18942 | noise=alls={noise}:all_seed={seed},format=yuv420p" | 20423 | noise=alls={noise}:all_seed={seed},format=yuv420p" |
| 18943 | ); | 20424 | ); |
| 18944 | - let cq_level = format!("--cq-level={}", [32, 45, 55][(attempt / 2 % 3) as usize]); | 20425 | + // lane-band63: 63 joins the rotation -- filter intra ON at a |
| 20426 | + // near-max quantiser is exactly the configuration the stale | ||
| 20427 | + // cq-63 premise blamed, and it decodes exact. | ||
| 20428 | + let cq_level = | ||
| 20429 | + format!("--cq-level={}", [32, 45, 55, 63][(attempt / 2 % 4) as usize]); | ||
| 18945 | let pix_fmt = if bit_depth == 10 { "yuv420p10le" } else { "yuv420p" }; | 20430 | let pix_fmt = if bit_depth == 10 { "yuv420p10le" } else { "yuv420p" }; |
| 18946 | let y4m = Command::new("ffmpeg") | 20431 | let y4m = Command::new("ffmpeg") |
| 18947 | .args([ | 20432 | .args([ |
lanes/angleinter-r1.report.mdadded+105 -0
| @@ -0,0 +1,105 @@ | |||
| 1 | +# lane-angleinter r1 — a nonzero angle delta on an intra block inside an inter frame | ||
| 2 | + | ||
| 3 | +Branch `lane-angleinter` off `lane-fiinter` 6b82994. Class: | ||
| 4 | +[[refusal-strings-are-claims]] + [[tool-disabled-in-every-gate]]. | ||
| 5 | + | ||
| 6 | +## The claim, tested | ||
| 7 | + | ||
| 8 | +Both intra-in-inter arms read `angle_delta_y` and then refused it as | ||
| 9 | +"a nonzero angle delta (this encoder never writes one)". The claim is FALSE: | ||
| 10 | +aomenc's `--enable-angle-delta` defaults to 1 and libaom's | ||
| 11 | +`read_intra_angle_info` (inside `read_intra_block_mode_info`, decodemv.c) | ||
| 12 | +writes the symbol for any directional `y_mode` at bsize >= 8x8 exactly as a | ||
| 13 | +key frame does. A real default-settings inter stream desynced there. | ||
| 14 | + | ||
| 15 | +Confirmed by the gate below on the FIRST attempt (seed 42, 8-bit): 4 intra | ||
| 16 | +blocks inside inter frames carry a nonzero `angle_delta_y`. | ||
| 17 | + | ||
| 18 | +## What changed | ||
| 19 | + | ||
| 20 | +- `crates/ec-av1/src/decode.rs:15542` (`decode_inter_block`, >=16x16 arm): | ||
| 21 | + refusal replaced by `read_angle_delta`; the delta is threaded into every | ||
| 22 | + luma prediction of the block — the split-transform per-TU | ||
| 23 | + `reconstruct`/`read_plane` pair and the block-level pair — where a literal | ||
| 24 | + `0` used to go. | ||
| 25 | +- `crates/ec-av1/src/decode.rs:15555`: the same arm derived | ||
| 26 | + `smooth_neighbor` (`get_intra_edge_filter_type`, spec 7.11.2) via the | ||
| 27 | + existing `Neighbours::modes_above_left` helper; it passed a hardcoded | ||
| 28 | + `false` before, which was unobservable while every directional | ||
| 29 | + intra-in-inter block was refused, and decides the intra edge filter's | ||
| 30 | + strength once a delta'd angle reaches it. | ||
| 31 | +- `crates/ec-av1/src/decode.rs:82` (+ around): counters | ||
| 32 | + `intra_in_inter_angle_delta_y_hits` / `intra_in_inter_angle_delta_uv_hits`. | ||
| 33 | +- `crates/ec-av1/src/decode.rs:17191` (`decode_inter_block8`, 8x8 leaf): | ||
| 34 | + the refusal STAYS, reworded to a claim about this decoder's gate coverage | ||
| 35 | + instead of about the encoder — see "Not lifted" below. | ||
| 36 | +- `crates/ec-av1/src/stream.rs`: gate `angle_delta_in_inter_gate` + its 8-bit | ||
| 37 | + and 10-bit tests. | ||
| 38 | +- `refusal_inventory.rs`: the capability claim is gone; the 8x8-leaf refusal | ||
| 39 | + is listed as a decoder-scoped refusal. `gate_coverage.rs`: | ||
| 40 | + `enable-angle-delta` deleted from `NEVER_EXERCISED_8BIT` and `_10BIT`. | ||
| 41 | + | ||
| 42 | +## Gate | ||
| 43 | + | ||
| 44 | +`a_real_aomenc_inter_sequence_with_a_directional_intra_block_with_angle_delta_decodes_pixel_exact` | ||
| 45 | +(+ `..._10bit_...`). Recipe = the intrainter/fiinter one (64x64 mandelbrot | ||
| 46 | +zoom with a hard overlay cut at frame 4, `--cq-level=30`, `--kf-min-dist=1000` | ||
| 47 | +`--kf-max-dist=1000`, `--min-partition-size=16`) with | ||
| 48 | +`--enable-directional-intra=1` and `--enable-angle-delta=1` — each flag | ||
| 49 | +spelled ONCE in the arg list (the base recipe's `=0` entries were edited in | ||
| 50 | +place, so flag precedence cannot silently invert the arm). Every frame's Y, U | ||
| 51 | +and V are compared against ffmpeg; a decode error or mismatch is a FAILURE, | ||
| 52 | +never a SKIP; the hit counter is a hard assert. | ||
| 53 | + | ||
| 54 | +``` | ||
| 55 | +cargo test -p ec-av1 --lib with_a_directional_intra_block_with_angle_delta -- --nocapture | ||
| 56 | +``` | ||
| 57 | + | ||
| 58 | +EVIDENCE: $HOME/.cache/angleinter-suite.log | aomenc --enable-angle-delta=1 --enable-directional-intra=1, 8 frames decoded and Y/U/V-compared vs ffmpeg | 8-bit seed 42: 4 nonzero-angle_delta_y intra-in-inter blocks, 0 sample mismatches; 10-bit seed 47: 4 blocks, 0 mismatches (buckets counted-exact=1 uncounted-exact=0) | ||
| 59 | + | ||
| 60 | +EVIDENCE: negative control (scratchpad decode.rs.bak diff) | re-inserted `return Err(unsupported("NEGATIVE CONTROL: a nonzero angle delta"))` at decode.rs:15549, reran both gates | 2 passed -> 2 FAILED, all 40 attempts refused with that string; lift reverted afterwards | ||
| 61 | + | ||
| 62 | +## Mutation sweep (task 3) | ||
| 63 | + | ||
| 64 | +All 56 `--enable-angle-delta=0` spellings in `stream.rs` flipped to `=1`, then | ||
| 65 | +the 17 `inter_sequence` gates rerun: **17 passed / 0 failed** — no hidden | ||
| 66 | +defect behind the flag. stream.rs restored from the scratchpad copy | ||
| 67 | +afterwards (only the new gate's own two spellings are `=1` on the branch). | ||
| 68 | + | ||
| 69 | +EVIDENCE: mutation run | sed -i 's/--enable-angle-delta=0/=1/g' + `cargo test -p ec-av1 --lib inter_sequence` | test result: ok. 17 passed; 0 failed; 2 ignored | ||
| 70 | + | ||
| 71 | +## Not lifted (disposition) | ||
| 72 | + | ||
| 73 | +`deferred: the 8x8-leaf arm's nonzero-delta case (decode.rs:17205) — 80 | ||
| 74 | +attempts (64x64 and 128x128 sources, cq 20/30/40/50/60, seeds 42..81) never | ||
| 75 | +produced an 8x8 intra leaf with a nonzero angle_delta_y, nor even one with a | ||
| 76 | +directional luma mode: the leaf's three sibling refusals ("a non-DC chroma | ||
| 77 | +mode on an 8x8 inter-frame leaf", "an 8x8 intra leaf ... whose tx_depth | ||
| 78 | +splits it into 4x4 transform units", "an inter partition below 16x16 other | ||
| 79 | +than SPLIT") fire first on 37/40 attempts. Lifting it would ship an ungated | ||
| 80 | +capability claim (class refusal-lifted-without-a-gate), so the refusal stays, | ||
| 81 | +reworded to be about this decoder. — unblocked by: lifting the non-DC-chroma | ||
| 82 | +and TX_4X4-split refusals on that leaf, which then makes a directional 8x8 | ||
| 83 | +intra leaf reachable.` | ||
| 84 | + | ||
| 85 | +`accepted: angle_delta_uv fired 0 times in every passing attempt — the | ||
| 86 | +recipe's `hue=s=0` desaturation is what keeps uv_mode on DC and the transform | ||
| 87 | +split luma-driven. The uv delta path was already read AND already threaded | ||
| 88 | +into both chroma predictions before this round (decode.rs:15556 ff.), so the | ||
| 89 | +lift did not touch it; the counter is in place for a future chroma gate.` | ||
| 90 | + | ||
| 91 | +`accepted: decode_inter_block8 still passes a hardcoded `false` for its luma | ||
| 92 | +edge-filter neighbour type. Unobservable while its directional-mode | ||
| 93 | +population is empty (see above); reverted rather than shipped ungated.` | ||
| 94 | + | ||
| 95 | +## Suite + film | ||
| 96 | + | ||
| 97 | +`cargo test -p ec-av1 --lib` (systemd unit, log `$HOME/.cache/angleinter-suite.log`): | ||
| 98 | +**348 passed / 0 failed / 32 ignored**, 384 s. | ||
| 99 | + | ||
| 100 | +Film probe (`hg-head.obu`, 0.4 s of the ReelB 2160p10 film, 18 frame | ||
| 101 | +headers): now stops at `filter intra on a HORZ/VERT strip (this decoder | ||
| 102 | +predicts square-only)` — a different, rect-prediction refusal; the angle-delta | ||
| 103 | +refusal is no longer on its path. | ||
| 104 | + | ||
| 105 | +EVIDENCE: $HOME/.cache/angleinter-suite.log | `cargo test -p ec-av1 --lib` under a systemd unit + `cargo run --example decode_probe -- hg-head.obu` | 348 passed / 0 failed; film refusal string = "filter intra on a HORZ/VERT strip" | ||
lanes/band63-r1.report.mdadded+119 -0
| @@ -0,0 +1,119 @@ | |||
| 1 | +# lane-band63 r1 — the cq-63 "defect" does not exist; a real one at cq 32 does | ||
| 2 | + | ||
| 3 | +Branch `lane-band63` off main `c729a38`, plus a merge of `lane-fi32x8` (c3a5032) so the | ||
| 4 | +filter-intra-on configuration could be tested at all. | ||
| 5 | + | ||
| 6 | +## 1. The chartered premise is FALSE (measured, not argued) | ||
| 7 | + | ||
| 8 | +Charter: *"the 8-px band fixture at `--cq-level=63` mismatches ffmpeg on frame 0 for 8-bit | ||
| 9 | +seeds 58/59/64 EVEN WITH `--enable-filter-intra=0`"* (from lanes/fi32x8-r1.report.md residue). | ||
| 10 | + | ||
| 11 | +Reproduced the exact recipe (fi32x8 gate family: `geq=lum='mod(floor({axis}/8)*{step},256)'`, | ||
| 12 | +`noise=alls={18+(attempt%4)*3}:all_seed={42+attempt}`, `--cq-level=63`, cpu-used=0, | ||
| 13 | +1:4 partitions on, min/max partition 8/32, directional/paeth/smooth intra off) and swept it | ||
| 14 | +far wider than the three named seeds: | ||
| 15 | + | ||
| 16 | +| sweep | streams | result | | ||
| 17 | +|---|---|---| | ||
| 18 | +| fi32x8 family, attempts 0..23, 8+10 bit, `--enable-filter-intra=0` | 48 | 48 pixel-exact, 0 refusals | | ||
| 19 | +| fi32x8 family, attempts 0..23, 8+10 bit, `--enable-filter-intra=1` (last) | 48 | 48 pixel-exact, 0 refusals | | ||
| 20 | +| 32x32-gate family (noise 6..15), attempts 0..7, 8+10 bit, cq 63 | 16 | 16 pixel-exact | | ||
| 21 | +| 32x32-gate family, seeds 58/59/64 x noise 6/9/12/15 x both axes, cq 63 | 24 | 24 pixel-exact | | ||
| 22 | + | ||
| 23 | +Seeds 58/59/64 (= fi32x8 attempts 16/17/22) are inside the first two rows and are exact at | ||
| 24 | +both depths. Streams hashed; generator `gen.sh`/`gen2.sh`/`gen3.sh` in the scratchpad. | ||
| 25 | + | ||
| 26 | +EVIDENCE: $HOME/.cache/cargo-target-band63/debug/examples/decode_probe + ffmpeg rawvideo | 136 aomenc streams at cq 63 regenerated across 4 parameter sweeps, each decoded by ec-av1 and by ffmpeg and byte-compared full-frame (8-bit u8 dump, 10-bit u16 dump) | 136/136 identical, 0 refusals | ||
| 27 | + | ||
| 28 | +Why the premise looked true in fi32x8's round: that lane's control ran `--enable-filter-intra=0` | ||
| 29 | +*before* the base recipe's `--enable-filter-intra=1`, and **aomenc keeps the LAST occurrence** | ||
| 30 | +(class aomenc-first-flag-wins, already in memory) — so the control flag never arrived, and what | ||
| 31 | +it saw was its own then-unfixed filter-intra path, not "another shape". Class: stale-premise | ||
| 32 | +lanes / refusal-names-a-correlate. | ||
| 33 | + | ||
| 34 | +My own instrument repeated the class once: `decode_probe` had no 10-bit dump, so an | ||
| 35 | +`EC_PROBE_OUT16` compare against a never-written file read as MISMATCH for three streams | ||
| 36 | +(class stale-output-faked-measurement). Fixed by adding the dump, then re-measured. | ||
| 37 | + | ||
| 38 | +## 2. What changed | ||
| 39 | + | ||
| 40 | +- `crates/ec-av1/examples/decode_probe.rs:81` — `EC_PROBE_OUT16` dumps planes as | ||
| 41 | + little-endian u16, the only form a 10-bit pixel diff against | ||
| 42 | + `ffmpeg -pix_fmt yuv420p10le` can use. Without it no 10-bit claim from this instrument is real. | ||
| 43 | +- `crates/ec-av1/src/stream.rs:16757` — the 32x32-level 1:4 gate's second quantiser is **63** | ||
| 44 | + instead of 45 (attempts 2,3,6,7 at both depths). The cq-32 attempts keep their exact streams, | ||
| 45 | + so nothing changes by accident. cq 63 is now coded, so the premise cannot come back unmeasured. | ||
| 46 | +- `crates/ec-av1/src/stream.rs:16992` — the filter-intra 1:4 gate's rotation is | ||
| 47 | + `[32,45,55,63]` (attempts 6,7,14,15 at cq 63), same reason, with filter intra ON. | ||
| 48 | + | ||
| 49 | +Both gates keep every existing hard assert (per-depth `horz_proved > 0 && vert_proved > 0`, | ||
| 50 | +`coeff_proved > 0`, `matched > 0`, `out_of_scope_mismatch == 0`, full-frame Y/U/V compare). | ||
| 51 | + | ||
| 52 | +Gate run: | ||
| 53 | +``` | ||
| 54 | +EC_NOMEMGUARD=1 EC_AV1_REQUIRE_AOMENC=1 CARGO_TARGET_DIR=$HOME/.cache/cargo-target-band63 \ | ||
| 55 | + cargo test -p ec-av1 --lib -j3 -- --nocapture 1to4 | ||
| 56 | +``` | ||
| 57 | +→ `test result: ok. 3 passed; 0 failed` (14.7 s): | ||
| 58 | +- 32x32-level 1:4: 8-bit 8/8 exact, horz_4=56 vert_4=84 coded=140; 10-bit 8/8 exact, | ||
| 59 | + horz_4=56 vert_4=68 coded=124. | ||
| 60 | +- filter-intra 1:4: 8-bit 5 matches/3 refusals, 54x(32x8)+5x(8x32); 10-bit 6 matches/1 refusal, | ||
| 61 | + 9x(32x8)+17x(8x32). | ||
| 62 | +- superblock-level 1:4 (sibling, untouched): ok. | ||
| 63 | + | ||
| 64 | +EVIDENCE: gate stdout above | both 1:4 gates run with cq 63 in the rotation at 8 and 10 bit | 3 passed / 0 failed, cq-63 attempts pixel-exact with the 1:4 counters non-zero per depth | ||
| 65 | + | ||
| 66 | +## 3. A REAL defect found on the way (NOT the chartered one) | ||
| 67 | + | ||
| 68 | +The first rotation I tried (`[32,45,63]`) also moved attempt 6 from cq 45 to cq 32, creating a | ||
| 69 | +stream nothing had ever coded — and it mismatches. Fully bisected, then set aside because it is | ||
| 70 | +not this lane's charter and not reachable from the shipped rotation: | ||
| 71 | + | ||
| 72 | +- Stream: 192x128, 8-bit, seed 48, `geq` axis Y, step 103, `noise=alls=12:all_seed=48`, | ||
| 73 | + **`--cq-level=32`**, otherwise the 32x32-level 1:4 gate recipe (filter intra off). | ||
| 74 | + Pinned at `/tmp/.../scratchpad/b63/gateA.obu` (regenerate: `gen.sh 48 Y 103 12 32 8 <out>`). | ||
| 75 | +- Stage: **reconstruction**, not filtering — `EC_AV1_PREFILT_DUMP` already differs, identically | ||
| 76 | + to `EC_AV1_POSTDEBLOCK_DUMP` (9057 luma samples, first at x=64,y=64). | ||
| 77 | +- First divergent element (range ladder, `EC_TRACE_MODE`/`EC_TRACE_MODE_STEP`, ours vs the | ||
| 78 | + instrumented aomdec, aligned by (mi_row, mi_col, name)): **`mi_row=24 mi_col=8`, element | ||
| 79 | + `mode`** — identical entry range 46952 on both sides, then aomdec `val=12 rng=36608`, | ||
| 80 | + ec-av1 `val=7 rng=33744`. Same range in, different value and range out = **wrong y-mode CDF | ||
| 81 | + row**, i.e. a wrong intra-mode neighbour context, not a wrong table value. | ||
| 82 | +- Context: the block is `BLOCK_32X16` (aomdec `bsize=8`) at the 32x32 level; its *above* | ||
| 83 | + neighbour is the last 32x8 `PARTITION_HORZ_4` strip at (22,8) (mode 12/PAETH) and its *left* | ||
| 84 | + is the 32x8 strip at (24,0) (mode 0/DC). `decode_block_rect4` (decode.rs:5990) stamps the | ||
| 85 | + COARSE 16-px `above_mode`/`left_mode` cells with "last strip wins"; the suspect is that | ||
| 86 | + coarse stamp seen by a 32x16 sibling in the next quadrant (class | ||
| 87 | + context-read-from-one-cell / neighbour-votes-all-its-fields). | ||
| 88 | +- Everything before that element is bit-exact: the ladder matches element for element through | ||
| 89 | + `mi_row=22`, so the entropy stream, the strips' own coefficients and their pixels are right. | ||
| 90 | + | ||
| 91 | +EVIDENCE: /tmp/.../scratchpad/b63/{gateA.obu,ours.trace,aom.trace,o.pre.f0,a.pre.f0} | ec-av1 vs instrumented aomdec range ladders + pre-filter/post-deblock dumps on the pinned stream | first divergence mi_row=24 mi_col=8 `mode` (entry rng 46952 both, out 36608 vs 33744); recon differs from (64,64), 9057 luma samples, deblock-only bleed at rows 62-63 | ||
| 92 | + | ||
| 93 | +## 4. Residue | ||
| 94 | + | ||
| 95 | +- deferred: the seed-48 @ cq-32 y-mode-context defect above — a wrong CDF row for a 32x16 block | ||
| 96 | + whose above neighbour is a 32x8 1:4 strip — what unblocks it: reading the above/left mode ctx | ||
| 97 | + ec-av1 computes at (24,8) against libaom's `intra_mode_context[]` of the same two neighbours | ||
| 98 | + (the ladder, stream and stage are already pinned above, so it starts at the fix, not the hunt). | ||
| 99 | + Not reachable from the shipped gate rotation (attempts 0,1,4,5 keep their original cq-32 | ||
| 100 | + streams and pass). | ||
| 101 | +- accepted: this lane merges `lane-fi32x8` (c3a5032, merge-ready per its own report) because the | ||
| 102 | + filter-intra-on arm of the premise cannot be tested on main, which still refuses those strips. | ||
| 103 | + If fi32x8 lands on main first, this merge is a no-op. | ||
| 104 | +- accepted: no refusal is lifted this round — nothing was refused. The deliverable is a coded | ||
| 105 | + quantiser the gates never coded, and a disproof. | ||
| 106 | + | ||
| 107 | +## 5. Suite | ||
| 108 | + | ||
| 109 | +``` | ||
| 110 | +systemd-run --user --unit=band63-suite-... -p MemoryMax=10G --same-dir bash -lc \ | ||
| 111 | + 'EC_NOMEMGUARD=1 EC_AV1_REQUIRE_AOMENC=1 CARGO_TARGET_DIR=$HOME/.cache/cargo-target-band63 \ | ||
| 112 | + nice -n 10 cargo test -p ec-av1 --lib -j3 > $HOME/.cache/band63-suite.log 2>&1' | ||
| 113 | +``` | ||
| 114 | +→ `test result: ok. 340 passed; 0 failed; 31 ignored` (337.9 s). | ||
| 115 | + | ||
| 116 | +`a_real_aomenc_multi_tile_intra_stream_decodes_pixel_exact` — red on main 11633d7 when | ||
| 117 | +lane-fi32x8 reported — is green here: lane-mtfix fixed it in main c729a38, this base carries it. | ||
| 118 | + | ||
| 119 | +EVIDENCE: $HOME/.cache/band63-suite.log | full `cargo test -p ec-av1 --lib` on lane-band63 c099bef with the oracle required | 340 passed / 0 failed / 31 ignored | ||
lanes/golomb-r1.report.mdadded+47 -0
| @@ -0,0 +1,47 @@ | |||
| 1 | +# lane-golomb r1 — the edge partition bit was read and thrown away | ||
| 2 | + | ||
| 3 | +## Verdict | ||
| 4 | +The "a Golomb tail longer than this decoder reads" refusal on the ReelB head was, as | ||
| 5 | +suspected (`refusal-from-own-desync`), a symptom. Root cause: at a frame edge the partition | ||
| 6 | +symbol is a single *gathered* bit, and this decoder read it and **discarded** it, always | ||
| 7 | +inferring `PARTITION_SPLIT`. libaom `ec_read_partition_impl` (decodeframe.c:1255): | ||
| 8 | +`!has_rows && has_cols` → `read ? PARTITION_SPLIT : PARTITION_HORZ`; the mirror case → | ||
| 9 | +`PARTITION_VERT`. Class: `parsed-then-discarded`. | ||
| 10 | + | ||
| 11 | +Charter STEP-2 fallback ("libaom read_golomb caps at 32 bits, extend the reader") is FALSE: | ||
| 12 | +`~/.cache/aom-oracle/src/av1/decoder/decodetxb.c:22` aborts the frame at `length > 20`, exactly | ||
| 13 | +our cap. The cap was never the bug and is unchanged. | ||
| 14 | + | ||
| 15 | +## First divergent element (EVIDENCE) | ||
| 16 | +EVIDENCE: /tmp/.../scratchpad/{ao-all.txt,ours-all.txt} | instrumented aomdec vs decode_probe, | ||
| 17 | +EC_TRACE_MODE+EC_TRACE_MODE_STEP+EC_TRACE_COEFF on the 2-frame extract f2.obu, ladders aligned | ||
| 18 | +element by element on msac RANGE | first diff at element 12053: key frame, **mi_row=400 | ||
| 19 | +mi_col=0** (last, 8-pixel-tall superblock row of a 1608-tall frame), `name=skip` | ||
| 20 | +oracle rng=34753 vs ours rng=43258. Oracle codes that superblock as one `BLOCK_64X32` | ||
| 21 | +(`EC_IMODE ... bsize=11`, PARTITION_HORZ); we forced SPLIT and descended to 16x16. | ||
| 22 | +After the fix the range ladder is element-exact for all 13712 shared elements of the key frame | ||
| 23 | +(EVIDENCE: /tmp/.../scratchpad/{a4.n,o4.n} | awk first-diff | idx 13713, inside a later INTER | ||
| 24 | +frame, i.e. past the whole key frame). | ||
| 25 | + | ||
| 26 | +## Fix | ||
| 27 | +`crates/ec-av1/src/decode.rs` — every edge-partition site, both tile paths, all three levels | ||
| 28 | +(64/32/16, intra and inter): the gathered bit now names HORZ/VERT vs SPLIT. The 64-level | ||
| 29 | +HORZ/VERT arms only decode the second half when it is inside the frame (`has_rows`/`has_cols`), | ||
| 30 | +mirroring libaom `decode_partition`. The intra 16x16 edge site can only walk four SPLIT leaves, | ||
| 31 | +so a 0 bit refuses by name there (new string, listed in `refusal_inventory.rs`) instead of | ||
| 32 | +desyncing. | ||
| 33 | + | ||
| 34 | +## Gates | ||
| 35 | +- NEW `stream::tests::the_reelb_head_key_frame_decodes_pixel_exact` — the film itself: | ||
| 36 | + `crates/ec-av1/fixtures/reelb_head_key_frame.obu` (147 B, first frame of his 3840x1608 | ||
| 37 | + yuv420p10le release) decodes and matches `ffmpeg -pix_fmt yuv420p10le` on Y, U and V. | ||
| 38 | + EVIDENCE: cargo test -p ec-av1 --lib -- the_reelb_head_key_frame | 1 passed | | ||
| 39 | + Y/U/V all equal to ffmpeg's decode, 3840x1608. | ||
| 40 | +- Full lib suite: `$HOME/.cache/golomb-suite.log` — **337 passed / 0 failed / 31 ignored**. | ||
| 41 | + | ||
| 42 | +## Film probes after the fix | ||
| 43 | +- `hg-head.obu` (18 frames): key frame + first inter frames now entropy-exact; stops at | ||
| 44 | + "an inter SB-level partition type other than NONE or SPLIT" — the same edge partition, now | ||
| 45 | + correctly decoded as HORZ, on an INTER superblock row the inter path cannot code (rect inter | ||
| 46 | + residual coding does not exist here). Next lane. | ||
| 47 | +- `reelb5.obu`: "a 32x32-level 1:4 strip with a split transform (depth=2)" (unchanged by this lane). | ||
lanes/inter4-r1.report.mdadded+97 -0
| @@ -0,0 +1,97 @@ | |||
| 1 | +# lane-inter4 r1 — inter-frame rect / 1:4 partition arms | ||
| 2 | + | ||
| 3 | +Branch `lane-inter4`, worktree `/home/user/Documents/Code/Rust/edith_codecs-inter4`, | ||
| 4 | +off main `146896f` (charter said 8262b99; main had moved two merges further — | ||
| 5 | +the worktree was already at 146896f and was NOT rebased backwards). | ||
| 6 | + | ||
| 7 | +## Premise re-measure (charter's premise was stale) | ||
| 8 | + | ||
| 9 | +`cargo run --release --example decode_probe` on both ReelC extracts, on THIS tree | ||
| 10 | +before any edit of mine, stops at | ||
| 11 | + | ||
| 12 | + unsupported: AV1 tile (a coded HORZ/VERT strip whose chroma transform has no | ||
| 13 | + rect coefficient tables here) | ||
| 14 | + | ||
| 15 | +i.e. an INTRA-frame refusal owned by lane-rectchroma, not "an INTER 32x32 partition | ||
| 16 | +type ... (value=9)". The charter's `value=9` observation was made on lane-rectchroma | ||
| 17 | +587d388, a tree where that intra refusal is already lifted. So ReelC's *next* blocker | ||
| 18 | +after rectchroma merges is plausibly the inter 1:4 arm, but this lane cannot observe it. | ||
| 19 | + | ||
| 20 | +## The real ceiling this round found | ||
| 21 | + | ||
| 22 | +`decode_inter_block` refuses every NON-SKIP rectangular inter block: | ||
| 23 | + | ||
| 24 | + decode.rs:12938 "a non-skip rectangular (HORZ/VERT/HORZ_B) strip needs | ||
| 25 | + rectangular residual coding" | ||
| 26 | + | ||
| 27 | +Rectangular inter residual coding does not exist. Empirically (30 aomenc recipes swept, | ||
| 28 | +`$HOME/.cache/inter4-probe`), every real stream that reaches an inter rect strip finds it | ||
| 29 | +non-skip and stops there — including every 10-bit attempt of this lane's own gate. | ||
| 30 | +Porting the partition ARMS is therefore necessary but not sufficient: the arms are | ||
| 31 | +reachable, but only an all-skip strip completes. | ||
| 32 | + | ||
| 33 | +## Changed | ||
| 34 | + | ||
| 35 | +- `crates/ec-av1/src/decode.rs` | ||
| 36 | + - `decode_inter_block`'s `at` is now in **MI (4 px) units**, not 16-px cells — a 32-level | ||
| 37 | + 1:4 strip sits at an 8-px offset the old unit could not name. All 20 call sites wrapped | ||
| 38 | + in the new `sub16_to_mi` helper; the body routes through `around_mi`, | ||
| 39 | + `record_rect_mi` (new), `record_split_luma_rect_mi` (new), `record_inter_rect_mi`, | ||
| 40 | + `record_compound_ctx_rect_mi`. `record_rect`/`record_split_luma_rect` now delegate to the | ||
| 41 | + new mi variants, so there is one implementation each. | ||
| 42 | + - `motion_mode`/`obmc` CDF row selection: `bsize_idx` is a full `(write_w, write_h)` match | ||
| 43 | + over every shape the decoder can now reach; an unknown shape refuses by name instead of | ||
| 44 | + reading the wrong-width alphabet (class wrong-alphabet-same-value). | ||
| 45 | + - `interintra` is no longer read on a 1:4 strip: `is_interintra_allowed_bsize` is | ||
| 46 | + `BLOCK_8X8..=BLOCK_32X32` in libaom's ENUM ORDER, which excludes BLOCK_8X32 (18) and | ||
| 47 | + BLOCK_32X8 (19) even though both dimensions are in range (class | ||
| 48 | + equal-range-means-unread / symbol the reference never wrote). | ||
| 49 | + - `maybe_read_delta_q`/`_lf`'s `is_whole_sb` is now `bsize == sbSize` (`side == 64 && | ||
| 50 | + write_w == 64 && write_h == 64`), not `side == 64` — a 64x32 strip's `skip` must not | ||
| 51 | + suppress the read. | ||
| 52 | + - inter tile, superblock level: `PARTITION_HORZ`/`VERT`/`HORZ_4`/`VERT_4` arms | ||
| 53 | + (two 64x32/32x64 strips, four 64x16/16x64 ones) with libaom's `i > 0` frame-edge break. | ||
| 54 | + AB at superblock level still refuses, by a new named string. | ||
| 55 | + - inter tile, 32x32 level: `PARTITION_HORZ_4`/`VERT_4` arms (four 32x8 / 8x32 strips, | ||
| 56 | + quarter step 2 mi). | ||
| 57 | + - new counters + accessors: `rect4_32_{horz,vert}_inter_hits`, | ||
| 58 | + `inter_sb_{horz,vert,horz4,vert4}_hits`. | ||
| 59 | + - a local `inter_piece!` macro carries the shared 50-argument call instead of six more copies. | ||
| 60 | +- `crates/ec-av1/src/cdf.rs`, `cdf_state.rs` — `OBMC`/`MOTION_MODE` widened 6 -> 12 rows with | ||
| 61 | + libaom's BLOCK_32X64/64X32/8X32/32X8/16X64/64X16 rows (`default_{obmc,motion_mode}_cdf`, | ||
| 62 | + `entropymode.c:549,562` of the oracle source). | ||
| 63 | +- `crates/ec-av1/src/refusal_inventory.rs` — the SB-level string now names AB only; new | ||
| 64 | + "a motion_mode symbol for a block shape this decoder has no CDF row for". | ||
| 65 | +- `crates/ec-av1/src/stream.rs` — `inter_rect_counters()` + the new gate. | ||
| 66 | +- `crates/ec-av1/examples/decode_probe.rs` — prints the six inter rect counters. | ||
| 67 | + | ||
| 68 | +## Gate | ||
| 69 | + | ||
| 70 | +`a_real_aomenc_inter_sequence_with_a_superblock_level_rect_partition_decodes_pixel_exact` | ||
| 71 | +(stream.rs). 16 attempts x {2 orientations, 4 quantisers, 2 motion steps}, 192x128, 6 frames, | ||
| 72 | +`--min-partition-size=32 --max-partition-size=64 --enable-rect-partitions=1 | ||
| 73 | +--enable-1to4-partitions=1 --lag-in-frames=0 --cpu-used=0` (overrides last, aomenc keeps the | ||
| 74 | +last occurrence). Noiseless split-motion source (one half translating, the other static) is | ||
| 75 | +what makes aomenc's RD pick a superblock HORZ whose strips are `skip`. Every decoded frame is | ||
| 76 | +compared Y/U/V to ffmpeg; refusals are counted, never SKIPped; a decoded attempt that carried | ||
| 77 | +no rect strip is still required to be pixel-exact. | ||
| 78 | + | ||
| 79 | + EC_AV1_REQUIRE_AOMENC=1 cargo test -p ec-av1 --lib superblock_level_rect_partition -- --nocapture | ||
| 80 | + | ||
| 81 | +EVIDENCE: $HOME/.cache/inter4-suite.log + `cargo test -p ec-av1 --lib superblock_level_rect_partition` | 16 aomenc encodes, decode + ffmpeg Y/U/V pixel compare over 6 frames each | 8-bit: 4 named refusals, 2 pixel-exact attempts carrying the arm, 64x32 strips=4, 32x64 strips=0, 10 out-of-scope (0 mismatched); gate ok. Full suite at commit 754a7dd: 321 passed / 2 failed / 30 ignored; both failures were stale pins of MINE (the SB refusal string and a line-continuation in a new refusal literal) and are fixed in the follow-up commit -- the suite has NOT been re-run end to end since. | ||
| 82 | + | ||
| 83 | +## Open residue (nothing here is claimed done) | ||
| 84 | + | ||
| 85 | +- **fix-now (r2): rectangular inter residual coding.** Until it exists no gate can cover a | ||
| 86 | + non-skip inter rect strip, and that is 100% of what real content produces. This blocks: | ||
| 87 | + the 32-level 1:4 inter arms (0 hits in every recipe swept), the SB-level VERT arm (fires, | ||
| 88 | + then its second strip is non-skip), the SB-level 1:4 arms, and the whole 10-bit side. | ||
| 89 | +- **deferred: the 10-bit twin of the new gate** — every 10-bit attempt found the strip | ||
| 90 | + non-skip. Unblocked by the item above. Written as an 8-bit-only loop with the reason in | ||
| 91 | + the source, not a weakened assert. | ||
| 92 | +- **deferred: SB-level AB inter partitions** — refused by name, no gate. Unblocked by the | ||
| 93 | + same residue (their pieces are rect too). | ||
| 94 | +- **accepted: `size_group` stays 3 for rect pieces** — inert (it only feeds the intra | ||
| 95 | + `y_mode` branch, which refuses non-square) and it matches the existing 32-level HORZ arm. | ||
| 96 | +- **DO NOT MERGE the two new arms as a capability claim**: the SB-level HORZ arm is gated, | ||
| 97 | + the SB-level VERT/1:4 and the 32-level 1:4 arms are NOT (class refusal-lifted-without-a-gate). | ||
lanes/inter4-r2.report.mdadded+128 -0
| @@ -0,0 +1,128 @@ | |||
| 1 | +# lane-inter4 r2 — rectangular INTER residual coding | ||
| 2 | + | ||
| 3 | +Branch `lane-inter4`, worktree `/home/user/Documents/Code/Rust/edith_codecs-inter4`, | ||
| 4 | +off r1's `59ccb01` (main `146896f`). No rebase this round (main unchanged since). | ||
| 5 | + | ||
| 6 | +## Owed from r1: the full suite at 59ccb01 | ||
| 7 | + | ||
| 8 | + $HOME/.cache/inter4-suite-r2a.log | ||
| 9 | + test result: ok. 323 passed; 0 failed; 30 ignored; finished in 458.10s | ||
| 10 | + | ||
| 11 | +r1's two self-failures were indeed fixed by `59ccb01`. | ||
| 12 | + | ||
| 13 | +EVIDENCE: $HOME/.cache/inter4-suite-r2a.log | ec-av1 --lib under systemd-run at 59ccb01 | 323 passed / 0 failed / 30 ignored | ||
| 14 | + | ||
| 15 | +## What this round built (capability present, NOT claimed proven) | ||
| 16 | + | ||
| 17 | +Rectangular inter residual coding for the 2:1 shapes whose tables exist — | ||
| 18 | +32x16 / 16x32 (`crates/ec-av1/src/decode.rs`): | ||
| 19 | + | ||
| 20 | +- `rect_inter_residual_supported` (decode.rs) — the shape gate. The r1 refusal | ||
| 21 | + string ("a non-skip rectangular (HORZ/VERT/HORZ_B) strip needs rectangular | ||
| 22 | + residual coding") is now conditional on it, so `refusal_inventory` is | ||
| 23 | + unchanged and 64x32/64x16/32x8/8x32/16x8 keep refusing by name. | ||
| 24 | +- `read_block_tx_size_rect` — spec 5.11.17 from the block's own *rect* | ||
| 25 | + `max_txsize_rect_lookup` entry. `TX_MODE_LARGEST`: no symbol, one rect TU. | ||
| 26 | + `TX_MODE_SELECT`: one depth-0 `txfm_partition` symbol whose context comes | ||
| 27 | + from the new `txfm_partition_ctx_rect` (above compares `tx_size_wide`, left | ||
| 28 | + `tx_size_high`, category from `txsize_sqr_up_map`); `0` leaves one rect TU, | ||
| 29 | + `1` splits into `sub_tx_size_map`'s two SQUARE sub-transforms from which the | ||
| 30 | + existing square `read_var_tx_size` continues at depth 1 — so every leaf of a | ||
| 31 | + split rect block is square and the existing square leaf loop reconstructs it. | ||
| 32 | +- `txfm_partition_update_rect` / the skipped-inter case — a skipped rect inter | ||
| 33 | + block records its own BLOCK width above and height left (libaom | ||
| 34 | + `set_txfm_ctxs(.., skip && is_inter)`), where r1 recorded a square `side` | ||
| 35 | + both ways. | ||
| 36 | +- `read_inter_plane_rect` + `embed_rect_grid` — rect coefficients via | ||
| 37 | + `read_coeffs_rect` (TxClass-aware scans/contexts), rect inverse via | ||
| 38 | + `dequant_and_inverse_typed_wh`, added onto the top-left `w x h` of the | ||
| 39 | + square-strided MC predictor. `txb_skip_ctx` 0 for luma (this unit IS the | ||
| 40 | + block: `get_txb_ctx`'s `plane_bsize == txsize_to_bsize[tx_size]` branch); | ||
| 41 | + chroma at `av1_get_max_uv_txsize` (16x8 / 8x16, `TxbSet::ChromaRect16x8`), | ||
| 42 | + inheriting the luma unit's `tx_type`. | ||
| 43 | +- `cdf_state.rs`: new `TxbSet::LumaRect32x16Inter` — `LumaRect32x16`'s | ||
| 44 | + coefficient tables (512-coefficient `eob_pt`) plus the inter `tx_type` | ||
| 45 | + alphabet `default_inter_ext_tx_cdf[3][TX_16X16]` (`EXT_TX_SET_DCT_IDTX`, | ||
| 46 | + which is what `av1_get_ext_tx_set_type` returns for an inter TU with | ||
| 47 | + `tx_size_sqr_up == TX_32X32`) — i.e. the existing `INTER_TX_TYPE_SET3_16`. | ||
| 48 | +- Two out-of-bounds fixes found by the new content (both in r1 code, both hit | ||
| 49 | + before any of this round's residual code runs): `around_mi(at, side)` read | ||
| 50 | + `side` cells left for a rect strip and indexed past the tile's last mi row | ||
| 51 | + (now `around_mi_rect(at_mi, write_w, write_h)` for a rect strip); and | ||
| 52 | + `record_rect_mi`/`record_split_luma_rect_mi` stamped past the frame's last | ||
| 53 | + 16-px column for an edge strip (now bounds-checked). | ||
| 54 | +- `EC_AV1_RECT_DUMP=1` prints the shape of every refused rect strip. | ||
| 55 | +- New counters `rect_inter_tu_hits` / `rect_inter_txsplit_hits` + accessors. | ||
| 56 | + | ||
| 57 | +## Gate — RED, kept and `#[ignore]`d with its exact reason | ||
| 58 | + | ||
| 59 | +`a_real_aomenc_inter_sequence_with_a_coded_rectangular_residual_decodes_pixel_exact` | ||
| 60 | +(stream.rs): 16 attempts x {2 axis-structured sources, 2 quantisers, 2 | ||
| 61 | +`--enable-tx-size-search` arms, 2 motion steps} x {8-bit, 10-bit}, 192x128, | ||
| 62 | +6 frames, `--enable-rect-partitions=1 --enable-ab-partitions=0 | ||
| 63 | +--enable-1to4-partitions=0 --min-partition-size=16 --max-partition-size=32`, | ||
| 64 | +overrides last; every decoded frame compared Y/U/V to ffmpeg, refusals counted | ||
| 65 | +never SKIPped, out-of-scope attempts still required pixel-exact. | ||
| 66 | + | ||
| 67 | +It never fires, and the reason is NOT the residual code: on real motion content | ||
| 68 | +the decode stops earlier, every attempt, at one of | ||
| 69 | + | ||
| 70 | + an inter partition below 16x16 other than SPLIT (16x8/8x16 rect inter leaves are not coded yet) | ||
| 71 | + an intra-coded HORZ/VERT strip needs rectangular intra prediction this decoder does not code yet | ||
| 72 | + an inter partition below 8x8 ... | ||
| 73 | + | ||
| 74 | +so no stream ever reached a 32x16/16x32 inter strip. Content sweep this round | ||
| 75 | +(4 source families x cq 22..61): flat/banded sources make the strips `skip` | ||
| 76 | +(r1's case) or trip aomenc's screen-content detector into an intra-strip | ||
| 77 | +refusal; textured/natural ones reach 16-level rect leaves first. `EC_AV1_RECT_DUMP` | ||
| 78 | +on the earlier recipe showed the only rect shapes actually refused were 32x8 / | ||
| 79 | +8x32 (the 32-level 1:4 arms), never 32x16. | ||
| 80 | + | ||
| 81 | +EVIDENCE: `cargo test -p ec-av1 --lib coded_rectangular_residual -- --nocapture` | 16 aomenc encodes x 8-bit, decode + ffmpeg Y/U/V compare | 15 named refusals, 0 attempts carrying a rect inter residual, whole-block rect TUs=0 -- gate proved nothing, so it is `#[ignore]`d with that sentence, not weakened | ||
| 82 | + | ||
| 83 | +EVIDENCE: `cargo test -p ec-av1 --lib superblock_level_rect_partition -- --nocapture` | r1's skip-strip gate re-run on this round's tree | 4 named refusals, 2 pixel-exact attempts carrying the arm, 64x32 strips=4, 0 mismatches -- the rect skip-context change did not regress it | ||
| 84 | + | ||
| 85 | +## Suite | ||
| 86 | + | ||
| 87 | + $HOME/.cache/inter4-suite-r2.log (systemd-run, unit inter4-suite-r2) | ||
| 88 | + test result: ok. 323 passed; 0 failed; 31 ignored; finished in 410.27s | ||
| 89 | + | ||
| 90 | +Same 323 passing as the 59ccb01 baseline; the one extra ignored test is this | ||
| 91 | +round's red gate. | ||
| 92 | + | ||
| 93 | +EVIDENCE: $HOME/.cache/inter4-suite-r2.log | ec-av1 --lib under systemd-run at b9dec1f | 323 passed / 0 failed / 31 ignored | ||
| 94 | + | ||
| 95 | +Sibling gates inside that run: inter_sequence*, 8x8_leaf_split, tx_select, | ||
| 96 | +superblock_level_*, obmc, warp, globalmv, force_integer_mv, refusal_inventory, | ||
| 97 | +gate_coverage -- all green. | ||
| 98 | + | ||
| 99 | +## Residue | ||
| 100 | + | ||
| 101 | +- **fix-now (r3): 16x8/8x16 inter rect leaves.** They are the real reach | ||
| 102 | + blocker: real content codes one before any 32-level 2:1 strip. Needs (a) the | ||
| 103 | + 16-level rect inter partition arm, (b) `default_inter_ext_tx_cdf[2][TX_8X8]` | ||
| 104 | + (12-symbol `DTT9_IDTX_1DDCT` at `tx_size_sqr == TX_8X8`, reachable only | ||
| 105 | + through a rect transform) as a new CDF + adaptation field, (c) a | ||
| 106 | + `TxbSet::LumaRect16x8Inter`. The residual machinery this round added then | ||
| 107 | + covers them unchanged. | ||
| 108 | +- **deferred: the 32x16/16x32 gate** — unblocked by the item above (or by a | ||
| 109 | + recipe that reaches a 32-level strip first; four source families did not). | ||
| 110 | +- **deferred: 64x32/32x64/64x16/16x64 and 32x8/8x32 rect residual** — 64-point | ||
| 111 | + and 1:4 rect transforms have no coefficient tables here; still refused by name. | ||
| 112 | +- **deferred: film probe** — not re-run: r1 measured both ReelC extracts stopping | ||
| 113 | + at lane-rectchroma's INTRA refusal ("a coded HORZ/VERT strip whose chroma | ||
| 114 | + transform has no rect coefficient tables here"), which nothing in this diff | ||
| 115 | + touches. | ||
| 116 | +- **accepted: a rect block's luma/chroma coefficient grid is embedded in the | ||
| 117 | + square grid** the downstream neighbour/deblock stamps expect (top-left | ||
| 118 | + placement). The split-leaf path already hands those stamps an all-zero square | ||
| 119 | + grid, so this is strictly more information than the shipping behaviour. | ||
| 120 | +- **open (not this lane's shape): 1-2 attempts per recipe decode fully with | ||
| 121 | + ZERO rect inter transform units and still MISMATCH ffmpeg** on 192x128 | ||
| 122 | + rect-partition inter content. Proven pre-existing for the banded recipe: with | ||
| 123 | + r1's square skip-context recording restored the same three attempts mismatch | ||
| 124 | + identically, so it is not this round's change. Not bisected (budget). | ||
| 125 | +- **DO NOT MERGE as a capability claim**: rectangular inter residual coding is | ||
| 126 | + implemented and compiles, and is exercised by no green gate (class | ||
| 127 | + refusal-lifted-without-a-gate). The refusal itself is still in place for every | ||
| 128 | + shape but 32x16/16x32. | ||
lanes/inter4-r3.report.mdadded+125 -0
| @@ -0,0 +1,125 @@ | |||
| 1 | +# lane-inter4 r3 — the 16x16-level rectangular INTER leaf | ||
| 2 | + | ||
| 3 | +Branch `lane-inter4`, worktree `/home/user/Documents/Code/Rust/edith_codecs-inter4`, | ||
| 4 | +off r2's `d2d7327` (main `11633d7`). No rebase needed (main unchanged since r2). | ||
| 5 | + | ||
| 6 | +## What shipped (commit `d913935`) | ||
| 7 | + | ||
| 8 | +The refusal r2 named as the reach blocker is gone: `PARTITION_HORZ`/`PARTITION_VERT` | ||
| 9 | +at 16x16 on an inter frame now decodes two 16x8 / 8x16 inter blocks. | ||
| 10 | + | ||
| 11 | +- `crates/ec-av1/src/decode.rs` (16-level partition site, ~17930): the HORZ/VERT | ||
| 12 | + arms. `side = SUB` keeps every CDF / prediction-buffer decision square (the | ||
| 13 | + corner-cut the 32-level rect arm already ships), `write_w`/`write_h` carry the | ||
| 14 | + true 16x8 / 8x16 footprint into the mv stack, the motion-mode row, the neighbour | ||
| 15 | + stamps and the rect residual path. AB / 1:4 at 16 refuse by name. | ||
| 16 | +- `rect_inter_residual_supported` + `rect_inter_luma_set` / `rect_inter_chroma_set` | ||
| 17 | + (decode.rs ~9020): 16x8/8x16 joins 32x16/16x32; the residual call sites pick the | ||
| 18 | + TxbSet from the block's TRUE shape instead of the hard-coded 32x16 pair. | ||
| 19 | +- `TxbSet::LumaRect16x8Inter` / `LumaRect16x8InterSet1` (cdf_state.rs): | ||
| 20 | + `LumaRect16x8`'s coefficient tables with the INTER `tx_type` alphabet. | ||
| 21 | + `av1_get_ext_tx_set_type(TX_16X8, is_inter=1, reduced)` = `EXT_TX_SET_DCT_IDTX` | ||
| 22 | + reduced, `EXT_TX_SET_ALL16` otherwise (`tx_size_sqr == TX_8X8`, not TX_16X16), | ||
| 23 | + both at the **TX_8X8** CDF row -- i.e. the existing `inter_tx_type_8` / | ||
| 24 | + `inter_tx_type_8_set1` tables, no new CDF and no new counter-reset entry. | ||
| 25 | + **r2's report was wrong here** (it predicted the 12-symbol | ||
| 26 | + `default_inter_ext_tx_cdf[2][TX_8X8]`); checked against | ||
| 27 | + `blockd.h:1092-1122` + `av1_num_ext_tx_set = {1,2,5,7,12,16}` in the oracle tree. | ||
| 28 | +- **Defect found in shipped code (class: table narrowed to the reachable sizes):** | ||
| 29 | + `eob_pt_128_luma_class1` and `eob_pt_32_chroma_class1` did not exist, so | ||
| 30 | + `LumaRect16x8`/`LumaRect16x8Set1` (the INTRA rect leaf, already shipping) and | ||
| 31 | + `ChromaRect8x4` fell back to the 2D `eob_pt` alphabet for `V_DCT`/`H_DCT` | ||
| 32 | + units. Added from `token_cdfs.h:792-848` (plane 0 / plane 1, class index 1), | ||
| 33 | + wired into all four `LumaRect16x8*` sets, `ChromaRect8x4`, and the per-frame | ||
| 34 | + `reset1` list. | ||
| 35 | +- **Second defect in shipped code:** `obmc_blend`'s `max_nb` closure was | ||
| 36 | + `1..=4 => 2`, while libaom's `max_neighbor_obmc[] = {0,1,2,3,4,4}` indexed by | ||
| 37 | + `mi_size_{wide,high}_log2` gives 0 for 1 mi and 1 for 2 mi. Only a block under | ||
| 38 | + 16 px on that axis can expose it -- i.e. exactly this round's leaves. | ||
| 39 | +- `size_group_wh` (decode.rs): `y_mode` (intra block in an inter frame) and the | ||
| 40 | + `interintra` / `interintra_mode` rows now come from `size_group_lookup[bsize]` | ||
| 41 | + of the block's TRUE footprint. The 32-level rect strips were reading the square | ||
| 42 | + row (3 where libaom says 2); a 16x8 leaf would have read 2 where libaom says 1. | ||
| 43 | + Deviation from charter: not requested, but it is the same defect shape and one | ||
| 44 | + helper covers every caller. | ||
| 45 | +- `MOTION_MODE` / `OBMC` CDFs extended from 12 to 14 packed rows with libaom's | ||
| 46 | + `BLOCK_8X16` (index 4) and `BLOCK_16X8` (index 5) entries. | ||
| 47 | + | ||
| 48 | +## Gate — GREEN | ||
| 49 | + | ||
| 50 | +`a_real_aomenc_inter_sequence_with_a_16_level_rect_leaf_decodes_pixel_exact` | ||
| 51 | +(stream.rs): 16 attempts x {2 axis-structured sources, 2 quantisers, 2 | ||
| 52 | +`--enable-tx-size-search` arms, 2 motion steps} x {8-bit, 10-bit}, 192x128, 6 | ||
| 53 | +frames, `--enable-rect-partitions=1 --enable-ab-partitions=0 | ||
| 54 | +--enable-1to4-partitions=0 --min-partition-size=8 --max-partition-size=16 | ||
| 55 | +--enable-obmc=0`, per-arm overrides LAST. Every decoded frame compared Y/U/V vs | ||
| 56 | +ffmpeg; a refusal is counted, never SKIPped; an attempt carrying no 16-level rect | ||
| 57 | +leaf is still required pixel-exact (`oos_mismatch == 0`). Hard asserts: a | ||
| 58 | +pixel-exact attempt carrying a 16x8 leaf AND one carrying an 8x16 leaf, per bit | ||
| 59 | +depth, plus at least one coded (non-skip) rectangular inter transform unit across | ||
| 60 | +the two depths. | ||
| 61 | + | ||
| 62 | + cargo test -p ec-av1 --lib 16_level_rect_leaf -- --nocapture | ||
| 63 | + | ||
| 64 | +EVIDENCE: $HOME/.cache/inter4-suite-r3.log (gate line) | 32 aomenc encodes, decode + ffmpeg Y/U/V compare of every frame | 8-bit: 6 refusals, 5 pixel-exact leaf-carrying attempts, 16x8=3, 8x16=2, coded rect TUs=2, 0 mismatches; 10-bit: 2 refusals, 4 leaf-carrying attempts, 16x8=2, 8x16=3, 0 mismatches | ||
| 65 | + | ||
| 66 | +## Refusals | ||
| 67 | + | ||
| 68 | +Lifted: `"an inter partition below 16x16 other than SPLIT (16x8/8x16 rect inter | ||
| 69 | +leaves are not coded yet)"`. | ||
| 70 | + | ||
| 71 | +Added (both in `refusal_inventory.rs`, both named, both narrow): | ||
| 72 | + | ||
| 73 | +- `"an inter 16x16-level AB or 1:4 partition (HORZ_A/HORZ_B/VERT_A/VERT_B/HORZ_4/VERT_4; ...)"` | ||
| 74 | +- `"OBMC on a 16x8/8x16 inter leaf (blend mismatches the reference on this shape)"` | ||
| 75 | + | ||
| 76 | +## The OBMC residue (open, instrumented) | ||
| 77 | + | ||
| 78 | +With `--enable-obmc=1` and everything else identical, attempt 10 (8-bit, cq 22, | ||
| 79 | +tx-size-search off) decodes all 6 frames but frame 5 has **5302 luma pixels | ||
| 80 | +wrong, max |delta| 84, first at (176,0)**; frames 0-4 are exact. The same recipe | ||
| 81 | +with `--enable-obmc=0` decodes 5 leaf-carrying attempts pixel-exact, and a run | ||
| 82 | +with obmc/warp/interintra/masked-compound ALL off is also exact -- re-enabling | ||
| 83 | +obmc alone reproduces it, so warp, interintra and masked compound are exonerated | ||
| 84 | +for this shape. The blend geometry in `obmc_blend` was checked element by element | ||
| 85 | +against libaom `build_obmc_inter_pred_above`/`_left` and | ||
| 86 | +`av1_skip_u4x4_pred_in_obmc` and matches for these shapes; `max_neighbor_obmc` | ||
| 87 | +was wrong and is fixed, but the fix left the mismatch byte-identical, so the | ||
| 88 | +cause is upstream of the blend (the neighbour walk's `size`/`size_h` stamps for a | ||
| 89 | +rect leaf, or `has_top_right`, whose doc still says "no rectangular partition | ||
| 90 | +ever produces an inter leaf here"). Refused by name rather than shipped. | ||
| 91 | + | ||
| 92 | +EVIDENCE: gate run with `--enable-obmc=1` | same 16 attempts, decode + ffmpeg compare | attempt 10 frame 5: 5302 luma pixels differ, max |delta| 84; with `--enable-obmc=0`: 0 mismatches over 5 leaf-carrying attempts | ||
| 93 | + | ||
| 94 | +## Suite | ||
| 95 | + | ||
| 96 | + $HOME/.cache/inter4-suite-r3.log (systemd user unit inter4-suite-1788315557) | ||
| 97 | + test result: ok. 324 passed; 0 failed; 31 ignored; finished in 412.37s | ||
| 98 | + | ||
| 99 | +Same 323 as r2's baseline plus this round's new gate; the one ignored addition | ||
| 100 | +is still r2's own 32x16/16x32 gate. Sibling gates inside that run: every | ||
| 101 | +`inter_sequence*`, `8x8_leaf_split`, `tx_select`, `superblock_level_rect_partition`, | ||
| 102 | +`obmc`, `warp`, `globalmv`, `force_integer_mv`, `refusal_inventory`, | ||
| 103 | +`gate_coverage` -- all green, including the ones that read the tables this round | ||
| 104 | +touched (`MOTION_MODE`/`OBMC` rows, `LumaRect16x8*`, `ChromaRect8x4`). | ||
| 105 | + | ||
| 106 | +EVIDENCE: $HOME/.cache/inter4-suite-r3.log | ec-av1 --lib under a systemd user unit at d913935 | 324 passed / 0 failed / 31 ignored | ||
| 107 | + | ||
| 108 | +## Residue | ||
| 109 | + | ||
| 110 | +- **fix-now (r4): OBMC on a 16x8/8x16 leaf** -- named refusal today. Next step is | ||
| 111 | + `has_top_right` for rect inter blocks (libaom's `xd->width < xd->height` / | ||
| 112 | + `> ` / `PARTITION_VERT_A` branches are dropped in our copy) and the | ||
| 113 | + `overlappable_above/left` step caps (`AOMMIN(xd->width, mi_size_wide[nb])`). | ||
| 114 | +- **deferred: r2's 32x16/16x32 gate** (`..._with_a_coded_rectangular_residual_...`) | ||
| 115 | + -- still `#[ignore]`d; not re-measured this round (budget). With the 16-level | ||
| 116 | + leaves reachable it may now get past its first rect strip; unblocked by simply | ||
| 117 | + re-running it, which r4 should do before anything else. | ||
| 118 | +- **deferred: 16x16 SPLIT under this recipe** -- the gate counts `16x16 SPLITs=0` | ||
| 119 | + on every attempt (aomenc picks NONE/HORZ/VERT at 16 here); the 8x8-leaf path is | ||
| 120 | + gated by its own sibling test, so the count is printed, not asserted. | ||
| 121 | +- **accepted: the 10-bit arm proves no residual** -- every 10-bit rect leaf in | ||
| 122 | + this recipe is `skip` at cq 34/22, and cq 30/26 or 24/12 stops reaching a rect | ||
| 123 | + leaf at all (measured). The residual half is asserted across both depths. | ||
| 124 | +- **accepted: `_size_group` is now a dead parameter** of `decode_inter_block` | ||
| 125 | + (superseded by `size_group_wh`), kept rather than editing twenty call sites. | ||
lanes/inter4-r4.report.mdadded+142 -0
| @@ -0,0 +1,142 @@ | |||
| 1 | +# lane-inter4 r4 — OBMC on a 16x8/8x16 inter leaf (refusal lifted, gated) | ||
| 2 | + | ||
| 3 | +Branch `lane-inter4`, worktree `/home/user/Documents/Code/Rust/edith_codecs-inter4`, | ||
| 4 | +off r3's `96847a3`, with `lane-interbis` (`8a6bede`, `build_motion_field`'s compound | ||
| 5 | +slot walk) merged FIRST as chartered. | ||
| 6 | + | ||
| 7 | +## TASK 1 — r2's ignored 32x16/16x32 gate: re-measured, STILL RED, blocker moved | ||
| 8 | + | ||
| 9 | + cargo test -p ec-av1 --lib coded_rectangular_residual -- --ignored --nocapture | ||
| 10 | + | ||
| 11 | +`a_real_aomenc_inter_sequence_with_a_coded_rectangular_residual_decodes_pixel_exact` | ||
| 12 | +still cannot prove itself: over its 16 8-bit attempts, **12 named refusals** — 10 of | ||
| 13 | +them `"an intra-coded HORZ/VERT strip needs rectangular intra prediction this decoder | ||
| 14 | +does not code yet"` and 2 `"an inter 16x16-level AB or 1:4 partition ..."` — and the | ||
| 15 | +other 4 attempts decode with **zero** rect inter residual (`tu=0`, `split=0`, 0 | ||
| 16 | +mismatches). So the 16-level leaf landing in r3 did NOT unblock it: what stops these | ||
| 17 | +streams now is rectangular *intra* prediction, another lane's refusal. Kept `#[ignore]`, | ||
| 18 | +with the reason string replaced by that measurement (stream.rs:4902). | ||
| 19 | + | ||
| 20 | +EVIDENCE: $HOME/.cache/inter4-t1.log | 16 aomenc encodes, decode + counter read | 12 named refusals (10 intra-rect-strip, 2 inter AB/1:4), 4 attempts with tu=0/split=0, 0 mismatches | ||
| 21 | + | ||
| 22 | +## TASK 2 — the OBMC residue: no defect left; refusal lifted | ||
| 23 | + | ||
| 24 | +r3 refused `"OBMC on a 16x8/8x16 inter leaf (blend mismatches the reference on this | ||
| 25 | +shape)"` off a measured 5302-luma-pixel mismatch (attempt 10, 8-bit, cq 22, frame 5). | ||
| 26 | +Re-measured on THIS tree before touching any code: | ||
| 27 | + | ||
| 28 | +- Rebuilt that exact stream from the gate's attempt-10 recipe with `--enable-obmc=1` | ||
| 29 | + (`scratchpad/o10.obu`, md5 `b643a93a8db45e2a1b89b2d777147ee3`, 828 B). | ||
| 30 | +- Added an `EC_OBMC` rung to the oracle `aomdec` | ||
| 31 | + (`dec_build_prediction_by_above_pred` / `_left_pred`, printing the block, the | ||
| 32 | + neighbour's rel position, `op_mi_size`, mv, ref, bsize, filter) and the matching | ||
| 33 | + rung to our `obmc_blend`, then compared. | ||
| 34 | + | ||
| 35 | +Both decoders emit **exactly 9 OBMC neighbour invocations**, in the same order, with | ||
| 36 | +identical block shape, `off4`/`rel`, `span4`/`op_mi_size`, neighbour mv, ref frame and | ||
| 37 | +filter — including the three on `wh=(8x16)` leaves. And every one of the six | ||
| 38 | +`EC_AV1_PREFILT_DUMP` frames is **byte-identical** between our decoder and aomdec | ||
| 39 | +(luma diff 0 on f0..f5). There is nothing left to fix on this shape: the mismatch r3 | ||
| 40 | +saw is gone. The only decode-path change between r3's measurement and this one is the | ||
| 41 | +lane-interbis merge (temporal MV candidates); not bisected further. | ||
| 42 | + | ||
| 43 | +EVIDENCE: scratchpad/{ours.obmc,ref.obmc,ours.yuv.f0-5,ref.yuv.f0-5} | EC_OBMC + EC_AV1_PREFILT_DUMP on o10.obu, ours (release decode_probe) vs instrumented aomdec | 9 vs 9 identical neighbour lines; per-frame luma diff 0/0/0/0/0/0 | ||
| 44 | + | ||
| 45 | +### What shipped | ||
| 46 | + | ||
| 47 | +- `crates/ec-av1/src/decode.rs` (`obmc_blend`, ~12843): the `(16,8)|(8,16)` refusal | ||
| 48 | + deleted; in its place the new `OBMC_RECT_LEAF_HITS` counter (+ `obmc_rect_leaf_hits()` | ||
| 49 | + at ~1355) that the gate reads. | ||
| 50 | +- `crates/ec-av1/src/refusal_inventory.rs`: the OBMC-rect-leaf string removed. | ||
| 51 | +- `crates/ec-av1/src/stream.rs` (`..._with_a_16_level_rect_leaf_...`, ~5090): the sweep | ||
| 52 | + runs **32 attempts** now — the same 16 (2 sources x 2 quantisers x 2 tx-size-search | ||
| 53 | + arms x 2 motion steps) with `--enable-obmc=0`, then repeated with `--enable-obmc=1` | ||
| 54 | + as the LAST flag. New hard assert per bit depth: `obmc_leaf_proved > 0`. | ||
| 55 | +- `crates/ec-av1/src/stream.rs` ~1948: the hidden-frames gate's `--enable-obmc=0` | ||
| 56 | + comment no longer cites a refusal that does not exist. | ||
| 57 | + | ||
| 58 | +### Gate — GREEN | ||
| 59 | + | ||
| 60 | + cargo test -p ec-av1 --lib 16_level_rect_leaf -- --nocapture | ||
| 61 | + | ||
| 62 | +- 8-bit: 15 named refusals, 9 pixel-exact leaf-carrying attempts (16x8=5, 8x16=4), | ||
| 63 | + whole-block rect TUs=4, **OBMC blends on a rect leaf=10**, 8 attempts carried none | ||
| 64 | + (0 mismatched). | ||
| 65 | +- 10-bit: 4 named refusals, 8 pixel-exact leaf-carrying attempts (16x8=4, 8x16=6), | ||
| 66 | + **OBMC blends on a rect leaf=4**, 20 carried none (0 mismatched). | ||
| 67 | + | ||
| 68 | +EVIDENCE: $HOME/.cache/inter4-g4.log | 64 aomenc encodes (32 attempts x 2 depths), every decoded frame Y/U/V vs ffmpeg | test result: ok. 1 passed; 0 failed; OBMC-on-rect-leaf blends 10 (8-bit) / 4 (10-bit), 0 mismatches | ||
| 69 | + | ||
| 70 | +## Verifier findings folded in (r4, after the OBMC commit) | ||
| 71 | + | ||
| 72 | +1. **`size_group_wh` was wrong for a 4-px side** (decode.rs ~9126): libaom | ||
| 73 | + `size_group_lookup[BLOCK_SIZES_ALL]` (`common_data.h:60`) is **0** for | ||
| 74 | + BLOCK_4X4/4X8/8X4/4X16/16X4, and our `0..=8 => 1` row gave those group 1 -- | ||
| 75 | + the `y_mode` / `interintra` / `interintra_mode` CDF row of every sub-8 leaf. | ||
| 76 | + Fixed, and pinned by a new unit test `size_group_wh_matches_libaom_size_group_lookup` | ||
| 77 | + that enumerates all 22 `BLOCK_SIZES_ALL` entries against the transcribed table | ||
| 78 | + (class enumerate-the-table-domain). | ||
| 79 | + | ||
| 80 | + cargo test -p ec-av1 --lib size_group_wh_matches -- --nocapture | ||
| 81 | + | ||
| 82 | +2. **rect var-tx SPLIT and the 10-bit coded rect TU are shipped unexercised.** | ||
| 83 | + Swept cq {8,12,16,22} x both source axes x both depths with tx-size-search on, | ||
| 84 | + reading `decode_probe`'s new `rect_inter: tu=.. txsplit=.. obmc_leaf=..` line: | ||
| 85 | + `txsplit=0` in every single decoding attempt, and every 10-bit rect leaf is | ||
| 86 | + `skip` (`tu=0`) at every cq that decodes at all. Below cq 22 the attempts stop | ||
| 87 | + at another lane's refusal -- mostly `"a HORZ/VERT intra strip below 16x16 with | ||
| 88 | + a split transform (per-unit rect prediction is not ported)"`, plus the sub-16 | ||
| 89 | + `HORZ_A/HORZ_B/VERT_A` and 32-level 1:4 ones. Deviation from the verifier's | ||
| 90 | + ask, stated: I did NOT add an `#[ignore]`d pin -- an ignored test that runs | ||
| 91 | + nothing carries the same information as the measurement now written into the | ||
| 92 | + gate's own comment (stream.rs ~5097) and into the residue below, at less code. | ||
| 93 | + The asserts stay where the feature does fire (8-bit `tu_total > 0`). | ||
| 94 | + | ||
| 95 | +3. `stream.rs` "aomenc keeps the last occurrence of a repeated `--enable-*` flag" | ||
| 96 | + is CORRECT (class aomenc-first-flag-wins is about `--enable-*` repeats resolving | ||
| 97 | + to the last one, and it is what the r4 obmc arm relies on) -- left unchanged. | ||
| 98 | + | ||
| 99 | +4. `cdf.rs` doc slip fixed: `EOB_PT_128_CHROMA_CLASS1_Q0` had lost its doc comment | ||
| 100 | + to the `EOB_PT_128_LUMA_CLASS1_Q0` block added in r3; moved back. | ||
| 101 | + | ||
| 102 | +EVIDENCE: sweep output in this round's transcript | 16 aomenc encodes (cq 8/12/16/22 x 2 axes x 8/10-bit) decoded through release decode_probe | txsplit=0 in all 7 decoding attempts, 10-bit tu=0 in all 4, 8-bit cq22 tu=1 txsplit=0 obmc_leaf=1 | ||
| 103 | + | ||
| 104 | +## Refusals | ||
| 105 | + | ||
| 106 | +Lifted: `"OBMC on a 16x8/8x16 inter leaf (blend mismatches the reference on this shape)"`. | ||
| 107 | +None added. | ||
| 108 | + | ||
| 109 | +## Suite | ||
| 110 | + | ||
| 111 | + $HOME/.cache/inter4-suite-r4.log | ||
| 112 | + | ||
| 113 | + test result: ok. 326 passed; 0 failed; 31 ignored; finished in 776.14s | ||
| 114 | + | ||
| 115 | +r3's 324 + the lane-interbis gate + this round's `size_group_wh` unit test; the 31 | ||
| 116 | +ignored are unchanged (still including r2's 32x16/16x32 gate). Every sibling ran in | ||
| 117 | +it: `obmc*`, `16_level_rect_leaf`, `superblock_level_rect_partition`, | ||
| 118 | +`inter_sequence*`, `temporal_mv_candidates`, `refusal_inventory`, `gate_coverage`. | ||
| 119 | + | ||
| 120 | +EVIDENCE: $HOME/.cache/inter4-suite-r4.log | ec-av1 --lib under a systemd user unit at b0588e4 + this report | 326 passed / 0 failed / 31 ignored | ||
| 121 | + | ||
| 122 | +## Film | ||
| 123 | + | ||
| 124 | +`scratchpad/hg-head.obu` through the release `decode_probe` on this lane still stops at | ||
| 125 | +`unsupported: AV1 tile (filter intra on a HORZ/VERT strip (this decoder predicts | ||
| 126 | +square-only))` — an intra refusal owned by another lane, unchanged by this round. | ||
| 127 | + | ||
| 128 | +EVIDENCE: scratchpad/hg-head.obu | release decode_probe under a 6G scope | REFUSED: filter intra on a HORZ/VERT strip | ||
| 129 | + | ||
| 130 | +## Residue | ||
| 131 | + | ||
| 132 | +- deferred: r2's 32x16/16x32 rect-residual gate — still `#[ignore]`d — unblocked by | ||
| 133 | + rectangular INTRA prediction (`an intra-coded HORZ/VERT strip ...`) landing, not by | ||
| 134 | + anything in this lane. | ||
| 135 | +- accepted: which change fixed r3's OBMC mismatch is not bisected (interbis merge is the | ||
| 136 | + only candidate); the shape is now proven exact against an instrumented aomdec, so the | ||
| 137 | + question is archaeology, not a defect. | ||
| 138 | +- deferred: the rect var-tx SPLIT path and a coded 10-bit rect TU are unexercised -- | ||
| 139 | + unblocked by the sub-16 intra-rect-strip refusal landing (every lower-cq attempt | ||
| 140 | + stops there before a rect inter leaf can carry a split tree). | ||
| 141 | +- accepted: `16x16 SPLITs=0` under this recipe (aomenc picks NONE/HORZ/VERT at 16); | ||
| 142 | + covered by the 8x8-leaf sibling gate. | ||
lanes/interbis-r1.report.mdadded+129 -0
| @@ -0,0 +1,129 @@ | |||
| 1 | +# lane-interbis r1 — the "decodes fully, still mismatches" inter defect | ||
| 2 | + | ||
| 3 | +Branch `lane-interbis`, worktree `edith_codecs-interbis`, off lane-inter4 `d2d7327`. | ||
| 4 | +No rebase (main unchanged since that base). | ||
| 5 | + | ||
| 6 | +## STEP 1 — reproduced and pinned | ||
| 7 | + | ||
| 8 | +The rect gate's 8-bit **attempt 1** is the one that decodes fully and mismatches: | ||
| 9 | +192x128, 6 frames @25, `geq=lum='128+58*sin((X+N*3)/6)+18*sin(Y/23)'`, cq 34, | ||
| 10 | +`--enable-tx-size-search=1`, `--min/max-partition-size=16/32`, cpu-used=0, lag 0. | ||
| 11 | +Regenerated twice, byte-identical: | ||
| 12 | +`fa70b7f68d311e577e3d14a86574909e6e58cac817b5a7fae04341c41ff50260` | ||
| 13 | +(script `$HOME/.cache/interbis/gen.sh`; 10-bit twin | ||
| 14 | +`67cad9bd5341db897de8a5308faecaedb1b0df761e4f315f1817156d124caef7`). | ||
| 15 | + | ||
| 16 | +Decode order == display order (no hidden frames; `--lag-in-frames=0`). | ||
| 17 | +Frames 0..4 exact; **frame 5** luma only, 646 px, bbox x160-191 y93-127, max delta 39. | ||
| 18 | +`EC_AV1_PREFILT_DUMP` (ours) vs the same rung from the instrumented aomdec: | ||
| 19 | +frames 0-4 byte-identical, frame 5 differs in 640 luma px at x160-191 y96-127 — | ||
| 20 | +i.e. **reconstruction**, not deblock/CDEF/LR, and exactly one 32x32 block: | ||
| 21 | +mi (row 24, col 40), the frame's last block. | ||
| 22 | + | ||
| 23 | +EVIDENCE: $HOME/.cache/interbis/{o_pre.f5,a_pre.f5} | EC_AV1_PREFILT_DUMP ours vs aomdec, per-frame byte diff | frames 0-4 identical, frame 5 640 luma px wrong in the single 32x32 block at mi(24,40) | ||
| 24 | + | ||
| 25 | +## STEP 2 — first divergent element | ||
| 26 | + | ||
| 27 | +Entropy is **exact**: the msac range ladder agrees at that block's entry | ||
| 28 | +(`EC_MODE ... rng=37852` both) and at the end of its mode read | ||
| 29 | +(`rng=59818` both). Both decoders read mode 13 (NEARESTMV), ref0=2 (LAST2), | ||
| 30 | +stack size 3. The **VALUE** differs: | ||
| 31 | + | ||
| 32 | + ours EC_MODE_VAL mi_row=24 mi_col=40 mode=13 ref0=2 mv0=(0,72) | ||
| 33 | + aomdec EC_MODE_VAL mi_row=24 mi_col=40 mode=13 ref0=2 mv0=(0,-230) | ||
| 34 | + | ||
| 35 | +New `EC_STACK` rung (added to both decoders) shows entries 1 and 2 identical | ||
| 36 | +(`(0,24) w=2`, `(0,-785) w=2`, the extra-search neighbours) and entry 0 — | ||
| 37 | +the temporal (MFMV) candidate — wrong: ours `(0,72) w=32`, aomdec `(0,-230) w=16`. | ||
| 38 | + | ||
| 39 | +New `EC_TPL` rung (per `add_tpl_ref_mv` probe, both decoders) isolates it to the | ||
| 40 | +projected motion field itself: over the 16 probes of that block, aomdec reads | ||
| 41 | +`INVALID` at blk_col 0/2 and `mfmv0=(0,-230) rfo=3` at blk_col 4/6; ours reads | ||
| 42 | +`mfmv0=(0,24) rfo=1` at all 16. `(0,24)*3/1 = (0,72)` — our wrong stored pair | ||
| 43 | +projected exactly to the wrong candidate. | ||
| 44 | + | ||
| 45 | +EVIDENCE: $HOME/.cache/interbis/{o_tpl.txt,a_tpl.txt} | EC_TRACE_MODE + EC_TRACE_TPL on both decoders, block mi(24,40) of frame 5 | ours mfmv0=(0,24) rfo=1 x16 vs aomdec INVALID x8 + (0,-230) rfo=3 x8; stack entry 0 (0,72) vs (0,-230) | ||
| 46 | + | ||
| 47 | +## Root cause (decode.rs `build_motion_field`, spec 7.19 / libaom `av1_copy_frame_mvs`) | ||
| 48 | + | ||
| 49 | +Our per-frame saved motion field stored **`ref_frame[0]`/`mv[0]` of every inter | ||
| 50 | +block**. libaom walks **both** reference slots and the **last qualifying one | ||
| 51 | +wins**, skipping a slot when | ||
| 52 | + | ||
| 53 | +* `cm->ref_frame_side[ref]` is non-zero — the reference's OrderHint is ahead of | ||
| 54 | + (or equal to) this frame's (`av1_calculate_ref_frame_side`), or | ||
| 55 | +* `|mv| > REFMVS_LIMIT` (`(1<<12)-1`). | ||
| 56 | + | ||
| 57 | +Every compound block in this stream is `LAST + GOLDEN` (both past), so libaom | ||
| 58 | +stores GOLDEN's mv with `ref_frame_offset = 3` where we stored LAST's with | ||
| 59 | +offset 1 — a wrong (mv, distance) pair in every compound block's 8x8 cell, which | ||
| 60 | +the next frame's temporal candidate then projects with the wrong reference | ||
| 61 | +distance. Class name: **saved-field-keeps-slot-0** — a per-frame/DPB *summary* | ||
| 62 | +of a multi-slot field must replay the reference's own slot walk (order + skips), | ||
| 63 | +not keep slot 0. (Sibling of `neighbour-votes-all-its-fields`: there the | ||
| 64 | +consumer voted only one slot, here the producer stores only one.) | ||
| 65 | + | ||
| 66 | +Fix: `crates/ec-av1/src/decode.rs:1728-1800` (`build_motion_field` now takes | ||
| 67 | +`order_hint_bits`, walks both slots last-wins, applies the side and | ||
| 68 | +`REFMVS_LIMIT` skips); call site `decode.rs:19040`. | ||
| 69 | + | ||
| 70 | +## Sweep | ||
| 71 | + | ||
| 72 | +`build_motion_field` is the only writer of `MotionField`/`SavedMv` | ||
| 73 | +(`grep -rn "SavedMv\|MotionField" crates/ec-av1/src`); the mv-stack neighbour | ||
| 74 | +maps already carry both slots (`MiInfo::ref_frame1`/`mv1`), and | ||
| 75 | +`motion_field_projection`/`setup_motion_field` were re-read line-for-line | ||
| 76 | +against `mvref_common.c` this round and match (one known, unreached gap noted | ||
| 77 | +below). | ||
| 78 | + | ||
| 79 | +## Gate — GREEN, and it binds | ||
| 80 | + | ||
| 81 | +`a_real_aomenc_inter_sequence_with_temporal_mv_candidates_decodes_pixel_exact` | ||
| 82 | +(`crates/ec-av1/src/stream.rs`, next to the rect gate): the pinned recipe above, | ||
| 83 | +2 tx-size-search arms x {8-bit, 10-bit}, every fully decoded attempt compared | ||
| 84 | +Y/U/V against ffmpeg, refusals counted (never SKIPped), and `decode::tmv_hits()` | ||
| 85 | +asserted > 0 per depth. | ||
| 86 | + | ||
| 87 | + cargo test -p ec-av1 --lib temporal_mv_candidates -- --nocapture | ||
| 88 | + 8-bit: 1 named refusal, 1 pixel-exact attempt, temporal-MV blocks = 66 | ||
| 89 | + 10-bit: 1 named refusal, 1 pixel-exact attempt, temporal-MV blocks = 67 | ||
| 90 | + test result: ok. 1 passed; 0 failed | ||
| 91 | + | ||
| 92 | +EVIDENCE: $HOME/.cache/interbis-tmvgate.log | cargo test -p ec-av1 --lib temporal_mv_candidates | 8-bit + 10-bit pixel-exact, tmv counter 66/67 | ||
| 93 | + | ||
| 94 | +Negative control (gate binds): with the store put back to first-slot-wins the | ||
| 95 | +same gate fails at `frame 5 luma vs ffmpeg (attempt 1, 8-bit)`. | ||
| 96 | + | ||
| 97 | +EVIDENCE: $HOME/.cache/interbis-tmvgate-neg.log | one-line revert to `if saved.is_none()` then re-run the gate | FAILED, frame 5 luma, restored immediately after | ||
| 98 | + | ||
| 99 | +## Instruments added (env-gated, both decoders) | ||
| 100 | + | ||
| 101 | +- ours: `EC_MODE_VAL` + `EC_STACK` on the single-ref path of `decode_inter_block` | ||
| 102 | + (byte-format-identical to the oracle's rung), `EC_TPL` per `add_tpl_ref_mv` probe. | ||
| 103 | +- oracle (`~/.cache/aom-oracle/src`): `EC_STACK` (stack dump at `EC_MODE_VAL`) and | ||
| 104 | + `EC_TPL` (per probe, incl. the `INVALID_MV` arm); `ninja aomdec` rebuilt. | ||
| 105 | + | ||
| 106 | +## Residue | ||
| 107 | + | ||
| 108 | +- **accepted: `motion_field_projection` does not check the source frame's | ||
| 109 | + frame_type.** libaom returns 0 for a KEY/INTRA_ONLY source; here an intra | ||
| 110 | + frame's saved field has no cells set, so the projection is inert — but its | ||
| 111 | + *return value* (which feeds `ref_stamp`) can differ. Unreached on every stream | ||
| 112 | + swept; fix-now if a future stream shows a `ref_stamp` divergence. | ||
| 113 | +- **deferred: the rect inter residual gate** stays `#[ignore]`d (lane-inter4's | ||
| 114 | + own residue, unblocked by 16x8/8x16 rect inter leaves); its | ||
| 115 | + `out_of_scope_mismatch` assert is what surfaced this defect and is now | ||
| 116 | + satisfiable on the 8-bit arm. | ||
| 117 | +- **deferred: film probe** — this diff lifts no refusal; both films still stop at | ||
| 118 | + lane-rectchroma's intra-rect-strip refusal. | ||
| 119 | + | ||
| 120 | +## Suite | ||
| 121 | + | ||
| 122 | + $HOME/.cache/interbis-suite.log (systemd-run unit, MemoryMax=10G) | ||
| 123 | + test result: ok. 324 passed; 0 failed; 31 ignored; finished in 443.08s | ||
| 124 | + | ||
| 125 | +323 (lane-inter4 r2 baseline) + this round's new gate. Siblings inside that run: | ||
| 126 | +inter_sequence*, obmc, warp, globalmv, compound_*, altref/hidden-frame, | ||
| 127 | +tx_select, refusal_inventory, gate_coverage — all green. | ||
| 128 | + | ||
| 129 | +EVIDENCE: $HOME/.cache/interbis-suite.log | ec-av1 --lib at 0527911 | 324 passed / 0 failed / 31 ignored | ||
lanes/oddh-r1.report.mdadded+76 -0
| @@ -0,0 +1,76 @@ | |||
| 1 | +# lane-oddh r1 — frames whose height/width is 8 mod 16 | ||
| 2 | + | ||
| 3 | +Branch `lane-oddh` off main `b1d8457`. Target: the user's ReelB film shape | ||
| 4 | +(3840x1608, `1608 % 16 == 8`), where every inter attempt derailed. | ||
| 5 | + | ||
| 6 | +## What the round established (measured, not reasoned) | ||
| 7 | + | ||
| 8 | +1. **The charter's premise is stale in its blame, right in its shape.** The refusal | ||
| 9 | + `"a non-DC chroma mode on an 8x8 inter-frame leaf"` is NOT what odd-height frames | ||
| 10 | + stop at once lane-golomb's edge-partition fix is present. Cherry-picking | ||
| 11 | + `eacd7fd` (clean, no conflicts) moves 192x136 to the same refusal its | ||
| 12 | + *even-height control* 192x128 hits, i.e. that one is width/content-related, not | ||
| 13 | + odd-height (see 4). | ||
| 14 | + | ||
| 15 | +2. **Minimal repro is 64x72, not 192x136.** With the standard inter-gate recipe | ||
| 16 | + (`--enable-rect-partitions=0 --min/max-partition-size=8/16`, mandelbrot, cq 40): | ||
| 17 | + - `64x64` decodes 4/4 frames pixel-exact (control), | ||
| 18 | + - `64x72` (bottom band 8 px) stopped at the key-frame 16-level edge refusal, | ||
| 19 | + - `72x64` (right band 8 px) stops in the inter tile path. | ||
| 20 | + | ||
| 21 | +3. **The real blocker underneath is a first-symbol desync of the KEY tile at | ||
| 22 | + height 72.** Not an edge-band defect at all: the *first* partition symbol of the | ||
| 23 | + frame diverges. | ||
| 24 | + `EVIDENCE: /tmp/.../scratchpad/k-64x72.obu (667 B, key frame only, aomenc cq40) | EC_AV1_TRACE=1 decode_probe vs EC_TRACE=1 aomdec | first element mi=(0,0) bsize=BLOCK_64X64 ctx=0: aomdec value=3 (PARTITION_SPLIT, tell=1 rng=32768), ours value=9` | ||
| 25 | + `EVIDENCE: /tmp/.../scratchpad/k-64x72.{ours,aom,ref}.y | aomdec --rawvideo + ffmpeg rawvideo vs our Y dump | aomdec == ffmpeg byte-for-byte; ours differs in 4583 of 4608 Y samples (whole frame), while the 64x64 control differs in 0` | ||
| 26 | + Our tile payload starts at file offset 20 in both the 64x64 and the 64x72 stream | ||
| 27 | + (`key_tile_bytes len=543`/`647`, file sizes 563/667), and `base_q_idx=160`, | ||
| 28 | + `mi_cols=16`, `mi_rows=18` all parse correctly, so the header field values are | ||
| 29 | + right; the divergence is in the very first symbol read off those bytes. | ||
| 30 | + **Not diagnosed further — this is the handoff item.** Ruled out by reading the | ||
| 31 | + source: `sb_rows`/`sb_cols` (`sequence.rs:409-422`, 18 -> 2 correct) and the | ||
| 32 | + uniform-spacing tile-info loops (`frame.rs:1296-1334`, both increment loops match | ||
| 33 | + spec 5.9.15, so the extra `increment_tile_rows_log2` bit that height 72 introduces | ||
| 34 | + IS consumed). | ||
| 35 | + | ||
| 36 | +4. Pre-existing, unrelated to odd height: `192x128` and `192x136` both stop at | ||
| 37 | + `"a 1:4 partition below 16x16"` with `--enable-1to4-partitions=0` on the command | ||
| 38 | + line — a same-shaped refusal-from-own-desync at width 192, present on the control. | ||
| 39 | + | ||
| 40 | +## Code changed (all in this worktree, unproven end to end) | ||
| 41 | + | ||
| 42 | +- cherry-pick `eacd7fd` (lane-golomb) — the frame-edge partition bit at 6 sites in | ||
| 43 | + both tile paths, plus its film key-frame fixture/gate. Clean merge. | ||
| 44 | +- `crates/ec-av1/src/decode.rs:11371` — the key-frame 16-level frame-edge | ||
| 45 | + `PARTITION_HORZ`/`VERT` now decodes its single visible 16x8 / 8x16 strip through | ||
| 46 | + `decode_leaf_rect` instead of refusing (removes that refusal string; entry dropped | ||
| 47 | + from `refusal_inventory.rs`). | ||
| 48 | +- `crates/ec-av1/src/decode.rs` (inter tile path, superblock level and 16-level) — | ||
| 49 | + the same edge half-strip as one 64x32 / 32x64 resp. 16x8 / 8x16 inter block | ||
| 50 | + (`write_w`/`write_h`, square CDF/size-class corner-cut, exactly the accepted | ||
| 51 | + corner-cut of the 32-level rect arm at `decode.rs:18448`). Interior rect | ||
| 52 | + partitions still refuse by name. | ||
| 53 | +- `decode.rs` — new counter `edge_rect_strip_hits()` (blocks decoded inside the 8px | ||
| 54 | + edge band), for the gate a successor must write. | ||
| 55 | + | ||
| 56 | +`corner-cut:` the two inter edge arms read square CDFs / size classes for a | ||
| 57 | +rectangular block (ceiling: coefficient and mode syntax for TX_64X32/TX_16X8 inter is | ||
| 58 | +not modelled; upgrade path = the same treatment the 32-level rect arm eventually gets). | ||
| 59 | + | ||
| 60 | +## Verification status — honest | ||
| 61 | + | ||
| 62 | +- NO gate was added and NO refusal claim is proven: every stream that reaches the new | ||
| 63 | + arms is desynced before them (finding 3), so a pixel compare would measure the | ||
| 64 | + desync, not the arm. Writing | ||
| 65 | + `a_real_aomenc_inter_sequence_with_an_8px_tall_edge_row_decodes_pixel_exact` on top | ||
| 66 | + of a first-symbol desync would have produced a vacuous or a permanently-red gate. | ||
| 67 | +- Suite: see `$HOME/.cache/oddh-suite.log` (run as a systemd unit, result quoted in | ||
| 68 | + the handoff message). | ||
| 69 | + | ||
| 70 | +## Disposition | ||
| 71 | + | ||
| 72 | +- fix-now (next round, r2): the 64x72 key-tile first-symbol desync. It is the root | ||
| 73 | + blocker; the edge arms above are dead code until it is fixed. | ||
| 74 | +- deferred(the desync above): the 8px-edge-band gate + the refusal lift claim. | ||
| 75 | +- deferred(width-192 defect, separate lane): the `"1:4 partition below 16x16"` stop | ||
| 76 | + that both 192x128 and 192x136 share. | ||
lanes/oddh-r2.report.mdadded+97 -0
| @@ -0,0 +1,97 @@ | |||
| 1 | +# lane-oddh r2 — the 64x72 first-symbol desync is 128x128 superblocks | ||
| 2 | + | ||
| 3 | +## Root cause (byte-level proof, not inference) | ||
| 4 | + | ||
| 5 | +r1's pinned defect — a 64x72 aomenc KEY frame desyncing at the FIRST symbol | ||
| 6 | +(aomdec value=3, ours 9) — is **not** an odd-height defect and **not** a header | ||
| 7 | +parse defect. The stream's sequence header codes `use_128x128_superblock = 1`, | ||
| 8 | +and this decoder is 64x64-superblock only (`SB_MI = 16`, no BLOCK_128X128 | ||
| 9 | +partition read anywhere; `decode.rs` never reads `use_128x128_superblock`). | ||
| 10 | + | ||
| 11 | +libaom picks it: `av1_select_sb_size` (encoder_utils.c:1000-1003) returns | ||
| 12 | +BLOCK_64X64 only when `speed >= 1 && min(w,h) <= 480`. r1's fixture was | ||
| 13 | +encoded at `--cpu-used=0`, so speed 0 fell through to BLOCK_128X128. | ||
| 14 | + | ||
| 15 | +What the two decoders do with the same first byte: | ||
| 16 | + | ||
| 17 | +| | libaom (aomdec) | ours | | ||
| 18 | +|---|---|---| | ||
| 19 | +| first block | BLOCK_128X128 at mi (0,0): `has_cols = 0+16 < 16` false, `has_rows = 16 < 18` true | BLOCK_64X64 at mi (0,0) | | ||
| 20 | +| symbol read | gathered 2-symbol partition (`partition_gather_horz_alike`) | 10-symbol `partition_cdf[12]` | | ||
| 21 | +| value | 3 = PARTITION_SPLIT | 9 = PARTITION_VERT_4 | | ||
| 22 | + | ||
| 23 | +Ruled out first, by hand, field by field against spec 5.9.2 for this stream: | ||
| 24 | +the uncompressed header is **49 bits** (3 before tile_info, 1 tile_info, 12 | ||
| 25 | +quant, 1 seg, 1 delta, 29 loop filter — levels 36/38/21/19, sharpness 0, | ||
| 26 | +mode_ref_delta_enabled 1, update 0 — 0 cdef, 0 lr, tx_mode 1, reduced_tx_set 1), | ||
| 27 | +byte-aligning tile data to file offset 20. Our parser reads exactly the same 49 | ||
| 28 | +bits. Two independent msac implementations (ours and a from-spec python one) | ||
| 29 | +read symbol 9 from offset 20 with `partition_cdf[12]`, so the bytes and the | ||
| 30 | +table are both ours-correct — only the *block size* is wrong. | ||
| 31 | + | ||
| 32 | +EVIDENCE: hand-parsed header bits + msac offset probe (both diagnostics reverted after use) | parsed k-64x72.obu, printed per-section bit positions (3/4/16/17/18/47/47/47/49), then decoded the first partition symbol at file offsets 16..24 with `PARTITION_W64[0]` in ours and in a from-spec python msac | both give 9 at offset 20 (aomdec: 3), i.e. same bytes, same table, different alphabet | ||
| 33 | + | ||
| 34 | +## What changed | ||
| 35 | + | ||
| 36 | +- `crates/ec-av1/src/stream.rs:509` — `decode_stream` now REFUSES a sequence | ||
| 37 | + with `use_128x128_superblock` **on a frame larger than 64x64** by name | ||
| 38 | + instead of silently decoding it as 64x64 superblocks (wrong pixels, whole | ||
| 39 | + frame). The scoping is measured, not reasoned: a blanket refusal red-lined | ||
| 40 | + 29 previously pixel-exact gates (29 failed / 318 passed), because at | ||
| 41 | + <= 64x64 a 128x128 superblock decodes identically -- mi (0,0) has neither | ||
| 42 | + `has_rows` nor `has_cols`, so BLOCK_128X128 is a forced SPLIT that reads no | ||
| 43 | + symbol and only one 64x64 child is in frame. Every sibling inter gate at | ||
| 44 | + 64x64 `--cpu-used=0` is exactly that case. | ||
| 45 | +- `crates/ec-av1/src/stream.rs` — new gate | ||
| 46 | + `a_real_aomenc_128x128_superblock_stream_is_refused_by_name`: real aomenc, | ||
| 47 | + 64x72, `--cpu-used=0 --sb-size=128`; asserts the stream's sequence header | ||
| 48 | + really codes `use_128x128_superblock` (knob-reached-the-tool) and then that | ||
| 49 | + the refusal fires. | ||
| 50 | +- `crates/ec-av1/src/stream.rs` — `a_real_aomenc_tiny_frame_size_sweep_decodes_pixel_exact` | ||
| 51 | + extended with the odd ladder 64x72, 72x64, 64x136, 136x64, 192x136; floor | ||
| 52 | + raised 70 -> 120 pixel-exact attempts. | ||
| 53 | +- `crates/ec-av1/src/refusal_inventory.rs` — the new refusal string pinned. | ||
| 54 | +- `crates/ec-av1/src/stream.rs` — `a_real_aomenc_inter_frame_edge_half_strip_decodes_pixel_exact` | ||
| 55 | + written and left `#[ignore]`d with its measured reason (below). | ||
| 56 | + | ||
| 57 | +## The size ladder (the table the charter asked for) | ||
| 58 | + | ||
| 59 | +`cargo test -p ec-av1 --lib -- a_real_aomenc_tiny_frame_size_sweep_decodes_pixel_exact`, | ||
| 60 | +10 seeds each, real aomenc at `--cpu-used=4` (= 64x64 superblocks), 8-bit: | ||
| 61 | + | ||
| 62 | +| size | pixel-exact | refused | | ||
| 63 | +|---|---|---| | ||
| 64 | +| 8x8 | 0/10 | 10 (16x16 rect transform, pre-existing) | | ||
| 65 | +| 16x16, 32x32, 16x32, 32x16, 64x64, 48x48, 24x24 | 10/10 each | 0 | | ||
| 66 | +| **64x72, 72x64, 64x136, 136x64, 192x136** | **10/10 each** | 0 | | ||
| 67 | + | ||
| 68 | +EVIDENCE: $HOME/.cache/oddh-suite-r2.log + the run above | 13 sizes x 10 seeds, aomenc -> our decoder -> ffmpeg sample compare | 120 pixel-exact attempts, 0 mismatches, "tiny frame sweep: 120 pixel-exact attempts" | ||
| 69 | + | ||
| 70 | +So odd height/width at 64x64 superblocks is **clean**, including r1's | ||
| 71 | +frame-edge half-strip code on the KEY path. | ||
| 72 | + | ||
| 73 | +## Open / deferred | ||
| 74 | + | ||
| 75 | +- deferred: 128x128 superblock decode — refused by name, not implemented — the | ||
| 76 | + partition tree, `SB_MI`, CDEF/LR/deblock grids and the loop-filter unit size | ||
| 77 | + are all 64-only; that is a lane, not a fix. Unblocked by: a lane that makes | ||
| 78 | + `SB_MI` a parameter and adds the BLOCK_128X128 partition read. | ||
| 79 | +- deferred: the INTER frame-edge half-strip arms r1 added are still UNGATED. | ||
| 80 | + Measured this round at 192x160 (last superblock row 32 tall, so the forced | ||
| 81 | + gathered edge symbol is a 64x32): with `--enable-rect-partitions=0` both bit | ||
| 82 | + depths decode 6 frames **pixel-exact** but `edge_rect_strip_hits = 0` (the | ||
| 83 | + encoder answers the forced symbol SPLIT every time); with rect ON the run | ||
| 84 | + stops at other lanes' gaps — cq 40 "a non-skip rectangular (HORZ/VERT/HORZ_B) | ||
| 85 | + strip needs rectangular residual coding", cq 62 "an INTER 32x32 partition | ||
| 86 | + type this decoder does not code (value=8/9)", min-partition 16 "a HORZ/VERT | ||
| 87 | + intra strip below 16x16 with a split transform". Unblocked by: the rect | ||
| 88 | + inter-residual lane. | ||
| 89 | + | ||
| 90 | +## Suite | ||
| 91 | + | ||
| 92 | +`cargo test -p ec-av1 --lib` (systemd unit, log `$HOME/.cache/oddh-suite-r2.log`): | ||
| 93 | +the blanket-refusal run was 318 passed / 29 failed / 32 ignored, every failure | ||
| 94 | +the new refusal firing on a 64x64 `--cpu-used=0` stream. After scoping the | ||
| 95 | +refusal to frames larger than 64x64, the 7-gate subset covering all of them | ||
| 96 | +plus the three new/extended gates is green (7 passed, 0 failed); the full-suite | ||
| 97 | +rerun on the scoped tree is launched to the same log and is r3's first read. | ||
lanes/refstamp-r1.report.mdadded+84 -0
| @@ -0,0 +1,84 @@ | |||
| 1 | +# lane-refstamp r1 — `ref_stamp` vs forward key frames, `av1_copy_frame_mvs` clear, scripted MFMV rungs | ||
| 2 | + | ||
| 3 | +Base: lane-inter4 `49af875` (contains lane-interbis's motion-field fix). Commits `34ae093`, `b03a4d2`. | ||
| 4 | + | ||
| 5 | +## What changed | ||
| 6 | + | ||
| 7 | +- `crates/ec-av1/src/motion_field.rs:270` — `MotionField` gains `is_intra` (the DPB slot's | ||
| 8 | + `frame_type`); `motion_field_projection` now opens with libaom's own first `return 0` | ||
| 9 | + (`start_frame_buf->frame_type == KEY_FRAME || INTRA_ONLY_FRAME`) before the frame-size test. | ||
| 10 | + Previously a forward reference holding a key frame was "projected" (empty field) and reported | ||
| 11 | + success, so it consumed the `ref_stamp` slot that ALTREF/LAST2 should have had. | ||
| 12 | +- `crates/ec-av1/src/motion_field.rs:335` — `setup_motion_field` ports | ||
| 13 | + `if (!order_hint_info->enable_order_hint) return;` (empty `TplField` when `order_hint_bits == 0`) | ||
| 14 | + and counts the frames that take the intra-forward-ref `ref_stamp` path | ||
| 15 | + (`refstamp_intra_frames() -> (>=1, >=2)`). | ||
| 16 | +- `crates/ec-av1/src/motion_field.rs:296` — `MotionField::set` now takes `Option<SavedMv>`; | ||
| 17 | + `crates/ec-av1/src/decode.rs:1772` `build_motion_field` ports `av1_copy_frame_mvs`'s leading | ||
| 18 | + CLEAR (`mv->ref_frame = NONE_FRAME; mv->mv.as_int = 0;`), which runs for every block of an | ||
| 19 | + inter frame — intra blocks, and inter blocks whose every slot is other-side/over-REFMVS_LIMIT, | ||
| 20 | + now wipe their 8x8 cells instead of `continue`ing. Latent until sub-8x8 leaves (only they share | ||
| 21 | + a cell), ported now. | ||
| 22 | +- `crates/ec-av1/src/stream.rs:614` — the key-frame DPB slot is constructed with `is_intra: true`. | ||
| 23 | +- `crates/ec-av1/src/gate_coverage.rs:221,272` — the 10-bit `enable-ref-frame-mvs` / | ||
| 24 | + `enable-fwd-kf` coverage holes are closed by the new gate; entries deleted, 8-bit reasons reworded. | ||
| 25 | +- `scripts/instrument-aom-oracle.sh` — new **rung 14**: `EC_TRACE_TPL` (`EC_TPL ... mfmv0=(..,..) | ||
| 26 | + rfo=..` / `INVALID` in `add_tpl_ref_mv`) and the per-entry `EC_STACK` dump under rung 4's | ||
| 27 | + `EC_TRACE_MODE`. Both existed only as hand edits in `~/.cache/aom-oracle/src` (lane-interbis) | ||
| 28 | + and would have vanished on the next oracle rebuild. | ||
| 29 | + | ||
| 30 | +## Gate | ||
| 31 | + | ||
| 32 | +`a_real_aomenc_inter_sequence_with_forward_keyframes_and_temporal_mvs_decodes_pixel_exact` | ||
| 33 | +(`crates/ec-av1/src/stream.rs:4900`): 192x128, 24 frames of translating structure, | ||
| 34 | +`--enable-fwd-kf=1 --fwd-kf-dist=8 --lag-in-frames=16 --auto-alt-ref=1 --arnr-maxframes=0 | ||
| 35 | +--enable-ref-frame-mvs=1 --enable-order-hint=1` (overrides last, aomenc keeps the last flag), | ||
| 36 | +2 attempts (cq 34 / 45), 8-bit AND 10-bit, every decoded frame — hidden alt-refs included — | ||
| 37 | +compared to the oracle IN DECODE ORDER via `decode_all_frames_vs_oracle`. A decode error is only | ||
| 38 | +tolerated as a named `unsupported` refusal and is counted, never SKIPped; three hard asserts | ||
| 39 | +(`compared > 0`, temporal candidates `> 0`, key/intra-forward-ref frames `> 0`). | ||
| 40 | + | ||
| 41 | +Run: `EC_NOMEMGUARD=1 EC_AV1_REQUIRE_AOMENC=1 CARGO_TARGET_DIR=$HOME/.cache/cargo-target-refstamp | ||
| 42 | +cargo test -p ec-av1 --lib forward_keyframes -- --nocapture` | ||
| 43 | + | ||
| 44 | +EVIDENCE: /home/user/.cache/refstamp-suite.log | aomenc fwd-kf recipe, 2 attempts x 2 depths, decode-order compare incl. hidden frames | 8-bit: 26 frames (2 hidden) pixel-exact, temporal candidates=524, key/intra-forward-ref frames=6; 10-bit: 26 frames (2 hidden) pixel-exact, candidates=514, frames=6; attempt 0 (cq 34) refuses by name ("an intra-coded HORZ/VERT strip needs rectangular intra prediction") | ||
| 45 | + | ||
| 46 | +MUTATION: removing the `if start.is_intra { return false; }` early return (pre-fix behaviour) makes | ||
| 47 | +the gate FAIL, not skip: | ||
| 48 | +EVIDENCE: /tmp/ec-av1-a_real_aomenc_inter_sequence_with_forward_keyframes_and_temporal_mvs_decodes_pixel_exact-8bit-attempt1-703199/in.obu | mutate motion_field.rs early return to a no-op, rerun the gate | "decode-order frame 15 of 26 (24 shown, 2 hidden) differs from the oracle at byte 6686 (ours 179 vs 178), 160 bytes differ" | ||
| 49 | + | ||
| 50 | +Rung 14 verification: applied to a scratch tree (pristine `mvref_common.c` from the oracle's git | ||
| 51 | +HEAD + a rung-13-state `decodemv.c`) and byte-compared to the live hand-patched oracle sources. | ||
| 52 | +EVIDENCE: scratchpad/rung14/av1/{common/mvref_common.c,decoder/decodemv.c} | `SRC=<scratch> bash rung14.sh`, then `diff` vs ~/.cache/aom-oracle/src | both files IDENTICAL to the live oracle; re-running on the live oracle prints "already applied (no-op)" twice (idempotent); `bash -n` clean | ||
| 53 | + | ||
| 54 | +## Refusals | ||
| 55 | + | ||
| 56 | +None lifted this round (no refusal guarded this path); `refusal_inventory` / `gate_coverage` | ||
| 57 | +unchanged and green in the suite below. | ||
| 58 | + | ||
| 59 | +## Suite | ||
| 60 | + | ||
| 61 | +`cargo test -p ec-av1 --lib` (systemd unit, MemoryMax=10G): **326 passed, 0 failed, 31 ignored** | ||
| 62 | +(`$HOME/.cache/refstamp-suite2.log`). The first run on the same tree failed exactly 2 tests -- | ||
| 63 | +`gate_coverage::never_exercised_10bit_matches_the_gate_recipes` and `never_on_10bit_...` -- because | ||
| 64 | +the new gate CLOSED two 10-bit coverage holes (`enable-ref-frame-mvs`, `enable-fwd-kf`); commit | ||
| 65 | +`00d37d3` deletes those entries and reworded the two 8-bit reasons (`is_ten_bit` classifies a | ||
| 66 | +dual-depth gate as 10-bit only, so the 8-bit lists keep the tools with an accurate reason). | ||
| 67 | +Siblings all green in that run: `..._temporal_mv_candidates_...`, `..._altref_sequence_hidden_frames_...`, | ||
| 68 | +every `..._inter_sequence_...`, `..._obmc_...`, `..._warped_motion_...`, `refusal_inventory` (3/3), | ||
| 69 | +`gate_coverage` (9/9). | ||
| 70 | + | ||
| 71 | +EVIDENCE: /home/user/.cache/refstamp-suite2.log | systemd-run unit, cargo test -p ec-av1 --lib -j3 | "test result: ok. 326 passed; 0 failed; 31 ignored" in 379 s | ||
| 72 | + | ||
| 73 | +## Residue | ||
| 74 | + | ||
| 75 | +- The gate's frames all have exactly ONE key/intra forward reference (`two or more: 0`) — the | ||
| 76 | + charter's ">=2 forward refs are key/intra" phrasing is not what `--enable-fwd-kf` produces at | ||
| 77 | + `--fwd-kf-dist=8`; one is already sufficient to move `ref_stamp` (it changes whether LAST2 and | ||
| 78 | + ALTREF are projected), and the mutation proves the gate is sensitive to exactly that. | ||
| 79 | + accepted. | ||
| 80 | +- `--enable-fwd-kf=1` at cq 34 still stops at the intra HORZ/VERT rect-strip refusal (attempt 0); | ||
| 81 | + cq 45 decodes fully. deferred(lane owning rectangular intra prediction) — not this lane's path. | ||
| 82 | +- The `av1_copy_frame_mvs` clear is unexercised by any gate today (needs a sub-8x8 inter leaf, | ||
| 83 | + which still refuses by name). deferred(the sub8 lane's 4x4 inter leaves) — ported now because | ||
| 84 | + the same block that lifts that refusal would otherwise silently inherit the old behaviour. | ||
scripts/instrument-aom-oracle.shmodified+71 -0
| @@ -761,3 +761,74 @@ s = s.replace(anchor, anchor + probe, 1) | |||
| 761 | open(path, "w").write(s) | 761 | open(path, "w").write(s) |
| 762 | print("decodemv rung 13 (EC_MODE_MV + EC_MODE_VAL stack=) instrumented") | 762 | print("decodemv rung 13 (EC_MODE_MV + EC_MODE_VAL stack=) instrumented") |
| 763 | PYMV | 763 | PYMV |
| 764 | + | ||
| 765 | +# --- rung 14: temporal-MV (MFMV) ground truth (lane-interbis, scripted by ---- | ||
| 766 | +# --- lane-refstamp r1) ----------------------------------------------------- | ||
| 767 | +# lane-interbis patched the live oracle tree BY HAND for its motion-field hunt, | ||
| 768 | +# so these two probes lived only in ~/.cache/aom-oracle/src and a rebuild from | ||
| 769 | +# this script would have dropped them (class: instrument that lives only in a | ||
| 770 | +# build tree -- same reason rung 13 exists). | ||
| 771 | +# * EC_TRACE_TPL=1 -> "EC_TPL mi_row=.. mi_col=.. blk=(..,..) mfmv0=(..,..) | ||
| 772 | +# rfo=.." (or ".. INVALID") for every temporal candidate `add_tpl_ref_mv` | ||
| 773 | +# probes -- the reference's own projected motion field, cell by cell, to | ||
| 774 | +# compare against ours (EC_TRACE_TPL on our side). | ||
| 775 | +# * the resolved MV STACK itself, one "EC_STACK mi_row=.. mi_col=.. ref=.. | ||
| 776 | +# i=.. this=(..,..) comp=(..,..) w=.." line per entry, printed under rung | ||
| 777 | +# 4's EC_TRACE_MODE right after EC_MODE_VAL (rung 13 only prints the | ||
| 778 | +# stack DEPTH). | ||
| 779 | +python3 - "$SRC/av1/common/mvref_common.c" <<'PYT' | ||
| 780 | +import sys | ||
| 781 | +path = sys.argv[1] | ||
| 782 | +s = open(path).read() | ||
| 783 | +if "EC_TRACE_TPL" in s: | ||
| 784 | + print("mvref_common rung 14 already applied (no-op)") | ||
| 785 | + sys.exit(0) | ||
| 786 | +old = " if (prev_frame_mvs->mfmv0.as_int == INVALID_MV) return 0;\n" | ||
| 787 | +assert old in s, "add_tpl_ref_mv's INVALID_MV early return moved" | ||
| 788 | +new = """ if (prev_frame_mvs->mfmv0.as_int == INVALID_MV) { | ||
| 789 | + if (getenv("EC_TRACE_TPL")) | ||
| 790 | + fprintf(stderr, "EC_TPL mi_row=%d mi_col=%d blk=(%d,%d) INVALID\\n", | ||
| 791 | + mi_row, mi_col, blk_row, blk_col); | ||
| 792 | + return 0; | ||
| 793 | + } | ||
| 794 | + if (getenv("EC_TRACE_TPL")) | ||
| 795 | + fprintf(stderr, | ||
| 796 | + "EC_TPL mi_row=%d mi_col=%d blk=(%d,%d) mfmv0=(%d,%d) rfo=%d\\n", | ||
| 797 | + mi_row, mi_col, blk_row, blk_col, prev_frame_mvs->mfmv0.as_mv.row, | ||
| 798 | + prev_frame_mvs->mfmv0.as_mv.col, prev_frame_mvs->ref_frame_offset); | ||
| 799 | +""" | ||
| 800 | +s = s.replace(old, new, 1) | ||
| 801 | +open(path, "w").write(s) | ||
| 802 | +print("mvref_common rung 14 (EC_TPL) instrumented") | ||
| 803 | +PYT | ||
| 804 | + | ||
| 805 | +python3 - "$SRC/av1/decoder/decodemv.c" <<'PYST' | ||
| 806 | +import sys | ||
| 807 | +path = sys.argv[1] | ||
| 808 | +s = open(path).read() | ||
| 809 | +if "EC_STACK mi_row" in s: | ||
| 810 | + print("decodemv rung 14 already applied (no-op)") | ||
| 811 | + sys.exit(0) | ||
| 812 | +assert "EC_MODE_MV" in s, "rung 14 needs rung 13 (run this script top to bottom)" | ||
| 813 | +anchor = """ /* EC_STACK */ (int)dcb->ref_mv_count[av1_ref_frame_type(mbmi->ref_frame)], | ||
| 814 | + (unsigned)r->ec.rng); | ||
| 815 | +""" | ||
| 816 | +assert s.count(anchor) == 1, "rung 13's EC_MODE_VAL body moved" | ||
| 817 | +dump = """ /* EC_INSTRUMENTED lane-interbis: the resolved mv stack itself */ | ||
| 818 | + const MV_REFERENCE_FRAME ec_rt = av1_ref_frame_type(mbmi->ref_frame); | ||
| 819 | + for (int ec_i = 0; ec_i < dcb->ref_mv_count[ec_rt]; ec_i++) { | ||
| 820 | + fprintf(stderr, | ||
| 821 | + "EC_STACK mi_row=%d mi_col=%d ref=%d i=%d this=(%d,%d) " | ||
| 822 | + "comp=(%d,%d) w=%d\\n", | ||
| 823 | + ec_xd->mi_row, ec_xd->mi_col, (int)ec_rt, ec_i, | ||
| 824 | + ec_xd->ref_mv_stack[ec_rt][ec_i].this_mv.as_mv.row, | ||
| 825 | + ec_xd->ref_mv_stack[ec_rt][ec_i].this_mv.as_mv.col, | ||
| 826 | + ec_xd->ref_mv_stack[ec_rt][ec_i].comp_mv.as_mv.row, | ||
| 827 | + ec_xd->ref_mv_stack[ec_rt][ec_i].comp_mv.as_mv.col, | ||
| 828 | + ec_xd->weight[ec_rt][ec_i]); | ||
| 829 | + } | ||
| 830 | +""" | ||
| 831 | +s = s.replace(anchor, anchor + dump, 1) | ||
| 832 | +open(path, "w").write(s) | ||
| 833 | +print("decodemv rung 14 (per-entry EC_STACK) instrumented") | ||
| 834 | +PYST | ||