Narrow the mode-info publish surface -- palette colours only from palette blocks, (u16,u8)/u8 edge maps
Browse files at this commitce0464d1e1fa476aa75bcc5ee0f86d7268124e44Parent: a263e1e- perf
- narrow the mode-info publish surface -- palette colours only from palette blocks, (u16,u8)/u8 edge maps
1 changed file +138 -76
- crates/ec-av1/src/decode.rs +138 -76
crates/ec-av1/src/decode.rsmodified+138 -76
| @@ -6380,8 +6380,10 @@ struct Neighbours { | ||
| 6380 | 6380 | /// block (lane-av1-rect) share a single [`SUB`]-grid cell, so a coarse |
| 6381 | 6381 | /// array cannot tell the second leaf's partition symbol that the first |
| 6382 | 6382 | /// one was coded at 8x8. |
| 6383 | - above_side_mi: Vec<usize>, | |
| 6384 | - left_side_mi: Vec<usize>, | |
| 6383 | + /// lane-publish2: `u8` (a block side is at most 128 px, and so is | |
| 6384 | + /// [`NO_NEIGHBOUR_SIDE`]) -- every block stamps these per mi. | |
| 6385 | + above_side_mi: Vec<u8>, | |
| 6386 | + left_side_mi: Vec<u8>, | |
| 6385 | 6387 | /// The luma `mode` of the last `BLOCK_4X4` leaf decoded at each mi column |
| 6386 | 6388 | /// / row, with the mi position it was written at |
| 6387 | 6389 | /// (`(usize::MAX, _)` = never written). `above_mode`/`left_mode` are on |
| @@ -6393,15 +6395,20 @@ struct Neighbours { | ||
| 6393 | 6395 | /// and read only by [`decode_leaf_split4`]; the position guard makes it |
| 6394 | 6396 | /// fall back to the coarse slot whenever the real neighbour was a block |
| 6395 | 6397 | /// of 8x8 or larger (whose one mode is correct for every row it spans). |
| 6396 | - sub8_mode_col: Vec<(usize, usize)>, | |
| 6397 | - sub8_mode_row: Vec<(usize, usize)>, | |
| 6398 | + /// lane-publish2: `(mi position, mode)` narrowed from `(usize, usize)` to | |
| 6399 | + /// `(u16, u8)` -- every block stamps these mi-granular maps, and 16 bytes | |
| 6400 | + /// per mi per side of publish traffic was pure width. `u16::MAX` is the | |
| 6401 | + /// "never written" sentinel (an mi index cannot reach it: AV1's largest | |
| 6402 | + /// frame is 65536 px = 16384 mi). | |
| 6403 | + sub8_mode_col: Vec<(u16, u8)>, | |
| 6404 | + sub8_mode_row: Vec<(u16, u8)>, | |
| 6398 | 6405 | /// The `uv_mode` twin of `sub8_mode_col`/`sub8_mode_row` (lane-sub8 r5): |
| 6399 | 6406 | /// chroma's edge-filter type reads the CHROMA neighbour's `uv_mode` |
| 6400 | 6407 | /// (`get_intra_edge_filter_type`, reconintra.c:974), and the coarse |
| 6401 | 6408 | /// [`SUB`] slots cannot name it once a 16x16 is split into 8x8 leaves -- |
| 6402 | 6409 | /// the leaf above writes the same row slot the block to the left owns. |
| 6403 | - uv_mode_col: Vec<(usize, usize)>, | |
| 6404 | - uv_mode_row: Vec<(usize, usize)>, | |
| 6410 | + uv_mode_col: Vec<(u16, u8)>, | |
| 6411 | + uv_mode_row: Vec<(u16, u8)>, | |
| 6405 | 6412 | /// Every mi cell's own `uv_mode`, the mi grid libaom's |
| 6406 | 6413 | /// `chroma_above_mbmi`/`chroma_left_mbmi` read directly (`set_mi_row_col`, |
| 6407 | 6414 | /// blockd.h). lane-t900 r12: the one-slot-per-column |
| @@ -6454,8 +6461,14 @@ struct Neighbours { | ||
| 6454 | 6461 | /// compound (spec `RefFrames[1]`), or `None` for single-ref/intra -- |
| 6455 | 6462 | /// lane-av1comp: `mvstack::reference_mode_ctx`/`comp_reference_type_ctx` |
| 6456 | 6463 | /// need a full [`crate::mvstack::NeighbourRef`], not just `above_ref`'s |
| 6457 | - /// `i8`, once a compound `read_ref_frames` lands. Always `None` today | |
| 6458 | - /// (no decode path here ever produces a compound block yet). | |
| 6464 | + /// `i8`, once a compound `read_ref_frames` lands. | |
| 6465 | + /// lane-publish2 audit: the "always `None` today" note this doc used to | |
| 6466 | + /// carry is long stale -- compound blocks do occur, and | |
| 6467 | + /// [`Self::record_compound_ctx_rect_mi`] stamps the real second reference | |
| 6468 | + /// over their span right after [`Self::record_inter_rect_mi`]'s reset. | |
| 6469 | + /// The array IS read: `single_ref_p*`/`comp_ref` contexts and every | |
| 6470 | + /// [`crate::mvstack::NeighbourRef`] construction (class | |
| 6471 | + /// [[branch-dropped-as-unreachable]] -- the note, not the code, was wrong). | |
| 6459 | 6472 | above_ref1: Vec<Option<i8>>, |
| 6460 | 6473 | left_ref1: Vec<Option<i8>>, |
| 6461 | 6474 | /// The precomputed `get_comp_group_idx_context`/`get_comp_index_context` |
| @@ -6542,15 +6555,15 @@ struct Neighbours { | ||
| 6542 | 6555 | /// and its base colours -- `av1_get_palette_mode_ctx`/ |
| 6543 | 6556 | /// `av1_get_palette_cache` (pred_common.c)'s neighbour lookup, lane-palette |
| 6544 | 6557 | /// r2. UV has no equivalent yet (stage 2, unreconstructed). |
| 6545 | - above_palette_size: Vec<usize>, | |
| 6546 | - left_palette_size: Vec<usize>, | |
| 6558 | + above_palette_size: Vec<u8>, | |
| 6559 | + left_palette_size: Vec<u8>, | |
| 6547 | 6560 | above_palette_colors: Vec<[u16; 8]>, |
| 6548 | 6561 | left_palette_colors: Vec<[u16; 8]>, |
| 6549 | 6562 | /// As the four fields above, for the neighbour's own chroma (U-channel |
| 6550 | 6563 | /// only -- `av1_get_palette_cache`'s plane-1 lookup, [`Self::palette_uv_cache`]) |
| 6551 | 6564 | /// palette size/colours (lane-palette2 r1). |
| 6552 | - above_palette_uv_size: Vec<usize>, | |
| 6553 | - left_palette_uv_size: Vec<usize>, | |
| 6565 | + above_palette_uv_size: Vec<u8>, | |
| 6566 | + left_palette_uv_size: Vec<u8>, | |
| 6554 | 6567 | above_palette_uv_colors: Vec<[u16; 8]>, |
| 6555 | 6568 | left_palette_uv_colors: Vec<[u16; 8]>, |
| 6556 | 6569 | /// This tile's own top-left corner, in 4x4 mode-info units (spec |
| @@ -6590,12 +6603,12 @@ impl Neighbours { | ||
| 6590 | 6603 | left_uv_mode: vec![DC_PRED; rows], |
| 6591 | 6604 | above_side: vec![NO_NEIGHBOUR_SIDE; cols], |
| 6592 | 6605 | left_side: vec![NO_NEIGHBOUR_SIDE; rows], |
| 6593 | - above_side_mi: vec![NO_NEIGHBOUR_SIDE; cols * (SUB / MI)], | |
| 6594 | - left_side_mi: vec![NO_NEIGHBOUR_SIDE; rows * (SUB / MI)], | |
| 6595 | - sub8_mode_col: vec![(usize::MAX, 0); cols * (SUB / MI)], | |
| 6596 | - sub8_mode_row: vec![(usize::MAX, 0); rows * (SUB / MI)], | |
| 6597 | - uv_mode_col: vec![(usize::MAX, 0); cols * (SUB / MI)], | |
| 6598 | - uv_mode_row: vec![(usize::MAX, 0); rows * (SUB / MI)], | |
| 6606 | + above_side_mi: vec![NO_NEIGHBOUR_SIDE as u8; cols * (SUB / MI)], | |
| 6607 | + left_side_mi: vec![NO_NEIGHBOUR_SIDE as u8; rows * (SUB / MI)], | |
| 6608 | + sub8_mode_col: vec![(u16::MAX, 0); cols * (SUB / MI)], | |
| 6609 | + sub8_mode_row: vec![(u16::MAX, 0); rows * (SUB / MI)], | |
| 6610 | + uv_mode_col: vec![(u16::MAX, 0); cols * (SUB / MI)], | |
| 6611 | + uv_mode_row: vec![(u16::MAX, 0); rows * (SUB / MI)], | |
| 6599 | 6612 | uv_mode_grid: vec![u8::MAX; cols * (SUB / MI) * rows * (SUB / MI)], |
| 6600 | 6613 | uv_grid_cols: cols * (SUB / MI), |
| 6601 | 6614 | above_txfm: vec![TXFM_CTX_INIT; cols * (SUB / MI)], |
| @@ -6661,7 +6674,7 @@ impl Neighbours { | ||
| 6661 | 6674 | let end = col1_mi.min(self.above.len()); |
| 6662 | 6675 | for i in col0_mi.min(end)..end { |
| 6663 | 6676 | self.above[i] = Default::default(); |
| 6664 | - self.above_side_mi[i] = NO_NEIGHBOUR_SIDE; | |
| 6677 | + self.above_side_mi[i] = NO_NEIGHBOUR_SIDE as u8; | |
| 6665 | 6678 | } |
| 6666 | 6679 | let (sc0, sc1) = ( |
| 6667 | 6680 | col0_mi / (SUB / MI), |
| @@ -6689,8 +6702,8 @@ impl Neighbours { | ||
| 6689 | 6702 | // tile's first block would read as its own above neighbour. |
| 6690 | 6703 | let mcol_end = col1_mi.min(self.sub8_mode_col.len()); |
| 6691 | 6704 | for i in col0_mi.min(mcol_end)..mcol_end { |
| 6692 | - self.sub8_mode_col[i] = (usize::MAX, 0); | |
| 6693 | - self.uv_mode_col[i] = (usize::MAX, 0); | |
| 6705 | + self.sub8_mode_col[i] = (u16::MAX, 0); | |
| 6706 | + self.uv_mode_col[i] = (u16::MAX, 0); | |
| 6694 | 6707 | } |
| 6695 | 6708 | // lane-mergefix r2: `av1_zero_above_context` also memsets the txfm row |
| 6696 | 6709 | // over the tile's own column span (to `tx_size_wide[TX_SIZES_LARGEST]`, |
| @@ -6735,14 +6748,21 @@ impl Neighbours { | ||
| 6735 | 6748 | // cache came out one entry short (class [[context-read-from-one-cell]]). |
| 6736 | 6749 | for cell in 0..(w / MI).max(1) { |
| 6737 | 6750 | if let Some(e) = self.above_palette_size.get_mut(c + cell) { |
| 6738 | - *e = size; | |
| 6739 | - self.above_palette_colors[c + cell] = colors; | |
| 6751 | + *e = size as u8; | |
| 6752 | + // lane-publish2: spec 5.11.46 `get_palette_cache` reads a | |
| 6753 | + // neighbour's colours only where its palette size > 0, so a | |
| 6754 | + // non-palette block need not stamp 16 bytes of zeroes here. | |
| 6755 | + if size > 0 { | |
| 6756 | + self.above_palette_colors[c + cell] = colors; | |
| 6757 | + } | |
| 6740 | 6758 | } |
| 6741 | 6759 | } |
| 6742 | 6760 | for cell in 0..(h / MI).max(1) { |
| 6743 | 6761 | if let Some(e) = self.left_palette_size.get_mut(r + cell) { |
| 6744 | - *e = size; | |
| 6745 | - self.left_palette_colors[r + cell] = colors; | |
| 6762 | + *e = size as u8; | |
| 6763 | + if size > 0 { | |
| 6764 | + self.left_palette_colors[r + cell] = colors; | |
| 6765 | + } | |
| 6746 | 6766 | } |
| 6747 | 6767 | } |
| 6748 | 6768 | } |
| @@ -6777,7 +6797,7 @@ impl Neighbours { | ||
| 6777 | 6797 | // `xd->above_mbmi` exists for every row but the tile's own first. |
| 6778 | 6798 | let above_is_palette = r > self.tile_row0_mi && self.above_palette_size[c] > 0; |
| 6779 | 6799 | let (above_n, above_colors) = if above_ok && self.above_palette_size[c] > 0 { |
| 6780 | - (self.above_palette_size[c], self.above_palette_colors[c]) | |
| 6800 | + (usize::from(self.above_palette_size[c]), self.above_palette_colors[c]) | |
| 6781 | 6801 | } else { |
| 6782 | 6802 | (0, [0u16; 8]) |
| 6783 | 6803 | }; |
| @@ -6788,7 +6808,7 @@ impl Neighbours { | ||
| 6788 | 6808 | // and its `palette_y_mode` ctx. |
| 6789 | 6809 | let left_ok = c > self.tile_col0_mi; |
| 6790 | 6810 | let (left_n, left_colors) = if left_ok && self.left_palette_size[r] > 0 { |
| 6791 | - (self.left_palette_size[r], self.left_palette_colors[r]) | |
| 6811 | + (usize::from(self.left_palette_size[r]), self.left_palette_colors[r]) | |
| 6792 | 6812 | } else { |
| 6793 | 6813 | (0, [0u16; 8]) |
| 6794 | 6814 | }; |
| @@ -6853,14 +6873,18 @@ impl Neighbours { | ||
| 6853 | 6873 | // mi granularity, see [`Self::record_palette_y_rect`]. |
| 6854 | 6874 | for cell in 0..(w / MI).max(1) { |
| 6855 | 6875 | if let Some(e) = self.above_palette_uv_size.get_mut(c + cell) { |
| 6856 | - *e = size; | |
| 6857 | - self.above_palette_uv_colors[c + cell] = colors; | |
| 6876 | + *e = size as u8; | |
| 6877 | + if size > 0 { | |
| 6878 | + self.above_palette_uv_colors[c + cell] = colors; | |
| 6879 | + } | |
| 6858 | 6880 | } |
| 6859 | 6881 | } |
| 6860 | 6882 | for cell in 0..(h / MI).max(1) { |
| 6861 | 6883 | if let Some(e) = self.left_palette_uv_size.get_mut(r + cell) { |
| 6862 | - *e = size; | |
| 6863 | - self.left_palette_uv_colors[r + cell] = colors; | |
| 6884 | + *e = size as u8; | |
| 6885 | + if size > 0 { | |
| 6886 | + self.left_palette_uv_colors[r + cell] = colors; | |
| 6887 | + } | |
| 6864 | 6888 | } |
| 6865 | 6889 | } |
| 6866 | 6890 | } |
| @@ -6880,14 +6904,14 @@ impl Neighbours { | ||
| 6880 | 6904 | let (r, c) = mi; |
| 6881 | 6905 | let above_ok = r % 16 != 0; |
| 6882 | 6906 | let (above_n, above_colors) = if above_ok && self.above_palette_uv_size[c] > 0 { |
| 6883 | - (self.above_palette_uv_size[c], self.above_palette_uv_colors[c]) | |
| 6907 | + (usize::from(self.above_palette_uv_size[c]), self.above_palette_uv_colors[c]) | |
| 6884 | 6908 | } else { |
| 6885 | 6909 | (0, [0u16; 8]) |
| 6886 | 6910 | }; |
| 6887 | 6911 | // Same tile-relative left availability as the luma cache above. |
| 6888 | 6912 | let left_ok = c > self.tile_col0_mi; |
| 6889 | 6913 | let (left_n, left_colors) = if left_ok && self.left_palette_uv_size[r] > 0 { |
| 6890 | - (self.left_palette_uv_size[r], self.left_palette_uv_colors[r]) | |
| 6914 | + (usize::from(self.left_palette_uv_size[r]), self.left_palette_uv_colors[r]) | |
| 6891 | 6915 | } else { |
| 6892 | 6916 | (0, [0u16; 8]) |
| 6893 | 6917 | }; |
| @@ -7087,7 +7111,7 @@ impl Neighbours { | ||
| 7087 | 7111 | self.left_mode.iter_mut().for_each(|m| *m = DC_PRED); |
| 7088 | 7112 | self.left_uv_mode.iter_mut().for_each(|m| *m = DC_PRED); |
| 7089 | 7113 | self.left_side.iter_mut().for_each(|s| *s = NO_NEIGHBOUR_SIDE); |
| 7090 | - self.left_side_mi.iter_mut().for_each(|s| *s = NO_NEIGHBOUR_SIDE); | |
| 7114 | + self.left_side_mi.iter_mut().for_each(|s| *s = NO_NEIGHBOUR_SIDE as u8); | |
| 7091 | 7115 | self.left_skip.iter_mut().for_each(|s| *s = false); |
| 7092 | 7116 | self.left_skip_mode.iter_mut().for_each(|s| *s = false); |
| 7093 | 7117 | self.left_inter.iter_mut().for_each(|i| *i = false); |
| @@ -7098,8 +7122,8 @@ impl Neighbours { | ||
| 7098 | 7122 | self.left_filter.iter_mut().for_each(|f| *f = [3u8; 2]); |
| 7099 | 7123 | // lane-sub8 r6: mi-granular row maps reset with the rest of the left |
| 7100 | 7124 | // context (a tile/SB-row boundary has no left neighbour). |
| 7101 | - self.sub8_mode_row.iter_mut().for_each(|s| *s = (usize::MAX, 0)); | |
| 7102 | - self.uv_mode_row.iter_mut().for_each(|s| *s = (usize::MAX, 0)); | |
| 7125 | + self.sub8_mode_row.iter_mut().for_each(|s| *s = (u16::MAX, 0)); | |
| 7126 | + self.uv_mode_row.iter_mut().for_each(|s| *s = (u16::MAX, 0)); | |
| 7103 | 7127 | // lane-tiles r11 (COMMON's NEIGHBOUR MAPS rule): the palette side bands |
| 7104 | 7128 | // are per-mi maps like every other one here, so they reset with the |
| 7105 | 7129 | // row too -- the left guard above is what actually stops a cross-tile |
| @@ -7207,9 +7231,9 @@ impl Neighbours { | ||
| 7207 | 7231 | self.above_skip_mode[c..c + w_mi].fill(skip_mode); |
| 7208 | 7232 | self.above_inter[c..c + w_mi].fill(is_inter); |
| 7209 | 7233 | self.above_ref[c..c + w_mi].fill(ref_frame); |
| 7210 | - // lane-av1comp: no caller of `record_inter` ever decodes a | |
| 7211 | - // compound block yet (see [`Self::above_ref1`]'s doc); the | |
| 7212 | - // parameter this becomes lands with `read_ref_frames`. | |
| 7234 | + // The single-ref default: `record_compound_ctx_rect_mi` overwrites | |
| 7235 | + // this with the block's real second reference for a compound block, | |
| 7236 | + // called right after this one (lane-publish2 audit). | |
| 7213 | 7237 | self.above_ref1[c..c + w_mi].fill(None); |
| 7214 | 7238 | // libaom `get_comp_group_idx_context`/`get_comp_index_context`'s |
| 7215 | 7239 | // single-ref special case: `ref_frame[0] == ALTREF_FRAME` reads |
| @@ -7315,8 +7339,8 @@ impl Neighbours { | ||
| 7315 | 7339 | /// arrays so the second leaf sees the first leaf's own 8x8 side rather |
| 7316 | 7340 | /// than the enclosing 16x16 slot's stale, shared state. |
| 7317 | 7341 | fn partition_ctx_mi(&self, (mi_r, mi_c): (usize, usize), side: usize) -> usize { |
| 7318 | - 2 * usize::from(self.left_side_mi[mi_r] * 2 <= side) | |
| 7319 | - + usize::from(self.above_side_mi[mi_c] * 2 <= side) | |
| 7342 | + 2 * usize::from(usize::from(self.left_side_mi[mi_r]) * 2 <= side) | |
| 7343 | + + usize::from(usize::from(self.above_side_mi[mi_c]) * 2 <= side) | |
| 7320 | 7344 | } |
| 7321 | 7345 | |
| 7322 | 7346 | /// The gathered coded/DC-sign state of the blocks above and to the left |
| @@ -7476,7 +7500,8 @@ impl Neighbours { | ||
| 7476 | 7500 | mi_h: usize, |
| 7477 | 7501 | mode: usize, |
| 7478 | 7502 | ) { |
| 7479 | - let (last_r, last_c) = (mi_r + mi_h - 1, mi_c + mi_w - 1); | |
| 7503 | + let (last_r, last_c) = ((mi_r + mi_h - 1) as u16, (mi_c + mi_w - 1) as u16); | |
| 7504 | + let mode = mode as u8; | |
| 7480 | 7505 | for cell in 0..mi_w { |
| 7481 | 7506 | if let Some(slot) = self.sub8_mode_col.get_mut(mi_c + cell) { |
| 7482 | 7507 | *slot = (last_r, mode); |
| @@ -7495,14 +7520,14 @@ impl Neighbours { | ||
| 7495 | 7520 | /// construction). See [`Self::record_mode_mi`]. |
| 7496 | 7521 | fn mode_above_mi(&self, mi_r: usize, mi_c: usize) -> Option<usize> { |
| 7497 | 7522 | match self.sub8_mode_col.get(mi_c) { |
| 7498 | - Some(&(row, m)) if mi_r > self.tile_row0_mi && row == mi_r - 1 => Some(m), | |
| 7523 | + Some(&(row, m)) if mi_r > self.tile_row0_mi && usize::from(row) == mi_r - 1 => Some(usize::from(m)), | |
| 7499 | 7524 | _ => None, |
| 7500 | 7525 | } |
| 7501 | 7526 | } |
| 7502 | 7527 | |
| 7503 | 7528 | fn mode_left_mi(&self, mi_r: usize, mi_c: usize) -> Option<usize> { |
| 7504 | 7529 | match self.sub8_mode_row.get(mi_r) { |
| 7505 | - Some(&(col, m)) if mi_c > self.tile_col0_mi && col == mi_c - 1 => Some(m), | |
| 7530 | + Some(&(col, m)) if mi_c > self.tile_col0_mi && usize::from(col) == mi_c - 1 => Some(usize::from(m)), | |
| 7506 | 7531 | _ => None, |
| 7507 | 7532 | } |
| 7508 | 7533 | } |
| @@ -7518,8 +7543,8 @@ impl Neighbours { | ||
| 7518 | 7543 | uv_mode: usize, |
| 7519 | 7544 | ) { |
| 7520 | 7545 | let (last_r, last_c) = (mi_r + mi_h - 1, mi_c + mi_w - 1); |
| 7521 | - fill_span(&mut self.uv_mode_col, mi_c, mi_w, (last_r, uv_mode)); | |
| 7522 | - fill_span(&mut self.uv_mode_row, mi_r, mi_h, (last_c, uv_mode)); | |
| 7546 | + fill_span(&mut self.uv_mode_col, mi_c, mi_w, (last_r as u16, uv_mode as u8)); | |
| 7547 | + fill_span(&mut self.uv_mode_row, mi_r, mi_h, (last_c as u16, uv_mode as u8)); | |
| 7523 | 7548 | // libaom writes one `MB_MODE_INFO` pointer into every mi cell a block |
| 7524 | 7549 | // covers, so the chroma neighbour read below is a plain grid read. |
| 7525 | 7550 | let stride = self.uv_grid_cols; |
| @@ -7590,20 +7615,20 @@ impl Neighbours { | ||
| 7590 | 7615 | }; |
| 7591 | 7616 | let above = match self.uv_mode_col.get(mi_c) { |
| 7592 | 7617 | _ if have_above && let Some(m) = cell(&self.uv_mode_grid, mi_r - 1, mi_c) => m, |
| 7593 | - Some(&(row, m)) if have_above && row == mi_r - 1 => m, | |
| 7618 | + Some(&(row, m)) if have_above && usize::from(row) == mi_r - 1 => usize::from(m), | |
| 7594 | 7619 | _ if have_above => self.above_uv_mode[c], |
| 7595 | 7620 | _ => DC_PRED, |
| 7596 | 7621 | }; |
| 7597 | 7622 | let left = match self.uv_mode_row.get(mi_r) { |
| 7598 | 7623 | _ if have_left && let Some(m) = cell(&self.uv_mode_grid, mi_r, mi_c - 1) => m, |
| 7599 | - Some(&(col, m)) if have_left && col == mi_c - 1 => m, | |
| 7624 | + Some(&(col, m)) if have_left && usize::from(col) == mi_c - 1 => usize::from(m), | |
| 7600 | 7625 | _ if have_left => self.left_uv_mode[r], |
| 7601 | 7626 | _ => DC_PRED, |
| 7602 | 7627 | }; |
| 7603 | 7628 | if have_above && cell(&self.uv_mode_grid, mi_r - 1, mi_c).is_some_and(|m| { |
| 7604 | - !matches!(self.uv_mode_col.get(mi_c), Some(&(row, cm)) if row == mi_r - 1 && cm == m) | |
| 7629 | + !matches!(self.uv_mode_col.get(mi_c), Some(&(row, cm)) if usize::from(row) == mi_r - 1 && usize::from(cm) == m) | |
| 7605 | 7630 | }) || have_left && cell(&self.uv_mode_grid, mi_r, mi_c - 1).is_some_and(|m| { |
| 7606 | - !matches!(self.uv_mode_row.get(mi_r), Some(&(col, cm)) if col == mi_c - 1 && cm == m) | |
| 7631 | + !matches!(self.uv_mode_row.get(mi_r), Some(&(col, cm)) if usize::from(col) == mi_c - 1 && usize::from(cm) == m) | |
| 7607 | 7632 | }) { |
| 7608 | 7633 | UV_MODE_GRID_OVERRIDE_HITS.with(|h| h.set(h.get() + 1)); |
| 7609 | 7634 | } |
| @@ -7762,8 +7787,8 @@ impl Neighbours { | ||
| 7762 | 7787 | if crate::envflags::env_flag!("EC_ECPUB") { |
| 7763 | 7788 | eprintln!("EC_ECPUB blk mi=({mi_r},{mi_c}) wh=({w},{h}) lvl={}", states[0].level); |
| 7764 | 7789 | } |
| 7765 | - fill_span(&mut self.left_side_mi, mi_r, h_mi, h); | |
| 7766 | - fill_span(&mut self.above_side_mi, mi_c, w_mi, w); | |
| 7790 | + fill_span(&mut self.left_side_mi, mi_r, h_mi, h as u8); | |
| 7791 | + fill_span(&mut self.above_side_mi, mi_c, w_mi, w as u8); | |
| 7767 | 7792 | // A chroma 4x4 unit straddling the true luma edge is still whole in |
| 7768 | 7793 | // chroma's own halved grid, so libaom rounds the luma bound up to the |
| 7769 | 7794 | // plane's own 4x4 unit before clamping a subsampled plane |
| @@ -7952,8 +7977,8 @@ impl Neighbours { | ||
| 7952 | 7977 | let (w_mi, h_mi) = (w / MI, h / MI); |
| 7953 | 7978 | self.record_mode_mi(mi_r, mi_c, w_mi, h_mi, mode); |
| 7954 | 7979 | self.record_uv_mode_mi(mi_r, mi_c, w_mi, h_mi, uv_mode); |
| 7955 | - fill_span(&mut self.left_side_mi, mi_r, h_mi, h); | |
| 7956 | - fill_span(&mut self.above_side_mi, mi_c, w_mi, w); | |
| 7980 | + fill_span(&mut self.left_side_mi, mi_r, h_mi, h as u8); | |
| 7981 | + fill_span(&mut self.above_side_mi, mi_c, w_mi, w as u8); | |
| 7957 | 7982 | let round_up_even = |n: usize| n.div_ceil(2) * 2; |
| 7958 | 7983 | let (bound_h, bound_w) = (round_up_even(self.mi_rows), round_up_even(self.mi_cols)); |
| 7959 | 7984 | for (plane_idx, grid) in chroma_grids.into_iter().enumerate() { |
| @@ -8694,10 +8719,16 @@ fn record_strip_palette( | ||
| 8694 | 8719 | { |
| 8695 | 8720 | for cell in 0..(bw / MI).max(1) { |
| 8696 | 8721 | if let Some(e) = n.above_palette_size.get_mut(c + cell) { |
| 8697 | - *e = y_size; | |
| 8698 | - n.above_palette_colors[c + cell] = y_colors; | |
| 8699 | - n.above_palette_uv_size[c + cell] = uv_size; | |
| 8700 | - n.above_palette_uv_colors[c + cell] = uv_colors; | |
| 8722 | + *e = y_size as u8; | |
| 8723 | + n.above_palette_uv_size[c + cell] = uv_size as u8; | |
| 8724 | + // lane-publish2, see [`Neighbours::record_palette_y_rect`]: | |
| 8725 | + // colours of a size-0 neighbour are never read. | |
| 8726 | + if y_size > 0 { | |
| 8727 | + n.above_palette_colors[c + cell] = y_colors; | |
| 8728 | + } | |
| 8729 | + if uv_size > 0 { | |
| 8730 | + n.above_palette_uv_colors[c + cell] = uv_colors; | |
| 8731 | + } | |
| 8701 | 8732 | } |
| 8702 | 8733 | } |
| 8703 | 8734 | } |
| @@ -8706,10 +8737,14 @@ fn record_strip_palette( | ||
| 8706 | 8737 | if n.left_palette_size.get(r + cell).is_none() { |
| 8707 | 8738 | break; |
| 8708 | 8739 | } |
| 8709 | - n.left_palette_size[r + cell] = y_size; | |
| 8710 | - n.left_palette_colors[r + cell] = y_colors; | |
| 8711 | - n.left_palette_uv_size[r + cell] = uv_size; | |
| 8712 | - n.left_palette_uv_colors[r + cell] = uv_colors; | |
| 8740 | + n.left_palette_size[r + cell] = y_size as u8; | |
| 8741 | + n.left_palette_uv_size[r + cell] = uv_size as u8; | |
| 8742 | + if y_size > 0 { | |
| 8743 | + n.left_palette_colors[r + cell] = y_colors; | |
| 8744 | + } | |
| 8745 | + if uv_size > 0 { | |
| 8746 | + n.left_palette_uv_colors[r + cell] = uv_colors; | |
| 8747 | + } | |
| 8713 | 8748 | } |
| 8714 | 8749 | } |
| 8715 | 8750 | } |
| @@ -11663,12 +11698,12 @@ fn decode_rect4_16_strip( | ||
| 11663 | 11698 | // the left (mirrored under VERT_4). |
| 11664 | 11699 | for cell in 0..mi_w { |
| 11665 | 11700 | if let Some(slot) = neighbours.above_side_mi.get_mut(lmi.1 + cell) { |
| 11666 | - *slot = bw; | |
| 11701 | + *slot = bw as u8; | |
| 11667 | 11702 | } |
| 11668 | 11703 | } |
| 11669 | 11704 | for cell in 0..mi_h { |
| 11670 | 11705 | if let Some(slot) = neighbours.left_side_mi.get_mut(lmi.0 + cell) { |
| 11671 | - *slot = bh; | |
| 11706 | + *slot = bh as u8; | |
| 11672 | 11707 | } |
| 11673 | 11708 | } |
| 11674 | 11709 | if has_chroma { |
| @@ -15744,8 +15779,8 @@ fn decode_leaf_rect8( | ||
| 15744 | 15779 | // -- the mirror of `decode_leaf_split4`'s `{31, 31}`, which |
| 15745 | 15780 | // `partition_ctx_mi` reads back off these side values. |
| 15746 | 15781 | for cell in 0..2 { |
| 15747 | - neighbours.above_side_mi[leaf_mi.1 + cell] = bw; | |
| 15748 | - neighbours.left_side_mi[leaf_mi.0 + cell] = bh; | |
| 15782 | + neighbours.above_side_mi[leaf_mi.1 + cell] = bw as u8; | |
| 15783 | + neighbours.left_side_mi[leaf_mi.0 + cell] = bh as u8; | |
| 15749 | 15784 | } |
| 15750 | 15785 | let round_up_even = |n: usize| n.div_ceil(2) * 2; |
| 15751 | 15786 | let bound_h = round_up_even(neighbours.mi_rows); |
| @@ -16542,10 +16577,10 @@ fn tx_size_context_txfm_rect( | ||
| 16542 | 16577 | let mut above = usize::from(n.above_txfm[mi_c]) >= own_w; |
| 16543 | 16578 | let mut left = usize::from(n.left_txfm[mi_r]) >= own_h; |
| 16544 | 16579 | if has_above && n.above_inter[mi_c] { |
| 16545 | - above = n.above_side_mi[mi_c] >= own_w; | |
| 16580 | + above = usize::from(n.above_side_mi[mi_c]) >= own_w; | |
| 16546 | 16581 | } |
| 16547 | 16582 | if has_left && n.left_inter[mi_r] { |
| 16548 | - left = n.left_side_mi[mi_r] >= own_h; | |
| 16583 | + left = usize::from(n.left_side_mi[mi_r]) >= own_h; | |
| 16549 | 16584 | } |
| 16550 | 16585 | if crate::envflags::env_flag!("EC_TXCTX") { |
| 16551 | 16586 | eprintln!( |
| @@ -16602,10 +16637,10 @@ fn tx_size_context_txfm(n: &Neighbours, (mi_r, mi_c): (usize, usize), side: usiz | ||
| 16602 | 16637 | // then missed libaom's "an inter neighbour contributes its BLOCK size" |
| 16603 | 16638 | // override and read `tx_size_cat1` row 1 where aomdec reads row 2. |
| 16604 | 16639 | if has_above && n.above_inter[mi_c] { |
| 16605 | - above = n.above_side_mi[mi_c] >= side; | |
| 16640 | + above = usize::from(n.above_side_mi[mi_c]) >= side; | |
| 16606 | 16641 | } |
| 16607 | 16642 | if has_left && n.left_inter[mi_r] { |
| 16608 | - left = n.left_side_mi[mi_r] >= side; | |
| 16643 | + left = usize::from(n.left_side_mi[mi_r]) >= side; | |
| 16609 | 16644 | } |
| 16610 | 16645 | if crate::envflags::env_flag!("EC_TXCTX") { |
| 16611 | 16646 | eprintln!( |
| @@ -29276,14 +29311,14 @@ fn decode_inter_sub8_rect2( | ||
| 29276 | 29311 | if i == 1 { |
| 29277 | 29312 | if vert { |
| 29278 | 29313 | for cell in 0..h_mi { |
| 29279 | - neighbours.left_side_mi[gr + cell] = bh; | |
| 29314 | + neighbours.left_side_mi[gr + cell] = bh as u8; | |
| 29280 | 29315 | } |
| 29281 | - neighbours.above_side_mi[gc] = bw; | |
| 29316 | + neighbours.above_side_mi[gc] = bw as u8; | |
| 29282 | 29317 | } else { |
| 29283 | 29318 | for cell in 0..w_mi { |
| 29284 | - neighbours.above_side_mi[gc + cell] = bw; | |
| 29319 | + neighbours.above_side_mi[gc + cell] = bw as u8; | |
| 29285 | 29320 | } |
| 29286 | - neighbours.left_side_mi[gr] = bh; | |
| 29321 | + neighbours.left_side_mi[gr] = bh as u8; | |
| 29287 | 29322 | } |
| 29288 | 29323 | } |
| 29289 | 29324 | let (rmi, cmi) = lmi; |
| @@ -29762,8 +29797,8 @@ fn decode_inter_sub8_rect2( | ||
| 29762 | 29797 | // over the whole 8x8 span -- BLOCK_4X8's width above and height left, the |
| 29763 | 29798 | // same values [`decode_leaf_rect8`] writes for the intra shape. |
| 29764 | 29799 | for cell in 0..2usize { |
| 29765 | - neighbours.above_side_mi[gc + cell] = bw; | |
| 29766 | - neighbours.left_side_mi[gr + cell] = bh; | |
| 29800 | + neighbours.above_side_mi[gc + cell] = bw as u8; | |
| 29801 | + neighbours.left_side_mi[gr + cell] = bh as u8; | |
| 29767 | 29802 | } |
| 29768 | 29803 | Ok(()) |
| 29769 | 29804 | } |
| @@ -35838,6 +35873,33 @@ mod tests { | ||
| 35838 | 35873 | assert!(n.palette_uv_cache((1, 1)).is_empty()); |
| 35839 | 35874 | } |
| 35840 | 35875 | |
| 35876 | + /// lane-publish2 (the mode-info publish surface narrowed): two invariants | |
| 35877 | + /// the byte-exact stream gate only covers indirectly -- a size-0 palette | |
| 35878 | + /// stamp leaves the PREVIOUS block's colours in place (spec 5.11.46 | |
| 35879 | + /// `get_palette_cache` reads a neighbour's colours only where its size is | |
| 35880 | + /// non-zero, so writing 16 bytes of zeroes was pure traffic), and the | |
| 35881 | + /// narrowed `(u16, u8)` mi maps keep their "never written" sentinel. | |
| 35882 | + #[test] | |
| 35883 | + fn narrowed_publish_surface_keeps_neighbour_semantics() { | |
| 35884 | + assert_eq!(std::mem::size_of::<(u16, u8)>(), 4, "the narrowing must actually be 4 bytes"); | |
| 35885 | + let fctx = &crate::decode::FrameCtx::new(); | |
| 35886 | + let mut n = Neighbours::new(4, 4, 16, 16, fctx); | |
| 35887 | + n.record_palette_y_rect((4, 4), 16, 16, 2, [7, 9, 0, 0, 0, 0, 0, 0]); | |
| 35888 | + n.record_palette_y_rect((4, 4), 16, 16, 0, [0u16; 8]); | |
| 35889 | + assert_eq!(n.above_palette_size[4], 0, "the size is what a reader gates on"); | |
| 35890 | + assert_eq!( | |
| 35891 | + n.above_palette_colors[4], | |
| 35892 | + [7, 9, 0, 0, 0, 0, 0, 0], | |
| 35893 | + "a size-0 stamp deliberately leaves the stale colours behind" | |
| 35894 | + ); | |
| 35895 | + let (ctx, cache) = n.palette_ctx_and_cache((1, 1)); | |
| 35896 | + assert_eq!(ctx, 0, "and they stay invisible to every reader"); | |
| 35897 | + assert!(cache.is_empty()); | |
| 35898 | + assert_eq!(n.mode_above_mi(4, 4), None, "u16::MAX sentinel = never written"); | |
| 35899 | + n.record_mode_mi(3, 4, 1, 1, DC_PRED); | |
| 35900 | + assert_eq!(n.mode_above_mi(4, 4), Some(DC_PRED)); | |
| 35901 | + } | |
| 35902 | + | |
| 35841 | 35903 | /// [`cdf::COMPOUND_MODE_CTX_MAP`] folded by hand against libaom's |
| 35842 | 35904 | /// `av1_mode_context_analyzer` compound branch (`mvref_common.h`): |
| 35843 | 35905 | /// `comp_ctx = compound_mode_ctx_map[refmv_ctx >> 1][min(newmv_ctx, 4)]` |