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 commitba5351f32be9ced7d53bb7ce6ce285f4a351e62eParent: 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
4 changed files +50 -1
- crates/ec-av1/src/decode.rs +7 -1
- crates/ec-av1/src/motion_field.rs +19 -0
- crates/ec-av1/src/mvstack.rs +16 -0
- crates/ec-av1/src/stream.rs +8 -0
crates/ec-av1/src/decode.rsmodified+7 -1
| @@ -2997,7 +2997,7 @@ pub(crate) fn build_motion_field( | |||
| 2997 | const REFMVS_LIMIT: i32 = (1 << 12) - 1; | 2997 | const REFMVS_LIMIT: i32 = (1 << 12) - 1; |
| 2998 | for row in 0..mi_rows { | 2998 | for row in 0..mi_rows { |
| 2999 | for col in 0..mi_cols { | 2999 | 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 { |
| 3001 | continue; | 3001 | continue; |
| 3002 | }; | 3002 | }; |
| 3003 | // `av1_copy_frame_mvs` runs for EVERY block of an inter frame and | 3003 | // `av1_copy_frame_mvs` runs for EVERY block of an inter frame and |
| @@ -3036,6 +3036,12 @@ pub(crate) fn build_motion_field( | |||
| 3036 | field.set(row, col, saved); | 3036 | field.set(row, col, saved); |
| 3037 | } | 3037 | } |
| 3038 | } | 3038 | } |
| 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 | + } | ||
| 3039 | field | 3045 | field |
| 3040 | } | 3046 | } |
| 3041 | 3047 | ||
crates/ec-av1/src/motion_field.rsmodified+19 -0
| @@ -75,6 +75,18 @@ impl MotionField { | |||
| 75 | } | 75 | } |
| 76 | } | 76 | } |
| 77 | 77 | ||
| 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 | + | ||
| 78 | fn get(&self, row8: usize, col8: usize) -> Option<SavedMv> { | 90 | fn get(&self, row8: usize, col8: usize) -> Option<SavedMv> { |
| 79 | if row8 < self.rows && col8 < self.cols { | 91 | if row8 < self.rows && col8 < self.cols { |
| 80 | self.cells[row8 * self.cols + col8] | 92 | self.cells[row8 * self.cols + col8] |
| @@ -95,6 +107,13 @@ pub struct TplField { | |||
| 95 | } | 107 | } |
| 96 | 108 | ||
| 97 | impl TplField { | 109 | 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 | + | ||
| 98 | fn get(&self, row8: usize, col8: usize) -> Option<((i32, i32), i32)> { | 117 | fn get(&self, row8: usize, col8: usize) -> Option<((i32, i32), i32)> { |
| 99 | if row8 < self.rows && col8 < self.cols { | 118 | if row8 < self.rows && col8 < self.cols { |
| 100 | self.cells[row8 * self.cols + col8] | 119 | self.cells[row8 * self.cols + col8] |
crates/ec-av1/src/mvstack.rsmodified+16 -0
| @@ -274,6 +274,22 @@ impl MiGrid { | |||
| 274 | None | 274 | None |
| 275 | } | 275 | } |
| 276 | } | 276 | } |
| 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 | + } | ||
| 277 | } | 293 | } |
| 278 | 294 | ||
| 279 | /// One entry of the reference MV stack: a candidate motion vector and the | 295 | /// 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>> { | |||
| 766 | header.mi_cols as usize, | 766 | header.mi_cols as usize, |
| 767 | ) | 767 | ) |
| 768 | }); | 768 | }); |
| 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 | + } | ||
| 769 | let (picture, end_cdfs, motion_field) = decode_inter_frame_tile_with_cdfs( | 777 | let (picture, end_cdfs, motion_field) = decode_inter_frame_tile_with_cdfs( |
| 770 | &tile_bufs, | 778 | &tile_bufs, |
| 771 | &header.tile_info, | 779 | &header.tile_info, |