forge
Explore
Log in

Don't you dare go Hollow

The chroma edge-filter type reads the mi grid's uv_mode, not a one-slot-per-column map

Browse files at this commit

f6d6eda40c3868ba51065b056a9ec9f01fbb6750Ahmet Kaan GümüşParent: 7f33a5e
  • fix
    • the chroma edge-filter type reads the mi grid's uv_mode, not a one-slot-per-column map
Show full message
fix(av1): the chroma edge-filter type reads the mi grid's uv_mode, not a one-slot-per-column map

get_intra_edge_filter_type takes the above/left uv_mode of the CHROMA
neighbour mi (libaom set_mi_row_col: chroma_above_mbmi = base_mi[-stride]),
and libaom writes one MB_MODE_INFO into every mi cell a block covers. Our
neighbour band kept a single (last_row, uv_mode) slot per mi column, so a
sub-8x8 pair's own first (non-chroma-ref) half stamped its DC_PRED over that
column before the pair's chroma-ref half -- which snaps its read to the base
(even) column -- looked at it: the mi-exact match failed and the coarse 16x16
band answered DC where a SMOOTH_PRED chroma block really sat one mi row above.
The edge-filter type flipped 1 -> 0, changing the chroma edge filter/upsample
decision: chroma-only +-1..3, luma bit-exact.

Adds a full mi-granular uv_mode grid (superblock-padded, per frame, tile
availability unchanged) read first, with the old maps kept as the fallback for
cells no block has written, plus counter uv_mode_grid_override_hits.

