From 14409e1965960c9d89f2e10eb4d76d4f44c7cf2e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Wed, 30 Sep 2026 09:26:04 +0300 Subject: [PATCH] lane-av1422llintra: fix the 4:2:2 dc_sign vote double-count + lane report libaom's get_txb_ctx_general sums one dc sign vote per CHROMA cell, over txb_w_unit above entries and txb_h_unit left entries -- for a TX_4X4 chroma unit, ONE above entry and ONE left entry. At ss (1, 0) one chroma column spans TWO luma mi columns, so the plain around_mi_rect walk summed that column's whole-unit dc sign twice. dc_sign_ctx only reads the vote's SIGNUM, so the doubling is invisible except exactly when above and left cancel: a+l = 0 (ctx 0) becomes 2a+l = +a (ctx 2), and the DC sign symbol is then read off the wrong CDF row and comes out inverted. 4:2:0 and 4:4:4 are immune because the plane block is square there, so the doubling scales the vote uniformly. MEASURED on the pinned 4:2:2 all-intra lossless control ll422_allintra.obu, paired against the instrumented aomdec: the V 4x4 unit at chroma (24, 8) of the BLOCK_32X8 at mi(2,8). The oracle's EC_DBGCTX reads above0=23 left0=13, which sums to dc 0 and reads dc_sign_cdf[0]; ours (EC_DCDUMP) summed the above column twice, got vote +1, read dc_sign_cdf[2], and the tile desynced from that symbol. rng agreed to the bit beforehand (40604 on both sides) and the level read 2 on both sides, so this is a CDF-row difference, not a level or a bit-position one. Three gathers still called the plain around_mi_rect where twenty-odd sibling sites already route ss (1, 0) through around_mi_422_chroma (which samples every second above cell): decode_rect_split's lossless chroma walk at 12735 (the site that produced the fork), read_intrabc_rect_chroma_split at 17802, and decode_block_rect64's tiled chroma walk at 19922. Each guard is byte-identical to the existing ones at 12865/13069/14327/44920 and a no-op at 4:2:0 and 4:4:4. EFFECT (own comparator, per-cell oracle-flip control included): - ll422_allintra LUMA becomes BYTE-EXACT (74 162 wrong -> 0); the whole 311 484-symbol coefficient stream now pairs with no disagreement; chroma 38 235/38 240 wrong -> 3 126/3 139. - W_intrabc and X_intrabc_tiled: frame 0 becomes BYTE-EXACT (first divergence moves from frame 0 to frame 1), totals down 24 % / 19 %. - Y_intrabc_10b: REGRESSION, named in the report -- it now REFUSES at frame 0 with the Golomb-tail guard where it decoded 16/16 wrongly. An isolation control (this fix on main, without the previous lane's chroma-unit mechanism) shows the refusal is caused by the dc gather alone and that the two defects interact: the dc gather alone is neutral-to-worse. Main's call to keep. - 4:2:0 / 4:4:4 lossless and every pinned 4:2:2 refusal gate: 70 passed, 0 failed. NOT GATED, and not described as gated: 4:2:2 is refused at the sequence header and the probe bypass must never be committed, so no committed test can execute the arms this touches. The evidence is the measurement, and the revert moves the numbers (ll422 luma 0 -> 75 210, W/X frame 0 exact -> diverging). --- crates/ec-av1/src/decode.rs | 192 ++++++++++++-- lanes/av1422llintra.report.md | 466 ++++++++++++++++++++++++++++++++++ 2 files changed, 631 insertions(+), 27 deletions(-) create mode 100644 lanes/av1422llintra.report.md diff --git a/crates/ec-av1/src/decode.rs b/crates/ec-av1/src/decode.rs index 3a9ba47e..16e9eeeb 100644 --- a/crates/ec-av1/src/decode.rs +++ b/crates/ec-av1/src/decode.rs @@ -2164,6 +2164,22 @@ pub fn chroma422_sub8_hits() -> usize { CHROMA422_SUB8_HITS.with(|c| c.get()) } +// lane-av1422llintra: how many 4:2:2 LOSSLESS chroma plane blocks +// (`decode_leaf8`) were walked as 4x4 units rather than as the one +// `av1_get_max_uv_txsize` rect that rule only reaches OUTSIDE a lossless +// frame. A 4:2:0 or 4:4:4 frame never takes the arm (its own lossless walk +// was already there), so a witness gate reading 0 here proves the model +// reverted to the rect unit. +thread_local! { + static CHROMA422_LOSSLESS_4X4_HITS: std::cell::Cell = + const { std::cell::Cell::new(0) }; +} + +/// Current value of [`CHROMA422_LOSSLESS_4X4_HITS`]. +pub fn chroma422_lossless_4x4_hits() -> usize { + CHROMA422_LOSSLESS_4X4_HITS.with(|c| c.get()) +} + // lane-av1-422sub8rect: how many PER-PIECE TX_4X4 chroma coefficient units // the INTER sub-8x8 split4 path read on a 4:2:2 frame (ss 1,0) -- one per // non-skipped odd-column piece per plane (`is_chroma_reference`'s @@ -12716,7 +12732,27 @@ fn decode_rect_split( for cu_row in 0..ch_n { for cu_col in 0..cw_n { let cu_mi = (mi_r + cu_row * (span_y / MI), mi_c + cu_col * (span_x / MI)); - let cu_around = neighbours.around_mi_rect(cu_mi, span_x, span_y); + // lane-av1422llintra: at ss (1, 0) one chroma column + // spans TWO luma mi columns, so the plain rect walk sums + // its whole-unit dc sign TWICE where libaom's + // `get_txb_ctx_general` reads `txb_w_unit` chroma cells + // -- one per column. `dc_sign_ctx` only sees the vote's + // SIGNUM, so a doubled above vote flips the row exactly + // when above and left cancel (a+l = 0 -> ctx 0 becomes + // 2a+l = +a). Measured on the pinned 4:2:2 all-intra + // lossless control `ll422_allintra.obu`: the V 4x4 unit + // at chroma (24, 8) of the BLOCK_32X8 at mi(2,8) -- + // oracle `EC_DBGCTX above0=23 left0=13` sums to dc 0 and + // reads `dc_sign_cdf[0]`; ours summed the above column + // twice, got vote +1, and read `dc_sign_cdf[2]`, so the + // DC sign symbol came out inverted and the whole tile + // desynced from there. Identical to the guard one arm up + // at 12865. + let cu_around = if ss_x(fctx) == 1 && ss_y(fctx) == 0 { + neighbours.around_mi_422_chroma(cu_mi, span_x, span_y) + } else { + neighbours.around_mi_rect(cu_mi, span_x, span_y) + }; let cu_reach = tu_reach( bw, bh, @@ -17783,7 +17819,16 @@ fn read_intrabc_rect_chroma_split( for cu_col in 0..nx { let (span_x, span_y) = (uw << ss_x(fctx), uh << ss_y(fctx)); let cu_mi = (mi_r + cu_row * (span_y / MI), mi_c + cu_col * (span_x / MI)); - let cu_around = neighbours.around_mi_rect(cu_mi, span_x, span_y); + // lane-av1422llintra: the same ss (1, 0) above-column + // double-count as the lossless walk at 12735 -- one chroma + // column spans two luma mi columns and libaom reads one. + // Identical at 4:2:0 and 4:4:4, where the plane block is + // square. + let cu_around = if ss_x(fctx) == 1 && ss_y(fctx) == 0 { + neighbours.around_mi_422_chroma(cu_mi, span_x, span_y) + } else { + neighbours.around_mi_rect(cu_mi, span_x, span_y) + }; let (cu_x, cu_y) = (cpx + cu_col * uw, cpy + cu_row * uh); let cu_pred = Pred::Inline(src, cside).offset(cu_row * uh * cside + cu_col * uw); // libaom's `av1_get_tx_type` (blockd.h:1287) reads @@ -19903,7 +19948,15 @@ fn decode_block_rect64( let lsx = uw << ss_x(fctx); let lsy = uh << ss_y(fctx); let cu_mi = (mi_r + cu_row * (lsy / MI), mi_c + cu_col * (lsx / MI)); - neighbours.around_mi_rect(cu_mi, lsx, lsy) + // lane-av1422llintra: same ss (1, 0) above-column + // double-count as 12735 -- one chroma column spans two + // luma mi columns, libaom reads one. Identical number + // at 4:2:0 and 4:4:4. + if ss_x(fctx) == 1 && ss_y(fctx) == 0 { + neighbours.around_mi_422_chroma(cu_mi, lsx, lsy) + } else { + neighbours.around_mi_rect(cu_mi, lsx, lsy) + } }; let lsx = uw << ss_x(fctx); let lsy = uh << ss_y(fctx); @@ -23889,7 +23942,11 @@ fn decode_leaf8( // unit per plane (CfL keeps its contribution, [`decode_block`]'s own // skip-arm rule); no coefficient symbol exists, so the entropy // context never enters the rect read. - if chroma_422 { + // lane-av1422llintra: NOT in a LOSSLESS frame -- `av1_get_tx_size`'s + // first line returns TX_4X4 on every plane there, so the 4x8 plane + // block is two 4x4 units and the `else` arm's per-unit walk is the + // right one. + if chroma_422 && !lossless(fctx) { u_grid = leaf8_chroma422_unit( dec, cdfs, @@ -23932,24 +23989,31 @@ fn decode_leaf8( )?; luma_grid = Grid::Zero(64); } else { - // 4:4:4 lossless: the leaf's chroma plane block is a 2x2 raster of - // TX_4X4 units (`av1_get_tx_size`: lossless forces TX_4X4 on EVERY - // plane), so a skipped leaf predicts per unit -- each from its own - // edges -- like the luma `SKIP_SPLIT_TX` loop above. CfL never fires - // here (`is_cfl_allowed` at lossless needs plane_bsize == 4x4; this - // chroma plane block is 8x8), and intrabc/palette keep the - // whole-plane-block prediction they already run. The guard also - // requires `chroma_444`, so it can never reach the 4:2:2 arm above. - let chroma_units_444 = - chroma_444 && lossless(fctx) && intrabc_bufs.is_none() && palette_uv_bufs.is_none(); + // 4:4:4 AND 4:2:2 lossless: the leaf's chroma plane block is a + // raster of TX_4X4 units (`av1_get_tx_size` returns TX_4X4 for + // EVERY plane of a lossless block, so `av1_get_max_uv_txsize` -- + // the TX_4X8 the 4:2:2 arm above reads -- is never reached), so a + // skipped leaf predicts per unit -- each from its own edges -- like + // the luma `SKIP_SPLIT_TX` loop above. At 4:2:2 that plane block is + // 4x8 (`av1_ss_size_lookup[BLOCK_8X8][1][0]`), so it is one 4x4 + // unit per chroma row pair. CfL never fires here (`is_cfl_allowed` + // at lossless needs plane_bsize == BLOCK_4X4; this plane block is + // 8x8 at 4:4:4 and 4x8 at 4:2:2, neither of which is BLOCK_4X4), + // and intrabc/palette keep the whole-plane-block prediction they + // already run. + let chroma_units_ll = (chroma_444 || chroma_422) + && lossless(fctx) + && intrabc_bufs.is_none() + && palette_uv_bufs.is_none(); + let cu_shape: (usize, usize) = if chroma_422 { (4, 8) } else { (8, 8) }; if let Some((_, ub, _)) = &intrabc_bufs { set_palette_pred(ub.clone(), fctx); } else if let Some((ub, _)) = &palette_uv_bufs { set_palette_pred(ub.clone(), fctx); } - if chroma_units_444 { - for cu_row in 0..2 { - for cu_col in 0..2 { + if chroma_units_ll { + for cu_row in 0..cu_shape.1 / 4 { + for cu_col in 0..cu_shape.0 / 4 { let cu_reach = tu_reach( 8, 8, @@ -24000,9 +24064,9 @@ fn decode_leaf8( } else if let Some((_, vb)) = &palette_uv_bufs { set_palette_pred(vb.clone(), fctx); } - if chroma_units_444 { - for cu_row in 0..2 { - for cu_col in 0..2 { + if chroma_units_ll { + for cu_row in 0..cu_shape.1 / 4 { + for cu_col in 0..cu_shape.0 / 4 { let cu_reach = tu_reach( 8, 8, @@ -24333,7 +24397,7 @@ fn decode_leaf8( if fctx.intrabc_chroma_tx.with(std::cell::Cell::get).is_some() { hit!(INTRABC_TX4_CHROMA_COPY_HITS); } - if chroma_422 { + if chroma_422 && !lossless(fctx) { // lane-av1-422d: the chroma unit does NOT follow the luma var-tx // split -- `uv_txsize` is `av1_get_max_uv_txsize` of the block, // still the one 4x8 rect unit per plane at ss (1,0). @@ -24377,6 +24441,80 @@ fn decode_leaf8( smooth_neighbor_uv, fctx, )?; + } else if (chroma_444 || chroma_422) && lossless(fctx) { + // lane-av1422llintra: a LOSSLESS 4:2:2 leaf is the 4:2:2 twin of + // the 4:4:4 arm below. libaom's `av1_get_tx_size` (`blockd.h:1381`) + // returns TX_4X4 for EVERY plane of a lossless block, and its + // FIRST line is the lossless test -- so `av1_get_max_uv_txsize` + // (the `Tx_4X8` the `chroma_422` arm above reads) is never reached + // in a lossless frame. At ss (1,0) the leaf's chroma PLANE BLOCK is + // 4x8 (`av1_ss_size_lookup[BLOCK_8X8][1][0]`), so it is a + // `(4, 8)` region walked as two 4x4 units per plane, PLANE-MAJOR + // -- the same walk `read_intra_chroma_lossless` runs for whole + // blocks, at this leaf's own 4x8 plane block. + // + // MEASURED: the pinned 4:2:2 all-intra LOSSLESS control + // `ll422_allintra.obu` (43 255 B, sha256 below) against the + // instrumented `aomdec`: its block at mi(0,2) is `EC_IMODE_VAL + // mi_row=0 mi_col=2 bsize=3` (BLOCK_8X8) and the oracle's + // `EC_COEFF` units are `plane=1 row=0`, `plane=1 row=1`, + // `plane=2 row=0`, `plane=2 row=1` -- four 4x4 units, two per + // plane. This arm read ONE `TxbSet::ChromaRect8x4` 4x8 unit per + // plane instead (our `EC_PRED` trace: + // `x=4 y=0 plane=1 bw=4 bh=8 mode=1`, the first line that + // disagrees with the oracle's `EC_PREDOUT8 + // plane=1 row_off=0 txw=4 txh=4` + `row_off=1 txh=4` pair), so + // the tile desynced at that block's second chroma symbol and + // every later pixel decoded from the wrong place. + // + // CfL never rides here: `is_cfl_allowed` (`cfl.h:24`) allows it in + // a lossless block only when the chroma PLANE BLOCK is + // BLOCK_4X4, and a 4:2:2 8x8 leaf's is BLOCK_4X8 -- so + // `read_intra_chroma_lossless`'s no-CfL `read_plane` is the + // correct arm for this shape too. + let (blk_w, blk_h) = if chroma_422 { + (4usize, 8usize) + } else { + (8usize, 8usize) + }; + let (mut uo, mut vo) = (Vec::new(), Vec::new()); + read_intra_chroma_lossless( + dec, + cdfs, + neighbours, + u, + v, + leaf_mi, + (px, py), + (cpx, cpy), + 8, + (blk_w, blk_h), + (0, 0), + (blk_w, blk_h), + blk_w, + reach, + (y.width, y.height), + mode, + uv_predict_mode, + angle_delta_uv, + palette_uv_bufs.as_ref().map(|(a, b)| (&a[..], &b[..])), + smooth_neighbor_uv, + base_q_idx, + &mut uo, + &mut vo, + fctx, + )?; + u_grid = if uo.is_empty() { + Grid::Zero(blk_w * blk_h) + } else { + Grid::Own(uo) + }; + v_grid = if vo.is_empty() { + Grid::Zero(blk_w * blk_h) + } else { + Grid::Own(vo) + }; + hit!(CHROMA422_LOSSLESS_4X4_HITS); } else if chroma_444 && lossless(fctx) { // 4:4:4 lossless: the leaf's chroma plane block is a 2x2 raster // of TX_4X4 units per plane, PLANE-MAJOR (`av1_get_tx_size`: @@ -24506,12 +24644,12 @@ fn decode_leaf8( let bound_w = round_up_even(neighbours.mi_cols); let u_state = neighbour_state(&u_grid); let v_state = neighbour_state(&v_grid); - // The 4:4:4 lossless walk above already stamped these bands PER UNIT - // (its raster-order last writer per cell is exactly libaom's - // per-entry last update); this whole-leaf aggregate would clobber - // four distinct unit states with one, so it runs only for the shapes - // whose chroma really is one unit. - if !(chroma_444 && lossless(fctx)) { + // The 4:4:4 AND 4:2:2 lossless walks above already stamped these + // bands PER UNIT (their raster-order last writer per cell is exactly + // libaom's per-entry last update); this whole-leaf aggregate would + // clobber distinct unit states with one, so it runs only for the + // shapes whose chroma really is one unit. + if !((chroma_444 || chroma_422) && lossless(fctx)) { for cell in 0..side_mi { if cell < side_mi.min(bound_h.saturating_sub(leaf_mi.0)) { neighbours.left[leaf_mi.0 + cell][1] = u_state; diff --git a/lanes/av1422llintra.report.md b/lanes/av1422llintra.report.md new file mode 100644 index 00000000..718e7927 --- /dev/null +++ b/lanes/av1422llintra.report.md @@ -0,0 +1,466 @@ +# lane-av1422llintra — the 4:2:2 lossless chroma context: the dc-sign vote was double-counted + +Base `main` = `3698787d` (the merge of lane-av1422lpf). Worktree +`~/.cache/wt/av1422llintra`, branch `lane-av1422llintra`. + +Two commits: + +1. `1cd7c85f` — the merged gate is renamed to what it asserts and told what it + does **not** cover. It was vacuous with respect to lane-av1422lpf's seven-site + fix. +2. the decode change below — **UN-GATEABLE** (stated, with the reason, and NOT + described as gated). + +Nothing else is committed. `crates/ec-av1/src/stream.rs` carries **no** bypass +in the committed tree; the `EC_AV1_ALLOW_422_PROBE` patch was applied for the +measurements below and reverted (`git diff` on stream.rs after commit 1 is +empty). + +--- + +## 0. Verdict + +| | | +|---|---| +| first-divergent unit found | V 4x4 at chroma (24, 8), `BLOCK_32X8` at mi(2, 8) | +| its cause | the `dc_sign` CDF row, not the level | +| that cause | the above vote was summed **twice** at ss (1, 0) | +| sites fixed | 3 chroma gathers that still used the plain `around_mi_rect` | +| the pinned 4:2:2 all-intra lossless control | **luma now byte-exact** (74 162 wrong -> 0); chroma 38 235/38 240 -> 3 126/3 139 | +| `W_intrabc`, `X_intrabc_tiled` | frame 0 now **byte-exact**; total wrong samples down 24 % / 19 % | +| `Y_intrabc_10b` | **REGRESSION, stated plainly: it now REFUSES at frame 0** (`a Golomb tail longer than this decoder reads`) where it used to decode 16/16 with 1 210 281 wrong luma samples. See §6. | +| regressions in the 422/lossless/444 gate families | **0** — 70 passed, 0 failed | +| a gate for the decode change | **none, and none is possible** — §5 | + +--- + +## 1. Goal A — the merged gate was lying, and is fixed + +`the_pinned_422_lossless_inter_chroma_panics_refuse_by_name` asserted +`REFUSAL = "a chroma format of 4:2:2"` — the **sequence-header** refusal, which +fires before any of the seven per-axis extent sites is reachable, and which +fires identically on the pre-fix tree. Main built `aef4fa67` and measured the +identical string. The gate therefore passes before and after the fix: with +respect to the seven sites it is **vacuous**. Its only real content is the three +pins (size + `fnv1a64`). + +It is now +`the_pinned_422_lossless_inter_witnesses_are_present_and_refuse_by_name`, its +doc says so, and it says the thing that is easy to get wrong: **no committed +test can reach a 4:2:2 decode at all**, because the bypass that would allow it +is a patch-run-restore hack that must never be committed — so the seven-site +panic fix's evidence is the bypassed manual measurement in +`lanes/av1422lpf.report.md`, not this gate. + +The false claim is retracted in the doc rather than deleted silently: the gate's +old name said `..._panics_...`, and lane-av1422lpf's report claimed `W` and `X` +now REFUSE with `a Golomb tail longer than this decoder reads` at frame 2. That +refusal **does not reproduce** — with the bypass, all three cells decode 16/16 +with no panic and no second refusal (measured, §2). + +**A second gate from the same lane carried the same over-claim**, in the softer +form: `the_422_lossless_inter_chroma_walk_sites_stay_per_axis` says "one +assertion per site, each with a mutation proof", which reads like more coverage +than a source scan is. It is a **spelling** scan — it cannot observe a decode — +and its doc now says exactly that. + +**Collateral damage found and repaired**: `69a3a4df` appended its own doc block +in the *middle* of the `lane-av1422warp` gate's doc comment, so +`the_pinned_422_residual_compound_warp_witness_is_present_and_refuses_by_name` +had lost its documentation entirely and two unrelated gates shared one comment +block. The warp doc is moved back onto its own gate. + +The three pins are unchanged. Both gates pass: + +``` +$ cargo test -p ec-av1 --lib -- the_pinned_422_lossless_inter_witnesses_are_present_and_refuse_by_name \ + the_422_lossless_inter_chroma_walk_sites_stay_per_axis +test stream::tests::the_pinned_422_lossless_inter_witnesses_are_present_and_refuse_by_name ... ok +test stream::tests::the_422_lossless_inter_chroma_walk_sites_stay_per_axis ... ok +test result: ok. 2 passed; 0 failed; 0 ignored; 0 measured; 787 filtered out +``` + +--- + +## 2. The measurement rig, and why the numbers below are real + +**Comparator** (`~/.cache/cells/av1422llintra/cmp422.py`, written here): pairs +our `dump_yuv` per-frame dumps against one flat `aomdec --rawvideo` file. The +per-frame plane geometry is derived from width/height/depth, never guessed; a +wrong SAMPLE is one `bps`-wide unit, so the 10-bit cell is counted per 16-bit +sample and not per byte. + +**The comparator has a liveness guard, and it caught me.** A first version +globbed zero frame files (the 10-bit dump had refused) and reported +`Y 0 U 0 V 0 — first wrong: none`, which reads as BYTE-EXACT. That is the class +`oracle-comparator-liveness-control`: a comparator that reads nothing proves +nothing. It now hard-errors on an empty glob, and the "Y_intrabc_10b is exact" +line I would otherwise have written is **retracted** — see §6. + +**Oracle-flip control, per cell** (the acceptance requirement): flip ONE byte of +the oracle dump and the count must move. + +``` +$ for c in W_intrabc:8 X_intrabc_tiled:8 Y_intrabc_10b:10; do cell=${c%%:*}; d=${c##*:}; \ + cp $cell.oracle.yuv /tmp/flip.yuv; \ + python3 -c "b=bytearray(open('/tmp/flip.yuv','rb').read()); b[3]^=0x01; open('/tmp/flip.yuv','wb').write(bytes(b))"; \ + ./cmp422.py $cell. /tmp/flip.yuv 320 240 $d ""; done +``` + +| cell | build | count | count with oracle byte 3 flipped | +|---|---|---|---| +| W_intrabc | after | Y 1 220 912 | Y 1 220 913 | +| X_intrabc_tiled | after | Y 990 733 | Y 990 734 | +| Y_intrabc_10b | after | Y 1 210 281 | Y 1 210 282 | +| W_intrabc | both fixes | Y 917 974 | Y 917 975 | +| X_intrabc_tiled | both fixes | Y 864 325 | Y 864 326 | +| ll422_allintra | both fixes | Y 0 / U 3 126 / V 3 139 | Y 1 / U 3 126 / V 3 139 | + +Every control moves by exactly the one flipped sample. The comparator is live. + +**Oracle soundness**: the oracle dumps are `~/.cache/aom-oracle/build/aomdec` +(the instrumented tree). On `ll422_allintra.obu` its raw output is +sha256 `ae45d5dc220527b29f6a4b4d69583639f1ca3e70b4e284374ffde62ee6ebb84e`, +which is the value the previous lane measured for the instrumented build, the +plain build, the second build and `ffmpeg -pix_fmt yuv422p`. The oracle is +trustworthy for this stream. + +`W_intrabc.oracle.yuv` and `X_intrabc_tiled.oracle.yuv` are byte-identical to +each other (`ea259d96fd2a2ff7...`) — the tiled re-encode of the same source +decodes to the same picture, so their divergence counts are directly comparable. + +**Oracle dumps produced here:** + +``` +$ ~/.cache/cells/av1422llintra/oracle_run.sh +W_intrabc.oracle.yuv 2 457 600 B ea259d96fd2a2ff7... +X_intrabc_tiled.oracle.yuv 2 457 600 B ea259d96fd2a2ff7... (same bytes) +Y_intrabc_10b.oracle.yuv 4 915 200 B dceee9c2ff925845... +ll422_allintra.oracle.yuv 153 600 B ae45d5dc220527b2... +``` + +--- + +## 3. Per-cell before / after (raw commands) + +Three builds of the same worktree, all with the same `EC_AV1_ALLOW_422_PROBE` +bypass, all from `dump_yuv`: + +* **BEFORE** = `main` 3698787d exactly (`git checkout -- crates/ec-av1/src/decode.rs`) +* **after** = BEFORE + Merve2-2's `decode_leaf8` chroma-unit mechanism +* **both fixes** = after + the dc-sign gather fix (this lane) +* **dc-only** = main + the dc-sign gather fix WITHOUT Merve2-2's mechanism + (the isolation control, §6) + +``` +$ export CARGO_TARGET_DIR= EC_NOMEMGUARD=1 EC_AV1_ALLOW_422_PROBE=1 +$ cargo build --release --example dump_yuv -p ec-av1 +$ for c in W_intrabc X_intrabc_tiled Y_intrabc_10b; do \ + ./dumpyuv_ ~/.cache/cells/av1422lpf/$c.obu /$c.; done +$ ./dumpyuv_ ~/.cache/cells/av1422lpf/probe/ll422_allintra.obu /ll422. +$ ./cmp422.py /$c. /$c.oracle.yuv 320 240 <8|10> "$c " +``` + +320x240, 4:2:2, 16 shown frames (1 for `ll422_allintra`). + +| cell | build | Y wrong | U wrong | V wrong | first wrong | +|---|---|---|---|---|---| +| `W_intrabc` | BEFORE | 1 214 609 | 611 596 | 612 205 | frame 0 Y sample 54 | +| | after (Merve) | 1 220 912 | 612 668 | 611 842 | frame 0 Y sample 54 | +| | **both fixes** | **917 974** | **474 518** | **487 693** | **frame 1 Y sample 0** | +| `X_intrabc_tiled` | BEFORE | 1 072 597 | 533 606 | 539 334 | frame 0 Y sample 32 | +| | after (Merve) | 990 733 | 488 493 | 490 484 | frame 0 Y sample 32 | +| | **both fixes** | **864 325** | **421 582** | **414 905** | **frame 1 Y sample 0** | +| `Y_intrabc_10b` (10-bit) | BEFORE | 1 227 876 | 613 885 | 614 058 | frame 0 Y sample 8 (= byte 16) | +| | after (Merve) | 1 210 281 | 612 170 | 613 127 | frame 0 Y sample 48 (= byte 96) | +| | **both fixes** | **REFUSES at frame 0** — §6 | | | | +| `ll422_allintra` (1 frame, pure intra) | BEFORE | 75 210 | 38 235 | 38 240 | frame 0 Y sample 16 | +| | after (Merve) | 74 162 | 36 703 | 37 114 | frame 0 Y sample 64 | +| | **both fixes** | **0** | **3 126** | **3 139** | frame 0 **U** sample 1853 | + +What this says, plainly: **Merve2-2's chroma-unit mechanism alone is not a win** +(`W` gets worse, `X` and `ll422` better, none exact). With the dc-sign gather fix +on top, `W`/`X` lose another 24 %/19 % of their wrong samples and — the +measurement that matters — **frame 0 of both becomes byte-exact**, and the pure +intra control's **luma becomes byte-exact**. + +--- + +## 4. The first divergence, localised + +### 4.1 The pairing + +Three paired rungs, all sequential, all env-gated: + +* `EC_PRED` (ours, `OUR_PRED`) vs the oracle's `EC_PREDOUT8` — prediction, per TU +* `EC_TRACE_COEFF` (both sides, `EC_COEFF_STEP`) — the entropy symbol stream +* `EC_DBGCTX` (oracle) vs the crate's own `EC_CHROMA_PUB` / `EC_DCDUMP` — the + per-cell entropy-context bytes that feed the dc-sign vote + +Four rung-shape differences are normalised away, each because it is a difference +in what is PRINTED, not in what is READ (all four are named in the header of +`pair_coeff.py`): `tx_type` (a lossless block reads no tx_type symbol, so the +oracle's rung fires once per block where ours does not), `ctx`/`dcctx` (printed on +one side only), `c`/`pos` (compared only when both print them), and our +`tag=br` run inside the base_eob arm (libaom prints one finished level where we +print the whole base-range loop). + +### 4.2 Before the dc fix: unit 189 of 9 600 + +``` +FIRST DISAGREEMENT at unit index 189 + oracle: mi=(2,8) plane=2 row_off=1 col_off=1 txw=4 txh=4 mode=8 sum=2408 + ours : x=20 y=12 plane=2 bw=4 bh=4 mode=8 sum=2410 +``` + +and the entropy stream, 4 292 symbols in: + +``` + [4291] O: EC_COEFF_STEP tag=after_bases rng=40604 + U: EC_COEFF_STEP tag=after_bases rng=40604 + [4292] O: EC_COEFF_STEP tag=sign c=0 sign=1 dcctx=0 rng=51524 <== MISMATCH + U: EC_COEFF_STEP tag=sign c=0 sign=0 rng=37124 +``` + +`rng` agrees to the bit (40 604 on both sides), so this is a **CDF row** +difference, not a bit-position difference — and the level read on both sides is +2. The oracle's `dc_sign` vote for that unit is `0`, ours is positive. + +`EC_COEFF plane=2 row=0 col=2 mi_row=2 mi_col=8` names the unit: the third 4x4 +V unit of the `BLOCK_32X8` at mi(2,8), i.e. **chroma (24, 8)**. + +### 4.3 The oracle's own vote, and ours + +libaom `get_txb_ctx_general` (`txb_common.h:280`) sums one `signs[]` vote per +CHROMA cell over `txb_w_unit` above entries and `txb_h_unit` left entries — for +a TX_4X4 chroma unit, **one** above entry and **one** left entry — and indexes +`dc_sign_contexts[dc + 32]`. + +``` +$ EC_DBGCTX=1 aomdec ... ll422_allintra.obu +EC_DBGCTX mi=2,8 plane=2 tx=0 above0=23 left0=13 base=2 off=10 ctx=12 +EC_DBGCTX mi=2,8 plane=2 tx=0 above0=23 left0=12 base=2 off=10 ctx=12 +``` + +Byte 23 = `16 | 7` (positive DC, level 7); byte 13 = `8 | 5` (negative DC, level +5). `signs[23>>3] = +1`, `signs[13>>3] = -1`, sum 0, so +`dc_sign_contexts[0 + 32] = 0` — `dc_sign_cdf[0]`, which is the row the oracle +read (`dcctx=0`). + +Ours (`EC_DCDUMP=1`, the crate's own per-cell gather): + +``` +EC_DCDUMP mi=(2,12) plane=2 wh=(8,4) vote=1 above=[Some(false)/7,Some(false)/7] left=[Some(true)/5] +``` + +**Two above cells.** At ss (1, 0) one chroma column spans TWO luma mi columns, so +the plain `around_mi_rect` walk summed the column's whole-unit dc sign twice: +vote `(+1) + (+1) + (-1) = +1` where libaom's is `(+1) + (-1) = 0`. +`dc_sign_ctx` only sees the vote's SIGNUM, so the doubling is invisible except +exactly when above and left cancel — `a + l = 0` (ctx 0) becomes `2a + l = +a` +(ctx 2). That is the whole defect, and it is why 4:2:0 and 4:4:4 are immune +(there the plane block is square, so the doubling scales the vote uniformly and +the signum is preserved). + +### 4.4 The fix + +Three chroma gathers still called the plain `around_mi_rect` where twenty-odd +sibling sites already route ss (1, 0) through `around_mi_422_chroma` (which +samples every second above cell — libaom's per-chroma-cell count): + +* `decode.rs:12735` — `decode_rect_split`'s lossless chroma walk (**the site that + produced the measured fork**) +* `decode.rs:17802` — `read_intrabc_rect_chroma_split` +* `decode.rs:19922` — `decode_block_rect64`'s tiled chroma walk + +Each is now `if ss_x == 1 && ss_y == 0 { around_mi_422_chroma(..) } else { +around_mi_rect(..) }` — byte-identical to the existing sites at 12865, 13069, +14327 and 44920, and a no-op at 4:2:0 and 4:4:4 by construction. + +### 4.5 After the fix + +``` +$ ./pair_coeff.py oracle_COEFF.log ours_COEFF_FIX.log +oracle symbols 311484 ours 311484 +no disagreement in the first 311484 paired symbols +``` + +**The entire coefficient-symbol stream of `ll422_allintra.obu` now pairs symbol +for symbol**, and the prediction trace pairs for 1 726 consecutive units (it was +189). Luma is byte-exact. What is left is 6 265 chroma samples, and it is +localised: + +``` +$ ./firstdiff.py ll422.FIX ll422_allintra.oracle.yuv 320 240 8 +frame 0 U (93,11) sample 1853: ours 159 oracle 160 +``` + +* **first mis-reconstructed unit: the U 4x4 chroma unit at chroma (92, 8)**, in + the 8x8 leaf at **mi(2,46)** (`EC_IMODE mi_row=2 mi_col=46 bsize=3` = + `BLOCK_8X8`, `mode=2 uv_mode=2`). +* it is a **prediction** difference, not a residual one: our + `OUR_PRED sum=2539` against the oracle's `sum=2542`, with `row0` and `col0` + byte-identical on both sides — so the difference is interior-only, while both + edges in the plane are byte-identical to the oracle (the units above, at + (92,4), and to the left, at (88,8), are not in the differing set). +* the oracle's filters are **inert** on this frame, so this is reconstruction, + not filtering: measured by dumping the oracle's own pre-loop-filter plane + (`EC_AV1_PREFILT_DUMP`) and comparing it to its final output — + `oracle prefilter-vs-final chroma differing samples: 0`, luma `0`. +* 496 of 4 800 chroma 4x4 units differ, 6 265 samples; 302 of those units differ + in all 16 samples. Only V and U; luma is exact. + +**Handed over, named:** the 4:2:2 leaf-8 chroma **prediction** for a +`BLOCK_8X8` chroma unit whose interior differs while both of its edge rows and +its edge column match the oracle byte for byte. The entropy stream is provably +clean up to and past it, so the defect is inside the prediction for this +mode/shape, not in its context gather and not in its residual. + +--- + +## 5. Why there is no gate for the decode change, and what was done instead + +**It cannot be gated, and this lane does not pretend otherwise.** 4:2:2 is refused +at the sequence header by name (`stream.rs:1803`), and the bypass that would +allow a decode is a patch-run-restore hack that must never be committed — so no +committed test, in any build, can execute the arms this change touches. There is +no source-scan substitute that would mean anything here: scanning for the guard's +spelling proves the spelling, which is precisely the criticism §1 levels at the +merged gate. + +What was done instead, and what it is worth: + +1. **The measurement is the evidence**, with the comparator's own liveness + control per cell (§2) and an isolation control that separates this fix from + the previous lane's (§6). +2. **The revert moves the numbers**, which is the only mutation proof available + for unreachable code. Reverting the dc gather (that IS the `BEFORE` / + `after` / `dc-only` row set) puts `ll422_allintra`'s luma back from 0 to + 75 210 wrong samples and its first divergence back to frame 0 Y sample 16, + and puts `W`/`X` back from frame-0-exact to frame-0-diverging. The change is + load-bearing; measured, not asserted. +3. **The three sites are swept as a class**, not one instance: every remaining + `around_mi_rect` chroma gather in `decode.rs` was classified, and the three + that can see ss (1, 0) are fixed. The other `around_mi_rect` call sites are + LUMA gathers (12449, 12499, 12553, 18661, 18712, 18770, 23290, 23383) or are + already guarded, and `around_mi` (18186, 19039) is a one-cell gather with no + above extent to double. + +This is stated as an **un-gateable correctness fix whose evidence is the +measurement**, not as a gated change. + +--- + +## 6. The one regression, stated plainly + +**`Y_intrabc_10b` now refuses at frame 0.** With both fixes it returns +`unsupported: AV1 tile (a Golomb tail longer than this decoder reads)` +(`frames_dispatched: 0`). Before, it decoded 16/16 with 1 227 876 wrong luma +samples. + +Isolation control (the same three sites patched onto **main**, without the +previous lane's chroma-unit mechanism): + +| build | W | X | Y_intrabc_10b | ll422_allintra (luma) | +|---|---|---|---|---| +| main (BEFORE) | 1 214 609 | 1 072 597 | 1 227 876 (decodes) | 75 210 | +| + Merve's mechanism only | 1 220 912 | 990 733 | 1 210 281 (decodes) | 74 162 | +| + dc gather only | 1 218 768 | 1 072 310 | **REFUSES at frame 0** | 75 981 | +| + both (**this lane**) | 917 974 | 864 325 | **REFUSES at frame 0** | **0** | + +So the two defects **interact**: the dc gather alone is neutral-to-slightly-worse +(it moves `ll422`'s fork *earlier*, to Y sample 16, because the leaf-8 defect +then trips a different symbol first), and only the pair is a large win. The +`Y_intrabc_10b` refusal is caused by the dc gather alone, not by the +interaction. + +Reading: on that stream the residual 4:2:2 defect now reaches a long unary run +in frame 0 and trips the named Golomb guard, where before it produced wrong +pixels instead. That is the crate's own honesty convention (a named refusal +beats silently wrong pixels) and it matches how lane-av1422lpf reported its own +panic-to-refusal conversion — but it IS a behaviour change on a cell, it is not +covered by any committed test, and **it is Main's call whether to keep it**. The +case for keeping it: the alternative leaves a defect diagnosed to the line and +the CDF row, unfixed, with `W`/`X` 19–24 % worse and the intra control's luma +wrong in 74 162 samples. + +`Y_intrabc_10b`'s own divergence was not localised past this: its 10-bit trace +pairing is not trustworthy with the four rung-shape normalisations above (the +oracle emits its eob `br` symbols before the `base_eob` line there, the reverse +of the 8-bit cell), so I stopped rather than report a fork index I cannot +defend. **Not claimed.** + +--- + +## 7. Refuted hypotheses, with the evidence + +* **"the previous lane's report's numbers are wrong"** — partly. Its `W`/`X`/ + `Y_intrabc_10b` per-plane counts do not reproduce under a per-SAMPLE + comparator (mine, §3). Its luma counts on `ll422_allintra` (75 210) reproduce + exactly. The difference is the plane attribution: counting 10-bit chroma + BYTE-wise counts the always-zero top 6 bits of each sample, which cannot + differ, so U and V coincide in ways a byte count hides. +* **"the `Golomb tail` refusal on `W`/`X` at frame 2 exists"** — **refuted**. + With the bypass, all three cells decode 16/16 on this tip with no panic and no + second refusal. The claim is retracted in the gate's doc (§1). +* **"the residual is a transform / dequant defect"** — **refuted as the first + cause** on the intra control: after the dc fix the whole 311 484-symbol + coefficient stream pairs, every level matches, and luma is byte-exact. A + dequant defect cannot leave the symbol stream and luma clean. +* **"the residual is a filter (deblock / CDEF / restoration) defect"** — + **refuted**: the oracle's own pre-loop-filter plane equals its final output on + every plane of this frame (0 differing samples), so the filters are inert here + and cannot be where our chroma diverges. +* **"the `txb_skip` / `all_zero` `ctx` mismatch at unit 3 is the fork"** — + **refuted** (re-confirmed): it is a label-space artifact — our chroma tables + hold the offset-7 rows first, so our `ctx=0` is libaom's `ctx=7` — and the + traces agree once `all_zero`'s `ctx` field is excluded. +* **"the oracle is unsound"** — **refuted**: §2, sha256 `ae45d5dc220527b2...`, + matching the previous lane's four-way agreement. +* **"my comparator proved `Y_intrabc_10b` byte-exact"** — **refuted by the + comparator's own liveness guard** (§2). I am recording the retraction because + the false line was produced by a real command, not by a typo. + +--- + +## 8. Regression sweep + +``` +$ CARGO_TARGET_DIR=/home/user/.cache/tgt/av1422llintra EC_NOMEMGUARD=1 \ + cargo test -p ec-av1 --lib -- 422 lossless 444 \ + --skip bitrate_target_lands_within_5_percent_over_48_frames +test result: ok. 70 passed; 0 failed; 0 ignored; 0 measured; 719 filtered out; finished in 26.30s +``` + +**70 passed, 0 failed.** That includes the whole 4:4:4 family, the lossless +transform family, and every pinned 4:2:2 refusal-by-name gate. The skip is the +known separate in-process hang. + +`cargo check -p ec-av1 --all-targets` is clean. + +--- + +## 9. Fixture provenance + +| file | bytes | sha256 | +|---|---|---| +| `W_intrabc.obu` | 130 320 | `0aad0d6fdd23655749110baf7db6e831d78103ef4bd0355dcd49ba6276af310c` | +| `X_intrabc_tiled.obu` | 131 696 | `e7c0c60af1a615312196bfba042b558aca73302ce6c7b85d93096369192fb40b` | +| `Y_intrabc_10b.obu` | 202 281 | `ce84d7cb4cfadf3f52f783628dfbfcf5c07059ddbc356889967f4e7a764b2c22` | +| `probe/ll422_allintra.obu` | 43 255 | `d56f6b655743897ad998f7dbba7742cb4c3fa677b544d72fddb2d8223085dfb8` | + +No instrumentation remains in the committed tree. Every trace used above is the +crate's own env-gated rung or the oracle's pre-existing one; nothing was left +behind. + +## 10. `not_done` + +- **`Y_intrabc_10b` is not localised** past "it refuses at frame 0" (§6), and its + fork is not reported because its 10-bit rung-shape normalisation is not + trustworthy. +- **The remaining `ll422_allintra` chroma residual is handed over, not fixed** + (§4.5): the leaf-8 chroma PREDICTION at chroma (92, 8), mi(2,46), interior-only. +- **`W`/`X` frames 1..15 are not localised** — only frame 0 is now exact. +- **No committed gate exists for the decode change and none can** (§5). +- **No full-suite run** (lane rules: scoped only; project-wide validation is + Main's).