From f97f58c7af18328827b0d7b944398321c8dcb2d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Fri, 25 Sep 2026 19:06:30 +0300 Subject: [PATCH] lane-av1-ibcskip2: skipped-intrabc sub8 chroma predicts the DV frame copy sub8_leaf_chroma444's skip arm pushed the intra mode (DC for an intrabc leaf) with zero residual where libaom's av1_build_inter_predictors_sb runs for an intrabc block regardless of skip: a skipped intrabc leaf's chroma is the bare frame copy at the DV. Measured fail-before on ll444_ibc_rect.obu at this HEAD (the leaf8 chroma-extent fix upstream lets the fixture decode through): luma clean, U 2794 / V 2830 differing samples across 180 4x4 cells, 175 of them exactly the frame's 150 skipped intrabc leaves, 5 their poisoned neighbours. Fix: new first arm in sub8_leaf_chroma444 -- when intrabc_dv is Some and skip, bilinear MC of the current frame's U/V at the DV armed through set_palette_pred and pushed with ZERO_RESIDUAL (the luma skip arms' route); the inherited chroma tx_type slot is disarmed unconsumed. SKIPPED_INTRABC_DV_COPY_HITS pins the route. The 4:2:0 group-tail skip arms are RESERVED territory: untouched, byte-for-byte, and 4:2:0 call sites pass intrabc_dv = None so control flow through the edited function is identical (420-heavy intrabc/lossless/sb128 batteries green). The ibc444rect gate a_lossless_444_intrabc_rect_leaf_walks_per_4x4_units pinned the leaf8 palette_window panic b6d4b528 removed and went red at this HEAD ((339,339) walk census vs the pinned (3,3)); flipped per its own r1 doc to the full-frame exact aomdec comparison with the census and ==150 DV-copy counter asserts. Mutation check: count-but-predict-flat arm leaves the gate red at 'aomdec plane U: 2503 samples differ'. Green: the flipped gate reports frame sample-exact vs oracle aomdec (339+339 rect walks, 150 skipped-intrabc DV copies, 0 differing samples on Y/U/V); every intrabc-named gate (17), lossless-named gate (12) and sb128-named gate (9) passes; cargo check -p ec-av1 --all-targets 0 warnings. Report: lanes/av1ibcskip2.report.md. --- crates/ec-av1/src/decode.rs | 74 ++++++++++++++++++++- crates/ec-av1/src/stream.rs | 127 +++++++++++++++++++++--------------- lanes/av1ibcskip2.report.md | 94 ++++++++++++++++++++++++++ 3 files changed, 241 insertions(+), 54 deletions(-) create mode 100644 lanes/av1ibcskip2.report.md diff --git a/crates/ec-av1/src/decode.rs b/crates/ec-av1/src/decode.rs index 95703e26..d0c630a3 100644 --- a/crates/ec-av1/src/decode.rs +++ b/crates/ec-av1/src/decode.rs @@ -3926,6 +3926,30 @@ pub(crate) fn reset_skipped_intrabc_chroma_arm_hits() { SKIPPED_INTRABC_CHROMA_ARM_HITS.with(|c| c.set(0)); } +thread_local! { + /// lane-av1-ibcskip2: a sub-8x8 4:4:4 leaf that is BOTH intrabc AND + /// `skip` -- the arm whose chroma is the bare frame copy at the DV + /// (libaom `av1_build_inter_predictors_sb` runs regardless of `skip`). + /// Before the fix this route predicted intra-DC and every one of this + /// fixture's 150 such cells differed from the oracle on both chroma + /// planes. + static SKIPPED_INTRABC_DV_COPY_HITS: std::cell::Cell = + const { std::cell::Cell::new(0) }; +} + +/// Current value of [`SKIPPED_INTRABC_DV_COPY_HITS`]. +#[allow(dead_code)] // read only from the `#[cfg(test)]` gates +pub(crate) fn skipped_intrabc_dv_copy_hits() -> usize { + SKIPPED_INTRABC_DV_COPY_HITS.with(|c| c.get()) +} + +/// Zeroes [`SKIPPED_INTRABC_DV_COPY_HITS`] (gate tests call this before a +/// decode). +#[allow(dead_code)] // read only from the `#[cfg(test)]` gates +pub(crate) fn reset_skipped_intrabc_dv_copy_hits() { + SKIPPED_INTRABC_DV_COPY_HITS.with(|c| c.set(0)); +} + /// Zeroes [`INTRABC_HITS`] (gate tests call this before a decode). #[allow(dead_code)] // read only from the `#[cfg(test)]` gates pub(crate) fn reset_intrabc_hits() { @@ -18902,7 +18926,10 @@ fn read_intra_mode_sub8( /// arm for arm at leaf scale: a skipped leaf keeps its CfL contribution, an /// intrabc leaf predicts a frame copy at its DV with the luma `tx_type` /// inherited through [`INTRABC_CHROMA_TX`] (the caller arms it right after -/// the luma read). The chroma position, reach and entropy-context span are +/// the luma read) -- and a SKIPPED intrabc leaf is still the DV copy, never +/// an intra prediction (lane-av1-ibcskip2: libaom's +/// `av1_build_inter_predictors_sb` runs for an intrabc block regardless of +/// `skip`). The chroma position, reach and entropy-context span are /// the leaf's own (ss 0/0); the 4x8/8x4 unit reads the same /// `ChromaRect8x4` tables [`decode_rect_split`] proves for that shape. /// Records the leaf's own `uv_mode` map entry and chroma above/left state, @@ -18939,7 +18966,50 @@ fn sub8_leaf_chroma444( } else { Reach::of_rect(bw, bh, px, py, y.width, y.height, fctx) }; - let grids = if skip { + let grids = if let Some(dv) = intrabc_dv.filter(|_| skip) { + // lane-av1-ibcskip2: a SKIPPED intrabc leaf still predicts the frame + // copy at its DV -- libaom's `av1_build_inter_predictors_sb` runs for + // an intrabc block regardless of `skip` (only the residual read is + // dropped), so the reconstruction is the bare DV copy. The intra push + // in the next arm is the NON-intrabc route; predicting DC there + // decoded flat cells where this fixture's oracle copies frame bytes + // (class skipped-intrabc-predicts-intra, + // lanes/av1ibcskip2.report.md). Same armed-palette-slot route the + // leaf's own luma skip arm uses (`decode_leaf_split4` / + // `decode_leaf_rect8`); the caller already flushed the recon queue + // before its luma DV copy, so the source samples are current. + let mut ub = vec![0u16; bw * bh]; + mc::predict_with_filter( + &u.data, u.width, u.true_width, u.true_height, + mv_to_q4(px, dv.1, 0), mv_to_q4(py, dv.0, 0), + bw, bh, mc::InterpFilterKind::Bilinear, &mut ub, fctx, + ); + let mut vb = vec![0u16; bw * bh]; + mc::predict_with_filter( + &v.data, v.width, v.true_width, v.true_height, + mv_to_q4(px, dv.1, 0), mv_to_q4(py, dv.0, 0), + bw, bh, mc::InterpFilterKind::Bilinear, &mut vb, fctx, + ); + hit!(SKIPPED_INTRABC_DV_COPY_HITS); + let zeros = &ZERO_RESIDUAL[..bw * bh]; + if square { + set_palette_pred(ub, fctx); + push_intra(1, px, py, 4, DC_PRED, 0, reach, zeros, None, None, smooth_neighbor_uv, fctx); + set_palette_pred(vb, fctx); + push_intra(2, px, py, 4, DC_PRED, 0, reach, zeros, None, None, smooth_neighbor_uv, fctx); + } else { + set_palette_pred(ub, fctx); + push_intra_rect(1, px, py, bw, bh, DC_PRED, 0, reach, zeros, None, None, smooth_neighbor_uv, fctx); + set_palette_pred(vb, fctx); + push_intra_rect(2, px, py, bw, bh, DC_PRED, 0, reach, zeros, None, None, smooth_neighbor_uv, fctx); + } + // The same arm-without-clear route the 4:2:0 tails count: a skipped + // leaf reads no coefficient, so the inherited chroma `tx_type` is + // dropped unconsumed. + hit!(SKIPPED_INTRABC_CHROMA_ARM_HITS); + fctx.intrabc_chroma_tx.with(|c| c.set(None)); + (Grid::Zero(bw * bh), Grid::Zero(bw * bh), 4, 4) + } else if skip { let ac = alpha.map(|_| cfl_src_rect(px, py, bw, bh)); if square { push_intra(1, px, py, 4, uv_predict_mode, 0, reach, &ZERO_RESIDUAL[..16], alpha.zip(ac).map(|((au, _), ac)| (au, ac)), None, smooth_neighbor_uv, fctx); diff --git a/crates/ec-av1/src/stream.rs b/crates/ec-av1/src/stream.rs index ea042588..ea5f8af4 100644 --- a/crates/ec-av1/src/stream.rs +++ b/crates/ec-av1/src/stream.rs @@ -6127,32 +6127,28 @@ pub(crate) mod tests { /// `LumaRect8x4Inter`/`ChromaRect8x4` rect unit the non-lossless arm /// reads, and not the lossy per-unit arm's tx_type read. /// - /// The pinned fixture `ll444_ibc_rect.obu` (99614 bytes, provenance and - /// the full pixel measurement in `lanes/av1ibc444rect.report.md`) is a - /// lossless `--profile=1 --i444 --enable-intrabc=1` key frame. Its first - /// unskipped intrabc rect leaf (mi (33,2), 8x4, dv (-64, -832)) must walk - /// its luma + chroma per-4x4 units with the tile's entropy ladder still - /// aligned afterwards -- three leaves walk before the frame reaches an - /// intrabc `BLOCK_8X8` leaf, whose llintra-deferred 8x8 chroma prediction - /// buffers - /// (`decode_leaf8`'s 16-sample `ub`/`vb`, their deferral in - /// `lanes/av1llintra.report.md`) panic in `palette_window` -- on the - /// committed tree that panic is this gate's ALIGNMENT WITNESS: any - /// unit-structure, context or tx_type regression in the walk desyncs the - /// tile long before mi (32,10) and the death signature moves (the - /// fail-before was the lossless WHT assert `(4, 8) != (4, 4)` at - /// `TxParams::run`). Measured with the two-line 8x8 buffer probe applied - /// (never committed): the walk is pixel-exact, luma 0 differing samples - /// on all 339 walked leaves and the walked leaves' chroma clean; the only - /// remaining diffs sit on SKIPPED intrabc blocks (the skipped-intrabc - /// sub8 chroma predictor defect, class-adjacent to the reserved 4:2:0 - /// tail skip arm). When the 8x8 buffers are fixed in their owning lane, - /// this gate flips to a full-frame exact `aomdec` comparison. + /// The pinned fixture `ll444_ibc_rect.obu` (99614 bytes, provenance in + /// `lanes/av1ibc444rect.report.md`) is a lossless `--profile=1 --i444 + /// --enable-intrabc=1` key frame. r1 pinned the (then-known) leaf8 + /// `palette_window` panic as its alignment witness; with that blocker + /// fixed upstream (lane-av1leaf8oob) the frame decodes to completion and + /// this gate is the FULL-FRAME exact `aomdec` comparison its r1 doc + /// promised, flipped by lane-av1-ibcskip2 -- which also closed the + /// SKIPPED intrabc sub8 chroma cells the r1 measurement called out: a + /// skipped intrabc leaf's chroma is the bare frame copy at the DV + /// (libaom's `av1_build_inter_predictors_sb` runs regardless of `skip`), + /// never the intra-DC push that arm used to run. Fail-before, measured on + /// this tree with the DV-copy arm cut back to the intra push: 2794 U + + /// 2830 V samples differ across 180 distinct 4x4 cells, 175 of them + /// exactly this frame's skipped intrabc leaves, luma clean; with the arm, + /// 0 differing samples on every plane. #[test] fn a_lossless_444_intrabc_rect_leaf_walks_per_4x4_units() { const NAME: &str = "a_lossless_444_intrabc_rect_leaf_walks_per_4x4_units"; const FIXTURE_LEN: usize = 99614; const FIXTURE_FNV: u64 = 0xa1b6_a84e_ac6a_656f; + const W: usize = 320; + const H: usize = 240; let obu = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR")) .join("fixtures/ll444_ibc_rect.obu"); let stream = std::fs::read(&obu).unwrap_or_else(|e| { @@ -6167,46 +6163,73 @@ pub(crate) mod tests { let _guard = lock_gate_counters(); crate::decode::reset_ibc444rect_hits(); - // The known leaf8 panic is the expected outcome; keep it out of the - // test log and catch it as a value. - let prev_hook = std::panic::take_hook(); - std::panic::set_hook(std::boxed::Box::new(|_| {})); - let result = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| { - decode_stream(&stream) - })); - std::panic::set_hook(prev_hook); + crate::decode::reset_skipped_intrabc_dv_copy_hits(); + let frames = decode_stream(&stream).unwrap_or_else(|e| { + panic!("{NAME}: the fixture must decode to completion (the leaf8 \ + chroma buffers were fixed upstream): {e}") + }); + assert_eq!(frames.len(), 1, "{NAME}: shown frame count"); let luma = crate::decode::intrabc_rect8_lossless_luma_hits(); let chroma = crate::decode::intrabc_rect8_lossless_chroma_hits(); assert_eq!( (luma, chroma), - (3, 3), - "{NAME}: the walk must fire exactly three times before the known \ - leaf8 death (got luma {luma}, chroma {chroma}) -- zero means the \ - fixture no longer reaches the fixed body (class \ + (339, 339), + "{NAME}: the per-4x4 walk must fire on the fixture's full unskipped \ + intrabc rect census (got luma {luma}, chroma {chroma}) -- zero \ + means the fixture no longer reaches the fixed body (class \ gate-blind-to-feature), more means the entropy desynced and \ garbage blocks read as intrabc rect leaves" ); - let payload = match result { - Err(e) => e, - Ok(_) => panic!( - "{NAME}: the fixture decoded to completion -- the known \ - llintra-deferred leaf8 panic at mi (32,10) is gone; flip this \ - gate to the full-frame exact aomdec comparison" - ), - }; - let msg = payload - .downcast_ref::() - .map(String::as_str) - .or_else(|| payload.downcast_ref::<&'static str>().copied()) - .unwrap_or(""); - assert!( - msg.contains("range end index 4 out of range for slice of length 0"), - "{NAME}: the decode died somewhere OTHER than the known leaf8 \ - palette_window site -- the walk desynced the tile (panic: {msg})" + let dv_skips = crate::decode::skipped_intrabc_dv_copy_hits(); + assert_eq!( + dv_skips, 150, + "{NAME}: the skipped-intrabc DV-copy chroma arm must fire on every \ + one of the fixture's 150 skipped intrabc leaves (got {dv_skips}) \ + -- zero means the arm is unreachable (class gate-blind-to-feature)" ); + + // The oracle aomdec, rawvideo out: one concatenated yuv444p frame. + if aomdec_path().is_file() { + let dir = std::env::temp_dir().join(format!("ec-av1-ibcskip2-{}", std::process::id())); + let _ = std::fs::remove_dir_all(&dir); + std::fs::create_dir_all(&dir).expect("scratch dir"); + let raw = dir.join("aomdec.raw"); + let out = Command::new(aomdec_path()) + .args(["--codec=av1", "--rawvideo", "-o"]) + .arg(&raw) + .arg(&obu) + .stdin(Stdio::null()) + .stdout(Stdio::piped()) + .stderr(Stdio::piped()) + .output() + .expect("aomdec failed to run"); + assert!( + out.status.success(), + "{NAME}: the oracle aomdec refused the stream: {}", + String::from_utf8_lossy(&out.stderr) + ); + let ref_raw = std::fs::read(&raw).expect("aomdec rawvideo output"); + let _ = std::fs::remove_dir_all(&dir); + assert_eq!(ref_raw.len(), W * H * 3, "{NAME}: aomdec raw size"); + let f = &frames[0]; + for (plane, off, p) in + [(&f.y, 0usize, "Y"), (&f.u, W * H, "U"), (&f.v, 2 * W * H, "V")] + { + let want = &ref_raw[off..off + W * H]; + let bad = plane.iter().zip(want).filter(|&(&a, &b)| a as u8 != b).count(); + assert_eq!( + bad, 0, + "{NAME}: aomdec plane {p}: {bad} samples differ -- a \ + regression here reopens the skipped-intrabc sub8 chroma \ + predictor or the rect walk" + ); + } + } else { + eprintln!("SKIP {NAME} aomdec arm: no oracle aomdec at {}", aomdec_path().display()); + } eprintln!( - "{NAME}: walk fired once (luma + chroma), entropy aligned through \ - the leaf, death at the known leaf8 site" + "{NAME}: frame sample-exact vs oracle aomdec; {luma}+{chroma} rect \ + walks, {dv_skips} skipped-intrabc DV copies" ); } diff --git a/lanes/av1ibcskip2.report.md b/lanes/av1ibcskip2.report.md new file mode 100644 index 00000000..da3f16b7 --- /dev/null +++ b/lanes/av1ibcskip2.report.md @@ -0,0 +1,94 @@ +# lane-av1-ibcskip2: skipped-intrabc sub8 chroma predicts the DV frame copy (r1) + +## Charter + +Close `av1ibc444rect` blocked_by item 2: `sub8_leaf_chroma444`'s skip arm +predicted the intra mode (DC for an intrabc leaf) where libaom predicts the +frame copy at the DV — `av1_build_inter_predictors_sb` runs for an intrabc +block regardless of `skip`; only the residual read is dropped. Work in +`edith_codecs-av1ibcskip2` @ b6d4b528 (`f23115aa` + cherry-picked +`9dbeafab`, the leaf8 chroma-extent fix that unblocked this fixture). The +RESERVED 4:2:0 group-tail chroma SKIP arm is untouched (see collision +statement). + +## Defect (measured on this tree, fail-before) + +The fixture decodes to completion at this HEAD (the parent lane needed a +throwaway leaf8 patch to measure; b6d4b528 landed it). Native reproduction, +oracle `aomdec --rawvideo` vs our decode: + +- luma: 0 differing samples, +- U: 2794 differing samples, V: 2830, across 180 distinct 4x4 cells — + 175 of them EXACTLY the frame's skipped intrabc leaves (150 leaves + covering 175 4x4 cells), the other 5 their immediate neighbours + (poisoned edge state), +- a throwaway cell trace confirmed every diff cell sits on a + `(intrabc=1, skip=1)` leaf or touches one. + +Class: `skipped-intrabc-predicts-intra`. The 4:2:0 group-tail twin (flat DC +at the tails) is the RESERVED arm — not touched, not fixed here. + +## Fix + +New first arm in `sub8_leaf_chroma444` (`if let Some(dv) = +intrabc_dv.filter(|_| skip)`): bilinear MC of the CURRENT frame's U/V at the +DV (the unskipped arm's own `mv_to_q4` route), armed through +`set_palette_pred` and pushed with `ZERO_RESIDUAL` via +`push_intra`/`push_intra_rect` — the same armed-palette-slot route the two +luma skip arms (`decode_leaf_split4`, `decode_leaf_rect8`) already use; the +callers flushed the recon queue before their luma DV copy, so the source +samples are current. The inherited chroma `tx_type` slot is disarmed +(consumed by nothing — a skipped leaf reads no coefficient), keeping +`SKIPPED_INTRABC_CHROMA_ARM_HITS` semantics. Engagement counter +`SKIPPED_INTRABC_DV_COPY_HITS` + accessors pin the route for the gate. + +## Stale gate flip (forced by the cherry-pick) + +`a_lossless_444_intrabc_rect_leaf_walks_per_4x4_units` was RED at HEAD as +committed: it pinned the leaf8 `palette_window` panic ((3, 3) walk hits) +which b6d4b528 removed — the walk now fires its full census (339, 339). +Flipped per its own r1 doc to the full-frame exact `aomdec` comparison: +fixture len/FNV pins kept, (339, 339) census assert, `SKIPPED_INTRABC_ +DV_COPY_HITS == 150` route assert, `aomdec --rawvideo` 0-diff on all three +planes (arm skipped with a notice only when the oracle binary is absent). + +## Verification (measured) + +- Mutation check: the arm mutated to count-but-predict-flat (grey 128 + prediction, flow intact, counter armed) → gate RED at "aomdec plane U: + 2503 samples differ". The pixel comparison is load-bearing; the ==150 + counter assert catches an unreachable arm. +- Gate green (post-fix, mutation reverted): "frame sample-exact vs oracle + aomdec; 339+339 rect walks, 150 skipped-intrabc DV copies". Whole-fixture + 0 differing samples on Y, U and V — also re-measured out-of-gate via a + throwaway plane dump + byte diff before the gate existed (0/0/0). +- Battery (superset of the parent's 16): every `intrabc`-named gate 17 + passed, every `lossless`-named gate 12 passed, every `sb128`-named gate 9 + passed (1 ignored diagnostic each where present), including the parent's + full list, the leaf8oob gate from HEAD's cherry-pick, and this flipped + gate. `cargo check -p ec-av1 --all-targets`: 0 warnings, 0 errors. + +## 4:2:0 / reserved-arm collision statement + +The diff lands only in `sub8_leaf_chroma444` (444-only: all six call sites +sit inside `if chroma_444` blocks; 4:2:0 chroma rides the group tails), +the `SKIPPED_INTRABC_DV_COPY_HITS` counter block in decode.rs, and the +flipped gate in stream.rs. The 4:2:0 group-tail chroma SKIP arm and the +`last_intrabc` tails in `decode_leaf_split4`/`decode_leaf_rect8` — the +RESERVED territory — are byte-for-byte untouched, and none of their call +sites pass `intrabc_dv = Some`, so 4:2:0 control flow through the edited +function is identical; the 420-heavy intrabc/lossless/sb128 battery above +confirms bit-identical behaviour. + +## Not claimed + +Exactness is claimed for the pinned fixture (whole frame, all planes) and +whatever the battery gates already pinned — not a general "every 4:4:4 +intrabc stream decodes exact" statement. The `444_leaf8_oob.obu` +divergence noted in `lanes/av1leaf8oob.report.md` is that lane's deferral, +not re-measured here. + +## Deferred + +Nothing. The charter's deliverable (skip arm consults the DV, fixture gate, +4:2:0 identical, gates green) is complete on this branch.