diff --git a/crates/ec-av1/fixtures/422_muchunk_intra_in_inter_128x256.obu b/crates/ec-av1/fixtures/422_muchunk_intra_in_inter_128x256.obu new file mode 100644 index 0000000000000000000000000000000000000000..8444ed0f0b4d412569521a4f0c16d695a487a95c GIT binary patch literal 667 zcmV;M0%ZLX0165~0009&|M&mq1TvEX5CFaa00C)cZafh36SDP)3#*;8CobXlNUFZ= z^_+2(!lxU?yq+Fj@1L{iF{uCjl@_eT0@8<00@`FX8-w48Rqa8pD|q> zl_h{PpC(uS?t>lK(?u0p*57*G!)gW*fzGm~A>t*2fpD6Rrn3^Z#-_Qm=Q4${<1+Z zRki!7R8?X&w?Qa|lx0d@R(cQCLu*I{G?pfl5p(BlT%(jcf(KGb+>c3Gjb|AdNV8vU zQMw-FWV&Dr@aEWC^Mzfie=GJhxn;D7)CoqPZQ0>Os>fB*uGnba9n34{$n zP#dc9fopeE^fu=cD5UsM$=hQy=%n-7Z4+UF<3rxS;iph%KOSkD{-(#;PLVKyBsAFw1c1t!tSv#p6^_ 64` mu-chunk + /// walk at 128x256 (TWO 128-superblock rows), site 8's second stream. + /// lane-av1muchunk422class measured this stream diverging with the class + /// signature -- V-plane-only diffs, first wrong sample V (row 190, col 36) + /// of shown frame 2 (V index `190 * 64 + 36 = 12196`, ours 147 vs + /// ffmpeg's 146), a byte-identical decode before and after the compound + /// fix, and the SAME `dc_sign_ctx` fork the compound fix targeted, on the + /// TX_32X32 chroma unit of THIS walk. The walk gathered its chroma + /// context with the plain luma `around_mi` (decode.rs:46820), which at + /// ss (1, 0) sums `unit_luma_w / MI` above cells where libaom sums + /// `txb_w_unit` -- twice as many -- flipping the signum whenever the + /// doubled above vote cancels the left one (see the walk's own comment). + /// + /// The fixture is the hunt's `i5_grad256_iis.obu` (sha256 + /// `64794f278eee738dcc59d90dc0c7c4ef2828c5b7c13724760a33be11f224908e`), + /// pinned byte-for-byte. Recipe: same aomenc argv as the 128x128 twin + /// below, source `gradients=size=128x256:...:seed=63:duration=0.24:rate=25, + /// noise=all_seed=63:alls=6:allf=t` (NOT re-encoded by this lane; the + /// bytes are the hunted bytes). + /// + /// Three halves, in order: (a) the site counter moved AND this stream + /// never enters the compound walk; (b) an ORACLE-FREE V-plane pin of + /// shown frame 2 plus the one sample that moved, so the exactness half + /// cannot silently skip; (c) the required ffmpeg compare -- every plane + /// of every shown frame byte-exact -- and the decode-order oracle compare + /// when one is available. + #[test] + fn a_422_muchunk_intra_in_inter_128x256_stream_is_exact_and_reaches_its_unit_walk() { + const NAME: &str = + "a_422_muchunk_intra_in_inter_128x256_stream_is_exact_and_reaches_its_unit_walk"; + const FILE: &str = "422_muchunk_intra_in_inter_128x256.obu"; + const LEN: usize = 667; + const FNV: u64 = 0x2bee_eba3_052b_f9a3; + const MIN_UNITS: usize = 96; + // 6 shown frames; the oracle also emits 1 hidden alt-ref frame. + const SHOWN: usize = 6; + // Shown frame 2's V plane, 4:2:2 at 128x256 -> 64 x 256 chroma. + const F2_V_FNV: u64 = 0xa7ba_8711_9d13_8fe5; + // V (row 190, col 36): the first sample that moved. The pre-fix + // square gather read 147 here, ffmpeg 146. + const FIRST_WRONG_V: usize = 190 * 64 + 36; + const F2_V_AT_FIRST_WRONG: u16 = 146; + let _gate_lock = lock_gate_counters(); + let stream = read_pinned_muchunk_fixture(FILE, LEN, FNV, NAME); + assert_eq!( + obu_stream_shape(&stream), + Some((true, 1, 0, false)), + "{NAME}: {FILE} is not a 4:2:2 (ss 1/0, non-mono) 128-superblock stream" + ); + let before = ( + crate::decode::mu_chunk_compound_units(), + crate::decode::mu_chunk_intra_in_inter_units(), + ); + let shown = crate::stream::decode_stream(&stream) + .unwrap_or_else(|e| panic!("{NAME}: {FILE} no longer decodes cleanly: {e}")); + let frames = shown.len(); + let (compound, intra) = ( + crate::decode::mu_chunk_compound_units() - before.0, + crate::decode::mu_chunk_intra_in_inter_units() - before.1, + ); + assert_eq!(frames, SHOWN, "{NAME}: {FILE} shown-frame count"); + assert!( + intra >= MIN_UNITS, + "{NAME}: {FILE} allocated only {intra} intra-in-inter `side > 64` mu-chunk units \ + (expected >= {MIN_UNITS}) -- the site counter this gate names did not move" + ); + assert_eq!( + compound, 0, + "{NAME}: {FILE} also ran the compound walk ({compound} units) -- the two cells are \ + no longer separated" + ); + // (b) the oracle-free half: the V plane of the first intrinsically + // wrong frame, sample-for-sample, plus the one sample the pre-fix + // gather got wrong. + assert_eq!( + shown[2].v.len(), + 64 * 256, + "{NAME}: {FILE} is no longer 4:2:2 at 128x256 -- the V plane shape moved" + ); + assert_eq!( + shown[2].v[FIRST_WRONG_V], F2_V_AT_FIRST_WRONG, + "{NAME}: {FILE} shown frame 2 V[{FIRST_WRONG_V}] (chroma (190, 36)) is {} -- the \ + pre-fix square gather read 147 here", + shown[2].v[FIRST_WRONG_V] + ); + assert_eq!( + fnv1a64(&shown[2].v.iter().map(|&s| s as u8).collect::>()), + F2_V_FNV, + "{NAME}: {FILE} shown frame 2's V plane moved -- the intra-in-inter mu-chunk walk's \ + 4:2:2 chroma context gather is wrong again (first sample to move is chroma (190, \ + 36), index {FIRST_WRONG_V})" + ); + // (c) the required ffmpeg compare: every plane of every shown frame. + if !have_ffmpeg() { + eprintln!( + "SKIP {NAME}: no ffmpeg -- the 4:2:2 pixel compare this gate exists for did NOT \ + run (set EC_AV1_REQUIRE_FFMPEG=1 to make this a failure)" + ); + return; + } + let ff = ffmpeg_decode_sequence_422(&stream, 128, 256, SHOWN); + assert_eq!(ff.len(), SHOWN, "{NAME}: {FILE} ffmpeg shown-frame count"); + for (i, (got, want)) in shown.iter().zip(&ff).enumerate() { + assert_eq!( + got.y, want.y, + "{NAME}: {FILE} shown frame {i} luma vs ffmpeg" + ); + assert_eq!(got.u, want.u, "{NAME}: {FILE} shown frame {i} U vs ffmpeg"); + assert_eq!(got.v, want.v, "{NAME}: {FILE} shown frame {i} V vs ffmpeg"); + } + if aomdec_available(NAME) { + let (decoded, hidden) = decode_all_frames_vs_oracle(&stream, NAME); + assert_eq!( + decoded, + SHOWN + 1, + "{NAME}: {FILE} decode-order frame count" + ); + eprintln!( + "{NAME}: {FILE} byte-exact vs ffmpeg over {SHOWN} shown frames and vs the \ + decode-order oracle over {decoded} frame(s) ({hidden} hidden), \ + intra_in_inter_units={intra}" + ); + } else { + eprintln!( + "{NAME}: {FILE} byte-exact vs ffmpeg over {SHOWN} shown frames, \ + intra_in_inter_units={intra} -- the decode-order oracle compare above did NOT \ + run (no aomdec)" + ); + } + } + /// lane-sbpart r2: a real `aomenc` stream whose superblock-level /// partition decision is genuinely HORZ/VERT (not NONE/SPLIT) must /// decode pixel-exact through [`crate::decode::decode_block_rect64`] -- diff --git a/lanes/av1muchunk422iis.report.md b/lanes/av1muchunk422iis.report.md new file mode 100644 index 00000000..e9bdbcce --- /dev/null +++ b/lanes/av1muchunk422iis.report.md @@ -0,0 +1,155 @@ +# lane-av1muchunk422iis — the intra-in-inter mu-chunk chroma gather at 4:2:2 + +Base: `main` @ `bba9767d`. Branch: `lane/av1muchunk422iis`. Local only. + +**Verdict: closed.** The intra-in-inter `side > 64` mu-chunk walk +(`decode.rs:46820`) gathered its per-unit CHROMA coefficient context with the +plain luma `around_mi`, which at ss (1, 0) sums `unit_luma_w / MI` above cells +where libaom sums `txb_w_unit` — twice as many — so `dc_sign_ctx`'s signum +flipped whenever the doubled above vote cancelled the left one. Routed through +`around_mi_422_chroma` with the unit's PER-AXIS luma footprint +(`unit_luma_w`, `unit_luma_h`) exactly as the compound twin already was, the +hunted stream `i5_grad256_iis.obu` is now **byte-exact against ffmpeg over all +6 shown frames, every plane**, and byte-exact against the decode-order oracle +over all 7 frames (6 shown + 1 hidden alt-ref). Restoring the square gather reds +the new gate on the exact sample the class report named. + +## 1. The change + +One site, `crates/ec-av1/src/decode.rs` in the intra-in-inter `side > 64` +mu-chunk unit loop: + +```rust +let cu_around = if ss_x(fctx) == 1 && ss_y(fctx) == 0 { + neighbours.around_mi_422_chroma(unit_mi, unit_luma_w, unit_luma_h) +} else { + neighbours.around_mi(unit_mi, unit_luma_w) +}; +``` + +The condition is the same ss (1, 0) gate the eight sibling chroma gathers use +(`decode.rs:15441, 18268, 23924, 24282, 24956, 43980, 45810`). At ss (1, 0) +`unit_luma_w = cu_tx << 1 = 64` and `unit_luma_h = cu_tx << 0 = 32`, so +`around_mi_422_chroma` samples every second above cell (libaom's +`txb_w_unit`-cell sum) and takes the full `unit_luma_h` left extent +(unsubsampled at ss_y 0). At 4:2:0 (ss 1,1) and 4:4:4 (ss 0,0) the two luma +extents are equal, so the `else` branch is the previous call verbatim — the +440/444 arms are unchanged text on an untaken path. + +Not touched: the compound walk, c3, c4. + +## 2. The pinned stream + +`crates/ec-av1/fixtures/422_muchunk_intra_in_inter_128x256.obu` + +| | | +|---|---| +| sha256 | `64794f278eee738dcc59d90dc0c7c4ef2828c5b7c13724760a33be11f224908e` | +| bytes | 667 | +| fnv1a64 | `0x2bee_eba3_052b_f9a3` | +| source | `~/.cache/av1muchunk422b/i5_grad256_iis.obu` (the hunt's file; NOT re-encoded) | +| shape | `(use_128x128_superblock, ss_x, ss_y, mono) = (true, 1, 0, false)` | +| frames | 6 shown + 1 hidden alt-ref (decode order 7) | + +Recipe (same aomenc argv as the 128x128 twin `422_muchunk_intra_in_inter_128root.obu`, +different source): + +```text +ffmpeg -v error -f lavfi -i "gradients=size=128x256:c0=0xa1128f:c1=0xd98c48:\ + c2=0x120601:c3=0x4abfba:seed=63:duration=0.24:rate=25,\ + noise=all_seed=63:alls=6:allf=t" -t 0.24 -pix_fmt yuv422p \ + -f yuv4mpegpipe - > grad256.y4m +aomenc --codec=av1 --profile=2 --input-chroma-subsampling-x=1 \ + --input-chroma-subsampling-y=0 --passes=1 --end-usage=q --cq-level=62 \ + --cpu-used=0 --threads=1 --row-mt=0 --sb-size=128 \ + --min-partition-size=128 --max-partition-size=128 \ + --enable-rect-partitions=0 --enable-ab-partitions=0 \ + --enable-1to4-partitions=0 --enable-palette=0 --enable-intrabc=0 \ + --deltaq-mode=0 --enable-tx-size-search=0 --enable-interintra-comp=1 \ + --enable-interintra-wedge=1 --enable-smooth-interintra=1 --obu -o X +``` + +## 3. Measurement — per-frame, per-plane vs ffmpeg + +`ffmpeg -v error -i X.obu -pix_fmt yuv422p -f rawvideo` vs +`dump_yuv X.obu `, differing samples per shown frame (Y / U / V): + +| stream | f0 | f1 | f2 | f3 | f4 | f5 | +|---|---|---|---|---|---|---| +| **pre-fix** (square gather) | 0 | 0 | V **2105** | 0 | V 1982 | Y 24155 U 12162 V 12091 | +| **post-fix** | 0 | 0 | 0 | 0 | 0 | 0 | + +Pre-fix first wrong sample: V (row 190, col 36) of shown frame 2 (V index +`190 * 64 + 36 = 12196`), **ours 147 vs ffmpeg 146**. Post-fix that sample reads +146 and shown frame 2's whole V plane hashes +`fnv1a64 = 0xa7ba_8711_9d13_8fe5`, equal to ffmpeg's own bytes. + +(The class report's prose wrote the pair as "ours 146 vs ffmpeg 147"; the +measured pair on this host is ours-147/ffmpeg-146 pre-fix. Same location, same +one-sample disagreement, mirrored wording.) + +## 4. The gate + +`crates/ec-av1/src/stream.rs` +`a_422_muchunk_intra_in_inter_128x256_stream_is_exact_and_reaches_its_unit_walk`: + +1. **Counter witness** — `mu_chunk_intra_in_inter_units()` delta `96 >= 96` + (the walk ran), `mu_chunk_compound_units()` delta `0` (this stream never + enters the compound arm). +2. **Oracle-free pin** — shown frame 2 V plane length `64 * 256`, sample + `V[12196] == 146`, whole-V-plane fnv `0xa7ba_8711_9d13_8fe5`. Cannot + silently skip. +3. **Required ffmpeg compare** — every plane of every shown frame equal to + `ffmpeg_decode_sequence_422` (hard-fails under `EC_AV1_REQUIRE_FFMPEG`; + prints a loud SKIP-note otherwise). +4. **Decode-order oracle compare** — `decode_all_frames_vs_oracle` when aomdec + is present (7 frames). + +### Red-before-green + +Restoring the call to `neighbours.around_mi(unit_mi, unit_luma_w)` reds exactly +the pin: + +``` +panicked at stream.rs:43404: + ... shown frame 2 V[12196] (chroma (190, 36)) is 147 -- the pre-fix square gather read 147 here + left: 147 right: 146 +``` + +Green after the fix (all three mu-chunk gates + the 4:4:4 twin): + +``` +a_422_muchunk_compound_128root_pinned_stream_reaches_its_unit_walk ... ok (compound_units=32, intra=0) +a_422_muchunk_intra_in_inter_128root_pinned_stream_is_exact_and_reaches_its_unit_walk ... ok +a_422_muchunk_intra_in_inter_128x256_stream_is_exact_and_reaches_its_unit_walk ... ok (intra_in_inter_units=96) +a_444_intra_in_inter_128root_muchroma_pinned_stream_decodes_pixel_exact ... ok +``` + +## 5. Repro + +``` +git worktree add -b lane/av1muchunk422iis ~/.cache/wt/av1muchunk422iis origin/main # bba9767d +cd ~/.cache/wt/av1muchunk422iis +export CARGO_TARGET_DIR=$HOME/.cache/tgt-av1muchunk422iis TMPDIR=$HOME/.cache/tmp +export EC_AV1_REQUIRE_FFMPEG=1 EC_AV1_AOMDEC=$HOME/.cache/aom-oracle/build/aomdec +cargo test -p ec-av1 --lib muchunk -- --nocapture +``` + +Raw ffmpeg compare (outputs under `$HOME`, never `/tmp` — this host's `/tmp` is +over quota): + +``` +S=crates/ec-av1/fixtures/422_muchunk_intra_in_inter_128x256.obu +ffmpeg -v error -y -i $S -pix_fmt yuv422p -f rawvideo $HOME/.cache/tmp/i5.ref.yuv +$CARGO_TARGET_DIR/debug/examples/dump_yuv $S $HOME/.cache/tmp/i5.ours.yuv +# per-frame 65536-byte planes: Y 32768, U 16384, V 16384 +``` + +## 6. Not claimed + +- The class is not declared closed beyond this walk: c3/c4 remain diverging and + were not touched. This lane fixes and pins the intra-in-inter `side > 64` + mu-chunk gather only. +- Nothing about 4:2:0 or 4:4:4 was changed; their identity is structural (the + `else` branch is the old call on an untaken path) and spot-checked on the + 4:4:4 twin above.