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 {
771771 MODE_MI_OVERRIDE_HITS.with(|c| c.get())
772772 }
773773
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+
774806 // lane-sbpart r2: how many superblock-level `PARTITION_HORZ`/`PARTITION_VERT`
775807 // blocks (two true 64x32/32x64 strips, [`decode_block_rect64`]) fired -- the
776808 // gate's proof this round's arms actually reached a real block, not just
@@ -1851,8 +1883,8 @@ struct Neighbours {
18511883 /// and read only by [`decode_leaf_split4`]; the position guard makes it
18521884 /// fall back to the coarse slot whenever the real neighbour was a block
18531885 /// 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)>,
18561888 /// Whether the block above/left of this column/row was coded `skip` --
18571889 /// an inter frame's own `skip` context (spec `SkipContext`), which the
18581890 /// key-frame writer never tracks (its skip context is always zero); a
@@ -1980,8 +2012,8 @@ impl Neighbours {
19802012 left_side: vec![SB; rows],
19812013 above_side_mi: vec![SB; cols * (SUB / MI)],
19822014 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)],
19852017 above_skip: vec![false; cols],
19862018 left_skip: vec![false; rows],
19872019 above_skip_mode: vec![false; cols],
@@ -2054,7 +2086,7 @@ impl Neighbours {
20542086 // unreset, a tile read its LEFT tile's modes across the boundary.
20552087 for i in col0_mi.min(end)..end {
20562088 if let Some(slot) = self.sub8_mode_col.get_mut(i) {
2057- *slot = (usize::MAX, 0);
2089+ *slot = (usize::MAX, 0, 0);
20582090 }
20592091 }
20602092 }
@@ -2314,7 +2346,7 @@ impl Neighbours {
23142346 self.left_comp_group_idx.iter_mut().for_each(|r| *r = 0);
23152347 self.left_compound_idx.iter_mut().for_each(|r| *r = 0);
23162348 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));
23182350 }
23192351
23202352 /// Records a block's `skip`/`is_inter`/`interp_filter` state for the next
@@ -2560,16 +2592,24 @@ impl Neighbours {
25602592 /// block to the right reads via `mi(row, col-1)`). Only sub-8x8 leaves
25612593 /// read these back, and only when the recorded position is exactly their
25622594 /// 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+ ) {
25642604 let (last_r, last_c) = (mi_r + mi_h - 1, mi_c + mi_w - 1);
25652605 for cell in 0..mi_w {
25662606 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);
25682608 }
25692609 }
25702610 for cell in 0..mi_h {
25712611 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);
25732613 }
25742614 }
25752615 }
@@ -2580,18 +2620,62 @@ impl Neighbours {
25802620 /// construction). See [`Self::record_mode_mi`].
25812621 fn mode_above_mi(&self, mi_r: usize, mi_c: usize) -> Option<usize> {
25822622 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),
25842624 _ => None,
25852625 }
25862626 }
25872627
25882628 fn mode_left_mi(&self, mi_r: usize, mi_c: usize) -> Option<usize> {
25892629 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),
25912652 _ => None,
25922653 }
25932654 }
25942655
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+
25952679 /// The above/left luma modes libaom's `above_mi`/`left_mi` really see for a
25962680 /// block at coarse [`SUB`]-grid `(r, c)`. lane-rectx r5: the coarse
25972681 /// `above_mode`/`left_mode` slots are written in 16x16 cells, so a
@@ -2631,7 +2715,7 @@ impl Neighbours {
26312715 self.left_uv_mode[r + cell] = uv_mode;
26322716 self.left_side[r + cell] = h;
26332717 }
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);
26352719 self.record_mi_rect((r * (SUB / MI), c * (SUB / MI)), w, h, grids);
26362720 }
26372721
@@ -2742,7 +2826,7 @@ impl Neighbours {
27422826 }
27432827 let (mi_r, mi_c) = (r * (SUB / MI), c * (SUB / MI));
27442828 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);
27462830 for cell in 0..side_mi {
27472831 self.left_side_mi[mi_r + cell] = side;
27482832 self.above_side_mi[mi_c + cell] = side;
@@ -3207,6 +3291,9 @@ fn read_intra_mode_rect(
32073291 0
32083292 };
32093293 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+ }
32103297 let mut filter_intra = None;
32113298 if std::env::var_os("EC_AV1_TRACE").is_some() {
32123299 let (rng, _) = dec.debug_state();
@@ -3333,7 +3420,10 @@ fn decode_block_rect(
33333420 // (spec `get_intra_edge_filter_type`) reads the CHROMA neighbour's
33343421 // `uv_mode`, not the luma one.
33353422 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+ };
33373427 if filter_intra.is_some() {
33383428 // `predict_filter_intra` (spec 7.11.2.3) is square-only in this
33393429 // decoder (`assert_eq!(dst.len(), side*side)`) -- a real symbol was
@@ -3728,6 +3818,11 @@ fn decode_leaf_rect(
37283818 ));
37293819 }
37303820 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);
37313826 let depth = if tx_select {
37323827 let ctx = tx_size_context_rect(neighbours, leaf_mi, bw, bh);
37333828 dec.symbol(&mut cdfs.tx_size_cat2[ctx])
@@ -3756,11 +3851,11 @@ fn decode_leaf_rect(
37563851 let ac = alpha.map(|_| cfl_ac_q3_rect(y, px, py, bw, bh));
37573852 u.reconstruct_rect(
37583853 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,
37603855 );
37613856 v.reconstruct_rect(
37623857 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,
37643859 );
37653860 } else {
37663861 // lane-rectx: a genuine 16x8/8x16 luma transform (`TxbSet::LumaRect16x8`,
@@ -3812,7 +3907,7 @@ fn decode_leaf_rect(
38123907 );
38133908 u.reconstruct_rect(
38143909 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,
38163911 );
38173912 let v_default_tx = default_intra_tx_type(uv_predict_mode as u8);
38183913 let v_skip_ctx = usize::from(around[2].0) + usize::from(around[2].1);
@@ -3828,7 +3923,7 @@ fn decode_leaf_rect(
38283923 );
38293924 v.reconstruct_rect(
38303925 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,
38323927 );
38333928 RECT_LEAF_COEFF_HITS.with(|c| c.set(c.get() + 1));
38343929 }
@@ -3837,7 +3932,7 @@ fn decode_leaf_rect(
38373932 neighbours.fill_lf_grid_rect(leaf_mi, mi_w, mi_h, bw as u8, bh as u8, 0);
38383933 // A rect leaf spans mi_w x mi_h, so its mode reaches several columns and
38393934 // 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);
38413936 Ok(mode)
38423937 }
38433938
@@ -3904,7 +3999,10 @@ fn decode_block_rect64(
39043999 SMOOTH_LUMA_HITS.with(|c| c.set(c.get() + 1));
39054000 }
39064001 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+ };
39084006 if filter_intra.is_some() {
39094007 // `filter_intra_size_class_rect` already returns `None` for both
39104008 // `(64, 32)` and `(32, 64)` (`av1_filter_intra_allowed_bsize` caps at
@@ -4346,6 +4444,9 @@ fn read_intra_mode(
43464444 0
43474445 };
43484446 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+ }
43494450 // `read_palette_mode_info` (spec 5.11.13, libaom decodemv.c:567, called
43504451 // at :840 right after `xd->cfl.store_y` and before `read_filter_intra_mode_info`):
43514452 // gated by `av1_allow_palette` (blockd.h -- size bound only,
@@ -4497,6 +4598,7 @@ const UV_CFL_PRED: usize = 13;
44974598 /// joint sign the same way. Returns each plane's final signed `alpha_q3`
44984599 /// (`cfl_idx_to_alpha`, cfl.c): magnitude `idx + 1`, sign-zero collapsing to 0.
44994600 fn read_cfl_alphas(dec: &mut SymbolDecoder, cdfs: &mut Cdfs) -> (i32, i32) {
4601+ CFL_BLOCK_HITS.with(|c| c.set(c.get() + 1));
45004602 let joint_sign = dec.symbol(&mut cdfs.cfl_sign) as i32;
45014603 let sign_u = ((joint_sign + 1) * 11) >> 5;
45024604 let sign_v = (joint_sign + 1) - 3 * sign_u;
@@ -5018,7 +5120,10 @@ fn decode_block(
50185120 SMOOTH_LUMA_HITS.with(|c| c.set(c.get() + 1));
50195121 }
50205122 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+ };
50225127 if std::env::var_os("EC_AV1_TRACE").is_some() {
50235128 eprintln!(
50245129 "TRACE block px={px} py={py} side={side} mode={mode} uv_mode={uv_mode} \
@@ -5437,6 +5542,14 @@ fn decode_leaf8(
54375542 if smooth_neighbor {
54385543 SMOOTH_LUMA_HITS.with(|c| c.set(c.get() + 1));
54395544 }
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);
54405553 // An 8x8 leaf is well within `is_cfl_allowed`'s <=32x32 bound (spec
54415554 // 5.11.5), so it reads the CFL-allowed `uv_mode_cfl` CDF, like every other
54425555 // `decode_block` caller at 16x16 and up.
@@ -5500,7 +5613,7 @@ fn decode_leaf8(
55005613 &vec![0i32; 16],
55015614 alpha.zip(ac.as_deref()).map(|((au, _), ac)| (au, ac)),
55025615 None,
5503- false,
5616+ smooth_neighbor_uv,
55045617 );
55055618 v.reconstruct(
55065619 cpx,
@@ -5512,7 +5625,7 @@ fn decode_leaf8(
55125625 &vec![0i32; 16],
55135626 alpha.zip(ac.as_deref()).map(|((_, av), ac)| (av, ac)),
55145627 None,
5515- false,
5628+ smooth_neighbor_uv,
55165629 );
55175630 luma_grid = vec![0i32; 64];
55185631 u_grid = vec![0i32; 16];
@@ -5566,7 +5679,7 @@ fn decode_leaf8(
55665679 alpha.zip(ac.as_deref()).map(|((au, _), ac)| (au, ac)),
55675680 None,
55685681 None,
5569- false,
5682+ smooth_neighbor_uv,
55705683 )?;
55715684 v_grid = read_plane(
55725685 dec,
@@ -5588,7 +5701,7 @@ fn decode_leaf8(
55885701 alpha.zip(ac.as_deref()).map(|((_, av), ac)| (av, ac)),
55895702 None,
55905703 None,
5591- false,
5704+ smooth_neighbor_uv,
55925705 )?;
55935706 } else {
55945707 // `tx_depth` resolved this leaf's luma to `TX4`: a 2x2 raster-order
@@ -5664,7 +5777,7 @@ fn decode_leaf8(
56645777 alpha.zip(ac.as_deref()).map(|((au, _), ac)| (au, ac)),
56655778 None,
56665779 None,
5667- false,
5780+ smooth_neighbor_uv,
56685781 )?;
56695782 v_grid = read_plane(
56705783 dec,
@@ -5686,7 +5799,7 @@ fn decode_leaf8(
56865799 alpha.zip(ac.as_deref()).map(|((_, av), ac)| (av, ac)),
56875800 None,
56885801 None,
5689- false,
5802+ smooth_neighbor_uv,
56905803 )?;
56915804 // `record_split_luma` expects a `record`-style `(r, c)` position in
56925805 // `SUB`-grid units and rescales it by `SUB / MI`; `leaf_mi` is
@@ -5718,13 +5831,13 @@ fn decode_leaf8(
57185831 }
57195832 neighbours.fill_skip_grid(leaf_mi, 2, skip);
57205833 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);
57225835 return Ok(mode);
57235836 }
57245837 neighbours.record_mi(leaf_mi, 8, &[luma_grid, u_grid, v_grid]);
57255838 neighbours.fill_skip_grid(leaf_mi, 2, skip);
57265839 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);
57285841 Ok(mode)
57295842 }
57305843
@@ -10670,6 +10783,9 @@ fn decode_inter_block(
1067010783 } else {
1067110784 0
1067210785 };
10786+ if angle_delta_uv != 0 {
10787+ UV_ANGLE_DELTA_HITS.with(|c| c.set(c.get() + 1));
10788+ }
1067310789 uv_predict_mode = if uv_mode == UV_CFL_PRED {
1067410790 DC_PRED
1067510791 } else {
@@ -10679,7 +10795,10 @@ fn decode_inter_block(
1067910795 // as [`read_intra_mode`]/[`read_intra_mode_rect`] -- the CHROMA
1068010796 // neighbour's own `uv_mode`, not the luma one.
1068110797 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+ };
1068310802 // `read_palette_mode_info` (decodemv.c:567, called from
1068410803 // `read_intra_block_mode_info` right after `xd->cfl.store_y`, same
1068510804 // 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 {
55725572 eprintln!("{NAME}: pixel-exact, mode_mi_override_hits={total_overrides}");
55735573 }
55745574
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+
55755745 #[test]
55765746 #[ignore = "lane-rectx r3 scratch sweep"]
55775747 fn sweep_rectx_recipes() {