From fefaafbc6c2157a37a3b10b75bca481ac89d82b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Fri, 28 Aug 2026 17:19:21 +0300 Subject: [PATCH] wip(av1): warp fixture found + decisive pinned mismatch -- COMPILING WIP lane-warp round 3, budget-capped stop. Resolved r2's puzzle first: leaf8 (decode_inter_block8) STILL refuses motion_mode==2 unconditionally (decode.rs ~6558) -- confirmed by direct read, not inferred. The gate's fixture partition is forced to 32x32 (--min/max-partition-size=32), so leaf8 (an 8x8 leaf) is structurally unreachable on that content; the puzzle's (a) was a red herring. The real reason the warp gate reported "40 named refusals, 0 matches" is a never-fired-instrument shape from a DIFFERENT angle: every one of the 40 attempts happens to *also* hit some other real, unrelated named refusal (allow_screen_content_tools, partition-below-16x16, partition-type-never- written, interintra, directional-chroma) before or regardless of whether warp fires -- confirmed by instrumenting the gate to print every refusal string and WARP_SELECTED_HITS (leaf16's counter): even the charter's own --auto-alt-ref=1 --lag-in-frames=16 --enable-fwd-kf=0 --enable-ref-frame-mvs=0 recipe (already present in the gate, unlike r2's guess) still gets swamped by aomenc's `gradients` synthetic content tripping screen-content-tools detection at cpu-used=0. Widening the sweep (new EC_WARP_GATE_ATTEMPTS env override, default 40) to 200 seeds found warp firing 14-75 times per run (leaf16 exercised for real) but never once producing a clean pixel-exact pass across two separate 200-seed runs -- same seed set gave DIFFERENT refusal shapes on each rerun (matches the documented aomenc-RD-nondeterminism class: parallel-flake-is-attempt-selection), so the fixture itself isn't reproducible by seed alone. DECISIVE FIND: seed 49 (this run) decoded WITHOUT hitting any other named refusal, warp fired exactly once (WARP_SELECTED_HITS 0->1), and frame 1 luma mismatched ffmpeg -- a real, isolated warp_affine/find_projection bug, not a confound. Stream pinned to $SP/warp-mismatch.obu (621 bytes, 64x64, 24 frames) and a new `pinned_warp_stream_decodes_pixel_exact` #[ignore]d test added (stream.rs) that re-decodes it deterministically (no aomenc/ffmpeg re-encode) and dumps an ASCII diff mask on mismatch. Diff shape: small-magnitude ('o', delta<4) errors spread across roughly the frame's upper-left half in a diagonal band, not a sharply-bounded single-block region of gross error -- consistent with a subtle coefficient/rounding bug in the warp path rather than a wrong-block/ desync bug. Spent the rest of the round auditing warp.rs's math line by line against av1/common/warped_motion.c and mvref_common.c: confirmed FAITHFUL (no bug found yet) in find_affine_int's LS_MV_MAX inner-loop gate, LS_SQUARE/LS_PRODUCT1/LS_PRODUCT2 shift constants (LS_MAT_DOWN_BITS =2, >>4 matches), get_mult_shift_diag/ndiag (confirmed we use the USE_LIMITED_PREC_MULT=0 -- i.e. simple Px*iDet + ROUND_POWER_OF_TWO_ SIGNED_64 -- branch, matching libaom's actual compiled path, not the unused resolve_multiplier_64 branch), get_shear_params/av1_get_shear_ params (alpha/beta/gamma/delta derivation, WARP_PARAM_REDUCE_BITS rounding, is_affine_shear_allowed bound), av1_warp_affine_c's whole horizontal+vertical two-pass loop (offset_bits, reduce_bits, sx4/sy4 alpha/beta/gamma/delta stepping, tap-offset formula, final clip_pixel formula) all transcribed correctly, and the DIV_LUT table's first ~20 entries spot-checked byte-identical. NOT YET CHECKED / next round's first move: record_sample's row_offset/ col_offset sign conventions and find_samples' above/left/TL/TR traversal order against av1_find_warp_samples in mvref_common.c (only structurally skimmed, not line-audited) -- since every arithmetic primitive downstream now checks out clean, a wrong *input sample* (wrong neighbour MV/position recorded) is the next most likely place for a small-but-real numeric error to originate. Also worth trying: print our own wmmat/alpha/beta/ gamma/delta for this pinned block and compare against libaom's find_affine_int by adding a debug printf at the av1_find_projection call site in decodemv.c (~1624) and rebuilding aomdec -- would immediately localize the bug to sample-gathering vs. estimation vs. filtering without more manual line-diffing. Gate/test changes this round (stream.rs): EC_WARP_GATE_ATTEMPTS env override on the refuse-or-match gate's seed count; dump-on-mismatch via EC_AV1_GATE_DUMP added to that gate (previously missing); new pinned `pinned_warp_stream_decodes_pixel_exact` test with ASCII diff-mask eprintln on failure. cargo check -p ec-av1 --lib and --tests both clean, 0 errors/warnings-of-note (only pre-existing missing-doc lint noise). Gate itself NOT flipped to require pixel-exact yet -- still legally refuses-or-matches, correctly reflecting that warp is not yet proven correct. tmpfs at session start: 65% (11G/16G), not a blocker this round. --- crates/ec-av1/src/stream.rs | 67 +++++++++++++++++++++++++++++++++++-- 1 file changed, 65 insertions(+), 2 deletions(-) diff --git a/crates/ec-av1/src/stream.rs b/crates/ec-av1/src/stream.rs index ae3719d0..c51acb49 100644 --- a/crates/ec-av1/src/stream.rs +++ b/crates/ec-av1/src/stream.rs @@ -3322,7 +3322,11 @@ mod tests { let (width, height, frame_count) = (64usize, 64usize, 24usize); let mut named_refusals = 0u32; let mut matched = 0u32; - for attempt in 0..40u32 { + let n_attempts: u32 = std::env::var("EC_WARP_GATE_ATTEMPTS") + .ok() + .and_then(|s| s.parse().ok()) + .unwrap_or(40); + for attempt in 0..n_attempts { let seed = 42 + attempt; let duration = frame_count as f64 / 25.0; let source = @@ -3366,6 +3370,7 @@ mod tests { "--enable-order-hint=1", "--enable-warped-motion=1", "--enable-obmc=1", + "--tune-content=default", "--enable-masked-comp=0", "--enable-interintra-comp=0", "--enable-onesided-comp=0", @@ -3421,12 +3426,21 @@ mod tests { "{NAME} failed outright, not a named refusal (seed {seed}): {msg}" ); named_refusals += 1; + eprintln!("seed {seed} refusal: {msg}"); continue; } Ok(frames) => frames, }; let ffmpeg_frames = ffmpeg_decode_sequence(&stream, width, height, frame_count); assert_eq!(frames.len(), frame_count); + let mismatched = frames + .iter() + .zip(&ffmpeg_frames) + .any(|(got, want)| got.y != want.y || got.u != want.u || got.v != want.v); + if mismatched && let Ok(path) = std::env::var("EC_AV1_GATE_DUMP") { + std::fs::write(&path, &stream).expect("writing pinned stream"); + eprintln!("EC_AV1_GATE_DUMP: wrote mismatching stream (seed {seed}) to {path}"); + } for (i, (got, want)) in frames.iter().zip(&ffmpeg_frames).enumerate() { assert_eq!( got.y, want.y, @@ -3439,10 +3453,59 @@ mod tests { matched += 1; } eprintln!( - "{NAME}: {named_refusals} named refusals, {matched} pixel-exact matches out of 40" + "{NAME}: {named_refusals} named refusals, {matched} pixel-exact matches out of {n_attempts}, warp_selected_hits={}", + crate::decode::warp_selected_hits() ); } + /// lane-warp round 3: reproduces the pinned mismatch bytes captured by + /// `EC_AV1_GATE_DUMP=$SP/warp-mismatch.obu` off + /// `a_real_aomenc_stream_with_warped_motion_refuses_or_matches` (seed 49, + /// frame 1). Deterministic and static -- `#[ignore]`d, run manually. + #[test] + #[ignore = "reads a pinned fixture path outside the repo; run manually"] + fn pinned_warp_stream_decodes_pixel_exact() { + use crate::decode::warp_selected_hits; + let path = std::env::var("EC_AV1_GATE_DUMP_PIN").unwrap_or_else(|_| { + "/tmp/claude-1000/-home-user-Documents-Code-Rust-edith-codecs/\ + 51b5f611-f998-43a8-b975-e64cb643a3e1/scratchpad/warp-mismatch.obu" + .to_string() + }); + let stream = std::fs::read(&path).expect("reading pinned stream"); + if !have_ffmpeg() { + eprintln!("SKIP pinned_warp_stream_decodes_pixel_exact: no ffmpeg"); + return; + } + let before = warp_selected_hits(); + let frames = decode_stream(&stream).expect("pinned stream must decode"); + eprintln!( + "warp_selected_hits before={before} after={}", + warp_selected_hits() + ); + let ffmpeg_frames = ffmpeg_decode_sequence(&stream, 64, 64, 24); + for (i, (got, want)) in frames.iter().zip(&ffmpeg_frames).enumerate() { + if got.y != want.y { + for row in 0..64 { + let mut line = String::new(); + for col in 0..64 { + let d = got.y[row * 64 + col] as i32 - want.y[row * 64 + col] as i32; + line.push(if d == 0 { + '.' + } else if d.abs() < 4 { + 'o' + } else { + 'X' + }); + } + eprintln!("{line}"); + } + } + assert_eq!(got.y, want.y, "frame {i} luma vs ffmpeg (pinned)"); + assert_eq!(got.u, want.u, "frame {i} U vs ffmpeg (pinned)"); + assert_eq!(got.v, want.v, "frame {i} V vs ffmpeg (pinned)"); + } + } + /// `LAST2_FRAME`/`LAST3_FRAME` are just older slots in the same forward /// reference-buffer ring `LAST_FRAME`/`GOLDEN_FRAME` already prove -- /// dropping the golden gate's `--max-reference-frames=3