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(
3644 3644
3645 /// `av1_get_pred_context_switchable_interp`'s context for `interp_filter[dir]`3645 /// `av1_get_pred_context_switchable_interp`'s context for `interp_filter[dir]`
3646 /// -- `above`/`left` are the neighbour's own resolved index for this3646 /// -- `above`/`left` are the neighbour's own resolved index for this
3647-/// direction (0..=2, or `3` = no info, spec `SWITCHABLE_FILTERS`). This3647+/// direction (0..=2, or `3` = no info, spec `SWITCHABLE_FILTERS`).
3648-/// decoder never codes a compound reference, so `INTER_FILTER_COMP_OFFSET`3648+/// `is_compound` folds in libaom `av1_get_pred_context_switchable_interp`'s
3649-/// is always 0; only `dir`'s own `INTER_FILTER_DIR_OFFSET` (8) is folded in.3649+/// own `ctx_offset` term (`INTER_FILTER_COMP_OFFSET` = 4, added when *this*
3650-fn switchable_interp_ctx(above: u8, left: u8, dir: usize) -> usize {3650+/// block itself has a second reference) -- lane-av1idx: a stale "this
3651- let base = dir * 8;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 };
3652 let term = if left == above {3658 let term = if left == above {
3653 left3659 left
3654 } else if left == 3 {3660 } else if left == 3 {
@@ -3679,6 +3685,7 @@ fn resolve_interp_filter(
3679 force_regular: bool,3685 force_regular: bool,
3680 above: [u8; 2],3686 above: [u8; 2],
3681 left: [u8; 2],3687 left: [u8; 2],
3688+ is_compound: bool,
3682 ) -> (mc::InterpFilterKind, mc::InterpFilterKind, [u8; 2]) {3689 ) -> (mc::InterpFilterKind, mc::InterpFilterKind, [u8; 2]) {
3683 if let Some(kind) = interp_fixed {3690 if let Some(kind) = interp_fixed {
3684 return (kind, kind, [3, 3]);3691 return (kind, kind, [3, 3]);
@@ -3696,10 +3703,10 @@ fn resolve_interp_filter(
3696 // "horizontal then vertical" despite `predict_with_filters`' own3703 // "horizontal then vertical" despite `predict_with_filters`' own
3697 // `h_kind`/`v_kind` argument order, which is why this function returns3704 // `h_kind`/`v_kind` argument order, which is why this function returns
3698 // `(h, v, ..)` but reads `dir0` (`v`) before `dir1` (`h`).3705 // `(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);
3700 let sym0 = dec.symbol(&mut cdfs.switchable_interp[ctx0]) as u8;3707 let sym0 = dec.symbol(&mut cdfs.switchable_interp[ctx0]) as u8;
3701 let sym1 = if enable_dual_filter {3708 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);
3703 dec.symbol(&mut cdfs.switchable_interp[ctx1]) as u83710 dec.symbol(&mut cdfs.switchable_interp[ctx1]) as u8
3704 } else {3711 } else {
3705 sym03712 sym0
@@ -4666,11 +4673,22 @@ fn decode_inter_block(
4666 // 846 pixels not fitting the (9,7)-vs-plain-average hypothesis4673 // 846 pixels not fitting the (9,7)-vs-plain-average hypothesis
4667 // either) already flagged more than one bug here. Re-masking:4674 // either) already flagged more than one bug here. Re-masking:
4668 // do not ship a blend that is right only sometimes.4675 // 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.
4669 return Err(unsupported(4687 return Err(unsupported(
4670 "a COMPOUND_REFERENCE 16x16 leaf using the plain/distance-weighted \4688 "a COMPOUND_REFERENCE 16x16 leaf using the plain/distance-weighted \
4671 average blend (comp_group_idx == 0) -- proven non-pixel-exact against \4689 average blend (comp_group_idx == 0) -- proven non-pixel-exact against \
4672- real aomenc streams beyond the one bug lane-av1blend r6/r7 fixed \4690+ real aomenc streams beyond the bugs lane-av1blend r6/r7 and lane-av1idx \
4673- (lane-av1blend r7, wide gate sweep)",4691+ r1 fixed (wide gate sweep, fixtures/av1idx-refsel-pin.obu)",
4674 ));4692 ));
4675 #[allow(unreachable_code)]4693 #[allow(unreachable_code)]
4676 let (fwd_offset, bck_offset, compound_idx) = if !skip_mode && enable_jnt_comp {4694 let (fwd_offset, bck_offset, compound_idx) = if !skip_mode && enable_jnt_comp {
@@ -4740,6 +4758,7 @@ fn decode_inter_block(
4740 is_globalmv,4758 is_globalmv,
4741 above_filter_ctx,4759 above_filter_ctx,
4742 left_filter_ctx,4760 left_filter_ctx,
4761+ true,
4743 );4762 );
4744 block_filter = resolved_filter;4763 block_filter = resolved_filter;
4745 4764
@@ -5063,6 +5082,7 @@ fn decode_inter_block(
5063 is_globalmv,5082 is_globalmv,
5064 above_filter_ctx,5083 above_filter_ctx,
5065 left_filter_ctx,5084 left_filter_ctx,
5085+ false,
5066 );5086 );
5067 block_filter = resolved_filter;5087 block_filter = resolved_filter;
5068 globalmv_for_lf = is_globalmv;5088 globalmv_for_lf = is_globalmv;
@@ -5580,11 +5600,14 @@ fn decode_inter_block8(
5580 // as the 16x16 leaf above -- one real bug found and fixed5600 // as the 16x16 leaf above -- one real bug found and fixed
5581 // (mvstack.rs ref_ctx family), a second, still-unfound5601 // (mvstack.rs ref_ctx family), a second, still-unfound
5582 // compound_idx defect surfaces on the wide gate sweep.5602 // 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.
5583 return Err(unsupported(5605 return Err(unsupported(
5584 "a COMPOUND_REFERENCE 8x8 leaf using the plain/distance-weighted \5606 "a COMPOUND_REFERENCE 8x8 leaf using the plain/distance-weighted \
5585 average blend (comp_group_idx == 0) -- proven non-pixel-exact \5607 average blend (comp_group_idx == 0) -- proven non-pixel-exact \
5586- against real aomenc streams beyond the one bug lane-av1blend \5608+ against real aomenc streams beyond the bugs lane-av1blend r6/r7 \
5587- r6/r7 fixed (lane-av1blend r7, wide gate sweep)",5609+ and lane-av1idx r1 fixed (wide gate sweep, \
5610+ fixtures/av1idx-refsel-pin.obu)",
5588 ));5611 ));
5589 #[allow(unreachable_code)]5612 #[allow(unreachable_code)]
5590 let (fwd_offset, bck_offset, compound_idx) = if !skip_mode && enable_jnt_comp {5613 let (fwd_offset, bck_offset, compound_idx) = if !skip_mode && enable_jnt_comp {