forge
Explore
Log in

Don't you dare go Hollow

The chroma edge-filter neighbour is tile-relative on its coarse fallback too

Browse files at this commit

db2b6f76b4cba6b91fae17b6aa72a89531be8b2dAhmet Kaan GümüşParent: 5b07c13
  • fix
    • the chroma edge-filter neighbour is tile-relative on its coarse fallback too
Show full message
fix(av1): the chroma edge-filter neighbour is tile-relative on its coarse fallback too

smooth_uv_neighbour's mi-exact uv_mode maps were tile-guarded but their coarse
fallbacks (above_uv_mode/left_uv_mode) were not, and above_uv_mode is the one
above_* band start_tile never clears. The first block of a tile ROW therefore
filtered its chroma edge at the strength of the block above it in the TILE
ABOVE, where libaom has above_mbmi == NULL: multi_tile_intra seed 46 frame 0,
chroma x[120..127] y[32..37] (luma 240,64 -- the bottom-right tile's first
block) off by 1..2 in U and V with luma bit-exact. Visible only since the
palette2 merge, which lifted the refusal that used to swallow that seed.

New uv_tile_edge_suppressed_hits() counts reads suppressed at a non-frame tile
edge whose coarse slot held a non-DC mode; the 2x2-tile intra gate (the only
arm with a tile row boundary) asserts it >= 1 and now decodes 6/6 pixel-exact.
crates/ec-av1/src/decode.rsmodified+37 -4
@@ -1627,6 +1627,23 @@ pub(crate) fn uv_mode_mi_override_hits() -> usize {
1627 UV_MODE_MI_OVERRIDE_HITS.with(|c| c.get())1627 UV_MODE_MI_OVERRIDE_HITS.with(|c| c.get())
1628 }1628 }
1629 1629
1630+// lane-mtfix r1: how many times a chroma intra-edge filter-type read was
1631+// suppressed at a TILE edge that is not a frame edge -- the above/left
1632+// `uv_mode` neighbour of a block on a tile's first mi row/column lives in
1633+// another tile, so libaom's `above_mbmi`/`left_mbmi` are NULL there. The
1634+// coarse [`SUB`] maps are frame-sized and (`above_uv_mode`) not cleared per
1635+// tile, so without the guard in [`Neighbours::smooth_uv_neighbour`] the tile
1636+// above would decide this tile's chroma edge filter strength.
1637+thread_local! {
1638+ static UV_TILE_EDGE_SUPPRESSED_HITS: std::cell::Cell<usize> =
1639+ const { std::cell::Cell::new(0) };
1640+}
1641+
1642+/// Current value of [`UV_TILE_EDGE_SUPPRESSED_HITS`].
1643+pub(crate) fn uv_tile_edge_suppressed_hits() -> usize {
1644+ UV_TILE_EDGE_SUPPRESSED_HITS.with(|c| c.get())
1645+}
1646+
1630 // lane-cfl r1 gate counters: `UV_CFL_PRED` blocks (every `cfl_alpha_signs`1647 // lane-cfl r1 gate counters: `UV_CFL_PRED` blocks (every `cfl_alpha_signs`
1631 // read) and chroma blocks with a NONZERO `angle_delta_uv` -- the two block1648 // read) and chroma blocks with a NONZERO `angle_delta_uv` -- the two block
1632 // shapes the r1 chroma defect showed up on.1649 // shapes the r1 chroma defect showed up on.
@@ -4048,13 +4065,29 @@ impl Neighbours {
4048 /// planes 1/2. Falls back to the coarse [`SUB`] slot on whichever axis no4065 /// planes 1/2. Falls back to the coarse [`SUB`] slot on whichever axis no
4049 /// block has recorded the exact neighbouring mi.4066 /// block has recorded the exact neighbouring mi.
4050 fn smooth_uv_neighbour(&self, mi_r: usize, mi_c: usize, r: usize, c: usize) -> bool {4067 fn smooth_uv_neighbour(&self, mi_r: usize, mi_c: usize, r: usize, c: usize) -> bool {
4068+ // lane-mtfix r1: availability is TILE-relative on BOTH axes and on the
4069+ // coarse fallback too. `above_uv_mode` is a frame-wide [`SUB`]-grid
4070+ // array that `start_tile` does not clear, so a block on a tile's first
4071+ // mi row used to read the uv_mode of the block above it in the tile
4072+ // ABOVE and filter its chroma edge at that neighbour's strength
4073+ // (2x2-tile intra gate, seed 46: chroma-only +-1..2 over the 8x8 block
4074+ // at chroma (120, 32), the top-right tile's first block).
4075+ let have_above = mi_r > self.tile_row0_mi;
4076+ let have_left = mi_c > self.tile_col0_mi;
4077+ if self.tile_row0_mi > 0 && !have_above && self.above_uv_mode[c] != DC_PRED
4078+ || self.tile_col0_mi > 0 && !have_left && self.left_uv_mode[r] != DC_PRED
4079+ {
4080+ UV_TILE_EDGE_SUPPRESSED_HITS.with(|h| h.set(h.get() + 1));
4081+ }
4051 let above = match self.uv_mode_col.get(mi_c) {4082 let above = match self.uv_mode_col.get(mi_c) {
4052- Some(&(row, m)) if mi_r > self.tile_row0_mi && row == mi_r - 1 => m,4083+ Some(&(row, m)) if have_above && row == mi_r - 1 => m,
4053- _ => self.above_uv_mode[c],4084+ _ if have_above => self.above_uv_mode[c],
4085+ _ => DC_PRED,
4054 };4086 };
4055 let left = match self.uv_mode_row.get(mi_r) {4087 let left = match self.uv_mode_row.get(mi_r) {
4056- Some(&(col, m)) if mi_c > self.tile_col0_mi && col == mi_c - 1 => m,4088+ Some(&(col, m)) if have_left && col == mi_c - 1 => m,
4057- _ => self.left_uv_mode[r],4089+ _ if have_left => self.left_uv_mode[r],
4090+ _ => DC_PRED,
4058 };4091 };
4059 // lane-cfl r1 counter: how often the mi-exact chroma neighbour differs4092 // lane-cfl r1 counter: how often the mi-exact chroma neighbour differs
4060 // from the coarse [`SUB`] slot -- i.e. how often a chroma edge would4093 // from the coarse [`SUB`] slot -- i.e. how often a chroma edge would
crates/ec-av1/src/stream.rsmodified+27 -10
@@ -16978,6 +16978,7 @@ mod tests {
16978 let expected_tiles = (1usize << tile_cols_log2) * (1usize << tile_rows_log2);16978 let expected_tiles = (1usize << tile_cols_log2) * (1usize << tile_rows_log2);
16979 let mut matched = 0u32;16979 let mut matched = 0u32;
16980 let mut named_refusals = 0u32;16980 let mut named_refusals = 0u32;
16981+ let mut uv_edge_suppressed = 0usize;
16981 let n_attempts: u32 = std::env::var("EC_TILES_GATE_ATTEMPTS")16982 let n_attempts: u32 = std::env::var("EC_TILES_GATE_ATTEMPTS")
16982 .ok()16983 .ok()
16983 .and_then(|s| s.parse().ok())16984 .and_then(|s| s.parse().ok())
@@ -17129,6 +17130,7 @@ mod tests {
17129 17130
17130 let before = crate::decode::tile_hits();17131 let before = crate::decode::tile_hits();
17131 let pal_before = crate::decode::palette_tile_left_hits();17132 let pal_before = crate::decode::palette_tile_left_hits();
17133+ let uv_edge_before = crate::decode::uv_tile_edge_suppressed_hits();
17132 let frames = match decode_stream(&stream) {17134 let frames = match decode_stream(&stream) {
17133 Err(e) => {17135 Err(e) => {
17134 let msg = e.to_string();17136 let msg = e.to_string();
@@ -17176,6 +17178,13 @@ mod tests {
17176 (seed {seed})"17178 (seed {seed})"
17177 );17179 );
17178 }17180 }
17181+ // lane-mtfix r1: the chroma edge-filter neighbour of a block on a
17182+ // tile's first mi row/column lives in the tile above/left, where
17183+ // libaom has no neighbour at all. This counts the reads suppressed
17184+ // there whose frame-wide coarse slot held a non-DC mode -- the
17185+ // reads that would otherwise pick the wrong chroma edge filter
17186+ // strength (they did, before this fix: seed 46 of this gate).
17187+ uv_edge_suppressed += crate::decode::uv_tile_edge_suppressed_hits() - uv_edge_before;
17179 matched += 1;17188 matched += 1;
17180 }17189 }
17181 assert!(17190 assert!(
@@ -17183,22 +17192,30 @@ mod tests {
17183 "{name}: every attempt refused ({named_refusals}); the gate never decoded a \17192 "{name}: every attempt refused ({named_refusals}); the gate never decoded a \
17184 multi-tile stream with the coding tools on"17193 multi-tile stream with the coding tools on"
17185 );17194 );
17186- eprintln!("{name}: {matched} pixel-exact matches, {named_refusals} named refusals");17195+ eprintln!(
17196+ "{name}: {matched} pixel-exact matches, {named_refusals} named refusals, \
17197+ {uv_edge_suppressed} chroma edge reads suppressed at a tile edge"
17198+ );
17187 }17199 }
17188 17200
17189 #[test]17201 #[test]
17190 fn a_real_aomenc_multi_tile_intra_stream_decodes_pixel_exact() {17202 fn a_real_aomenc_multi_tile_intra_stream_decodes_pixel_exact() {
17191- run_multi_tile_gate(17203+ const NAME: &str = "a_real_aomenc_multi_tile_intra_stream_decodes_pixel_exact";
17192- "a_real_aomenc_multi_tile_intra_stream_decodes_pixel_exact",17204+ let before = crate::decode::uv_tile_edge_suppressed_hits();
17193- 1,17205+ run_multi_tile_gate(NAME, 1, 1, 8, 1, &[], false, None);
17194- 1,17206+ // lane-mtfix r1: this is the only arm with a tile ROW boundary, so it
17195- 8,17207+ // is the one that exercises the tile-relative guard on the chroma
17196- 1,17208+ // edge-filter neighbour. Without the guard, seed 46's first block of
17197- &[],17209+ // the bottom-right tile read the tile ABOVE it and mis-filtered its
17198- false,17210+ // chroma edge (U/V off by 1..2 over chroma x[120..127] y[32..37]).
17199- None,17211+ if have_ffmpeg() && have_aomenc() {
17212+ assert!(
17213+ crate::decode::uv_tile_edge_suppressed_hits() > before,
17214+ "{NAME}: no chroma edge-filter neighbour read was suppressed at a tile edge -- \
17215+ the tile-relative guard is untested by this gate"
17200 );17216 );
17201 }17217 }
17218+ }
17202 17219
17203 #[test]17220 #[test]
17204 fn a_real_aomenc_multi_tile_intra_10bit_stream_decodes_pixel_exact() {17221 fn a_real_aomenc_multi_tile_intra_10bit_stream_decodes_pixel_exact() {
lanes/mtfix-r1.report.mdadded+80 -0
@@ -0,0 +1,80 @@
1+# lane-mtfix r1 — the multi-tile intra gate's U-plane failure on main 11633d7
2+
3+## What was wrong
4+
5+`Neighbours::smooth_uv_neighbour` (`crates/ec-av1/src/decode.rs`) decides the chroma
6+intra-edge filter strength from the above/left `uv_mode` neighbour (libaom
7+`get_intra_edge_filter_type`, reconintra.c). Its mi-exact maps (`uv_mode_col`/`uv_mode_row`)
8+were tile-guarded, but the COARSE fallbacks were not: on a miss it read
9+`above_uv_mode[c]` / `left_uv_mode[r]` unconditionally. `above_uv_mode` is a frame-wide
10+`SUB`-grid array and is the ONE `above_*` band `start_tile` never clears (checked by
11+enumerating the struct's `above_*` fields against `start_tile`'s reset list:
12+`above_txfm` and `above_palette_*` are missing from the reset too, but every reader of
13+those is already guarded by `mi_r > tile_row0_mi` / `mi_c > tile_col0_mi`).
14+
15+So the first block of a tile ROW read the `uv_mode` of the block above it **in the tile
16+above**, where libaom has `above_mbmi == NULL`, and filtered its chroma edge at the wrong
17+strength — luma untouched.
18+
19+This is class `new-map-ignores-tile-edge`. It was not a regression of working code: at
20+56ea250 seed 46 REFUSED (`palette syntax is consumed for square blocks only`); the
21+palette2 merge lifted that refusal and the defect behind it became visible
22+(class `refusal-hides-a-defect`).
23+
24+## Bisect
25+
26+| commit | gate `a_real_aomenc_multi_tile_intra_stream_decodes_pixel_exact` |
27+|---|---|
28+| 56ea250 (lane-ab16 merge) | ok — 5 pixel-exact matches, **1 named refusal at seed 46** |
29+| 11633d7 (lane-palette2 merge, main) | FAILED — frame 0 U vs ffmpeg, seed 46 |
30+| this branch | ok — 6 pixel-exact matches, 0 refusals, 4 tile-edge suppressions |
31+
32+EVIDENCE: $HOME/.cache/mtfix-ab16.log, $HOME/.cache/mtfix-gate1.log, $HOME/.cache/mtfix-gate2.log | ran the one gate in a detached worktree at 56ea250 and in the lane worktree at 11633d7 | pass w/ seed-46 refusal vs FAILED U plane
33+
34+## First wrong block
35+
36+`EC_AV1_GATE_DUMP` pinned the seed-46 stream (166 bytes, 256x128, `cols=2 rows=2`); ours
37+vs the oracle's `EC_AV1_PREFILT_DUMP` frame 0:
38+
39+* Y: 0 differing samples.
40+* U: 14 samples, V: 17 samples, all inside chroma x[120..127] y[32..37], magnitude 1..2.
41+* That is the 8x8 chroma / 16x16 luma block at luma (240, 64) — the FIRST block of the
42+ bottom-right tile (tile row boundary y=64, tile column boundary x=128), i.e. exactly a
43+ tile's top edge. Reconstruction was already wrong pre-loop-filter.
44+
45+EVIDENCE: /tmp/claude-1000/-home-user-Documents-Code-Rust-edith-codecs/b6d8a07f-96a4-4bbb-b378-af9ae25cf7c9/scratchpad/mtfix/{ours,ref}.f0 | decode_probe + aomdec, both under EC_AV1_PREFILT_DUMP, on the pinned seed-46 stream | Y diff 0, U diff 14 / V diff 17, bbox chroma x[120..127] y[32..37]
46+
47+## Fix
48+
49+`crates/ec-av1/src/decode.rs` `smooth_uv_neighbour`: availability is tile-relative on both
50+axes and on the coarse fallback too (`have_above = mi_r > tile_row0_mi`,
51+`have_left = mi_c > tile_col0_mi`); no neighbour ⇒ `DC_PRED` (not smooth), which is what
52+libaom's NULL `above_mbmi`/`left_mbmi` gives. Guarding the READ rather than adding
53+`above_uv_mode` to `start_tile`'s reset also covers the left axis and leaves the leak
54+observable, which is what the new counter counts.
55+
56+`crates/ec-av1/src/decode.rs` `uv_tile_edge_suppressed_hits()`: counts reads suppressed at
57+a tile edge that is not a frame edge AND whose coarse slot held a non-DC mode — i.e. reads
58+that would have picked the wrong filter strength.
59+
60+`crates/ec-av1/src/stream.rs` `run_multi_tile_gate` reports the per-gate delta, and
61+`a_real_aomenc_multi_tile_intra_stream_decodes_pixel_exact` (the only arm with a tile ROW
62+boundary) HARD-ASSERTS it is ≥ 1.
63+
64+Mutation: the un-guarded code IS main 11633d7, and that tree fails this gate at seed 46
65+(row 2 of the bisect table above).
66+
67+## Gates
68+
69+* `cargo test -p ec-av1 --lib multi_tile cfl chroma_edge palette ab_partitions filter_intra refusal_inventory gate_coverage`: 31 passed, 0 failed, 3 ignored.
70+ Counters: intra 2x2 gate 6/6 matches, 4 tile-edge suppressions; 10-bit (4x1 tiles) and
71+ palette (2x1) arms report 0 — they have no tile row boundary, and the left band resets
72+ every SB row, so there is nothing to suppress there.
73+* Full suite (`systemd-run` unit, log `$HOME/.cache/mtfix-suite.log`): **339 passed, 0 failed, 31 ignored**.
74+
75+## Residue
76+
77+* `above_txfm`, `above_palette_size`, `above_palette_colors`, `above_palette_uv_*` are still
78+ absent from `start_tile`'s reset list — accepted: every reader of them is tile-guarded
79+ (decode.rs:3411/3422/3505/4837/4838/9149/9150), so the arrays are dead across a tile edge.
80+ COMMON's "reset in start_tile" rule would add 4 more loops for no behavioural change.