10-bit 3840x1608 10 s head: 66 of 241 decode frames differed (first 161, worst
199 B) -> 0 of 241 byte-exact vs instrumented aomdec. 10-bit 1920x792 cut:
134 of 275 differed (worst 2410 B, the 1942 B chroma-only intra-in-inter frame
included) -> 5, worst 3 B. Second 1920x792 cut unchanged (36 frames, 1-13 B,
the open bottom-edge MC residue).
crates/ec-av1/src/decode.rsmodified+66 -2
@@ -2597,6 +2597,20 @@ pub(crate) fn uv_mode_mi_override_hits() -> usize {
2597 UV_MODE_MI_OVERRIDE_HITS.with(|c| c.get())2597 UV_MODE_MI_OVERRIDE_HITS.with(|c| c.get())
2598 }2598 }
2599 2599
2600+// lane-t900 r12: how many chroma edge-filter-type reads took their above/left
2601+// `uv_mode` from the mi GRID where the one-slot-per-column map would have
2602+// answered differently -- the sub-8x8 pair case where the pair's own first
2603+// half had already overwritten the column slot the chroma-ref half reads.
2604+thread_local! {
2605+ static UV_MODE_GRID_OVERRIDE_HITS: std::cell::Cell<usize> =
2606+ const { std::cell::Cell::new(0) };
2607+}
2608+
2609+/// Current value of [`UV_MODE_GRID_OVERRIDE_HITS`].
2610+pub fn uv_mode_grid_override_hits() -> usize {
2611+ UV_MODE_GRID_OVERRIDE_HITS.with(|c| c.get())
2612+}
2613+
2600 // lane-t900 r8: how many intra edge-filter-type reads (luma + chroma) the2614 // lane-t900 r8: how many intra edge-filter-type reads (luma + chroma) the
2601 // INTER neighbour stamp saved: the coarse SUB band still held a SMOOTH mode2615 // INTER neighbour stamp saved: the coarse SUB band still held a SMOOTH mode
2602 // from an earlier block in that pixel row/column while the mi-exact map --2616 // from an earlier block in that pixel row/column while the mi-exact map --
@@ -4633,6 +4647,18 @@ struct Neighbours {
4633 /// the leaf above writes the same row slot the block to the left owns.4647 /// the leaf above writes the same row slot the block to the left owns.
4634 uv_mode_col: Vec<(usize, usize)>,4648 uv_mode_col: Vec<(usize, usize)>,
4635 uv_mode_row: Vec<(usize, usize)>,4649 uv_mode_row: Vec<(usize, usize)>,
4650+ /// Every mi cell's own `uv_mode`, the mi grid libaom's
4651+ /// `chroma_above_mbmi`/`chroma_left_mbmi` read directly (`set_mi_row_col`,
4652+ /// blockd.h). lane-t900 r12: the one-slot-per-column
4653+ /// `uv_mode_col`/`uv_mode_row` maps above hold only the LAST block written
4654+ /// in that column, so a sub-8x8 pair's own first (non-chroma-ref) half
4655+ /// overwrote the row the pair's chroma-ref half then wanted to read --
4656+ /// the mi-exact match failed and the coarse [`SUB`] band answered instead.
4657+ /// `u8::MAX` = no block has written this cell yet (fall back to the maps).
4658+ uv_mode_grid: Vec<u8>,
4659+ /// [`Self::uv_mode_grid`]'s stride, in mi units (superblock-padded, like
4660+ /// every other band here).
4661+ uv_grid_cols: usize,
4636 /// Whether the block above/left of this column/row was coded `skip` --4662 /// Whether the block above/left of this column/row was coded `skip` --
4637 /// an inter frame's own `skip` context (spec `SkipContext`), which the4663 /// an inter frame's own `skip` context (spec `SkipContext`), which the
4638 /// key-frame writer never tracks (its skip context is always zero); a4664 /// key-frame writer never tracks (its skip context is always zero); a
@@ -4811,6 +4837,8 @@ impl Neighbours {
4811 sub8_mode_row: vec![(usize::MAX, 0); rows * (SUB / MI)],4837 sub8_mode_row: vec![(usize::MAX, 0); rows * (SUB / MI)],
4812 uv_mode_col: vec![(usize::MAX, 0); cols * (SUB / MI)],4838 uv_mode_col: vec![(usize::MAX, 0); cols * (SUB / MI)],
4813 uv_mode_row: vec![(usize::MAX, 0); rows * (SUB / MI)],4839 uv_mode_row: vec![(usize::MAX, 0); rows * (SUB / MI)],
4840+ uv_mode_grid: vec![u8::MAX; cols * (SUB / MI) * rows * (SUB / MI)],
4841+ uv_grid_cols: cols * (SUB / MI),
4814 above_txfm: vec![TXFM_CTX_INIT; cols * (SUB / MI)],4842 above_txfm: vec![TXFM_CTX_INIT; cols * (SUB / MI)],
4815 left_txfm: vec![TXFM_CTX_INIT; rows * (SUB / MI)],4843 left_txfm: vec![TXFM_CTX_INIT; rows * (SUB / MI)],
4816 // lane-inter8 r2: mi(4px)-granular, not [`SUB`]-granular -- an4844 // lane-inter8 r2: mi(4px)-granular, not [`SUB`]-granular -- an
@@ -5749,6 +5777,18 @@ impl Neighbours {
5749 *slot = (last_c, uv_mode);5777 *slot = (last_c, uv_mode);
5750 }5778 }
5751 }5779 }
5780+ // libaom writes one `MB_MODE_INFO` pointer into every mi cell a block
5781+ // covers, so the chroma neighbour read below is a plain grid read.
5782+ let stride = self.uv_grid_cols;
5783+ for row in mi_r..=last_r {
5784+ for col in mi_c..=last_c {
5785+ if col < stride
5786+ && let Some(cell) = self.uv_mode_grid.get_mut(row * stride + col)
5787+ {
5788+ *cell = uv_mode as u8;
5789+ }
5790+ }
5791+ }
5752 }5792 }
5753 5793
5754 /// Whether either mi-exact chroma neighbour of the block at `(mi_r, mi_c)`5794 /// Whether either mi-exact chroma neighbour of the block at `(mi_r, mi_c)`
@@ -5801,16 +5841,34 @@ impl Neighbours {
5801 {5841 {
5802 UV_TILE_EDGE_SUPPRESSED_HITS.with(|h| h.set(h.get() + 1));5842 UV_TILE_EDGE_SUPPRESSED_HITS.with(|h| h.set(h.get() + 1));
5803 }5843 }
5844+ // The mi grid is libaom's own read; the two maps below stay as the
5845+ // fallback for cells no block has written (see [`Self::uv_mode_grid`]).
5846+ let cell = |grid: &Vec<u8>, row: usize, col: usize| -> Option<usize> {
5847+ (col < self.uv_grid_cols)
5848+ .then(|| grid.get(row * self.uv_grid_cols + col).copied())
5849+ .flatten()
5850+ .filter(|&m| m != u8::MAX)
5851+ .map(usize::from)
5852+ };
5804 let above = match self.uv_mode_col.get(mi_c) {5853 let above = match self.uv_mode_col.get(mi_c) {
5854+ _ if have_above && let Some(m) = cell(&self.uv_mode_grid, mi_r - 1, mi_c) => m,
5805 Some(&(row, m)) if have_above && row == mi_r - 1 => m,5855 Some(&(row, m)) if have_above && row == mi_r - 1 => m,
5806 _ if have_above => self.above_uv_mode[c],5856 _ if have_above => self.above_uv_mode[c],
5807 _ => DC_PRED,5857 _ => DC_PRED,
5808 };5858 };
5809 let left = match self.uv_mode_row.get(mi_r) {5859 let left = match self.uv_mode_row.get(mi_r) {
5860+ _ if have_left && let Some(m) = cell(&self.uv_mode_grid, mi_r, mi_c - 1) => m,
5810 Some(&(col, m)) if have_left && col == mi_c - 1 => m,5861 Some(&(col, m)) if have_left && col == mi_c - 1 => m,
5811 _ if have_left => self.left_uv_mode[r],5862 _ if have_left => self.left_uv_mode[r],
5812 _ => DC_PRED,5863 _ => DC_PRED,
5813 };5864 };
5865+ if have_above && cell(&self.uv_mode_grid, mi_r - 1, mi_c).is_some_and(|m| {
5866+ !matches!(self.uv_mode_col.get(mi_c), Some(&(row, cm)) if row == mi_r - 1 && cm == m)
5867+ }) || have_left && cell(&self.uv_mode_grid, mi_r, mi_c - 1).is_some_and(|m| {
5868+ !matches!(self.uv_mode_row.get(mi_r), Some(&(col, cm)) if col == mi_c - 1 && cm == m)
5869+ }) {
5870+ UV_MODE_GRID_OVERRIDE_HITS.with(|h| h.set(h.get() + 1));
5871+ }
5814 // lane-cfl r1 counter: how often the mi-exact chroma neighbour differs5872 // lane-cfl r1 counter: how often the mi-exact chroma neighbour differs
5815 // from the coarse [`SUB`] slot -- i.e. how often a chroma edge would5873 // from the coarse [`SUB`] slot -- i.e. how often a chroma edge would
5816 // have been filtered at the wrong strength by the coarse map alone.5874 // have been filtered at the wrong strength by the coarse map alone.
@@ -18109,7 +18167,10 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
18109 // in reconstruction (this dump) vs is introduced by the loop filter18167 // in reconstruction (this dump) vs is introduced by the loop filter
18110 // (EC_AV1_DECODE_ORDER_DUMP's post-filter dump).18168 // (EC_AV1_DECODE_ORDER_DUMP's post-filter dump).
18111 // Decode-order frame marker for the EC_OBMC / EC_TRACE_MODE ladders.18169 // Decode-order frame marker for the EC_OBMC / EC_TRACE_MODE ladders.
18112- if std::env::var_os("EC_OBMC").is_some() || std::env::var_os("EC_TRACE_MODE").is_some() {18170+ if std::env::var_os("EC_OBMC").is_some()
18171+ || std::env::var_os("EC_TRACE_MODE").is_some()
18172+ || std::env::var_os("EC_PRED").is_some()
18173+ {
18113 eprintln!(18174 eprintln!(
18114 "EC_PICT idx={}",18175 "EC_PICT idx={}",
18115 PREFILT_PICTURE_IDX.load(std::sync::atomic::Ordering::SeqCst)18176 PREFILT_PICTURE_IDX.load(std::sync::atomic::Ordering::SeqCst)
@@ -29677,7 +29738,10 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
29677 // in reconstruction (this dump) vs is introduced by the loop filter29738 // in reconstruction (this dump) vs is introduced by the loop filter
29678 // (EC_AV1_DECODE_ORDER_DUMP's post-filter dump).29739 // (EC_AV1_DECODE_ORDER_DUMP's post-filter dump).
29679 // Decode-order frame marker for the EC_OBMC / EC_TRACE_MODE ladders.29740 // Decode-order frame marker for the EC_OBMC / EC_TRACE_MODE ladders.
29680- if std::env::var_os("EC_OBMC").is_some() || std::env::var_os("EC_TRACE_MODE").is_some() {29741+ if std::env::var_os("EC_OBMC").is_some()
29742+ || std::env::var_os("EC_TRACE_MODE").is_some()
29743+ || std::env::var_os("EC_PRED").is_some()
29744+ {
29681 eprintln!(29745 eprintln!(
29682 "EC_PICT idx={}",29746 "EC_PICT idx={}",
29683 PREFILT_PICTURE_IDX.load(std::sync::atomic::Ordering::SeqCst)29747 PREFILT_PICTURE_IDX.load(std::sync::atomic::Ordering::SeqCst)
lanes/t900-r12.handoff.mdadded+104 -0
@@ -0,0 +1,104 @@
1+# lane-t900 r12 handoff -- the chroma edge-filter type read a one-slot-per-column uv_mode map; a sub-8x8 pair overwrote its own neighbour row
2+
3+Tip: `2b65cb8e+` on `lane-t900` (base: main `2b65cb8e`, fast-forwarded in before any edit).
4+
5+## Target A -- 4K 10 s head, decode frame 161: ROOT CAUSE FOUND AND FIXED
6+
7+Stage split first (r11 method rule), BEFORE reading any prediction code:
8+`EC_AV1_PREFILT_DUMP16` on both decoders over a 250-OBU / 168-decode-frame cut of the
9+10 s head (`~/.cache/t900-tmp/reelb250.obu`) -- the mismatch is already in RECONSTRUCTION
10+(pre-filter), frames 161 and 162 only, and it is **CHROMA ONLY, luma bit-exact**:
11+
12+ f161 U 37 px, V 22 px, deltas -3..+3, in three anti-diagonal triangles at
13+ chroma (856,160), (1080,252), (1088,696)
14+
15+Block: chroma (856,160) = luma mi(80,429), a 4x8 luma leaf (PARTITION_VERT of an 8x8),
16+i.e. the CHROMA-REFERENCE half of a sub-8x8 pair. `EC_PRED` on both decoders
17+(ours needs `EC_PICT` under `EC_PRED`, added this round, decode.rs:29684 -- the second
18+of the two EC_PICT sites is the inter-frame one):
19+
20+ aomdec EC_PRED mi_row=80 mi_col=429 plane=1 txw=4 txh=4 mode=3 p_angle=45
21+ have_top=1 have_left=1 n_top=4 n_left=4 n_tr=4 n_bl=-1 bsize=3 part=2 ft=1
22+ EC_PREDOUT sum=8355 row0=514,521,523,523
23+ ours OUR_PRED x=856 y=160 side=4 mode=3 ad=0 ft=0 sum=8358 row0=[514,524,522,523]
24+
25+One field: `ft` (intra_edge_filter_type) 1 vs 0. Same mode, same angle, same edges.
26+
27+Root cause (`decode.rs` `Neighbours::smooth_uv_neighbour_unsnapped`): libaom reads the
28+chroma neighbours straight off the mi grid (`chroma_above_mbmi = base_mi[-stride]`,
29+`set_mi_row_col`), where every mi cell a block covers holds that block's `uv_mode`.
30+Ours kept only ONE slot per mi column (`uv_mode_col[col] = (last_row, uv_mode)`), so
31+inside a sub-8x8 pair the pair's own FIRST half (mi(80,428), non-chroma-ref, stamps
32+DC_PRED over mi rows 80..81) overwrote column 428 before the pair's chroma-ref half
33+(mi(80,429), which snaps its neighbour read to base column 428) read it. The mi-exact
34+match `row == mi_r - 1` then failed and the coarse SUB-grid band answered DC instead of
35+the SMOOTH_PRED chroma block really sitting at mi(79,428) -- `ft` 1 -> 0, which flips
36+`av1_use_intra_edge_upsample`/filter strength on the chroma edge.
37+
38+Fix: `uv_mode_grid`, a full mi-granular `uv_mode` grid (superblock-padded stride
39+`uv_grid_cols`, `u8::MAX` = unwritten) written by `record_uv_mode_mi` over every cell a
40+block covers and read first by `smooth_uv_neighbour_unsnapped`; the two old maps stay as
41+the fallback for unwritten cells, so no existing path changes answer unless the grid
42+knows better. Availability stays tile-relative (`mi_r > tile_row0_mi` /
43+`mi_c > tile_col0_mi`, untouched); the grid is per-frame (`Neighbours::new`).
44+New counter `ec_av1::decode::uv_mode_grid_override_hits()`.
45+
46+Measured (cmp.sh = `EC_AV1_FINAL_DUMP` both decoders, byte compare per decode frame):
47+
48+| stream | before r12 | after r12 |
49+|---|---|---|
50+| 4K 10 s head, 168-frame cut `reelb250.obu` | 2 differ (f161 60 B, f162 72 B) | **0 of 168** |
51+| 4K 10 s head, full `~/.cache/hg-0-10s.obu` (241 f) | 66 differ, first 161, worst 199 B | **0 of 241** |
52+| 1080p @5400 cut (275 f) | 134 differ, first 61, f113 1942 B, worst 2410 B | **5 differ, first 61, worst 3 B (f63)** |
53+| 1080p @900 cut (267 f) | 36 differ, first 41, worst 13 B | 36 / 41 / 13 (unchanged) |
54+
55+## Target B -- 1080p @5400 f113 (1942 B, chroma-only intra in an inter frame): FIXED BY A
56+
57+Same root cause, same fix: f113 is byte-exact now, and the cut went 134 -> 5 differing
58+frames, worst 2410 B -> 3 B. The r11 charter premise (CfL / chroma DC ctx / the r8
59+DC_PRED stamp being wrong on the chroma side) was NOT the defect -- the stamp is right
60+(an inter neighbour must read as not-smooth for chroma); what was wrong is WHICH cell
61+the read landed on. Residue on that cut: 5 frames, 1-3 B each (f61, f63, f136, f174,
62+f236) -- same 1-3 B shape as target C, unmeasured this round.
63+
64+## Target C -- 1-3 B bottom-edge residue on the @900 cut: UNTOUCHED, premise narrowed
65+
66+36 frames, first 41, worst 13 B; unchanged by A. Not started this round beyond reading
67+the reference-clamp path on both sides:
68+* ours `mc::sample` clamps every tap to `true_width/true_height`, which
69+ `decode.rs:16238` sets to the MI-ALIGNED size (`mi_cols*4`, `mi_rows*4`), halved for
70+ chroma;
71+* libaom clamps via `extend_mc_border` -> `build_mc_border(..., pre_buf->width,
72+ pre_buf->height)` and `setup_pred_plane` fills those from the CROP dims
73+ (`uv_crop_width/height`).
74+For 1920x792: MiRows 198 -> aligned 792 == crop 792, chroma 396 == 396, so
75+aligned-vs-crop CANNOT be the explanation on this stream (r11 said the same; now read
76+off both sources). Next step is the tap-row rung as chartered: `EC_MC_CALL` already
77+exists on our side (`mc.rs:380`, prints x_q4/y_q4/xfrac/yfrac/tw/th/stride); add the
78+matching rung in `dec_calc_subpel_params` / `update_extend_mc_border_params`
79+(decodeframe.c:484-560) printing `block.x0/x1/y0/y1`, `frame_width/height` and whether
80+the border-extension path was TAKEN -- note that path is skipped entirely when the MV is
81+whole-pel and both frame dims are multiples of 8, so libaom then reads the ref buffer's
82+own extended border rows rather than a clamped copy. Frame 41, chroma (353,395), skip
83+32x32 mi(192,176) mv0=(-4,14).
84+
85+## Method notes for the successor
86+
87+* Our `EC_PICT idx=N` marker is printed at the END of frame N's decode, so a frame's
88+ trace lines are the ones BEFORE its marker, not after (an r11/r12 off-by-one that
89+ silently reads the next frame).
90+* `EC_PICT` now also prints under `EC_PRED` (both sites).
91+* aomdec has no frame marker; align its `EC_PRED` lines by grepping a small mi window
92+ in both decoders and matching the sequences 1:1 -- an UNMATCHED extra line on our side
93+ is itself the finding.
94+* Dumps: `~/.cache/t900-tmp/pf_r12_161/` (prefilter, 168 f), `d_r12_reelb10/`,
95+ `d_r12_cut_900/`, `d_r12_cut_5400/`.
96+
97+## Owed (not done at the turn cap)
98+
99+* Witness gate: no gate asserts `uv_mode_grid_override_hits() > 0` yet. Check the
100+ existing 128sb/gm_small_side/frame_edge_mv_clamping fixtures for a hit first
101+ (`decode_probe` does not print the new counter yet), else pin the smallest prefix of
102+ the 4K head that fires it (the defect frame is 161, so a ~250-OBU cut).
103+* Full `cargo test -p ec-av1 --lib` suite run (charter said no suite this round).
104+* 1080p head 0-10 s re-probe (was 78 differing, first 86).