forge
Explore
Log in

Don't you dare go Hollow

wip(av1): pre-filter dump pinned frame-1 desync to Luma32Inter's tx_type

Browse files at this commit

a3dcb121bddb208d8198e40b93f4172ec587d00bAhmet Kaan GümüşParent: 8d878fe
read; flip-to-None regressed 16 tests, reverted. Round 4, capped at budget.

COMPILES. Does not fix the pin. Full suite back to baseline (instrumentation
only, no behaviour change from r3's HEAD besides the two new dumps below).

STEP 1 DONE, DECISIVE NEW EVIDENCE:

Added `EC_AV1_PREFILT_DUMP` (decode.rs, both apply_deblock call sites,
`PREFILT_PICTURE_IDX` global counter mirroring stream.rs's own
`pictures_decoded`), diffed against aomdec's own `EC_AV1_PREFILT_DUMP`
(decodeframe.c ~5451, already built into /tmp/libaom-src's debug aomdec).
Confirmed r3's own pre/post-filter accounting: decode-order frame 1's
mismatch (4407/6144 bytes) is already present PRE-filter -- reconstruction,
not the loop filter, exactly as r3 inferred from aomdec's own before/after
delta being tiny (333 bytes) by comparison.

STEP 2 DONE: pulled aomdec's unconditional per-block `EC_TRACE`
(decodemv.c ~1681, fires for every block regardless of env var) for
decode-order frame 1 specifically (the FIRST group of `is_inter=1` lines
after the keyframe's intra-only group, not "frame 1" by display/order_hint
-- r2's mistake) and cross-checked block-by-block against our own
`EC_AV1_TRACE`:

  block (mi 0,0):  ours skip=0 mv=(-2,-8) ref=LAST   -- MATCHES aomdec
                    exactly (mode=NEWMV both sides, motion_mode SIMPLE
                    both sides, no OBMC either side)
  block (mi 0,8):  ours skip=0 mv=(-14,8)  vs  aomdec skip=1 mv=(22,-40)
                    -- FIRST DIVERGENCE, immediately after block(0,0)

Since block(0,0)'s own mode-info matches bit-for-bit, the desync happens
inside block(0,0)'s own RESIDUAL decode (it is skip=0, so tokens are read)
-- the last thing before block(0,8)'s mode-info starts. Traced both sides'
coefficient reads for that one 32x32 luma transform (our own inline
`EC_AV1_TRACE` coeff logging in `read_coeffs`, decode.rs ~606, vs aomdec's
`EC_TRACE2`, decodetxb.c):

  ours:   tx_type symbol read, value=1 (from a real 2-symbol CDF, len=3)
  aomdec: EC_TXTYPE_VAL tx_type=0 (from a degenerate 1-symbol CDF -- no
          real bits consumed; spec `av1_get_ext_tx_set_type` resolves
          every tx_size_sqr >= TX_32X32 to `EXT_TX_SET_DCTONLY`, i.e. no
          tx_type is coded at all for a 32x32 inter transform)
  ours:   eob_pt=6 -> eob=18/17 (varies by exact run)
  aomdec: eob_pt=5 -> eob=13

`cdf_state.rs`'s `TxbSet::Luma32` (intra) already has `tx_type: None`
(correctly forced `DctDct`, matching `Luma64`'s `None` too) -- but
`TxbSet::Luma32Inter` (the one this block's `read_inter_plane` actually
uses, decode.rs ~5591) sets `tx_type: Some(self.inter_tx_type_32...)`,
reading a real symbol that spec says should never be read at this size.

TRIED AND REVERTED: flipping `Luma32Inter`'s `tx_type` to `None` (matching
`Luma32`) does NOT fix the pin -- `eob_pt` still reads 6 instead of
aomdec's 5 immediately afterward (same wrong value as before the flip),
proving the primary desync is NOT (only) the tx_type read; `eob_pt`'s own
context/table selection for this size class has a separate, still-unfound
bug. Worse: the flip regressed `cargo test -p ec-av1 --release --lib` from
green to 201 passed / 16 failed -- `inter_tx_type_32`'s CDF is evidently
depended on (adaptively, via `end_cdfs`/`cdf_slots` propagation into a
later frame's `started_from`, most likely) by other streams that DO expect
a real symbol read at this size, so `None` is not simply "more correct" in
isolation. REVERTED to `Some(...)` (baseline, all tests green again).

class: two independent-looking desync leads (tx_type over-read AND a wrong
eob_pt for 32x32) sit back-to-back in the exact same transform block --
this looks less like "one bug" and more like the CDF/context wiring for
`TxbSet::Luma32Inter` overall not matching spec's 32x32 inter path, closer
to [[tx-class-cross-cutting]] than a single point fix.

R5 UPGRADE PATH, IN ORDER:
1. Do NOT re-attempt the bare `tx_type: None` flip without first finding
   and fixing the `eob_pt` bug too -- confirmed above it does not fix
   anything alone and breaks 16 tests, so it is not a safe partial step.
2. Find the `eob_pt` bug first, in isolation: `read_eob`/`eob_pt` selection
   for `TxClass::TwoD` at side=32 (decode.rs ~549-560) against libaom's own
   `get_eob_pos_token`/`eob_multi_ctx` derivation for `TX_32X32`
   (av1/decoder/decodetxb.c, the `EC_EOBPT` trace line's own call site) --
   the aomdec fixture already prints `eob_pt=5 txs_ctx=3 tx_class=0
   eob_multi_ctx=0`, giving every context input needed to hand-derive the
   expected CDF row without more instrumentation.
3. Once eob_pt is confirmed fixed AND matches for this exact block, retry
   the `tx_type: None` flip for `Luma32Inter` and rerun the FULL
   `cargo test -p ec-av1 --release --lib` (not just the pin) before
   declaring it safe -- the 16-test regression must be understood (which
   16, why they wanted `Some`) or reproduced-fixed, not just silently
   re-broken again.
4. Re-run pin (`EC_AV1_PIN_N=24`) only after both land together.

Instrumentation added this round, env-gated (no behaviour change when
unset): `EC_AV1_PREFILT_DUMP` (decode.rs, `PREFILT_PICTURE_IDX` counter).
Reused, unchanged: `EC_AV1_TRACE` (decode.rs, already had inline coeff
tracing in `read_coeffs`/mode-info logging -- did not need new plumbing),
aomdec's own always-on `EC_TRACE`/`EC_TRACE2`/`EC_AV1_PREFILT_DUMP`
(/tmp/libaom-src, prebuilt at build/decoder-debug/aomdec).

STEP 5 (self-pin-on-mismatch for the two gates) -- STILL NOT reached, now
owed 3 rounds. Must be r5's first task per the standing charter note.

class: dpb-propagation-from-an-unverified-hidden-frame (r3's class) is
CONFIRMED as the correct causal chain (hidden frame 1 -> corrupts later
refs via refresh_frame_flags), origin now narrowed from "frame 1's
reconstruction" to "frame 1's very first non-skip 32x32 luma transform's
own token decode", two candidate bugs identified, neither closes it alone.
crates/ec-av1/src/cdf_state.rsmodified+12 -0
@@ -1038,6 +1038,18 @@ impl Cdfs {
10381038 tx_type: None,
10391039 eob_pt_class1: None,
10401040 },
1041+ // lane-comppin r4 (REVERTED, see r4's own commit message):
1042+ // `Some(inter_tx_type_32)` looked wrong against aomdec's 32x32
1043+ // trace (degenerate 1-symbol EC_TXTYPE_VAL=0 read) and matches
1044+ // spec `av1_get_ext_tx_set_type`'s `EXT_TX_SET_DCTONLY` for
1045+ // every tx_size_sqr >= TX_32X32 -- but flipping this to `None`
1046+ // regressed 16 previously-green `ec-av1` tests (full-suite count
1047+ // went 217/217 -> 201/216), and did NOT fix the pin's own
1048+ // eob_pt desync either (still reads 6 instead of aomdec's 5
1049+ // right after this read, proving eob_pt's own context/table
1050+ // selection is a SEPARATE, still-unfound bug upstream of this
1051+ // one) -- kept `Some` pending a real fix that ports both without
1052+ // breaking the 16.
10411053 TxbSet::Luma32Inter => TxbTables {
10421054 side: 32,
10431055 txb_skip: &mut self.txb_skip_luma_32,
crates/ec-av1/src/decode.rsmodified+37 -0
@@ -62,6 +62,11 @@ pub(crate) fn filter_intra_hits() -> usize {
6262 /// before/after counter pattern as [`FILTER_INTRA_HITS`], proving a stream
6363 /// exercised `apply_deblock` rather than every edge landing on level 0.
6464 static DEBLOCK_HITS: std::sync::atomic::AtomicUsize = std::sync::atomic::AtomicUsize::new(0);
65+/// lane-comppin r4: decode-order picture counter for `EC_AV1_PREFILT_DUMP`,
66+/// mirroring stream.rs's `pictures_decoded` so the two dumps index
67+/// identically against aomdec's own `ec_frame_idx` in decodeframe.c.
68+static PREFILT_PICTURE_IDX: std::sync::atomic::AtomicUsize =
69+ std::sync::atomic::AtomicUsize::new(0);
6570
6671 /// Current value of [`DEBLOCK_HITS`].
6772 pub(crate) fn deblock_hits() -> usize {
@@ -3613,6 +3618,22 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
36133618 }
36143619 }
36153620
3621+ // lane-comppin r4: pre-loop-filter decode-order dump, matching aomdec's
3622+ // own EC_AV1_PREFILT_DUMP shape (decodeframe.c ~5451) -- diffs against
3623+ // that isolate whether a decode-order frame's mismatch already exists
3624+ // in reconstruction (this dump) vs is introduced by the loop filter
3625+ // (EC_AV1_DECODE_ORDER_DUMP's post-filter dump).
3626+ if let Ok(path) = std::env::var("EC_AV1_PREFILT_DUMP") {
3627+ use std::io::Write;
3628+ let idx = PREFILT_PICTURE_IDX.fetch_add(1, std::sync::atomic::Ordering::SeqCst);
3629+ if let Ok(mut f) = std::fs::File::create(format!("{path}.f{idx}")) {
3630+ let _ = f.write_all(&y.data);
3631+ let _ = f.write_all(&u.data);
3632+ let _ = f.write_all(&v.data);
3633+ }
3634+ } else {
3635+ PREFILT_PICTURE_IDX.fetch_add(1, std::sync::atomic::Ordering::SeqCst);
3636+ }
36163637 apply_deblock(&mut y, &mut u, &mut v, loop_filter, &neighbours);
36173638 apply_cdef(&mut y, &mut u, &mut v, cdef, &neighbours);
36183639
@@ -7190,6 +7211,22 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
71907211 }
71917212 }
71927213
7214+ // lane-comppin r4: pre-loop-filter decode-order dump, matching aomdec's
7215+ // own EC_AV1_PREFILT_DUMP shape (decodeframe.c ~5451) -- diffs against
7216+ // that isolate whether a decode-order frame's mismatch already exists
7217+ // in reconstruction (this dump) vs is introduced by the loop filter
7218+ // (EC_AV1_DECODE_ORDER_DUMP's post-filter dump).
7219+ if let Ok(path) = std::env::var("EC_AV1_PREFILT_DUMP") {
7220+ use std::io::Write;
7221+ let idx = PREFILT_PICTURE_IDX.fetch_add(1, std::sync::atomic::Ordering::SeqCst);
7222+ if let Ok(mut f) = std::fs::File::create(format!("{path}.f{idx}")) {
7223+ let _ = f.write_all(&y.data);
7224+ let _ = f.write_all(&u.data);
7225+ let _ = f.write_all(&v.data);
7226+ }
7227+ } else {
7228+ PREFILT_PICTURE_IDX.fetch_add(1, std::sync::atomic::Ordering::SeqCst);
7229+ }
71937230 apply_deblock(&mut y, &mut u, &mut v, loop_filter, &neighbours);
71947231 apply_cdef(&mut y, &mut u, &mut v, cdef, &neighbours);
71957232