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 commit53add124abbca90743936ec6bb931038ede62e8bParent: 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
2 changed files +101 -8
crates/ec-av1/src/mvstack.rsmodified+28 -8
| @@ -516,7 +516,10 @@ fn scan_row( | |||
| 516 | let Some(row) = mi_row.checked_add_signed(row_offset) else { | 516 | let Some(row) = mi_row.checked_add_signed(row_offset) else { |
| 517 | return false; | 517 | return false; |
| 518 | }; | 518 | }; |
| 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)); | ||
| 520 | let use_step_16 = bw4 >= 16; | 523 | let use_step_16 = bw4 >= 16; |
| 521 | let end_mi = bw4.min(16); | 524 | let end_mi = bw4.min(16); |
| 522 | let mut found = false; | 525 | let mut found = false; |
| @@ -534,7 +537,7 @@ fn scan_row( | |||
| 534 | len = len.max(2); | 537 | len = len.max(2); |
| 535 | } | 538 | } |
| 536 | let mut weight = ROW_COL_WEIGHT_FLOOR; | 539 | let mut weight = ROW_COL_WEIGHT_FLOOR; |
| 537 | - if bw4 <= n4 { | 540 | + if bw4 >= 2 && bw4 <= n4 { |
| 538 | let inc = ((-max_row_offset + row_offset + 1) as usize).min(info.size_h); | 541 | let inc = ((-max_row_offset + row_offset + 1) as usize).min(info.size_h); |
| 539 | weight = weight.max(inc as u32); | 542 | weight = weight.max(inc as u32); |
| 540 | *processed_rows = (inc as isize - row_offset - 1).max(0) as usize; | 543 | *processed_rows = (inc as isize - row_offset - 1).max(0) as usize; |
| @@ -598,7 +601,14 @@ fn scan_col( | |||
| 598 | let Some(col) = mi_col.checked_add_signed(col_offset) else { | 601 | let Some(col) = mi_col.checked_add_signed(col_offset) else { |
| 599 | return false; | 602 | return false; |
| 600 | }; | 603 | }; |
| 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)); | ||
| 602 | let use_step_16 = bh4 >= 16; | 612 | let use_step_16 = bh4 >= 16; |
| 603 | let end_mi = bh4.min(16); | 613 | let end_mi = bh4.min(16); |
| 604 | let mut found = false; | 614 | let mut found = false; |
| @@ -616,7 +626,7 @@ fn scan_col( | |||
| 616 | len = len.max(2); | 626 | len = len.max(2); |
| 617 | } | 627 | } |
| 618 | let mut weight = ROW_COL_WEIGHT_FLOOR; | 628 | let mut weight = ROW_COL_WEIGHT_FLOOR; |
| 619 | - if bh4 <= n4 { | 629 | + if bh4 >= 2 && bh4 <= n4 { |
| 620 | let inc = ((-max_col_offset + col_offset + 1) as usize).min(info.size); | 630 | let inc = ((-max_col_offset + col_offset + 1) as usize).min(info.size); |
| 621 | weight = weight.max(inc as u32); | 631 | weight = weight.max(inc as u32); |
| 622 | *processed_cols = (inc as isize - col_offset - 1).max(0) as usize; | 632 | *processed_cols = (inc as isize - col_offset - 1).max(0) as usize; |
| @@ -1346,7 +1356,10 @@ fn scan_row_compound( | |||
| 1346 | let Some(row) = mi_row.checked_add_signed(row_offset) else { | 1356 | let Some(row) = mi_row.checked_add_signed(row_offset) else { |
| 1347 | return false; | 1357 | return false; |
| 1348 | }; | 1358 | }; |
| 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)); | ||
| 1350 | let use_step_16 = bw4 >= 16; | 1363 | let use_step_16 = bw4 >= 16; |
| 1351 | let end_mi = bw4.min(16); | 1364 | let end_mi = bw4.min(16); |
| 1352 | let mut found = false; | 1365 | let mut found = false; |
| @@ -1364,7 +1377,7 @@ fn scan_row_compound( | |||
| 1364 | len = len.max(2); | 1377 | len = len.max(2); |
| 1365 | } | 1378 | } |
| 1366 | let mut weight = ROW_COL_WEIGHT_FLOOR; | 1379 | let mut weight = ROW_COL_WEIGHT_FLOOR; |
| 1367 | - if bw4 <= n4 { | 1380 | + if bw4 >= 2 && bw4 <= n4 { |
| 1368 | let inc = ((-max_row_offset + row_offset + 1) as usize).min(info.size_h); | 1381 | let inc = ((-max_row_offset + row_offset + 1) as usize).min(info.size_h); |
| 1369 | weight = weight.max(inc as u32); | 1382 | weight = weight.max(inc as u32); |
| 1370 | *processed_rows = (inc as isize - row_offset - 1).max(0) as usize; | 1383 | *processed_rows = (inc as isize - row_offset - 1).max(0) as usize; |
| @@ -1403,7 +1416,14 @@ fn scan_col_compound( | |||
| 1403 | let Some(col) = mi_col.checked_add_signed(col_offset) else { | 1416 | let Some(col) = mi_col.checked_add_signed(col_offset) else { |
| 1404 | return false; | 1417 | return false; |
| 1405 | }; | 1418 | }; |
| 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)); | ||
| 1407 | let use_step_16 = bh4 >= 16; | 1427 | let use_step_16 = bh4 >= 16; |
| 1408 | let end_mi = bh4.min(16); | 1428 | let end_mi = bh4.min(16); |
| 1409 | let mut found = false; | 1429 | let mut found = false; |
| @@ -1421,7 +1441,7 @@ fn scan_col_compound( | |||
| 1421 | len = len.max(2); | 1441 | len = len.max(2); |
| 1422 | } | 1442 | } |
| 1423 | let mut weight = ROW_COL_WEIGHT_FLOOR; | 1443 | let mut weight = ROW_COL_WEIGHT_FLOOR; |
| 1424 | - if bh4 <= n4 { | 1444 | + if bh4 >= 2 && bh4 <= n4 { |
| 1425 | let inc = ((-max_col_offset + col_offset + 1) as usize).min(info.size); | 1445 | let inc = ((-max_col_offset + col_offset + 1) as usize).min(info.size); |
| 1426 | weight = weight.max(inc as u32); | 1446 | weight = weight.max(inc as u32); |
| 1427 | *processed_cols = (inc as isize - col_offset - 1).max(0) as usize; | 1447 | *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. | ||