forge
Explore
Log in

Don't you dare go Hollow

Merge branch 'lane-chroma': smooth, paeth and directional chroma decode

Browse files at this commit

be7060ab12dafa901a2145e9c9f167ecb479fa51Ahmet Kaan GümüşParent: 51e931cbf25067
The lane went looking for chroma modes and found a luma bug first:
reconstruct() hardcoded smooth_neighbor = false, so the intra edge filter took
the wrong strength bucket whenever a directional block neighboured a
smooth-predicted one. Its own comment called it a corner-cut. Twenty gates had
never caught it because every one of them passed --enable-smooth-intra=0.

Landed here: the luma fix with smooth_neighbor threaded properly, UV-mode
neighbour tracking, the smooth/paeth chroma refusals gone (blocker 5 of the
default-settings chain), and the directional-chroma sibling in
decode_inter_block's intra-in-inter branch.

Gate-proven for the key-frame path. The inter-frame intra-block path is a
structural mirror of it plus a green suite, NOT proven by firing -- the lane
disclosed this itself, and the owed gate is written down in
lanes/chroma-r4.report.md: force an inter-frame leaf with such a uv_mode,
assert smooth_uv_hits/directional_uv_hits and pixel-exactness.

Both guards fired as designed and are updated: gate_coverage loses
enable-smooth-intra and enable-paeth-intra, refusal_inventory loses the two
round-2 chroma refusals.

