forge
Explore
Log in

Don't you dare go Hollow

Merge lane-av1422llpred: per-axis reach for 4:2:2 chroma -- ll422_allintra U 3126 -> 2984, V 3139 -> 3067; plus a two-site class sweep

Browse files at this commit

6f83d9c4e0a5304055ff104d8138721068e0229aAhmet Kaan GümüşParent: 2177457177f6ca
THE FIX: read_intra_chroma_lossless called tu_reach(side, side, col_off, row_off, 4 << ss_x(fctx), ...),
and tu_reach passes ONE transform size as BOTH tx_w and tx_h -- so a TX_4x4 chroma unit's HEIGHT came
from ss_x instead of ss_y. A chroma unit is 4 << ss_x luma px wide but 4 << ss_y tall; the two shifts
coincide at 4:2:0 and 4:4:4, which is why only 4:2:2 could ever reach this. Now tu_reach_rect with
tx_h = 4 << ss_y(fctx). The reach itself is libaom's has_bottom_left (reconintra.c:411,
row_off + tx_size_high_unit[TX_4X4] < AOMMAX(mi_size_high[bsize] >> ss_y, 1)): 0 + 8 < 8 was false
before, 0 + 4 < 8 is true now. The interior-only signature follows: build_directional_and_filter_intra_
predictors fills left_col[0..3] and extends to [4..7] only when n_bottomleft_px > 0, so with the reach
denied our edge builder replicated left_col[3]; z3 reads [0..3] for row0/col0 (byte-identical) and the
replicated tail for the interior. Feeding libaom's formula the 8-sample column reproduces the oracle's
col0 exactly -- the arithmetic was right, the edge was short.

MEASURED BY MAIN on a bypassed release build of the branch, per plane, vs aomdec --rawvideo:
ll422_allintra Y 0 / U 3126 -> 2984 / V 3139 -> 3067; prediction-sum disagreements 490 -> 453 of 9600.
W_intrabc (917974/474506/487694) and X_intrabc_tiled unchanged -- inter/intrabc streams do not reach the
function. Oracle-flip control: rotating one oracle V byte moves V by exactly +1.

CLASS SWEEP: two more instances of the same one-size-for-two-axes shape, both in decode_rect4_16_strip
(18985, 19072), converted the same way. Measured a NO-OP on both 4:2:2 cells we have -- recorded as
correct-for-the-4:2:2-port, NOT as a win; they are an identity at 4:2:0/4:4:4 where ss_x == ss_y, which
is the only reason they are safe to land without a measurement. The remaining 15 tu_reach sites pass no
subsampled size, and four sites already using separate sizes were already correct.

NOT GATEABLE: 4:2:2 is refused at the sequence header, so no committed test can reach the fixed path;
the evidence is the measurement table plus an isolation control, and the change is not described as
gated. Regression: 175 passed, 0 failed, 2 ignored (422/lossless/444/warp/intra).
crates/ec-av1/src/decode.rsmodified+16 -3
@@ -18998,12 +18998,19 @@ fn decode_rect4_16_strip(
18998 // never reads (measured: key frame 0, 4:4:4 lossless18998 // never reads (measured: key frame 0, 4:4:4 lossless
18999 // 16x4 strip at (104,26), U 29 + V 34 samples wrong,18999 // 16x4 strip at (104,26), U 29 + V 34 samples wrong,
19000 // entropy bit-identical over 351109 EC_SYMR reads).19000 // entropy bit-identical over 351109 EC_SYMR reads).
19001- let cu_reach = tu_reach(19001+ // lane-av1422llpred r2: this site had the OTHER half
19002+ // of the same shape -- `tu_reach` takes ONE size for
19003+ // both axes, so a subsampled chroma unit's height
19004+ // came from `<< ss_x` instead of `<< ss_y` (a TX_4x4
19005+ // chroma unit is `4 << ss_x` luma px wide but
19006+ // `4 << ss_y` tall). Identical at 4:2:0/4:4:4.
19007+ let cu_reach = tu_reach_rect(
19002 pw,19008 pw,
19003 ph,19009 ph,
19004 ox << ss_x(fctx),19010 ox << ss_x(fctx),
19005 oy << ss_y(fctx),19011 oy << ss_y(fctx),
19006 4 << ss_x(fctx),19012 4 << ss_x(fctx),
19013+ 4 << ss_y(fctx),
19007 pair_reach,19014 pair_reach,
19008 ppx,19015 ppx,
19009 ppy,19016 ppy,
@@ -19085,12 +19092,17 @@ fn decode_rect4_16_strip(
19085 // Same ss-aware luma footprint as the skip arm19092 // Same ss-aware luma footprint as the skip arm
19086 // above -- `ox * 2 / 8` is the 4:2:0-only form and19093 // above -- `ox * 2 / 8` is the 4:2:0-only form and
19087 // mis-answers `of_tu` at 4:4:4 (see there).19094 // mis-answers `of_tu` at 4:4:4 (see there).
19088- let cu_reach = tu_reach(19095+ // lane-av1422llpred r2: and the SKIP arm's fix
19096+ // missed the other half of the same shape -- one
19097+ // size for both axes makes the height come from
19098+ // `<< ss_x`, so only 4:2:2 can reach it.
19099+ let cu_reach = tu_reach_rect(
19089 pw,19100 pw,
19090 ph,19101 ph,
19091 ox << ss_x(fctx),19102 ox << ss_x(fctx),
19092 oy << ss_y(fctx),19103 oy << ss_y(fctx),
19093 4 << ss_x(fctx),19104 4 << ss_x(fctx),
19105+ 4 << ss_y(fctx),
19094 pair_reach,19106 pair_reach,
19095 ppx,19107 ppx,
19096 ppy,19108 ppy,
@@ -37582,12 +37594,13 @@ fn read_intra_chroma_lossless(
37582 let cu_around = neighbours.around_mi(cu_mi, MI);37594 let cu_around = neighbours.around_mi(cu_mi, MI);
37583 // The unit's origin and extent in LUMA pixels: `<< ss` at37595 // The unit's origin and extent in LUMA pixels: `<< ss` at
37584 // 4:2:0 (8x8 luma for a 4x4 chroma unit), identity at 4:4:4.37596 // 4:2:0 (8x8 luma for a 4x4 chroma unit), identity at 4:4:4.
37585- let cu_reach = tu_reach(37597+ let cu_reach = tu_reach_rect(
37586 side,37598 side,
37587 side,37599 side,
37588 ox << ss_x(fctx),37600 ox << ss_x(fctx),
37589 oy << ss_y(fctx),37601 oy << ss_y(fctx),
37590 4 << ss_x(fctx),37602 4 << ss_x(fctx),
37603+ 4 << ss_y(fctx),
37591 reach,37604 reach,
37592 px,37605 px,
37593 py,37606 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