forge
Explore
Log in

Don't you dare go Hollow

The mi-granular mode maps are per TILE -- tile-relative guards + per-tile/row reset

Browse files at this commit

91b5f76331e756687792fea124f205fc39deb820Ahmet Kaan GümüşParent: 278df5f
  • fix
    • the mi-granular mode maps are per TILE -- tile-relative guards + per-tile/row reset
Show full message
fix(av1): the mi-granular mode maps are per TILE -- tile-relative guards + per-tile/row reset

sub8_mode_col/row and uv_mode_col/row were read with a frame-relative
availability guard (mi_r > 0 / mi_c > 0) and never cleared, so the first
block of a second tile column/row read the previous tile's recorded
(row, mode) entry as its own neighbour: wrong intra-mode context and wrong
chroma edge-filter type. Verifier repro (128x64, --tile-columns=1, seeds
207/228) mismatched 221 and 158 bytes, every one at x>=64; both streams now
decode pixel-exact. decode_leaf_rect also records its own span in those maps
(the caller patched only the coarse 16x16 slot, so a neighbour of the top
strip read the bottom strip's mode).

Gate: three arms (single tile, --tile-columns=1, --tile-rows=1), tile_hits
delta >= 2 asserted on the tile arms, the Err arm now panics on any decode
error that is not a named "unsupported: " refusal, and the lavfi noise
fixture carries all_seed so (seed, cq) names one exact stream. Reverting the
guard+reset hunks makes that gate FAIL (U plane, seed=139 cq=12).
crates/ec-av1/src/decode.rsmodified+24 -8
@@ -1998,6 +1998,14 @@ impl Neighbours {
1998 self.above_compound_idx[i] = 0;1998 self.above_compound_idx[i] = 0;
1999 self.above_filter[i] = [3u8; 2];1999 self.above_filter[i] = [3u8; 2];
2000 }2000 }
2001+ // lane-sub8 r6: the mi-granular column maps are per tile too -- a
2002+ // stale `(row, mode)` from the tile to the LEFT names an mi row this
2003+ // tile's first block would read as its own above neighbour.
2004+ let mcol_end = col1_mi.min(self.sub8_mode_col.len());
2005+ for i in col0_mi.min(mcol_end)..mcol_end {
2006+ self.sub8_mode_col[i] = (usize::MAX, 0);
2007+ self.uv_mode_col[i] = (usize::MAX, 0);
2008+ }
2001 }2009 }
2002 2010
2003 /// Writes a just-decoded block's own palette-Y size/colours (`size == 0`2011 /// Writes a just-decoded block's own palette-Y size/colours (`size == 0`
@@ -2266,6 +2274,10 @@ impl Neighbours {
2266 self.left_comp_group_idx.iter_mut().for_each(|r| *r = 0);2274 self.left_comp_group_idx.iter_mut().for_each(|r| *r = 0);
2267 self.left_compound_idx.iter_mut().for_each(|r| *r = 0);2275 self.left_compound_idx.iter_mut().for_each(|r| *r = 0);
2268 self.left_filter.iter_mut().for_each(|f| *f = [3u8; 2]);2276 self.left_filter.iter_mut().for_each(|f| *f = [3u8; 2]);
2277+ // lane-sub8 r6: mi-granular row maps reset with the rest of the left
2278+ // context (a tile/SB-row boundary has no left neighbour).
2279+ self.sub8_mode_row.iter_mut().for_each(|s| *s = (usize::MAX, 0));
2280+ self.uv_mode_row.iter_mut().for_each(|s| *s = (usize::MAX, 0));
2269 }2281 }
2270 2282
2271 /// Records a block's `skip`/`is_inter`/`interp_filter` state for the next2283 /// Records a block's `skip`/`is_inter`/`interp_filter` state for the next
@@ -2531,14 +2543,14 @@ impl Neighbours {
2531 /// construction). See [`Self::record_mode_mi`].2543 /// construction). See [`Self::record_mode_mi`].
2532 fn mode_above_mi(&self, mi_r: usize, mi_c: usize) -> Option<usize> {2544 fn mode_above_mi(&self, mi_r: usize, mi_c: usize) -> Option<usize> {
2533 match self.sub8_mode_col.get(mi_c) {2545 match self.sub8_mode_col.get(mi_c) {
2534- Some(&(row, m)) if mi_r > 0 && row == mi_r - 1 => Some(m),2546+ Some(&(row, m)) if mi_r > self.tile_row0_mi && row == mi_r - 1 => Some(m),
2535 _ => None,2547 _ => None,
2536 }2548 }
2537 }2549 }
2538 2550
2539 fn mode_left_mi(&self, mi_r: usize, mi_c: usize) -> Option<usize> {2551 fn mode_left_mi(&self, mi_r: usize, mi_c: usize) -> Option<usize> {
2540 match self.sub8_mode_row.get(mi_r) {2552 match self.sub8_mode_row.get(mi_r) {
2541- Some(&(col, m)) if mi_c > 0 && col == mi_c - 1 => Some(m),2553+ Some(&(col, m)) if mi_c > self.tile_col0_mi && col == mi_c - 1 => Some(m),
2542 _ => None,2554 _ => None,
2543 }2555 }
2544 }2556 }
@@ -2572,11 +2584,11 @@ impl Neighbours {
2572 /// block has recorded the exact neighbouring mi.2584 /// block has recorded the exact neighbouring mi.
2573 fn smooth_uv_neighbour(&self, mi_r: usize, mi_c: usize, r: usize, c: usize) -> bool {2585 fn smooth_uv_neighbour(&self, mi_r: usize, mi_c: usize, r: usize, c: usize) -> bool {
2574 let above = match self.uv_mode_col.get(mi_c) {2586 let above = match self.uv_mode_col.get(mi_c) {
2575- Some(&(row, m)) if mi_r > 0 && row == mi_r - 1 => m,2587+ Some(&(row, m)) if mi_r > self.tile_row0_mi && row == mi_r - 1 => m,
2576 _ => self.above_uv_mode[c],2588 _ => self.above_uv_mode[c],
2577 };2589 };
2578 let left = match self.uv_mode_row.get(mi_r) {2590 let left = match self.uv_mode_row.get(mi_r) {
2579- Some(&(col, m)) if mi_c > 0 && col == mi_c - 1 => m,2591+ Some(&(col, m)) if mi_c > self.tile_col0_mi && col == mi_c - 1 => m,
2580 _ => self.left_uv_mode[r],2592 _ => self.left_uv_mode[r],
2581 };2593 };
2582 is_smooth_mode(above) || is_smooth_mode(left)2594 is_smooth_mode(above) || is_smooth_mode(left)
@@ -3745,6 +3757,11 @@ fn decode_leaf_rect(
3745 vec![0i32; chroma_w * chroma_h],3757 vec![0i32; chroma_w * chroma_h],
3746 ],3758 ],
3747 );3759 );
3760+ // lane-sub8 r6: the caller patches only the coarse `above_mode`/
3761+ // `left_mode` slot (one value for the whole 16x16), so record this
3762+ // strip's own span mi-exactly like every square leaf does.
3763+ neighbours.record_mode_mi(leaf_mi.0, leaf_mi.1, mi_w, mi_h, mode);
3764+ neighbours.record_uv_mode_mi(leaf_mi.0, leaf_mi.1, mi_w, mi_h, uv_predict_mode);
3748 neighbours.fill_skip_grid_rect(leaf_mi, mi_w, mi_h, skip);3765 neighbours.fill_skip_grid_rect(leaf_mi, mi_w, mi_h, skip);
3749 neighbours.fill_lf_grid_rect(leaf_mi, mi_w, mi_h, bw as u8, bh as u8, 0);3766 neighbours.fill_lf_grid_rect(leaf_mi, mi_w, mi_h, bw as u8, bh as u8, 0);
3750 Ok(mode)3767 Ok(mode)
@@ -5324,10 +5341,9 @@ fn decode_leaf8(
5324 // this leaf's `smooth_neighbor` is built from -- passing `false` here5341 // this leaf's `smooth_neighbor` is built from -- passing `false` here
5325 // filtered a directional chroma block's edge at the wrong strength5342 // filtered a directional chroma block's edge at the wrong strength
5326 // (lane-sub8 r5: 4 pixels of one 8x8 leaf's chroma, deltas 1..3).5343 // (lane-sub8 r5: 4 pixels of one 8x8 leaf's chroma, deltas 1..3).
5327- // corner-cut: the `uv_mode` neighbours are the coarse [`SUB`] slots, so5344+ // The `uv_mode` neighbours are mi-exact (`uv_mode_col`/`uv_mode_row`),
5328- // two 8x8 leaves of one 16x16 see the slot the previous leaf wrote5345+ // with the coarse [`SUB`] slot as the fallback when no block recorded
5329- // (updated below) rather than a real mi-exact neighbour; upgrade path is5346+ // that exact mi cell.
5330- // an mi-granular map like `sub8_mode_col`.
5331 let smooth_neighbor_uv = neighbours.smooth_uv_neighbour(leaf_mi.0, leaf_mi.1, r, c);5347 let smooth_neighbor_uv = neighbours.smooth_uv_neighbour(leaf_mi.0, leaf_mi.1, r, c);
5332 if smooth_neighbor {5348 if smooth_neighbor {
5333 SMOOTH_LUMA_HITS.with(|c| c.set(c.get() + 1));5349 SMOOTH_LUMA_HITS.with(|c| c.set(c.get() + 1));
crates/ec-av1/src/stream.rsmodified+38 -6
@@ -7256,7 +7256,16 @@ mod tests {
7256 // safe way to isolate the leaf count. Left red; do not "fix" this7256 // safe way to isolate the leaf count. Left red; do not "fix" this
7257 // gate by picking fixture parameters that dodge the desync without7257 // gate by picking fixture parameters that dodge the desync without
7258 // finding it.7258 // finding it.
7259- let (width, height) = (64usize, 64usize);7259+ // lane-sub8 r6: three arms. The mi-granular mode maps
7260+ // (`sub8_mode_col`/`uv_mode_col` and their row twins) are per TILE --
7261+ // the verifier's repro was a 128x64 `--tile-columns=1` stream (seeds
7262+ // 207/228) whose every mismatching luma pixel sat at x>=64, the tile
7263+ // boundary -- so one arm per tile axis is part of this gate.
7264+ for (width, height, tile_args) in [
7265+ (64usize, 64usize, &[][..]),
7266+ (128usize, 64usize, &["--tile-columns=1"][..]),
7267+ (64usize, 128usize, &["--tile-rows=1"][..]),
7268+ ] {
7260 let mut refusals = Vec::new();7269 let mut refusals = Vec::new();
7261 let mut fired_runs = 0u32;7270 let mut fired_runs = 0u32;
7262 for attempt in 0..40u32 {7271 for attempt in 0..40u32 {
@@ -7271,7 +7280,10 @@ mod tests {
7271 "-i",7280 "-i",
7272 &gradients_source(seed, width, height, "rate=25"),7281 &gradients_source(seed, width, height, "rate=25"),
7273 "-vf",7282 "-vf",
7274- "noise=alls=40:allf=t,format=yuv420p",7283+ // `noise` without `all_seed` re-renders differently on
7284+ // every run (seeded-fixture-not-reproducible); pinning it
7285+ // makes (seed, cq) name one exact stream.
7286+ &format!("noise=alls=40:allf=t:all_seed={seed},format=yuv420p"),
7275 "-t",7287 "-t",
7276 "0.04",7288 "0.04",
7277 "-f",7289 "-f",
@@ -7324,6 +7336,7 @@ mod tests {
7324 "-",7336 "-",
7325 "-",7337 "-",
7326 ])7338 ])
7339+ .args(tile_args)
7327 .stdin(Stdio::piped())7340 .stdin(Stdio::piped())
7328 .stdout(Stdio::piped())7341 .stdout(Stdio::piped())
7329 .stderr(Stdio::piped())7342 .stderr(Stdio::piped())
@@ -7344,13 +7357,29 @@ mod tests {
7344 }7357 }
7345 let stream = out.stdout;7358 let stream = out.stdout;
7346 let before = decode::sub8_split_hits();7359 let before = decode::sub8_split_hits();
7360+ let tiles_before = decode::tile_hits();
7347 let frames = match decode_stream(&stream) {7361 let frames = match decode_stream(&stream) {
7348 Ok(frames) => frames,7362 Ok(frames) => frames,
7349 Err(e) => {7363 Err(e) => {
7350- refusals.push(format!("seed={seed} cq={cq}: {e}"));7364+ // Only a named refusal ("unsupported: ...") is a skip
7365+ // reason; any other decode error is this decoder failing.
7366+ let msg = e.to_string();
7367+ assert!(
7368+ msg.starts_with("unsupported: "),
7369+ "decode error that is not a named refusal \
7370+ (seed={seed} cq={cq} tiles={tile_args:?}): {msg}"
7371+ );
7372+ refusals.push(format!("seed={seed} cq={cq}: {msg}"));
7351 continue;7373 continue;
7352 }7374 }
7353 };7375 };
7376+ // gate-blind-to-feature: a tile arm must actually decode more
7377+ // than one tile, not merely carry `tile_info.cols > 1`.
7378+ assert!(
7379+ tile_args.is_empty() || decode::tile_hits() - tiles_before >= 2,
7380+ "tiles={tile_args:?} decoded only {} tile(s) (seed={seed} cq={cq})",
7381+ decode::tile_hits() - tiles_before
7382+ );
7354 if decode::sub8_split_hits() == before {7383 if decode::sub8_split_hits() == before {
7355 refusals.push(format!(7384 refusals.push(format!(
7356 "seed={seed} cq={cq}: decoded, but no block read a real PARTITION_SPLIT below 8x8"7385 "seed={seed} cq={cq}: decoded, but no block read a real PARTITION_SPLIT below 8x8"
@@ -7372,13 +7401,16 @@ mod tests {
7372 );7401 );
7373 fired_runs += 1;7402 fired_runs += 1;
7374 if fired_runs >= 4 {7403 if fired_runs >= 4 {
7375- return;7404+ break;
7376 }7405 }
7377 }7406 }
7378- panic!(7407+ assert!(
7379- "fewer than 4 firing+pixel-exact runs out of 40 attempts:\n{}",7408+ fired_runs >= 4,
7409+ "fewer than 4 firing+pixel-exact runs out of 40 attempts \
7410+ ({width}x{height} tiles={tile_args:?}):\n{}",
7380 refusals.join("\n")7411 refusals.join("\n")
7381 );7412 );
7413+ }
7382 }7414 }
7383 7415
7384 /// lane-av1golden7 r9's decisive fixture: a real aomenc stream (seed 59,7416 /// lane-av1golden7 r9's decisive fixture: a real aomenc stream (seed 59,
lanes/sub8-r5.report.mdmodified+2 -1
@@ -43,7 +43,8 @@ existing mi-granular `sub8_mode_col`/`sub8_mode_row` machinery.
43 hardcoded `false` at all 10 chroma reconstruct/read_plane arguments in those43 hardcoded `false` at all 10 chroma reconstruct/read_plane arguments in those
44 two functions.44 two functions.
45 - `crates/ec-av1/src/refusal_inventory.rs:31` -- deleted the stale capability45 - `crates/ec-av1/src/refusal_inventory.rs:31` -- deleted the stale capability
46- claim `"a partition below 16x16 other than a clean split ..."`; r4's fixes46+ claim `"a partition below 8x8 (this decoder codes no leaf smaller than
47+ 8x8)"` (corrected in r6: the string named here originally was wrong); r4's fixes
47 removed that string from the decode path, which is exactly what made48 removed that string from the decode path, which is exactly what made
48 `the_decode_path_refuses_exactly_the_listed_cases` RED (charter step 2).49 `the_decode_path_refuses_exactly_the_listed_cases` RED (charter step 2).
49 It was the only entry the test named.50 It was the only entry the test named.
lanes/sub8-r6.report.mdadded+71 -0
@@ -0,0 +1,71 @@
1+# lane-sub8 report (round 6) -- verifier FAIL closed
2+
3+## The defect the verifier found (root cause)
4+
5+The mi-granular mode maps added in r2/r5 (`sub8_mode_col`/`sub8_mode_row`,
6+`uv_mode_col`/`uv_mode_row`) are FRAME-wide arrays read with a FRAME-relative
7+availability guard (`mi_r > 0` / `mi_c > 0`) and never reset per tile. Every
8+other neighbour site in `decode.rs` guards tile-relatively
9+(`mi_r > self.tile_row0_mi`, e.g. :2240, :3222, :6152). With more than one
10+tile, the first block of tile N read a `(row, mode)` entry left by the tile to
11+its LEFT (or above) as if it were its own neighbour -- wrong intra-mode
12+context / wrong chroma edge-filter type, and from there wrong pixels.
13+
14+## What changed (all in the lane worktree, branch `lane-sub8`)
15+- `crates/ec-av1/src/decode.rs:2533,2540,2574,2578` -- the four reads now guard
16+ with `self.tile_row0_mi` / `self.tile_col0_mi`.
17+- `crates/ec-av1/src/decode.rs:2000` (`start_tile`) -- clears
18+ `sub8_mode_col`/`uv_mode_col` over the tile's own mi column span
19+ (`col0_mi..col1_mi`), alongside the existing `above_*` reset.
20+- `crates/ec-av1/src/decode.rs:2286` (`start_row`) -- clears
21+ `sub8_mode_row`/`uv_mode_row` with the rest of the left context.
22+- `crates/ec-av1/src/decode.rs:3763` -- `decode_leaf_rect` (the 16x8/8x16
23+ strips) now calls `record_mode_mi`/`record_uv_mode_mi` over its real span;
24+ before, the caller patched only the coarse 16x16 `above_mode`/`left_mode`
25+ slot, so a neighbour of the TOP strip read the BOTTOM strip's mode.
26+ (Sweep item 1 of the verifier's list.)
27+- `crates/ec-av1/src/decode.rs:5326` -- deleted the stale `corner-cut` comment
28+ claiming the uv neighbours are coarse; they are mi-exact since r5.
29+- `crates/ec-av1/src/stream.rs:7259..` -- gate rewritten: three arms
30+ (single tile / `--tile-columns=1` at 128x64 / `--tile-rows=1` at 64x128),
31+ each needing 4 firing + pixel-exact runs; `tile_hits()` delta >= 2 asserted
32+ on the tile arms (gate-blind-to-feature); the `Err` arm now ASSERTS the
33+ message starts with `unsupported: ` -- any other decode error panics
34+ instead of counting as a tolerated refusal; the fixture's `noise` filter
35+ carries `all_seed={seed}`.
36+- `lanes/sub8-r5.report.md:45` -- the deleted refusal string named correctly
37+ ("a partition below 8x8 ...").
38+
39+## Gate
40+
41+`EC_AV1_REQUIRE_AOMENC=1 cargo test -p ec-av1 --lib sub8` -> **ok, 1 passed**
42+(3 arms x 4 firing+pixel-exact runs).
43+
44+Regression value proved by reverting only the guard+reset hunks: the same gate
45+FAILS (`U vs ffmpeg (seed=139 cq=12)`, stream.rs:7394) -- so this gate catches
46+the defect, it is not a pass-by-construction arm.
47+
48+EVIDENCE: <scratchpad>/bad207.obu (sha256 0f78db8b...), bad228.obu (sha256 6a73db99...) | `decode_probe <obu> out.yuv` + `ffmpeg -i <obu> -f rawvideo -pix_fmt yuv420p` on this branch | both 12288/12288 bytes equal (verifier's pre-fix .mine.yuv: 221 and 158 differing bytes, all at x>=64)
49+EVIDENCE: gate run above | 3-arm gate incl. --tile-columns=1 / --tile-rows=1, tile_hits delta >= 2 asserted | ok; with the guard+reset hunks reverted the same gate FAILS at seed=139 cq=12 (U plane)
50+EVIDENCE: <scratchpad>/reelb_r6.obu | `ffmpeg -t 0.4 -c:v copy -f obu` from the ReelB film, `decode_probe` on this branch | REFUSED at "a HORZ/VERT partition below 8x8 (... 4x8/8x4 need a real rectangular transform)" -- unchanged from r5, and past main's "a partition below 8x8"
51+EVIDENCE: fixture reproducibility | the gate's lavfi source (seed 207, 128x64) rendered twice with and without `all_seed=207` | with: d3c4b3e3... both runs; without: 5619b3ee... both runs -- ffmpeg's `noise` was in fact deterministic in this pair of runs, `all_seed` pins it explicitly rather than relying on that
52+
53+## Refusals
54+None lifted, none added this round; `refusal_inventory` and `gate_coverage`
55+stay green (totals below).
56+
57+## Suite
58+`EC_AV1_REQUIRE_AOMENC=1 cargo test -p ec-av1 --lib`: SUITE_TOTALS
59+
60+## Open / disposition
61+- deferred(an inter lane) -- `decode.rs:8547-8548` (`up_available`/
62+ `left_available` in the inter path) and `mvstack.rs:727,733,742,756,1486,
63+ 1492,1501,1515` still use frame-relative `mi_row > 0` / `mi_col > 0` where
64+ libaom uses `tile->mi_row_start`/`mi_col_start`. Same shape as this round's
65+ defect but in code this lane never touched and no intra gate reaches;
66+ unblocked by a multi-tile INTER gate.
67+- deferred(an inter-frame gate whose chroma neighbour codes a smooth
68+ `uv_mode`) -- carried from r5: `decode.rs:12084,12096` still pass a
69+ hardcoded `false` chroma edge-filter type.
70+- accepted: `smooth_uv_neighbour` falls back to the coarse `SUB` slot when no
71+ block recorded the exact neighbouring mi.