forge
Explore
Log in

Don't you dare go Hollow

wip(av1): FALSIFY r4's tx_type theory; decisive new lead -- raw eob_pt symbol off-by-one with byte-identical CDF and matching prior read. Round 5, capped at budget.

Browse files at this commit

ea8acbfe34e1be7f80fa1ccd69022f7681667c82Ahmet Kaan GümüşParent: 69a575c
COMPILES. No behaviour change (two new EC_AV1_EOBPT_CDF-gated eprintln!
diagnostics only, both no-ops when the env var is unset -- same pattern
as EC_AV1_TRACE/EC_AV1_PREFILT_DUMP).

STEP 1 DONE (owed 3 rounds): self-pin-on-mismatch landed in the previous
commit (de8e7a5) for both compound-refs and reference-select gates.

STEP 2, R4'S CORE THEORY FALSIFIED: r4 believed `Luma32Inter`'s tx_type
symbol was spuriously read (spec forcing EXT_TX_SET_DCTONLY for every
tx_size_sqr >= TX_32X32) and that removing it would fix the pin. Re-read
libaom's own `av1_get_ext_tx_set_type` (blockd.h ~1097) closely: that
DCTONLY collapse is INTRA-only. For an INTER 32x32 block it returns
`EXT_TX_SET_DCT_IDTX` (2 symbols: IDTX, DCT_DCT) -- a REAL read, matching
this crate's existing `INTER_TX_TYPE_SET3_32` table exactly (confirmed
`av1_ext_tx_inv[EXT_TX_SET_DCT_IDTX] = {9, 0}`, our `from_symbol`'s
default arm agrees). `TxbSet::Luma32Inter`'s `Some(inter_tx_type_32)` was
right all along; r4's own doc comment at the site is now stale (still
says "REVERTED... pending a real fix" -- superseded by this commit, left
in place for the paper trail rather than rewritten under budget).

DECISIVE NEW EVIDENCE (rebuilt `/tmp/libaom-src`'s debug `aomdec` with a
new `EC_INTERTXTYPE_CDF`/`EC_INTERTXTYPE_RAWSYM` trace in
`decodemv.c`'s inter branch of `av1_read_tx_type` -- previously only the
intra branch printed its CDF/raw symbol; the inter branch's own read was
invisible to every earlier round's trace):

  block mi(0,0), decode-order frame 1 (aomdec's own `frame=14`), the
  32x32 luma tx_type read:
    aomdec CDF (icdf, decreasing) [32020, 0, 0]  ==  ours (increasing)
      [748, 32768, 0]  (32768-32020=748, exact match, confirms this
      crate's CDF-forwarding for `inter_tx_type_32` is byte-correct --
      the table is untouched since the keyframe never runs an inter
      block, so this is genuinely still spec-default 748, both sides)
    aomdec raw sym=1 (tell=15)  ==  ours: `TRACE tx_type value=1 len=3`
      -- EXACT MATCH, both sides decode the identical symbol here.

  Immediately after, the SAME block's `eob_pt` read (`eob_flag_cdf1024`,
  already libaom-traced via its pre-existing `EC_CDF`/`EC_TRACE` gates,
  no new instrumentation needed there):
    aomdec CDF (icdf) [26070, 24434, 20807, 17006, 12582, 8906, 5334,
      3442, 1686, 718, 0, 0]  ==  ours (converted, increasing)
      [6698, 8334, 11961, 15762, 20186, 23862, 27434, 29326, 31082,
      32050, 32768, 0] -- every entry is an EXACT complement
      (32768-aomdec[i] == ours[i]), proving `eob_pt_1024_luma`'s own
      CDF forwarding is ALSO byte-correct at this point.
    aomdec raw sym=4 (`eob_pt-1`, decodetxb.c's own `EC_CDF decoder2`
      trace)  vs  ours: `TRACE eob_pt value=6` (`group = dec.symbol()+1`,
      so our raw `dec.symbol()` returned 5) -- OFF BY EXACTLY ONE.

CONCLUSION: this rules out CDF forwarding, table selection, and the
tx_type read itself as the cause (all three now proven byte-identical
immediately before the divergent read). The remaining candidates are
narrower than r4 left them:
  1. `msac.rs`'s `symbol_fixed` (the shared decode primitive both this
     table AND every passing table in the suite go through) -- unlikely
     to be generically wrong given the suite's breadth, but not yet
     re-derived by hand against spec 8.2.6 for an 11-symbol read
     specifically (`EC_MIN_PROB * (nsyms - 1 - symbol)` term, `nsyms=11`
     here vs the far more common 2/3/5-symbol tables everywhere else --
     worth checking whether EC_MIN_PROB scaling or the loop's `cur`/`prev`
     arithmetic has an off-by-one that only bites at this width).
  2. A single bit's worth of unaccounted range/`rng` state consumed
     somewhere between the tx_type read's renormalisation and the
     eob_pt read's first comparison -- re-derive `self.range` and
     `self.value` by hand at both points (spec 8.2.6's exact
     `decode_symbol`) rather than trusting the CDF-value comparison
     alone; identical CDF does not guarantee identical `range`/`value`
     entering the read if renormalisation after tx_type diverged by even
     one bit.
  3. Cross-check against a THIRD implementation (dav1d, not just aomdec)
     for this exact eob_pt read to rule out an aomdec-side convention
     quirk in how it reports `symbol=eob_pt-1` (shared-oracle-blindness
     class) -- low priority, aomdec's own reported pixels already
     disagree with ours so it is very unlikely to be a reporting-only
     artifact, but worth naming as the fallback if (1)/(2) both clear.

