lane-av1-llinter2: port 13a262a6, firing gate for the 444 lossless inter fix
Browse files at this commit66a6553369a1898fbe7d962a2ef0e4faf6d48748Parent: 988e5283 changed files +253 -0
- crates/ec-av1/fixtures/ll444_minp64_inter.obu +0 -0
- crates/ec-av1/src/stream.rs +152 -0
- lanes/av1llinter2.report.md +101 -0
crates/ec-av1/fixtures/ll444_minp64_inter.obuadded+0 -0
Binary file changed
crates/ec-av1/src/stream.rsmodified+152 -0
| @@ -5476,6 +5476,158 @@ pub(crate) mod tests { | |||
| 5476 | } | 5476 | } |
| 5477 | } | 5477 | } |
| 5478 | 5478 | ||
| 5479 | + /// As [`ffmpeg_decode_sequence`], for a 4:4:4 stream: chroma planes are | ||
| 5480 | + /// FULL resolution (`yuv444p` rawvideo), the shape lane-av1-llinter's | ||
| 5481 | + /// lossless profile-1 fixture codes. | ||
| 5482 | + fn ffmpeg_decode_sequence_444( | ||
| 5483 | + stream: &[u8], | ||
| 5484 | + width: usize, | ||
| 5485 | + height: usize, | ||
| 5486 | + frames: usize, | ||
| 5487 | + ) -> Vec<Pic> { | ||
| 5488 | + let out = run_with_stdin( | ||
| 5489 | + Command::new("ffmpeg").args([ | ||
| 5490 | + "-v", "error", "-f", "obu", "-i", "-", "-f", "rawvideo", "-pix_fmt", "yuv444p", "-", | ||
| 5491 | + ]), | ||
| 5492 | + stream, | ||
| 5493 | + ); | ||
| 5494 | + assert!( | ||
| 5495 | + out.status.success(), | ||
| 5496 | + "ffmpeg refused the 4:4:4 stream: {}", | ||
| 5497 | + String::from_utf8_lossy(&out.stderr) | ||
| 5498 | + ); | ||
| 5499 | + let plane = width * height; | ||
| 5500 | + let frame_bytes = 3 * plane; | ||
| 5501 | + assert_eq!( | ||
| 5502 | + out.stdout.len(), | ||
| 5503 | + frame_bytes * frames, | ||
| 5504 | + "expected {frames} 4:4:4 frames, ffmpeg said: {}", | ||
| 5505 | + String::from_utf8_lossy(&out.stderr) | ||
| 5506 | + ); | ||
| 5507 | + (0..frames) | ||
| 5508 | + .map(|i| { | ||
| 5509 | + let base = i * frame_bytes; | ||
| 5510 | + Pic { | ||
| 5511 | + width, | ||
| 5512 | + height, | ||
| 5513 | + y: out.stdout[base..base + plane].iter().map(|&v| u16::from(v)).collect(), | ||
| 5514 | + u: out.stdout[base + plane..base + 2 * plane].iter().map(|&v| u16::from(v)).collect(), | ||
| 5515 | + v: out.stdout[base + 2 * plane..base + 3 * plane].iter().map(|&v| u16::from(v)).collect(), | ||
| 5516 | + } | ||
| 5517 | + }) | ||
| 5518 | + .collect() | ||
| 5519 | + } | ||
| 5520 | + | ||
| 5521 | + /// lane-av1-llinter: the firing gate for the lossless 4:4:4 INTER chroma | ||
| 5522 | + /// fix. The fixture is the report's dodge2 stream pinned into `fixtures/`: | ||
| 5523 | + /// aomenc profile 1 over testsrc2 128x96 yuv444p, `--lossless=1`, | ||
| 5524 | + /// `--sb-size=64 --min-partition-size=64 --max-partition-size=64`, 6 | ||
| 5525 | + /// frames; 37658 bytes, sha256 | ||
| 5526 | + /// `5a070fa351a3f2109de855234f2b3d0a872970f3e7f658db21f65c12eeb135b4`. | ||
| 5527 | + /// The firing counter is the EXISTING `decode::chroma_split_tx_hits` (one | ||
| 5528 | + /// bump per lossless chroma TX unit read): with min=max partition 64 the | ||
| 5529 | + /// roots stay whole 64x64 inter blocks -- no 8x8 leaf exists in this | ||
| 5530 | + /// stream -- so every chroma unit goes through the big-block ss-aware | ||
| 5531 | + /// lossless route this lane fixed (fixes 2-5). A 4:2:0 lossless stream | ||
| 5532 | + /// fires the same counter, but the fixture bytes are pinned, so the gate | ||
| 5533 | + /// cannot run on anything else; the pre-fix 4:2:0-hardcoded math corrupts | ||
| 5534 | + /// at 4:4:4, so the pixel-exact compares are what prove the ss-aware path | ||
| 5535 | + /// (class `gate-blind-to-feature`). Every frame must come out pixel-exact | ||
| 5536 | + /// through BOTH the oracle `aomdec --rawvideo` and ffmpeg. The | ||
| 5537 | + /// default-partition ll444 stream is deliberately NOT claimed here: its | ||
| 5538 | + /// key frame is still the intra lane's named sub8-chroma stop | ||
| 5539 | + /// (lanes/av1llintra.report.md). | ||
| 5540 | + #[test] | ||
| 5541 | + fn a_lossless_444_min_partition64_inter_stream_decodes_pixel_exact() { | ||
| 5542 | + const NAME: &str = "a_lossless_444_min_partition64_inter_stream_decodes_pixel_exact"; | ||
| 5543 | + const FIXTURE_LEN: usize = 37658; | ||
| 5544 | + const FIXTURE_FNV: u64 = 0xf68d_c26f_a14d_283c; | ||
| 5545 | + const W: usize = 128; | ||
| 5546 | + const H: usize = 96; | ||
| 5547 | + const FRAMES: usize = 6; | ||
| 5548 | + let obu = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR")) | ||
| 5549 | + .join("fixtures/ll444_minp64_inter.obu"); | ||
| 5550 | + let stream = std::fs::read(&obu).unwrap_or_else(|e| { | ||
| 5551 | + panic!( | ||
| 5552 | + "{NAME}: pinned fixture {} is missing ({e}) -- the gate cannot run, \ | ||
| 5553 | + which is a failure, not a skip", | ||
| 5554 | + obu.display() | ||
| 5555 | + ) | ||
| 5556 | + }); | ||
| 5557 | + assert_eq!(stream.len(), FIXTURE_LEN, "{NAME}: fixture length moved"); | ||
| 5558 | + assert_eq!(fnv1a64(&stream), FIXTURE_FNV, "{NAME}: fixture bytes moved"); | ||
| 5559 | + | ||
| 5560 | + let _guard = lock_gate_counters(); | ||
| 5561 | + let before = crate::decode::chroma_split_tx_hits(); | ||
| 5562 | + let frames = decode_stream(&stream).unwrap_or_else(|e| { | ||
| 5563 | + panic!("{NAME}: the pinned stream no longer decodes cleanly: {e}") | ||
| 5564 | + }); | ||
| 5565 | + let hits = crate::decode::chroma_split_tx_hits(); | ||
| 5566 | + assert!( | ||
| 5567 | + hits > before, | ||
| 5568 | + "{NAME}: gate is vacuous -- no lossless chroma TX unit was read \ | ||
| 5569 | + (delta {before} -> {hits})" | ||
| 5570 | + ); | ||
| 5571 | + assert_eq!(frames.len(), FRAMES, "{NAME}: frame count"); | ||
| 5572 | + for f in &frames { | ||
| 5573 | + assert_eq!((f.width, f.height), (W, H), "{NAME}: dimensions"); | ||
| 5574 | + } | ||
| 5575 | + | ||
| 5576 | + // The oracle aomdec, rawvideo out: FRAMES concatenated yuv444p frames. | ||
| 5577 | + if aomdec_path().is_file() { | ||
| 5578 | + let dir = std::env::temp_dir().join(format!("ec-av1-ll444-{}", std::process::id())); | ||
| 5579 | + let _ = std::fs::remove_dir_all(&dir); | ||
| 5580 | + std::fs::create_dir_all(&dir).expect("scratch dir"); | ||
| 5581 | + let raw = dir.join("aomdec.raw"); | ||
| 5582 | + let out = Command::new(aomdec_path()) | ||
| 5583 | + .args(["--codec=av1", "--rawvideo", "-o"]) | ||
| 5584 | + .arg(&raw) | ||
| 5585 | + .arg(&obu) | ||
| 5586 | + .stdin(Stdio::null()) | ||
| 5587 | + .stdout(Stdio::piped()) | ||
| 5588 | + .stderr(Stdio::piped()) | ||
| 5589 | + .output() | ||
| 5590 | + .expect("aomdec failed to run"); | ||
| 5591 | + assert!( | ||
| 5592 | + out.status.success(), | ||
| 5593 | + "{NAME}: the oracle aomdec refused the stream: {}", | ||
| 5594 | + String::from_utf8_lossy(&out.stderr) | ||
| 5595 | + ); | ||
| 5596 | + let ref_raw = std::fs::read(&raw).expect("aomdec rawvideo output"); | ||
| 5597 | + let _ = std::fs::remove_dir_all(&dir); | ||
| 5598 | + assert_eq!(ref_raw.len(), W * H * 3 * FRAMES, "{NAME}: aomdec raw size"); | ||
| 5599 | + for (i, f) in frames.iter().enumerate() { | ||
| 5600 | + let base = i * W * H * 3; | ||
| 5601 | + for ((plane, off), p) in [(&f.y, 0usize), (&f.u, W * H), (&f.v, 2 * W * H)] | ||
| 5602 | + .into_iter() | ||
| 5603 | + .zip(["y", "u", "v"]) | ||
| 5604 | + { | ||
| 5605 | + let want = &ref_raw[base + off..base + off + W * H]; | ||
| 5606 | + let bad = plane.iter().zip(want).filter(|&(&a, &b)| a as u8 != b).count(); | ||
| 5607 | + assert_eq!(bad, 0, "{NAME}: aomdec frame {i} plane {p}: {bad} samples differ"); | ||
| 5608 | + } | ||
| 5609 | + } | ||
| 5610 | + } else { | ||
| 5611 | + eprintln!("SKIP {NAME} aomdec arm: no oracle aomdec at {}", aomdec_path().display()); | ||
| 5612 | + } | ||
| 5613 | + | ||
| 5614 | + // ffmpeg's decoder: same frames, full-resolution chroma. | ||
| 5615 | + if have_ffmpeg() { | ||
| 5616 | + let refs = ffmpeg_decode_sequence_444(&stream, W, H, FRAMES); | ||
| 5617 | + for (i, (got, want)) in frames.iter().zip(refs.iter()).enumerate() { | ||
| 5618 | + for (p, (g, r)) in [(&got.y, &want.y), (&got.u, &want.u), (&got.v, &want.v)] | ||
| 5619 | + .iter() | ||
| 5620 | + .enumerate() | ||
| 5621 | + { | ||
| 5622 | + let bad = g.iter().zip(r.iter()).filter(|(a, b)| a != b).count(); | ||
| 5623 | + assert_eq!(bad, 0, "{NAME}: ffmpeg frame {i} plane {p}: {bad} samples differ"); | ||
| 5624 | + } | ||
| 5625 | + } | ||
| 5626 | + } else { | ||
| 5627 | + eprintln!("SKIP {NAME} ffmpeg arm: no ffmpeg"); | ||
| 5628 | + } | ||
| 5629 | + } | ||
| 5630 | + | ||
| 5479 | /// lane-lossless128: a LOSSLESS key frame that codes a 128-axis | 5631 | /// lane-lossless128: a LOSSLESS key frame that codes a 128-axis |
| 5480 | /// (`BLOCK_64X128`) intra block -- the shape libaom's `read_tx_size` forces | 5632 | /// (`BLOCK_64X128`) intra block -- the shape libaom's `read_tx_size` forces |
| 5481 | /// to `TX_4X4` on its very first line (`decodeframe.c:1183`), so every plane | 5633 | /// to `TX_4X4` on its very first line (`decodeframe.c:1183`), so every plane |
lanes/av1llinter2.report.mdadded+101 -0
| @@ -0,0 +1,101 @@ | |||
| 1 | +# lane-av1-llinter2: 4:4:4 lossless inter side — sibling panic ported (r1) | ||
| 2 | + | ||
| 3 | +## Charter | ||
| 4 | + | ||
| 5 | +The lossless INTER panic named by `av1llband2` (`reconstruct_mc_rect`, | ||
| 6 | +decode.rs:2589, `read_inter_rect_chroma`'s branch) is the same panic | ||
| 7 | +sibling lane `av1llinter` fixed in 84acbd09 + 13a262a6. Port that fix; | ||
| 8 | +never author a second fix for the same defect. 4:2:0 lossless stays | ||
| 9 | +identical; the key-frame gate stays green. Work in | ||
| 10 | +`edith_codecs-av1llinter2` @ 6da581a8. | ||
| 11 | + | ||
| 12 | +## Same-panic proof (measured, before any edit) | ||
| 13 | + | ||
| 14 | +Repro on the sibling's pinned bytes `dodge2.obu` (37658 B, sha256 | ||
| 15 | +`5a070fa351a3f2109de855234f2b3d0a872970f3e7f658db21f65c12eeb135b4` — | ||
| 16 | +byte-identical to the sibling's committed | ||
| 17 | +`crates/ec-av1/fixtures/ll444_minp64_inter.obu`): | ||
| 18 | + | ||
| 19 | +- RELEASE build: `panicked at crates/ec-av1/src/decode.rs:28454:32: | ||
| 20 | + range end index 24 out of range for slice of length 16` in `exec_mc` — | ||
| 21 | + line 28454 is `reconstruct_mc_rect`'s coded-arm `dst..dst + w` index | ||
| 22 | + (fn at 28413), inlined into `exec_mc`. The sibling's parent-tree panic | ||
| 23 | + was the identical message and numbers at their decode.rs:28336, same | ||
| 24 | + fn, same inline frame. | ||
| 25 | +- DEBUG build: the underlying unit defect surfaces first — the lossless | ||
| 26 | + WHT assert `(8, 8) != (4, 4)` at `TxParams::run` (decode.rs:2566), via | ||
| 27 | + `decode_inter_block8 -> read_inter_plane -> push_mc_rect_tx` — the | ||
| 28 | + sibling report's exact chain. The band2 report's "decode.rs:2589" | ||
| 29 | + citation is this same worker (`strided[row * self.stride..][..self.w]`, | ||
| 30 | + the release-form panic of the same 8-wide lossless unit); the | ||
| 31 | + "reconstruct_mc_rect" name is the release-build site proven above. | ||
| 32 | + | ||
| 33 | +⇒ same defect, same root cause the sibling named: the 8x8 inter leaf's | ||
| 34 | +chroma plane block read as ONE TX_8X8 unit where lossless codes TX_4X4 | ||
| 35 | +on every plane (`av1_get_tx_size`). 84acbd09 IS the writer's fix. | ||
| 36 | +Ported it; no second fix invented. | ||
| 37 | + | ||
| 38 | +## Port (faithful cherry-pick of 84acbd09, three deliberate deltas) | ||
| 39 | + | ||
| 40 | +`git cherry-pick -n 84acbd09`: | ||
| 41 | + | ||
| 42 | +1. `decode_rect_split` conflicts (fix 4) resolved to THIS tree's version: | ||
| 43 | + lane-av1-llband2 already ported that exact fix (01a34bc8) with the | ||
| 44 | + `RECT_SPLIT_LOSSLESS_CHROMA444_HITS` non-vacuity counter; semantics | ||
| 45 | + identical (`4 << ss` spans, span-carrying `ll_chroma_units`). | ||
| 46 | +2. **fix 5 EXCLUDED**: its three hunks are inside | ||
| 47 | + `decode_rect4_16_strip` (the `cu_mi` divisor and both | ||
| 48 | + `record_mi_chroma` spans), a function owned by a live lane — reverted | ||
| 49 | + to HEAD byte-for-byte. The strip fn still carries the 4:2:0-hardcoded | ||
| 50 | + walk at 4:4:4 lossless: deferred(fix-now in the owning lane, same | ||
| 51 | + span derivation as fixes 2-4). | ||
| 52 | +3. The sibling's lane report file dropped; this lane writes its own. | ||
| 53 | + | ||
| 54 | +Applied verbatim: fix 1 (`decode_inter_block8`'s single-ref AND compound | ||
| 55 | +chroma arms route `chroma_side == 8 && lossless && !mono` through the | ||
| 56 | +new `leaf8_inter_chroma_lossless` helper wrapping the per-unit | ||
| 57 | +`read_inter_chroma_lossless` walk, with the tail `record_mi`'s chroma | ||
| 58 | +half saved/restored — `saved_chroma_ctx`, the `saved_luma_ctx` pattern; | ||
| 59 | +both `record_mi` tails patched), fix 2 (`read_inter_chroma_lossless`: | ||
| 60 | +`cu_mi` divisor `4 >> ss`, record spans `4 << ss`), fix 3 | ||
| 61 | +(`decode_inter_block`'s `mu_chroma_units` lossless replay: extents | ||
| 62 | +`>> ss`, mi-steps and spans `cu << ss`). All byte-identical at 4:2:0 | ||
| 63 | +(`4 << 1 = 8`). Off-limits files untouched: `decode_rect4_16_strip`, | ||
| 64 | +`restoration.rs`, intra write-back. Net diff vs HEAD: 9 hunks, earliest | ||
| 65 | +at decode.rs:28734 — nothing before `read_inter_chroma_lossless`. | ||
| 66 | + | ||
| 67 | +Gate port: `git cherry-pick -n 13a262a6` (fixture | ||
| 68 | +`fixtures/ll444_minp64_inter.obu` 37658 B, the `ffmpeg_decode_sequence_444` | ||
| 69 | +helper, gate `a_lossless_444_min_partition64_inter_stream_decodes_pixel_exact` | ||
| 70 | +with the `chroma_split_tx_hits` non-vacuity assert and FNV/len pins). | ||
| 71 | +stream.rs conflict = both lanes appended tests at the same spot; resolved | ||
| 72 | +by keeping BOTH (band2's key-frame gate first, then the helper + inter | ||
| 73 | +gate). | ||
| 74 | + | ||
| 75 | +## Verification (measured, this tree @ HEAD+2) | ||
| 76 | + | ||
| 77 | +- `a_lossless_444_min_partition64_inter_stream_decodes_pixel_exact`: | ||
| 78 | + **PASS** — all 6 dodge2 frames pixel-exact through BOTH the oracle | ||
| 79 | + `aomdec --rawvideo` (oracle at `~/.cache/aom-oracle/build`, arm | ||
| 80 | + executed, not skipped) and ffmpeg `yuv444p`; counter moved (non-vacuity). | ||
| 81 | +- Key-frame gate stays green: `a_real_aomenc_lossless_444_key_frame_ | ||
| 82 | + decodes_sample_exact` PASS. | ||
| 83 | +- 4:2:0 unchanged: `a_lossless_libaom_key_frame_decodes_sample_exact`, | ||
| 84 | + `a_lossless_libaom_inter_frame_decodes_sample_exact` — both PASS | ||
| 85 | + (4 passed, 0 failed in the battery run). | ||
| 86 | +- `decode_probe dodge2.obu`: `OK: 6 frames decoded`, no panic, debug AND | ||
| 87 | + release. | ||
| 88 | +- `cargo check -p ec-av1 --all-targets`: 0 warnings, 0 errors. | ||
| 89 | + | ||
| 90 | +## Same-class suspects, deferred (spoken, not hidden) | ||
| 91 | + | ||
| 92 | +- `decode_rect4_16_strip`'s lossless chroma walk still hardcodes the | ||
| 93 | + 4:2:0 span (`oy / 2`, `record_mi_chroma(.., 8, 8, ..)` at decode.rs | ||
| 94 | + ~14631/14653/14675): excluded per lane ownership. | ||
| 95 | + deferred(fix-now in the owning lane; shape = fixes 2-4's `4 << ss`). | ||
| 96 | +- Default-partition `ll444.obu` no longer panics but stops at a NAMED | ||
| 97 | + non-panic gap: `EC_RECTCHROMA_GAP luma=64x32 tx=4x4 chroma=64x32` | ||
| 98 | + (decode.rs:10126 — the `(64, 32)` chroma plane block has no TxbSet row | ||
| 99 | + at the rect64 lossless route). The sibling's gate deliberately does not | ||
| 100 | + claim this stream either. deferred(fix-now in a lane chartering the | ||
| 101 | + rect64 chroma lossless route; distinct defect, not this panic). | ||