Merge branch 'lane-sub8merge': sub-8x8 partitions (4x4 leaves, mi-granular y/uv mode maps with tile guards; ReelB head blocker) + Reach row-shadowing fix from the merge
Browse files at this commit11 changed files +1460 -87
- crates/ec-av1/src/decode.rs +587 -65
- crates/ec-av1/src/encode.rs +61 -20
- crates/ec-av1/src/gate_coverage.rs +1 -1
- crates/ec-av1/src/refusal_inventory.rs +3 -1
- crates/ec-av1/src/stream.rs +200 -0
- lanes/COMMON-20260901.md +91 -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/decode.rsmodified+587 -65
| @@ -1641,6 +1641,21 @@ pub(crate) fn angle_delta_hits() -> usize { | ||
| 1641 | 1641 | pub(crate) fn tx_class1_hits() -> usize { |
| 1642 | 1642 | TX_CLASS1_HITS.with(|c| c.get()) |
| 1643 | 1643 | } |
| 1644 | + | |
| 1645 | +// How many `PARTITION_SPLIT` decisions below an 8x8 block (four independent | |
| 1646 | +// `BLOCK_4X4` leaves, spec `decode_partition`'s `bSize < BLOCK_8X8` recursion | |
| 1647 | +// bottom) this thread's decode actually reconstructed -- the same | |
| 1648 | +// before/after counter pattern as [`TX_CLASS1_HITS`], proving a stream | |
| 1649 | +// genuinely exercised the sub-8x8 leaf path rather than every attempt | |
| 1650 | +// coincidentally landing on `PARTITION_NONE`. | |
| 1651 | +thread_local! { | |
| 1652 | + static SUB8_SPLIT_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) }; | |
| 1653 | +} | |
| 1654 | + | |
| 1655 | +/// Current value of [`SUB8_SPLIT_HITS`]. | |
| 1656 | +pub(crate) fn sub8_split_hits() -> usize { | |
| 1657 | + SUB8_SPLIT_HITS.with(|c| c.get()) | |
| 1658 | +} | |
| 1644 | 1659 | const SUB_MI: u32 = 4; |
| 1645 | 1660 | const MI: usize = 4; |
| 1646 | 1661 | const SB: usize = 64; |
| @@ -2591,6 +2606,26 @@ struct Neighbours { | ||
| 2591 | 2606 | /// one was coded at 8x8. |
| 2592 | 2607 | above_side_mi: Vec<usize>, |
| 2593 | 2608 | left_side_mi: Vec<usize>, |
| 2609 | + /// The luma `mode` of the last `BLOCK_4X4` leaf decoded at each mi column | |
| 2610 | + /// / row, with the mi position it was written at | |
| 2611 | + /// (`(usize::MAX, _)` = never written). `above_mode`/`left_mode` are on | |
| 2612 | + /// the coarse 16x16 grid, which cannot distinguish the two 4x4 leaves an | |
| 2613 | + /// 8x8 `PARTITION_SPLIT` puts in one mi column; libaom's intra-mode | |
| 2614 | + /// context reads `mi(row, col-1)`/`mi(row-1, col)` exactly, so a sub-8x8 | |
| 2615 | + /// leaf whose neighbour is another split group needs that group's leaf 3 | |
| 2616 | + /// (bottom-right), not the leaf the coarse slot happens to hold. Written | |
| 2617 | + /// and read only by [`decode_leaf_split4`]; the position guard makes it | |
| 2618 | + /// fall back to the coarse slot whenever the real neighbour was a block | |
| 2619 | + /// of 8x8 or larger (whose one mode is correct for every row it spans). | |
| 2620 | + sub8_mode_col: Vec<(usize, usize)>, | |
| 2621 | + sub8_mode_row: Vec<(usize, usize)>, | |
| 2622 | + /// The `uv_mode` twin of `sub8_mode_col`/`sub8_mode_row` (lane-sub8 r5): | |
| 2623 | + /// chroma's edge-filter type reads the CHROMA neighbour's `uv_mode` | |
| 2624 | + /// (`get_intra_edge_filter_type`, reconintra.c:974), and the coarse | |
| 2625 | + /// [`SUB`] slots cannot name it once a 16x16 is split into 8x8 leaves -- | |
| 2626 | + /// the leaf above writes the same row slot the block to the left owns. | |
| 2627 | + uv_mode_col: Vec<(usize, usize)>, | |
| 2628 | + uv_mode_row: Vec<(usize, usize)>, | |
| 2594 | 2629 | /// Whether the block above/left of this column/row was coded `skip` -- |
| 2595 | 2630 | /// an inter frame's own `skip` context (spec `SkipContext`), which the |
| 2596 | 2631 | /// key-frame writer never tracks (its skip context is always zero); a |
| @@ -2738,6 +2773,10 @@ impl Neighbours { | ||
| 2738 | 2773 | left_side: vec![SB; rows], |
| 2739 | 2774 | above_side_mi: vec![SB; cols * (SUB / MI)], |
| 2740 | 2775 | left_side_mi: vec![SB; rows * (SUB / MI)], |
| 2776 | + sub8_mode_col: vec![(usize::MAX, 0); cols * (SUB / MI)], | |
| 2777 | + sub8_mode_row: vec![(usize::MAX, 0); rows * (SUB / MI)], | |
| 2778 | + uv_mode_col: vec![(usize::MAX, 0); cols * (SUB / MI)], | |
| 2779 | + uv_mode_row: vec![(usize::MAX, 0); rows * (SUB / MI)], | |
| 2741 | 2780 | above_txfm: vec![TXFM_CTX_INIT; cols * (SUB / MI)], |
| 2742 | 2781 | left_txfm: vec![TXFM_CTX_INIT; rows * (SUB / MI)], |
| 2743 | 2782 | // lane-inter8 r2: mi(4px)-granular, not [`SUB`]-granular -- an |
| @@ -2821,6 +2860,14 @@ impl Neighbours { | ||
| 2821 | 2860 | self.above_compound_idx[i] = 0; |
| 2822 | 2861 | self.above_filter[i] = [3u8; 2]; |
| 2823 | 2862 | } |
| 2863 | + // lane-sub8 r6: the mi-granular column maps are per tile too -- a | |
| 2864 | + // stale `(row, mode)` from the tile to the LEFT names an mi row this | |
| 2865 | + // tile's first block would read as its own above neighbour. | |
| 2866 | + let mcol_end = col1_mi.min(self.sub8_mode_col.len()); | |
| 2867 | + for i in col0_mi.min(mcol_end)..mcol_end { | |
| 2868 | + self.sub8_mode_col[i] = (usize::MAX, 0); | |
| 2869 | + self.uv_mode_col[i] = (usize::MAX, 0); | |
| 2870 | + } | |
| 2824 | 2871 | } |
| 2825 | 2872 | |
| 2826 | 2873 | /// Writes a just-decoded block's own palette-Y size/colours (`size == 0` |
| @@ -3089,6 +3136,10 @@ impl Neighbours { | ||
| 3089 | 3136 | self.left_comp_group_idx.iter_mut().for_each(|r| *r = 0); |
| 3090 | 3137 | self.left_compound_idx.iter_mut().for_each(|r| *r = 0); |
| 3091 | 3138 | self.left_filter.iter_mut().for_each(|f| *f = [3u8; 2]); |
| 3139 | + // lane-sub8 r6: mi-granular row maps reset with the rest of the left | |
| 3140 | + // context (a tile/SB-row boundary has no left neighbour). | |
| 3141 | + self.sub8_mode_row.iter_mut().for_each(|s| *s = (usize::MAX, 0)); | |
| 3142 | + self.uv_mode_row.iter_mut().for_each(|s| *s = (usize::MAX, 0)); | |
| 3092 | 3143 | } |
| 3093 | 3144 | |
| 3094 | 3145 | /// Records a block's `skip`/`is_inter`/`interp_filter` state for the next |
| @@ -3377,6 +3428,85 @@ impl Neighbours { | ||
| 3377 | 3428 | /// [`Self::partition_ctx`]) are the neighbour's own width/height per the |
| 3378 | 3429 | /// spec's per-edge partition-context rule, so a true rectangular block |
| 3379 | 3430 | /// naturally wants two different values here rather than one. |
| 3431 | + /// Writes this block's luma `mode` into the mi-granular | |
| 3432 | + /// [`Self::sub8_mode_col`]/[`Self::sub8_mode_row`] maps, keyed by the mi | |
| 3433 | + /// position a *later* neighbour would read it from: the block's LAST mi | |
| 3434 | + /// row for every column it spans (what the block below reads via | |
| 3435 | + /// `mi(row-1, col)`) and its LAST mi column for every row (what the | |
| 3436 | + /// block to the right reads via `mi(row, col-1)`). Only sub-8x8 leaves | |
| 3437 | + /// read these back, and only when the recorded position is exactly their | |
| 3438 | + /// own neighbour -- see [`Self::sub8_mode_col`]'s doc. | |
| 3439 | + fn record_mode_mi(&mut self, mi_r: usize, mi_c: usize, mi_w: usize, mi_h: usize, mode: usize) { | |
| 3440 | + let (last_r, last_c) = (mi_r + mi_h - 1, mi_c + mi_w - 1); | |
| 3441 | + for cell in 0..mi_w { | |
| 3442 | + if let Some(slot) = self.sub8_mode_col.get_mut(mi_c + cell) { | |
| 3443 | + *slot = (last_r, mode); | |
| 3444 | + } | |
| 3445 | + } | |
| 3446 | + for cell in 0..mi_h { | |
| 3447 | + if let Some(slot) = self.sub8_mode_row.get_mut(mi_r + cell) { | |
| 3448 | + *slot = (last_c, mode); | |
| 3449 | + } | |
| 3450 | + } | |
| 3451 | + } | |
| 3452 | + | |
| 3453 | + /// The mi-exact above/left neighbour luma mode for a block whose top-left | |
| 3454 | + /// mi is `(mi_r, mi_c)`, or `None` when no block has recorded that exact | |
| 3455 | + /// mi position (then the coarse [`SUB`]-grid slot is right by | |
| 3456 | + /// construction). See [`Self::record_mode_mi`]. | |
| 3457 | + fn mode_above_mi(&self, mi_r: usize, mi_c: usize) -> Option<usize> { | |
| 3458 | + match self.sub8_mode_col.get(mi_c) { | |
| 3459 | + Some(&(row, m)) if mi_r > self.tile_row0_mi && row == mi_r - 1 => Some(m), | |
| 3460 | + _ => None, | |
| 3461 | + } | |
| 3462 | + } | |
| 3463 | + | |
| 3464 | + fn mode_left_mi(&self, mi_r: usize, mi_c: usize) -> Option<usize> { | |
| 3465 | + match self.sub8_mode_row.get(mi_r) { | |
| 3466 | + Some(&(col, m)) if mi_c > self.tile_col0_mi && col == mi_c - 1 => Some(m), | |
| 3467 | + _ => None, | |
| 3468 | + } | |
| 3469 | + } | |
| 3470 | + | |
| 3471 | + /// [`Self::record_mode_mi`] for the block's `uv_mode`, into | |
| 3472 | + /// [`Self::uv_mode_col`]/[`Self::uv_mode_row`]. | |
| 3473 | + fn record_uv_mode_mi( | |
| 3474 | + &mut self, | |
| 3475 | + mi_r: usize, | |
| 3476 | + mi_c: usize, | |
| 3477 | + mi_w: usize, | |
| 3478 | + mi_h: usize, | |
| 3479 | + uv_mode: usize, | |
| 3480 | + ) { | |
| 3481 | + let (last_r, last_c) = (mi_r + mi_h - 1, mi_c + mi_w - 1); | |
| 3482 | + for cell in 0..mi_w { | |
| 3483 | + if let Some(slot) = self.uv_mode_col.get_mut(mi_c + cell) { | |
| 3484 | + *slot = (last_r, uv_mode); | |
| 3485 | + } | |
| 3486 | + } | |
| 3487 | + for cell in 0..mi_h { | |
| 3488 | + if let Some(slot) = self.uv_mode_row.get_mut(mi_r + cell) { | |
| 3489 | + *slot = (last_c, uv_mode); | |
| 3490 | + } | |
| 3491 | + } | |
| 3492 | + } | |
| 3493 | + | |
| 3494 | + /// Whether either mi-exact chroma neighbour of the block at `(mi_r, mi_c)` | |
| 3495 | + /// coded a smooth `uv_mode` -- libaom's `intra_edge_filter_type` for | |
| 3496 | + /// planes 1/2. Falls back to the coarse [`SUB`] slot on whichever axis no | |
| 3497 | + /// block has recorded the exact neighbouring mi. | |
| 3498 | + fn smooth_uv_neighbour(&self, mi_r: usize, mi_c: usize, r: usize, c: usize) -> bool { | |
| 3499 | + let above = match self.uv_mode_col.get(mi_c) { | |
| 3500 | + Some(&(row, m)) if mi_r > self.tile_row0_mi && row == mi_r - 1 => m, | |
| 3501 | + _ => self.above_uv_mode[c], | |
| 3502 | + }; | |
| 3503 | + let left = match self.uv_mode_row.get(mi_r) { | |
| 3504 | + Some(&(col, m)) if mi_c > self.tile_col0_mi && col == mi_c - 1 => m, | |
| 3505 | + _ => self.left_uv_mode[r], | |
| 3506 | + }; | |
| 3507 | + is_smooth_mode(above) || is_smooth_mode(left) | |
| 3508 | + } | |
| 3509 | + | |
| 3380 | 3510 | fn record_rect( |
| 3381 | 3511 | &mut self, |
| 3382 | 3512 | at: (usize, usize), |
| @@ -3397,6 +3527,8 @@ impl Neighbours { | ||
| 3397 | 3527 | self.left_uv_mode[r + cell] = uv_mode; |
| 3398 | 3528 | self.left_side[r + cell] = h; |
| 3399 | 3529 | } |
| 3530 | + self.record_mode_mi(r * (SUB / MI), c * (SUB / MI), w / MI, h / MI, mode); | |
| 3531 | + self.record_uv_mode_mi(r * (SUB / MI), c * (SUB / MI), w / MI, h / MI, uv_mode); | |
| 3400 | 3532 | self.record_mi_rect((r * (SUB / MI), c * (SUB / MI)), w, h, grids); |
| 3401 | 3533 | } |
| 3402 | 3534 | |
| @@ -3526,6 +3658,8 @@ impl Neighbours { | ||
| 3526 | 3658 | } |
| 3527 | 3659 | let (mi_r, mi_c) = (r * (SUB / MI), c * (SUB / MI)); |
| 3528 | 3660 | let (w_mi, h_mi) = (w / MI, h / MI); |
| 3661 | + self.record_mode_mi(mi_r, mi_c, w_mi, h_mi, mode); | |
| 3662 | + self.record_uv_mode_mi(mi_r, mi_c, w_mi, h_mi, uv_mode); | |
| 3529 | 3663 | for cell in 0..h_mi { |
| 3530 | 3664 | self.left_side_mi[mi_r + cell] = h; |
| 3531 | 3665 | } |
| @@ -4846,6 +4980,11 @@ fn decode_leaf_rect( | ||
| 4846 | 4980 | vec![0i32; chroma_w * chroma_h], |
| 4847 | 4981 | ], |
| 4848 | 4982 | ); |
| 4983 | + // lane-sub8 r6: the caller patches only the coarse `above_mode`/ | |
| 4984 | + // `left_mode` slot (one value for the whole 16x16), so record this | |
| 4985 | + // strip's own span mi-exactly like every square leaf does. | |
| 4986 | + neighbours.record_mode_mi(leaf_mi.0, leaf_mi.1, mi_w, mi_h, mode); | |
| 4987 | + neighbours.record_uv_mode_mi(leaf_mi.0, leaf_mi.1, mi_w, mi_h, uv_predict_mode); | |
| 4849 | 4988 | neighbours.fill_skip_grid_rect(leaf_mi, mi_w, mi_h, skip); |
| 4850 | 4989 | neighbours.fill_lf_grid_rect(leaf_mi, mi_w, mi_h, bw as u8, bh as u8, 0); |
| 4851 | 4990 | Ok(mode) |
| @@ -5357,7 +5496,7 @@ fn read_intra_mode( | ||
| 5357 | 5496 | } |
| 5358 | 5497 | let skip = dec.symbol(&mut cdfs.skip[skip_ctx]) != 0; |
| 5359 | 5498 | if trace { |
| 5360 | - eprintln!("TRACE skip value={}", skip as i32); | |
| 5499 | + eprintln!("TRACE skip value={} rng={}", skip as i32, dec.debug_state().0); | |
| 5361 | 5500 | } |
| 5362 | 5501 | istep!("skip", skip as i32); |
| 5363 | 5502 | if !seg_id_pre_skip() { |
| @@ -5403,7 +5542,7 @@ fn read_intra_mode( | ||
| 5403 | 5542 | let left_ctx = INTRA_MODE_CTX[left_mode]; |
| 5404 | 5543 | let mode = dec.symbol(&mut cdfs.kf_y_mode[above_ctx][left_ctx]); |
| 5405 | 5544 | if trace { |
| 5406 | - eprintln!("TRACE y_mode ctx=({above_ctx},{left_ctx}) value={mode}"); | |
| 5545 | + eprintln!("TRACE y_mode ctx=({above_ctx},{left_ctx}) value={mode} rng={}", dec.debug_state().0); | |
| 5407 | 5546 | } |
| 5408 | 5547 | istep!("mode", mode as i32); |
| 5409 | 5548 | let angle_delta_y = if (V_PRED..=D67_PRED).contains(&mode) { |
| @@ -5425,7 +5564,7 @@ fn read_intra_mode( | ||
| 5425 | 5564 | dec.symbol(&mut cdfs.uv_mode_no_cfl[mode]) |
| 5426 | 5565 | }; |
| 5427 | 5566 | if trace { |
| 5428 | - eprintln!("TRACE uv_mode cfl={cfl} y_mode={mode} value={uv_mode}"); | |
| 5567 | + eprintln!("TRACE uv_mode cfl={cfl} y_mode={mode} value={uv_mode} rng={}", dec.debug_state().0); | |
| 5429 | 5568 | } |
| 5430 | 5569 | istep!("uv_mode", uv_mode as i32); |
| 5431 | 5570 | let alpha = if cfl && uv_mode == UV_CFL_PRED { |
| @@ -5544,7 +5683,7 @@ fn read_intra_mode( | ||
| 5544 | 5683 | let use_filter_intra = dec.symbol(&mut cdfs.filter_intra[class]) != 0; |
| 5545 | 5684 | if trace { |
| 5546 | 5685 | eprintln!( |
| 5547 | - "TRACE use_filter_intra side={side} value={}", | |
| 5686 | + "TRACE use_filter_intra side={side} rng={} value={}", dec.debug_state().0, | |
| 5548 | 5687 | use_filter_intra as i32 |
| 5549 | 5688 | ); |
| 5550 | 5689 | } |
| @@ -6575,9 +6714,26 @@ fn decode_leaf8( | ||
| 6575 | 6714 | left_mode = pmode; |
| 6576 | 6715 | } |
| 6577 | 6716 | } |
| 6578 | - // See [`PlaneBuf::reconstruct`]'s doc: chroma stays `false` (exact) until | |
| 6579 | - // a smooth/paeth `uv_mode` can reach decode at all. | |
| 6717 | + // The mi-exact neighbour wins over both the coarse 16x16 slot and | |
| 6718 | + // `prev_leaf`: one 16x16 slot cannot hold the two different modes its | |
| 6719 | + // two 8x8 (or four 4x4) columns leave behind, so a leaf whose above/left | |
| 6720 | + // neighbour sits in a split cell read the wrong `kf_y_mode` row. | |
| 6721 | + if let Some(m) = neighbours.mode_above_mi(leaf_mi.0, leaf_mi.1) { | |
| 6722 | + above_mode = m; | |
| 6723 | + } | |
| 6724 | + if let Some(m) = neighbours.mode_left_mi(leaf_mi.0, leaf_mi.1) { | |
| 6725 | + left_mode = m; | |
| 6726 | + } | |
| 6580 | 6727 | let smooth_neighbor = is_smooth_mode(above_mode) || is_smooth_mode(left_mode); |
| 6728 | + // Chroma's edge-filter type reads the CHROMA neighbour's `uv_mode` | |
| 6729 | + // (`get_intra_edge_filter_type`, reconintra.c:974), never the luma mode | |
| 6730 | + // this leaf's `smooth_neighbor` is built from -- passing `false` here | |
| 6731 | + // filtered a directional chroma block's edge at the wrong strength | |
| 6732 | + // (lane-sub8 r5: 4 pixels of one 8x8 leaf's chroma, deltas 1..3). | |
| 6733 | + // The `uv_mode` neighbours are mi-exact (`uv_mode_col`/`uv_mode_row`), | |
| 6734 | + // with the coarse [`SUB`] slot as the fallback when no block recorded | |
| 6735 | + // that exact mi cell. | |
| 6736 | + let smooth_neighbor_uv = neighbours.smooth_uv_neighbour(leaf_mi.0, leaf_mi.1, r, c); | |
| 6581 | 6737 | if smooth_neighbor { |
| 6582 | 6738 | SMOOTH_LUMA_HITS.with(|c| c.set(c.get() + 1)); |
| 6583 | 6739 | } |
| @@ -6606,6 +6762,9 @@ fn decode_leaf8( | ||
| 6606 | 6762 | } else { |
| 6607 | 6763 | uv_mode |
| 6608 | 6764 | }; |
| 6765 | + neighbours.above_uv_mode[c] = uv_predict_mode; | |
| 6766 | + neighbours.left_uv_mode[r] = uv_predict_mode; | |
| 6767 | + neighbours.record_uv_mode_mi(leaf_mi.0, leaf_mi.1, 2, 2, uv_predict_mode); | |
| 6609 | 6768 | // `TxMode::Select`'s `tx_depth` at an 8x8 leaf (spec 5.11.16): the only |
| 6610 | 6769 | // depths an 8x8 block offers are `TX8` (depth 0) and `TX4` (depth 1, |
| 6611 | 6770 | // which splits the leaf's own 8x8 prediction into a 2x2 grid of 4x4 |
| @@ -6644,7 +6803,7 @@ fn decode_leaf8( | ||
| 6644 | 6803 | &vec![0i32; 16], |
| 6645 | 6804 | alpha.zip(ac.as_deref()).map(|((au, _), ac)| (au, ac)), |
| 6646 | 6805 | None, |
| 6647 | - false, | |
| 6806 | + smooth_neighbor_uv, | |
| 6648 | 6807 | ); |
| 6649 | 6808 | v.reconstruct( |
| 6650 | 6809 | cpx, |
| @@ -6656,7 +6815,7 @@ fn decode_leaf8( | ||
| 6656 | 6815 | &vec![0i32; 16], |
| 6657 | 6816 | alpha.zip(ac.as_deref()).map(|((_, av), ac)| (av, ac)), |
| 6658 | 6817 | None, |
| 6659 | - false, | |
| 6818 | + smooth_neighbor_uv, | |
| 6660 | 6819 | ); |
| 6661 | 6820 | luma_grid = vec![0i32; 64]; |
| 6662 | 6821 | u_grid = vec![0i32; 16]; |
| @@ -6710,7 +6869,7 @@ fn decode_leaf8( | ||
| 6710 | 6869 | alpha.zip(ac.as_deref()).map(|((au, _), ac)| (au, ac)), |
| 6711 | 6870 | None, |
| 6712 | 6871 | None, |
| 6713 | - false, | |
| 6872 | + smooth_neighbor_uv, | |
| 6714 | 6873 | )?; |
| 6715 | 6874 | v_grid = read_plane( |
| 6716 | 6875 | dec, |
| @@ -6732,7 +6891,7 @@ fn decode_leaf8( | ||
| 6732 | 6891 | alpha.zip(ac.as_deref()).map(|((_, av), ac)| (av, ac)), |
| 6733 | 6892 | None, |
| 6734 | 6893 | None, |
| 6735 | - false, | |
| 6894 | + smooth_neighbor_uv, | |
| 6736 | 6895 | )?; |
| 6737 | 6896 | } else { |
| 6738 | 6897 | // `tx_depth` resolved this leaf's luma to `TX4`: a 2x2 raster-order |
| @@ -6808,7 +6967,7 @@ fn decode_leaf8( | ||
| 6808 | 6967 | alpha.zip(ac.as_deref()).map(|((au, _), ac)| (au, ac)), |
| 6809 | 6968 | None, |
| 6810 | 6969 | None, |
| 6811 | - false, | |
| 6970 | + smooth_neighbor_uv, | |
| 6812 | 6971 | )?; |
| 6813 | 6972 | v_grid = read_plane( |
| 6814 | 6973 | dec, |
| @@ -6830,7 +6989,7 @@ fn decode_leaf8( | ||
| 6830 | 6989 | alpha.zip(ac.as_deref()).map(|((_, av), ac)| (av, ac)), |
| 6831 | 6990 | None, |
| 6832 | 6991 | None, |
| 6833 | - false, | |
| 6992 | + smooth_neighbor_uv, | |
| 6834 | 6993 | )?; |
| 6835 | 6994 | // `record_split_luma` expects a `record`-style `(r, c)` position in |
| 6836 | 6995 | // `SUB`-grid units and rescales it by `SUB / MI`; `leaf_mi` is |
| @@ -6862,14 +7021,290 @@ fn decode_leaf8( | ||
| 6862 | 7021 | } |
| 6863 | 7022 | neighbours.fill_skip_grid(leaf_mi, 2, skip); |
| 6864 | 7023 | neighbours.fill_lf_grid(leaf_mi, 2, 4, 0); |
| 7024 | + neighbours.record_mode_mi(leaf_mi.0, leaf_mi.1, 2, 2, mode); | |
| 6865 | 7025 | return Ok(mode); |
| 6866 | 7026 | } |
| 6867 | 7027 | neighbours.record_mi(leaf_mi, 8, &[luma_grid, u_grid, v_grid]); |
| 6868 | 7028 | neighbours.fill_skip_grid(leaf_mi, 2, skip); |
| 6869 | 7029 | neighbours.fill_lf_grid(leaf_mi, 2, 8, 0); |
| 7030 | + neighbours.record_mode_mi(leaf_mi.0, leaf_mi.1, 2, 2, mode); | |
| 6870 | 7031 | Ok(mode) |
| 6871 | 7032 | } |
| 6872 | 7033 | |
| 7034 | +/// `read_intra_frame_mode_info`'s mode-info read for one `BLOCK_4X4` leaf | |
| 7035 | +/// below an 8x8 partition (spec `decode_partition`'s `bSize < BLOCK_8X8` | |
| 7036 | +/// bottom, where no partition symbol is read at all -- `decode_block` runs | |
| 7037 | +/// directly). No palette (`av1_allow_palette` needs both dims >= 8, spec | |
| 7038 | +/// blockd.h) and no `read_tx_size` (a sub-8x8 block's transform is always | |
| 7039 | +/// its own bsize, spec 5.11.16). `has_chroma` follows `is_chroma_reference` | |
| 7040 | +/// (spec/libaom `av1_common_int.h`): for 4:2:0, only the bottom-right leaf | |
| 7041 | +/// of the 2x2 4x4 group carries chroma syntax at all. | |
| 7042 | +#[allow(clippy::too_many_arguments)] | |
| 7043 | +fn read_intra_mode_sub8( | |
| 7044 | + dec: &mut SymbolDecoder, | |
| 7045 | + cdfs: &mut Cdfs, | |
| 7046 | + above_mode: usize, | |
| 7047 | + left_mode: usize, | |
| 7048 | + has_chroma: bool, | |
| 7049 | + enable_filter_intra: bool, | |
| 7050 | + skip_ctx: usize, | |
| 7051 | + allow_intrabc: bool, | |
| 7052 | + mi_r: usize, | |
| 7053 | + mi_c: usize, | |
| 7054 | +) -> Result<(bool, usize, i32, Option<(usize, i32, Option<(i32, i32)>)>, Option<usize>)> { | |
| 7055 | + let trace = std::env::var_os("EC_AV1_TRACE").is_some(); | |
| 7056 | + let skip = dec.symbol(&mut cdfs.skip[skip_ctx]) != 0; | |
| 7057 | + if trace { | |
| 7058 | + eprintln!("TRACE sub8 skip mi=({mi_r},{mi_c}) ctx={skip_ctx} value={} rng={}", skip as i32, dec.debug_state().0); | |
| 7059 | + } | |
| 7060 | + maybe_read_cdef_idx(dec, mi_r, mi_c, skip); | |
| 7061 | + maybe_read_delta_q(dec, cdfs, mi_r, mi_c, false, skip); | |
| 7062 | + maybe_read_delta_lf(dec, cdfs, mi_r, mi_c, false, skip); | |
| 7063 | + if allow_intrabc { | |
| 7064 | + let use_intrabc = dec.symbol(&mut cdfs.intrabc) != 0; | |
| 7065 | + if use_intrabc { | |
| 7066 | + return Err(unsupported( | |
| 7067 | + "a sub-8x8 leaf that uses intrabc (this reader has no block-vector path; the 8x8-and-up reader reconstructs one)", | |
| 7068 | + )); | |
| 7069 | + } | |
| 7070 | + } | |
| 7071 | + let above_ctx = INTRA_MODE_CTX[above_mode]; | |
| 7072 | + let left_ctx = INTRA_MODE_CTX[left_mode]; | |
| 7073 | + let mode = dec.symbol(&mut cdfs.kf_y_mode[above_ctx][left_ctx]); | |
| 7074 | + if trace { | |
| 7075 | + eprintln!("TRACE sub8 y_mode mi=({mi_r},{mi_c}) ctx=({above_ctx},{left_ctx}) value={mode} rng={}", dec.debug_state().0); | |
| 7076 | + } | |
| 7077 | + // No `angle_delta` at all below 8x8: spec 5.11.6's `intra_angle_info_y`/ | |
| 7078 | + // `_uv` are gated on `MiSize >= BLOCK_8X8` (libaom `av1_use_angle_delta`, | |
| 7079 | + // blockd.h), so a directional mode on a `BLOCK_4X4` leaf carries no delta | |
| 7080 | + // symbol. Reading one consumed a symbol the encoder never wrote and | |
| 7081 | + // desynced the tile at the very next element. | |
| 7082 | + let angle_delta_y = 0; | |
| 7083 | + let chroma = if has_chroma { | |
| 7084 | + let uv_mode = dec.symbol(&mut cdfs.uv_mode_cfl[mode]); | |
| 7085 | + if trace { | |
| 7086 | + eprintln!("TRACE sub8 uv_mode value={uv_mode} rng={}", dec.debug_state().0); | |
| 7087 | + } | |
| 7088 | + if (9..=12).contains(&uv_mode) { | |
| 7089 | + SMOOTH_UV_HITS.with(|c| c.set(c.get() + 1)); | |
| 7090 | + } | |
| 7091 | + let alpha = if uv_mode == UV_CFL_PRED { | |
| 7092 | + Some(read_cfl_alphas(dec, cdfs)) | |
| 7093 | + } else { | |
| 7094 | + None | |
| 7095 | + }; | |
| 7096 | + if (V_PRED..=D67_PRED).contains(&uv_mode) { | |
| 7097 | + DIRECTIONAL_UV_HITS.with(|c| c.set(c.get() + 1)); | |
| 7098 | + } | |
| 7099 | + // See the luma comment above: no angle delta below 8x8. | |
| 7100 | + let angle_delta_uv = 0; | |
| 7101 | + Some((uv_mode, angle_delta_uv, alpha)) | |
| 7102 | + } else { | |
| 7103 | + None | |
| 7104 | + }; | |
| 7105 | + let mut filter_intra = None; | |
| 7106 | + if mode == DC_PRED && enable_filter_intra { | |
| 7107 | + // `BLOCK_4X4`'s own row (class 0, `filter_intra_size_class(4)`) -- | |
| 7108 | + // every sub-8x8 leaf here is a `BLOCK_4X4`. | |
| 7109 | + let use_filter_intra = dec.symbol(&mut cdfs.filter_intra[0]) != 0; | |
| 7110 | + if trace { | |
| 7111 | + eprintln!("TRACE sub8 use_filter_intra value={}", use_filter_intra as i32); | |
| 7112 | + } | |
| 7113 | + if use_filter_intra { | |
| 7114 | + FILTER_INTRA_HITS.with(|c| c.set(c.get() + 1)); | |
| 7115 | + let fi_mode = dec.symbol(&mut cdfs.filter_intra_mode); | |
| 7116 | + filter_intra = Some(fi_mode); | |
| 7117 | + } | |
| 7118 | + } | |
| 7119 | + Ok((skip, mode, angle_delta_y, chroma, filter_intra)) | |
| 7120 | +} | |
| 7121 | + | |
| 7122 | +/// Decodes a `PARTITION_SPLIT` of one 8x8 block into four `BLOCK_4X4` leaves | |
| 7123 | +/// (spec `decode_partition`'s recursion bottom), sharing [`decode_leaf8`]'s | |
| 7124 | +/// own signature so its caller's `prev_leaf`/`above_mode`/`left_mode` | |
| 7125 | +/// bookkeeping needs no change. Each leaf reads its own luma mode info, | |
| 7126 | +/// neighboured off the *previously decoded leaf in this same group* on | |
| 7127 | +/// whichever axis is adjacent (mirroring [`decode_leaf8`]'s own `prev_leaf` | |
| 7128 | +/// pattern, one level deeper); chroma is read and reconstructed exactly | |
| 7129 | +/// once, on the last (bottom-right) leaf, at the whole 8x8 group's own 4x4 | |
| 7130 | +/// chroma unit -- [`read_intra_mode_sub8`]'s doc has the `is_chroma_reference` | |
| 7131 | +/// derivation. | |
| 7132 | +#[allow(clippy::too_many_arguments)] | |
| 7133 | +fn decode_leaf_split4( | |
| 7134 | + dec: &mut SymbolDecoder, | |
| 7135 | + cdfs: &mut Cdfs, | |
| 7136 | + neighbours: &mut Neighbours, | |
| 7137 | + outer_at: (usize, usize), | |
| 7138 | + leaf_mi: (usize, usize), | |
| 7139 | + scan4: &[u16], | |
| 7140 | + prev_leaf: Option<((usize, usize), usize)>, | |
| 7141 | + y: &mut PlaneBuf, | |
| 7142 | + u: &mut PlaneBuf, | |
| 7143 | + v: &mut PlaneBuf, | |
| 7144 | + base_q_idx: u8, | |
| 7145 | + enable_filter_intra: bool, | |
| 7146 | + allow_intrabc: bool, | |
| 7147 | + reduced_tx_set: bool, | |
| 7148 | + // Returns `(below_mode, right_mode)`: the mode a neighbour BELOW this 8x8 | |
| 7149 | + // group sees (its bottom-left 4x4, libaom reads mi(row-1, col)) and the | |
| 7150 | + // one a neighbour to its RIGHT sees (its top-right 4x4, mi(row, col-1)). | |
| 7151 | +) -> Result<(usize, usize)> { | |
| 7152 | + SUB8_SPLIT_HITS.with(|c| c.set(c.get() + 1)); | |
| 7153 | + let (r, c) = outer_at; | |
| 7154 | + let mut above_mode = neighbours.above_mode[c]; | |
| 7155 | + let mut left_mode = neighbours.left_mode[r]; | |
| 7156 | + if let Some(((pr, pc), pmode)) = prev_leaf { | |
| 7157 | + if pc == leaf_mi.1 && leaf_mi.0 == pr + 2 { | |
| 7158 | + above_mode = pmode; | |
| 7159 | + } else if pr == leaf_mi.0 && leaf_mi.1 == pc + 2 { | |
| 7160 | + left_mode = pmode; | |
| 7161 | + } | |
| 7162 | + } | |
| 7163 | + // See `decode_leaf8`'s own `smooth_neighbor_uv`: the chroma edge-filter | |
| 7164 | + // type is the chroma neighbours' `uv_mode`, mi-exact where recorded. | |
| 7165 | + let smooth_neighbor_uv = neighbours.smooth_uv_neighbour(leaf_mi.0, leaf_mi.1, r, c); | |
| 7166 | + let mut leaf_modes = [0usize; 4]; | |
| 7167 | + let mut leaf_skips = [false; 4]; | |
| 7168 | + let mut last_uv: Option<(usize, i32, Option<(i32, i32)>)> = None; | |
| 7169 | + for i in 0..4usize { | |
| 7170 | + let (dr, dc) = (i / 2, i % 2); | |
| 7171 | + let lmi = (leaf_mi.0 + dr, leaf_mi.1 + dc); | |
| 7172 | + // Neighbour modes at real mi granularity: inside the group the | |
| 7173 | + // sibling leaf, outside it the split-leaf map when the adjacent mi | |
| 7174 | + // was itself a 4x4 leaf, else the coarse 16x16 slot (see | |
| 7175 | + // `sub8_mode_col`'s doc). | |
| 7176 | + let leaf_above = if dr == 0 { | |
| 7177 | + neighbours.mode_above_mi(lmi.0, lmi.1).unwrap_or(above_mode) | |
| 7178 | + } else { | |
| 7179 | + leaf_modes[i - 2] | |
| 7180 | + }; | |
| 7181 | + let leaf_left = if dc == 0 { | |
| 7182 | + neighbours.mode_left_mi(lmi.0, lmi.1).unwrap_or(left_mode) | |
| 7183 | + } else { | |
| 7184 | + leaf_modes[i - 1] | |
| 7185 | + }; | |
| 7186 | + let has_chroma = i == 3; | |
| 7187 | + let skip_ctx = neighbours.skip_txfm_ctx(lmi.0, lmi.1); | |
| 7188 | + let (skip, mode, angle_delta_y, chroma, filter_intra) = read_intra_mode_sub8( | |
| 7189 | + dec, cdfs, leaf_above, leaf_left, has_chroma, enable_filter_intra, skip_ctx, | |
| 7190 | + allow_intrabc, lmi.0, lmi.1, | |
| 7191 | + )?; | |
| 7192 | + leaf_modes[i] = mode; | |
| 7193 | + leaf_skips[i] = skip; | |
| 7194 | + neighbours.record_mode_mi(lmi.0, lmi.1, 1, 1, mode); | |
| 7195 | + let smooth_neighbor = is_smooth_mode(leaf_above) || is_smooth_mode(leaf_left); | |
| 7196 | + if smooth_neighbor { | |
| 7197 | + SMOOTH_LUMA_HITS.with(|c| c.set(c.get() + 1)); | |
| 7198 | + } | |
| 7199 | + let (px, py) = (lmi.1 * MI, lmi.0 * MI); | |
| 7200 | + let reach = Reach::of(4, px, py, y.width, y.height); | |
| 7201 | + if skip { | |
| 7202 | + y.reconstruct(px, py, 4, mode, angle_delta_y, reach, &vec![0i32; 16], None, filter_intra, smooth_neighbor); | |
| 7203 | + neighbours.record_mi_luma(lmi, 4, &vec![0i32; 16]); | |
| 7204 | + } else { | |
| 7205 | + let tu_around = neighbours.around_mi(lmi, 4)[0]; | |
| 7206 | + // A `BLOCK_4X4` leaf's luma TU *is* the whole block, so libaom's | |
| 7207 | + // `get_txb_ctx` takes its `plane_bsize == txsize_to_bsize[tx_size]` | |
| 7208 | + // branch: `txb_skip_ctx = 0`, never the neighbour-magnitude table | |
| 7209 | + // (`txb_common.h:400`). Reading the table here decoded `all_zero` | |
| 7210 | + // off the wrong CDF on the very first leaf and desynced the tile. | |
| 7211 | + let tu_grid = read_plane( | |
| 7212 | + dec, | |
| 7213 | + cdfs, | |
| 7214 | + if reduced_tx_set { TxbSet::Luma4 } else { TxbSet::Luma4Set1 }, | |
| 7215 | + scan4, | |
| 7216 | + 0, | |
| 7217 | + tu_around, | |
| 7218 | + mode, | |
| 7219 | + mode, | |
| 7220 | + angle_delta_y, | |
| 7221 | + reach, | |
| 7222 | + y, | |
| 7223 | + px, | |
| 7224 | + py, | |
| 7225 | + 4, | |
| 7226 | + 4, | |
| 7227 | + base_q_idx, | |
| 7228 | + None, | |
| 7229 | + filter_intra, | |
| 7230 | + None, | |
| 7231 | + smooth_neighbor, | |
| 7232 | + )?; | |
| 7233 | + neighbours.record_mi_luma(lmi, 4, &tu_grid); | |
| 7234 | + } | |
| 7235 | + neighbours.fill_skip_grid(lmi, 1, skip); | |
| 7236 | + neighbours.fill_lf_grid(lmi, 1, 4, 0); | |
| 7237 | + if has_chroma { | |
| 7238 | + last_uv = chroma; | |
| 7239 | + } | |
| 7240 | + } | |
| 7241 | + let (gpx, gpy) = (leaf_mi.1 * MI, leaf_mi.0 * MI); | |
| 7242 | + let (cpx, cpy) = (gpx / 2, gpy / 2); | |
| 7243 | + let group_reach = Reach::of(8, gpx, gpy, y.width, y.height); | |
| 7244 | + let (uv_mode, angle_delta_uv, alpha) = | |
| 7245 | + last_uv.expect("i==3 always sets has_chroma, so chroma is always Some"); | |
| 7246 | + let uv_predict_mode = if uv_mode == UV_CFL_PRED { DC_PRED } else { uv_mode }; | |
| 7247 | + neighbours.above_uv_mode[c] = uv_predict_mode; | |
| 7248 | + neighbours.left_uv_mode[r] = uv_predict_mode; | |
| 7249 | + neighbours.record_uv_mode_mi(leaf_mi.0, leaf_mi.1, 2, 2, uv_predict_mode); | |
| 7250 | + let (u_grid, v_grid): (Vec<i32>, Vec<i32>) = if leaf_skips[3] { | |
| 7251 | + u.reconstruct(cpx, cpy, 4, uv_predict_mode, angle_delta_uv, group_reach, &vec![0i32; 16], None, None, smooth_neighbor_uv); | |
| 7252 | + v.reconstruct(cpx, cpy, 4, uv_predict_mode, angle_delta_uv, group_reach, &vec![0i32; 16], None, None, smooth_neighbor_uv); | |
| 7253 | + (vec![0i32; 16], vec![0i32; 16]) | |
| 7254 | + } else { | |
| 7255 | + let ac = alpha.map(|_| cfl_ac_q3(y, gpx, gpy, 8)); | |
| 7256 | + let chroma_around = neighbours.around_mi(leaf_mi, 8); | |
| 7257 | + let ug = read_plane( | |
| 7258 | + dec, cdfs, TxbSet::Chroma4, scan4, 1, chroma_around[1], uv_mode, uv_predict_mode, | |
| 7259 | + angle_delta_uv, group_reach, u, cpx, cpy, 4, TX4, base_q_idx, | |
| 7260 | + alpha.zip(ac.as_deref()).map(|((au, _), ac)| (au, ac)), None, None, smooth_neighbor_uv, | |
| 7261 | + )?; | |
| 7262 | + let vg = read_plane( | |
| 7263 | + dec, cdfs, TxbSet::Chroma4, scan4, 2, chroma_around[2], uv_mode, uv_predict_mode, | |
| 7264 | + angle_delta_uv, group_reach, v, cpx, cpy, 4, TX4, base_q_idx, | |
| 7265 | + alpha.zip(ac.as_deref()).map(|((_, av), ac)| (av, ac)), None, None, smooth_neighbor_uv, | |
| 7266 | + )?; | |
| 7267 | + (ug, vg) | |
| 7268 | + }; | |
| 7269 | + // Chroma neighbour bookkeeping for the whole 8x8 group -- mirrors | |
| 7270 | + // [`decode_leaf8`]'s own tx4-chroma section (`record_split_luma`'s | |
| 7271 | + // rescaling is wrong for an already-mi-unit position, so this inlines | |
| 7272 | + // its tail directly at `leaf_mi`, side_mi=2), EXCEPT for the partition | |
| 7273 | + // context value itself. Unlike `decode_leaf8`'s TX4 branch (still one | |
| 7274 | + // `BLOCK_8X8`, `PARTITION_NONE`, transform depth only), this group is | |
| 7275 | + // genuinely four `BLOCK_4X4` blocks (`PARTITION_SPLIT` at the 8x8 | |
| 7276 | + // level, libaom `decode_partition`'s `bsize2`/`subsize` recursion | |
| 7277 | + // bottom). libaom's `update_ext_partition_context` writes | |
| 7278 | + // `partition_context_lookup[subsize]` at the 8x8 slot -- `{30,30}` for | |
| 7279 | + // `BLOCK_8X8` (bit0=0, what `decode_leaf8` already reproduces via | |
| 7280 | + // side_mi=8) but `{31,31}` for `BLOCK_4X4` (bit0=1) here, and | |
| 7281 | + // `partition_ctx_mi`'s `left_side_mi[mi_r]*2 <= side` needs | |
| 7282 | + // `left_side_mi <= 4` to read that bit as 1. Leaving this at 8 (this | |
| 7283 | + // round's bug) makes the very next sibling 8x8's `partition_w8` read | |
| 7284 | + // with the wrong context and desync immediately. | |
| 7285 | + let side_mi = 2; | |
| 7286 | + for cell in 0..side_mi { | |
| 7287 | + neighbours.left_side_mi[leaf_mi.0 + cell] = 4; | |
| 7288 | + neighbours.above_side_mi[leaf_mi.1 + cell] = 4; | |
| 7289 | + } | |
| 7290 | + let round_up_even = |n: usize| n.div_ceil(2) * 2; | |
| 7291 | + let bound_h = round_up_even(neighbours.mi_rows); | |
| 7292 | + let bound_w = round_up_even(neighbours.mi_cols); | |
| 7293 | + let u_state = neighbour_state(&u_grid); | |
| 7294 | + let v_state = neighbour_state(&v_grid); | |
| 7295 | + for cell in 0..side_mi { | |
| 7296 | + if cell < side_mi.min(bound_h.saturating_sub(leaf_mi.0)) { | |
| 7297 | + neighbours.left[leaf_mi.0 + cell][1] = u_state; | |
| 7298 | + neighbours.left[leaf_mi.0 + cell][2] = v_state; | |
| 7299 | + } | |
| 7300 | + if cell < side_mi.min(bound_w.saturating_sub(leaf_mi.1)) { | |
| 7301 | + neighbours.above[leaf_mi.1 + cell][1] = u_state; | |
| 7302 | + neighbours.above[leaf_mi.1 + cell][2] = v_state; | |
| 7303 | + } | |
| 7304 | + } | |
| 7305 | + Ok((leaf_modes[2], leaf_modes[1])) | |
| 7306 | +} | |
| 7307 | + | |
| 6873 | 7308 | /// Spec 7.15.3's `Cdef_Directions`: `(row, col)` offsets for the two primary |
| 6874 | 7309 | /// taps of each of the eight directions; the secondary taps at `dir+2`/`dir-2` |
| 6875 | 7310 | /// (mod 8) reuse the same table. |
| @@ -8952,11 +9387,38 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( | ||
| 8952 | 9387 | // the one or two the edge leaves. |
| 8953 | 9388 | let (mi_row0, mi_col0) = |
| 8954 | 9389 | (sr as u32 * SUB_MI, sc as u32 * SUB_MI); |
| 8955 | - let mut prev_leaf: Option<((usize, usize), usize)> = None; | |
| 9390 | + // Each 8x8 leaf's intra-mode context | |
| 9391 | + // must see its own siblings: the | |
| 9392 | + // bottom-left leaf's ABOVE neighbour | |
| 9393 | + // is leaf 0, not the previously | |
| 9394 | + // decoded leaf 1 (and the bottom-right | |
| 9395 | + // leaf's above is leaf 1, while | |
| 9396 | + // `prev_leaf` only ever carried the | |
| 9397 | + // immediately preceding one). The | |
| 9398 | + // coarse `above_mode`/`left_mode` | |
| 9399 | + // arrays hold one slot per 16x16, so | |
| 9400 | + // the sibling modes are swapped in | |
| 9401 | + // around each leaf call and restored | |
| 9402 | + // after; the loop tail writes the last | |
| 9403 | + // leaf's mode as before. | |
| 9404 | + let mut sib_modes: [Option<(usize, usize)>; 4] = [None; 4]; | |
| 8956 | 9405 | for i in 0..4 { |
| 8957 | 9406 | let (mr, mc) = |
| 8958 | 9407 | (mi_row0 + (i / 2) * 2, mi_col0 + (i % 2) * 2); |
| 8959 | 9408 | let leaf_mi = (mr as usize, mc as usize); |
| 9409 | + let li = i as usize; | |
| 9410 | + let saved_modes = | |
| 9411 | + (neighbours.above_mode[sc], neighbours.left_mode[sr]); | |
| 9412 | + if li >= 2 { | |
| 9413 | + if let Some((below, _)) = sib_modes[li - 2] { | |
| 9414 | + neighbours.above_mode[sc] = below; | |
| 9415 | + } | |
| 9416 | + } | |
| 9417 | + if li % 2 == 1 { | |
| 9418 | + if let Some((_, right)) = sib_modes[li - 1] { | |
| 9419 | + neighbours.left_mode[sr] = right; | |
| 9420 | + } | |
| 9421 | + } | |
| 8960 | 9422 | let leaf_ctx = neighbours.partition_ctx_mi(leaf_mi, 8); |
| 8961 | 9423 | let part8 = |
| 8962 | 9424 | dec.symbol(&mut cdfs.partition_w8[leaf_ctx]); |
| @@ -8965,34 +9427,56 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( | ||
| 8965 | 9427 | "TRACE partition_w8 mi=({mr},{mc}) ctx={leaf_ctx} value={part8}" |
| 8966 | 9428 | ); |
| 8967 | 9429 | } |
| 8968 | - if part8 != PARTITION_NONE { | |
| 9430 | + let leaf_mode = if part8 == PARTITION_NONE { | |
| 9431 | + decode_leaf8( | |
| 9432 | + &mut dec, | |
| 9433 | + &mut cdfs, | |
| 9434 | + &mut neighbours, | |
| 9435 | + at16, | |
| 9436 | + leaf_mi, | |
| 9437 | + (&scan8, &scan4), | |
| 9438 | + None, | |
| 9439 | + &mut y, | |
| 9440 | + &mut u, | |
| 9441 | + &mut v, | |
| 9442 | + base_q_idx, | |
| 9443 | + enable_filter_intra, | |
| 9444 | + allow_screen_content_tools, | |
| 9445 | + allow_intrabc, | |
| 9446 | + tx_select, | |
| 9447 | + reduced_tx_set, | |
| 9448 | + ).map(|m| (m, m))? | |
| 9449 | + } else if part8 == PARTITION_SPLIT { | |
| 9450 | + decode_leaf_split4( | |
| 9451 | + &mut dec, | |
| 9452 | + &mut cdfs, | |
| 9453 | + &mut neighbours, | |
| 9454 | + at16, | |
| 9455 | + leaf_mi, | |
| 9456 | + &scan4, | |
| 9457 | + None, | |
| 9458 | + &mut y, | |
| 9459 | + &mut u, | |
| 9460 | + &mut v, | |
| 9461 | + base_q_idx, | |
| 9462 | + enable_filter_intra, | |
| 9463 | + allow_intrabc, | |
| 9464 | + reduced_tx_set, | |
| 9465 | + )? | |
| 9466 | + } else { | |
| 8969 | 9467 | return Err(unsupported( |
| 8970 | - "a partition below 8x8 (this decoder codes no leaf smaller than 8x8)", | |
| 9468 | + "a HORZ/VERT partition below 8x8 (this decoder's transform primitive is square-only; 4x8/8x4 need a real rectangular transform)", | |
| 8971 | 9469 | )); |
| 8972 | - } | |
| 8973 | - let leaf_mode = decode_leaf8( | |
| 8974 | - &mut dec, | |
| 8975 | - &mut cdfs, | |
| 8976 | - &mut neighbours, | |
| 8977 | - at16, | |
| 8978 | - leaf_mi, | |
| 8979 | - (&scan8, &scan4), | |
| 8980 | - prev_leaf, | |
| 8981 | - &mut y, | |
| 8982 | - &mut u, | |
| 8983 | - &mut v, | |
| 8984 | - base_q_idx, | |
| 8985 | - enable_filter_intra, | |
| 8986 | - allow_screen_content_tools, | |
| 8987 | - allow_intrabc, | |
| 8988 | - tx_select, | |
| 8989 | - reduced_tx_set, | |
| 8990 | - )?; | |
| 8991 | - prev_leaf = Some((leaf_mi, leaf_mode)); | |
| 9470 | + }; | |
| 9471 | + neighbours.above_mode[sc] = saved_modes.0; | |
| 9472 | + neighbours.left_mode[sr] = saved_modes.1; | |
| 9473 | + sib_modes[li] = Some(leaf_mode); | |
| 8992 | 9474 | } |
| 8993 | - if let Some((_, mode)) = prev_leaf { | |
| 8994 | - neighbours.above_mode[sc] = mode; | |
| 8995 | - neighbours.left_mode[sr] = mode; | |
| 9475 | + if let Some((below, _)) = sib_modes[2].or(sib_modes[3]).or(sib_modes[0]) { | |
| 9476 | + neighbours.above_mode[sc] = below; | |
| 9477 | + } | |
| 9478 | + if let Some((_, right)) = sib_modes[1].or(sib_modes[3]).or(sib_modes[0]) { | |
| 9479 | + neighbours.left_mode[sr] = right; | |
| 8996 | 9480 | } |
| 8997 | 9481 | continue; |
| 8998 | 9482 | } |
| @@ -9026,9 +9510,25 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( | ||
| 9026 | 9510 | .map(|i| (mi_row0 + (i / 2) * 2, mi_col0 + (i % 2) * 2)) |
| 9027 | 9511 | .filter(|&(mr, mc)| mr < mi_rows && mc < mi_cols) |
| 9028 | 9512 | .collect(); |
| 9029 | - let mut prev_leaf: Option<((usize, usize), usize)> = None; | |
| 9513 | + // See the sibling-mode note in the clean | |
| 9514 | + // SPLIT path above. | |
| 9515 | + let mut sib_modes: [Option<(usize, usize)>; 4] = [None; 4]; | |
| 9030 | 9516 | for (mr, mc) in leaf_positions { |
| 9031 | 9517 | let leaf_mi = (mr as usize, mc as usize); |
| 9518 | + let li = (((mr - mi_row0) / 2) * 2 + (mc - mi_col0) / 2) | |
| 9519 | + as usize; | |
| 9520 | + let saved_modes = | |
| 9521 | + (neighbours.above_mode[sc], neighbours.left_mode[sr]); | |
| 9522 | + if li >= 2 { | |
| 9523 | + if let Some((below, _)) = sib_modes[li - 2] { | |
| 9524 | + neighbours.above_mode[sc] = below; | |
| 9525 | + } | |
| 9526 | + } | |
| 9527 | + if li % 2 == 1 { | |
| 9528 | + if let Some((_, right)) = sib_modes[li - 1] { | |
| 9529 | + neighbours.left_mode[sr] = right; | |
| 9530 | + } | |
| 9531 | + } | |
| 9032 | 9532 | let leaf_ctx = neighbours.partition_ctx_mi(leaf_mi, 8); |
| 9033 | 9533 | let part8 = dec.symbol(&mut cdfs.partition_w8[leaf_ctx]); |
| 9034 | 9534 | if std::env::var_os("EC_AV1_TRACE").is_some() { |
| @@ -9036,30 +9536,50 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( | ||
| 9036 | 9536 | "TRACE partition_w8 mi=({mr},{mc}) ctx={leaf_ctx} value={part8}" |
| 9037 | 9537 | ); |
| 9038 | 9538 | } |
| 9039 | - if part8 != PARTITION_NONE { | |
| 9539 | + let leaf_mode = if part8 == PARTITION_NONE { | |
| 9540 | + decode_leaf8( | |
| 9541 | + &mut dec, | |
| 9542 | + &mut cdfs, | |
| 9543 | + &mut neighbours, | |
| 9544 | + at16, | |
| 9545 | + leaf_mi, | |
| 9546 | + (&scan8, &scan4), | |
| 9547 | + None, | |
| 9548 | + &mut y, | |
| 9549 | + &mut u, | |
| 9550 | + &mut v, | |
| 9551 | + base_q_idx, | |
| 9552 | + enable_filter_intra, | |
| 9553 | + allow_screen_content_tools, | |
| 9554 | + allow_intrabc, | |
| 9555 | + tx_select, | |
| 9556 | + reduced_tx_set, | |
| 9557 | + ).map(|m| (m, m))? | |
| 9558 | + } else if part8 == PARTITION_SPLIT { | |
| 9559 | + decode_leaf_split4( | |
| 9560 | + &mut dec, | |
| 9561 | + &mut cdfs, | |
| 9562 | + &mut neighbours, | |
| 9563 | + at16, | |
| 9564 | + leaf_mi, | |
| 9565 | + &scan4, | |
| 9566 | + None, | |
| 9567 | + &mut y, | |
| 9568 | + &mut u, | |
| 9569 | + &mut v, | |
| 9570 | + base_q_idx, | |
| 9571 | + enable_filter_intra, | |
| 9572 | + allow_intrabc, | |
| 9573 | + reduced_tx_set, | |
| 9574 | + )? | |
| 9575 | + } else { | |
| 9040 | 9576 | return Err(unsupported( |
| 9041 | - "a partition below 8x8 (this decoder codes no leaf smaller than 8x8)", | |
| 9577 | + "a HORZ/VERT partition below 8x8 (this decoder's transform primitive is square-only; 4x8/8x4 need a real rectangular transform)", | |
| 9042 | 9578 | )); |
| 9043 | - } | |
| 9044 | - let leaf_mode = decode_leaf8( | |
| 9045 | - &mut dec, | |
| 9046 | - &mut cdfs, | |
| 9047 | - &mut neighbours, | |
| 9048 | - at16, | |
| 9049 | - leaf_mi, | |
| 9050 | - (&scan8, &scan4), | |
| 9051 | - prev_leaf, | |
| 9052 | - &mut y, | |
| 9053 | - &mut u, | |
| 9054 | - &mut v, | |
| 9055 | - base_q_idx, | |
| 9056 | - enable_filter_intra, | |
| 9057 | - allow_screen_content_tools, | |
| 9058 | - allow_intrabc, | |
| 9059 | - tx_select, | |
| 9060 | - reduced_tx_set, | |
| 9061 | - )?; | |
| 9062 | - prev_leaf = Some((leaf_mi, leaf_mode)); | |
| 9579 | + }; | |
| 9580 | + neighbours.above_mode[sc] = saved_modes.0; | |
| 9581 | + neighbours.left_mode[sr] = saved_modes.1; | |
| 9582 | + sib_modes[li] = Some(leaf_mode); | |
| 9063 | 9583 | } |
| 9064 | 9584 | // `record()`'s `above_mode`/`left_mode` |
| 9065 | 9585 | // write is a no-op at an 8x8 leaf's own |
| @@ -9067,9 +9587,11 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( | ||
| 9067 | 9587 | // 16x16 slot's leaves are done, from the |
| 9068 | 9588 | // last leaf (mirrors the writer's r15 |
| 9069 | 9589 | // fix). |
| 9070 | - if let Some((_, mode)) = prev_leaf { | |
| 9071 | - neighbours.above_mode[sc] = mode; | |
| 9072 | - neighbours.left_mode[sr] = mode; | |
| 9590 | + if let Some((below, _)) = sib_modes[2].or(sib_modes[3]).or(sib_modes[0]) { | |
| 9591 | + neighbours.above_mode[sc] = below; | |
| 9592 | + } | |
| 9593 | + if let Some((_, right)) = sib_modes[1].or(sib_modes[3]).or(sib_modes[0]) { | |
| 9594 | + neighbours.left_mode[sr] = right; | |
| 9073 | 9595 | } |
| 9074 | 9596 | } |
| 9075 | 9597 | } |
| @@ -15648,7 +16170,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( | ||
| 15648 | 16170 | let part8 = dec.symbol(&mut cdfs.partition_w8[leaf_ctx]); |
| 15649 | 16171 | if part8 != PARTITION_NONE { |
| 15650 | 16172 | return Err(unsupported( |
| 15651 | - "a partition below 8x8 (this decoder codes no leaf smaller than 8x8)", | |
| 16173 | + "an inter partition below 8x8 (this decoder codes no inter leaf smaller than 8x8; lane-sub8 scoped to intra)", | |
| 15652 | 16174 | )); |
| 15653 | 16175 | } |
| 15654 | 16176 | let ( |
crates/ec-av1/src/encode.rsmodified+61 -20
| @@ -1020,7 +1020,7 @@ pub(crate) struct Reach { | ||
| 1020 | 1020 | /// it. Indexed by the block's position in the superblock, in blocks of its own |
| 1021 | 1021 | /// size, as `row * (128 / side) + col` (`Reach::table_stride`) -- libaom's |
| 1022 | 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 | 1024 | &[255, 85, 119, 85, 127, 85, 119, 85], |
| 1025 | 1025 | &[95, 87], |
| 1026 | 1026 | // has_tr_8x8 (libaom av1/common/reconintra.c) -- table_stride(8) == 16 |
| @@ -1029,11 +1029,28 @@ const HAS_TOP_RIGHT: [&[u8]; 3] = [ | ||
| 1029 | 1029 | 255, 255, 85, 85, 119, 119, 85, 85, 127, 127, 85, 85, 119, 119, 85, 85, 255, 127, 85, 85, |
| 1030 | 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 | 1051 | /// `has_bl_16x16` / `has_bl_32x32`: the same, for the block below and to the |
| 1035 | 1052 | /// left. |
| 1036 | -const HAS_BOTTOM_LEFT: [&[u8]; 3] = [ | |
| 1053 | +const HAS_BOTTOM_LEFT: [&[u8]; 4] = [ | |
| 1037 | 1054 | &[84, 16, 84, 0, 84, 16, 84, 0], |
| 1038 | 1055 | &[4, 4], |
| 1039 | 1056 | // has_bl_8x8 (libaom av1/common/reconintra.c) |
| @@ -1041,6 +1058,16 @@ const HAS_BOTTOM_LEFT: [&[u8]; 3] = [ | ||
| 1041 | 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 | 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 | 1073 | /// `has_tr_vert_*` (libaom `reconintra.c`, `has_tr_vert_tables`), indexed by |
| @@ -1196,21 +1223,22 @@ impl Reach { | ||
| 1196 | 1223 | if col + 1 == per_side { |
| 1197 | 1224 | return false; |
| 1198 | 1225 | } |
| 1199 | - // corner-cut: `HAS_TOP_RIGHT`/`HAS_BOTTOM_LEFT` only carry dedicated | |
| 1200 | - // rows for side 8/16/32/64 (libaom's own `has_tr_8x8`/`has_tr_16x16` | |
| 1201 | - // families); a `TxMode::Select` TX4 transform unit reaches here with | |
| 1202 | - // side 4, whose real table (`has_tr_4x4`, 128 bytes) was never | |
| 1203 | - // transcribed. Clamping into the 16/32 table's own bit range keeps | |
| 1204 | - // this in-bounds and correct at every position that table already | |
| 1205 | - // covers periodically -- wrong only at the small remainder past its | |
| 1206 | - // length, a reach over-/under-estimate (extra or missing above-right | |
| 1207 | - // reference pixels), never a stream desync (Reach never gates a | |
| 1208 | - // symbol read). Ceiling: transcribe `has_tr_4x4`/`has_bl_4x4` | |
| 1209 | - // verbatim and give TX4 its own `HAS_TOP_RIGHT`/`HAS_BOTTOM_LEFT` row. | |
| 1210 | - let table = if VERT_AB_PARTITION.with(std::cell::Cell::get) { | |
| 1211 | - HAS_TOP_RIGHT_VERT[Self::table(side)] | |
| 1226 | + // lane-sub8 r4: side 4 now has its own `has_tr_4x4`/`has_bl_4x4` row | |
| 1227 | + // (the clamp corner-cut that used to live here is gone); sides | |
| 1228 | + // 16/32/64 share row 0 exactly as libaom's tables repeat. | |
| 1229 | + // corner-cut: libaom transcribes no vert 4x4 row, so a side-4 block | |
| 1230 | + // inside a `PARTITION_VERT_A`/`_B` falls back to the ordinary table | |
| 1231 | + // -- a reach over-estimate (extra above-right reference pixels), | |
| 1232 | + // never a stream desync. Ceiling: transcribe `has_tr_vert_4x4` / | |
| 1233 | + // `has_bl_vert_4x4` and extend the VERT tables to four rows. | |
| 1234 | + // NB: named `table_row`, not `row` -- `row` above is the block's | |
| 1235 | + // position inside the superblock and is what the bit index below | |
| 1236 | + // steps by (a merge that shadowed it desynced every block size). | |
| 1237 | + let table_row = Self::table(side); | |
| 1238 | + let table = if VERT_AB_PARTITION.with(std::cell::Cell::get) && table_row < HAS_TOP_RIGHT_VERT.len() { | |
| 1239 | + HAS_TOP_RIGHT_VERT[table_row] | |
| 1212 | 1240 | } else { |
| 1213 | - HAS_TOP_RIGHT[Self::table(side)] | |
| 1241 | + HAS_TOP_RIGHT[table_row] | |
| 1214 | 1242 | }; |
| 1215 | 1243 | Self::bit( |
| 1216 | 1244 | table, |
| @@ -1230,11 +1258,22 @@ impl Reach { | ||
| 1230 | 1258 | if row + 1 == per_side { |
| 1231 | 1259 | return false; |
| 1232 | 1260 | } |
| 1233 | - // corner-cut: see `top_right`'s note -- same clamp, same ceiling. | |
| 1234 | - let table = if VERT_AB_PARTITION.with(std::cell::Cell::get) { | |
| 1235 | - HAS_BOTTOM_LEFT_VERT[Self::table(side)] | |
| 1261 | + // lane-sub8 r4: side 4 now has its own `has_tr_4x4`/`has_bl_4x4` row | |
| 1262 | + // (the clamp corner-cut that used to live here is gone); sides | |
| 1263 | + // 16/32/64 share row 0 exactly as libaom's tables repeat. | |
| 1264 | + // corner-cut: libaom transcribes no vert 4x4 row, so a side-4 block | |
| 1265 | + // inside a `PARTITION_VERT_A`/`_B` falls back to the ordinary table | |
| 1266 | + // -- a reach over-estimate (extra above-right reference pixels), | |
| 1267 | + // never a stream desync. Ceiling: transcribe `has_tr_vert_4x4` / | |
| 1268 | + // `has_bl_vert_4x4` and extend the VERT tables to four rows. | |
| 1269 | + // NB: named `table_row`, not `row` -- `row` above is the block's | |
| 1270 | + // position inside the superblock and is what the bit index below | |
| 1271 | + // steps by (a merge that shadowed it desynced every block size). | |
| 1272 | + let table_row = Self::table(side); | |
| 1273 | + let table = if VERT_AB_PARTITION.with(std::cell::Cell::get) && table_row < HAS_BOTTOM_LEFT_VERT.len() { | |
| 1274 | + HAS_BOTTOM_LEFT_VERT[table_row] | |
| 1236 | 1275 | } else { |
| 1237 | - HAS_BOTTOM_LEFT[Self::table(side)] | |
| 1276 | + HAS_BOTTOM_LEFT[table_row] | |
| 1238 | 1277 | }; |
| 1239 | 1278 | Self::bit( |
| 1240 | 1279 | table, |
| @@ -1270,6 +1309,8 @@ impl Reach { | ||
| 1270 | 1309 | 1 |
| 1271 | 1310 | } else if side == 8 { |
| 1272 | 1311 | 2 |
| 1312 | + } else if side == 4 { | |
| 1313 | + 3 | |
| 1273 | 1314 | } else { |
| 1274 | 1315 | 0 |
| 1275 | 1316 | } |
crates/ec-av1/src/gate_coverage.rsmodified+1 -1
| @@ -199,7 +199,7 @@ const NEVER_EXERCISED_10BIT: &[(&str, &str)] = &[ | ||
| 199 | 199 | // gate passes `=1` for both. |
| 200 | 200 | ( |
| 201 | 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 | 205 | "enable-angle-delta", |
crates/ec-av1/src/refusal_inventory.rsmodified+3 -1
| @@ -28,7 +28,6 @@ const CAPABILITY_CLAIMS: &[&str] = &[ | ||
| 28 | 28 | "a non-2D tx class on a rectangular transform (never expected at this size)", |
| 29 | 29 | "a non-DC chroma mode on an 8x8 inter-frame leaf (this encoder never writes one)", |
| 30 | 30 | "a nonzero angle delta (this encoder never writes one)", |
| 31 | - "a partition below 8x8 (this decoder codes no leaf smaller than 8x8)", | |
| 32 | 31 | "a tx_type symbol on a rectangular transform (never expected at this size)", |
| 33 | 32 | ]; |
| 34 | 33 | |
| @@ -39,6 +38,8 @@ const REFUSALS: &[&str] = &[ | ||
| 39 | 38 | "a coded HORZ/VERT strip whose chroma transform has no rect coefficient tables here", |
| 40 | 39 | "a HORZ/VERT intra strip below 16x16 with a split transform (per-unit rect prediction is not ported)", |
| 41 | 40 | "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)", |
| 41 | + "a HORZ/VERT partition below 8x8 (this decoder's transform primitive is square-only; 4x8/8x4 need a real rectangular transform)", | |
| 42 | + "an inter partition below 8x8 (this decoder codes no inter leaf smaller than 8x8; lane-sub8 scoped to intra)", | |
| 42 | 43 | "a 16x16 block whose true edge cuts through both axes needs a rectangular transform this decoder does not code yet", |
| 43 | 44 | "a 16x16 inter block whose true edge cuts through both axes needs a rectangular transform this decoder does not code yet", |
| 44 | 45 | "a 32x32 partition type this decoder does not code (value={part32})", |
| @@ -49,6 +50,7 @@ const REFUSALS: &[&str] = &[ | ||
| 49 | 50 | "a HORZ/VERT intra strip in a screen-content frame (palette syntax is consumed for square blocks only)", |
| 50 | 51 | "a block that actually uses a palette (UV) -- reconstruction is out of scope", |
| 51 | 52 | "a block that actually uses a palette (Y) -- reconstruction is out of scope", |
| 53 | + "a sub-8x8 leaf that uses intrabc (this reader has no block-vector path; the 8x8-and-up reader reconstructs one)", | |
| 52 | 54 | "an intrabc block under TxMode::Select (its transform size is coded by the inter var-tx partition tree, which this decoder never reads)", |
| 53 | 55 | "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 | 56 | "a frame OBU with no tile group", |
crates/ec-av1/src/stream.rsmodified+200 -0
| @@ -10113,6 +10113,206 @@ mod tests { | ||
| 10113 | 10113 | ); |
| 10114 | 10114 | } |
| 10115 | 10115 | |
| 10116 | + /// lane-sub8 r1: `--min-partition-size=4` on fine-detail noisy gradients | |
| 10117 | + /// at low cq reliably makes aomenc split an 8x8 block all the way to | |
| 10118 | + /// four `BLOCK_4X4` leaves (`PARTITION_SPLIT` below 8x8, spec | |
| 10119 | + /// `decode_partition`'s recursion bottom) -- confirmed with | |
| 10120 | + /// `EC_AV1_TRACE=1` against `examples/decode_probe` before this gate was | |
| 10121 | + /// written (`partition_w8 ... value=3` at mi=(0,0) on the very first | |
| 10122 | + /// block). [`decode::sub8_split_hits`] hard-asserts the path actually | |
| 10123 | + /// ran rather than every attempt landing on `PARTITION_NONE`. | |
| 10124 | + #[test] | |
| 10125 | + fn a_real_aomenc_stream_with_a_sub8_split_decodes_pixel_exact() { | |
| 10126 | + if !have_ffmpeg() { | |
| 10127 | + eprintln!("SKIP a_real_aomenc_stream_with_a_sub8_split_decodes_pixel_exact: no ffmpeg"); | |
| 10128 | + return; | |
| 10129 | + } | |
| 10130 | + if !have_aomenc() { | |
| 10131 | + let msg = format!( | |
| 10132 | + "no aomenc at {}", | |
| 10133 | + aomenc_path().display() | |
| 10134 | + ); | |
| 10135 | + assert!( | |
| 10136 | + std::env::var_os("EC_AV1_REQUIRE_AOMENC").is_none(), | |
| 10137 | + "EC_AV1_REQUIRE_AOMENC is set but {msg}" | |
| 10138 | + ); | |
| 10139 | + eprintln!("SKIP a_real_aomenc_stream_with_a_sub8_split_decodes_pixel_exact: {msg}"); | |
| 10140 | + return; | |
| 10141 | + } | |
| 10142 | + // round 2: `--enable-rect-partitions=0` was added below to keep | |
| 10143 | + // aomenc off HORZ/VERT-below-8x8 elsewhere in the same tile, but it | |
| 10144 | + // is NOT sufficient alone -- see the round-2 report | |
| 10145 | + // (lanes/sub8-r1.report.md) for the live finding: 0/160 attempts | |
| 10146 | + // across both 64x64 and a spatially-isolated single-16x16-leaf | |
| 10147 | + // fixture passed, and every SPLIT that fires is immediately | |
| 10148 | + // followed by a spurious HORZ/VERT read on the very next sibling | |
| 10149 | + // 8x8 leaf, which reads as a real desync left behind by | |
| 10150 | + // `decode_leaf_split4`/`read_intra_mode_sub8`, not an encoder | |
| 10151 | + // choice this recipe can dodge. Tried and rejected: shrinking the | |
| 10152 | + // frame to 16x16 (single 16x16 leaf, at most 4 candidate 8x8s) -- | |
| 10153 | + // that surfaces an UNRELATED pre-existing tiny-frame edge-straddle | |
| 10154 | + // defect (reproduces with zero sub8 code involved, `--min-partition | |
| 10155 | + // -size`/`--max-partition-size` absent entirely), so it is not a | |
| 10156 | + // safe way to isolate the leaf count. Left red; do not "fix" this | |
| 10157 | + // gate by picking fixture parameters that dodge the desync without | |
| 10158 | + // finding it. | |
| 10159 | + // lane-sub8 r6: three arms. The mi-granular mode maps | |
| 10160 | + // (`sub8_mode_col`/`uv_mode_col` and their row twins) are per TILE -- | |
| 10161 | + // the verifier's repro was a 128x64 `--tile-columns=1` stream (seeds | |
| 10162 | + // 207/228) whose every mismatching luma pixel sat at x>=64, the tile | |
| 10163 | + // boundary -- so one arm per tile axis is part of this gate. | |
| 10164 | + for (width, height, tile_args) in [ | |
| 10165 | + (64usize, 64usize, &[][..]), | |
| 10166 | + (128usize, 64usize, &["--tile-columns=1"][..]), | |
| 10167 | + (64usize, 128usize, &["--tile-rows=1"][..]), | |
| 10168 | + ] { | |
| 10169 | + let mut refusals = Vec::new(); | |
| 10170 | + let mut fired_runs = 0u32; | |
| 10171 | + for attempt in 0..40u32 { | |
| 10172 | + let seed = 100 + attempt; | |
| 10173 | + let cq = 6 + (attempt % 4) * 2; | |
| 10174 | + let y4m = Command::new("ffmpeg") | |
| 10175 | + .args([ | |
| 10176 | + "-v", | |
| 10177 | + "error", | |
| 10178 | + "-f", | |
| 10179 | + "lavfi", | |
| 10180 | + "-i", | |
| 10181 | + &gradients_source(seed, width, height, "rate=25"), | |
| 10182 | + "-vf", | |
| 10183 | + // `noise` without `all_seed` re-renders differently on | |
| 10184 | + // every run (seeded-fixture-not-reproducible); pinning it | |
| 10185 | + // makes (seed, cq) name one exact stream. | |
| 10186 | + &format!("noise=alls=40:allf=t:all_seed={seed},format=yuv420p"), | |
| 10187 | + "-t", | |
| 10188 | + "0.04", | |
| 10189 | + "-f", | |
| 10190 | + "yuv4mpegpipe", | |
| 10191 | + "-", | |
| 10192 | + ]) | |
| 10193 | + .stdin(Stdio::null()) | |
| 10194 | + .stdout(Stdio::piped()) | |
| 10195 | + .stderr(Stdio::piped()) | |
| 10196 | + .output() | |
| 10197 | + .expect("ffmpeg failed to run"); | |
| 10198 | + assert!( | |
| 10199 | + y4m.status.success(), | |
| 10200 | + "ffmpeg fixture: {}", | |
| 10201 | + String::from_utf8_lossy(&y4m.stderr) | |
| 10202 | + ); | |
| 10203 | + let mut child = Command::new(aomenc_path()) | |
| 10204 | + .args([ | |
| 10205 | + "--codec=av1", | |
| 10206 | + "--passes=1", | |
| 10207 | + "--end-usage=q", | |
| 10208 | + &format!("--cq-level={cq}"), | |
| 10209 | + "--cpu-used=0", | |
| 10210 | + "--threads=1", | |
| 10211 | + "--row-mt=0", | |
| 10212 | + "--sb-size=64", | |
| 10213 | + "--min-partition-size=4", | |
| 10214 | + "--max-partition-size=8", | |
| 10215 | + // Below 8x8 only PARTITION_NONE/SPLIT are decodable (HORZ/VERT | |
| 10216 | + // need a real rectangular transform, see the module doc above); | |
| 10217 | + // disabling rect partitions entirely -- not just AB -- keeps | |
| 10218 | + // aomenc from picking the still-refused HORZ/VERT arms almost | |
| 10219 | + // every attempt (round 2 measured ~90% HORZ/VERT-below-8x8 | |
| 10220 | + // refusals with --enable-ab-partitions=0 alone). | |
| 10221 | + "--enable-rect-partitions=0", | |
| 10222 | + "--enable-ab-partitions=0", | |
| 10223 | + "--enable-1to4-partitions=1", | |
| 10224 | + "--enable-palette=0", | |
| 10225 | + "--enable-intrabc=0", | |
| 10226 | + "--enable-restoration=0", | |
| 10227 | + "--enable-cdef=0", | |
| 10228 | + "--loopfilter-control=0", | |
| 10229 | + // use_ref_frame_mvs (temporal MV projection) is unimplemented in | |
| 10230 | + // mvstack; this is a key-frame-only fixture, but keep it off for | |
| 10231 | + // safety against a run that emits a second frame. | |
| 10232 | + "--enable-ref-frame-mvs=0", | |
| 10233 | + "--limit=1", | |
| 10234 | + "--obu", | |
| 10235 | + "-o", | |
| 10236 | + "-", | |
| 10237 | + "-", | |
| 10238 | + ]) | |
| 10239 | + .args(tile_args) | |
| 10240 | + .stdin(Stdio::piped()) | |
| 10241 | + .stdout(Stdio::piped()) | |
| 10242 | + .stderr(Stdio::piped()) | |
| 10243 | + .spawn() | |
| 10244 | + .expect("aomenc failed to start"); | |
| 10245 | + child | |
| 10246 | + .stdin | |
| 10247 | + .take() | |
| 10248 | + .expect("aomenc stdin") | |
| 10249 | + .write_all(&y4m.stdout) | |
| 10250 | + .expect("writing y4m to aomenc"); | |
| 10251 | + let out = child.wait_with_output().expect("aomenc failed to run"); | |
| 10252 | + if !out.status.success() { | |
| 10253 | + refusals.push(format!( | |
| 10254 | + "seed={seed} cq={cq}: aomenc itself refused the fixture" | |
| 10255 | + )); | |
| 10256 | + continue; | |
| 10257 | + } | |
| 10258 | + let stream = out.stdout; | |
| 10259 | + let before = decode::sub8_split_hits(); | |
| 10260 | + let tiles_before = decode::tile_hits(); | |
| 10261 | + let frames = match decode_stream(&stream) { | |
| 10262 | + Ok(frames) => frames, | |
| 10263 | + Err(e) => { | |
| 10264 | + // Only a named refusal ("unsupported: ...") is a skip | |
| 10265 | + // reason; any other decode error is this decoder failing. | |
| 10266 | + let msg = e.to_string(); | |
| 10267 | + assert!( | |
| 10268 | + msg.starts_with("unsupported: "), | |
| 10269 | + "decode error that is not a named refusal \ | |
| 10270 | + (seed={seed} cq={cq} tiles={tile_args:?}): {msg}" | |
| 10271 | + ); | |
| 10272 | + refusals.push(format!("seed={seed} cq={cq}: {msg}")); | |
| 10273 | + continue; | |
| 10274 | + } | |
| 10275 | + }; | |
| 10276 | + // gate-blind-to-feature: a tile arm must actually decode more | |
| 10277 | + // than one tile, not merely carry `tile_info.cols > 1`. | |
| 10278 | + assert!( | |
| 10279 | + tile_args.is_empty() || decode::tile_hits() - tiles_before >= 2, | |
| 10280 | + "tiles={tile_args:?} decoded only {} tile(s) (seed={seed} cq={cq})", | |
| 10281 | + decode::tile_hits() - tiles_before | |
| 10282 | + ); | |
| 10283 | + if decode::sub8_split_hits() == before { | |
| 10284 | + refusals.push(format!( | |
| 10285 | + "seed={seed} cq={cq}: decoded, but no block read a real PARTITION_SPLIT below 8x8" | |
| 10286 | + )); | |
| 10287 | + continue; | |
| 10288 | + } | |
| 10289 | + let ffmpeg_frames = ffmpeg_decode_sequence(&stream, width, height, 1); | |
| 10290 | + assert_eq!( | |
| 10291 | + frames[0].y, ffmpeg_frames[0].y, | |
| 10292 | + "luma vs ffmpeg (seed={seed} cq={cq})" | |
| 10293 | + ); | |
| 10294 | + assert_eq!( | |
| 10295 | + frames[0].u, ffmpeg_frames[0].u, | |
| 10296 | + "U vs ffmpeg (seed={seed} cq={cq})" | |
| 10297 | + ); | |
| 10298 | + assert_eq!( | |
| 10299 | + frames[0].v, ffmpeg_frames[0].v, | |
| 10300 | + "V vs ffmpeg (seed={seed} cq={cq})" | |
| 10301 | + ); | |
| 10302 | + fired_runs += 1; | |
| 10303 | + if fired_runs >= 4 { | |
| 10304 | + break; | |
| 10305 | + } | |
| 10306 | + } | |
| 10307 | + assert!( | |
| 10308 | + fired_runs >= 4, | |
| 10309 | + "fewer than 4 firing+pixel-exact runs out of 40 attempts \ | |
| 10310 | + ({width}x{height} tiles={tile_args:?}):\n{}", | |
| 10311 | + refusals.join("\n") | |
| 10312 | + ); | |
| 10313 | + } | |
| 10314 | + } | |
| 10315 | + | |
| 10116 | 10316 | /// lane-av1golden7 r9's decisive fixture: a real aomenc stream (seed 59, |
| 10117 | 10317 | /// `--tune-content=film`, GOLDEN_FRAME firing downstream) whose frame-0 |
| 10118 | 10318 | /// *intra keyframe* mismatched ffmpeg on 3855/4096 luma pixels -- traced |
lanes/COMMON-20260901.mdadded+91 -0
| @@ -0,0 +1,91 @@ | ||
| 1 | +# COMMON CHARTER PREAMBLE — batch 2026-09-01 (ec-av1 decode, his real films) | |
| 2 | + | |
| 3 | +GOAL (why): ec-av1 must decode the user's two real AV1 films bit-exact | |
| 4 | +(`/home/user/Videos/Films/reelc.mkv`, | |
| 5 | +`/home/user/Downloads/reelb.mkv`, | |
| 6 | +both yuv420p10le). 47 refusal strings remain in crates/ec-av1/src/refusal_inventory.rs. | |
| 7 | +Each lane lifts its cluster of refusals WITH a real-aomenc gate proving it. | |
| 8 | + | |
| 9 | +WORKING RULES (binding): | |
| 10 | +- Work ONLY in your worktree; branch named in your charter. Never touch main, never | |
| 11 | + merge into main, never `git checkout <file>` to revert (copy to scratch first). | |
| 12 | +- `export CARGO_TARGET_DIR=$HOME/.cache/cargo-target-<lane>` (named in charter) for EVERY cargo | |
| 13 | + command. sccache is the global rustc wrapper. Use `nice -n 10 cargo ... -j3` — 10 lanes | |
| 14 | + run concurrently on 12 cores / 30G RAM. Long/lavfi runs under | |
| 15 | + `systemd-run --user --scope -p MemoryMax=8G` and bound ffmpeg with `-t`. | |
| 16 | +- Test scope: `cargo test -p ec-av1 --lib` only (plus `cargo check -p ec-av1`). Never the | |
| 17 | + workspace suite. Set `EC_AV1_REQUIRE_AOMENC=1` so an absent oracle FAILS, never SKIPs. | |
| 18 | +- Oracle: `~/.cache/aom-oracle/build/aomenc` and instrumented `aomdec` (scripts/build-aom-oracle.sh, | |
| 19 | + scripts/instrument-aom-oracle.sh; rungs EC_TRACE=1 / EC_TRACE_COEFF=1 / EC_TRACE_MODE=1 / | |
| 20 | + EC_AV1_PREFILT_DUMP). Ours: EC_TRACE_COEFF / EC_TRACE_MODE / EC_TRACE_MODE_STEP in decode.rs. | |
| 21 | + Cross-decoder bisection compares msac RANGE element by element, never tell(). | |
| 22 | + The reference is at the oracle source tree (find via scripts/build-aom-oracle.sh). | |
| 23 | +- FIRST STEP, always: `git log --oneline -8 main` and rebase your branch onto main | |
| 24 | + (`git rebase main`; resolve conflicts, keeping main's fixes). Then RE-MEASURE your lane's | |
| 25 | + premise before building — charters may carry stale premises. Cite the command that | |
| 26 | + produced every premise you act on. | |
| 27 | +- Fixtures: `fixtures` is a symlink to main's fixtures dir (shared). Pin any new stream | |
| 28 | + fixture under crates/ec-av1/fixtures/ or fixtures/ with a hash; hash an aomenc output | |
| 29 | + TWICE before trusting a seed (lavfi gradients ignores its seed). | |
| 30 | +- A refusal is lifted ONLY together with a gate: a real-aomenc stream (tool explicitly | |
| 31 | + enabled on the aomenc command line) decoded pixel-exact vs ffmpeg/aomdec, that | |
| 32 | + HARD-ASSERTS a hit counter proving the feature fired, and never turns a decode error or | |
| 33 | + pixel mismatch into SKIP. Update refusal_inventory.rs + gate_coverage.rs in the same | |
| 34 | + commit. `refusal_inventory` and `gate_coverage` tests must stay green. | |
| 35 | +- Defect classes to check first (memory-proven, each cost rounds): CDF row indexed by a | |
| 36 | + field that moves; table indexed by RAW vs adjusted tx_size; scan/ctx tables transposed | |
| 37 | + vs spec (libaom layout is not the spec's — gate on asymmetric behaviour); neighbour ctx | |
| 38 | + read from one cell instead of gathered over the span; a symbol we read that the | |
| 39 | + reference never wrote (reference range unchanged = unread); a header field parsed then | |
| 40 | + never consumed; counter-reset list missing a table; call-site arg order; a probe loop | |
| 41 | + reusing last run's output file (rm -f first, check exit status). | |
| 42 | +- Tool-call ceiling ~70. If you hit it: commit everything on your branch, write | |
| 43 | + `lanes/<lane>-r<N>.handoff.md` with exact facts (ranges, stream, element) so a fresh | |
| 44 | + agent continues without re-reading. | |
| 45 | +- DONE = commit(s) on your branch + `lanes/<lane>-r<N>.report.md` in your worktree with: | |
| 46 | + what changed (path:line), gate name + command + result, refusals lifted, test totals | |
| 47 | + (`cargo test -p ec-av1 --lib` passed/failed/ignored), and EVIDENCE lines of the form | |
| 48 | + `EVIDENCE: <artifact> | <steps> | <measurement>`. State open residue with | |
| 49 | + fix-now | deferred(<what unblocks>) | accepted. Never claim "done" beyond what you ran. | |
| 50 | +- Film check, when your lane targets a film blocker: extract 0.4s with | |
| 51 | + `ffmpeg -t 0.4 -i <film> -c:v copy -f obu <out>.obu` (bounded), run | |
| 52 | + `cargo run -p ec-av1 --example decode_probe -- <out>.obu` before and after; report | |
| 53 | + the refusal string each film now stops at. | |
| 54 | + | |
| 55 | +VERIFIERS (added 2026-09-01 22:40 after a verifier left a lane worktree on a detached HEAD | |
| 56 | +while its builder was mid-round): a verifier NEVER runs `git checkout`, `git switch`, | |
| 57 | +`git stash` or any tree-changing git command inside a lane worktree. To test a specific | |
| 58 | +commit, `git worktree add --detach /tmp/claude-1000/.../scratchpad/verify-<lane> <sha>` with its | |
| 59 | +own CARGO_TARGET_DIR, and remove it when done. | |
| 60 | + | |
| 61 | +NEIGHBOUR MAPS (added 2026-09-02 00:50, class new-map-ignores-tile-edge): any per-mi side band | |
| 62 | +you add or inherit (mode, uv_mode, skip, ref, filter, txfm ctx, palette) MUST (1) guard | |
| 63 | +availability with `mi_r > tile_row0_mi` / `mi_c > tile_col0_mi`, never `> 0`; (2) be reset in | |
| 64 | +start_tile AND start_row; (3) have a `--tile-columns=1` arm in the lane's gate. Gate Err arms | |
| 65 | +tolerate ONLY messages containing "unsupported"; lavfi sources carry an explicit seed | |
| 66 | +(noise=all_seed=N) and the report shows two identical hashes. | |
| 67 | + | |
| 68 | +SIBLING GATES (added 2026-09-02 03:00, rectsplit r3): a root-cause fix that turns YOUR gate green | |
| 69 | +is not done until every gate that exercises the same tables/paths (grep the table name and the | |
| 70 | +function in stream.rs) is re-run — rectsplit r2 shipped a transposition that fixed its gate and | |
| 71 | +broke the merged SB HORZ/VERT gate at seed 43. Run the siblings before writing "root cause". | |
| 72 | + | |
| 73 | +FORMAT + LOGS (added 2026-09-02 03:30): never run a repo-wide `cargo fmt` in a lane (txselect | |
| 74 | +carried 5000 lines of churn that the merge had to strip; format only files you touched, or | |
| 75 | +not at all). Suite logs go to a PRIVATE path (`$CARGO_TARGET_DIR/../<lane>-suite.log`), never | |
| 76 | +a shared scratchpad name — another session overwrote a verifier's log mid-run. | |
| 77 | + | |
| 78 | +## AOMENC FLAG PRECEDENCE (measured 2026-09-02 08:45, md5 of 4 orderings) | |
| 79 | +aomenc keeps the LAST occurrence of a repeated `--enable-*` flag. Per-arm overrides go AFTER the | |
| 80 | +base recipe. Every gate proves its flag arrived through a decoder-side counter or a header field; | |
| 81 | +a counter at 0 means the flag did not arrive or the encoder declined — never weaken the assert. | |
| 82 | + | |
| 83 | +## SUITE RUNS (3 self-kills on 2026-09-02; setsid -f ALSO died ~10 min in, twice) | |
| 84 | +Run the full suite as a user systemd unit — the only form that survived every time today: | |
| 85 | +`systemd-run --user --unit=<lane>-suite-$(date +%s) -p MemoryMax=10G --same-dir bash -lc 'EC_NOMEMGUARD=1 EC_AV1_REQUIRE_AOMENC=1 CARGO_TARGET_DIR=$HOME/.cache/cargo-target-<lane> nice -n 10 cargo test -p ec-av1 --lib -j3 > $HOME/.cache/<lane>-suite.log 2>&1'` | |
| 86 | +Then continue other work; check with single instantaneous `grep -E "^test result|FAILED" <log>` calls. | |
| 87 | +NEVER wait with a foreground `until/while ... sleep` loop or `tail --pid`. | |
| 88 | + | |
| 89 | +## NEVER pkill BY BINARY NAME (2026-09-02: one lane's `pkill -f ec_av1-<hash>` killed another lane's suite) | |
| 90 | +The test binary hash is identical across worktrees. Kill only by PID you own (`$!`, or the systemd unit | |
| 91 | +name you started). `pkill -f`/`killall` on cargo/ec_av1 patterns is forbidden. |
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. |