forge
Explore
Log in

Don't you dare go Hollow

Mvstack extended row/col scan, intra-aware coverage

Browse files at this commit

b26ee9f6b0bb8d18a0ca2e274aa85ed1573d84b0Ahmet Kaan GümüşParent: cac7aab
  • fix
    • mvstack extended row/col scan, intra-aware coverage
    • enable 16x16 inter leaves
Show full message
fix(av1): mvstack extended row/col scan, intra-aware coverage; enable 16x16 inter leaves

Ports spec 7.10.2.4's extended row/col scan (libaom scan_row_mbmi/
scan_col_mbmi's idx=2..MVREF_ROW_COLS positions), invisible at pure
8-mi geometry because the immediate scan's own processed_rows/cols
coverage already reaches as far -- but only once that coverage counts
every *coded* neighbour cell, intra or inter, the way libaom's
processed_rows update sits outside add_ref_mv_candidate's ref-frame
match. The straddle-test attempt this round started from computed
coverage only from ref-matching (inter) cells, so an intra neighbour
above an 8-mi query silently un-suppressed the extended scan -- a real
8-mi behavior change, caught by two new differential tests
(extended_{row,col}_scan_is_a_no_op_at_8mi_geometry_even_behind_an_intra_neighbour)
that place a distinctively-MV'd tracer candidate at the extended
offsets and assert it never gets picked up. MiGrid now records intra
cells (encode.rs/tile.rs's else branches) so mvstack sees them.

With the no-op proven, lifts the `false &&` gate on 16x16-leaf
NEARESTMV (encode.rs:1231, wired r1, gated since dead code never
touched write_inter_frame_leaf's real symbol chain): full suite
130+3 new = 133/0/9, straddle and real_clip both green with the gate
live. The 640x384 real-clip fixture tiles exactly into 32x32
quadrants (no true-edge straddle), so its numbers are unchanged
(45.41 dB / 69861 bytes) -- the gate's leaf path is unexercised there;
the straddle test is what proves it live.
crates/ec-av1/src/encode.rsmodified+53 -30
@@ -1217,18 +1217,21 @@ fn code_square_inter(
1217 luma_trial.bits + u.bits + v.bits1217 luma_trial.bits + u.bits + v.bits
1218 });1218 });
1219 1219
1220- // corner-cut: the NEARESTMV choice below is gated off (`false &&`) --1220+ // NEARESTMV for 16x16 leaves, gated on real cost. r1/r2 found the gate's
1221- // enabling it round-trips ffmpeg/dav1d as "Invalid data found" on the1221+ // desync in `mvstack.rs`'s `find_mv_stack`: it lacked spec 7.10.2.4's
1222- // straddle test, a desync somewhere in `write_inter_frame_leaf`'s or this1222+ // extended row/col scan, invisible at 8-mi-only geometry (the immediate
1223- // function's new symbol chain, not yet isolated. With the gate off this1223+ // scan's own coverage already reached as far) but a real gap at 4-mi
1224- // is dead code (never reached, `intra_block` always wins), kept in place1224+ // leaf geometry. r3 ported the extended scan and, while proving it a
1225- // for the next round to debug with an `EC_RNG` trace rather than delete1225+ // no-op at 8-mi (`extended_row_scan_is_a_no_op_at_8mi_geometry_*`,
1226- // and re-derive. Ceiling: no real inter coding for these leaves until1226+ // `mvstack.rs`), found and fixed a second bug the extended scan's
1227- // this is lifted. Upgrade path: trace the first diverging symbol between1227+ // coverage bookkeeping (`processed_rows`/`processed_cols`) exposed: an
1228- // this function's cost model and `write_inter_frame_leaf`'s actual1228+ // intra neighbour is a coded cell too (libaom's `scan_row_mbmi`/
1229- // write, most likely a stack/grid mismatch between the encode-time and1229+ // `scan_col_mbmi` advance coverage from any candidate's `bsize`,
1230- // write-time `find_mv_stack` calls despite both using `bw4=bh4=4`.1230+ // regardless of whether it also casts a ref-frame-matching vote) --
1231- if false && inter_cost < intra_cost {1231+ // `MiGrid` now records intra cells (`tile.rs`/`encode.rs`'s `else`
1232+ // branches), which is what made 8-mi geometry a true no-op instead of
1233+ // one that only held when every neighbour happened to be inter.
1234+ if inter_cost < intra_cost {
1232 luma.commit(x, y, SUB, &luma_trial);1235 luma.commit(x, y, SUB, &luma_trial);
1233 chroma[0].commit(x / 2, y / 2, SUB / 2, &u);1236 chroma[0].commit(x / 2, y / 2, SUB / 2, &u);
1234 chroma[1].commit(x / 2, y / 2, SUB / 2, &v);1237 chroma[1].commit(x / 2, y / 2, SUB / 2, &v);
@@ -2441,20 +2444,32 @@ pub(crate) fn encode_inter_frame(
2441 &stack,2444 &stack,
2442 );2445 );
2443 2446
2444- if let Some(info) = block.inter {2447+ for dr in 0..8 {
2445- for dr in 0..8 {2448+ for dc in 0..8 {
2446- for dc in 0..8 {2449+ grid.set(
2447- grid.set(2450+ mi_row + dr,
2448- mi_row + dr,2451+ mi_col + dc,
2449- mi_col + dc,2452+ match block.inter {
2450- MiInfo {2453+ Some(info) => MiInfo {
2451 is_inter: true,2454 is_inter: true,
2452 ref_frame: LAST_FRAME,2455 ref_frame: LAST_FRAME,
2453 mv: info.mv,2456 mv: info.mv,
2454 is_new_mv: matches!(info.mode, InterMode::NewMv),2457 is_new_mv: matches!(info.mode, InterMode::NewMv),
2458+ size: 8,
2455 },2459 },
2456- );2460+ // Intra: no vote, but still a coded cell
2457- }2461+ // -- mvstack's extended-scan coverage
2462+ // (`processed_rows`/`processed_cols`)
2463+ // must see it (module doc).
2464+ None => MiInfo {
2465+ is_inter: false,
2466+ ref_frame: -1,
2467+ mv: (0, 0),
2468+ is_new_mv: false,
2469+ size: 8,
2470+ },
2471+ },
2472+ );
2458 }2473 }
2459 }2474 }
2460 blocks[r32 * cols + c32] = Quadrant::Whole(block);2475 blocks[r32 * cols + c32] = Quadrant::Whole(block);
@@ -2512,20 +2527,28 @@ pub(crate) fn encode_inter_frame(
2512 reference,2527 reference,
2513 &stack,2528 &stack,
2514 );2529 );
2515- if let Some(info) = block.inter {2530+ for dr in 0..4 {
2516- for dr in 0..4 {2531+ for dc in 0..4 {
2517- for dc in 0..4 {2532+ grid.set(
2518- grid.set(2533+ mi_row + dr,
2519- mi_row + dr,2534+ mi_col + dc,
2520- mi_col + dc,2535+ match block.inter {
2521- MiInfo {2536+ Some(info) => MiInfo {
2522 is_inter: true,2537 is_inter: true,
2523 ref_frame: LAST_FRAME,2538 ref_frame: LAST_FRAME,
2524 mv: info.mv,2539 mv: info.mv,
2525 is_new_mv: matches!(info.mode, InterMode::NewMv),2540 is_new_mv: matches!(info.mode, InterMode::NewMv),
2541+ size: 4,
2526 },2542 },
2527- );2543+ None => MiInfo {
2528- }2544+ is_inter: false,
2545+ ref_frame: -1,
2546+ mv: (0, 0),
2547+ is_new_mv: false,
2548+ size: 4,
2549+ },
2550+ },
2551+ );
2529 }2552 }
2530 }2553 }
2531 leaves.push(block);2554 leaves.push(block);
crates/ec-av1/src/mvstack.rsmodified+256 -18
@@ -97,6 +97,18 @@ pub struct MiInfo {
97 /// has no compound candidates). Feeds `NewMvContext` (7.10.2.8): a97 /// has no compound candidates). Feeds `NewMvContext` (7.10.2.8): a
98 /// neighbour's own coded-with-NEWMV state, not this block's.98 /// neighbour's own coded-with-NEWMV state, not this block's.
99 pub is_new_mv: bool,99 pub is_new_mv: bool,
100+ /// The side, in 4x4 units, of the square block this unit belongs to (8
101+ /// for a whole 32x32 block, 4 for a 16x16 leaf -- every block this crate
102+ /// ever codes is square, so one dimension is enough). Feeds the extended
103+ /// row/col scan's `processed_rows`/`processed_cols` (spec 7.10.2.2/.3,
104+ /// libaom `scan_row_mbmi`/`scan_col_mbmi`'s `inc` term): a query block no
105+ /// wider than its immediate neighbour has that neighbour's whole span
106+ /// already covered by the immediate (-1) scan, so the extended scan
107+ /// below only has to run past that. Set for *every* coded unit, intra or
108+ /// inter -- libaom's `scan_row_mbmi` advances `processed_rows` from any
109+ /// candidate's `bsize` regardless of whether it also casts a vote (that
110+ /// requires a ref-frame match, checked separately in `add_ref_mv_candidate`).
111+ pub size: usize,
100 }112 }
101 113
102 /// The whole frame's `mi` grid, one [`MiInfo`] per 4x4 unit, in raster order.114 /// The whole frame's `mi` grid, one [`MiInfo`] per 4x4 unit, in raster order.
@@ -188,6 +200,10 @@ const MAX_STACK_SIZE: usize = 8;
188 /// this module makes — see the module doc).200 /// this module makes — see the module doc).
189 const IMMEDIATE_WEIGHT: u32 = 2;201 const IMMEDIATE_WEIGHT: u32 = 2;
190 202
203+/// Spec `MVREF_ROW_COLS`: the extended row/col scan runs at offsets `-3` and
204+/// `-5` (`idx = 2..=3`), one past `IMMEDIATE_WEIGHT`'s own `-1`.
205+const MVREF_ROW_COLS: usize = 3;
206+
191 /// Adds one candidate MV with `weight` to `candidates`, merging it into an207 /// Adds one candidate MV with `weight` to `candidates`, merging it into an
192 /// existing entry with the same MV rather than duplicating it (spec208 /// existing entry with the same MV rather than duplicating it (spec
193 /// `add_ref_mv_candidate`, 7.10.2.5).209 /// `add_ref_mv_candidate`, 7.10.2.5).
@@ -200,7 +216,14 @@ fn add_candidate(candidates: &mut Vec<StackEntry>, mv: (i32, i32), weight: u32)
200 }216 }
201 217
202 /// The row-above scan (spec 7.10.2.2): every 4x4 unit directly above the218 /// The row-above scan (spec 7.10.2.2): every 4x4 unit directly above the
203-/// block's span. Returns whether any unit voted.219+/// block's span. Returns whether any unit voted, and `processed_rows`
220+/// (libaom `scan_row_mbmi`'s output): how many rows past the immediate one
221+/// this span already covers by *geometry* alone (0 unless a same-or-wider
222+/// neighbour occupies it, in which case that neighbour's own `size` is the
223+/// coverage, spec 7.10.2.2's `inc` term reduced to this crate's square,
224+/// fixed-weight candidates) -- tracked for *every* coded cell, intra or
225+/// inter, since libaom's `processed_rows` update sits outside the
226+/// ref-frame-matching `add_ref_mv_candidate` call.
204 fn scan_row(227 fn scan_row(
205 grid: &MiGrid,228 grid: &MiGrid,
206 mi_row: usize,229 mi_row: usize,
@@ -209,26 +232,31 @@ fn scan_row(
209 ref_frame: i8,232 ref_frame: i8,
210 candidates: &mut Vec<StackEntry>,233 candidates: &mut Vec<StackEntry>,
211 newmv_count: &mut u32,234 newmv_count: &mut u32,
212-) -> bool {235+) -> (bool, usize) {
213 let Some(row) = mi_row.checked_sub(1) else {236 let Some(row) = mi_row.checked_sub(1) else {
214- return false;237+ return (false, 0);
215 };238 };
216 let mut found = false;239 let mut found = false;
240+ let mut processed_rows = 0;
217 for col in mi_col..mi_col + bw4 {241 for col in mi_col..mi_col + bw4 {
218- if let Some(info) = grid.get(row, col)242+ let Some(info) = grid.get(row, col) else {
219- && info.is_inter243+ continue;
220- && info.ref_frame == ref_frame244+ };
221- {245+ if bw4 <= info.size {
246+ processed_rows = processed_rows.max(info.size);
247+ }
248+ if info.is_inter && info.ref_frame == ref_frame {
222 found = true;249 found = true;
223 add_candidate(candidates, info.mv, IMMEDIATE_WEIGHT);250 add_candidate(candidates, info.mv, IMMEDIATE_WEIGHT);
224 *newmv_count += u32::from(info.is_new_mv);251 *newmv_count += u32::from(info.is_new_mv);
225 }252 }
226 }253 }
227- found254+ (found, processed_rows)
228 }255 }
229 256
230 /// The col-left scan (spec 7.10.2.3): every 4x4 unit directly left of the257 /// The col-left scan (spec 7.10.2.3): every 4x4 unit directly left of the
231-/// block's span. Returns whether any unit voted.258+/// block's span. Returns whether any unit voted, and `processed_cols`
259+/// (`scan_row`'s doc, transposed).
232 fn scan_col(260 fn scan_col(
233 grid: &MiGrid,261 grid: &MiGrid,
234 mi_row: usize,262 mi_row: usize,
@@ -237,21 +265,99 @@ fn scan_col(
237 ref_frame: i8,265 ref_frame: i8,
238 candidates: &mut Vec<StackEntry>,266 candidates: &mut Vec<StackEntry>,
239 newmv_count: &mut u32,267 newmv_count: &mut u32,
240-) -> bool {268+) -> (bool, usize) {
241 let Some(col) = mi_col.checked_sub(1) else {269 let Some(col) = mi_col.checked_sub(1) else {
242- return false;270+ return (false, 0);
243 };271 };
244 let mut found = false;272 let mut found = false;
273+ let mut processed_cols = 0;
245 for row in mi_row..mi_row + bh4 {274 for row in mi_row..mi_row + bh4 {
246- if let Some(info) = grid.get(row, col)275+ let Some(info) = grid.get(row, col) else {
247- && info.is_inter276+ continue;
248- && info.ref_frame == ref_frame277+ };
249- {278+ if bh4 <= info.size {
279+ processed_cols = processed_cols.max(info.size);
280+ }
281+ if info.is_inter && info.ref_frame == ref_frame {
250 found = true;282 found = true;
251 add_candidate(candidates, info.mv, IMMEDIATE_WEIGHT);283 add_candidate(candidates, info.mv, IMMEDIATE_WEIGHT);
252 *newmv_count += u32::from(info.is_new_mv);284 *newmv_count += u32::from(info.is_new_mv);
253 }285 }
254 }286 }
287+ (found, processed_cols)
288+}
289+
290+/// The extended row scan (spec 7.10.2.4's `idx = 2..MVREF_ROW_COLS` row
291+/// positions, libaom `mvref_common.c`'s second loop): probes rows `-3` and
292+/// `-5`, shifted one column right (`col_offset = 1`, libaom's `col_adj`
293+/// collapses to that for every block size this crate ever queries), each
294+/// only run when the immediate scan's own `processed_rows` hasn't already
295+/// covered it and the tile's top edge doesn't clip it first. Its match folds
296+/// into the row side (`ref_match_count`, never `nearest_match`), same as the
297+/// corner probe.
298+fn scan_row_extended(
299+ grid: &MiGrid,
300+ mi_row: usize,
301+ mi_col: usize,
302+ bw4: usize,
303+ ref_frame: i8,
304+ candidates: &mut Vec<StackEntry>,
305+ processed_rows: usize,
306+) -> bool {
307+ let max_row_offset = mi_row.min(MVREF_ROW_COLS * 2);
308+ let mut found = false;
309+ for idx in 2..=MVREF_ROW_COLS {
310+ let offset = idx * 2 - 1;
311+ if offset > max_row_offset || offset <= processed_rows {
312+ continue;
313+ }
314+ let Some(row) = mi_row.checked_sub(offset) else {
315+ continue;
316+ };
317+ for col in mi_col + 1..mi_col + 1 + bw4 {
318+ if let Some(info) = grid.get(row, col)
319+ && info.is_inter
320+ && info.ref_frame == ref_frame
321+ {
322+ found = true;
323+ add_candidate(candidates, info.mv, IMMEDIATE_WEIGHT);
324+ }
325+ }
326+ }
327+ found
328+}
329+
330+/// The extended col scan: `scan_row_extended`, transposed (probes cols `-3`
331+/// and `-5`, shifted one row down).
332+fn scan_col_extended(
333+ grid: &MiGrid,
334+ mi_row: usize,
335+ mi_col: usize,
336+ bh4: usize,
337+ ref_frame: i8,
338+ candidates: &mut Vec<StackEntry>,
339+ processed_cols: usize,
340+) -> bool {
341+ let max_col_offset = mi_col.min(MVREF_ROW_COLS * 2);
342+ let mut found = false;
343+ for idx in 2..=MVREF_ROW_COLS {
344+ let offset = idx * 2 - 1;
345+ if offset > max_col_offset || offset <= processed_cols {
346+ continue;
347+ }
348+ let Some(col) = mi_col.checked_sub(offset) else {
349+ continue;
350+ };
351+ for row in mi_row + 1..mi_row + 1 + bh4 {
352+ if let Some(info) = grid.get(row, col)
353+ && info.is_inter
354+ && info.ref_frame == ref_frame
355+ {
356+ found = true;
357+ add_candidate(candidates, info.mv, IMMEDIATE_WEIGHT);
358+ }
359+ }
360+ }
255 found361 found
256 }362 }
257 363
@@ -363,7 +469,7 @@ pub fn find_mv_stack(
363 ) -> MvStack {469 ) -> MvStack {
364 let mut candidates = Vec::new();470 let mut candidates = Vec::new();
365 let mut newmv_count = 0u32;471 let mut newmv_count = 0u32;
366- let found_above = scan_row(472+ let (found_above, processed_rows) = scan_row(
367 grid,473 grid,
368 mi_row,474 mi_row,
369 mi_col,475 mi_col,
@@ -372,7 +478,7 @@ pub fn find_mv_stack(
372 &mut candidates,478 &mut candidates,
373 &mut newmv_count,479 &mut newmv_count,
374 );480 );
375- let found_left = scan_col(481+ let (found_left, processed_cols) = scan_col(
376 grid,482 grid,
377 mi_row,483 mi_row,
378 mi_col,484 mi_col,
@@ -417,7 +523,34 @@ pub fn find_mv_stack(
417 &mut candidates,523 &mut candidates,
418 &mut dummy_newmv_count,524 &mut dummy_newmv_count,
419 );525 );
420- let ref_match_count = usize::from(row_matched || corner_matched) + usize::from(found_left);526+ // The extended row/col scan (spec 7.10.2.4's `idx = 2..MVREF_ROW_COLS`):
527+ // only reachable once the immediate scan's own reach (`processed_rows`/
528+ // `processed_cols`) leaves a gap the tile's edge doesn't already clip.
529+ // At this module's fixed 8-mi block geometry with every coded cell
530+ // (intra or inter) now feeding coverage, that reach always hits
531+ // `MVREF_ROW_COLS`'s farthest offset first -- a true no-op there (see
532+ // module doc and `extended_scan_is_a_no_op_at_8mi_geometry` below). Folds
533+ // into the row/col match booleans, never `nearest_match`.
534+ let row_matched_ext = scan_row_extended(
535+ grid,
536+ mi_row,
537+ mi_col,
538+ bw4,
539+ ref_frame,
540+ &mut candidates,
541+ processed_rows,
542+ );
543+ let col_matched_ext = scan_col_extended(
544+ grid,
545+ mi_row,
546+ mi_col,
547+ bh4,
548+ ref_frame,
549+ &mut candidates,
550+ processed_cols,
551+ );
552+ let ref_match_count = usize::from(row_matched || corner_matched || row_matched_ext)
553+ + usize::from(found_left || col_matched_ext);
421 554
422 // Highest weight first; a stable sort keeps scan order (above, left,555 // Highest weight first; a stable sort keeps scan order (above, left,
423 // top-right, corner) among ties, matching spec 7.10.2.6. The corner556 // top-right, corner) among ties, matching spec 7.10.2.6. The corner
@@ -537,6 +670,10 @@ mod tests {
537 ref_frame: 1,670 ref_frame: 1,
538 mv,671 mv,
539 is_new_mv: false,672 is_new_mv: false,
673+ // 1: smaller than every `bw4`/`bh4` these small-grid tests use,
674+ // so it never trips the extended-scan coverage boost -- these
675+ // tests only exercise the immediate/corner/top-right scans.
676+ size: 1,
540 }677 }
541 }678 }
542 679
@@ -682,6 +819,7 @@ mod tests {
682 ref_frame: 1,819 ref_frame: 1,
683 mv: (4, 4),820 mv: (4, 4),
684 is_new_mv: true,821 is_new_mv: true,
822+ size: 1,
685 },823 },
686 );824 );
687 // Only the row matches (nearest_match == 1): newmv_count > 0 picks825 // Only the row matches (nearest_match == 1): newmv_count > 0 picks
@@ -742,4 +880,104 @@ mod tests {
742 assert_eq!(single_ref_ctx(false), 1);880 assert_eq!(single_ref_ctx(false), 1);
743 assert_eq!(single_ref_ctx(true), 2);881 assert_eq!(single_ref_ctx(true), 2);
744 }882 }
883+
884+ /// An 8-mi-sized (`size: 8`) coded-but-intra neighbour: contributes no
885+ /// vote (`is_inter: false`) but must still count for extended-scan
886+ /// coverage, the way libaom's `scan_row_mbmi`/`scan_col_mbmi` advance
887+ /// `processed_rows`/`processed_cols` from any candidate's `bsize` alone.
888+ fn intra8() -> MiInfo {
889+ MiInfo {
890+ is_inter: false,
891+ ref_frame: -1,
892+ mv: (0, 0),
893+ is_new_mv: false,
894+ size: 8,
895+ }
896+ }
897+
898+ /// An 8-mi-sized inter neighbour with an arbitrary, distinctive `mv` --
899+ /// used below as a "would this get picked up" tracer at extended-scan
900+ /// offsets that a correct implementation must never reach at 8-mi
901+ /// geometry.
902+ fn inter8(mv: (i32, i32)) -> MiInfo {
903+ MiInfo {
904+ is_inter: true,
905+ ref_frame: 1,
906+ mv,
907+ is_new_mv: false,
908+ size: 8,
909+ }
910+ }
911+
912+ /// The class of bug this round fixed: at 8-mi geometry, an intra
913+ /// neighbour directly above the query block must suppress the extended
914+ /// row scan exactly as an inter one would (spec 7.10.2.2's
915+ /// `processed_rows` tracks *coded* neighbours, not merely *matching*
916+ /// ones). Two tracer candidates sit at the row's extended-scan offsets
917+ /// (-3 and -5, spec 7.10.2.4) with MVs no other scan could produce; if
918+ /// the coverage bug regresses, they show up in `stack.entries`.
919+ #[test]
920+ fn extended_row_scan_is_a_no_op_at_8mi_geometry_even_behind_an_intra_neighbour() {
921+ let mut grid = MiGrid::new(32, 32);
922+ let (mi_row, mi_col) = (10, 10);
923+ for col in mi_col..mi_col + 8 {
924+ grid.set(mi_row - 1, col, intra8());
925+ }
926+ for col in mi_col + 1..mi_col + 1 + 8 {
927+ grid.set(mi_row - 3, col, inter8((999, 999)));
928+ grid.set(mi_row - 5, col, inter8((888, 888)));
929+ }
930+
931+ let stack = find_mv_stack(&grid, mi_row, mi_col, 8, 8, 1, 32, 32);
932+
933+ assert!(
934+ stack.entries.is_empty(),
935+ "extended row scan fired at 8-mi geometry: {:?}",
936+ stack.entries
937+ );
938+ }
939+
940+ /// `extended_row_scan_is_a_no_op_at_8mi_geometry_even_behind_an_intra_neighbour`,
941+ /// transposed to the col-left scan.
942+ #[test]
943+ fn extended_col_scan_is_a_no_op_at_8mi_geometry_even_behind_an_intra_neighbour() {
944+ let mut grid = MiGrid::new(32, 32);
945+ let (mi_row, mi_col) = (10, 10);
946+ for row in mi_row..mi_row + 8 {
947+ grid.set(row, mi_col - 1, intra8());
948+ }
949+ for row in mi_row + 1..mi_row + 1 + 8 {
950+ grid.set(row, mi_col - 3, inter8((999, 999)));
951+ grid.set(row, mi_col - 5, inter8((888, 888)));
952+ }
953+
954+ let stack = find_mv_stack(&grid, mi_row, mi_col, 8, 8, 1, 32, 32);
955+
956+ assert!(
957+ stack.entries.is_empty(),
958+ "extended col scan fired at 8-mi geometry: {:?}",
959+ stack.entries
960+ );
961+ }
962+
963+ /// Same shape, but the immediate neighbour is itself inter (a same-size
964+ /// vote) rather than intra -- the geometry-only coverage path must not
965+ /// have broken the ordinary matching one.
966+ #[test]
967+ fn extended_row_scan_is_a_no_op_at_8mi_geometry_behind_an_inter_neighbour() {
968+ let mut grid = MiGrid::new(32, 32);
969+ let (mi_row, mi_col) = (10, 10);
970+ for col in mi_col..mi_col + 8 {
971+ grid.set(mi_row - 1, col, inter8((4, 4)));
972+ }
973+ for col in mi_col + 1..mi_col + 1 + 8 {
974+ grid.set(mi_row - 3, col, inter8((999, 999)));
975+ grid.set(mi_row - 5, col, inter8((888, 888)));
976+ }
977+
978+ let stack = find_mv_stack(&grid, mi_row, mi_col, 8, 8, 1, 32, 32);
979+
980+ assert_eq!(stack.entries.len(), 1);
981+ assert_eq!(stack.entries[0].mv, (4, 4));
982+ }
745 }983 }
crates/ec-av1/src/tile.rsmodified+40 -0
@@ -2117,6 +2117,7 @@ pub fn sb_coeff_inter_frame_tile(
2117 ref_frame: LAST_FRAME,2117 ref_frame: LAST_FRAME,
2118 mv,2118 mv,
2119 is_new_mv,2119 is_new_mv,
2120+ size: 8,
2120 },2121 },
2121 );2122 );
2122 for dr in 0..8 {2123 for dr in 0..8 {
@@ -2132,6 +2133,7 @@ pub fn sb_coeff_inter_frame_tile(
2132 ref_frame: LAST_FRAME,2133 ref_frame: LAST_FRAME,
2133 mv,2134 mv,
2134 is_new_mv,2135 is_new_mv,
2136+ size: 8,
2135 },2137 },
2136 );2138 );
2137 }2139 }
@@ -2145,6 +2147,24 @@ pub fn sb_coeff_inter_frame_tile(
2145 }2147 }
2146 enc.symbol(DC_PRED, &mut cdfs.uv_mode_cfl[mode]);2148 enc.symbol(DC_PRED, &mut cdfs.uv_mode_cfl[mode]);
2147 mode_for_tx = mode;2149 mode_for_tx = mode;
2150+ // Intra: no vote, but still a coded cell -- mvstack's
2151+ // extended-scan coverage must see it (module doc).
2152+ let (mi_row, mi_col) = (r32 as usize * 8, c32 as usize * 8);
2153+ for dr in 0..8 {
2154+ for dc in 0..8 {
2155+ grid.set(
2156+ mi_row + dr,
2157+ mi_col + dc,
2158+ MiInfo {
2159+ is_inter: false,
2160+ ref_frame: -1,
2161+ mv: (0, 0),
2162+ is_new_mv: false,
2163+ size: 8,
2164+ },
2165+ );
2166+ }
2167+ }
2148 }2168 }
2149 2169
2150 if block.skip {2170 if block.skip {
@@ -2278,6 +2298,7 @@ fn write_inter_frame_leaf(
2278 ref_frame: LAST_FRAME,2298 ref_frame: LAST_FRAME,
2279 mv,2299 mv,
2280 is_new_mv,2300 is_new_mv,
2301+ size: SUB_MI as usize,
2281 },2302 },
2282 );2303 );
2283 }2304 }
@@ -2291,6 +2312,24 @@ fn write_inter_frame_leaf(
2291 }2312 }
2292 enc.symbol(DC_PRED, &mut cdfs.uv_mode_cfl[mode]);2313 enc.symbol(DC_PRED, &mut cdfs.uv_mode_cfl[mode]);
2293 mode_for_tx = mode;2314 mode_for_tx = mode;
2315+ // Intra: no vote, but still a coded cell -- mvstack's extended-scan
2316+ // coverage must see it (module doc).
2317+ let (mi_row, mi_col) = (r * SUB_MI as usize, c * SUB_MI as usize);
2318+ for dr in 0..SUB_MI as usize {
2319+ for dc in 0..SUB_MI as usize {
2320+ grid.set(
2321+ mi_row + dr,
2322+ mi_col + dc,
2323+ MiInfo {
2324+ is_inter: false,
2325+ ref_frame: -1,
2326+ mv: (0, 0),
2327+ is_new_mv: false,
2328+ size: SUB_MI as usize,
2329+ },
2330+ );
2331+ }
2332+ }
2294 }2333 }
2295 2334
2296 if block.skip {2335 if block.skip {
@@ -4538,6 +4577,7 @@ mod tests {
4538 ref_frame: 1,4577 ref_frame: 1,
4539 mv,4578 mv,
4540 is_new_mv,4579 is_new_mv,
4580+ size: 8,
4541 },4581 },
4542 );4582 );
4543 }4583 }