Mi-precise partition ctx for 8x8 leaves
Browse files at this commit9a698569e293f0266822b18c8e484fad31448f5eParent: 51db03e- fix
- mi-precise partition ctx for 8x8 leaves
- falsify r7's ctx hypothesis
2 changed files +55 -13
- crates/ec-av1/src/encode.rs +20 -5
- crates/ec-av1/src/tile.rs +35 -8
crates/ec-av1/src/encode.rsmodified+20 -5
| @@ -3860,11 +3860,26 @@ mod tests { | ||
| 3860 | 3860 | /// column half only (`has_half` false on cols, true on rows) -- exactly |
| 3861 | 3861 | /// the single-axis straddle lane-av1-rect r7 wires through |
| 3862 | 3862 | /// `crate::tile::write_leaf8`'s 8x8 leaves. Not yet decoder-clean: |
| 3863 | - /// dav1d rejects the stream ("Invalid data found"), a genuine desync r7 | |
| 3864 | - /// ran out of budget to trace (see the r7 handoff -- first falsification | |
| 3865 | - /// candidate is `partition_w8`'s ctx being read from the *enclosing* | |
| 3866 | - /// 16x16 slot identically for both leaves). Ignored rather than deleted, | |
| 3867 | - /// so the class stays named and the gate stays green. | |
| 3863 | + /// dav1d rejects the stream ("Invalid data found"). r7's falsification | |
| 3864 | + /// candidate (`partition_w8`'s ctx reading the enclosing 16x16 slot) is | |
| 3865 | + /// FALSIFIED by r8's rng trace against a debug `aomdec`: libaom's own | |
| 3866 | + /// `partition_plane_context` masks at `bsl = 0` for `BLOCK_8X8`, and every | |
| 3867 | + /// `partition_context_lookup` entry this writer ever produces (no 4x4 | |
| 3868 | + /// splits exist) has bit 0 clear, so the ctx is provably 0 for every | |
| 3869 | + /// leaf regardless of neighbour state -- our writer already agreed with | |
| 3870 | + /// the decoder here (`ctx=0` both sides). r8 still ported the mi-precise | |
| 3871 | + /// tracking (`Neighbours::{above,left}_side_mi`, `partition_ctx_mi`) as a | |
| 3872 | + /// spec-accurate fix in its own right (it matters once 4x4 exists), and | |
| 3873 | + /// it does not regress the gate. The real first divergence is later: | |
| 3874 | + /// leaf0's own luma transform (`TxbSet::Luma8`/`Chroma4`, exercised by no | |
| 3875 | + /// other caller) reads a wrong `EC_EOBPT` category (decoder eob=36 vs the | |
| 3876 | + /// writer's real eob=7) -- the writer's own `EC_TXBSKIP`/`EC_TXBCTX` | |
| 3877 | + /// equivalents agree with the decoder up to and including the skip flag, | |
| 3878 | + /// so the fault is between the `TX_TYPE` symbol and the `EOB_PT` symbol: | |
| 3879 | + /// either the intra tx-type CDF selection or the eob CDF table/adaptation | |
| 3880 | + /// state for the never-before-exercised `Luma8`/`Chroma4` pair. Ignored | |
| 3881 | + /// rather than deleted, so the class stays named and the gate stays | |
| 3882 | + /// green. | |
| 3868 | 3883 | #[test] |
| 3869 | 3884 | #[ignore = "lane-av1-rect r7: 8x8-leaf path desyncs dav1d, not yet traced"] |
| 3870 | 3885 | fn a_single_axis_straddle_round_trips_through_ffmpeg() { |
crates/ec-av1/src/tile.rsmodified+35 -8
| @@ -616,6 +616,17 @@ struct Neighbours { | ||
| 616 | 616 | above_side: Vec<usize>, |
| 617 | 617 | /// The same, down the left edge. |
| 618 | 618 | left_side: Vec<usize>, |
| 619 | + /// The same as `above_side`/`left_side`, but kept at the finer mi (4x4) | |
| 620 | + /// granularity [`Self::above`]/[`Self::left`] are, rather than [`SUB`]: | |
| 621 | + /// two 8x8 leaves of one straddling 16x16 block (lane-av1-rect) share a | |
| 622 | + /// single [`SUB`]-grid cell, so a coarse array cannot tell the second | |
| 623 | + /// leaf's partition symbol that the first one was coded at 8x8 (finer | |
| 624 | + /// than the 16x16 it sits in) -- exactly what its `above`/`left` context | |
| 625 | + /// needs to read (spec 9.3's `AbovePartitionContext`/`LeftPartitionContext`, | |
| 626 | + /// which libaom keeps per mi unit for this reason). | |
| 627 | + above_side_mi: Vec<usize>, | |
| 628 | + /// The same, down the left edge. | |
| 629 | + left_side_mi: Vec<usize>, | |
| 619 | 630 | /// Whether the neighbour carried no residual, for [`sb_coeff_inter_frame_tile`]'s |
| 620 | 631 | /// skip context. Unused (and left at its default) by the key frame writers. |
| 621 | 632 | above_skip: Vec<bool>, |
| @@ -663,6 +674,8 @@ impl Neighbours { | ||
| 663 | 674 | left_mode: vec![DC_PRED; rows], |
| 664 | 675 | above_side: vec![SB; cols], |
| 665 | 676 | left_side: vec![SB; rows], |
| 677 | + above_side_mi: vec![SB; cols * (SUB / MI)], | |
| 678 | + left_side_mi: vec![SB; rows * (SUB / MI)], | |
| 666 | 679 | above_skip: vec![false; cols], |
| 667 | 680 | left_skip: vec![false; rows], |
| 668 | 681 | above_inter: vec![false; cols], |
| @@ -677,6 +690,7 @@ impl Neighbours { | ||
| 677 | 690 | self.left.iter_mut().for_each(|l| *l = Default::default()); |
| 678 | 691 | self.left_mode.iter_mut().for_each(|m| *m = DC_PRED); |
| 679 | 692 | self.left_side.iter_mut().for_each(|s| *s = SB); |
| 693 | + self.left_side_mi.iter_mut().for_each(|s| *s = SB); | |
| 680 | 694 | self.left_skip.iter_mut().for_each(|s| *s = false); |
| 681 | 695 | self.left_inter.iter_mut().for_each(|i| *i = false); |
| 682 | 696 | } |
| @@ -710,6 +724,10 @@ impl Neighbours { | ||
| 710 | 724 | let (mi_r, mi_c) = at_mi; |
| 711 | 725 | let states: [Neighbour; 3] = std::array::from_fn(|plane| neighbour_state(&grids[plane])); |
| 712 | 726 | let side_mi = side / MI; |
| 727 | + for cell in 0..side_mi { | |
| 728 | + self.left_side_mi[mi_r + cell] = side; | |
| 729 | + self.above_side_mi[mi_c + cell] = side; | |
| 730 | + } | |
| 713 | 731 | // libaom rounds the luma edge up to the plane's own 4x4 unit before |
| 714 | 732 | // clamping a subsampled plane (`ROUND_POWER_OF_TWO(max_blocks_high, |
| 715 | 733 | // subsampling_y)` in av1_write_intra_coeffs_mb, encodetxb.c:456-459): |
| @@ -789,6 +807,15 @@ impl Neighbours { | ||
| 789 | 807 | let (r, c) = at; |
| 790 | 808 | 2 * usize::from(self.left_side[r] * 2 <= side) + usize::from(self.above_side[c] * 2 <= side) |
| 791 | 809 | } |
| 810 | + | |
| 811 | + /// [`Self::partition_ctx`] at mi granularity, for an 8x8 leaf of a | |
| 812 | + /// straddling 16x16 block: reads the finer `above_side_mi`/`left_side_mi` | |
| 813 | + /// arrays so the second leaf sees the first leaf's own 8x8 side rather | |
| 814 | + /// than the enclosing 16x16 slot's stale, shared state. | |
| 815 | + fn partition_ctx_mi(&self, (mi_r, mi_c): (usize, usize), side: usize) -> usize { | |
| 816 | + 2 * usize::from(self.left_side_mi[mi_r] * 2 <= side) | |
| 817 | + + usize::from(self.above_side_mi[mi_c] * 2 <= side) | |
| 818 | + } | |
| 792 | 819 | } |
| 793 | 820 | |
| 794 | 821 | /// Writes the payload of a one-tile key frame built from `superblocks`, each |
| @@ -1161,14 +1188,14 @@ pub fn sb_coeff_key_frame_tile( | ||
| 1161 | 1188 | } |
| 1162 | 1189 | for (leaf, (mr, mc)) in leaves.iter().zip(leaf_positions) { |
| 1163 | 1190 | let leaf_mi = (mr as usize, mc as usize); |
| 1164 | - // Per r6's charter, this must be | |
| 1165 | - // recomputed per leaf; nothing this | |
| 1166 | - // writer's [`Neighbours`] tracks at | |
| 1167 | - // [`SUB`] granularity changes between | |
| 1168 | - // the two leaves of one straddling | |
| 1169 | - // 16x16, so both read the same | |
| 1170 | - // enclosing-slot context. | |
| 1171 | - let leaf_ctx = neighbours.partition_ctx(at, SUB); | |
| 1191 | + // r8: read at mi granularity, not the | |
| 1192 | + // enclosing 16x16 slot -- the first | |
| 1193 | + // leaf's `record_mi` call below | |
| 1194 | + // updates `above_side_mi`/ | |
| 1195 | + // `left_side_mi` at this leaf's own | |
| 1196 | + // mi position, which the second | |
| 1197 | + // leaf's ctx lookup then sees. | |
| 1198 | + let leaf_ctx = neighbours.partition_ctx_mi(leaf_mi, 8); | |
| 1172 | 1199 | ec_rng_trace(|| { |
| 1173 | 1200 | format!( |
| 1174 | 1201 | "EC_PART mi_row={} mi_col={} bsize=3 ctx={} tell={}", |