forge
Explore
Log in

Don't you dare go Hollow

Every kf_y_mode reader takes the mi-exact intra mode neighbour, not just the strip path -- a 32x16 strip whose left neighbour was a 16x8 rect leaf read the stale coarse 16x16 slot and picked a different CDF row for the same mode value (whole bottom-right quadrant wrong)

Browse files at this commit

fbf038b5c57db6cdf4737a6e14330dea89c5f7c7Ahmet Kaan GümüşParent: 725112d
  • fix
    • every kf_y_mode reader takes the mi-exact intra mode neighbour, not just the strip path -- a 32x16 strip whose left neighbour was a 16x8 rect leaf read the stale coarse 16x16 slot and picked a different CDF row for the same mode value (whole bottom-right quadrant wrong)
    • mi-exact map now tile-guarded (mi_r > tile_row0_mi) and reset in start_tile/start_row like every other neighbour array
Show full message
fix(av1): every kf_y_mode reader takes the mi-exact intra mode neighbour, not just the strip path -- a 32x16 strip whose left neighbour was a 16x8 rect leaf read the stale coarse 16x16 slot and picked a different CDF row for the same mode value (whole bottom-right quadrant wrong); mi-exact map now tile-guarded (mi_r > tile_row0_mi) and reset in start_tile/start_row like every other neighbour array
crates/ec-av1/src/decode.rsmodified+40 -14
@@ -2035,6 +2035,14 @@ impl Neighbours {
20352035 self.above_compound_idx[i] = 0;
20362036 self.above_filter[i] = [3u8; 2];
20372037 }
2038+ // lane-rectx r5 (defect found by lane-sub8's verifier): the mi-exact
2039+ // mode map is neighbour state like every array above it -- left
2040+ // unreset, a tile read its LEFT tile's modes across the boundary.
2041+ for i in col0_mi.min(end)..end {
2042+ if let Some(slot) = self.sub8_mode_col.get_mut(i) {
2043+ *slot = (usize::MAX, 0);
2044+ }
2045+ }
20382046 }
20392047
20402048 /// Writes a just-decoded block's own palette-Y size/colours (`size == 0`
@@ -2292,6 +2300,7 @@ impl Neighbours {
22922300 self.left_comp_group_idx.iter_mut().for_each(|r| *r = 0);
22932301 self.left_compound_idx.iter_mut().for_each(|r| *r = 0);
22942302 self.left_filter.iter_mut().for_each(|f| *f = [3u8; 2]);
2303+ self.sub8_mode_row.iter_mut().for_each(|e| *e = (usize::MAX, 0));
22952304 }
22962305
22972306 /// Records a block's `skip`/`is_inter`/`interp_filter` state for the next
@@ -2557,18 +2566,35 @@ impl Neighbours {
25572566 /// construction). See [`Self::record_mode_mi`].
25582567 fn mode_above_mi(&self, mi_r: usize, mi_c: usize) -> Option<usize> {
25592568 match self.sub8_mode_col.get(mi_c) {
2560- Some(&(row, m)) if mi_r > 0 && row == mi_r - 1 => Some(m),
2569+ Some(&(row, m)) if mi_r > self.tile_row0_mi && row == mi_r - 1 => Some(m),
25612570 _ => None,
25622571 }
25632572 }
25642573
25652574 fn mode_left_mi(&self, mi_r: usize, mi_c: usize) -> Option<usize> {
25662575 match self.sub8_mode_row.get(mi_r) {
2567- Some(&(col, m)) if mi_c > 0 && col == mi_c - 1 => Some(m),
2576+ Some(&(col, m)) if mi_c > self.tile_col0_mi && col == mi_c - 1 => Some(m),
25682577 _ => None,
25692578 }
25702579 }
25712580
2581+ /// The above/left luma modes libaom's `above_mi`/`left_mi` really see for a
2582+ /// block at coarse [`SUB`]-grid `(r, c)`. lane-rectx r5: the coarse
2583+ /// `above_mode`/`left_mode` slots are written in 16x16 cells, so a
2584+ /// sub-16x16 neighbour (a 16x8 rect leaf, an 8x8 split cell) leaves them
2585+ /// holding an OLDER, larger block's mode -- it only ever recorded into the
2586+ /// mi-exact map. Every `kf_y_mode` reader goes through here, not just the
2587+ /// strip path ([`decode_leaf_rect`] took this override in r4; a 32x16 strip
2588+ /// whose left neighbour was a 16x8 leaf still read the stale row and picked
2589+ /// a different CDF for the same mode value).
2590+ fn modes_above_left(&self, r: usize, c: usize) -> (usize, usize) {
2591+ let (mi_r, mi_c) = (r * (SUB / MI), c * (SUB / MI));
2592+ (
2593+ self.mode_above_mi(mi_r, mi_c).unwrap_or(self.above_mode[c]),
2594+ self.mode_left_mi(mi_r, mi_c).unwrap_or(self.left_mode[r]),
2595+ )
2596+ }
2597+
25722598 fn record_rect(
25732599 &mut self,
25742600 at: (usize, usize),
@@ -3267,12 +3293,13 @@ fn decode_block_rect(
32673293 ) -> Result<()> {
32683294 let (r, c) = at;
32693295 let (px, py) = (c * SUB, r * SUB);
3296+ let (nb_above_mode, nb_left_mode) = neighbours.modes_above_left(r, c);
32703297 let (skip, mode, angle_delta_y, uv_mode, angle_delta_uv, alpha, filter_intra) =
32713298 read_intra_mode_rect(
32723299 dec,
32733300 cdfs,
3274- neighbours.above_mode[c],
3275- neighbours.left_mode[r],
3301+ nb_above_mode,
3302+ nb_left_mode,
32763303 true,
32773304 bw,
32783305 bh,
@@ -3282,8 +3309,7 @@ fn decode_block_rect(
32823309 r * (SUB / MI),
32833310 c * (SUB / MI),
32843311 )?;
3285- let smooth_neighbor =
3286- is_smooth_mode(neighbours.above_mode[c]) || is_smooth_mode(neighbours.left_mode[r]);
3312+ let smooth_neighbor = is_smooth_mode(nb_above_mode) || is_smooth_mode(nb_left_mode);
32873313 if smooth_neighbor {
32883314 SMOOTH_LUMA_HITS.with(|c| c.set(c.get() + 1));
32893315 }
@@ -3834,12 +3860,13 @@ fn decode_block_rect64(
38343860 ) -> Result<()> {
38353861 let (r, c) = at;
38363862 let (px, py) = (c * SUB, r * SUB);
3863+ let (nb_above_mode, nb_left_mode) = neighbours.modes_above_left(r, c);
38373864 let (skip, mode, angle_delta_y, uv_mode, angle_delta_uv, alpha, filter_intra) =
38383865 read_intra_mode_rect(
38393866 dec,
38403867 cdfs,
3841- neighbours.above_mode[c],
3842- neighbours.left_mode[r],
3868+ nb_above_mode,
3869+ nb_left_mode,
38433870 // `is_cfl_allowed` (spec 5.11.5) caps CFL at <=32x32; these
38443871 // superblock-level HORZ/VERT strips are 64x32/32x64, so unlike
38453872 // `decode_block_rect`'s own 32x16/16x32 strips (where `true` is
@@ -3856,8 +3883,7 @@ fn decode_block_rect64(
38563883 r * (SUB / MI),
38573884 c * (SUB / MI),
38583885 )?;
3859- let smooth_neighbor =
3860- is_smooth_mode(neighbours.above_mode[c]) || is_smooth_mode(neighbours.left_mode[r]);
3886+ let smooth_neighbor = is_smooth_mode(nb_above_mode) || is_smooth_mode(nb_left_mode);
38613887 if smooth_neighbor {
38623888 SMOOTH_LUMA_HITS.with(|c| c.set(c.get() + 1));
38633889 }
@@ -4945,12 +4971,13 @@ fn decode_block(
49454971 let (px, py) = (c * SUB, r * SUB);
49464972 let (palette_ctx, palette_cache) = neighbours.palette_ctx_and_cache(at);
49474973 let palette_uv_cache = neighbours.palette_uv_cache(at);
4974+ let (nb_above_mode, nb_left_mode) = neighbours.modes_above_left(r, c);
49484975 let (skip, mode, angle_delta_y, uv_mode, angle_delta_uv, alpha, filter_intra, palette_y, palette_uv) =
49494976 read_intra_mode(
49504977 dec,
49514978 cdfs,
4952- neighbours.above_mode[c],
4953- neighbours.left_mode[r],
4979+ nb_above_mode,
4980+ nb_left_mode,
49544981 cfl,
49554982 side,
49564983 enable_filter_intra,
@@ -4970,8 +4997,7 @@ fn decode_block(
49704997 } else {
49714998 uv_mode
49724999 };
4973- let smooth_neighbor =
4974- is_smooth_mode(neighbours.above_mode[c]) || is_smooth_mode(neighbours.left_mode[r]);
5000+ let smooth_neighbor = is_smooth_mode(nb_above_mode) || is_smooth_mode(nb_left_mode);
49755001 if smooth_neighbor {
49765002 SMOOTH_LUMA_HITS.with(|c| c.set(c.get() + 1));
49775003 }