forge
Explore
Log in

Don't you dare go Hollow

wip(av1): msac symbol_fixed hand-verified correct; real desync is a switchable_interp read aomdec never performs for this block. Round 6, capped at budget.

Browse files at this commit

21c832090b62b7b73239fcf7d59cda4a6a386507Ahmet Kaan GümüşParent: ea8acbf
COMPILES. No behaviour change: new EC_AV1_EOBPT_CDF-gated
`debug_state()`/eprintln! diagnostics only (msac.rs's new `pub(crate) fn
debug_state`, decode.rs's three new state prints in `read_coeffs` and
`read_eob`), same pattern as every prior round's instrumentation.

R6'S OWN PLAN'S STEP 1/2 (msac.rs correctness) IS NOW CLOSED, NEGATIVE:
hand-derived `symbol_fixed` (msac.rs:301-329) against libaom's actual
`od_ec_decode_cdf_q15` source (`/tmp/libaom-src/aom_dsp/entdec.c:204`,
read fresh this round, not from memory) term-by-term for nsyms=11
specifically -- `N = nsyms - 1`, loop increments `ret` before indexing
`icdf[++ret]`, `v = ((r>>8)*(icdf[ret]>>EC_PROB_SHIFT))>>(7-EC_PROB_SHIFT)
+ EC_MIN_PROB*(N-ret)`, loop continues `while (c < v)`. This is
algebraically IDENTICAL to our `cur = (((range>>8)*(f>>EC_PROB_SHIFT))
>>(7-EC_PROB_SHIFT)) + EC_MIN_PROB*(nsyms-1-symbol)`, loop `while value
< cur`. nsyms=11 is not special-cased anywhere in either implementation.
r5's suspicion (1) is FALSIFIED -- do not re-open without new evidence.

DECISIVE NEW EVIDENCE (this round's actual find): added a
`debug_state()` accessor to `SymbolDecoder` and printed `(range, value)`
before/after the `all_zero` (txb_skip) read, after the `tx_type` read,
and entering `eob_pt` -- then added the SAME state to aomdec's
`decodetxb.c` (`EC_AV1_EOBPT_STATE_IN`, plus `rng_before` on the
existing `EC_PLANE` trace). Result: **the coder state ALREADY diverges
before the `txb_skip` read even starts** -- ours enters at
`range=46855`, aomdec enters at `rng_before=50720`. So r5's "CDF +
symbol byte-identical at tx_type/eob_pt" was real but downstream of an
earlier, silent divergence; walking back from there:

Between `EC_MV` (motion vector, matches exactly: `mv=(-2,-8)` both
sides) and `EC_TXBCTX`/`EC_PLANE` (first plane's coeff decode), the ONLY
symbol read possible on this path is the switchable interpolation
filter (`resolve_interp_filter`, decode.rs:3726 / libaom's
`read_mb_interp_filter`, decodemv.c:1122). Ours takes the *real-symbol*
branch (`interp_fixed == None`, i.e. the frame header says
`interpolation_filter == Switchable`) and decodes `filter=[3, 3]`
(BILINEAR both directions) -- a real, adapting 3-symbol CDF read.
aomdec's own trace for this exact block (`mi_row=0 mi_col=0`, frame=14,
ref=1, mode=NEWMV=16) shows `interp=(0,0)` (REGULAR both directions)
with **no `IFILTER_DBG` line at all** -- confirmed by instrumenting
`av1_is_interp_needed()`'s own three sub-conditions directly
(`IFILTER_NEEDED ... skip_mode=0 motion_mode=0 mode=16 needed=1`): the
function returns TRUE (the read is not skipped by the gate), yet
`read_mb_interp_filter`'s OWN symbol-read branch never fires for this
block, which by its source (decodemv.c:1134,
`if (interp_filter != SWITCHABLE)`) is only possible if **libaom's own
per-frame `features->interp_filter` is a FIXED value for frame 14, not
`SWITCHABLE`** -- i.e. aomdec's `interpolation_filter` header field for
THIS frame differs from what our decoder computed.

CONCLUSION / R7 HANDOFF, IN ORDER:
1. This is very likely NOT an msac bug at all (closed, see above). The
   live suspect is `read_interpolation_filter()`
   (`ec-av1-syntax/src/frame.rs:1165`) or, more likely given the header
   bit-parsing there matches spec 5.9.10 exactly on inspection, a
   **frame-header/frame-index MISMATCH**: this pin's "decode-order frame
   1" may not be resolving to the same underlying temporal-unit frame
   aomdec calls its own "frame=14" -- ties back to f952bb4's
   already-flagged "hidden frame" suspicion from round 3, never fully
   closed. Confirm by dumping `header.interpolation_filter` (and ideally
   `show_frame`/`frame_type`/`order_hint`) for EVERY frame header our
   decoder parses in this stream, aligned against aomdec's own
   `cm->current_frame.frame_number` sequence (add an
   `EC_AV1_FRAME_NUMBER`-style eprintln! to `av1_read_coeffs_txb` or the
   frame-header decode point on aomdec's side, matching the counters
   already in place) -- find the first frame where the two disagree on
   `interpolation_filter`, and from there whether it's a genuine
   off-by-one in which OBU/frame our pin harness treats as
   "decode-order frame 1", or a real per-frame header field ours reads
   as `Switchable` when it should not.
2. If frame alignment IS correct and headers genuinely disagree on this
   field for the SAME frame: re-derive `read_interpolation_filter`
   against spec 5.9.10 word-for-word once more (looks correct on this
   round's read, but re-check the surrounding `allow_high_precision_mv`
   /`force_integer_mv` order just above it, frame.rs:963-968 -- an
   earlier misread bit could shift every subsequent header field by one
   bit position without desyncing the *tile* data at all, which is
   exactly the shape of "everything downstream of one header field
   looks locally consistent but globally wrong").
3. Once the true cause is found and fixed, re-run the pin
   (`EC_AV1_PIN_N=24`) for exactness, THEN full
   `cargo test -p ec-av1 --release` (not just `--lib`) per existing
   done-criteria -- a header-parsing fix is even more likely than an
   msac fix to touch every stream.
4. If the pin goes exact: run the three flaking gates 15x each
   (`compound_references`, `reference_select`, `deblocking`) and report
   pass counts honestly.

Instrumentation added this round, env-gated (no behaviour change when
unset): `SymbolDecoder::debug_state()` (msac.rs, `pub(crate)`, mirrors
the existing `debug_bitpos()`), three new `EC_AV1_EOBPT_CDF`-gated
state prints in decode.rs (`EC_AV1_STATE_BEFORE_TXBSKIP`,
`EC_AV1_STATE_AFTER_TXBSKIP`, `EC_AV1_STATE_AFTER_TXTYPE`). External,
not committed to this repo: `/tmp/libaom-src`'s
`av1/decoder/decodetxb.c` (`EC_AV1_EOBPT_STATE_IN`, `rng_before` on
`EC_PLANE`) and `av1/decoder/decodemv.c` (`IFILTER_NEEDED`, gated on the
pre-existing `EC_IFILTER_DBG`) -- rebuilt into
`/tmp/libaom-src/build/decoder-debug/aomdec`; this source tree is
outside the repo and NOT reproducible from a fresh checkout, note for
whoever runs r7 without the same `/tmp` state.

class: sibling of [[stale-premise-lanes]] -- r4 and r5 both suspected
mechanisms one level too deep (a table's forwarding, then a coder
primitive) because both were proven correct in isolation without first
walking the state itself backward to its true entry point; the actual
divergence sits one whole syntax element earlier (a per-block symbol
read that should not have fired at all), in territory ([[hidden frame]]
frame-index resolution) an even earlier round (f952bb4) already named
and left open.
crates/ec-av1/src/decode.rsmodified+14 -1
@@ -551,7 +551,8 @@ fn read_eob(dec: &mut SymbolDecoder, coding: &mut TxbTables, class: TxClass) ->
551 (_, Some(class1)) => class1,551 (_, Some(class1)) => class1,
552 };552 };
553 if std::env::var_os("EC_AV1_EOBPT_CDF").is_some() && eob_pt.len() == 12 {553 if std::env::var_os("EC_AV1_EOBPT_CDF").is_some() && eob_pt.len() == 12 {
554- eprintln!("EC_AV1_EOBPT_CDF {eob_pt:?}");554+ let (range, value) = dec.debug_state();
555+ eprintln!("EC_AV1_EOBPT_CDF {eob_pt:?} range={range} value={value}");
555 }556 }
556 let group = dec.symbol(eob_pt) + 1;557 let group = dec.symbol(eob_pt) + 1;
557 if trace {558 if trace {
@@ -622,10 +623,18 @@ fn read_coeffs(
622 let trace = std::env::var_os("EC_AV1_TRACE").is_some();623 let trace = std::env::var_os("EC_AV1_TRACE").is_some();
623 let side = coding.side;624 let side = coding.side;
624 let mut grid = vec![0i32; side * side];625 let mut grid = vec![0i32; side * side];
626+ if std::env::var_os("EC_AV1_EOBPT_CDF").is_some() {
627+ let (range, value) = dec.debug_state();
628+ eprintln!("EC_AV1_STATE_BEFORE_TXBSKIP range={range} value={value}");
629+ }
625 let all_zero = dec.symbol(&mut coding.txb_skip[skip_ctx]) == 1;630 let all_zero = dec.symbol(&mut coding.txb_skip[skip_ctx]) == 1;
626 if trace {631 if trace {
627 eprintln!("TRACE all_zero ctx={skip_ctx} value={}", all_zero as i32);632 eprintln!("TRACE all_zero ctx={skip_ctx} value={}", all_zero as i32);
628 }633 }
634+ if std::env::var_os("EC_AV1_EOBPT_CDF").is_some() {
635+ let (range, value) = dec.debug_state();
636+ eprintln!("EC_AV1_STATE_AFTER_TXBSKIP range={range} value={value}");
637+ }
629 if all_zero {638 if all_zero {
630 return Ok((grid, TxType::DctDct));639 return Ok((grid, TxType::DctDct));
631 }640 }
@@ -644,6 +653,10 @@ fn read_coeffs(
644 eprintln!("EC_AV1_TXTYPE32_CDF {tx_type_cdf:?}");653 eprintln!("EC_AV1_TXTYPE32_CDF {tx_type_cdf:?}");
645 }654 }
646 let t = dec.symbol(tx_type_cdf);655 let t = dec.symbol(tx_type_cdf);
656+ if std::env::var_os("EC_AV1_EOBPT_CDF").is_some() {
657+ let (range, value) = dec.debug_state();
658+ eprintln!("EC_AV1_STATE_AFTER_TXTYPE range={range} value={value}");
659+ }
647 if trace {660 if trace {
648 eprintln!("TRACE tx_type value={t} len={len}");661 eprintln!("TRACE tx_type value={t} len={len}");
649 }662 }
crates/ec-av1/src/msac.rsmodified+8 -0
@@ -335,6 +335,14 @@ impl<'a> SymbolDecoder<'a> {
335 self.bit335 self.bit
336 }336 }
337 337
338+ /// Debug-only: the raw coder state (`range`, `value`) entering the next
339+ /// read, for a byte-for-byte diff against a reference decoder's own
340+ /// `r->ec.rng`/`r->ec.dif` while chasing a desync (see
341+ /// `EC_AV1_EOBPT_CDF`). Not spec output, just the two live fields.
342+ pub(crate) fn debug_state(&self) -> (u32, u32) {
343+ (self.range, self.value)
344+ }
345+
338 /// Reads `bits` raw bits, most significant first — the `L(n)` descriptor346 /// Reads `bits` raw bits, most significant first — the `L(n)` descriptor
339 /// of spec 4.10.4.347 /// of spec 4.10.4.
340 pub fn literal(&mut self, bits: u32) -> u32 {348 pub fn literal(&mut self, bits: u32) -> u32 {