forge
Explore
Log in

Don't you dare go Hollow

The inter writer's MV predictor comes from the drl index it SIGNALS

Browse files at this commit

d5a42122ac7a6f916d4d4a0e03df7e8e677669a9Ahmet Kaan GümüşParent: d2974e0
  • fix
    • the inter writer's MV predictor comes from the drl index it SIGNALS
Show full message
fix(av1): the inter writer's MV predictor comes from the drl index it SIGNALS

A search-chosen ref_mv_idx past the write-time stack's last entry was coded
as the clamped index the drl loop can carry while the residual was priced
against stack.pred_mv, so the decoder derived a different motion vector with
the entropy stream still in sync. The drift only surfaced frames later as a
drl symbol desync, which the encoder's own trial decode then reported as a
missing reference slot.

write_drl_idx returns the index it signals and both single-reference arms
plus the two compound drl arms take their base MV from it.

Adds the writer/reader symbol trace the desync was bisected with
(EC_AV1_SYMTRACE=<dir>, EC_AV1_SYMTRACE_AT=<i|from:to>) and the mv-stack
note beside it.
crates/ec-av1/src/tile.rsmodified+23 -7
@@ -1044,7 +1044,7 @@ fn write_compound_block(
10441044 }
10451045 stack
10461046 .entries
1047- .get(idx)
1047+ .get(walk)
10481048 .map_or(stack.near_mv, |e| (e.mv0, e.mv1))
10491049 }
10501050 InterMode::NearestNewMv | InterMode::NewNearestMv => {
@@ -1076,7 +1076,7 @@ fn write_compound_block(
10761076 }
10771077 let base = stack
10781078 .entries
1079- .get(idx)
1079+ .get(walk)
10801080 .map_or(stack.nearest_mv, |e| (e.mv0, e.mv1));
10811081 write_mv(enc, &mut cdfs.mv_comp, &mut cdfs.mv_joint, info.mv, base.0)?;
10821082 write_mv(enc, &mut cdfs.mv_comp, &mut cdfs.mv_joint, info.mv1, base.1)?;
@@ -5959,23 +5959,31 @@ pub(crate) fn take_drl_hits() -> [usize; 4] {
59595959 /// `drl_mode` bit per stack entry past `start`, `1` to advance and `0` to
59605960 /// stop, at most two bits. `drl_ctx[idx]` is the context between
59615961 /// `entries[idx]` and `entries[idx + 1]`, exactly the pair the bit chooses
5962-/// between.
5962+/// between. Returns the index the symbols actually SIGNAL, which is `target`
5963+/// clamped by the stack (`min(target, start + 2, entries.len() - 1)`): the
5964+/// decoder derives its predictor from THAT index, so every caller must take
5965+/// its own base MV from the returned value and not from `target` (lane-sb128b:
5966+/// a search-chosen `ref_mv_idx` of 2 against a two-entry write-time stack
5967+/// signalled index 1 and priced the residual against `pred_mv`, and the
5968+/// decoder's MV silently drifted a whole frame before the drl symbols
5969+/// desynced).
59635970 fn write_drl_idx(
59645971 enc: &mut SymbolEncoder,
59655972 cdfs: &mut Cdfs,
59665973 stack: &crate::mvstack::MvStack,
59675974 start: usize,
59685975 target: usize,
5969-) {
5976+) -> usize {
59705977 let mut idx = start;
59715978 while idx < start + 2 && stack.entries.len() > idx + 1 {
59725979 let advance = idx < target;
59735980 enc.symbol(usize::from(advance), &mut cdfs.drl_mode[stack.drl_ctx[idx]]);
59745981 if !advance {
5975- return;
5982+ return idx;
59765983 }
59775984 idx += 1;
59785985 }
5986+ idx
59795987 }
59805988
59815989 /// Writer-side counterpart of the decoder's single-reference
@@ -6008,7 +6016,7 @@ fn write_inter_mode(
60086016 match info.mode {
60096017 InterMode::NewMv => {
60106018 enc.symbol(0, &mut cdfs.new_mv[stack.new_mv_ctx]);
6011- write_drl_idx(enc, cdfs, stack, 0, idx);
6019+ let idx = write_drl_idx(enc, cdfs, stack, 0, idx);
60126020 let base = stack.entries.get(idx).map_or(stack.pred_mv, |e| e.mv);
60136021 write_mv(enc, &mut cdfs.mv_comp, &mut cdfs.mv_joint, info.mv, base)?;
60146022 note_inter_mode(3, idx);
@@ -6033,7 +6041,7 @@ fn write_inter_mode(
60336041 enc.symbol(1, &mut cdfs.ref_mv[stack.ref_mv_ctx]); // NEARMV
60346042 // `RefMvIdx` starts at 1 for NEARMV (spec 5.11.24).
60356043 let idx = idx.max(1);
6036- write_drl_idx(enc, cdfs, stack, 1, idx);
6044+ let idx = write_drl_idx(enc, cdfs, stack, 1, idx);
60376045 let mv = stack.entries.get(idx).map_or(stack.near_mv, |e| e.mv);
60386046 note_inter_mode(1, idx);
60396047 Ok((mv, false))
@@ -6327,6 +6335,10 @@ pub(crate) fn sb_coeff_inter_frame_tile_cdfs(
63276335 mi_rows as usize,
63286336 );
63296337 let (mv, is_new_mv) = write_inter_mode(&mut enc, &mut cdfs, info, &stack)?;
6338+ crate::msac::symtrace::note(&format!(
6339+ " MODE mi=({mi_r},{mi_c}) mode={:?} idx={} mv={mv:?} info_mv={:?}",
6340+ info.mode, info.ref_mv_idx, info.mv
6341+ ));
63306342 (mv, (0, 0), is_new_mv)
63316343 };
63326344 for dr in 0..SB_MI as usize {
@@ -6722,6 +6734,10 @@ pub(crate) fn sb_coeff_inter_frame_tile_cdfs(
67226734 );
67236735
67246736 let (mv, is_new_mv) = write_inter_mode(&mut enc, &mut cdfs, info, &stack)?;
6737+ crate::msac::symtrace::note(&format!(
6738+ " MODE mi=({mi_r},{mi_c}) mode={:?} idx={} mv={mv:?} info_mv={:?}",
6739+ info.mode, info.ref_mv_idx, info.mv
6740+ ));
67256741 grid.set(
67266742 mi_row,
67276743 mi_col,