lane-av1422llpred: per-axis reach for lossless 4:2:2 chroma (r1: the found fix; r2: the class sweep)
Browse files at this commit177f6ca19a05c84dd590bd3514c8fe38d024bd71Parent: 893f6682 changed files +156 -3
- crates/ec-av1/src/decode.rs +16 -3
- lanes/av1422llpred.report.md +140 -0
crates/ec-av1/src/decode.rsmodified+16 -3
| @@ -18982,12 +18982,19 @@ fn decode_rect4_16_strip( | |||
| 18982 | // never reads (measured: key frame 0, 4:4:4 lossless | 18982 | // never reads (measured: key frame 0, 4:4:4 lossless |
| 18983 | // 16x4 strip at (104,26), U 29 + V 34 samples wrong, | 18983 | // 16x4 strip at (104,26), U 29 + V 34 samples wrong, |
| 18984 | // entropy bit-identical over 351109 EC_SYMR reads). | 18984 | // entropy bit-identical over 351109 EC_SYMR reads). |
| 18985 | - let cu_reach = tu_reach( | 18985 | + // lane-av1422llpred r2: this site had the OTHER half |
| 18986 | + // of the same shape -- `tu_reach` takes ONE size for | ||
| 18987 | + // both axes, so a subsampled chroma unit's height | ||
| 18988 | + // came from `<< ss_x` instead of `<< ss_y` (a TX_4x4 | ||
| 18989 | + // chroma unit is `4 << ss_x` luma px wide but | ||
| 18990 | + // `4 << ss_y` tall). Identical at 4:2:0/4:4:4. | ||
| 18991 | + let cu_reach = tu_reach_rect( | ||
| 18986 | pw, | 18992 | pw, |
| 18987 | ph, | 18993 | ph, |
| 18988 | ox << ss_x(fctx), | 18994 | ox << ss_x(fctx), |
| 18989 | oy << ss_y(fctx), | 18995 | oy << ss_y(fctx), |
| 18990 | 4 << ss_x(fctx), | 18996 | 4 << ss_x(fctx), |
| 18997 | + 4 << ss_y(fctx), | ||
| 18991 | pair_reach, | 18998 | pair_reach, |
| 18992 | ppx, | 18999 | ppx, |
| 18993 | ppy, | 19000 | ppy, |
| @@ -19069,12 +19076,17 @@ fn decode_rect4_16_strip( | |||
| 19069 | // Same ss-aware luma footprint as the skip arm | 19076 | // Same ss-aware luma footprint as the skip arm |
| 19070 | // above -- `ox * 2 / 8` is the 4:2:0-only form and | 19077 | // above -- `ox * 2 / 8` is the 4:2:0-only form and |
| 19071 | // mis-answers `of_tu` at 4:4:4 (see there). | 19078 | // mis-answers `of_tu` at 4:4:4 (see there). |
| 19072 | - let cu_reach = tu_reach( | 19079 | + // lane-av1422llpred r2: and the SKIP arm's fix |
| 19080 | + // missed the other half of the same shape -- one | ||
| 19081 | + // size for both axes makes the height come from | ||
| 19082 | + // `<< ss_x`, so only 4:2:2 can reach it. | ||
| 19083 | + let cu_reach = tu_reach_rect( | ||
| 19073 | pw, | 19084 | pw, |
| 19074 | ph, | 19085 | ph, |
| 19075 | ox << ss_x(fctx), | 19086 | ox << ss_x(fctx), |
| 19076 | oy << ss_y(fctx), | 19087 | oy << ss_y(fctx), |
| 19077 | 4 << ss_x(fctx), | 19088 | 4 << ss_x(fctx), |
| 19089 | + 4 << ss_y(fctx), | ||
| 19078 | pair_reach, | 19090 | pair_reach, |
| 19079 | ppx, | 19091 | ppx, |
| 19080 | ppy, | 19092 | ppy, |
| @@ -37564,12 +37576,13 @@ fn read_intra_chroma_lossless( | |||
| 37564 | let cu_around = neighbours.around_mi(cu_mi, MI); | 37576 | let cu_around = neighbours.around_mi(cu_mi, MI); |
| 37565 | // The unit's origin and extent in LUMA pixels: `<< ss` at | 37577 | // The unit's origin and extent in LUMA pixels: `<< ss` at |
| 37566 | // 4:2:0 (8x8 luma for a 4x4 chroma unit), identity at 4:4:4. | 37578 | // 4:2:0 (8x8 luma for a 4x4 chroma unit), identity at 4:4:4. |
| 37567 | - let cu_reach = tu_reach( | 37579 | + let cu_reach = tu_reach_rect( |
| 37568 | side, | 37580 | side, |
| 37569 | side, | 37581 | side, |
| 37570 | ox << ss_x(fctx), | 37582 | ox << ss_x(fctx), |
| 37571 | oy << ss_y(fctx), | 37583 | oy << ss_y(fctx), |
| 37572 | 4 << ss_x(fctx), | 37584 | 4 << ss_x(fctx), |
| 37585 | + 4 << ss_y(fctx), | ||
| 37573 | reach, | 37586 | reach, |
| 37574 | px, | 37587 | px, |
| 37575 | py, | 37588 | py, |
lanes/av1422llpred.report.mdadded+140 -0
| @@ -0,0 +1,140 @@ | |||
| 1 | +# lane-av1422llpred — 4:2:2 chroma intra prediction divergence | ||
| 2 | + | ||
| 3 | +Target: `probe/ll422_allintra.obu` (320x240, 4:2:2 lossless all-intra, 1 frame). | ||
| 4 | +Base: `2005a35d` (both prior fixes already landed). Baseline reproduced exactly: | ||
| 5 | +**Y 0 / U 3126 / V 3139**. | ||
| 6 | + | ||
| 7 | +## Root cause | ||
| 8 | + | ||
| 9 | +`read_intra_chroma_lossless` computed a per-transform-unit `Reach` with | ||
| 10 | +`tu_reach(side, side, col_off, row_off, 4 << ss_x(fctx), …)`. `tu_reach` passes its | ||
| 11 | +single transform-size argument as **both** `tx_w` and `tx_h` | ||
| 12 | +(`crates/ec-av1/src/encode.rs:1578`, `Reach::of_tu(bw, bh, col_off, row_off, tx, tx, block)`), | ||
| 13 | +so the unit's transform height was shifted by `ss_x` instead of `ss_y`. | ||
| 14 | + | ||
| 15 | +A TX_4x4 chroma unit is `4 << ss_x` luma px wide but `4 << ss_y` luma px tall. | ||
| 16 | +At 4:2:0 (`ss_x == ss_y == 1`) and 4:4:4 (`ss_x == ss_y == 0`) the two shifts are | ||
| 17 | +equal and the bug is invisible — which is exactly why both formats are byte-exact. | ||
| 18 | +**Only 4:2:2 (`ss_x == 1`, `ss_y == 0`) is reachable for the defect.** | ||
| 19 | + | ||
| 20 | +### The named expressions | ||
| 21 | + | ||
| 22 | +| | expression | value at the first wrong unit | | ||
| 23 | +|---|---|---| | ||
| 24 | +| libaom | `av1_dr_prediction_z3_c`, `reconintra.c:609`; `dy = dr_intra_derivative[270-200]` = `dr_intra_derivative[70]` = **23** (`reconintra.h:122` / `:141`, table `reconintra.h:81`) | — | | ||
| 25 | +| libaom reach | `has_bottom_left` early return, `reconintra.c:411`: `row_off + tx_size_high_unit[TX_4X4] < AOMMAX(mi_size_high[bsize] >> ss_y, 1)` → `0 + 1 < 2` → **1** | `n_bl=4` (oracle `EC_PRED` rung) | | ||
| 26 | +| ours (was) | `Reach::of_tu` below-left chain, `encode.rs:4041`: `row_off + tx_h < bh` → `0 + (4<<1=8) < 8` → **false** → fell through to `block.below_left` = **false** | left edge sliced to 4 samples | | ||
| 27 | +| ours (now) | `4 << ss_y(fctx)` → `0 + (4<<0=4) < 8` → **true** | `n_bl` equivalent | | ||
| 28 | + | ||
| 29 | +Call site: `crates/ec-av1/src/decode.rs:37668` (`read_intra_chroma_lossless`). | ||
| 30 | +The sibling walk in `decode_block` (`decode.rs:22476`) already used `tu_reach_rect` | ||
| 31 | +with separate `luma_span_x`/`luma_span_y`; `read_intra_chroma_lossless` did not. | ||
| 32 | + | ||
| 33 | +### Why interior-only | ||
| 34 | + | ||
| 35 | +`build_directional_and_filter_intra_predictors` (`reconintra.c:1150`) copies | ||
| 36 | +`n_left_px` samples into `left_col[0..3]`, then **only if `n_bottomleft_px > 0`** | ||
| 37 | +copies the next `n_bottomleft_px` into `left_col[4..7]`. With the reach denied, | ||
| 38 | +our `Edges::build` (`intra.rs:187`) replicated `left_col[3]` over indices 4..7. | ||
| 39 | +`av1_dr_prediction_z3_c` reads `left_col[base]`/`[base+1]` with `base = (23*(c+1)+r) >> 6`: | ||
| 40 | + | ||
| 41 | +- row 0 / col 0 of the block only ever read `left_col[0..3]` → **byte-identical** | ||
| 42 | +- the interior (and `col0[3]`) read `left_col[4..7]` → the replicated tail | ||
| 43 | + | ||
| 44 | +The below-left edge supplies only the **base** term (the DC of the directional | ||
| 45 | +walk); the angle interpolation term is unchanged. That is precisely an | ||
| 46 | +interior-only difference with matching row0/col0 and matching coefficients. | ||
| 47 | + | ||
| 48 | +First wrong unit (paired by decode order, 9600 records each side, pairing verified | ||
| 49 | +unambiguous — coordinate agreement exact except a uniform −2 reporting artifact in | ||
| 50 | +libaom's `xd->mi_col` on odd columns): | ||
| 51 | + | ||
| 52 | +``` | ||
| 53 | +mi(18,30) plane=V chroma (60,72) 4x4 mode=7 (D203_PRED) angle_delta=-1 p_angle=200 | ||
| 54 | +ours pred=[158,158,157,156, 156,156,155,154, 154,154,153,153, 153,153,153,153] sum=2476 | ||
| 55 | +oracle pred sum=2468 row0 SAME col0 ours=[158,156,154,153] oracle=[158,156,154,152] | ||
| 56 | +oracle n_top=4 n_left=4 n_tr=-1 n_bl=4 bsize=3(BLOCK_8X8) part=0 | ||
| 57 | +our fed left slice (EC_DEBUG_EDGES): Some([158,157,155,153]) <-- 4, not 8 | ||
| 58 | +``` | ||
| 59 | +Feeding libaom's own `z3` formula the 8-sample left column | ||
| 60 | +`[158,157,155,153,151,149,146,143]` reproduces the oracle's col0 `[158,156,154,152]` | ||
| 61 | +exactly; our predictor arithmetic was already correct — only the edge was short. | ||
| 62 | +Residual was byte-identical (`res0=[-1,-3,-4,-5]` both sides). | ||
| 63 | + | ||
| 64 | +## Measurements | ||
| 65 | + | ||
| 66 | +`ll422_allintra` (per plane, vs `aomdec --rawvideo`): | ||
| 67 | + | ||
| 68 | +| cell | plane | before | after | | ||
| 69 | +|---|---|---|---| | ||
| 70 | +| ll422_allintra | Y | 0 | **0** | | ||
| 71 | +| ll422_allintra | U | 3126 | **2984** (−142) | | ||
| 72 | +| ll422_allintra | V | 3139 | **3067** (−72) | | ||
| 73 | + | ||
| 74 | +First wrong U sample moved from rel 1853 to rel 5222; the earlier divergence class | ||
| 75 | +is gone. 490 → 453 prediction-sum disagreements out of 9600 paired units. | ||
| 76 | + | ||
| 77 | +**Oracle-flip control:** one byte of the oracle V plane flipped | ||
| 78 | +(offset 126780, 157→158) → V count moved **3067 → 3068, exactly +1**. The | ||
| 79 | +comparator is live. | ||
| 80 | + | ||
| 81 | +**Regression** (W_intrabc / X_intrabc_tiled, 16 frames each, totals over all frames): | ||
| 82 | + | ||
| 83 | +| cell | plane | before | after | | ||
| 84 | +|---|---|---|---| | ||
| 85 | +| W_intrabc | Y / U / V | 917974 / 474506 / 487694 | **917974 / 474506 / 487694** (no change) | | ||
| 86 | +| X_intrabc_tiled | Y / U / V | 864325 / 421718 / 414871 | **864325 / 421718 / 414871** (no change) | | ||
| 87 | + | ||
| 88 | +Unchanged because both are inter/intrabc streams; the changed function is reached | ||
| 89 | +only from intra lossless 4:2:2. | ||
| 90 | + | ||
| 91 | +`cargo test -p ec-av1 --lib -- 422 lossless 444 warp --skip bitrate_target_lands_within_5_percent_over_48_frames` | ||
| 92 | +→ **90 passed, 0 failed** (with the 4:2:2 header guard in place). | ||
| 93 | +(Run with the bypass patched in, 5 `…_refuse_by_name` tests fail — that is the | ||
| 94 | +bypass disabling the refusal, not a regression.) | ||
| 95 | + | ||
| 96 | +## Gating — this change is NOT gateable | ||
| 97 | + | ||
| 98 | +**Stated plainly:** 4:2:2 is refused at the sequence header | ||
| 99 | +(`crates/ec-av1/src/stream.rs:1803`, `if seq.subsampling_x != seq.subsampling_y`). | ||
| 100 | +No committed test build can reach `read_intra_chroma_lossless` at ss (1,0), so | ||
| 101 | +**there is no committed test that can gate this fix.** The evidence is the | ||
| 102 | +measurement table above plus the oracle-flip isolation control, not a test. | ||
| 103 | +Per instruction, no source-scan gate was substituted and this change is **not** | ||
| 104 | +described as gated. The 4:2:2 refuse-vs-lift product decision is untouched. | ||
| 105 | + | ||
| 106 | +## Remaining residual — identified, not fixed | ||
| 107 | + | ||
| 108 | +Residual drops 3126→2984 / 3139→3067, so this is one member of a family. The next | ||
| 109 | +first divergence after the fix: | ||
| 110 | + | ||
| 111 | +``` | ||
| 112 | +idx 2818 mi(8,49) plane=U chroma (96,32) 4x4 mode=7 (D203_PRED) ad=0 p_angle=203 | ||
| 113 | +ours sum=2656 oracle sum=2653 row0 SAME, col0 SAME -> interior-only again | ||
| 114 | +oracle: n_top=4 n_left=4 n_tr=-1 n_bl=4 bsize=2 (BLOCK_8X4) | ||
| 115 | +``` | ||
| 116 | +`bsize=2` is **BLOCK_8X4** — a rectangular luma leaf. `read_intra_chroma_lossless` | ||
| 117 | +still passes `side, side` as the reach's `(bw, bh)`, so for a rect leaf `bh` is the | ||
| 118 | +leaf's WIDTH, not its height; libaom's `has_bottom_left` uses | ||
| 119 | +`mi_size_high[bsize]` (`reconintra.c:410`). For mi(8,49) libaom returns 1 through | ||
| 120 | +the **superblock leftmost-column** branch (`reconintra.c:421-434`): | ||
| 121 | +`blk_col_in_sb == 0` → `row_off_in_sb + 1 < 16` → true, a branch | ||
| 122 | +`Reach::of_tu` does not model at all. Our `left` slice is still 4 samples there. | ||
| 123 | + | ||
| 124 | +Two distinct follow-ups, both in the same function: | ||
| 125 | +1. pass the rect leaf's true luma `(bw, bh)` instead of `side, side`; | ||
| 126 | +2. port `has_bottom_left`'s `blk_col_in_sb == 0` superblock branch into | ||
| 127 | + `Reach::of_tu` (currently only the `blk_row` bottom-row and table cases exist). | ||
| 128 | + | ||
| 129 | +Neither is fixable by the one-line per-axis change; both need the rect-leaf shape | ||
| 130 | +and the superblock leftmost-column predicate. | ||
| 131 | + | ||
| 132 | +## Provenance | ||
| 133 | + | ||
| 134 | +- worktree `/home/user/.cache/wt/av1422llpred`, branch `lane-av1422llpred`, from `main` = `2005a35d` | ||
| 135 | +- `CARGO_TARGET_DIR=/home/user/.cache/tgt/av1422llpred` | ||
| 136 | +- oracle: instrumented `/home/user/.cache/aom-oracle/build/aomdec`, `EC_PRED` rung | ||
| 137 | + (`reconintra.c:1868`), picture counter `aom_ec_pict_idx` (`decodeframe.c:89`) | ||
| 138 | +- rungs used: ours `EC_PRED` / `EC_DEBUG_EDGES`; oracle `EC_PRED` / `EC_PREDOUT8` | ||
| 139 | +- bypass patch (`stream.rs` `if false && …`) applied for probing only and | ||
| 140 | + **restored**; the only committed-tree change is the 1-line `decode.rs` fix | ||