forge
Explore
Log in

Don't you dare go Hollow

R5 -- interp_filter read-order spec bug (real, inert on this fixture)

Browse files at this commit

4d7335c0fd41bf6b3a83d45d4fa256b1bf1052ceAhmet Kaan GümüşParent: dc3404f
  • fix
    • r5 -- interp_filter read-order spec bug (real, inert on this fixture)
    • re-mask leaf16 blend, deepen compound_idx trace
Show full message
fix(av1): r5 -- interp_filter read-order spec bug (real, inert on this fixture); re-mask leaf16 blend, deepen compound_idx trace

Two things this round:

1. Real bug, independently found and fixed: `resolve_interp_filter`'s
   symbol read sat BEFORE `comp_group_idx`/`compound_idx` in the compound
   leaf16 path. Spec 5.11.19 / libaom decodemv.c:1575 reads
   `read_mb_interp_filter` AFTER `read_compound_type`, not before. Moved
   the call to after the compound_idx read (still before its h_filter/
   v_filter are used for MC). Confirmed via a one-off dump that this
   fixture's own stream carries `interp_fixed = Some(Regular)` (fixed,
   non-Switchable filter), so the reorder moves zero bits here and does
   NOT explain the fixture's mismatch -- kept anyway as a genuine,
   independently-verified spec-order fix for the next Switchable-filter
   compound stream.

