forge
Explore
Log in

Don't you dare go Hollow

wip(av1): r2's skip_mode-desync theory FALSIFIED; real defect is decode-order

Browse files at this commit

8d878fe6f28b599e7c3cc7349cefcc7f393211b5Ahmet Kaan GümüşParent: 15f253d
frame 1's own reconstruction, invisible to the existing pin (hidden frame)

COMPILES. Does not fix the pin. Round 3 of lane-comppin, capped at budget.

STEP 1/2 OF THE CHARTER, DONE -- DECISIVE, OVERTURNS r2:
Added EC_AV1_SKIPMODE_DUMP (decode.rs ~4623, ctx+tell before/after the
skip_mode symbol read) and a matching hook in libaom's own read_skip_mode
(/tmp/libaom-src/av1/decoder/decodemv.c ~453, EC_SKIPMODE env var, rebuilt
into /tmp/libaom-src/build/decoder-debug/aomdec). Direct comparison for the
frame r2 called "frame 1" (order_hint=1, the pin's 2nd *shown* frame):

  ctx sequence:    ours 0,1,1,2   aomdec 0,1,1,2   -- MATCH
  result sequence: ours T,T,T,T   aomdec T,T,T,T   -- MATCH

r2's claim ("real bitstream's block (0,0) is SINGLE-ref LAST, skip_mode
false") does not hold under this direct comparison -- it was very likely an
artifact of comparing OUR decode-order frame index against aomdec's own
*decode*-order frame_number without accounting for AV1's hierarchical-B
reorder (decode order for this pin's skip_mode-bearing frames is
order_hint 7, then 3, then 1 -- NOT ascending display order; r2's manual
aomdec read likely landed on a different frame_number than intended). The
raw `tell` numeric gap noted in-flight this round (19 vs 5 bits before the
first read) is ALSO not evidence: aom_reader_tell()/od_ec_dec_tell() is a
fractional-bit *estimate*, not a raw bit-offset like our debug_bitpos() --
apples to oranges, not comparable numerically.

Also confirmed from libaom source (decodemv.c ~1541-1578): comp_group_idx
and compound_idx are NEVER read for a skip_mode block -- both stay at their
init values (0, 1 = COMPOUND_AVERAGE) unconditionally. So compound_idx is
not a desync candidate for this pin's all-skip_mode frame either, closing
off the other half of r2's upgrade path 2/3 as inapplicable here (right
answer, wrong question -- there is no compound_idx *read* to desync).

NEW FINDING THIS ROUND (the actual lead for r4): the existing pixel-diff
harness (`scratch_isolate_pinned_mismatch`) only ever compares *shown*
frames (display order) against ffmpeg's own (also display-order) output --
so it never directly checks the hidden altref/bwdref frames a shown frame's
compound prediction is built from. Added EC_AV1_DECODE_ORDER_DUMP
(stream.rs, dumps every decoded frame's post-loop-filter Y+U+V in DECODE
order, `pictures_decoded` counter) and cross-checked against aomdec's own
EC_AV1_POSTFILT_DUMP for the same pin:

  decode-order frame 0 (keyframe):        byte-exact (as already known)
  decode-order frame 1 (first hidden alt, predicts ONLY from the exact
    keyframe -- no other reference exists yet, so DPB/ref_slots corruption
    is RULED OUT as a cause here):        4439 / 6144 bytes differ (72%),
    mostly +-1/+-2 (row0 col0: 126 vs 127 ...), one outlier delta 31 at
    Y offset 4033 (row 63, col 1)
  cross-checked against aomdec's OWN pre- vs post-loop-filter dump for that
    same frame: only 333/6144 bytes change from its own loop filter, so the
    bulk of our 4439-byte gap already exists in *reconstruction*, upstream
    of loop filtering, not a filter-strength mismatch.

This is a much cleaner, earlier, and larger divergence than the "display
frame 1" comparison r1/r2 chased (worst delta 4, growing to 60 by frame 23)
-- that number was symptom, not source: it is contamination flowing forward
from THIS frame (decode-order 1) through refresh_frame_flags into every
later reference, exactly like lane-av1blend's already-documented DPB
propagation class, except here the corruption's true origin is now pinned
to one fully-isolated single-reference-input frame instead of a whole GOP.

R4 UPGRADE PATH, IN ORDER:
1. Add a Rust-side PRE-loop-filter dump (hook before apply_deblock is
   called in decode_inter_frame_tile_with_cdfs, same shape as
   EC_AV1_DECODE_ORDER_DUMP) and diff against aomdec's EC_AV1_PREFILT_DUMP
   for decode-order frame 1 specifically -- confirms whether the ~4100+
   byte gap is present pre-filter (reconstruction/MC bug) as the pre-vs-post
   accounting above already implies, or partly filter-side.
2. If pre-filter also mismatches widely: decode-order frame 1's own blocks
   are skip_mode=true/compound (per the r2/r3 traces), predicting from a
   single known-exact source (the keyframe) with an MV this round did NOT
   yet verify against aomdec's own decoded MV for THIS frame (r2's MV claim
   was for the wrong frame per the falsification above) -- get
   EC_TRACE mode/mv/ref dumps from decodemv.c for decode-order frame 1
   specifically (not "frame 1" by order_hint) and diff mv/ref pair
   block-by-block against our own EC_AV1_TRACE.
3. Given the pattern (widespread +-1/+-2, one 31-outlier) looks like either
   a systematic rounding bug in the compound blend/MC round-off (the
   ALTREF_FRAME single-ref altref-context special case in record_inter,
   decode.rs ~1023-1032, is one plausible site: this frame's ref pair likely
   *is* LAST+ALTREF) or a wrong film-grain/identity-matrix path leaking in
   before the DPB store -- check `film_grain.apply_grain` isn't
   accidentally hitting this "hidden" frame's stored (pre-grain) picture,
   though stream.rs's grain gating already looks correct on inspection.

