diff --git a/crates/ec-av1/src/decode.rs b/crates/ec-av1/src/decode.rs index 6e5e9abd..553ff958 100644 --- a/crates/ec-av1/src/decode.rs +++ b/crates/ec-av1/src/decode.rs @@ -19919,12 +19919,43 @@ fn sub8_leaf_chroma422( scan4: &[u16], base_q_idx: u8, smooth_neighbor_uv: bool, + // The owning luma leaf's own shape (`(4, 4)` for a split leaf, `(8, 4)` / + // `(4, 8)` for a rect pair's strip): libaom's `has_top_right` / + // `has_bottom_left` answer for this chroma TX_4X4 unit comes from the + // LEAF's own rect table row at the leaf's mi (`bsize` is the leaf, the + // unit covers it whole), never the standalone square-4x4 table the old + // `Reach::of(4, ..)` lookup used -- that said 1 where `has_tr_8x4` says 0 + // at mi(27,44) (the oracle's own EC_PRED prints `n_tr=0` there), so the + // D45 unit read undecoded pixels to its upper right. + leaf_shape: (usize, usize), fctx: &crate::decode::FrameCtx, ) -> Result<(Grid, Grid)> { let uv_predict_mode = if uv_mode == UV_CFL_PRED { DC_PRED } else { uv_mode }; - neighbours.record_uv_mode_mi(lmi.0, lmi.1, 1, 1, uv_predict_mode); + // lane-av1-422kf2: libaom writes one MB_MODE_INFO per mi cell the LEAF + // covers, and `chroma_left_mbmi`/`chroma_above_mbmi` read whichever of + // those cells the next block's snap lands on -- an 8x4 strip's SM_V + // uv_mode must therefore be visible at BOTH of its mi columns, or the + // block to its right (mi (30,50): left neighbour cell (30,49)) missed the + // smooth neighbour and skipped libaom's strength-1 intra edge filter + // (class context-read-from-one-cell, the 4:2:2 sub-8 twin of the + // lane-kf900 snap fix). + neighbours.record_uv_mode_mi( + lmi.0, + lmi.1, + (leaf_shape.0 / MI).max(1), + (leaf_shape.1 / MI).max(1), + uv_predict_mode, + ); let (px, py) = (lmi.1 * MI, lmi.0 * MI); - let (cpx, cpy) = (px >> ss_x(fctx), py >> ss_y(fctx)); + // lane-av1-422kf2: the unit's WRITE/PREDICTION anchor is the same floored + // chroma cell as the entropy anchor below -- libaom positions the sub-8 + // chroma plane block at `av1_setup_dst_planes`' mi-exact floor + // (`(mi_col & !1) * MI >> ss_x`), NOT at the odd leaf's own chroma x: + // the oracle's mi(18,55) TX_4X4 unit reconstructed chroma px 108..111 + // (a pure V-copy of the row above at 108..111), while the leaf's own + // chroma x is 110 -- anchoring there left px 108..109 unwritten (zeros) + // and stepped px 112..113 with the unit's right columns. + let (cpx, cpy) = (((lmi.1 & !1) * MI) >> ss_x(fctx), py >> ss_y(fctx)); // lane-av1-422h: the entropy-context anchor is the unit's FLOOR chroma // cell (`pd->above_entropy_context + (mi_col >> ss_x)`): an ODD-column // leaf's 4-px unit starts at a chroma px that is NOT cell aligned, and @@ -19935,9 +19966,17 @@ fn sub8_leaf_chroma422( // overwrites exactly the cell the first one wrote, as libaom's // `av1_set_entropy_contexts` per-TU writes do. let ctx_mi = (lmi.0, lmi.1 & !1); - // The square unit takes the leaf's own `Reach::of` (its luma's), the way - // [`decode_leaf8`]'s 422 arm passes the enclosing block's luma reach. - let reach = Reach::of(4, px, py, y.width, y.height, fctx); + // lane-av1-422kf2: the square unit takes the leaf's OWN reach: a split + // leaf is a standalone BLOCK_4X4 (square table), a rect pair's strip is + // `of_rect` on the strip's true (8x4 / 4x8) shape -- libaom passes the + // LEAF's bsize to `has_top_right`/`has_bottom_left`, so a rect strip's + // answer comes from `has_tr_8x4`/`has_tr_4x8` at the strip's mi, not + // from a 4x4-block lookup. + let reach = if leaf_shape == (4, 4) { + Reach::of(4, px, py, y.width, y.height, fctx) + } else { + Reach::of_rect(leaf_shape.0, leaf_shape.1, px, py, y.width, y.height, fctx) + }; let chroma_around = neighbours.around_mi_422_chroma(ctx_mi, 8, 4); let ac = alpha.map(|_| cfl_src_rect(px, py, 8, 4)); let grids: (Grid, Grid) = if skip { @@ -20206,7 +20245,8 @@ fn decode_leaf_split4( sub8_leaf_chroma422( dec, cdfs, neighbours, lmi, DC_PRED, 0, None, skip, Some(dv), y, u, v, scan4, base_q_idx, - neighbours.smooth_uv_neighbour(lmi.0, lmi.1, r, c, fctx), fctx, + neighbours.smooth_uv_neighbour(lmi.0, lmi.1, r, c, fctx), + (4, 4), fctx, )?; last_uv422 = DC_PRED; } else { @@ -20280,7 +20320,8 @@ fn decode_leaf_split4( sub8_leaf_chroma422( dec, cdfs, neighbours, lmi, uv_mode, angle_delta_uv, alpha, skip, None, y, u, v, scan4, base_q_idx, - neighbours.smooth_uv_neighbour(lmi.0, lmi.1, r, c, fctx), fctx, + neighbours.smooth_uv_neighbour(lmi.0, lmi.1, r, c, fctx), + (4, 4), fctx, )?; last_uv422 = if uv_mode == UV_CFL_PRED { DC_PRED } else { uv_mode }; } else { @@ -20744,7 +20785,8 @@ fn decode_leaf_rect8( sub8_leaf_chroma422( dec, cdfs, neighbours, lmi, DC_PRED, 0, None, skip, Some(dv), y, u, v, scan4, base_q_idx, - neighbours.smooth_uv_neighbour(lmi.0, lmi.1, r, c, fctx), fctx, + neighbours.smooth_uv_neighbour(lmi.0, lmi.1, r, c, fctx), + (bw, bh), fctx, )?; last_uv422 = DC_PRED; } else { @@ -20912,7 +20954,8 @@ fn decode_leaf_rect8( sub8_leaf_chroma422( dec, cdfs, neighbours, lmi, uv_mode, angle_delta_uv, alpha, skip, None, y, u, v, scan4, base_q_idx, - neighbours.smooth_uv_neighbour(lmi.0, lmi.1, r, c, fctx), fctx, + neighbours.smooth_uv_neighbour(lmi.0, lmi.1, r, c, fctx), + (bw, bh), fctx, )?; last_uv422 = if uv_mode == UV_CFL_PRED { DC_PRED } else { uv_mode }; } else { @@ -21015,7 +21058,8 @@ fn decode_leaf_rect8( sub8_leaf_chroma422( dec, cdfs, neighbours, lmi, uv_mode, angle_delta_uv, alpha, skip, None, y, u, v, scan4, base_q_idx, - neighbours.smooth_uv_neighbour(lmi.0, lmi.1, r, c, fctx), fctx, + neighbours.smooth_uv_neighbour(lmi.0, lmi.1, r, c, fctx), + (bw, bh), fctx, )?; last_uv422 = if uv_mode == UV_CFL_PRED { DC_PRED } else { uv_mode }; } else { diff --git a/lanes/av1422kf2.report.md b/lanes/av1422kf2.report.md new file mode 100644 index 00000000..2d29ba5b --- /dev/null +++ b/lanes/av1422kf2.report.md @@ -0,0 +1,97 @@ +# lane-av1-422kf2 — the remaining frame-0 class at U (108, 72) / V (48, 0): +# NAMED and FIXED — the sub-8x8 4:2:2 chroma unit decoded at the wrong +# position, wrong reach table and half-visible neighbour mode (three related +# one-index defects, all in [`sub8_leaf_chroma422`]); frame-0 PRE-FILTER +# reconstruction is now pixel-exact (Y, U and V) against the oracle's +# `EC_AV1_PREFILT_DUMP` + +## Outcome + +1. REMEASURED first (pinned fixture, single-frame cut + `/tmp/t422f0.obu` sha256 `3dd3f768ef553c02316848c2d3184c3765030c0a6fcb95887e4719add9ded3af` + — first OBU prefix of the pinned 22-frame t422.obu; the frame is + **256x144**, chroma planes 128x144; local `EC_AV1_ALLOW_422_PROBE` + bypass applied, reverted byte-identical after): at the parent's baseline + the pre-filter chroma diffs were U 533 / V 869, first U (108, 72) — + confirming the parent's sample. +2. NAMED the class at U (108, 72): the 8x8 luma block at luma (216, 72) + splits into four 4x4 leaves; 4:2:2's `is_chroma_reference` + (`av1_common_int.h:1454`) puts the chroma syntax on the ODD-column leaves + (`(mi_col & 1) || !(bw & 1) || !ss_x` — the port already read uv_mode + there, entropy in sync, luma byte-exact), but libaom ANCHORS the leaf's + TX_4X4 chroma unit at the floored chroma cell + (`(mi_col & !1) * MI >> ss_x` = chroma px 108), not at the odd leaf's own + chroma x (110). Ours reconstructed at 110: px 108..109 were never written + (zeros at exactly the parent's sample), px 112..113 got the unit's right + columns. Oracle ground truth: the mi(18,55) unit's reconstruction is a + pure V-copy of the row above AT 108..111. Fix 1: anchor `cpx` at + `(lmi.1 & !1) * MI >> ss_x`. U/V prefilt 533/869 → 477/813, first diff + moved to (96, 104). +3. The (96, 104) cluster named the next layer: an 8x4 strip's chroma unit + (mi(27,44), uv D45) read undecoded pixels to its upper right. The oracle's + own `EC_PRED` trace prints `n_tr=0` there: libaom answers + `has_top_right`/`has_bottom_left` from the LEAF's OWN rect shape + (`has_tr_8x4`/`has_tr_4x8` at the leaf's mi — bit 6 of byte 22 is 0), + while the port used the standalone square-4x4 `Reach::of(4, ..)` lookup + (same bit = 1). Fix 2: `sub8_leaf_chroma422` takes the leaf's shape and + uses `Reach::of(4, ..)` only for a BLOCK_4X4 leaf, `Reach::of_rect(8, 4)` + / `(4, 8)` for a rect pair's strip. Prefilt chroma 477/813 → 8/15. +4. The last 8/15 samples (chroma (100..103, 120..123), the H-mode unit at + mi(30,50)) named the third defect: the unit's left neighbour mi(30,48) is + an 8x4 strip with uv SMOOTH_V, but its `record_uv_mode_mi(…, 1, 1, …)` + stamped only ONE of the strip's two mi columns, so mi(30,50)'s + `chroma_left_mbmi` lookup hit an empty cell, lost the smooth neighbour and + skipped libaom's always-on strength-1 intra edge filter + (`get_intra_edge_filter_type` 1 vs our 0; prediction sums 6139/6307 vs + 6142/6312). Fix 3: record the uv mode over the leaf's whole mi footprint + (`(w_mi, h_mi)` from the leaf shape). All three fixes are inside + [`sub8_leaf_chroma422`] and its five call sites. +5. MEASURED after the three fixes: **PREFILT Y EXACT, U EXACT, V EXACT** + (byte-identical frame-0 pre-loop-filter reconstruction against the oracle + dump). FINAL dumps: U 1774 → 1236, V 2165 → 1263 — every remaining final + diff is introduced by the LOOP FILTER (pre-filter row 0 is exact; the + filter propagates damage to the top rows). Non-vacuity: + `chroma422_square` = 24, `chroma422_rect` = 96, `chroma422_sub8` = 26 on + this frame — all three touched arms provably ran. +6. REMAINING class for the next lane: the 4:2:2 LOOP FILTER. With pre-filter + recon byte-exact, the 1236/1263 final-diff samples are deblock/CDEF/LR + chroma work (the parent's V (48, 0) is this class's first final sample — + pre-filter V at row 0 is exact). Frame 0 is still not final-pixel-exact, + so the "delete the header refusal" condition stays unmet. + +## Decision + +- The palette set in 93c4dff5 is untouched (chroma422_square still 24; the + chroma_tiled arm's `set_palette_pred` intact). +- `read_coeffs_rect` untouched. The frame-9 rect scratch panic is untouched. + The 4:2:0 group-tail SKIP arm untouched. Header refusal STAYS + unconditional in `stream.rs` — verified firing by name on this very + fixture after the bypass revert, plus the named gate test. +- The bypass was local-only (`EC_AV1_ALLOW_422_PROBE` on the env, one + `&& std::env::var(…).is_err()` clause), reverted byte-identical before the + commit; `git diff` after the revert carries ONLY the decode.rs fix. + +## Verification + +- `cargo check -p ec-av1` (target `~/.cache/cargo-target-av1422kf2`): + 0 warnings, 0 errors. +- 420 gate green under `EC_AV1_REQUIRE_AOMENC=1`: + `stream::tests::a_real_aomenc_stream_with_a_skipped_8x8_intra_leaf_ + whose_tx_split_decodes_pixel_exact`: 1 passed, 0 failed. +- `stream::tests::a_non_420_subsampled_sequence_header_is_refused_by_name`: + 1 passed, 0 failed. +- Stage dumps compared sample-for-sample (cropped `PREFILT_WIDE_DUMP` vs the + oracle `EC_AV1_PREFILT_DUMP`, same 73728-byte layout, 256x144 / 128x144): + post-fix Y/U/V all exact; symbol-level pairing via the oracle's + `EC_ISTEP`/`EC_PALSYN`/`EC_PRED`/`EC_PREDOUT8` rungs against our + `EC_TRACE_MODE_STEP`/`EC_PRED` traces (rng and values matched at every + step of every unit named above). + +## State + +- Commit on lane-av1-422kf2 (no push): the three sub8-422 chroma fixes + + this report. +- Next stop named for the owning lane: the 4:2:2 loop filter — deblock/CDEF + chroma extents against `$HOME/.cache/aom-oracle/build` aomdec dumps + (`EC_AV1_POSTDEBLOCK_DUMP` rungs exist on both sides); the decode-side + frame-0 recon it consumes is now proven exact.