forge
Explore
Log in

Don't you dare go Hollow

Mv-stack column/row scans dropped libaom's two sub-8x8 rules -- an 8x4 leaf's refmv CDF row was 3 where libaom uses 4

Browse files at this commit

53add124abbca90743936ec6bb931038ede62e8bAhmet Kaan GümüşParent: 2b05cf7
  • fix
    • mv-stack column/row scans dropped libaom's two sub-8x8 rules -- an 8x4 leaf's refmv CDF row was 3 where libaom uses 4
Show full message
fix(av1): mv-stack column/row scans dropped libaom's two sub-8x8 rules -- an 8x4 leaf's refmv CDF row was 3 where libaom uses 4

`scan_col_mbmi`'s odd-row snap (`if ((mi_row & 0x01) && xd->height < n8_h_8) --row_offset;`) and
its transposed `scan_row_mbmi` twin were never ported, and the weight/`processed_cols` guard kept
only `xd->height <= n4_h`, dropping libaom's `xd->height >= n8_h_8` half. Both only misfire for a
query block with a side under 8px, so they surfaced the moment an intra 8x4 leaf made its inter
neighbour's second-outer column scan matter: the scan probed the undecoded row below, lost
`col_match_count`, and read the `refmv` symbol off ctx 3 instead of 4 -- same decoded mode, wrong
CDF row, tile desynced from there (class wrong-alphabet-same-value).

