forge
Explore
Log in

Don't you dare go Hollow

Switchable_interp compound-block ctx offset

Browse files at this commit

3ab7e16cf3f5559e6092404870386b37147e5b8dAhmet Kaan GümüşParent: c806031
  • fix
    • switchable_interp compound-block ctx offset
    • re-pin second compound_idx defect
Show full message
fix(av1): switchable_interp compound-block ctx offset; re-pin second compound_idx defect

Fix (real, spec-verified): switchable_interp_ctx never folded in libaom's
INTER_FILTER_COMP_OFFSET (av1_get_pred_context_switchable_interp,
pred_common.c) for a block that itself has a second reference -- a stale
"this decoder never codes a compound reference" doc comment baked the
offset to always-0. resolve_interp_filter now takes is_compound and adds
+4 to the CDF context bucket for the compound leaf16 call site only (the
single-ref leaf16 call site passes false; leaf8 still never resolves a
switchable filter at all -- pre-existing documented corner-cut, out of
scope this round).

Bisect (lane-av1idx r1): unmasked both comp_group_idx==0 refusals locally,
looped a_real_aomenc_stream_with_reference_select_reads_comp_mode_correctly
with EC_AV1_GATE_DUMP until a mismatch pinned (seed 61) ->
fixtures/av1idx-refsel-pin.obu. Confirmed deterministic 3x via
scratch_isolate_pinned_mismatch. First divergence: decode-order frame 8
(the stream's one Switchable-interpolation-filter frame), small deltas
(worst 1-2), 149-299 luma px, propagating through frames 9-12 via DPB
reference before frames 13-19 return to MATCH -- consistent with a wrong
CDF context bucket (occasional wrong bit) rather than a hard desync.

Re-tested the pinned fixture after the ctx-offset fix: mismatch UNCHANGED
(same frame, same deltas) -- this fix is real and kept, but does not
explain this fixture's defect. A second, still-unfound compound_idx bug
remains. Re-masked both refusals (still non-pixel-exact beyond the two
bugs now fixed across lane-av1blend r6/r7 + this round).

Next step: scratch_isolate_pinned_mismatch already narrows it to frame 8's
own decode or an upstream DPB slot corruption reaching it -- bisect frame
8's tile decode (EC_TOK/EC_PART trace vs instrumented aomdec) now that the
fixture is small (501 bytes, 20 frames of 64x64) and cheap to iterate on.

Both wide gates green (legal named refusal), cargo test -p ec-av1 --lib
--skip aomenc: 196 passed/0 failed/19 ignored.
crates/ec-av1/src/decode.rsmodified+34 -11
@@ -3644,11 +3644,17 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
36443644
36453645 /// `av1_get_pred_context_switchable_interp`'s context for `interp_filter[dir]`
36463646 /// -- `above`/`left` are the neighbour's own resolved index for this
3647-/// direction (0..=2, or `3` = no info, spec `SWITCHABLE_FILTERS`). This
3648-/// decoder never codes a compound reference, so `INTER_FILTER_COMP_OFFSET`
3649-/// is always 0; only `dir`'s own `INTER_FILTER_DIR_OFFSET` (8) is folded in.
3650-fn switchable_interp_ctx(above: u8, left: u8, dir: usize) -> usize {
3651- let base = dir * 8;
3647+/// direction (0..=2, or `3` = no info, spec `SWITCHABLE_FILTERS`).
3648+/// `is_compound` folds in libaom `av1_get_pred_context_switchable_interp`'s
3649+/// own `ctx_offset` term (`INTER_FILTER_COMP_OFFSET` = 4, added when *this*
3650+/// block itself has a second reference) -- lane-av1idx: a stale "this
3651+/// decoder never codes a compound reference" assumption baked this to
3652+/// always-0, which desynced the CDF context bucket (not the decoded value
3653+/// outright, hence small pixel deltas rather than a hard desync) the moment
3654+/// lane-av1blend unmasked plain-average compound blocks on a Switchable-
3655+/// filter frame.
3656+fn switchable_interp_ctx(above: u8, left: u8, dir: usize, is_compound: bool) -> usize {
3657+ let base = dir * 8 + if is_compound { 4 } else { 0 };
36523658 let term = if left == above {
36533659 left
36543660 } else if left == 3 {
@@ -3679,6 +3685,7 @@ fn resolve_interp_filter(
36793685 force_regular: bool,
36803686 above: [u8; 2],
36813687 left: [u8; 2],
3688+ is_compound: bool,
36823689 ) -> (mc::InterpFilterKind, mc::InterpFilterKind, [u8; 2]) {
36833690 if let Some(kind) = interp_fixed {
36843691 return (kind, kind, [3, 3]);
@@ -3696,10 +3703,10 @@ fn resolve_interp_filter(
36963703 // "horizontal then vertical" despite `predict_with_filters`' own
36973704 // `h_kind`/`v_kind` argument order, which is why this function returns
36983705 // `(h, v, ..)` but reads `dir0` (`v`) before `dir1` (`h`).
3699- let ctx0 = switchable_interp_ctx(above[0], left[0], 0);
3706+ let ctx0 = switchable_interp_ctx(above[0], left[0], 0, is_compound);
37003707 let sym0 = dec.symbol(&mut cdfs.switchable_interp[ctx0]) as u8;
37013708 let sym1 = if enable_dual_filter {
3702- let ctx1 = switchable_interp_ctx(above[1], left[1], 1);
3709+ let ctx1 = switchable_interp_ctx(above[1], left[1], 1, is_compound);
37033710 dec.symbol(&mut cdfs.switchable_interp[ctx1]) as u8
37043711 } else {
37053712 sym0
@@ -4666,11 +4673,22 @@ fn decode_inter_block(
46664673 // 846 pixels not fitting the (9,7)-vs-plain-average hypothesis
46674674 // either) already flagged more than one bug here. Re-masking:
46684675 // do not ship a blend that is right only sometimes.
4676+ // lane-av1idx r1: fixed one real bug this round
4677+ // (`switchable_interp_ctx` never folded in libaom's
4678+ // `INTER_FILTER_COMP_OFFSET` for a compound block's own
4679+ // interp_filter context -- kept). Pinned
4680+ // `fixtures/av1idx-refsel-pin.obu` (seed 61, reference_select
4681+ // gate) still mismatches after that fix (decode-order frame 8
4682+ // first, small deltas, worst 1-2, propagating through later
4683+ // frames via DPB reference) -- a second, still-unfound bug.
4684+ // Re-masking: see that fixture + `scratch_isolate_pinned_mismatch`
4685+ // (`EC_AV1_PIN=fixtures/av1idx-refsel-pin.obu EC_AV1_PIN_N=20`)
4686+ // for the next round's starting point.
46694687 return Err(unsupported(
46704688 "a COMPOUND_REFERENCE 16x16 leaf using the plain/distance-weighted \
46714689 average blend (comp_group_idx == 0) -- proven non-pixel-exact against \
4672- real aomenc streams beyond the one bug lane-av1blend r6/r7 fixed \
4673- (lane-av1blend r7, wide gate sweep)",
4690+ real aomenc streams beyond the bugs lane-av1blend r6/r7 and lane-av1idx \
4691+ r1 fixed (wide gate sweep, fixtures/av1idx-refsel-pin.obu)",
46744692 ));
46754693 #[allow(unreachable_code)]
46764694 let (fwd_offset, bck_offset, compound_idx) = if !skip_mode && enable_jnt_comp {
@@ -4740,6 +4758,7 @@ fn decode_inter_block(
47404758 is_globalmv,
47414759 above_filter_ctx,
47424760 left_filter_ctx,
4761+ true,
47434762 );
47444763 block_filter = resolved_filter;
47454764
@@ -5063,6 +5082,7 @@ fn decode_inter_block(
50635082 is_globalmv,
50645083 above_filter_ctx,
50655084 left_filter_ctx,
5085+ false,
50665086 );
50675087 block_filter = resolved_filter;
50685088 globalmv_for_lf = is_globalmv;
@@ -5580,11 +5600,14 @@ fn decode_inter_block8(
55805600 // as the 16x16 leaf above -- one real bug found and fixed
55815601 // (mvstack.rs ref_ctx family), a second, still-unfound
55825602 // compound_idx defect surfaces on the wide gate sweep.
5603+ // lane-av1idx r1: same re-mask as the 16x16 leaf above --
5604+ // see that comment.
55835605 return Err(unsupported(
55845606 "a COMPOUND_REFERENCE 8x8 leaf using the plain/distance-weighted \
55855607 average blend (comp_group_idx == 0) -- proven non-pixel-exact \
5586- against real aomenc streams beyond the one bug lane-av1blend \
5587- r6/r7 fixed (lane-av1blend r7, wide gate sweep)",
5608+ against real aomenc streams beyond the bugs lane-av1blend r6/r7 \
5609+ and lane-av1idx r1 fixed (wide gate sweep, \
5610+ fixtures/av1idx-refsel-pin.obu)",
55885611 ));
55895612 #[allow(unreachable_code)]
55905613 let (fwd_offset, bck_offset, compound_idx) = if !skip_mode && enable_jnt_comp {