merge(palette2): main 4a29b4e (sub8merge mi-granular mode maps + rectx coded strips)
Browse files at this commit16 changed files +2617 -194
- crates/ec-av1/src/cdf.rs +45 -1
- crates/ec-av1/src/cdf_state.rs +96 -2
- crates/ec-av1/src/decode.rs +904 -147
- crates/ec-av1/src/encode.rs +180 -40
- crates/ec-av1/src/gate_coverage.rs +1 -1
- crates/ec-av1/src/refusal_inventory.rs +3 -3
- crates/ec-av1/src/stream.rs +524 -0
- lanes/rectx-r3.handoff.md +54 -0
- lanes/rectx-r3.report.md +88 -0
- lanes/rectx-r4.report.md +89 -0
- lanes/rectx-r5.report.md +116 -0
- lanes/sub8-r1.report.md +206 -0
- lanes/sub8-r4.report.md +74 -0
- lanes/sub8-r5.report.md +93 -0
- lanes/sub8-r6.report.md +77 -0
- lanes/sub8merge-r1.report.md +67 -0
crates/ec-av1/src/cdf.rsmodified+45 -1
| @@ -293,6 +293,42 @@ pub const EOB_PT_128_CHROMA_Q3: [u16; 9] = [ | |||
| 293 | 24313, 26062, 28385, 30107, 31217, 31898, 32345, 32768, 0, | 293 | 24313, 26062, 28385, 30107, 31217, 31898, 32345, 32768, 0, |
| 294 | ]; | 294 | ]; |
| 295 | 295 | ||
| 296 | +/// `av1_default_eob_multi128_cdfs[2][0][0]` (`token_cdfs.h:830-849`, | ||
| 297 | +/// lane-rectx): the end-of-block group of a LUMA transform with 128 coded | ||
| 298 | +/// positions -- what a true 16x8/8x16 rectangular transform has | ||
| 299 | +/// (`decode_leaf_rect`'s own leaf, one level below [`EOB_PT_512_LUMA`]'s | ||
| 300 | +/// 32x16/16x32), distinct from [`EOB_PT_256_LUMA`]'s 256-position group a | ||
| 301 | +/// *square* 16x16 reads. Read straight from the plane-0 half of the same | ||
| 302 | +/// `token_cdfs.h` table [`EOB_PT_128_CHROMA`] reads its plane-1 half from. | ||
| 303 | +pub const EOB_PT_128_LUMA: [u16; 9] = [ | ||
| 304 | + 1366, 1738, 2527, 5016, 9355, 15797, 24643, 32768, 0, | ||
| 305 | +]; | ||
| 306 | +/// [`EOB_PT_128_LUMA`], q-context 0. | ||
| 307 | +pub const EOB_PT_128_LUMA_Q0: [u16; 9] = [ | ||
| 308 | + 219, 482, 1140, 2091, 3680, 6028, 12586, 32768, 0, | ||
| 309 | +]; | ||
| 310 | +/// [`EOB_PT_128_LUMA`], q-context 1. | ||
| 311 | +pub const EOB_PT_128_LUMA_Q1: [u16; 9] = [ | ||
| 312 | + 685, 933, 1488, 2714, 4766, 8562, 19254, 32768, 0, | ||
| 313 | +]; | ||
| 314 | +/// [`EOB_PT_128_LUMA`], q-context 3. | ||
| 315 | +pub const EOB_PT_128_LUMA_Q3: [u16; 9] = [ | ||
| 316 | + 3472, 4885, 7489, 12481, 18517, 24536, 29635, 32768, 0, | ||
| 317 | +]; | ||
| 318 | + | ||
| 319 | +/// `av1_default_eob_multi32_cdfs[2][1][0]` (`token_cdfs.h:792-808`, | ||
| 320 | +/// lane-rectx): the end-of-block group of a CHROMA transform with 32 coded | ||
| 321 | +/// positions -- what a true 8x4/4x8 rectangular transform has (the chroma | ||
| 322 | +/// plane of a [`decode_leaf_rect`] 16x8/8x16 luma strip), distinct from | ||
| 323 | +/// [`EOB_PT_16_CHROMA`]'s 16-position group a *square* 4x4 reads. | ||
| 324 | +pub const EOB_PT_32_CHROMA: [u16; 7] = [13468, 16303, 20361, 25105, 29281, 32768, 0]; | ||
| 325 | +/// [`EOB_PT_32_CHROMA`], q-context 0. | ||
| 326 | +pub const EOB_PT_32_CHROMA_Q0: [u16; 7] = [2636, 4273, 7588, 11794, 20401, 32768, 0]; | ||
| 327 | +/// [`EOB_PT_32_CHROMA`], q-context 1. | ||
| 328 | +pub const EOB_PT_32_CHROMA_Q1: [u16; 7] = [8394, 10352, 13932, 18855, 26014, 32768, 0]; | ||
| 329 | +/// [`EOB_PT_32_CHROMA`], q-context 3. | ||
| 330 | +pub const EOB_PT_32_CHROMA_Q3: [u16; 7] = [22086, 24282, 27010, 29770, 31743, 32768, 0]; | ||
| 331 | + | ||
| 296 | /// `av1_default_eob_multi512_cdfs[2][1][0]` (`token_cdfs.h:874-901`, | 332 | /// `av1_default_eob_multi512_cdfs[2][1][0]` (`token_cdfs.h:874-901`, |
| 297 | /// lane-part32 r4): the end-of-block group of a CHROMA transform with 512 | 333 | /// lane-part32 r4): the end-of-block group of a CHROMA transform with 512 |
| 298 | /// coded positions -- what a 32x16/16x32 chroma transform has (the chroma | 334 | /// coded positions -- what a 32x16/16x32 chroma transform has (the chroma |
| @@ -421,13 +457,21 @@ pub const CFL_SIGN: [u16; 9] = [1418, 2123, 13340, 18405, 26972, 28343, 32294, 3 | |||
| 421 | /// (12756/14301, `default_filter_intra_cdfs` index 8/7) -- the two rect | 457 | /// (12756/14301, `default_filter_intra_cdfs` index 8/7) -- the two rect |
| 422 | /// strips `PARTITION_HORZ`/`PARTITION_VERT` decode, each with its own | 458 | /// strips `PARTITION_HORZ`/`PARTITION_VERT` decode, each with its own |
| 423 | /// distinct default probability from every square class above. | 459 | /// distinct default probability from every square class above. |
| 424 | -pub const FILTER_INTRA: [[u16; 3]; 6] = [ | 460 | +/// `[6]`/`[7]` (lane-rectx r3) add `BLOCK_16X8`/`BLOCK_8X16`'s own rows |
| 461 | +/// (9394/12551, `default_filter_intra_cdfs` index 5/4) -- the 16x8/8x16 | ||
| 462 | +/// strips [`crate::decode`]'s `decode_leaf_rect` codes. Missing them meant | ||
| 463 | +/// the flag was never read at that size at all (libaom reads it for every | ||
| 464 | +/// DC_PRED block whose sides are both <= 32), so every DC_PRED 16x8 strip | ||
| 465 | +/// dropped one symbol and desynced the tile from that block on. | ||
| 466 | +pub const FILTER_INTRA: [[u16; 3]; 8] = [ | ||
| 425 | [4621, 32768, 0], | 467 | [4621, 32768, 0], |
| 426 | [7866, 32768, 0], | 468 | [7866, 32768, 0], |
| 427 | [12408, 32768, 0], | 469 | [12408, 32768, 0], |
| 428 | [22343, 32768, 0], | 470 | [22343, 32768, 0], |
| 429 | [12756, 32768, 0], | 471 | [12756, 32768, 0], |
| 430 | [14301, 32768, 0], | 472 | [14301, 32768, 0], |
| 473 | + [9394, 32768, 0], | ||
| 474 | + [12551, 32768, 0], | ||
| 431 | ]; | 475 | ]; |
| 432 | /// `default_filter_intra_mode_cdf` (entropymode.c): which of the five | 476 | /// `default_filter_intra_mode_cdf` (entropymode.c): which of the five |
| 433 | /// `FILTER_INTRA_MODES` a `use_filter_intra` block picks. | 477 | /// `FILTER_INTRA_MODES` a `use_filter_intra` block picks. |
crates/ec-av1/src/cdf_state.rsmodified+96 -2
| @@ -127,6 +127,41 @@ pub(crate) enum TxbSet { | |||
| 127 | /// different existing sets is why this variant exists at all rather than | 127 | /// different existing sets is why this variant exists at all rather than |
| 128 | /// reusing [`LumaRect32x16`](TxbSet::LumaRect32x16)'s chroma sibling. | 128 | /// reusing [`LumaRect32x16`](TxbSet::LumaRect32x16)'s chroma sibling. |
| 129 | ChromaRect32x16, | 129 | ChromaRect32x16, |
| 130 | + /// The luma 16x8/8x16 transform of a `PARTITION_HORZ`/`VERT` intra strip | ||
| 131 | + /// below 16x16 (lane-rectx, `decode_leaf_rect`'s own leaf, one level | ||
| 132 | + /// under [`LumaRect32x16`](TxbSet::LumaRect32x16)): `get_txsize_entropy_ctx` | ||
| 133 | + /// reduces this 2:1 rect size to `TX_16X16` too, so this shares every | ||
| 134 | + /// table [`Luma16`](TxbSet::Luma16) does except two: its mode-indexed | ||
| 135 | + /// `tx_type` CDF, which is the *8x8* row's (see | ||
| 136 | + /// [`LumaRect16x8Set1`](TxbSet::LumaRect16x8Set1)), and `eob_pt`, which | ||
| 137 | + /// reads the true 128-position [`crate::cdf::EOB_PT_128_LUMA`] rather | ||
| 138 | + /// than `Luma16`'s 256-position one. Unlike | ||
| 139 | + /// [`LumaRect32x16`](TxbSet::LumaRect32x16), this size DOES carry a | ||
| 140 | + /// `tx_type` symbol: `av1_get_ext_tx_set_type` (`av1/common/blockd.h`) | ||
| 141 | + /// sees `tx_size_sqr_up == TX_16X16`, so intra reads | ||
| 142 | + /// `EXT_TX_SET_DTT4_IDTX` under `reduced_tx_set` and | ||
| 143 | + /// `EXT_TX_SET_DTT4_IDTX_1DDCT` without it (`tx_size_sqr` is `TX_8X8` | ||
| 144 | + /// here, not `TX_16X16`) -- this variant is the reduced arm, its | ||
| 145 | + /// `Set1` sibling the other. | ||
| 146 | + LumaRect16x8, | ||
| 147 | + /// [`LumaRect16x8`](TxbSet::LumaRect16x8)'s `reduced_tx_set: false` | ||
| 148 | + /// counterpart (lane-rectx r3), the same split | ||
| 149 | + /// [`Luma8Set1`](TxbSet::Luma8Set1) has to [`Luma8`](TxbSet::Luma8) -- | ||
| 150 | + /// and it is deliberately those two tables, not the 16x16 row: libaom's | ||
| 151 | + /// `read_tx_type` indexes `intra_ext_tx_cdf[eset][square_tx_size]` with | ||
| 152 | + /// `square_tx_size = txsize_sqr_map[tx_size]`, which for `TX_16X8`/ | ||
| 153 | + /// `TX_8X16` is `TX_8X8`, NOT the `txsize_sqr_up_map` `TX_16X16` the | ||
| 154 | + /// txb-skip/base/br tables use (`get_txsize_entropy_ctx`). r2 read the | ||
| 155 | + /// 16x16 row's five-symbol reduced CDF here and desynced on the very | ||
| 156 | + /// first coded rect leaf. | ||
| 157 | + LumaRect16x8Set1, | ||
| 158 | + /// The chroma 8x4/4x8 transform under the same leaf (lane-rectx): | ||
| 159 | + /// [`Chroma8`](TxbSet::Chroma8)'s tables except `eob_pt`, which reads the | ||
| 160 | + /// true 32-position [`crate::cdf::EOB_PT_32_CHROMA`] instead of | ||
| 161 | + /// `Chroma8`'s 64-position one -- the same square-up relationship | ||
| 162 | + /// [`ChromaRect16x8`](TxbSet::ChromaRect16x8) has to `Chroma16`, one size | ||
| 163 | + /// class down. | ||
| 164 | + ChromaRect8x4, | ||
| 130 | } | 165 | } |
| 131 | 166 | ||
| 132 | /// The tables one transform block is coded with, borrowed from the state for | 167 | /// The tables one transform block is coded with, borrowed from the state for |
| @@ -301,6 +336,12 @@ pub(crate) struct Cdfs { | |||
| 301 | /// The end-of-block group of a true 32x16/16x32 rect CHROMA transform | 336 | /// The end-of-block group of a true 32x16/16x32 rect CHROMA transform |
| 302 | /// (lane-sbpart), see [`TxbSet::ChromaRect32x16`]. | 337 | /// (lane-sbpart), see [`TxbSet::ChromaRect32x16`]. |
| 303 | pub eob_pt_512_chroma: [u16; 11], | 338 | pub eob_pt_512_chroma: [u16; 11], |
| 339 | + /// The end-of-block group of a true 16x8/8x16 rect LUMA transform | ||
| 340 | + /// (lane-rectx), see [`TxbSet::LumaRect16x8`]. | ||
| 341 | + pub eob_pt_128_luma: [u16; 9], | ||
| 342 | + /// The end-of-block group of a true 8x4/4x8 rect CHROMA transform | ||
| 343 | + /// (lane-rectx), see [`TxbSet::ChromaRect8x4`]. | ||
| 344 | + pub eob_pt_32_chroma: [u16; 7], | ||
| 304 | /// The end-of-block offset bit, per table set. | 345 | /// The end-of-block offset bit, per table set. |
| 305 | pub eob_extra_luma_32: [[u16; 3]; 9], | 346 | pub eob_extra_luma_32: [[u16; 3]; 9], |
| 306 | /// The same, for a 64x64 luma transform. | 347 | /// The same, for a 64x64 luma transform. |
| @@ -464,9 +505,10 @@ pub(crate) struct Cdfs { | |||
| 464 | /// [`Self::dv_joint`]'s per-component half. | 505 | /// [`Self::dv_joint`]'s per-component half. |
| 465 | pub dv_comp: [MvComponentCdfs; 2], | 506 | pub dv_comp: [MvComponentCdfs; 2], |
| 466 | /// The `use_filter_intra` flag, indexed by block-size class (`[0]`=4x4, | 507 | /// The `use_filter_intra` flag, indexed by block-size class (`[0]`=4x4, |
| 467 | - /// `[1]`=8x8, `[2]`=16x16, `[3]`=32x32, `[4]`=32x16, `[5]`=16x32) -- | 508 | + /// `[1]`=8x8, `[2]`=16x16, `[3]`=32x32, `[4]`=32x16, `[5]`=16x32, |
| 509 | + /// `[6]`=16x8, `[7]`=8x16) -- | ||
| 468 | /// see [`cdf::FILTER_INTRA`]. | 510 | /// see [`cdf::FILTER_INTRA`]. |
| 469 | - pub filter_intra: [[u16; 3]; 6], | 511 | + pub filter_intra: [[u16; 3]; 8], |
| 470 | /// Which `FILTER_INTRA_MODES` entry a `use_filter_intra` block picks. | 512 | /// Which `FILTER_INTRA_MODES` entry a `use_filter_intra` block picks. |
| 471 | pub filter_intra_mode: [u16; 6], | 513 | pub filter_intra_mode: [u16; 6], |
| 472 | /// `TxMode::Select`'s `tx_depth` flag at an 8x8 block, by `tx_size_context` | 514 | /// `TxMode::Select`'s `tx_depth` flag at an 8x8 block, by `tx_size_context` |
| @@ -681,6 +723,8 @@ impl Cdfs { | |||
| 681 | reset1(&mut self.eob_pt_512_luma); | 723 | reset1(&mut self.eob_pt_512_luma); |
| 682 | reset1(&mut self.eob_pt_128_chroma); | 724 | reset1(&mut self.eob_pt_128_chroma); |
| 683 | reset1(&mut self.eob_pt_512_chroma); | 725 | reset1(&mut self.eob_pt_512_chroma); |
| 726 | + reset1(&mut self.eob_pt_128_luma); | ||
| 727 | + reset1(&mut self.eob_pt_32_chroma); | ||
| 684 | reset2(&mut self.eob_extra_luma_32); | 728 | reset2(&mut self.eob_extra_luma_32); |
| 685 | reset2(&mut self.eob_extra_luma_64); | 729 | reset2(&mut self.eob_extra_luma_64); |
| 686 | reset2(&mut self.eob_extra_chroma_16); | 730 | reset2(&mut self.eob_extra_chroma_16); |
| @@ -1138,6 +1182,20 @@ impl Cdfs { | |||
| 1138 | cdf::EOB_PT_128_CHROMA, | 1182 | cdf::EOB_PT_128_CHROMA, |
| 1139 | cdf::EOB_PT_128_CHROMA_Q3, | 1183 | cdf::EOB_PT_128_CHROMA_Q3, |
| 1140 | ), | 1184 | ), |
| 1185 | + eob_pt_128_luma: pick( | ||
| 1186 | + q_ctx, | ||
| 1187 | + cdf::EOB_PT_128_LUMA_Q0, | ||
| 1188 | + cdf::EOB_PT_128_LUMA_Q1, | ||
| 1189 | + cdf::EOB_PT_128_LUMA, | ||
| 1190 | + cdf::EOB_PT_128_LUMA_Q3, | ||
| 1191 | + ), | ||
| 1192 | + eob_pt_32_chroma: pick( | ||
| 1193 | + q_ctx, | ||
| 1194 | + cdf::EOB_PT_32_CHROMA_Q0, | ||
| 1195 | + cdf::EOB_PT_32_CHROMA_Q1, | ||
| 1196 | + cdf::EOB_PT_32_CHROMA, | ||
| 1197 | + cdf::EOB_PT_32_CHROMA_Q3, | ||
| 1198 | + ), | ||
| 1141 | eob_pt_512_chroma: pick( | 1199 | eob_pt_512_chroma: pick( |
| 1142 | q_ctx, | 1200 | q_ctx, |
| 1143 | cdf::EOB_PT_512_CHROMA_Q0, | 1201 | cdf::EOB_PT_512_CHROMA_Q0, |
| @@ -1584,6 +1642,42 @@ impl Cdfs { | |||
| 1584 | tx_type: None, | 1642 | tx_type: None, |
| 1585 | eob_pt_class1: Some(&mut self.eob_pt_512_chroma_class1), | 1643 | eob_pt_class1: Some(&mut self.eob_pt_512_chroma_class1), |
| 1586 | }, | 1644 | }, |
| 1645 | + TxbSet::LumaRect16x8 => TxbTables { | ||
| 1646 | + side: 16, | ||
| 1647 | + txb_skip: &mut self.txb_skip_luma_16, | ||
| 1648 | + eob_pt: &mut self.eob_pt_128_luma, | ||
| 1649 | + eob_extra: &mut self.eob_extra_luma_16, | ||
| 1650 | + base: &mut self.base_luma_16, | ||
| 1651 | + base_eob: &mut self.base_eob_luma_16, | ||
| 1652 | + br: &mut self.br_luma_16, | ||
| 1653 | + dc_sign: &mut self.dc_sign_luma, | ||
| 1654 | + tx_type: Some(self.intra_tx_type_8[mode].as_mut_slice()), | ||
| 1655 | + eob_pt_class1: None, | ||
| 1656 | + }, | ||
| 1657 | + TxbSet::LumaRect16x8Set1 => TxbTables { | ||
| 1658 | + side: 16, | ||
| 1659 | + txb_skip: &mut self.txb_skip_luma_16, | ||
| 1660 | + eob_pt: &mut self.eob_pt_128_luma, | ||
| 1661 | + eob_extra: &mut self.eob_extra_luma_16, | ||
| 1662 | + base: &mut self.base_luma_16, | ||
| 1663 | + base_eob: &mut self.base_eob_luma_16, | ||
| 1664 | + br: &mut self.br_luma_16, | ||
| 1665 | + dc_sign: &mut self.dc_sign_luma, | ||
| 1666 | + tx_type: Some(self.intra_tx_type_8_set1[mode].as_mut_slice()), | ||
| 1667 | + eob_pt_class1: None, | ||
| 1668 | + }, | ||
| 1669 | + TxbSet::ChromaRect8x4 => TxbTables { | ||
| 1670 | + side: 8, | ||
| 1671 | + txb_skip: &mut self.txb_skip_chroma_8, | ||
| 1672 | + eob_pt: &mut self.eob_pt_32_chroma, | ||
| 1673 | + eob_extra: &mut self.eob_extra_chroma_8, | ||
| 1674 | + base: &mut self.base_chroma_8, | ||
| 1675 | + base_eob: &mut self.base_eob_chroma_8, | ||
| 1676 | + br: &mut self.br_chroma_8, | ||
| 1677 | + dc_sign: &mut self.dc_sign_chroma, | ||
| 1678 | + tx_type: None, | ||
| 1679 | + eob_pt_class1: None, | ||
| 1680 | + }, | ||
| 1587 | } | 1681 | } |
| 1588 | } | 1682 | } |
| 1589 | } | 1683 | } |
crates/ec-av1/src/decode.rsmodified+904 -147
| @@ -1437,6 +1437,33 @@ pub(crate) fn rect_coeff_hits() -> usize { | |||
| 1437 | RECT_COEFF_HITS.with(|c| c.get()) | 1437 | RECT_COEFF_HITS.with(|c| c.get()) |
| 1438 | } | 1438 | } |
| 1439 | 1439 | ||
| 1440 | +// lane-rectx r1: how many below-16x16 HORZ/VERT leaves ([`decode_leaf_rect`]) | ||
| 1441 | +// decoded real (non-skip) TX_16X8/TX_8X16 coefficients -- the counter the | ||
| 1442 | +// charter's real-aomenc gate hard-asserts. | ||
| 1443 | +thread_local! { | ||
| 1444 | + static RECT_LEAF_COEFF_HITS: std::cell::Cell<usize> = | ||
| 1445 | + const { std::cell::Cell::new(0) }; | ||
| 1446 | +} | ||
| 1447 | + | ||
| 1448 | +/// Current value of [`RECT_LEAF_COEFF_HITS`]. | ||
| 1449 | +pub(crate) fn rect_leaf_coeff_hits() -> usize { | ||
| 1450 | + RECT_LEAF_COEFF_HITS.with(|c| c.get()) | ||
| 1451 | +} | ||
| 1452 | + | ||
| 1453 | +// lane-rectx r5: how many times a NON-strip `kf_y_mode` reader | ||
| 1454 | +// ([`decode_block`], [`decode_block_rect`], [`decode_block_rect64`]) took an | ||
| 1455 | +// above/left mode from the mi-exact map that DIFFERS from its coarse 16x16 | ||
| 1456 | +// slot -- i.e. how often the r5 defect would have picked the wrong CDF row. | ||
| 1457 | +thread_local! { | ||
| 1458 | + static MODE_MI_OVERRIDE_HITS: std::cell::Cell<usize> = | ||
| 1459 | + const { std::cell::Cell::new(0) }; | ||
| 1460 | +} | ||
| 1461 | + | ||
| 1462 | +/// Current value of [`MODE_MI_OVERRIDE_HITS`]. | ||
| 1463 | +pub(crate) fn mode_mi_override_hits() -> usize { | ||
| 1464 | + MODE_MI_OVERRIDE_HITS.with(|c| c.get()) | ||
| 1465 | +} | ||
| 1466 | + | ||
| 1440 | // lane-sbpart r2: how many superblock-level `PARTITION_HORZ`/`PARTITION_VERT` | 1467 | // lane-sbpart r2: how many superblock-level `PARTITION_HORZ`/`PARTITION_VERT` |
| 1441 | // blocks (two true 64x32/32x64 strips, [`decode_block_rect64`]) fired -- the | 1468 | // blocks (two true 64x32/32x64 strips, [`decode_block_rect64`]) fired -- the |
| 1442 | // gate's proof this round's arms actually reached a real block, not just | 1469 | // gate's proof this round's arms actually reached a real block, not just |
| @@ -1694,6 +1721,21 @@ pub(crate) fn angle_delta_hits() -> usize { | |||
| 1694 | pub(crate) fn tx_class1_hits() -> usize { | 1721 | pub(crate) fn tx_class1_hits() -> usize { |
| 1695 | TX_CLASS1_HITS.with(|c| c.get()) | 1722 | TX_CLASS1_HITS.with(|c| c.get()) |
| 1696 | } | 1723 | } |
| 1724 | + | ||
| 1725 | +// How many `PARTITION_SPLIT` decisions below an 8x8 block (four independent | ||
| 1726 | +// `BLOCK_4X4` leaves, spec `decode_partition`'s `bSize < BLOCK_8X8` recursion | ||
| 1727 | +// bottom) this thread's decode actually reconstructed -- the same | ||
| 1728 | +// before/after counter pattern as [`TX_CLASS1_HITS`], proving a stream | ||
| 1729 | +// genuinely exercised the sub-8x8 leaf path rather than every attempt | ||
| 1730 | +// coincidentally landing on `PARTITION_NONE`. | ||
| 1731 | +thread_local! { | ||
| 1732 | + static SUB8_SPLIT_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) }; | ||
| 1733 | +} | ||
| 1734 | + | ||
| 1735 | +/// Current value of [`SUB8_SPLIT_HITS`]. | ||
| 1736 | +pub(crate) fn sub8_split_hits() -> usize { | ||
| 1737 | + SUB8_SPLIT_HITS.with(|c| c.get()) | ||
| 1738 | +} | ||
| 1697 | const SUB_MI: u32 = 4; | 1739 | const SUB_MI: u32 = 4; |
| 1698 | const MI: usize = 4; | 1740 | const MI: usize = 4; |
| 1699 | const SB: usize = 64; | 1741 | const SB: usize = 64; |
| @@ -2067,6 +2109,25 @@ const SCAN_8X32: [u16; 256] = [ | |||
| 2067 | 228, 235, 242, 249, 215, 222, 229, 236, 243, 250, 223, 230, 237, 244, 251, 231, 238, 245, 252, | 2109 | 228, 235, 242, 249, 215, 222, 229, 236, 243, 250, 223, 230, 237, 244, 251, 231, 238, 245, 252, |
| 2068 | 239, 246, 253, 247, 254, 255, | 2110 | 239, 246, 253, 247, 254, 255, |
| 2069 | ]; | 2111 | ]; |
| 2112 | +/// `Default_Scan_8x4` (lane-rectx, see [`SCAN_32X16`]'s doc comment for the | ||
| 2113 | +/// transposition rule this repo's `SCAN_WxH` names follow): this repo's | ||
| 2114 | +/// `(w=8, h=4)` reads libaom's own `default_scan_4x8` verbatim -- the same | ||
| 2115 | +/// axis swap [`SCAN_16X8`]/[`SCAN_8X16`] already carry one size class up | ||
| 2116 | +/// (repo `SCAN_16X8` == libaom `default_scan_8x16`, repo `SCAN_8X16` == | ||
| 2117 | +/// libaom `default_scan_16x8`), checked against `scan.c` before landing | ||
| 2118 | +/// rather than re-deriving the zigzag formula. | ||
| 2119 | +const SCAN_8X4: [u16; 32] = [ | ||
| 2120 | + 0, 8, 1, 16, 9, 2, 24, 17, 10, 3, 25, 18, 11, 4, 26, 19, 12, 5, 27, 20, 13, 6, 28, 21, 14, 7, | ||
| 2121 | + 29, 22, 15, 30, 23, 31, | ||
| 2122 | +]; | ||
| 2123 | + | ||
| 2124 | +/// `Default_Scan_4x8` (lane-rectx): this repo's `(w=4, h=8)` reads libaom's | ||
| 2125 | +/// own `default_scan_8x4` verbatim, the same transposition [`SCAN_8X4`]'s | ||
| 2126 | +/// doc comment explains. | ||
| 2127 | +const SCAN_4X8: [u16; 32] = [ | ||
| 2128 | + 0, 1, 4, 2, 5, 8, 3, 6, 9, 12, 7, 10, 13, 16, 11, 14, 17, 20, 15, 18, 21, 24, 19, 22, 25, 28, | ||
| 2129 | + 23, 26, 29, 27, 30, 31, | ||
| 2130 | +]; | ||
| 2070 | 2131 | ||
| 2071 | /// [`neighbour`] with independent `w` (row stride)/`h` (row-bound) extents | 2132 | /// [`neighbour`] with independent `w` (row stride)/`h` (row-bound) extents |
| 2072 | /// (lane-rectwire, mirrors [`record_rect`](Neighbours::record_rect)'s | 2133 | /// (lane-rectwire, mirrors [`record_rect`](Neighbours::record_rect)'s |
| @@ -2453,12 +2514,14 @@ fn read_coeffs( | |||
| 2453 | Ok((grid, tx_type)) | 2514 | Ok((grid, tx_type)) |
| 2454 | } | 2515 | } |
| 2455 | 2516 | ||
| 2456 | -/// [`read_coeffs`] widened to `(w, h)` (lane-rectwire), restricted to | 2517 | +/// [`read_coeffs`] widened to `(w, h)` (lane-rectwire; lane-rectx added the |
| 2457 | -/// `TxClass::TwoD` -- the only class either rect size pair this decoder codes | 2518 | +/// `tx_type` read [`TxbSet::LumaRect16x8`] needs), restricted to |
| 2458 | -/// can ever produce (see [`decode_block_rect`]'s doc comment): refuses by | 2519 | +/// `TxClass::TwoD` -- the only class any rect size pair this decoder codes |
| 2459 | -/// name rather than guess-decode if a `tx_type` symbol or non-2D class ever | 2520 | +/// can ever produce, since every `tx_type` this decoder's rect sets can read |
| 2460 | -/// shows up here, since neither `base_ctx_rect`/`br_ctx_rect` nor | 2521 | +/// (`EXT_TX_SET_DTT4_IDTX`'s five members) is itself 2D: refuses by name |
| 2461 | -/// [`class_scan_table`] have a rect form for those. | 2522 | +/// rather than guess-decode if a non-2D class ever shows up here, since |
| 2523 | +/// neither `base_ctx_rect`/`br_ctx_rect` nor [`class_scan_table`] have a rect | ||
| 2524 | +/// form for those. | ||
| 2462 | fn read_coeffs_rect( | 2525 | fn read_coeffs_rect( |
| 2463 | dec: &mut SymbolDecoder, | 2526 | dec: &mut SymbolDecoder, |
| 2464 | coding: &mut TxbTables, | 2527 | coding: &mut TxbTables, |
| @@ -2471,6 +2534,7 @@ fn read_coeffs_rect( | |||
| 2471 | ) -> Result<(Vec<i32>, TxType)> { | 2534 | ) -> Result<(Vec<i32>, TxType)> { |
| 2472 | let ec_trace_coeff = std::env::var_os("EC_TRACE_COEFF").is_some(); | 2535 | let ec_trace_coeff = std::env::var_os("EC_TRACE_COEFF").is_some(); |
| 2473 | let mut grid = vec![0i32; w * h]; | 2536 | let mut grid = vec![0i32; w * h]; |
| 2537 | + let entry_rng = dec.debug_state().0; | ||
| 2474 | let all_zero = dec.symbol(&mut coding.txb_skip[skip_ctx]) == 1; | 2538 | let all_zero = dec.symbol(&mut coding.txb_skip[skip_ctx]) == 1; |
| 2475 | if ec_trace_coeff { | 2539 | if ec_trace_coeff { |
| 2476 | let (rng, _) = dec.debug_state(); | 2540 | let (rng, _) = dec.debug_state(); |
| @@ -2482,17 +2546,35 @@ fn read_coeffs_rect( | |||
| 2482 | if all_zero { | 2546 | if all_zero { |
| 2483 | return Ok((grid, TxType::DctDct)); | 2547 | return Ok((grid, TxType::DctDct)); |
| 2484 | } | 2548 | } |
| 2485 | - if coding.tx_type.is_some() { | 2549 | + let trace = std::env::var_os("EC_TRACE_COEFF").is_some(); |
| 2486 | - return Err(unsupported( | 2550 | + if trace { |
| 2487 | - "a tx_type symbol on a rectangular transform (never expected at this size)", | 2551 | + let (rng, _) = dec.debug_state(); |
| 2488 | - )); | 2552 | + eprintln!("EC_COEFF_STEP tag=all_zero ctx={skip_ctx} all_zero=0 rng={rng}"); |
| 2553 | + } | ||
| 2554 | + let mut tx_type = default_tx_type; | ||
| 2555 | + if let Some(tx_type_cdf) = coding.tx_type.as_deref_mut() { | ||
| 2556 | + // Mirrors [`read_coeffs`]'s own `tx_type` read: the CDF row's width | ||
| 2557 | + // names its set (lane-rectx, `TxbSet::LumaRect16x8` -- the one rect | ||
| 2558 | + // set here that carries a `tx_type` symbol at all). | ||
| 2559 | + let len = tx_type_cdf.len(); | ||
| 2560 | + let t = dec.symbol(tx_type_cdf); | ||
| 2561 | + tx_type = match len { | ||
| 2562 | + 17 => TxType::from_symbol_all16(t), | ||
| 2563 | + 13 => TxType::from_symbol_set2_12(t), | ||
| 2564 | + 8 => TxType::from_symbol_set1(t), | ||
| 2565 | + _ => TxType::from_symbol(t), | ||
| 2566 | + } | ||
| 2567 | + .ok_or_else(|| unsupported(format!("a tx_type symbol outside its CDF's own set: {t}")))?; | ||
| 2489 | } | 2568 | } |
| 2490 | - let tx_type = default_tx_type; | ||
| 2491 | if TxClass::of(tx_type) != TxClass::TwoD { | 2569 | if TxClass::of(tx_type) != TxClass::TwoD { |
| 2492 | return Err(unsupported( | 2570 | return Err(unsupported( |
| 2493 | "a non-2D tx class on a rectangular transform (never expected at this size)", | 2571 | "a non-2D tx class on a rectangular transform (never expected at this size)", |
| 2494 | )); | 2572 | )); |
| 2495 | } | 2573 | } |
| 2574 | + if trace { | ||
| 2575 | + let (rng, _) = dec.debug_state(); | ||
| 2576 | + eprintln!("EC_COEFF_STEP tag=tx_type rng={rng}"); | ||
| 2577 | + } | ||
| 2496 | let eob = read_eob(dec, coding, TxClass::TwoD); | 2578 | let eob = read_eob(dec, coding, TxClass::TwoD); |
| 2497 | if ec_trace_coeff { | 2579 | if ec_trace_coeff { |
| 2498 | let (rng, _) = dec.debug_state(); | 2580 | let (rng, _) = dec.debug_state(); |
| @@ -2547,6 +2629,10 @@ fn read_coeffs_rect( | |||
| 2547 | level | 2629 | level |
| 2548 | }; | 2630 | }; |
| 2549 | levels[pos] = level; | 2631 | levels[pos] = level; |
| 2632 | + if trace { | ||
| 2633 | + let (rng, _) = dec.debug_state(); | ||
| 2634 | + eprintln!("EC_COEFF_STEP tag=base c={scan_idx} pos={pos} level={level} rng={rng}"); | ||
| 2635 | + } | ||
| 2550 | } | 2636 | } |
| 2551 | if ec_trace_coeff { | 2637 | if ec_trace_coeff { |
| 2552 | let (rng, _) = dec.debug_state(); | 2638 | let (rng, _) = dec.debug_state(); |
| @@ -2562,6 +2648,10 @@ fn read_coeffs_rect( | |||
| 2562 | } else { | 2648 | } else { |
| 2563 | dec.literal(1) == 1 | 2649 | dec.literal(1) == 1 |
| 2564 | }; | 2650 | }; |
| 2651 | + if trace { | ||
| 2652 | + let (rng, _) = dec.debug_state(); | ||
| 2653 | + eprintln!("EC_COEFF_STEP tag=sign_rect pos={pos} sign={} rng={rng}", u8::from(negative)); | ||
| 2654 | + } | ||
| 2565 | let level = if level.abs_diff(0) as i32 > MAX_BR_LEVEL { | 2655 | let level = if level.abs_diff(0) as i32 > MAX_BR_LEVEL { |
| 2566 | let g = read_golomb(dec)?; | 2656 | let g = read_golomb(dec)?; |
| 2567 | level + g as i32 | 2657 | level + g as i32 |
| @@ -2644,6 +2734,26 @@ struct Neighbours { | |||
| 2644 | /// one was coded at 8x8. | 2734 | /// one was coded at 8x8. |
| 2645 | above_side_mi: Vec<usize>, | 2735 | above_side_mi: Vec<usize>, |
| 2646 | left_side_mi: Vec<usize>, | 2736 | left_side_mi: Vec<usize>, |
| 2737 | + /// The luma `mode` of the last `BLOCK_4X4` leaf decoded at each mi column | ||
| 2738 | + /// / row, with the mi position it was written at | ||
| 2739 | + /// (`(usize::MAX, _)` = never written). `above_mode`/`left_mode` are on | ||
| 2740 | + /// the coarse 16x16 grid, which cannot distinguish the two 4x4 leaves an | ||
| 2741 | + /// 8x8 `PARTITION_SPLIT` puts in one mi column; libaom's intra-mode | ||
| 2742 | + /// context reads `mi(row, col-1)`/`mi(row-1, col)` exactly, so a sub-8x8 | ||
| 2743 | + /// leaf whose neighbour is another split group needs that group's leaf 3 | ||
| 2744 | + /// (bottom-right), not the leaf the coarse slot happens to hold. Written | ||
| 2745 | + /// and read only by [`decode_leaf_split4`]; the position guard makes it | ||
| 2746 | + /// fall back to the coarse slot whenever the real neighbour was a block | ||
| 2747 | + /// of 8x8 or larger (whose one mode is correct for every row it spans). | ||
| 2748 | + sub8_mode_col: Vec<(usize, usize)>, | ||
| 2749 | + sub8_mode_row: Vec<(usize, usize)>, | ||
| 2750 | + /// The `uv_mode` twin of `sub8_mode_col`/`sub8_mode_row` (lane-sub8 r5): | ||
| 2751 | + /// chroma's edge-filter type reads the CHROMA neighbour's `uv_mode` | ||
| 2752 | + /// (`get_intra_edge_filter_type`, reconintra.c:974), and the coarse | ||
| 2753 | + /// [`SUB`] slots cannot name it once a 16x16 is split into 8x8 leaves -- | ||
| 2754 | + /// the leaf above writes the same row slot the block to the left owns. | ||
| 2755 | + uv_mode_col: Vec<(usize, usize)>, | ||
| 2756 | + uv_mode_row: Vec<(usize, usize)>, | ||
| 2647 | /// Whether the block above/left of this column/row was coded `skip` -- | 2757 | /// Whether the block above/left of this column/row was coded `skip` -- |
| 2648 | /// an inter frame's own `skip` context (spec `SkipContext`), which the | 2758 | /// an inter frame's own `skip` context (spec `SkipContext`), which the |
| 2649 | /// key-frame writer never tracks (its skip context is always zero); a | 2759 | /// key-frame writer never tracks (its skip context is always zero); a |
| @@ -2791,6 +2901,10 @@ impl Neighbours { | |||
| 2791 | left_side: vec![SB; rows], | 2901 | left_side: vec![SB; rows], |
| 2792 | above_side_mi: vec![SB; cols * (SUB / MI)], | 2902 | above_side_mi: vec![SB; cols * (SUB / MI)], |
| 2793 | left_side_mi: vec![SB; rows * (SUB / MI)], | 2903 | left_side_mi: vec![SB; rows * (SUB / MI)], |
| 2904 | + sub8_mode_col: vec![(usize::MAX, 0); cols * (SUB / MI)], | ||
| 2905 | + sub8_mode_row: vec![(usize::MAX, 0); rows * (SUB / MI)], | ||
| 2906 | + uv_mode_col: vec![(usize::MAX, 0); cols * (SUB / MI)], | ||
| 2907 | + uv_mode_row: vec![(usize::MAX, 0); rows * (SUB / MI)], | ||
| 2794 | above_txfm: vec![TXFM_CTX_INIT; cols * (SUB / MI)], | 2908 | above_txfm: vec![TXFM_CTX_INIT; cols * (SUB / MI)], |
| 2795 | left_txfm: vec![TXFM_CTX_INIT; rows * (SUB / MI)], | 2909 | left_txfm: vec![TXFM_CTX_INIT; rows * (SUB / MI)], |
| 2796 | // lane-inter8 r2: mi(4px)-granular, not [`SUB`]-granular -- an | 2910 | // lane-inter8 r2: mi(4px)-granular, not [`SUB`]-granular -- an |
| @@ -2874,6 +2988,14 @@ impl Neighbours { | |||
| 2874 | self.above_compound_idx[i] = 0; | 2988 | self.above_compound_idx[i] = 0; |
| 2875 | self.above_filter[i] = [3u8; 2]; | 2989 | self.above_filter[i] = [3u8; 2]; |
| 2876 | } | 2990 | } |
| 2991 | + // lane-sub8 r6: the mi-granular column maps are per tile too -- a | ||
| 2992 | + // stale `(row, mode)` from the tile to the LEFT names an mi row this | ||
| 2993 | + // tile's first block would read as its own above neighbour. | ||
| 2994 | + let mcol_end = col1_mi.min(self.sub8_mode_col.len()); | ||
| 2995 | + for i in col0_mi.min(mcol_end)..mcol_end { | ||
| 2996 | + self.sub8_mode_col[i] = (usize::MAX, 0); | ||
| 2997 | + self.uv_mode_col[i] = (usize::MAX, 0); | ||
| 2998 | + } | ||
| 2877 | } | 2999 | } |
| 2878 | 3000 | ||
| 2879 | /// Writes a just-decoded block's own palette-Y size/colours (`size == 0` | 3001 | /// Writes a just-decoded block's own palette-Y size/colours (`size == 0` |
| @@ -3192,6 +3314,10 @@ impl Neighbours { | |||
| 3192 | self.left_comp_group_idx.iter_mut().for_each(|r| *r = 0); | 3314 | self.left_comp_group_idx.iter_mut().for_each(|r| *r = 0); |
| 3193 | self.left_compound_idx.iter_mut().for_each(|r| *r = 0); | 3315 | self.left_compound_idx.iter_mut().for_each(|r| *r = 0); |
| 3194 | self.left_filter.iter_mut().for_each(|f| *f = [3u8; 2]); | 3316 | self.left_filter.iter_mut().for_each(|f| *f = [3u8; 2]); |
| 3317 | + // lane-sub8 r6: mi-granular row maps reset with the rest of the left | ||
| 3318 | + // context (a tile/SB-row boundary has no left neighbour). | ||
| 3319 | + self.sub8_mode_row.iter_mut().for_each(|s| *s = (usize::MAX, 0)); | ||
| 3320 | + self.uv_mode_row.iter_mut().for_each(|s| *s = (usize::MAX, 0)); | ||
| 3195 | } | 3321 | } |
| 3196 | 3322 | ||
| 3197 | /// Records a block's `skip`/`is_inter`/`interp_filter` state for the next | 3323 | /// Records a block's `skip`/`is_inter`/`interp_filter` state for the next |
| @@ -3480,6 +3606,104 @@ impl Neighbours { | |||
| 3480 | /// [`Self::partition_ctx`]) are the neighbour's own width/height per the | 3606 | /// [`Self::partition_ctx`]) are the neighbour's own width/height per the |
| 3481 | /// spec's per-edge partition-context rule, so a true rectangular block | 3607 | /// spec's per-edge partition-context rule, so a true rectangular block |
| 3482 | /// naturally wants two different values here rather than one. | 3608 | /// naturally wants two different values here rather than one. |
| 3609 | + /// Writes this block's luma `mode` into the mi-granular | ||
| 3610 | + /// [`Self::sub8_mode_col`]/[`Self::sub8_mode_row`] maps, keyed by the mi | ||
| 3611 | + /// position a *later* neighbour would read it from: the block's LAST mi | ||
| 3612 | + /// row for every column it spans (what the block below reads via | ||
| 3613 | + /// `mi(row-1, col)`) and its LAST mi column for every row (what the | ||
| 3614 | + /// block to the right reads via `mi(row, col-1)`). Only sub-8x8 leaves | ||
| 3615 | + /// read these back, and only when the recorded position is exactly their | ||
| 3616 | + /// own neighbour -- see [`Self::sub8_mode_col`]'s doc. | ||
| 3617 | + fn record_mode_mi(&mut self, mi_r: usize, mi_c: usize, mi_w: usize, mi_h: usize, mode: usize) { | ||
| 3618 | + let (last_r, last_c) = (mi_r + mi_h - 1, mi_c + mi_w - 1); | ||
| 3619 | + for cell in 0..mi_w { | ||
| 3620 | + if let Some(slot) = self.sub8_mode_col.get_mut(mi_c + cell) { | ||
| 3621 | + *slot = (last_r, mode); | ||
| 3622 | + } | ||
| 3623 | + } | ||
| 3624 | + for cell in 0..mi_h { | ||
| 3625 | + if let Some(slot) = self.sub8_mode_row.get_mut(mi_r + cell) { | ||
| 3626 | + *slot = (last_c, mode); | ||
| 3627 | + } | ||
| 3628 | + } | ||
| 3629 | + } | ||
| 3630 | + | ||
| 3631 | + /// The mi-exact above/left neighbour luma mode for a block whose top-left | ||
| 3632 | + /// mi is `(mi_r, mi_c)`, or `None` when no block has recorded that exact | ||
| 3633 | + /// mi position (then the coarse [`SUB`]-grid slot is right by | ||
| 3634 | + /// construction). See [`Self::record_mode_mi`]. | ||
| 3635 | + fn mode_above_mi(&self, mi_r: usize, mi_c: usize) -> Option<usize> { | ||
| 3636 | + match self.sub8_mode_col.get(mi_c) { | ||
| 3637 | + Some(&(row, m)) if mi_r > self.tile_row0_mi && row == mi_r - 1 => Some(m), | ||
| 3638 | + _ => None, | ||
| 3639 | + } | ||
| 3640 | + } | ||
| 3641 | + | ||
| 3642 | + fn mode_left_mi(&self, mi_r: usize, mi_c: usize) -> Option<usize> { | ||
| 3643 | + match self.sub8_mode_row.get(mi_r) { | ||
| 3644 | + Some(&(col, m)) if mi_c > self.tile_col0_mi && col == mi_c - 1 => Some(m), | ||
| 3645 | + _ => None, | ||
| 3646 | + } | ||
| 3647 | + } | ||
| 3648 | + | ||
| 3649 | + /// [`Self::record_mode_mi`] for the block's `uv_mode`, into | ||
| 3650 | + /// [`Self::uv_mode_col`]/[`Self::uv_mode_row`]. | ||
| 3651 | + fn record_uv_mode_mi( | ||
| 3652 | + &mut self, | ||
| 3653 | + mi_r: usize, | ||
| 3654 | + mi_c: usize, | ||
| 3655 | + mi_w: usize, | ||
| 3656 | + mi_h: usize, | ||
| 3657 | + uv_mode: usize, | ||
| 3658 | + ) { | ||
| 3659 | + let (last_r, last_c) = (mi_r + mi_h - 1, mi_c + mi_w - 1); | ||
| 3660 | + for cell in 0..mi_w { | ||
| 3661 | + if let Some(slot) = self.uv_mode_col.get_mut(mi_c + cell) { | ||
| 3662 | + *slot = (last_r, uv_mode); | ||
| 3663 | + } | ||
| 3664 | + } | ||
| 3665 | + for cell in 0..mi_h { | ||
| 3666 | + if let Some(slot) = self.uv_mode_row.get_mut(mi_r + cell) { | ||
| 3667 | + *slot = (last_c, uv_mode); | ||
| 3668 | + } | ||
| 3669 | + } | ||
| 3670 | + } | ||
| 3671 | + | ||
| 3672 | + /// Whether either mi-exact chroma neighbour of the block at `(mi_r, mi_c)` | ||
| 3673 | + /// coded a smooth `uv_mode` -- libaom's `intra_edge_filter_type` for | ||
| 3674 | + /// planes 1/2. Falls back to the coarse [`SUB`] slot on whichever axis no | ||
| 3675 | + /// block has recorded the exact neighbouring mi. | ||
| 3676 | + fn smooth_uv_neighbour(&self, mi_r: usize, mi_c: usize, r: usize, c: usize) -> bool { | ||
| 3677 | + let above = match self.uv_mode_col.get(mi_c) { | ||
| 3678 | + Some(&(row, m)) if mi_r > self.tile_row0_mi && row == mi_r - 1 => m, | ||
| 3679 | + _ => self.above_uv_mode[c], | ||
| 3680 | + }; | ||
| 3681 | + let left = match self.uv_mode_row.get(mi_r) { | ||
| 3682 | + Some(&(col, m)) if mi_c > self.tile_col0_mi && col == mi_c - 1 => m, | ||
| 3683 | + _ => self.left_uv_mode[r], | ||
| 3684 | + }; | ||
| 3685 | + is_smooth_mode(above) || is_smooth_mode(left) | ||
| 3686 | + } | ||
| 3687 | + | ||
| 3688 | + /// The above/left luma modes libaom's `above_mi`/`left_mi` really see for a | ||
| 3689 | + /// block at coarse [`SUB`]-grid `(r, c)`. lane-rectx r5: the coarse | ||
| 3690 | + /// `above_mode`/`left_mode` slots are written in 16x16 cells, so a | ||
| 3691 | + /// sub-16x16 neighbour (a 16x8 rect leaf, an 8x8 split cell) leaves them | ||
| 3692 | + /// holding an OLDER, larger block's mode -- it only ever recorded into the | ||
| 3693 | + /// mi-exact map. Every `kf_y_mode` reader goes through here, not just the | ||
| 3694 | + /// strip path ([`decode_leaf_rect`] took this override in r4; a 32x16 strip | ||
| 3695 | + /// whose left neighbour was a 16x8 leaf still read the stale row and picked | ||
| 3696 | + /// a different CDF for the same mode value). | ||
| 3697 | + fn modes_above_left(&self, r: usize, c: usize) -> (usize, usize) { | ||
| 3698 | + let (mi_r, mi_c) = (r * (SUB / MI), c * (SUB / MI)); | ||
| 3699 | + let above = self.mode_above_mi(mi_r, mi_c).unwrap_or(self.above_mode[c]); | ||
| 3700 | + let left = self.mode_left_mi(mi_r, mi_c).unwrap_or(self.left_mode[r]); | ||
| 3701 | + if above != self.above_mode[c] || left != self.left_mode[r] { | ||
| 3702 | + MODE_MI_OVERRIDE_HITS.with(|h| h.set(h.get() + 1)); | ||
| 3703 | + } | ||
| 3704 | + (above, left) | ||
| 3705 | + } | ||
| 3706 | + | ||
| 3483 | fn record_rect( | 3707 | fn record_rect( |
| 3484 | &mut self, | 3708 | &mut self, |
| 3485 | at: (usize, usize), | 3709 | at: (usize, usize), |
| @@ -3500,6 +3724,8 @@ impl Neighbours { | |||
| 3500 | self.left_uv_mode[r + cell] = uv_mode; | 3724 | self.left_uv_mode[r + cell] = uv_mode; |
| 3501 | self.left_side[r + cell] = h; | 3725 | self.left_side[r + cell] = h; |
| 3502 | } | 3726 | } |
| 3727 | + self.record_mode_mi(r * (SUB / MI), c * (SUB / MI), w / MI, h / MI, mode); | ||
| 3728 | + self.record_uv_mode_mi(r * (SUB / MI), c * (SUB / MI), w / MI, h / MI, uv_mode); | ||
| 3503 | self.record_mi_rect((r * (SUB / MI), c * (SUB / MI)), w, h, grids); | 3729 | self.record_mi_rect((r * (SUB / MI), c * (SUB / MI)), w, h, grids); |
| 3504 | } | 3730 | } |
| 3505 | 3731 | ||
| @@ -3629,6 +3855,8 @@ impl Neighbours { | |||
| 3629 | } | 3855 | } |
| 3630 | let (mi_r, mi_c) = (r * (SUB / MI), c * (SUB / MI)); | 3856 | let (mi_r, mi_c) = (r * (SUB / MI), c * (SUB / MI)); |
| 3631 | let (w_mi, h_mi) = (w / MI, h / MI); | 3857 | let (w_mi, h_mi) = (w / MI, h / MI); |
| 3858 | + self.record_mode_mi(mi_r, mi_c, w_mi, h_mi, mode); | ||
| 3859 | + self.record_uv_mode_mi(mi_r, mi_c, w_mi, h_mi, uv_mode); | ||
| 3632 | for cell in 0..h_mi { | 3860 | for cell in 0..h_mi { |
| 3633 | self.left_side_mi[mi_r + cell] = h; | 3861 | self.left_side_mi[mi_r + cell] = h; |
| 3634 | } | 3862 | } |
| @@ -3685,6 +3913,13 @@ fn filter_intra_size_class_rect(bw: usize, bh: usize) -> Option<usize> { | |||
| 3685 | match (bw, bh) { | 3913 | match (bw, bh) { |
| 3686 | (32, 16) => Some(4), | 3914 | (32, 16) => Some(4), |
| 3687 | (16, 32) => Some(5), | 3915 | (16, 32) => Some(5), |
| 3916 | + // lane-rectx r3: `av1_filter_intra_allowed_bsize` is "both sides <= | ||
| 3917 | + // 32", so a 16x8/8x16 strip reads the flag too -- returning `None` | ||
| 3918 | + // here dropped that symbol on every DC_PRED strip of that size and | ||
| 3919 | + // desynced the tile (caught against an aomdec EC_TRACE_COEFF ladder: | ||
| 3920 | + // identical mode/uv_mode values, range 34808 vs the oracle's 40668). | ||
| 3921 | + (16, 8) => Some(6), | ||
| 3922 | + (8, 16) => Some(7), | ||
| 3688 | _ if bw == bh => filter_intra_size_class(bw), | 3923 | _ if bw == bh => filter_intra_size_class(bw), |
| 3689 | _ => None, | 3924 | _ => None, |
| 3690 | } | 3925 | } |
| @@ -4562,14 +4797,15 @@ fn decode_block_rect( | |||
| 4562 | ) -> Result<()> { | 4797 | ) -> Result<()> { |
| 4563 | let (r, c) = at; | 4798 | let (r, c) = at; |
| 4564 | let (px, py) = (c * SUB, r * SUB); | 4799 | let (px, py) = (c * SUB, r * SUB); |
| 4800 | + let (nb_above_mode, nb_left_mode) = neighbours.modes_above_left(r, c); | ||
| 4565 | let (palette_ctx, palette_cache) = neighbours.palette_ctx_and_cache(at); | 4801 | let (palette_ctx, palette_cache) = neighbours.palette_ctx_and_cache(at); |
| 4566 | let palette_uv_cache = neighbours.palette_uv_cache(at); | 4802 | let palette_uv_cache = neighbours.palette_uv_cache(at); |
| 4567 | let (skip, mode, angle_delta_y, uv_mode, angle_delta_uv, alpha, filter_intra, palette_y, palette_uv) = | 4803 | let (skip, mode, angle_delta_y, uv_mode, angle_delta_uv, alpha, filter_intra, palette_y, palette_uv) = |
| 4568 | read_intra_mode_rect( | 4804 | read_intra_mode_rect( |
| 4569 | dec, | 4805 | dec, |
| 4570 | cdfs, | 4806 | cdfs, |
| 4571 | - neighbours.above_mode[c], | 4807 | + nb_above_mode, |
| 4572 | - neighbours.left_mode[r], | 4808 | + nb_left_mode, |
| 4573 | true, | 4809 | true, |
| 4574 | bw, | 4810 | bw, |
| 4575 | bh, | 4811 | bh, |
| @@ -4581,8 +4817,7 @@ fn decode_block_rect( | |||
| 4581 | r * (SUB / MI), | 4817 | r * (SUB / MI), |
| 4582 | c * (SUB / MI), | 4818 | c * (SUB / MI), |
| 4583 | )?; | 4819 | )?; |
| 4584 | - let smooth_neighbor = | 4820 | + let smooth_neighbor = is_smooth_mode(nb_above_mode) || is_smooth_mode(nb_left_mode); |
| 4585 | - is_smooth_mode(neighbours.above_mode[c]) || is_smooth_mode(neighbours.left_mode[r]); | ||
| 4586 | if smooth_neighbor { | 4821 | if smooth_neighbor { |
| 4587 | SMOOTH_LUMA_HITS.with(|c| c.set(c.get() + 1)); | 4822 | SMOOTH_LUMA_HITS.with(|c| c.set(c.get() + 1)); |
| 4588 | } | 4823 | } |
| @@ -4977,9 +5212,10 @@ fn decode_block_rect( | |||
| 4977 | /// writers (`record_mi_rect`, `fill_skip_grid_rect`, `fill_lf_grid_rect`) at | 5212 | /// writers (`record_mi_rect`, `fill_skip_grid_rect`, `fill_lf_grid_rect`) at |
| 4978 | /// this strip's real position, never the coarse `record_rect` (which the | 5213 | /// this strip's real position, never the coarse `record_rect` (which the |
| 4979 | /// caller uses once, after both strips, exactly like the `VERT_B` arm next | 5214 | /// caller uses once, after both strips, exactly like the `VERT_B` arm next |
| 4980 | -/// to it). Only the skip case is ported -- see [`decode_block_rect`]'s own | 5215 | +/// to it). The non-skip case (lane-rectx) reads real `TX_16X8`/`TX_8X16` |
| 4981 | -/// doc for why a coded rect strip below 16x16 has no coefficient tables here | 5216 | +/// luma coefficients (`TxbSet::LumaRect16x8`) and their `TX_8X4`/`TX_4X8` |
| 4982 | -/// yet. | 5217 | +/// chroma half (`TxbSet::ChromaRect8x4`), the two size classes one level |
| 5218 | +/// under [`decode_block_rect`]'s own 32x16/16x32 strip. | ||
| 4983 | #[allow(clippy::too_many_arguments)] | 5219 | #[allow(clippy::too_many_arguments)] |
| 4984 | fn decode_leaf_rect( | 5220 | fn decode_leaf_rect( |
| 4985 | dec: &mut SymbolDecoder, | 5221 | dec: &mut SymbolDecoder, |
| @@ -4997,8 +5233,15 @@ fn decode_leaf_rect( | |||
| 4997 | allow_screen_content_tools: bool, | 5233 | allow_screen_content_tools: bool, |
| 4998 | base_q_idx: u8, | 5234 | base_q_idx: u8, |
| 4999 | tx_select: bool, | 5235 | tx_select: bool, |
| 5236 | + reduced_tx_set: bool, | ||
| 5000 | ) -> Result<usize> { | 5237 | ) -> Result<usize> { |
| 5001 | let _ = base_q_idx; | 5238 | let _ = base_q_idx; |
| 5239 | + if std::env::var_os("EC_AV1_RECTX_TRACE").is_some() { | ||
| 5240 | + eprintln!( | ||
| 5241 | + "decode_leaf_rect: leaf_mi={leaf_mi:?} bw={bw} bh={bh} outer_at={outer_at:?} rng={}", | ||
| 5242 | + dec.debug_state().0 | ||
| 5243 | + ); | ||
| 5244 | + } | ||
| 5002 | let (r, c) = outer_at; | 5245 | let (r, c) = outer_at; |
| 5003 | let mut above_mode = neighbours.above_mode[c]; | 5246 | let mut above_mode = neighbours.above_mode[c]; |
| 5004 | let mut left_mode = neighbours.left_mode[r]; | 5247 | let mut left_mode = neighbours.left_mode[r]; |
| @@ -5010,6 +5253,16 @@ fn decode_leaf_rect( | |||
| 5010 | left_mode = pmode; | 5253 | left_mode = pmode; |
| 5011 | } | 5254 | } |
| 5012 | } | 5255 | } |
| 5256 | + // Same mi-exact override [`decode_leaf8`] takes: one coarse 16x16 slot | ||
| 5257 | + // cannot hold the modes a split (or a pair of strips) leaves behind, so | ||
| 5258 | + // when the map holds the block at exactly this strip's above/left mi it | ||
| 5259 | + // is the neighbour libaom's `above_mi`/`left_mi` reads. | ||
| 5260 | + if let Some(m) = neighbours.mode_above_mi(leaf_mi.0, leaf_mi.1) { | ||
| 5261 | + above_mode = m; | ||
| 5262 | + } | ||
| 5263 | + if let Some(m) = neighbours.mode_left_mi(leaf_mi.0, leaf_mi.1) { | ||
| 5264 | + left_mode = m; | ||
| 5265 | + } | ||
| 5013 | let smooth_neighbor = | 5266 | let smooth_neighbor = |
| 5014 | is_smooth_mode(above_mode) || is_smooth_mode(left_mode); | 5267 | is_smooth_mode(above_mode) || is_smooth_mode(left_mode); |
| 5015 | if smooth_neighbor { | 5268 | if smooth_neighbor { |
| @@ -5049,6 +5302,9 @@ fn decode_leaf_rect( | |||
| 5049 | "a palette block on a HORZ/VERT intra strip below 16x16 (reconstruction not ported)", | 5302 | "a palette block on a HORZ/VERT intra strip below 16x16 (reconstruction not ported)", |
| 5050 | )); | 5303 | )); |
| 5051 | } | 5304 | } |
| 5305 | + if std::env::var_os("EC_AV1_RECTX_TRACE").is_some() { | ||
| 5306 | + eprintln!(" skip={skip} mode={mode} angle_delta_y={angle_delta_y} uv_mode={uv_mode}"); | ||
| 5307 | + } | ||
| 5052 | if filter_intra.is_some() { | 5308 | if filter_intra.is_some() { |
| 5053 | return Err(unsupported( | 5309 | return Err(unsupported( |
| 5054 | "filter intra on a HORZ/VERT strip (this decoder predicts square-only)", | 5310 | "filter intra on a HORZ/VERT strip (this decoder predicts square-only)", |
| @@ -5067,66 +5323,99 @@ fn decode_leaf_rect( | |||
| 5067 | prediction is not ported)", | 5323 | prediction is not ported)", |
| 5068 | )); | 5324 | )); |
| 5069 | } | 5325 | } |
| 5070 | - if !skip { | ||
| 5071 | - return Err(unsupported( | ||
| 5072 | - "a coded (non-skip) HORZ/VERT rect strip below 16x16 (this decoder ports only \ | ||
| 5073 | - the skip case at this size)", | ||
| 5074 | - )); | ||
| 5075 | - } | ||
| 5076 | let (px, py) = (leaf_mi.1 * MI, leaf_mi.0 * MI); | 5326 | let (px, py) = (leaf_mi.1 * MI, leaf_mi.0 * MI); |
| 5077 | let reach = Reach::of_rect(bw, bh, px, py, y.width, y.height); | 5327 | let reach = Reach::of_rect(bw, bh, px, py, y.width, y.height); |
| 5078 | let (cpx, cpy) = (px / 2, py / 2); | 5328 | let (cpx, cpy) = (px / 2, py / 2); |
| 5079 | let (chroma_w, chroma_h) = (bw / 2, bh / 2); | 5329 | let (chroma_w, chroma_h) = (bw / 2, bh / 2); |
| 5080 | - y.reconstruct_rect( | 5330 | + let (luma_levels, u_levels, v_levels); |
| 5081 | - px, | 5331 | + if skip { |
| 5082 | - py, | 5332 | + luma_levels = vec![0i32; bw * bh]; |
| 5083 | - bw, | 5333 | + u_levels = vec![0i32; chroma_w * chroma_h]; |
| 5084 | - bh, | 5334 | + v_levels = vec![0i32; chroma_w * chroma_h]; |
| 5085 | - mode, | 5335 | + y.reconstruct_rect( |
| 5086 | - angle_delta_y, | 5336 | + px, py, bw, bh, mode, angle_delta_y, reach, &luma_levels, None, filter_intra, |
| 5087 | - reach, | 5337 | + smooth_neighbor, |
| 5088 | - &vec![0i32; bw * bh], | 5338 | + ); |
| 5089 | - None, | 5339 | + let ac = alpha.map(|_| cfl_ac_q3_rect(y, px, py, bw, bh)); |
| 5090 | - filter_intra, | 5340 | + u.reconstruct_rect( |
| 5091 | - smooth_neighbor, | 5341 | + cpx, cpy, chroma_w, chroma_h, uv_predict_mode, angle_delta_uv, reach, &u_levels, |
| 5092 | - ); | 5342 | + alpha.zip(ac.as_deref()).map(|((au, _), ac)| (au, ac)), None, false, |
| 5093 | - let ac = alpha.map(|_| cfl_ac_q3_rect(y, px, py, bw, bh)); | 5343 | + ); |
| 5094 | - u.reconstruct_rect( | 5344 | + v.reconstruct_rect( |
| 5095 | - cpx, | 5345 | + cpx, cpy, chroma_w, chroma_h, uv_predict_mode, angle_delta_uv, reach, &v_levels, |
| 5096 | - cpy, | 5346 | + alpha.zip(ac.as_deref()).map(|((_, av), ac)| (av, ac)), None, false, |
| 5097 | - chroma_w, | 5347 | + ); |
| 5098 | - chroma_h, | 5348 | + } else { |
| 5099 | - uv_predict_mode, | 5349 | + // lane-rectx: a genuine 16x8/8x16 luma transform (`TxbSet::LumaRect16x8`, |
| 5100 | - angle_delta_uv, | 5350 | + // real `EOB_PT_128_LUMA` alphabet + the same mode-indexed `tx_type` |
| 5101 | - reach, | 5351 | + // symbol the square `Luma16` set reads -- `get_ext_tx_set_type`'s |
| 5102 | - &vec![0i32; chroma_w * chroma_h], | 5352 | + // `use_reduced_set` branch returns `EXT_TX_SET_DTT4_IDTX` at |
| 5103 | - alpha.zip(ac.as_deref()).map(|((au, _), ac)| (au, ac)), | 5353 | + // `tx_size_sqr_up == TX_16X16` regardless of the true, non-square |
| 5104 | - None, | 5354 | + // `tx_size`) and its chroma half (8x4/4x8, `TxbSet::ChromaRect8x4`). |
| 5105 | - false, | 5355 | + let (luma_scan, chroma_scan): (&[u16], &[u16]) = if bw == 16 { |
| 5106 | - ); | 5356 | + (&SCAN_16X8, &SCAN_8X4) |
| 5107 | - v.reconstruct_rect( | 5357 | + } else { |
| 5108 | - cpx, | 5358 | + (&SCAN_8X16, &SCAN_4X8) |
| 5109 | - cpy, | 5359 | + }; |
| 5110 | - chroma_w, | 5360 | + let around = neighbours.around_mi_rect(leaf_mi, bw, bh); |
| 5111 | - chroma_h, | 5361 | + let luma_set = if reduced_tx_set { |
| 5112 | - uv_predict_mode, | 5362 | + TxbSet::LumaRect16x8 |
| 5113 | - angle_delta_uv, | 5363 | + } else { |
| 5114 | - reach, | 5364 | + TxbSet::LumaRect16x8Set1 |
| 5115 | - &vec![0i32; chroma_w * chroma_h], | 5365 | + }; |
| 5116 | - alpha.zip(ac.as_deref()).map(|((_, av), ac)| (av, ac)), | 5366 | + let mut luma_coding = cdfs.txb(luma_set, mode); |
| 5117 | - None, | 5367 | + let (l_levels, luma_tx_type) = read_coeffs_rect( |
| 5118 | - false, | 5368 | + dec, &mut luma_coding, luma_scan, bw, bh, 0, dc_sign_ctx(around[0].2), TxType::DctDct, |
| 5119 | - ); | 5369 | + )?; |
| 5120 | - neighbours.record_mi_rect( | 5370 | + if std::env::var_os("EC_AV1_RECTX_TRACE").is_some() { |
| 5121 | - leaf_mi, | 5371 | + let nz: Vec<(usize, i32)> = l_levels.iter().copied().enumerate().filter(|(_, v)| *v != 0).collect(); |
| 5122 | - bw, | 5372 | + eprintln!(" luma_tx_type={luma_tx_type:?} nz_levels={nz:?}"); |
| 5123 | - bh, | 5373 | + } |
| 5124 | - &[ | 5374 | + luma_levels = l_levels; |
| 5125 | - vec![0i32; bw * bh], | 5375 | + let luma_residual = dequant_and_inverse_typed_wh( |
| 5126 | - vec![0i32; chroma_w * chroma_h], | 5376 | + &luma_levels, bw, bh, crate::decode::bit_depth(), |
| 5127 | - vec![0i32; chroma_w * chroma_h], | 5377 | + CURRENT_Q_IDX.with(|c| c.get()), plane_q_delta(0).0, plane_q_delta(0).1, luma_tx_type, |
| 5128 | - ], | 5378 | + ); |
| 5129 | - ); | 5379 | + y.reconstruct_rect( |
| 5380 | + px, py, bw, bh, mode, angle_delta_y, reach, &luma_residual, None, filter_intra, | ||
| 5381 | + smooth_neighbor, | ||
| 5382 | + ); | ||
| 5383 | + let ac = alpha.map(|_| cfl_ac_q3_rect(y, px, py, bw, bh)); | ||
| 5384 | + let u_default_tx = default_intra_tx_type(uv_predict_mode as u8); | ||
| 5385 | + let u_skip_ctx = usize::from(around[1].0) + usize::from(around[1].1); | ||
| 5386 | + let mut u_coding = cdfs.txb(TxbSet::ChromaRect8x4, uv_predict_mode); | ||
| 5387 | + let (u_l, u_tx_type) = read_coeffs_rect( | ||
| 5388 | + dec, &mut u_coding, chroma_scan, chroma_w, chroma_h, u_skip_ctx, | ||
| 5389 | + dc_sign_ctx(around[1].2), u_default_tx, | ||
| 5390 | + )?; | ||
| 5391 | + u_levels = u_l; | ||
| 5392 | + let u_residual = dequant_and_inverse_typed_wh( | ||
| 5393 | + &u_levels, chroma_w, chroma_h, crate::decode::bit_depth(), | ||
| 5394 | + CURRENT_Q_IDX.with(|c| c.get()), plane_q_delta(1).0, plane_q_delta(1).1, u_tx_type, | ||
| 5395 | + ); | ||
| 5396 | + u.reconstruct_rect( | ||
| 5397 | + cpx, cpy, chroma_w, chroma_h, uv_predict_mode, angle_delta_uv, reach, &u_residual, | ||
| 5398 | + alpha.zip(ac.as_deref()).map(|((au, _), ac)| (au, ac)), None, false, | ||
| 5399 | + ); | ||
| 5400 | + let v_default_tx = default_intra_tx_type(uv_predict_mode as u8); | ||
| 5401 | + let v_skip_ctx = usize::from(around[2].0) + usize::from(around[2].1); | ||
| 5402 | + let mut v_coding = cdfs.txb(TxbSet::ChromaRect8x4, uv_predict_mode); | ||
| 5403 | + let (v_l, v_tx_type) = read_coeffs_rect( | ||
| 5404 | + dec, &mut v_coding, chroma_scan, chroma_w, chroma_h, v_skip_ctx, | ||
| 5405 | + dc_sign_ctx(around[2].2), v_default_tx, | ||
| 5406 | + )?; | ||
| 5407 | + v_levels = v_l; | ||
| 5408 | + let v_residual = dequant_and_inverse_typed_wh( | ||
| 5409 | + &v_levels, chroma_w, chroma_h, crate::decode::bit_depth(), | ||
| 5410 | + CURRENT_Q_IDX.with(|c| c.get()), plane_q_delta(2).0, plane_q_delta(2).1, v_tx_type, | ||
| 5411 | + ); | ||
| 5412 | + v.reconstruct_rect( | ||
| 5413 | + cpx, cpy, chroma_w, chroma_h, uv_predict_mode, angle_delta_uv, reach, &v_residual, | ||
| 5414 | + alpha.zip(ac.as_deref()).map(|((_, av), ac)| (av, ac)), None, false, | ||
| 5415 | + ); | ||
| 5416 | + RECT_LEAF_COEFF_HITS.with(|c| c.set(c.get() + 1)); | ||
| 5417 | + } | ||
| 5418 | + neighbours.record_mi_rect(leaf_mi, bw, bh, &[luma_levels, u_levels, v_levels]); | ||
| 5130 | neighbours.fill_skip_grid_rect(leaf_mi, mi_w, mi_h, skip); | 5419 | neighbours.fill_skip_grid_rect(leaf_mi, mi_w, mi_h, skip); |
| 5131 | neighbours.fill_lf_grid_rect(leaf_mi, mi_w, mi_h, bw as u8, bh as u8, 0); | 5420 | neighbours.fill_lf_grid_rect(leaf_mi, mi_w, mi_h, bw as u8, bh as u8, 0); |
| 5132 | // This leaf is necessarily non-palette (a palette one refused above), so | 5421 | // This leaf is necessarily non-palette (a palette one refused above), so |
| @@ -5135,6 +5424,10 @@ fn decode_leaf_rect( | |||
| 5135 | // off whatever block last covered the cell (lane-palette2 r8). | 5424 | // off whatever block last covered the cell (lane-palette2 r8). |
| 5136 | neighbours.record_palette_y_rect(pal_at, bw, bh, 0, [0u16; 8]); | 5425 | neighbours.record_palette_y_rect(pal_at, bw, bh, 0, [0u16; 8]); |
| 5137 | neighbours.record_palette_uv_rect(pal_at, bw, bh, 0, [0u16; 8]); | 5426 | neighbours.record_palette_uv_rect(pal_at, bw, bh, 0, [0u16; 8]); |
| 5427 | + // A rect leaf spans mi_w x mi_h, so its mode reaches several columns and | ||
| 5428 | + // rows -- record the whole span, not one cell. | ||
| 5429 | + neighbours.record_mode_mi(leaf_mi.0, leaf_mi.1, mi_w, mi_h, mode); | ||
| 5430 | + neighbours.record_uv_mode_mi(leaf_mi.0, leaf_mi.1, mi_w, mi_h, uv_predict_mode); | ||
| 5138 | Ok(mode) | 5431 | Ok(mode) |
| 5139 | } | 5432 | } |
| 5140 | 5433 | ||
| @@ -5174,14 +5467,15 @@ fn decode_block_rect64( | |||
| 5174 | ) -> Result<()> { | 5467 | ) -> Result<()> { |
| 5175 | let (r, c) = at; | 5468 | let (r, c) = at; |
| 5176 | let (px, py) = (c * SUB, r * SUB); | 5469 | let (px, py) = (c * SUB, r * SUB); |
| 5470 | + let (nb_above_mode, nb_left_mode) = neighbours.modes_above_left(r, c); | ||
| 5177 | let (palette_ctx, palette_cache) = neighbours.palette_ctx_and_cache(at); | 5471 | let (palette_ctx, palette_cache) = neighbours.palette_ctx_and_cache(at); |
| 5178 | let palette_uv_cache = neighbours.palette_uv_cache(at); | 5472 | let palette_uv_cache = neighbours.palette_uv_cache(at); |
| 5179 | let (skip, mode, angle_delta_y, uv_mode, angle_delta_uv, alpha, filter_intra, palette_y, palette_uv) = | 5473 | let (skip, mode, angle_delta_y, uv_mode, angle_delta_uv, alpha, filter_intra, palette_y, palette_uv) = |
| 5180 | read_intra_mode_rect( | 5474 | read_intra_mode_rect( |
| 5181 | dec, | 5475 | dec, |
| 5182 | cdfs, | 5476 | cdfs, |
| 5183 | - neighbours.above_mode[c], | 5477 | + nb_above_mode, |
| 5184 | - neighbours.left_mode[r], | 5478 | + nb_left_mode, |
| 5185 | // `is_cfl_allowed` (spec 5.11.5) caps CFL at <=32x32; these | 5479 | // `is_cfl_allowed` (spec 5.11.5) caps CFL at <=32x32; these |
| 5186 | // superblock-level HORZ/VERT strips are 64x32/32x64, so unlike | 5480 | // superblock-level HORZ/VERT strips are 64x32/32x64, so unlike |
| 5187 | // `decode_block_rect`'s own 32x16/16x32 strips (where `true` is | 5481 | // `decode_block_rect`'s own 32x16/16x32 strips (where `true` is |
| @@ -5212,8 +5506,7 @@ fn decode_block_rect64( | |||
| 5212 | strip (corner-cropped luma coefficients not ported for palette)", | 5506 | strip (corner-cropped luma coefficients not ported for palette)", |
| 5213 | )); | 5507 | )); |
| 5214 | } | 5508 | } |
| 5215 | - let smooth_neighbor = | 5509 | + let smooth_neighbor = is_smooth_mode(nb_above_mode) || is_smooth_mode(nb_left_mode); |
| 5216 | - is_smooth_mode(neighbours.above_mode[c]) || is_smooth_mode(neighbours.left_mode[r]); | ||
| 5217 | if smooth_neighbor { | 5510 | if smooth_neighbor { |
| 5218 | SMOOTH_LUMA_HITS.with(|c| c.set(c.get() + 1)); | 5511 | SMOOTH_LUMA_HITS.with(|c| c.set(c.get() + 1)); |
| 5219 | } | 5512 | } |
| @@ -5702,7 +5995,7 @@ fn read_intra_mode( | |||
| 5702 | } | 5995 | } |
| 5703 | let skip = dec.symbol(&mut cdfs.skip[skip_ctx]) != 0; | 5996 | let skip = dec.symbol(&mut cdfs.skip[skip_ctx]) != 0; |
| 5704 | if trace { | 5997 | if trace { |
| 5705 | - eprintln!("TRACE skip value={}", skip as i32); | 5998 | + eprintln!("TRACE skip value={} rng={}", skip as i32, dec.debug_state().0); |
| 5706 | } | 5999 | } |
| 5707 | istep!("skip", skip as i32); | 6000 | istep!("skip", skip as i32); |
| 5708 | if !seg_id_pre_skip() { | 6001 | if !seg_id_pre_skip() { |
| @@ -5748,7 +6041,7 @@ fn read_intra_mode( | |||
| 5748 | let left_ctx = INTRA_MODE_CTX[left_mode]; | 6041 | let left_ctx = INTRA_MODE_CTX[left_mode]; |
| 5749 | let mode = dec.symbol(&mut cdfs.kf_y_mode[above_ctx][left_ctx]); | 6042 | let mode = dec.symbol(&mut cdfs.kf_y_mode[above_ctx][left_ctx]); |
| 5750 | if trace { | 6043 | if trace { |
| 5751 | - eprintln!("TRACE y_mode ctx=({above_ctx},{left_ctx}) value={mode}"); | 6044 | + eprintln!("TRACE y_mode ctx=({above_ctx},{left_ctx}) value={mode} rng={}", dec.debug_state().0); |
| 5752 | } | 6045 | } |
| 5753 | istep!("mode", mode as i32); | 6046 | istep!("mode", mode as i32); |
| 5754 | let angle_delta_y = if (V_PRED..=D67_PRED).contains(&mode) { | 6047 | let angle_delta_y = if (V_PRED..=D67_PRED).contains(&mode) { |
| @@ -5770,7 +6063,7 @@ fn read_intra_mode( | |||
| 5770 | dec.symbol(&mut cdfs.uv_mode_no_cfl[mode]) | 6063 | dec.symbol(&mut cdfs.uv_mode_no_cfl[mode]) |
| 5771 | }; | 6064 | }; |
| 5772 | if trace { | 6065 | if trace { |
| 5773 | - eprintln!("TRACE uv_mode cfl={cfl} y_mode={mode} value={uv_mode}"); | 6066 | + eprintln!("TRACE uv_mode cfl={cfl} y_mode={mode} value={uv_mode} rng={}", dec.debug_state().0); |
| 5774 | } | 6067 | } |
| 5775 | istep!("uv_mode", uv_mode as i32); | 6068 | istep!("uv_mode", uv_mode as i32); |
| 5776 | let alpha = if cfl && uv_mode == UV_CFL_PRED { | 6069 | let alpha = if cfl && uv_mode == UV_CFL_PRED { |
| @@ -5895,7 +6188,7 @@ fn read_intra_mode( | |||
| 5895 | let use_filter_intra = dec.symbol(&mut cdfs.filter_intra[class]) != 0; | 6188 | let use_filter_intra = dec.symbol(&mut cdfs.filter_intra[class]) != 0; |
| 5896 | if trace { | 6189 | if trace { |
| 5897 | eprintln!( | 6190 | eprintln!( |
| 5898 | - "TRACE use_filter_intra side={side} value={}", | 6191 | + "TRACE use_filter_intra side={side} rng={} value={}", dec.debug_state().0, |
| 5899 | use_filter_intra as i32 | 6192 | use_filter_intra as i32 |
| 5900 | ); | 6193 | ); |
| 5901 | } | 6194 | } |
| @@ -6480,12 +6773,13 @@ fn decode_block( | |||
| 6480 | let (px, py) = (c * SUB, r * SUB); | 6773 | let (px, py) = (c * SUB, r * SUB); |
| 6481 | let (palette_ctx, palette_cache) = neighbours.palette_ctx_and_cache(at); | 6774 | let (palette_ctx, palette_cache) = neighbours.palette_ctx_and_cache(at); |
| 6482 | let palette_uv_cache = neighbours.palette_uv_cache(at); | 6775 | let palette_uv_cache = neighbours.palette_uv_cache(at); |
| 6776 | + let (nb_above_mode, nb_left_mode) = neighbours.modes_above_left(r, c); | ||
| 6483 | let (skip, mode, angle_delta_y, uv_mode, angle_delta_uv, alpha, filter_intra, palette_y, palette_uv) = | 6777 | let (skip, mode, angle_delta_y, uv_mode, angle_delta_uv, alpha, filter_intra, palette_y, palette_uv) = |
| 6484 | read_intra_mode( | 6778 | read_intra_mode( |
| 6485 | dec, | 6779 | dec, |
| 6486 | cdfs, | 6780 | cdfs, |
| 6487 | - neighbours.above_mode[c], | 6781 | + nb_above_mode, |
| 6488 | - neighbours.left_mode[r], | 6782 | + nb_left_mode, |
| 6489 | cfl, | 6783 | cfl, |
| 6490 | side, | 6784 | side, |
| 6491 | enable_filter_intra, | 6785 | enable_filter_intra, |
| @@ -6515,8 +6809,7 @@ fn decode_block( | |||
| 6515 | } else { | 6809 | } else { |
| 6516 | uv_mode | 6810 | uv_mode |
| 6517 | }; | 6811 | }; |
| 6518 | - let smooth_neighbor = | 6812 | + let smooth_neighbor = is_smooth_mode(nb_above_mode) || is_smooth_mode(nb_left_mode); |
| 6519 | - is_smooth_mode(neighbours.above_mode[c]) || is_smooth_mode(neighbours.left_mode[r]); | ||
| 6520 | if smooth_neighbor { | 6813 | if smooth_neighbor { |
| 6521 | SMOOTH_LUMA_HITS.with(|c| c.set(c.get() + 1)); | 6814 | SMOOTH_LUMA_HITS.with(|c| c.set(c.get() + 1)); |
| 6522 | } | 6815 | } |
| @@ -6919,6 +7212,17 @@ fn decode_block( | |||
| 6919 | /// at. Returns the mode this leaf decoded, for the caller's own | 7212 | /// at. Returns the mode this leaf decoded, for the caller's own |
| 6920 | /// `prev_leaf`/final mode-writeback bookkeeping. | 7213 | /// `prev_leaf`/final mode-writeback bookkeeping. |
| 6921 | #[allow(clippy::too_many_arguments)] | 7214 | #[allow(clippy::too_many_arguments)] |
| 7215 | +/// The coarse 16x16 `above_mode`/`left_mode` cells a four-way SPLIT of one | ||
| 7216 | +/// 16x16 parent leaves behind (lane-rectx r3). The next block DOWN reads | ||
| 7217 | +/// `above_mode[col]`, and its true above neighbour is the mi directly above | ||
| 7218 | +/// its own top-left corner -- the parent's BOTTOM-LEFT leaf, not the last one | ||
| 7219 | +/// decoded; the next block RIGHT reads `left_mode[row]`, whose true left | ||
| 7220 | +/// neighbour is the parent's TOP-RIGHT leaf. Writing the z-order last leaf | ||
| 7221 | +/// (bottom-right) into both, as this path did, is right only when all four | ||
| 7222 | +/// leaves happen to share a mode. `done` may be short at the true frame edge | ||
| 7223 | +/// (the straddle caller filters positions off the frame), so each side falls | ||
| 7224 | +/// back to the last leaf actually decoded. | ||
| 7225 | + | ||
| 6922 | fn decode_leaf8( | 7226 | fn decode_leaf8( |
| 6923 | dec: &mut SymbolDecoder, | 7227 | dec: &mut SymbolDecoder, |
| 6924 | cdfs: &mut Cdfs, | 7228 | cdfs: &mut Cdfs, |
| @@ -6947,9 +7251,26 @@ fn decode_leaf8( | |||
| 6947 | left_mode = pmode; | 7251 | left_mode = pmode; |
| 6948 | } | 7252 | } |
| 6949 | } | 7253 | } |
| 6950 | - // See [`PlaneBuf::reconstruct`]'s doc: chroma stays `false` (exact) until | 7254 | + // The mi-exact neighbour wins over both the coarse 16x16 slot and |
| 6951 | - // a smooth/paeth `uv_mode` can reach decode at all. | 7255 | + // `prev_leaf`: one 16x16 slot cannot hold the two different modes its |
| 7256 | + // two 8x8 (or four 4x4) columns leave behind, so a leaf whose above/left | ||
| 7257 | + // neighbour sits in a split cell read the wrong `kf_y_mode` row. | ||
| 7258 | + if let Some(m) = neighbours.mode_above_mi(leaf_mi.0, leaf_mi.1) { | ||
| 7259 | + above_mode = m; | ||
| 7260 | + } | ||
| 7261 | + if let Some(m) = neighbours.mode_left_mi(leaf_mi.0, leaf_mi.1) { | ||
| 7262 | + left_mode = m; | ||
| 7263 | + } | ||
| 6952 | let smooth_neighbor = is_smooth_mode(above_mode) || is_smooth_mode(left_mode); | 7264 | let smooth_neighbor = is_smooth_mode(above_mode) || is_smooth_mode(left_mode); |
| 7265 | + // Chroma's edge-filter type reads the CHROMA neighbour's `uv_mode` | ||
| 7266 | + // (`get_intra_edge_filter_type`, reconintra.c:974), never the luma mode | ||
| 7267 | + // this leaf's `smooth_neighbor` is built from -- passing `false` here | ||
| 7268 | + // filtered a directional chroma block's edge at the wrong strength | ||
| 7269 | + // (lane-sub8 r5: 4 pixels of one 8x8 leaf's chroma, deltas 1..3). | ||
| 7270 | + // The `uv_mode` neighbours are mi-exact (`uv_mode_col`/`uv_mode_row`), | ||
| 7271 | + // with the coarse [`SUB`] slot as the fallback when no block recorded | ||
| 7272 | + // that exact mi cell. | ||
| 7273 | + let smooth_neighbor_uv = neighbours.smooth_uv_neighbour(leaf_mi.0, leaf_mi.1, r, c); | ||
| 6953 | if smooth_neighbor { | 7274 | if smooth_neighbor { |
| 6954 | SMOOTH_LUMA_HITS.with(|c| c.set(c.get() + 1)); | 7275 | SMOOTH_LUMA_HITS.with(|c| c.set(c.get() + 1)); |
| 6955 | } | 7276 | } |
| @@ -6978,6 +7299,9 @@ fn decode_leaf8( | |||
| 6978 | } else { | 7299 | } else { |
| 6979 | uv_mode | 7300 | uv_mode |
| 6980 | }; | 7301 | }; |
| 7302 | + neighbours.above_uv_mode[c] = uv_predict_mode; | ||
| 7303 | + neighbours.left_uv_mode[r] = uv_predict_mode; | ||
| 7304 | + neighbours.record_uv_mode_mi(leaf_mi.0, leaf_mi.1, 2, 2, uv_predict_mode); | ||
| 6981 | // `TxMode::Select`'s `tx_depth` at an 8x8 leaf (spec 5.11.16): the only | 7305 | // `TxMode::Select`'s `tx_depth` at an 8x8 leaf (spec 5.11.16): the only |
| 6982 | // depths an 8x8 block offers are `TX8` (depth 0) and `TX4` (depth 1, | 7306 | // depths an 8x8 block offers are `TX8` (depth 0) and `TX4` (depth 1, |
| 6983 | // which splits the leaf's own 8x8 prediction into a 2x2 grid of 4x4 | 7307 | // which splits the leaf's own 8x8 prediction into a 2x2 grid of 4x4 |
| @@ -7016,7 +7340,7 @@ fn decode_leaf8( | |||
| 7016 | &vec![0i32; 16], | 7340 | &vec![0i32; 16], |
| 7017 | alpha.zip(ac.as_deref()).map(|((au, _), ac)| (au, ac)), | 7341 | alpha.zip(ac.as_deref()).map(|((au, _), ac)| (au, ac)), |
| 7018 | None, | 7342 | None, |
| 7019 | - false, | 7343 | + smooth_neighbor_uv, |
| 7020 | ); | 7344 | ); |
| 7021 | v.reconstruct( | 7345 | v.reconstruct( |
| 7022 | cpx, | 7346 | cpx, |
| @@ -7028,7 +7352,7 @@ fn decode_leaf8( | |||
| 7028 | &vec![0i32; 16], | 7352 | &vec![0i32; 16], |
| 7029 | alpha.zip(ac.as_deref()).map(|((_, av), ac)| (av, ac)), | 7353 | alpha.zip(ac.as_deref()).map(|((_, av), ac)| (av, ac)), |
| 7030 | None, | 7354 | None, |
| 7031 | - false, | 7355 | + smooth_neighbor_uv, |
| 7032 | ); | 7356 | ); |
| 7033 | luma_grid = vec![0i32; 64]; | 7357 | luma_grid = vec![0i32; 64]; |
| 7034 | u_grid = vec![0i32; 16]; | 7358 | u_grid = vec![0i32; 16]; |
| @@ -7082,7 +7406,7 @@ fn decode_leaf8( | |||
| 7082 | alpha.zip(ac.as_deref()).map(|((au, _), ac)| (au, ac)), | 7406 | alpha.zip(ac.as_deref()).map(|((au, _), ac)| (au, ac)), |
| 7083 | None, | 7407 | None, |
| 7084 | None, | 7408 | None, |
| 7085 | - false, | 7409 | + smooth_neighbor_uv, |
| 7086 | )?; | 7410 | )?; |
| 7087 | v_grid = read_plane( | 7411 | v_grid = read_plane( |
| 7088 | dec, | 7412 | dec, |
| @@ -7104,7 +7428,7 @@ fn decode_leaf8( | |||
| 7104 | alpha.zip(ac.as_deref()).map(|((_, av), ac)| (av, ac)), | 7428 | alpha.zip(ac.as_deref()).map(|((_, av), ac)| (av, ac)), |
| 7105 | None, | 7429 | None, |
| 7106 | None, | 7430 | None, |
| 7107 | - false, | 7431 | + smooth_neighbor_uv, |
| 7108 | )?; | 7432 | )?; |
| 7109 | } else { | 7433 | } else { |
| 7110 | // `tx_depth` resolved this leaf's luma to `TX4`: a 2x2 raster-order | 7434 | // `tx_depth` resolved this leaf's luma to `TX4`: a 2x2 raster-order |
| @@ -7180,7 +7504,7 @@ fn decode_leaf8( | |||
| 7180 | alpha.zip(ac.as_deref()).map(|((au, _), ac)| (au, ac)), | 7504 | alpha.zip(ac.as_deref()).map(|((au, _), ac)| (au, ac)), |
| 7181 | None, | 7505 | None, |
| 7182 | None, | 7506 | None, |
| 7183 | - false, | 7507 | + smooth_neighbor_uv, |
| 7184 | )?; | 7508 | )?; |
| 7185 | v_grid = read_plane( | 7509 | v_grid = read_plane( |
| 7186 | dec, | 7510 | dec, |
| @@ -7202,7 +7526,7 @@ fn decode_leaf8( | |||
| 7202 | alpha.zip(ac.as_deref()).map(|((_, av), ac)| (av, ac)), | 7526 | alpha.zip(ac.as_deref()).map(|((_, av), ac)| (av, ac)), |
| 7203 | None, | 7527 | None, |
| 7204 | None, | 7528 | None, |
| 7205 | - false, | 7529 | + smooth_neighbor_uv, |
| 7206 | )?; | 7530 | )?; |
| 7207 | // `record_split_luma` expects a `record`-style `(r, c)` position in | 7531 | // `record_split_luma` expects a `record`-style `(r, c)` position in |
| 7208 | // `SUB`-grid units and rescales it by `SUB / MI`; `leaf_mi` is | 7532 | // `SUB`-grid units and rescales it by `SUB / MI`; `leaf_mi` is |
| @@ -7242,6 +7566,7 @@ fn decode_leaf8( | |||
| 7242 | } | 7566 | } |
| 7243 | neighbours.fill_skip_grid(leaf_mi, 2, skip); | 7567 | neighbours.fill_skip_grid(leaf_mi, 2, skip); |
| 7244 | neighbours.fill_lf_grid(leaf_mi, 2, 4, 0); | 7568 | neighbours.fill_lf_grid(leaf_mi, 2, 4, 0); |
| 7569 | + neighbours.record_mode_mi(leaf_mi.0, leaf_mi.1, 2, 2, mode); | ||
| 7245 | return Ok(mode); | 7570 | return Ok(mode); |
| 7246 | } | 7571 | } |
| 7247 | neighbours.record_mi(leaf_mi, 8, &[luma_grid, u_grid, v_grid]); | 7572 | neighbours.record_mi(leaf_mi, 8, &[luma_grid, u_grid, v_grid]); |
| @@ -7255,9 +7580,284 @@ fn decode_leaf8( | |||
| 7255 | } | 7580 | } |
| 7256 | neighbours.fill_skip_grid(leaf_mi, 2, skip); | 7581 | neighbours.fill_skip_grid(leaf_mi, 2, skip); |
| 7257 | neighbours.fill_lf_grid(leaf_mi, 2, 8, 0); | 7582 | neighbours.fill_lf_grid(leaf_mi, 2, 8, 0); |
| 7583 | + neighbours.record_mode_mi(leaf_mi.0, leaf_mi.1, 2, 2, mode); | ||
| 7258 | Ok(mode) | 7584 | Ok(mode) |
| 7259 | } | 7585 | } |
| 7260 | 7586 | ||
| 7587 | +/// `read_intra_frame_mode_info`'s mode-info read for one `BLOCK_4X4` leaf | ||
| 7588 | +/// below an 8x8 partition (spec `decode_partition`'s `bSize < BLOCK_8X8` | ||
| 7589 | +/// bottom, where no partition symbol is read at all -- `decode_block` runs | ||
| 7590 | +/// directly). No palette (`av1_allow_palette` needs both dims >= 8, spec | ||
| 7591 | +/// blockd.h) and no `read_tx_size` (a sub-8x8 block's transform is always | ||
| 7592 | +/// its own bsize, spec 5.11.16). `has_chroma` follows `is_chroma_reference` | ||
| 7593 | +/// (spec/libaom `av1_common_int.h`): for 4:2:0, only the bottom-right leaf | ||
| 7594 | +/// of the 2x2 4x4 group carries chroma syntax at all. | ||
| 7595 | +#[allow(clippy::too_many_arguments)] | ||
| 7596 | +fn read_intra_mode_sub8( | ||
| 7597 | + dec: &mut SymbolDecoder, | ||
| 7598 | + cdfs: &mut Cdfs, | ||
| 7599 | + above_mode: usize, | ||
| 7600 | + left_mode: usize, | ||
| 7601 | + has_chroma: bool, | ||
| 7602 | + enable_filter_intra: bool, | ||
| 7603 | + skip_ctx: usize, | ||
| 7604 | + allow_intrabc: bool, | ||
| 7605 | + mi_r: usize, | ||
| 7606 | + mi_c: usize, | ||
| 7607 | +) -> Result<(bool, usize, i32, Option<(usize, i32, Option<(i32, i32)>)>, Option<usize>)> { | ||
| 7608 | + let trace = std::env::var_os("EC_AV1_TRACE").is_some(); | ||
| 7609 | + let skip = dec.symbol(&mut cdfs.skip[skip_ctx]) != 0; | ||
| 7610 | + if trace { | ||
| 7611 | + eprintln!("TRACE sub8 skip mi=({mi_r},{mi_c}) ctx={skip_ctx} value={} rng={}", skip as i32, dec.debug_state().0); | ||
| 7612 | + } | ||
| 7613 | + maybe_read_cdef_idx(dec, mi_r, mi_c, skip); | ||
| 7614 | + maybe_read_delta_q(dec, cdfs, mi_r, mi_c, false, skip); | ||
| 7615 | + maybe_read_delta_lf(dec, cdfs, mi_r, mi_c, false, skip); | ||
| 7616 | + if allow_intrabc { | ||
| 7617 | + let use_intrabc = dec.symbol(&mut cdfs.intrabc) != 0; | ||
| 7618 | + if use_intrabc { | ||
| 7619 | + return Err(unsupported( | ||
| 7620 | + "a sub-8x8 leaf that uses intrabc (this reader has no block-vector path; the 8x8-and-up reader reconstructs one)", | ||
| 7621 | + )); | ||
| 7622 | + } | ||
| 7623 | + } | ||
| 7624 | + let above_ctx = INTRA_MODE_CTX[above_mode]; | ||
| 7625 | + let left_ctx = INTRA_MODE_CTX[left_mode]; | ||
| 7626 | + let mode = dec.symbol(&mut cdfs.kf_y_mode[above_ctx][left_ctx]); | ||
| 7627 | + if trace { | ||
| 7628 | + eprintln!("TRACE sub8 y_mode mi=({mi_r},{mi_c}) ctx=({above_ctx},{left_ctx}) value={mode} rng={}", dec.debug_state().0); | ||
| 7629 | + } | ||
| 7630 | + // No `angle_delta` at all below 8x8: spec 5.11.6's `intra_angle_info_y`/ | ||
| 7631 | + // `_uv` are gated on `MiSize >= BLOCK_8X8` (libaom `av1_use_angle_delta`, | ||
| 7632 | + // blockd.h), so a directional mode on a `BLOCK_4X4` leaf carries no delta | ||
| 7633 | + // symbol. Reading one consumed a symbol the encoder never wrote and | ||
| 7634 | + // desynced the tile at the very next element. | ||
| 7635 | + let angle_delta_y = 0; | ||
| 7636 | + let chroma = if has_chroma { | ||
| 7637 | + let uv_mode = dec.symbol(&mut cdfs.uv_mode_cfl[mode]); | ||
| 7638 | + if trace { | ||
| 7639 | + eprintln!("TRACE sub8 uv_mode value={uv_mode} rng={}", dec.debug_state().0); | ||
| 7640 | + } | ||
| 7641 | + if (9..=12).contains(&uv_mode) { | ||
| 7642 | + SMOOTH_UV_HITS.with(|c| c.set(c.get() + 1)); | ||
| 7643 | + } | ||
| 7644 | + let alpha = if uv_mode == UV_CFL_PRED { | ||
| 7645 | + Some(read_cfl_alphas(dec, cdfs)) | ||
| 7646 | + } else { | ||
| 7647 | + None | ||
| 7648 | + }; | ||
| 7649 | + if (V_PRED..=D67_PRED).contains(&uv_mode) { | ||
| 7650 | + DIRECTIONAL_UV_HITS.with(|c| c.set(c.get() + 1)); | ||
| 7651 | + } | ||
| 7652 | + // See the luma comment above: no angle delta below 8x8. | ||
| 7653 | + let angle_delta_uv = 0; | ||
| 7654 | + Some((uv_mode, angle_delta_uv, alpha)) | ||
| 7655 | + } else { | ||
| 7656 | + None | ||
| 7657 | + }; | ||
| 7658 | + let mut filter_intra = None; | ||
| 7659 | + if mode == DC_PRED && enable_filter_intra { | ||
| 7660 | + // `BLOCK_4X4`'s own row (class 0, `filter_intra_size_class(4)`) -- | ||
| 7661 | + // every sub-8x8 leaf here is a `BLOCK_4X4`. | ||
| 7662 | + let use_filter_intra = dec.symbol(&mut cdfs.filter_intra[0]) != 0; | ||
| 7663 | + if trace { | ||
| 7664 | + eprintln!("TRACE sub8 use_filter_intra value={}", use_filter_intra as i32); | ||
| 7665 | + } | ||
| 7666 | + if use_filter_intra { | ||
| 7667 | + FILTER_INTRA_HITS.with(|c| c.set(c.get() + 1)); | ||
| 7668 | + let fi_mode = dec.symbol(&mut cdfs.filter_intra_mode); | ||
| 7669 | + filter_intra = Some(fi_mode); | ||
| 7670 | + } | ||
| 7671 | + } | ||
| 7672 | + Ok((skip, mode, angle_delta_y, chroma, filter_intra)) | ||
| 7673 | +} | ||
| 7674 | + | ||
| 7675 | +/// Decodes a `PARTITION_SPLIT` of one 8x8 block into four `BLOCK_4X4` leaves | ||
| 7676 | +/// (spec `decode_partition`'s recursion bottom), sharing [`decode_leaf8`]'s | ||
| 7677 | +/// own signature so its caller's `prev_leaf`/`above_mode`/`left_mode` | ||
| 7678 | +/// bookkeeping needs no change. Each leaf reads its own luma mode info, | ||
| 7679 | +/// neighboured off the *previously decoded leaf in this same group* on | ||
| 7680 | +/// whichever axis is adjacent (mirroring [`decode_leaf8`]'s own `prev_leaf` | ||
| 7681 | +/// pattern, one level deeper); chroma is read and reconstructed exactly | ||
| 7682 | +/// once, on the last (bottom-right) leaf, at the whole 8x8 group's own 4x4 | ||
| 7683 | +/// chroma unit -- [`read_intra_mode_sub8`]'s doc has the `is_chroma_reference` | ||
| 7684 | +/// derivation. | ||
| 7685 | +#[allow(clippy::too_many_arguments)] | ||
| 7686 | +fn decode_leaf_split4( | ||
| 7687 | + dec: &mut SymbolDecoder, | ||
| 7688 | + cdfs: &mut Cdfs, | ||
| 7689 | + neighbours: &mut Neighbours, | ||
| 7690 | + outer_at: (usize, usize), | ||
| 7691 | + leaf_mi: (usize, usize), | ||
| 7692 | + scan4: &[u16], | ||
| 7693 | + prev_leaf: Option<((usize, usize), usize)>, | ||
| 7694 | + y: &mut PlaneBuf, | ||
| 7695 | + u: &mut PlaneBuf, | ||
| 7696 | + v: &mut PlaneBuf, | ||
| 7697 | + base_q_idx: u8, | ||
| 7698 | + enable_filter_intra: bool, | ||
| 7699 | + allow_intrabc: bool, | ||
| 7700 | + reduced_tx_set: bool, | ||
| 7701 | + // Returns `(below_mode, right_mode)`: the mode a neighbour BELOW this 8x8 | ||
| 7702 | + // group sees (its bottom-left 4x4, libaom reads mi(row-1, col)) and the | ||
| 7703 | + // one a neighbour to its RIGHT sees (its top-right 4x4, mi(row, col-1)). | ||
| 7704 | +) -> Result<(usize, usize)> { | ||
| 7705 | + SUB8_SPLIT_HITS.with(|c| c.set(c.get() + 1)); | ||
| 7706 | + let (r, c) = outer_at; | ||
| 7707 | + let mut above_mode = neighbours.above_mode[c]; | ||
| 7708 | + let mut left_mode = neighbours.left_mode[r]; | ||
| 7709 | + if let Some(((pr, pc), pmode)) = prev_leaf { | ||
| 7710 | + if pc == leaf_mi.1 && leaf_mi.0 == pr + 2 { | ||
| 7711 | + above_mode = pmode; | ||
| 7712 | + } else if pr == leaf_mi.0 && leaf_mi.1 == pc + 2 { | ||
| 7713 | + left_mode = pmode; | ||
| 7714 | + } | ||
| 7715 | + } | ||
| 7716 | + // See `decode_leaf8`'s own `smooth_neighbor_uv`: the chroma edge-filter | ||
| 7717 | + // type is the chroma neighbours' `uv_mode`, mi-exact where recorded. | ||
| 7718 | + let smooth_neighbor_uv = neighbours.smooth_uv_neighbour(leaf_mi.0, leaf_mi.1, r, c); | ||
| 7719 | + let mut leaf_modes = [0usize; 4]; | ||
| 7720 | + let mut leaf_skips = [false; 4]; | ||
| 7721 | + let mut last_uv: Option<(usize, i32, Option<(i32, i32)>)> = None; | ||
| 7722 | + for i in 0..4usize { | ||
| 7723 | + let (dr, dc) = (i / 2, i % 2); | ||
| 7724 | + let lmi = (leaf_mi.0 + dr, leaf_mi.1 + dc); | ||
| 7725 | + // Neighbour modes at real mi granularity: inside the group the | ||
| 7726 | + // sibling leaf, outside it the split-leaf map when the adjacent mi | ||
| 7727 | + // was itself a 4x4 leaf, else the coarse 16x16 slot (see | ||
| 7728 | + // `sub8_mode_col`'s doc). | ||
| 7729 | + let leaf_above = if dr == 0 { | ||
| 7730 | + neighbours.mode_above_mi(lmi.0, lmi.1).unwrap_or(above_mode) | ||
| 7731 | + } else { | ||
| 7732 | + leaf_modes[i - 2] | ||
| 7733 | + }; | ||
| 7734 | + let leaf_left = if dc == 0 { | ||
| 7735 | + neighbours.mode_left_mi(lmi.0, lmi.1).unwrap_or(left_mode) | ||
| 7736 | + } else { | ||
| 7737 | + leaf_modes[i - 1] | ||
| 7738 | + }; | ||
| 7739 | + let has_chroma = i == 3; | ||
| 7740 | + let skip_ctx = neighbours.skip_txfm_ctx(lmi.0, lmi.1); | ||
| 7741 | + let (skip, mode, angle_delta_y, chroma, filter_intra) = read_intra_mode_sub8( | ||
| 7742 | + dec, cdfs, leaf_above, leaf_left, has_chroma, enable_filter_intra, skip_ctx, | ||
| 7743 | + allow_intrabc, lmi.0, lmi.1, | ||
| 7744 | + )?; | ||
| 7745 | + leaf_modes[i] = mode; | ||
| 7746 | + leaf_skips[i] = skip; | ||
| 7747 | + neighbours.record_mode_mi(lmi.0, lmi.1, 1, 1, mode); | ||
| 7748 | + let smooth_neighbor = is_smooth_mode(leaf_above) || is_smooth_mode(leaf_left); | ||
| 7749 | + if smooth_neighbor { | ||
| 7750 | + SMOOTH_LUMA_HITS.with(|c| c.set(c.get() + 1)); | ||
| 7751 | + } | ||
| 7752 | + let (px, py) = (lmi.1 * MI, lmi.0 * MI); | ||
| 7753 | + let reach = Reach::of(4, px, py, y.width, y.height); | ||
| 7754 | + if skip { | ||
| 7755 | + y.reconstruct(px, py, 4, mode, angle_delta_y, reach, &vec![0i32; 16], None, filter_intra, smooth_neighbor); | ||
| 7756 | + neighbours.record_mi_luma(lmi, 4, &vec![0i32; 16]); | ||
| 7757 | + } else { | ||
| 7758 | + let tu_around = neighbours.around_mi(lmi, 4)[0]; | ||
| 7759 | + // A `BLOCK_4X4` leaf's luma TU *is* the whole block, so libaom's | ||
| 7760 | + // `get_txb_ctx` takes its `plane_bsize == txsize_to_bsize[tx_size]` | ||
| 7761 | + // branch: `txb_skip_ctx = 0`, never the neighbour-magnitude table | ||
| 7762 | + // (`txb_common.h:400`). Reading the table here decoded `all_zero` | ||
| 7763 | + // off the wrong CDF on the very first leaf and desynced the tile. | ||
| 7764 | + let tu_grid = read_plane( | ||
| 7765 | + dec, | ||
| 7766 | + cdfs, | ||
| 7767 | + if reduced_tx_set { TxbSet::Luma4 } else { TxbSet::Luma4Set1 }, | ||
| 7768 | + scan4, | ||
| 7769 | + 0, | ||
| 7770 | + tu_around, | ||
| 7771 | + mode, | ||
| 7772 | + mode, | ||
| 7773 | + angle_delta_y, | ||
| 7774 | + reach, | ||
| 7775 | + y, | ||
| 7776 | + px, | ||
| 7777 | + py, | ||
| 7778 | + 4, | ||
| 7779 | + 4, | ||
| 7780 | + base_q_idx, | ||
| 7781 | + None, | ||
| 7782 | + filter_intra, | ||
| 7783 | + None, | ||
| 7784 | + smooth_neighbor, | ||
| 7785 | + )?; | ||
| 7786 | + neighbours.record_mi_luma(lmi, 4, &tu_grid); | ||
| 7787 | + } | ||
| 7788 | + neighbours.fill_skip_grid(lmi, 1, skip); | ||
| 7789 | + neighbours.fill_lf_grid(lmi, 1, 4, 0); | ||
| 7790 | + if has_chroma { | ||
| 7791 | + last_uv = chroma; | ||
| 7792 | + } | ||
| 7793 | + } | ||
| 7794 | + let (gpx, gpy) = (leaf_mi.1 * MI, leaf_mi.0 * MI); | ||
| 7795 | + let (cpx, cpy) = (gpx / 2, gpy / 2); | ||
| 7796 | + let group_reach = Reach::of(8, gpx, gpy, y.width, y.height); | ||
| 7797 | + let (uv_mode, angle_delta_uv, alpha) = | ||
| 7798 | + last_uv.expect("i==3 always sets has_chroma, so chroma is always Some"); | ||
| 7799 | + let uv_predict_mode = if uv_mode == UV_CFL_PRED { DC_PRED } else { uv_mode }; | ||
| 7800 | + neighbours.above_uv_mode[c] = uv_predict_mode; | ||
| 7801 | + neighbours.left_uv_mode[r] = uv_predict_mode; | ||
| 7802 | + neighbours.record_uv_mode_mi(leaf_mi.0, leaf_mi.1, 2, 2, uv_predict_mode); | ||
| 7803 | + let (u_grid, v_grid): (Vec<i32>, Vec<i32>) = if leaf_skips[3] { | ||
| 7804 | + u.reconstruct(cpx, cpy, 4, uv_predict_mode, angle_delta_uv, group_reach, &vec![0i32; 16], None, None, smooth_neighbor_uv); | ||
| 7805 | + v.reconstruct(cpx, cpy, 4, uv_predict_mode, angle_delta_uv, group_reach, &vec![0i32; 16], None, None, smooth_neighbor_uv); | ||
| 7806 | + (vec![0i32; 16], vec![0i32; 16]) | ||
| 7807 | + } else { | ||
| 7808 | + let ac = alpha.map(|_| cfl_ac_q3(y, gpx, gpy, 8)); | ||
| 7809 | + let chroma_around = neighbours.around_mi(leaf_mi, 8); | ||
| 7810 | + let ug = read_plane( | ||
| 7811 | + dec, cdfs, TxbSet::Chroma4, scan4, 1, chroma_around[1], uv_mode, uv_predict_mode, | ||
| 7812 | + angle_delta_uv, group_reach, u, cpx, cpy, 4, TX4, base_q_idx, | ||
| 7813 | + alpha.zip(ac.as_deref()).map(|((au, _), ac)| (au, ac)), None, None, smooth_neighbor_uv, | ||
| 7814 | + )?; | ||
| 7815 | + let vg = read_plane( | ||
| 7816 | + dec, cdfs, TxbSet::Chroma4, scan4, 2, chroma_around[2], uv_mode, uv_predict_mode, | ||
| 7817 | + angle_delta_uv, group_reach, v, cpx, cpy, 4, TX4, base_q_idx, | ||
| 7818 | + alpha.zip(ac.as_deref()).map(|((_, av), ac)| (av, ac)), None, None, smooth_neighbor_uv, | ||
| 7819 | + )?; | ||
| 7820 | + (ug, vg) | ||
| 7821 | + }; | ||
| 7822 | + // Chroma neighbour bookkeeping for the whole 8x8 group -- mirrors | ||
| 7823 | + // [`decode_leaf8`]'s own tx4-chroma section (`record_split_luma`'s | ||
| 7824 | + // rescaling is wrong for an already-mi-unit position, so this inlines | ||
| 7825 | + // its tail directly at `leaf_mi`, side_mi=2), EXCEPT for the partition | ||
| 7826 | + // context value itself. Unlike `decode_leaf8`'s TX4 branch (still one | ||
| 7827 | + // `BLOCK_8X8`, `PARTITION_NONE`, transform depth only), this group is | ||
| 7828 | + // genuinely four `BLOCK_4X4` blocks (`PARTITION_SPLIT` at the 8x8 | ||
| 7829 | + // level, libaom `decode_partition`'s `bsize2`/`subsize` recursion | ||
| 7830 | + // bottom). libaom's `update_ext_partition_context` writes | ||
| 7831 | + // `partition_context_lookup[subsize]` at the 8x8 slot -- `{30,30}` for | ||
| 7832 | + // `BLOCK_8X8` (bit0=0, what `decode_leaf8` already reproduces via | ||
| 7833 | + // side_mi=8) but `{31,31}` for `BLOCK_4X4` (bit0=1) here, and | ||
| 7834 | + // `partition_ctx_mi`'s `left_side_mi[mi_r]*2 <= side` needs | ||
| 7835 | + // `left_side_mi <= 4` to read that bit as 1. Leaving this at 8 (this | ||
| 7836 | + // round's bug) makes the very next sibling 8x8's `partition_w8` read | ||
| 7837 | + // with the wrong context and desync immediately. | ||
| 7838 | + let side_mi = 2; | ||
| 7839 | + for cell in 0..side_mi { | ||
| 7840 | + neighbours.left_side_mi[leaf_mi.0 + cell] = 4; | ||
| 7841 | + neighbours.above_side_mi[leaf_mi.1 + cell] = 4; | ||
| 7842 | + } | ||
| 7843 | + let round_up_even = |n: usize| n.div_ceil(2) * 2; | ||
| 7844 | + let bound_h = round_up_even(neighbours.mi_rows); | ||
| 7845 | + let bound_w = round_up_even(neighbours.mi_cols); | ||
| 7846 | + let u_state = neighbour_state(&u_grid); | ||
| 7847 | + let v_state = neighbour_state(&v_grid); | ||
| 7848 | + for cell in 0..side_mi { | ||
| 7849 | + if cell < side_mi.min(bound_h.saturating_sub(leaf_mi.0)) { | ||
| 7850 | + neighbours.left[leaf_mi.0 + cell][1] = u_state; | ||
| 7851 | + neighbours.left[leaf_mi.0 + cell][2] = v_state; | ||
| 7852 | + } | ||
| 7853 | + if cell < side_mi.min(bound_w.saturating_sub(leaf_mi.1)) { | ||
| 7854 | + neighbours.above[leaf_mi.1 + cell][1] = u_state; | ||
| 7855 | + neighbours.above[leaf_mi.1 + cell][2] = v_state; | ||
| 7856 | + } | ||
| 7857 | + } | ||
| 7858 | + Ok((leaf_modes[2], leaf_modes[1])) | ||
| 7859 | +} | ||
| 7860 | + | ||
| 7261 | /// Spec 7.15.3's `Cdef_Directions`: `(row, col)` offsets for the two primary | 7861 | /// Spec 7.15.3's `Cdef_Directions`: `(row, col)` offsets for the two primary |
| 7262 | /// taps of each of the eight directions; the secondary taps at `dir+2`/`dir-2` | 7862 | /// taps of each of the eight directions; the secondary taps at `dir+2`/`dir-2` |
| 7263 | /// (mod 8) reuse the same table. | 7863 | /// (mod 8) reuse the same table. |
| @@ -9258,6 +9858,7 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( | |||
| 9258 | allow_screen_content_tools, | 9858 | allow_screen_content_tools, |
| 9259 | base_q_idx, | 9859 | base_q_idx, |
| 9260 | tx_select, | 9860 | tx_select, |
| 9861 | + reduced_tx_set, | ||
| 9261 | )?; | 9862 | )?; |
| 9262 | let mode_bot = decode_leaf_rect( | 9863 | let mode_bot = decode_leaf_rect( |
| 9263 | &mut dec, | 9864 | &mut dec, |
| @@ -9275,6 +9876,7 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( | |||
| 9275 | allow_screen_content_tools, | 9876 | allow_screen_content_tools, |
| 9276 | base_q_idx, | 9877 | base_q_idx, |
| 9277 | tx_select, | 9878 | tx_select, |
| 9879 | + reduced_tx_set, | ||
| 9278 | )?; | 9880 | )?; |
| 9279 | neighbours.above_mode[sc] = mode_bot; | 9881 | neighbours.above_mode[sc] = mode_bot; |
| 9280 | neighbours.left_mode[sr] = mode_bot; | 9882 | neighbours.left_mode[sr] = mode_bot; |
| @@ -9304,6 +9906,7 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( | |||
| 9304 | allow_screen_content_tools, | 9906 | allow_screen_content_tools, |
| 9305 | base_q_idx, | 9907 | base_q_idx, |
| 9306 | tx_select, | 9908 | tx_select, |
| 9909 | + reduced_tx_set, | ||
| 9307 | )?; | 9910 | )?; |
| 9308 | let mode_right = decode_leaf_rect( | 9911 | let mode_right = decode_leaf_rect( |
| 9309 | &mut dec, | 9912 | &mut dec, |
| @@ -9321,6 +9924,7 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( | |||
| 9321 | allow_screen_content_tools, | 9924 | allow_screen_content_tools, |
| 9322 | base_q_idx, | 9925 | base_q_idx, |
| 9323 | tx_select, | 9926 | tx_select, |
| 9927 | + reduced_tx_set, | ||
| 9324 | )?; | 9928 | )?; |
| 9325 | neighbours.above_mode[sc] = mode_right; | 9929 | neighbours.above_mode[sc] = mode_right; |
| 9326 | neighbours.left_mode[sr] = mode_right; | 9930 | neighbours.left_mode[sr] = mode_right; |
| @@ -9340,11 +9944,38 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( | |||
| 9340 | // the one or two the edge leaves. | 9944 | // the one or two the edge leaves. |
| 9341 | let (mi_row0, mi_col0) = | 9945 | let (mi_row0, mi_col0) = |
| 9342 | (sr as u32 * SUB_MI, sc as u32 * SUB_MI); | 9946 | (sr as u32 * SUB_MI, sc as u32 * SUB_MI); |
| 9343 | - let mut prev_leaf: Option<((usize, usize), usize)> = None; | 9947 | + // Each 8x8 leaf's intra-mode context |
| 9948 | + // must see its own siblings: the | ||
| 9949 | + // bottom-left leaf's ABOVE neighbour | ||
| 9950 | + // is leaf 0, not the previously | ||
| 9951 | + // decoded leaf 1 (and the bottom-right | ||
| 9952 | + // leaf's above is leaf 1, while | ||
| 9953 | + // `prev_leaf` only ever carried the | ||
| 9954 | + // immediately preceding one). The | ||
| 9955 | + // coarse `above_mode`/`left_mode` | ||
| 9956 | + // arrays hold one slot per 16x16, so | ||
| 9957 | + // the sibling modes are swapped in | ||
| 9958 | + // around each leaf call and restored | ||
| 9959 | + // after; the loop tail writes the last | ||
| 9960 | + // leaf's mode as before. | ||
| 9961 | + let mut sib_modes: [Option<(usize, usize)>; 4] = [None; 4]; | ||
| 9344 | for i in 0..4 { | 9962 | for i in 0..4 { |
| 9345 | let (mr, mc) = | 9963 | let (mr, mc) = |
| 9346 | (mi_row0 + (i / 2) * 2, mi_col0 + (i % 2) * 2); | 9964 | (mi_row0 + (i / 2) * 2, mi_col0 + (i % 2) * 2); |
| 9347 | let leaf_mi = (mr as usize, mc as usize); | 9965 | let leaf_mi = (mr as usize, mc as usize); |
| 9966 | + let li = i as usize; | ||
| 9967 | + let saved_modes = | ||
| 9968 | + (neighbours.above_mode[sc], neighbours.left_mode[sr]); | ||
| 9969 | + if li >= 2 { | ||
| 9970 | + if let Some((below, _)) = sib_modes[li - 2] { | ||
| 9971 | + neighbours.above_mode[sc] = below; | ||
| 9972 | + } | ||
| 9973 | + } | ||
| 9974 | + if li % 2 == 1 { | ||
| 9975 | + if let Some((_, right)) = sib_modes[li - 1] { | ||
| 9976 | + neighbours.left_mode[sr] = right; | ||
| 9977 | + } | ||
| 9978 | + } | ||
| 9348 | let leaf_ctx = neighbours.partition_ctx_mi(leaf_mi, 8); | 9979 | let leaf_ctx = neighbours.partition_ctx_mi(leaf_mi, 8); |
| 9349 | let part8 = | 9980 | let part8 = |
| 9350 | dec.symbol(&mut cdfs.partition_w8[leaf_ctx]); | 9981 | dec.symbol(&mut cdfs.partition_w8[leaf_ctx]); |
| @@ -9353,34 +9984,56 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( | |||
| 9353 | "TRACE partition_w8 mi=({mr},{mc}) ctx={leaf_ctx} value={part8}" | 9984 | "TRACE partition_w8 mi=({mr},{mc}) ctx={leaf_ctx} value={part8}" |
| 9354 | ); | 9985 | ); |
| 9355 | } | 9986 | } |
| 9356 | - if part8 != PARTITION_NONE { | 9987 | + let leaf_mode = if part8 == PARTITION_NONE { |
| 9988 | + decode_leaf8( | ||
| 9989 | + &mut dec, | ||
| 9990 | + &mut cdfs, | ||
| 9991 | + &mut neighbours, | ||
| 9992 | + at16, | ||
| 9993 | + leaf_mi, | ||
| 9994 | + (&scan8, &scan4), | ||
| 9995 | + None, | ||
| 9996 | + &mut y, | ||
| 9997 | + &mut u, | ||
| 9998 | + &mut v, | ||
| 9999 | + base_q_idx, | ||
| 10000 | + enable_filter_intra, | ||
| 10001 | + allow_screen_content_tools, | ||
| 10002 | + allow_intrabc, | ||
| 10003 | + tx_select, | ||
| 10004 | + reduced_tx_set, | ||
| 10005 | + ).map(|m| (m, m))? | ||
| 10006 | + } else if part8 == PARTITION_SPLIT { | ||
| 10007 | + decode_leaf_split4( | ||
| 10008 | + &mut dec, | ||
| 10009 | + &mut cdfs, | ||
| 10010 | + &mut neighbours, | ||
| 10011 | + at16, | ||
| 10012 | + leaf_mi, | ||
| 10013 | + &scan4, | ||
| 10014 | + None, | ||
| 10015 | + &mut y, | ||
| 10016 | + &mut u, | ||
| 10017 | + &mut v, | ||
| 10018 | + base_q_idx, | ||
| 10019 | + enable_filter_intra, | ||
| 10020 | + allow_intrabc, | ||
| 10021 | + reduced_tx_set, | ||
| 10022 | + )? | ||
| 10023 | + } else { | ||
| 9357 | return Err(unsupported( | 10024 | return Err(unsupported( |
| 9358 | - "a partition below 8x8 (this decoder codes no leaf smaller than 8x8)", | 10025 | + "a HORZ/VERT partition below 8x8 (this decoder's transform primitive is square-only; 4x8/8x4 need a real rectangular transform)", |
| 9359 | )); | 10026 | )); |
| 9360 | - } | 10027 | + }; |
| 9361 | - let leaf_mode = decode_leaf8( | 10028 | + neighbours.above_mode[sc] = saved_modes.0; |
| 9362 | - &mut dec, | 10029 | + neighbours.left_mode[sr] = saved_modes.1; |
| 9363 | - &mut cdfs, | 10030 | + sib_modes[li] = Some(leaf_mode); |
| 9364 | - &mut neighbours, | 10031 | + } |
| 9365 | - at16, | 10032 | + if let Some((below, _)) = sib_modes[2].or(sib_modes[3]).or(sib_modes[0]) { |
| 9366 | - leaf_mi, | 10033 | + neighbours.above_mode[sc] = below; |
| 9367 | - (&scan8, &scan4), | ||
| 9368 | - prev_leaf, | ||
| 9369 | - &mut y, | ||
| 9370 | - &mut u, | ||
| 9371 | - &mut v, | ||
| 9372 | - base_q_idx, | ||
| 9373 | - enable_filter_intra, | ||
| 9374 | - allow_screen_content_tools, | ||
| 9375 | - allow_intrabc, | ||
| 9376 | - tx_select, | ||
| 9377 | - reduced_tx_set, | ||
| 9378 | - )?; | ||
| 9379 | - prev_leaf = Some((leaf_mi, leaf_mode)); | ||
| 9380 | } | 10034 | } |
| 9381 | - if let Some((_, mode)) = prev_leaf { | 10035 | + if let Some((_, right)) = sib_modes[1].or(sib_modes[3]).or(sib_modes[0]) { |
| 9382 | - neighbours.above_mode[sc] = mode; | 10036 | + neighbours.left_mode[sr] = right; |
| 9383 | - neighbours.left_mode[sr] = mode; | ||
| 9384 | } | 10037 | } |
| 9385 | continue; | 10038 | continue; |
| 9386 | } | 10039 | } |
| @@ -9414,9 +10067,25 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( | |||
| 9414 | .map(|i| (mi_row0 + (i / 2) * 2, mi_col0 + (i % 2) * 2)) | 10067 | .map(|i| (mi_row0 + (i / 2) * 2, mi_col0 + (i % 2) * 2)) |
| 9415 | .filter(|&(mr, mc)| mr < mi_rows && mc < mi_cols) | 10068 | .filter(|&(mr, mc)| mr < mi_rows && mc < mi_cols) |
| 9416 | .collect(); | 10069 | .collect(); |
| 9417 | - let mut prev_leaf: Option<((usize, usize), usize)> = None; | 10070 | + // See the sibling-mode note in the clean |
| 10071 | + // SPLIT path above. | ||
| 10072 | + let mut sib_modes: [Option<(usize, usize)>; 4] = [None; 4]; | ||
| 9418 | for (mr, mc) in leaf_positions { | 10073 | for (mr, mc) in leaf_positions { |
| 9419 | let leaf_mi = (mr as usize, mc as usize); | 10074 | let leaf_mi = (mr as usize, mc as usize); |
| 10075 | + let li = (((mr - mi_row0) / 2) * 2 + (mc - mi_col0) / 2) | ||
| 10076 | + as usize; | ||
| 10077 | + let saved_modes = | ||
| 10078 | + (neighbours.above_mode[sc], neighbours.left_mode[sr]); | ||
| 10079 | + if li >= 2 { | ||
| 10080 | + if let Some((below, _)) = sib_modes[li - 2] { | ||
| 10081 | + neighbours.above_mode[sc] = below; | ||
| 10082 | + } | ||
| 10083 | + } | ||
| 10084 | + if li % 2 == 1 { | ||
| 10085 | + if let Some((_, right)) = sib_modes[li - 1] { | ||
| 10086 | + neighbours.left_mode[sr] = right; | ||
| 10087 | + } | ||
| 10088 | + } | ||
| 9420 | let leaf_ctx = neighbours.partition_ctx_mi(leaf_mi, 8); | 10089 | let leaf_ctx = neighbours.partition_ctx_mi(leaf_mi, 8); |
| 9421 | let part8 = dec.symbol(&mut cdfs.partition_w8[leaf_ctx]); | 10090 | let part8 = dec.symbol(&mut cdfs.partition_w8[leaf_ctx]); |
| 9422 | if std::env::var_os("EC_AV1_TRACE").is_some() { | 10091 | if std::env::var_os("EC_AV1_TRACE").is_some() { |
| @@ -9424,30 +10093,50 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( | |||
| 9424 | "TRACE partition_w8 mi=({mr},{mc}) ctx={leaf_ctx} value={part8}" | 10093 | "TRACE partition_w8 mi=({mr},{mc}) ctx={leaf_ctx} value={part8}" |
| 9425 | ); | 10094 | ); |
| 9426 | } | 10095 | } |
| 9427 | - if part8 != PARTITION_NONE { | 10096 | + let leaf_mode = if part8 == PARTITION_NONE { |
| 10097 | + decode_leaf8( | ||
| 10098 | + &mut dec, | ||
| 10099 | + &mut cdfs, | ||
| 10100 | + &mut neighbours, | ||
| 10101 | + at16, | ||
| 10102 | + leaf_mi, | ||
| 10103 | + (&scan8, &scan4), | ||
| 10104 | + None, | ||
| 10105 | + &mut y, | ||
| 10106 | + &mut u, | ||
| 10107 | + &mut v, | ||
| 10108 | + base_q_idx, | ||
| 10109 | + enable_filter_intra, | ||
| 10110 | + allow_screen_content_tools, | ||
| 10111 | + allow_intrabc, | ||
| 10112 | + tx_select, | ||
| 10113 | + reduced_tx_set, | ||
| 10114 | + ).map(|m| (m, m))? | ||
| 10115 | + } else if part8 == PARTITION_SPLIT { | ||
| 10116 | + decode_leaf_split4( | ||
| 10117 | + &mut dec, | ||
| 10118 | + &mut cdfs, | ||
| 10119 | + &mut neighbours, | ||
| 10120 | + at16, | ||
| 10121 | + leaf_mi, | ||
| 10122 | + &scan4, | ||
| 10123 | + None, | ||
| 10124 | + &mut y, | ||
| 10125 | + &mut u, | ||
| 10126 | + &mut v, | ||
| 10127 | + base_q_idx, | ||
| 10128 | + enable_filter_intra, | ||
| 10129 | + allow_intrabc, | ||
| 10130 | + reduced_tx_set, | ||
| 10131 | + )? | ||
| 10132 | + } else { | ||
| 9428 | return Err(unsupported( | 10133 | return Err(unsupported( |
| 9429 | - "a partition below 8x8 (this decoder codes no leaf smaller than 8x8)", | 10134 | + "a HORZ/VERT partition below 8x8 (this decoder's transform primitive is square-only; 4x8/8x4 need a real rectangular transform)", |
| 9430 | )); | 10135 | )); |
| 9431 | - } | 10136 | + }; |
| 9432 | - let leaf_mode = decode_leaf8( | 10137 | + neighbours.above_mode[sc] = saved_modes.0; |
| 9433 | - &mut dec, | 10138 | + neighbours.left_mode[sr] = saved_modes.1; |
| 9434 | - &mut cdfs, | 10139 | + sib_modes[li] = Some(leaf_mode); |
| 9435 | - &mut neighbours, | ||
| 9436 | - at16, | ||
| 9437 | - leaf_mi, | ||
| 9438 | - (&scan8, &scan4), | ||
| 9439 | - prev_leaf, | ||
| 9440 | - &mut y, | ||
| 9441 | - &mut u, | ||
| 9442 | - &mut v, | ||
| 9443 | - base_q_idx, | ||
| 9444 | - enable_filter_intra, | ||
| 9445 | - allow_screen_content_tools, | ||
| 9446 | - allow_intrabc, | ||
| 9447 | - tx_select, | ||
| 9448 | - reduced_tx_set, | ||
| 9449 | - )?; | ||
| 9450 | - prev_leaf = Some((leaf_mi, leaf_mode)); | ||
| 9451 | } | 10140 | } |
| 9452 | // `record()`'s `above_mode`/`left_mode` | 10141 | // `record()`'s `above_mode`/`left_mode` |
| 9453 | // write is a no-op at an 8x8 leaf's own | 10142 | // write is a no-op at an 8x8 leaf's own |
| @@ -9455,9 +10144,11 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( | |||
| 9455 | // 16x16 slot's leaves are done, from the | 10144 | // 16x16 slot's leaves are done, from the |
| 9456 | // last leaf (mirrors the writer's r15 | 10145 | // last leaf (mirrors the writer's r15 |
| 9457 | // fix). | 10146 | // fix). |
| 9458 | - if let Some((_, mode)) = prev_leaf { | 10147 | + if let Some((below, _)) = sib_modes[2].or(sib_modes[3]).or(sib_modes[0]) { |
| 9459 | - neighbours.above_mode[sc] = mode; | 10148 | + neighbours.above_mode[sc] = below; |
| 9460 | - neighbours.left_mode[sr] = mode; | 10149 | + } |
| 10150 | + if let Some((_, right)) = sib_modes[1].or(sib_modes[3]).or(sib_modes[0]) { | ||
| 10151 | + neighbours.left_mode[sr] = right; | ||
| 9461 | } | 10152 | } |
| 9462 | } | 10153 | } |
| 9463 | } | 10154 | } |
| @@ -16036,7 +16727,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( | |||
| 16036 | let part8 = dec.symbol(&mut cdfs.partition_w8[leaf_ctx]); | 16727 | let part8 = dec.symbol(&mut cdfs.partition_w8[leaf_ctx]); |
| 16037 | if part8 != PARTITION_NONE { | 16728 | if part8 != PARTITION_NONE { |
| 16038 | return Err(unsupported( | 16729 | return Err(unsupported( |
| 16039 | - "a partition below 8x8 (this decoder codes no leaf smaller than 8x8)", | 16730 | + "an inter partition below 8x8 (this decoder codes no inter leaf smaller than 8x8; lane-sub8 scoped to intra)", |
| 16040 | )); | 16731 | )); |
| 16041 | } | 16732 | } |
| 16042 | let ( | 16733 | let ( |
| @@ -17164,6 +17855,72 @@ mod tests { | |||
| 17164 | // this decoder's one target, and the round-trip test below is against | 17855 | // this decoder's one target, and the round-trip test below is against |
| 17165 | // that path with real quantised residual, not a synthetic all-DC frame. | 17856 | // that path with real quantised residual, not a synthetic all-DC frame. |
| 17166 | 17857 | ||
| 17858 | + /// [`SCAN_8X4`]/[`SCAN_4X8`] (lane-rectx r2): a bijection check alone | ||
| 17859 | + /// cannot catch a transposed pair -- a swap of two orientation tables is | ||
| 17860 | + /// still a bijection over the same 32 positions. This pins BOTH arrays | ||
| 17861 | + /// at once, element-for-element, against literal transcriptions of | ||
| 17862 | + /// libaom's real `default_scan_4x8`/`default_scan_8x4` in | ||
| 17863 | + /// `av1/common/scan.c` (`~/.cache/aom-oracle/src`, read directly for | ||
| 17864 | + /// this test, not re-derived from the zigzag formula). The two source | ||
| 17865 | + /// sequences are themselves different in their own right (not equal to | ||
| 17866 | + /// each other), so this is asymmetric in the two axes: if the repo's | ||
| 17867 | + /// `SCAN_8X4`/`SCAN_4X8` were swapped with each other, one side of this | ||
| 17868 | + /// assert pair would fail even though each individual array would still | ||
| 17869 | + /// pass a same-orientation bijection test. | ||
| 17870 | + #[test] | ||
| 17871 | + fn scan_8x4_and_4x8_are_not_transposed_against_each_other() { | ||
| 17872 | + // libaom `default_scan_4x8` verbatim (scan.c:29-32) -- this repo | ||
| 17873 | + // names it `SCAN_8X4` under the established w/h axis swap (see | ||
| 17874 | + // `SCAN_8X4`'s own doc comment). | ||
| 17875 | + const LIBAOM_DEFAULT_SCAN_4X8: [u16; 32] = [ | ||
| 17876 | + 0, 8, 1, 16, 9, 2, 24, 17, 10, 3, 25, 18, 11, 4, 26, 19, 12, 5, 27, 20, 13, 6, 28, 21, | ||
| 17877 | + 14, 7, 29, 22, 15, 30, 23, 31, | ||
| 17878 | + ]; | ||
| 17879 | + // libaom `default_scan_8x4` verbatim (scan.c:44-47) -- this repo's | ||
| 17880 | + // `SCAN_4X8`. | ||
| 17881 | + const LIBAOM_DEFAULT_SCAN_8X4: [u16; 32] = [ | ||
| 17882 | + 0, 1, 4, 2, 5, 8, 3, 6, 9, 12, 7, 10, 13, 16, 11, 14, 17, 20, 15, 18, 21, 24, 19, 22, | ||
| 17883 | + 25, 28, 23, 26, 29, 27, 30, 31, | ||
| 17884 | + ]; | ||
| 17885 | + assert_ne!( | ||
| 17886 | + LIBAOM_DEFAULT_SCAN_4X8, LIBAOM_DEFAULT_SCAN_8X4, | ||
| 17887 | + "the two libaom source sequences must differ, or this pin would \ | ||
| 17888 | + pass regardless of a swap" | ||
| 17889 | + ); | ||
| 17890 | + assert_eq!(SCAN_8X4, LIBAOM_DEFAULT_SCAN_4X8, "SCAN_8X4 vs libaom default_scan_4x8"); | ||
| 17891 | + assert_eq!(SCAN_4X8, LIBAOM_DEFAULT_SCAN_8X4, "SCAN_4X8 vs libaom default_scan_8x4"); | ||
| 17892 | + } | ||
| 17893 | + | ||
| 17894 | + /// lane-rectx r3: `av1_filter_intra_allowed_bsize` is "both sides <= 32", | ||
| 17895 | + /// so a DC_PRED 16x8/8x16 strip reads a `use_filter_intra` flag exactly | ||
| 17896 | + /// like a square 16x16 does. [`filter_intra_size_class_rect`] returned | ||
| 17897 | + /// `None` at those two sizes, so the symbol was never read and the tile | ||
| 17898 | + /// desynced from that block on (root-caused against an instrumented | ||
| 17899 | + /// aomdec `EC_TRACE_COEFF` ladder on a real stream: identical `mode=0`/ | ||
| 17900 | + /// `uv_mode=9` values, our range 34808 vs the oracle's 40668 at the very | ||
| 17901 | + /// next transform block). | ||
| 17902 | + /// | ||
| 17903 | + /// The two rows are ASYMMETRIC (9394 for 16x8, 12551 for 8x16), so this | ||
| 17904 | + /// pin fails if the pair is ever transposed -- the shape the repo's | ||
| 17905 | + /// scan tables already carry (`SCAN_8X4` == libaom `default_scan_4x8`). | ||
| 17906 | + #[test] | ||
| 17907 | + fn a_rect_strip_below_16x16_reads_its_own_filter_intra_cdf_row() { | ||
| 17908 | + // `default_filter_intra_cdfs` (entropymode.c), indexed by BLOCK_SIZES_ALL: | ||
| 17909 | + // [4] = BLOCK_8X16, [5] = BLOCK_16X8, [7] = BLOCK_16X32, [8] = BLOCK_32X16. | ||
| 17910 | + const LIBAOM_8X16: u16 = 12551; | ||
| 17911 | + const LIBAOM_16X8: u16 = 9394; | ||
| 17912 | + let c16x8 = filter_intra_size_class_rect(16, 8).expect("16x8 reads use_filter_intra"); | ||
| 17913 | + let c8x16 = filter_intra_size_class_rect(8, 16).expect("8x16 reads use_filter_intra"); | ||
| 17914 | + assert_ne!(c16x8, c8x16, "the two orientations must not share a CDF row"); | ||
| 17915 | + assert_eq!(cdf::FILTER_INTRA[c16x8][0], LIBAOM_16X8, "16x8 filter_intra row"); | ||
| 17916 | + assert_eq!(cdf::FILTER_INTRA[c8x16][0], LIBAOM_8X16, "8x16 filter_intra row"); | ||
| 17917 | + // The sizes one class up keep their own distinct rows (lane-intradisp). | ||
| 17918 | + assert_eq!(cdf::FILTER_INTRA[filter_intra_size_class_rect(32, 16).unwrap()][0], 12756); | ||
| 17919 | + assert_eq!(cdf::FILTER_INTRA[filter_intra_size_class_rect(16, 32).unwrap()][0], 14301); | ||
| 17920 | + // A size with a side over 32 is genuinely not allowed the flag. | ||
| 17921 | + assert_eq!(filter_intra_size_class_rect(64, 32), None); | ||
| 17922 | + } | ||
| 17923 | + | ||
| 17167 | /// `is_uni_comp_ref` (lane-av1comp): a pair is unidirectional exactly | 17924 | /// `is_uni_comp_ref` (lane-av1comp): a pair is unidirectional exactly |
| 17168 | /// when both references sit on the same temporal side -- the three | 17925 | /// when both references sit on the same temporal side -- the three |
| 17169 | /// `uni_comp_ref` bitstream pairs (LAST/LAST2, LAST/LAST3, LAST/GOLDEN) | 17926 | /// `uni_comp_ref` bitstream pairs (LAST/LAST2, LAST/LAST3, LAST/GOLDEN) |
crates/ec-av1/src/encode.rsmodified+180 -40
| @@ -1020,7 +1020,7 @@ pub(crate) struct Reach { | |||
| 1020 | /// it. Indexed by the block's position in the superblock, in blocks of its own | 1020 | /// it. Indexed by the block's position in the superblock, in blocks of its own |
| 1021 | /// size, as `row * (128 / side) + col` (`Reach::table_stride`) -- libaom's | 1021 | /// size, as `row * (128 / side) + col` (`Reach::table_stride`) -- libaom's |
| 1022 | /// 128, not this crate's 64 superblock -- bit by bit from the low end. | 1022 | /// 128, not this crate's 64 superblock -- bit by bit from the low end. |
| 1023 | -const HAS_TOP_RIGHT: [&[u8]; 3] = [ | 1023 | +const HAS_TOP_RIGHT: [&[u8]; 4] = [ |
| 1024 | &[255, 85, 119, 85, 127, 85, 119, 85], | 1024 | &[255, 85, 119, 85, 127, 85, 119, 85], |
| 1025 | &[95, 87], | 1025 | &[95, 87], |
| 1026 | // has_tr_8x8 (libaom av1/common/reconintra.c) -- table_stride(8) == 16 | 1026 | // has_tr_8x8 (libaom av1/common/reconintra.c) -- table_stride(8) == 16 |
| @@ -1029,11 +1029,28 @@ const HAS_TOP_RIGHT: [&[u8]; 3] = [ | |||
| 1029 | 255, 255, 85, 85, 119, 119, 85, 85, 127, 127, 85, 85, 119, 119, 85, 85, 255, 127, 85, 85, | 1029 | 255, 255, 85, 85, 119, 119, 85, 85, 127, 127, 85, 85, 119, 119, 85, 85, 255, 127, 85, 85, |
| 1030 | 119, 119, 85, 85, 127, 127, 85, 85, 119, 119, 85, 85, | 1030 | 119, 119, 85, 85, 127, 127, 85, 85, 119, 119, 85, 85, |
| 1031 | ], | 1031 | ], |
| 1032 | + | ||
| 1033 | + // has_tr_4x4 (libaom av1/common/reconintra.c, transcribed verbatim) -- | ||
| 1034 | + // table_stride(4) == 32 (128 / 4), so 32 bits per row, 32 rows, 128 | ||
| 1035 | + // bytes. Sub-8x8 leaves (lane-sub8) are the only blocks that reach here | ||
| 1036 | + // with side 4 outside a TX4 split; without their own row they clamped | ||
| 1037 | + // into the 8x8 table and read above-right samples the decoder has not | ||
| 1038 | + // written yet (all-zero pixels in the bottom-right triangle of a | ||
| 1039 | + // directional 4x4 leaf). | ||
| 1040 | + &[ | ||
| 1041 | + 255, 255, 255, 255, 85, 85, 85, 85, 119, 119, 119, 119, 85, 85, 85, 85, 127, 127, 127, 127, | ||
| 1042 | + 85, 85, 85, 85, 119, 119, 119, 119, 85, 85, 85, 85, 255, 127, 255, 127, 85, 85, 85, 85, | ||
| 1043 | + 119, 119, 119, 119, 85, 85, 85, 85, 127, 127, 127, 127, 85, 85, 85, 85, 119, 119, 119, 119, | ||
| 1044 | + 85, 85, 85, 85, 255, 255, 255, 127, 85, 85, 85, 85, 119, 119, 119, 119, 85, 85, 85, 85, | ||
| 1045 | + 127, 127, 127, 127, 85, 85, 85, 85, 119, 119, 119, 119, 85, 85, 85, 85, 255, 127, 255, 127, | ||
| 1046 | + 85, 85, 85, 85, 119, 119, 119, 119, 85, 85, 85, 85, 127, 127, 127, 127, 85, 85, 85, 85, | ||
| 1047 | + 119, 119, 119, 119, 85, 85, 85, 85, | ||
| 1048 | + ], | ||
| 1032 | ]; | 1049 | ]; |
| 1033 | 1050 | ||
| 1034 | /// `has_bl_16x16` / `has_bl_32x32`: the same, for the block below and to the | 1051 | /// `has_bl_16x16` / `has_bl_32x32`: the same, for the block below and to the |
| 1035 | /// left. | 1052 | /// left. |
| 1036 | -const HAS_BOTTOM_LEFT: [&[u8]; 3] = [ | 1053 | +const HAS_BOTTOM_LEFT: [&[u8]; 4] = [ |
| 1037 | &[84, 16, 84, 0, 84, 16, 84, 0], | 1054 | &[84, 16, 84, 0, 84, 16, 84, 0], |
| 1038 | &[4, 4], | 1055 | &[4, 4], |
| 1039 | // has_bl_8x8 (libaom av1/common/reconintra.c) | 1056 | // has_bl_8x8 (libaom av1/common/reconintra.c) |
| @@ -1041,6 +1058,16 @@ const HAS_BOTTOM_LEFT: [&[u8]; 3] = [ | |||
| 1041 | 84, 85, 16, 17, 84, 85, 0, 1, 84, 85, 16, 17, 84, 85, 0, 0, 84, 85, 16, 17, 84, 85, 0, 1, | 1058 | 84, 85, 16, 17, 84, 85, 0, 1, 84, 85, 16, 17, 84, 85, 0, 0, 84, 85, 16, 17, 84, 85, 0, 1, |
| 1042 | 84, 85, 16, 17, 84, 85, 0, 0, | 1059 | 84, 85, 16, 17, 84, 85, 0, 0, |
| 1043 | ], | 1060 | ], |
| 1061 | + | ||
| 1062 | + // has_bl_4x4 (same source, same order). | ||
| 1063 | + &[ | ||
| 1064 | + 84, 85, 85, 85, 16, 17, 17, 17, 84, 85, 85, 85, 0, 1, 1, 1, 84, 85, 85, 85, 16, 17, 17, 17, | ||
| 1065 | + 84, 85, 85, 85, 0, 0, 1, 0, 84, 85, 85, 85, 16, 17, 17, 17, 84, 85, 85, 85, 0, 1, 1, 1, 84, | ||
| 1066 | + 85, 85, 85, 16, 17, 17, 17, 84, 85, 85, 85, 0, 0, 0, 0, 84, 85, 85, 85, 16, 17, 17, 17, 84, | ||
| 1067 | + 85, 85, 85, 0, 1, 1, 1, 84, 85, 85, 85, 16, 17, 17, 17, 84, 85, 85, 85, 0, 0, 1, 0, 84, 85, | ||
| 1068 | + 85, 85, 16, 17, 17, 17, 84, 85, 85, 85, 0, 1, 1, 1, 84, 85, 85, 85, 16, 17, 17, 17, 84, 85, | ||
| 1069 | + 85, 85, 0, 0, 0, 0, | ||
| 1070 | + ], | ||
| 1044 | ]; | 1071 | ]; |
| 1045 | 1072 | ||
| 1046 | /// `has_tr_vert_*` (libaom `reconintra.c`, `has_tr_vert_tables`), indexed by | 1073 | /// `has_tr_vert_*` (libaom `reconintra.c`, `has_tr_vert_tables`), indexed by |
| @@ -1104,6 +1131,38 @@ const HAS_TOP_RIGHT_RECT: [&[u8]; 2] = [&[15, 5, 7, 5], &[255, 119, 127, 119]]; | |||
| 1104 | /// `has_bl_32x16`/`has_bl_16x32`, same source, same order. | 1131 | /// `has_bl_32x16`/`has_bl_16x32`, same source, same order. |
| 1105 | const HAS_BOTTOM_LEFT_RECT: [&[u8]; 2] = [&[78, 14, 78, 14], &[16, 0, 16, 0]]; | 1132 | const HAS_BOTTOM_LEFT_RECT: [&[u8]; 2] = [&[78, 14, 78, 14], &[16, 0, 16, 0]]; |
| 1106 | 1133 | ||
| 1134 | +/// libaom `reconintra.c`'s `has_tr_*`/`has_bl_*` for the four rectangular | ||
| 1135 | +/// block sizes this decoder codes, transcribed verbatim (lane-rectx r4). | ||
| 1136 | +/// The 16x8/8x16 rows are what the 32x16/16x32 pair above cannot stand in | ||
| 1137 | +/// for: they are 16 bytes, not 4, and their bit pattern is a different | ||
| 1138 | +/// coding order entirely -- reading the 16x32 table for a 16x8 block gave | ||
| 1139 | +/// the wrong bottom-left availability and a directional (D203) strip whose | ||
| 1140 | +/// prediction diverged exactly where it starts reading below its own height. | ||
| 1141 | +/// `has_tr_vert_tables`/`has_bl_vert_tables` hold the SAME pointers as these | ||
| 1142 | +/// for every W<H entry, and are NULL for W>H (no VERT_A/B ever produces one), | ||
| 1143 | +/// so the partition type does not select a different table at these sizes. | ||
| 1144 | +fn has_tr_rect_table(bw: usize, bh: usize) -> &'static [u8] { | ||
| 1145 | + match (bw, bh) { | ||
| 1146 | + (16, 8) => &[255, 0, 85, 0, 119, 0, 85, 0, 127, 0, 85, 0, 119, 0, 85, 0], | ||
| 1147 | + (8, 16) => &[255, 255, 119, 119, 127, 127, 119, 119, 255, 127, 119, 119, 127, 127, 119, 119], | ||
| 1148 | + (32, 16) => &[15, 5, 7, 5], | ||
| 1149 | + (16, 32) => &[255, 119, 127, 119], | ||
| 1150 | + (64, 32) => &[19], | ||
| 1151 | + _ => &[127], | ||
| 1152 | + } | ||
| 1153 | +} | ||
| 1154 | + | ||
| 1155 | +fn has_bl_rect_table(bw: usize, bh: usize) -> &'static [u8] { | ||
| 1156 | + match (bw, bh) { | ||
| 1157 | + (16, 8) => &[254, 84, 254, 16, 254, 84, 254, 0, 254, 84, 254, 16, 254, 84, 254, 0], | ||
| 1158 | + (8, 16) => &[16, 17, 0, 1, 16, 17, 0, 0, 16, 17, 0, 1, 16, 17, 0, 0], | ||
| 1159 | + (32, 16) => &[78, 14, 78, 14], | ||
| 1160 | + (16, 32) => &[16, 0, 16, 0], | ||
| 1161 | + (64, 32) => &[34], | ||
| 1162 | + _ => &[0], | ||
| 1163 | + } | ||
| 1164 | +} | ||
| 1165 | + | ||
| 1107 | impl Reach { | 1166 | impl Reach { |
| 1108 | /// What a block of `side` samples at `(x, y)` may read past its own edges, | 1167 | /// What a block of `side` samples at `(x, y)` may read past its own edges, |
| 1109 | /// in a frame of `width` by `height`. | 1168 | /// in a frame of `width` by `height`. |
| @@ -1133,37 +1192,61 @@ impl Reach { | |||
| 1133 | } | 1192 | } |
| 1134 | } | 1193 | } |
| 1135 | 1194 | ||
| 1136 | - fn position_rect(bw: usize, bh: usize, x: usize, y: usize) -> (usize, usize, usize, usize) { | 1195 | + /// libaom `has_top_right` at block granularity (`row_off`/`col_off` 0, |
| 1137 | - ( | 1196 | + /// the transform covering the whole block, luma): everything before the |
| 1138 | - (y % SUPERBLOCK) / bh, | 1197 | + /// table lookup is that function's own early-exit ladder. |
| 1139 | - (x % SUPERBLOCK) / bw, | ||
| 1140 | - SUPERBLOCK / bh, | ||
| 1141 | - SUPERBLOCK / bw, | ||
| 1142 | - ) | ||
| 1143 | - } | ||
| 1144 | - | ||
| 1145 | fn top_right_rect(bw: usize, bh: usize, x: usize, y: usize) -> bool { | 1198 | fn top_right_rect(bw: usize, bh: usize, x: usize, y: usize) -> bool { |
| 1146 | - let (row, col, _per_row, per_col) = Self::position_rect(bw, bh, x, y); | 1199 | + const SB_MI: usize = SUPERBLOCK / 4; |
| 1147 | - if row == 0 { | 1200 | + let (mi_row, mi_col) = (y / 4, x / 4); |
| 1201 | + let bw_log2 = (bw / 4).trailing_zeros() as usize; | ||
| 1202 | + let bh_log2 = (bh / 4).trailing_zeros() as usize; | ||
| 1203 | + let blk_row = (mi_row & (SB_MI - 1)) >> bh_log2; | ||
| 1204 | + let blk_col = (mi_col & (SB_MI - 1)) >> bw_log2; | ||
| 1205 | + // Top row of the superblock: the top-right pixels are in the (already | ||
| 1206 | + // decoded) superblock above. | ||
| 1207 | + if blk_row == 0 { | ||
| 1148 | return true; | 1208 | return true; |
| 1149 | } | 1209 | } |
| 1150 | - if col + 1 == per_col { | 1210 | + // Rightmost column: they fall in the superblock to the right. |
| 1211 | + if ((blk_col + 1) << bw_log2) >= SB_MI { | ||
| 1151 | return false; | 1212 | return false; |
| 1152 | } | 1213 | } |
| 1153 | - let table = HAS_TOP_RIGHT_RECT[usize::from(bw == 16)]; | 1214 | + let table = has_tr_rect_table(bw, bh); |
| 1154 | - Self::bit(table, (row * Self::table_stride(bw) + col) % (table.len() * 8)) | 1215 | + Self::bit(table, Self::rect_table_index(bw_log2, blk_row, blk_col)) |
| 1216 | + } | ||
| 1217 | + | ||
| 1218 | + /// libaom `has_top_right`'s own index arithmetic: | ||
| 1219 | + /// `(blk_row << (MAX_MIB_SIZE_LOG2 - bw_in_mi_log2)) + blk_col`, and | ||
| 1220 | + /// `MAX_MIB_SIZE_LOG2` is 5 (`enums.h`: libaom's tables are laid out for a | ||
| 1221 | + /// 128x128 superblock = 32 mi), NOT this crate's 64x64 = 16. lane-rectx r5: | ||
| 1222 | + /// r4 wrote `4 - bw_log2`, halving the row stride -- every table row but | ||
| 1223 | + /// the first then read the wrong byte (16x8 wrong at 80 mi positions in a | ||
| 1224 | + /// 64-wide SB, 8x16 at 16, 32x16 at 64, a regression against main). | ||
| 1225 | + /// [`tests::rect_reach_tables_are_indexed_with_a_32_mi_row_stride`] pins it. | ||
| 1226 | + fn rect_table_index(bw_log2: usize, blk_row: usize, blk_col: usize) -> usize { | ||
| 1227 | + (blk_row << (5 - bw_log2)) + blk_col | ||
| 1155 | } | 1228 | } |
| 1156 | 1229 | ||
| 1230 | + /// libaom `has_bottom_left`, same granularity as [`Self::top_right_rect`]. | ||
| 1157 | fn bottom_left_rect(bw: usize, bh: usize, x: usize, y: usize) -> bool { | 1231 | fn bottom_left_rect(bw: usize, bh: usize, x: usize, y: usize) -> bool { |
| 1158 | - let (row, col, per_row, _per_col) = Self::position_rect(bw, bh, x, y); | 1232 | + const SB_MI: usize = SUPERBLOCK / 4; |
| 1159 | - if col == 0 { | 1233 | + let (mi_row, mi_col) = (y / 4, x / 4); |
| 1160 | - return row * bh + bh < SUPERBLOCK; | 1234 | + let bw_log2 = (bw / 4).trailing_zeros() as usize; |
| 1235 | + let bh_log2 = (bh / 4).trailing_zeros() as usize; | ||
| 1236 | + let blk_row = (mi_row & (SB_MI - 1)) >> bh_log2; | ||
| 1237 | + let blk_col = (mi_col & (SB_MI - 1)) >> bw_log2; | ||
| 1238 | + // Leftmost column of the superblock: the bottom-left pixels are in | ||
| 1239 | + // the left superblock iff they stay inside its height. | ||
| 1240 | + if blk_col == 0 { | ||
| 1241 | + return (blk_row << bh_log2) + (bh / 4) < SB_MI; | ||
| 1161 | } | 1242 | } |
| 1162 | - if row + 1 == per_row { | 1243 | + // Bottom row (and not the leftmost column): they fall in the |
| 1244 | + // superblock below, which is not decoded yet. | ||
| 1245 | + if ((blk_row + 1) << bh_log2) >= SB_MI { | ||
| 1163 | return false; | 1246 | return false; |
| 1164 | } | 1247 | } |
| 1165 | - let table = HAS_BOTTOM_LEFT_RECT[usize::from(bw == 16)]; | 1248 | + let table = has_bl_rect_table(bw, bh); |
| 1166 | - Self::bit(table, (row * Self::table_stride(bw) + col) % (table.len() * 8)) | 1249 | + Self::bit(table, Self::rect_table_index(bw_log2, blk_row, blk_col)) |
| 1167 | } | 1250 | } |
| 1168 | 1251 | ||
| 1169 | /// Marks every [`Reach::of`] made until the returned guard drops as being | 1252 | /// Marks every [`Reach::of`] made until the returned guard drops as being |
| @@ -1196,21 +1279,22 @@ impl Reach { | |||
| 1196 | if col + 1 == per_side { | 1279 | if col + 1 == per_side { |
| 1197 | return false; | 1280 | return false; |
| 1198 | } | 1281 | } |
| 1199 | - // corner-cut: `HAS_TOP_RIGHT`/`HAS_BOTTOM_LEFT` only carry dedicated | 1282 | + // lane-sub8 r4: side 4 now has its own `has_tr_4x4`/`has_bl_4x4` row |
| 1200 | - // rows for side 8/16/32/64 (libaom's own `has_tr_8x8`/`has_tr_16x16` | 1283 | + // (the clamp corner-cut that used to live here is gone); sides |
| 1201 | - // families); a `TxMode::Select` TX4 transform unit reaches here with | 1284 | + // 16/32/64 share row 0 exactly as libaom's tables repeat. |
| 1202 | - // side 4, whose real table (`has_tr_4x4`, 128 bytes) was never | 1285 | + // corner-cut: libaom transcribes no vert 4x4 row, so a side-4 block |
| 1203 | - // transcribed. Clamping into the 16/32 table's own bit range keeps | 1286 | + // inside a `PARTITION_VERT_A`/`_B` falls back to the ordinary table |
| 1204 | - // this in-bounds and correct at every position that table already | 1287 | + // -- a reach over-estimate (extra above-right reference pixels), |
| 1205 | - // covers periodically -- wrong only at the small remainder past its | 1288 | + // never a stream desync. Ceiling: transcribe `has_tr_vert_4x4` / |
| 1206 | - // length, a reach over-/under-estimate (extra or missing above-right | 1289 | + // `has_bl_vert_4x4` and extend the VERT tables to four rows. |
| 1207 | - // reference pixels), never a stream desync (Reach never gates a | 1290 | + // NB: named `table_row`, not `row` -- `row` above is the block's |
| 1208 | - // symbol read). Ceiling: transcribe `has_tr_4x4`/`has_bl_4x4` | 1291 | + // position inside the superblock and is what the bit index below |
| 1209 | - // verbatim and give TX4 its own `HAS_TOP_RIGHT`/`HAS_BOTTOM_LEFT` row. | 1292 | + // steps by (a merge that shadowed it desynced every block size). |
| 1210 | - let table = if VERT_AB_PARTITION.with(std::cell::Cell::get) { | 1293 | + let table_row = Self::table(side); |
| 1211 | - HAS_TOP_RIGHT_VERT[Self::table(side)] | 1294 | + let table = if VERT_AB_PARTITION.with(std::cell::Cell::get) && table_row < HAS_TOP_RIGHT_VERT.len() { |
| 1295 | + HAS_TOP_RIGHT_VERT[table_row] | ||
| 1212 | } else { | 1296 | } else { |
| 1213 | - HAS_TOP_RIGHT[Self::table(side)] | 1297 | + HAS_TOP_RIGHT[table_row] |
| 1214 | }; | 1298 | }; |
| 1215 | Self::bit( | 1299 | Self::bit( |
| 1216 | table, | 1300 | table, |
| @@ -1230,11 +1314,22 @@ impl Reach { | |||
| 1230 | if row + 1 == per_side { | 1314 | if row + 1 == per_side { |
| 1231 | return false; | 1315 | return false; |
| 1232 | } | 1316 | } |
| 1233 | - // corner-cut: see `top_right`'s note -- same clamp, same ceiling. | 1317 | + // lane-sub8 r4: side 4 now has its own `has_tr_4x4`/`has_bl_4x4` row |
| 1234 | - let table = if VERT_AB_PARTITION.with(std::cell::Cell::get) { | 1318 | + // (the clamp corner-cut that used to live here is gone); sides |
| 1235 | - HAS_BOTTOM_LEFT_VERT[Self::table(side)] | 1319 | + // 16/32/64 share row 0 exactly as libaom's tables repeat. |
| 1320 | + // corner-cut: libaom transcribes no vert 4x4 row, so a side-4 block | ||
| 1321 | + // inside a `PARTITION_VERT_A`/`_B` falls back to the ordinary table | ||
| 1322 | + // -- a reach over-estimate (extra above-right reference pixels), | ||
| 1323 | + // never a stream desync. Ceiling: transcribe `has_tr_vert_4x4` / | ||
| 1324 | + // `has_bl_vert_4x4` and extend the VERT tables to four rows. | ||
| 1325 | + // NB: named `table_row`, not `row` -- `row` above is the block's | ||
| 1326 | + // position inside the superblock and is what the bit index below | ||
| 1327 | + // steps by (a merge that shadowed it desynced every block size). | ||
| 1328 | + let table_row = Self::table(side); | ||
| 1329 | + let table = if VERT_AB_PARTITION.with(std::cell::Cell::get) && table_row < HAS_BOTTOM_LEFT_VERT.len() { | ||
| 1330 | + HAS_BOTTOM_LEFT_VERT[table_row] | ||
| 1236 | } else { | 1331 | } else { |
| 1237 | - HAS_BOTTOM_LEFT[Self::table(side)] | 1332 | + HAS_BOTTOM_LEFT[table_row] |
| 1238 | }; | 1333 | }; |
| 1239 | Self::bit( | 1334 | Self::bit( |
| 1240 | table, | 1335 | table, |
| @@ -1270,6 +1365,8 @@ impl Reach { | |||
| 1270 | 1 | 1365 | 1 |
| 1271 | } else if side == 8 { | 1366 | } else if side == 8 { |
| 1272 | 2 | 1367 | 2 |
| 1368 | + } else if side == 4 { | ||
| 1369 | + 3 | ||
| 1273 | } else { | 1370 | } else { |
| 1274 | 0 | 1371 | 0 |
| 1275 | } | 1372 | } |
| @@ -3128,6 +3225,49 @@ pub fn encode_sequence( | |||
| 3128 | 3225 | ||
| 3129 | #[cfg(test)] | 3226 | #[cfg(test)] |
| 3130 | mod tests { | 3227 | mod tests { |
| 3228 | + | ||
| 3229 | + /// lane-rectx r5: libaom lays `has_tr_*`/`has_bl_*` out row-major for a | ||
| 3230 | + /// 128x128 superblock -- `MAX_MIB_SIZE_LOG2 = 5` mi columns per row, so a | ||
| 3231 | + /// row holds `32 >> bw_in_mi_log2` bits and the table holds | ||
| 3232 | + /// `32 >> bh_in_mi_log2` such rows. Walking every block position of that | ||
| 3233 | + /// superblock must therefore hit every bit of the table EXACTLY ONCE. | ||
| 3234 | + /// r4's `4 - bw_log2` index halved the row stride: the walk then covered | ||
| 3235 | + /// only a quarter of the 16x8 table and read the wrong byte for every | ||
| 3236 | + /// block row but the first (silently wrong above-right/below-left | ||
| 3237 | + /// availability -- wrong pixels, no error). | ||
| 3238 | + #[test] | ||
| 3239 | + fn rect_reach_tables_are_indexed_with_a_32_mi_row_stride() { | ||
| 3240 | + for (bw, bh) in [(16usize, 8usize), (8, 16), (32, 16), (16, 32), (64, 32), (32, 64)] { | ||
| 3241 | + let (bw_log2, bh_log2) = | ||
| 3242 | + ((bw / 4).trailing_zeros() as usize, (bh / 4).trailing_zeros() as usize); | ||
| 3243 | + let (rows, cols) = (32 >> bh_log2, 32 >> bw_log2); | ||
| 3244 | + for (name, table) in | ||
| 3245 | + [("has_tr", has_tr_rect_table(bw, bh)), ("has_bl", has_bl_rect_table(bw, bh))] | ||
| 3246 | + { | ||
| 3247 | + assert_eq!( | ||
| 3248 | + table.len() * 8, | ||
| 3249 | + rows * cols, | ||
| 3250 | + "{name}_{bw}x{bh}: libaom's table is {rows} rows of {cols} bits" | ||
| 3251 | + ); | ||
| 3252 | + let mut seen = vec![0u32; table.len() * 8]; | ||
| 3253 | + for blk_row in 0..rows { | ||
| 3254 | + for blk_col in 0..cols { | ||
| 3255 | + let idx = Reach::rect_table_index(bw_log2, blk_row, blk_col); | ||
| 3256 | + assert!( | ||
| 3257 | + idx < seen.len(), | ||
| 3258 | + "{name}_{bw}x{bh}: index {idx} past the table at ({blk_row},{blk_col})" | ||
| 3259 | + ); | ||
| 3260 | + seen[idx] += 1; | ||
| 3261 | + } | ||
| 3262 | + } | ||
| 3263 | + assert!( | ||
| 3264 | + seen.iter().all(|&n| n == 1), | ||
| 3265 | + "{name}_{bw}x{bh}: the block walk is not a bijection onto the table's bits \ | ||
| 3266 | + (row stride is not {cols})" | ||
| 3267 | + ); | ||
| 3268 | + } | ||
| 3269 | + } | ||
| 3270 | + } | ||
| 3131 | use super::*; | 3271 | use super::*; |
| 3132 | use crate::intra::{D45_PRED, D135_PRED, H_PRED, KEY_FRAME_MODES, NON_DIRECTIONAL, V_PRED}; | 3272 | use crate::intra::{D45_PRED, D135_PRED, H_PRED, KEY_FRAME_MODES, NON_DIRECTIONAL, V_PRED}; |
| 3133 | use std::io::Write; | 3273 | use std::io::Write; |
crates/ec-av1/src/gate_coverage.rsmodified+1 -1
| @@ -199,7 +199,7 @@ const NEVER_EXERCISED_10BIT: &[(&str, &str)] = &[ | |||
| 199 | // gate passes `=1` for both. | 199 | // gate passes `=1` for both. |
| 200 | ( | 200 | ( |
| 201 | "enable-1to4-partitions", | 201 | "enable-1to4-partitions", |
| 202 | - "10-bit hole only: lane-tx64x16's 8-bit SB-level 1:4 gate passes `=1` and asserts both arms, but no 10-bit gate does", | 202 | + "10-bit hole only: 8-bit gates (lane-tx64x16 SB-level 1:4, lane-sub8) pass `=1` and assert their arms, but no 10-bit gate does", |
| 203 | ), | 203 | ), |
| 204 | ( | 204 | ( |
| 205 | "enable-angle-delta", | 205 | "enable-angle-delta", |
crates/ec-av1/src/refusal_inventory.rsmodified+3 -3
| @@ -28,17 +28,16 @@ const CAPABILITY_CLAIMS: &[&str] = &[ | |||
| 28 | "a non-2D tx class on a rectangular transform (never expected at this size)", | 28 | "a non-2D tx class on a rectangular transform (never expected at this size)", |
| 29 | "a non-DC chroma mode on an 8x8 inter-frame leaf (this encoder never writes one)", | 29 | "a non-DC chroma mode on an 8x8 inter-frame leaf (this encoder never writes one)", |
| 30 | "a nonzero angle delta (this encoder never writes one)", | 30 | "a nonzero angle delta (this encoder never writes one)", |
| 31 | - "a partition below 8x8 (this decoder codes no leaf smaller than 8x8)", | ||
| 32 | - "a tx_type symbol on a rectangular transform (never expected at this size)", | ||
| 33 | ]; | 31 | ]; |
| 34 | 32 | ||
| 35 | #[cfg(test)] | 33 | #[cfg(test)] |
| 36 | const REFUSALS: &[&str] = &[ | 34 | const REFUSALS: &[&str] = &[ |
| 37 | "a coded (non-skip) HORZ_B/VERT_B rect strip below 16x16 (this decoder ports only the skip case at this size)", | 35 | "a coded (non-skip) HORZ_B/VERT_B rect strip below 16x16 (this decoder ports only the skip case at this size)", |
| 38 | - "a coded (non-skip) HORZ/VERT rect strip below 16x16 (this decoder ports only the skip case at this size)", | ||
| 39 | "a coded HORZ/VERT strip whose chroma transform has no rect coefficient tables here", | 36 | "a coded HORZ/VERT strip whose chroma transform has no rect coefficient tables here", |
| 40 | "a HORZ/VERT intra strip below 16x16 with a split transform (per-unit rect prediction is not ported)", | 37 | "a HORZ/VERT intra strip below 16x16 with a split transform (per-unit rect prediction is not ported)", |
| 41 | "a HORZ_A/HORZ_B/VERT_A partition below 16x16 (this decoder codes only the square arms, HORZ, VERT, VERT_B, and a clean split below 16x16)", | 38 | "a HORZ_A/HORZ_B/VERT_A partition below 16x16 (this decoder codes only the square arms, HORZ, VERT, VERT_B, and a clean split below 16x16)", |
| 39 | + "a HORZ/VERT partition below 8x8 (this decoder's transform primitive is square-only; 4x8/8x4 need a real rectangular transform)", | ||
| 40 | + "an inter partition below 8x8 (this decoder codes no inter leaf smaller than 8x8; lane-sub8 scoped to intra)", | ||
| 42 | "a 16x16 block whose true edge cuts through both axes needs a rectangular transform this decoder does not code yet", | 41 | "a 16x16 block whose true edge cuts through both axes needs a rectangular transform this decoder does not code yet", |
| 43 | "a 16x16 inter block whose true edge cuts through both axes needs a rectangular transform this decoder does not code yet", | 42 | "a 16x16 inter block whose true edge cuts through both axes needs a rectangular transform this decoder does not code yet", |
| 44 | "a 32x32 partition type this decoder does not code (value={part32})", | 43 | "a 32x32 partition type this decoder does not code (value={part32})", |
| @@ -50,6 +49,7 @@ const REFUSALS: &[&str] = &[ | |||
| 50 | "a palette block with a real transform on a superblock-level HORZ/VERT strip (corner-cropped luma coefficients not ported for palette)", | 49 | "a palette block with a real transform on a superblock-level HORZ/VERT strip (corner-cropped luma coefficients not ported for palette)", |
| 51 | "a block that actually uses a palette (UV) -- reconstruction is out of scope", | 50 | "a block that actually uses a palette (UV) -- reconstruction is out of scope", |
| 52 | "a block that actually uses a palette (Y) -- reconstruction is out of scope", | 51 | "a block that actually uses a palette (Y) -- reconstruction is out of scope", |
| 52 | + "a sub-8x8 leaf that uses intrabc (this reader has no block-vector path; the 8x8-and-up reader reconstructs one)", | ||
| 53 | "an intrabc block under TxMode::Select (its transform size is coded by the inter var-tx partition tree, which this decoder never reads)", | 53 | "an intrabc block under TxMode::Select (its transform size is coded by the inter var-tx partition tree, which this decoder never reads)", |
| 54 | "a bit depth of 12 (this decoder is gated at 8 and 10 only: warp/MC/wiener rounding shifts change at 12-bit and no 12-bit gate exists)", | 54 | "a bit depth of 12 (this decoder is gated at 8 and 10 only: warp/MC/wiener rounding shifts change at 12-bit and no 12-bit gate exists)", |
| 55 | "a frame OBU with no tile group", | 55 | "a frame OBU with no tile group", |
crates/ec-av1/src/stream.rsmodified+524 -0
| @@ -8268,6 +8268,330 @@ mod tests { | |||
| 8268 | result.as_ref().map(|f| f.len()).map_err(|e| e.to_string()) | 8268 | result.as_ref().map(|f| f.len()).map_err(|e| e.to_string()) |
| 8269 | ); | 8269 | ); |
| 8270 | } | 8270 | } |
| 8271 | + /// lane-rectx r3: a real `aomenc` stream whose 16x16-level | ||
| 8272 | + /// `PARTITION_HORZ`/`PARTITION_VERT` strips are CODED (non-skip), i.e. | ||
| 8273 | + /// carry genuine `TX_16X8`/`TX_8X16` luma coefficients and their | ||
| 8274 | + /// `TX_8X4`/`TX_4X8` chroma halves through [`decode_leaf_rect`]'s | ||
| 8275 | + /// lane-rectx arm -- the refusal "a coded (non-skip) HORZ/VERT rect strip | ||
| 8276 | + /// below 16x16" this round lifts. `--min-partition-size=8 | ||
| 8277 | + /// --max-partition-size=32 --enable-rect-partitions=1` is what makes | ||
| 8278 | + /// aomenc reach for a 16x8 leaf at all; mandelbrot at `cq-level=24` is | ||
| 8279 | + /// what makes those leaves non-skip (a gradient fixture codes them all | ||
| 8280 | + /// away). `--reduced-tx-type-set=1` pins the five-symbol | ||
| 8281 | + /// `EXT_TX_SET_DTT4_IDTX` alphabet: without it aomenc also writes | ||
| 8282 | + /// `V_DCT`/`H_DCT`, whose 1D tx classes [`read_coeffs_rect`] still | ||
| 8283 | + /// refuses by name (see the r3 report's open residue), so a `=0` run | ||
| 8284 | + /// would prove nothing about the 2D path it does support. | ||
| 8285 | + /// | ||
| 8286 | + /// r2 shipped this path unproven; it was wrong. `TxbSet::LumaRect16x8` | ||
| 8287 | + /// read its `tx_type` symbol from the 16x16 row, but libaom's | ||
| 8288 | + /// `read_tx_type` indexes `intra_ext_tx_cdf[eset][txsize_sqr_map[tx_size]]` | ||
| 8289 | + /// and `txsize_sqr_map[TX_16X8] == TX_8X8` -- a five-symbol CDF where a | ||
| 8290 | + /// seven-symbol one belonged, desyncing at the FIRST coded rect leaf | ||
| 8291 | + /// (whole frame wrong from pixel (0,0)). | ||
| 8292 | + #[test] | ||
| 8293 | + fn a_real_aomenc_stream_with_a_coded_rect_strip_below_16x16_decodes_pixel_exact() { | ||
| 8294 | + const NAME: &str = | ||
| 8295 | + "a_real_aomenc_stream_with_a_coded_rect_strip_below_16x16_decodes_pixel_exact"; | ||
| 8296 | + let _gate_lock = lock_gate_counters(); | ||
| 8297 | + if !have_ffmpeg() { | ||
| 8298 | + eprintln!("SKIP {NAME}: no ffmpeg"); | ||
| 8299 | + return; | ||
| 8300 | + } | ||
| 8301 | + if !have_aomenc() { | ||
| 8302 | + eprintln!("SKIP {NAME}: no aomenc at {}", aomenc_path().display()); | ||
| 8303 | + return; | ||
| 8304 | + } | ||
| 8305 | + let (width, height) = (64usize, 64usize); | ||
| 8306 | + let y4m = Command::new("ffmpeg") | ||
| 8307 | + .args([ | ||
| 8308 | + "-v", | ||
| 8309 | + "error", | ||
| 8310 | + "-f", | ||
| 8311 | + "lavfi", | ||
| 8312 | + "-i", | ||
| 8313 | + &format!("mandelbrot=size={width}x{height}:start_x=-0.6"), | ||
| 8314 | + "-pix_fmt", | ||
| 8315 | + "yuv420p", | ||
| 8316 | + "-t", | ||
| 8317 | + "1", | ||
| 8318 | + "-vframes", | ||
| 8319 | + "1", | ||
| 8320 | + "-f", | ||
| 8321 | + "yuv4mpegpipe", | ||
| 8322 | + "-", | ||
| 8323 | + ]) | ||
| 8324 | + .stdin(Stdio::null()) | ||
| 8325 | + .stdout(Stdio::piped()) | ||
| 8326 | + .stderr(Stdio::piped()) | ||
| 8327 | + .output() | ||
| 8328 | + .expect("ffmpeg failed to run"); | ||
| 8329 | + assert!(y4m.status.success(), "ffmpeg fixture: {}", String::from_utf8_lossy(&y4m.stderr)); | ||
| 8330 | + let encode = || { | ||
| 8331 | + let mut child = Command::new(aomenc_path()) | ||
| 8332 | + .args([ | ||
| 8333 | + "--codec=av1", | ||
| 8334 | + "--passes=1", | ||
| 8335 | + "--end-usage=q", | ||
| 8336 | + "--cq-level=16", | ||
| 8337 | + "--cpu-used=4", | ||
| 8338 | + "--threads=1", | ||
| 8339 | + "--row-mt=0", | ||
| 8340 | + "--sb-size=64", | ||
| 8341 | + "--kf-max-dist=0", | ||
| 8342 | + "--enable-rect-partitions=1", | ||
| 8343 | + "--enable-ab-partitions=0", | ||
| 8344 | + "--enable-1to4-partitions=0", | ||
| 8345 | + "--enable-tx-size-search=0", | ||
| 8346 | + // Filter intra on a strip is a separate, still-refused | ||
| 8347 | + // predictor (`filter intra on a HORZ/VERT strip`); this | ||
| 8348 | + // gate is about the rect RESIDUAL path, so it is off here | ||
| 8349 | + // and covered by the square filter-intra gate instead. | ||
| 8350 | + "--enable-filter-intra=0", | ||
| 8351 | + "--reduced-tx-type-set=1", | ||
| 8352 | + "--min-partition-size=8", | ||
| 8353 | + "--max-partition-size=32", | ||
| 8354 | + "--obu", | ||
| 8355 | + "-o", | ||
| 8356 | + "-", | ||
| 8357 | + "-", | ||
| 8358 | + ]) | ||
| 8359 | + .stdin(Stdio::piped()) | ||
| 8360 | + .stdout(Stdio::piped()) | ||
| 8361 | + .stderr(Stdio::piped()) | ||
| 8362 | + .spawn() | ||
| 8363 | + .expect("aomenc failed to start"); | ||
| 8364 | + child | ||
| 8365 | + .stdin | ||
| 8366 | + .take() | ||
| 8367 | + .expect("aomenc stdin") | ||
| 8368 | + .write_all(&y4m.stdout) | ||
| 8369 | + .expect("writing y4m to aomenc"); | ||
| 8370 | + let out = child.wait_with_output().expect("aomenc failed to run"); | ||
| 8371 | + assert!( | ||
| 8372 | + out.status.success(), | ||
| 8373 | + "aomenc refused the fixture: {}", | ||
| 8374 | + String::from_utf8_lossy(&out.stderr) | ||
| 8375 | + ); | ||
| 8376 | + out.stdout | ||
| 8377 | + }; | ||
| 8378 | + // The fixture rule: an encoder output is only a pin if it reproduces. | ||
| 8379 | + let stream = encode(); | ||
| 8380 | + assert_eq!(stream, encode(), "{NAME}: aomenc output is not reproducible for this recipe"); | ||
| 8381 | + let before = crate::decode::rect_leaf_coeff_hits(); | ||
| 8382 | + let frames = decode_stream(&stream) | ||
| 8383 | + .unwrap_or_else(|e| panic!("{NAME}: decode failed, not a pixel mismatch: {e}")); | ||
| 8384 | + let fired = crate::decode::rect_leaf_coeff_hits() - before; | ||
| 8385 | + assert!( | ||
| 8386 | + fired > 0, | ||
| 8387 | + "{NAME}: the stream decoded but no coded (non-skip) rect leaf fired -- \ | ||
| 8388 | + the gate proves nothing" | ||
| 8389 | + ); | ||
| 8390 | + let ffmpeg_frames = ffmpeg_decode_sequence(&stream, width, height, frames.len()); | ||
| 8391 | + assert_eq!(frames.len(), 1, "{NAME}: expected one key frame"); | ||
| 8392 | + assert_eq!(ffmpeg_frames.len(), frames.len(), "{NAME}: ffmpeg frame count"); | ||
| 8393 | + for (i, (got, want)) in frames.iter().zip(&ffmpeg_frames).enumerate() { | ||
| 8394 | + assert_eq!(got.y, want.y, "{NAME} frame {i} luma vs ffmpeg ({fired} coded rect leaves)"); | ||
| 8395 | + assert_eq!(got.u, want.u, "{NAME} frame {i} U vs ffmpeg"); | ||
| 8396 | + assert_eq!(got.v, want.v, "{NAME} frame {i} V vs ffmpeg"); | ||
| 8397 | + } | ||
| 8398 | + eprintln!("{NAME}: pixel-exact, rect_leaf_coeff_hits={fired}"); | ||
| 8399 | + } | ||
| 8400 | + | ||
| 8401 | + /// lane-rectx r5: the same 16x8/8x16 rect leaves, but this time proving | ||
| 8402 | + /// what a LATER, non-strip block reads from them. `decode_leaf_rect` took | ||
| 8403 | + /// the mi-exact intra mode map in r4; `decode_block`/`decode_block_rect`/ | ||
| 8404 | + /// `decode_block_rect64` did not, so a 32x16 strip whose left neighbour was | ||
| 8405 | + /// a 16x8 leaf still read the coarse per-16x16 `left_mode` slot -- which no | ||
| 8406 | + /// sub-16x16 block ever writes -- and picked a DIFFERENT `kf_y_mode` CDF row | ||
| 8407 | + /// for the same decoded mode value. The stream stayed in sync through mode | ||
| 8408 | + /// info (`EC_TRACE_MODE_STEP` ranges match up to that symbol) and then | ||
| 8409 | + /// diverged inside the block's own coefficients: the whole bottom-right | ||
| 8410 | + /// 32x32 quadrant of this fixture decoded wrong (1650 bytes) while the | ||
| 8411 | + /// three earlier quadrants were exact -- wrong pixels returned as success. | ||
| 8412 | + /// `mode_mi_override_hits` counts exactly the reads where the mi-exact | ||
| 8413 | + /// neighbour disagrees with the coarse slot, so a regression that drops the | ||
| 8414 | + /// override again fails the counter as well as the pixels. | ||
| 8415 | + #[test] | ||
| 8416 | + fn a_real_aomenc_stream_whose_square_block_reads_a_sub16_neighbours_mode_decodes_pixel_exact() { | ||
| 8417 | + const NAME: &str = | ||
| 8418 | + "a_real_aomenc_stream_whose_square_block_reads_a_sub16_neighbours_mode_decodes_pixel_exact"; | ||
| 8419 | + let _gate_lock = lock_gate_counters(); | ||
| 8420 | + if !have_ffmpeg() { | ||
| 8421 | + eprintln!("SKIP {NAME}: no ffmpeg"); | ||
| 8422 | + return; | ||
| 8423 | + } | ||
| 8424 | + if !have_aomenc() { | ||
| 8425 | + eprintln!("SKIP {NAME}: no aomenc at {}", aomenc_path().display()); | ||
| 8426 | + return; | ||
| 8427 | + } | ||
| 8428 | + let (width, height) = (64usize, 64usize); | ||
| 8429 | + let y4m = Command::new("ffmpeg") | ||
| 8430 | + .args([ | ||
| 8431 | + "-v", "error", "-f", "lavfi", "-i", | ||
| 8432 | + &format!("rgbtestsrc=size={width}x{height}"), | ||
| 8433 | + "-pix_fmt", "yuv420p", "-t", "1", "-vframes", "1", "-f", "yuv4mpegpipe", "-", | ||
| 8434 | + ]) | ||
| 8435 | + .stdin(Stdio::null()) | ||
| 8436 | + .stdout(Stdio::piped()) | ||
| 8437 | + .stderr(Stdio::piped()) | ||
| 8438 | + .output() | ||
| 8439 | + .expect("ffmpeg failed to run"); | ||
| 8440 | + assert!(y4m.status.success(), "ffmpeg fixture: {}", String::from_utf8_lossy(&y4m.stderr)); | ||
| 8441 | + // Two swept cells of the r4 sweep that decoded to completion with | ||
| 8442 | + // WRONG pixels (1714 and 1650 bytes): `--reduced-tx-type-set` and | ||
| 8443 | + // `--enable-filter-intra` are the two axes that move which block sizes | ||
| 8444 | + // aomenc reaches for here; both arms are pinned. | ||
| 8445 | + let mut total_overrides = 0usize; | ||
| 8446 | + for (rtx, filter_intra) in [("1", "0"), ("0", "1")] { | ||
| 8447 | + let encode = || { | ||
| 8448 | + let mut child = Command::new(aomenc_path()) | ||
| 8449 | + .args([ | ||
| 8450 | + "--codec=av1", "--passes=1", "--end-usage=q", "--cq-level=32", | ||
| 8451 | + "--cpu-used=4", "--threads=1", "--row-mt=0", "--sb-size=64", | ||
| 8452 | + "--kf-max-dist=0", "--enable-rect-partitions=1", | ||
| 8453 | + "--enable-ab-partitions=0", "--enable-1to4-partitions=0", | ||
| 8454 | + "--enable-tx-size-search=0", "--enable-cdef=0", | ||
| 8455 | + "--enable-restoration=0", | ||
| 8456 | + &format!("--enable-filter-intra={filter_intra}"), | ||
| 8457 | + &format!("--reduced-tx-type-set={rtx}"), | ||
| 8458 | + "--min-partition-size=8", "--max-partition-size=32", | ||
| 8459 | + "--obu", "-o", "-", "-", | ||
| 8460 | + ]) | ||
| 8461 | + .stdin(Stdio::piped()) | ||
| 8462 | + .stdout(Stdio::piped()) | ||
| 8463 | + .stderr(Stdio::piped()) | ||
| 8464 | + .spawn() | ||
| 8465 | + .expect("aomenc failed to start"); | ||
| 8466 | + child | ||
| 8467 | + .stdin | ||
| 8468 | + .take() | ||
| 8469 | + .expect("aomenc stdin") | ||
| 8470 | + .write_all(&y4m.stdout) | ||
| 8471 | + .expect("writing y4m to aomenc"); | ||
| 8472 | + let out = child.wait_with_output().expect("aomenc failed to run"); | ||
| 8473 | + assert!( | ||
| 8474 | + out.status.success(), | ||
| 8475 | + "aomenc refused the fixture: {}", | ||
| 8476 | + String::from_utf8_lossy(&out.stderr) | ||
| 8477 | + ); | ||
| 8478 | + out.stdout | ||
| 8479 | + }; | ||
| 8480 | + let stream = encode(); | ||
| 8481 | + assert_eq!( | ||
| 8482 | + stream, | ||
| 8483 | + encode(), | ||
| 8484 | + "{NAME}: aomenc output is not reproducible (rtx={rtx} filter_intra={filter_intra})" | ||
| 8485 | + ); | ||
| 8486 | + let before = crate::decode::mode_mi_override_hits(); | ||
| 8487 | + let frames = decode_stream(&stream).unwrap_or_else(|e| { | ||
| 8488 | + panic!("{NAME}: decode failed (rtx={rtx} filter_intra={filter_intra}): {e}") | ||
| 8489 | + }); | ||
| 8490 | + // Counted only on an attempt that actually decoded AND is compared | ||
| 8491 | + // below -- a refusal never contributes to the firing assert. | ||
| 8492 | + let overrides = crate::decode::mode_mi_override_hits() - before; | ||
| 8493 | + let ffmpeg_frames = ffmpeg_decode_sequence(&stream, width, height, frames.len()); | ||
| 8494 | + assert_eq!(frames.len(), 1, "{NAME}: expected one key frame"); | ||
| 8495 | + assert_eq!(ffmpeg_frames.len(), frames.len(), "{NAME}: ffmpeg frame count"); | ||
| 8496 | + for (i, (got, want)) in frames.iter().zip(&ffmpeg_frames).enumerate() { | ||
| 8497 | + assert_eq!( | ||
| 8498 | + got.y, want.y, | ||
| 8499 | + "{NAME} frame {i} luma vs ffmpeg (rtx={rtx} filter_intra={filter_intra}, \ | ||
| 8500 | + {overrides} mi-exact mode overrides)" | ||
| 8501 | + ); | ||
| 8502 | + assert_eq!(got.u, want.u, "{NAME} frame {i} U vs ffmpeg (rtx={rtx})"); | ||
| 8503 | + assert_eq!(got.v, want.v, "{NAME} frame {i} V vs ffmpeg (rtx={rtx})"); | ||
| 8504 | + } | ||
| 8505 | + total_overrides += overrides; | ||
| 8506 | + } | ||
| 8507 | + assert!( | ||
| 8508 | + total_overrides > 0, | ||
| 8509 | + "{NAME}: no non-strip block ever read a mi-exact neighbour that disagreed with its \ | ||
| 8510 | + coarse slot -- the gate proves nothing" | ||
| 8511 | + ); | ||
| 8512 | + eprintln!("{NAME}: pixel-exact, mode_mi_override_hits={total_overrides}"); | ||
| 8513 | + } | ||
| 8514 | + | ||
| 8515 | + #[test] | ||
| 8516 | + #[ignore = "lane-rectx r3 scratch sweep"] | ||
| 8517 | + fn sweep_rectx_recipes() { | ||
| 8518 | + let _gate_lock = lock_gate_counters(); | ||
| 8519 | + let srcs: Vec<String> = vec![ | ||
| 8520 | + "mandelbrot=size=64x64:start_x=0.4".into(), | ||
| 8521 | + "mandelbrot=size=64x64:start_x=-0.6".into(), | ||
| 8522 | + "mandelbrot=size=64x64:start_x=0.1".into(), | ||
| 8523 | + "mandelbrot=size=128x128:start_x=0.4".into(), | ||
| 8524 | + "mandelbrot=size=128x128:start_x=-0.6".into(), | ||
| 8525 | + "testsrc2=size=64x64".into(), | ||
| 8526 | + "testsrc2=size=128x128".into(), | ||
| 8527 | + "rgbtestsrc=size=64x64".into(), | ||
| 8528 | + "smptebars=size=128x128".into(), | ||
| 8529 | + ]; | ||
| 8530 | + for start_x in srcs { | ||
| 8531 | + let y4m = Command::new("ffmpeg") | ||
| 8532 | + .args([ | ||
| 8533 | + "-v", "error", "-f", "lavfi", "-i", | ||
| 8534 | + &start_x, | ||
| 8535 | + "-pix_fmt", "yuv420p", "-t", "1", "-vframes", "1", "-f", "yuv4mpegpipe", "-", | ||
| 8536 | + ]) | ||
| 8537 | + .stdin(Stdio::null()).stdout(Stdio::piped()).stderr(Stdio::piped()) | ||
| 8538 | + .output().expect("ffmpeg"); | ||
| 8539 | + assert!(y4m.status.success()); | ||
| 8540 | + let (width, height) = if start_x.contains("128x128") { (128usize, 128usize) } else { (64usize, 64usize) }; | ||
| 8541 | + for cq in [16u32, 20, 24, 28, 32, 40, 50] { | ||
| 8542 | + for rtx in ["0", "1"] { | ||
| 8543 | + let mut child = Command::new(aomenc_path()) | ||
| 8544 | + .args([ | ||
| 8545 | + "--codec=av1", "--passes=1", "--end-usage=q", | ||
| 8546 | + &format!("--cq-level={cq}"), "--cpu-used=4", "--threads=1", | ||
| 8547 | + "--row-mt=0", "--sb-size=64", "--kf-max-dist=0", | ||
| 8548 | + "--enable-rect-partitions=1", "--enable-ab-partitions=0", | ||
| 8549 | + "--enable-1to4-partitions=0", "--enable-tx-size-search=0", | ||
| 8550 | + "--enable-cdef=0", "--enable-restoration=0", | ||
| 8551 | + &format!("--reduced-tx-type-set={rtx}"), | ||
| 8552 | + "--min-partition-size=8", "--max-partition-size=32", | ||
| 8553 | + "--obu", "-o", "-", "-", | ||
| 8554 | + ]) | ||
| 8555 | + .stdin(Stdio::piped()).stdout(Stdio::piped()).stderr(Stdio::piped()) | ||
| 8556 | + .spawn().expect("aomenc"); | ||
| 8557 | + child.stdin.take().unwrap().write_all(&y4m.stdout).unwrap(); | ||
| 8558 | + let out = child.wait_with_output().unwrap(); | ||
| 8559 | + assert!(out.status.success()); | ||
| 8560 | + let stream = out.stdout; | ||
| 8561 | + let before = crate::decode::rect_leaf_coeff_hits(); | ||
| 8562 | + let res = decode_stream(&stream); | ||
| 8563 | + let fired = crate::decode::rect_leaf_coeff_hits() - before; | ||
| 8564 | + match res { | ||
| 8565 | + Err(e) => eprintln!("x={start_x} cq={cq} rtx={rtx} fired={fired} REFUSED {e}"), | ||
| 8566 | + Ok(frames) => { | ||
| 8567 | + let want = ffmpeg_decode_sequence(&stream, width, height, frames.len()); | ||
| 8568 | + let bad = frames.iter().zip(&want) | ||
| 8569 | + .filter(|(g, w)| g.y != w.y || g.u != w.u || g.v != w.v).count(); | ||
| 8570 | + eprintln!("x={start_x} cq={cq} rtx={rtx} fired={fired} frames={} mismatched={bad}", frames.len()); | ||
| 8571 | + if bad == 0 { continue; } | ||
| 8572 | + let (g, w) = (&frames[0], &want[0]); | ||
| 8573 | + for br in 0..height / 8 { | ||
| 8574 | + let mut line = String::new(); | ||
| 8575 | + for bc in 0..width / 8 { | ||
| 8576 | + let mut n = 0; | ||
| 8577 | + for row in br * 8..br * 8 + 8 { | ||
| 8578 | + for col in bc * 8..bc * 8 + 8 { | ||
| 8579 | + if g.y[row * width + col] != w.y[row * width + col] { | ||
| 8580 | + n += 1; | ||
| 8581 | + } | ||
| 8582 | + } | ||
| 8583 | + } | ||
| 8584 | + line.push_str(&format!("{n:4}")); | ||
| 8585 | + } | ||
| 8586 | + eprintln!(" blk8 row{br}: {line}"); | ||
| 8587 | + } | ||
| 8588 | + } | ||
| 8589 | + } | ||
| 8590 | + } | ||
| 8591 | + } | ||
| 8592 | + } | ||
| 8593 | + } | ||
| 8594 | + | ||
| 8271 | /// lane-rectgate r1: every prior gate pins `--enable-rect-partitions=0 | 8595 | /// lane-rectgate r1: every prior gate pins `--enable-rect-partitions=0 |
| 8272 | /// --enable-ab-partitions=0 --min/max-partition-size=32` so aomenc never | 8596 | /// --enable-ab-partitions=0 --min/max-partition-size=32` so aomenc never |
| 8273 | /// gets to choose a real rect/ab split. This charter's premise ("rect | 8597 | /// gets to choose a real rect/ab split. This charter's premise ("rect |
| @@ -10457,6 +10781,206 @@ mod tests { | |||
| 10457 | ); | 10781 | ); |
| 10458 | } | 10782 | } |
| 10459 | 10783 | ||
| 10784 | + /// lane-sub8 r1: `--min-partition-size=4` on fine-detail noisy gradients | ||
| 10785 | + /// at low cq reliably makes aomenc split an 8x8 block all the way to | ||
| 10786 | + /// four `BLOCK_4X4` leaves (`PARTITION_SPLIT` below 8x8, spec | ||
| 10787 | + /// `decode_partition`'s recursion bottom) -- confirmed with | ||
| 10788 | + /// `EC_AV1_TRACE=1` against `examples/decode_probe` before this gate was | ||
| 10789 | + /// written (`partition_w8 ... value=3` at mi=(0,0) on the very first | ||
| 10790 | + /// block). [`decode::sub8_split_hits`] hard-asserts the path actually | ||
| 10791 | + /// ran rather than every attempt landing on `PARTITION_NONE`. | ||
| 10792 | + #[test] | ||
| 10793 | + fn a_real_aomenc_stream_with_a_sub8_split_decodes_pixel_exact() { | ||
| 10794 | + if !have_ffmpeg() { | ||
| 10795 | + eprintln!("SKIP a_real_aomenc_stream_with_a_sub8_split_decodes_pixel_exact: no ffmpeg"); | ||
| 10796 | + return; | ||
| 10797 | + } | ||
| 10798 | + if !have_aomenc() { | ||
| 10799 | + let msg = format!( | ||
| 10800 | + "no aomenc at {}", | ||
| 10801 | + aomenc_path().display() | ||
| 10802 | + ); | ||
| 10803 | + assert!( | ||
| 10804 | + std::env::var_os("EC_AV1_REQUIRE_AOMENC").is_none(), | ||
| 10805 | + "EC_AV1_REQUIRE_AOMENC is set but {msg}" | ||
| 10806 | + ); | ||
| 10807 | + eprintln!("SKIP a_real_aomenc_stream_with_a_sub8_split_decodes_pixel_exact: {msg}"); | ||
| 10808 | + return; | ||
| 10809 | + } | ||
| 10810 | + // round 2: `--enable-rect-partitions=0` was added below to keep | ||
| 10811 | + // aomenc off HORZ/VERT-below-8x8 elsewhere in the same tile, but it | ||
| 10812 | + // is NOT sufficient alone -- see the round-2 report | ||
| 10813 | + // (lanes/sub8-r1.report.md) for the live finding: 0/160 attempts | ||
| 10814 | + // across both 64x64 and a spatially-isolated single-16x16-leaf | ||
| 10815 | + // fixture passed, and every SPLIT that fires is immediately | ||
| 10816 | + // followed by a spurious HORZ/VERT read on the very next sibling | ||
| 10817 | + // 8x8 leaf, which reads as a real desync left behind by | ||
| 10818 | + // `decode_leaf_split4`/`read_intra_mode_sub8`, not an encoder | ||
| 10819 | + // choice this recipe can dodge. Tried and rejected: shrinking the | ||
| 10820 | + // frame to 16x16 (single 16x16 leaf, at most 4 candidate 8x8s) -- | ||
| 10821 | + // that surfaces an UNRELATED pre-existing tiny-frame edge-straddle | ||
| 10822 | + // defect (reproduces with zero sub8 code involved, `--min-partition | ||
| 10823 | + // -size`/`--max-partition-size` absent entirely), so it is not a | ||
| 10824 | + // safe way to isolate the leaf count. Left red; do not "fix" this | ||
| 10825 | + // gate by picking fixture parameters that dodge the desync without | ||
| 10826 | + // finding it. | ||
| 10827 | + // lane-sub8 r6: three arms. The mi-granular mode maps | ||
| 10828 | + // (`sub8_mode_col`/`uv_mode_col` and their row twins) are per TILE -- | ||
| 10829 | + // the verifier's repro was a 128x64 `--tile-columns=1` stream (seeds | ||
| 10830 | + // 207/228) whose every mismatching luma pixel sat at x>=64, the tile | ||
| 10831 | + // boundary -- so one arm per tile axis is part of this gate. | ||
| 10832 | + for (width, height, tile_args) in [ | ||
| 10833 | + (64usize, 64usize, &[][..]), | ||
| 10834 | + (128usize, 64usize, &["--tile-columns=1"][..]), | ||
| 10835 | + (64usize, 128usize, &["--tile-rows=1"][..]), | ||
| 10836 | + ] { | ||
| 10837 | + let mut refusals = Vec::new(); | ||
| 10838 | + let mut fired_runs = 0u32; | ||
| 10839 | + for attempt in 0..40u32 { | ||
| 10840 | + let seed = 100 + attempt; | ||
| 10841 | + let cq = 6 + (attempt % 4) * 2; | ||
| 10842 | + let y4m = Command::new("ffmpeg") | ||
| 10843 | + .args([ | ||
| 10844 | + "-v", | ||
| 10845 | + "error", | ||
| 10846 | + "-f", | ||
| 10847 | + "lavfi", | ||
| 10848 | + "-i", | ||
| 10849 | + &gradients_source(seed, width, height, "rate=25"), | ||
| 10850 | + "-vf", | ||
| 10851 | + // `noise` without `all_seed` re-renders differently on | ||
| 10852 | + // every run (seeded-fixture-not-reproducible); pinning it | ||
| 10853 | + // makes (seed, cq) name one exact stream. | ||
| 10854 | + &format!("noise=alls=40:allf=t:all_seed={seed},format=yuv420p"), | ||
| 10855 | + "-t", | ||
| 10856 | + "0.04", | ||
| 10857 | + "-f", | ||
| 10858 | + "yuv4mpegpipe", | ||
| 10859 | + "-", | ||
| 10860 | + ]) | ||
| 10861 | + .stdin(Stdio::null()) | ||
| 10862 | + .stdout(Stdio::piped()) | ||
| 10863 | + .stderr(Stdio::piped()) | ||
| 10864 | + .output() | ||
| 10865 | + .expect("ffmpeg failed to run"); | ||
| 10866 | + assert!( | ||
| 10867 | + y4m.status.success(), | ||
| 10868 | + "ffmpeg fixture: {}", | ||
| 10869 | + String::from_utf8_lossy(&y4m.stderr) | ||
| 10870 | + ); | ||
| 10871 | + let mut child = Command::new(aomenc_path()) | ||
| 10872 | + .args([ | ||
| 10873 | + "--codec=av1", | ||
| 10874 | + "--passes=1", | ||
| 10875 | + "--end-usage=q", | ||
| 10876 | + &format!("--cq-level={cq}"), | ||
| 10877 | + "--cpu-used=0", | ||
| 10878 | + "--threads=1", | ||
| 10879 | + "--row-mt=0", | ||
| 10880 | + "--sb-size=64", | ||
| 10881 | + "--min-partition-size=4", | ||
| 10882 | + "--max-partition-size=8", | ||
| 10883 | + // Below 8x8 only PARTITION_NONE/SPLIT are decodable (HORZ/VERT | ||
| 10884 | + // need a real rectangular transform, see the module doc above); | ||
| 10885 | + // disabling rect partitions entirely -- not just AB -- keeps | ||
| 10886 | + // aomenc from picking the still-refused HORZ/VERT arms almost | ||
| 10887 | + // every attempt (round 2 measured ~90% HORZ/VERT-below-8x8 | ||
| 10888 | + // refusals with --enable-ab-partitions=0 alone). | ||
| 10889 | + "--enable-rect-partitions=0", | ||
| 10890 | + "--enable-ab-partitions=0", | ||
| 10891 | + "--enable-1to4-partitions=1", | ||
| 10892 | + "--enable-palette=0", | ||
| 10893 | + "--enable-intrabc=0", | ||
| 10894 | + "--enable-restoration=0", | ||
| 10895 | + "--enable-cdef=0", | ||
| 10896 | + "--loopfilter-control=0", | ||
| 10897 | + // use_ref_frame_mvs (temporal MV projection) is unimplemented in | ||
| 10898 | + // mvstack; this is a key-frame-only fixture, but keep it off for | ||
| 10899 | + // safety against a run that emits a second frame. | ||
| 10900 | + "--enable-ref-frame-mvs=0", | ||
| 10901 | + "--limit=1", | ||
| 10902 | + "--obu", | ||
| 10903 | + "-o", | ||
| 10904 | + "-", | ||
| 10905 | + "-", | ||
| 10906 | + ]) | ||
| 10907 | + .args(tile_args) | ||
| 10908 | + .stdin(Stdio::piped()) | ||
| 10909 | + .stdout(Stdio::piped()) | ||
| 10910 | + .stderr(Stdio::piped()) | ||
| 10911 | + .spawn() | ||
| 10912 | + .expect("aomenc failed to start"); | ||
| 10913 | + child | ||
| 10914 | + .stdin | ||
| 10915 | + .take() | ||
| 10916 | + .expect("aomenc stdin") | ||
| 10917 | + .write_all(&y4m.stdout) | ||
| 10918 | + .expect("writing y4m to aomenc"); | ||
| 10919 | + let out = child.wait_with_output().expect("aomenc failed to run"); | ||
| 10920 | + if !out.status.success() { | ||
| 10921 | + refusals.push(format!( | ||
| 10922 | + "seed={seed} cq={cq}: aomenc itself refused the fixture" | ||
| 10923 | + )); | ||
| 10924 | + continue; | ||
| 10925 | + } | ||
| 10926 | + let stream = out.stdout; | ||
| 10927 | + let before = decode::sub8_split_hits(); | ||
| 10928 | + let tiles_before = decode::tile_hits(); | ||
| 10929 | + let frames = match decode_stream(&stream) { | ||
| 10930 | + Ok(frames) => frames, | ||
| 10931 | + Err(e) => { | ||
| 10932 | + // Only a named refusal ("unsupported: ...") is a skip | ||
| 10933 | + // reason; any other decode error is this decoder failing. | ||
| 10934 | + let msg = e.to_string(); | ||
| 10935 | + assert!( | ||
| 10936 | + msg.starts_with("unsupported: "), | ||
| 10937 | + "decode error that is not a named refusal \ | ||
| 10938 | + (seed={seed} cq={cq} tiles={tile_args:?}): {msg}" | ||
| 10939 | + ); | ||
| 10940 | + refusals.push(format!("seed={seed} cq={cq}: {msg}")); | ||
| 10941 | + continue; | ||
| 10942 | + } | ||
| 10943 | + }; | ||
| 10944 | + // gate-blind-to-feature: a tile arm must actually decode more | ||
| 10945 | + // than one tile, not merely carry `tile_info.cols > 1`. | ||
| 10946 | + assert!( | ||
| 10947 | + tile_args.is_empty() || decode::tile_hits() - tiles_before >= 2, | ||
| 10948 | + "tiles={tile_args:?} decoded only {} tile(s) (seed={seed} cq={cq})", | ||
| 10949 | + decode::tile_hits() - tiles_before | ||
| 10950 | + ); | ||
| 10951 | + if decode::sub8_split_hits() == before { | ||
| 10952 | + refusals.push(format!( | ||
| 10953 | + "seed={seed} cq={cq}: decoded, but no block read a real PARTITION_SPLIT below 8x8" | ||
| 10954 | + )); | ||
| 10955 | + continue; | ||
| 10956 | + } | ||
| 10957 | + let ffmpeg_frames = ffmpeg_decode_sequence(&stream, width, height, 1); | ||
| 10958 | + assert_eq!( | ||
| 10959 | + frames[0].y, ffmpeg_frames[0].y, | ||
| 10960 | + "luma vs ffmpeg (seed={seed} cq={cq})" | ||
| 10961 | + ); | ||
| 10962 | + assert_eq!( | ||
| 10963 | + frames[0].u, ffmpeg_frames[0].u, | ||
| 10964 | + "U vs ffmpeg (seed={seed} cq={cq})" | ||
| 10965 | + ); | ||
| 10966 | + assert_eq!( | ||
| 10967 | + frames[0].v, ffmpeg_frames[0].v, | ||
| 10968 | + "V vs ffmpeg (seed={seed} cq={cq})" | ||
| 10969 | + ); | ||
| 10970 | + fired_runs += 1; | ||
| 10971 | + if fired_runs >= 4 { | ||
| 10972 | + break; | ||
| 10973 | + } | ||
| 10974 | + } | ||
| 10975 | + assert!( | ||
| 10976 | + fired_runs >= 4, | ||
| 10977 | + "fewer than 4 firing+pixel-exact runs out of 40 attempts \ | ||
| 10978 | + ({width}x{height} tiles={tile_args:?}):\n{}", | ||
| 10979 | + refusals.join("\n") | ||
| 10980 | + ); | ||
| 10981 | + } | ||
| 10982 | + } | ||
| 10983 | + | ||
| 10460 | /// lane-av1golden7 r9's decisive fixture: a real aomenc stream (seed 59, | 10984 | /// lane-av1golden7 r9's decisive fixture: a real aomenc stream (seed 59, |
| 10461 | /// `--tune-content=film`, GOLDEN_FRAME firing downstream) whose frame-0 | 10985 | /// `--tune-content=film`, GOLDEN_FRAME firing downstream) whose frame-0 |
| 10462 | /// *intra keyframe* mismatched ffmpeg on 3855/4096 luma pixels -- traced | 10986 | /// *intra keyframe* mismatched ffmpeg on 3855/4096 luma pixels -- traced |
lanes/rectx-r3.handoff.mdadded+54 -0
| @@ -0,0 +1,54 @@ | |||
| 1 | +# lane-rectx r3 handoff — one defect fixed, one precisely located | ||
| 2 | + | ||
| 3 | +TOTALS `EC_AV1_REQUIRE_AOMENC=1 cargo test -p ec-av1 --lib` (CARGO_TARGET_DIR=~/.cache/cargo-target-rectx): | ||
| 4 | +**269 passed, 1 failed, 24 ignored** (1042s). The single failure is this lane's own gate, | ||
| 5 | +`stream::tests::a_real_aomenc_stream_with_a_coded_rect_strip_below_16x16_decodes_pixel_exact`; | ||
| 6 | +it now stops on an unrelated third blocker ("a 32x32 partition type this decoder does not code | ||
| 7 | +(value=7)" = PARTITION_VERT_B at 32x32) with the recipe as written. No other test regressed | ||
| 8 | +(268 -> 269 passed is this round's new pin). | ||
| 9 | + | ||
| 10 | +## Do next, in this order | ||
| 11 | + | ||
| 12 | +1. **Per-mi y-mode neighbour grid.** `Neighbours::above_mode` (decode.rs:1806) / `left_mode` | ||
| 13 | + are per-16x16 cell; libaom reads `above_mi`/`left_mi` off the real mi grid. Reproduce in | ||
| 14 | + one command: | ||
| 15 | + - stream: `ffmpeg -v error -f lavfi -i rgbtestsrc=size=64x64 -pix_fmt yuv420p -t 1 -vframes 1 | ||
| 16 | + -f yuv4mpegpipe g.y4m` then `aomenc --codec=av1 --passes=1 --end-usage=q --cq-level=50 | ||
| 17 | + --cpu-used=4 --threads=1 --row-mt=0 --sb-size=64 --kf-max-dist=0 --enable-rect-partitions=1 | ||
| 18 | + --enable-ab-partitions=0 --enable-1to4-partitions=0 --enable-tx-size-search=0 | ||
| 19 | + --enable-cdef=0 --enable-restoration=0 --reduced-tx-type-set=1 --min-partition-size=8 | ||
| 20 | + --max-partition-size=32 --obu -o t.obu g.y4m` | ||
| 21 | + - ours: `EC_TRACE_COEFF=1 EC_AV1_RECTX_TRACE=1 EC_TRACE_MODE_STEP=1 | ||
| 22 | + target/debug/examples/decode_probe t.obu` | ||
| 23 | + - oracle: `EC_TRACE_COEFF=1 EC_TRACE_MODE=1 ~/.cache/aom-oracle/build/aomdec --rawvideo | ||
| 24 | + -o /dev/null t.obu` | ||
| 25 | + - THE ELEMENT: leaf `mi=(4,12)`, bw=16 bh=8, outer_at=(1,3). Both enter at range **59792**. | ||
| 26 | + Oracle `EC_IMODE_VAL mode=2 uv_mode=2 skip=0 -> rng=49036`; ours `mode=0 uv_mode=13 -> | ||
| 27 | + rng=47236`. First 15 transform blocks of the frame are bit-exact before it. | ||
| 28 | + - Fix shape: a per-mi mode grid written wherever `fill_skip_grid`/`fill_skip_grid_rect` | ||
| 29 | + (13 sites) is written, read by `read_intra_mode*`'s `above_ctx`/`left_ctx`. | ||
| 30 | +2. **Then re-pick the gate recipe.** `stream::tests::sweep_rectx_recipes` (`#[ignore]`, | ||
| 31 | + `--nocapture`) sweeps 9 lavfi sources x 7 cq x reduced-tx-type-set 0/1 and prints | ||
| 32 | + `fired=`/refusal/`mismatched=` per cell plus an 8x8 mismatch map. After the filter_intra fix | ||
| 33 | + exactly one cell decodes to completion (rgbtestsrc cq=50 rtx=1, fired=4) and it mismatches | ||
| 34 | + on defect (1). Every other cell refuses; the dominant refusal is | ||
| 35 | + "a HORZ_A/HORZ_B/VERT_A partition below 16x16" — this aomenc build writes AB partitions | ||
| 36 | + below 16x16 even with `--enable-ab-partitions=0` (126/126 cells swept; same quirk the ledger | ||
| 37 | + records at SB level). Wiring HORZ_A/HORZ_B/VERT_A below 16x16 may be the cheaper route to a | ||
| 38 | + green gate than recipe hunting. | ||
| 39 | +3. Only then lift "a coded (non-skip) HORZ/VERT rect strip below 16x16" and "a non-skip | ||
| 40 | + rectangular (HORZ/VERT/HORZ_B) strip needs rectangular residual coding" in | ||
| 41 | + `refusal_inventory.rs` + `gate_coverage.rs`. NOT lifted this round. | ||
| 42 | + | ||
| 43 | +## Do NOT re-do | ||
| 44 | + | ||
| 45 | +- The r2 coefficient path (scans, `EOB_PT_128_LUMA`/`EOB_PT_32_CHROMA`, txb sets, nz-map/br | ||
| 46 | + ctx, DC-sign ctx) is range-exact against aomdec for a real non-skip TX_16X8 leaf + both | ||
| 47 | + TX_8X4 chroma halves. Don't re-derive it. | ||
| 48 | +- `base_ctx_rect`'s 11/16 rect nz-map offsets are CORRECT as written (display-orientation | ||
| 49 | + convention: our (row,col) are display row/col, libaom's flat `av1_nz_map_ctx_offset` tables | ||
| 50 | + are column-major so their INDEX packing, not their rule, is what differs). Swapping the two | ||
| 51 | + constants was tried this round: the 126-cell sweep went from 2 full decodes to 0 (every cell | ||
| 52 | + refused). Dead end. | ||
| 53 | +- `SCAN_8X4`/`SCAN_4X8` were re-checked verbatim against | ||
| 54 | + `~/.cache/aom-oracle/src/av1/common/scan.c` this round. They are right. | ||
lanes/rectx-r3.report.mdadded+88 -0
| @@ -0,0 +1,88 @@ | |||
| 1 | +# lane-rectx r3 — the rect leaf was bit-exact; the block AFTER it was not | ||
| 2 | + | ||
| 3 | +Branch `lane-rectx`, on top of `main` 3808cf8 (`git merge-base --is-ancestor main HEAD` = OK, | ||
| 4 | +no rebase needed). Prior state: r1/r2 landed non-skip TX_16X8/TX_8X16 rect-leaf coefficient | ||
| 5 | +decode (`decode_leaf_rect`'s lane-rectx arm, `read_coeffs_rect`, `TxbSet::LumaRect16x8{,Set1}` | ||
| 6 | +/`ChromaRect8x4`, `EOB_PT_128_LUMA`/`EOB_PT_32_CHROMA`, `SCAN_8X4`/`SCAN_4X8`) UNPROVEN, with | ||
| 7 | +the lane's own gate red. | ||
| 8 | + | ||
| 9 | +## What this round proved | ||
| 10 | + | ||
| 11 | +1. **The r2 coefficient path is right.** Against the instrumented oracle | ||
| 12 | + (`~/.cache/aom-oracle/build/aomdec`, `EC_TRACE_COEFF=1`) on a real aomenc stream, a | ||
| 13 | + non-skip `TX_16X8` luma leaf plus both its `TX_8X4` chroma halves decode with an | ||
| 14 | + IDENTICAL msac range at every element (`all_zero` 37445, `tx_type` 55512, `eob`=1 41024, | ||
| 15 | + `base_eob` pos 0 level 1 64544, DC sign 37072, chroma `all_zero`=1 40760 / 47390). | ||
| 16 | + Scans, eob CDF alphabet, txb sets, nz-map/br contexts and the DC-sign context at this size | ||
| 17 | + are all confirmed by that ladder, not by argument. | ||
| 18 | +2. **`SCAN_8X4`/`SCAN_4X8` re-checked against the real `scan.c`** (not a memory of it): | ||
| 19 | + `~/.cache/aom-oracle/src/av1/common/scan.c` `default_scan_4x8` == our `SCAN_8X4` and | ||
| 20 | + `default_scan_8x4` == our `SCAN_4X8`, verbatim, which is what | ||
| 21 | + `decode.rs::tests::the_rect_scan_tables_match_libaom...` already pins (asymmetric pair, a | ||
| 22 | + swap fails it). | ||
| 23 | +3. **Root cause of the desync (FIXED): the `use_filter_intra` flag was never read at | ||
| 24 | + 16x8/8x16.** `av1_filter_intra_allowed_bsize` is "both sides <= 32", so libaom reads the | ||
| 25 | + flag for every DC_PRED 16x8/8x16 block; `filter_intra_size_class_rect` returned `None` | ||
| 26 | + there, so we dropped one symbol per DC_PRED strip and desynced the tile from that block on | ||
| 27 | + — silently, with a full-frame pixel mismatch and no error. Ladder evidence: leaf mi=(2,4), | ||
| 28 | + we and the oracle both decode `mode=0 uv_mode=9 skip=0`, but our post-mode range is 34808 | ||
| 29 | + where the oracle's is 40668 (value-equal narrowing drift). After the fix our range at that | ||
| 30 | + point is 40668 and the next transform block's `all_zero` reads 40269 — bit-identical to the | ||
| 31 | + oracle. | ||
| 32 | + | ||
| 33 | +## Files changed | ||
| 34 | + | ||
| 35 | +- `crates/ec-av1/src/cdf.rs:415` — `FILTER_INTRA` 6 -> 8 rows, adding `default_filter_intra_cdfs` | ||
| 36 | + index 5 (BLOCK_16X8, 9394) and 4 (BLOCK_8X16, 12551). | ||
| 37 | +- `crates/ec-av1/src/cdf_state.rs:467` — the field's type/doc follow. | ||
| 38 | +- `crates/ec-av1/src/decode.rs` `filter_intra_size_class_rect` — `(16,8) => Some(6)`, | ||
| 39 | + `(8,16) => Some(7)`; the actual fix. | ||
| 40 | +- `crates/ec-av1/src/decode.rs` `read_coeffs_rect` — three env-gated trace prints | ||
| 41 | + (`tag=all_zero_rect` with the pre-symbol range, `tag=sign_rect`) under the existing | ||
| 42 | + `EC_TRACE_COEFF`, plus the entry range on the `EC_AV1_RECTX_TRACE` line; these are what made | ||
| 43 | + the cross-decoder bisection possible and are kept for the successor. | ||
| 44 | +- `crates/ec-av1/src/decode.rs` tests — new | ||
| 45 | + `a_rect_strip_below_16x16_reads_its_own_filter_intra_cdf_row`. | ||
| 46 | +- `crates/ec-av1/src/stream.rs` `sweep_rectx_recipes` (scratch, `#[ignore]`) — also sweeps | ||
| 47 | + `--reduced-tx-type-set=1`, and only dumps the 8x8 mismatch map when there IS a mismatch. | ||
| 48 | + | ||
| 49 | +## Checks | ||
| 50 | + | ||
| 51 | +- `cargo test -p ec-av1 --lib -- filter_intra scan_` -> 8 passed, 0 failed (includes the new pin | ||
| 52 | + and the existing `a_real_aomenc_filter_intra_stream_decodes_pixel_exact`). | ||
| 53 | +- `EC_AV1_REQUIRE_AOMENC=1 cargo test -p ec-av1 --lib` -> see TOTALS below. | ||
| 54 | +- EVIDENCE: /tmp/claude-1000/.../scratchpad/{s.obu,aom.log,ours.log} | ffmpeg mandelbrot 64x64 | ||
| 55 | + start_x=-0.6 -> aomenc cq16 --enable-rect-partitions=1 --min-partition-size=8 | ||
| 56 | + --max-partition-size=32; instrumented aomdec `EC_TRACE_COEFF=1` vs | ||
| 57 | + `examples/decode_probe` `EC_TRACE_COEFF=1` | first divergence moved from the transform block | ||
| 58 | + after leaf mi=(2,4) (ours 34467 vs oracle 40269) to none at that point (both 40269) after the | ||
| 59 | + fix. | ||
| 60 | + | ||
| 61 | +## Open residue | ||
| 62 | + | ||
| 63 | +- **fix-now (next round, out of this round's tool budget): the rect leaf's `kf_y_mode` | ||
| 64 | + context is read from the coarse 16x16 neighbour grid.** Second, independent defect, found | ||
| 65 | + by the same ladder on `rgbtestsrc=size=64x64` cq=50 `--reduced-tx-type-set=1`: at leaf | ||
| 66 | + mi=(4,12) (`decode_leaf_rect`, bw=16 bh=8, outer_at=(1,3)) we and the oracle ENTER the block | ||
| 67 | + at the same range 59792, and then we decode `mode=0` where the oracle decodes `mode=2` | ||
| 68 | + (H_PRED) — a wrong CDF row, not a wrong value. `Neighbours::above_mode`/`left_mode` | ||
| 69 | + (decode.rs:1806) are per-16x16-cell; libaom takes `above_mi`/`left_mi` from the real mi grid, | ||
| 70 | + so when the cell above was split into 8x8 leaves our slot holds the last-written leaf's mode | ||
| 71 | + (bottom-RIGHT) instead of the true above neighbour (bottom-LEFT at mi col 12). Known class: | ||
| 72 | + "context read from one cell". The fix is a per-mi mode grid alongside the existing per-mi | ||
| 73 | + `skip_grid`/`lf_grid` — 13 `fill_skip_grid*` call sites would gain a mode write. It affects | ||
| 74 | + every intra path, not just rect leaves. | ||
| 75 | +- **deferred(the mode-grid fix above): the lane gate | ||
| 76 | + `a_real_aomenc_stream_with_a_coded_rect_strip_below_16x16_decodes_pixel_exact` is still RED**, | ||
| 77 | + and its two refusals are NOT lifted. Its current recipe fails on a third, unrelated blocker | ||
| 78 | + ("a HORZ_A/HORZ_B/VERT_A partition below 16x16"): a 126-cell sweep (9 lavfi sources x 7 | ||
| 79 | + cq x reduced-tx-type-set 0/1, `sweep_rectx_recipes`) found aomenc writes AB partitions below | ||
| 80 | + 16x16 despite `--enable-ab-partitions=0` in most cells — same aomenc quirk the ledger already | ||
| 81 | + records one level up. After the filter_intra fix the sweep has exactly ONE cell that decodes | ||
| 82 | + to completion (rgbtestsrc cq=50 rtx=1, 4 rect leaves fired) and it mismatches on the mode-ctx | ||
| 83 | + defect above. So there is currently no recipe that can turn the gate green; a green gate | ||
| 84 | + needs the mode-grid fix first. | ||
| 85 | +- accepted: `read_coeffs_rect` still refuses `V_DCT`/`H_DCT` ("a non-2D tx class on a | ||
| 86 | + rectangular transform"), which is why the gate recipe pins `--reduced-tx-type-set=1`. | ||
| 87 | + | ||
| 88 | +TOTALS: see lanes/rectx-r3.handoff.md. | ||
lanes/rectx-r4.report.mdadded+89 -0
| @@ -0,0 +1,89 @@ | |||
| 1 | +# lane-rectx r4 — the gate is GREEN: two defects, one cherry-picked, one found here | ||
| 2 | + | ||
| 3 | +Branch `lane-rectx`, commits on top of `main` 3808cf8. Round 3 left the lane's own gate red | ||
| 4 | +with the mode-neighbour defect precisely located; this round fixed it and one more. | ||
| 5 | + | ||
| 6 | +## What changed | ||
| 7 | + | ||
| 8 | +1. **Cherry-picked lane-sub8 `1841406`** (mi-exact intra mode neighbours + `has_tr_4x4`/ | ||
| 9 | + `has_bl_4x4`): `Neighbours::sub8_mode_col/row`, `record_mode_mi`, `mode_above_mi`/ | ||
| 10 | + `mode_left_mi` (`crates/ec-av1/src/decode.rs` ~1830, ~2533-2570), written by `record_rect` | ||
| 11 | + and `record_split_luma`/`decode_leaf8`, plus `crates/ec-av1/src/encode.rs`'s reach rows. | ||
| 12 | + The commit's `decode_leaf_split4`/`read_intra_mode_sub8` hunks were dropped — those | ||
| 13 | + functions exist only on lane-sub8. | ||
| 14 | +2. **`decode_leaf_rect` joins that map** (`decode.rs` ~3644 read, ~3786 write): it now reads | ||
| 15 | + `mode_above_mi`/`mode_left_mi` after the `prev_leaf` override and records its own | ||
| 16 | + `mi_w x mi_h` span, not one cell. This is r3's located defect (leaf mi=(4,12) read | ||
| 17 | + `kf_y_mode` from the coarse 16x16 slot, decoding `mode=0` where the oracle decodes | ||
| 18 | + `mode=2`). | ||
| 19 | +3. **ROOT CAUSE FOUND THIS ROUND — the rect reach tables were the wrong block size.** | ||
| 20 | + `Reach::of_rect` (`encode.rs` ~1096) indexed `HAS_TOP_RIGHT_RECT`/`HAS_BOTTOM_LEFT_RECT` | ||
| 21 | + by `bw == 16`; both arrays only ever held the 32x16/16x32 rows (lane-intradisp's sizes). | ||
| 22 | + A 16x8 block read `has_tr_16x32`/`has_bl_16x32` (4 bytes) where libaom reads | ||
| 23 | + `has_tr_16x8`/`has_bl_16x8` (16 bytes), an 8x16 read the 32x16 rows, and the index | ||
| 24 | + arithmetic (`table_stride = 128/side`, `% (len*8)`) was not libaom's either. | ||
| 25 | + `top_right_rect`/`bottom_left_rect` are now libaom `has_top_right`/`has_bottom_left` | ||
| 26 | + verbatim at block granularity (`row_off`/`col_off` 0, luma), with `has_tr_rect_table`/ | ||
| 27 | + `has_bl_rect_table` carrying 16x8, 8x16, 32x16, 16x32, 64x32 and 32x64 transcribed from | ||
| 28 | + `~/.cache/aom-oracle/src/av1/common/reconintra.c`. (`has_tr_vert_tables`/`has_bl_vert_tables` | ||
| 29 | + hold the SAME pointers for every W<H entry and NULL for W>H, so the partition type selects | ||
| 30 | + no different table at these sizes.) | ||
| 31 | +4. Gate recipe (`stream.rs` ~5366): mandelbrot `start_x=-0.6`, `--cq-level=16`, and | ||
| 32 | + `--enable-filter-intra=0` added (filter intra ON a strip is a separate, still-refused | ||
| 33 | + predictor). | ||
| 34 | +5. `examples/decode_probe.rs`: lane-sub8's optional second arg dumping raw yuv420p, which is | ||
| 35 | + what made the ffmpeg pixel diff a one-liner outside the test harness. | ||
| 36 | + | ||
| 37 | +## Evidence | ||
| 38 | + | ||
| 39 | +EVIDENCE: /tmp/claude-1000/.../scratchpad/{x.obu,pre_a.yuv.f0,pre_o.yuv.f0} | ffmpeg lavfi | ||
| 40 | +rgbtestsrc 64x64 -> aomenc cq50 --enable-rect-partitions=1 --enable-ab-partitions=0 | ||
| 41 | +--enable-filter-intra=0 --reduced-tx-type-set=1 --min-partition-size=8 --max-partition-size=32; | ||
| 42 | +`EC_AV1_PREFILT_DUMP` on instrumented aomdec vs `examples/decode_probe` | pre-loop-filter luma | ||
| 43 | +diffs 1440 -> 0, final vs `ffmpeg -f rawvideo` 1567 -> 0 bytes. The 1440 luma diffs were a | ||
| 44 | +D203 (`mode=7`) 16x8 strip at mi=(4,8): exact for the first rows, first mismatch at pixel | ||
| 45 | +(44,18) with a diagonal wavefront — the signature of a ray that has started reading BELOW the | ||
| 46 | +block's own height, i.e. wrong bottom-left availability. | ||
| 47 | + | ||
| 48 | +EVIDENCE: gate `a_real_aomenc_stream_with_a_coded_rect_strip_below_16x16_decodes_pixel_exact` | | ||
| 49 | +`EC_AV1_REQUIRE_AOMENC=1 cargo test -p ec-av1 --lib -- a_real_aomenc_stream_with_a_coded_rect_strip_below_16x16 --nocapture` | | ||
| 50 | +`pixel-exact, rect_leaf_coeff_hits=8`; the stream's own symbol trace shows 6 non-skip TX_16X8 | ||
| 51 | +luma leaves + 1 non-skip TX_8X16 (both orientations), 9 non-skip TX_8X4 and 3 non-skip TX_4X8 | ||
| 52 | +chroma halves. | ||
| 53 | + | ||
| 54 | +## Refusals | ||
| 55 | + | ||
| 56 | +- `a coded (non-skip) HORZ/VERT rect strip below 16x16` — the string was already removed from | ||
| 57 | + `decode.rs` in r2 (never in `refusal_inventory::REFUSALS`); this round is what finally PROVES | ||
| 58 | + it, with the gate above. Nothing to delete, the inventory test stays green. | ||
| 59 | +- `a non-skip rectangular (HORZ/VERT/HORZ_B) strip needs rectangular residual coding` | ||
| 60 | + (`decode.rs:9138`) — **NOT lifted.** It sits in the INTER square-block path | ||
| 61 | + (`reject_residual`, lane-warp r5), which this key-frame gate never reaches. Lifting it needs | ||
| 62 | + an inter gate. | ||
| 63 | +- `a coded (non-skip) HORZ_B/VERT_B rect strip below 16x16` — **NOT lifted**, HORZ_B/VERT_B | ||
| 64 | + never fired in the gate stream. | ||
| 65 | + | ||
| 66 | +## Open residue | ||
| 67 | + | ||
| 68 | +- accepted: `read_coeffs_rect` still refuses `V_DCT`/`H_DCT` (`a non-2D tx class on a | ||
| 69 | + rectangular transform`), hence `--reduced-tx-type-set=1` in the gate. | ||
| 70 | +- deferred(a lane for AB partitions below 16x16): the dominant refusal across the recipe sweep | ||
| 71 | + is still `a HORZ_A/HORZ_B/VERT_A partition below 16x16`. NOTE: unlike r3's premise, this | ||
| 72 | + survives the mode-grid fix, so at THIS size it is not (only) our own desync — 8 of 24 swept | ||
| 73 | + cells still refuse on it after both fixes. | ||
| 74 | +- fix-now(next round): two swept cells decode to completion but are NOT pixel-exact | ||
| 75 | + (rgbtestsrc cq24 3540 bytes, cq32 1714; mandelbrot start_x=-0.6 cq16 with | ||
| 76 | + `--enable-filter-intra=1` 126). Same ladder applies; the gate's own cell is exact. | ||
| 77 | + | ||
| 78 | +## Totals | ||
| 79 | + | ||
| 80 | +`EC_AV1_REQUIRE_AOMENC=1 cargo test -p ec-av1 --lib` (CARGO_TARGET_DIR=~/.cache/cargo-target-rectx): | ||
| 81 | +**270 passed, 0 failed, 24 ignored** (738.88s) — r3's single failure (this lane's own gate) is | ||
| 82 | +gone and nothing regressed (269 -> 270 passed is exactly this gate). | ||
| 83 | + | ||
| 84 | +That full run was built BEFORE the last hunk (the explicit 64x32/32x64 rows in | ||
| 85 | +`has_tr_rect_table`/`has_bl_rect_table`, which previously fell through to the 16x32 row). | ||
| 86 | +On the final build the four gates that can see those sizes were re-run: | ||
| 87 | +`a_real_aomenc_stream_with_a_superblock_level_horz_vert_partition_decodes_pixel_exact`, | ||
| 88 | +`..._with_mandelbrot_fires_the_vert_b_partition_arm`, `..._with_directional_chroma_...` and | ||
| 89 | +this lane's own gate — 4 passed, 0 failed, 1 ignored (21.26s). | ||
lanes/rectx-r5.report.mdadded+116 -0
| @@ -0,0 +1,116 @@ | |||
| 1 | +# lane-rectx r5 -- three "decodes fine, wrong pixels" cells: one root cause, luma now exact in all three | ||
| 2 | + | ||
| 3 | +Branch `lane-rectx`, on top of r4's `fad4d5a`. r4 left three swept cells decoding to | ||
| 4 | +completion with WRONG pixels (the worst class). All three had the SAME root cause; after the | ||
| 5 | +fix two are byte-exact and all three are LUMA-exact, with a chroma-only residue below. | ||
| 6 | + | ||
| 7 | +## Root cause (found this round) | ||
| 8 | + | ||
| 9 | +`decode_leaf_rect` took the mi-exact intra-mode neighbour map in r4 (`mode_above_mi` / | ||
| 10 | +`mode_left_mi`). The three OTHER `kf_y_mode` readers did not: | ||
| 11 | +`decode_block` (square, `decode.rs` ~4960), `decode_block_rect` (32x16/16x32, ~3274) and | ||
| 12 | +`decode_block_rect64` (64x32/32x64, ~3850) each read the COARSE per-16x16 `above_mode[c]` / | ||
| 13 | +`left_mode[r]` slots -- which no sub-16x16 block ever writes (`record_rect` loops | ||
| 14 | +`w / SUB` = 0 cells for a 16x8). So a 32x16 strip whose left neighbour was a 16x8 rect leaf | ||
| 15 | +read an older, larger block's mode, indexed a DIFFERENT `kf_y_mode` CDF row, decoded the same | ||
| 16 | +mode VALUE off a different distribution, and desynced from that block's first coefficient on. | ||
| 17 | +This is the memory class "context read from one cell" / "CDF row held constant", one level up | ||
| 18 | +from r4's own instance. | ||
| 19 | + | ||
| 20 | +Fix (`decode.rs`): one `Neighbours::modes_above_left(r, c)` helper (mi-exact if the map holds | ||
| 21 | +exactly this block's above/left mi, else the coarse slot) used by all three readers, for the | ||
| 22 | +mode CDF row AND for `smooth_neighbor` (libaom's `get_filt_type` reads the same `above_mi`/ | ||
| 23 | +`left_mi`). New `MODE_MI_OVERRIDE_HITS` counter (`decode.rs` ~760) counts the reads where the | ||
| 24 | +two disagree. | ||
| 25 | + | ||
| 26 | +Also applied here, per the coordinator's mid-round correction (defect found by lane-sub8's | ||
| 27 | +verifier in the code r4 cherry-picked from that lane): `mode_above_mi`/`mode_left_mi` guarded | ||
| 28 | +availability with `mi_r > 0`/`mi_c > 0` instead of the tile-relative | ||
| 29 | +`mi_r > tile_row0_mi`/`mi_c > tile_col0_mi`, and the maps were never reset -- `start_tile` now | ||
| 30 | +clears `sub8_mode_col` over the tile's mi columns and `start_row` clears `sub8_mode_row`, | ||
| 31 | +exactly like every other neighbour array beside them. (This lane's sweep is single-tile, so | ||
| 32 | +that half is code-verified here, not gate-proven; lane-sub8 r6 owns the multi-tile gate.) | ||
| 33 | + | ||
| 34 | +## Evidence | ||
| 35 | + | ||
| 36 | +EVIDENCE: /tmp/.../scratchpad/rx/{rgb240.obu,pre_a.f0,pre_o.f0,o.step.txt,a.step.txt} | | ||
| 37 | +ffmpeg lavfi `rgbtestsrc=size=64x64` -> aomenc `--cq-level=24 --reduced-tx-type-set=0 | ||
| 38 | +--enable-rect-partitions=1 --min-partition-size=8 --max-partition-size=32 | ||
| 39 | +--enable-filter-intra=0 --enable-cdef=0 --enable-restoration=0` (sha256 | ||
| 40 | +22113636b7ab950b5d1a175a60b9e01251dcead819f99a9ef14dcd1378ccfad6, reproducible across two | ||
| 41 | +encodes); `EC_TRACE_MODE_STEP` ladder ours vs instrumented aomdec, `EC_AV1_PREFILT_DUMP` both | | ||
| 42 | +first divergent element = `mi_row=8 mi_col=8 name=mode val=2` at range 53452 (oracle) vs 33402 | ||
| 43 | +(ours) -- same value, different CDF row, entry ranges equal (56121) so it is the ROW not the | ||
| 44 | +symbol; that block's left neighbour is the 16x8 leaf at mi(8,4) mode=12. Pre-filter luma diff | ||
| 45 | +1006 -> 0, total 1650 -> 12 bytes (all chroma). | ||
| 46 | + | ||
| 47 | +EVIDENCE: gate `a_real_aomenc_stream_whose_square_block_reads_a_sub16_neighbours_mode_decodes_pixel_exact` | ||
| 48 | +(`stream.rs` ~5460) | `EC_AV1_REQUIRE_AOMENC=1 cargo test -p ec-av1 --lib -- a_real_aomenc_stream_whose_square_block_reads_a_sub16 --nocapture` | | ||
| 49 | +`pixel-exact, mode_mi_override_hits=2`, two pinned arms (`rgbtestsrc` 64x64 cq32 with | ||
| 50 | +`--reduced-tx-type-set=1 --enable-filter-intra=0` and with `=0 --enable-filter-intra=1`), each | ||
| 51 | +encoded twice and byte-compared before decode; the counter is read only on an attempt that | ||
| 52 | +decoded AND is pixel-compared. | ||
| 53 | + | ||
| 54 | +EVIDENCE: /tmp/.../scratchpad/rx/{rgb240,rgb241,rgb321,mandfi161}.{obu,ours.yuv,ref.yuv} | | ||
| 55 | +`examples/decode_probe <obu> <yuv>` vs `ffmpeg -i <obu> -f rawvideo`, per-plane byte diff | | ||
| 56 | +per cell, before -> after this round: rgbtestsrc cq24 rtx=0 1650 -> 12 (luma 1118 -> 0); | ||
| 57 | +rgbtestsrc cq24 rtx=1 3461 -> 14 (luma 2304 -> 0); rgbtestsrc cq32 rtx=1 1622 -> 0; | ||
| 58 | +rgbtestsrc cq32 `--enable-filter-intra=1` rtx=0 -> 0; mandelbrot start_x=-0.6 cq16 | ||
| 59 | +`--enable-filter-intra=1` rtx=1 126 -> 123 (luma 0, U 40, V 83). | ||
| 60 | + | ||
| 61 | +## Second defect this round (coordinator-reported, verified and fixed) | ||
| 62 | + | ||
| 63 | +`Reach::top_right_rect`/`bottom_left_rect` (`encode.rs` ~1162/~1196) indexed the rect | ||
| 64 | +`has_tr_*`/`has_bl_*` tables with `(blk_row << (4 - bw_log2)) + blk_col`. libaom's | ||
| 65 | +`has_top_right` uses `MAX_MIB_SIZE_LOG2` = **5** (`enums.h`; its tables are laid out for a | ||
| 66 | +128x128 = 32-mi superblock), so r4 halved the row stride and every table row but the first | ||
| 67 | +read the wrong byte -- 16x8 wrong at 80 mi positions in a 64-wide SB, 8x16 at 16, 32x16 at 64 | ||
| 68 | +(a regression against `main`). Fixed via a named `Reach::rect_table_index` used by both. | ||
| 69 | + | ||
| 70 | +EVIDENCE: `cargo test -p ec-av1 --lib -- rect_reach_tables_are_indexed --nocapture` | | ||
| 71 | +new `encode::tests::rect_reach_tables_are_indexed_with_a_32_mi_row_stride` walks every block | ||
| 72 | +position of a 32-mi superblock for all six rect sizes and asserts the index set is a BIJECTION | ||
| 73 | +onto the table's bits (plus `len * 8 == rows * cols`) | passes with the shift at 5; with r4's | ||
| 74 | +`4 - bw_log2` the walk covers a quarter of the 16x8 table and the assert fails. No pixel change | ||
| 75 | +in the five swept cells (they are all luma-exact either way), so this fix is table-verified, | ||
| 76 | +not gate-differentiated. | ||
| 77 | + | ||
| 78 | +## Open residue | ||
| 79 | + | ||
| 80 | +- fix-now(next round, needs its own lane -- it is a CHROMA PREDICTION defect, not a rect one): | ||
| 81 | + every remaining mismatch is chroma-only with luma byte-exact and the entropy ladder | ||
| 82 | + IDENTICAL end to end (`diff` of the two `EC_ISTEP` traces on mandfi161 is empty apart from | ||
| 83 | + two `use_filter_intra` lines the oracle prints and we do not -- ranges match, so the symbol | ||
| 84 | + is consumed). Localised per 4x4 chroma block on mandelbrot cq16 fi=1: the three FULLY wrong | ||
| 85 | + blocks (16/16 samples) are mi(10,4) V, mi(10,6) V, mi(12,12) U -- all three `uv_mode=13` | ||
| 86 | + (`UV_CFL_PRED`), one plane wrong while the other is exact, i.e. the per-plane CFL alpha, not | ||
| 87 | + the shared luma AC. The partially wrong blocks (1-13 samples, max delta 9) are all | ||
| 88 | + directional chroma with a NON-ZERO `angle_uv` (mi(8,12) uv=4 delta -3, mi(10,2) uv=4 delta 3, | ||
| 89 | + mi(12,8) uv=6 delta -3, ...), i.e. the chroma intra-edge filter/upsample path. Ruled out this | ||
| 90 | + round by experiment: `smooth_neighbor_uv` is NOT the cause -- forcing it true and false | ||
| 91 | + globally leaves the diff at 123 bytes either way (rgb240: 12/13/12). | ||
| 92 | +- deferred(a lane for AB partitions below 16x16): unchanged from r4, `a HORZ_A/HORZ_B/VERT_A | ||
| 93 | + partition below 16x16` still dominates the refusals in the sweep. | ||
| 94 | +- accepted: `read_coeffs_rect` still refuses `V_DCT`/`H_DCT` on a rect transform | ||
| 95 | + (`--reduced-tx-type-set=0` cells can hit it: rgbtestsrc cq32 rtx=0 fi=0 refuses by name). | ||
| 96 | +- accepted: `filter intra on a HORZ/VERT strip` still refuses (4 of the 6 filter-intra cells | ||
| 97 | + swept above stop there, non-silently). | ||
| 98 | +- deferred(the rect `predict_filter_intra` predictor): the coordinator asked for a gate arm | ||
| 99 | + asserting a counter of `use_filter_intra` reads on 16x8/8x16 leaves. It cannot exist yet -- | ||
| 100 | + every recipe where aomenc puts filter intra ON a rect leaf hits exactly that refusal | ||
| 101 | + (`filter intra on a HORZ/VERT strip`, 4 of 6 cells), and the two `--enable-filter-intra=1` | ||
| 102 | + recipes that DO decode (`rgbtestsrc` cq32 rtx=0, now a pinned arm of the new gate) contain no | ||
| 103 | + such leaf, so the counter would assert 0. A gate for those CDF rows unblocks when | ||
| 104 | + `predict_filter_intra` grows a rectangular arm; the r4 refusal is what holds the line | ||
| 105 | + meanwhile. | ||
| 106 | + | ||
| 107 | +## Refusals | ||
| 108 | + | ||
| 109 | +None lifted or added this round; `refusal_inventory` and `gate_coverage` unchanged and green. | ||
| 110 | + | ||
| 111 | +## Totals | ||
| 112 | + | ||
| 113 | +`EC_AV1_REQUIRE_AOMENC=1 cargo test -p ec-av1 --lib` (CARGO_TARGET_DIR=~/.cache/cargo-target-rectx, | ||
| 114 | +final commit): **272 passed, 0 failed, 24 ignored** (825.42s) -- r4's 270 plus the two tests | ||
| 115 | +added this round (`a_real_aomenc_stream_whose_square_block_reads_a_sub16_neighbours_mode_decodes_pixel_exact`, | ||
| 116 | +`rect_reach_tables_are_indexed_with_a_32_mi_row_stride`); nothing regressed. | ||
lanes/sub8-r1.report.mdadded+206 -0
| @@ -0,0 +1,206 @@ | |||
| 1 | +# lane-sub8 report (rounds 1-2) | ||
| 2 | + | ||
| 3 | +## Round 1 (2f35dec, a564705) | ||
| 4 | +Implemented `read_intra_mode_sub8` + `decode_leaf_split4` in | ||
| 5 | +`crates/ec-av1/src/decode.rs` (~5140-5370): decodes `PARTITION_SPLIT` of an | ||
| 6 | +8x8 intra block into four `BLOCK_4X4` leaves (spec `decode_partition`'s | ||
| 7 | +recursion bottom). Both intra call sites (the straddle path and the clean | ||
| 8 | +16x16-SPLIT path) branch on the new `part8` read; `PARTITION_HORZ`/`VERT` | ||
| 9 | +below 8x8 and all inter sub-8x8 stay refused by name. | ||
| 10 | + | ||
| 11 | +**is_chroma_reference derivation** (spec/libaom `av1_common_int.h:1454`): | ||
| 12 | +for 4:2:0 subsampling, only the *last* (bottom-right, index 3) of the four | ||
| 13 | +4x4 leaves in a split 8x8 group carries chroma syntax at all -- the whole | ||
| 14 | +8x8 group's one 4x4 chroma unit is read and reconstructed once, on that | ||
| 15 | +leaf. `decode_leaf_split4` implements this via `has_chroma = i == 3`. | ||
| 16 | + | ||
| 17 | +**Filter-intra CDF row**: `BLOCK_4X4`'s own row (`cdf.rs FILTER_INTRA[0] = | ||
| 18 | +4621`) is already present and is what every sub-8x8 leaf here uses | ||
| 19 | +(`filter_intra_size_class(4)` in libaom is class 0 for all sub-8x8 sizes). | ||
| 20 | +If 4x8/8x4 (HORZ/VERT below 8x8) were ever implemented, they would need two | ||
| 21 | +*more* rows: `BLOCK_4X8 = 6743`, `BLOCK_8X4 = 5893` (libaom | ||
| 22 | +`BLOCK_SIZES_ALL` order, values from `entropymode.c:821`) -- not present | ||
| 23 | +in this table yet. | ||
| 24 | + | ||
| 25 | +**Why HORZ/VERT below 8x8 stays refused**: this decoder's transform | ||
| 26 | +primitive is square-only. A real 4x8/8x4 leaf needs an actual rectangular | ||
| 27 | +TX_4X8/TX_8X4 transform (scan order, EOB context, coefficient CDF set all | ||
| 28 | +differ from the square 4x4 case); faking it as two 4x4 squares would desync | ||
| 29 | +against a real encoder immediately. This is a scope cut, not a bug -- | ||
| 30 | +tracked by refusal name in `refusal_inventory.rs`. | ||
| 31 | + | ||
| 32 | +## Round 2 (6703411) | ||
| 33 | +Round 1 left the gate (`a_real_aomenc_stream_with_a_sub8_split_decodes_pixel_exact`, | ||
| 34 | +`stream.rs` ~6604) uncompiled. It now compiles clean | ||
| 35 | +(`cargo check -p ec-av1 --lib`, zero errors). **The gate is still RED.** | ||
| 36 | + | ||
| 37 | +### What was tried | ||
| 38 | +1. `--enable-rect-partitions=0` added to the aomenc recipe: necessary but | ||
| 39 | + not sufficient. Without it, aomenc picks a real `PARTITION_HORZ`/`VERT` | ||
| 40 | + at 8x8 (still refused by name) in ~63% of the original 40 attempts | ||
| 41 | + (25/40). With it, that specific refusal drops but the gate still hits | ||
| 42 | + 0/160 total passing attempts across two fixture shapes (see below). | ||
| 43 | +2. Shrinking the fixture to a single-16x16-leaf frame (16x16 pixels, so at | ||
| 44 | + most four 8x8 candidates exist in the whole frame) to structurally rule | ||
| 45 | + out a second, still-refused HORZ/VERT leaf sharing the tile. This | ||
| 46 | + surfaced an **unrelated, pre-existing tiny-frame defect**: a plain | ||
| 47 | + 16x16 aomenc stream with NO `--min-partition-size`/`--max-partition-size` | ||
| 48 | + override and no sub8 code involved at all (`decode_leaf_split4` never | ||
| 49 | + called) still decodes with wrong pixels for most seeds (2/3 sampled). | ||
| 50 | + `EC_AV1_TRACE=1` shows the bitstream parses cleanly (no refusal, no | ||
| 51 | + panic, valid-looking symbol values throughout) but the picture desyncs | ||
| 52 | + silently partway through -- consistent with the frame-edge/"true edge | ||
| 53 | + straddle" logic (`decode.rs` ~6864-6957, the `has_cols16`/`has_rows16` | ||
| 54 | + branch) being exercised at a degenerate case (frame == exactly one | ||
| 55 | + 16x16 block, most of the SB out of frame) that larger sub-SB frames | ||
| 56 | + (32x32, 64x64, used successfully elsewhere in this file) don't reach. | ||
| 57 | + **Out of scope for this lane** -- not touched, not fixed, flagged here | ||
| 58 | + for whichever lane owns edge-straddle handling next. | ||
| 59 | +3. Widening the seed/cq sweep for the 64x64 fixture (with | ||
| 60 | + `--enable-rect-partitions=0`) to 160 total attempts across two batches: | ||
| 61 | + still 0 passes. | ||
| 62 | + | ||
| 63 | +### The actual finding | ||
| 64 | +`EC_AV1_TRACE=1` on failing 64x64 attempts shows the pattern directly: | ||
| 65 | +`partition_w8 mi=(0,0) ... value=3` (a real, clean `PARTITION_SPLIT`, | ||
| 66 | +`decode_leaf_split4` fires, `SUB8_SPLIT_HITS` increments) is immediately | ||
| 67 | +followed by `partition_w8 mi=(0,2) ... value=2` (`PARTITION_VERT`) on the | ||
| 68 | +very next sibling 8x8 leaf in the same 16x16 parent -- and that leaf hits | ||
| 69 | +the (correct, by-design) HORZ/VERT-below-8x8 refusal. This happened on | ||
| 70 | +every single attempt that reached a SPLIT at all, which is not consistent | ||
| 71 | +with random encoder choice given `--enable-rect-partitions=0` is set (per | ||
| 72 | +libaom `partition_search.c`'s `do_rectangular_split` gating, that flag | ||
| 73 | +should make `PARTITION_HORZ`/`VERT` unreachable via RD at 8x8 too). The | ||
| 74 | +more consistent read: `decode_leaf_split4`/`read_intra_mode_sub8` leaves | ||
| 75 | +some piece of decoder, CDF, or neighbour-context state wrong on return, and | ||
| 76 | +the very next `partition_w8` symbol read (on the sibling leaf) decodes a | ||
| 77 | +value the real bitstream did not write -- i.e. a real desync introduced by | ||
| 78 | +this round's own new code, immediately after it runs. | ||
| 79 | + | ||
| 80 | +**This was not chased down further this round** -- turn budget spent | ||
| 81 | +finding and narrowing it. Next round should NOT try more fixture-shape | ||
| 82 | +workarounds; instead: trace `dec`'s range/tell before and after | ||
| 83 | +`decode_leaf_split4` against a byte-identical aomdec run (mirror the | ||
| 84 | +`av1-mvstack-refmv-corner`/`cdf-counter-not-reset` class method: exact | ||
| 85 | +range ladder up to the read, compare the step) to find which of | ||
| 86 | +`read_intra_mode_sub8`'s reads or which piece of `Neighbours`/CDF | ||
| 87 | +bookkeeping in `decode_leaf_split4`'s tail (the chroma-neighbour section, | ||
| 88 | +lines ~5346-5369) is wrong. | ||
| 89 | + | ||
| 90 | +### Suite / build state at HEAD (6703411) | ||
| 91 | +- `cargo check -p ec-av1 --lib`: clean, 0 errors. | ||
| 92 | +- Gate `a_real_aomenc_stream_with_a_sub8_split_decodes_pixel_exact`: FAILS | ||
| 93 | + (0/40 in-suite attempts pass; `sub8_split_hits()` DOES go nonzero during | ||
| 94 | + the run -- the SPLIT path fires -- but no attempt completes pixel-exact). | ||
| 95 | +- Full `cargo test -p ec-av1 --lib` and ReelB extract probe: not run | ||
| 96 | + this round (turn budget spent on the above investigation). Deferred to | ||
| 97 | + round 3. | ||
| 98 | + | ||
| 99 | +## Round 3 (05b20f9) | ||
| 100 | + | ||
| 101 | +### Fixed: the partition-context bug the round-2 finding pointed at | ||
| 102 | +libaom's `update_ext_partition_context` (`av1_common_int.h:1500`) only | ||
| 103 | +writes anything when `bsize >= BLOCK_8X8`; the four recursive | ||
| 104 | +`decode_partition(BLOCK_4X4)` calls a real `PARTITION_SPLIT` at 8x8 | ||
| 105 | +produces are no-ops for context purposes. The *one* write that happens is | ||
| 106 | +at the 8x8 level itself, with `subsize = BLOCK_4X4`: | ||
| 107 | +`partition_context_lookup[BLOCK_4X4] = {31, 31}` (bit0 = 1), vs | ||
| 108 | +`partition_context_lookup[BLOCK_8X8] = {30, 30}` (bit0 = 0) for a plain | ||
| 109 | +`PARTITION_NONE` 8x8. `decode_leaf_split4`'s chroma-tail (the block that | ||
| 110 | +sets `left_side_mi`/`above_side_mi` for the whole 8x8 group, `decode.rs` | ||
| 111 | +~5350-5354) had copied `decode_leaf8`'s own TX4-branch value (`8`, | ||
| 112 | +correct there -- that block is still one whole `BLOCK_8X8`, just with a | ||
| 113 | +split *transform*) instead of the value that makes | ||
| 114 | +`partition_ctx_mi`'s `left_side_mi[mi_r]*2 <= side` bit read as 1, which | ||
| 115 | +needs `<= 4`. Changed both writes to `4`. Verified directly against the | ||
| 116 | +libaom source at `~/.cache/aom-oracle/src/av1/common/av1_common_int.h:1441-1552` | ||
| 117 | +(`update_partition_context`/`update_ext_partition_context`/ | ||
| 118 | +`partition_plane_context`), not by re-deriving it by hand. | ||
| 119 | + | ||
| 120 | +**Effect measured**: before the fix, every attempt that hit a real SPLIT | ||
| 121 | +crashed the very next sibling 8x8's `partition_w8` read (round 2's | ||
| 122 | +finding). After the fix, `EC_AV1_TRACE=1` on the dumped stream that | ||
| 123 | +previously crashed shows the sibling reads land on the *correct* context | ||
| 124 | +(cross-checked bit-for-bit against instrumented aomdec's `EC_PART` trace | ||
| 125 | +at the equivalent block, ctx encodes the same left/above bits both sides) | ||
| 126 | +and the whole stream decodes to completion with `Ok`, no error, no panic. | ||
| 127 | +This is real, but not sufficient -- see below. | ||
| 128 | + | ||
| 129 | +### Range-ladder result: gate still RED, and the divergence is UPSTREAM of any sub8 code | ||
| 130 | +Ran the decisive check the charter asked for: rebuilt | ||
| 131 | +`~/.cache/aom-oracle` (rungs 2/5/10 already present in the source, | ||
| 132 | +`EC_PART`/`EC_PART_VAL`/`EC_ISTEP` per-symbol range ladder), decoded the | ||
| 133 | +one dumped failing stream (seed=139, cq=12, 64x64, | ||
| 134 | +`--enable-rect-partitions=0 --min-partition-size=4 --max-partition-size=8`) | ||
| 135 | +through instrumented `aomdec` and compared trace order against our own | ||
| 136 | +`EC_AV1_TRACE` output block by block. | ||
| 137 | + | ||
| 138 | +**First divergence**: the 16x16-level partition read at SUB-unit | ||
| 139 | +`at16=(0,1)` (mi=(0,4)), the *second* 16x16 quadrant of the first 32x32 | ||
| 140 | +block -- i.e. it fires before our decoder has executed one single line of | ||
| 141 | +`decode_leaf_split4`/`read_intra_mode_sub8` (the actual sub8x8-SPLIT in | ||
| 142 | +this stream is at mi=(2,6), inside quadrant (0,1)'s own subtree, per | ||
| 143 | +aomdec's `EC_PART_VAL mi_row=2 mi_col=6 bsize=3 value=3`). aomdec reads | ||
| 144 | +`PARTITION_SPLIT` (value=3) there; ours reads `PARTITION_NONE` (value=0). | ||
| 145 | +The context bits agree (both decode to left=1, above=0, aomdec's combined | ||
| 146 | +`ctx=6` and ours `ctx=2` are the same left/above pair under different | ||
| 147 | +context-array encodings) -- so this is not a context bug, it is either a | ||
| 148 | +CDF-adaptation drift carried in from the *first* 16x16 quadrant's own | ||
| 149 | +four 8x8 leaves (all plain `decode_leaf8`, zero sub8 code touched) or a | ||
| 150 | +genuine range/probability desync from something even earlier that this | ||
| 151 | +round did not get to trace symbol-by-symbol (no per-symbol trace exists | ||
| 152 | +in our decoder for `decode_leaf8`'s own mode-info reads, only for the | ||
| 153 | +`read_intra_mode_sub8` leaves added in round 1 -- that instrumentation | ||
| 154 | +gap is why the ladder stops here this round). | ||
| 155 | + | ||
| 156 | +**This changes the round-2 hypothesis**: the failure is very likely NOT | ||
| 157 | +inside `decode_leaf_split4`/`read_intra_mode_sub8` at all. It reproduces | ||
| 158 | +on this stream before any of that code has run. Whatever the true root | ||
| 159 | +cause is, it sits in code shared by every 8x8/16x16 intra block in this | ||
| 160 | +recipe (`decode_leaf8`, `partition_w16`/`partition_w32` context, or CDF | ||
| 161 | +adaptation for `kf_y_mode`/`uv_mode`/`skip`), and `--min-partition-size=4` | ||
| 162 | +is what surfaces it (this exact recipe may not be exercised by any other | ||
| 163 | +gate). Round 4 should NOT keep assuming the bug is sub8-owned code -- | ||
| 164 | +start by adding the same per-symbol trace (`skip`/`mode`/`uv_mode`/ | ||
| 165 | +`angle_delta`) to `decode_leaf8` itself and ladder the *first* 16x16 | ||
| 166 | +quadrant's four 8x8 leaves symbol-by-symbol against aomdec's `EC_ISTEP` | ||
| 167 | +trace before looking at sub8 code again. | ||
| 168 | + | ||
| 169 | +### Suite / build state at HEAD (05b20f9) | ||
| 170 | +- `cargo check --workspace --all-targets`: clean. | ||
| 171 | +- Gate `a_real_aomenc_stream_with_a_sub8_split_decodes_pixel_exact`: | ||
| 172 | + still FAILS, now for a different, better-localized reason (see above). | ||
| 173 | + Only 1/40 attempts this round both fired a real SPLIT and reached the | ||
| 174 | + pixel comparison at all (39/40 either fired no SPLIT -- most now decode | ||
| 175 | + clean with `PARTITION_NONE` chosen throughout the min-partition-size=4 | ||
| 176 | + region, itself now consistent with correct decoding since they don't | ||
| 177 | + panic -- or the run's own aomenc/decode plumbing skipped). The one that | ||
| 178 | + did fire failed pixel-exact per the finding above. | ||
| 179 | +- `cargo test -p ec-av1 --lib`: not completed this round (turn budget | ||
| 180 | + spent on the range-ladder trace above); deferred to round 4, run it | ||
| 181 | + first thing. | ||
| 182 | +- Debug-only instrumentation (`EC_AV1_DUMP_SUB8` stream dump in | ||
| 183 | + `stream.rs`, temp `dec.rng()` trace print attempt in `decode.rs`) was | ||
| 184 | + added, used, and **reverted** this round -- not left in the tree. | ||
| 185 | + | ||
| 186 | +## Open (round 4 charter should start here) | ||
| 187 | +- fix-now candidate: root cause is upstream of sub8's own code (see | ||
| 188 | + "changes the round-2 hypothesis" above) -- add per-symbol trace to | ||
| 189 | + `decode_leaf8` and ladder against aomdec `EC_ISTEP` on the first 16x16 | ||
| 190 | + quadrant before touching `decode_leaf_split4` again. | ||
| 191 | +- `cargo test -p ec-av1 --lib` full run: not done this round, do it first. | ||
| 192 | +- ReelB extract probe (charter step 4): not reached this round -- | ||
| 193 | + the gate is still red and the 10-bit wall in this branch (main merged | ||
| 194 | + 10-bit at 5636fd2, this branch has not) makes it low-value until the | ||
| 195 | + above is fixed. | ||
| 196 | + | ||
| 197 | +## Open (carried from round 2, unchanged) | ||
| 198 | +- fix-now candidate: the desync in `decode_leaf_split4`/ | ||
| 199 | + `read_intra_mode_sub8` (see "the actual finding" above) -- root cause, | ||
| 200 | + not yet found. | ||
| 201 | +- deferred: tiny-frame (exactly-16x16) edge-straddle defect, unrelated to | ||
| 202 | + sub8, found as a side effect of workaround #2 above -- needs its own | ||
| 203 | + charter, not this lane's. | ||
| 204 | +- deferred: ReelB extract probe (charter step 4) and the ledger | ||
| 205 | + append for round 1's findings (charter step 5) -- partially done here | ||
| 206 | + (this file), full ledger append below. | ||
lanes/sub8-r4.report.mdadded+74 -0
| @@ -0,0 +1,74 @@ | |||
| 1 | +# lane-sub8 report (round 4) | ||
| 2 | + | ||
| 3 | +## Premise correction (this is the round's main result) | ||
| 4 | +Round 2/3 assumed aomenc was really choosing `PARTITION_HORZ`/`VERT` below 8x8 | ||
| 5 | +and AB partitions in this gate's recipe. **It is not.** Instrumented aomdec on | ||
| 6 | +the gate's own stream (seed=117 cq=8, `--enable-rect-partitions=0`) reads only | ||
| 7 | +`value=0` (NONE) and `value=3` (SPLIT) at every level: | ||
| 8 | + | ||
| 9 | +``` | ||
| 10 | +EC_TRACE=1 ~/.cache/aom-oracle/build/aomdec --rawvideo -o /dev/null s117.obu \ | ||
| 11 | + | grep EC_PART_VAL | awk '{print $4,$5}' | sort | uniq -c | ||
| 12 | + 42 bsize=3 value=0 22 bsize=3 value=3 16 bsize=6 value=3 | ||
| 13 | + 4 bsize=9 value=3 1 bsize=12 value=3 | ||
| 14 | +``` | ||
| 15 | + | ||
| 16 | +So all 40 of the gate's "refusals" (`HORZ/VERT below 8x8`, `HORZ_A/B/VERT_A | ||
| 17 | +below 16x16`, `a 32x32 partition type value=4/8/9`) were **hallucinated symbols | ||
| 18 | +from our own desync**, not encoder choices. `--enable-rect-partitions=0` IS | ||
| 19 | +honoured. Every refusal-shaped conclusion in rounds 2-3 was measuring the | ||
| 20 | +desync. | ||
| 21 | + | ||
| 22 | +## Root causes found and fixed (commit "mi-exact intra mode neighbours ...") | ||
| 23 | +1. **Coarse mode neighbours (`context-read-from-one-cell` class).** | ||
| 24 | + `above_mode`/`left_mode` are one slot per 16x16; a split cell leaves two | ||
| 25 | + (8x8) or four (4x4) different modes behind, and a leaf whose above/left | ||
| 26 | + neighbour sits in such a cell read the wrong `kf_y_mode` CDF row -> desync. | ||
| 27 | + `Neighbours` now keeps a mi-granular map (`sub8_mode_col`/`sub8_mode_row`, | ||
| 28 | + `record_mode_mi`), written by `record_rect`, `record_split_luma`, | ||
| 29 | + `decode_leaf8` and every 4x4 leaf, read back with an exact-position guard | ||
| 30 | + (`mode_above_mi`/`mode_left_mi`) that falls back to the coarse slot. | ||
| 31 | +2. **`has_tr_4x4`/`has_bl_4x4` never transcribed** (`encode.rs`, the | ||
| 32 | + `corner-cut` comment that named this exact ceiling). Side-4 blocks clamped | ||
| 33 | + into the 8x8 table, so a directional 4x4 leaf predicted from above-right | ||
| 34 | + samples the decoder has not written yet -- all-zero pixels in the leaf's | ||
| 35 | + bottom-right triangle. Both tables transcribed verbatim from | ||
| 36 | + `~/.cache/aom-oracle/src/av1/common/reconintra.c:65,254`; `Reach::table` | ||
| 37 | + maps side 4 to the new row. | ||
| 38 | +3. Cherry-picked lane-tiny `9b1297a` (deblocker chroma tx size from the block | ||
| 39 | + span) per the charter -- it does not change this lane's residue but keeps | ||
| 40 | + the branch aligned with main's fix. | ||
| 41 | + | ||
| 42 | +## Gate result | ||
| 43 | +`a_real_aomenc_stream_with_a_sub8_split_decodes_pixel_exact` -- **still RED**, | ||
| 44 | +but for a 4-pixel chroma residue instead of a desync: | ||
| 45 | +- symbol ladder vs instrumented aomdec is now **exact** on both sampled | ||
| 46 | + streams (324/324 elements seed=117, 318/318 seed=100), no refusal, decode | ||
| 47 | + completes; | ||
| 48 | +- luma is **bit-exact** on seed=100; | ||
| 49 | +- chroma differs on 4 pixels: U/V (row 20, cols 18-19), deltas 1..3. | ||
| 50 | + | ||
| 51 | +EVIDENCE: /tmp/.../scratchpad/{ref100.yuv,ours100.yuv} | aomenc seed=100 cq=6 recipe from the gate, decoded by ec-av1 and by ffmpeg | 4096/4096 luma bytes equal, 4/2048 chroma bytes differ (max |delta| 3); before this round the same stream refused at a hallucinated partition symbol | ||
| 52 | +EVIDENCE: /tmp/.../scratchpad/{ref.txt,ours.txt} + ladder.py | EC_TRACE/EC_TRACE_MODE_STEP ladder, ours vs instrumented aomdec, seed=117 | 324 elements, no divergence (was: first divergence at element 62) | ||
| 53 | + | ||
| 54 | +## Suite | ||
| 55 | +`cargo test -p ec-av1 --lib` (EC_AV1_REQUIRE_AOMENC=1): **267 passed, 2 failed, | ||
| 56 | +22 ignored**, 1124 s. | ||
| 57 | +- `stream::a_real_aomenc_stream_with_a_sub8_split_decodes_pixel_exact` -- the | ||
| 58 | + 4-pixel chroma residue above. | ||
| 59 | +- `refusal_inventory::the_decode_path_refuses_exactly_the_listed_cases` -- | ||
| 60 | + NOT investigated this round (budget). Expected shape: a refusal the | ||
| 61 | + inventory expects to fire no longer fires now that the desync is gone | ||
| 62 | + (that is what the fix was for), but it is a RED test and no refusal string | ||
| 63 | + was lifted this round. | ||
| 64 | + | ||
| 65 | +## Open | ||
| 66 | +- fix-now: the 4-pixel chroma residue (U/V row 20, cols 18-19 of the 64x64 | ||
| 67 | + seed=100 frame; block = chroma 4x4 at (20,16), luma 8x8 group mi(10,8)). | ||
| 68 | + Tried and REVERTED (no effect on these pixels): OR-ing the subsampling scale | ||
| 69 | + into the chroma edge's mi (`set_lpf_parameters`' `scale_vert | ...`) in | ||
| 70 | + `edge_params`. Next step: dump post-reconstruction vs `EC_AV1_PREFILT_DUMP` | ||
| 71 | + to separate recon from deblock before touching either. | ||
| 72 | +- fix-now: `refusal_inventory` red (see above). | ||
| 73 | +- deferred(gate green): lifting any refusal string -- nothing lifted, none | ||
| 74 | + proven. | ||
lanes/sub8-r5.report.mdadded+93 -0
| @@ -0,0 +1,93 @@ | |||
| 1 | +# lane-sub8 report (round 5) | ||
| 2 | + | ||
| 3 | +## Root cause of the 4-pixel chroma residue | ||
| 4 | + | ||
| 5 | +Recon vs filtering was separated FIRST (charter step 1): the gate's own aomenc | ||
| 6 | +recipe carries `--enable-cdef=0 --loopfilter-control=0`, and our | ||
| 7 | +`EC_AV1_PREFILT_DUMP` / `EC_AV1_POSTDEBLOCK_DUMP` dumps are byte-identical to | ||
| 8 | +the final planes -- so every filter stage is inert on this stream and the | ||
| 9 | +residue was pure reconstruction. (r4's `edge_params` experiment could not have | ||
| 10 | +moved it: there is no deblocking in this stream at all.) | ||
| 11 | + | ||
| 12 | +The mismatching block is NOT a sub-8x8 group: `EC_AV1_TRACE` shows | ||
| 13 | +`partition_w8 mi=(10,8) value=0` -- a plain `PARTITION_NONE` 8x8 leaf with | ||
| 14 | +`tx_depth=1` (four 4x4 luma TUs), luma mode H_PRED, `uv_mode=6` (D157_PRED), | ||
| 15 | +chroma 4x4 at (16,20). Subtracting the (bit-exact) residual from both recons | ||
| 16 | +isolates it to the *prediction*: ours and libaom's differ only at row 0, | ||
| 17 | +columns 2-3. | ||
| 18 | + | ||
| 19 | +**`get_intra_edge_filter_type` (reconintra.c:974) reads the CHROMA neighbours' | ||
| 20 | +`uv_mode` for planes 1/2**, never the luma mode. `decode_leaf8` and | ||
| 21 | +`decode_leaf_split4` passed a hardcoded `false` on every chroma | ||
| 22 | +`reconstruct`/`read_plane`, so a directional chroma block whose chroma | ||
| 23 | +neighbour is smooth filtered its above edge at `intra_edge_filter_strength` | ||
| 24 | +type 0 (kernel `{0,4,8,4,0}`, strength 1 at d=67) instead of type 1 | ||
| 25 | +(`{0,5,6,5,0}`, strength 2) -- deltas of 1..3 on the two pixels the kernel | ||
| 26 | +difference reaches. | ||
| 27 | + | ||
| 28 | +Second half of the cause: the coarse `SUB`-grid `above_uv_mode`/`left_uv_mode` | ||
| 29 | +slots cannot name that neighbour. Adding the leaf's own write to them makes | ||
| 30 | +the top-left 8x8 leaf of a 16x16 clobber the row slot that the block to the | ||
| 31 | +LEFT owns, and the block at mi(10,8) then still read `false` (measured: the | ||
| 32 | +frame stayed 4 pixels off). So this round adds the `uv_mode` twin of the | ||
| 33 | +existing mi-granular `sub8_mode_col`/`sub8_mode_row` machinery. | ||
| 34 | + | ||
| 35 | +## What changed | ||
| 36 | +- `crates/ec-av1/src/decode.rs:1784` -- new `uv_mode_col`/`uv_mode_row` mi-granular | ||
| 37 | + maps on `Neighbours` (+ init). | ||
| 38 | +- `crates/ec-av1/src/decode.rs:2548` `record_uv_mode_mi`, `:2573` | ||
| 39 | + `smooth_uv_neighbour` (mi-exact above/left `uv_mode`, coarse `SUB` slot as | ||
| 40 | + fallback), written from `record_rect` (:2606), `record_split_luma` (:2718), | ||
| 41 | + `decode_leaf8` (:5362) and `decode_leaf_split4` (:5845). | ||
| 42 | +- `crates/ec-av1/src/decode.rs:5331,5758` -- `smooth_neighbor_uv` replaces the | ||
| 43 | + hardcoded `false` at all 10 chroma reconstruct/read_plane arguments in those | ||
| 44 | + two functions. | ||
| 45 | +- `crates/ec-av1/src/refusal_inventory.rs:31` -- deleted the stale capability | ||
| 46 | + claim `"a partition below 8x8 (this decoder codes no leaf smaller than | ||
| 47 | + 8x8)"` (corrected in r6: the string named here originally was wrong); r4's fixes | ||
| 48 | + removed that string from the decode path, which is exactly what made | ||
| 49 | + `the_decode_path_refuses_exactly_the_listed_cases` RED (charter step 2). | ||
| 50 | + It was the only entry the test named. | ||
| 51 | + | ||
| 52 | +## Gate | ||
| 53 | +`a_real_aomenc_stream_with_a_sub8_split_decodes_pixel_exact` -- **GREEN** | ||
| 54 | +(4 firing + pixel-exact runs; `sub8_split_hits` hard-asserted, no SKIP). | ||
| 55 | + | ||
| 56 | +``` | ||
| 57 | +EC_AV1_REQUIRE_AOMENC=1 cargo test -p ec-av1 --lib sub8 | ||
| 58 | + test stream::tests::a_real_aomenc_stream_with_a_sub8_split_decodes_pixel_exact ... ok | ||
| 59 | +``` | ||
| 60 | + | ||
| 61 | +EVIDENCE: <scratchpad>/sub8r5/{mine.yuv,ref.yuv} | seed=100 cq=6 gate recipe re-run standalone (sha256 64f6f74e... 3994 B), decoded by `examples/decode_probe` and by ffmpeg | 6144/6144 bytes equal (was 4 chroma bytes off, |delta| <= 3) | ||
| 62 | +EVIDENCE: <scratchpad>/sub8r5/prefilt+postdeblock dumps | EC_AV1_PREFILT_DUMP / EC_AV1_POSTDEBLOCK_DUMP on the same stream | both byte-identical to the final planes -> filters inert, residue is reconstruction | ||
| 63 | +EVIDENCE: <scratchpad>/sub8r5/hg.obu | `ffmpeg -t 0.4 -c:v copy -f obu` from the ReelB film, `decode_probe` after the fix | REFUSED at "a HORZ/VERT partition below 8x8" (was: "a partition below 8x8") | ||
| 64 | + | ||
| 65 | +## Refusals | ||
| 66 | +Nothing lifted, nothing to lift: the PARTITION_SPLIT-to-4x4 shape the charter | ||
| 67 | +names has had **no refusal string** since `decode_leaf_split4` landed (r2) -- | ||
| 68 | +the gate is what was missing, and it is now green, so the capability is | ||
| 69 | +proven rather than assumed. The two below-8x8 strings that remain are both | ||
| 70 | +out of this lane by the standing constraint: | ||
| 71 | +- `"a HORZ/VERT partition below 8x8 (... 4x8/8x4 need a real rectangular | ||
| 72 | + transform)"` -- deferred(a real TX_4X8/TX_8X4 primitive). This is now the | ||
| 73 | + ReelB blocker. | ||
| 74 | +- `"an inter partition below 8x8 ..."` -- deferred(an inter lane; lane-sub8 is | ||
| 75 | + intra-scoped). | ||
| 76 | + | ||
| 77 | +## Suite | ||
| 78 | +`EC_AV1_REQUIRE_AOMENC=1 cargo test -p ec-av1 --lib`: **269 passed, 0 failed, 22 | ||
| 79 | +ignored**, 476 s (r4 was 267 passed, 2 failed -- both now green). | ||
| 80 | + | ||
| 81 | +## Open / disposition | ||
| 82 | +- deferred(an inter-frame gate whose chroma neighbour codes a smooth `uv_mode`) | ||
| 83 | + -- same-shape sweep: `decode.rs:12084,12096` (`decode_inter_block8`'s | ||
| 84 | + intra-in-inter chroma reconstruct) still pass a hardcoded `false` for the | ||
| 85 | + chroma edge-filter type. Every other chroma site now takes a `uv_mode`-derived | ||
| 86 | + flag; `decode_block`/`decode_inter_block` (:3251,:3765,:4893,:10929) take it | ||
| 87 | + from the coarse `SUB` slots, which is exact for >=16x16 neighbours and | ||
| 88 | + approximate when the neighbour is an 8x8 leaf -- upgrade path is to route | ||
| 89 | + those four through `smooth_uv_neighbour` too. | ||
| 90 | +- accepted: `smooth_uv_neighbour` falls back to the coarse slot when no block | ||
| 91 | + recorded the exact neighbouring mi (documented at the field). | ||
| 92 | +- Film: ReelB now stops at the HORZ/VERT-below-8x8 refusal above; the | ||
| 93 | + film is also yuv420p10le, so a 10-bit refusal waits behind it. | ||
lanes/sub8-r6.report.mdadded+77 -0
| @@ -0,0 +1,77 @@ | |||
| 1 | +# lane-sub8 report (round 6) -- verifier FAIL closed | ||
| 2 | + | ||
| 3 | +## The defect the verifier found (root cause) | ||
| 4 | + | ||
| 5 | +The mi-granular mode maps added in r2/r5 (`sub8_mode_col`/`sub8_mode_row`, | ||
| 6 | +`uv_mode_col`/`uv_mode_row`) are FRAME-wide arrays read with a FRAME-relative | ||
| 7 | +availability guard (`mi_r > 0` / `mi_c > 0`) and never reset per tile. Every | ||
| 8 | +other neighbour site in `decode.rs` guards tile-relatively | ||
| 9 | +(`mi_r > self.tile_row0_mi`, e.g. :2240, :3222, :6152). With more than one | ||
| 10 | +tile, the first block of tile N read a `(row, mode)` entry left by the tile to | ||
| 11 | +its LEFT (or above) as if it were its own neighbour -- wrong intra-mode | ||
| 12 | +context / wrong chroma edge-filter type, and from there wrong pixels. | ||
| 13 | + | ||
| 14 | +## What changed (all in the lane worktree, branch `lane-sub8`) | ||
| 15 | +- `crates/ec-av1/src/decode.rs:2533,2540,2574,2578` -- the four reads now guard | ||
| 16 | + with `self.tile_row0_mi` / `self.tile_col0_mi`. | ||
| 17 | +- `crates/ec-av1/src/decode.rs:2000` (`start_tile`) -- clears | ||
| 18 | + `sub8_mode_col`/`uv_mode_col` over the tile's own mi column span | ||
| 19 | + (`col0_mi..col1_mi`), alongside the existing `above_*` reset. | ||
| 20 | +- `crates/ec-av1/src/decode.rs:2286` (`start_row`) -- clears | ||
| 21 | + `sub8_mode_row`/`uv_mode_row` with the rest of the left context. | ||
| 22 | +- `crates/ec-av1/src/decode.rs:3763` -- `decode_leaf_rect` (the 16x8/8x16 | ||
| 23 | + strips) now calls `record_mode_mi`/`record_uv_mode_mi` over its real span; | ||
| 24 | + before, the caller patched only the coarse 16x16 `above_mode`/`left_mode` | ||
| 25 | + slot, so a neighbour of the TOP strip read the BOTTOM strip's mode. | ||
| 26 | + (Sweep item 1 of the verifier's list.) | ||
| 27 | +- `crates/ec-av1/src/decode.rs:5326` -- deleted the stale `corner-cut` comment | ||
| 28 | + claiming the uv neighbours are coarse; they are mi-exact since r5. | ||
| 29 | +- `crates/ec-av1/src/stream.rs:7259..` -- gate rewritten: three arms | ||
| 30 | + (single tile / `--tile-columns=1` at 128x64 / `--tile-rows=1` at 64x128), | ||
| 31 | + each needing 4 firing + pixel-exact runs; `tile_hits()` delta >= 2 asserted | ||
| 32 | + on the tile arms (gate-blind-to-feature); the `Err` arm now ASSERTS the | ||
| 33 | + message starts with `unsupported: ` -- any other decode error panics | ||
| 34 | + instead of counting as a tolerated refusal; the fixture's `noise` filter | ||
| 35 | + carries `all_seed={seed}`. | ||
| 36 | +- `lanes/sub8-r5.report.md:45` -- the deleted refusal string named correctly | ||
| 37 | + ("a partition below 8x8 ..."). | ||
| 38 | + | ||
| 39 | +## Gate | ||
| 40 | + | ||
| 41 | +`EC_AV1_REQUIRE_AOMENC=1 cargo test -p ec-av1 --lib sub8` -> **ok, 1 passed** | ||
| 42 | +(3 arms x 4 firing+pixel-exact runs). | ||
| 43 | + | ||
| 44 | +Regression value proved by reverting only the guard+reset hunks: the same gate | ||
| 45 | +FAILS (`U vs ffmpeg (seed=139 cq=12)`, stream.rs:7394) -- so this gate catches | ||
| 46 | +the defect, it is not a pass-by-construction arm. | ||
| 47 | + | ||
| 48 | +EVIDENCE: <scratchpad>/bad207.obu (sha256 0f78db8b...), bad228.obu (sha256 6a73db99...) | `decode_probe <obu> out.yuv` + `ffmpeg -i <obu> -f rawvideo -pix_fmt yuv420p` on this branch | both 12288/12288 bytes equal (verifier's pre-fix .mine.yuv: 221 and 158 differing bytes, all at x>=64) | ||
| 49 | +EVIDENCE: gate run above | 3-arm gate incl. --tile-columns=1 / --tile-rows=1, tile_hits delta >= 2 asserted | ok; with the guard+reset hunks reverted the same gate FAILS at seed=139 cq=12 (U plane) | ||
| 50 | +EVIDENCE: <scratchpad>/reelb_r6.obu | `ffmpeg -t 0.4 -c:v copy -f obu` from the ReelB film, `decode_probe` on this branch | REFUSED at "a HORZ/VERT partition below 8x8 (... 4x8/8x4 need a real rectangular transform)" -- unchanged from r5, and past main's "a partition below 8x8" | ||
| 51 | +EVIDENCE: fixture reproducibility | the gate's lavfi source (seed 207, 128x64) rendered twice with and without `all_seed=207` | with: d3c4b3e3... both runs; without: 5619b3ee... both runs -- ffmpeg's `noise` was in fact deterministic in this pair of runs, `all_seed` pins it explicitly rather than relying on that | ||
| 52 | + | ||
| 53 | +## Refusals | ||
| 54 | +None lifted, none added this round; `refusal_inventory` and `gate_coverage` | ||
| 55 | +stay green (totals below). | ||
| 56 | + | ||
| 57 | +## Suite | ||
| 58 | +`EC_AV1_REQUIRE_AOMENC=1 cargo test -p ec-av1 --lib`: **269 passed, 0 failed, 22 ignored**, 933 s (r5: 269/0/22). | ||
| 59 | + | ||
| 60 | +An earlier run of the same command on the same tree reported `error: test | ||
| 61 | +failed` with the failing test's name swallowed by my own grep filter; the | ||
| 62 | +full rerun above (log `<scratchpad>/suite_r6.log`) is clean. Flagged as a | ||
| 63 | +possible flake under 10 concurrent lanes rather than claimed benign -- | ||
| 64 | +open, unblocked by a rerun that captures the whole log. | ||
| 65 | + | ||
| 66 | +## Open / disposition | ||
| 67 | +- deferred(an inter lane) -- `decode.rs:8547-8548` (`up_available`/ | ||
| 68 | + `left_available` in the inter path) and `mvstack.rs:727,733,742,756,1486, | ||
| 69 | + 1492,1501,1515` still use frame-relative `mi_row > 0` / `mi_col > 0` where | ||
| 70 | + libaom uses `tile->mi_row_start`/`mi_col_start`. Same shape as this round's | ||
| 71 | + defect but in code this lane never touched and no intra gate reaches; | ||
| 72 | + unblocked by a multi-tile INTER gate. | ||
| 73 | +- deferred(an inter-frame gate whose chroma neighbour codes a smooth | ||
| 74 | + `uv_mode`) -- carried from r5: `decode.rs:12084,12096` still pass a | ||
| 75 | + hardcoded `false` chroma edge-filter type. | ||
| 76 | +- accepted: `smooth_uv_neighbour` falls back to the coarse `SUB` slot when no | ||
| 77 | + block recorded the exact neighbouring mi. | ||
lanes/sub8merge-r1.report.mdadded+67 -0
| @@ -0,0 +1,67 @@ | |||
| 1 | +# lane-sub8merge report (round 1) -- merge cross-product defect closed | ||
| 2 | + | ||
| 3 | +## Root cause (one line, one variable) | ||
| 4 | + | ||
| 5 | +The merge resolution of `Reach::top_right` / `Reach::bottom_left` | ||
| 6 | +(`crates/ec-av1/src/encode.rs:1237,1272`) introduced | ||
| 7 | + | ||
| 8 | +```rust | ||
| 9 | +let row = Self::table(side); // 0..=3, the TABLE row | ||
| 10 | +``` | ||
| 11 | + | ||
| 12 | +which SHADOWS the block's position row bound eight lines above | ||
| 13 | +(`let (row, col, per_side) = Self::position(side, x, y);`) and is then used by | ||
| 14 | +the bit index `(row * Self::table_stride(side) + col)`. Main computed the table | ||
| 15 | +index inline (`HAS_TOP_RIGHT[Self::table(side)]`) and kept `row` = position. | ||
| 16 | +So on the merged tree EVERY block size read `has_top_right`/`has_bottom_left` | ||
| 17 | +at the wrong bit: the reach (above-right / below-left reference availability) | ||
| 18 | +was wrong for ordinary square blocks, not just sub-8x8 -- which is exactly why | ||
| 19 | +each side was green alone and the merged tree failed a gate whose stream | ||
| 20 | +contains zero sub8 splits and zero split-tx strips (seed 55 printed | ||
| 21 | +"split-tx strips this stream: 0"). | ||
| 22 | + | ||
| 23 | +Fix: rename to `table_row` in both functions, restoring `row` as the position | ||
| 24 | +row, plus a NB comment naming the shadowing hazard. | ||
| 25 | +`crates/ec-av1/src/encode.rs:1234-1241,1269-1276`. | ||
| 26 | + | ||
| 27 | +Class: `adjacent same-typed args` / shadowing sibling -- a merge that renames a | ||
| 28 | +value into an identifier already live in scope. Sweep: `grep -n "let row = \|let col = " crates/ec-av1/src/encode.rs` | ||
| 29 | +returns nothing else; the only two `Self::position*` consumers are these two. | ||
| 30 | + | ||
| 31 | +Also removed the previous agent's leftover ablation hook | ||
| 32 | +`EC_ABLATE_SUB8` in `decode_leaf_split4` (`crates/ec-av1/src/decode.rs:6978`). | ||
| 33 | + | ||
| 34 | +The charter's untested suspects (the six `smooth_neighbor_uv` sites, the | ||
| 35 | +per-tile mi-map resets, `Neighbours::new`, `record_split_luma_rect`) are all | ||
| 36 | +INNOCENT: they are unchanged by this round and both gates are green. | ||
| 37 | + | ||
| 38 | +## Gates | ||
| 39 | + | ||
| 40 | +EVIDENCE: $HOME/.cache/sub8merge-suite.log | `EC_AV1_REQUIRE_AOMENC=1 cargo test -p ec-av1 --lib split_transform_horz_vert` on the merged tree before and after the rename | before: FAILED, seed 55 first luma mismatch (191,76) ours=127 ffmpeg=128, 3080 samples, bbox x94..191 y76..127; after: ok, 1 passed (8.55 s) | ||
| 41 | +EVIDENCE: same log | `EC_AV1_REQUIRE_AOMENC=1 cargo test -p ec-av1 --lib sub8` after the rename | ok, 1 passed (5.10 s, 3 tile arms x 4 firing+pixel-exact runs) | ||
| 42 | +EVIDENCE: $HOME/.cache/sub8merge-suite.log | full `EC_AV1_REQUIRE_AOMENC=1 cargo test -p ec-av1 --lib` (1228 s) | 298 passed, 1 failed, 27 ignored -- every sibling gate named in the charter (sub8, tiny_frame_size_sweep, tx_select, an_8x8_leaf_split, split_transform_horz_vert, filter_intra_on_a_horz, superblock_level_*, refusal_inventory, gate_coverage) green | ||
| 43 | + | ||
| 44 | +## The one failure is INHERITED FROM MAIN, not this lane | ||
| 45 | + | ||
| 46 | +`decode::tests::nz_map_ctx_offset_tables_match_the_rect_rule` fails: | ||
| 47 | +`32x64 nz_map offset at display (row 0, col 2): left 6, right 11` | ||
| 48 | +(decode.rs:16837). `cdf.rs` is byte-identical between the merge base 61c6a5b, | ||
| 49 | +this branch, and current main df5d630, and the test body is identical on | ||
| 50 | +df5d630 (`git show df5d630:crates/ec-av1/src/decode.rs`, lines 16299-16321) -- | ||
| 51 | +so main itself is red on this test. `NZ_MAP_CTX_OFFSET_32X64` row 2 is | ||
| 52 | +`[6, 6, 21, 21, 21]`, i.e. under the column-major read the table gives 6 where | ||
| 53 | +the rule (w<h, display row<2) wants 11 for display rows 0/1 at columns 2/3. | ||
| 54 | +Either the lane-rectsplit table or its rule test is wrong. | ||
| 55 | +Disposition: **deferred(the rectsplit owner)** -- changing the table changes | ||
| 56 | +real coefficient contexts and needs its own aomenc gate run; out of this merge | ||
| 57 | +lane's scope and demonstrably not caused by it. | ||
| 58 | + | ||
| 59 | +## Suite | ||
| 60 | +`EC_AV1_REQUIRE_AOMENC=1 cargo test -p ec-av1 --lib`: 298 passed, 1 failed | ||
| 61 | +(inherited, above), 27 ignored, 1228 s. Log: `$HOME/.cache/sub8merge-suite.log`. | ||
| 62 | + | ||
| 63 | +## Refusals | ||
| 64 | +None lifted or added this round; the merge's own bookkeeping (refusal string | ||
| 65 | +narrowed to "a sub-8x8 leaf that uses intrabc" + inventory entry, gate_coverage | ||
| 66 | +8-bit list dropping enable-1to4-partitions) came in with ea90092 and both | ||
| 67 | +`refusal_inventory` and `gate_coverage` tests are green. | ||