forge
Explore
Log in

Don't you dare go Hollow

The saved motion field kept only the LAST tile's columns -- av1_copy_frame_mvs read the mi grid through the per-tile reach clamp

Browse files at this commit

ba5351f32be9ced7d53bb7ce6ce285f4a351e62eAhmet Kaan GümüşParent: 54a60c1
  • fix
    • the saved motion field kept only the LAST tile's columns -- av1_copy_frame_mvs read the mi grid through the per-tile reach clamp
Show full message
fix(av1): the saved motion field kept only the LAST tile's columns -- av1_copy_frame_mvs read the mi grid through the per-tile reach clamp

`build_motion_field` (this crate's `av1_copy_frame_mvs`) walks the whole
frame's mi grid AFTER the tile loop has finished, when `MiGrid`'s tile
window is still narrowed to the last tile. `MiGrid::get` returns `None`
outside that window, so every tile but the last saved no motion vectors at
all: on the pinned 192x68 2-tile-column stream the saved field held only
mi_col 32..47, and the next frame's temporal (MFMV) candidates over the
whole left two thirds silently vanished from the MV stack. The entropy
stream still matched symbol for symbol -- a missing weight-2 temporal vote
only reorders the stack -- so a NEW_NEWMV block at mi(0,24) took stack[1]
= (36,0) (the compound extension's zero-fill) instead of libaom's (0,0),
predicting 32 px off and leaving a 32-px-wide wrong column band.

New `MiGrid::get_frame` is the unclamped frame-level read; only
`build_motion_field` uses it. Rungs added with it: `EC_TPL` (per frame:
use_ref_frame_mvs + filled projected cells) and `EC_TRACE_TPL`'s new
`EC_TPL_SAVED` occupancy map of the saved field, which is what showed the
16-column hole.

Pre-filter reconstruction of all 6 decode-order frames of the pinned
stream goes 1306/3358/5027/6622 wrong luma px (frames 2..5) -> 0.
crates/ec-av1/src/decode.rsmodified+7 -1
@@ -2997,7 +2997,7 @@ pub(crate) fn build_motion_field(
29972997 const REFMVS_LIMIT: i32 = (1 << 12) - 1;
29982998 for row in 0..mi_rows {
29992999 for col in 0..mi_cols {
3000- let Some(info) = grid.get(row, col) else {
3000+ let Some(info) = grid.get_frame(row, col) else {
30013001 continue;
30023002 };
30033003 // `av1_copy_frame_mvs` runs for EVERY block of an inter frame and
@@ -3036,6 +3036,12 @@ pub(crate) fn build_motion_field(
30363036 field.set(row, col, saved);
30373037 }
30383038 }
3039+ if std::env::var_os("EC_TRACE_TPL").is_some() {
3040+ eprintln!("EC_TPL_SAVED oh={order_hint}");
3041+ for (r, row) in field.occupancy().iter().enumerate() {
3042+ eprintln!("EC_TPL_SAVED r{r} {row}");
3043+ }
3044+ }
30393045 field
30403046 }
30413047
crates/ec-av1/src/motion_field.rsmodified+19 -0
@@ -75,6 +75,18 @@ impl MotionField {
7575 }
7676 }
7777
78+ /// lane-mergefix r5 rung (`EC_TRACE_TPL`): occupancy map of the SAVED
79+ /// field, the input side of [`setup_motion_field`]'s projection.
80+ pub fn occupancy(&self) -> Vec<String> {
81+ (0..self.rows)
82+ .map(|r| {
83+ (0..self.cols)
84+ .map(|c| if self.cells[r * self.cols + c].is_some() { '#' } else { '.' })
85+ .collect()
86+ })
87+ .collect()
88+ }
89+
7890 fn get(&self, row8: usize, col8: usize) -> Option<SavedMv> {
7991 if row8 < self.rows && col8 < self.cols {
8092 self.cells[row8 * self.cols + col8]
@@ -95,6 +107,13 @@ pub struct TplField {
95107 }
96108
97109 impl TplField {
110+ /// lane-mergefix r5 rung (`EC_TPL`): how many 8x8 cells the projection
111+ /// actually filled -- an empty field means every temporal candidate is
112+ /// silently absent while the entropy stream still matches.
113+ pub fn filled_cells(&self) -> usize {
114+ self.cells.iter().filter(|c| c.is_some()).count()
115+ }
116+
98117 fn get(&self, row8: usize, col8: usize) -> Option<((i32, i32), i32)> {
99118 if row8 < self.rows && col8 < self.cols {
100119 self.cells[row8 * self.cols + col8]
crates/ec-av1/src/mvstack.rsmodified+16 -0
@@ -274,6 +274,22 @@ impl MiGrid {
274274 None
275275 }
276276 }
277+
278+ /// The unit at `(row, col)` ignoring the tile window -- the frame-level
279+ /// read `av1_copy_frame_mvs` (this crate's
280+ /// `crate::decode::build_motion_field`) needs: it stores EVERY block of
281+ /// the frame, and it runs after the last tile has already narrowed
282+ /// [`Self::set_tile_bounds`], so reading it through [`Self::get`] saved
283+ /// only the last tile's columns into the motion field and every other
284+ /// tile's temporal candidates silently vanished from the next frame's
285+ /// MV stack.
286+ pub fn get_frame(&self, row: usize, col: usize) -> Option<&MiInfo> {
287+ if row < self.rows && col < self.cols {
288+ self.cells[row * self.cols + col].as_ref()
289+ } else {
290+ None
291+ }
292+ }
277293 }
278294
279295 /// One entry of the reference MV stack: a candidate motion vector and the
crates/ec-av1/src/stream.rsmodified+8 -0
@@ -766,6 +766,14 @@ pub fn decode_stream(data: &[u8]) -> Result<Vec<Picture>> {
766766 header.mi_cols as usize,
767767 )
768768 });
769+ if std::env::var_os("EC_TPL").is_some() {
770+ eprintln!(
771+ "EC_TPL order_hint={} use_ref_frame_mvs={} cells={}",
772+ header.order_hint,
773+ header.use_ref_frame_mvs,
774+ tpl_field.as_ref().map_or(0, crate::motion_field::TplField::filled_cells)
775+ );
776+ }
769777 let (picture, end_cdfs, motion_field) = decode_inter_frame_tile_with_cdfs(
770778 &tile_bufs,
771779 &header.tile_info,