forge
Explore
Log in

Don't you dare go Hollow

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 commit

6c2db9eb9d611cd9b73af32b8025843cb61c5e80Ahmet Kaan GümüşParent: 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
Show full message
fix(av1): 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

libaom's get_filt_type (reconintra.c) picks the chroma intra-edge filter
strength from chroma_above_mbmi/chroma_left_mbmi's `uv_mode`. Two defects
stacked on the sub-16x16 path:

1. decode_leaf_rect / decode_leaf_8x8 passed a literal `false` for
   smooth_neighbor_uv into every chroma reconstruct_rect call -- chroma edges
   were never smooth-filtered below 16x16, whatever the neighbour was.
2. The coarse SUB (16px) above_uv_mode/left_uv_mode cells are written by
   `for cell in 0..w / SUB`, which runs ZERO times for a block narrower than
   16 -- so even the 16x16-and-up readers saw whatever a larger block had
   left in the slot, not the real neighbour (class: context read from one
   cell / neighbour map coarser than the block).

Fix: Neighbours::sub8_mode_{col,row} carry the uv_mode alongside the luma
mode, and uv_modes_above_left{,_mi} resolve the mi-exact chroma neighbour
with the coarse slot only as fallback (tile-edge guards inherited from the
luma twin). Every chroma reconstruct site now passes the derived
smooth_neighbor_uv; zero `None, false,` sites remain in decode.rs.