2. r4 had left leaf16's compound blend UNMASKED (live) with no gate rerun;
   confirmed this round that live state FAILS both compound gates (frame
   17 luma mismatch, seed 42). Re-added leaf16's refusal-by-name (matching
   leaf8's existing one), restoring both compound gates to green
   (a_real_aomenc_stream_with_compound_references_decodes_pixel_exact,
   a_real_aomenc_stream_with_reference_select_reads_comp_mode_correctly,
   1x each) and the full `cargo test -p ec-av1 --release --lib` suite to
   213 passed / 1 failed (bwdref-reference gate, known parallel-run flake
   per ledger's "PID-keyed temp path" class -- green standalone).

Root cause of the actual compound_idx mismatch is still open. This round
falsified: CDF-forwarding-map gap (rebuilt+ran the instrumented aomdec's
own COMPIDX_PRE dump -- ctx0..ctx5 identical to ours at the same frame,
byte for byte) and the interp_filter reorder (inert here, see above).
Comparing `SymbolDecoder::debug_bitpos()` to aomdec's `aom_reader_tell()`
is NOT a valid probe (different quantities -- see the code comment right
above the restored refusal) -- do not repeat it. Next real lead: audit
`read_comp_mode`/`read_compound_ref_frames`/`read_inter_compound_mode`'s
own context computations for this exact (LAST, BWDREF) pair -- all three
decode the SAME symbol values as aomdec on this block (ref0=1, ref1=5,
mode=NEAREST_NEARESTMV), which does not rule out a context/CDF mismatch
that happens to decode the same value while still narrowing `range` by a
different amount than aomdec, drifting entropy state into the next read
(compound_idx) without ever showing up as a value mismatch upstream.

Scratch instrumentation kept, not cleaned up (r1-r5 EC_AV1_COMPIDX_DUMP/
EC_AV1_COMPOUND_DEBUG dumps, IFILTER_PRE/BITPOS_BLK_START additions this
round, scratch_dump_compound_idx_cdf_state/scratch_sweep_compound_mismatch
tests) -- budget spent on the bisection above, not cleanup.
crates/ec-av1/src/decode.rsmodified+85 -11
@@ -4299,6 +4299,14 @@ fn decode_inter_block(
4299 let (cpx, cpy) = (px / 2, py / 2);4299 let (cpx, cpy) = (px / 2, py / 2);
4300 let chroma_side = side / 2;4300 let chroma_side = side / 2;
4301 4301
4302+ if std::env::var_os("EC_AV1_COMPIDX_DUMP").is_some() {
4303+ eprintln!(
4304+ "BITPOS_BLK_START mi_row={} mi_col={} bitpos={}",
4305+ py / 4,
4306+ px / 4,
4307+ dec.debug_bitpos()
4308+ );
4309+ }
4302 let skip_mode_ctx =4310 let skip_mode_ctx =
4303 usize::from(neighbours.above_skip_mode[c]) + usize::from(neighbours.left_skip_mode[r]);4311 usize::from(neighbours.above_skip_mode[c]) + usize::from(neighbours.left_skip_mode[r]);
4304 let skip_mode = skip_mode_present && dec.symbol(&mut cdfs.skip_mode[skip_mode_ctx]) == 1;4312 let skip_mode = skip_mode_present && dec.symbol(&mut cdfs.skip_mode[skip_mode_ctx]) == 1;
@@ -4418,16 +4426,6 @@ fn decode_inter_block(
4418 } else {4426 } else {
4419 [3, 3]4427 [3, 3]
4420 };4428 };
4421- let (h_filter, v_filter, resolved_filter) = resolve_interp_filter(
4422- dec,
4423- cdfs,
4424- interp_fixed,
4425- enable_dual_filter,
4426- is_globalmv,
4427- above_filter_ctx,
4428- left_filter_ctx,
4429- );
4430- block_filter = resolved_filter;
4431 globalmv_for_lf = is_globalmv;4429 globalmv_for_lf = is_globalmv;
4432 ref_frame_for_lf = ref0;4430 ref_frame_for_lf = ref0;
4433 mode_for_tx = 0;4431 mode_for_tx = 0;
@@ -4600,6 +4598,52 @@ fn decode_inter_block(
4600 // read specifically, not just the surrounding mode/mv/skip4598 // read specifically, not just the surrounding mode/mv/skip
4601 // trace which does match -- the desync (if any) is local to4599 // trace which does match -- the desync (if any) is local to
4602 // this one read, not a wider stream desync.4600 // this one read, not a wider stream desync.
4601+ //
4602+ // r5 (this round): the `resolve_interp_filter` call used to sit
4603+ // right here, ahead of `comp_group_idx`/`compound_idx` -- spec
4604+ // 5.11.19/libaom `decodemv.c:1575` reads `interp_filter` AFTER
4605+ // `read_compound_type`, not before, so that was a genuine
4606+ // ordering bug for a Switchable-filter frame (moved below, past
4607+ // the `compound_ctx = Some(...)` line). It does NOT explain this
4608+ // fixture's own mismatch, though: `av1blend-r1-mismatch.obu`'s
4609+ // header carries a *fixed* interpolation filter
4610+ // (`interp_fixed = Some(Regular)`, confirmed live via a
4611+ // one-off dump), so `resolve_interp_filter` never read a symbol
4612+ // in either position -- zero bits moved, decoded values
4613+ // unchanged before and after the reorder. Kept anyway: it is a
4614+ // real spec-order fix for the next Switchable-filter compound
4615+ // stream, independently correct regardless of this fixture.
4616+ //
4617+ // Also ruled out this round: comparing this crate's own
4618+ // `SymbolDecoder::debug_bitpos()` against aomdec's
4619+ // `aom_reader_tell()` at the block boundary is NOT a valid
4620+ // desync probe -- they are different quantities (raw consumed
4621+ // input bits vs. an entropy-cost estimate that advances without
4622+ // a literal byte fetch), so equal/unequal bitpos proves nothing
4623+ // either way. Do not repeat that comparison; instead trace
4624+ // `range`/`value` (this crate) against libaom's own internal
4625+ // `dif`/`rng` (needs new instrumentation in both) immediately
4626+ // after each read *upstream* of this one in the same block:
4627+ // `read_comp_mode`, `read_compound_ref_frames` (comp_ref_type/
4628+ // uni_comp_ref/comp_ref/comp_bwdref), `read_inter_compound_mode`,
4629+ // and the DRL loop. All of those independently decoded the SAME
4630+ // values this crate and aomdec both show (ref0=1, ref1=5, mode
4631+ // NEAREST_NEARESTMV, mv=(0,0)) -- but an upstream *context*
4632+ // miscomputation can still decode the identical symbol value off
4633+ // a slightly different CDF, narrowing `range` by a different
4634+ // amount than aomdec without changing the decoded value itself,
4635+ // and only surface as a wrong decode a few reads later exactly
4636+ // like this. `get_comp_index_context` and the `COMPOUND_IDX`
4637+ // table were independently re-verified again this round and are
4638+ // still correct; the four candidates above were not re-audited
4639+ // this round. Refusing here (rather than shipping a value-exact-
4640+ // most-of-the-time blend) until one of them is found wrong.
4641+ return Err(unsupported(
4642+ "a COMPOUND_REFERENCE 16x16 leaf using the plain/distance-weighted average \
4643+ blend (comp_group_idx == 0) -- proven non-pixel-exact against a real aomenc \
4644+ stream (lane-av1blend r1/r3/r5, see av1blend-r1-mismatch.obu)",
4645+ ));
4646+ #[allow(unreachable_code)]
4603 let (fwd_offset, bck_offset, compound_idx) = if !skip_mode && enable_jnt_comp {4647 let (fwd_offset, bck_offset, compound_idx) = if !skip_mode && enable_jnt_comp {
4604 let idx_ctx = get_comp_index_context(4648 let idx_ctx = get_comp_index_context(
4605 neighbours,4649 neighbours,
@@ -4622,7 +4666,12 @@ fn decode_inter_block(
4622 }4666 }
4623 let idx = dec.symbol(&mut cdfs.compound_idx[idx_ctx]);4667 let idx = dec.symbol(&mut cdfs.compound_idx[idx_ctx]);
4624 if std::env::var_os("EC_AV1_COMPIDX_DUMP").is_some() {4668 if std::env::var_os("EC_AV1_COMPIDX_DUMP").is_some() {
4625- eprintln!("COMPIDX_VAL mi_row={} mi_col={} decoded={idx}", py / 4, px / 4);4669+ eprintln!(
4670+ "COMPIDX_VAL mi_row={} mi_col={} decoded={idx} bitpos={}",
4671+ py / 4,
4672+ px / 4,
4673+ dec.debug_bitpos()
4674+ );
4626 }4675 }
4627 if idx == 1 {4676 if idx == 1 {
4628 (8, 8, 1u8)4677 (8, 8, 1u8)
@@ -4640,6 +4689,31 @@ fn decode_inter_block(
4640 };4689 };
4641 compound_ctx = Some((ref1, comp_group_idx as u8, compound_idx));4690 compound_ctx = Some((ref1, comp_group_idx as u8, compound_idx));
4642 4691
4692+ // spec 5.11.19/libaom `decodemv.c` 1575: `read_mb_interp_filter`
4693+ // comes AFTER `read_compound_type` (the `comp_group_idx`/
4694+ // `compound_idx` reads just above), not before -- moved here
4695+ // (lane-av1blend r5) from its old position ahead of those reads,
4696+ // which stole their bits for a Switchable-filter compound block
4697+ // and desynced every symbol read after it in the tile.
4698+ if std::env::var_os("EC_AV1_COMPIDX_DUMP").is_some() {
4699+ eprintln!(
4700+ "IFILTER_PRE mi_row={} mi_col={} interp_fixed={:?} is_globalmv={is_globalmv}",
4701+ py / 4,
4702+ px / 4,
4703+ interp_fixed
4704+ );
4705+ }
4706+ let (h_filter, v_filter, resolved_filter) = resolve_interp_filter(
4707+ dec,
4708+ cdfs,
4709+ interp_fixed,
4710+ enable_dual_filter,
4711+ is_globalmv,
4712+ above_filter_ctx,
4713+ left_filter_ctx,
4714+ );
4715+ block_filter = resolved_filter;
4716+
4643 let mut inter0_y = vec![0i32; side * side];4717 let mut inter0_y = vec![0i32; side * side];
4644 mc::predict_compound_intermediate(4718 mc::predict_compound_intermediate(
4645 &py0.data,4719 &py0.data,