Fixed in all four scan functions (single-ref and compound). On the 8-bit 128x128 sub-8x8 witness
the all_zero range ladder now matches the reference on 2106/2106 transform units across all 6
frames (was 1405) and mi(24,0)'s mode range matches; the three remaining pixel clusters are the
OBMC `mi_step == 1` chroma-pair merge already fixed on another lane, with which the witness is
cmp-exact against ffmpeg on all 6 frames. No refusal lifted, no gate yet.
crates/ec-av1/src/mvstack.rsmodified+28 -8
@@ -516,7 +516,10 @@ fn scan_row(
516516 let Some(row) = mi_row.checked_add_signed(row_offset) else {
517517 return false;
518518 };
519- let col_shift: usize = if row_offset.unsigned_abs() > 1 { 1 } else { 0 };
519+ // libaom `scan_row_mbmi`: the transpose of `scan_col_mbmi`'s rule --
520+ // `if ((mi_col & 0x01) && xd->width < n8_w_8) --col_offset;`.
521+ let col_shift: usize =
522+ usize::from(row_offset.unsigned_abs() > 1 && !(mi_col % 2 == 1 && bw4 < 2));
520523 let use_step_16 = bw4 >= 16;
521524 let end_mi = bw4.min(16);
522525 let mut found = false;
@@ -534,7 +537,7 @@ fn scan_row(
534537 len = len.max(2);
535538 }
536539 let mut weight = ROW_COL_WEIGHT_FLOOR;
537- if bw4 <= n4 {
540+ if bw4 >= 2 && bw4 <= n4 {
538541 let inc = ((-max_row_offset + row_offset + 1) as usize).min(info.size_h);
539542 weight = weight.max(inc as u32);
540543 *processed_rows = (inc as isize - row_offset - 1).max(0) as usize;
@@ -598,7 +601,14 @@ fn scan_col(
598601 let Some(col) = mi_col.checked_add_signed(col_offset) else {
599602 return false;
600603 };
601- let row_shift: usize = if col_offset.unsigned_abs() > 1 { 1 } else { 0 };
604+ // libaom `scan_col_mbmi`: `row_offset = 1` for the outer columns, then
605+ // `if ((mi_row & 0x01) && xd->height < n8_h_8) --row_offset;` -- a sub-8x8
606+ // block on an odd mi row probes its OWN row, not the one below (which is
607+ // not decoded yet). Missing this made the second-outer column scan of an
608+ // 8x4 leaf read an undecoded cell, losing `col_match_count` and reading
609+ // the `refmv` symbol off ctx 3 instead of 4 (lane-sub8intra r2).
610+ let row_shift: usize =
611+ usize::from(col_offset.unsigned_abs() > 1 && !(mi_row % 2 == 1 && bh4 < 2));
602612 let use_step_16 = bh4 >= 16;
603613 let end_mi = bh4.min(16);
604614 let mut found = false;
@@ -616,7 +626,7 @@ fn scan_col(
616626 len = len.max(2);
617627 }
618628 let mut weight = ROW_COL_WEIGHT_FLOOR;
619- if bh4 <= n4 {
629+ if bh4 >= 2 && bh4 <= n4 {
620630 let inc = ((-max_col_offset + col_offset + 1) as usize).min(info.size);
621631 weight = weight.max(inc as u32);
622632 *processed_cols = (inc as isize - col_offset - 1).max(0) as usize;
@@ -1346,7 +1356,10 @@ fn scan_row_compound(
13461356 let Some(row) = mi_row.checked_add_signed(row_offset) else {
13471357 return false;
13481358 };
1349- let col_shift: usize = if row_offset.unsigned_abs() > 1 { 1 } else { 0 };
1359+ // libaom `scan_row_mbmi`: the transpose of `scan_col_mbmi`'s rule --
1360+ // `if ((mi_col & 0x01) && xd->width < n8_w_8) --col_offset;`.
1361+ let col_shift: usize =
1362+ usize::from(row_offset.unsigned_abs() > 1 && !(mi_col % 2 == 1 && bw4 < 2));
13501363 let use_step_16 = bw4 >= 16;
13511364 let end_mi = bw4.min(16);
13521365 let mut found = false;
@@ -1364,7 +1377,7 @@ fn scan_row_compound(
13641377 len = len.max(2);
13651378 }
13661379 let mut weight = ROW_COL_WEIGHT_FLOOR;
1367- if bw4 <= n4 {
1380+ if bw4 >= 2 && bw4 <= n4 {
13681381 let inc = ((-max_row_offset + row_offset + 1) as usize).min(info.size_h);
13691382 weight = weight.max(inc as u32);
13701383 *processed_rows = (inc as isize - row_offset - 1).max(0) as usize;
@@ -1403,7 +1416,14 @@ fn scan_col_compound(
14031416 let Some(col) = mi_col.checked_add_signed(col_offset) else {
14041417 return false;
14051418 };
1406- let row_shift: usize = if col_offset.unsigned_abs() > 1 { 1 } else { 0 };
1419+ // libaom `scan_col_mbmi`: `row_offset = 1` for the outer columns, then
1420+ // `if ((mi_row & 0x01) && xd->height < n8_h_8) --row_offset;` -- a sub-8x8
1421+ // block on an odd mi row probes its OWN row, not the one below (which is
1422+ // not decoded yet). Missing this made the second-outer column scan of an
1423+ // 8x4 leaf read an undecoded cell, losing `col_match_count` and reading
1424+ // the `refmv` symbol off ctx 3 instead of 4 (lane-sub8intra r2).
1425+ let row_shift: usize =
1426+ usize::from(col_offset.unsigned_abs() > 1 && !(mi_row % 2 == 1 && bh4 < 2));
14071427 let use_step_16 = bh4 >= 16;
14081428 let end_mi = bh4.min(16);
14091429 let mut found = false;
@@ -1421,7 +1441,7 @@ fn scan_col_compound(
14211441 len = len.max(2);
14221442 }
14231443 let mut weight = ROW_COL_WEIGHT_FLOOR;
1424- if bh4 <= n4 {
1444+ if bh4 >= 2 && bh4 <= n4 {
14251445 let inc = ((-max_col_offset + col_offset + 1) as usize).min(info.size);
14261446 weight = weight.max(inc as u32);
14271447 *processed_cols = (inc as isize - col_offset - 1).max(0) as usize;
lanes/sub8intra-r2.handoff.mdadded+73 -0
@@ -0,0 +1,73 @@
1+# lane-sub8intra r2 HANDOFF (tip = this commit)
2+
3+## The band: NOT a band -- the mv-stack's second-outer COLUMN scan (`mvstack.rs`)
4+
5+r1's suspects (above/left txfm, inter, ref, skip, y_mode, coeff, side-mi bands published by
6+the intra leaf) were ALL innocent. The first diverging symbol on the r1 witness
7+`~/.cache/sub8intra-tmp/x_1t_48_8_128x128.obu` is the `refmv` symbol of the INTER 8x4 leaf at
8+mi(23,14) -- the block whose LEFT neighbour is the intra leaf at mi(23,12..13). Same decoded
9+value (NEARESTMV), different CDF ROW (class `wrong-alphabet-same-value` / `cdf-row-held-constant`):
10+
11+* instrumented aomdec (private build, see below): `mode_ctx=75` -> newmv 3, globalmv 1, **refmv 4**
12+* ours before the fix: newmv 3, globalmv 1, **refmv 3** -> rng 62378 where the reference has 47820
13+
14+`refmv 4` vs `3` is `ref_match_count == 2` vs `1` in `setup_ref_mv_list`'s `case 1:` switch
15+(mvref_common.c:638): libaom's second-outer column scan (`col_offset = -3`) found an inter
16+match at mi(23,11), ours found none.
17+
18+## Two defects fixed (crates/ec-av1/src/mvstack.rs, all FOUR scan functions)
19+
20+Both are pure sub-8x8 (a side < 2 mi) defects; every block main decodes today has both sides
21+>= 8px in at least one of the two axes checked, which is why they survived until this lane.
22+
23+1. **`scan_col_mbmi`'s odd-row snap was missing** (`scan_col` L~600, `scan_col_compound` L~1406):
24+ libaom does `row_offset = 1; if ((mi_row & 0x01) && xd->height < n8_h_8) --row_offset;`.
25+ For an 8x4 leaf on an ODD mi row our walk probed the row BELOW (undecoded), losing the
26+ match. Fixed as `col_offset.unsigned_abs() > 1 && !(mi_row % 2 == 1 && bh4 < 2)`.
27+ Transposed twin fixed in `scan_row`/`scan_row_compound`
28+ (`(mi_col & 1) && xd->width < n8_w_8`).
29+2. **the weight / `processed_rows|cols` guard dropped libaom's `>= n8_*_8` half**:
30+ libaom `if (xd->height >= n8_h_8 && xd->height <= n4_h)`; ours was `if (bh4 <= n4)`, so a
31+ 1-mi-tall query block set `processed_cols` and a boosted weight libaom never sets (which can
32+ also suppress the second-outer scan entirely). Now `bh4 >= 2 && bh4 <= n4` (and `bw4` twin).
33+
34+`cargo check -p ec-av1`: clean.
35+
36+## Ladder result on x_1t_48_8_128x128.obu (EC_SUB8INTRA_DECODE=1)
37+
38+* mi(24,0) EC_MODE: ref 39238, ours **39238** (was 44268) -- matches.
39+* `tag=all_zero` ladder: **2106/2106 units identical in value AND range, all 6 frames**
40+ (`diff rz2.l oz2.l` empty). r1's ladder stopped matching at 1405.
41+* `OK: 6 frames decoded, 128x128`, `sub8_intra_rect: horz8x4=19 vert4x8=2 chroma_ref=10 mixed=3`.
42+* Pixels: 3 residual clusters (frame 3 two 4x4 luma, frames 4/5 one +-1 pixel triple) --
43+ root-caused to the OBMC `mi_step == 1` chroma-pair merge, which is **already fixed on
44+ lane-intra16x4 as f403337** (`overlappable_above`/`overlappable_left`). NOT duplicated here
45+ (charter: those functions belong to that lane). With f403337's decode.rs hunk applied on top of
46+ this commit the witness is **cmp-EXACT vs `ffmpeg -pix_fmt yuv420p` on all 6 frames**
47+ (verified, then reverted out of this tree).
48+
49+## Oracle instrumentation added (additive, env-gated `EC_SUB8CTX`)
50+
51+`av1/decoder/decodemv.c` in `~/.cache/aom-oracle/src`: one print after `read_ref_frames`
52+(single-ref p1 ctx + rng) and one after `read_inter_mode` (mode_ctx split into
53+newmv/globalmv/refmv + ref_mv_count). Built into the PRIVATE dir
54+`~/.cache/sub8intra-tmp/aom-build` (`ninja aomdec`); `~/.cache/aom-oracle/build` untouched.
55+This print is what named the band in one step -- keep it.
56+
57+## Next step (r3)
58+
59+1. Sweep `~/.cache/sub8intra-tmp/sweep3.sh` (max-partition-size=8, 1:4 off, 8- and 10-bit,
60+ cq 48/55/63, 128x128 + 192x128) -- 5 of 12 arms already decode all 6 frames pixel-EXACT
61+ (`10 cq48 128x128`, `10 cq48 192x128`, `10 cq55 128x128`, `10 cq63 128x128`,
62+ `8 cq55 192x128`). Those are the gate arms.
63+2. The other arms still stop at a refusal naming a shape the encoder cannot have coded
64+ (`--max-partition-size=8` + `--enable-1to4-partitions=0`) -- class `refusal-from-own-desync`,
65+ one desync left. Bisected on `g_8_48_128x128.obu`: first divergence at all_zero unit 1581,
66+ block mi(25,2) -- the reference reads `use_filter_intra=1`, `filter_intra_mode=3`,
67+ `tx_depth=1` for an INTRA sub-8x8 leaf there (ra2.l:4370-4372) which OUR path never reads;
68+ ours continues the previous block's 4x4 units instead. So: filter_intra IS read on a
69+ sub-8x8 intra leaf in that stream, and the `tx_depth=1` split (two TX_4X4) path is the
70+ one to check first.
71+3. Then: gate + refusal lift (both sub-8x8 intra refusals), refusal_inventory.rs +
72+ gate_coverage.rs, suite, films. Also still open: the flagged all-inter `first_tx_type`
73+ rule (blockd.h:1288, LAST sub-block vs first) -- unmeasured this round.