diff --git a/crates/ec-av1/examples/decode_probe.rs b/crates/ec-av1/examples/decode_probe.rs index 057257d2..2d3a9fc6 100644 --- a/crates/ec-av1/examples/decode_probe.rs +++ b/crates/ec-av1/examples/decode_probe.rs @@ -189,6 +189,11 @@ fn main() { ec_av1::decode::rect4_16_lossless_chroma_hits(), ec_av1::decode::rect4_16_intrabc_hits(), ); + println!( + "loss64: chroma_edge_tu_clip={} skip_lossless_band_reset={}", + ec_av1::decode::chroma_edge_tu_clip_hits(), + ec_av1::decode::skip_lossless_band_reset_hits(), + ); // lane-t900 r12: chroma edge-filter neighbour answered from the mi-granular // uv_mode grid instead of the coarse one-slot-per-column map. println!( diff --git a/crates/ec-av1/src/decode.rs b/crates/ec-av1/src/decode.rs index 946657be..7fb70d3d 100644 --- a/crates/ec-av1/src/decode.rs +++ b/crates/ec-av1/src/decode.rs @@ -5084,6 +5084,15 @@ thread_local! { /// lane-kf1200 r2: sub-8x8 chroma blocks that are `skip_txfm` AND /// `UV_CFL_PRED` -- the arm that used to drop the CfL alpha entirely. static SKIP_CFL_HITS: std::cell::Cell = const { std::cell::Cell::new(0) }; + /// lane-av1-loss64: chroma transform units the frame-edge clip skipped + /// (libaom `decode_reconstruct_tx`'s `max_blocks_wide/high` test) in + /// [`decode_block`]'s multi-transform-unit walk -- the units a lossless + /// block overhanging the frame does NOT code. + static CHROMA_EDGE_TU_CLIP_HITS: std::cell::Cell = const { std::cell::Cell::new(0) }; + /// lane-av1-loss64: skipped lossless intrabc rect strips whose luma + /// entropy bands were zeroed per unit (libaom `av1_reset_entropy_context`, + /// decodeframe.c:1262) instead of leaking the previous occupant's. + static SKIP_LOSSLESS_BAND_RESET_HITS: std::cell::Cell = const { std::cell::Cell::new(0) }; } /// How many skipped sub-8x8 chroma blocks carried a CfL alpha (the shape @@ -5092,6 +5101,26 @@ pub fn skip_cfl_hits() -> usize { SKIP_CFL_HITS.with(|c| c.get()) } +/// How many chroma transform units the frame-edge clip skipped in +/// [`decode_block`]'s multi-transform-unit walk (lane-av1-loss64). Zero on a +/// stream whose lossless blocks never overhang the frame -- a gate asserting +/// the clip fired must see this nonzero. +pub fn chroma_edge_tu_clip_hits() -> usize { + CHROMA_EDGE_TU_CLIP_HITS.with(|c| c.get()) +} + +/// How many skipped lossless intrabc rect strips had their luma entropy +/// bands zeroed per unit (lane-av1-loss64). +pub fn skip_lossless_band_reset_hits() -> usize { + SKIP_LOSSLESS_BAND_RESET_HITS.with(|c| c.get()) +} + +/// Gate-side reset for the two lane-av1-loss64 counters above. +pub fn reset_loss64_hits() { + CHROMA_EDGE_TU_CLIP_HITS.with(|c| c.set(0)); + SKIP_LOSSLESS_BAND_RESET_HITS.with(|c| c.set(0)); +} + /// How many 16x4/4x16 chroma pairs took a different `intra_edge_filter_type` /// from the pair's base mi than the strip's own mi would have given. pub fn rect4_16_uv_pair_filt_hits() -> usize { @@ -11147,6 +11176,29 @@ fn decode_intrabc_rect( push_mc_rect(0, px, py, side, bw, bh, Pred::Inline(&pred_y, side), &ZERO_RESIDUAL[..side * side], fctx); push_mc_rect(1, cpx, cpy, cside, cw, ch, Pred::Inline(&pred_u, cside), &ZERO_RESIDUAL[..cside * cside], fctx); push_mc_rect(2, cpx, cpy, cside, cw, ch, Pred::Inline(&pred_v, cside), &ZERO_RESIDUAL[..cside * cside], fctx); + if let Some(ls) = leaves.as_ref() { + // lane-av1-loss64, merged: the same reset [`decode_intrabc_owned_rect`]'s + // skip arm performs -- libaom `av1_reset_entropy_context` + // (`if (mbmi->skip_txfm)`, decodeframe.c:1262 -> blockd.c:58): a + // SKIPPED block zeroes its whole entropy-band footprint. This + // helper serves `decode_block_rect4`'s 1:4 strips on this tree, + // so a skipped lossless strip whose `leaves` resolved (every + // lossless frame -- `read_block_tx_size_rect`'s lossless arm + // returns the 4x4 grid before it looks at `skip`) left the + // PREVIOUS occupant's luma bands standing and the NEXT block's + // partition parse diverged from libaom's: the 320x242 lossless + // sb128 gate read a phantom unskipped 8x32 intrabc strip at + // mi(56,66) right after the skipped 8x16 one at mi(48,66). + hit!(SKIP_LOSSLESS_BAND_RESET_HITS); + for &(row, col, tw, th) in ls { + neighbours.record_mi_luma_rect( + (mi_r + row, mi_c + col), + tw, + th, + &ZERO_RESIDUAL[..tw * th], + ); + } + } luma_tx_type = TxType::DctDct; luma_grid = Grid::Zero(side * side); u_grid = Grid::Zero(cside * cside); @@ -12810,6 +12862,30 @@ fn decode_intrabc_owned_rect( push_mc_rect(0, px, py, side, bw, bh, Pred::Inline(&pred_y, side), &ZERO_RESIDUAL[..side * bh], fctx); push_mc_rect(1, px / 2, py / 2, cside, cw, ch, Pred::Inline(&pred_u, cside), &ZERO_RESIDUAL[..cside * ch], fctx); push_mc_rect(2, px / 2, py / 2, cside, cw, ch, Pred::Inline(&pred_v, cside), &ZERO_RESIDUAL[..cside * ch], fctx); + if let Some(ls) = leaves.as_ref() { + // libaom `av1_reset_entropy_context` (`if (mbmi->skip_txfm)`, + // decodeframe.c:1262 -> blockd.c:58): a SKIPPED block zeroes its + // whole entropy-band footprint. The non-skip arm below writes + // those bands per transform unit and the tail's + // `record_split_luma_rect_mi` writes chroma only, so without + // this walk a skipped strip whose `leaves` resolved (every + // lossless frame -- `read_block_tx_size_rect`'s lossless arm + // returns the 4x4 grid before it looks at `skip`) leaked the + // PREVIOUS occupant's luma bands into the next block's + // `txb_skip`/coefficient contexts (lane-av1-loss64: the skipped + // 8x16 intrabc strip at mi(48,66) of the 320x242 lossless sb128 + // stream left a stale 7 in left[48] and mi(48,68)'s first + // transform unit read `txb_skip_ctx` 3 where aomdec reads 1). + hit!(SKIP_LOSSLESS_BAND_RESET_HITS); + for &(row, col, tw, th) in ls { + neighbours.record_mi_luma_rect( + (mi_r + row, mi_c + col), + tw, + th, + &ZERO_RESIDUAL[..tw * th], + ); + } + } luma_grid = Grid::Zero(side * side); u_grid = Grid::Zero(cside * cside); v_grid = Grid::Zero(cside * cside); @@ -16088,6 +16164,35 @@ fn decode_block( let mut pass_idx = 0usize; for cu_row in ch_row * cpc..(ch_row + 1) * cpc { for cu_col in ch_col * cpc..(ch_col + 1) * cpc { + // libaom `decode_reconstruct_tx`'s frame-edge clip + // (decodeframe.c:299, `blk_row >= max_blocks_high || blk_col + // >= max_blocks_wide` returns before ANY symbol is read): a + // transform unit whose 4x4 origin sits outside the frame's mi + // grid is not coded at all. The luma loop above carries the + // same clip; its absence here read `txb_skip` (+coeffs) for + // chroma units libaom never wrote -- the lossless 64x64 block + // at mi(48,0) of a 320x240 frame overhangs the bottom edge by + // 4 mi, so its 32x32 chroma codes SIX rows of 4x4 units, not + // eight (lane-av1-loss64; 48 chroma units per plane in + // aomdec's EC_COEFF census vs the 64 this loop read). + // `max_block_wide/high` (av1_common_int.h:1565): the plane + // block's pixel span (4:2:0 halves the luma span, clamped to + // 4 by `set_plane_n4`) plus the negative overhang + // (`mb_to_*_edge` = `2 * overhang_mi` chroma px), in 4x4 + // units. + let span_mi = side / MI; + let over_w_mi = + (2 * y.true_width.div_ceil(8)) as i32 - mi_c as i32 - span_mi as i32; + let over_h_mi = + (2 * y.true_height.div_ceil(8)) as i32 - mi_r as i32 - span_mi as i32; + let plane_px = ((span_mi * 2).max(4)) as i32; + let max_units_w = ((plane_px + 2 * over_w_mi.min(0)) >> 2).max(0) as usize; + let max_units_h = ((plane_px + 2 * over_h_mi.min(0)) >> 2).max(0) as usize; + let unit = chroma_tx / 4; // TU side in 4x4 chroma units + if cu_col * unit >= max_units_w || cu_row * unit >= max_units_h { + hit!(CHROMA_EDGE_TU_CLIP_HITS); + continue; + } // The chroma context arrays are indexed in LUMA mi, so this // unit's anchor is its own luma quadrant: `chroma_tx` chroma // pixels span `2 * chroma_tx` luma ones. @@ -18261,7 +18366,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) @@ -18291,37 +18396,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 2b2ad28f..52c63231 100644 --- a/crates/ec-av1/src/stream.rs +++ b/crates/ec-av1/src/stream.rs @@ -5019,6 +5019,185 @@ pub(crate) mod tests { eprintln!("{NAME}: {frames} frames sample-exact, intra128_lossless hits {hits}"); } + /// lane-av1-loss64: the generator for the two gates below -- a deterministic + /// 1-frame lossless superblock-128 aomenc stream of `testsrc2`. `extra` + /// flags land last (aomenc keeps the LAST occurrence of a repeated flag). + /// The recipe is the one lanes/av1rect14.report.md section 2 measured + /// (`--lossless=1 --sb-size=128 --enable-1to4-partitions=1`); the + /// `--min-partition-size` override is what steers the bottom superblock + /// row's RD into overhanging 64x64 `NONE` blocks (the shape the first fix + /// clips) or, at 8, keeps sub-8x8 partitions out of the second gate's + /// stream so the whole frame is decodable. + fn lossless_sb128_testsrc2(width: usize, height: usize, extra: &[&str]) -> Vec { + let mut ff = Command::new("ffmpeg"); + let out = ff + .args(["-v", "error", "-f", "lavfi", "-i"]) + .arg(format!("testsrc2=s={width}x{height}:r=25")) + .args(["-frames:v", "1", "-pix_fmt", "yuv420p", "-strict", "-1", "-f", "yuv4mpegpipe", "-"]) + .stdin(Stdio::null()) + .stdout(Stdio::piped()) + .stderr(Stdio::piped()) + .output() + .expect("ffmpeg failed to run"); + assert!(out.status.success(), "ffmpeg failed for testsrc2 {width}x{height}"); + let y4m = out.stdout; + let mut child = Command::new(aomenc_path()) + .args(["--codec=av1", "--bit-depth=8", "--input-bit-depth=8"]) + .args([ + "--passes=1", + "--cpu-used=0", + "--lag-in-frames=0", + "--kf-max-dist=1", + "--limit=1", + "--threads=1", + "--tile-columns=0", + "--lossless=1", + "--sb-size=128", + "--enable-1to4-partitions=1", + ]) + .args(extra) + .args(["--obu", "-o", "-", "-"]) + .stdin(Stdio::piped()) + .stdout(Stdio::piped()) + .stderr(Stdio::piped()) + .spawn() + .expect("aomenc failed to start"); + child + .stdin + .take() + .expect("aomenc stdin") + .write_all(&y4m) + .expect("aomenc stdin write"); + let out = child.wait_with_output().expect("aomenc failed to run"); + assert!(out.status.success(), "aomenc failed: {}", String::from_utf8_lossy(&out.stderr)); + out.stdout + } + + /// lane-av1-loss64: a lossless superblock-128 frame whose intra blocks + /// overhang the bottom frame edge codes NO coefficient symbols for the + /// chroma transform units whose 4x4 origin sits outside the frame's mi + /// grid -- libaom `decode_reconstruct_tx` returns before any read + /// (`decodeframe.c:299`, `blk_row >= max_blocks_high || blk_col >= + /// max_blocks_wide`, the limits from `max_block_wide/high`, + /// av1_common_int.h:1565). The square multi-transform-unit chroma loop in + /// [`crate::decode`] carried no such clip (the luma loop had one) and read + /// `txb_skip`+coefficients for the phantom units: on the measured stream + /// the first lossless 64x64 `NONE` block, at mi(48,0), overhangs the + /// 240-px frame by 4 mi, so its 32x32 chroma codes SIX rows of 4x4 units, + /// not eight -- 32 phantom unit reads per plane desynced the tile and + /// every later symbol (including partition reads, which is what made + /// aomdec's zero-`value=8/9` census look like a partition-reader defect + /// in the rect14 review) decoded as garbage. + /// + /// Fail-pre-fix, measured on the ed12fe52 probe: both arms differ from + /// ffmpeg at byte 41120 (luma row 128 col 160, the first block decoded + /// after the phantom reads). The counter delta pins non-vacuity (class + /// `gate-blind-to-feature`): 96 clipped units on each arm. + #[test] + fn a_lossless_sb128_square_frame_clips_overhanging_chroma_tus() { + const NAME: &str = "a_lossless_sb128_square_frame_clips_overhanging_chroma_tus"; + if !have_ffmpeg() { + eprintln!("SKIP {NAME}: no ffmpeg"); + return; + } + // Arm 0 is the rect14 report's `loss320` recipe verbatim; arm 1 is its + // `lnone` companion (1:4 and rect partitions off) -- both coded the + // overhanging 64x64 blocks and both desynced at byte 41120 pre-fix. + let arms: [&[&str]; 2] = [ + &["--min-partition-size=4"], + &["--min-partition-size=4", "--enable-1to4-partitions=0", "--enable-rect-partitions=0"], + ]; + let mut clips_total = 0usize; + for (arm, extra) in arms.iter().enumerate() { + let stream = lossless_sb128_testsrc2(320, 240, extra); + crate::decode::reset_loss64_hits(); + let ours = decode_stream(&stream) + .unwrap_or_else(|e| panic!("{NAME}: arm {arm} decodes: {e}")); + let clips = crate::decode::chroma_edge_tu_clip_hits(); + assert!( + clips > 0, + "{NAME}: arm {arm} clipped NO overhanging chroma transform unit -- \ + the fixed body was never reached (class gate-blind-to-feature)" + ); + clips_total += clips; + let refs = ffmpeg_decode_sequence(&stream, 320, 240, 1); + assert_eq!(ours.len(), 1, "{NAME}: arm {arm} 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)] + .iter() + .enumerate() + { + let bad = g.iter().zip(r.iter()).filter(|(a, b)| a != b).count(); + assert_eq!(bad, 0, "{NAME}: arm {arm} plane {plane}: {bad} samples differ from ffmpeg"); + } + } + eprintln!("{NAME}: 2 arms full-frame exact, {clips_total} chroma units clipped"); + } + + /// lane-av1-loss64: a SKIPPED intrabc rect strip on a lossless frame + /// zeroes its whole entropy-band footprint (libaom + /// `av1_reset_entropy_context`, `if (mbmi->skip_txfm)` decodeframe.c:1262 -> + /// blockd.c:58) instead of leaving the previous occupant's luma bands + /// standing. The skip arm of `decode_intrabc_owned_rect` never wrote the + /// luma bands: the lossless `read_block_tx_size_rect` resolves the 4x4 + /// leaf list before it looks at `skip`, so the tail took the + /// per-transform-unit record path (chroma only) with no per-unit luma + /// writes ever run. The next block then read a STALE band: on the 320x242 + /// `--min-partition-size=4` sibling of this stream the skipped 8x16 + /// intrabc strip at mi(48,66) left a 7 in left[48] and mi(48,68)'s first + /// transform unit read `txb_skip_ctx` 3 where aomdec reads 1 (measured + /// `EC_ECDUMP` against the instrumented aomdec) -- a coefficient-walk + /// desync at byte 61712 with every mode symbol still matching. + /// + /// 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 + /// the lane tree with ONLY this gate's walk reverted: differs at byte + /// 61712, the band-leak site. + #[test] + fn a_skipped_lossless_intrabc_rect_strip_zeroes_its_entropy_bands() { + const NAME: &str = "a_skipped_lossless_intrabc_rect_strip_zeroes_its_entropy_bands"; + if !have_ffmpeg() { + eprintln!("SKIP {NAME}: no ffmpeg"); + return; + } + 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)] + .iter() + .enumerate() + { + 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, \ + {intrabc_skips} skipped intrabc chroma predictions" + ); + } + /// lane-dkey: the palette-neighbour-band gate. A palette-Y block's size and /// colours used to stay standing in the mi-granular above/left bands after a /// sub-8x8 group was decoded next to it -- the sub-8x8 readers published diff --git a/lanes/av1loss64.report.md b/lanes/av1loss64.report.md new file mode 100644 index 00000000..498d299b --- /dev/null +++ b/lanes/av1loss64.report.md @@ -0,0 +1,118 @@ +# 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: 421ca38c91a133e78b84a9a3c9f79defbddbc7163a0b3088a176f4cd50179728 +``` + +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. + +## Suite (orchestrator-run, committed tree 5c48d7b0) + +`CARGO_TARGET_DIR=$HOME/.cache/cargo-target-av1l64 TMPDIR=$HOME/tmp-av1l64 cargo test -p ec-av1 --release --lib -- --test-threads=1`: + +``` +test result: ok. 605 passed; 0 failed; 60 ignored; 0 measured; 0 filtered out; finished in 1371.22s +``` + +605 = 603 (main after rect14) + this lane's 2 new gate tests. First attempt +failed 6 tests on a missing TMPDIR directory (`writing the probe stream: No +such file or directory`) — environmental, green on re-run with the dir +created.