The neighbour palette side bands were indexed on the 16px SUB cell, so a 16x8 strip pair shared one slot and the second strip read the first's palette size -- every screen key frame with palette + tx-size-search decoded whole-superblocks wrong
Browse files at this commitc642e2802cb13b4094e89f21c920c057213f2f0aParent: d68cb84- fix
- the neighbour palette side bands were indexed on the 16px SUB cell, so a 16x8 strip pair shared one slot and the second strip read the first's palette size -- every screen key frame with palette + tx-size-search decoded whole-superblocks wrong
2 changed files +135 -117
- crates/ec-av1/src/decode.rs +114 -116
- crates/ec-av1/src/stream.rs +21 -1
crates/ec-av1/src/decode.rsmodified+114 -116
| @@ -3933,14 +3933,14 @@ impl Neighbours { | ||
| 3933 | 3933 | uv_tx_h_grid: vec![0u8; cols * (SUB / MI) * rows * (SUB / MI)], |
| 3934 | 3934 | ref_grid: vec![0i8; cols * (SUB / MI) * rows * (SUB / MI)], |
| 3935 | 3935 | delta_lf_grid: vec![[0i8; 4]; cols * (SUB / MI) * rows * (SUB / MI)], |
| 3936 | - above_palette_size: vec![0; cols], | |
| 3937 | - left_palette_size: vec![0; rows], | |
| 3938 | - above_palette_colors: vec![[0u16; 8]; cols], | |
| 3939 | - left_palette_colors: vec![[0u16; 8]; rows], | |
| 3940 | - above_palette_uv_size: vec![0; cols], | |
| 3941 | - left_palette_uv_size: vec![0; rows], | |
| 3942 | - above_palette_uv_colors: vec![[0u16; 8]; cols], | |
| 3943 | - left_palette_uv_colors: vec![[0u16; 8]; rows], | |
| 3936 | + above_palette_size: vec![0; cols * (SUB / MI)], | |
| 3937 | + left_palette_size: vec![0; rows * (SUB / MI)], | |
| 3938 | + above_palette_colors: vec![[0u16; 8]; cols * (SUB / MI)], | |
| 3939 | + left_palette_colors: vec![[0u16; 8]; rows * (SUB / MI)], | |
| 3940 | + above_palette_uv_size: vec![0; cols * (SUB / MI)], | |
| 3941 | + left_palette_uv_size: vec![0; rows * (SUB / MI)], | |
| 3942 | + above_palette_uv_colors: vec![[0u16; 8]; cols * (SUB / MI)], | |
| 3943 | + left_palette_uv_colors: vec![[0u16; 8]; rows * (SUB / MI)], | |
| 3944 | 3944 | tile_row0_mi: 0, |
| 3945 | 3945 | tile_col0_mi: 0, |
| 3946 | 3946 | } |
| @@ -4000,7 +4000,7 @@ impl Neighbours { | ||
| 4000 | 4000 | /// mirrors [`Self::record_rect`]'s loop shape, square-only (this lane's |
| 4001 | 4001 | /// call sites are all square blocks). |
| 4002 | 4002 | fn record_palette_y(&mut self, at: (usize, usize), side: usize, size: usize, colors: [u16; 8]) { |
| 4003 | - self.record_palette_y_rect(at, side, side, size, colors); | |
| 4003 | + self.record_palette_y_rect((at.0 * (SUB / MI), at.1 * (SUB / MI)), side, side, size, colors); | |
| 4004 | 4004 | } |
| 4005 | 4005 | |
| 4006 | 4006 | /// [`Self::record_palette_y`] with independent above (`w`)/left (`h`) |
| @@ -4009,29 +4009,30 @@ impl Neighbours { | ||
| 4009 | 4009 | /// differ. |
| 4010 | 4010 | fn record_palette_y_rect( |
| 4011 | 4011 | &mut self, |
| 4012 | - at: (usize, usize), | |
| 4012 | + mi: (usize, usize), | |
| 4013 | 4013 | w: usize, |
| 4014 | 4014 | h: usize, |
| 4015 | 4015 | size: usize, |
| 4016 | 4016 | colors: [u16; 8], |
| 4017 | 4017 | ) { |
| 4018 | - let (r, c) = at; | |
| 4019 | - // `.max(1)`: a below-16px span covers no whole SUB cell, so the plain | |
| 4020 | - // `w / SUB` loop was a NO-OP for every 16x8/8x16/8x8/4x4 leaf and the | |
| 4021 | - // next block read a long-dead palette out of the above/left arrays | |
| 4022 | - // (class [[cdf-row-held-constant]], lane-palette2 r8). libaom keeps | |
| 4023 | - // `palette_size` per 4px mi cell; corner-cut: our grid is 16px, so a | |
| 4024 | - // sub-16 leaf stamps its whole containing cell -- safe today because | |
| 4025 | - // every sub-16 leaf path refuses palette outright (so it can only | |
| 4026 | - // ever stamp `size == 0`, and its cell holds no palette sibling). | |
| 4027 | - // Upgrade path: widen the palette arrays to mi granularity. | |
| 4028 | - for cell in 0..(w / SUB).max(1) { | |
| 4029 | - self.above_palette_size[c + cell] = size; | |
| 4030 | - self.above_palette_colors[c + cell] = colors; | |
| 4018 | + let (r, c) = mi; | |
| 4019 | + // lane-kf900 r6: mi (4px) granularity, libaom's own -- `palette_size` | |
| 4020 | + // lives per mi cell in `MB_MODE_INFO`, and `xd->left_mbmi` is the mi | |
| 4021 | + // cell immediately left of the block, not its 16px [`SUB`] cell. The | |
| 4022 | + // old SUB grid let a 16x8 strip pair share one slot, so the second | |
| 4023 | + // strip of mi(0,8) read the FIRST strip's palette size and the colour | |
| 4024 | + // cache came out one entry short (class [[context-read-from-one-cell]]). | |
| 4025 | + for cell in 0..(w / MI).max(1) { | |
| 4026 | + if let Some(e) = self.above_palette_size.get_mut(c + cell) { | |
| 4027 | + *e = size; | |
| 4028 | + self.above_palette_colors[c + cell] = colors; | |
| 4029 | + } | |
| 4031 | 4030 | } |
| 4032 | - for cell in 0..(h / SUB).max(1) { | |
| 4033 | - self.left_palette_size[r + cell] = size; | |
| 4034 | - self.left_palette_colors[r + cell] = colors; | |
| 4031 | + for cell in 0..(h / MI).max(1) { | |
| 4032 | + if let Some(e) = self.left_palette_size.get_mut(r + cell) { | |
| 4033 | + *e = size; | |
| 4034 | + self.left_palette_colors[r + cell] = colors; | |
| 4035 | + } | |
| 4035 | 4036 | } |
| 4036 | 4037 | } |
| 4037 | 4038 | |
| @@ -4049,7 +4050,7 @@ impl Neighbours { | ||
| 4049 | 4050 | /// palette block decoded as "no palette" and the tile desynced from |
| 4050 | 4051 | /// there (class [[cdf-row-held-constant]]). |
| 4051 | 4052 | fn palette_ctx_and_cache(&self, at: (usize, usize)) -> (usize, Vec<u16>) { |
| 4052 | - self.palette_ctx_and_cache_mi(at, at.0 * (SUB / MI)) | |
| 4053 | + self.palette_ctx_and_cache_mi((at.0 * (SUB / MI), at.1 * (SUB / MI))) | |
| 4053 | 4054 | } |
| 4054 | 4055 | |
| 4055 | 4056 | /// [`Self::palette_ctx_and_cache`] with the block's REAL mi row, which a |
| @@ -4059,11 +4060,11 @@ impl Neighbours { | ||
| 4059 | 4060 | /// block's own PIXEL row), and strip 1 of a HORZ_4 sits 8 px into the |
| 4060 | 4061 | /// cell -- reading `at.0 % 4` there excludes strip 0 from the cache of |
| 4061 | 4062 | /// every strip in an SB's top cell row, which libaom does not do. |
| 4062 | - fn palette_ctx_and_cache_mi(&self, at: (usize, usize), mi_r: usize) -> (usize, Vec<u16>) { | |
| 4063 | - let (r, c) = at; | |
| 4064 | - let above_ok = mi_r % 16 != 0; | |
| 4063 | + fn palette_ctx_and_cache_mi(&self, mi: (usize, usize)) -> (usize, Vec<u16>) { | |
| 4064 | + let (r, c) = mi; | |
| 4065 | + let above_ok = r % 16 != 0; | |
| 4065 | 4066 | // `xd->above_mbmi` exists for every row but the tile's own first. |
| 4066 | - let above_is_palette = mi_r > self.tile_row0_mi && self.above_palette_size[c] > 0; | |
| 4067 | + let above_is_palette = r > self.tile_row0_mi && self.above_palette_size[c] > 0; | |
| 4067 | 4068 | let (above_n, above_colors) = if above_ok && self.above_palette_size[c] > 0 { |
| 4068 | 4069 | (self.above_palette_size[c], self.above_palette_colors[c]) |
| 4069 | 4070 | } else { |
| @@ -4074,7 +4075,7 @@ impl Neighbours { | ||
| 4074 | 4075 | // (`left_available`), not the frame's -- without this guard a second |
| 4075 | 4076 | // tile column reads the previous tile's palette colours into its cache |
| 4076 | 4077 | // and its `palette_y_mode` ctx. |
| 4077 | - let left_ok = c > self.tile_col0_mi / (SUB / MI); | |
| 4078 | + let left_ok = c > self.tile_col0_mi; | |
| 4078 | 4079 | let (left_n, left_colors) = if left_ok && self.left_palette_size[r] > 0 { |
| 4079 | 4080 | (self.left_palette_size[r], self.left_palette_colors[r]) |
| 4080 | 4081 | } else { |
| @@ -4116,7 +4117,13 @@ impl Neighbours { | ||
| 4116 | 4117 | /// (U-channel) palette size/colours -- `size == 0` clears stale state the |
| 4117 | 4118 | /// same way (lane-palette2 r1). |
| 4118 | 4119 | fn record_palette_uv(&mut self, at: (usize, usize), side: usize, size: usize, colors: [u16; 8]) { |
| 4119 | - self.record_palette_uv_rect(at, side, side, size, colors); | |
| 4120 | + self.record_palette_uv_rect( | |
| 4121 | + (at.0 * (SUB / MI), at.1 * (SUB / MI)), | |
| 4122 | + side, | |
| 4123 | + side, | |
| 4124 | + size, | |
| 4125 | + colors, | |
| 4126 | + ); | |
| 4120 | 4127 | } |
| 4121 | 4128 | |
| 4122 | 4129 | /// [`Self::record_palette_uv`] with independent above (`w`)/left (`h`) |
| @@ -4125,21 +4132,25 @@ impl Neighbours { | ||
| 4125 | 4132 | /// luma resolution regardless of which plane the recorded state is for). |
| 4126 | 4133 | fn record_palette_uv_rect( |
| 4127 | 4134 | &mut self, |
| 4128 | - at: (usize, usize), | |
| 4135 | + mi: (usize, usize), | |
| 4129 | 4136 | w: usize, |
| 4130 | 4137 | h: usize, |
| 4131 | 4138 | size: usize, |
| 4132 | 4139 | colors: [u16; 8], |
| 4133 | 4140 | ) { |
| 4134 | - let (r, c) = at; | |
| 4135 | - // See [`Self::record_palette_y_rect`] for the `.max(1)`. | |
| 4136 | - for cell in 0..(w / SUB).max(1) { | |
| 4137 | - self.above_palette_uv_size[c + cell] = size; | |
| 4138 | - self.above_palette_uv_colors[c + cell] = colors; | |
| 4141 | + let (r, c) = mi; | |
| 4142 | + // mi granularity, see [`Self::record_palette_y_rect`]. | |
| 4143 | + for cell in 0..(w / MI).max(1) { | |
| 4144 | + if let Some(e) = self.above_palette_uv_size.get_mut(c + cell) { | |
| 4145 | + *e = size; | |
| 4146 | + self.above_palette_uv_colors[c + cell] = colors; | |
| 4147 | + } | |
| 4139 | 4148 | } |
| 4140 | - for cell in 0..(h / SUB).max(1) { | |
| 4141 | - self.left_palette_uv_size[r + cell] = size; | |
| 4142 | - self.left_palette_uv_colors[r + cell] = colors; | |
| 4149 | + for cell in 0..(h / MI).max(1) { | |
| 4150 | + if let Some(e) = self.left_palette_uv_size.get_mut(r + cell) { | |
| 4151 | + *e = size; | |
| 4152 | + self.left_palette_uv_colors[r + cell] = colors; | |
| 4153 | + } | |
| 4143 | 4154 | } |
| 4144 | 4155 | } |
| 4145 | 4156 | |
| @@ -4149,21 +4160,21 @@ impl Neighbours { | ||
| 4149 | 4160 | /// palette use, `read_palette_mode_info`'s `pmi->palette_size[0] > 0`), |
| 4150 | 4161 | /// so only the cache is wanted here. |
| 4151 | 4162 | fn palette_uv_cache(&self, at: (usize, usize)) -> Vec<u16> { |
| 4152 | - self.palette_uv_cache_mi(at, at.0 * (SUB / MI)) | |
| 4163 | + self.palette_uv_cache_mi((at.0 * (SUB / MI), at.1 * (SUB / MI))) | |
| 4153 | 4164 | } |
| 4154 | 4165 | |
| 4155 | 4166 | /// [`Self::palette_uv_cache`] with the block's real mi row -- see |
| 4156 | 4167 | /// [`Self::palette_ctx_and_cache_mi`]. |
| 4157 | - fn palette_uv_cache_mi(&self, at: (usize, usize), mi_r: usize) -> Vec<u16> { | |
| 4158 | - let (r, c) = at; | |
| 4159 | - let above_ok = mi_r % 16 != 0; | |
| 4168 | + fn palette_uv_cache_mi(&self, mi: (usize, usize)) -> Vec<u16> { | |
| 4169 | + let (r, c) = mi; | |
| 4170 | + let above_ok = r % 16 != 0; | |
| 4160 | 4171 | let (above_n, above_colors) = if above_ok && self.above_palette_uv_size[c] > 0 { |
| 4161 | 4172 | (self.above_palette_uv_size[c], self.above_palette_uv_colors[c]) |
| 4162 | 4173 | } else { |
| 4163 | 4174 | (0, [0u16; 8]) |
| 4164 | 4175 | }; |
| 4165 | 4176 | // Same tile-relative left availability as the luma cache above. |
| 4166 | - let left_ok = c > self.tile_col0_mi / (SUB / MI); | |
| 4177 | + let left_ok = c > self.tile_col0_mi; | |
| 4167 | 4178 | let (left_n, left_colors) = if left_ok && self.left_palette_uv_size[r] > 0 { |
| 4168 | 4179 | (self.left_palette_uv_size[r], self.left_palette_uv_colors[r]) |
| 4169 | 4180 | } else { |
| @@ -5777,40 +5788,43 @@ fn read_intra_mode_rect( | ||
| 5777 | 5788 | )) |
| 5778 | 5789 | } |
| 5779 | 5790 | |
| 5780 | -/// Stamps a 1:4 strip's palette state into the coarse above/left arrays. | |
| 5781 | -/// `av1_get_palette_cache` reads `xd->above_mbmi`/`xd->left_mbmi`, and inside | |
| 5782 | -/// a HORZ_4 (VERT_4) the next strip's ABOVE (LEFT) neighbour is this strip | |
| 5783 | -/// while its LEFT (ABOVE) neighbour is still the parent block's. The coarse | |
| 5784 | -/// [`SUB`]-cell arrays alias all four strips onto one entry, so writing BOTH | |
| 5785 | -/// axes after every strip would hand strip i+1 this strip's colours on the | |
| 5786 | -/// wrong axis too -- a wrong cache costs the same bits, so the tile stays in | |
| 5787 | -/// sync and only the pixels are wrong (class [[cdf-row-held-constant]]). | |
| 5788 | -/// Only the split axis is written until the closing strip, which stamps both | |
| 5789 | -/// for whatever follows the parent block. | |
| 5791 | +/// Stamps a 1:4 strip's palette state into the mi-granular above/left arrays, | |
| 5792 | +/// at the strip's REAL mi position. `av1_get_palette_cache` reads | |
| 5793 | +/// `xd->above_mbmi`/`xd->left_mbmi`, i.e. the mi cell above/left of the | |
| 5794 | +/// block, so each strip owns its own rows and columns and no aliasing rule | |
| 5795 | +/// is needed (lane-kf900 r6). | |
| 5790 | 5796 | #[allow(clippy::too_many_arguments)] |
| 5791 | 5797 | fn record_strip_palette( |
| 5792 | 5798 | n: &mut Neighbours, |
| 5793 | - at: (usize, usize), | |
| 5799 | + mi: (usize, usize), | |
| 5794 | 5800 | bw: usize, |
| 5795 | 5801 | bh: usize, |
| 5796 | 5802 | y_size: usize, |
| 5797 | 5803 | y_colors: [u16; 8], |
| 5798 | 5804 | uv_size: usize, |
| 5799 | 5805 | uv_colors: [u16; 8], |
| 5800 | - last: bool, | |
| 5801 | 5806 | ) { |
| 5802 | - let (r, c) = at; | |
| 5803 | - let horz = bw > bh; | |
| 5804 | - if horz || last { | |
| 5805 | - for cell in 0..(bw / SUB).max(1) { | |
| 5806 | - n.above_palette_size[c + cell] = y_size; | |
| 5807 | - n.above_palette_colors[c + cell] = y_colors; | |
| 5808 | - n.above_palette_uv_size[c + cell] = uv_size; | |
| 5809 | - n.above_palette_uv_colors[c + cell] = uv_colors; | |
| 5807 | + let (r, c) = mi; | |
| 5808 | + // lane-kf900 r6: the palette side bands are mi-granular now, so a strip | |
| 5809 | + // writes its OWN span on BOTH axes -- the old `last` split-axis rule only | |
| 5810 | + // existed because the 16px [`SUB`] cell held one slot for all the strips | |
| 5811 | + // of a HORZ_4/VERT_4 and leaf 0 zeroing the other axis threw away the | |
| 5812 | + // real neighbour leaf 1 reads. | |
| 5813 | + { | |
| 5814 | + for cell in 0..(bw / MI).max(1) { | |
| 5815 | + if let Some(e) = n.above_palette_size.get_mut(c + cell) { | |
| 5816 | + *e = y_size; | |
| 5817 | + n.above_palette_colors[c + cell] = y_colors; | |
| 5818 | + n.above_palette_uv_size[c + cell] = uv_size; | |
| 5819 | + n.above_palette_uv_colors[c + cell] = uv_colors; | |
| 5820 | + } | |
| 5810 | 5821 | } |
| 5811 | 5822 | } |
| 5812 | - if !horz || last { | |
| 5813 | - for cell in 0..(bh / SUB).max(1) { | |
| 5823 | + { | |
| 5824 | + for cell in 0..(bh / MI).max(1) { | |
| 5825 | + if n.left_palette_size.get(r + cell).is_none() { | |
| 5826 | + break; | |
| 5827 | + } | |
| 5814 | 5828 | n.left_palette_size[r + cell] = y_size; |
| 5815 | 5829 | n.left_palette_colors[r + cell] = y_colors; |
| 5816 | 5830 | n.left_palette_uv_size[r + cell] = uv_size; |
| @@ -6659,10 +6673,10 @@ fn decode_block_rect( | ||
| 6659 | 6673 | // wrong VALUE -- same bit count, so the entropy stream stayed in sync |
| 6660 | 6674 | // and only those pixels were wrong (lane-palette2 r10). |
| 6661 | 6675 | let (py_size, py_colors) = palette_y.as_ref().map_or((0, [0u16; 8]), |p| (p.size, p.colors)); |
| 6662 | - neighbours.record_palette_y_rect(at, bw, bh, py_size, py_colors); | |
| 6676 | + neighbours.record_palette_y_rect((mi_r, mi_c), bw, bh, py_size, py_colors); | |
| 6663 | 6677 | let (puv_size, puv_colors) = |
| 6664 | 6678 | palette_uv.as_ref().map_or((0, [0u16; 8]), |p| (p.size, p.u_colors)); |
| 6665 | - neighbours.record_palette_uv_rect(at, bw, bh, puv_size, puv_colors); | |
| 6679 | + neighbours.record_palette_uv_rect((mi_r, mi_c), bw, bh, puv_size, puv_colors); | |
| 6666 | 6680 | RECT_PARTITION_HITS.with(|c| c.set(c.get() + 1)); |
| 6667 | 6681 | return Ok(()); |
| 6668 | 6682 | } |
| @@ -6927,10 +6941,10 @@ fn decode_block_rect( | ||
| 6927 | 6941 | } |
| 6928 | 6942 | } |
| 6929 | 6943 | let (py_size, py_colors) = palette_y.as_ref().map_or((0, [0u16; 8]), |p| (p.size, p.colors)); |
| 6930 | - neighbours.record_palette_y_rect(at, bw, bh, py_size, py_colors); | |
| 6944 | + neighbours.record_palette_y_rect((mi_r, mi_c), bw, bh, py_size, py_colors); | |
| 6931 | 6945 | let (puv_size, puv_colors) = |
| 6932 | 6946 | palette_uv.as_ref().map_or((0, [0u16; 8]), |p| (p.size, p.u_colors)); |
| 6933 | - neighbours.record_palette_uv_rect(at, bw, bh, puv_size, puv_colors); | |
| 6947 | + neighbours.record_palette_uv_rect((mi_r, mi_c), bw, bh, puv_size, puv_colors); | |
| 6934 | 6948 | neighbours.fill_skip_grid_rect((mi_r, mi_c), bw / MI, bh / MI, skip); |
| 6935 | 6949 | neighbours.fill_lf_grid_rect((mi_r, mi_c), bw / MI, bh / MI, tx_w as u8, tx_h as u8, 0); |
| 6936 | 6950 | RECT_PARTITION_HITS.with(|c| c.set(c.get() + 1)); |
| @@ -7016,12 +7030,13 @@ fn decode_leaf_rect( | ||
| 7016 | 7030 | // a palette narrows the wrong interval and desyncs the tile even when the |
| 7017 | 7031 | // decoded bit is the same. The cell is the 16px-SUB cell containing the |
| 7018 | 7032 | // leaf (the palette neighbour arrays have no finer granularity). |
| 7019 | - let pal_at = (leaf_mi.0 / (SUB / MI), leaf_mi.1 / (SUB / MI)); | |
| 7020 | - // lane-kf900 r4: the leaf's REAL mi row -- the second leaf of a 16x8 pair | |
| 7021 | - // sits 8 px into the cell, so the cache's superblock-top-row exclusion | |
| 7022 | - // must not be read off the cell (see [`Neighbours::palette_ctx_and_cache_mi`]). | |
| 7023 | - let (palette_ctx, palette_cache) = neighbours.palette_ctx_and_cache_mi(pal_at, leaf_mi.0); | |
| 7024 | - let palette_uv_cache = neighbours.palette_uv_cache_mi(pal_at, leaf_mi.0); | |
| 7033 | + // lane-kf900 r6: the leaf's REAL mi position -- the second leaf of a 16x8 | |
| 7034 | + // pair sits 8 px into the 16px cell, and both the cache's superblock-top-row | |
| 7035 | + // exclusion and the neighbour palette lookup itself are mi-granular | |
| 7036 | + // (see [`Neighbours::palette_ctx_and_cache_mi`]). | |
| 7037 | + let pal_at = leaf_mi; | |
| 7038 | + let (palette_ctx, palette_cache) = neighbours.palette_ctx_and_cache_mi(pal_at); | |
| 7039 | + let palette_uv_cache = neighbours.palette_uv_cache_mi(pal_at); | |
| 7025 | 7040 | let (skip, mode, angle_delta_y, uv_mode, angle_delta_uv, alpha, filter_intra, palette_y, palette_uv) = |
| 7026 | 7041 | read_intra_mode_rect( |
| 7027 | 7042 | dec, |
| @@ -7059,12 +7074,6 @@ fn decode_leaf_rect( | ||
| 7059 | 7074 | palette_y.as_ref().map_or((0, [0u16; 8]), |p| (p.size, p.colors)); |
| 7060 | 7075 | let (pal_uv_size, pal_uv_colors) = |
| 7061 | 7076 | palette_uv.as_ref().map_or((0, [0u16; 8]), |p| (p.size, p.u_colors)); |
| 7062 | - // The closing leaf of the pair -- see [`record_strip_palette`]. | |
| 7063 | - let pal_last = if bw > bh { | |
| 7064 | - leaf_mi.0 % 4 == 2 | |
| 7065 | - } else { | |
| 7066 | - leaf_mi.1 % 4 == 2 | |
| 7067 | - }; | |
| 7068 | 7077 | if std::env::var_os("EC_AV1_RECTX_TRACE").is_some() { |
| 7069 | 7078 | eprintln!(" skip={skip} mode={mode} angle_delta_y={angle_delta_y} uv_mode={uv_mode}"); |
| 7070 | 7079 | } |
| @@ -7147,7 +7156,6 @@ fn decode_leaf_rect( | ||
| 7147 | 7156 | )?; |
| 7148 | 7157 | record_strip_palette( |
| 7149 | 7158 | neighbours, pal_at, bw, bh, pal_y_size, pal_y_colors, pal_uv_size, pal_uv_colors, |
| 7150 | - pal_last, | |
| 7151 | 7159 | ); |
| 7152 | 7160 | return Ok(mode); |
| 7153 | 7161 | } |
| @@ -7271,7 +7279,6 @@ fn decode_leaf_rect( | ||
| 7271 | 7279 | // real left neighbour leaf 1 reads (lane-kf900 r4). |
| 7272 | 7280 | record_strip_palette( |
| 7273 | 7281 | neighbours, pal_at, bw, bh, pal_y_size, pal_y_colors, pal_uv_size, pal_uv_colors, |
| 7274 | - pal_last, | |
| 7275 | 7282 | ); |
| 7276 | 7283 | // A rect leaf spans mi_w x mi_h, so its mode reaches several columns and |
| 7277 | 7284 | // rows -- record the whole span, not one cell. |
| @@ -7341,9 +7348,9 @@ fn decode_block_rect4( | ||
| 7341 | 7348 | // `palette_colors_y` cache hit off an EMPTY cache -- right symbol count, |
| 7342 | 7349 | // wrong interval, so a screen-content tile desynced at the first strip |
| 7343 | 7350 | // whose neighbour used a palette (class [[cdf-row-held-constant]]). |
| 7344 | - let pal_at = (mi_r / (SUB / MI), mi_c / (SUB / MI)); | |
| 7345 | - let (palette_ctx, palette_cache) = neighbours.palette_ctx_and_cache_mi(pal_at, mi_r); | |
| 7346 | - let palette_uv_cache = neighbours.palette_uv_cache_mi(pal_at, mi_r); | |
| 7351 | + let pal_at = (mi_r, mi_c); | |
| 7352 | + let (palette_ctx, palette_cache) = neighbours.palette_ctx_and_cache_mi(pal_at); | |
| 7353 | + let palette_uv_cache = neighbours.palette_uv_cache_mi(pal_at); | |
| 7347 | 7354 | let ( |
| 7348 | 7355 | skip, |
| 7349 | 7356 | mode, |
| @@ -7387,10 +7394,6 @@ fn decode_block_rect4( | ||
| 7387 | 7394 | p.map.iter().map(|&i| p.v_colors[i as usize]).collect(), |
| 7388 | 7395 | ) |
| 7389 | 7396 | }); |
| 7390 | - // `last`: strip 3 of the parent 32x32's HORZ_4 (VERT_4), the only one | |
| 7391 | - // whose colours a block outside the parent sees -- see | |
| 7392 | - // [`record_strip_palette`]. | |
| 7393 | - let pal_last = if bw > bh { mi_r % 8 == 6 } else { mi_c % 8 == 6 }; | |
| 7394 | 7397 | let (pal_y_size, pal_y_colors) = |
| 7395 | 7398 | palette_y.as_ref().map_or((0, [0u16; 8]), |p| (p.size, p.colors)); |
| 7396 | 7399 | let (pal_uv_size, pal_uv_colors) = |
| @@ -7478,7 +7481,7 @@ fn decode_block_rect4( | ||
| 7478 | 7481 | )?; |
| 7479 | 7482 | record_strip_palette( |
| 7480 | 7483 | neighbours, pal_at, bw, bh, pal_y_size, pal_y_colors, pal_uv_size, |
| 7481 | - pal_uv_colors, pal_last, | |
| 7484 | + pal_uv_colors, | |
| 7482 | 7485 | ); |
| 7483 | 7486 | if bw > bh { |
| 7484 | 7487 | RECT4_32_HORZ_HITS.with(|c| c.set(c.get() + 1)); |
| @@ -7631,7 +7634,7 @@ fn decode_block_rect4( | ||
| 7631 | 7634 | neighbours.fill_lf_grid_rect((mi_r, mi_c), mi_w, mi_h, bw as u8, bh as u8, 0); |
| 7632 | 7635 | record_strip_palette( |
| 7633 | 7636 | neighbours, pal_at, bw, bh, pal_y_size, pal_y_colors, pal_uv_size, |
| 7634 | - pal_uv_colors, pal_last, | |
| 7637 | + pal_uv_colors, | |
| 7635 | 7638 | ); |
| 7636 | 7639 | if bw > bh { |
| 7637 | 7640 | RECT4_32_HORZ_HITS.with(|c| c.set(c.get() + 1)); |
| @@ -7694,7 +7697,6 @@ fn decode_block_rect4( | ||
| 7694 | 7697 | neighbours.fill_lf_grid_rect((mi_r, mi_c), mi_w, mi_h, bw as u8, bh as u8, 0); |
| 7695 | 7698 | record_strip_palette( |
| 7696 | 7699 | neighbours, pal_at, bw, bh, pal_y_size, pal_y_colors, pal_uv_size, pal_uv_colors, |
| 7697 | - pal_last, | |
| 7698 | 7700 | ); |
| 7699 | 7701 | if bw > bh { |
| 7700 | 7702 | RECT4_32_HORZ_HITS.with(|c| c.set(c.get() + 1)); |
| @@ -7778,9 +7780,8 @@ fn decode_rect4_16( | ||
| 7778 | 7780 | // lane-kf900 r4: the strip's real palette ctx + colour cache (see |
| 7779 | 7781 | // [`decode_block_rect4`]); `None`/`&[]` here read `palette_y_mode` |
| 7780 | 7782 | // off CDF row 0 and every cache hit off an empty cache. |
| 7781 | - let (palette_ctx, palette_cache) = | |
| 7782 | - neighbours.palette_ctx_and_cache_mi(at16, lmi.0); | |
| 7783 | - let palette_uv_cache = neighbours.palette_uv_cache_mi(at16, lmi.0); | |
| 7783 | + let (palette_ctx, palette_cache) = neighbours.palette_ctx_and_cache_mi(lmi); | |
| 7784 | + let palette_uv_cache = neighbours.palette_uv_cache_mi(lmi); | |
| 7784 | 7785 | let ( |
| 7785 | 7786 | skip, |
| 7786 | 7787 | mode, |
| @@ -8180,8 +8181,7 @@ fn decode_rect4_16( | ||
| 8180 | 8181 | let (pal_uv_size, pal_uv_colors) = |
| 8181 | 8182 | palette_uv.as_ref().map_or((0, [0u16; 8]), |p| (p.size, p.u_colors)); |
| 8182 | 8183 | record_strip_palette( |
| 8183 | - neighbours, at16, bw, bh, pal_y_size, pal_y_colors, pal_uv_size, pal_uv_colors, | |
| 8184 | - i == 3, | |
| 8184 | + neighbours, lmi, bw, bh, pal_y_size, pal_y_colors, pal_uv_size, pal_uv_colors, | |
| 8185 | 8185 | ); |
| 8186 | 8186 | last_mode = mode; |
| 8187 | 8187 | prev = Some((lmi, mode)); |
| @@ -8376,10 +8376,10 @@ fn decode_block_rect64( | ||
| 8376 | 8376 | // split-tx superblock strip would otherwise leave the above/left |
| 8377 | 8377 | // palette arrays holding a dead block's colours. |
| 8378 | 8378 | let (py_size, py_colors) = palette_y.as_ref().map_or((0, [0u16; 8]), |p| (p.size, p.colors)); |
| 8379 | - neighbours.record_palette_y_rect(at, bw, bh, py_size, py_colors); | |
| 8379 | + neighbours.record_palette_y_rect((mi_r, mi_c), bw, bh, py_size, py_colors); | |
| 8380 | 8380 | let (puv_size, puv_colors) = |
| 8381 | 8381 | palette_uv.as_ref().map_or((0, [0u16; 8]), |p| (p.size, p.u_colors)); |
| 8382 | - neighbours.record_palette_uv_rect(at, bw, bh, puv_size, puv_colors); | |
| 8382 | + neighbours.record_palette_uv_rect((mi_r, mi_c), bw, bh, puv_size, puv_colors); | |
| 8383 | 8383 | RECT_PARTITION_HITS.with(|c| c.set(c.get() + 1)); |
| 8384 | 8384 | return Ok(()); |
| 8385 | 8385 | } |
| @@ -8691,10 +8691,10 @@ fn decode_block_rect64( | ||
| 8691 | 8691 | RECT_COEFF_HITS.with(|c| c.set(c.get() + 1)); |
| 8692 | 8692 | } |
| 8693 | 8693 | let (py_size, py_colors) = palette_y.as_ref().map_or((0, [0u16; 8]), |p| (p.size, p.colors)); |
| 8694 | - neighbours.record_palette_y_rect(at, bw, bh, py_size, py_colors); | |
| 8694 | + neighbours.record_palette_y_rect((mi_r, mi_c), bw, bh, py_size, py_colors); | |
| 8695 | 8695 | let (puv_size, puv_colors) = |
| 8696 | 8696 | palette_uv.as_ref().map_or((0, [0u16; 8]), |p| (p.size, p.u_colors)); |
| 8697 | - neighbours.record_palette_uv_rect(at, bw, bh, puv_size, puv_colors); | |
| 8697 | + neighbours.record_palette_uv_rect((mi_r, mi_c), bw, bh, puv_size, puv_colors); | |
| 8698 | 8698 | neighbours.fill_skip_grid_rect((mi_r, mi_c), bw / MI, bh / MI, skip); |
| 8699 | 8699 | neighbours.fill_lf_grid_rect((mi_r, mi_c), bw / MI, bh / MI, tx_w as u8, tx_h as u8, 0); |
| 8700 | 8700 | SB_RECT_HITS.with(|c| c.set(c.get() + 1)); |
| @@ -10657,9 +10657,8 @@ fn decode_leaf8( | ||
| 10657 | 10657 | // above/left palette state over its own cell so the next block's ctx and |
| 10658 | 10658 | // colour cache do not read a previous block's palette (lane-palette2 r8). |
| 10659 | 10659 | { |
| 10660 | - let pal_at = (leaf_mi.0 / (SUB / MI), leaf_mi.1 / (SUB / MI)); | |
| 10661 | - neighbours.record_palette_y_rect(pal_at, 8, 8, 0, [0u16; 8]); | |
| 10662 | - neighbours.record_palette_uv_rect(pal_at, 8, 8, 0, [0u16; 8]); | |
| 10660 | + neighbours.record_palette_y_rect(leaf_mi, 8, 8, 0, [0u16; 8]); | |
| 10661 | + neighbours.record_palette_uv_rect(leaf_mi, 8, 8, 0, [0u16; 8]); | |
| 10663 | 10662 | } |
| 10664 | 10663 | neighbours.fill_skip_grid(leaf_mi, 2, skip); |
| 10665 | 10664 | neighbours.fill_lf_grid(leaf_mi, 2, 4, 0); |
| @@ -10671,9 +10670,8 @@ fn decode_leaf8( | ||
| 10671 | 10670 | // above/left palette state over its own cell so the next block's ctx and |
| 10672 | 10671 | // colour cache do not read a previous block's palette (lane-palette2 r8). |
| 10673 | 10672 | { |
| 10674 | - let pal_at = (leaf_mi.0 / (SUB / MI), leaf_mi.1 / (SUB / MI)); | |
| 10675 | - neighbours.record_palette_y_rect(pal_at, 8, 8, 0, [0u16; 8]); | |
| 10676 | - neighbours.record_palette_uv_rect(pal_at, 8, 8, 0, [0u16; 8]); | |
| 10673 | + neighbours.record_palette_y_rect(leaf_mi, 8, 8, 0, [0u16; 8]); | |
| 10674 | + neighbours.record_palette_uv_rect(leaf_mi, 8, 8, 0, [0u16; 8]); | |
| 10677 | 10675 | } |
| 10678 | 10676 | neighbours.fill_skip_grid(leaf_mi, 2, skip); |
| 10679 | 10677 | // lane-kf900 r1: the leaf's own RESOLVED transform size, never the literal |
| @@ -23277,19 +23275,19 @@ mod tests { | ||
| 23277 | 23275 | fn a_sub16_leaf_after_a_palette_block_yields_palette_ctx_zero() { |
| 23278 | 23276 | let mut n = Neighbours::new(4, 4, 16, 16); |
| 23279 | 23277 | // A real 16x16 palette block covering SUB cell (1, 1). |
| 23280 | - n.record_palette_y_rect((1, 1), 16, 16, 2, [7, 9, 0, 0, 0, 0, 0, 0]); | |
| 23278 | + n.record_palette_y_rect((4, 4), 16, 16, 2, [7, 9, 0, 0, 0, 0, 0, 0]); | |
| 23281 | 23279 | let (ctx, cache) = n.palette_ctx_and_cache((1, 1)); |
| 23282 | 23280 | assert_eq!(ctx, 2, "the palette block itself must be visible"); |
| 23283 | 23281 | assert_eq!(cache, vec![7, 9]); |
| 23284 | 23282 | // An 8x8 non-palette leaf in that same cell. |
| 23285 | - n.record_palette_y_rect((1, 1), 8, 8, 0, [0u16; 8]); | |
| 23283 | + n.record_palette_y_rect((4, 4), 8, 8, 0, [0u16; 8]); | |
| 23286 | 23284 | let (ctx, cache) = n.palette_ctx_and_cache((1, 1)); |
| 23287 | 23285 | assert_eq!(ctx, 0, "a sub-16 non-palette leaf must clear its own cell"); |
| 23288 | 23286 | assert!(cache.is_empty(), "and its stale colour cache with it"); |
| 23289 | 23287 | // Same for the chroma half. |
| 23290 | - n.record_palette_uv_rect((1, 1), 16, 16, 2, [1, 2, 0, 0, 0, 0, 0, 0]); | |
| 23288 | + n.record_palette_uv_rect((4, 4), 16, 16, 2, [1, 2, 0, 0, 0, 0, 0, 0]); | |
| 23291 | 23289 | assert_eq!(n.palette_uv_cache((1, 1)), vec![1, 2]); |
| 23292 | - n.record_palette_uv_rect((1, 1), 8, 8, 0, [0u16; 8]); | |
| 23290 | + n.record_palette_uv_rect((4, 4), 8, 8, 0, [0u16; 8]); | |
| 23293 | 23291 | assert!(n.palette_uv_cache((1, 1)).is_empty()); |
| 23294 | 23292 | } |
| 23295 | 23293 |
crates/ec-av1/src/stream.rsmodified+21 -1
| @@ -2974,10 +2974,30 @@ mod tests { | ||
| 2974 | 2974 | "--enable-1to4-partitions=1", |
| 2975 | 2975 | "--min-partition-size=8", |
| 2976 | 2976 | ]; |
| 2977 | - let arms: [(&str, String, &[&str]); 3] = [ | |
| 2977 | + // lane-kf900 r6: arms 3-4 are the palette + `--enable-tx-size-search=1` | |
| 2978 | + // shape whose neighbour palette lookup was SUB-granular -- a 16x8 strip | |
| 2979 | + // pair shares one 16px cell, so strip 1 read strip 0's palette size and | |
| 2980 | + // the colour cache came out short. Both were whole-frame wrong before | |
| 2981 | + // the mi-granular fix (`$HOME/.cache/kf900-r6/sweep.log`: smptebars | |
| 2982 | + // cq40/cq55 txs=1 pal=1 = DIFF). | |
| 2983 | + let screen_txs: &[&str] = &[ | |
| 2984 | + "--tune-content=screen", | |
| 2985 | + "--enable-palette=1", | |
| 2986 | + "--enable-1to4-partitions=1", | |
| 2987 | + "--min-partition-size=8", | |
| 2988 | + "--max-partition-size=32", | |
| 2989 | + "--sb-size=64", | |
| 2990 | + "--enable-intrabc=1", | |
| 2991 | + "--enable-tx-size-search=1", | |
| 2992 | + ]; | |
| 2993 | + let cq40: Vec<&str> = screen_txs.iter().copied().chain(["--cq-level=40"]).collect(); | |
| 2994 | + let cq55: Vec<&str> = screen_txs.iter().copied().chain(["--cq-level=55"]).collect(); | |
| 2995 | + let arms: [(&str, String, &[&str]); 5] = [ | |
| 2978 | 2996 | ("testsrc2-pinned", "testsrc2=s=256x192:r=25".to_string(), &[]), |
| 2979 | 2997 | ("testsrc2-screen", "testsrc2=s=256x192:r=25".to_string(), screen), |
| 2980 | 2998 | ("smptebars-screen", "smptebars=size=256x192:rate=25".to_string(), screen), |
| 2999 | + ("smptebars-screen-txs-cq40", "smptebars=size=256x192:rate=25".to_string(), &cq40), | |
| 3000 | + ("smptebars-screen-txs-cq55", "smptebars=size=256x192:rate=25".to_string(), &cq55), | |
| 2981 | 3001 | ]; |
| 2982 | 3002 | let (mut fired_arms, mut out_of_scope, mut out_of_scope_mismatch) = (0u32, 0u32, 0u32); |
| 2983 | 3003 | let mut refused = 0u32; |