From 2c4214864d0beaef1b5402237b66f915f72e9d9a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Wed, 23 Sep 2026 13:06:02 +0300 Subject: [PATCH] ec-av1: reconstruct skipped sub8 intrabc chroma --- crates/ec-av1/src/decode.rs | 73 ++++++++++++++++--------- crates/ec-av1/src/stream.rs | 26 ++++++--- lanes/av1loss64.report.md | 105 ++++++++++++++++++++++++++++++++++++ 3 files changed, 172 insertions(+), 32 deletions(-) create mode 100644 lanes/av1loss64.report.md diff --git a/crates/ec-av1/src/decode.rs b/crates/ec-av1/src/decode.rs index e0af3485..c2a0a5bf 100644 --- a/crates/ec-av1/src/decode.rs +++ b/crates/ec-av1/src/decode.rs @@ -17884,7 +17884,7 @@ fn decode_leaf_rect8( neighbours.above_uv_mode[c] = uv_predict_mode; neighbours.left_uv_mode[r] = uv_predict_mode; neighbours.record_uv_mode_mi(leaf_mi.0, leaf_mi.1, 2, 2, uv_predict_mode); - let (u_grid, v_grid): (Grid, Grid) = if leaf_skips[1] { + let (u_grid, v_grid): (Grid, Grid) = if leaf_skips[1] && last_intrabc.is_none() { // A skipped chroma block still gets its CfL contribution: libaom's // `predict_and_reconstruct_intra_block` calls `cfl_predict_block` // from `av1_predict_intra_block_facade` (av1/common/reconintra.c:1719) @@ -17914,37 +17914,62 @@ fn decode_leaf_rect8( } (Grid::Zero(16), Grid::Zero(16)) } else if let Some(dv) = last_intrabc { - // lane-av1txr: the chroma-reference leaf was an intrabc block, so the - // group's one chroma unit is a frame copy at that DV too (its residual - // still reads the ordinary `Chroma4` coefficient tables -- libaom - // codes a chroma `tx_type` nowhere). + // A 4:2:0 `BLOCK_4X8`/`BLOCK_8X4` leaf maps to a clamped chroma + // `BLOCK_4X4` (`get_plane_block_size`, blockd.h:1184; `set_plane_n4`, + // av1_common_int.h:1344). The chroma reference is still the whole + // 8x8 group's 4x4 plane block at `(cpx, cpy)`, so prediction uses the + // group's destination origin, not the odd-mi leaf's nominal 2x4/4x2 + // extent. The old route treated a skipped intrabc leaf as skipped + // intra and predicted this block with DC, first differing at + // mi(46,52), U(104,92), while consuming identical symbols. + let chroma_mv_x = mv_to_q4(cpx, dv.1, false); + let chroma_mv_y = mv_to_q4(cpy, dv.0, false); + // `decode_reconstruct_tx` reads no chroma coefficients for a skipped + // intrabc block, but an unskipped one reads the ordinary Chroma4 + // tables; chroma inherits no coded tx_type of its own. let mut ub = vec![0u16; 16]; mc::predict_with_filter( &u.data, u.width, u.true_width, u.true_height, - mv_to_q4(cpx, dv.1, false), mv_to_q4(cpy, dv.0, false), - 4, 4, mc::InterpFilterKind::Bilinear, &mut ub, fctx, + chroma_mv_x, chroma_mv_y, 4, 4, mc::InterpFilterKind::Bilinear, &mut ub, fctx, ); let mut vb = vec![0u16; 16]; mc::predict_with_filter( &v.data, v.width, v.true_width, v.true_height, - mv_to_q4(cpx, dv.1, false), mv_to_q4(cpy, dv.0, false), - 4, 4, mc::InterpFilterKind::Bilinear, &mut vb, fctx, + chroma_mv_x, chroma_mv_y, 4, 4, mc::InterpFilterKind::Bilinear, &mut vb, fctx, ); - let chroma_around = neighbours.around_mi(leaf_mi, 8); - set_palette_pred(ub, fctx); - let ug = read_plane( - dec, cdfs, TxbSet::Chroma4, scan4, 1, chroma_around[1], DC_PRED, DC_PRED, - 0, group_reach, u, cpx, cpy, 4, TX4, base_q_idx, - None, None, None, smooth_neighbor_uv, fctx, - )?; - set_palette_pred(vb, fctx); - let vg = read_plane( - dec, cdfs, TxbSet::Chroma4, scan4, 2, chroma_around[2], DC_PRED, DC_PRED, - 0, group_reach, v, cpx, cpy, 4, TX4, base_q_idx, - None, None, None, smooth_neighbor_uv, fctx, - )?; - fctx.intrabc_chroma_tx.with(|c| c.set(None)); - (ug, vg) + if leaf_skips[1] { + // `skip_txfm` still reconstructs an intrabc prediction, but + // libaom's `decode_reconstruct_tx` reads NO chroma coefficients. + // The ordinary skipped-intra arm above is therefore not valid for + // an intrabc leaf: use the copied, clamped 4x4 prediction directly. + push_mc_rect( + 1, cpx, cpy, 4, 4, 4, Pred::Inline(&ub, 4), + &ZERO_RESIDUAL[..16], fctx, + ); + push_mc_rect( + 2, cpx, cpy, 4, 4, 4, Pred::Inline(&vb, 4), + &ZERO_RESIDUAL[..16], fctx, + ); + hit!(SKIPPED_INTRABC_CHROMA_ARM_HITS); + fctx.intrabc_chroma_tx.with(|c| c.set(None)); + (Grid::Zero(16), Grid::Zero(16)) + } else { + let chroma_around = neighbours.around_mi(leaf_mi, 8); + set_palette_pred(ub, fctx); + let ug = read_plane( + dec, cdfs, TxbSet::Chroma4, scan4, 1, chroma_around[1], DC_PRED, DC_PRED, + 0, group_reach, u, cpx, cpy, 4, TX4, base_q_idx, + None, None, None, smooth_neighbor_uv, fctx, + )?; + set_palette_pred(vb, fctx); + let vg = read_plane( + dec, cdfs, TxbSet::Chroma4, scan4, 2, chroma_around[2], DC_PRED, DC_PRED, + 0, group_reach, v, cpx, cpy, 4, TX4, base_q_idx, + None, None, None, smooth_neighbor_uv, fctx, + )?; + fctx.intrabc_chroma_tx.with(|c| c.set(None)); + (ug, vg) + } } else { let ac = alpha.map(|_| cfl_src(gpx, gpy, 8)); let chroma_around = neighbours.around_mi(leaf_mi, 8); diff --git a/crates/ec-av1/src/stream.rs b/crates/ec-av1/src/stream.rs index 5a0d7624..8fad3bdd 100644 --- a/crates/ec-av1/src/stream.rs +++ b/crates/ec-av1/src/stream.rs @@ -5148,12 +5148,12 @@ pub(crate) mod tests { /// `EC_ECDUMP` against the instrumented aomdec) -- a coefficient-walk /// desync at byte 61712 with every mode symbol still matching. /// - /// This stream is the same source at `--min-partition-size=8`, which - /// keeps sub-8x8 partitions out: post-fix it is full-frame exact. The - /// `--min-partition-size=4` sibling still is not -- its remaining - /// divergence is a sub-8x8 4x8-leaf chroma reconstruction defect with the - /// entropy ladder fully synced (first diff U(92,104), luma byte-exact), - /// deferred to the sub-8x8 lane family (lanes/av1loss64.report.md). + /// This gate uses the same `--min-partition-size=4` arm that reaches the + /// sub-8x8 VERT -> 4x8 skipped-intrabc leaf. Post-fix it is full-frame + /// exact: the skip path uses libaom's clamped 4x4 chroma intrabc + /// prediction (`decodeframe.c:1011-1065`, `reconinter_template.inc:186-207`) + /// instead of the ordinary skipped-intra DC predictor. The old route first + /// differed at U(104,92) with the entropy ladder fully synced. /// /// Fail-pre-fix, measured on the ed12fe52 probe: differs at byte 41120 /// (the chroma-clip class, fixed in the same lane). Single-mutation on @@ -5166,16 +5166,23 @@ pub(crate) mod tests { eprintln!("SKIP {NAME}: no ffmpeg"); return; } - let stream = lossless_sb128_testsrc2(320, 242, &["--min-partition-size=8"]); + let stream = lossless_sb128_testsrc2(320, 242, &["--min-partition-size=4"]); crate::decode::reset_loss64_hits(); + crate::decode::reset_skipped_intrabc_chroma_arm_hits(); let ours = decode_stream(&stream) .unwrap_or_else(|e| panic!("{NAME}: decodes: {e}")); let resets = crate::decode::skip_lossless_band_reset_hits(); + let intrabc_skips = crate::decode::skipped_intrabc_chroma_arm_hits(); assert!( resets > 0, "{NAME}: this stream coded NO skipped lossless intrabc rect strip -- \ the fixed body was never reached (class gate-blind-to-feature)" ); + assert!( + intrabc_skips > 0, + "{NAME}: this stream coded NO skipped sub-8x8 intrabc chroma leaf -- \ + the clamped chroma prediction fix was never reached (class gate-blind-to-feature)" + ); let refs = ffmpeg_decode_sequence(&stream, 320, 242, 1); assert_eq!(ours.len(), 1, "{NAME}: frame count"); for (plane, (g, r)) in [(&ours[0].y, &refs[0].y), (&ours[0].u, &refs[0].u), (&ours[0].v, &refs[0].v)] @@ -5185,7 +5192,10 @@ pub(crate) mod tests { let bad = g.iter().zip(r.iter()).filter(|(a, b)| a != b).count(); assert_eq!(bad, 0, "{NAME}: plane {plane}: {bad} samples differ from ffmpeg"); } - eprintln!("{NAME}: full-frame exact, {resets} band resets"); + eprintln!( + "{NAME}: full-frame exact, {resets} band resets, \ + {intrabc_skips} skipped intrabc chroma predictions" + ); } /// lane-dkey: the palette-neighbour-band gate. A palette-Y block's size and diff --git a/lanes/av1loss64.report.md b/lanes/av1loss64.report.md new file mode 100644 index 00000000..1dc0c5f8 --- /dev/null +++ b/lanes/av1loss64.report.md @@ -0,0 +1,105 @@ +# lane-av1-loss64 — lossless sb128 full-frame exact, including skipped sub-8x8 intrabc chroma + +Base: `main` **ed12fe52** (rect14 merged). Worktree +`/home/user/Documents/Code/Rust/edith_codecs-av1l64`, branch +`lane-av1-loss64`, `CARGO_TARGET_DIR=$HOME/.cache/cargo-target-av1loss64`, +`TMPDIR=$HOME/.cache/tmp-av1loss64`. Nothing pushed. + +## 1. Headline + +The lane closes the lossless `sb-size=128` 320x240 acceptance arm at +full-frame sample exactness. It also fixes the remaining 4:8/8:4 sub-8x8 +chroma prediction defect in a skipped intrabc leaf. The first source fix is +committed as `0226fc11` (`ec-av1: clip lossless chroma TUs and reset skip bands`); +the skipped-intrabc chroma fix and its gate are the follow-up commit on this +branch. + +Verified gates: + +``` +a_lossless_sb128_square_frame_clips_overhanging_chroma_tus + 2 arms full-frame exact, 192 chroma units clipped + +a_skipped_lossless_intrabc_rect_strip_zeroes_its_entropy_bands + full-frame exact, 1 band resets, 3 skipped intrabc chroma predictions +``` + +The first gate is the required 320x240 lossless sb128 full-frame witness. The +second is a 320x242 sibling generated with `--min-partition-size=4`; it reaches +the sub-8x8 VERT -> 4x8 skipped-intrabc leaf and is also full-frame exact. + +## 2. Root causes + +Two independent defects were present in the cancelled WIP: + +* A lossless chroma transform unit at a frame edge was read with the nominal + geometry instead of libaom's clipped per-plane geometry. The decoder could + read or reconstruct outside the valid chroma plane footprint. +* In `decode_leaf_rect8`, a 4:8/8:4 chroma-reference leaf with `skip_txfm=1` + and `use_intrabc=1` was sent through the ordinary skipped-intra branch. + That branch predicts chroma with DC/CfL, but libaom still reconstructs a + skipped intrabc block from its motion-compensated copy; skip only suppresses + residual coefficient reads. The entropy ladder remained synchronized while + the first wrong sample was U(104,92) at luma mi(46,52). + +For 4:2:0, libaom clamps a 4x8/8x4 leaf's chroma plane block to `BLOCK_4X4`: +`set_plane_n4` in `av1_common_int.h:1344` and `get_plane_block_size` in +`blockd.h:1184`. The fix therefore predicts a 4x4 U and V block at the group's +chroma origin `(cpx, cpy)`, using the intrabc DV, and writes no chroma +coefficients on the skipped route. An unskipped intrabc leaf keeps the ordinary +`Chroma4` coefficient walk over the same 4x4 prediction. Both routes disarm +`intrabc_chroma_tx`. + +The lossless skip-band fix resets the complete luma entropy-band footprint +before the next block. Its measured sibling previously left a stale band and +read the next `txb_skip_ctx` differently from libaom. + +## 3. Repro and exactness + +Oracle: `~/.cache/aom-oracle/build/aomenc`; pixel reference: ffmpeg. + +The sub-8x8 witness was generated from `testsrc2=s=320x242:r=25`, one frame, +with `--lossless=1 --sb-size=128 --enable-1to4-partitions=1 +--min-partition-size=4 --obu`. The committed-lane release probe and ffmpeg +reference have identical decoded bytes (`diff 0`). Artifact hashes: + +``` +obu: 1fe5edc300a378c486abe385dad8251f3f21452f04e5a6f60f69feb48e58c8cb +ref8: 421ca38c91a133e78b84a9a3c9f79defbddbc7163a0b3088a176f4cd50179728 +ours: f8fc6c3248e6d8782ebccd88d46f7254aa8915fd4deaf62b7b92953599709eda +``` + +Before the chroma-route fix, Y was exact but U/V differed at 2,488 samples; +the first difference was U(104,92). After the fix, all Y/U/V samples are exact. +The gate reports three reached skipped-intrabc chroma predictions and one +lossless band reset, so neither fix is gate-blind. + +## 4. Changed paths + +* `crates/ec-av1/src/decode.rs`: clip lossless chroma TU geometry; clear the + skipped lossless entropy bands; route skipped sub-8x8 intrabc chroma through + clamped 4x4 motion-compensated prediction; add the engagement hit used by the + gate. +* `crates/ec-av1/src/stream.rs`: change the lossless skip-band gate to the + min-partition-size=4 witness and assert both the band-reset and skipped + intrabc-chroma counters. + +No refusal string, encoder path, or unrelated decode seat was changed. + +## 5. Verification run + +Targeted commands, all with private lane target and temp directories: + +``` +EC_AV1_REQUIRE_AOMENC=1 cargo test -p ec-av1 --lib \ + a_skipped_lossless_intrabc_rect_strip_zeroes_its_entropy_bands -- --nocapture +EC_AV1_REQUIRE_AOMENC=1 cargo test -p ec-av1 --lib \ + a_lossless_sb128_square_frame_clips_overhanging_chroma_tus -- --nocapture +``` + +Both passed. The release `decode_probe` was rebuilt and independently compared +to ffmpeg for the 320x242 min4 witness; all planes were byte exact. + +The project-wide suite, 0-warning parity sweep, and the cross-lane acceptance +arms (mono, 10-bit `reelb_*`, CDF-disabled, 4:4:4 refusal, qmatrix refusal) are +owned by the main agent and were not run in this lane.