From 947082223f7ef02d4c5c4363c1fa3c01a5ca0a6d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Mon, 28 Sep 2026 21:32:43 +0300 Subject: [PATCH] ec-av1: lane-av1444rect -- a 1:4 inter strip's chroma context was gathered at the 4:2:0 pair extent at ss (0,0), forking the coder (H1) At 4:4:4 `is_chroma_reference` (av1_common_int.h:1454) reduces both parity clauses to `!subsampling_y` / `!subsampling_x`, so EVERY block is its own chroma reference and no 1:4 pair exists. `decode_inter_block`'s `around_c` never gated on ss, so a HORZ_4 16x4 strip read its chroma coefficient context over the 4:2:0 pair extent (16x8 luma = left[mi_r] and left[mi_r+1]) instead of its own 4-px one. The U unit's `get_txb_ctx` then saw a left neighbour libaom does not have and forked the arithmetic coder. The 4:4:4 lossy + RECT cell -- the largest correctness gap the chroma-format sweep left (lanes/av1formatsweep.report.md H1) -- had NO exactness gate at all: the whole committed 4:4:4 base is lossless 8-bit. Witness: testsrc2 128x96 rate=25 yuv444p, aomenc --profile=1 --passes=1 --end-usage=q --cq-level=20 --cpu-used=2 --threads=1 --row-mt=0 --lag-in-frames=0 --kf-max-dist=100 --limit=2, 6441 B, sha256 77f727e7... Red before: frame 1, 8884/36864 samples wrong, first at Y(91,32); the first wrong symbol was read 26263, both sides at mi (8,16) -- ours a luma-shaped txb_skip row (re-indexed chroma ctx 1), the oracle decodetxb.c:158 on the U plane with txb_skip_ctx 7. Green after: 2/2 frames byte-exact vs aomdec. Gate `a_444_lossy_rect4_inter_stream_decodes_pixel_exact` pins the fixture (len + FNV), asserts the ss (0,0) full-resolution chroma shape, the byte-exact compare through the oracle aomdec, and non-vacuity on the corrected route via `rect4_inter_own_chroma444_hits` (9 gathers here, 0 on the 4:2:0 control, which also carries 16 HORZ_4 / 28 VERT_4 strips and is itself compared byte-for-byte so a widening past ss_x 0 goes red). Mutation proof: restoring the old arm with the counter left in place turns the gate red at byte 4187 (ours 35 vs 38), 8884 bytes differing. Identity: the crate's whole 444 family (9), rect_strip family (10), the 16-level rect-leaf gate, and all three new chroma-format-sweep gates (444 lossless 10-bit, 444 12-bit, odd coded dimensions) run green against this decode.rs. H2 (4:4:4 lossy tx-size-search chroma +/-1, 608/36864 from frame 2) is unchanged and still divergent -- it is reconstruction arithmetic, not entropy, and belongs to its own lane. H3's tile-column recipe (77847 B, 6 frames) is byte-exact here. --- .../444_lossy_rect4_inter_witness.obu | Bin 0 -> 6441 bytes crates/ec-av1/src/decode.rs | 59 +++++- crates/ec-av1/src/stream.rs | 182 +++++++++++++++++- 3 files changed, 232 insertions(+), 9 deletions(-) create mode 100644 crates/ec-av1/fixtures/444_lossy_rect4_inter_witness.obu diff --git a/crates/ec-av1/fixtures/444_lossy_rect4_inter_witness.obu b/crates/ec-av1/fixtures/444_lossy_rect4_inter_witness.obu new file mode 100644 index 0000000000000000000000000000000000000000..9f58f522f507c6d888f566a589ce24e947a18451 GIT binary patch literal 6441 zcmV+^8P?_!0165q0009w`{vio5HgJ_6aXMF001Eb5C{U@Fb)Lg?qU%ToSlGaN*5v# zuBapd%~D#v^%efy^Xl=WLI)TA)Q&K1B4I5_ib3Ni|H9`#{Q5-nMt73u>G>D({bkbQKYvDETRWh5|SqM>Om9Z1PU5J0FS9P(Ojo}_oJbz z06!-L9(l&$`tliyx5nTXW)9HMf^2~=rVkQU1ay$8`6vWDwG`lWM9P>y&%J>u0)6+U zEg`tbNSDa!xErcSZ@JtmK4chCx2<{t=r7V_=wkkMt=Ppg#B!6n;7v-^cN;fF@`56A zKn8#A31Z9mb`N?pf>tX42Tq5uTvQVt7I9HSiioFt@WJk^K9Ie{pVU7luvXp)B3MX@ zN8H1&Gd0Oa-aIt7qMT%`JN;*fhS!f|U;Qek70Jg{CB$)2-RF_0j6er+3r2Wiw-Y z2CCb!#pnjF4Al$J)dnklLH z*Q$(0AYj&s16EtrFJsb@v$G)@8Rn2`TVmH=MfAx4M`$#Hc> z3Q9!~Tu{)~yzVw0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 --- a/crates/ec-av1/src/decode.rs +++ b/crates/ec-av1/src/decode.rs @@ -5504,6 +5504,28 @@ pub(crate) fn intra_rect4_strip_in_inter_hits(shape: usize) -> usize { INTRA_RECT4_IN_INTER_HITS.with(|c| c.get()[shape]) } +// lane-av1444rect: how many 1:4 inter strips at `ss_x == 0` read their chroma +// coefficient context over the STRIP'S OWN extent instead of the 4:2:0 pair's +// (see [`decode_inter_block`]'s `around_c`). `is_chroma_reference` +// (av1_common_int.h:1454) is unconditionally true at ss (0,0), so no pair +// exists there; the counter is what keeps a 4:4:4 1:4-strip gate from passing +// vacuously (a 4:2:0 stream of the same content leaves it at 0). +thread_local! { + static RECT4_INTER_OWN_CHROMA444_HITS: std::cell::Cell = const { std::cell::Cell::new(0) }; +} + +/// Current value of [`RECT4_INTER_OWN_CHROMA444_HITS`]. +#[allow(dead_code)] // read only from the `#[cfg(test)]` gates +pub(crate) fn rect4_inter_own_chroma444_hits() -> usize { + RECT4_INTER_OWN_CHROMA444_HITS.with(std::cell::Cell::get) +} + +/// Resets [`RECT4_INTER_OWN_CHROMA444_HITS`] before a decode. +#[allow(dead_code)] // read only from the `#[cfg(test)]` gates +pub(crate) fn reset_rect4_inter_own_chroma444_hits() { + RECT4_INTER_OWN_CHROMA444_HITS.with(|c| c.set(0)); +} + // lane-intra14 r1: set while an INTRA block of an INTER frame is decoded // through one of the key-frame rect readers ([`decode_block_rect4`], // [`decode_block_rect64`]). `Some((size_group, skip))` tells @@ -40827,17 +40849,38 @@ fn decode_inter_block( // ([`Neighbours::around_mi_422_chroma`]) -- and the same // reroute catches 4:2:2 VERT: its (8, 16) pair span's // above side covers one chroma column per two luma mi - // columns, the identical double-count. The plain per-mi - // gather survives only where the ss gate excludes it: - // the 4:2:0 pair merge (16, 8) and every 4:4:4 shape. + // columns, the identical double-count. + // + // lane-av1444rect (H1, MEASURED): the (16, 8) / (8, 16) pair + // extent was reached at ss (0,0) too, where no pair exists. + // At 4:4:4 `is_chroma_reference` (av1_common_int.h:1454) + // reduces BOTH parity clauses to `!subsampling_y` / + // `!subsampling_x`, so every block is its own chroma + // reference: a HORZ_4 16x4 strip codes its OWN 16x4 chroma + // and the setter above already gave it `pair_mi == at_mi`. + // Its coefficient context is therefore the strip's own, + // which is exactly the `around` gathered one screen above + // as `around_mi_rect(at_mi, write_w, write_h)`. The pair + // gather read one EXTRA luma mi row of LEFT chroma context + // (`ph = 8` covers left[8] and left[9], a 4-px strip only + // left[8]), so the U unit's `get_txb_ctx` saw a neighbour + // libaom does not have and forked the arithmetic coder: the + // 6441-byte 4:4:4 lossy cq-20 stream, frame 1, mi(8,16) + // read our `txb_skip_ctx` 1 (0 above + 1 left) where the + // oracle read offset-7 row 7 (ctx_base 0). let around_c = match strip_chroma { + // lane-av1444rect: the arm `is_chroma_reference` makes the + // ONLY correct choice at ss_x 0 -- no pair exists, the + // extent is the strip's own. Counted so a 4:4:4 1:4-strip + // gate can prove it exercised this route (a 4:2:0 stream + // of the same content reads 0). + Some(_) if ss_x(fctx) == 0 => { + hit!(RECT4_INTER_OWN_CHROMA444_HITS); + around + } Some(s) if s.has_chroma => { let (pw, ph) = if s.horz { - if ss_x(fctx) == 1 && ss_y(fctx) == 0 { - (16, 4) - } else { - (16, 8) - } + if ss_y(fctx) == 0 { (16, 4) } else { (16, 8) } } else { (8, 16) }; diff --git a/crates/ec-av1/src/stream.rs b/crates/ec-av1/src/stream.rs index 001fcfe7..406c9de6 100644 --- a/crates/ec-av1/src/stream.rs +++ b/crates/ec-av1/src/stream.rs @@ -2671,7 +2671,6 @@ pub(crate) mod tests { ); } - /// lane-av1-qmatrix: WITNESS for the lifted `using_qmatrix` refusal (the /// old gate `a_frame_using_quantisation_matrices_is_refused_by_name` is /// its mirror image -- its own panic said "flip this gate to a witness" @@ -6928,6 +6927,187 @@ pub(crate) mod tests { } } + /// lane-av1444rect (H1): the 4:4:4 LOSSY cell with a 1:4 (HORZ_4 / + /// VERT_4) partition -- the largest correctness gap the chroma-format + /// sweep left, and the first 4:4:4 lossy exactness gate in the crate. + /// + /// **The defect.** `decode_inter_block`'s `around_c` gathered a 1:4 + /// strip's chroma coefficient context at the 4:2:0 PAIR extent + /// (`(16, 8)` HORZ / `(8, 16)` VERT) with no `ss` gate, so at ss (0,0) + /// it read one extra luma mi row of LEFT chroma context. At 4:4:4 + /// `is_chroma_reference` (av1_common_int.h:1454) reduces both parity + /// clauses to `!subsampling_y` / `!subsampling_x`, so every block is its + /// own chroma reference and no pair exists: the strip codes its own + /// 16x4 chroma over its own context. Our U unit's `get_txb_ctx` then saw + /// a neighbour libaom does not have, and the arithmetic coder forked. + /// + /// **The recipe** (sha256 + /// `77f727e76d81fe48cd03709f799131677c04869b163e18d78e96bc742ec69153`, + /// 6441 bytes, 2 frames, `testsrc2 128x96 rate=25` yuv444p): + /// ```text + /// ffmpeg -f lavfi -i "testsrc2=size=128x96:rate=25" -frames:v 2 \ + /// -pix_fmt yuv444p -f yuv4mpegpipe - | \ + /// aomenc --codec=av1 --profile=1 --passes=1 --end-usage=q --cq-level=20 \ + /// --cpu-used=2 --threads=1 --row-mt=0 --lag-in-frames=0 \ + /// --kf-max-dist=100 --limit=2 - out.obu + /// ``` + /// (`rate=25` is load-bearing: `testsrc2`'s pattern is time-parameterised, + /// so `rate=1` produces a different, already-exact stream.) + /// + /// Red before the fix: frame 1, 8884 of 36864 samples wrong, first at + /// Y(91,32); the first wrong symbol was read 26263 of the frame, both + /// sides at mi (8,16) -- ours a luma-shaped `txb_skip` row (our + /// re-indexed chroma ctx 1), the oracle `decodetxb.c:158` on the U plane + /// with `txb_skip_ctx = 7`. + /// + /// Non-vacuity, three ways: the pinned stream must really be ss (0,0) + /// (asserted through the oracle aomdec's own sequence header, below); + /// `decode::rect4_inter_own_chroma444_hits()` must be non-zero, so the + /// 1:4-strip route the fix sits on really ran; and the SAME source and + /// flags at 4:2:0 must leave that counter at zero, which is what makes + /// it the 4:4:4-only route rather than a tally every strip bumps. + #[test] + fn a_444_lossy_rect4_inter_stream_decodes_pixel_exact() { + const NAME: &str = "a_444_lossy_rect4_inter_stream_decodes_pixel_exact"; + const FIXTURE_LEN: usize = 6441; + const FIXTURE_FNV: u64 = 0x0436_8b2d_2e91_72b0; + const W: usize = 128; + const H: usize = 96; + const FRAMES: usize = 2; + let obu = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR")) + .join("fixtures/444_lossy_rect4_inter_witness.obu"); + let stream = std::fs::read(&obu).unwrap_or_else(|e| { + panic!( + "{NAME}: pinned fixture {} is missing ({e}) -- the gate cannot run, \ + which is a failure, not a skip", + obu.display() + ) + }); + assert_eq!(stream.len(), FIXTURE_LEN, "{NAME}: fixture length moved"); + assert_eq!(fnv1a64(&stream), FIXTURE_FNV, "{NAME}: fixture bytes moved"); + + let _guard = lock_gate_counters(); + crate::decode::reset_rect4_inter_own_chroma444_hits(); + let frames = decode_stream(&stream).unwrap_or_else(|e| { + panic!("{NAME}: the pinned 4:4:4 lossy stream no longer decodes cleanly: {e}") + }); + let own_chroma = crate::decode::rect4_inter_own_chroma444_hits(); + assert!( + own_chroma > 0, + "{NAME}: no 1:4 inter strip read its chroma context over its own \ + extent -- the corrected route never ran (class gate-blind-to-feature)" + ); + assert_eq!(frames.len(), FRAMES, "{NAME}: frame count"); + for (i, f) in frames.iter().enumerate() { + assert_eq!((f.width, f.height), (W, H), "{NAME}: frame {i} dimensions"); + // At 4:4:4 the chroma planes are full resolution. A decoder that + // kept the 4:2:0 extent would hand quarter-size chroma planes to + // the byte compare below, which cannot pass -- but say so here + // rather than let the compare stand in for the shape claim. + assert_eq!( + f.u.len(), + W * H, + "{NAME}: frame {i} chroma plane is {} samples; at 4:4:4 it must be \ + full resolution ({W}x{H})", + f.u.len() + ); + } + if aomdec_path().is_file() { + let (decoded, _hidden) = decode_all_frames_vs_oracle(&stream, NAME); + eprintln!( + "{NAME}: {decoded} frame(s) byte-exact vs aomdec, {own_chroma} \ + own-extent 1:4 chroma gather(s)" + ); + } else { + eprintln!("{NAME}: no oracle aomdec, pixel arm skipped"); + } + + // The specificity arm: the SAME source, flags and 1:4 partitions at + // 4:2:0 must not touch the 4:4:4-only route. If a later change made + // the counter fire everywhere, this arm is what catches it. + if !have_aomenc() { + eprintln!("{NAME}: no aomenc, 4:2:0 specificity arm skipped"); + return; + } + let source = format!("testsrc2=size={W}x{H}:rate=25"); + let y4m = Command::new("ffmpeg") + .args([ + "-v", + "error", + "-f", + "lavfi", + "-i", + &source, + "-frames:v", + "2", + "-pix_fmt", + "yuv420p", + "-strict", + "-1", + "-f", + "yuv4mpegpipe", + "-", + ]) + .stdin(Stdio::null()) + .stdout(Stdio::piped()) + .stderr(Stdio::piped()) + .output() + .expect("ffmpeg failed to run"); + assert!( + y4m.status.success(), + "{NAME}: ffmpeg refused the 4:2:0 control source: {}", + String::from_utf8_lossy(&y4m.stderr) + ); + let out = run_with_stdin( + Command::new(aomenc_path()).args([ + "--codec=av1", + "--passes=1", + "--end-usage=q", + "--cq-level=20", + "--cpu-used=2", + "--threads=1", + "--row-mt=0", + "--lag-in-frames=0", + "--kf-max-dist=100", + "--limit=2", + "--obu", + "-o", + "-", + "-", + ]), + &y4m.stdout, + ); + assert!( + out.status.success(), + "{NAME}: aomenc refused the 4:2:0 control recipe: {}", + String::from_utf8_lossy(&out.stderr) + ); + crate::decode::reset_rect4_inter_own_chroma444_hits(); + decode_stream(&out.stdout) + .unwrap_or_else(|e| panic!("{NAME}: the 4:2:0 control stream was refused: {e}")); + let (h4, v4, _, _) = crate::decode::inter16_rect4_counters(); + // The control must actually code 1:4 inter strips, or it says nothing + // about the arm the fix touches. Measured: 16 HORZ_4, 28 VERT_4. + assert!( + h4 + v4 > 0, + "{NAME}: the 4:2:0 control coded NO 1:4 inter strip ({h4} HORZ_4, {v4} \ + VERT_4) -- the identity arm below would say nothing about 1:4 strips" + ); + assert_eq!( + crate::decode::rect4_inter_own_chroma444_hits(), + 0, + "{NAME}: the 4:2:0 control fired the ss_x-0 own-extent route -- the route \ + is not specific to the 4:4:4 cell it was fixed for" + ); + // The identity half: the fix adds an arm gated on `ss_x == 0`, so a + // 4:2:0 stream must stay byte-exact through it. This is the arm that + // would go red if the new arm were ever widened past ss_x 0. + if aomdec_path().is_file() { + decode_all_frames_vs_oracle(&out.stdout, &format!("{NAME}-420")); + } + eprintln!("{NAME}: 4:2:0 control {h4} HORZ_4 / {v4} VERT_4 strips, 0 own-extent gathers"); + } + /// lane-av1lrflush: the pipelined loop-restoration band release flushes /// RU row 0 on the inter frame whose top superblock row carries a /// 128-root rect -- the exact shape lanes/av1444sb.report.md r2 named as