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 commitfbf038b5c57db6cdf4737a6e14330dea89c5f7c7Parent: 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
1 changed file +40 -14
- crates/ec-av1/src/decode.rs +40 -14
crates/ec-av1/src/decode.rsmodified+40 -14
| @@ -2035,6 +2035,14 @@ impl Neighbours { | |||
| 2035 | self.above_compound_idx[i] = 0; | 2035 | self.above_compound_idx[i] = 0; |
| 2036 | self.above_filter[i] = [3u8; 2]; | 2036 | self.above_filter[i] = [3u8; 2]; |
| 2037 | } | 2037 | } |
| 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 | + } | ||
| 2038 | } | 2046 | } |
| 2039 | 2047 | ||
| 2040 | /// Writes a just-decoded block's own palette-Y size/colours (`size == 0` | 2048 | /// Writes a just-decoded block's own palette-Y size/colours (`size == 0` |
| @@ -2292,6 +2300,7 @@ impl Neighbours { | |||
| 2292 | self.left_comp_group_idx.iter_mut().for_each(|r| *r = 0); | 2300 | self.left_comp_group_idx.iter_mut().for_each(|r| *r = 0); |
| 2293 | self.left_compound_idx.iter_mut().for_each(|r| *r = 0); | 2301 | self.left_compound_idx.iter_mut().for_each(|r| *r = 0); |
| 2294 | self.left_filter.iter_mut().for_each(|f| *f = [3u8; 2]); | 2302 | 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)); | ||
| 2295 | } | 2304 | } |
| 2296 | 2305 | ||
| 2297 | /// Records a block's `skip`/`is_inter`/`interp_filter` state for the next | 2306 | /// Records a block's `skip`/`is_inter`/`interp_filter` state for the next |
| @@ -2557,18 +2566,35 @@ impl Neighbours { | |||
| 2557 | /// construction). See [`Self::record_mode_mi`]. | 2566 | /// construction). See [`Self::record_mode_mi`]. |
| 2558 | fn mode_above_mi(&self, mi_r: usize, mi_c: usize) -> Option<usize> { | 2567 | fn mode_above_mi(&self, mi_r: usize, mi_c: usize) -> Option<usize> { |
| 2559 | match self.sub8_mode_col.get(mi_c) { | 2568 | 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), |
| 2561 | _ => None, | 2570 | _ => None, |
| 2562 | } | 2571 | } |
| 2563 | } | 2572 | } |
| 2564 | 2573 | ||
| 2565 | fn mode_left_mi(&self, mi_r: usize, mi_c: usize) -> Option<usize> { | 2574 | fn mode_left_mi(&self, mi_r: usize, mi_c: usize) -> Option<usize> { |
| 2566 | match self.sub8_mode_row.get(mi_r) { | 2575 | 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), |
| 2568 | _ => None, | 2577 | _ => None, |
| 2569 | } | 2578 | } |
| 2570 | } | 2579 | } |
| 2571 | 2580 | ||
| 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 | + | ||
| 2572 | fn record_rect( | 2598 | fn record_rect( |
| 2573 | &mut self, | 2599 | &mut self, |
| 2574 | at: (usize, usize), | 2600 | at: (usize, usize), |
| @@ -3267,12 +3293,13 @@ fn decode_block_rect( | |||
| 3267 | ) -> Result<()> { | 3293 | ) -> Result<()> { |
| 3268 | let (r, c) = at; | 3294 | let (r, c) = at; |
| 3269 | let (px, py) = (c * SUB, r * SUB); | 3295 | let (px, py) = (c * SUB, r * SUB); |
| 3296 | + let (nb_above_mode, nb_left_mode) = neighbours.modes_above_left(r, c); | ||
| 3270 | let (skip, mode, angle_delta_y, uv_mode, angle_delta_uv, alpha, filter_intra) = | 3297 | let (skip, mode, angle_delta_y, uv_mode, angle_delta_uv, alpha, filter_intra) = |
| 3271 | read_intra_mode_rect( | 3298 | read_intra_mode_rect( |
| 3272 | dec, | 3299 | dec, |
| 3273 | cdfs, | 3300 | cdfs, |
| 3274 | - neighbours.above_mode[c], | 3301 | + nb_above_mode, |
| 3275 | - neighbours.left_mode[r], | 3302 | + nb_left_mode, |
| 3276 | true, | 3303 | true, |
| 3277 | bw, | 3304 | bw, |
| 3278 | bh, | 3305 | bh, |
| @@ -3282,8 +3309,7 @@ fn decode_block_rect( | |||
| 3282 | r * (SUB / MI), | 3309 | r * (SUB / MI), |
| 3283 | c * (SUB / MI), | 3310 | c * (SUB / MI), |
| 3284 | )?; | 3311 | )?; |
| 3285 | - let smooth_neighbor = | 3312 | + let smooth_neighbor = is_smooth_mode(nb_above_mode) || is_smooth_mode(nb_left_mode); |
| 3286 | - is_smooth_mode(neighbours.above_mode[c]) || is_smooth_mode(neighbours.left_mode[r]); | ||
| 3287 | if smooth_neighbor { | 3313 | if smooth_neighbor { |
| 3288 | SMOOTH_LUMA_HITS.with(|c| c.set(c.get() + 1)); | 3314 | SMOOTH_LUMA_HITS.with(|c| c.set(c.get() + 1)); |
| 3289 | } | 3315 | } |
| @@ -3834,12 +3860,13 @@ fn decode_block_rect64( | |||
| 3834 | ) -> Result<()> { | 3860 | ) -> Result<()> { |
| 3835 | let (r, c) = at; | 3861 | let (r, c) = at; |
| 3836 | let (px, py) = (c * SUB, r * SUB); | 3862 | let (px, py) = (c * SUB, r * SUB); |
| 3863 | + let (nb_above_mode, nb_left_mode) = neighbours.modes_above_left(r, c); | ||
| 3837 | let (skip, mode, angle_delta_y, uv_mode, angle_delta_uv, alpha, filter_intra) = | 3864 | let (skip, mode, angle_delta_y, uv_mode, angle_delta_uv, alpha, filter_intra) = |
| 3838 | read_intra_mode_rect( | 3865 | read_intra_mode_rect( |
| 3839 | dec, | 3866 | dec, |
| 3840 | cdfs, | 3867 | cdfs, |
| 3841 | - neighbours.above_mode[c], | 3868 | + nb_above_mode, |
| 3842 | - neighbours.left_mode[r], | 3869 | + nb_left_mode, |
| 3843 | // `is_cfl_allowed` (spec 5.11.5) caps CFL at <=32x32; these | 3870 | // `is_cfl_allowed` (spec 5.11.5) caps CFL at <=32x32; these |
| 3844 | // superblock-level HORZ/VERT strips are 64x32/32x64, so unlike | 3871 | // superblock-level HORZ/VERT strips are 64x32/32x64, so unlike |
| 3845 | // `decode_block_rect`'s own 32x16/16x32 strips (where `true` is | 3872 | // `decode_block_rect`'s own 32x16/16x32 strips (where `true` is |
| @@ -3856,8 +3883,7 @@ fn decode_block_rect64( | |||
| 3856 | r * (SUB / MI), | 3883 | r * (SUB / MI), |
| 3857 | c * (SUB / MI), | 3884 | c * (SUB / MI), |
| 3858 | )?; | 3885 | )?; |
| 3859 | - let smooth_neighbor = | 3886 | + let smooth_neighbor = is_smooth_mode(nb_above_mode) || is_smooth_mode(nb_left_mode); |
| 3860 | - is_smooth_mode(neighbours.above_mode[c]) || is_smooth_mode(neighbours.left_mode[r]); | ||
| 3861 | if smooth_neighbor { | 3887 | if smooth_neighbor { |
| 3862 | SMOOTH_LUMA_HITS.with(|c| c.set(c.get() + 1)); | 3888 | SMOOTH_LUMA_HITS.with(|c| c.set(c.get() + 1)); |
| 3863 | } | 3889 | } |
| @@ -4945,12 +4971,13 @@ fn decode_block( | |||
| 4945 | let (px, py) = (c * SUB, r * SUB); | 4971 | let (px, py) = (c * SUB, r * SUB); |
| 4946 | let (palette_ctx, palette_cache) = neighbours.palette_ctx_and_cache(at); | 4972 | let (palette_ctx, palette_cache) = neighbours.palette_ctx_and_cache(at); |
| 4947 | let palette_uv_cache = neighbours.palette_uv_cache(at); | 4973 | let palette_uv_cache = neighbours.palette_uv_cache(at); |
| 4974 | + let (nb_above_mode, nb_left_mode) = neighbours.modes_above_left(r, c); | ||
| 4948 | let (skip, mode, angle_delta_y, uv_mode, angle_delta_uv, alpha, filter_intra, palette_y, palette_uv) = | 4975 | let (skip, mode, angle_delta_y, uv_mode, angle_delta_uv, alpha, filter_intra, palette_y, palette_uv) = |
| 4949 | read_intra_mode( | 4976 | read_intra_mode( |
| 4950 | dec, | 4977 | dec, |
| 4951 | cdfs, | 4978 | cdfs, |
| 4952 | - neighbours.above_mode[c], | 4979 | + nb_above_mode, |
| 4953 | - neighbours.left_mode[r], | 4980 | + nb_left_mode, |
| 4954 | cfl, | 4981 | cfl, |
| 4955 | side, | 4982 | side, |
| 4956 | enable_filter_intra, | 4983 | enable_filter_intra, |
| @@ -4970,8 +4997,7 @@ fn decode_block( | |||
| 4970 | } else { | 4997 | } else { |
| 4971 | uv_mode | 4998 | uv_mode |
| 4972 | }; | 4999 | }; |
| 4973 | - let smooth_neighbor = | 5000 | + let smooth_neighbor = is_smooth_mode(nb_above_mode) || is_smooth_mode(nb_left_mode); |
| 4974 | - is_smooth_mode(neighbours.above_mode[c]) || is_smooth_mode(neighbours.left_mode[r]); | ||
| 4975 | if smooth_neighbor { | 5001 | if smooth_neighbor { |
| 4976 | SMOOTH_LUMA_HITS.with(|c| c.set(c.get() + 1)); | 5002 | SMOOTH_LUMA_HITS.with(|c| c.set(c.get() + 1)); |
| 4977 | } | 5003 | } |