From 8cbebd59cc7b16dc1d9d50357773a7e3a1408bbd 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 11:19:58 +0300 Subject: [PATCH] wip(av1): r3 -- r2's ref1 fix real but does not close the pin; isolate to one switchable_interp symbol Pin verdict: r2's neighbour-ref1 filter-ctx fix (b7977cd) is a real, correct fix but does NOT close fixtures/av1idx-refsel-pin.obu -- 3x repro identical (149 y mismatches, worst delta 1, frame 8, row 32 col 58). The mismatching frame (aomdec's frame 8, this decoder's internal r17 index 7) has ZERO compound blocks -- all 4 32x32 leaves are single-ref -- so the CREF ref1 fix cannot be the cause of THIS fixture's residual defect; keeping it anyway as an independently-real bug fix. Isolation (new IFILTER_RS dump, gated EC_AV1_SREF_DUMP, kept as instrumentation): built an instrumented aomdec (decodemv.c read_mb_interp_filter, EC_IFILTER_DBG env var, /tmp/libaom-src decoder-debug target) and traced every switchable_interp read in this frame. mi(0,0) dir0 (ctx=3) and the next three blocks' reads all decode identically to aomdec (values AND post-adapt CDF state converted through AOM_ICDF match byte-for-byte). Exactly one read diverges: mi(0,0) dir1 (ctx=11, the x_filter direction) -- both decoders enter this read holding the literal default CDF ([27403, 32636, 32768], confirmed against both crates/ec-av1/src/cdf.rs::SWITCHABLE_INTERP[11] and libaom entropymode.c's default_switchable_interp_cdf row 11 via the AOM_ICDF inversion) -- yet we decode symbol=1, aomdec decodes symbol=0 (confirmed via aomdec's post-adapt CDF shape matching a symbol=0 adaptation, same direction/magnitude as the confirmed-matching dir0 case). Matching CDF + matching context + a symbol=0 decode on both sides for the immediately preceding dir0 read is NOT proof the raw entropy coder (value/range) state was actually synced entering dir1 -- CDF state is a pure function of decoded symbols and says nothing about the coder's internal value/range, so a desync introduced earlier in this exact block (is_inter, ref_frame, new_mv/zero_mv/ref_mv, or partition reads before this leaf) that happens to still decode the SAME symbol at dir0 by coincidence remains a live hypothesis, not ruled out. msac.rs::symbol_fixed was read against spec 8.2.6 and looks structurally sound; did not find a defect in it directly, and it is used by thousands of other passing reads across the suite, making a generic bug there unlikely. Next step: instrument this crate's own SymbolDecoder value/range (self.value, self.range) immediately after EVERY symbol read in this exact block (partition down through mode/mv/ref_frame/is_inter, ahead of the two interp_filter reads) and diff against an aomdec od_ec_dec trace of the same (needs a matching dif/rng eprintf added to av1/decoder/decodemv.c's read path, not just read_mb_interp_filter) -- find the FIRST read in this block where value/range diverges, not just where a decoded symbol first differs. The mismatching block is mi_row=8/mi_col=8 (frame's 4th leaf, ref_frame=7) but the diverging SYMBOL read is on the FIRST leaf mi_row=0/mi_col=0 dir1 -- i.e. the divergence is a probability-table/entropy-state issue from block 1 that apparently self-corrects for blocks 2-4's decoded symbol VALUES (all match aomdec) yet still produces a different final pixel outcome at block 4 -- suggesting the wrong dir1 symbol at block 1 changes block 1's own x_filter kernel (used for MC) without moving the bitstream position differently enough to cascade a symbol-level desync, but IS enough to shift block 4's reconstruction via some other coupling (context array carrying the wrong filter forward?) -- re-check whether block1's WRONG x_filter[dir1]=1 (SMOOTH) vs correct 0 (REGULAR) is used as `above_filter` context for block 3 (mi_row=8,mi_col=0) and beyond, which could explain why block 4 (not block 1) is where the PIXEL mismatch surfaces even though block1's own MC output apparently still matched (rows 0-31 all MATCH per the pin's per-plane report). Instrumented aomdec: /tmp/libaom-src/build/decoder-debug/aomdec, rebuilt after adding EC_IFILTER_DBG to decodemv.c (patch is outside this repo, in /tmp/libaom-src, not committed here -- reapply by re-adding the getenv("EC_IFILTER_DBG") block in read_mb_interp_filter before the !enable_dual_filter check, then `cd /tmp/libaom-src/build/decoder-debug && make -j12 aomdec`). Class sweep (neighbour-votes-all-its-fields) and the wide-gate unmask are both DEFERRED to the next round -- the pin still fails, so unmasking the compound gates would ship an unproven blend again per the r1/r6/r7 history's own lesson. --- crates/ec-av1/src/decode.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/crates/ec-av1/src/decode.rs b/crates/ec-av1/src/decode.rs index b6982120..7c4b5a53 100644 --- a/crates/ec-av1/src/decode.rs +++ b/crates/ec-av1/src/decode.rs @@ -3704,9 +3704,21 @@ fn resolve_interp_filter( // `h_kind`/`v_kind` argument order, which is why this function returns // `(h, v, ..)` but reads `dir0` (`v`) before `dir1` (`h`). let ctx0 = switchable_interp_ctx(above[0], left[0], 0, is_compound); + if std::env::var_os("EC_AV1_SREF_DUMP").is_some() { + eprintln!( + "IFILTER_RS dir=0 ctx={ctx0} cdf={:?}", + &cdfs.switchable_interp[ctx0][..3] + ); + } let sym0 = dec.symbol(&mut cdfs.switchable_interp[ctx0]) as u8; let sym1 = if enable_dual_filter { let ctx1 = switchable_interp_ctx(above[1], left[1], 1, is_compound); + if std::env::var_os("EC_AV1_SREF_DUMP").is_some() { + eprintln!( + "IFILTER_RS dir=1 ctx={ctx1} cdf={:?}", + &cdfs.switchable_interp[ctx1][..3] + ); + } dec.symbol(&mut cdfs.switchable_interp[ctx1]) as u8 } else { sym0