Chroma intra-edge filter type read a constant false (and a 16px-coarse uv_mode) below 16x16 -- sub-16 leaves filtered every chroma edge at the wrong strength
Browse files at this commit6c2db9eb9d611cd9b73af32b8025843cb61c5e80Parent: eb6a140- fix
- chroma intra-edge filter type read a constant false (and a 16px-coarse uv_mode) below 16x16 -- sub-16 leaves filtered every chroma edge at the wrong strength
2 changed files +319 -30
- crates/ec-av1/src/decode.rs +149 -30
- crates/ec-av1/src/stream.rs +170 -0
crates/ec-av1/src/decode.rsmodified+149 -30
| @@ -771,6 +771,38 @@ pub(crate) fn mode_mi_override_hits() -> usize { | ||
| 771 | 771 | MODE_MI_OVERRIDE_HITS.with(|c| c.get()) |
| 772 | 772 | } |
| 773 | 773 | |
| 774 | +// lane-cfl r1: how many times a chroma intra-edge filter-type read | |
| 775 | +// (`get_filt_type`, libaom reconintra.c) took an above/left UV mode from the | |
| 776 | +// mi-exact map that DIFFERS from its coarse 16x16 slot -- i.e. how often the | |
| 777 | +// r1 defect would have filtered a chroma edge with the wrong strength. | |
| 778 | +thread_local! { | |
| 779 | + static UV_MODE_MI_OVERRIDE_HITS: std::cell::Cell<usize> = | |
| 780 | + const { std::cell::Cell::new(0) }; | |
| 781 | +} | |
| 782 | + | |
| 783 | +/// Current value of [`UV_MODE_MI_OVERRIDE_HITS`]. | |
| 784 | +pub(crate) fn uv_mode_mi_override_hits() -> usize { | |
| 785 | + UV_MODE_MI_OVERRIDE_HITS.with(|c| c.get()) | |
| 786 | +} | |
| 787 | + | |
| 788 | +// lane-cfl r1 gate counters: `UV_CFL_PRED` blocks (every `cfl_alpha_signs` | |
| 789 | +// read) and chroma blocks with a NONZERO `angle_delta_uv` -- the two block | |
| 790 | +// shapes the r1 chroma defect showed up on. | |
| 791 | +thread_local! { | |
| 792 | + static CFL_BLOCK_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) }; | |
| 793 | + static UV_ANGLE_DELTA_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) }; | |
| 794 | +} | |
| 795 | + | |
| 796 | +/// Current value of [`CFL_BLOCK_HITS`]. | |
| 797 | +pub(crate) fn cfl_block_hits() -> usize { | |
| 798 | + CFL_BLOCK_HITS.with(|c| c.get()) | |
| 799 | +} | |
| 800 | + | |
| 801 | +/// Current value of [`UV_ANGLE_DELTA_HITS`]. | |
| 802 | +pub(crate) fn uv_angle_delta_hits() -> usize { | |
| 803 | + UV_ANGLE_DELTA_HITS.with(|c| c.get()) | |
| 804 | +} | |
| 805 | + | |
| 774 | 806 | // lane-sbpart r2: how many superblock-level `PARTITION_HORZ`/`PARTITION_VERT` |
| 775 | 807 | // blocks (two true 64x32/32x64 strips, [`decode_block_rect64`]) fired -- the |
| 776 | 808 | // gate's proof this round's arms actually reached a real block, not just |
| @@ -1851,8 +1883,8 @@ struct Neighbours { | ||
| 1851 | 1883 | /// and read only by [`decode_leaf_split4`]; the position guard makes it |
| 1852 | 1884 | /// fall back to the coarse slot whenever the real neighbour was a block |
| 1853 | 1885 | /// of 8x8 or larger (whose one mode is correct for every row it spans). |
| 1854 | - sub8_mode_col: Vec<(usize, usize)>, | |
| 1855 | - sub8_mode_row: Vec<(usize, usize)>, | |
| 1886 | + sub8_mode_col: Vec<(usize, usize, usize)>, | |
| 1887 | + sub8_mode_row: Vec<(usize, usize, usize)>, | |
| 1856 | 1888 | /// Whether the block above/left of this column/row was coded `skip` -- |
| 1857 | 1889 | /// an inter frame's own `skip` context (spec `SkipContext`), which the |
| 1858 | 1890 | /// key-frame writer never tracks (its skip context is always zero); a |
| @@ -1980,8 +2012,8 @@ impl Neighbours { | ||
| 1980 | 2012 | left_side: vec![SB; rows], |
| 1981 | 2013 | above_side_mi: vec![SB; cols * (SUB / MI)], |
| 1982 | 2014 | left_side_mi: vec![SB; rows * (SUB / MI)], |
| 1983 | - sub8_mode_col: vec![(usize::MAX, 0); cols * (SUB / MI)], | |
| 1984 | - sub8_mode_row: vec![(usize::MAX, 0); rows * (SUB / MI)], | |
| 2015 | + sub8_mode_col: vec![(usize::MAX, 0, 0); cols * (SUB / MI)], | |
| 2016 | + sub8_mode_row: vec![(usize::MAX, 0, 0); rows * (SUB / MI)], | |
| 1985 | 2017 | above_skip: vec![false; cols], |
| 1986 | 2018 | left_skip: vec![false; rows], |
| 1987 | 2019 | above_skip_mode: vec![false; cols], |
| @@ -2054,7 +2086,7 @@ impl Neighbours { | ||
| 2054 | 2086 | // unreset, a tile read its LEFT tile's modes across the boundary. |
| 2055 | 2087 | for i in col0_mi.min(end)..end { |
| 2056 | 2088 | if let Some(slot) = self.sub8_mode_col.get_mut(i) { |
| 2057 | - *slot = (usize::MAX, 0); | |
| 2089 | + *slot = (usize::MAX, 0, 0); | |
| 2058 | 2090 | } |
| 2059 | 2091 | } |
| 2060 | 2092 | } |
| @@ -2314,7 +2346,7 @@ impl Neighbours { | ||
| 2314 | 2346 | self.left_comp_group_idx.iter_mut().for_each(|r| *r = 0); |
| 2315 | 2347 | self.left_compound_idx.iter_mut().for_each(|r| *r = 0); |
| 2316 | 2348 | self.left_filter.iter_mut().for_each(|f| *f = [3u8; 2]); |
| 2317 | - self.sub8_mode_row.iter_mut().for_each(|e| *e = (usize::MAX, 0)); | |
| 2349 | + self.sub8_mode_row.iter_mut().for_each(|e| *e = (usize::MAX, 0, 0)); | |
| 2318 | 2350 | } |
| 2319 | 2351 | |
| 2320 | 2352 | /// Records a block's `skip`/`is_inter`/`interp_filter` state for the next |
| @@ -2560,16 +2592,24 @@ impl Neighbours { | ||
| 2560 | 2592 | /// block to the right reads via `mi(row, col-1)`). Only sub-8x8 leaves |
| 2561 | 2593 | /// read these back, and only when the recorded position is exactly their |
| 2562 | 2594 | /// own neighbour -- see [`Self::sub8_mode_col`]'s doc. |
| 2563 | - fn record_mode_mi(&mut self, mi_r: usize, mi_c: usize, mi_w: usize, mi_h: usize, mode: usize) { | |
| 2595 | + fn record_mode_mi( | |
| 2596 | + &mut self, | |
| 2597 | + mi_r: usize, | |
| 2598 | + mi_c: usize, | |
| 2599 | + mi_w: usize, | |
| 2600 | + mi_h: usize, | |
| 2601 | + mode: usize, | |
| 2602 | + uv_mode: usize, | |
| 2603 | + ) { | |
| 2564 | 2604 | let (last_r, last_c) = (mi_r + mi_h - 1, mi_c + mi_w - 1); |
| 2565 | 2605 | for cell in 0..mi_w { |
| 2566 | 2606 | if let Some(slot) = self.sub8_mode_col.get_mut(mi_c + cell) { |
| 2567 | - *slot = (last_r, mode); | |
| 2607 | + *slot = (last_r, mode, uv_mode); | |
| 2568 | 2608 | } |
| 2569 | 2609 | } |
| 2570 | 2610 | for cell in 0..mi_h { |
| 2571 | 2611 | if let Some(slot) = self.sub8_mode_row.get_mut(mi_r + cell) { |
| 2572 | - *slot = (last_c, mode); | |
| 2612 | + *slot = (last_c, mode, uv_mode); | |
| 2573 | 2613 | } |
| 2574 | 2614 | } |
| 2575 | 2615 | } |
| @@ -2580,18 +2620,62 @@ impl Neighbours { | ||
| 2580 | 2620 | /// construction). See [`Self::record_mode_mi`]. |
| 2581 | 2621 | fn mode_above_mi(&self, mi_r: usize, mi_c: usize) -> Option<usize> { |
| 2582 | 2622 | match self.sub8_mode_col.get(mi_c) { |
| 2583 | - Some(&(row, m)) if mi_r > self.tile_row0_mi && row == mi_r - 1 => Some(m), | |
| 2623 | + Some(&(row, m, _)) if mi_r > self.tile_row0_mi && row == mi_r - 1 => Some(m), | |
| 2584 | 2624 | _ => None, |
| 2585 | 2625 | } |
| 2586 | 2626 | } |
| 2587 | 2627 | |
| 2588 | 2628 | fn mode_left_mi(&self, mi_r: usize, mi_c: usize) -> Option<usize> { |
| 2589 | 2629 | match self.sub8_mode_row.get(mi_r) { |
| 2590 | - Some(&(col, m)) if mi_c > self.tile_col0_mi && col == mi_c - 1 => Some(m), | |
| 2630 | + Some(&(col, m, _)) if mi_c > self.tile_col0_mi && col == mi_c - 1 => Some(m), | |
| 2631 | + _ => None, | |
| 2632 | + } | |
| 2633 | + } | |
| 2634 | + | |
| 2635 | + /// [`Self::mode_above_mi`]/[`Self::mode_left_mi`] for the CHROMA mode | |
| 2636 | + /// (lane-cfl r1). libaom's `get_filt_type` reads `chroma_above_mbmi`/ | |
| 2637 | + /// `chroma_left_mbmi`'s `uv_mode` for the intra-edge filter type of a | |
| 2638 | + /// chroma plane, and the coarse [`SUB`] (16px) `above_uv_mode`/ | |
| 2639 | + /// `left_uv_mode` cells are never written by a block smaller than 16x16 | |
| 2640 | + /// (`for cell in 0..w / SUB` runs zero times), so an 8x8 leaf's chroma | |
| 2641 | + /// neighbour was whatever a 16x16-or-larger block left there. | |
| 2642 | + fn uv_mode_above_mi(&self, mi_r: usize, mi_c: usize) -> Option<usize> { | |
| 2643 | + match self.sub8_mode_col.get(mi_c) { | |
| 2644 | + Some(&(row, _, uv)) if mi_r > self.tile_row0_mi && row == mi_r - 1 => Some(uv), | |
| 2645 | + _ => None, | |
| 2646 | + } | |
| 2647 | + } | |
| 2648 | + | |
| 2649 | + fn uv_mode_left_mi(&self, mi_r: usize, mi_c: usize) -> Option<usize> { | |
| 2650 | + match self.sub8_mode_row.get(mi_r) { | |
| 2651 | + Some(&(col, _, uv)) if mi_c > self.tile_col0_mi && col == mi_c - 1 => Some(uv), | |
| 2591 | 2652 | _ => None, |
| 2592 | 2653 | } |
| 2593 | 2654 | } |
| 2594 | 2655 | |
| 2656 | + /// The above/left CHROMA modes libaom's `get_filt_type` really sees for a | |
| 2657 | + /// block at coarse [`SUB`]-grid `(r, c)` -- the chroma twin of | |
| 2658 | + /// [`Self::modes_above_left`]. | |
| 2659 | + fn uv_modes_above_left(&self, r: usize, c: usize) -> (usize, usize) { | |
| 2660 | + self.uv_modes_above_left_mi(r * (SUB / MI), c * (SUB / MI)) | |
| 2661 | + } | |
| 2662 | + | |
| 2663 | + /// [`Self::uv_modes_above_left`] keyed directly by the block's own | |
| 2664 | + /// top-left mi position -- what a sub-16x16 leaf ([`decode_leaf_8x8`], | |
| 2665 | + /// [`decode_leaf_rect`]) has; the coarse [`SUB`] slot is only the | |
| 2666 | + /// fallback for an mi position no block recorded. | |
| 2667 | + fn uv_modes_above_left_mi(&self, mi_r: usize, mi_c: usize) -> (usize, usize) { | |
| 2668 | + let (r, c) = (mi_r * MI / SUB, mi_c * MI / SUB); | |
| 2669 | + let coarse_above = self.above_uv_mode.get(c).copied().unwrap_or(DC_PRED); | |
| 2670 | + let coarse_left = self.left_uv_mode.get(r).copied().unwrap_or(DC_PRED); | |
| 2671 | + let above = self.uv_mode_above_mi(mi_r, mi_c).unwrap_or(coarse_above); | |
| 2672 | + let left = self.uv_mode_left_mi(mi_r, mi_c).unwrap_or(coarse_left); | |
| 2673 | + if above != coarse_above || left != coarse_left { | |
| 2674 | + UV_MODE_MI_OVERRIDE_HITS.with(|h| h.set(h.get() + 1)); | |
| 2675 | + } | |
| 2676 | + (above, left) | |
| 2677 | + } | |
| 2678 | + | |
| 2595 | 2679 | /// The above/left luma modes libaom's `above_mi`/`left_mi` really see for a |
| 2596 | 2680 | /// block at coarse [`SUB`]-grid `(r, c)`. lane-rectx r5: the coarse |
| 2597 | 2681 | /// `above_mode`/`left_mode` slots are written in 16x16 cells, so a |
| @@ -2631,7 +2715,7 @@ impl Neighbours { | ||
| 2631 | 2715 | self.left_uv_mode[r + cell] = uv_mode; |
| 2632 | 2716 | self.left_side[r + cell] = h; |
| 2633 | 2717 | } |
| 2634 | - self.record_mode_mi(r * (SUB / MI), c * (SUB / MI), w / MI, h / MI, mode); | |
| 2718 | + self.record_mode_mi(r * (SUB / MI), c * (SUB / MI), w / MI, h / MI, mode, uv_mode); | |
| 2635 | 2719 | self.record_mi_rect((r * (SUB / MI), c * (SUB / MI)), w, h, grids); |
| 2636 | 2720 | } |
| 2637 | 2721 | |
| @@ -2742,7 +2826,7 @@ impl Neighbours { | ||
| 2742 | 2826 | } |
| 2743 | 2827 | let (mi_r, mi_c) = (r * (SUB / MI), c * (SUB / MI)); |
| 2744 | 2828 | let side_mi = side / MI; |
| 2745 | - self.record_mode_mi(mi_r, mi_c, side_mi, side_mi, mode); | |
| 2829 | + self.record_mode_mi(mi_r, mi_c, side_mi, side_mi, mode, uv_mode); | |
| 2746 | 2830 | for cell in 0..side_mi { |
| 2747 | 2831 | self.left_side_mi[mi_r + cell] = side; |
| 2748 | 2832 | self.above_side_mi[mi_c + cell] = side; |
| @@ -3207,6 +3291,9 @@ fn read_intra_mode_rect( | ||
| 3207 | 3291 | 0 |
| 3208 | 3292 | }; |
| 3209 | 3293 | istep!("angle_uv", angle_delta_uv); |
| 3294 | + if angle_delta_uv != 0 { | |
| 3295 | + UV_ANGLE_DELTA_HITS.with(|c| c.set(c.get() + 1)); | |
| 3296 | + } | |
| 3210 | 3297 | let mut filter_intra = None; |
| 3211 | 3298 | if std::env::var_os("EC_AV1_TRACE").is_some() { |
| 3212 | 3299 | let (rng, _) = dec.debug_state(); |
| @@ -3333,7 +3420,10 @@ fn decode_block_rect( | ||
| 3333 | 3420 | // (spec `get_intra_edge_filter_type`) reads the CHROMA neighbour's |
| 3334 | 3421 | // `uv_mode`, not the luma one. |
| 3335 | 3422 | let smooth_neighbor_uv = |
| 3336 | - is_smooth_mode(neighbours.above_uv_mode[c]) || is_smooth_mode(neighbours.left_uv_mode[r]); | |
| 3423 | + { | |
| 3424 | + let (au, lu) = neighbours.uv_modes_above_left(r, c); | |
| 3425 | + is_smooth_mode(au) || is_smooth_mode(lu) | |
| 3426 | + }; | |
| 3337 | 3427 | if filter_intra.is_some() { |
| 3338 | 3428 | // `predict_filter_intra` (spec 7.11.2.3) is square-only in this |
| 3339 | 3429 | // decoder (`assert_eq!(dst.len(), side*side)`) -- a real symbol was |
| @@ -3728,6 +3818,11 @@ fn decode_leaf_rect( | ||
| 3728 | 3818 | )); |
| 3729 | 3819 | } |
| 3730 | 3820 | let uv_predict_mode = if uv_mode == UV_CFL_PRED { DC_PRED } else { uv_mode }; |
| 3821 | + // lane-cfl r1, same defect as [`decode_leaf_8x8`]: chroma's intra-edge | |
| 3822 | + // filter type is the NEIGHBOUR's `uv_mode` (libaom `get_filt_type`), not | |
| 3823 | + // a constant `false`. | |
| 3824 | + let (uv_above, uv_left) = neighbours.uv_modes_above_left_mi(leaf_mi.0, leaf_mi.1); | |
| 3825 | + let smooth_neighbor_uv = is_smooth_mode(uv_above) || is_smooth_mode(uv_left); | |
| 3731 | 3826 | let depth = if tx_select { |
| 3732 | 3827 | let ctx = tx_size_context_rect(neighbours, leaf_mi, bw, bh); |
| 3733 | 3828 | dec.symbol(&mut cdfs.tx_size_cat2[ctx]) |
| @@ -3756,11 +3851,11 @@ fn decode_leaf_rect( | ||
| 3756 | 3851 | let ac = alpha.map(|_| cfl_ac_q3_rect(y, px, py, bw, bh)); |
| 3757 | 3852 | u.reconstruct_rect( |
| 3758 | 3853 | cpx, cpy, chroma_w, chroma_h, uv_predict_mode, angle_delta_uv, reach, &u_levels, |
| 3759 | - alpha.zip(ac.as_deref()).map(|((au, _), ac)| (au, ac)), None, false, | |
| 3854 | + alpha.zip(ac.as_deref()).map(|((au, _), ac)| (au, ac)), None, smooth_neighbor_uv, | |
| 3760 | 3855 | ); |
| 3761 | 3856 | v.reconstruct_rect( |
| 3762 | 3857 | cpx, cpy, chroma_w, chroma_h, uv_predict_mode, angle_delta_uv, reach, &v_levels, |
| 3763 | - alpha.zip(ac.as_deref()).map(|((_, av), ac)| (av, ac)), None, false, | |
| 3858 | + alpha.zip(ac.as_deref()).map(|((_, av), ac)| (av, ac)), None, smooth_neighbor_uv, | |
| 3764 | 3859 | ); |
| 3765 | 3860 | } else { |
| 3766 | 3861 | // lane-rectx: a genuine 16x8/8x16 luma transform (`TxbSet::LumaRect16x8`, |
| @@ -3812,7 +3907,7 @@ fn decode_leaf_rect( | ||
| 3812 | 3907 | ); |
| 3813 | 3908 | u.reconstruct_rect( |
| 3814 | 3909 | cpx, cpy, chroma_w, chroma_h, uv_predict_mode, angle_delta_uv, reach, &u_residual, |
| 3815 | - alpha.zip(ac.as_deref()).map(|((au, _), ac)| (au, ac)), None, false, | |
| 3910 | + alpha.zip(ac.as_deref()).map(|((au, _), ac)| (au, ac)), None, smooth_neighbor_uv, | |
| 3816 | 3911 | ); |
| 3817 | 3912 | let v_default_tx = default_intra_tx_type(uv_predict_mode as u8); |
| 3818 | 3913 | let v_skip_ctx = usize::from(around[2].0) + usize::from(around[2].1); |
| @@ -3828,7 +3923,7 @@ fn decode_leaf_rect( | ||
| 3828 | 3923 | ); |
| 3829 | 3924 | v.reconstruct_rect( |
| 3830 | 3925 | cpx, cpy, chroma_w, chroma_h, uv_predict_mode, angle_delta_uv, reach, &v_residual, |
| 3831 | - alpha.zip(ac.as_deref()).map(|((_, av), ac)| (av, ac)), None, false, | |
| 3926 | + alpha.zip(ac.as_deref()).map(|((_, av), ac)| (av, ac)), None, smooth_neighbor_uv, | |
| 3832 | 3927 | ); |
| 3833 | 3928 | RECT_LEAF_COEFF_HITS.with(|c| c.set(c.get() + 1)); |
| 3834 | 3929 | } |
| @@ -3837,7 +3932,7 @@ fn decode_leaf_rect( | ||
| 3837 | 3932 | neighbours.fill_lf_grid_rect(leaf_mi, mi_w, mi_h, bw as u8, bh as u8, 0); |
| 3838 | 3933 | // A rect leaf spans mi_w x mi_h, so its mode reaches several columns and |
| 3839 | 3934 | // rows -- record the whole span, not one cell. |
| 3840 | - neighbours.record_mode_mi(leaf_mi.0, leaf_mi.1, mi_w, mi_h, mode); | |
| 3935 | + neighbours.record_mode_mi(leaf_mi.0, leaf_mi.1, mi_w, mi_h, mode, uv_mode); | |
| 3841 | 3936 | Ok(mode) |
| 3842 | 3937 | } |
| 3843 | 3938 | |
| @@ -3904,7 +3999,10 @@ fn decode_block_rect64( | ||
| 3904 | 3999 | SMOOTH_LUMA_HITS.with(|c| c.set(c.get() + 1)); |
| 3905 | 4000 | } |
| 3906 | 4001 | let smooth_neighbor_uv = |
| 3907 | - is_smooth_mode(neighbours.above_uv_mode[c]) || is_smooth_mode(neighbours.left_uv_mode[r]); | |
| 4002 | + { | |
| 4003 | + let (au, lu) = neighbours.uv_modes_above_left(r, c); | |
| 4004 | + is_smooth_mode(au) || is_smooth_mode(lu) | |
| 4005 | + }; | |
| 3908 | 4006 | if filter_intra.is_some() { |
| 3909 | 4007 | // `filter_intra_size_class_rect` already returns `None` for both |
| 3910 | 4008 | // `(64, 32)` and `(32, 64)` (`av1_filter_intra_allowed_bsize` caps at |
| @@ -4346,6 +4444,9 @@ fn read_intra_mode( | ||
| 4346 | 4444 | 0 |
| 4347 | 4445 | }; |
| 4348 | 4446 | istep!("angle_uv", angle_delta_uv); |
| 4447 | + if angle_delta_uv != 0 { | |
| 4448 | + UV_ANGLE_DELTA_HITS.with(|c| c.set(c.get() + 1)); | |
| 4449 | + } | |
| 4349 | 4450 | // `read_palette_mode_info` (spec 5.11.13, libaom decodemv.c:567, called |
| 4350 | 4451 | // at :840 right after `xd->cfl.store_y` and before `read_filter_intra_mode_info`): |
| 4351 | 4452 | // gated by `av1_allow_palette` (blockd.h -- size bound only, |
| @@ -4497,6 +4598,7 @@ const UV_CFL_PRED: usize = 13; | ||
| 4497 | 4598 | /// joint sign the same way. Returns each plane's final signed `alpha_q3` |
| 4498 | 4599 | /// (`cfl_idx_to_alpha`, cfl.c): magnitude `idx + 1`, sign-zero collapsing to 0. |
| 4499 | 4600 | fn read_cfl_alphas(dec: &mut SymbolDecoder, cdfs: &mut Cdfs) -> (i32, i32) { |
| 4601 | + CFL_BLOCK_HITS.with(|c| c.set(c.get() + 1)); | |
| 4500 | 4602 | let joint_sign = dec.symbol(&mut cdfs.cfl_sign) as i32; |
| 4501 | 4603 | let sign_u = ((joint_sign + 1) * 11) >> 5; |
| 4502 | 4604 | let sign_v = (joint_sign + 1) - 3 * sign_u; |
| @@ -5018,7 +5120,10 @@ fn decode_block( | ||
| 5018 | 5120 | SMOOTH_LUMA_HITS.with(|c| c.set(c.get() + 1)); |
| 5019 | 5121 | } |
| 5020 | 5122 | let smooth_neighbor_uv = |
| 5021 | - is_smooth_mode(neighbours.above_uv_mode[c]) || is_smooth_mode(neighbours.left_uv_mode[r]); | |
| 5123 | + { | |
| 5124 | + let (au, lu) = neighbours.uv_modes_above_left(r, c); | |
| 5125 | + is_smooth_mode(au) || is_smooth_mode(lu) | |
| 5126 | + }; | |
| 5022 | 5127 | if std::env::var_os("EC_AV1_TRACE").is_some() { |
| 5023 | 5128 | eprintln!( |
| 5024 | 5129 | "TRACE block px={px} py={py} side={side} mode={mode} uv_mode={uv_mode} \ |
| @@ -5437,6 +5542,14 @@ fn decode_leaf8( | ||
| 5437 | 5542 | if smooth_neighbor { |
| 5438 | 5543 | SMOOTH_LUMA_HITS.with(|c| c.set(c.get() + 1)); |
| 5439 | 5544 | } |
| 5545 | + // lane-cfl r1: chroma's own `get_filt_type` (libaom reconintra.c) reads | |
| 5546 | + // the NEIGHBOUR's `uv_mode`, mi-exactly -- this leaf passed a hardcoded | |
| 5547 | + // `false` ("until a smooth/paeth uv_mode can reach decode at all"), which | |
| 5548 | + // stopped being true once real streams put SMOOTH chroma next to a | |
| 5549 | + // directional chroma block: every 8x8 leaf filtered its chroma edge at | |
| 5550 | + // the wrong strength. | |
| 5551 | + let (uv_above, uv_left) = neighbours.uv_modes_above_left_mi(leaf_mi.0, leaf_mi.1); | |
| 5552 | + let smooth_neighbor_uv = is_smooth_mode(uv_above) || is_smooth_mode(uv_left); | |
| 5440 | 5553 | // An 8x8 leaf is well within `is_cfl_allowed`'s <=32x32 bound (spec |
| 5441 | 5554 | // 5.11.5), so it reads the CFL-allowed `uv_mode_cfl` CDF, like every other |
| 5442 | 5555 | // `decode_block` caller at 16x16 and up. |
| @@ -5500,7 +5613,7 @@ fn decode_leaf8( | ||
| 5500 | 5613 | &vec![0i32; 16], |
| 5501 | 5614 | alpha.zip(ac.as_deref()).map(|((au, _), ac)| (au, ac)), |
| 5502 | 5615 | None, |
| 5503 | - false, | |
| 5616 | + smooth_neighbor_uv, | |
| 5504 | 5617 | ); |
| 5505 | 5618 | v.reconstruct( |
| 5506 | 5619 | cpx, |
| @@ -5512,7 +5625,7 @@ fn decode_leaf8( | ||
| 5512 | 5625 | &vec![0i32; 16], |
| 5513 | 5626 | alpha.zip(ac.as_deref()).map(|((_, av), ac)| (av, ac)), |
| 5514 | 5627 | None, |
| 5515 | - false, | |
| 5628 | + smooth_neighbor_uv, | |
| 5516 | 5629 | ); |
| 5517 | 5630 | luma_grid = vec![0i32; 64]; |
| 5518 | 5631 | u_grid = vec![0i32; 16]; |
| @@ -5566,7 +5679,7 @@ fn decode_leaf8( | ||
| 5566 | 5679 | alpha.zip(ac.as_deref()).map(|((au, _), ac)| (au, ac)), |
| 5567 | 5680 | None, |
| 5568 | 5681 | None, |
| 5569 | - false, | |
| 5682 | + smooth_neighbor_uv, | |
| 5570 | 5683 | )?; |
| 5571 | 5684 | v_grid = read_plane( |
| 5572 | 5685 | dec, |
| @@ -5588,7 +5701,7 @@ fn decode_leaf8( | ||
| 5588 | 5701 | alpha.zip(ac.as_deref()).map(|((_, av), ac)| (av, ac)), |
| 5589 | 5702 | None, |
| 5590 | 5703 | None, |
| 5591 | - false, | |
| 5704 | + smooth_neighbor_uv, | |
| 5592 | 5705 | )?; |
| 5593 | 5706 | } else { |
| 5594 | 5707 | // `tx_depth` resolved this leaf's luma to `TX4`: a 2x2 raster-order |
| @@ -5664,7 +5777,7 @@ fn decode_leaf8( | ||
| 5664 | 5777 | alpha.zip(ac.as_deref()).map(|((au, _), ac)| (au, ac)), |
| 5665 | 5778 | None, |
| 5666 | 5779 | None, |
| 5667 | - false, | |
| 5780 | + smooth_neighbor_uv, | |
| 5668 | 5781 | )?; |
| 5669 | 5782 | v_grid = read_plane( |
| 5670 | 5783 | dec, |
| @@ -5686,7 +5799,7 @@ fn decode_leaf8( | ||
| 5686 | 5799 | alpha.zip(ac.as_deref()).map(|((_, av), ac)| (av, ac)), |
| 5687 | 5800 | None, |
| 5688 | 5801 | None, |
| 5689 | - false, | |
| 5802 | + smooth_neighbor_uv, | |
| 5690 | 5803 | )?; |
| 5691 | 5804 | // `record_split_luma` expects a `record`-style `(r, c)` position in |
| 5692 | 5805 | // `SUB`-grid units and rescales it by `SUB / MI`; `leaf_mi` is |
| @@ -5718,13 +5831,13 @@ fn decode_leaf8( | ||
| 5718 | 5831 | } |
| 5719 | 5832 | neighbours.fill_skip_grid(leaf_mi, 2, skip); |
| 5720 | 5833 | neighbours.fill_lf_grid(leaf_mi, 2, 4, 0); |
| 5721 | - neighbours.record_mode_mi(leaf_mi.0, leaf_mi.1, 2, 2, mode); | |
| 5834 | + neighbours.record_mode_mi(leaf_mi.0, leaf_mi.1, 2, 2, mode, uv_mode); | |
| 5722 | 5835 | return Ok(mode); |
| 5723 | 5836 | } |
| 5724 | 5837 | neighbours.record_mi(leaf_mi, 8, &[luma_grid, u_grid, v_grid]); |
| 5725 | 5838 | neighbours.fill_skip_grid(leaf_mi, 2, skip); |
| 5726 | 5839 | neighbours.fill_lf_grid(leaf_mi, 2, 8, 0); |
| 5727 | - neighbours.record_mode_mi(leaf_mi.0, leaf_mi.1, 2, 2, mode); | |
| 5840 | + neighbours.record_mode_mi(leaf_mi.0, leaf_mi.1, 2, 2, mode, uv_mode); | |
| 5728 | 5841 | Ok(mode) |
| 5729 | 5842 | } |
| 5730 | 5843 | |
| @@ -10670,6 +10783,9 @@ fn decode_inter_block( | ||
| 10670 | 10783 | } else { |
| 10671 | 10784 | 0 |
| 10672 | 10785 | }; |
| 10786 | + if angle_delta_uv != 0 { | |
| 10787 | + UV_ANGLE_DELTA_HITS.with(|c| c.set(c.get() + 1)); | |
| 10788 | + } | |
| 10673 | 10789 | uv_predict_mode = if uv_mode == UV_CFL_PRED { |
| 10674 | 10790 | DC_PRED |
| 10675 | 10791 | } else { |
| @@ -10679,7 +10795,10 @@ fn decode_inter_block( | ||
| 10679 | 10795 | // as [`read_intra_mode`]/[`read_intra_mode_rect`] -- the CHROMA |
| 10680 | 10796 | // neighbour's own `uv_mode`, not the luma one. |
| 10681 | 10797 | let smooth_neighbor_uv = |
| 10682 | - is_smooth_mode(neighbours.above_uv_mode[c]) || is_smooth_mode(neighbours.left_uv_mode[r]); | |
| 10798 | + { | |
| 10799 | + let (au, lu) = neighbours.uv_modes_above_left(r, c); | |
| 10800 | + is_smooth_mode(au) || is_smooth_mode(lu) | |
| 10801 | + }; | |
| 10683 | 10802 | // `read_palette_mode_info` (decodemv.c:567, called from |
| 10684 | 10803 | // `read_intra_block_mode_info` right after `xd->cfl.store_y`, same |
| 10685 | 10804 | // gating and same corner-cut as `read_intra_mode`'s own copy above |
crates/ec-av1/src/stream.rsmodified+170 -0
| @@ -5572,6 +5572,176 @@ mod tests { | ||
| 5572 | 5572 | eprintln!("{NAME}: pixel-exact, mode_mi_override_hits={total_overrides}"); |
| 5573 | 5573 | } |
| 5574 | 5574 | |
| 5575 | + /// lane-cfl r1: the chroma intra-edge FILTER TYPE is the neighbour's | |
| 5576 | + /// `uv_mode` (libaom `get_filt_type`, reconintra.c: `chroma_above_mbmi`/ | |
| 5577 | + /// `chroma_left_mbmi` -> `is_smooth` on `uv_mode`), and two whole decode | |
| 5578 | + /// paths passed a hardcoded `false` for it -- `decode_leaf_8x8` (every | |
| 5579 | + /// 8x8 leaf of a SPLIT) and `decode_leaf_rect` (every rect strip below | |
| 5580 | + /// 16x16), on a stale "chroma stays false (exact) until a smooth/paeth | |
| 5581 | + /// uv_mode can reach decode at all" comment. On top of that the coarse | |
| 5582 | + /// `above_uv_mode`/`left_uv_mode` cells are 16px-granular and their | |
| 5583 | + /// `for cell in 0..w / SUB` write runs ZERO times for any block below | |
| 5584 | + /// 16x16, so even the paths that DID read them saw whatever a | |
| 5585 | + /// 16x16-or-larger block had left there (class: context read from one | |
| 5586 | + /// cell / neighbour map at the wrong granularity). Result on this | |
| 5587 | + /// recipe: luma byte-exact, entropy ladder identical, and 40 U + 86 V | |
| 5588 | + /// chroma bytes wrong -- every one of them downstream of one 4x4 chroma | |
| 5589 | + /// block at mi(8,12) whose D135 + `angle_delta_uv=-3` left edge was | |
| 5590 | + /// filtered at the wrong strength (`ft=0` where the instrumented aomdec | |
| 5591 | + /// prints `ft=1`, left edge `95,59,30,28` vs `90,61,37,29`). | |
| 5592 | + /// | |
| 5593 | + /// Both arms hard-assert per-attempt counters for the two chroma block | |
| 5594 | + /// shapes involved (`UV_CFL_PRED` blocks, nonzero `angle_delta_uv` | |
| 5595 | + /// blocks) plus the mi-exact UV-neighbour override, and are counted only | |
| 5596 | + /// on an attempt that decoded AND is pixel-compared. | |
| 5597 | + #[test] | |
| 5598 | + fn a_real_aomenc_stream_whose_chroma_edge_filter_reads_a_sub16_neighbours_uv_mode_decodes_pixel_exact() | |
| 5599 | + { | |
| 5600 | + const NAME: &str = "a_real_aomenc_stream_whose_chroma_edge_filter_reads_a_sub16_neighbours_uv_mode_decodes_pixel_exact"; | |
| 5601 | + let _gate_lock = lock_gate_counters(); | |
| 5602 | + if !have_ffmpeg() { | |
| 5603 | + eprintln!("SKIP {NAME}: no ffmpeg"); | |
| 5604 | + return; | |
| 5605 | + } | |
| 5606 | + if !have_aomenc() { | |
| 5607 | + eprintln!("SKIP {NAME}: no aomenc at {}", aomenc_path().display()); | |
| 5608 | + return; | |
| 5609 | + } | |
| 5610 | + let mut compared = 0usize; | |
| 5611 | + let (width, height) = (64usize, 64usize); | |
| 5612 | + // 8-bit arm = the r5 residue cell ("mandfi161"); 10-bit arm = its | |
| 5613 | + // twin through the same recipe at `--bit-depth=10`. | |
| 5614 | + for depth in [8usize, 10] { | |
| 5615 | + let pix = if depth == 10 { "yuv420p10le" } else { "yuv420p" }; | |
| 5616 | + let y4m = Command::new("ffmpeg") | |
| 5617 | + .args([ | |
| 5618 | + "-v", "error", "-f", "lavfi", "-i", | |
| 5619 | + &format!("mandelbrot=size={width}x{height}:start_x=-0.6"), | |
| 5620 | + "-pix_fmt", pix, "-strict", "-1", "-t", "1", "-vframes", "1", | |
| 5621 | + "-f", "yuv4mpegpipe", "-", | |
| 5622 | + ]) | |
| 5623 | + .stdin(Stdio::null()) | |
| 5624 | + .stdout(Stdio::piped()) | |
| 5625 | + .stderr(Stdio::piped()) | |
| 5626 | + .output() | |
| 5627 | + .expect("ffmpeg failed to run"); | |
| 5628 | + assert!( | |
| 5629 | + y4m.status.success(), | |
| 5630 | + "{NAME}: ffmpeg fixture (depth={depth}): {}", | |
| 5631 | + String::from_utf8_lossy(&y4m.stderr) | |
| 5632 | + ); | |
| 5633 | + let encode = || { | |
| 5634 | + let mut child = Command::new(aomenc_path()) | |
| 5635 | + .args([ | |
| 5636 | + "--codec=av1", "--passes=1", "--end-usage=q", "--cq-level=16", | |
| 5637 | + "--cpu-used=4", "--threads=1", "--row-mt=0", "--sb-size=64", | |
| 5638 | + "--kf-max-dist=0", "--enable-rect-partitions=1", | |
| 5639 | + "--enable-ab-partitions=0", "--enable-1to4-partitions=0", | |
| 5640 | + "--enable-tx-size-search=0", "--enable-filter-intra=1", | |
| 5641 | + "--reduced-tx-type-set=1", "--min-partition-size=8", | |
| 5642 | + "--max-partition-size=32", | |
| 5643 | + &format!("--input-bit-depth={depth}"), | |
| 5644 | + &format!("--bit-depth={depth}"), | |
| 5645 | + "--obu", "-o", "-", "-", | |
| 5646 | + ]) | |
| 5647 | + .stdin(Stdio::piped()) | |
| 5648 | + .stdout(Stdio::piped()) | |
| 5649 | + .stderr(Stdio::piped()) | |
| 5650 | + .spawn() | |
| 5651 | + .expect("aomenc failed to start"); | |
| 5652 | + child | |
| 5653 | + .stdin | |
| 5654 | + .take() | |
| 5655 | + .expect("aomenc stdin") | |
| 5656 | + .write_all(&y4m.stdout) | |
| 5657 | + .expect("writing y4m to aomenc"); | |
| 5658 | + let out = child.wait_with_output().expect("aomenc failed to run"); | |
| 5659 | + assert!( | |
| 5660 | + out.status.success(), | |
| 5661 | + "aomenc refused the fixture (depth={depth}): {}", | |
| 5662 | + String::from_utf8_lossy(&out.stderr) | |
| 5663 | + ); | |
| 5664 | + out.stdout | |
| 5665 | + }; | |
| 5666 | + let stream = encode(); | |
| 5667 | + assert_eq!( | |
| 5668 | + stream, | |
| 5669 | + encode(), | |
| 5670 | + "{NAME}: aomenc output is not reproducible (depth={depth})" | |
| 5671 | + ); | |
| 5672 | + let before_cfl = crate::decode::cfl_block_hits(); | |
| 5673 | + let before_angle = crate::decode::uv_angle_delta_hits(); | |
| 5674 | + let before_uv = crate::decode::uv_mode_mi_override_hits(); | |
| 5675 | + let frames = match decode_stream(&stream) { | |
| 5676 | + Ok(frames) => frames, | |
| 5677 | + // Only a NAMED refusal is tolerated (COMMON rule): the 10-bit | |
| 5678 | + // twin of this recipe still stops at another lane's open | |
| 5679 | + // sub-16 AB-partition / strip-filter-intra refusals, so it | |
| 5680 | + // cannot be compared yet. Any other error is a failure, and | |
| 5681 | + // `compared` below keeps the test from passing vacuously. | |
| 5682 | + Err(e) => { | |
| 5683 | + let msg = e.to_string(); | |
| 5684 | + assert!( | |
| 5685 | + msg.contains("unsupported"), | |
| 5686 | + "{NAME}: decode failed (depth={depth}): {msg}" | |
| 5687 | + ); | |
| 5688 | + eprintln!("{NAME}: depth={depth} arm refused (not compared): {msg}"); | |
| 5689 | + continue; | |
| 5690 | + } | |
| 5691 | + }; | |
| 5692 | + compared += 1; | |
| 5693 | + // Read only on an attempt that decoded AND is compared below. | |
| 5694 | + let cfl_blocks = crate::decode::cfl_block_hits() - before_cfl; | |
| 5695 | + let angle_blocks = crate::decode::uv_angle_delta_hits() - before_angle; | |
| 5696 | + let uv_overrides = crate::decode::uv_mode_mi_override_hits() - before_uv; | |
| 5697 | + let ffmpeg_frames = if depth == 10 { | |
| 5698 | + ffmpeg_decode_sequence_10bit(&stream, width, height, frames.len()) | |
| 5699 | + } else { | |
| 5700 | + ffmpeg_decode_sequence(&stream, width, height, frames.len()) | |
| 5701 | + }; | |
| 5702 | + assert_eq!(frames.len(), 1, "{NAME}: expected one key frame (depth={depth})"); | |
| 5703 | + assert_eq!(ffmpeg_frames.len(), frames.len(), "{NAME}: ffmpeg frame count"); | |
| 5704 | + for (i, (got, want)) in frames.iter().zip(&ffmpeg_frames).enumerate() { | |
| 5705 | + assert_eq!(got.y, want.y, "{NAME} frame {i} luma vs ffmpeg (depth={depth})"); | |
| 5706 | + assert_eq!( | |
| 5707 | + got.u, want.u, | |
| 5708 | + "{NAME} frame {i} U vs ffmpeg (depth={depth}, {cfl_blocks} CFL blocks, \ | |
| 5709 | + {angle_blocks} nonzero-angle_delta_uv blocks, {uv_overrides} mi-exact UV \ | |
| 5710 | + neighbour overrides)" | |
| 5711 | + ); | |
| 5712 | + assert_eq!( | |
| 5713 | + got.v, want.v, | |
| 5714 | + "{NAME} frame {i} V vs ffmpeg (depth={depth}, {cfl_blocks} CFL blocks, \ | |
| 5715 | + {angle_blocks} nonzero-angle_delta_uv blocks, {uv_overrides} mi-exact UV \ | |
| 5716 | + neighbour overrides)" | |
| 5717 | + ); | |
| 5718 | + } | |
| 5719 | + assert!( | |
| 5720 | + cfl_blocks > 0, | |
| 5721 | + "{NAME}: no UV_CFL_PRED block decoded (depth={depth}) -- the gate proves nothing" | |
| 5722 | + ); | |
| 5723 | + assert!( | |
| 5724 | + angle_blocks > 0, | |
| 5725 | + "{NAME}: no nonzero angle_delta_uv chroma block decoded (depth={depth}) -- \ | |
| 5726 | + the chroma intra-edge filter path never ran" | |
| 5727 | + ); | |
| 5728 | + assert!( | |
| 5729 | + uv_overrides > 0, | |
| 5730 | + "{NAME}: no chroma edge-filter read ever took a mi-exact UV neighbour that \ | |
| 5731 | + disagreed with its coarse 16x16 slot (depth={depth}) -- the r1 defect is \ | |
| 5732 | + not exercised" | |
| 5733 | + ); | |
| 5734 | + eprintln!( | |
| 5735 | + "{NAME}: pixel-exact at {depth}-bit, cfl_blocks={cfl_blocks} \ | |
| 5736 | + angle_delta_uv_blocks={angle_blocks} uv_mi_overrides={uv_overrides}" | |
| 5737 | + ); | |
| 5738 | + } | |
| 5739 | + assert!( | |
| 5740 | + compared > 0, | |
| 5741 | + "{NAME}: every arm refused -- the gate compared no pixels at all" | |
| 5742 | + ); | |
| 5743 | + } | |
| 5744 | + | |
| 5575 | 5745 | #[test] |
| 5576 | 5746 | #[ignore = "lane-rectx r3 scratch sweep"] |
| 5577 | 5747 | fn sweep_rectx_recipes() { |