diff --git a/crates/ec-av1/examples/decode_probe.rs b/crates/ec-av1/examples/decode_probe.rs index 7a27aee2..bc36ce1f 100644 --- a/crates/ec-av1/examples/decode_probe.rs +++ b/crates/ec-av1/examples/decode_probe.rs @@ -105,6 +105,10 @@ fn main() { ); let (h84, h48) = ec_av1::decode::sub8_inter_rect_hits(); println!("sub8_inter_rect: horz8x4={h84} vert4x8={h48}"); + println!( + "llintra8_chroma_walk: {}", + ec_av1::decode::llintra8_chroma_walk_hits() + ); let si = ec_av1::stream::sub8_intra_rect_hits(); println!( "sub8_intra_rect: horz8x4={} vert4x8={} chroma_ref={} mixed={} split4x4={}", diff --git a/crates/ec-av1/src/decode.rs b/crates/ec-av1/src/decode.rs index bd0f2e89..87feb284 100644 --- a/crates/ec-av1/src/decode.rs +++ b/crates/ec-av1/src/decode.rs @@ -25795,6 +25795,21 @@ pub(crate) fn chroma_split_tx_hits() -> usize { CHROMA_SPLIT_TX_HITS.with(std::cell::Cell::get) } +thread_local! { + /// How many INTRA leaves of an inter frame's 8x8 block ran the lossless + /// 4:4:4 chroma walk ([`read_intra_chroma_lossless`], lane-av1-llintra8) + /// -- one bump per leaf, four units per plane inside it. A gate proving + /// the arm must see this nonzero; CHROMA_SPLIT_TX_HITS alone cannot + /// attribute its bumps to THIS leaf. + pub(crate) static LLINTRA8_CHROMA_WALK_HITS: std::cell::Cell = const { std::cell::Cell::new(0) }; +} + +/// [`LLINTRA8_CHROMA_WALK_HITS`]: lossless 4:4:4 chroma walks through an +/// inter frame's 8x8 INTRA leaf. +pub fn llintra8_chroma_walk_hits() -> usize { + LLINTRA8_CHROMA_WALK_HITS.with(|c| c.get()) +} + fn read_sb128_root( dec: &mut SymbolDecoder, cdfs: &mut Cdfs, @@ -38538,10 +38553,22 @@ fn decode_inter_block8( // but `DC_PRED` was refused here, which is what blocked the low-cq // CDEF arms and the 10-bit gates. let has_chroma = !mono(fctx); + // lane-av1-llintra8: `read_intra_mode_uv` (decodemv.c:145) picks the + // uv CDF row by `is_cfl_allowed` (cfl.h:23) -- at LOSSLESS that is + // "the chroma plane block is BLOCK_4X4" (cfl.h:29), for this + // BLOCK_8X8 leaf only at 4:2:0. The 4:4:4 lossless leaf reads the + // 13-symbol `uv_mode_no_cfl` alphabet; the unconditional CFL row + // consumed a different partition than aomdec at the leaf's own + // uv_mode symbol (class wrong-alphabet-same-value) and desynced + // every stream that reached the leaf's lossless chroma walk below. + // 4:2:0 and every non-lossless partition keep the CFL row + // (`cfl_allowed_px` answers true exactly as before). let uv_mode = if !has_chroma { DC_PRED - } else { + } else if cfl_allowed_px(SIDE, SIDE, fctx) { dec.symbol(&mut cdfs.uv_mode_cfl[mode]) + } else { + dec.symbol(&mut cdfs.uv_mode_no_cfl[mode]) }; if crate::envflags::env_flag!("EC_TRACE_MODE_STEP") { eprintln!( @@ -38951,6 +38978,33 @@ fn decode_inter_block8( )? }; let ac = alpha.map(|_| cfl_src(px, py, SIDE)); + if chroma_side == 8 && lossless(fctx) && !mono(fctx) { + // lane-av1-llintra8: lossless codes TX_4X4 on EVERY plane + // (`av1_get_tx_size`, blockd.h:1383), so this intra leaf's 8x8 + // chroma plane block is a 2x2 raster of TX_4X4 units per + // plane, plane-major -- the same per-unit walk the >=16x16 + // intra-in-inter block runs, not one TX_8X8 unit (whose WHT + // hits `TxParams::run`'s `(8, 8) != (4, 4)` lossless assert). + // The walk stamps each unit's own coefficient context + // (`record_mi_chroma` inside it), so the tail's whole-block + // `record_mi` gets its chroma half saved/restored around -- + // the same rule the INTER arms' + // `leaf8_inter_chroma_lossless` obeys. 4:2:0 keeps its single + // TX_4X4 unit in the `else` below. + let (mut uo, mut vo) = (Vec::new(), Vec::new()); + read_intra_chroma_lossless( + dec, cdfs, neighbours, u, v, leaf_mi, (px, py), (cpx, cpy), + SIDE, (chroma_side, chroma_side), (0, 0), + (chroma_side, chroma_side), chroma_side, 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(64) } else { Grid::Own(uo) }; + v_grid = if vo.is_empty() { Grid::Zero(64) } else { Grid::Own(vo) }; + chroma_stamped_per_unit = true; + hit!(LLINTRA8_CHROMA_WALK_HITS); + } else { if let Some((ub, _)) = &palette_uv_bufs { set_palette_pred(ub.clone(), fctx); } @@ -39001,6 +39055,7 @@ fn decode_inter_block8( None, smooth_neighbor_uv, fctx, )?; + } } } // lane-txselect: a split leaf's plane-0 neighbour context is per 4x4 diff --git a/lanes/av1llintra8.report.md b/lanes/av1llintra8.report.md new file mode 100644 index 00000000..a5dc3e47 --- /dev/null +++ b/lanes/av1llintra8.report.md @@ -0,0 +1,105 @@ +# lane-av1-llintra8: the inter frame's 8x8 INTRA leaf lossless 4:4:4 chroma walk + +## Ticket + +`decode_inter_block8`'s intra leaf read 4:4:4 lossless chroma as ONE TX_8X8 +unit (`u_grid`/`v_grid = read_plane(..)` at `chroma_side == 8`, +decode.rs:38958/:38985 pre-change) and hit `TxParams::run`'s lossless WHT +assert `(8, 8) != (4, 4)` at decode.rs:2566 — the one arm sibling +`84acbd09`/fb4e4b0e did not cover (it routed the INTER arms only, named in +llsub8b's report item 1). `decode_inter_sub8_rect2` and +`sub8_leaf_chroma444` untouched (owned elsewhere). + +## Change (decode.rs, one branch + one alphabet gate + counter) + +1. `chroma_side == 8 && lossless(fctx) && !mono(fctx)` routes the leaf's + chroma through `read_intra_chroma_lossless` — the intra twin the >=16x16 + intra-in-inter block already runs (plane-major 2x2 raster of TX_4X4 + units per plane, `av1_get_tx_size` blockd.h:1383) — with region and + block `(8, 8)` at stride 8, the leaf's own `reach`, and the leaf's + `palette_uv_bufs` windowed per unit by the helper. The walk stamps each + unit's own coefficient context, so `chroma_stamped_per_unit = true` and + the tail's whole-block `record_mi` gets its chroma half saved/restored + around — the same rule the INTER arms' `leaf8_inter_chroma_lossless` + obeys (the mechanism was already in place). `Grid::Zero(64)` when every + unit hung off the frame edge, matching the inter helper. 4:2:0: zero + change — the branch lives inside `chroma_side == 8`, and the reserved + 4:2:0 group-tail chroma arm was not touched. +2. SAME LEAF, one read earlier, second defect of the same class: the leaf + read `uv_mode` off `uv_mode_cfl[mode]` unconditionally, but libaom picks + the uv CDF row by `is_cfl_allowed` (decodemv.c:145, cfl.h:23) and at + LOSSLESS that is "the chroma plane block is BLOCK_4X4" (cfl.h:29) — + for this BLOCK_8X8 leaf only at 4:2:0. A 4:4:4 lossless leaf must read + the 13-symbol `uv_mode_no_cfl` alphabet; the tables differ (cdf.rs + `UV_MODE_CFL` vs `UV_MODE_NO_CFL`, row 0: 10407.. vs 22631..), so the + unconditional CFL row consumed a different partition at the leaf's own + uv_mode symbol and desynced every stream that reached the leaf. + Now gated on `cfl_allowed_px(SIDE, SIDE, fctx)` — the same gate five + other readers use; 4:2:0 lossless and every non-lossless partition + still take the CFL row (value-identical reads). +3. Non-vacuity counter `LLINTRA8_CHROMA_WALK_HITS` + + `llintra8_chroma_walk_hits()` + a `decode_probe` line, per the lane + convention: CHROMA_SPLIT_TX_HITS cannot attribute its bumps to this + leaf. + +## Verification (measured, this tree @ HEAD + this change) + +- Fail-before (assert): `testsrc2 128x96 yuv444p`, aomenc + `--profile=1 --lossless=1 --enable-palette=0 --enable-intrabc=0 + --max-partition-size=64`, 6 frames (`/tmp/llintra8/t6.obu`) → panic + `(8, 8) != (4, 4)` at decode.rs:2566, debug backtrace + `read_plane (decode.rs:38958) → push_intra_tx → TxParams::run`. The + release build's assert folds into an index panic at `exec_intra`; the + debug line numbers are the evidence. +- Fail-before (alphabet): with only the uv hunk reverted, the regenerated + `--min-partition-size=8` stream's EC_COEFF trace diverges from aomdec's + at all_zero #2400 — `plane=0 mi(4,0)`, the reads right after that leaf's + uv_mode symbol. With the fix: divergence gone (below). +- Entropy witness: `testsrc2 128x96 yuv444p` with + `--min-partition-size=8 --max-partition-size=64` (min 8 excludes the + sub-8 shapes so the leaf actually fires; key frame becomes exact too): + our EC_COEFF `all_zero` rng sequence matches fresh + `aomdec --rawvideo` **11292/11292 reads across all 6 frames** with the + walk firing 34 times; frame 0 is byte-exact and ALL luma planes are + byte-exact stream-wide. The pre-fix stream panicked at the leaf; this + stream decodes all 6 frames. +- Non-regression: sibling's own witness bytes + `/tmp/ll444/dodge2.obu` decode byte-exact vs fresh `aomdec`, 6 frames, + in this tree with this change. +- Gates: `cargo test -p ec-av1 --lib a_lossless` → 6 passed, 0 failed + (both 4:2:0 lossless libaom gates, the 444 min-partition-64 inter gate, + the sb128 pair, the 16x4 pair). +- `cargo check -p ec-av1 --all-targets`: 0 warnings, 0 errors (target dir + `$HOME/.cache/cargo-target-av1llintra8`). Release decode_probe output + identical to debug on both streams. +- Fixtures are scratch in /tmp/llintra8 (regenerable recipes above); + fixtures/ is gitignored, nothing committed from it. + +## Named, not chased (spoken) + +1. Chroma PREDICTION pixel diffs, entropy-exact: on the min-8 stream, + 2772 bytes differ from aomdec — all chroma, luma exact, and the EC_COEFF + trace is bit-aligned everywhere (so symbols, uv modes and angle deltas + all match; only reconstructed pixels differ). Frame 1's diffs cover + three readers at once with clean upstream edges: the inter 8x16 strip's + chroma at mi(0,16) (2x4 units, MC-side), an INTRA 8x8 leaf at mi(2,24) + (uv V_PRED, via this lane's new walk), and the >=16x16 intra block's + chroma at mi(8,28) (the pre-existing `read_intra_chroma_lossless` + caller, untouched by this change). One shared per-unit chroma + prediction-input class across readers, present before this change + (the >=16 arm predates it) — larger than this arm. + deferred(the lane owning per-unit 4:4:4 chroma prediction: + `read_plane`/`PlaneBuf::reconstruct` intra chroma edges + the inter + strip chroma MC), with the min-8 stream as a ready-made fixture. +2. The default-partition (min 4) testsrc2 key frame still entropy-diverges + at frame-0 coefficient read #452 (pre-existing, key-frame intra lane; + llsub8b's item 3). The min-8 key frame is exact, so this lane's witness + does not depend on it. + +## Note on the shared oracle + +aomenc/aomdec are the shared `$HOME/.cache/aom-oracle/build`; the +EC_COEFF/EC_COEFF_STEP rungs of that patched tree are what the entropy +pairing above used. Today's aomenc produces different RD picks than this +morning's (llsub8b's note), so every comparison is against fresh aomdec +output of THE SAME bytes.