forge
Explore
Log in

Don't you dare go Hollow

lane-av1-llpred: chroma OBMC sizes follow the plane's own subsampling

Browse files at this commit

ab305461bdb39f7cdd9381e289ed419a9ef913b9Ahmet Kaan GümüşParent: 3e0f682
The min-partition-8 lossless 4:4:4 stream's 2772 chroma pixel diffs were
OBMC, not prediction input: obmc_run sized the chroma neighbour prediction
and blend windows with a literal /2 (the 4:2:0 half) where libaom shifts by
the plane's own subsampling (>>0 at 4:4:4), and obmc_plan's
skip_chroma_above hardcoded the luma shape list that av1_skip_u4x4_pred_in_obmc
only applies to 4x4/8x4/4x8 PLANE blocks, silencing the above-pass chroma
blend of every 8x8/16x8/8x16 OBMC block at 4:4:4. First differing sample:
frame 1 plane 1 x=88 y=4 (leaf mi(0,22), mv=(0,11)). Value-identical at
4:2:0. Stream now byte-exact vs fresh aomdec on all 6 frames; a_lossless
gates 6/6; cargo check 0 warnings.
crates/ec-av1/src/decode.rsmodified+23 -9
@@ -29897,10 +29897,19 @@ pub(crate) fn obmc_plan(
2989729897 let overlap_above = write_h.min(64) / 2;
2989829898 let overlap_left = write_w.min(64) / 2;
2989929899 // lane-inter8 r1 / lane-scaledref r1: `av1_skip_u4x4_pred_in_obmc`
29900- // (`reconinter.c` 820) returns `dir == 0` when the chroma plane's own
29901- // block is BLOCK_4X4/8X4/4X8 (an 8x8, 16x8 or 8x16 luma block at 4:2:0):
29902- // the ABOVE pass skips chroma entirely, the LEFT pass still blends it.
29903- let skip_chroma_above = matches!((write_w, write_h), (8, 8) | (16, 8) | (8, 16));
29900+ // (`reconinter.c` 829) switches on the PLANE block
29901+ // (`get_plane_block_size`, ss-shifted): only 4x4/8x4/4x8 skip the ABOVE
29902+ // pass's chroma (`return dir == 0`), the LEFT pass still blends them.
29903+ // lane-av1-llpred: the old luma-shape list `(8,8)|(16,8)|(8,16)`
29904+ // hardcoded the 4:2:0 plane sizes; at 4:4:4 the plane block is the luma
29905+ // block itself (never 4-wide), so every one of those blocks was silently
29906+ // missing its above-pass chroma OBMC blend. Derive ss from `chroma_side`
29907+ // (`obmc_plan` has no `fctx`, and the encoder callsite passes the same
29908+ // square pair).
29909+ let ss_x = (write_w / chroma_side).trailing_zeros() as usize;
29910+ let ss_y = (write_h / chroma_side).trailing_zeros() as usize;
29911+ let skip_chroma_above =
29912+ matches!((write_w >> ss_x, write_h >> ss_y), (4, 4) | (8, 4) | (4, 8));
2990429913 let mut above = Vec::new();
2990529914 for (off4, span4, nb, src4) in overlappable_above(grid, mi_row, mi_col, bw4, mi_cols, max_nb(bw4))
2990629915 {
@@ -30080,9 +30089,13 @@ pub(crate) fn obmc_run(
3008030089 if !skip_chroma_above {
3008130090 // lane-t900 r13 (measured, NOT a defect): libaom's min-4 clamp
3008230091 // sizes only the OBMC PREDICTION buffer; the blend length is the
30083- // plain half (`build_obmc_inter_pred_above`: `overlap >> ss_y`).
30084- let (cbw, cbh, cox) = (bw / 2, overlap_above / 2, ox / 2);
30085- let cw = cbw.min(write_w / 2 - cox);
30092+ // plain overlap (`build_obmc_inter_pred_above`:
30093+ // `overlap >> ss_y`) -- the PLANE's own subsampling shift, 0 at
30094+ // 4:4:4 (lane-av1-llpred: the old `/2` hardcoded the 4:2:0 half
30095+ // and half-blended every 4:4:4 OBMC block's chroma).
30096+ let (cbw, cbh, cox) =
30097+ (bw >> ss_x(fctx), overlap_above >> ss_y(fctx), ox >> ss_x(fctx));
30098+ let cw = cbw.min((write_w >> ss_x(fctx)) - cox);
3008630099 obmc_neighbour_pred(nu, cpx + cox, cpy, nb.mv, cbw, cbh, false, nb.h_kind, nb.v_kind, nb.scale, &mut tmp_u, fctx);
3008730100 obmc_blend_v(pred_u, chroma_side, cox, 0, cw, cbh, cbw, &tmp_u);
3008830101 obmc_neighbour_pred(nv, cpx + cox, cpy, nb.mv, cbw, cbh, false, nb.h_kind, nb.v_kind, nb.scale, &mut tmp_v, fctx);
@@ -30097,7 +30110,8 @@ pub(crate) fn obmc_run(
3009730110 let (bw, bh, oy) = (overlap_left, nb.span4 * 4, nb.off4 * 4);
3009830111 obmc_neighbour_pred(ny, px, py + oy, nb.mv, bw, bh, true, nb.h_kind, nb.v_kind, nb.scale, &mut tmp_y, fctx);
3009930112 obmc_blend_h(pred_y, side, 0, oy, bw, bh.min(write_h - oy), &tmp_y);
30100- let (cbw, cbh, coy) = (overlap_left / 2, bh / 2, oy / 2);
30113+ let (cbw, cbh, coy) =
30114+ (overlap_left >> ss_x(fctx), bh >> ss_y(fctx), oy >> ss_y(fctx));
3010130115 obmc_neighbour_pred(nu, cpx, cpy + coy, nb.mv, cbw, cbh, false, nb.h_kind, nb.v_kind, nb.scale, &mut tmp_u, fctx);
3010230116 if let Some((_, _, idx)) = ec_mcb {
3010330117 eprintln!(
@@ -30109,7 +30123,7 @@ pub(crate) fn obmc_run(
3010930123 eprintln!("OUR_MCB lrow{r}: {row:?}");
3011030124 }
3011130125 }
30112- let ch = cbh.min(write_h / 2 - coy);
30126+ let ch = cbh.min((write_h >> ss_y(fctx)) - coy);
3011330127 obmc_blend_h(pred_u, chroma_side, 0, coy, cbw, ch, &tmp_u);
3011430128 obmc_neighbour_pred(nv, cpx, cpy + coy, nb.mv, cbw, cbh, false, nb.h_kind, nb.v_kind, nb.scale, &mut tmp_v, fctx);
3011530129 obmc_blend_h(pred_v, chroma_side, 0, coy, cbw, ch, &tmp_v);
lanes/av1llpred.report.mdadded+80 -0
@@ -0,0 +1,80 @@
1+# lane-av1-llpred: the min-partition-8 lossless 4:4:4 chroma OBMC blend is ss-blind
2+
3+## Ticket
4+
5+Remeasure the 2772 chroma pixel diffs the llintra8 lane named (entropy-exact,
6+luma-exact), name the FIRST differing sample, and fix it only if one index
7+explains it. `decode_leaf8`'s palette set untouched (another branch), the
8+reserved 4:2:0 group-tail chroma arm untouched.
9+
10+## Remeasure (this tree @ b3f815c8, BEFORE the change)
11+
12+Same pinned fixture `/tmp/llintra8/testsrc2_min8.obu` (testsrc2 128x96
13+yuv444p, aomenc `--profile=1 --lossless=1 --enable-palette=0
14+--enable-intrabc=0 --min-partition-size=8 --max-partition-size=64`, 6
15+frames), fresh `aomdec --rawvideo` of the same bytes: **2772 chroma diffs
16+reproduced exactly** (frame 0 and all luma planes clean). But the parent's
17+three named sites did NOT hold: the first differing sample is
18+
19+> frame 1, plane 1 (U), x=88 y=4 (mi row 1, col 22), ours=149 ref=150
20+
21+— an inter 8x8 leaf at mi(0,22) with mv=(0,11), not any of mi(0,16),
22+mi(2,24) or mi(8,28) as named. Error maps (residuals are equal by
23+entropy-exactness, so final diff = prediction diff) showed narrow
24+column/row fragments inside blend regions — OBMC shape, not whole-block MC
25+or intra-edge shape.
26+
27+## Root cause: one class, two sites, both "the 4:2:0 half hardcoded"
28+
29+1. `obmc_run` (decode.rs ~30085/30101/30113) sized the CHROMA neighbour
30+ prediction and blend windows with literal `/ 2` (cbw/cbh/cox/cw and
31+ cbh/coy/ch). libaom sizes them per plane with the PLANE's own
32+ subsampling shift (`dec_build_prediction_by_above_pred`:
33+ `(op_mi_size * MI_SIZE) >> pd->subsampling_x`, blend bounds likewise),
34+ which is `>> 0` at 4:4:4 — the chroma blend covered half the columns at
35+ half the offsets. Luma was never affected (luma exact everywhere).
36+2. `obmc_plan`'s `skip_chroma_above` hardcoded the luma shape list
37+ `(8,8)|(16,8)|(8,16)`. libaom's `av1_skip_u4x4_pred_in_obmc`
38+ (reconinter.c:829) switches on the PLANE block
39+ (`get_plane_block_size`): only 4x4/8x4/4x8 skip the ABOVE pass's chroma
40+ (`return dir == 0`). At 4:4:4 the plane block is the luma block itself,
41+ so every 8x8/16x8/8x16 OBMC block was silently missing its above-pass
42+ chroma blend — the (96..101, y8..10) family on leaf mi(2,24).
43+
44+Both fixed to derive ss (from `chroma_side` in `obmc_plan`, `ss_x/ss_y(fctx)`
45+in `obmc_run`); value-identical at 4:2:0 (`/2 == >>ss`). `obmc_run` is shared
46+by the 16x16+ square path and the 8x8 leaf path, so one fix covers both.
47+The `obmc_mask` table was already complete (M1..M32).
48+
49+## Verification (this tree @ HEAD + the change)
50+
51+- Fail-before → fix-after measured in steps: 2772 chroma diffs → 1126
52+ (geometry fix alone) → **0** (skip fix): decode output is byte-exact
53+ against fresh `aomdec --rawvideo` for ALL 6 frames, all planes
54+ (`cmp`-equal 221184 bytes). The stream-exactness claim is now TOTAL for
55+ this fixture.
56+- 4:2:0 non-regression: `cargo test -p ec-av1 --lib a_lossless` → 6 passed,
57+ 0 failed (both 4:2:0 lossless libaom gates, the 444 min-partition-64
58+ inter gate, the sb128 pair, the 16x4 pair).
59+- `cargo check -p ec-av1 --all-targets`: 0 warnings, 0 errors (target dir
60+ `$HOME/.cache/cargo-target-av1llpred`).
61+
62+## Named, not chased (spoken)
63+
64+1. `EC_MCB` rung (decode.rs obmc_run) still windows its own dump with
65+ `write_w / 2` — a lane-t900 4:2:0-era INSTRUMENTATION assumption only;
66+ output-inert, decode unaffected. fix-now(deferred to whoever next
67+ touches that rung).
68+2. The llintra8 report's three named sites (mi(0,16)/mi(2,24)/mi(8,28))
69+ did not match a fresh run of the same bytes; mi(2,24) and mi(8,28) do
70+ appear in the diff set but the FIRST miss was mi(0,22). Lesson recorded:
71+ reremeasure before owning.
72+
73+## Note on the shared oracle
74+
75+All comparisons against fresh `$HOME/.cache/aom-oracle/build/aomdec
76+--rawvideo` output of THE SAME pinned bytes. The oracle tree has no
77+`EC_OBMC` rung (the decoder-side comment claiming a byte-matching oracle
78+format is aspirational); EC_PREDND covers intra only. Fixtures stay in
79+/tmp/llpred + /tmp/llintra8 (regenerable recipes above); nothing committed
80+from fixtures/.