ec-av1: route the intra-in-inter side>64 mu-chunk chroma gather through the 4:2:2 pair rule
Browse files at this commit5b9e8bc87c3738dc7bf7b82c5de6598958a9a9b4Parent: 8e086184 changed files +309 -1
- crates/ec-av1/fixtures/422_muchunk_intra_in_inter_128x256.obu +0 -0
- crates/ec-av1/src/decode.rs +23 -1
- crates/ec-av1/src/stream.rs +131 -0
- lanes/av1muchunk422iis.report.md +155 -0
crates/ec-av1/fixtures/422_muchunk_intra_in_inter_128x256.obuadded+0 -0
Binary file changed
crates/ec-av1/src/decode.rsmodified+23 -1
| @@ -46816,7 +46816,29 @@ fn decode_inter_block( | ||
| 46816 | 46816 | // The unit's own entropy-cell span, so the |
| 46817 | 46817 | // NEXT unit of this chunk reads THIS one's |
| 46818 | 46818 | // state and the next chunk reads the last. |
| 46819 | - let cu_around = neighbours.around_mi(unit_mi, unit_luma_w); | |
| 46819 | + // | |
| 46820 | + // lane-av1muchunk422iis: the intra-in-inter twin | |
| 46821 | + // of the compound mu-chunk gather. At ss (1, 0) | |
| 46822 | + // one CHROMA column spans two luma mi columns, | |
| 46823 | + // so libaom's `get_txb_ctx_general` reads its | |
| 46824 | + // above votes over `txb_w_unit` chroma cells | |
| 46825 | + // while a plain luma `around_mi` gathers | |
| 46826 | + // `unit_luma_w / MI` -- twice as many -- and | |
| 46827 | + // `dc_sign_ctx`'s signum flips whenever the | |
| 46828 | + // doubled above vote cancels the left one. The | |
| 46829 | + // LEFT extent is unsubsampled at ss_y 0, so the | |
| 46830 | + // per-axis footprint is what the pair-aware | |
| 46831 | + // helper needs; 4:2:0 / 4:4:4 have square | |
| 46832 | + // footprints and keep the plain gather verbatim. | |
| 46833 | + let cu_around = if ss_x(fctx) == 1 && ss_y(fctx) == 0 { | |
| 46834 | + neighbours.around_mi_422_chroma( | |
| 46835 | + unit_mi, | |
| 46836 | + unit_luma_w, | |
| 46837 | + unit_luma_h, | |
| 46838 | + ) | |
| 46839 | + } else { | |
| 46840 | + neighbours.around_mi(unit_mi, unit_luma_w) | |
| 46841 | + }; | |
| 46820 | 46842 | let (cu_x, cu_y) = ( |
| 46821 | 46843 | cpx + cc * chunk_chroma_w + uc * cu_tx, |
| 46822 | 46844 | cpy + cr * chunk_chroma_h + ur * cu_tx, |
crates/ec-av1/src/stream.rsmodified+131 -0
| @@ -43322,6 +43322,137 @@ exit 0 | ||
| 43322 | 43322 | ); |
| 43323 | 43323 | } |
| 43324 | 43324 | |
| 43325 | + /// lane-av1muchunk422iis: the **intra-in-inter** `side > 64` mu-chunk | |
| 43326 | + /// walk at 128x256 (TWO 128-superblock rows), site 8's second stream. | |
| 43327 | + /// lane-av1muchunk422class measured this stream diverging with the class | |
| 43328 | + /// signature -- V-plane-only diffs, first wrong sample V (row 190, col 36) | |
| 43329 | + /// of shown frame 2 (V index `190 * 64 + 36 = 12196`, ours 147 vs | |
| 43330 | + /// ffmpeg's 146), a byte-identical decode before and after the compound | |
| 43331 | + /// fix, and the SAME `dc_sign_ctx` fork the compound fix targeted, on the | |
| 43332 | + /// TX_32X32 chroma unit of THIS walk. The walk gathered its chroma | |
| 43333 | + /// context with the plain luma `around_mi` (decode.rs:46820), which at | |
| 43334 | + /// ss (1, 0) sums `unit_luma_w / MI` above cells where libaom sums | |
| 43335 | + /// `txb_w_unit` -- twice as many -- flipping the signum whenever the | |
| 43336 | + /// doubled above vote cancels the left one (see the walk's own comment). | |
| 43337 | + /// | |
| 43338 | + /// The fixture is the hunt's `i5_grad256_iis.obu` (sha256 | |
| 43339 | + /// `64794f278eee738dcc59d90dc0c7c4ef2828c5b7c13724760a33be11f224908e`), | |
| 43340 | + /// pinned byte-for-byte. Recipe: same aomenc argv as the 128x128 twin | |
| 43341 | + /// below, source `gradients=size=128x256:...:seed=63:duration=0.24:rate=25, | |
| 43342 | + /// noise=all_seed=63:alls=6:allf=t` (NOT re-encoded by this lane; the | |
| 43343 | + /// bytes are the hunted bytes). | |
| 43344 | + /// | |
| 43345 | + /// Three halves, in order: (a) the site counter moved AND this stream | |
| 43346 | + /// never enters the compound walk; (b) an ORACLE-FREE V-plane pin of | |
| 43347 | + /// shown frame 2 plus the one sample that moved, so the exactness half | |
| 43348 | + /// cannot silently skip; (c) the required ffmpeg compare -- every plane | |
| 43349 | + /// of every shown frame byte-exact -- and the decode-order oracle compare | |
| 43350 | + /// when one is available. | |
| 43351 | + #[test] | |
| 43352 | + fn a_422_muchunk_intra_in_inter_128x256_stream_is_exact_and_reaches_its_unit_walk() { | |
| 43353 | + const NAME: &str = | |
| 43354 | + "a_422_muchunk_intra_in_inter_128x256_stream_is_exact_and_reaches_its_unit_walk"; | |
| 43355 | + const FILE: &str = "422_muchunk_intra_in_inter_128x256.obu"; | |
| 43356 | + const LEN: usize = 667; | |
| 43357 | + const FNV: u64 = 0x2bee_eba3_052b_f9a3; | |
| 43358 | + const MIN_UNITS: usize = 96; | |
| 43359 | + // 6 shown frames; the oracle also emits 1 hidden alt-ref frame. | |
| 43360 | + const SHOWN: usize = 6; | |
| 43361 | + // Shown frame 2's V plane, 4:2:2 at 128x256 -> 64 x 256 chroma. | |
| 43362 | + const F2_V_FNV: u64 = 0xa7ba_8711_9d13_8fe5; | |
| 43363 | + // V (row 190, col 36): the first sample that moved. The pre-fix | |
| 43364 | + // square gather read 147 here, ffmpeg 146. | |
| 43365 | + const FIRST_WRONG_V: usize = 190 * 64 + 36; | |
| 43366 | + const F2_V_AT_FIRST_WRONG: u16 = 146; | |
| 43367 | + let _gate_lock = lock_gate_counters(); | |
| 43368 | + let stream = read_pinned_muchunk_fixture(FILE, LEN, FNV, NAME); | |
| 43369 | + assert_eq!( | |
| 43370 | + obu_stream_shape(&stream), | |
| 43371 | + Some((true, 1, 0, false)), | |
| 43372 | + "{NAME}: {FILE} is not a 4:2:2 (ss 1/0, non-mono) 128-superblock stream" | |
| 43373 | + ); | |
| 43374 | + let before = ( | |
| 43375 | + crate::decode::mu_chunk_compound_units(), | |
| 43376 | + crate::decode::mu_chunk_intra_in_inter_units(), | |
| 43377 | + ); | |
| 43378 | + let shown = crate::stream::decode_stream(&stream) | |
| 43379 | + .unwrap_or_else(|e| panic!("{NAME}: {FILE} no longer decodes cleanly: {e}")); | |
| 43380 | + let frames = shown.len(); | |
| 43381 | + let (compound, intra) = ( | |
| 43382 | + crate::decode::mu_chunk_compound_units() - before.0, | |
| 43383 | + crate::decode::mu_chunk_intra_in_inter_units() - before.1, | |
| 43384 | + ); | |
| 43385 | + assert_eq!(frames, SHOWN, "{NAME}: {FILE} shown-frame count"); | |
| 43386 | + assert!( | |
| 43387 | + intra >= MIN_UNITS, | |
| 43388 | + "{NAME}: {FILE} allocated only {intra} intra-in-inter `side > 64` mu-chunk units \ | |
| 43389 | + (expected >= {MIN_UNITS}) -- the site counter this gate names did not move" | |
| 43390 | + ); | |
| 43391 | + assert_eq!( | |
| 43392 | + compound, 0, | |
| 43393 | + "{NAME}: {FILE} also ran the compound walk ({compound} units) -- the two cells are \ | |
| 43394 | + no longer separated" | |
| 43395 | + ); | |
| 43396 | + // (b) the oracle-free half: the V plane of the first intrinsically | |
| 43397 | + // wrong frame, sample-for-sample, plus the one sample the pre-fix | |
| 43398 | + // gather got wrong. | |
| 43399 | + assert_eq!( | |
| 43400 | + shown[2].v.len(), | |
| 43401 | + 64 * 256, | |
| 43402 | + "{NAME}: {FILE} is no longer 4:2:2 at 128x256 -- the V plane shape moved" | |
| 43403 | + ); | |
| 43404 | + assert_eq!( | |
| 43405 | + shown[2].v[FIRST_WRONG_V], F2_V_AT_FIRST_WRONG, | |
| 43406 | + "{NAME}: {FILE} shown frame 2 V[{FIRST_WRONG_V}] (chroma (190, 36)) is {} -- the \ | |
| 43407 | + pre-fix square gather read 147 here", | |
| 43408 | + shown[2].v[FIRST_WRONG_V] | |
| 43409 | + ); | |
| 43410 | + assert_eq!( | |
| 43411 | + fnv1a64(&shown[2].v.iter().map(|&s| s as u8).collect::<Vec<u8>>()), | |
| 43412 | + F2_V_FNV, | |
| 43413 | + "{NAME}: {FILE} shown frame 2's V plane moved -- the intra-in-inter mu-chunk walk's \ | |
| 43414 | + 4:2:2 chroma context gather is wrong again (first sample to move is chroma (190, \ | |
| 43415 | + 36), index {FIRST_WRONG_V})" | |
| 43416 | + ); | |
| 43417 | + // (c) the required ffmpeg compare: every plane of every shown frame. | |
| 43418 | + if !have_ffmpeg() { | |
| 43419 | + eprintln!( | |
| 43420 | + "SKIP {NAME}: no ffmpeg -- the 4:2:2 pixel compare this gate exists for did NOT \ | |
| 43421 | + run (set EC_AV1_REQUIRE_FFMPEG=1 to make this a failure)" | |
| 43422 | + ); | |
| 43423 | + return; | |
| 43424 | + } | |
| 43425 | + let ff = ffmpeg_decode_sequence_422(&stream, 128, 256, SHOWN); | |
| 43426 | + assert_eq!(ff.len(), SHOWN, "{NAME}: {FILE} ffmpeg shown-frame count"); | |
| 43427 | + for (i, (got, want)) in shown.iter().zip(&ff).enumerate() { | |
| 43428 | + assert_eq!( | |
| 43429 | + got.y, want.y, | |
| 43430 | + "{NAME}: {FILE} shown frame {i} luma vs ffmpeg" | |
| 43431 | + ); | |
| 43432 | + assert_eq!(got.u, want.u, "{NAME}: {FILE} shown frame {i} U vs ffmpeg"); | |
| 43433 | + assert_eq!(got.v, want.v, "{NAME}: {FILE} shown frame {i} V vs ffmpeg"); | |
| 43434 | + } | |
| 43435 | + if aomdec_available(NAME) { | |
| 43436 | + let (decoded, hidden) = decode_all_frames_vs_oracle(&stream, NAME); | |
| 43437 | + assert_eq!( | |
| 43438 | + decoded, | |
| 43439 | + SHOWN + 1, | |
| 43440 | + "{NAME}: {FILE} decode-order frame count" | |
| 43441 | + ); | |
| 43442 | + eprintln!( | |
| 43443 | + "{NAME}: {FILE} byte-exact vs ffmpeg over {SHOWN} shown frames and vs the \ | |
| 43444 | + decode-order oracle over {decoded} frame(s) ({hidden} hidden), \ | |
| 43445 | + intra_in_inter_units={intra}" | |
| 43446 | + ); | |
| 43447 | + } else { | |
| 43448 | + eprintln!( | |
| 43449 | + "{NAME}: {FILE} byte-exact vs ffmpeg over {SHOWN} shown frames, \ | |
| 43450 | + intra_in_inter_units={intra} -- the decode-order oracle compare above did NOT \ | |
| 43451 | + run (no aomdec)" | |
| 43452 | + ); | |
| 43453 | + } | |
| 43454 | + } | |
| 43455 | + | |
| 43325 | 43456 | /// lane-sbpart r2: a real `aomenc` stream whose superblock-level |
| 43326 | 43457 | /// partition decision is genuinely HORZ/VERT (not NONE/SPLIT) must |
| 43327 | 43458 | /// decode pixel-exact through [`crate::decode::decode_block_rect64`] -- |
lanes/av1muchunk422iis.report.mdadded+155 -0
| @@ -0,0 +1,155 @@ | ||
| 1 | +# lane-av1muchunk422iis — the intra-in-inter mu-chunk chroma gather at 4:2:2 | |
| 2 | + | |
| 3 | +Base: `main` @ `bba9767d`. Branch: `lane/av1muchunk422iis`. Local only. | |
| 4 | + | |
| 5 | +**Verdict: closed.** The intra-in-inter `side > 64` mu-chunk walk | |
| 6 | +(`decode.rs:46820`) gathered its per-unit CHROMA coefficient context with the | |
| 7 | +plain luma `around_mi`, which at ss (1, 0) sums `unit_luma_w / MI` above cells | |
| 8 | +where libaom sums `txb_w_unit` — twice as many — so `dc_sign_ctx`'s signum | |
| 9 | +flipped whenever the doubled above vote cancelled the left one. Routed through | |
| 10 | +`around_mi_422_chroma` with the unit's PER-AXIS luma footprint | |
| 11 | +(`unit_luma_w`, `unit_luma_h`) exactly as the compound twin already was, the | |
| 12 | +hunted stream `i5_grad256_iis.obu` is now **byte-exact against ffmpeg over all | |
| 13 | +6 shown frames, every plane**, and byte-exact against the decode-order oracle | |
| 14 | +over all 7 frames (6 shown + 1 hidden alt-ref). Restoring the square gather reds | |
| 15 | +the new gate on the exact sample the class report named. | |
| 16 | + | |
| 17 | +## 1. The change | |
| 18 | + | |
| 19 | +One site, `crates/ec-av1/src/decode.rs` in the intra-in-inter `side > 64` | |
| 20 | +mu-chunk unit loop: | |
| 21 | + | |
| 22 | +```rust | |
| 23 | +let cu_around = if ss_x(fctx) == 1 && ss_y(fctx) == 0 { | |
| 24 | + neighbours.around_mi_422_chroma(unit_mi, unit_luma_w, unit_luma_h) | |
| 25 | +} else { | |
| 26 | + neighbours.around_mi(unit_mi, unit_luma_w) | |
| 27 | +}; | |
| 28 | +``` | |
| 29 | + | |
| 30 | +The condition is the same ss (1, 0) gate the eight sibling chroma gathers use | |
| 31 | +(`decode.rs:15441, 18268, 23924, 24282, 24956, 43980, 45810`). At ss (1, 0) | |
| 32 | +`unit_luma_w = cu_tx << 1 = 64` and `unit_luma_h = cu_tx << 0 = 32`, so | |
| 33 | +`around_mi_422_chroma` samples every second above cell (libaom's | |
| 34 | +`txb_w_unit`-cell sum) and takes the full `unit_luma_h` left extent | |
| 35 | +(unsubsampled at ss_y 0). At 4:2:0 (ss 1,1) and 4:4:4 (ss 0,0) the two luma | |
| 36 | +extents are equal, so the `else` branch is the previous call verbatim — the | |
| 37 | +440/444 arms are unchanged text on an untaken path. | |
| 38 | + | |
| 39 | +Not touched: the compound walk, c3, c4. | |
| 40 | + | |
| 41 | +## 2. The pinned stream | |
| 42 | + | |
| 43 | +`crates/ec-av1/fixtures/422_muchunk_intra_in_inter_128x256.obu` | |
| 44 | + | |
| 45 | +| | | | |
| 46 | +|---|---| | |
| 47 | +| sha256 | `64794f278eee738dcc59d90dc0c7c4ef2828c5b7c13724760a33be11f224908e` | | |
| 48 | +| bytes | 667 | | |
| 49 | +| fnv1a64 | `0x2bee_eba3_052b_f9a3` | | |
| 50 | +| source | `~/.cache/av1muchunk422b/i5_grad256_iis.obu` (the hunt's file; NOT re-encoded) | | |
| 51 | +| shape | `(use_128x128_superblock, ss_x, ss_y, mono) = (true, 1, 0, false)` | | |
| 52 | +| frames | 6 shown + 1 hidden alt-ref (decode order 7) | | |
| 53 | + | |
| 54 | +Recipe (same aomenc argv as the 128x128 twin `422_muchunk_intra_in_inter_128root.obu`, | |
| 55 | +different source): | |
| 56 | + | |
| 57 | +```text | |
| 58 | +ffmpeg -v error -f lavfi -i "gradients=size=128x256:c0=0xa1128f:c1=0xd98c48:\ | |
| 59 | + c2=0x120601:c3=0x4abfba:seed=63:duration=0.24:rate=25,\ | |
| 60 | + noise=all_seed=63:alls=6:allf=t" -t 0.24 -pix_fmt yuv422p \ | |
| 61 | + -f yuv4mpegpipe - > grad256.y4m | |
| 62 | +aomenc --codec=av1 --profile=2 --input-chroma-subsampling-x=1 \ | |
| 63 | + --input-chroma-subsampling-y=0 --passes=1 --end-usage=q --cq-level=62 \ | |
| 64 | + --cpu-used=0 --threads=1 --row-mt=0 --sb-size=128 \ | |
| 65 | + --min-partition-size=128 --max-partition-size=128 \ | |
| 66 | + --enable-rect-partitions=0 --enable-ab-partitions=0 \ | |
| 67 | + --enable-1to4-partitions=0 --enable-palette=0 --enable-intrabc=0 \ | |
| 68 | + --deltaq-mode=0 --enable-tx-size-search=0 --enable-interintra-comp=1 \ | |
| 69 | + --enable-interintra-wedge=1 --enable-smooth-interintra=1 --obu -o X | |
| 70 | +``` | |
| 71 | + | |
| 72 | +## 3. Measurement — per-frame, per-plane vs ffmpeg | |
| 73 | + | |
| 74 | +`ffmpeg -v error -i X.obu -pix_fmt yuv422p -f rawvideo` vs | |
| 75 | +`dump_yuv X.obu <out>`, differing samples per shown frame (Y / U / V): | |
| 76 | + | |
| 77 | +| stream | f0 | f1 | f2 | f3 | f4 | f5 | | |
| 78 | +|---|---|---|---|---|---|---| | |
| 79 | +| **pre-fix** (square gather) | 0 | 0 | V **2105** | 0 | V 1982 | Y 24155 U 12162 V 12091 | | |
| 80 | +| **post-fix** | 0 | 0 | 0 | 0 | 0 | 0 | | |
| 81 | + | |
| 82 | +Pre-fix first wrong sample: V (row 190, col 36) of shown frame 2 (V index | |
| 83 | +`190 * 64 + 36 = 12196`), **ours 147 vs ffmpeg 146**. Post-fix that sample reads | |
| 84 | +146 and shown frame 2's whole V plane hashes | |
| 85 | +`fnv1a64 = 0xa7ba_8711_9d13_8fe5`, equal to ffmpeg's own bytes. | |
| 86 | + | |
| 87 | +(The class report's prose wrote the pair as "ours 146 vs ffmpeg 147"; the | |
| 88 | +measured pair on this host is ours-147/ffmpeg-146 pre-fix. Same location, same | |
| 89 | +one-sample disagreement, mirrored wording.) | |
| 90 | + | |
| 91 | +## 4. The gate | |
| 92 | + | |
| 93 | +`crates/ec-av1/src/stream.rs` | |
| 94 | +`a_422_muchunk_intra_in_inter_128x256_stream_is_exact_and_reaches_its_unit_walk`: | |
| 95 | + | |
| 96 | +1. **Counter witness** — `mu_chunk_intra_in_inter_units()` delta `96 >= 96` | |
| 97 | + (the walk ran), `mu_chunk_compound_units()` delta `0` (this stream never | |
| 98 | + enters the compound arm). | |
| 99 | +2. **Oracle-free pin** — shown frame 2 V plane length `64 * 256`, sample | |
| 100 | + `V[12196] == 146`, whole-V-plane fnv `0xa7ba_8711_9d13_8fe5`. Cannot | |
| 101 | + silently skip. | |
| 102 | +3. **Required ffmpeg compare** — every plane of every shown frame equal to | |
| 103 | + `ffmpeg_decode_sequence_422` (hard-fails under `EC_AV1_REQUIRE_FFMPEG`; | |
| 104 | + prints a loud SKIP-note otherwise). | |
| 105 | +4. **Decode-order oracle compare** — `decode_all_frames_vs_oracle` when aomdec | |
| 106 | + is present (7 frames). | |
| 107 | + | |
| 108 | +### Red-before-green | |
| 109 | + | |
| 110 | +Restoring the call to `neighbours.around_mi(unit_mi, unit_luma_w)` reds exactly | |
| 111 | +the pin: | |
| 112 | + | |
| 113 | +``` | |
| 114 | +panicked at stream.rs:43404: | |
| 115 | + ... shown frame 2 V[12196] (chroma (190, 36)) is 147 -- the pre-fix square gather read 147 here | |
| 116 | + left: 147 right: 146 | |
| 117 | +``` | |
| 118 | + | |
| 119 | +Green after the fix (all three mu-chunk gates + the 4:4:4 twin): | |
| 120 | + | |
| 121 | +``` | |
| 122 | +a_422_muchunk_compound_128root_pinned_stream_reaches_its_unit_walk ... ok (compound_units=32, intra=0) | |
| 123 | +a_422_muchunk_intra_in_inter_128root_pinned_stream_is_exact_and_reaches_its_unit_walk ... ok | |
| 124 | +a_422_muchunk_intra_in_inter_128x256_stream_is_exact_and_reaches_its_unit_walk ... ok (intra_in_inter_units=96) | |
| 125 | +a_444_intra_in_inter_128root_muchroma_pinned_stream_decodes_pixel_exact ... ok | |
| 126 | +``` | |
| 127 | + | |
| 128 | +## 5. Repro | |
| 129 | + | |
| 130 | +``` | |
| 131 | +git worktree add -b lane/av1muchunk422iis ~/.cache/wt/av1muchunk422iis origin/main # bba9767d | |
| 132 | +cd ~/.cache/wt/av1muchunk422iis | |
| 133 | +export CARGO_TARGET_DIR=$HOME/.cache/tgt-av1muchunk422iis TMPDIR=$HOME/.cache/tmp | |
| 134 | +export EC_AV1_REQUIRE_FFMPEG=1 EC_AV1_AOMDEC=$HOME/.cache/aom-oracle/build/aomdec | |
| 135 | +cargo test -p ec-av1 --lib muchunk -- --nocapture | |
| 136 | +``` | |
| 137 | + | |
| 138 | +Raw ffmpeg compare (outputs under `$HOME`, never `/tmp` — this host's `/tmp` is | |
| 139 | +over quota): | |
| 140 | + | |
| 141 | +``` | |
| 142 | +S=crates/ec-av1/fixtures/422_muchunk_intra_in_inter_128x256.obu | |
| 143 | +ffmpeg -v error -y -i $S -pix_fmt yuv422p -f rawvideo $HOME/.cache/tmp/i5.ref.yuv | |
| 144 | +$CARGO_TARGET_DIR/debug/examples/dump_yuv $S $HOME/.cache/tmp/i5.ours.yuv | |
| 145 | +# per-frame 65536-byte planes: Y 32768, U 16384, V 16384 | |
| 146 | +``` | |
| 147 | + | |
| 148 | +## 6. Not claimed | |
| 149 | + | |
| 150 | +- The class is not declared closed beyond this walk: c3/c4 remain diverging and | |
| 151 | + were not touched. This lane fixes and pins the intra-in-inter `side > 64` | |
| 152 | + mu-chunk gather only. | |
| 153 | +- Nothing about 4:2:0 or 4:4:4 was changed; their identity is structural (the | |
| 154 | + `else` branch is the old call on an untaken path) and spot-checked on the | |
| 155 | + 4:4:4 twin above. |