forge
Explore
Log in

Don't you dare go Hollow

Use the drl-selected stack entry as NEWMV's base predictor

Browse files at this commit

f5ee53bc8fd6f9591592eb3c0feb17c2484cbd79Ahmet Kaan GümüşParent: 821ba2f
  • fix
    • use the drl-selected stack entry as NEWMV's base predictor
Show full message
fix(av1): use the drl-selected stack entry as NEWMV's base predictor

decode_inter_block's NEWMV arm read the drl_mode bit (when the stack has
more than one entry) but discarded it and always based the predicted MV
on stack.entries[0] -- spec 5.11.24's read_drl_idx picks RefMvIdx via up
to two drl_mode reads, and 7.10.2.10's assign_mv bases NEWMV's PredMv on
entries[RefMvIdx], not always entry 0. Ported the same idx-selection loop
NEARMV already had (mirrored in both NEWMV arms: decode_inter_block and
the leaf8 decoder). Confirmed against a patched aomdec (read_drl_idx
trace) that libaom reads the identical number of drl bits per NEWMV
stack size -- the desync was purely which entry we fed to read_mv.

Verified against the round's pinned 4-frame stream (seed 44): frames 0-2
now decode pixel-exact against ffmpeg/aomdec (frame idx2 was the
decisive divergent case -- mi_row=4,mi_col=8 NEWMV column now matches).

Frame 3 (and the pre-existing a_real_aomenc_inter_sequence_with_cdf_
forwarding flake) still mismatches -- traced to a second, real defect:
mvstack.rs's IMMEDIATE_WEIGHT=2-per-cell approximation is only tied
between above/left neighbours for the fixed bw4==bh4==8 caller the
module doc assumes (tile.rs); decode.rs calls find_mv_stack with the
leaf's real (smaller/mixed) block size, where libaom's real weight
formula (`len * max(2, inc)`, scan_row_mbmi/scan_col_mbmi,
mvref_common.c) is *not* tied -- confirmed live against a patched
libaom at mi_row=4,mi_col=8/frame 3: real weights 660 vs 668 (raw 20 vs
28), ours ties both at 8, giving the wrong stack order and hence the
wrong DRL-selected entry despite an identical drl_mode bit value. This
is the module doc's own predicted gap ("A caller with mixed block sizes
would need the real weight formula; none exists today") now confirmed
reachable and needs a dedicated port of the real weight formula --
follow-up lane, not attempted here (budget).
crates/ec-av1/src/decode.rsmodified+28 -6
@@ -3669,15 +3669,26 @@ fn decode_inter_block(
36693669 let not_new = dec.symbol(&mut cdfs.new_mv[stack.new_mv_ctx]) == 1;
36703670 let mut is_globalmv = false;
36713671 let (mv, is_new_mv) = if !not_new {
3672- if stack.entries.len() > 1 {
3673- dec.symbol(&mut cdfs.drl_mode[stack.drl_ctx[0]]);
3672+ // NEWMV (spec 5.11.24's `read_drl_idx`, `RefMvIdx` starting at 0):
3673+ // read at most two `drl_mode` bits, one per stack entry past the
3674+ // first, stopping at the first `0`. The chosen index selects
3675+ // which stack entry `read_mv`'s base predictor comes from
3676+ // (spec 7.10.2.10 `assign_mv`'s `PredMv = RefStackMv[RefMvIdx]`)
3677+ // -- entry 0 (`stack.pred_mv`) only when the loop never advances.
3678+ let mut idx = 0usize;
3679+ while idx < 2 && stack.entries.len() > idx + 1 {
3680+ if dec.symbol(&mut cdfs.drl_mode[stack.drl_ctx[idx]]) == 0 {
3681+ break;
3682+ }
3683+ idx += 1;
36743684 }
3685+ let base_mv = stack.entries.get(idx).map_or(stack.pred_mv, |e| e.mv);
36753686 (
36763687 read_mv(
36773688 dec,
36783689 &mut cdfs.mv_comp,
36793690 &mut cdfs.mv_joint,
3680- stack.pred_mv,
3691+ base_mv,
36813692 allow_high_precision_mv,
36823693 ),
36833694 true,
@@ -4111,15 +4122,26 @@ fn decode_inter_block8(
41114122
41124123 let not_new = dec.symbol(&mut cdfs.new_mv[stack.new_mv_ctx]) == 1;
41134124 let (mv, is_new_mv) = if !not_new {
4114- if stack.entries.len() > 1 {
4115- dec.symbol(&mut cdfs.drl_mode[stack.drl_ctx[0]]);
4125+ // NEWMV (spec 5.11.24's `read_drl_idx`, `RefMvIdx` starting at 0):
4126+ // read at most two `drl_mode` bits, one per stack entry past the
4127+ // first, stopping at the first `0`. The chosen index selects
4128+ // which stack entry `read_mv`'s base predictor comes from
4129+ // (spec 7.10.2.10 `assign_mv`'s `PredMv = RefStackMv[RefMvIdx]`)
4130+ // -- entry 0 (`stack.pred_mv`) only when the loop never advances.
4131+ let mut idx = 0usize;
4132+ while idx < 2 && stack.entries.len() > idx + 1 {
4133+ if dec.symbol(&mut cdfs.drl_mode[stack.drl_ctx[idx]]) == 0 {
4134+ break;
4135+ }
4136+ idx += 1;
41164137 }
4138+ let base_mv = stack.entries.get(idx).map_or(stack.pred_mv, |e| e.mv);
41174139 (
41184140 read_mv(
41194141 dec,
41204142 &mut cdfs.mv_comp,
41214143 &mut cdfs.mv_joint,
4122- stack.pred_mv,
4144+ base_mv,
41234145 allow_high_precision_mv,
41244146 ),
41254147 true,