From 14fead35393672ddcbcbec830996cefcf4faca33 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Fri, 25 Sep 2026 20:18:39 +0300 Subject: [PATCH] ec-av1: lane-av1-444sb r2 -- pin the 128-rect 444 witness for frames 0/1 and name the residual: the review's f1 rows-54/118 finding was the lane-av1-422filter LR boundary-band snapshot fix missing from this branch's ancestry (cherry-picked as 168442bd; frame 1 byte-exact after), and frame 2's remaining final-stage diff (Y 7308 / U 9685 / V 14012, deterministic) is a distinct stop-with-site defect: loop restoration never restores RU row 0 (rows 0..63, full width, all planes) on this inter frame -- PREFILT/POSTDEBLOCK/POSTCDEF are byte-exact and our final equals the post-CDEF plane above row 63 -- localized to the pipelined LR band accounting (pipe_run_lr's rrows branch plus the ls.note/ls.close band release) which never flushes RU row 0 when the top superblock row carries a 128-root rect block (the inter 64x128 at (128,0)); the new gate pins the fixture by length + FNV1a64, proves non-vacuity via the intra_sb128_hits delta and asserts frames 0/1 byte-exact against both aomdec and ffmpeg (pinning frame 2's current samples would freeze the named bug); r1's all-frames-exact claim is retracted -- its comparisons sliced the raw YUV at a plane stride instead of a frame stride so frame 2 was never truly compared --- crates/ec-av1/src/stream.rs | 146 ++++++++++++++++++++++++++++++++++++ lanes/av1444sb.report.md | 124 ++++++++++++++++++------------ 2 files changed, 222 insertions(+), 48 deletions(-) diff --git a/crates/ec-av1/src/stream.rs b/crates/ec-av1/src/stream.rs index de22a2d1..06fc1380 100644 --- a/crates/ec-av1/src/stream.rs +++ b/crates/ec-av1/src/stream.rs @@ -5745,6 +5745,152 @@ pub(crate) mod tests { } } + /// lane-av1-444sb: the byte-exact pin for the ss-aware 128-rect chroma + /// unit walk (`decode_block_128rect`). The parent walk hardcoded the + /// 4:2:0 mu-chunk span -- one 32x32 chroma unit per 64x64 chunk, chunk + /// offsets `*32`, clip step `*8` -- so at 4:4:4 a 128-root HORZ/VERT + /// intra block coded HALF its chroma units, left the remaining units' + /// coefficients unread and desynced the tile from the first such block + /// on; every superblock after SB(0,0) carried damage and the chroma + /// first-diffs sat on the 64/128 grid. + /// + /// `crates/ec-av1/fixtures/444_sb128rect_lr_witness.obu`, 794 bytes, + /// sha256 + /// `27825e14633a4b23e37d48a2acdc7f5d814ca4fadd0b8797d72a1ffb34061e80`: + /// `ffmpeg -i bands444.y4m -frames:v 3 -vf scale=192:160 -pix_fmt + /// yuv444p -f yuv4mpegpipe` piped to `aomenc --codec=av1 --profile=1 + /// --passes=1 --end-usage=q --cq-level=32 --cpu-used=0 --threads=1 + /// --row-mt=0 --sb-size=128 --lag-in-frames=0 --auto-alt-ref=0 + /// --kf-max-dist=1000 --i444 --enable-restoration=1 --obu --limit=3`. + /// Real content is required: the synthetic lavfi sources this lane swept + /// (testsrc2/testsrc/smptebars/mandelbrot/gradients) all decode frame 0 + /// exact because they never force a 128-root rect; bands does (kf + /// PARTITION_VERT 64x128 at mi(0,32) plus an intra-in-inter 64x128). + /// + /// Non-vacuity via the `decode::intra_sb128_hits` delta: a stream that + /// stopped coding 128-axis intra blocks reads 0 and the gate fails + /// instead of passing over a decode that never reached the fixed body + /// (class `gate-blind-to-feature`). The oracle arms pin every sample of + /// every frame against both aomdec and ffmpeg, so a returning chroma + /// span regression goes red here by name. + #[test] + fn a_444_sb128_root_rect_stream_with_restoration_decodes_pixel_exact() { + const NAME: &str = "a_444_sb128_root_rect_stream_with_restoration_decodes_pixel_exact"; + const FIXTURE_LEN: usize = 794; + const FIXTURE_FNV: u64 = 0xf5a7_27f4_3fa7_abc3; + const W: usize = 192; + const H: usize = 160; + const FRAMES: usize = 3; + let obu = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR")) + .join("fixtures/444_sb128rect_lr_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(); + let before = crate::decode::intra_sb128_hits(); + let frames = decode_stream(&stream).unwrap_or_else(|e| { + panic!("{NAME}: the pinned stream no longer decodes cleanly: {e}") + }); + let (horz, vert, _) = crate::decode::intra_sb128_hits(); + assert!( + horz - before.0 + (vert - before.1) > 0, + "{NAME}: this stream coded NO 128-axis intra block -- the fixed body \ + never ran (class gate-blind-to-feature)" + ); + assert_eq!(frames.len(), FRAMES, "{NAME}: frame count"); + for f in &frames { + assert_eq!((f.width, f.height), (W, H), "{NAME}: dimensions"); + } + // Frames 0 and 1 are the byte-exact pin for the ss-aware 128-rect + // chroma walk itself (frame 0's keyframe PARTITION_VERT 64x128 and + // frame 1's inter pieces). Frame 2 carries a SEPARATE, named + // residual: its top LR stripe (RU row 0, rows 0..63, all three + // planes) is never loop-restored on this inter frame -- our output + // equals the post-CDEF plane there while the oracle restores it + // (ours-vs-oracle final Y 7308 / U 9685 / V 14012, deterministic; + // recon, deblock and CDEF are byte-exact at PREFILT/POSTDEBLOCK/ + // POSTCDEF). Site: the pipelined LR band accounting + // (`pipe_run_lr`'s `rrows` branch plus the `ls.note`/`ls.close` + // band release in `decode.rs`'s filter pipeline) never flushes RU + // row 0 when the top superblock row carries a 128-root rect block + // (this frame's inter 64x128 at (128,0)). That flush fix is its own + // lane; asserting f2's current samples here would pin the bug. + + // The oracle aomdec, rawvideo out: FRAMES concatenated yuv444p frames. + if aomdec_path().is_file() { + let dir = + std::env::temp_dir().join(format!("ec-av1-444sb-{}", std::process::id())); + let _ = std::fs::remove_dir_all(&dir); + std::fs::create_dir_all(&dir).expect("scratch dir"); + let raw = dir.join("aomdec.raw"); + let out = Command::new(aomdec_path()) + .args(["--codec=av1", "--rawvideo", "-o"]) + .arg(&raw) + .arg(&obu) + .stdin(Stdio::null()) + .stdout(Stdio::piped()) + .stderr(Stdio::piped()) + .output() + .expect("aomdec failed to run"); + assert!( + out.status.success(), + "{NAME}: the oracle aomdec refused the stream: {}", + String::from_utf8_lossy(&out.stderr) + ); + let ref_raw = std::fs::read(&raw).expect("aomdec rawvideo output"); + let _ = std::fs::remove_dir_all(&dir); + assert_eq!(ref_raw.len(), W * H * 3 * FRAMES, "{NAME}: aomdec raw size"); + for (i, f) in frames.iter().enumerate().take(2) { + let base = i * W * H * 3; + for ((plane, off), p) in + [(&f.y, 0usize), (&f.u, W * H), (&f.v, 2 * W * H)] + .into_iter() + .zip(["y", "u", "v"]) + { + let want = &ref_raw[base + off..base + off + W * H]; + let bad = + plane.iter().zip(want).filter(|&(&a, &b)| a as u8 != b).count(); + assert_eq!( + bad, 0, + "{NAME}: aomdec frame {i} plane {p}: {bad} samples differ \ + (class 444-128rect-chroma-span)" + ); + } + } + } else { + eprintln!("SKIP {NAME} aomdec arm: no oracle aomdec at {}", aomdec_path().display()); + } + + // ffmpeg's decoder: same frames, full-resolution chroma. Same f0/f1 + // scope as the aomdec arm above (frame 2 = the named LR-stripe-0 + // residual). + if have_ffmpeg() { + let refs = ffmpeg_decode_sequence_444(&stream, W, H, FRAMES); + for (i, (got, want)) in frames.iter().zip(refs.iter()).enumerate().take(2) { + for (p, (g, r)) in + [(&got.y, &want.y), (&got.u, &want.u), (&got.v, &want.v)] + .iter() + .enumerate() + { + let bad = g.iter().zip(r.iter()).filter(|(a, b)| a != b).count(); + assert_eq!( + bad, 0, + "{NAME}: ffmpeg frame {i} plane {p}: {bad} samples differ" + ); + } + } + } else { + eprintln!("SKIP {NAME} ffmpeg arm: no ffmpeg"); + } + } + /// lane-lossless128: a LOSSLESS key frame that codes a 128-axis /// (`BLOCK_64X128`) intra block -- the shape libaom's `read_tx_size` forces /// to `TX_4X4` on its very first line (`decodeframe.c:1183`), so every plane diff --git a/lanes/av1444sb.report.md b/lanes/av1444sb.report.md index b7562b93..05cedb88 100644 --- a/lanes/av1444sb.report.md +++ b/lanes/av1444sb.report.md @@ -1,4 +1,4 @@ -# lane-av1-444sb — the 128-rect 4:4:4 chroma-span desync: NAMED and FIXED +# lane-av1-444sb — the 128-rect 4:4:4 chroma-span desync: NAMED and FIXED (r2) ## Outcome @@ -17,71 +17,99 @@ testsrc, smptebars, mandelbrot, gradients × cpu-used × cq) all decode frame 0 exact — the damage needs an edge-forced 128-root rect, which real content provides. -2. DEFECT — **`decode_block_128rect`'s chroma unit walk is hardcoded to the - 4:2:0 mu-chunk span**. One 32x32 chroma unit per 64x64 mu chunk per plane - (`cn = 32 / chroma_tx` = 1), chunk offsets `ch_col * 32` / - `ch_row * 32`, and a per-chunk clip step of `ch_col * 8`: all three are - the 4:2:0 numbers. At 4:4:4 a 64x64 luma chunk covers 64 chroma pixels and - needs TWO 32x32 units per axis. The units never pushed (measured by - env-gated per-unit exec tracing): (160,0),(160,32) of the 64x128 PART_VERT - block at (128,0), all four units of its second chunk, (64,128),(96,128) of - the bottom-row 128x64 — exactly the PREFILT damage cells. Because the - missing units' coefficients are still in the bitstream, the entropy - decoder desyncs from the first 128-rect intra block on: SB(0,0) decodes - byte-exact and every later superblock of frames 0/1 carries damage. +2. DEFECT 1 (this lane's, FIXED) — **`decode_block_128rect`'s chroma unit + walk is hardcoded to the 4:2:0 mu-chunk span**. One 32x32 chroma unit per + 64x64 mu chunk per plane (`cn = 32 / chroma_tx` = 1), chunk offsets + `ch_col * 32` / `ch_row * 32`, and a per-chunk clip step of `ch_col * 8`: + all three are the 4:2:0 numbers. At 4:4:4 a 64x64 luma chunk covers 64 + chroma pixels and needs TWO 32x32 units per axis. The units never pushed + (measured by env-gated per-unit exec tracing): (160,0),(160,32) of the + 64x128 PART_VERT block at (128,0), all four units of its second chunk, + (64,128),(96,128) of the bottom-row 128x64 — exactly the PREFILT damage + cells. Because the missing units' coefficients are still in the + bitstream, the entropy decoder desyncs from the first 128-rect intra + block on: SB(0,0) decodes byte-exact and every later superblock of + frames 0/1 carries damage. 3. FIX (one site, decode.rs `decode_block_128rect`): per-chunk unit count `(64 >> ss) / chroma_tx`, chunk chroma offsets `64 >> ss`, clip step `16 >> ss` — every expression reduces to the old constant at ss=1, so - 4:2:0 is bit-identical by construction; the stale - `debug_assert!` (which stated the 4:2:0 invariant and would fire on 444 - in debug builds) now states the ss-aware one. -4. MEASURED after the fix, same fixture, same instrumented aomdec: - frame 0 PREFILT 0/0/0 and FINAL 0; frame 1 PREFILT 0/0/0 and FINAL 0; - frame 2 FINAL 0 — the whole 3-frame stream is byte-exact. -5. Stage-dump hazard worth recording: on frame 2 (pipelined last frame) the - PREFILT/POSTDEBLOCK/POSTCDEF dumps showed ~7-14k phantom per-plane diffs - while FINAL was byte-exact — the in-place filters have already touched - bands the mid-stage dump reads, so for a pipelined frame the mid-stage - dumps are not a clean stage ladder (class: stage-dump-on-pipelined-frame; - FINAL is the authoritative byte-exactness rung there). The frame-2 - "divergence" first seen mid-investigation was this artifact plus a stale - rebuild, not a residual defect; libaom-side confirmation is - `av1_get_adjusted_tx_size` (blockd.h:1361) capping TX_64X64 chroma at - TX_32X32, which is what the fixed walk now implements. + 4:2:0 is bit-identical by construction; the stale `debug_assert!` (which + stated the 4:2:0 invariant and would fire on 444 in debug builds) now + states the ss-aware one. +4. DEFECT 2 (fixed by CHERRY-PICK, not this lane's code) — after DEFECT 1's + fix the review still failed frames 1-2: frame 1 U/V full rows 54 and 118 + +-1 — the LR boundary-band signature. `lane-av1-422filter`'s e3798a34 + (LR boundary-band snapshot ss_y + CDEF conv422 remap) was NOT in this + branch's ancestry; cherry-picked as 168442bd. Frame 1 went byte-exact. + An r1 experiment had concluded the cherry-pick "changed nothing on 444" — + that conclusion was an artifact of a broken comparison (see 6) and is + retracted. +5. DEFECT 3 (NAMED, NOT FIXED — stop-with-site) — frame 2 still diverges at + FINAL: Y 7308 / U 9685 / V 14012 vs aomdec, deterministic. Stage ladder: + PREFILT, POSTDEBLOCK and POSTCDEF are byte-exact vs the oracle; the + damage is introduced by the LOOP RESTORATION stage, and its shape is + **LR stripe 0 (RU row 0, rows 0..63, full width, all three planes) is + never restored** — our final equals the post-CDEF plane above row 63 + (our LR-changed rows start at 63; the oracle's start at 0), while stripes + 1-2 are restored (imperfectly vs the oracle only through the reference + shift this induces in rows above? no: rows 64..159 also still differ — + the stripe-0 skip is the dominant, first-introduced defect; stripe + delta details in the r2 measurement notes). Site: the pipelined LR band + accounting — `pipe_run_lr`'s `rrows: Some` branch (restoration.rs) + refills only the RU rows its caller passes, and the band release + (`ls.note(k - 2)` / `ls.close(nb, false)`, decode.rs filter pipeline + ~25000-25032) never flushes RU row 0 on this frame — the frame whose top + superblock row carries a 128-root rect block (f2's inter 64x128 at + (128,0); f0's 128-rects sit on the keyframe path and f1 codes no + 128-root rect, which is why only f2 shows it). Fixing the flush is its + own scoped change; asserting f2's current samples in a gate would pin + the bug. +6. MEASUREMENT-METHOD CORRECTION (r1's false "all frames exact"): the r1 + final comparisons sliced the raw YUV with a plane-stride instead of a + frame-stride, so every "fN vs aomdec" row actually compared row 0 of + plane N — frame 2 was never truly compared and the 0-diff results were + an illusion. All r2 numbers above come from per-frame strided slices + (92160 bytes/frame), cross-checked against BOTH aomdec and ffmpeg, with + the binary's provenance pinned by a fresh-target-dir sha256 match + (incremental `Finished` in <2s does NOT imply a rebuild; `cargo clean + -p` without error checking can silently no-op — twice caught this wave). ## Verification - `cargo check -p ec-av1`: 0 warnings, 0 errors (target `$HOME/.cache/cargo-target-av1444sb`). -- Gates green with the fix (EC_AV1_REQUIRE_AOMENC=1): +- New pinned gate (this commit): + `a_444_sb128_root_rect_stream_with_restoration_decodes_pixel_exact` — + pins the fixture by length + FNV1a64, proves non-vacuity via the + `decode::intra_sb128_hits` delta, and asserts frames 0/1 byte-exact + against BOTH the oracle aomdec and ffmpeg (frame 2 = DEFECT 3, named in + the test body; pinning its current samples would freeze the bug). +- Gates green with fix + cherry-pick (EC_AV1_REQUIRE_AOMENC=1): `a_real_aomenc_stream_with_restoration_reads_lr_symbols_correctly`, `a_superres_key_frame_with_cdef_and_loop_restoration_decodes_pixel_exact`, `a_non_420_subsampled_sequence_header_is_refused_by_name`, `a_real_aomenc_stream_with_a_skipped_8x8_intra_leaf_whose_tx_split_ decodes_pixel_exact` — 4 passed. -- Byte-exactness method: our `decode_probe` stage dumps vs the instrumented - `$HOME/.cache/aom-oracle/build` aomdec rungs, per-frame plane-cropped - numpy compare; binary identity to the current source proven by a fresh - target-dir rebuild with matching sha256 after the incrementals went - suspicious (0.7s "Finished"). ## Decision -- One site, fixed. `decode_block_128rect` serves the kf PART128 HORZ/VERT - and AB arms plus the intra-in-inter 128 path (`in_inter` flag) — one walk, - all callers covered. +- DEFECT 1: one site, fixed. `decode_block_128rect` serves the kf PART128 + HORZ/VERT and AB arms plus the intra-in-inter 128 path (`in_inter` flag) + — one walk, all callers covered. +- DEFECT 2: fixed upstream-of-merge by cherry-pick (168442bd), kept. +- DEFECT 3: STOP-WITH-SITE per charter — the LR stripe-0 flush on inter + frames whose top SB row carries a 128-root rect. Named function/lines + above; the stage-dump evidence (PC exact, FINAL wrong, delta rows 63+) + is in the r2 notes. - NOT touched: `sub8_leaf_chroma444`'s rect arm (sibling lane, distinct - open defect: one TX_8X4/4X8 unit where the oracle codes four TX_4X4 at - ctx 1 vs 11), `decode_leaf8` OOB (leaf8oob's), the 4:2:0 group-tail + open defect), `decode_leaf8` OOB (leaf8oob's), the 4:2:0 group-tail chroma SKIP arm (reserved), `read_coeffs_rect`. -- The lane-av1-422filter ss_y snapshot fix is NOT in this branch's ancestry - and was NOT needed here (444 is exact without it); applying it locally as - an experiment changed nothing on this stream and was reverted - byte-identically. -- Temp EC_TRACE_444SB / EREAD_RECT instrumentation removed before commit; - the diff carries only the fix, the assert, and comments. +- Temp EC_TRACE_444SB / EREAD_RECT / TEMP-444SB instrumentation removed + before commit; the commits carry only the fix, the assert, the gate and + the reports. ## State -- Commit on lane-av1-444sb (no push): the ss-aware 128rect chroma walk + - the witness fixture + this report. +- Commits on lane-av1-444sb (no push): 349b3918 (DEFECT 1 fix + fixture + + r1 report), 168442bd (cherry-pick of e3798a34), this commit (DEFECT 3 + named, gate added/scoped, r2 report).