forge
Explore
Log in

Don't you dare go Hollow

wip(av1): trace skip_mode/compound_idx on the sb128-compound-refs pin -- NOT the compound blend, it is skip_mode desync

Browse files at this commit

15f253dabf2f30000a2dd2a065326627bd782fbdAhmet Kaan GümüşParent: e48aa4c
COMPILES. Does not fix the pin (still mismatches). round 2 of lane-comppin,
capped at budget -- leaving the decisive lead + instrumentation for round 3.

WHAT THIS ROUND RULED OUT (all re-verified against libaom source, all correct):
- mc.rs predict_compound_intermediate/combine_compound: CONV_BUF-domain i32
  intermediates, round2 offsets, INTER_ROUND_1_COMPOUND=7/INTER_POST_ROUND=4/
  DIST_PRECISION_BITS=4 all match av1_dist_wtd_convolve_2d_c bit-for-bit
  (already landed pre-r1, re-audited this round, still correct).
- compound.rs dist_wtd_comp_weight_assign: QUANT_DIST_WEIGHT/LOOKUP_TABLE
  match libaom's reconinter.c/common_data.h row-for-row.
- decode.rs get_comp_index_context / get_comp_group_idx_context: match
  pred_common.c av1_get_comp_index_context/av1_get_pred_context_comp_group_idx
  line for line, including the single-ref ALTREF_FRAME special case
  (Neighbours::record_inter's altref bit at decode.rs ~1028-1032).
- reference_mode_ctx (mvstack.rs ~1876): matches av1_get_reference_mode_context
  exactly, including the has_second_ref asymmetric branches.
- read_skip_mode_params (ec-av1-syntax/src/frame.rs:1644): matches spec 5.9.22's
  skipModeAllowed forward/backward-ref search verbatim.

THE ACTUAL DEFECT (new this round): decode-order frame 1 of the pin
(sb128-compound-refs-flake.obu, EC_AV1_PIN_N=24) is 4x 32x32 leaves, all
identical: ref0=LAST(1) ref1=ALTREF(7 or 5), mv=(0,0)/(0,0), mode
NEAREST_NEARESTMV, compound_idx=1 (plain average) -- EVERY block reads
skip_mode=true (added EC_AV1_COMPIDX_DUMP trace at decode.rs ~5017/~6022,
EC_PRECOMP trace at ~4671 dumps skip_mode/skip/reference_select/tell before
the comp_mode read).

Cross-checked against a real instrumented aomdec (rebuilt
/tmp/libaom-src/build/decoder-debug/aomdec with a `mbmi->compound_idx` field
added to decodemv.c's existing EC_TRACE fprintf ~1671-1685, since the prior
round's patch only traced comp_group_idx not compound_idx): the REAL
bitstream's frame 1 block (0,0) is `ref=(1,-1)` -- SINGLE reference LAST_FRAME,
real coded MV (-2,-8) in 1/8-pel, skip_mode is NEVER forced there. Any true
skip_mode block would be forced compound by spec 5.11.24 -- a single-ref
result at that block proves the real bitstream's skip_mode bit read false
there, not true.

skip_mode_present (the frame-level bit, spec 5.9.22) is very likely read
correctly -- header fields after it (force_integer_mv, primary_ref_frame,
etc, dumped for all 24 frames by the existing scratch_isolate_pinned_mismatch
test) look sane and stay sane for the rest of the stream, which would not
survive a header-level bit-count desync this early. So the bug is specific to
the PER-BLOCK skip_mode symbol read at decode.rs ~4623 (skip_mode_ctx =
above_skip_mode[c] + left_skip_mode[r], SKIP_MODE cdf table cdf.rs:1206):
`SKIP_MODE = [[32621,32768,0], [20708,32768,0], [8127,32768,0]]` (verified
byte-identical to libaom's default_skip_mode_cdfs) means ctx=0 (both
neighbours false, true at any tile's mi_row=0/mi_col=0 corner if Neighbours
resets its skip_mode arrays per frame) has ~99.6% weight on skip_mode=false
-- decoding true there, then AGAIN at (0,8)/(8,0)/(8,8) (all four leaves of
the frame, tell values repeating 8/16/24 across MANY of the 24 frames, not
just frame 1) is not plausible as a correctly-drawn symbol from that CDF. The
leading hypothesis: `Neighbours::above_skip_mode`/`left_skip_mode` are stale
(not reset per frame, or reset at the wrong granularity) so skip_mode_ctx is
NOT actually 0 at (0,0) despite no real neighbour existing yet -- OR the same
DPB/ref_frame_idx bookkeeping the r1-era av1blend investigation already
flagged (ref_slots/refresh_frame_flags) is corrupting `skip_mode_frame`'s
own reference *pair* (LAST vs ALTREF/BWDREF getting mixed up across frames --
note ref1 alternates 7/5/4 across frames in the EC_COMPIDX dump, tracking
DPB slot churn) even when the boolean itself is right.

UPGRADE PATH for round 3, in order:
1. Print skip_mode_ctx (not just skip_mode) at every read (the second Edit
   attempt this round hit "2 matches, use replace_all" on the identical
   leaf16/leaf8 skip_mode block -- disambiguate by including the `skip_ctx`
   line that follows, which differs between the two call sites) and confirm
   ctx is really 0 at (0,0) of frame 1. If ctx != 0, the neighbour-array
   reset is the bug (grep Neighbours::new / wherever it's re-constructed
   per frame in decode_stream, stream.rs).
2. If ctx IS 0 and the symbol still reads 1, instrument SymbolDecoder::symbol
   itself (msac.rs) to dump (cdf_before, symbol_read, rng, value) for this
   ONE call across frames 1-3 and diff against a fresh COMPIDX_BLK-style hook
   in decodemv.c's own skip_mode read (~line before 1656 in
   /tmp/libaom-src/av1/decoder/decodemv.c -- not yet added, do this first).
3. Only after (1)/(2) rule out a local read bug: chase the DPB/ref_frame_idx
   bookkeeping the ref1=7/5/4 churn hints at (stream.rs's ref_slots /
   refresh_frame_flags, same suspect the pre-existing decode.rs ~4832-4845
   comment already named for a different fixture).

Gates a_real_aomenc_stream_with_compound_references_decodes_pixel_exact /
_reference_select_ NOT yet given the self-pin-on-failure treatment (step 4 of
the charter) -- deferred to round 3, no budget left this round.

Instrumented aomdec debug build lives at
/tmp/libaom-src/build/decoder-debug/aomdec (not repo-tracked, rebuild with
`make -j12 aomdec` there if it goes stale); its decodemv.c EC_TRACE fprintf
now also carries mbmi->compound_idx.
crates/ec-av1/src/decode.rsmodified+18 -0
@@ -4668,6 +4668,12 @@ fn decode_inter_block(
4668 uni: neighbours.left_ref1[r]4668 uni: neighbours.left_ref1[r]
4669 .is_some_and(|r1| is_uni_comp_ref(neighbours.left_ref[r], r1)),4669 .is_some_and(|r1| is_uni_comp_ref(neighbours.left_ref[r], r1)),
4670 });4670 });
4671+ if std::env::var_os("EC_AV1_COMPIDX_DUMP").is_some() {
4672+ eprintln!(
4673+ "EC_PRECOMP r={r} c={c} skip_mode={skip_mode} skip={skip} reference_select={reference_select} tell={}",
4674+ dec.debug_bitpos()
4675+ );
4676+ }
4671 let is_compound =4677 let is_compound =
4672 skip_mode || (reference_select && read_comp_mode(dec, cdfs, above_nbr, left_nbr));4678 skip_mode || (reference_select && read_comp_mode(dec, cdfs, above_nbr, left_nbr));
4673 if is_compound {4679 if is_compound {
@@ -5015,6 +5021,12 @@ fn decode_inter_block(
5015 (8, 8, 1u8)5021 (8, 8, 1u8)
5016 };5022 };
5017 compound_ctx = Some((ref1, comp_group_idx as u8, compound_idx));5023 compound_ctx = Some((ref1, comp_group_idx as u8, compound_idx));
5024+ if std::env::var_os("EC_AV1_COMPIDX_DUMP").is_some() {
5025+ eprintln!(
5026+ "EC_COMPIDX mi_row={mi_row} mi_col={mi_col} bsize={side} mode={compound_mode} mv0=({},{}) mv1=({},{}) ref0={ref0} ref1={ref1} comp_group_idx={comp_group_idx} compound_idx={compound_idx} tell={}",
5027+ mv0.0, mv0.1, mv1.0, mv1.1, dec.debug_bitpos()
5028+ );
5029+ }
5018 5030
5019 // spec 5.11.19/libaom `decodemv.c` 1575: `read_mb_interp_filter`5031 // spec 5.11.19/libaom `decodemv.c` 1575: `read_mb_interp_filter`
5020 // comes AFTER `read_compound_type` (the `comp_group_idx`/5032 // comes AFTER `read_compound_type` (the `comp_group_idx`/
@@ -6014,6 +6026,12 @@ fn decode_inter_block8(
6014 (8, 8, 1u8)6026 (8, 8, 1u8)
6015 };6027 };
6016 compound_ctx8 = Some((ref0, ref1, comp_group_idx as u8, compound_idx));6028 compound_ctx8 = Some((ref0, ref1, comp_group_idx as u8, compound_idx));
6029+ if std::env::var_os("EC_AV1_COMPIDX_DUMP").is_some() {
6030+ eprintln!(
6031+ "EC_COMPIDX mi_row={mi_row} mi_col={mi_col} bsize=8 mode={compound_mode} mv0=({},{}) mv1=({},{}) ref0={ref0} ref1={ref1} comp_group_idx={comp_group_idx} compound_idx={compound_idx} tell={}",
6032+ mv0.0, mv0.1, mv1.0, mv1.1, dec.debug_bitpos()
6033+ );
6034+ }
6017 6035
6018 let (py0, pu0, pv0) = ref_planes(ref0, ref_y, ref_u, ref_v, other_refs)?;6036 let (py0, pu0, pv0) = ref_planes(ref0, ref_y, ref_u, ref_v, other_refs)?;
6019 let (py1, pu1, pv1) = ref_planes(ref1, ref_y, ref_u, ref_v, other_refs)?;6037 let (py1, pu1, pv1) = ref_planes(ref1, ref_y, ref_u, ref_v, other_refs)?;