From a3dcb121bddb208d8198e40b93f4172ec587d00b 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:10:25 +0300 Subject: [PATCH] wip(av1): pre-filter dump pinned frame-1 desync to Luma32Inter's tx_type 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.rs | 12 +++++++++++ crates/ec-av1/src/decode.rs | 37 ++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+) diff --git a/crates/ec-av1/src/cdf_state.rs b/crates/ec-av1/src/cdf_state.rs index dbdf2d10..26008f56 100644 --- a/crates/ec-av1/src/cdf_state.rs +++ b/crates/ec-av1/src/cdf_state.rs @@ -1038,6 +1038,18 @@ impl Cdfs { tx_type: None, eob_pt_class1: None, }, + // lane-comppin r4 (REVERTED, see r4's own commit message): + // `Some(inter_tx_type_32)` looked wrong against aomdec's 32x32 + // trace (degenerate 1-symbol EC_TXTYPE_VAL=0 read) and matches + // spec `av1_get_ext_tx_set_type`'s `EXT_TX_SET_DCTONLY` for + // every tx_size_sqr >= TX_32X32 -- but flipping this to `None` + // regressed 16 previously-green `ec-av1` tests (full-suite count + // went 217/217 -> 201/216), and did NOT fix the pin's own + // eob_pt desync either (still reads 6 instead of aomdec's 5 + // right after this read, proving eob_pt's own context/table + // selection is a SEPARATE, still-unfound bug upstream of this + // one) -- kept `Some` pending a real fix that ports both without + // breaking the 16. TxbSet::Luma32Inter => TxbTables { side: 32, txb_skip: &mut self.txb_skip_luma_32, diff --git a/crates/ec-av1/src/decode.rs b/crates/ec-av1/src/decode.rs index a2e070f6..549897fe 100644 --- a/crates/ec-av1/src/decode.rs +++ b/crates/ec-av1/src/decode.rs @@ -62,6 +62,11 @@ pub(crate) fn filter_intra_hits() -> usize { /// before/after counter pattern as [`FILTER_INTRA_HITS`], proving a stream /// exercised `apply_deblock` rather than every edge landing on level 0. static DEBLOCK_HITS: std::sync::atomic::AtomicUsize = std::sync::atomic::AtomicUsize::new(0); +/// lane-comppin r4: decode-order picture counter for `EC_AV1_PREFILT_DUMP`, +/// mirroring stream.rs's `pictures_decoded` so the two dumps index +/// identically against aomdec's own `ec_frame_idx` in decodeframe.c. +static PREFILT_PICTURE_IDX: std::sync::atomic::AtomicUsize = + std::sync::atomic::AtomicUsize::new(0); /// Current value of [`DEBLOCK_HITS`]. pub(crate) fn deblock_hits() -> usize { @@ -3613,6 +3618,22 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( } } + // lane-comppin r4: pre-loop-filter decode-order dump, matching aomdec's + // own EC_AV1_PREFILT_DUMP shape (decodeframe.c ~5451) -- diffs against + // that isolate whether a decode-order frame's mismatch already exists + // in reconstruction (this dump) vs is introduced by the loop filter + // (EC_AV1_DECODE_ORDER_DUMP's post-filter dump). + if let Ok(path) = std::env::var("EC_AV1_PREFILT_DUMP") { + use std::io::Write; + let idx = PREFILT_PICTURE_IDX.fetch_add(1, std::sync::atomic::Ordering::SeqCst); + if let Ok(mut f) = std::fs::File::create(format!("{path}.f{idx}")) { + let _ = f.write_all(&y.data); + let _ = f.write_all(&u.data); + let _ = f.write_all(&v.data); + } + } else { + PREFILT_PICTURE_IDX.fetch_add(1, std::sync::atomic::Ordering::SeqCst); + } apply_deblock(&mut y, &mut u, &mut v, loop_filter, &neighbours); apply_cdef(&mut y, &mut u, &mut v, cdef, &neighbours); @@ -7190,6 +7211,22 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( } } + // lane-comppin r4: pre-loop-filter decode-order dump, matching aomdec's + // own EC_AV1_PREFILT_DUMP shape (decodeframe.c ~5451) -- diffs against + // that isolate whether a decode-order frame's mismatch already exists + // in reconstruction (this dump) vs is introduced by the loop filter + // (EC_AV1_DECODE_ORDER_DUMP's post-filter dump). + if let Ok(path) = std::env::var("EC_AV1_PREFILT_DUMP") { + use std::io::Write; + let idx = PREFILT_PICTURE_IDX.fetch_add(1, std::sync::atomic::Ordering::SeqCst); + if let Ok(mut f) = std::fs::File::create(format!("{path}.f{idx}")) { + let _ = f.write_all(&y.data); + let _ = f.write_all(&u.data); + let _ = f.write_all(&v.data); + } + } else { + PREFILT_PICTURE_IDX.fetch_add(1, std::sync::atomic::Ordering::SeqCst); + } apply_deblock(&mut y, &mut u, &mut v, loop_filter, &neighbours); apply_cdef(&mut y, &mut u, &mut v, cdef, &neighbours);