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(
1044 }1044 }
1045 stack1045 stack
1046 .entries1046 .entries
1047- .get(idx)1047+ .get(walk)
1048 .map_or(stack.near_mv, |e| (e.mv0, e.mv1))1048 .map_or(stack.near_mv, |e| (e.mv0, e.mv1))
1049 }1049 }
1050 InterMode::NearestNewMv | InterMode::NewNearestMv => {1050 InterMode::NearestNewMv | InterMode::NewNearestMv => {
@@ -1076,7 +1076,7 @@ fn write_compound_block(
1076 }1076 }
1077 let base = stack1077 let base = stack
1078 .entries1078 .entries
1079- .get(idx)1079+ .get(walk)
1080 .map_or(stack.nearest_mv, |e| (e.mv0, e.mv1));1080 .map_or(stack.nearest_mv, |e| (e.mv0, e.mv1));
1081 write_mv(enc, &mut cdfs.mv_comp, &mut cdfs.mv_joint, info.mv, base.0)?;1081 write_mv(enc, &mut cdfs.mv_comp, &mut cdfs.mv_joint, info.mv, base.0)?;
1082 write_mv(enc, &mut cdfs.mv_comp, &mut cdfs.mv_joint, info.mv1, base.1)?;1082 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] {
5959 /// `drl_mode` bit per stack entry past `start`, `1` to advance and `0` to5959 /// `drl_mode` bit per stack entry past `start`, `1` to advance and `0` to
5960 /// stop, at most two bits. `drl_ctx[idx]` is the context between5960 /// stop, at most two bits. `drl_ctx[idx]` is the context between
5961 /// `entries[idx]` and `entries[idx + 1]`, exactly the pair the bit chooses5961 /// `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).
5963 fn write_drl_idx(5970 fn write_drl_idx(
5964 enc: &mut SymbolEncoder,5971 enc: &mut SymbolEncoder,
5965 cdfs: &mut Cdfs,5972 cdfs: &mut Cdfs,
5966 stack: &crate::mvstack::MvStack,5973 stack: &crate::mvstack::MvStack,
5967 start: usize,5974 start: usize,
5968 target: usize,5975 target: usize,
5969-) {5976+) -> usize {
5970 let mut idx = start;5977 let mut idx = start;
5971 while idx < start + 2 && stack.entries.len() > idx + 1 {5978 while idx < start + 2 && stack.entries.len() > idx + 1 {
5972 let advance = idx < target;5979 let advance = idx < target;
5973 enc.symbol(usize::from(advance), &mut cdfs.drl_mode[stack.drl_ctx[idx]]);5980 enc.symbol(usize::from(advance), &mut cdfs.drl_mode[stack.drl_ctx[idx]]);
5974 if !advance {5981 if !advance {
5975- return;5982+ return idx;
5976 }5983 }
5977 idx += 1;5984 idx += 1;
5978 }5985 }
5986+ idx
5979 }5987 }
5980 5988
5981 /// Writer-side counterpart of the decoder's single-reference5989 /// Writer-side counterpart of the decoder's single-reference
@@ -6008,7 +6016,7 @@ fn write_inter_mode(
6008 match info.mode {6016 match info.mode {
6009 InterMode::NewMv => {6017 InterMode::NewMv => {
6010 enc.symbol(0, &mut cdfs.new_mv[stack.new_mv_ctx]);6018 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);
6012 let base = stack.entries.get(idx).map_or(stack.pred_mv, |e| e.mv);6020 let base = stack.entries.get(idx).map_or(stack.pred_mv, |e| e.mv);
6013 write_mv(enc, &mut cdfs.mv_comp, &mut cdfs.mv_joint, info.mv, base)?;6021 write_mv(enc, &mut cdfs.mv_comp, &mut cdfs.mv_joint, info.mv, base)?;
6014 note_inter_mode(3, idx);6022 note_inter_mode(3, idx);
@@ -6033,7 +6041,7 @@ fn write_inter_mode(
6033 enc.symbol(1, &mut cdfs.ref_mv[stack.ref_mv_ctx]); // NEARMV6041 enc.symbol(1, &mut cdfs.ref_mv[stack.ref_mv_ctx]); // NEARMV
6034 // `RefMvIdx` starts at 1 for NEARMV (spec 5.11.24).6042 // `RefMvIdx` starts at 1 for NEARMV (spec 5.11.24).
6035 let idx = idx.max(1);6043 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);
6037 let mv = stack.entries.get(idx).map_or(stack.near_mv, |e| e.mv);6045 let mv = stack.entries.get(idx).map_or(stack.near_mv, |e| e.mv);
6038 note_inter_mode(1, idx);6046 note_inter_mode(1, idx);
6039 Ok((mv, false))6047 Ok((mv, false))
@@ -6327,6 +6335,10 @@ pub(crate) fn sb_coeff_inter_frame_tile_cdfs(
6327 mi_rows as usize,6335 mi_rows as usize,
6328 );6336 );
6329 let (mv, is_new_mv) = write_inter_mode(&mut enc, &mut cdfs, info, &stack)?;6337 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+ ));
6330 (mv, (0, 0), is_new_mv)6342 (mv, (0, 0), is_new_mv)
6331 };6343 };
6332 for dr in 0..SB_MI as usize {6344 for dr in 0..SB_MI as usize {
@@ -6722,6 +6734,10 @@ pub(crate) fn sb_coeff_inter_frame_tile_cdfs(
6722 );6734 );
6723 6735
6724 let (mv, is_new_mv) = write_inter_mode(&mut enc, &mut cdfs, info, &stack)?;6736 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+ ));
6725 grid.set(6741 grid.set(
6726 mi_row,6742 mi_row,
6727 mi_col,6743 mi_col,