The inter writer's MV predictor comes from the drl index it SIGNALS
Browse files at this commitd5a42122ac7a6f916d4d4a0e03df7e8e677669a9Parent: d2974e0- fix
- the inter writer's MV predictor comes from the drl index it SIGNALS
1 changed file +23 -7
- crates/ec-av1/src/tile.rs +23 -7
crates/ec-av1/src/tile.rsmodified+23 -7
| @@ -1044,7 +1044,7 @@ fn write_compound_block( | ||
| 1044 | 1044 | } |
| 1045 | 1045 | stack |
| 1046 | 1046 | .entries |
| 1047 | - .get(idx) | |
| 1047 | + .get(walk) | |
| 1048 | 1048 | .map_or(stack.near_mv, |e| (e.mv0, e.mv1)) |
| 1049 | 1049 | } |
| 1050 | 1050 | InterMode::NearestNewMv | InterMode::NewNearestMv => { |
| @@ -1076,7 +1076,7 @@ fn write_compound_block( | ||
| 1076 | 1076 | } |
| 1077 | 1077 | let base = stack |
| 1078 | 1078 | .entries |
| 1079 | - .get(idx) | |
| 1079 | + .get(walk) | |
| 1080 | 1080 | .map_or(stack.nearest_mv, |e| (e.mv0, e.mv1)); |
| 1081 | 1081 | write_mv(enc, &mut cdfs.mv_comp, &mut cdfs.mv_joint, info.mv, base.0)?; |
| 1082 | 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 | 5959 | /// `drl_mode` bit per stack entry past `start`, `1` to advance and `0` to |
| 5960 | 5960 | /// stop, at most two bits. `drl_ctx[idx]` is the context between |
| 5961 | 5961 | /// `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 | 5970 | fn write_drl_idx( |
| 5964 | 5971 | enc: &mut SymbolEncoder, |
| 5965 | 5972 | cdfs: &mut Cdfs, |
| 5966 | 5973 | stack: &crate::mvstack::MvStack, |
| 5967 | 5974 | start: usize, |
| 5968 | 5975 | target: usize, |
| 5969 | -) { | |
| 5976 | +) -> usize { | |
| 5970 | 5977 | let mut idx = start; |
| 5971 | 5978 | while idx < start + 2 && stack.entries.len() > idx + 1 { |
| 5972 | 5979 | let advance = idx < target; |
| 5973 | 5980 | enc.symbol(usize::from(advance), &mut cdfs.drl_mode[stack.drl_ctx[idx]]); |
| 5974 | 5981 | if !advance { |
| 5975 | - return; | |
| 5982 | + return idx; | |
| 5976 | 5983 | } |
| 5977 | 5984 | idx += 1; |
| 5978 | 5985 | } |
| 5986 | + idx | |
| 5979 | 5987 | } |
| 5980 | 5988 | |
| 5981 | 5989 | /// Writer-side counterpart of the decoder's single-reference |
| @@ -6008,7 +6016,7 @@ fn write_inter_mode( | ||
| 6008 | 6016 | match info.mode { |
| 6009 | 6017 | InterMode::NewMv => { |
| 6010 | 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 | 6020 | let base = stack.entries.get(idx).map_or(stack.pred_mv, |e| e.mv); |
| 6013 | 6021 | write_mv(enc, &mut cdfs.mv_comp, &mut cdfs.mv_joint, info.mv, base)?; |
| 6014 | 6022 | note_inter_mode(3, idx); |
| @@ -6033,7 +6041,7 @@ fn write_inter_mode( | ||
| 6033 | 6041 | enc.symbol(1, &mut cdfs.ref_mv[stack.ref_mv_ctx]); // NEARMV |
| 6034 | 6042 | // `RefMvIdx` starts at 1 for NEARMV (spec 5.11.24). |
| 6035 | 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 | 6045 | let mv = stack.entries.get(idx).map_or(stack.near_mv, |e| e.mv); |
| 6038 | 6046 | note_inter_mode(1, idx); |
| 6039 | 6047 | Ok((mv, false)) |
| @@ -6327,6 +6335,10 @@ pub(crate) fn sb_coeff_inter_frame_tile_cdfs( | ||
| 6327 | 6335 | mi_rows as usize, |
| 6328 | 6336 | ); |
| 6329 | 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 | 6342 | (mv, (0, 0), is_new_mv) |
| 6331 | 6343 | }; |
| 6332 | 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 | 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 | 6741 | grid.set( |
| 6726 | 6742 | mi_row, |
| 6727 | 6743 | mi_col, |