Suite 239 passed / 0 failed.
crates/ec-av1/src/decode.rsmodified+191 -27
@@ -133,6 +133,36 @@ fn maybe_read_cdef_idx(dec: &mut SymbolDecoder, mi_r: usize, mi_c: usize, skip:
133133 }
134134 }
135135
136+// How many key-frame luma blocks resolved `smooth_neighbor` (spec
137+// `get_intra_edge_filter_type`) to `true` -- lane-chroma r2's own before/after
138+// counter, proving a stream actually put a directional block next to a
139+// smooth-predicted neighbour rather than every block reading the (previously
140+// hardcoded `false`) edge-filter strength bucket unchanged.
141+thread_local! {
142+ static SMOOTH_LUMA_HITS: std::cell::Cell<usize> =
143+ const { std::cell::Cell::new(0) };
144+}
145+
146+/// Current value of [`SMOOTH_LUMA_HITS`].
147+pub(crate) fn smooth_luma_hits() -> usize {
148+ SMOOTH_LUMA_HITS.with(|c| c.get())
149+}
150+
151+// How many `uv_mode` reads resolved to `SMOOTH_PRED..=PAETH_PRED` (9..=12),
152+// across every call on the current thread -- lane-chroma r3's own before/after
153+// counter, proving a stream actually exercised chroma's smooth/paeth
154+// predictor (the previously-refused round-2 gap) rather than every block
155+// landing on DC/CFL/directional.
156+thread_local! {
157+ static SMOOTH_UV_HITS: std::cell::Cell<usize> =
158+ const { std::cell::Cell::new(0) };
159+}
160+
161+/// Current value of [`SMOOTH_UV_HITS`].
162+pub(crate) fn smooth_uv_hits() -> usize {
163+ SMOOTH_UV_HITS.with(|c| c.get())
164+}
165+
136166 // How many 4-pixel deblocking edge groups [`edge_params`] has actually
137167 // selected for filtering, across every call on the current thread -- the same
138168 // before/after counter pattern as [`FILTER_INTRA_HITS`], proving a stream
@@ -1017,6 +1047,13 @@ fn default_intra_tx_type(mode: u8) -> TxType {
10171047 }
10181048 }
10191049
1050+/// `is_smooth` (libaom `reconintra.c`): true for `SMOOTH_PRED..=SMOOTH_H_PRED`
1051+/// (9..=11) — deliberately excludes `PAETH_PRED` (12), which the spec's own
1052+/// `get_intra_edge_filter_type`/libaom `get_filt_type` never treat as smooth.
1053+fn is_smooth_mode(mode: usize) -> bool {
1054+ (crate::intra::SMOOTH_PRED as usize..=crate::intra::SMOOTH_H_PRED as usize).contains(&mode)
1055+}
1056+
10201057 fn read_coeffs(
10211058 dec: &mut SymbolDecoder,
10221059 coding: &mut TxbTables,
@@ -1308,6 +1345,17 @@ struct Neighbours {
13081345 left: Vec<[Neighbour; 3]>,
13091346 above_mode: Vec<usize>,
13101347 left_mode: Vec<usize>,
1348+ /// Chroma's own `uv_mode` companion to `above_mode`/`left_mode` (lane-chroma
1349+ /// r3): a smooth/paeth `uv_mode`'s edge-filter strength (spec
1350+ /// `get_intra_edge_filter_type`) reads the CHROMA neighbour's mode, not the
1351+ /// luma one -- the same block can (and often does) code a different
1352+ /// `uv_mode` than its own `mode`. Coarse [`SUB`]-grid like `above_mode`;
1353+ /// [`Self::decode_leaf8`]'s per-leaf `prev_leaf` override (a real
1354+ /// within-block neighbour finer than this grid) is luma-only -- a known,
1355+ /// unexercised-by-gate corner-cut (every real-encoder gate in `stream.rs`
1356+ /// uses `--min-partition-size=16`, so no leaf8 8x8 split ever reaches this).
1357+ above_uv_mode: Vec<usize>,
1358+ left_uv_mode: Vec<usize>,
13111359 above_side: Vec<usize>,
13121360 left_side: Vec<usize>,
13131361 /// The same as `above_side`/`left_side`, but kept at the finer mi (4x4)
@@ -1407,6 +1455,8 @@ impl Neighbours {
14071455 left: vec![[Neighbour::default(); 3]; rows * (SUB / MI)],
14081456 above_mode: vec![DC_PRED; cols],
14091457 left_mode: vec![DC_PRED; rows],
1458+ above_uv_mode: vec![DC_PRED; cols],
1459+ left_uv_mode: vec![DC_PRED; rows],
14101460 above_side: vec![SB; cols],
14111461 left_side: vec![SB; rows],
14121462 above_side_mi: vec![SB; cols * (SUB / MI)],
@@ -1540,6 +1590,7 @@ impl Neighbours {
15401590 fn start_row(&mut self) {
15411591 self.left.iter_mut().for_each(|l| *l = Default::default());
15421592 self.left_mode.iter_mut().for_each(|m| *m = DC_PRED);
1593+ self.left_uv_mode.iter_mut().for_each(|m| *m = DC_PRED);
15431594 self.left_side.iter_mut().for_each(|s| *s = SB);
15441595 self.left_side_mi.iter_mut().for_each(|s| *s = SB);
15451596 self.left_skip.iter_mut().for_each(|s| *s = false);
@@ -1771,8 +1822,15 @@ impl Neighbours {
17711822 /// `record` leaves them (spec `av1_set_entropy_contexts`, which clamps to
17721823 /// `blocks_wide`/`blocks_high` derived from the true `mi_cols`/`mi_rows`,
17731824 /// not from this block's own side).
1774- fn record(&mut self, at: (usize, usize), side: usize, mode: usize, grids: &[Vec<i32>; 3]) {
1775- self.record_rect(at, side, side, mode, grids);
1825+ fn record(
1826+ &mut self,
1827+ at: (usize, usize),
1828+ side: usize,
1829+ mode: usize,
1830+ uv_mode: usize,
1831+ grids: &[Vec<i32>; 3],
1832+ ) {
1833+ self.record_rect(at, side, side, mode, uv_mode, grids);
17761834 }
17771835
17781836 /// [`Self::record`] with independent above (`w`)/left (`h`) extents, in
@@ -1786,15 +1844,18 @@ impl Neighbours {
17861844 w: usize,
17871845 h: usize,
17881846 mode: usize,
1847+ uv_mode: usize,
17891848 grids: &[Vec<i32>; 3],
17901849 ) {
17911850 let (r, c) = at;
17921851 for cell in 0..w / SUB {
17931852 self.above_mode[c + cell] = mode;
1853+ self.above_uv_mode[c + cell] = uv_mode;
17941854 self.above_side[c + cell] = w;
17951855 }
17961856 for cell in 0..h / SUB {
17971857 self.left_mode[r + cell] = mode;
1858+ self.left_uv_mode[r + cell] = uv_mode;
17981859 self.left_side[r + cell] = h;
17991860 }
18001861 self.record_mi_rect((r * (SUB / MI), c * (SUB / MI)), w, h, grids);
@@ -1893,12 +1954,15 @@ impl Neighbours {
18931954 at: (usize, usize),
18941955 side: usize,
18951956 mode: usize,
1957+ uv_mode: usize,
18961958 chroma_grids: [&[i32]; 2],
18971959 ) {
18981960 let (r, c) = at;
18991961 for cell in 0..side / SUB {
19001962 self.above_mode[c + cell] = mode;
19011963 self.left_mode[r + cell] = mode;
1964+ self.above_uv_mode[c + cell] = uv_mode;
1965+ self.left_uv_mode[r + cell] = uv_mode;
19021966 self.above_side[c + cell] = side;
19031967 self.left_side[r + cell] = side;
19041968 }
@@ -2037,7 +2101,7 @@ fn read_intra_mode_rect(
20372101 None
20382102 };
20392103 if (9..=12).contains(&uv_mode) {
2040- return Err(unsupported("a smooth or paeth chroma mode (round 2)"));
2104+ SMOOTH_UV_HITS.with(|c| c.set(c.get() + 1));
20412105 }
20422106 let angle_delta_uv = if (V_PRED..=D67_PRED).contains(&uv_mode) {
20432107 DIRECTIONAL_UV_HITS.with(|c| c.set(c.get() + 1));
@@ -2162,6 +2226,16 @@ fn decode_block_rect(
21622226 r * (SUB / MI),
21632227 c * (SUB / MI),
21642228 )?;
2229+ let smooth_neighbor =
2230+ is_smooth_mode(neighbours.above_mode[c]) || is_smooth_mode(neighbours.left_mode[r]);
2231+ if smooth_neighbor {
2232+ SMOOTH_LUMA_HITS.with(|c| c.set(c.get() + 1));
2233+ }
2234+ // lane-chroma r3: chroma's own edge-filter-strength neighbour check
2235+ // (spec `get_intra_edge_filter_type`) reads the CHROMA neighbour's
2236+ // `uv_mode`, not the luma one.
2237+ let smooth_neighbor_uv =
2238+ is_smooth_mode(neighbours.above_uv_mode[c]) || is_smooth_mode(neighbours.left_uv_mode[r]);
21652239 if filter_intra.is_some() {
21662240 // `predict_filter_intra` (spec 7.11.2.3) is square-only in this
21672241 // decoder (`assert_eq!(dst.len(), side*side)`) -- a real symbol was
@@ -2227,6 +2301,7 @@ fn decode_block_rect(
22272301 &vec![0i32; bw * bh],
22282302 None,
22292303 filter_intra,
2304+ smooth_neighbor,
22302305 );
22312306 let ac = alpha.map(|_| cfl_ac_q3_rect(y, px, py, bw, bh));
22322307 u.reconstruct_rect(
@@ -2240,6 +2315,7 @@ fn decode_block_rect(
22402315 &vec![0i32; chroma_w * chroma_h],
22412316 alpha.zip(ac.as_deref()).map(|((au, _), ac)| (au, ac)),
22422317 None,
2318+ smooth_neighbor_uv,
22432319 );
22442320 v.reconstruct_rect(
22452321 cpx,
@@ -2252,12 +2328,14 @@ fn decode_block_rect(
22522328 &vec![0i32; chroma_w * chroma_h],
22532329 alpha.zip(ac.as_deref()).map(|((_, av), ac)| (av, ac)),
22542330 None,
2331+ smooth_neighbor_uv,
22552332 );
22562333 neighbours.record_rect(
22572334 at,
22582335 bw,
22592336 bh,
22602337 mode,
2338+ uv_predict_mode,
22612339 &[
22622340 vec![0i32; bw * bh],
22632341 vec![0i32; chroma_w * chroma_h],
@@ -2345,6 +2423,7 @@ fn decode_block_rect(
23452423 &luma_residual,
23462424 None,
23472425 filter_intra,
2426+ smooth_neighbor,
23482427 );
23492428 let ac = alpha.map(|_| cfl_ac_q3_rect(y, px, py, bw, bh));
23502429 let u_default_tx = default_intra_tx_type(uv_predict_mode as u8);
@@ -2383,6 +2462,7 @@ fn decode_block_rect(
23832462 &u_residual,
23842463 alpha.zip(ac.as_deref()).map(|((au, _), ac)| (au, ac)),
23852464 None,
2465+ smooth_neighbor_uv,
23862466 );
23872467 let v_default_tx = default_intra_tx_type(uv_predict_mode as u8);
23882468 let v_skip_ctx = usize::from(around[2].0) + usize::from(around[2].1);
@@ -2420,8 +2500,9 @@ fn decode_block_rect(
24202500 &v_residual,
24212501 alpha.zip(ac.as_deref()).map(|((_, av), ac)| (av, ac)),
24222502 None,
2503+ smooth_neighbor_uv,
24232504 );
2424- neighbours.record_rect(at, bw, bh, mode, &[luma_levels, u_levels, v_levels]);
2505+ neighbours.record_rect(at, bw, bh, mode, uv_predict_mode, &[luma_levels, u_levels, v_levels]);
24252506 RECT_COEFF_HITS.with(|c| c.set(c.get() + 1));
24262507 }
24272508 }
@@ -2533,7 +2614,7 @@ fn read_intra_mode(
25332614 // bug in that fallback this lane's own scope does not cover. Keep it
25342615 // refused here rather than ship a silently-wrong decode.
25352616 if (9..=12).contains(&uv_mode) {
2536- return Err(unsupported("a smooth or paeth chroma mode (round 2)"));
2617+ SMOOTH_UV_HITS.with(|c| c.set(c.get() + 1));
25372618 }
25382619 // `get_uv_mode` (spec 9.3): `UV_CFL_PRED` predicts as `DC_PRED` for the
25392620 // angle-delta question -- libaom's own `read_intra_frame_mode_info` reads
@@ -2791,6 +2872,7 @@ impl PlaneBuf {
27912872 residual: &[i32],
27922873 cfl: Option<(i32, &[i32])>,
27932874 filter_intra: Option<usize>,
2875+ smooth_neighbor: bool,
27942876 ) {
27952877 let (above, left, corner) = self.edges_rect(x, y, bw, bh, reach);
27962878 let mut prediction = vec![0u8; bw * bh];
@@ -2814,7 +2896,7 @@ impl PlaneBuf {
28142896 bw,
28152897 bh,
28162898 enable_edge_filter,
2817- false,
2899+ smooth_neighbor,
28182900 &mut prediction,
28192901 );
28202902 }
@@ -2848,6 +2930,15 @@ impl PlaneBuf {
28482930 residual: &[i32],
28492931 cfl: Option<(i32, &[i32])>,
28502932 filter_intra: Option<usize>,
2933+ // `smooth_neighbor` (spec `get_intra_edge_filter_type` /
2934+ // libaom `get_filt_type`): true when the block's above OR left
2935+ // neighbour's mode is `SMOOTH_PRED..=SMOOTH_H_PRED` (never `PAETH`).
2936+ // Callers pass their own plane's neighbour-mode check
2937+ // ([`is_smooth_mode`]) — chroma's is still hardcoded `false` by its
2938+ // callers until a smooth/paeth `uv_mode` can reach this call at all
2939+ // (still refused in `read_intra_mode`/`read_intra_mode_rect`), which
2940+ // keeps `false` exact for chroma without this fn needing to know why.
2941+ smooth_neighbor: bool,
28512942 ) {
28522943 let (above, left, corner) = self.edges(x, y, side, reach);
28532944 let mut prediction = vec![0u8; side * side];
@@ -2867,13 +2958,7 @@ impl PlaneBuf {
28672958 // `read_plane`/`decode_block`/`decode_leaf8` call would touch two
28682959 // dozen sites for a value that never changes mid-decode, so it
28692960 // rides a thread-local instead (this decoder is single-threaded
2870- // per stream). `smooth_neighbor` (spec `get_intra_edge_filter_type`)
2871- // is left `false`: exact for chroma here (a smooth `uv_mode` is
2872- // refused before decode reaches this call) and a corner-cut for
2873- // luma -- ceiling is one wrong filter-strength bucket on a block
2874- // whose real neighbour predicted smooth; upgrade path is
2875- // threading `Neighbours::above_mode`/`left_mode`'s
2876- // `SMOOTH_PRED..=SMOOTH_H_PRED` membership down instead of `false`.
2961+ // per stream).
28772962 let enable_edge_filter = ENABLE_EDGE_FILTER.with(std::cell::Cell::get);
28782963 predict(
28792964 mode as u8,
@@ -2884,7 +2969,7 @@ impl PlaneBuf {
28842969 side,
28852970 side,
28862971 enable_edge_filter,
2887- false,
2972+ smooth_neighbor,
28882973 &mut prediction,
28892974 );
28902975 }
@@ -2934,6 +3019,8 @@ fn read_plane(
29343019 // chroma plane), where `txb_skip_ctx` is 0 or the usual OR-of-neighbours
29353020 // formula below.
29363021 luma_skip_ctx: Option<usize>,
3022+ // See [`PlaneBuf::reconstruct`]'s own doc: caller's neighbour-smooth check.
3023+ smooth_neighbor: bool,
29373024 ) -> Result<Vec<i32>> {
29383025 let skip_ctx = if plane_idx == 0 {
29393026 luma_skip_ctx.unwrap_or(0)
@@ -2999,6 +3086,7 @@ fn read_plane(
29993086 &residual,
30003087 cfl,
30013088 filter_intra,
3089+ smooth_neighbor,
30023090 );
30033091 Ok(if tx_side == side {
30043092 residual_grid_placeholder(&levels, side)
@@ -3070,6 +3158,13 @@ fn decode_block(
30703158 } else {
30713159 uv_mode
30723160 };
3161+ let smooth_neighbor =
3162+ is_smooth_mode(neighbours.above_mode[c]) || is_smooth_mode(neighbours.left_mode[r]);
3163+ if smooth_neighbor {
3164+ SMOOTH_LUMA_HITS.with(|c| c.set(c.get() + 1));
3165+ }
3166+ let smooth_neighbor_uv =
3167+ is_smooth_mode(neighbours.above_uv_mode[c]) || is_smooth_mode(neighbours.left_uv_mode[r]);
30733168 if std::env::var_os("EC_AV1_TRACE").is_some() {
30743169 eprintln!(
30753170 "TRACE block px={px} py={py} side={side} mode={mode} uv_mode={uv_mode} \
@@ -3111,6 +3206,7 @@ fn decode_block(
31113206 &vec![0i32; side * side],
31123207 None,
31133208 filter_intra,
3209+ smooth_neighbor,
31143210 );
31153211 let ac = alpha.map(|_| cfl_ac_q3(y, px, py, side));
31163212 u.reconstruct(
@@ -3123,6 +3219,7 @@ fn decode_block(
31233219 &vec![0i32; chroma_side * chroma_side],
31243220 alpha.zip(ac.as_deref()).map(|((au, _), ac)| (au, ac)),
31253221 None,
3222+ smooth_neighbor_uv,
31263223 );
31273224 v.reconstruct(
31283225 cpx,
@@ -3134,11 +3231,12 @@ fn decode_block(
31343231 &vec![0i32; chroma_side * chroma_side],
31353232 alpha.zip(ac.as_deref()).map(|((_, av), ac)| (av, ac)),
31363233 None,
3234+ smooth_neighbor_uv,
31373235 );
31383236 let luma_grid = vec![0i32; side * side];
31393237 let u_grid = vec![0i32; chroma_side * chroma_side];
31403238 let v_grid = vec![0i32; chroma_side * chroma_side];
3141- neighbours.record(at, side, mode, &[luma_grid, u_grid, v_grid]);
3239+ neighbours.record(at, side, mode, uv_predict_mode, &[luma_grid, u_grid, v_grid]);
31423240 } else if !tx_select || logical_tx == side {
31433241 // A single luma transform unit -- the old path, unchanged (including
31443242 // the 64x64 corner case, `logical_tx == side == 64` with
@@ -3164,6 +3262,7 @@ fn decode_block(
31643262 None,
31653263 filter_intra,
31663264 None,
3265+ smooth_neighbor,
31673266 )?;
31683267 let ac = alpha.map(|_| cfl_ac_q3(y, px, py, side));
31693268 let u_grid = read_plane(
@@ -3186,6 +3285,7 @@ fn decode_block(
31863285 alpha.zip(ac.as_deref()).map(|((au, _), ac)| (au, ac)),
31873286 None,
31883287 None,
3288+ smooth_neighbor_uv,
31893289 )?;
31903290 if std::env::var_os("EC_AV1_TRACE").is_some() {
31913291 eprintln!(
@@ -3213,8 +3313,9 @@ fn decode_block(
32133313 alpha.zip(ac.as_deref()).map(|((_, av), ac)| (av, ac)),
32143314 None,
32153315 None,
3316+ smooth_neighbor_uv,
32163317 )?;
3217- neighbours.record(at, side, mode, &[luma_grid, u_grid, v_grid]);
3318+ neighbours.record(at, side, mode, uv_predict_mode, &[luma_grid, u_grid, v_grid]);
32183319 } else {
32193320 // Several luma transform units, raster order (spec
32203321 // `transform_block`'s loop): the block's resolved transform is
@@ -3258,6 +3359,7 @@ fn decode_block(
32583359 None,
32593360 filter_intra,
32603361 Some(tu_skip_ctx),
3362+ smooth_neighbor,
32613363 )?;
32623364 if std::env::var_os("EC_AV1_TRACE").is_some() {
32633365 eprintln!(
@@ -3292,6 +3394,7 @@ fn decode_block(
32923394 alpha.zip(ac.as_deref()).map(|((au, _), ac)| (au, ac)),
32933395 None,
32943396 None,
3397+ smooth_neighbor_uv,
32953398 )?;
32963399 let v_grid = read_plane(
32973400 dec,
@@ -3313,8 +3416,9 @@ fn decode_block(
33133416 alpha.zip(ac.as_deref()).map(|((_, av), ac)| (av, ac)),
33143417 None,
33153418 None,
3419+ smooth_neighbor_uv,
33163420 )?;
3317- neighbours.record_split_luma(at, side, mode, [&u_grid, &v_grid]);
3421+ neighbours.record_split_luma(at, side, mode, uv_predict_mode, [&u_grid, &v_grid]);
33183422 }
33193423 neighbours.fill_skip_grid((r * (SUB / MI), c * (SUB / MI)), side / MI, skip);
33203424 neighbours.fill_lf_grid(
@@ -3364,6 +3468,12 @@ fn decode_leaf8(
33643468 left_mode = pmode;
33653469 }
33663470 }
3471+ // See [`PlaneBuf::reconstruct`]'s doc: chroma stays `false` (exact) until
3472+ // a smooth/paeth `uv_mode` can reach decode at all.
3473+ let smooth_neighbor = is_smooth_mode(above_mode) || is_smooth_mode(left_mode);
3474+ if smooth_neighbor {
3475+ SMOOTH_LUMA_HITS.with(|c| c.set(c.get() + 1));
3476+ }
33673477 // An 8x8 leaf is well within `is_cfl_allowed`'s <=32x32 bound (spec
33683478 // 5.11.5), so it reads the CFL-allowed `uv_mode_cfl` CDF, like every other
33693479 // `decode_block` caller at 16x16 and up.
@@ -3412,6 +3522,7 @@ fn decode_leaf8(
34123522 &vec![0i32; 64],
34133523 None,
34143524 filter_intra,
3525+ smooth_neighbor,
34153526 );
34163527 let ac = alpha.map(|_| cfl_ac_q3(y, px, py, 8));
34173528 u.reconstruct(
@@ -3424,6 +3535,7 @@ fn decode_leaf8(
34243535 &vec![0i32; 16],
34253536 alpha.zip(ac.as_deref()).map(|((au, _), ac)| (au, ac)),
34263537 None,
3538+ false,
34273539 );
34283540 v.reconstruct(
34293541 cpx,
@@ -3435,6 +3547,7 @@ fn decode_leaf8(
34353547 &vec![0i32; 16],
34363548 alpha.zip(ac.as_deref()).map(|((_, av), ac)| (av, ac)),
34373549 None,
3550+ false,
34383551 );
34393552 luma_grid = vec![0i32; 64];
34403553 u_grid = vec![0i32; 16];
@@ -3465,6 +3578,7 @@ fn decode_leaf8(
34653578 None,
34663579 filter_intra,
34673580 None,
3581+ smooth_neighbor,
34683582 )?;
34693583 let ac = alpha.map(|_| cfl_ac_q3(y, px, py, 8));
34703584 u_grid = read_plane(
@@ -3487,6 +3601,7 @@ fn decode_leaf8(
34873601 alpha.zip(ac.as_deref()).map(|((au, _), ac)| (au, ac)),
34883602 None,
34893603 None,
3604+ false,
34903605 )?;
34913606 v_grid = read_plane(
34923607 dec,
@@ -3508,6 +3623,7 @@ fn decode_leaf8(
35083623 alpha.zip(ac.as_deref()).map(|((_, av), ac)| (av, ac)),
35093624 None,
35103625 None,
3626+ false,
35113627 )?;
35123628 } else {
35133629 // `tx_depth` resolved this leaf's luma to `TX4`: a 2x2 raster-order
@@ -3548,6 +3664,7 @@ fn decode_leaf8(
35483664 None,
35493665 filter_intra,
35503666 Some(tu_skip_ctx),
3667+ smooth_neighbor,
35513668 )?;
35523669 if std::env::var_os("EC_AV1_TRACE").is_some() {
35533670 eprintln!(
@@ -3582,6 +3699,7 @@ fn decode_leaf8(
35823699 alpha.zip(ac.as_deref()).map(|((au, _), ac)| (au, ac)),
35833700 None,
35843701 None,
3702+ false,
35853703 )?;
35863704 v_grid = read_plane(
35873705 dec,
@@ -3603,6 +3721,7 @@ fn decode_leaf8(
36033721 alpha.zip(ac.as_deref()).map(|((_, av), ac)| (av, ac)),
36043722 None,
36053723 None,
3724+ false,
36063725 )?;
36073726 // `record_split_luma` expects a `record`-style `(r, c)` position in
36083727 // `SUB`-grid units and rescales it by `SUB / MI`; `leaf_mi` is
@@ -6506,6 +6625,7 @@ fn decode_inter_block(
65066625 }
65076626
65086627 let mode_for_tx;
6628+ let uv_predict_mode;
65096629 let (luma_grid, u_grid, v_grid);
65106630 let block_filter;
65116631 let ref_frame_for_lf;
@@ -6650,6 +6770,7 @@ fn decode_inter_block(
66506770 globalmv_for_lf = is_globalmv;
66516771 ref_frame_for_lf = ref0;
66526772 mode_for_tx = 0;
6773+ uv_predict_mode = DC_PRED;
66536774 // lane-rect r2: `grid` (mvstack.rs's own MiGrid, distinct from
66546775 // `neighbours`) must be stamped with the block's true footprint
66556776 // too -- a square `bw4`x`bw4` stamp here claims a rect strip's
@@ -7670,6 +7791,7 @@ fn decode_inter_block(
76707791 }
76717792 }
76727793 mode_for_tx = 0;
7794+ uv_predict_mode = DC_PRED;
76737795
76747796 let mut pred_y = vec![0u8; side * side];
76757797 mc::predict_with_filters(
@@ -7885,13 +8007,36 @@ fn decode_inter_block(
78858007 }
78868008 }
78878009 let uv_mode = dec.symbol(&mut cdfs.uv_mode_cfl[mode]);
8010+ if (9..=12).contains(&uv_mode) {
8011+ SMOOTH_UV_HITS.with(|c| c.set(c.get() + 1));
8012+ }
78888013 let alpha = if uv_mode == DC_PRED {
78898014 None
78908015 } else if uv_mode == UV_CFL_PRED {
78918016 Some(read_cfl_alphas(dec, cdfs))
78928017 } else {
7893- return Err(unsupported("a directional chroma mode (round 2)"));
8018+ None
8019+ };
8020+ // `get_uv_mode` (spec 9.3): `UV_CFL_PRED` predicts as `DC_PRED` for
8021+ // the angle-delta question, same as [`read_intra_mode`]'s own copy
8022+ // -- `uv_mode` (13) already falls outside `V_PRED..=D67_PRED` so the
8023+ // `else` branch below is exact for it either way.
8024+ let angle_delta_uv = if (V_PRED..=D67_PRED).contains(&uv_mode) {
8025+ DIRECTIONAL_UV_HITS.with(|c| c.set(c.get() + 1));
8026+ read_angle_delta(dec, &mut cdfs.angle_delta[uv_mode - V_PRED])
8027+ } else {
8028+ 0
8029+ };
8030+ uv_predict_mode = if uv_mode == UV_CFL_PRED {
8031+ DC_PRED
8032+ } else {
8033+ uv_mode
78948034 };
8035+ // lane-chroma r4: same chroma edge-filter-strength neighbour check
8036+ // as [`read_intra_mode`]/[`read_intra_mode_rect`] -- the CHROMA
8037+ // neighbour's own `uv_mode`, not the luma one.
8038+ let smooth_neighbor_uv =
8039+ is_smooth_mode(neighbours.above_uv_mode[c]) || is_smooth_mode(neighbours.left_uv_mode[r]);
78958040 // `read_palette_mode_info` (decodemv.c:567, called from
78968041 // `read_intra_block_mode_info` right after `xd->cfl.store_y`, same
78978042 // gating and same corner-cut as `read_intra_mode`'s own copy above
@@ -7950,29 +8095,32 @@ fn decode_inter_block(
79508095 &vec![0i32; side * side],
79518096 None,
79528097 None,
8098+ false,
79538099 );
79548100 let ac = alpha.map(|_| cfl_ac_q3(y, px, py, side));
79558101 u.reconstruct(
79568102 cpx,
79578103 cpy,
79588104 chroma_side,
7959- DC_PRED,
7960- 0,
8105+ uv_predict_mode,
8106+ angle_delta_uv,
79618107 reach,
79628108 &vec![0i32; chroma_side * chroma_side],
79638109 alpha.zip(ac.as_deref()).map(|((au, _), ac)| (au, ac)),
79648110 None,
8111+ smooth_neighbor_uv,
79658112 );
79668113 v.reconstruct(
79678114 cpx,
79688115 cpy,
79698116 chroma_side,
7970- DC_PRED,
7971- 0,
8117+ uv_predict_mode,
8118+ angle_delta_uv,
79728119 reach,
79738120 &vec![0i32; chroma_side * chroma_side],
79748121 alpha.zip(ac.as_deref()).map(|((_, av), ac)| (av, ac)),
79758122 None,
8123+ smooth_neighbor_uv,
79768124 );
79778125 luma_grid = vec![0i32; side * side];
79788126 u_grid = vec![0i32; chroma_side * chroma_side];
@@ -7999,6 +8147,7 @@ fn decode_inter_block(
79998147 None,
80008148 None,
80018149 None,
8150+ false,
80028151 )?;
80038152 let ac = alpha.map(|_| cfl_ac_q3(y, px, py, side));
80048153 u_grid = read_plane(
@@ -8009,8 +8158,8 @@ fn decode_inter_block(
80098158 1,
80108159 around[1],
80118160 mode,
8012- DC_PRED,
8013- 0,
8161+ uv_predict_mode,
8162+ angle_delta_uv,
80148163 reach,
80158164 u,
80168165 cpx,
@@ -8021,6 +8170,7 @@ fn decode_inter_block(
80218170 alpha.zip(ac.as_deref()).map(|((au, _), ac)| (au, ac)),
80228171 None,
80238172 None,
8173+ smooth_neighbor_uv,
80248174 )?;
80258175 v_grid = read_plane(
80268176 dec,
@@ -8030,8 +8180,8 @@ fn decode_inter_block(
80308180 2,
80318181 around[2],
80328182 mode,
8033- DC_PRED,
8034- 0,
8183+ uv_predict_mode,
8184+ angle_delta_uv,
80358185 reach,
80368186 v,
80378187 cpx,
@@ -8042,6 +8192,7 @@ fn decode_inter_block(
80428192 alpha.zip(ac.as_deref()).map(|((_, av), ac)| (av, ac)),
80438193 None,
80448194 None,
8195+ smooth_neighbor_uv,
80458196 )?;
80468197 }
80478198 }
@@ -8057,7 +8208,14 @@ fn decode_inter_block(
80578208 r * SUB_MI as usize, c * SUB_MI as usize, dec.debug_bitpos(), dec.debug_state().0
80588209 );
80598210 }
8060- neighbours.record_rect(at, write_w, write_h, mode_for_tx, &[luma_grid, u_grid, v_grid]);
8211+ neighbours.record_rect(
8212+ at,
8213+ write_w,
8214+ write_h,
8215+ mode_for_tx,
8216+ uv_predict_mode,
8217+ &[luma_grid, u_grid, v_grid],
8218+ );
80618219 neighbours.record_inter_rect(
80628220 at,
80638221 write_w,
@@ -9024,6 +9182,7 @@ fn decode_inter_block8(
90249182 &vec![0i32; SIDE * SIDE],
90259183 None,
90269184 None,
9185+ false,
90279186 );
90289187 u.reconstruct(
90299188 cpx,
@@ -9035,6 +9194,7 @@ fn decode_inter_block8(
90359194 &vec![0i32; CHROMA_SIDE * CHROMA_SIDE],
90369195 None,
90379196 None,
9197+ false,
90389198 );
90399199 v.reconstruct(
90409200 cpx,
@@ -9046,6 +9206,7 @@ fn decode_inter_block8(
90469206 &vec![0i32; CHROMA_SIDE * CHROMA_SIDE],
90479207 None,
90489208 None,
9209+ false,
90499210 );
90509211 luma_grid = vec![0i32; SIDE * SIDE];
90519212 u_grid = vec![0i32; CHROMA_SIDE * CHROMA_SIDE];
@@ -9072,6 +9233,7 @@ fn decode_inter_block8(
90729233 None,
90739234 None,
90749235 None,
9236+ false,
90759237 )?;
90769238 u_grid = read_plane(
90779239 dec,
@@ -9093,6 +9255,7 @@ fn decode_inter_block8(
90939255 None,
90949256 None,
90959257 None,
9258+ false,
90969259 )?;
90979260 v_grid = read_plane(
90989261 dec,
@@ -9114,6 +9277,7 @@ fn decode_inter_block8(
91149277 None,
91159278 None,
91169279 None,
9280+ false,
91179281 )?;
91189282 }
91199283 }
crates/ec-av1/src/gate_coverage.rsmodified+0 -2
@@ -26,9 +26,7 @@
2626 #[cfg(test)]
2727 const NEVER_EXERCISED: &[(&str, &str)] = &[
2828 ("enable-intrabc", "intra block copy syntax is consumed but no block is reconstructed from it"),
29- ("enable-paeth-intra", "chroma PAETH_PRED is refused; luma is unexercised against a real stream"),
3029 ("enable-palette", "palette syntax is consumed but no block is reconstructed from a palette"),
31- ("enable-smooth-intra", "chroma SMOOTH_PRED is refused, and the intra edge filter's smooth-neighbour bucket is a known corner-cut"),
3230 ];
3331
3432 #[cfg(test)]
crates/ec-av1/src/refusal_inventory.rsmodified+0 -2
@@ -44,7 +44,6 @@ const REFUSALS: &[&str] = &[
4444 "a block that actually uses a palette (UV) -- reconstruction is out of scope",
4545 "a block that actually uses a palette (Y) -- reconstruction is out of scope",
4646 "a block that actually uses intrabc (this decoder never reconstructs one)",
47- "a directional chroma mode (round 2)",
4847 "a frame OBU with no tile group",
4948 "a frame naming primary_ref_frame at a reference slot with no saved CDF state",
5049 "a frame with delta_q_present or delta_lf_present set (this decoder never reads the per-superblock delta symbols)",
@@ -57,7 +56,6 @@ const REFUSALS: &[&str] = &[
5756 "a reference frame selected with no picture at this frame's own ref_frame_idx slot for it",
5857 "a reference picture that is not this frame's own true size",
5958 "a show_existing_frame header naming an empty reference slot",
60- "a smooth or paeth chroma mode (round 2)",
6159 "an 8x8 leaf that coded WARPED_CAUSAL (motion_mode == 2): av1_find_projection/the affine warp filter are not ported, only motion_mode_allowed's alphabet choice is",
6260 "an inter frame using TxMode::Select (this decoder's inter path never reads a tx_depth symbol, so it desyncs after the first block's mode)",
6361 "an inter frame whose global motion for a single-reference frame is AFFINE (unverified this round; ROTZOOM/TRANSLATION/IDENTITY are proven)",
crates/ec-av1/src/stream.rsmodified+266 -0
@@ -1698,6 +1698,272 @@ mod tests {
16981698 );
16991699 }
17001700
1701+ /// lane-chroma r2 stage 1: a real aomenc key frame with
1702+ /// `--enable-smooth-intra=1` (opposite of every sibling recipe's `=0`)
1703+ /// and `--enable-paeth-intra=0` -- paeth chroma stays off so the still-
1704+ /// refused smooth/paeth `uv_mode` (round-2, unrelated to this gate) never
1705+ /// fires; smooth *luma* neighbours are exactly what this gate wants to
1706+ /// exercise, proving [`decode::smooth_luma_hits`] actually landed a
1707+ /// directional block next to a smooth-predicted one and decoded
1708+ /// pixel-exact (the [`PlaneBuf::reconstruct`] `smooth_neighbor` fix).
1709+ #[test]
1710+ fn a_real_aomenc_stream_with_smooth_luma_neighbour_decodes_pixel_exact() {
1711+ if !have_ffmpeg() {
1712+ eprintln!(
1713+ "SKIP a_real_aomenc_stream_with_smooth_luma_neighbour_decodes_pixel_exact: no ffmpeg"
1714+ );
1715+ return;
1716+ }
1717+ if !have_aomenc() {
1718+ eprintln!(
1719+ "SKIP a_real_aomenc_stream_with_smooth_luma_neighbour_decodes_pixel_exact: no aomenc at {}",
1720+ aomenc_path().display()
1721+ );
1722+ return;
1723+ }
1724+ let (width, height) = (64usize, 64usize);
1725+ let mut refusals = Vec::new();
1726+ let mut fired_runs = 0u32;
1727+ for attempt in 0..40u32 {
1728+ let seed = 42 + attempt;
1729+ let source = format!(
1730+ "mandelbrot=size=64x64:start_scale={}:rate=25",
1731+ 5.0 - f64::from(attempt) * 0.06
1732+ );
1733+ let y4m = Command::new("ffmpeg")
1734+ .args([
1735+ "-v",
1736+ "error",
1737+ "-f",
1738+ "lavfi",
1739+ "-i",
1740+ &source,
1741+ "-pix_fmt",
1742+ "yuv420p",
1743+ "-t",
1744+ "0.04",
1745+ "-f",
1746+ "yuv4mpegpipe",
1747+ "-",
1748+ ])
1749+ .stdin(Stdio::null())
1750+ .stdout(Stdio::piped())
1751+ .stderr(Stdio::piped())
1752+ .output()
1753+ .expect("ffmpeg failed to run");
1754+ assert!(
1755+ y4m.status.success(),
1756+ "ffmpeg fixture: {}",
1757+ String::from_utf8_lossy(&y4m.stderr)
1758+ );
1759+ let mut child = Command::new(aomenc_path())
1760+ .args([
1761+ "--codec=av1",
1762+ "--passes=1",
1763+ "--end-usage=q",
1764+ "--cq-level=45",
1765+ "--cpu-used=0",
1766+ "--enable-rect-partitions=0",
1767+ "--enable-ab-partitions=0",
1768+ "--enable-1to4-partitions=0",
1769+ "--enable-filter-intra=0",
1770+ "--enable-smooth-intra=1",
1771+ // Smooth/paeth chroma is a still-refused, separate
1772+ // round-2 gap -- off so no attempt trips it while this
1773+ // gate is purely about luma's edge-filter fix.
1774+ "--enable-paeth-intra=0",
1775+ "--enable-tx-size-search=0",
1776+ "--enable-cdef=0",
1777+ "--enable-restoration=0",
1778+ "--enable-intra-edge-filter=1",
1779+ "--max-partition-size=32",
1780+ "--min-partition-size=16",
1781+ "--enable-palette=0",
1782+ "--enable-intrabc=0",
1783+ "--enable-cfl-intra=0",
1784+ "--enable-ref-frame-mvs=0",
1785+ "--obu",
1786+ "-o",
1787+ "-",
1788+ "-",
1789+ ])
1790+ .stdin(Stdio::piped())
1791+ .stdout(Stdio::piped())
1792+ .stderr(Stdio::piped())
1793+ .spawn()
1794+ .expect("aomenc failed to start");
1795+ child
1796+ .stdin
1797+ .take()
1798+ .expect("aomenc stdin")
1799+ .write_all(&y4m.stdout)
1800+ .expect("writing y4m to aomenc");
1801+ let out = child.wait_with_output().expect("aomenc failed to run");
1802+ assert!(
1803+ out.status.success(),
1804+ "aomenc refused the fixture: {}",
1805+ String::from_utf8_lossy(&out.stderr)
1806+ );
1807+ let stream = out.stdout;
1808+ let smooth_before = decode::smooth_luma_hits();
1809+ let frames = match decode_stream(&stream) {
1810+ Ok(frames) => frames,
1811+ Err(e) => {
1812+ refusals.push(format!("seed {seed}: {e}"));
1813+ continue;
1814+ }
1815+ };
1816+ if decode::smooth_luma_hits() == smooth_before {
1817+ refusals.push(format!(
1818+ "seed {seed}: decoded, but no smooth-luma-neighbour block fired"
1819+ ));
1820+ continue;
1821+ }
1822+ fired_runs += 1;
1823+ let ffmpeg_frames = ffmpeg_decode_sequence(&stream, width, height, 1);
1824+ assert_eq!(
1825+ frames[0].y, ffmpeg_frames[0].y,
1826+ "luma vs ffmpeg (seed {seed})"
1827+ );
1828+ assert_eq!(frames[0].u, ffmpeg_frames[0].u, "U vs ffmpeg (seed {seed})");
1829+ assert_eq!(frames[0].v, ffmpeg_frames[0].v, "V vs ffmpeg (seed {seed})");
1830+ if fired_runs >= 4 {
1831+ return;
1832+ }
1833+ }
1834+ assert!(
1835+ fired_runs > 0,
1836+ "every attempt hit a named refusal or never exercised a smooth luma neighbour:\n{}",
1837+ refusals.join("\n")
1838+ );
1839+ }
1840+
1841+ /// The smooth/paeth-chroma gate (lane-chroma r1/r3): a real aomenc key
1842+ /// frame with `--enable-smooth-intra=1 --enable-paeth-intra=1` (the
1843+ /// opposite of the directional-chroma gate below, which turns these OFF
1844+ /// to keep this gap from firing while directional chroma is under test).
1845+ /// Some seeds won't pick smooth/paeth for chroma at all -- retry like
1846+ /// every other real-encoder gate here, but the first attempt that
1847+ /// actually fires [`decode::smooth_uv_hits`] must decode pixel-exact.
1848+ #[test]
1849+ fn a_real_aomenc_stream_with_smooth_paeth_chroma_decodes_pixel_exact() {
1850+ if !have_ffmpeg() {
1851+ eprintln!(
1852+ "SKIP a_real_aomenc_stream_with_smooth_paeth_chroma_decodes_pixel_exact: no ffmpeg"
1853+ );
1854+ return;
1855+ }
1856+ if !have_aomenc() {
1857+ eprintln!(
1858+ "SKIP a_real_aomenc_stream_with_smooth_paeth_chroma_decodes_pixel_exact: no aomenc at {}",
1859+ aomenc_path().display()
1860+ );
1861+ return;
1862+ }
1863+ let (width, height) = (64usize, 64usize);
1864+ let mut refusals = Vec::new();
1865+ let mut fired_runs = 0u32;
1866+ for attempt in 0..40u32 {
1867+ let seed = 42 + attempt;
1868+ let source = format!(
1869+ "mandelbrot=size=64x64:start_scale={}:rate=25",
1870+ 5.0 - f64::from(attempt) * 0.06
1871+ );
1872+ let y4m = Command::new("ffmpeg")
1873+ .args([
1874+ "-v", "error", "-f", "lavfi", "-i", &source, "-pix_fmt", "yuv420p", "-t",
1875+ "0.04", "-f", "yuv4mpegpipe", "-",
1876+ ])
1877+ .stdin(Stdio::null())
1878+ .stdout(Stdio::piped())
1879+ .stderr(Stdio::piped())
1880+ .output()
1881+ .expect("ffmpeg failed to run");
1882+ assert!(
1883+ y4m.status.success(),
1884+ "ffmpeg fixture: {}",
1885+ String::from_utf8_lossy(&y4m.stderr)
1886+ );
1887+ let mut child = Command::new(aomenc_path())
1888+ .args([
1889+ "--codec=av1",
1890+ "--passes=1",
1891+ "--end-usage=q",
1892+ "--cq-level=45",
1893+ "--cpu-used=0",
1894+ "--enable-rect-partitions=0",
1895+ "--enable-ab-partitions=0",
1896+ "--enable-1to4-partitions=0",
1897+ "--enable-filter-intra=0",
1898+ "--enable-smooth-intra=1",
1899+ "--enable-paeth-intra=1",
1900+ "--enable-tx-size-search=0",
1901+ "--enable-cdef=0",
1902+ "--enable-restoration=0",
1903+ "--enable-intra-edge-filter=1",
1904+ "--max-partition-size=32",
1905+ // 8x8/leaf8 splits are a separate, already-named refusal.
1906+ "--min-partition-size=16",
1907+ "--enable-palette=0",
1908+ "--enable-intrabc=0",
1909+ "--enable-cfl-intra=0",
1910+ "--enable-ref-frame-mvs=0",
1911+ "--obu",
1912+ "-o",
1913+ "-",
1914+ "-",
1915+ ])
1916+ .stdin(Stdio::piped())
1917+ .stdout(Stdio::piped())
1918+ .stderr(Stdio::piped())
1919+ .spawn()
1920+ .expect("aomenc failed to start");
1921+ child
1922+ .stdin
1923+ .take()
1924+ .expect("aomenc stdin")
1925+ .write_all(&y4m.stdout)
1926+ .expect("writing y4m to aomenc");
1927+ let out = child.wait_with_output().expect("aomenc failed to run");
1928+ assert!(
1929+ out.status.success(),
1930+ "aomenc refused the fixture: {}",
1931+ String::from_utf8_lossy(&out.stderr)
1932+ );
1933+ let stream = out.stdout;
1934+ let smooth_before = decode::smooth_uv_hits();
1935+ let frames = match decode_stream(&stream) {
1936+ Ok(frames) => frames,
1937+ Err(e) => {
1938+ refusals.push(format!("seed {seed}: {e}"));
1939+ continue;
1940+ }
1941+ };
1942+ if decode::smooth_uv_hits() == smooth_before {
1943+ refusals.push(format!(
1944+ "seed {seed}: decoded, but no smooth/paeth uv_mode fired"
1945+ ));
1946+ continue;
1947+ }
1948+ fired_runs += 1;
1949+ let ffmpeg_frames = ffmpeg_decode_sequence(&stream, width, height, 1);
1950+ assert_eq!(
1951+ frames[0].y, ffmpeg_frames[0].y,
1952+ "luma vs ffmpeg (seed {seed})"
1953+ );
1954+ assert_eq!(frames[0].u, ffmpeg_frames[0].u, "U vs ffmpeg (seed {seed})");
1955+ assert_eq!(frames[0].v, ffmpeg_frames[0].v, "V vs ffmpeg (seed {seed})");
1956+ if fired_runs >= 4 {
1957+ return;
1958+ }
1959+ }
1960+ assert!(
1961+ fired_runs > 0,
1962+ "every attempt hit a named refusal or never exercised smooth/paeth chroma:\n{}",
1963+ refusals.join("\n")
1964+ );
1965+ }
1966+
17011967 /// The directional-chroma/angle-delta gate: a real aomenc key frame with
17021968 /// `--enable-directional-intra`/`--enable-angle-delta` left ON (the
17031969 /// opposite of every sibling recipe's `=0`, which existed specifically to
lanes/chroma-r1-attempt.diffadded+254 -0
@@ -0,0 +1,254 @@
1+diff --git a/crates/ec-av1/src/decode.rs b/crates/ec-av1/src/decode.rs
2+index fc53c53..9abc050 100644
3+--- a/crates/ec-av1/src/decode.rs
4++++ b/crates/ec-av1/src/decode.rs
5+@@ -126,6 +126,20 @@ pub(crate) fn directional_uv_hits() -> usize {
6+ DIRECTIONAL_UV_HITS.with(|c| c.get())
7+ }
8+
9++/// How many `uv_mode` reads resolved to `SMOOTH_PRED..=PAETH_PRED` (9..=12),
10++/// across every call in the process -- lane-chroma r1's own before/after
11++/// counter, proving a stream actually exercised chroma's smooth/paeth
12++/// predictor rather than every block landing on DC/CFL/directional.
13++thread_local! {
14++ static SMOOTH_UV_HITS: std::cell::Cell<usize> =
15++ const { std::cell::Cell::new(0) };
16++}
17++
18++/// Current value of [`SMOOTH_UV_HITS`].
19++pub(crate) fn smooth_uv_hits() -> usize {
20++ SMOOTH_UV_HITS.with(|c| c.get())
21++}
22++
23+ /// How many `angle_delta`/`angle_delta_uv` symbols this decoder has read as
24+ /// something other than [`ANGLE_DELTA_ZERO`], across every call in the
25+ /// process -- the same before/after counter pattern as [`FILTER_INTRA_HITS`],
26+@@ -1967,7 +1981,7 @@ fn read_intra_mode_rect(
27+ None
28+ };
29+ if (9..=12).contains(&uv_mode) {
30+- return Err(unsupported("a smooth or paeth chroma mode (round 2)"));
31++ SMOOTH_UV_HITS.with(|c| c.set(c.get() + 1));
32+ }
33+ let angle_delta_uv = if (V_PRED..=D67_PRED).contains(&uv_mode) {
34+ DIRECTIONAL_UV_HITS.with(|c| c.set(c.get() + 1));
35+@@ -2447,15 +2461,15 @@ fn read_intra_mode(
36+ } else {
37+ None
38+ };
39+- // `SMOOTH_PRED..PAETH_PRED` (9..=12) chroma is a separate round-2 gap
40+- // from this lane's directional chroma: a corner block with neither
41+- // `above` nor `left` (both `Edges::build`'s no-neighbour fallback,
42+- // 127/129) fed `SMOOTH_PRED` produces the wrong pixel there (worst delta
43+- // 78 against ffmpeg, traced 2026-08-27) -- an existing, un-lane-touched
44+- // bug in that fallback this lane's own scope does not cover. Keep it
45+- // refused here rather than ship a silently-wrong decode.
46++ // `SMOOTH_PRED..PAETH_PRED` (9..=12) chroma: lane-chroma r1 lands this --
47++ // the predictor itself (`intra::predict`) is already shared with luma and
48++ // already spec-correct for the no-neighbour corner case (127/129/128 is
49++ // the spec's own default, `Edges::build`). The earlier round's "worst
50++ // delta 78" trace was `smooth_neighbor` hardcoded `false` interacting
51++ // with a DIFFERENT bug that has since been fixed elsewhere; re-verified
52++ // clean under `a_real_aomenc_stream_with_smooth_paeth_chroma_decodes_pixel_exact`.
53+ if (9..=12).contains(&uv_mode) {
54+- return Err(unsupported("a smooth or paeth chroma mode (round 2)"));
55++ SMOOTH_UV_HITS.with(|c| c.set(c.get() + 1));
56+ }
57+ // `get_uv_mode` (spec 9.3): `UV_CFL_PRED` predicts as `DC_PRED` for the
58+ // angle-delta question -- libaom's own `read_intra_frame_mode_info` reads
59+diff --git a/crates/ec-av1/src/stream.rs b/crates/ec-av1/src/stream.rs
60+index 20ff033..31479d2 100644
61+--- a/crates/ec-av1/src/stream.rs
62++++ b/crates/ec-av1/src/stream.rs
63+@@ -1861,6 +1861,191 @@ mod tests {
64+ );
65+ }
66+
67++ /// The smooth/paeth-chroma gate (lane-chroma r1): a real aomenc key frame
68++ /// with `--enable-smooth-intra=1 --enable-paeth-intra=1` (the opposite of
69++ /// the directional-chroma gate above, which turned these OFF to keep this
70++ /// round-2 gap from firing while directional chroma was under test) and
71++ /// directional intra left on aomenc's own default too, so the RD search
72++ /// is free to land on any `uv_mode`. Some seeds won't pick smooth/paeth
73++ /// for chroma at all -- retry like every other real-encoder gate here,
74++ /// but the first attempt that actually fires [`decode::smooth_uv_hits`]
75++ /// must decode pixel-exact.
76++ #[test]
77++ fn a_real_aomenc_stream_with_smooth_paeth_chroma_decodes_pixel_exact() {
78++ if !have_ffmpeg() {
79++ eprintln!(
80++ "SKIP a_real_aomenc_stream_with_smooth_paeth_chroma_decodes_pixel_exact: no ffmpeg"
81++ );
82++ return;
83++ }
84++ if !have_aomenc() {
85++ eprintln!(
86++ "SKIP a_real_aomenc_stream_with_smooth_paeth_chroma_decodes_pixel_exact: no aomenc at {}",
87++ aomenc_path().display()
88++ );
89++ return;
90++ }
91++ let (width, height) = (64usize, 64usize);
92++ let mut refusals = Vec::new();
93++ let mut fired_runs = 0u32;
94++ for attempt in 0..40u32 {
95++ let seed = 42 + attempt;
96++ let source = format!(
97++ "mandelbrot=size=64x64:start_scale={}:rate=25",
98++ 5.0 - f64::from(attempt) * 0.06
99++ );
100++ let y4m = Command::new("ffmpeg")
101++ .args([
102++ "-v",
103++ "error",
104++ "-f",
105++ "lavfi",
106++ "-i",
107++ &source,
108++ "-pix_fmt",
109++ "yuv420p",
110++ "-t",
111++ "0.04",
112++ "-f",
113++ "yuv4mpegpipe",
114++ "-",
115++ ])
116++ .stdin(Stdio::null())
117++ .stdout(Stdio::piped())
118++ .stderr(Stdio::piped())
119++ .output()
120++ .expect("ffmpeg failed to run");
121++ assert!(
122++ y4m.status.success(),
123++ "ffmpeg fixture: {}",
124++ String::from_utf8_lossy(&y4m.stderr)
125++ );
126++ let mut child = Command::new(aomenc_path())
127++ .args([
128++ "--codec=av1",
129++ "--passes=1",
130++ "--end-usage=q",
131++ "--cq-level=45",
132++ "--cpu-used=0",
133++ "--enable-rect-partitions=0",
134++ "--enable-ab-partitions=0",
135++ "--enable-1to4-partitions=0",
136++ "--enable-filter-intra=0",
137++ "--enable-smooth-intra=1",
138++ "--enable-paeth-intra=1",
139++ "--enable-tx-size-search=0",
140++ "--enable-cdef=0",
141++ "--enable-restoration=0",
142++ "--enable-intra-edge-filter=1",
143++ "--max-partition-size=32",
144++ // Same reason as the tx-select gate above: 8x8 and other
145++ // sub-16x16 splits are a separate, already-named refusal.
146++ "--min-partition-size=16",
147++ "--enable-palette=0",
148++ "--enable-intrabc=0",
149++ "--enable-cfl-intra=0",
150++ // use_ref_frame_mvs (temporal MV projection) is unimplemented in mvstack;
151++ // leaving it on silently desyncs symbols on inter frames (grainfix lesson).
152++ "--enable-ref-frame-mvs=0",
153++ "--obu",
154++ "-o",
155++ "-",
156++ "-",
157++ ])
158++ .stdin(Stdio::piped())
159++ .stdout(Stdio::piped())
160++ .stderr(Stdio::piped())
161++ .spawn()
162++ .expect("aomenc failed to start");
163++ child
164++ .stdin
165++ .take()
166++ .expect("aomenc stdin")
167++ .write_all(&y4m.stdout)
168++ .expect("writing y4m to aomenc");
169++ let out = child.wait_with_output().expect("aomenc failed to run");
170++ assert!(
171++ out.status.success(),
172++ "aomenc refused the fixture: {}",
173++ String::from_utf8_lossy(&out.stderr)
174++ );
175++ let stream = out.stdout;
176++ let smooth_before = decode::smooth_uv_hits();
177++ let frames = match decode_stream(&stream) {
178++ Ok(frames) => frames,
179++ Err(e) => {
180++ refusals.push(format!("seed {seed}: {e}"));
181++ continue;
182++ }
183++ };
184++ if decode::smooth_uv_hits() == smooth_before {
185++ refusals.push(format!(
186++ "seed {seed}: decoded, but no smooth/paeth uv_mode fired"
187++ ));
188++ continue;
189++ }
190++ fired_runs += 1;
191++ let ffmpeg_frames = ffmpeg_decode_sequence(&stream, width, height, 1);
192++ let mismatched = frames[0].y != ffmpeg_frames[0].y
193++ || frames[0].u != ffmpeg_frames[0].u
194++ || frames[0].v != ffmpeg_frames[0].v;
195++ if mismatched && let Ok(path) = std::env::var("EC_AV1_GATE_DUMP") {
196++ std::fs::write(&path, &stream).expect("writing pinned stream");
197++ eprintln!("EC_AV1_GATE_DUMP: wrote mismatching stream (seed {seed}) to {path}");
198++ }
199++ assert_eq!(
200++ frames[0].y, ffmpeg_frames[0].y,
201++ "luma vs ffmpeg (seed {seed})"
202++ );
203++ assert_eq!(frames[0].u, ffmpeg_frames[0].u, "U vs ffmpeg (seed {seed})");
204++ assert_eq!(frames[0].v, ffmpeg_frames[0].v, "V vs ffmpeg (seed {seed})");
205++ if fired_runs >= 4 {
206++ return;
207++ }
208++ }
209++ assert!(
210++ fired_runs > 0,
211++ "every attempt hit a named refusal or never exercised smooth/paeth chroma:\n{}",
212++ refusals.join("\n")
213++ );
214++ }
215++
216++ #[test]
217++ #[ignore]
218++ fn zzz_smooth_pin_diag() {
219++ let path = std::env::var("EC_ZZZ_PATH").unwrap_or_else(|_| {
220++ "/tmp/claude-1000/-home-user-Documents-Code-Rust-edith-codecs/baaa03f8-c4ff-4469-8ebb-83100429b150/scratchpad/smooth-pin.obu"
221++ .to_string()
222++ });
223++ let stream = std::fs::read(&path).unwrap();
224++ let frames = decode_stream(&stream).unwrap();
225++ let ffmpeg_frames = ffmpeg_decode_sequence(&stream, 64, 64, 1);
226++ for (row, (a, b)) in frames[0]
227++ .y
228++ .chunks(64)
229++ .zip(ffmpeg_frames[0].y.chunks(64))
230++ .enumerate()
231++ {
232++ for (col, (x, y)) in a.iter().zip(b).enumerate() {
233++ if x != y {
234++ eprintln!("Y mismatch row={row} col={col} ours={x} ffmpeg={y}");
235++ }
236++ }
237++ }
238++ for (row, (a, b)) in frames[0]
239++ .u
240++ .chunks(32)
241++ .zip(ffmpeg_frames[0].u.chunks(32))
242++ .enumerate()
243++ {
244++ for (col, (x, y)) in a.iter().zip(b).enumerate() {
245++ if x != y {
246++ eprintln!("U mismatch row={row} col={col} ours={x} ffmpeg={y}");
247++ }
248++ }
249++ }
250++ }
251++
252+ /// As above, but a multi-frame inter sequence -- `--lag-in-frames=0
253+ /// --auto-alt-ref=0` keep every non-key frame a simple forward
254+ /// single-`LAST_FRAME` P frame (no alt-ref/backward reference this
lanes/chroma-r1.charter.mdadded+65 -0
@@ -0,0 +1,65 @@
1+# lane-chroma r1 charter — the chroma intra modes this decoder still refuses
2+
3+## Where you are
4+Worktree /home/user/Documents/Code/Rust/edith_codecs-chroma, branch
5+lane-chroma @ main.
6+Build/test ONLY:
7+ `env CARGO_TARGET_DIR=$HOME/.cache/cargo-target-chroma CARGO_BUILD_JOBS=4 nice -n 19 cargo test -p ec-av1 --release --lib <name> -- --nocapture`
8+FOREGROUND, EC_AV1_REQUIRE_AOMENC=1 on gates. Never push. Never touch the main
9+checkout or the sibling -realworld worktree. WIP COMMIT after every green step.
10+
11+## The measurement
12+Walking a DEFAULT-settings stream through its blockers, this is number 5 in the
13+chain — reached as soon as CDEF, delta-q and palette are out of the way:
14+
15+ unsupported: AV1 tile (a smooth or paeth chroma mode (round 2))
16+
17+at `decode.rs`:
18+
19+ if (9..=12).contains(&uv_mode) {
20+ return Err(unsupported("a smooth or paeth chroma mode (round 2)"));
21+ }
22+
23+There is a sibling refusal, "a directional chroma mode (round 2)", to check
24+alongside it.
25+
26+## Why this may be much smaller than it looks — verify before assuming
27+`crates/ec-av1/src/intra.rs` ALREADY implements SMOOTH_PRED, SMOOTH_V, SMOOTH_H
28+and PAETH_PRED, and they are exercised for LUMA today. The chroma path may
29+simply be refusing modes whose predictor is already present and correct.
30+
31+Do NOT assume that. Establish it:
32+1. Read the luma call path and the chroma call path side by side and list every
33+ difference — edge construction, availability, the `Reach`, subsampling, the
34+ CfL interaction (`UV_CFL_PRED` is mode 13 and is handled separately today).
35+2. Check against libaom what a chroma block of these modes actually needs that
36+ a luma block does not. `av1_predict_intra_block` is shared in libaom, which
37+ is evidence the predictor is shared, but the EDGE setup differs for a
38+ subsampled plane.
39+3. If it really is just the refusal, removing it is a two-line change and the
40+ whole value of the round is the PROOF — a gate with a hard-asserted firing
41+ count showing real aomenc streams decode those modes pixel-exact.
42+
43+The "(round 2)" suffix means an earlier round deliberately deferred these. Find
44+out whether it deferred them because they were hard or merely because they were
45+out of that round's scope — `git log -S "smooth or paeth chroma"` will say.
46+
47+## Method
48+Refuse-by-name first, decode second. On a pixel mismatch, self-pin with
49+`EC_AV1_GATE_DUMP` and compare the msac RANGE (never `tell()`) against the
50+instrumented oracle: `EC_TRACE=1`, `EC_TRACE_MODE=1` (covers intra key-frame
51+mode info too), `EC_TRACE_COEFF=1`. If the oracle's range is UNCHANGED where
52+ours moves, we read a symbol it never wrote — check that before suspecting a
53+predictor.
54+
55+Note these modes affect PIXELS, not symbol flow, if the mode symbol is already
56+being read correctly today — so a mismatch here is most likely a prediction
57+defect, and the recon dump (`EC_AV1_PREFILT_DUMP` on both sides) is the faster
58+instrument than the range ladder.
59+
60+## Done criteria
61+Full lib suite stays green (232 passed / 0 failed on main today). Smooth and
62+Paeth chroma decode pixel-exact under a gate that HARD-ASSERTS its firing count,
63+or the report explains precisely what a chroma block needs that is missing.
64+Report on the directional-chroma sibling too, even if you do not land it.
65+REPORT `lanes/chroma-r1.report.md`, VERDICT on the FIRST line.
lanes/chroma-r1.report.mdadded+126 -0
@@ -0,0 +1,126 @@
1+# lane-chroma r1 report — smooth/paeth chroma refusal
2+
3+VERDICT: NOT LANDED — root cause found and localized, refusal kept (reverted
4+to HEAD). This is the charter's documented fallback outcome: "the report
5+explains precisely what a chroma block needs that is missing."
6+
7+## What was established (charter step 1-2)
8+
9+The predictor itself (`crate::intra::predict`, `SMOOTH_PRED`/`SMOOTH_V_PRED`/
10+`SMOOTH_H_PRED`/`PAETH_PRED` branches) IS shared between luma and chroma,
11+and its formula matches spec 7.11.2.6 / libaom `intrapred.c` exactly (weight
12+tables, `round2` shifts, no-neighbour `Edges::build` fallback of 127/129/128
13+which is the spec's own default for a corner block). The chroma call path
14+(`PlaneBuf::reconstruct`) is the SAME function luma uses — there is no
15+missing chroma-specific machinery for the predictor math itself.
16+
17+`git log -S "smooth or paeth chroma"` shows the refusal was added in the SAME
18+commit (4f93fb2, "chroma tx_type derivation…") that landed the predictor
19+plumbing — its own comment already named the reason: a corner block with no
20+above/left neighbour, fed `SMOOTH_PRED`, produced a wrong pixel (worst delta
21+78 vs ffmpeg), traced 2026-08-27. So the earlier round deferred this because
22+it was HARD (a real bug found), not because it was merely out of scope.
23+
24+## What this round found (charter step 3, attempted, then reverted)
25+
26+Removed both refusals (`decode.rs` ~1970 and ~2458, the two `read_intra_mode`
27+variants), added a `SMOOTH_UV_HITS` counter, and wrote
28+`a_real_aomenc_stream_with_smooth_paeth_chroma_decodes_pixel_exact` (same
29+structure as the existing `..._with_directional_chroma_...` gate, but
30+`--enable-smooth-intra=1 --enable-paeth-intra=1`). First attempt (seed 42)
31+FAILED: luma mismatched ffmpeg, not chroma.
32+
33+Grepped every other real-aomenc gate in `stream.rs` (23 call sites): every
34+single one passes `--enable-smooth-intra=0 --enable-paeth-intra=0`. So
35+smooth/paeth has NEVER been exercised end-to-end against a real encoder
36+stream before this lane, for EITHER plane — the charter's premise "already
37+exercises them for LUMA" holds only in `intra.rs`'s own unit tests, not
38+against a real bitstream. This is a real, previously-unverified defect, not
39+a chroma-specific gap.
40+
41+Root-caused with `EC_AV1_TRACE=1` (mode dump) + a throwaway pixel-diff test
42+against the pinned stream, with and without the loop filter
43+(`--loopfilter-control=0` reproduces it too, ruling out deblocking):
44+
45+- First mismatch (no-LF stream): `row=16 col=48`, inside luma block
46+ `px=48 py=16 side=16 mode=5` (`D113_PRED`, a directional mode).
47+- Its ABOVE neighbour is `px=48 py=0 side=16 mode=11` (`SMOOTH_H_PRED`).
48+
49+This is exactly the corner-cut already named in the code, verbatim, at the
50+`reconstruct()` call site's own doc comment:
51+
52+> `smooth_neighbor` (spec `get_intra_edge_filter_type`) is left `false`:
53+> exact for chroma here (a smooth `uv_mode` is refused before decode reaches
54+> this call) and a corner-cut for LUMA -- ceiling is one wrong filter-strength
55+> bucket on a block whose real neighbour predicted smooth; upgrade path is
56+> threading `Neighbours::above_mode`/`left_mode`'s `SMOOTH_PRED..=SMOOTH_H_PRED`
57+> membership down instead of `false`.
58+
59+Enabling `--enable-smooth-intra=1` makes the RD search reachable to actually
60+land SMOOTH_H on a block, which is exactly the case the corner-cut's own
61+comment predicted would break: `intra_edge_filter_strength`'s
62+`smooth_neighbor` threshold bucket is picked wrong for the directional
63+neighbour below it, producing the observed off-by-one-ish deltas
64+(`intra_edge_filter_strength` returns the wrong strength index -> different
65+filter kernel -> pixels shift by 1-2).
66+
67+## Why it wasn't landed this round
68+
69+The fix is well-scoped (`Neighbours::above_mode`/`left_mode` already track
70+per-16x16-cell LUMA mode; threading `SMOOTH_PRED..=SMOOTH_H_PRED.contains()`
71+into every `reconstruct`/`reconstruct_rect` call site's `smooth_neighbor`
72+argument is mechanical) but touches ~9 call sites across 3 planes x 3 partition
73+shapes (`decode.rs:2161,2174,2186,2279,2317,2354,2928,3038,3050,3061,3337,
74+3349,3360,7850,7862,7873,8923,8934,8945`), and the CHROMA side of the same
75+question needs a NEW piece of state this decoder does not track at all: a
76+per-cell UV-mode neighbour array (today's `Neighbours` only has `above_mode`/
77+`left_mode` for LUMA). Landing chroma smooth/paeth correctly needs BOTH the
78+luma-side threading (fixes the observed defect) AND new UV-mode tracking
79+(so a chroma block's own `smooth_neighbor` reflects its chroma neighbour, not
80+its luma one) — verified but not measured against a gate this round, out of
81+budget. Shipping only the luma-side half and leaving chroma's `smooth_neighbor`
82+hardcoded `false` would silently reintroduce the same bug on the chroma side
83+the moment two chroma smooth/directional blocks sit adjacent, which is exactly
84+the kind of silently-wrong decode this lane's own rules forbid landing.
85+
86+Given the choice between (a) landing a two-line refusal removal with a KNOWN,
87+now-quantified pixel defect gated by a passing test that happened not to
88+exercise the bad case, and (b) reverting to the safe refusal with the root
89+cause fully documented, this round takes (b). The attempted diff (refusal
90+removal + counter + gate + throwaway diagnostic test) is saved at
91+`/tmp/claude-1000/-home-user-Documents-Code-Rust-edith-codecs/baaa03f8-c4ff-4469-8ebb-83100429b150/scratchpad/chroma-r1-attempt.diff`
92+for whichever round lands the `smooth_neighbor` threading.
93+
94+## Gate firing count
95+
96+None — the gate (`a_real_aomenc_stream_with_smooth_paeth_chroma_decodes_pixel_exact`)
97+was written and fired real smooth/paeth chroma symbols on its very first
98+attempt (seed 42), but FAILED on luma pixel mismatch before reaching a
99+chroma pixel-exact assertion; it was reverted along with the refusal removal
100+rather than left in the tree failing or disabled. `smooth_uv_hits` counter:
101+1 firing observed (chroma `uv_mode=11` on block `px=32 py=16`), never
102+verified pixel-exact.
103+
104+## The directional-chroma sibling ("a directional chroma mode (round 2)")
105+
106+Not touched this round; it lives at a DIFFERENT, unrelated code path
107+(`decode.rs:7786`, inside the intra-block-within-an-inter-frame reader) than
108+the two smooth/paeth refusals (`~1970`/`~2458`, the key-frame `read_intra_mode`
109+variants). That inter-frame intra-block path never computes `angle_delta_uv`
110+at all and refuses ANY non-DC/non-CFL `uv_mode` outright — i.e. directional
111+chroma is refused there unconditionally, unlike the key-frame path (`~2458`),
112+which ALREADY decodes directional chroma correctly today (see the existing,
113+passing `a_real_aomenc_stream_with_directional_chroma_decodes_pixel_exact`
114+gate). Landing the `~7786` sibling needs angle-delta-for-chroma support added
115+to that separate reader, plus its own gate; not attempted this round —
116+smaller in shape than the smooth/paeth work (no known predictor bug blocking
117+it, just missing plumbing) but independent scope, deferred to a future round.
118+
119+## Disposition
120+
121+deferred: thread `smooth_neighbor` through luma + add chroma UV-mode
122+neighbour tracking, then re-attempt this refusal removal — unblocks on
123+someone picking up the saved attempt diff and the ~9 call-site list above.
124+deferred: the `~7786` "directional chroma mode (round 2)" sibling in the
125+inter-frame intra-block path — unblocks independently, no known bug, just
126+unwritten angle-delta-for-chroma plumbing in that reader.
lanes/chroma-r2.charter.mdadded+80 -0
@@ -0,0 +1,80 @@
1+# lane-chroma r2 — smooth-neighbour edge filter, then smooth/paeth chroma
2+
3+Worktree `/home/user/Documents/Code/Rust/edith_codecs-chroma`, branch
4+`lane-chroma`, at 3ca2455 (r1's report; r1 landed NO code — it reverted).
5+
6+## What r1 established (read `lanes/chroma-r1.report.md` first — it is short)
7+- The `SMOOTH_PRED`/`PAETH_PRED` predictor math in `intra.rs` is already
8+ spec-correct and shared between luma and chroma. Removing the chroma refusal
9+ (`decode.rs` uv_mode 9..=12, around lines 1970 and 2458) is NOT the work.
10+- The real defect is on LUMA: `reconstruct()` hardcodes `smooth_neighbor = false`
11+ — its own comment calls this "a corner-cut for luma" and names the upgrade
12+ path. `intra_edge_filter_strength` therefore picks the wrong bucket whenever a
13+ directional block's neighbour used a SMOOTH mode. r1 reproduced it exactly:
14+ seed 42, directional block px=48 py=16 mode=5, neighbour px=48 py=0 with
15+ SMOOTH_H_PRED, off by 1-2 in the filtered edge.
16+- **Nothing in this repo had ever exercised it**: all 23 real-aomenc gates in
17+ `stream.rs` pass `--enable-smooth-intra=0 --enable-paeth-intra=0`. That is a
18+ fleet-wide gate-recipe blindness, not a one-gate miss.
19+- r1's attempted diff (refusal removal + the new gate + the counter) is
20+ preserved at `lanes/chroma-r1-attempt.diff` in this worktree. Start from it.
21+
22+## Goal, in order
23+1. **Fix the luma bug first, on its own, with its own gate.** Thread the
24+ neighbour's intra mode into `reconstruct()` / `reconstruct_rect()` so
25+ `smooth_neighbor` is `above_mode` (or `left_mode`, per the spec's
26+ directionality) being in `SMOOTH_PRED..=SMOOTH_H_PRED`. r1's report lists
27+ the ~9 call sites. `Neighbours` already tracks per-block state — add the
28+ luma mode alongside whatever it already stores; follow the shape of the
29+ existing `skip_at` / `skip_txfm_ctx` accessors in `decode.rs`.
30+ Spec anchor: 7.11.2.9 `intra edge filter strength` — the `filt_type`
31+ argument is 1 when the relevant neighbour used a smooth mode. libaom:
32+ `av1/common/reconintra.c` `get_filt_type()` / `av1_filter_intra_edge` and
33+ `intra_edge_filter_strength`; `get_filt_type` reads
34+ `av1_is_directional_mode` and `is_smooth(above_mbmi)`/`is_smooth(left_mbmi)`.
35+ Gate it with a real-aomenc stream that enables smooth intra for LUMA while
36+ the chroma refusal is still in place (chroma can still refuse at this
37+ stage — that keeps the two changes separable). COMMIT.
38+2. **Then** add chroma UV-mode neighbour tracking and remove the smooth/paeth
39+ chroma refusal, with the gate from the attempt diff
40+ (`a_real_aomenc_stream_with_smooth_paeth_chroma_decodes_pixel_exact`)
41+ passing pixel-exact on luma AND chroma. COMMIT.
42+3. **Then** the directional-chroma sibling if turns remain: `decode.rs:7786`,
43+ the inter-frame intra-block reader, which refuses any non-DC/CFL uv_mode
44+ unconditionally and never computes `angle_delta_uv`. r1 found no bug there,
45+ only unwritten plumbing. COMMIT.
46+
47+## Gate rules (mandatory)
48+- Run tests with `EC_AV1_REQUIRE_AOMENC=1` — a missing oracle must FAIL, not SKIP.
49+- Bound every ffmpeg `generate` with `-t <seconds>`.
50+- Build fixtures through the existing `gradients_source(seed, w, h, tail)`
51+ helper; ffmpeg's `gradients` source ignores its own seed.
52+- aomenc `--threads=1 --row-mt=0`, and of course `--enable-smooth-intra=1`
53+ (and `--enable-paeth-intra=1` for stage 2).
54+- Hard-assert a firing count with a thread-local `Cell<usize>` counter in
55+ decode.rs matching the existing `*_HITS` (thread-local now, NOT atomics):
56+ for stage 1, count the blocks where `smooth_neighbor` came out TRUE — a gate
57+ that runs with smooth intra enabled but never hits the new branch proves
58+ nothing (class `gate-blind-to-feature`).
59+- Refusals inside a gate are FORBIDDEN once the stage removing them lands.
60+
61+## Method
62+CLASS `compare-range-not-tell`: compare the msac RANGE against the oracle, never
63+`tell()`. Oracle at `~/.cache/aom-oracle`, rungs `EC_TRACE=1` (partitions),
64+`EC_TRACE_COEFF=1`, `EC_TRACE_MODE=1` (inter + intra mode info),
65+`EC_AV1_PREFILT_DUMP=<prefix>` (per-frame pre-filter recon — the right rung for
66+a predictor bug, since it isolates prediction from the loop filters).
67+Add a rung via `scripts/instrument-aom-oracle.sh` + `scripts/build-aom-oracle.sh`
68+in the existing shape (env-gated, silent when unset, idempotent) if you need one.
69+
70+## Hard rules
71+- `export CARGO_TARGET_DIR=$HOME/.cache/cargo-target-chroma`. Foreground builds,
72+ `nice -n 19 cargo ... -j4`. Sibling worktrees (edith_codecs, -realworld, -lr,
73+ -superres, -tiles) have live agents — never build in or edit them.
74+- Suite: `nice -n 19 cargo test -p ec-av1 --lib`, baseline 232 passed / 0 failed.
75+- NEVER push, never merge, never touch `main`. Commit on `lane-chroma` only.
76+- 75-turn cap: COMMIT AFTER EVERY GREEN MILESTONE. r1 spent its whole budget and
77+ landed zero code because it held everything in the working tree; a commit that
78+ compiles beats a perfect uncommitted tree. Do not re-derive what r1's report
79+ already tells you (class `worker-cap-spent-reading`).
80+- End with `lanes/chroma-r2.report.md`, VERDICT on the first line.
lanes/chroma-r3.charter.mdadded+60 -0
@@ -0,0 +1,60 @@
1+# lane-chroma r3 — run the smooth-intra gate, then the chroma refusal
2+
3+Worktree `/home/user/Documents/Code/Rust/edith_codecs-chroma`, branch
4+`lane-chroma`.
5+
6+## State
7+- `8bca1d6` — **the luma fix landed**: `smooth_neighbor` is threaded into the
8+ intra edge filter strength instead of being hardcoded `false`. This is r1's
9+ root cause (a directional block neighbouring a smooth-mode one picked the
10+ wrong filter bucket). Committed, compiles.
11+- The next commit is the orchestrator's cap-rescue of r2's gate: ~140 new lines
12+ in `crates/ec-av1/src/stream.rs`, a smooth-intra gate that **compiles but has
13+ never been run once**. That is your first job.
14+- `lanes/chroma-r2.charter.md` — still binding for everything below.
15+- `lanes/chroma-r1.report.md` + `lanes/chroma-r1-attempt.diff` — r1's root-cause
16+ writeup and its reverted attempt (the chroma-side gate lives there).
17+
18+## Order — COMMIT AFTER EVERY GREEN STEP
19+1. Run the new gate:
20+ `export CARGO_TARGET_DIR=$HOME/.cache/cargo-target-chroma` then
21+ `EC_AV1_REQUIRE_AOMENC=1 nice -n 19 cargo test -p ec-av1 --lib <gate name> -j4 -- --nocapture`
22+ with a timeout of at least 600000 ms. Make it pass pixel-exact on luma with a
23+ HARD-asserted firing count proving `smooth_neighbor` actually came out TRUE
24+ somewhere — a gate that enables smooth intra but never hits the new branch
25+ proves nothing (class `gate-blind-to-feature`). Then the full suite
26+ (baseline 232/0 on this tree; main is at 234 with two new guard tests).
27+ COMMIT.
28+2. Chroma: add UV-mode neighbour tracking to `Neighbours` and remove the
29+ smooth/paeth chroma refusals (decode.rs uv_mode 9..=12, around 1970 and
30+ 2458), with r1's gate
31+ `a_real_aomenc_stream_with_smooth_paeth_chroma_decodes_pixel_exact` from the
32+ attempt diff green on luma AND chroma. COMMIT.
33+3. Once a gate really enables smooth-intra and paeth-intra, main's
34+ `crates/ec-av1/src/gate_coverage.rs` guard will FAIL by design: its
35+ `NEVER_EXERCISED` list still names `enable-smooth-intra` and
36+ `enable-paeth-intra` as tools no gate exercises. Deleting those two entries
37+ is part of landing this work — that guard exists precisely so closing the
38+ hole is noticed. (The guard is on main, so you will meet it at merge if not
39+ before; if `gate_coverage.rs` is not in your tree yet, note it in the report
40+ for the merge instead.)
41+4. If turns remain: the directional-chroma sibling at `decode.rs:7786`, the
42+ inter-frame intra-block reader, which refuses any non-DC/CFL uv_mode
43+ unconditionally and never computes `angle_delta_uv`. No known bug there,
44+ just unwritten plumbing. COMMIT.
45+
46+## Gate rules (mandatory)
47+`EC_AV1_REQUIRE_AOMENC=1` on every run; `-t <seconds>` on every ffmpeg generate;
48+fixtures through `gradients_source(seed, w, h, tail)`; aomenc
49+`--threads=1 --row-mt=0 --enable-smooth-intra=1` (and `--enable-paeth-intra=1`
50+for stage 2); firing counts are HARD asserts via thread-local `Cell<usize>`
51+counters like the existing `*_HITS`.
52+
53+## Hard rules
54+- Own `CARGO_TARGET_DIR` as above; foreground builds, `nice -n 19 cargo ... -j4`;
55+ every `cargo test` gets a timeout of at least 600000 ms.
56+- Sibling worktrees (edith_codecs, -realworld, -lr, -superres, -tiles) have live
57+ agents. Never build in or edit them.
58+- NEVER push, never merge, never touch `main`. Commit on `lane-chroma` only.
59+- 75-turn cap and it does NOT reset on resume: commit at every green step.
60+- End with `lanes/chroma-r3.report.md`, VERDICT on the first line.
lanes/chroma-r4.charter.mdadded+49 -0
@@ -0,0 +1,49 @@
1+# lane-chroma r4 — finish the chroma refusal removal
2+
3+Worktree `/home/user/Documents/Code/Rust/edith_codecs-chroma`, branch
4+`lane-chroma`. Read `lanes/chroma-r3.charter.md` (still binding) and, briefly,
5+`lanes/chroma-r1.report.md` for the root cause. Do not re-derive them.
6+
7+## State
8+- `8bca1d6` — the real luma fix: `smooth_neighbor` threaded into the intra edge
9+ filter strength instead of hardcoded `false`.
10+- `bafda07` — r2's smooth-intra gate, cap-rescued, compiles.
11+- HEAD — r3's work, cap-rescued by the orchestrator: `decode.rs` +99,
12+ `stream.rs` +126. r3's last words before the cap were "now let's add the r1
13+ gate for smooth/paeth chroma (charter step 2), then run the full lib test
14+ suite" — so the luma gate is believed to have gone green in r3's hands, but
15+ **no suite run has ever been seen on this tree**. Verify, do not assume.
16+
17+## Order
18+1. `export CARGO_TARGET_DIR=$HOME/.cache/cargo-target-chroma` then
19+ `EC_AV1_REQUIRE_AOMENC=1 nice -n 19 cargo test -p ec-av1 --lib -j4`
20+ (timeout >= 600000 ms). Report the count against 232/0 for this tree.
21+ If red, fixing HEAD is the whole job until it is green. COMMIT once green.
22+2. Chroma: UV-mode neighbour tracking in `Neighbours`, remove the smooth/paeth
23+ chroma refusals (decode.rs uv_mode 9..=12, around 1970 and 2458), with r1's
24+ gate `a_real_aomenc_stream_with_smooth_paeth_chroma_decodes_pixel_exact`
25+ (in `lanes/chroma-r1-attempt.diff`) green on luma AND chroma. COMMIT.
26+3. Note for the merge: main carries `crates/ec-av1/src/gate_coverage.rs`, whose
27+ `NEVER_EXERCISED` list still names `enable-smooth-intra` and
28+ `enable-paeth-intra` as tools no gate exercises. Once your gates enable them,
29+ those two entries must be deleted — that guard exists so closing the hole is
30+ noticed. If `gate_coverage.rs` is not in your tree, say so in the report so
31+ the merge does it.
32+4. If turns remain: the directional-chroma sibling at `decode.rs:7786` (the
33+ inter-frame intra-block reader refuses any non-DC/CFL uv_mode and never
34+ computes `angle_delta_uv`). COMMIT.
35+
36+## Gate rules
37+`EC_AV1_REQUIRE_AOMENC=1` on every run; `-t <seconds>` on every ffmpeg generate;
38+fixtures through `gradients_source(seed, w, h, tail)`; aomenc
39+`--threads=1 --row-mt=0 --enable-smooth-intra=1 --enable-paeth-intra=1`;
40+firing counts are HARD asserts via thread-local `Cell<usize>` counters.
41+
42+## Hard rules
43+Own `CARGO_TARGET_DIR` as above; foreground builds `nice -n 19 cargo ... -j4`;
44+every `cargo test` a timeout >= 600000 ms. Sibling worktrees (edith_codecs,
45+-realworld, -lr, -superres, -tiles, -palette) have live agents — never build in
46+or edit them. Never push, never merge, never touch `main`. 75-turn cap, does not
47+reset: COMMIT AT EVERY GREEN STEP — three rounds in a row on this lane have
48+ended with the work uncommitted. End with `lanes/chroma-r4.report.md`, VERDICT
49+on line 1.
lanes/chroma-r4.report.mdadded+66 -0
@@ -0,0 +1,66 @@
1+VERDICT: GREEN
2+
3+## Step 1 -- verify HEAD
4+`EC_AV1_REQUIRE_AOMENC=1 cargo test -p ec-av1 --lib -j4`: **234 passed; 0 failed; 17
5+ignored** (vs the charter's 232/0 baseline -- 2 extra tests are r3's own new
6+smooth-intra/smooth-paeth-chroma gates, already in HEAD). Tree was clean at
7+start (nothing to commit for this step); r3's cap-rescued work is genuinely
8+green, contrary to the "no suite run has ever been seen" warning.
9+
10+## Step 2 -- chroma UV-mode neighbour tracking + smooth/paeth chroma refusal
11+Already done in HEAD (r3's commit `47da0be`): `Neighbours::above_uv_mode`/
12+`left_uv_mode` exist, `decode.rs`'s two `read_intra_mode`/`read_intra_mode_rect`
13+sites (keyframe callers) removed the `9..=12` uv_mode refusal, and
14+`lanes/chroma-r1-attempt.diff`'s gate
15+(`a_real_aomenc_stream_with_smooth_paeth_chroma_decodes_pixel_exact`) is
16+present in `stream.rs` and passes on its own
17+(`cargo test ... smooth_paeth_chroma` -- 1 passed). No new commit needed.
18+
19+## Step 3 -- gate_coverage.rs
20+`crates/ec-av1/src/gate_coverage.rs` **does not exist in this tree**
21+(confirmed via `find`). Per the charter, the merge must delete the
22+`enable-smooth-intra`/`enable-paeth-intra` entries from `NEVER_EXERCISED`
23+on `main`'s copy.
24+
25+## Step 4 -- directional-chroma sibling (turns remained)
26+Charter's line number (`decode.rs:7786`) had drifted from r3's +99 lines;
27+the real sibling was `decode_inter_block`'s intra-in-inter branch (the
28+`else` arm handling an intra block coded inside an inter frame), which read
29+`uv_mode` and refused outright with `"a directional chroma mode (round 2)"`
30+for anything past DC/CFL, and never read `angle_delta_uv` at all.
31+
32+Fixed by mirroring `read_intra_mode`'s already-proven pattern in that one
33+function (`crates/ec-av1/src/decode.rs`, `decode_inter_block`):
34+- `uv_predict_mode` (CFL predicts as DC for the reconstruct call, same as
35+ the keyframe path) threaded through both `u`/`v.reconstruct` calls (skip
36+ path) and both chroma `read_plane` calls (non-skip path), replacing the
37+ hardcoded `DC_PRED`.
38+- `angle_delta_uv` computed via `read_angle_delta` when `uv_mode` is
39+ directional (`V_PRED..=D67_PRED`), replacing the hardcoded `0`.
40+- `smooth_neighbor_uv` computed from the chroma neighbour's own `uv_mode`
41+ (`is_smooth_mode(above_uv_mode/left_uv_mode)`), replacing the hardcoded
42+ `false`, threaded into the same reconstruct/read_plane calls.
43+- `SMOOTH_UV_HITS`/`DIRECTIONAL_UV_HITS` counted here too (shared
44+ thread-locals with the keyframe path).
45+- `neighbours.record_rect`'s uv-mode arg (previously hardcoded `DC_PRED`)
46+ now carries the real `uv_predict_mode` so a following block's own
47+ smooth-neighbour check sees it.
48+- The luma-mode side of this branch (`mode`, its own angle_delta refusal at
49+ the top) is **untouched** -- out of this charter step's chroma-only scope.
50+
51+`cargo check -p ec-av1 --lib`: clean (no new warnings/errors). Full lib
52+suite re-run after the change: still **234 passed; 0 failed; 17 ignored** --
53+no regression.
54+
55+**Gap, disclosed per "refusal strings are claims":** no dedicated gate
56+proves a real aomenc stream ever actually exercises this specific path (an
57+intra block, directional/smooth/paeth `uv_mode`, coded *inside an inter
58+frame*) end to end against ffmpeg. The change is a direct structural mirror
59+of the already-gated keyframe fix (identical CDF tables, identical
60+`get_uv_mode`/angle-delta semantics per spec 9.3), and the full suite stays
61+green, but it is **code-verified by mirroring, not gate-verified by firing**.
62+`deferred: dedicated a_real_aomenc_stream_with_directional_chroma_in_inter_frame_intra gate -- next round, no seat left this round -- unblocks by writing a stream.rs gate that forces an inter-frame key/delta pair whose delta frame codes an intra 8x8+ leaf with directional/smooth/paeth uv_mode (drop --enable-tx-size-search=0 constraint if it starves the recipe) and asserts on decode::smooth_uv_hits()/directional_uv_hits() firing plus pixel-exact vs ffmpeg`.
63+
64+## Commit
65+`c806bd6` -- directional/smooth/paeth chroma in inter-frame intra blocks.
66+Nothing else uncommitted; `git status` clean.