Gate: a_real_aomenc_stream_whose_chroma_edge_filter_reads_a_sub16_neighbours_uv_mode_decodes_pixel_exact
(mandelbrot start_x=-0.6 64x64, cq16, filter-intra on, reduced-tx-type-set=1,
min/max-partition-size 8/32) -- 8-bit arm pixel-exact vs ffmpeg with
cfl_blocks=15, angle_delta_uv_blocks=19, uv_mi_overrides=52 hard-asserted;
the 10-bit twin still refuses on another lane's sub-16 AB-partition gap and
is skipped from comparison, with a `compared > 0` assert keeping the gate
from passing vacuously.
crates/ec-av1/src/decode.rsmodified+149 -30
@@ -771,6 +771,38 @@ pub(crate) fn mode_mi_override_hits() -> usize {
771 MODE_MI_OVERRIDE_HITS.with(|c| c.get())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 // lane-sbpart r2: how many superblock-level `PARTITION_HORZ`/`PARTITION_VERT`806 // lane-sbpart r2: how many superblock-level `PARTITION_HORZ`/`PARTITION_VERT`
775 // blocks (two true 64x32/32x64 strips, [`decode_block_rect64`]) fired -- the807 // blocks (two true 64x32/32x64 strips, [`decode_block_rect64`]) fired -- the
776 // gate's proof this round's arms actually reached a real block, not just808 // gate's proof this round's arms actually reached a real block, not just
@@ -1851,8 +1883,8 @@ struct Neighbours {
1851 /// and read only by [`decode_leaf_split4`]; the position guard makes it1883 /// and read only by [`decode_leaf_split4`]; the position guard makes it
1852 /// fall back to the coarse slot whenever the real neighbour was a block1884 /// fall back to the coarse slot whenever the real neighbour was a block
1853 /// of 8x8 or larger (whose one mode is correct for every row it spans).1885 /// of 8x8 or larger (whose one mode is correct for every row it spans).
1854- sub8_mode_col: Vec<(usize, usize)>,1886+ sub8_mode_col: Vec<(usize, usize, usize)>,
1855- sub8_mode_row: Vec<(usize, usize)>,1887+ sub8_mode_row: Vec<(usize, usize, usize)>,
1856 /// Whether the block above/left of this column/row was coded `skip` --1888 /// Whether the block above/left of this column/row was coded `skip` --
1857 /// an inter frame's own `skip` context (spec `SkipContext`), which the1889 /// an inter frame's own `skip` context (spec `SkipContext`), which the
1858 /// key-frame writer never tracks (its skip context is always zero); a1890 /// key-frame writer never tracks (its skip context is always zero); a
@@ -1980,8 +2012,8 @@ impl Neighbours {
1980 left_side: vec![SB; rows],2012 left_side: vec![SB; rows],
1981 above_side_mi: vec![SB; cols * (SUB / MI)],2013 above_side_mi: vec![SB; cols * (SUB / MI)],
1982 left_side_mi: vec![SB; rows * (SUB / MI)],2014 left_side_mi: vec![SB; rows * (SUB / MI)],
1983- sub8_mode_col: vec![(usize::MAX, 0); cols * (SUB / MI)],2015+ sub8_mode_col: vec![(usize::MAX, 0, 0); cols * (SUB / MI)],
1984- sub8_mode_row: vec![(usize::MAX, 0); rows * (SUB / MI)],2016+ sub8_mode_row: vec![(usize::MAX, 0, 0); rows * (SUB / MI)],
1985 above_skip: vec![false; cols],2017 above_skip: vec![false; cols],
1986 left_skip: vec![false; rows],2018 left_skip: vec![false; rows],
1987 above_skip_mode: vec![false; cols],2019 above_skip_mode: vec![false; cols],
@@ -2054,7 +2086,7 @@ impl Neighbours {
2054 // unreset, a tile read its LEFT tile's modes across the boundary.2086 // unreset, a tile read its LEFT tile's modes across the boundary.
2055 for i in col0_mi.min(end)..end {2087 for i in col0_mi.min(end)..end {
2056 if let Some(slot) = self.sub8_mode_col.get_mut(i) {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 self.left_comp_group_idx.iter_mut().for_each(|r| *r = 0);2346 self.left_comp_group_idx.iter_mut().for_each(|r| *r = 0);
2315 self.left_compound_idx.iter_mut().for_each(|r| *r = 0);2347 self.left_compound_idx.iter_mut().for_each(|r| *r = 0);
2316 self.left_filter.iter_mut().for_each(|f| *f = [3u8; 2]);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 /// Records a block's `skip`/`is_inter`/`interp_filter` state for the next2352 /// Records a block's `skip`/`is_inter`/`interp_filter` state for the next
@@ -2560,16 +2592,24 @@ impl Neighbours {
2560 /// block to the right reads via `mi(row, col-1)`). Only sub-8x8 leaves2592 /// block to the right reads via `mi(row, col-1)`). Only sub-8x8 leaves
2561 /// read these back, and only when the recorded position is exactly their2593 /// read these back, and only when the recorded position is exactly their
2562 /// own neighbour -- see [`Self::sub8_mode_col`]'s doc.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 let (last_r, last_c) = (mi_r + mi_h - 1, mi_c + mi_w - 1);2604 let (last_r, last_c) = (mi_r + mi_h - 1, mi_c + mi_w - 1);
2565 for cell in 0..mi_w {2605 for cell in 0..mi_w {
2566 if let Some(slot) = self.sub8_mode_col.get_mut(mi_c + cell) {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 for cell in 0..mi_h {2610 for cell in 0..mi_h {
2571 if let Some(slot) = self.sub8_mode_row.get_mut(mi_r + cell) {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 /// construction). See [`Self::record_mode_mi`].2620 /// construction). See [`Self::record_mode_mi`].
2581 fn mode_above_mi(&self, mi_r: usize, mi_c: usize) -> Option<usize> {2621 fn mode_above_mi(&self, mi_r: usize, mi_c: usize) -> Option<usize> {
2582 match self.sub8_mode_col.get(mi_c) {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 _ => None,2624 _ => None,
2585 }2625 }
2586 }2626 }
2587 2627
2588 fn mode_left_mi(&self, mi_r: usize, mi_c: usize) -> Option<usize> {2628 fn mode_left_mi(&self, mi_r: usize, mi_c: usize) -> Option<usize> {
2589 match self.sub8_mode_row.get(mi_r) {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 _ => None,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 /// The above/left luma modes libaom's `above_mi`/`left_mi` really see for a2679 /// The above/left luma modes libaom's `above_mi`/`left_mi` really see for a
2596 /// block at coarse [`SUB`]-grid `(r, c)`. lane-rectx r5: the coarse2680 /// block at coarse [`SUB`]-grid `(r, c)`. lane-rectx r5: the coarse
2597 /// `above_mode`/`left_mode` slots are written in 16x16 cells, so a2681 /// `above_mode`/`left_mode` slots are written in 16x16 cells, so a
@@ -2631,7 +2715,7 @@ impl Neighbours {
2631 self.left_uv_mode[r + cell] = uv_mode;2715 self.left_uv_mode[r + cell] = uv_mode;
2632 self.left_side[r + cell] = h;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 self.record_mi_rect((r * (SUB / MI), c * (SUB / MI)), w, h, grids);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 let (mi_r, mi_c) = (r * (SUB / MI), c * (SUB / MI));2827 let (mi_r, mi_c) = (r * (SUB / MI), c * (SUB / MI));
2744 let side_mi = side / MI;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 for cell in 0..side_mi {2830 for cell in 0..side_mi {
2747 self.left_side_mi[mi_r + cell] = side;2831 self.left_side_mi[mi_r + cell] = side;
2748 self.above_side_mi[mi_c + cell] = side;2832 self.above_side_mi[mi_c + cell] = side;
@@ -3207,6 +3291,9 @@ fn read_intra_mode_rect(
3207 03291 0
3208 };3292 };
3209 istep!("angle_uv", angle_delta_uv);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 let mut filter_intra = None;3297 let mut filter_intra = None;
3211 if std::env::var_os("EC_AV1_TRACE").is_some() {3298 if std::env::var_os("EC_AV1_TRACE").is_some() {
3212 let (rng, _) = dec.debug_state();3299 let (rng, _) = dec.debug_state();
@@ -3333,7 +3420,10 @@ fn decode_block_rect(
3333 // (spec `get_intra_edge_filter_type`) reads the CHROMA neighbour's3420 // (spec `get_intra_edge_filter_type`) reads the CHROMA neighbour's
3334 // `uv_mode`, not the luma one.3421 // `uv_mode`, not the luma one.
3335 let smooth_neighbor_uv =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 if filter_intra.is_some() {3427 if filter_intra.is_some() {
3338 // `predict_filter_intra` (spec 7.11.2.3) is square-only in this3428 // `predict_filter_intra` (spec 7.11.2.3) is square-only in this
3339 // decoder (`assert_eq!(dst.len(), side*side)`) -- a real symbol was3429 // decoder (`assert_eq!(dst.len(), side*side)`) -- a real symbol was
@@ -3728,6 +3818,11 @@ fn decode_leaf_rect(
3728 ));3818 ));
3729 }3819 }
3730 let uv_predict_mode = if uv_mode == UV_CFL_PRED { DC_PRED } else { uv_mode };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 let depth = if tx_select {3826 let depth = if tx_select {
3732 let ctx = tx_size_context_rect(neighbours, leaf_mi, bw, bh);3827 let ctx = tx_size_context_rect(neighbours, leaf_mi, bw, bh);
3733 dec.symbol(&mut cdfs.tx_size_cat2[ctx])3828 dec.symbol(&mut cdfs.tx_size_cat2[ctx])
@@ -3756,11 +3851,11 @@ fn decode_leaf_rect(
3756 let ac = alpha.map(|_| cfl_ac_q3_rect(y, px, py, bw, bh));3851 let ac = alpha.map(|_| cfl_ac_q3_rect(y, px, py, bw, bh));
3757 u.reconstruct_rect(3852 u.reconstruct_rect(
3758 cpx, cpy, chroma_w, chroma_h, uv_predict_mode, angle_delta_uv, reach, &u_levels,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 v.reconstruct_rect(3856 v.reconstruct_rect(
3762 cpx, cpy, chroma_w, chroma_h, uv_predict_mode, angle_delta_uv, reach, &v_levels,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 } else {3860 } else {
3766 // lane-rectx: a genuine 16x8/8x16 luma transform (`TxbSet::LumaRect16x8`,3861 // lane-rectx: a genuine 16x8/8x16 luma transform (`TxbSet::LumaRect16x8`,
@@ -3812,7 +3907,7 @@ fn decode_leaf_rect(
3812 );3907 );
3813 u.reconstruct_rect(3908 u.reconstruct_rect(
3814 cpx, cpy, chroma_w, chroma_h, uv_predict_mode, angle_delta_uv, reach, &u_residual,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 let v_default_tx = default_intra_tx_type(uv_predict_mode as u8);3912 let v_default_tx = default_intra_tx_type(uv_predict_mode as u8);
3818 let v_skip_ctx = usize::from(around[2].0) + usize::from(around[2].1);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 v.reconstruct_rect(3924 v.reconstruct_rect(
3830 cpx, cpy, chroma_w, chroma_h, uv_predict_mode, angle_delta_uv, reach, &v_residual,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 RECT_LEAF_COEFF_HITS.with(|c| c.set(c.get() + 1));3928 RECT_LEAF_COEFF_HITS.with(|c| c.set(c.get() + 1));
3834 }3929 }
@@ -3837,7 +3932,7 @@ fn decode_leaf_rect(
3837 neighbours.fill_lf_grid_rect(leaf_mi, mi_w, mi_h, bw as u8, bh as u8, 0);3932 neighbours.fill_lf_grid_rect(leaf_mi, mi_w, mi_h, bw as u8, bh as u8, 0);
3838 // A rect leaf spans mi_w x mi_h, so its mode reaches several columns and3933 // A rect leaf spans mi_w x mi_h, so its mode reaches several columns and
3839 // rows -- record the whole span, not one cell.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 Ok(mode)3936 Ok(mode)
3842 }3937 }
3843 3938
@@ -3904,7 +3999,10 @@ fn decode_block_rect64(
3904 SMOOTH_LUMA_HITS.with(|c| c.set(c.get() + 1));3999 SMOOTH_LUMA_HITS.with(|c| c.set(c.get() + 1));
3905 }4000 }
3906 let smooth_neighbor_uv =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 if filter_intra.is_some() {4006 if filter_intra.is_some() {
3909 // `filter_intra_size_class_rect` already returns `None` for both4007 // `filter_intra_size_class_rect` already returns `None` for both
3910 // `(64, 32)` and `(32, 64)` (`av1_filter_intra_allowed_bsize` caps at4008 // `(64, 32)` and `(32, 64)` (`av1_filter_intra_allowed_bsize` caps at
@@ -4346,6 +4444,9 @@ fn read_intra_mode(
4346 04444 0
4347 };4445 };
4348 istep!("angle_uv", angle_delta_uv);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 // `read_palette_mode_info` (spec 5.11.13, libaom decodemv.c:567, called4450 // `read_palette_mode_info` (spec 5.11.13, libaom decodemv.c:567, called
4350 // at :840 right after `xd->cfl.store_y` and before `read_filter_intra_mode_info`):4451 // at :840 right after `xd->cfl.store_y` and before `read_filter_intra_mode_info`):
4351 // gated by `av1_allow_palette` (blockd.h -- size bound only,4452 // gated by `av1_allow_palette` (blockd.h -- size bound only,
@@ -4497,6 +4598,7 @@ const UV_CFL_PRED: usize = 13;
4497 /// joint sign the same way. Returns each plane's final signed `alpha_q3`4598 /// joint sign the same way. Returns each plane's final signed `alpha_q3`
4498 /// (`cfl_idx_to_alpha`, cfl.c): magnitude `idx + 1`, sign-zero collapsing to 0.4599 /// (`cfl_idx_to_alpha`, cfl.c): magnitude `idx + 1`, sign-zero collapsing to 0.
4499 fn read_cfl_alphas(dec: &mut SymbolDecoder, cdfs: &mut Cdfs) -> (i32, i32) {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 let joint_sign = dec.symbol(&mut cdfs.cfl_sign) as i32;4602 let joint_sign = dec.symbol(&mut cdfs.cfl_sign) as i32;
4501 let sign_u = ((joint_sign + 1) * 11) >> 5;4603 let sign_u = ((joint_sign + 1) * 11) >> 5;
4502 let sign_v = (joint_sign + 1) - 3 * sign_u;4604 let sign_v = (joint_sign + 1) - 3 * sign_u;
@@ -5018,7 +5120,10 @@ fn decode_block(
5018 SMOOTH_LUMA_HITS.with(|c| c.set(c.get() + 1));5120 SMOOTH_LUMA_HITS.with(|c| c.set(c.get() + 1));
5019 }5121 }
5020 let smooth_neighbor_uv =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 if std::env::var_os("EC_AV1_TRACE").is_some() {5127 if std::env::var_os("EC_AV1_TRACE").is_some() {
5023 eprintln!(5128 eprintln!(
5024 "TRACE block px={px} py={py} side={side} mode={mode} uv_mode={uv_mode} \5129 "TRACE block px={px} py={py} side={side} mode={mode} uv_mode={uv_mode} \
@@ -5437,6 +5542,14 @@ fn decode_leaf8(
5437 if smooth_neighbor {5542 if smooth_neighbor {
5438 SMOOTH_LUMA_HITS.with(|c| c.set(c.get() + 1));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 // An 8x8 leaf is well within `is_cfl_allowed`'s <=32x32 bound (spec5553 // An 8x8 leaf is well within `is_cfl_allowed`'s <=32x32 bound (spec
5441 // 5.11.5), so it reads the CFL-allowed `uv_mode_cfl` CDF, like every other5554 // 5.11.5), so it reads the CFL-allowed `uv_mode_cfl` CDF, like every other
5442 // `decode_block` caller at 16x16 and up.5555 // `decode_block` caller at 16x16 and up.
@@ -5500,7 +5613,7 @@ fn decode_leaf8(
5500 &vec![0i32; 16],5613 &vec![0i32; 16],
5501 alpha.zip(ac.as_deref()).map(|((au, _), ac)| (au, ac)),5614 alpha.zip(ac.as_deref()).map(|((au, _), ac)| (au, ac)),
5502 None,5615 None,
5503- false,5616+ smooth_neighbor_uv,
5504 );5617 );
5505 v.reconstruct(5618 v.reconstruct(
5506 cpx,5619 cpx,
@@ -5512,7 +5625,7 @@ fn decode_leaf8(
5512 &vec![0i32; 16],5625 &vec![0i32; 16],
5513 alpha.zip(ac.as_deref()).map(|((_, av), ac)| (av, ac)),5626 alpha.zip(ac.as_deref()).map(|((_, av), ac)| (av, ac)),
5514 None,5627 None,
5515- false,5628+ smooth_neighbor_uv,
5516 );5629 );
5517 luma_grid = vec![0i32; 64];5630 luma_grid = vec![0i32; 64];
5518 u_grid = vec![0i32; 16];5631 u_grid = vec![0i32; 16];
@@ -5566,7 +5679,7 @@ fn decode_leaf8(
5566 alpha.zip(ac.as_deref()).map(|((au, _), ac)| (au, ac)),5679 alpha.zip(ac.as_deref()).map(|((au, _), ac)| (au, ac)),
5567 None,5680 None,
5568 None,5681 None,
5569- false,5682+ smooth_neighbor_uv,
5570 )?;5683 )?;
5571 v_grid = read_plane(5684 v_grid = read_plane(
5572 dec,5685 dec,
@@ -5588,7 +5701,7 @@ fn decode_leaf8(
5588 alpha.zip(ac.as_deref()).map(|((_, av), ac)| (av, ac)),5701 alpha.zip(ac.as_deref()).map(|((_, av), ac)| (av, ac)),
5589 None,5702 None,
5590 None,5703 None,
5591- false,5704+ smooth_neighbor_uv,
5592 )?;5705 )?;
5593 } else {5706 } else {
5594 // `tx_depth` resolved this leaf's luma to `TX4`: a 2x2 raster-order5707 // `tx_depth` resolved this leaf's luma to `TX4`: a 2x2 raster-order
@@ -5664,7 +5777,7 @@ fn decode_leaf8(
5664 alpha.zip(ac.as_deref()).map(|((au, _), ac)| (au, ac)),5777 alpha.zip(ac.as_deref()).map(|((au, _), ac)| (au, ac)),
5665 None,5778 None,
5666 None,5779 None,
5667- false,5780+ smooth_neighbor_uv,
5668 )?;5781 )?;
5669 v_grid = read_plane(5782 v_grid = read_plane(
5670 dec,5783 dec,
@@ -5686,7 +5799,7 @@ fn decode_leaf8(
5686 alpha.zip(ac.as_deref()).map(|((_, av), ac)| (av, ac)),5799 alpha.zip(ac.as_deref()).map(|((_, av), ac)| (av, ac)),
5687 None,5800 None,
5688 None,5801 None,
5689- false,5802+ smooth_neighbor_uv,
5690 )?;5803 )?;
5691 // `record_split_luma` expects a `record`-style `(r, c)` position in5804 // `record_split_luma` expects a `record`-style `(r, c)` position in
5692 // `SUB`-grid units and rescales it by `SUB / MI`; `leaf_mi` is5805 // `SUB`-grid units and rescales it by `SUB / MI`; `leaf_mi` is
@@ -5718,13 +5831,13 @@ fn decode_leaf8(
5718 }5831 }
5719 neighbours.fill_skip_grid(leaf_mi, 2, skip);5832 neighbours.fill_skip_grid(leaf_mi, 2, skip);
5720 neighbours.fill_lf_grid(leaf_mi, 2, 4, 0);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 return Ok(mode);5835 return Ok(mode);
5723 }5836 }
5724 neighbours.record_mi(leaf_mi, 8, &[luma_grid, u_grid, v_grid]);5837 neighbours.record_mi(leaf_mi, 8, &[luma_grid, u_grid, v_grid]);
5725 neighbours.fill_skip_grid(leaf_mi, 2, skip);5838 neighbours.fill_skip_grid(leaf_mi, 2, skip);
5726 neighbours.fill_lf_grid(leaf_mi, 2, 8, 0);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 Ok(mode)5841 Ok(mode)
5729 }5842 }
5730 5843
@@ -10670,6 +10783,9 @@ fn decode_inter_block(
10670 } else {10783 } else {
10671 010784 0
10672 };10785 };
10786+ if angle_delta_uv != 0 {
10787+ UV_ANGLE_DELTA_HITS.with(|c| c.set(c.get() + 1));
10788+ }
10673 uv_predict_mode = if uv_mode == UV_CFL_PRED {10789 uv_predict_mode = if uv_mode == UV_CFL_PRED {
10674 DC_PRED10790 DC_PRED
10675 } else {10791 } else {
@@ -10679,7 +10795,10 @@ fn decode_inter_block(
10679 // as [`read_intra_mode`]/[`read_intra_mode_rect`] -- the CHROMA10795 // as [`read_intra_mode`]/[`read_intra_mode_rect`] -- the CHROMA
10680 // neighbour's own `uv_mode`, not the luma one.10796 // neighbour's own `uv_mode`, not the luma one.
10681 let smooth_neighbor_uv =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 // `read_palette_mode_info` (decodemv.c:567, called from10802 // `read_palette_mode_info` (decodemv.c:567, called from
10684 // `read_intra_block_mode_info` right after `xd->cfl.store_y`, same10803 // `read_intra_block_mode_info` right after `xd->cfl.store_y`, same
10685 // gating and same corner-cut as `read_intra_mode`'s own copy above10804 // 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 eprintln!("{NAME}: pixel-exact, mode_mi_override_hits={total_overrides}");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 #[test]5745 #[test]
5576 #[ignore = "lane-rectx r3 scratch sweep"]5746 #[ignore = "lane-rectx r3 scratch sweep"]
5577 fn sweep_rectx_recipes() {5747 fn sweep_rectx_recipes() {