R6 UPGRADE PATH, IN ORDER:
1. Hand-derive `symbol_fixed`'s loop against spec 8.2.6 for nsyms=11
   specifically, on paper, with the exact CDF values above -- confirm or
   rule out (1) before touching any code.
2. If (1) clears, add a temp `range`/`value` eprintln! (same
   EC_AV1_EOBPT_CDF gate) right after the tx_type read's renormalisation
   and diff against a matching `aom_reader`-internal trace (may need a
   THIRD aomdec rebuild exposing `r->ec.rng`/`r->ec.dif` at that exact
   point, decodetxb.c already prints `rng` via `EC_EOBPT`'s own
   `(unsigned)r->ec.rng` field -- reuse that, don't rebuild again if
   already sufficient) to find where the single bit goes missing.
3. Once found, the previous 16-test regression risk (r4's premise) does
   NOT apply here -- this is a decoder-primitive-level bug, not a
   table-selection one, so a correct fix should not regress any
   currently-green stream (they only pass today because a raw-symbol
   off-by-one at width 11 happens not to matter for their content, or
   they never exercise an 11-wide table with this exact adapted CDF
   shape -- re-run full `cargo test -p ec-av1 --release` after landing
   regardless, per the existing done-criteria).
4. Re-run pin (`EC_AV1_PIN_N=24`) only after (1)-(3) converge.

Instrumentation added this round, env-gated (no behaviour change when
unset): `EC_AV1_EOBPT_CDF` (decode.rs, prints `coding.eob_pt` right
before the read for size-12 tables, and `tx_type_cdf` right before the
read for size-3 tables). External, not committed to this repo:
`/tmp/libaom-src/av1/decoder/decodemv.c`'s new
`EC_INTERTXTYPE_CDF`/`EC_INTERTXTYPE_RAWSYM` (gated on `EC_TRACE2`,
mirrors the pre-existing intra-branch print) -- rebuilt into
`/tmp/libaom-src/build/decoder-debug/aomdec`, this source tree is
outside the repo and NOT reproducible from a fresh checkout; note this
for whoever runs r6 without the same /tmp state.

class: [[reference-layout-not-spec]]'s sibling in the opposite
direction -- r4 trusted a HALF-remembered spec rule (DCTONLY at
tx_size>=32) without checking the is_inter branch, and "fixed" a table
that was already correct; the actual defect turned out to be one level
deeper (the raw symbol decode itself) and only became visible once both
surrounding reads were proven byte-identical first. Lesson: prove the
INPUTS identical (CDF + prior symbol) before suspecting the higher-level
table/forwarding logic, not after.
crates/ec-av1/src/decode.rsmodified+6 -0
@@ -550,6 +550,9 @@ fn read_eob(dec: &mut SymbolDecoder, coding: &mut TxbTables, class: TxClass) ->
550 (TxClass::TwoD, _) | (_, None) => coding.eob_pt,550 (TxClass::TwoD, _) | (_, None) => coding.eob_pt,
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 {
554+ eprintln!("EC_AV1_EOBPT_CDF {eob_pt:?}");
555+ }
553 let group = dec.symbol(eob_pt) + 1;556 let group = dec.symbol(eob_pt) + 1;
554 if trace {557 if trace {
555 eprintln!("TRACE eob_pt value={group}");558 eprintln!("TRACE eob_pt value={group}");
@@ -637,6 +640,9 @@ fn read_coeffs(
637 // share their symbol order with (`Tx_Type_Inter_Inv_Set3`'s two640 // share their symbol order with (`Tx_Type_Inter_Inv_Set3`'s two
638 // members are a prefix of `Tx_Type_Intra_Inv_Set2`'s five).641 // members are a prefix of `Tx_Type_Intra_Inv_Set2`'s five).
639 let len = tx_type_cdf.len();642 let len = tx_type_cdf.len();
643+ if std::env::var_os("EC_AV1_EOBPT_CDF").is_some() && len == 3 {
644+ eprintln!("EC_AV1_TXTYPE32_CDF {tx_type_cdf:?}");
645+ }
640 let t = dec.symbol(tx_type_cdf);646 let t = dec.symbol(tx_type_cdf);
641 if trace {647 if trace {
642 eprintln!("TRACE tx_type value={t} len={len}");648 eprintln!("TRACE tx_type value={t} len={len}");