STEP 5 (self-pin-on-mismatch for the two gates) -- NOT reached this round,
still owed to r4.

Instrumentation left in place, all env-var-gated (no behaviour change when
unset): EC_AV1_SKIPMODE_DUMP (decode.rs), EC_AV1_DECODE_ORDER_DUMP
(stream.rs), EC_SKIPMODE (libaom decodemv.c, rebuild with `make -j12 aomdec`
in /tmp/libaom-src/build/decoder-debug if stale).

class: dpb-propagation-from-an-unverified-hidden-frame -- same shape as
lane-av1blend's already-filed ref_slots/refresh_frame_flags class, but here
the true origin is now isolated to ONE frame with only one possible input.
crates/ec-av1/src/decode.rsmodified+15 -0
@@ -4622,7 +4622,22 @@ fn decode_inter_block(
4622 4622
4623 let skip_mode_ctx =4623 let skip_mode_ctx =
4624 usize::from(neighbours.above_skip_mode[c]) + usize::from(neighbours.left_skip_mode[r]);4624 usize::from(neighbours.above_skip_mode[c]) + usize::from(neighbours.left_skip_mode[r]);
4625+ // lane-comppin r3: skip_mode desync isolation -- dump ctx + the pre-read
4626+ // MSAC tell so it can be diffed against an equivalent hook in libaom's
4627+ // own `read_skip_mode`/`av1_get_skip_mode_context`.
4628+ if std::env::var_os("EC_AV1_SKIPMODE_DUMP").is_some() {
4629+ eprintln!(
4630+ "EC_SKIPMODE r={r} c={c} ctx={skip_mode_ctx} skip_mode_present={skip_mode_present} tell_before={}",
4631+ dec.debug_bitpos()
4632+ );
4633+ }
4625 let skip_mode = skip_mode_present && dec.symbol(&mut cdfs.skip_mode[skip_mode_ctx]) == 1;4634 let skip_mode = skip_mode_present && dec.symbol(&mut cdfs.skip_mode[skip_mode_ctx]) == 1;
4635+ if std::env::var_os("EC_AV1_SKIPMODE_DUMP").is_some() {
4636+ eprintln!(
4637+ "EC_SKIPMODE r={r} c={c} result={skip_mode} tell_after={}",
4638+ dec.debug_bitpos()
4639+ );
4640+ }
4626 if skip_mode {4641 if skip_mode {
4627 SKIP_MODE_HITS.fetch_add(1, std::sync::atomic::Ordering::Relaxed);4642 SKIP_MODE_HITS.fetch_add(1, std::sync::atomic::Ordering::Relaxed);
4628 }4643 }
crates/ec-av1/src/stream.rsmodified+19 -0
@@ -46,6 +46,7 @@ use crate::encode::Picture;
46 pub fn decode_stream(data: &[u8]) -> Result<Vec<Picture>> {46 pub fn decode_stream(data: &[u8]) -> Result<Vec<Picture>> {
47 let mut parser = Av1Parser::new();47 let mut parser = Av1Parser::new();
48 let mut pictures = Vec::new();48 let mut pictures = Vec::new();
49+ let mut pictures_decoded: usize = 0;
49 // Spec 7.20/7.4: each of the 8 reference slots remembers the picture a50 // Spec 7.20/7.4: each of the 8 reference slots remembers the picture a
50 // previous frame's `refresh_frame_flags` stored into it, exactly like the51 // previous frame's `refresh_frame_flags` stored into it, exactly like the
51 // CDF slots below -- `LAST_FRAME` names a slot via `ref_frame_idx[0]`,52 // CDF slots below -- `LAST_FRAME` names a slot via `ref_frame_idx[0]`,
@@ -421,6 +422,24 @@ pub fn decode_stream(data: &[u8]) -> Result<Vec<Picture>> {
421 let _ = writeln!(f, "mv_joint {:?}", stored_cdfs.mv_joint);422 let _ = writeln!(f, "mv_joint {:?}", stored_cdfs.mv_joint);
422 }423 }
423 }424 }
425+ // lane-comppin r3: decode-order (not display-order) dump of every
426+ // frame's own post-deblock buffer -- the pre-existing pixel diff
427+ // (`scratch_isolate_pinned_mismatch`) only ever compares *shown*
428+ // frames, so a hidden reference (altref/bwdref) that DPB-corrupts a
429+ // later shown frame is otherwise invisible; diff this byte-for-byte
430+ // against `EC_AV1_POSTFILT_DUMP.fN` from the instrumented aomdec
431+ // build to isolate whether the defect is in a hidden frame's own
432+ // reconstruction or downstream of it.
433+ if let Ok(path) = std::env::var("EC_AV1_DECODE_ORDER_DUMP") {
434+ use std::io::Write;
435+ let idx = pictures_decoded;
436+ if let Ok(mut f) = std::fs::File::create(format!("{path}.f{idx}")) {
437+ let _ = f.write_all(&picture.y);
438+ let _ = f.write_all(&picture.u);
439+ let _ = f.write_all(&picture.v);
440+ }
441+ }
442+ pictures_decoded += 1;
424 for i in 0..NUM_REF_FRAMES {443 for i in 0..NUM_REF_FRAMES {
425 if header.refresh_frame_flags & (1 << i) != 0 {444 if header.refresh_frame_flags & (1 << i) != 0 {
426 cdf_slots[i] = Some(stored_cdfs.clone());445 cdf_slots[i] = Some(stored_cdfs.clone());