forge
Explore
Log in

Don't you dare go Hollow

merge: main (85887c7) into lane-sb128c

Browse files at this commit

350a0dbd1f223d1bc402adcc916bc6cc16bed9efAhmet Kaan GümüşParent: 712eb45cfef385
No conflicts (auto-merge in decode.rs, stream.rs, gate_coverage.rs, mvstack.rs).
cdf.rs untouched by both sides. `cargo check -p ec-av1` clean on the merged tree.
crates/ec-av1/examples/decode_probe.rsmodified+2 -0
@@ -29,6 +29,8 @@ fn main() {
29 }29 }
30 };30 };
31 let report = || {31 let report = || {
32+ let (sc, dp) = ec_av1::decode::reelc_chroma_counters();
33+ println!("reelc_chroma: skip_cfl={sc} dir_1to4_pairs={dp}");
32 let (h, v, c) = ec_av1::stream::rect4_32_counters();34 let (h, v, c) = ec_av1::stream::rect4_32_counters();
33 println!("rect4_32: horz={h} vert={v} coded={c}");35 println!("rect4_32: horz={h} vert={v} coded={c}");
34 let (rtu, rsplit, robmc) = ec_av1::stream::rect_inter_tu_counters();36 let (rtu, rsplit, robmc) = ec_av1::stream::rect_inter_tu_counters();
crates/ec-av1/fixtures/reelc_kf2700.obuadded+0 -0

Binary file changed

crates/ec-av1/src/decode.rsmodified+58 -7
@@ -2222,6 +2222,24 @@ thread_local! {
2222 static RECT4_16_SPLIT_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };2222 static RECT4_16_SPLIT_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
2223 }2223 }
2224 2224
2225+// lane-reelckf r1: the two chroma defects ReelC's key frames exposed --
2226+// CHROMA_SKIP_CFL counts skipped intra blocks whose chroma is `UV_CFL_PRED`
2227+// (prediction still runs, libaom `predict_and_reconstruct_intra_block`), and
2228+// RECT4_16_CHROMA_DIR counts 1:4 chroma pairs predicted directionally (whose
2229+// intra-edge filter type must come from the chroma-reference position).
2230+thread_local! {
2231+ static CHROMA_SKIP_CFL_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
2232+ static RECT4_16_CHROMA_DIR_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
2233+}
2234+
2235+/// `(skipped UV_CFL_PRED blocks, directional 1:4 chroma pairs)` -- lane-reelckf.
2236+pub fn reelc_chroma_counters() -> (usize, usize) {
2237+ (
2238+ CHROMA_SKIP_CFL_HITS.with(|c| c.get()),
2239+ RECT4_16_CHROMA_DIR_HITS.with(|c| c.get()),
2240+ )
2241+}
2242+
2225 /// Current values of the 16x16-level 1:4 counters: `(16x4 strips, 4x162243 /// Current values of the 16x16-level 1:4 counters: `(16x4 strips, 4x16
2226 /// strips, chroma-reference strips, strips with a coded residual, strips2244 /// strips, chroma-reference strips, strips with a coded residual, strips
2227 /// whose luma transform is split)`.2245 /// whose luma transform is split)`.
@@ -7740,11 +7758,30 @@ fn decode_rect4_16(
7740 let (cpx, cpy) = (ppx / 2, ppy / 2);7758 let (cpx, cpy) = (ppx / 2, ppy / 2);
7741 let (cw, ch) = (pw / 2, ph / 2);7759 let (cw, ch) = (pw / 2, ph / 2);
7742 let uv_predict_mode = if uv_mode == UV_CFL_PRED { DC_PRED } else { uv_mode };7760 let uv_predict_mode = if uv_mode == UV_CFL_PRED { DC_PRED } else { uv_mode };
7761+ if (V_PRED..=D67_PRED).contains(&uv_predict_mode) {
7762+ RECT4_16_CHROMA_DIR_HITS.with(|h| h.set(h.get() + 1));
7763+ }
7743 let pair_reach = Reach::of_rect(pw, ph, ppx, ppy, y.width, y.height);7764 let pair_reach = Reach::of_rect(pw, ph, ppx, ppy, y.width, y.height);
7744- let smooth_neighbor_uv = neighbours.smooth_uv_neighbour(lmi.0, lmi.1, r, c);7765+ // libaom `get_intra_edge_filter_type` reads `chroma_above_mbmi` /
7766+ // `chroma_left_mbmi` -- the neighbours of the CHROMA REFERENCE
7767+ // position, not of the closing strip. At `lmi` the above cell is
7768+ // the pair's own first strip, so the mi-exact map missed and the
7769+ // coarse fallback answered; the filter type then flipped the
7770+ // `use_intra_edge_upsample` decision (blk_wh 12 <= 16 for type 0,
7771+ // no upsample for type 1) on directional chroma.
7772+ let smooth_neighbor_uv = neighbours.smooth_uv_neighbour(pair_mi.0, pair_mi.1, r, c);
7745 let (u_levels, v_levels) = if skip {7773 let (u_levels, v_levels) = if skip {
7746 let zeros = vec![0i32; cw * ch];7774 let zeros = vec![0i32; cw * ch];
7747- for (buf, _plane) in [(&mut *u, 1usize), (&mut *v, 2)] {7775+ // libaom `predict_and_reconstruct_intra_block` (decodeframe.c
7776+ // ~1000) predicts EVERY plane and only guards the residual on
7777+ // `mbmi->skip_txfm`, so a skipped `UV_CFL_PRED` block is still
7778+ // DC + alpha * luma-AC. Dropping the CfL term here left a
7779+ // chroma-only bounded box on ReelC's key frames.
7780+ let ac = alpha.map(|_| cfl_ac_q3_rect(y, ppx, ppy, pw, ph));
7781+ if alpha.is_some() {
7782+ CHROMA_SKIP_CFL_HITS.with(|h| h.set(h.get() + 1));
7783+ }
7784+ for (buf, plane) in [(&mut *u, 1usize), (&mut *v, 2)] {
7748 buf.reconstruct_rect(7785 buf.reconstruct_rect(
7749 cpx,7786 cpx,
7750 cpy,7787 cpy,
@@ -7754,7 +7791,9 @@ fn decode_rect4_16(
7754 angle_delta_uv,7791 angle_delta_uv,
7755 pair_reach,7792 pair_reach,
7756 &zeros,7793 &zeros,
7757- None,7794+ alpha
7795+ .zip(ac.as_deref())
7796+ .map(|((au, av), ac)| (if plane == 1 { au } else { av }, ac)),
7758 None,7797 None,
7759 smooth_neighbor_uv,7798 smooth_neighbor_uv,
7760 );7799 );
@@ -10547,8 +10586,14 @@ fn decode_leaf_split4(
10547 neighbours.left_uv_mode[r] = uv_predict_mode;10586 neighbours.left_uv_mode[r] = uv_predict_mode;
10548 neighbours.record_uv_mode_mi(leaf_mi.0, leaf_mi.1, 2, 2, uv_predict_mode);10587 neighbours.record_uv_mode_mi(leaf_mi.0, leaf_mi.1, 2, 2, uv_predict_mode);
10549 let (u_grid, v_grid): (Vec<i32>, Vec<i32>) = if leaf_skips[3] {10588 let (u_grid, v_grid): (Vec<i32>, Vec<i32>) = if leaf_skips[3] {
10550- u.reconstruct(cpx, cpy, 4, uv_predict_mode, angle_delta_uv, group_reach, &vec![0i32; 16], None, None, smooth_neighbor_uv);10589+ // As the rect4 pair above: a skipped block still predicts, and CfL is
10551- v.reconstruct(cpx, cpy, 4, uv_predict_mode, angle_delta_uv, group_reach, &vec![0i32; 16], None, None, smooth_neighbor_uv);10590+ // prediction (libaom `predict_and_reconstruct_intra_block`).
10591+ let ac = alpha.map(|_| cfl_ac_q3(y, gpx, gpy, 8));
10592+ if alpha.is_some() {
10593+ CHROMA_SKIP_CFL_HITS.with(|h| h.set(h.get() + 1));
10594+ }
10595+ u.reconstruct(cpx, cpy, 4, uv_predict_mode, angle_delta_uv, group_reach, &vec![0i32; 16], alpha.zip(ac.as_deref()).map(|((au, _), ac)| (au, ac)), None, smooth_neighbor_uv);
10596+ v.reconstruct(cpx, cpy, 4, uv_predict_mode, angle_delta_uv, group_reach, &vec![0i32; 16], alpha.zip(ac.as_deref()).map(|((_, av), ac)| (av, ac)), None, smooth_neighbor_uv);
10552 (vec![0i32; 16], vec![0i32; 16])10597 (vec![0i32; 16], vec![0i32; 16])
10553 } else {10598 } else {
10554 let ac = alpha.map(|_| cfl_ac_q3(y, gpx, gpy, 8));10599 let ac = alpha.map(|_| cfl_ac_q3(y, gpx, gpy, 8));
@@ -10900,8 +10945,14 @@ fn decode_leaf_rect8(
10900 neighbours.left_uv_mode[r] = uv_predict_mode;10945 neighbours.left_uv_mode[r] = uv_predict_mode;
10901 neighbours.record_uv_mode_mi(leaf_mi.0, leaf_mi.1, 2, 2, uv_predict_mode);10946 neighbours.record_uv_mode_mi(leaf_mi.0, leaf_mi.1, 2, 2, uv_predict_mode);
10902 let (u_grid, v_grid): (Vec<i32>, Vec<i32>) = if leaf_skips[1] {10947 let (u_grid, v_grid): (Vec<i32>, Vec<i32>) = if leaf_skips[1] {
10903- u.reconstruct(cpx, cpy, 4, uv_predict_mode, angle_delta_uv, group_reach, &vec![0i32; 16], None, None, smooth_neighbor_uv);10948+ // As the rect4 pair above: a skipped block still predicts, and CfL is
10904- v.reconstruct(cpx, cpy, 4, uv_predict_mode, angle_delta_uv, group_reach, &vec![0i32; 16], None, None, smooth_neighbor_uv);10949+ // prediction (libaom `predict_and_reconstruct_intra_block`).
10950+ let ac = alpha.map(|_| cfl_ac_q3(y, gpx, gpy, 8));
10951+ if alpha.is_some() {
10952+ CHROMA_SKIP_CFL_HITS.with(|h| h.set(h.get() + 1));
10953+ }
10954+ u.reconstruct(cpx, cpy, 4, uv_predict_mode, angle_delta_uv, group_reach, &vec![0i32; 16], alpha.zip(ac.as_deref()).map(|((au, _), ac)| (au, ac)), None, smooth_neighbor_uv);
10955+ v.reconstruct(cpx, cpy, 4, uv_predict_mode, angle_delta_uv, group_reach, &vec![0i32; 16], alpha.zip(ac.as_deref()).map(|((_, av), ac)| (av, ac)), None, smooth_neighbor_uv);
10905 (vec![0i32; 16], vec![0i32; 16])10956 (vec![0i32; 16], vec![0i32; 16])
10906 } else {10957 } else {
10907 let ac = alpha.map(|_| cfl_ac_q3(y, gpx, gpy, 8));10958 let ac = alpha.map(|_| cfl_ac_q3(y, gpx, gpy, 8));
crates/ec-av1/src/gate_coverage.rsmodified+8 -9
@@ -148,10 +148,9 @@ const ALIASES: &[(&str, &str)] = &[("superres-mode", "enable-superres")];
148 /// depth retires the entry, and this test fails until it is deleted.148 /// depth retires the entry, and this test fails until it is deleted.
149 #[cfg(test)]149 #[cfg(test)]
150 const NEVER_EXERCISED_8BIT: &[(&str, &str)] = &[150 const NEVER_EXERCISED_8BIT: &[(&str, &str)] = &[
151- (151+ // `enable-cfl-intra` LEFT both lists on 2026-09-02 (lane-reelckf r1): the
152- "enable-cfl-intra",152+ // sb128 skipped-CfL / 1:4-chroma gate passes `--enable-cfl-intra=1` at 8
153- "off in 41 gates, on in none: chroma-from-luma prediction is unimplemented",153+ // AND 10 bits and pixel-compares both arms.
154- ),
155 (154 (
156 "enable-dist-wtd-comp",155 "enable-dist-wtd-comp",
157 "off in 11 gates, on in none: distance-weighted compound is unimplemented",156 "off in 11 gates, on in none: distance-weighted compound is unimplemented",
@@ -206,10 +205,6 @@ const NEVER_EXERCISED_10BIT: &[(&str, &str)] = &[ // lane-cwarp's 10-bit comp
206 // gate passes `=1` for both. `enable-1to4-partitions` left it on 2026-09-02:205 // gate passes `=1` for both. `enable-1to4-partitions` left it on 2026-09-02:
207 // lane-tx64x16 r4's 32-level 1:4 gate has a 10-bit arm that asserts both206 // lane-tx64x16 r4's 32-level 1:4 gate has a 10-bit arm that asserts both
208 // orientations and coded strips inside pixel-exact attempts.207 // orientations and coded strips inside pixel-exact attempts.
209- (
210- "enable-cfl-intra",
211- "hole at both depths, see the 8-bit list",
212- ),
213 (208 (
214 "enable-dual-filter",209 "enable-dual-filter",
215 "hole at both depths, see the 8-bit list",210 "hole at both depths, see the 8-bit list",
@@ -416,8 +411,12 @@ mod tests {
416 /// an 8-bit and a 10-bit stream from one recipe, so its flags cover both411 /// an 8-bit and a 10-bit stream from one recipe, so its flags cover both
417 /// depths -- classifying it by the 10-bit strings inside its conditional412 /// depths -- classifying it by the 10-bit strings inside its conditional
418 /// alone hid `--enable-tx-size-search=1` from the 8-bit list.413 /// alone hid `--enable-tx-size-search=1` from the 8-bit list.
414+ /// lane-reelckf r1: the same blind spot with the other spelling -- a gate
415+ /// that loops `for depth in [8usize, 10]` builds BOTH streams from one
416+ /// recipe, but its `yuv420p10le` arm made `is_ten_bit` classify it as
417+ /// 10-bit only, hiding `--enable-cfl-intra=1` from the 8-bit list.
419 fn covers_both_depths(body: &str) -> bool {418 fn covers_both_depths(body: &str) -> bool {
420- body.contains("if bit_depth == 10")419+ body.contains("if bit_depth == 10") || body.contains("for depth in [8usize, 10]")
421 }420 }
422 421
423 /// Whether a gate body drives a stream at this depth.422 /// Whether a gate body drives a stream at this depth.
crates/ec-av1/src/mvstack.rsmodified+199 -18
@@ -92,6 +92,36 @@ pub(crate) fn tmv_hits() -> usize {
92 TMV_HITS.load(std::sync::atomic::Ordering::Relaxed)92 TMV_HITS.load(std::sync::atomic::Ordering::Relaxed)
93 }93 }
94 94
95+/// lane-mvtwin r1 firing counters, one per divergence this round closed.
96+/// `COMP_GM_FILL_HITS`: compound extension candidates whose `comp_list` slot
97+/// came from `gm_mv_candidates[side]` rather than a scanned neighbour, and
98+/// where that global mv was NOT `(0, 0)` (the only case the old zero fill
99+/// could not fake). `STACK_FULL_DROPS`: distinct candidates libaom drops at
100+/// `MAX_REF_MV_STACK_SIZE` on insertion. `TILE_REACH_CLIPS`: row/col reaches
101+/// shortened by a tile origin past mi 0, which the old frame-edge clamp
102+/// missed entirely.
103+static COMP_GM_FILL_HITS: std::sync::atomic::AtomicUsize =
104+ std::sync::atomic::AtomicUsize::new(0);
105+static STACK_FULL_DROPS: std::sync::atomic::AtomicUsize =
106+ std::sync::atomic::AtomicUsize::new(0);
107+static TILE_REACH_CLIPS: std::sync::atomic::AtomicUsize =
108+ std::sync::atomic::AtomicUsize::new(0);
109+
110+/// [`COMP_GM_FILL_HITS`].
111+pub(crate) fn comp_gm_fill_hits() -> usize {
112+ COMP_GM_FILL_HITS.load(std::sync::atomic::Ordering::Relaxed)
113+}
114+
115+/// [`STACK_FULL_DROPS`].
116+pub(crate) fn stack_full_drops() -> usize {
117+ STACK_FULL_DROPS.load(std::sync::atomic::Ordering::Relaxed)
118+}
119+
120+/// [`TILE_REACH_CLIPS`].
121+pub(crate) fn tile_reach_clips() -> usize {
122+ TILE_REACH_CLIPS.load(std::sync::atomic::Ordering::Relaxed)
123+}
124+
95 /// Everything [`find_mv_stack_with_sign_bias`] needs to fold temporal MV125 /// Everything [`find_mv_stack_with_sign_bias`] needs to fold temporal MV
96 /// candidates into a block's stack (spec 7.10.2.8, only reached when the126 /// candidates into a block's stack (spec 7.10.2.8, only reached when the
97 /// frame header's own `use_ref_frame_mvs` is set): the current frame's own127 /// frame header's own `use_ref_frame_mvs` is set): the current frame's own
@@ -213,6 +243,14 @@ impl MiGrid {
213 self.tile_col1 = col1;243 self.tile_col1 = col1;
214 }244 }
215 245
246+ /// The current tile's top-left mi-unit origin ([`Self::set_tile_bounds`]).
247+ /// libaom's `tile->mi_row_start`/`mi_col_start`, which every availability
248+ /// and reach clamp in `setup_ref_mv_list` is written against
249+ /// (`xd->up_available`, `find_valid_row_offset`, mvref_common.c:512-528).
250+ pub fn tile_origin(&self) -> (usize, usize) {
251+ (self.tile_row0, self.tile_col0)
252+ }
253+
216 /// Records the unit at `(row, col)`. Out-of-range coordinates are a254 /// Records the unit at `(row, col)`. Out-of-range coordinates are a
217 /// no-op — the caller only ever addresses units inside the grid it built.255 /// no-op — the caller only ever addresses units inside the grid it built.
218 pub fn set(&mut self, row: usize, col: usize, info: MiInfo) {256 pub fn set(&mut self, row: usize, col: usize, info: MiInfo) {
@@ -313,7 +351,15 @@ const MVREF_ROW_COLS: usize = 3;
313 fn add_candidate(candidates: &mut Vec<StackEntry>, mv: (i32, i32), weight: u32) {351 fn add_candidate(candidates: &mut Vec<StackEntry>, mv: (i32, i32), weight: u32) {
314 if let Some(entry) = candidates.iter_mut().find(|e| e.mv == mv) {352 if let Some(entry) = candidates.iter_mut().find(|e| e.mv == mv) {
315 entry.weight += weight;353 entry.weight += weight;
354+ } else if candidates.len() >= MAX_STACK_SIZE {
355+ STACK_FULL_DROPS.fetch_add(1, std::sync::atomic::Ordering::Relaxed);
316 } else {356 } else {
357+ // libaom `add_ref_mv_candidate` (mvref_common.c:100) and
358+ // `add_tpl_ref_mv` (:388) only push when
359+ // `*refmv_count < MAX_REF_MV_STACK_SIZE` -- the 9th distinct MV is
360+ // DROPPED AT INSERTION, never "kept if it outweighs an earlier one".
361+ // Sorting first and truncating afterwards (what this did) keeps a
362+ // different set whenever more than 8 distinct candidates are seen.
317 candidates.push(StackEntry { mv, weight });363 candidates.push(StackEntry { mv, weight });
318 }364 }
319 }365 }
@@ -773,22 +819,35 @@ pub fn find_mv_stack_with_sign_bias(
773 // nothing here relies on that.819 // nothing here relies on that.
774 let row_adj = bh4 < 2 && mi_row % 2 == 1;820 let row_adj = bh4 < 2 && mi_row % 2 == 1;
775 let col_adj = bw4 < 2 && mi_col % 2 == 1;821 let col_adj = bw4 < 2 && mi_col % 2 == 1;
776- let max_row_offset: isize = if mi_row > 0 {822+ // r1 (lane-mvtwin): availability and reach are TILE-relative, never
823+ // frame-relative -- libaom's `xd->up_available`/`left_available` are
824+ // `mi_row > tile->mi_row_start` / `mi_col > tile->mi_col_start`, and
825+ // `find_valid_row_offset`/`find_valid_col_offset` (mvref_common.c:512-528)
826+ // clamp the reach to `tile->mi_row_start - mi_row`. Clamping to the FRAME
827+ // edge left `max_row_offset`/`max_col_offset` too long inside every tile
828+ // that does not start at 0, which changes the row/col scan's `inc` weight
829+ // (and so the stack ORDER) even though `MiGrid::get` already returns
830+ // `None` for the cells outside the tile.
831+ let (tile_row0, tile_col0) = grid.tile_origin();
832+ if tile_row0 > 0 || tile_col0 > 0 {
833+ TILE_REACH_CLIPS.fetch_add(1, std::sync::atomic::Ordering::Relaxed);
834+ }
835+ let max_row_offset: isize = if mi_row > tile_row0 {
777 let reach = if bh4 < 2 { -4 } else { -6 } + isize::from(row_adj);836 let reach = if bh4 < 2 { -4 } else { -6 } + isize::from(row_adj);
778- reach.max(-(mi_row as isize))837+ reach.max(tile_row0 as isize - mi_row as isize)
779 } else {838 } else {
780 0839 0
781 };840 };
782- let max_col_offset: isize = if mi_col > 0 {841+ let max_col_offset: isize = if mi_col > tile_col0 {
783 let reach = if bw4 < 2 { -4 } else { -6 } + isize::from(col_adj);842 let reach = if bw4 < 2 { -4 } else { -6 } + isize::from(col_adj);
784- reach.max(-(mi_col as isize))843+ reach.max(tile_col0 as isize - mi_col as isize)
785 } else {844 } else {
786 0845 0
787 };846 };
788 847
789 let mut processed_rows = 0usize;848 let mut processed_rows = 0usize;
790 let mut processed_cols = 0usize;849 let mut processed_cols = 0usize;
791- let found_above = mi_row > 0850+ let found_above = max_row_offset.unsigned_abs() >= 1
792 && scan_row(851 && scan_row(
793 grid,852 grid,
794 mi_row,853 mi_row,
@@ -802,7 +861,7 @@ pub fn find_mv_stack_with_sign_bias(
802 &mut newmv_count,861 &mut newmv_count,
803 &mut processed_rows,862 &mut processed_rows,
804 );863 );
805- let found_left = mi_col > 0864+ let found_left = max_col_offset.unsigned_abs() >= 1
806 && scan_col(865 && scan_col(
807 grid,866 grid,
808 mi_row,867 mi_row,
@@ -1227,7 +1286,12 @@ fn add_compound_candidate(
1227 ) {1286 ) {
1228 if let Some(entry) = candidates.iter_mut().find(|e| e.mv0 == mv0 && e.mv1 == mv1) {1287 if let Some(entry) = candidates.iter_mut().find(|e| e.mv0 == mv0 && e.mv1 == mv1) {
1229 entry.weight += weight;1288 entry.weight += weight;
1289+ } else if candidates.len() >= MAX_STACK_SIZE {
1290+ STACK_FULL_DROPS.fetch_add(1, std::sync::atomic::Ordering::Relaxed);
1230 } else {1291 } else {
1292+ // Same insertion cap as [`add_candidate`]: libaom's compound branch
1293+ // of `add_ref_mv_candidate` (mvref_common.c:128) and `add_tpl_ref_mv`
1294+ // (:425) both gate the push on `*refmv_count < MAX_REF_MV_STACK_SIZE`.
1231 candidates.push(CompoundStackEntry { mv0, mv1, weight });1295 candidates.push(CompoundStackEntry { mv0, mv1, weight });
1232 }1296 }
1233 }1297 }
@@ -1477,9 +1541,18 @@ fn process_compound_ref_mv_candidate(
1477 /// libaom's combine step (`setup_ref_mv_list`, `mvref_common.c` ~696-720):1541 /// libaom's combine step (`setup_ref_mv_list`, `mvref_common.c` ~696-720):
1478 /// zips each side's `ref_id` (exact matches) then `ref_diff` (borrowed,1542 /// zips each side's `ref_id` (exact matches) then `ref_diff` (borrowed,
1479 /// sign-flipped) entries, position-wise and independently per side, into up1543 /// sign-flipped) entries, position-wise and independently per side, into up
1480-/// to two full `(mv0, mv1)` pair candidates — missing slots default to1544+/// to two full `(mv0, mv1)` pair candidates. r1 (lane-mvtwin): slots past
1481-/// `(0, 0)`, matching libaom's zero-initialized `combined_mvs`.1545+/// both lists are filled with THAT SIDE's own global motion vector
1482-fn combine_compound_candidates(lists: &CompoundRefLists) -> [((i32, i32), (i32, i32)); 2] {1546+/// (`gm_mv_candidates[idx]`, mvref_common.c:718-719), never `(0, 0)` — the
1547+/// exact gap the single-reference twin closed in r6 for its own
1548+/// `mv_ref_list` tail, still open on this side. Invisible while every live
1549+/// reference's global motion is IDENTITY (an unclamped gm mv of exactly
1550+/// `(0,0)`), wrong the moment a compound pair names a ROTZOOM/AFFINE
1551+/// reference and the scans leave the stack short.
1552+fn combine_compound_candidates(
1553+ lists: &CompoundRefLists,
1554+ gm_mv_candidates: [(i32, i32); 2],
1555+) -> [((i32, i32), (i32, i32)); 2] {
1483 let side_slots = |side: usize| -> [(i32, i32); 2] {1556 let side_slots = |side: usize| -> [(i32, i32); 2] {
1484 let merged: Vec<(i32, i32)> = lists.ref_id[side]1557 let merged: Vec<(i32, i32)> = lists.ref_id[side]
1485 .iter()1558 .iter()
@@ -1487,7 +1560,14 @@ fn combine_compound_candidates(lists: &CompoundRefLists) -> [((i32, i32), (i32,
1487 .take(2)1560 .take(2)
1488 .copied()1561 .copied()
1489 .collect();1562 .collect();
1490- std::array::from_fn(|i| merged.get(i).copied().unwrap_or((0, 0)))1563+ std::array::from_fn(|i| {
1564+ merged.get(i).copied().unwrap_or_else(|| {
1565+ if gm_mv_candidates[side] != (0, 0) {
1566+ COMP_GM_FILL_HITS.fetch_add(1, std::sync::atomic::Ordering::Relaxed);
1567+ }
1568+ gm_mv_candidates[side]
1569+ })
1570+ })
1491 };1571 };
1492 let side0 = side_slots(0);1572 let side0 = side_slots(0);
1493 let side1 = side_slots(1);1573 let side1 = side_slots(1);
@@ -1532,22 +1612,35 @@ pub fn find_mv_stack_compound(
1532 1612
1533 let row_adj = bh4 < 2 && mi_row % 2 == 1;1613 let row_adj = bh4 < 2 && mi_row % 2 == 1;
1534 let col_adj = bw4 < 2 && mi_col % 2 == 1;1614 let col_adj = bw4 < 2 && mi_col % 2 == 1;
1535- let max_row_offset: isize = if mi_row > 0 {1615+ // r1 (lane-mvtwin): availability and reach are TILE-relative, never
1616+ // frame-relative -- libaom's `xd->up_available`/`left_available` are
1617+ // `mi_row > tile->mi_row_start` / `mi_col > tile->mi_col_start`, and
1618+ // `find_valid_row_offset`/`find_valid_col_offset` (mvref_common.c:512-528)
1619+ // clamp the reach to `tile->mi_row_start - mi_row`. Clamping to the FRAME
1620+ // edge left `max_row_offset`/`max_col_offset` too long inside every tile
1621+ // that does not start at 0, which changes the row/col scan's `inc` weight
1622+ // (and so the stack ORDER) even though `MiGrid::get` already returns
1623+ // `None` for the cells outside the tile.
1624+ let (tile_row0, tile_col0) = grid.tile_origin();
1625+ if tile_row0 > 0 || tile_col0 > 0 {
1626+ TILE_REACH_CLIPS.fetch_add(1, std::sync::atomic::Ordering::Relaxed);
1627+ }
1628+ let max_row_offset: isize = if mi_row > tile_row0 {
1536 let reach = if bh4 < 2 { -4 } else { -6 } + isize::from(row_adj);1629 let reach = if bh4 < 2 { -4 } else { -6 } + isize::from(row_adj);
1537- reach.max(-(mi_row as isize))1630+ reach.max(tile_row0 as isize - mi_row as isize)
1538 } else {1631 } else {
1539 01632 0
1540 };1633 };
1541- let max_col_offset: isize = if mi_col > 0 {1634+ let max_col_offset: isize = if mi_col > tile_col0 {
1542 let reach = if bw4 < 2 { -4 } else { -6 } + isize::from(col_adj);1635 let reach = if bw4 < 2 { -4 } else { -6 } + isize::from(col_adj);
1543- reach.max(-(mi_col as isize))1636+ reach.max(tile_col0 as isize - mi_col as isize)
1544 } else {1637 } else {
1545 01638 0
1546 };1639 };
1547 1640
1548 let mut processed_rows = 0usize;1641 let mut processed_rows = 0usize;
1549 let mut processed_cols = 0usize;1642 let mut processed_cols = 0usize;
1550- let found_above = mi_row > 01643+ let found_above = max_row_offset.unsigned_abs() >= 1
1551 && scan_row_compound(1644 && scan_row_compound(
1552 grid,1645 grid,
1553 mi_row,1646 mi_row,
@@ -1561,7 +1654,7 @@ pub fn find_mv_stack_compound(
1561 &mut newmv_count,1654 &mut newmv_count,
1562 &mut processed_rows,1655 &mut processed_rows,
1563 );1656 );
1564- let found_left = mi_col > 01657+ let found_left = max_col_offset.unsigned_abs() >= 1
1565 && scan_col_compound(1658 && scan_col_compound(
1566 grid,1659 grid,
1567 mi_row,1660 mi_row,
@@ -1802,7 +1895,8 @@ pub fn find_mv_stack_compound(
1802 // bump) — otherwise append `comp_list[0]` as a brand-new entry. When1895 // bump) — otherwise append `comp_list[0]` as a brand-new entry. When
1803 // the stack is empty, both `comp_list[0]` and `comp_list[1]` are1896 // the stack is empty, both `comp_list[0]` and `comp_list[1]` are
1804 // appended unconditionally, with no dedup check at all.1897 // appended unconditionally, with no dedup check at all.
1805- let comp_list = combine_compound_candidates(&lists);1898+ let comp_list =
1899+ combine_compound_candidates(&lists, [gm_mv(gm, ref_frame.0), gm_mv(gm, ref_frame.1)]);
1806 if candidates.len() == 1 {1900 if candidates.len() == 1 {
1807 let (mv0, mv1) = if comp_list[0] == (candidates[0].mv0, candidates[0].mv1) {1901 let (mv0, mv1) = if comp_list[0] == (candidates[0].mv0, candidates[0].mv1) {
1808 comp_list[1]1902 comp_list[1]
@@ -2824,7 +2918,7 @@ mod tests {
2824 // side 1 has only one entry -> comp_idx 1 falls back to ref_diff.2918 // side 1 has only one entry -> comp_idx 1 falls back to ref_diff.
2825 lists.ref_diff[1].push((4, 4));2919 lists.ref_diff[1].push((4, 4));
2826 2920
2827- let combined = combine_compound_candidates(&lists);2921+ let combined = combine_compound_candidates(&lists, [(0, 0), (0, 0)]);
2828 assert_eq!(combined[0], ((1, 1), (3, 3)));2922 assert_eq!(combined[0], ((1, 1), (3, 3)));
2829 assert_eq!(combined[1], ((2, 2), (4, 4)));2923 assert_eq!(combined[1], ((2, 2), (4, 4)));
2830 }2924 }
@@ -2911,4 +3005,91 @@ mod tests {
2911 assert_eq!(stack.entries[1].mv0, (-3, -3));3005 assert_eq!(stack.entries[1].mv0, (-3, -3));
2912 assert_eq!(stack.entries[1].mv1, (7, 7));3006 assert_eq!(stack.entries[1].mv1, (7, 7));
2913 }3007 }
3008+
3009+ /// lane-mvtwin r1, defect 1 (twin drift, compound only): libaom fills a
3010+ /// `comp_list` slot past both `ref_id`/`ref_diff` lists with THAT SIDE's
3011+ /// own `gm_mv_candidates[idx]` (mvref_common.c:718-719). This module
3012+ /// filled it with `(0, 0)`, which is only accidentally right while every
3013+ /// live reference's global motion is IDENTITY -- the single-ref twin had
3014+ /// already closed the same gap on its own `mv_ref_list` tail in r6.
3015+ #[test]
3016+ fn a_missing_compound_combine_slot_takes_that_sides_global_mv_not_zero() {
3017+ let lists = CompoundRefLists::default();
3018+ let combined = combine_compound_candidates(&lists, [(9, -5), (-11, 3)]);
3019+ assert_eq!(combined[0], ((9, -5), (-11, 3)));
3020+ assert_eq!(combined[1], ((9, -5), (-11, 3)));
3021+ // One side supplied, the other short: only the short side falls back.
3022+ let mut half = CompoundRefLists::default();
3023+ half.ref_id[0].push((1, 2));
3024+ let combined = combine_compound_candidates(&half, [(9, -5), (-11, 3)]);
3025+ assert_eq!(combined[0], ((1, 2), (-11, 3)));
3026+ assert_eq!(combined[1], ((9, -5), (-11, 3)));
3027+ }
3028+
3029+ /// lane-mvtwin r1, defect 2 (both twins): libaom drops the 9th distinct
3030+ /// candidate AT INSERTION (`*refmv_count < MAX_REF_MV_STACK_SIZE`,
3031+ /// mvref_common.c:100/128/388/425). Pushing everything and truncating
3032+ /// after the weight sort keeps a different set: here the heavy 9th
3033+ /// candidate would survive and evict a scanned one.
3034+ #[test]
3035+ fn the_ninth_distinct_candidate_is_dropped_at_insertion_not_after_sorting() {
3036+ let mut candidates = Vec::new();
3037+ for i in 0..MAX_STACK_SIZE as i32 {
3038+ add_candidate(&mut candidates, (i, i), 2);
3039+ }
3040+ let before = stack_full_drops();
3041+ add_candidate(&mut candidates, (99, 99), 10_000);
3042+ assert_eq!(candidates.len(), MAX_STACK_SIZE);
3043+ assert!(!candidates.iter().any(|e| e.mv == (99, 99)));
3044+ assert_eq!(stack_full_drops(), before + 1);
3045+ // A full stack still takes the dedup weight bump libaom applies
3046+ // before the cap check.
3047+ add_candidate(&mut candidates, (0, 0), 6);
3048+ assert_eq!(candidates[0].weight, 8);
3049+
3050+ let mut comp = Vec::new();
3051+ for i in 0..MAX_STACK_SIZE as i32 {
3052+ add_compound_candidate(&mut comp, (i, i), (i, -i), 2);
3053+ }
3054+ add_compound_candidate(&mut comp, (99, 99), (99, 99), 10_000);
3055+ assert_eq!(comp.len(), MAX_STACK_SIZE);
3056+ }
3057+
3058+ /// lane-mvtwin r1, defect 3 (both twins): the row/col reach is clamped to
3059+ /// the TILE origin (`find_valid_row_offset`, mvref_common.c:512-528), not
3060+ /// the frame edge. `MiGrid::get` already hides the out-of-tile cells, so
3061+ /// the only visible symptom is the scan WEIGHT (`inc`) -- and through it
3062+ /// the stack order. Query at mi_row 9 with the tile starting at row 8:
3063+ /// the real reach is -1, so `inc = 1` and the weight stays at the floor
3064+ /// 2; the frame-edge clamp gave -6, `inc = min(6, size_h) = 4`, doubling
3065+ /// the vote.
3066+ #[test]
3067+ fn the_row_reach_is_clamped_to_the_tile_origin_not_the_frame_edge() {
3068+ let weight_with_tile_origin = |row0: usize| {
3069+ // A neighbour at least as wide as the query block (`bw4 <= n4`)
3070+ // is what makes libaom compute `inc` at all.
3071+ let wide = MiInfo {
3072+ size: 4,
3073+ size_h: 4,
3074+ ..inter((5, 5))
3075+ };
3076+ let mut grid = MiGrid::new(16, 16);
3077+ grid.set(8, 4, wide);
3078+ grid.set(8, 6, wide);
3079+ grid.set_tile_bounds(row0, 0, 16, 16);
3080+ let stack = find_mv_stack(&grid, 9, 4, 2, 2, LAST_FRAME, 16, 16);
3081+ assert_eq!(stack.entries.len(), 1);
3082+ stack.entries[0].weight
3083+ };
3084+ let tiled = weight_with_tile_origin(8);
3085+ let whole_frame = weight_with_tile_origin(0);
3086+ // One scanned row cell (`end_mi == bw4 == 2`, `len == 2`) plus the
3087+ // top-right probe's own flat `CORNER_WEIGHT`, which the reach never
3088+ // touches -- so the whole delta below is the row scan's `inc`.
3089+ // reach -1 -> inc 1 -> weight stays at the floor 2.
3090+ assert_eq!(tiled, REF_CAT_LEVEL + 2 * 2 + CORNER_WEIGHT);
3091+ // frame-edge clamp: reach -6 -> inc min(6, size_h) = 4.
3092+ assert_eq!(whole_frame, REF_CAT_LEVEL + 2 * 4 + CORNER_WEIGHT);
3093+ assert_ne!(tiled, whole_frame);
3094+ }
2914 }3095 }
crates/ec-av1/src/stream.rsmodified+514 -0
@@ -2972,6 +2972,64 @@ mod tests {
2972 assert_eq!(frames[0].u, ffmpeg_frames[0].u, "{NAME}: U vs ffmpeg");2972 assert_eq!(frames[0].u, ffmpeg_frames[0].u, "{NAME}: U vs ffmpeg");
2973 assert_eq!(frames[0].v, ffmpeg_frames[0].v, "{NAME}: V vs ffmpeg");2973 assert_eq!(frames[0].v, ffmpeg_frames[0].v, "{NAME}: V vs ffmpeg");
2974 }2974 }
2975+ /// lane-reelckf r2: `crates/ec-av1/fixtures/reelc_kf2700.obu` is a 1920x792
2976+ /// 10-bit AV1 key frame taken out of one of the user's own films
2977+ /// (`ffmpeg -ss 2700 -c:v copy -f obu`, then truncated to its first temporal
2978+ /// unit, 36 kB) -- the ONLY stream in this repo that contains a SKIPPED
2979+ /// `UV_CFL_PRED` block. 30 aomenc recipes (r1's 20 plus r2's chroma-correlated
2980+ /// `geq` sweep, cq 40..63, cpu-used 0..2, min/max-partition 4..64, 8 and
2981+ /// 10 bit) never made the encoder pick one, so the counter can only be
2982+ /// hard-asserted against a real film frame. The instrumented oracle agrees:
2983+ /// `EC_TRACE_MODE=1 aomdec` prints 5 `EC_IMODE_VAL ... uv_mode=13 skip=1`
2984+ /// lines for this frame.
2985+ ///
2986+ /// The defect it pins (fixed at 29cd53f, `decode.rs:7719`/`:10528`/`:10891`):
2987+ /// a skipped intra block must still PREDICT with CfL -- libaom's
2988+ /// `predict_and_reconstruct_intra_block` predicts every plane and guards only
2989+ /// the residual on `skip_txfm`. Before the fix this frame had 499 wrong
2990+ /// chroma samples (U rows 48..79 cols 464..492); after it, zero.
2991+ ///
2992+ /// The ffmpeg reference is `ffmpeg -f obu -i <fixture> -f rawvideo
2993+ /// -pix_fmt yuv420p10le -` (what `ffmpeg_decode_sequence_10bit` runs).
2994+ #[test]
2995+ fn a_real_film_key_frame_with_a_skipped_cfl_block_decodes_pixel_exact() {
2996+ const NAME: &str = "a_real_film_key_frame_with_a_skipped_cfl_block_decodes_pixel_exact";
2997+ let path =
2998+ std::path::Path::new(env!("CARGO_MANIFEST_DIR")).join("fixtures/reelc_kf2700.obu");
2999+ let stream = std::fs::read(&path)
3000+ .unwrap_or_else(|e| panic!("{NAME}: reading {}: {e}", path.display()));
3001+ let (width, height) = (1920usize, 792usize);
3002+ let before = crate::decode::reelc_chroma_counters();
3003+ let frames = match decode_stream(&stream) {
3004+ Ok(frames) => frames,
3005+ Err(e) => panic!("{NAME}: decode_stream refused: {e}"),
3006+ };
3007+ let after = crate::decode::reelc_chroma_counters();
3008+ let skip_cfl = after.0 - before.0;
3009+ assert_eq!(frames.len(), 1, "{NAME}: one key frame");
3010+ assert_eq!((frames[0].width, frames[0].height), (width, height));
3011+ // Asserted before the ffmpeg compare so an absent ffmpeg cannot make the
3012+ // gate vacuous: the skipped-CfL path is exercised on every run.
3013+ assert!(
3014+ skip_cfl > 0,
3015+ "{NAME}: zero skipped-CfL blocks -- the fixture no longer exercises defect 1"
3016+ );
3017+ if !have_ffmpeg() {
3018+ eprintln!("SKIP {NAME} pixel compare: no ffmpeg (skipped_cfl={skip_cfl})");
3019+ return;
3020+ }
3021+ let ffmpeg_frames = ffmpeg_decode_sequence_10bit(&stream, width, height, 1);
3022+ assert_eq!(frames[0].y, ffmpeg_frames[0].y, "{NAME}: luma vs ffmpeg");
3023+ assert_eq!(
3024+ frames[0].u, ffmpeg_frames[0].u,
3025+ "{NAME}: U vs ffmpeg ({skip_cfl} skipped-CfL blocks)"
3026+ );
3027+ assert_eq!(
3028+ frames[0].v, ffmpeg_frames[0].v,
3029+ "{NAME}: V vs ffmpeg ({skip_cfl} skipped-CfL blocks)"
3030+ );
3031+ eprintln!("{NAME}: pixel-exact, skipped_cfl={skip_cfl}");
3032+ }
2975 3033
2976 /// lane-hbd10 r1: a real `aomenc --bit-depth=10 --superres-mode=13034 /// lane-hbd10 r1: a real `aomenc --bit-depth=10 --superres-mode=1
2977 /// --superres-denominator=12` key frame, decoded pixel-exact against3035 /// --superres-denominator=12` key frame, decoded pixel-exact against
@@ -11441,6 +11499,169 @@ mod tests {
11441 );11499 );
11442 }11500 }
11443 11501
11502+ /// lane-reelckf r1: ReelC's key frames decoded with no refusal and WRONG
11503+ /// CHROMA (luma bit-exact at every one of ten seek points), from two
11504+ /// defects this gate pins:
11505+ ///
11506+ /// 1. a SKIPPED intra block whose `uv_mode` is `UV_CFL_PRED` still
11507+ /// predicts with the CfL term -- libaom
11508+ /// `predict_and_reconstruct_intra_block` (decodeframe.c) calls
11509+ /// `av1_predict_intra_block_facade` unconditionally and only guards
11510+ /// the residual on `mbmi->skip_txfm`. Three skip arms (the 16x16-level
11511+ /// 1:4 chroma pair and the two sub-8x8 4x4 groups) dropped it.
11512+ /// 2. the chroma intra-edge FILTER TYPE of a 1:4 pair comes from the
11513+ /// CHROMA REFERENCE position (libaom `get_intra_edge_filter_type` ->
11514+ /// `chroma_above_mbmi`/`chroma_left_mbmi`), not from the closing
11515+ /// strip: at the closing strip the above cell is the pair's own first
11516+ /// strip, the mi-exact UV map misses and the coarse fallback answers,
11517+ /// which flipped `av1_use_intra_edge_upsample` (blk_wh 12 <= 16 for
11518+ /// type 0, no upsample for type 1) and moved directional chroma by
11519+ /// +-1..3.
11520+ ///
11521+ /// Recipe is a real `aomenc --sb-size=128 --cpu-used=0` (the shape ReelC
11522+ /// uses) with 1:4 partitions and CfL on, both bit depths, and both
11523+ /// counters hard-asserted per compared attempt.
11524+ #[test]
11525+ fn a_real_aomenc_sb128_stream_whose_skipped_cfl_and_1to4_chroma_pairs_decode_pixel_exact() {
11526+ const NAME: &str =
11527+ "a_real_aomenc_sb128_stream_whose_skipped_cfl_and_1to4_chroma_pairs_decode_pixel_exact";
11528+ let _gate_lock = lock_gate_counters();
11529+ if !have_ffmpeg() {
11530+ eprintln!("SKIP {NAME}: no ffmpeg");
11531+ return;
11532+ }
11533+ if !have_aomenc() {
11534+ eprintln!("SKIP {NAME}: no aomenc at {}", aomenc_path().display());
11535+ return;
11536+ }
11537+ let mut compared = 0usize;
11538+ let (width, height) = (256usize, 256usize);
11539+ for depth in [8usize, 10] {
11540+ let pix = if depth == 10 { "yuv420p10le" } else { "yuv420p" };
11541+ let y4m = Command::new("ffmpeg")
11542+ .args([
11543+ "-v", "error", "-f", "lavfi", "-i",
11544+ &format!(
11545+ "mandelbrot=size={width}x{height},\
11546+ noise=alls=20:allf=t+u:all_seed=7"
11547+ ),
11548+ "-pix_fmt", pix, "-strict", "-1", "-t", "1", "-vframes", "1",
11549+ "-f", "yuv4mpegpipe", "-",
11550+ ])
11551+ .stdin(Stdio::null())
11552+ .stdout(Stdio::piped())
11553+ .stderr(Stdio::piped())
11554+ .output()
11555+ .expect("ffmpeg failed to run");
11556+ assert!(
11557+ y4m.status.success(),
11558+ "{NAME}: ffmpeg fixture (depth={depth}): {}",
11559+ String::from_utf8_lossy(&y4m.stderr)
11560+ );
11561+ let encode = || {
11562+ let mut child = Command::new(aomenc_path())
11563+ .args([
11564+ "--codec=av1", "--passes=1", "--end-usage=q", "--cq-level=52",
11565+ "--cpu-used=0", "--threads=1", "--row-mt=0", "--sb-size=128",
11566+ "--kf-max-dist=0", "--enable-rect-partitions=1",
11567+ "--enable-ab-partitions=0", "--enable-1to4-partitions=1",
11568+ "--enable-cfl-intra=1", "--enable-tx-size-search=0",
11569+ "--enable-filter-intra=0", "--enable-intra-edge-filter=1",
11570+ "--reduced-tx-type-set=1", "--min-partition-size=4",
11571+ "--max-partition-size=32",
11572+ &format!("--input-bit-depth={depth}"),
11573+ &format!("--bit-depth={depth}"),
11574+ "--obu", "-o", "-", "-",
11575+ ])
11576+ .stdin(Stdio::piped())
11577+ .stdout(Stdio::piped())
11578+ .stderr(Stdio::piped())
11579+ .spawn()
11580+ .expect("aomenc failed to start");
11581+ child
11582+ .stdin
11583+ .take()
11584+ .expect("aomenc stdin")
11585+ .write_all(&y4m.stdout)
11586+ .expect("writing y4m to aomenc");
11587+ let out = child.wait_with_output().expect("aomenc failed to run");
11588+ assert!(
11589+ out.status.success(),
11590+ "aomenc refused the fixture (depth={depth}): {}",
11591+ String::from_utf8_lossy(&out.stderr)
11592+ );
11593+ out.stdout
11594+ };
11595+ let stream = encode();
11596+ assert_eq!(
11597+ stream,
11598+ encode(),
11599+ "{NAME}: aomenc output is not reproducible (depth={depth})"
11600+ );
11601+ let before = crate::decode::reelc_chroma_counters();
11602+ let frames = match decode_stream(&stream) {
11603+ Ok(frames) => frames,
11604+ Err(e) => {
11605+ let msg = e.to_string();
11606+ assert!(
11607+ msg.contains("unsupported"),
11608+ "{NAME}: decode failed (depth={depth}): {msg}"
11609+ );
11610+ eprintln!("{NAME}: depth={depth} arm refused (not compared): {msg}");
11611+ continue;
11612+ }
11613+ };
11614+ compared += 1;
11615+ // Counters read only on an attempt that decoded AND is compared.
11616+ let after = crate::decode::reelc_chroma_counters();
11617+ let (skip_cfl, dir_pairs) = (after.0 - before.0, after.1 - before.1);
11618+ let ffmpeg_frames = if depth == 10 {
11619+ ffmpeg_decode_sequence_10bit(&stream, width, height, frames.len())
11620+ } else {
11621+ ffmpeg_decode_sequence(&stream, width, height, frames.len())
11622+ };
11623+ assert_eq!(ffmpeg_frames.len(), frames.len(), "{NAME}: ffmpeg frame count");
11624+ for (i, (got, want)) in frames.iter().zip(&ffmpeg_frames).enumerate() {
11625+ assert_eq!(got.y, want.y, "{NAME} frame {i} luma (depth={depth})");
11626+ assert_eq!(
11627+ got.u, want.u,
11628+ "{NAME} frame {i} U (depth={depth}, {skip_cfl} skipped-CfL blocks, \
11629+ {dir_pairs} directional 1:4 chroma pairs)"
11630+ );
11631+ assert_eq!(
11632+ got.v, want.v,
11633+ "{NAME} frame {i} V (depth={depth}, {skip_cfl} skipped-CfL blocks, \
11634+ {dir_pairs} directional 1:4 chroma pairs)"
11635+ );
11636+ }
11637+ // Defect 1 (skipped `UV_CFL_PRED`) is NOT asserted here: 20 aomenc
11638+ // recipes (cq 40..63, 9 lavfi sources, min/max-partition 4..64,
11639+ // both `--sb-size=128` and 64) never made the encoder pick a
11640+ // skipped 1:4 / sub-8x8 CfL block, so an assert would only ever
11641+ // fire on his real film. Its evidence is ReelC's own key frames
11642+ // (lanes/reelckf-r1.report.md): ss=2700 went 499 wrong chroma
11643+ // samples -> 0 on this fix alone. The count is printed so a future
11644+ // recipe that does reach it is visible immediately. r2 pinned that
11645+ // film frame as a fixture instead:
11646+ // `a_real_film_key_frame_with_a_skipped_cfl_block_decodes_pixel_exact`
11647+ // hard-asserts the counter.
11648+ assert!(
11649+ dir_pairs > 0,
11650+ "{NAME}: no directional 1:4 chroma pair decoded (depth={depth}) -- defect 2 \
11651+ is not exercised"
11652+ );
11653+ eprintln!(
11654+ "{NAME}: pixel-exact at {depth}-bit over {} frames, skipped_cfl={skip_cfl} \
11655+ directional_1to4_chroma_pairs={dir_pairs}",
11656+ frames.len()
11657+ );
11658+ }
11659+ assert!(
11660+ compared > 0,
11661+ "{NAME}: every arm refused -- the gate compared no pixels at all"
11662+ );
11663+ }
11664+
11444 /// lane-ab16 r1: real `aomenc --enable-ab-partitions=1` streams whose11665 /// lane-ab16 r1: real `aomenc --enable-ab-partitions=1` streams whose
11445 /// 16x16 blocks are split T-shaped (`PARTITION_HORZ_A`/`_HORZ_B`/11666 /// 16x16 blocks are split T-shaped (`PARTITION_HORZ_A`/`_HORZ_B`/
11446 /// `_VERT_A`/`_VERT_B`: two 8x8 squares plus one 16x8/8x16 strip), the11667 /// `_VERT_A`/`_VERT_B`: two 8x8 squares plus one 16x8/8x16 strip), the
@@ -14395,6 +14616,299 @@ mod tests {
14395 a_real_aomenc_temporal_mv_gate(42, 40);14616 a_real_aomenc_temporal_mv_gate(42, 40);
14396 }14617 }
14397 14618
14619+ /// lane-mvtwin r1: the COMPOUND MV-stack gate. Every other compound gate
14620+ /// here pins `--enable-ref-frame-mvs=0`, so `find_mv_stack_compound`'s
14621+ /// temporal half (the three `tpl_sample_pos` extension samples lane-sb128
14622+ /// r3 found missing) and its extension pass have never been exercised by
14623+ /// a real encoder. This arm turns ref-frame-mvs ON, gives the encoder a
14624+ /// 25-frame lookahead plus alt-refs so `reference_select` really drives
14625+ /// blocks to COMPOUND_REFERENCE, and sweeps global motion off/on so the
14626+ /// combine step's `gm_mv_candidates` fill (r1 defect 1) is reachable.
14627+ ///
14628+ /// Firing proof, hard-asserted: `decode::comp_mode_hits` (a real
14629+ /// compound block) AND `mvstack::tmv_hits` (a temporal candidate landed
14630+ /// in some stack) must BOTH have advanced on an attempt that also
14631+ /// decoded pixel-exact -- class [[gate-skips-on-its-own-failure]]: a
14632+ /// decode that succeeds is ALWAYS compared, on every decode-order frame,
14633+ /// and only the counters decide whether the attempt counts.
14634+ fn a_real_aomenc_compound_mv_stack_gate(
14635+ gate_name: &str,
14636+ seed_base: u32,
14637+ attempts: u32,
14638+ bit_depth: u32,
14639+ sb_size: u32,
14640+ global_motion: u32,
14641+ width: usize,
14642+ tile_columns: u32,
14643+ ) {
14644+ let _gate_lock = lock_gate_counters();
14645+ if !have_ffmpeg() {
14646+ eprintln!("SKIP {gate_name}: no ffmpeg");
14647+ return;
14648+ }
14649+ if !have_aomenc() {
14650+ eprintln!("SKIP {gate_name}: no aomenc at {}", aomenc_path().display());
14651+ return;
14652+ }
14653+ let (height, frame_count) = (64usize, 16usize);
14654+ let mut never_fired = 0u32;
14655+ let mut refusals = Vec::new();
14656+ for attempt in 0..attempts {
14657+ let seed = seed_base + attempt;
14658+ let duration = frame_count as f64 / 25.0;
14659+ let source =
14660+ gradients_source(seed, width, height, &format!("duration={duration}:rate=25"));
14661+ let y4m = Command::new("ffmpeg")
14662+ .args([
14663+ "-v",
14664+ "error",
14665+ "-f",
14666+ "lavfi",
14667+ "-i",
14668+ &source,
14669+ "-pix_fmt",
14670+ if bit_depth == 10 { "yuv420p10le" } else { "yuv420p" },
14671+ "-strict",
14672+ "-1",
14673+ "-t",
14674+ "0.64",
14675+ "-f",
14676+ "yuv4mpegpipe",
14677+ "-strict",
14678+ "-1",
14679+ "-",
14680+ ])
14681+ .stdin(Stdio::null())
14682+ .stdout(Stdio::piped())
14683+ .stderr(Stdio::piped())
14684+ .output()
14685+ .expect("ffmpeg failed to run");
14686+ assert!(
14687+ y4m.status.success(),
14688+ "ffmpeg fixture: {}",
14689+ String::from_utf8_lossy(&y4m.stderr)
14690+ );
14691+ let depth_args: &[&str] = if bit_depth == 10 {
14692+ &["-b", "10", "--input-bit-depth=10"]
14693+ } else {
14694+ &[]
14695+ };
14696+ // The cq sweep: how finely RD partitions decides how often a
14697+ // block's stack comes up short enough to reach the extension
14698+ // pass at all.
14699+ let cq = format!("--cq-level={}", [45u32, 55, 35][(attempt % 3) as usize]);
14700+ let sb = format!("--sb-size={sb_size}");
14701+ let gm = format!("--enable-global-motion={global_motion}");
14702+ // `--tile-columns` is log2: 1 means two tile columns, which is
14703+ // what makes every block in the right-hand tile carry a nonzero
14704+ // `tile_col0` and so exercise r1 defect 3's reach clamp.
14705+ let tiles = format!("--tile-columns={tile_columns}");
14706+ // class [[aomenc-last-flag-wins]]: every flag appears exactly
14707+ // once below, so there is no override to order.
14708+ let out = {
14709+ let mut child = Command::new(aomenc_path())
14710+ .args(depth_args)
14711+ .arg(&cq)
14712+ .arg(&sb)
14713+ .arg(&gm)
14714+ .arg(&tiles)
14715+ .args([
14716+ "--codec=av1",
14717+ "--passes=1",
14718+ "--end-usage=q",
14719+ "--cpu-used=0",
14720+ "--kf-max-dist=1000",
14721+ "--threads=1",
14722+ "--row-mt=0",
14723+ // What this gate is about: real compound references
14724+ // with a real temporal MV field behind them.
14725+ "--enable-ref-frame-mvs=1",
14726+ "--enable-order-hint=1",
14727+ "--auto-alt-ref=1",
14728+ "--lag-in-frames=25",
14729+ "--enable-fwd-kf=0",
14730+ "--enable-warped-motion=0",
14731+ "--enable-obmc=0",
14732+ "--enable-masked-comp=0",
14733+ "--enable-interintra-comp=0",
14734+ "--enable-dist-wtd-comp=0",
14735+ "--enable-diff-wtd-comp=0",
14736+ "--enable-onesided-comp=0",
14737+ "--enable-interintra-wedge=0",
14738+ "--enable-smooth-interintra=0",
14739+ "--enable-rect-partitions=0",
14740+ "--enable-ab-partitions=0",
14741+ "--enable-1to4-partitions=0",
14742+ "--enable-filter-intra=0",
14743+ "--enable-smooth-intra=0",
14744+ "--enable-paeth-intra=0",
14745+ "--enable-directional-intra=0",
14746+ "--enable-angle-delta=0",
14747+ "--enable-tx-size-search=0",
14748+ "--enable-cdef=0",
14749+ "--enable-restoration=0",
14750+ "--max-partition-size=32",
14751+ "--min-partition-size=32",
14752+ "--enable-palette=0",
14753+ "--enable-intrabc=0",
14754+ "--enable-cfl-intra=0",
14755+ "--obu",
14756+ "-o",
14757+ "-",
14758+ "-",
14759+ ])
14760+ .stdin(Stdio::piped())
14761+ .stdout(Stdio::piped())
14762+ .stderr(Stdio::piped())
14763+ .spawn()
14764+ .expect("aomenc failed to start");
14765+ child
14766+ .stdin
14767+ .take()
14768+ .expect("aomenc stdin")
14769+ .write_all(&y4m.stdout)
14770+ .expect("writing y4m to aomenc");
14771+ child.wait_with_output().expect("aomenc failed to run")
14772+ };
14773+ assert!(
14774+ out.status.success(),
14775+ "aomenc refused the fixture: {}",
14776+ String::from_utf8_lossy(&out.stderr)
14777+ );
14778+ let stream = out.stdout;
14779+ let (before_comp, before_tmv) = (decode::comp_mode_hits(), decode::tmv_hits());
14780+ let frames = match decode_stream(&stream) {
14781+ Err(e) => {
14782+ let msg = e.to_string();
14783+ assert!(
14784+ msg.contains("unsupported"),
14785+ "{gate_name} failed outright (seed {seed}): {msg}"
14786+ );
14787+ refusals.push(format!("seed {seed}: {msg}"));
14788+ continue;
14789+ }
14790+ Ok(frames) => frames,
14791+ };
14792+ let counted =
14793+ decode::comp_mode_hits() != before_comp && decode::tmv_hits() != before_tmv;
14794+ if !counted {
14795+ never_fired += 1;
14796+ }
14797+ let ffmpeg_frames = if bit_depth == 10 {
14798+ ffmpeg_decode_sequence_10bit(&stream, width, height, frame_count)
14799+ } else {
14800+ ffmpeg_decode_sequence(&stream, width, height, frame_count)
14801+ };
14802+ assert_eq!(frames.len(), frame_count);
14803+ // EVERY decode-order frame compared, never just the shown ones
14804+ // (class [[gate-blind-to-hidden-frames]]).
14805+ for (i, (got, want)) in frames.iter().zip(&ffmpeg_frames).enumerate() {
14806+ assert_eq!(
14807+ got.y, want.y,
14808+ "{gate_name} frame {i} luma vs ffmpeg (seed {seed})"
14809+ );
14810+ assert_eq!(
14811+ got.u, want.u,
14812+ "{gate_name} frame {i} U vs ffmpeg (seed {seed})"
14813+ );
14814+ assert_eq!(
14815+ got.v, want.v,
14816+ "{gate_name} frame {i} V vs ffmpeg (seed {seed})"
14817+ );
14818+ }
14819+ if counted {
14820+ eprintln!(
14821+ "{gate_name} FIRING seed {seed}: comp_mode_hits +{}, tmv_hits +{}, \
14822+ comp_gm_fill_hits={}, stack_full_drops={}, tile_reach_clips={}",
14823+ decode::comp_mode_hits() - before_comp,
14824+ decode::tmv_hits() - before_tmv,
14825+ crate::mvstack::comp_gm_fill_hits(),
14826+ crate::mvstack::stack_full_drops(),
14827+ crate::mvstack::tile_reach_clips(),
14828+ );
14829+ gate_buckets(gate_name, 1, never_fired, refusals.len());
14830+ return;
14831+ }
14832+ }
14833+ gate_buckets(gate_name, 0, never_fired, refusals.len());
14834+ eprintln!(
14835+ "SKIP {gate_name}: {never_fired} attempts decoded but never drove a compound block \
14836+ with a temporal MV candidate, and every other attempt hit a named refusal:\n{}",
14837+ refusals.join("\n")
14838+ );
14839+ }
14840+
14841+ #[test]
14842+ fn a_real_aomenc_compound_mv_stack_with_temporal_mvs_decodes_pixel_exact() {
14843+ a_real_aomenc_compound_mv_stack_gate(
14844+ "a_real_aomenc_compound_mv_stack_with_temporal_mvs_decodes_pixel_exact",
14845+ 42,
14846+ 30,
14847+ 8,
14848+ 64,
14849+ 0,
14850+ 64,
14851+ 0,
14852+ );
14853+ }
14854+
14855+ #[test]
14856+ fn a_real_aomenc_compound_mv_stack_with_global_motion_decodes_pixel_exact() {
14857+ a_real_aomenc_compound_mv_stack_gate(
14858+ "a_real_aomenc_compound_mv_stack_with_global_motion_decodes_pixel_exact",
14859+ 80,
14860+ 30,
14861+ 8,
14862+ 64,
14863+ 1,
14864+ 64,
14865+ 0,
14866+ );
14867+ }
14868+
14869+ #[test]
14870+ fn a_real_aomenc_10bit_compound_mv_stack_at_128_superblocks_decodes_pixel_exact() {
14871+ a_real_aomenc_compound_mv_stack_gate(
14872+ "a_real_aomenc_10bit_compound_mv_stack_at_128_superblocks_decodes_pixel_exact",
14873+ 120,
14874+ 30,
14875+ 10,
14876+ 128,
14877+ 1,
14878+ 64,
14879+ 0,
14880+ );
14881+ }
14882+
14883+ /// KNOWN OPEN DEFECT, found by lane-mvtwin r1 and NOT caused by it: a
14884+ /// real aomenc stream 128 px wide with `--tile-columns=1` (two 64-px tile
14885+ /// columns) mis-decodes frame 1's luma against ffmpeg, at seed 200 with
14886+ /// this exact recipe. ABLATION-PROVEN pre-existing: the same arm fails
14887+ /// identically with r1's tile-origin reach clamp
14888+ /// (`MiGrid::tile_origin`) forced back to `(0, 0)`, so the cause is
14889+ /// somewhere else in the multi-tile path, not in `mvstack`. Kept as the
14890+ /// exact reproducer for the lane that owns tiles -- it is `#[ignore]`d
14891+ /// rather than deleted so the repro command survives:
14892+ /// `cargo test -p ec-av1 --lib across_two_tile_columns -- --ignored --nocapture`.
14893+ ///
14894+ /// It is also the ONLY arm that reaches r1 defect 3 (the col reach is
14895+ /// clamped to `tile_col0`, not the frame edge): the counter
14896+ /// `mvstack::tile_reach_clips` advanced to 60 on this stream. Defect 3
14897+ /// itself is proven deterministically by
14898+ /// `mvstack::tests::the_row_reach_is_clamped_to_the_tile_origin_not_the_frame_edge`.
14899+ #[test]
14900+ #[ignore = "known pre-existing multi-tile-column decode defect, see doc comment"]
14901+ fn a_real_aomenc_compound_mv_stack_across_two_tile_columns_decodes_pixel_exact() {
14902+ let name = "a_real_aomenc_compound_mv_stack_across_two_tile_columns_decodes_pixel_exact";
14903+ let before = crate::mvstack::tile_reach_clips();
14904+ a_real_aomenc_compound_mv_stack_gate(name, 200, 30, 8, 64, 0, 128, 1);
14905+ assert!(
14906+ crate::mvstack::tile_reach_clips() > before,
14907+ "{name}: no block was ever built inside a tile past mi 0 -- \
14908+ --tile-columns=1 did not produce a second tile column"
14909+ );
14910+ }
14911+
14398 /// bisect scratch: decode a pinned stream exactly once -- generic14912 /// bisect scratch: decode a pinned stream exactly once -- generic
14399 /// pin-repro tool, kept for manual use.14913 /// pin-repro tool, kept for manual use.
14400 #[test]14914 #[test]
lanes/mvtwin-r1.report.mdadded+91 -0
@@ -0,0 +1,91 @@
1+# lane-mvtwin r1 — phase-by-phase diff of the two MV-stack twins vs libaom
2+
3+Base: lane-sb128 5ea5ec8, merged main 7a47fc1 (clean; the 128x128-superblock
4+refusal main re-added at b51719f stayed deleted — grep confirms).
5+Oracle: `~/.cache/aom-oracle/src/av1/common/mvref_common.c` (`setup_ref_mv_list`,
6+`av1_find_mv_refs`). Ours: `crates/ec-av1/src/mvstack.rs`
7+(`find_mv_stack_with_sign_bias` = single-ref twin, `find_mv_stack_compound` = compound twin).
8+
9+## The table (libaom line = mvref_common.c)
10+
11+| # | phase (libaom) | single-ref ours | compound ours | defect? |
12+|---|---|---|---|---|
13+| 1 | `row_adj`/`col_adj`, `find_valid_row/col_offset` reach (:502-533) | mvstack.rs:809 | mvstack.rs:1610 | **DEFECT 3** — both clamped the reach to the FRAME edge, libaom clamps to `tile->mi_row_start`/`mi_col_start` |
14+| 2 | `scan_row_mbmi` immediate, `len`/`weight`/`inc`/`processed_rows` (:141-190, :534-538) | `scan_row` :471 | `scan_row_compound` :1290 | exact (availability gate was `mi_row > 0`, folded into defect 3) |
15+| 3 | `scan_col_mbmi` (:192-236, :540-543) | `scan_col` :553 | `scan_col_compound` :1347 | exact |
16+| 4 | `has_top_right` + top-right `scan_blk_mbmi` (:264-312, :496, :544-548) | `scan_top_right` :645 | `scan_top_right_compound` :1403 | no change — see "has_tr" below |
17+| 5 | `nearest_match`, `REF_CAT_LEVEL` boost over `nearest_refmv_count` (:550-555) | :836 | :1600 | exact |
18+| 6 | `add_tpl_ref_mv` main loop, `step_h`/`step_w`/`blk_*_end` (:557-589) | :868 | :1625 | exact (compound reads the field once per side; `motion_field.rs:500` makes the lookup offset-independent, so both sides are Some/None together — libaom's single lookup) |
19+| 7 | `tpl_sample_pos` 3 extension samples + `check_sb_border` (:591-600, :316) | :898 | :1670 (added lane-sb128 r3) | exact — the twin drift r3 found, now symmetric |
20+| 8 | `GLOBALMV_OFFSET` / `zero_mv_ctx` far-or-missing test (:375-380, :406-412, :592) | :955 | :1750 | exact |
21+| 9 | corner `scan_blk_mbmi(-1,-1)` with `dummy_newmv_count`, weight `2*len`=4 (:604-607) | :967 | :1758 | exact |
22+| 10 | extended row/col scan `idx = 2..=MVREF_ROW_COLS` (:609-622) | :990 | :1770 | exact |
23+| 11 | `ref_match_count` + `mode_context` switch / `REFMV_OFFSET` (:624-651) | :1140 | :1858 | exact |
24+| 12 | the TWO bubble passes (nearest region, then the rest) (:653-682) | single stable `sort_by_key` :1050 | same :1802 | not a defect — every nearest entry carries `+REF_CAT_LEVEL` (640) and no post-boost entry can reach it (max post-boost weight seen is `len*weight` <= 80), so the two-phase ranking and one stable global sort agree |
25+| 13 | insertion cap `*refmv_count < MAX_REF_MV_STACK_SIZE` (:100, :128, :388, :425) | `add_candidate` :341 | `add_compound_candidate` :1268 | **DEFECT 2** — both pushed unbounded then sorted+truncated, keeping a different set than libaom's drop-at-insertion |
26+| 14 | `mi_size` = min(64x64 span, block span, frame edge) (:684-689) | :1060 | :1815 | exact |
27+| 15 | `process_compound_ref_mv_candidate`, sign-bias inversion, `can_rf > INTRA_FRAME` (:434-470, :693-706) | n/a | :1478 | exact |
28+| 16 | `comp_list` combine, slots past both lists = `gm_mv_candidates[idx]` (:708-720) | n/a | `combine_compound_candidates` :1520 | **DEFECT 1 (twin drift)** — filled `(0, 0)`; the single-ref twin closed the same gm-fallback gap in r6 |
29+| 17 | compound stack merge, `refmv_count==1` dedupe vs empty (:722-742) | n/a | :1845 | exact |
30+| 18 | `clamp_mv_ref` + `MV_BORDER`, every entry (:745-751, :768-772) | :1105 | :1878 | exact |
31+| 19 | single-ref extension gated per step on `MAX_MV_REF_CANDIDATES` (:754-766) | :1065 | n/a | exact |
32+| 20 | `mv_ref_list` tail filled with `gm_mv_candidates[0]`, unclamped (:775-782) | :1128 | n/a (libaom has no compound `mv_ref_list`) | exact |
33+
34+### has_tr (phase 4), why no change
35+Ours probes "is the grid cell at `(mi_row-1, mi_col+bw4)` populated", which for a
36+decoder is exactly "was it decoded". Walking libaom's mask logic: for SQUARE blocks
37+the mask result and "already decoded" coincide at both sb64 and sb128; for the
38+rect case that differs (`bs > 16` at a 64x128 block) libaom's own
39+`is_last_vertical_rect` refinement forces `has_tr = 1` again, agreeing with our
40+probe. Porting the mask WITHOUT the three shape refinements (which need the
41+partition type, not passed to this module) would REGRESS the VERT-rect case.
42+Recorded as the same corner-cut already documented at `mvstack.rs:588`;
43+upgrade path = thread the partition type in with the rect inter leaf.
44+
45+## Fixes (all in crates/ec-av1/src/mvstack.rs)
46+- D1 `combine_compound_candidates` (:1520 + call site :1859): unfilled slots take
47+ `gm_mv(gm, ref_frame.side)`, not `(0, 0)` (mvref_common.c:718-719).
48+- D2 `add_candidate` (:341) / `add_compound_candidate` (:1268): drop the 9th
49+ distinct candidate AT INSERTION (mvref_common.c:100/128/388/425); the dedup
50+ weight bump still applies on a full stack.
51+- D3 both twins (:809, :1610) + new `MiGrid::tile_origin` (:216): reach and
52+ availability are tile-relative (mvref_common.c:512-533).
53+
54+## Checks
55+`cargo test -p ec-av1 --lib mvstack::` -> 32 passed, 0 failed. Three new
56+deterministic tests, one per defect:
57+- `a_missing_compound_combine_slot_takes_that_sides_global_mv_not_zero`
58+- `the_ninth_distinct_candidate_is_dropped_at_insertion_not_after_sorting`
59+- `the_row_reach_is_clamped_to_the_tile_origin_not_the_frame_edge` (644 -> 648 vs 652)
60+
61+New real-aomenc gate `a_real_aomenc_compound_mv_stack_gate` (stream.rs), the first
62+compound gate here that does NOT pin `--enable-ref-frame-mvs=0`:
63+`--enable-ref-frame-mvs=1 --enable-order-hint=1 --auto-alt-ref=1 --lag-in-frames=25`,
64+cq sweep 45/55/35, 30 seeds/arm, hard-asserting BOTH `comp_mode_hits` and
65+`tmv_hits` advanced, every decode-order frame compared (Y/U/V) against ffmpeg,
66+decode errors only tolerated when the message contains "unsupported".
67+Arms: 8-bit sb64 gm=0 · 8-bit sb64 gm=1 · 10-bit sb128 gm=1.
68+
69+EVIDENCE: $HOME/.cache/mvtwin-suite-r1.log | cargo test -p ec-av1 --lib compound_mv_stack -- --test-threads=1 --nocapture | 3 arms FIRING pixel-exact: seed 44 comp_mode_hits +7 tmv_hits +56; seed 80 comp_mode_hits +1 tmv_hits +56; seed 122 (10-bit, sb128) comp_mode_hits +8 tmv_hits +55
70+EVIDENCE: crates/ec-av1/src/mvstack.rs tests | cargo test -p ec-av1 --lib mvstack:: | 32 passed 0 failed, each of the 3 defects asserted on its own values
71+
72+Full suite (systemd unit, MemoryMax=10G): `cargo test -p ec-av1 --lib -j3` ->
73+**375 passed, 0 failed, 33 ignored**, 692 s. Log `$HOME/.cache/mvtwin-suite-r1.log`.
74+
75+EVIDENCE: $HOME/.cache/mvtwin-suite-r1.log | systemd-run --user --unit=mvtwin-suite-... cargo test -p ec-av1 --lib -j3 | test result: ok. 375 passed; 0 failed; 33 ignored
76+
77+## Open residue
78+- fix-now-elsewhere (NOT this lane's surface): a real aomenc stream 128 px wide
79+ with `--tile-columns=1` MIS-DECODES frame 1 luma vs ffmpeg (seed 200, recipe in
80+ `a_real_aomenc_compound_mv_stack_across_two_tile_columns_decodes_pixel_exact`,
81+ `#[ignore]`d with the repro command in its doc). ABLATION-PROVEN pre-existing:
82+ identical failure with r1's tile-origin clamp forced back to `(0, 0)`. That arm
83+ is also the only one that reaches defect 3 on a real stream —
84+ `mvstack::tile_reach_clips` advanced to 60 there.
85+- deferred(a stream whose compound pair names a non-IDENTITY ROTZOOM/AFFINE
86+ reference) — `comp_gm_fill_hits` reads 0 on all three green arms, so D1 is
87+ proven by its unit test, not yet by a real stream. aomenc at gradients content
88+ keeps global motion IDENTITY even with `--enable-global-motion=1`.
89+- deferred(same) — `stack_full_drops` reads 0 on all three arms: no real block
90+ here produced 9 distinct candidates. D2 is unit-test-proven only.
91+- accepted — `has_tr` corner-cut (phase 4 above), ceiling and upgrade path named.
lanes/reelckf-r1.handoff.mdadded+100 -0
@@ -0,0 +1,100 @@
1+# lane-reelckf r1 handoff
2+
3+Tip: see `git log -2`. Base `lane-sb128b` e8e64a6. Both root causes FIXED and the
4+lane is GREEN on its own gate; the only thing still owed is the final full-suite
5+number (the unit was still running at the turn cap, 318/~404 tests logged, zero
6+`FAILED` lines so far). Log: `$HOME/.cache/reelckf-suite-r1.log`.
7+
8+## Method (reusable)
9+`$HOME/.cache/reelckf-work/one.sh <ss>` — extracts 2 s with `ffmpeg -ss <ss> -c:v copy
10+-f obu`, truncates to ONE frame with `trunc.py`, decodes under
11+`systemd-run --scope -p MemoryMax=6G` with `EC_PROBE_OUT16`, sha256s the output,
12+decodes the same truncated file with `ffmpeg -pix_fmt yuv420p10le`, and prints
13+per-plane diff count + first differing sample + bounding box.
14+`$HOME/.cache/reelckf-work/stage.sh <ss>` — the same file through
15+`EC_AV1_PREFILT_DUMP16` / `EC_AV1_POSTDEBLOCK_DUMP16` on BOTH decoders.
16+`$HOME/.cache/reelckf-work/sweep.sh <lavfi-src> <cq> <depth>` (env `MP=` for
17+max-partition) — aomenc recipe probe printing `reelc_chroma:` counters.
18+
19+## Per-key-frame findings (1920x792 10-bit AV1, 12 seek points)
20+
21+All measurements are of decode-order frame 0 of a 1-frame truncation.
22+
23+| ss | first differing sample (before) | extent | stage | verdict |
24+|----|--------------------------------|--------|-------|---------|
25+| 0 | none | — | — | exact before and after |
26+| 900 | U (r103,c304) | U rows 103..395 cols 304..479, V rows 99..383; luma exact | prefilter | fixed, now 0 |
27+| 1800 | U (r19,c538) | U rows 19..313 cols 311..732; luma exact | prefilter | fixed, now 0 |
28+| 2700 | U (r48,c468) | ONE 8x16-luma chroma pair, chroma rows 48..79 cols 464..492 | prefilter (467 diffs) vs postdeblock (499) — reconstruction, not a filter | fixed, now 0 |
29+| 3600 | U (r151,c469) | U rows 151..395 cols 468..959; luma exact | prefilter | fixed, now 0 |
30+| 4500 | none | — | — | exact before and after |
31+| 5400 | U (r164,c154) | U rows 164..168 cols 153..159 (one 8x4 chroma block) + V (r152,c278) | prefilter | fixed, now 0 |
32+| 6300 | U (r148,c545) | U rows 148..395; V rows 148..395 cols 84..903 | prefilter | fixed, now 0 |
33+| 7200 | U (r24,c561) | U rows 24..348 cols 210..959 | prefilter | fixed, now 0 |
34+| 9900 | U (r8,c500) | U rows 8..395 cols 497..959 | prefilter | fixed, now 0 |
35+| 8100 | frame 0 REFUSES (128-root non-SPLIT) | — | — | lane-sb128c owns it |
36+| 9000 | frame 0 REFUSES (128-root non-SPLIT) | — | — | lane-sb128c owns it |
37+
38+LUMA WAS BIT-EXACT IN EVERY ROW, before and after. That single fact exonerated
39+the entropy stream at the first measurement and is why no range ladder was ever
40+needed.
41+
42+## Blocks found, and the symbol/prediction comparison
43+
44+* ss=2700, chroma (48,468) = luma (96,936) = mi(24,234). aomdec `EC_TRACE_MODE`:
45+ `EC_IMODE mi_row=24 mi_col=232..235 bsize=16` — four `BLOCK_4X16`
46+ (`PARTITION_VERT_4`); `mi_col=235` is the chroma reference and prints
47+ `uv_mode=13 skip=1`. Our chroma there was plain DC.
48+* ss=5400, chroma (164,152) = luma (328,608) = mi(82,76). aomdec: `mi_row=80..83
49+ mi_col=76 bsize=17` (`BLOCK_16X4`, `PARTITION_HORZ_4`), chroma reference
50+ `mi_row=83`, `uv_mode=5` (D113). aomdec `EC_PRED mi_row=83 mi_col=76 plane=1
51+ txw=8 txh=4 mode=5 p_angle=107 have_top=1 have_left=1 n_top=8 n_left=4 ft=0`,
52+ `EC_PREDOUT row0=415,431,453,471,467,442,408,397`.
53+ Ours (`EC_PRED=1`, `OUR_PRED x=152 y=164 bw=8 bh=4 mode=5 ad=-2`):
54+ `row0=[415,431,452,470,466,441,409,398]` — prediction, not residual.
55+
56+## Fixes applied and their effect
57+1. `decode.rs:7719` + `:10528` + `:10891` — a skipped intra block still predicts
58+ with CfL (libaom `predict_and_reconstruct_intra_block` predicts every plane
59+ and guards only the residual on `skip_txfm`). ss=2700 499 -> 0.
60+2. `decode.rs:7714` — the 1:4 pair reads `smooth_uv_neighbour` at `pair_mi` (the
61+ chroma reference), not at the closing strip: libaom
62+ `get_intra_edge_filter_type` uses `chroma_above_mbmi`/`chroma_left_mbmi`. The
63+ wrong filter type flipped `av1_use_intra_edge_upsample` (`blk_wh = 8+4 = 12
64+ <= 16` upsamples for type 0, never for type 1). ss=5400 46 -> 0; every
65+ remaining seek point -> 0.
66+3. `gate_coverage.rs` — `enable-cfl-intra` retired from BOTH never-exercised
67+ lists, and `covers_both_depths` learned the `for depth in [8usize, 10]`
68+ spelling (a gate with a `yuv420p10le` arm was being classified 10-bit only).
69+
70+## Hypotheses RULED OUT (do not re-spend rounds on these)
71+* Entropy desync / wrong CDF row: luma bit-exact on all ten frames.
72+* CDEF / loop restoration / deblock at a 128 superblock (the charter's leading
73+ suspects): the prefilter dump already carries the whole defect (ss=2700
74+ prefilter 467 diffs, postdeblock 499) and luma is exact through every filter.
75+* `delta_q` / `delta_lf` read at the 128 root: a wrong plane qindex would move
76+ the residual, not the prediction, and would not leave luma exact.
77+* Intra edge availability at 128 (`has_tr_128x128`/`has_bl_128x128`): `Reach` is
78+ two booleans computed from luma geometry, which libaom reuses for chroma; the
79+ ss=5400 `EC_PRED` line agrees (`n_tr=-1 n_bl=-1`).
80+* `Reach::of_rect(pw, ph, ...)` being luma-scaled while the chroma block is half
81+ the size: checked, correct — libaom computes availability once, in luma mi.
82+
83+## Gate
84+`cargo test -p ec-av1 --lib a_real_aomenc_sb128_stream_whose_skipped_cfl -- --nocapture`
85+-> pixel-exact at 8-bit AND 10-bit, `directional_1to4_chroma_pairs=11` per arm,
86+`skipped_cfl=0`.
87+
88+## Exact next step for a successor
89+1. `grep -E "^test result|FAILED" $HOME/.cache/reelckf-suite-r1.log` — the suite
90+ was mid-run at the cap. If anything is red, it is a sibling of the two
91+ touched paths (grep `smooth_uv_neighbour` and `cfl_ac_q3`).
92+2. Defect 1 (skipped CfL) has NO synthetic gate. 20 aomenc recipes were swept
93+ (cq 40/44/46/50/52/55/58/62/63 x mandelbrot, blurred mandelbrot, noised
94+ mandelbrot, testsrc2, gradients, smptebars, cellauto, life, grey+noise;
95+ min-partition 4, max-partition 16/32/64, sb-size 128/64) and `skip_cfl`
96+ stayed 0 in every one. Either find a recipe that fires it (the counter is
97+ printed by the gate AND by `decode_probe`, so a hit is immediately visible)
98+ or commit a pinned single-frame stream fixture.
99+3. The two remaining ReelC seek points (8100, 9000) need lane-sb128c's 128-root
100+ non-SPLIT partition; re-run the 12-point table after that lands.
lanes/reelckf-r1.report.mdadded+99 -0
@@ -0,0 +1,99 @@
1+# lane-reelckf r1 — ReelC key frames: two chroma-only reconstruction defects
2+
3+Base: `lane-sb128b` e8e64a6 (= main 18bf7dc + the 128 NONE block fix).
4+
5+## Premise re-measured (not taken from the charter)
6+census4's `reelc4.tsv` was recorded on main 18bf7dc, where every ReelC segment
7+REFUSED. On this base all ten non-`sb128c` key frames decode with **no refusal**
8+and **luma bit-exact**, chroma wrong — which is what made the entropy stream an
9+exonerated suspect from the first measurement.
10+
11+## Root causes (both chroma, both cited to libaom)
12+
13+1. **A skipped intra block still predicts, and CfL is prediction.**
14+ libaom `predict_and_reconstruct_intra_block` (decodeframe.c) calls
15+ `av1_predict_intra_block_facade` unconditionally and guards only the
16+ residual on `mbmi->skip_txfm`. Three of our skip arms dropped the CfL term
17+ and predicted plain DC:
18+ - `crates/ec-av1/src/decode.rs:7719` — the 16x16-level 1:4 chroma pair
19+ (`decode_rect4_16`).
20+ - `crates/ec-av1/src/decode.rs:10528`, `:10891` — the two sub-8x8 4x4-group
21+ chroma arms.
22+ ReelC ss=2700: chroma-only bounded box at chroma (48..79, 464..492), the
23+ `VERT_4` pair at mi(24,234)/(24,235) — aomdec `EC_TRACE_MODE` prints
24+ `uv_mode=13 skip=1` there. 499 wrong samples -> **0**.
25+
26+2. **The 1:4 pair's chroma intra-edge FILTER TYPE is read at the chroma
27+ reference, not at the closing strip.**
28+ libaom `get_intra_edge_filter_type` (reconintra.c) reads
29+ `chroma_above_mbmi`/`chroma_left_mbmi`, i.e. the neighbours of the
30+ chroma-reference mi. We passed the closing strip's own mi, whose above cell
31+ is the pair's FIRST strip: the mi-exact UV map missed, the coarse 16px
32+ fallback answered, and the filter type flipped
33+ `av1_use_intra_edge_upsample` (`blk_wh = 8 + 4 = 12 <= 16` upsamples for
34+ type 0, never for type 1). `crates/ec-av1/src/decode.rs:7714`.
35+ ReelC ss=5400, the `HORZ_4` pair at mi(82,83)/76: aomdec
36+ `EC_PRED ... mode=5 p_angle=107 ft=0`, `EC_PREDOUT row0=415,431,453,471,...`
37+ vs our `OUR_PRED ... row0=[415,431,452,470,...]`. 46 wrong samples -> **0**.
38+
39+## Files changed
40+- `crates/ec-av1/src/decode.rs` — the three skip arms now pass the CfL term;
41+ the 1:4 pair's `smooth_uv_neighbour` is read at `pair_mi`; two new
42+ counters + `pub fn reelc_chroma_counters()`.
43+- `crates/ec-av1/src/stream.rs` — new gate
44+ `a_real_aomenc_sb128_stream_whose_skipped_cfl_and_1to4_chroma_pairs_decode_pixel_exact`.
45+- `crates/ec-av1/examples/decode_probe.rs` — prints `reelc_chroma:` counters.
46+
47+## Sweep for the same shape
48+`grep -n "u\.reconstruct\|v\.reconstruct\|buf\.reconstruct"` over decode.rs, then
49+every `if skip {` arm (21 sites) inspected: the square path (`:9416`), the rect
50+strip paths (`:6490`, `:6930`, `:7248`, `:8034`) and the inter paths already
51+computed `ac` inside their skip arm. The three fixed above were the only
52+chroma-CfL-dropping arms. All 11 `smooth_uv_neighbour` call sites checked: the
53+other ten pass a block/group ORIGIN mi (`leaf_mi`, `r*(SUB/MI)`), which already
54+is the chroma reference; only `decode_rect4_16` passed a non-origin mi.
55+
56+## Gate
57+`cargo test -p ec-av1 --lib a_real_aomenc_sb128_stream_whose_skipped_cfl -- --nocapture`
58+(real aomenc `--sb-size=128 --cpu-used=0 --enable-1to4-partitions=1
59+--enable-cfl-intra=1 --min-partition-size=4 --max-partition-size=32
60+--cq-level=52`, 256x256 `mandelbrot+noise(all_seed=7)`, 8- and 10-bit arms,
61+aomenc output hashed twice for reproducibility, decode error tolerated only if
62+the message contains "unsupported", `compared > 0` asserted).
63+
64+EVIDENCE: $HOME/.cache/reelckf-suite-r1.log (gate stdout quoted below) | cargo test ... --nocapture | pixel-exact at 8-bit and 10-bit, directional_1to4_chroma_pairs=11 per arm, skipped_cfl=0
65+
66+## ReelC key-frame table (1 frame per seek point, `EC_PROBE_OUT16` vs ffmpeg yuv420p10le)
67+
68+| ss | before (this base) | after |
69+|----|--------------------|-------|
70+| 0 | 0 | 0 |
71+| 900 | 4173 (U 3107 / V 1066, max 7) | **0** |
72+| 1800 | 14402 (max 10) | **0** |
73+| 2700 | 499 (max 3) | **0** |
74+| 3600 | 119652 (max 37) | **0** |
75+| 4500 | 0 | 0 |
76+| 5400 | 46 (max 4) | **0** |
77+| 6300 | 33742 (max 7) | **0** |
78+| 7200 | 52891 (max 11) | **0** |
79+| 9900 | 4131 (max 7) | **0** |
80+| 8100 | frame 0 refuses (128-root non-SPLIT) — lane-sb128c | unchanged |
81+| 9000 | frame 0 refuses (128-root non-SPLIT) — lane-sb128c | unchanged |
82+
83+Luma was bit-exact in every row, before and after.
84+
85+EVIDENCE: $HOME/.cache/reelckf-work/xo_*.raw vs xr_*.raw | ffmpeg -ss <t> -t 2 -c:v copy -f obu, trunc.py to 1 frame, decode_probe EC_PROBE_OUT16, ffmpeg -pix_fmt yuv420p10le | samples_diff 0/2280960 on all ten decodable key frames
86+
87+## Residue
88+- deferred(a lavfi/aomenc recipe or a committed stream fixture that fires a
89+ SKIPPED 1:4 or sub-8x8 CfL block) — defect 1 has no synthetic gate. 20 aomenc
90+ recipes were swept (cq 40/44/46/50/52/55/58/62/63 x mandelbrot, blurred
91+ mandelbrot, noised mandelbrot, testsrc2, gradients, smptebars, cellauto, life,
92+ grey+noise; min-partition 4, max-partition 16/32/64, sb-size 128) and
93+ `skip_cfl` stayed 0 in all of them. Its evidence is ReelC ss=2700 (499 -> 0)
94+ and the counter is printed by the gate and by `decode_probe`, so the first
95+ recipe that reaches it is visible.
96+- accepted — ss=8100 / ss=9000 still refuse inside frame 0 on the 128-root
97+ non-SPLIT partition; that refusal belongs to lane-sb128c.
98+- No refusal was lifted this round, so `refusal_inventory.rs` /
99+ `gate_coverage.rs` are unchanged.
lanes/reelckf-r2.handoff.mdadded+22 -0
@@ -0,0 +1,22 @@
1+# lane-reelckf r2 handoff
2+
3+SUPERSEDED: the suite finished after this file was written --
4+`test result: ok. 379 passed; 0 failed; 33 ignored` (1055 s). Nothing is owed.
5+Tip `f7e0d3d` at the time of writing; see `lanes/reelckf-r2.report.md`.
6+
7+* Log: `$HOME/.cache/reelckf-suite-r2.log`. Check with a single
8+ `grep -E "^test result|FAILED" $HOME/.cache/reelckf-suite-r2.log`.
9+ At the cap: ~200 of ~412 tests logged, **zero `FAILED` lines**.
10+ r1's run of the same suite on the pre-merge tree reached 361 tests with zero
11+ FAILED before I stopped it (superseded by this run); both film-grain gates
12+ (`a_real_aomenc_stream_with_film_grain_decodes_pixel_exact` and its 10-bit
13+ sibling) were `ok` there, so the cross-lane concurrency red did not appear.
14+* If anything is red, it is a sibling of the two touched paths: grep
15+ `smooth_uv_neighbour` and `cfl_ac_q3` in `crates/ec-av1/src/decode.rs`.
16+* Nothing else is owed. Merge of main 85887c7 is at 4667015 (clean auto-merge,
17+ cdf.rs untouched, no deletions).
18+* Reusable instruments: `$HOME/.cache/reelckf-work/one.sh <ss>` (per-seek-point
19+ film compare), `.../cflsweep.sh <tag> <lavfi> <cq> <depth> [cpu] [maxpart]
20+ [minpart]` (aomenc + `EC_TRACE_MODE=1 aomdec`, prints `cfl=` and `skipcfl=`
21+ with no cargo build at all — this is how 28 more recipes were swept while a
22+ suite held the target dir).
lanes/reelckf-r2.report.mdadded+80 -0
@@ -0,0 +1,80 @@
1+# lane-reelckf r2 report
2+
3+Base `lane-reelckf` bb6ebe5 (r1). Merged main 85887c7 (lane-mvtwin) at 4667015.
4+
5+## What changed
6+* `crates/ec-av1/fixtures/reelc_kf2700.obu` (NEW, tracked, 36 kB) — a 1920x792
7+ 10-bit AV1 key frame from one of the user's own films, truncated to its first
8+ temporal unit. The only stream in this repo containing a **skipped
9+ `UV_CFL_PRED` block**; the instrumented oracle counts 5 of them.
10+* `crates/ec-av1/src/stream.rs:2975` —
11+ `a_real_film_key_frame_with_a_skipped_cfl_block_decodes_pixel_exact`: decodes
12+ the fixture, HARD-asserts `reelc_chroma_counters().0 > 0` (skipped CfL) BEFORE
13+ any ffmpeg dependency, then compares all three planes against
14+ `ffmpeg -f obu -i - -f rawvideo -pix_fmt yuv420p10le -`.
15+
16+This closes r1's open item: defect 1 (a skipped intra block must still predict
17+with CfL) now has a gate that fails if the fix is reverted.
18+
19+## Gate hunt for a synthetic recipe: 18 more recipes, still zero
20+r1 swept 20 aomenc recipes without producing a skipped CfL block. r2 swept 28
21+more, detecting the block **oracle-side** (`EC_TRACE_MODE=1 aomdec` →
22+`EC_IMODE_VAL ... uv_mode=13 skip=1`), which needs no decode of ours:
23+
24+| family | recipes | CfL blocks | skipped CfL |
25+|--------|---------|-----------|-------------|
26+| `geq` sin/X chroma-correlated stripes, cq 40..63, 8+10 bit | 6 | 0..3 | 0 |
27+| mandelbrot/testsrc2 with `cb=128+0.35*(lum(2X,2Y)-128)`, cq 40..63 | 6 | 1..117 | 0 |
28+| smooth ramp / low-frequency `sin(X/60)cos(Y/70)`, cq 45..63 | 6 | 0 | 0 |
29+| blurred mandelbrot/testsrc2/gradients/cellauto/life, 0.6 chroma gain, cq 55..63, 8+10 bit | 10 | 0..10 | 0 |
30+
31+Result (measured, not inferred): aomenc DOES pick CfL freely on
32+chroma-correlated content (117 blocks at cq 40), but never with `skip=1` — the
33+two conditions pull against each other (skip needs a zero LUMA residual, CfL
34+needs luma AC worth scaling). His film reaches it because directional intra on
35+real texture predicts exactly at a 1:4 leaf. Script:
36+`$HOME/.cache/reelckf-work/cflsweep.sh <tag> <lavfi> <cq> <depth> [cpu] [maxpart] [minpart]`.
37+
38+## Deviation from the charter
39+The charter asked for stored per-plane **sha256 constants**. The crate has no
40+sha256 (and adding a hash dependency for one fixture is not warranted), and the
41+sibling film fixture test `the_reelb_head_key_frame_decodes_pixel_exact`
42+already pins against a live `ffmpeg` decode. I used that same helper. Vacuity is
43+covered the other way round: the decode and the `skip_cfl > 0` assert run
44+unconditionally, only the pixel compare is behind `have_ffmpeg()`.
45+
46+## Ten real key frames, re-measured on the MERGED tree (main 85887c7 in)
47+`$HOME/.cache/reelckf-work/one.sh <ss>` per point: 2 s `-c:v copy -f obu` extract,
48+truncated to one temporal unit, decoded with `EC_PROBE_OUT16` under a 6G scope,
49+compared sample-by-sample against `ffmpeg -pix_fmt yuv420p10le`.
50+
51+| ss | bytes | decode | samples differing (of 2 280 960) |
52+|----|-------|--------|----------------------------------|
53+| 0 | 74 | OK 1920x792 | 0 |
54+| 900 | 50350 | OK | 0 |
55+| 1800 | 98871 | OK | 0 |
56+| 2700 | 36785 | OK | 0 |
57+| 3600 | 39883 | OK | 0 |
58+| 4500 | 44734 | OK | 0 |
59+| 5400 | 287497 | OK | 0 |
60+| 6300 | 124067 | OK | 0 |
61+| 7200 | 82748 | OK | 0 |
62+| 9900 | 161573 | OK | 0 |
63+
64+10/10 Y=U=V=0, `max|d|=0`. The merge of lane-mvtwin changed nothing here.
65+ss=8100 and ss=9000 still refuse at a 128-root non-SPLIT partition (lane-sb128c's
66+cluster) and are not in the table.
67+
68+## Residue
69+* ss=8100 / ss=9000 — deferred(lane-sb128c's 128-root non-SPLIT partition).
70+ Re-measured on the merged tree, both still stop at exactly
71+ `unsupported: AV1 tile (a 128x128 superblock HORZ/VERT or AB partition (only
72+ SPLIT and NONE are decoded at the 128 root))`.
73+* A synthetic aomenc recipe for a skipped CfL block — accepted as unreachable at
74+ 48 recipes; the pinned film frame is the gate instead.
75+
76+## Full suite (merged tree, tip 735c80e)
77+`systemd-run --user --unit=reelckf-suite-1788326584 -p MemoryMax=10G ... cargo test -p ec-av1 --lib -j3`
78+-> `test result: ok. 379 passed; 0 failed; 33 ignored; 0 measured; 0 filtered out;
79+finished in 1055.41s`. Log: `$HOME/.cache/reelckf-suite-r2.log`.
80+**GREEN 379/0.**