forge
Explore
Log in

Don't you dare go Hollow

lane-av1422llpred: per-axis reach for lossless 4:2:2 chroma (r1: the found fix; r2: the class sweep)

Browse files at this commit

177f6ca19a05c84dd590bd3514c8fe38d024bd71Ahmet Kaan GümüşParent: 893f668
r1 -- THE FIX (lane-av1422llpred). read_intra_chroma_lossless computed the per-TU Reach with
tu_reach(side, side, col_off, row_off, 4 << ss_x(fctx), ...), and tu_reach takes ONE transform size and
passes it as BOTH tx_w and tx_h, so the transform HEIGHT came from ss_x instead of ss_y. A TX_4x4
chroma unit is 4 << ss_x luma px WIDE but 4 << ss_y luma px TALL; at 4:2:0 and 4:4:4 the two shifts are
identical, which is exactly why both formats have been byte-exact and only 4:2:2 could reach it.
Now tu_reach_rect with tx_h = 4 << ss_y(fctx) (decode.rs:37568). The sibling walk in decode_block
already did this correctly with separate spans.

libaom: av1_dr_prediction_z3_c (reconintra.c:609) with the reach decided by has_bottom_left
(reconintra.c:411) -- row_off + tx_size_high_unit[TX_4X4] < AOMMAX(mi_size_high[bsize] >> ss_y, 1).
Ours before: row_off + tx_h < bh -> 0 + 8 < 8 -> false, so below_left was denied. After: 0 + 4 < 8 -> true.
WHY INTERIOR-ONLY: build_directional_and_filter_intra_predictors (reconintra.c:1150) fills left_col[0..3]
and only extends to [4..7] when n_bottomleft_px > 0; with the reach denied our Edges::build replicated
left_col[3] across 4..7. z3 reads left_col[base]/[base+1] with base = (23*(c+1)+r)>>6, so row0 and col0
only read [0..3] (byte-identical) while the interior reads the replicated tail. Feeding libaom's own
formula the 8-sample left column reproduces the oracle's col0 exactly -- the arithmetic was right, the
edge was short.

MEASURED by Main on a bypassed release build of this branch vs the oracle (aomdec --rawvideo, per
plane, 320x240 4:2:2 intra): ll422_allintra Y 0 / U 3126 -> 2984 / V 3139 -> 3067. Prediction-sum
disagreements 490 -> 453 of 9600 paired units. W_intrabc and X_intrabc_tiled UNCHANGED
(917974/474506/487694 and 864325/421718/414871) -- both are inter/intrabc streams and the changed
function is reached only from intra lossless 4:2:2. Oracle-flip control: one oracle V byte rotated
moves V by exactly +1.

r2 -- THE CLASS SWEEP, done by Main, because r1 fixed one instance of a shape with more. tu_reach takes
ONE size for two axes; grepping every call site for a subsampled single size found TWO more, both in
decode_rect4_16_strip (18985 and 19072), both converted to tu_reach_rect with tx_h = 4 << ss_y(fctx).
The remaining 15 tu_reach sites pass no subsampled size, and the sites that already used separate sizes
(19022/19116/37613/37783) were already correct. MEASURED: a no-op on both 4:2:2 cells we have
(W_intrabc byte-for-byte the same counts; ll422_allintra unchanged), so those two are recorded as
correct-for-the-4:2:2-port and NOT as a measured win -- they are provably an identity at 4:2:0 and 4:4:4
where ss_x == ss_y, which is the only reason they are safe to land unmeasured.

NOT GATEABLE, stated plainly: 4:2:2 is refused at the sequence header (stream.rs:1803), so no committed
test build can reach read_intra_chroma_lossless at ss (1,0) and no committed test can gate this. The
evidence is the measurement table plus the oracle-flip isolation control -- no source-scan substitute,
and this change is NOT described as gated. Regression: 422/lossless/444/warp/intra -> 175 passed,
0 failed, 2 ignored.
crates/ec-av1/src/decode.rsmodified+16 -3
@@ -18982,12 +18982,19 @@ fn decode_rect4_16_strip(
1898218982 // never reads (measured: key frame 0, 4:4:4 lossless
1898318983 // 16x4 strip at (104,26), U 29 + V 34 samples wrong,
1898418984 // 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(
1898618992 pw,
1898718993 ph,
1898818994 ox << ss_x(fctx),
1898918995 oy << ss_y(fctx),
1899018996 4 << ss_x(fctx),
18997+ 4 << ss_y(fctx),
1899118998 pair_reach,
1899218999 ppx,
1899319000 ppy,
@@ -19069,12 +19076,17 @@ fn decode_rect4_16_strip(
1906919076 // Same ss-aware luma footprint as the skip arm
1907019077 // above -- `ox * 2 / 8` is the 4:2:0-only form and
1907119078 // 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(
1907319084 pw,
1907419085 ph,
1907519086 ox << ss_x(fctx),
1907619087 oy << ss_y(fctx),
1907719088 4 << ss_x(fctx),
19089+ 4 << ss_y(fctx),
1907819090 pair_reach,
1907919091 ppx,
1908019092 ppy,
@@ -37564,12 +37576,13 @@ fn read_intra_chroma_lossless(
3756437576 let cu_around = neighbours.around_mi(cu_mi, MI);
3756537577 // The unit's origin and extent in LUMA pixels: `<< ss` at
3756637578 // 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(
3756837580 side,
3756937581 side,
3757037582 ox << ss_x(fctx),
3757137583 oy << ss_y(fctx),
3757237584 4 << ss_x(fctx),
37585+ 4 << ss_y(fctx),
3757337586 reach,
3757437587 px,
3757537588 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