forge
Explore
Log in

Don't you dare go Hollow

Merge branch 'lane-publish2' (3737303f): palette colour caches stamped only by palette blocks (spec reads them only where size > 0), sub-8 and uv mode edge arrays narrowed to (u16,u8), side and palette-size bands to u8; second-reference edge array audited as correct (stale comments fixed); byte-exact, -0.13% instructions

Browse files at this commit

b032d070b0c354061d4b44ef59d4c4aabff49b1fAhmet Kaan GümüşParent: 59bce73ce0464d
crates/ec-av1/src/decode.rsmodified+138 -76
@@ -6388,8 +6388,10 @@ struct Neighbours {
63886388 /// block (lane-av1-rect) share a single [`SUB`]-grid cell, so a coarse
63896389 /// array cannot tell the second leaf's partition symbol that the first
63906390 /// one was coded at 8x8.
6391- above_side_mi: Vec<usize>,
6392- left_side_mi: Vec<usize>,
6391+ /// lane-publish2: `u8` (a block side is at most 128 px, and so is
6392+ /// [`NO_NEIGHBOUR_SIDE`]) -- every block stamps these per mi.
6393+ above_side_mi: Vec<u8>,
6394+ left_side_mi: Vec<u8>,
63936395 /// The luma `mode` of the last `BLOCK_4X4` leaf decoded at each mi column
63946396 /// / row, with the mi position it was written at
63956397 /// (`(usize::MAX, _)` = never written). `above_mode`/`left_mode` are on
@@ -6401,15 +6403,20 @@ struct Neighbours {
64016403 /// and read only by [`decode_leaf_split4`]; the position guard makes it
64026404 /// fall back to the coarse slot whenever the real neighbour was a block
64036405 /// of 8x8 or larger (whose one mode is correct for every row it spans).
6404- sub8_mode_col: Vec<(usize, usize)>,
6405- sub8_mode_row: Vec<(usize, usize)>,
6406+ /// lane-publish2: `(mi position, mode)` narrowed from `(usize, usize)` to
6407+ /// `(u16, u8)` -- every block stamps these mi-granular maps, and 16 bytes
6408+ /// per mi per side of publish traffic was pure width. `u16::MAX` is the
6409+ /// "never written" sentinel (an mi index cannot reach it: AV1's largest
6410+ /// frame is 65536 px = 16384 mi).
6411+ sub8_mode_col: Vec<(u16, u8)>,
6412+ sub8_mode_row: Vec<(u16, u8)>,
64066413 /// The `uv_mode` twin of `sub8_mode_col`/`sub8_mode_row` (lane-sub8 r5):
64076414 /// chroma's edge-filter type reads the CHROMA neighbour's `uv_mode`
64086415 /// (`get_intra_edge_filter_type`, reconintra.c:974), and the coarse
64096416 /// [`SUB`] slots cannot name it once a 16x16 is split into 8x8 leaves --
64106417 /// the leaf above writes the same row slot the block to the left owns.
6411- uv_mode_col: Vec<(usize, usize)>,
6412- uv_mode_row: Vec<(usize, usize)>,
6418+ uv_mode_col: Vec<(u16, u8)>,
6419+ uv_mode_row: Vec<(u16, u8)>,
64136420 /// Every mi cell's own `uv_mode`, the mi grid libaom's
64146421 /// `chroma_above_mbmi`/`chroma_left_mbmi` read directly (`set_mi_row_col`,
64156422 /// blockd.h). lane-t900 r12: the one-slot-per-column
@@ -6462,8 +6469,14 @@ struct Neighbours {
64626469 /// compound (spec `RefFrames[1]`), or `None` for single-ref/intra --
64636470 /// lane-av1comp: `mvstack::reference_mode_ctx`/`comp_reference_type_ctx`
64646471 /// need a full [`crate::mvstack::NeighbourRef`], not just `above_ref`'s
6465- /// `i8`, once a compound `read_ref_frames` lands. Always `None` today
6466- /// (no decode path here ever produces a compound block yet).
6472+ /// `i8`, once a compound `read_ref_frames` lands.
6473+ /// lane-publish2 audit: the "always `None` today" note this doc used to
6474+ /// carry is long stale -- compound blocks do occur, and
6475+ /// [`Self::record_compound_ctx_rect_mi`] stamps the real second reference
6476+ /// over their span right after [`Self::record_inter_rect_mi`]'s reset.
6477+ /// The array IS read: `single_ref_p*`/`comp_ref` contexts and every
6478+ /// [`crate::mvstack::NeighbourRef`] construction (class
6479+ /// [[branch-dropped-as-unreachable]] -- the note, not the code, was wrong).
64676480 above_ref1: Vec<Option<i8>>,
64686481 left_ref1: Vec<Option<i8>>,
64696482 /// The precomputed `get_comp_group_idx_context`/`get_comp_index_context`
@@ -6550,15 +6563,15 @@ struct Neighbours {
65506563 /// and its base colours -- `av1_get_palette_mode_ctx`/
65516564 /// `av1_get_palette_cache` (pred_common.c)'s neighbour lookup, lane-palette
65526565 /// r2. UV has no equivalent yet (stage 2, unreconstructed).
6553- above_palette_size: Vec<usize>,
6554- left_palette_size: Vec<usize>,
6566+ above_palette_size: Vec<u8>,
6567+ left_palette_size: Vec<u8>,
65556568 above_palette_colors: Vec<[u16; 8]>,
65566569 left_palette_colors: Vec<[u16; 8]>,
65576570 /// As the four fields above, for the neighbour's own chroma (U-channel
65586571 /// only -- `av1_get_palette_cache`'s plane-1 lookup, [`Self::palette_uv_cache`])
65596572 /// palette size/colours (lane-palette2 r1).
6560- above_palette_uv_size: Vec<usize>,
6561- left_palette_uv_size: Vec<usize>,
6573+ above_palette_uv_size: Vec<u8>,
6574+ left_palette_uv_size: Vec<u8>,
65626575 above_palette_uv_colors: Vec<[u16; 8]>,
65636576 left_palette_uv_colors: Vec<[u16; 8]>,
65646577 /// This tile's own top-left corner, in 4x4 mode-info units (spec
@@ -6598,12 +6611,12 @@ impl Neighbours {
65986611 left_uv_mode: vec![DC_PRED; rows],
65996612 above_side: vec![NO_NEIGHBOUR_SIDE; cols],
66006613 left_side: vec![NO_NEIGHBOUR_SIDE; rows],
6601- above_side_mi: vec![NO_NEIGHBOUR_SIDE; cols * (SUB / MI)],
6602- left_side_mi: vec![NO_NEIGHBOUR_SIDE; rows * (SUB / MI)],
6603- sub8_mode_col: vec![(usize::MAX, 0); cols * (SUB / MI)],
6604- sub8_mode_row: vec![(usize::MAX, 0); rows * (SUB / MI)],
6605- uv_mode_col: vec![(usize::MAX, 0); cols * (SUB / MI)],
6606- uv_mode_row: vec![(usize::MAX, 0); rows * (SUB / MI)],
6614+ above_side_mi: vec![NO_NEIGHBOUR_SIDE as u8; cols * (SUB / MI)],
6615+ left_side_mi: vec![NO_NEIGHBOUR_SIDE as u8; rows * (SUB / MI)],
6616+ sub8_mode_col: vec![(u16::MAX, 0); cols * (SUB / MI)],
6617+ sub8_mode_row: vec![(u16::MAX, 0); rows * (SUB / MI)],
6618+ uv_mode_col: vec![(u16::MAX, 0); cols * (SUB / MI)],
6619+ uv_mode_row: vec![(u16::MAX, 0); rows * (SUB / MI)],
66076620 uv_mode_grid: vec![u8::MAX; cols * (SUB / MI) * rows * (SUB / MI)],
66086621 uv_grid_cols: cols * (SUB / MI),
66096622 above_txfm: vec![TXFM_CTX_INIT; cols * (SUB / MI)],
@@ -6669,7 +6682,7 @@ impl Neighbours {
66696682 let end = col1_mi.min(self.above.len());
66706683 for i in col0_mi.min(end)..end {
66716684 self.above[i] = Default::default();
6672- self.above_side_mi[i] = NO_NEIGHBOUR_SIDE;
6685+ self.above_side_mi[i] = NO_NEIGHBOUR_SIDE as u8;
66736686 }
66746687 let (sc0, sc1) = (
66756688 col0_mi / (SUB / MI),
@@ -6697,8 +6710,8 @@ impl Neighbours {
66976710 // tile's first block would read as its own above neighbour.
66986711 let mcol_end = col1_mi.min(self.sub8_mode_col.len());
66996712 for i in col0_mi.min(mcol_end)..mcol_end {
6700- self.sub8_mode_col[i] = (usize::MAX, 0);
6701- self.uv_mode_col[i] = (usize::MAX, 0);
6713+ self.sub8_mode_col[i] = (u16::MAX, 0);
6714+ self.uv_mode_col[i] = (u16::MAX, 0);
67026715 }
67036716 // lane-mergefix r2: `av1_zero_above_context` also memsets the txfm row
67046717 // over the tile's own column span (to `tx_size_wide[TX_SIZES_LARGEST]`,
@@ -6743,14 +6756,21 @@ impl Neighbours {
67436756 // cache came out one entry short (class [[context-read-from-one-cell]]).
67446757 for cell in 0..(w / MI).max(1) {
67456758 if let Some(e) = self.above_palette_size.get_mut(c + cell) {
6746- *e = size;
6747- self.above_palette_colors[c + cell] = colors;
6759+ *e = size as u8;
6760+ // lane-publish2: spec 5.11.46 `get_palette_cache` reads a
6761+ // neighbour's colours only where its palette size > 0, so a
6762+ // non-palette block need not stamp 16 bytes of zeroes here.
6763+ if size > 0 {
6764+ self.above_palette_colors[c + cell] = colors;
6765+ }
67486766 }
67496767 }
67506768 for cell in 0..(h / MI).max(1) {
67516769 if let Some(e) = self.left_palette_size.get_mut(r + cell) {
6752- *e = size;
6753- self.left_palette_colors[r + cell] = colors;
6770+ *e = size as u8;
6771+ if size > 0 {
6772+ self.left_palette_colors[r + cell] = colors;
6773+ }
67546774 }
67556775 }
67566776 }
@@ -6785,7 +6805,7 @@ impl Neighbours {
67856805 // `xd->above_mbmi` exists for every row but the tile's own first.
67866806 let above_is_palette = r > self.tile_row0_mi && self.above_palette_size[c] > 0;
67876807 let (above_n, above_colors) = if above_ok && self.above_palette_size[c] > 0 {
6788- (self.above_palette_size[c], self.above_palette_colors[c])
6808+ (usize::from(self.above_palette_size[c]), self.above_palette_colors[c])
67896809 } else {
67906810 (0, [0u16; 8])
67916811 };
@@ -6796,7 +6816,7 @@ impl Neighbours {
67966816 // and its `palette_y_mode` ctx.
67976817 let left_ok = c > self.tile_col0_mi;
67986818 let (left_n, left_colors) = if left_ok && self.left_palette_size[r] > 0 {
6799- (self.left_palette_size[r], self.left_palette_colors[r])
6819+ (usize::from(self.left_palette_size[r]), self.left_palette_colors[r])
68006820 } else {
68016821 (0, [0u16; 8])
68026822 };
@@ -6861,14 +6881,18 @@ impl Neighbours {
68616881 // mi granularity, see [`Self::record_palette_y_rect`].
68626882 for cell in 0..(w / MI).max(1) {
68636883 if let Some(e) = self.above_palette_uv_size.get_mut(c + cell) {
6864- *e = size;
6865- self.above_palette_uv_colors[c + cell] = colors;
6884+ *e = size as u8;
6885+ if size > 0 {
6886+ self.above_palette_uv_colors[c + cell] = colors;
6887+ }
68666888 }
68676889 }
68686890 for cell in 0..(h / MI).max(1) {
68696891 if let Some(e) = self.left_palette_uv_size.get_mut(r + cell) {
6870- *e = size;
6871- self.left_palette_uv_colors[r + cell] = colors;
6892+ *e = size as u8;
6893+ if size > 0 {
6894+ self.left_palette_uv_colors[r + cell] = colors;
6895+ }
68726896 }
68736897 }
68746898 }
@@ -6888,14 +6912,14 @@ impl Neighbours {
68886912 let (r, c) = mi;
68896913 let above_ok = r % 16 != 0;
68906914 let (above_n, above_colors) = if above_ok && self.above_palette_uv_size[c] > 0 {
6891- (self.above_palette_uv_size[c], self.above_palette_uv_colors[c])
6915+ (usize::from(self.above_palette_uv_size[c]), self.above_palette_uv_colors[c])
68926916 } else {
68936917 (0, [0u16; 8])
68946918 };
68956919 // Same tile-relative left availability as the luma cache above.
68966920 let left_ok = c > self.tile_col0_mi;
68976921 let (left_n, left_colors) = if left_ok && self.left_palette_uv_size[r] > 0 {
6898- (self.left_palette_uv_size[r], self.left_palette_uv_colors[r])
6922+ (usize::from(self.left_palette_uv_size[r]), self.left_palette_uv_colors[r])
68996923 } else {
69006924 (0, [0u16; 8])
69016925 };
@@ -7095,7 +7119,7 @@ impl Neighbours {
70957119 self.left_mode.iter_mut().for_each(|m| *m = DC_PRED);
70967120 self.left_uv_mode.iter_mut().for_each(|m| *m = DC_PRED);
70977121 self.left_side.iter_mut().for_each(|s| *s = NO_NEIGHBOUR_SIDE);
7098- self.left_side_mi.iter_mut().for_each(|s| *s = NO_NEIGHBOUR_SIDE);
7122+ self.left_side_mi.iter_mut().for_each(|s| *s = NO_NEIGHBOUR_SIDE as u8);
70997123 self.left_skip.iter_mut().for_each(|s| *s = false);
71007124 self.left_skip_mode.iter_mut().for_each(|s| *s = false);
71017125 self.left_inter.iter_mut().for_each(|i| *i = false);
@@ -7106,8 +7130,8 @@ impl Neighbours {
71067130 self.left_filter.iter_mut().for_each(|f| *f = [3u8; 2]);
71077131 // lane-sub8 r6: mi-granular row maps reset with the rest of the left
71087132 // context (a tile/SB-row boundary has no left neighbour).
7109- self.sub8_mode_row.iter_mut().for_each(|s| *s = (usize::MAX, 0));
7110- self.uv_mode_row.iter_mut().for_each(|s| *s = (usize::MAX, 0));
7133+ self.sub8_mode_row.iter_mut().for_each(|s| *s = (u16::MAX, 0));
7134+ self.uv_mode_row.iter_mut().for_each(|s| *s = (u16::MAX, 0));
71117135 // lane-tiles r11 (COMMON's NEIGHBOUR MAPS rule): the palette side bands
71127136 // are per-mi maps like every other one here, so they reset with the
71137137 // row too -- the left guard above is what actually stops a cross-tile
@@ -7215,9 +7239,9 @@ impl Neighbours {
72157239 self.above_skip_mode[c..c + w_mi].fill(skip_mode);
72167240 self.above_inter[c..c + w_mi].fill(is_inter);
72177241 self.above_ref[c..c + w_mi].fill(ref_frame);
7218- // lane-av1comp: no caller of `record_inter` ever decodes a
7219- // compound block yet (see [`Self::above_ref1`]'s doc); the
7220- // parameter this becomes lands with `read_ref_frames`.
7242+ // The single-ref default: `record_compound_ctx_rect_mi` overwrites
7243+ // this with the block's real second reference for a compound block,
7244+ // called right after this one (lane-publish2 audit).
72217245 self.above_ref1[c..c + w_mi].fill(None);
72227246 // libaom `get_comp_group_idx_context`/`get_comp_index_context`'s
72237247 // single-ref special case: `ref_frame[0] == ALTREF_FRAME` reads
@@ -7323,8 +7347,8 @@ impl Neighbours {
73237347 /// arrays so the second leaf sees the first leaf's own 8x8 side rather
73247348 /// than the enclosing 16x16 slot's stale, shared state.
73257349 fn partition_ctx_mi(&self, (mi_r, mi_c): (usize, usize), side: usize) -> usize {
7326- 2 * usize::from(self.left_side_mi[mi_r] * 2 <= side)
7327- + usize::from(self.above_side_mi[mi_c] * 2 <= side)
7350+ 2 * usize::from(usize::from(self.left_side_mi[mi_r]) * 2 <= side)
7351+ + usize::from(usize::from(self.above_side_mi[mi_c]) * 2 <= side)
73287352 }
73297353
73307354 /// The gathered coded/DC-sign state of the blocks above and to the left
@@ -7484,7 +7508,8 @@ impl Neighbours {
74847508 mi_h: usize,
74857509 mode: usize,
74867510 ) {
7487- let (last_r, last_c) = (mi_r + mi_h - 1, mi_c + mi_w - 1);
7511+ let (last_r, last_c) = ((mi_r + mi_h - 1) as u16, (mi_c + mi_w - 1) as u16);
7512+ let mode = mode as u8;
74887513 for cell in 0..mi_w {
74897514 if let Some(slot) = self.sub8_mode_col.get_mut(mi_c + cell) {
74907515 *slot = (last_r, mode);
@@ -7503,14 +7528,14 @@ impl Neighbours {
75037528 /// construction). See [`Self::record_mode_mi`].
75047529 fn mode_above_mi(&self, mi_r: usize, mi_c: usize) -> Option<usize> {
75057530 match self.sub8_mode_col.get(mi_c) {
7506- Some(&(row, m)) if mi_r > self.tile_row0_mi && row == mi_r - 1 => Some(m),
7531+ Some(&(row, m)) if mi_r > self.tile_row0_mi && usize::from(row) == mi_r - 1 => Some(usize::from(m)),
75077532 _ => None,
75087533 }
75097534 }
75107535
75117536 fn mode_left_mi(&self, mi_r: usize, mi_c: usize) -> Option<usize> {
75127537 match self.sub8_mode_row.get(mi_r) {
7513- Some(&(col, m)) if mi_c > self.tile_col0_mi && col == mi_c - 1 => Some(m),
7538+ Some(&(col, m)) if mi_c > self.tile_col0_mi && usize::from(col) == mi_c - 1 => Some(usize::from(m)),
75147539 _ => None,
75157540 }
75167541 }
@@ -7526,8 +7551,8 @@ impl Neighbours {
75267551 uv_mode: usize,
75277552 ) {
75287553 let (last_r, last_c) = (mi_r + mi_h - 1, mi_c + mi_w - 1);
7529- fill_span(&mut self.uv_mode_col, mi_c, mi_w, (last_r, uv_mode));
7530- fill_span(&mut self.uv_mode_row, mi_r, mi_h, (last_c, uv_mode));
7554+ fill_span(&mut self.uv_mode_col, mi_c, mi_w, (last_r as u16, uv_mode as u8));
7555+ fill_span(&mut self.uv_mode_row, mi_r, mi_h, (last_c as u16, uv_mode as u8));
75317556 // libaom writes one `MB_MODE_INFO` pointer into every mi cell a block
75327557 // covers, so the chroma neighbour read below is a plain grid read.
75337558 let stride = self.uv_grid_cols;
@@ -7598,20 +7623,20 @@ impl Neighbours {
75987623 };
75997624 let above = match self.uv_mode_col.get(mi_c) {
76007625 _ if have_above && let Some(m) = cell(&self.uv_mode_grid, mi_r - 1, mi_c) => m,
7601- Some(&(row, m)) if have_above && row == mi_r - 1 => m,
7626+ Some(&(row, m)) if have_above && usize::from(row) == mi_r - 1 => usize::from(m),
76027627 _ if have_above => self.above_uv_mode[c],
76037628 _ => DC_PRED,
76047629 };
76057630 let left = match self.uv_mode_row.get(mi_r) {
76067631 _ if have_left && let Some(m) = cell(&self.uv_mode_grid, mi_r, mi_c - 1) => m,
7607- Some(&(col, m)) if have_left && col == mi_c - 1 => m,
7632+ Some(&(col, m)) if have_left && usize::from(col) == mi_c - 1 => usize::from(m),
76087633 _ if have_left => self.left_uv_mode[r],
76097634 _ => DC_PRED,
76107635 };
76117636 if have_above && cell(&self.uv_mode_grid, mi_r - 1, mi_c).is_some_and(|m| {
7612- !matches!(self.uv_mode_col.get(mi_c), Some(&(row, cm)) if row == mi_r - 1 && cm == m)
7637+ !matches!(self.uv_mode_col.get(mi_c), Some(&(row, cm)) if usize::from(row) == mi_r - 1 && usize::from(cm) == m)
76137638 }) || have_left && cell(&self.uv_mode_grid, mi_r, mi_c - 1).is_some_and(|m| {
7614- !matches!(self.uv_mode_row.get(mi_r), Some(&(col, cm)) if col == mi_c - 1 && cm == m)
7639+ !matches!(self.uv_mode_row.get(mi_r), Some(&(col, cm)) if usize::from(col) == mi_c - 1 && usize::from(cm) == m)
76157640 }) {
76167641 UV_MODE_GRID_OVERRIDE_HITS.with(|h| h.set(h.get() + 1));
76177642 }
@@ -7770,8 +7795,8 @@ impl Neighbours {
77707795 if crate::envflags::env_flag!("EC_ECPUB") {
77717796 eprintln!("EC_ECPUB blk mi=({mi_r},{mi_c}) wh=({w},{h}) lvl={}", states[0].level);
77727797 }
7773- fill_span(&mut self.left_side_mi, mi_r, h_mi, h);
7774- fill_span(&mut self.above_side_mi, mi_c, w_mi, w);
7798+ fill_span(&mut self.left_side_mi, mi_r, h_mi, h as u8);
7799+ fill_span(&mut self.above_side_mi, mi_c, w_mi, w as u8);
77757800 // A chroma 4x4 unit straddling the true luma edge is still whole in
77767801 // chroma's own halved grid, so libaom rounds the luma bound up to the
77777802 // plane's own 4x4 unit before clamping a subsampled plane
@@ -7960,8 +7985,8 @@ impl Neighbours {
79607985 let (w_mi, h_mi) = (w / MI, h / MI);
79617986 self.record_mode_mi(mi_r, mi_c, w_mi, h_mi, mode);
79627987 self.record_uv_mode_mi(mi_r, mi_c, w_mi, h_mi, uv_mode);
7963- fill_span(&mut self.left_side_mi, mi_r, h_mi, h);
7964- fill_span(&mut self.above_side_mi, mi_c, w_mi, w);
7988+ fill_span(&mut self.left_side_mi, mi_r, h_mi, h as u8);
7989+ fill_span(&mut self.above_side_mi, mi_c, w_mi, w as u8);
79657990 let round_up_even = |n: usize| n.div_ceil(2) * 2;
79667991 let (bound_h, bound_w) = (round_up_even(self.mi_rows), round_up_even(self.mi_cols));
79677992 for (plane_idx, grid) in chroma_grids.into_iter().enumerate() {
@@ -8702,10 +8727,16 @@ fn record_strip_palette(
87028727 {
87038728 for cell in 0..(bw / MI).max(1) {
87048729 if let Some(e) = n.above_palette_size.get_mut(c + cell) {
8705- *e = y_size;
8706- n.above_palette_colors[c + cell] = y_colors;
8707- n.above_palette_uv_size[c + cell] = uv_size;
8708- n.above_palette_uv_colors[c + cell] = uv_colors;
8730+ *e = y_size as u8;
8731+ n.above_palette_uv_size[c + cell] = uv_size as u8;
8732+ // lane-publish2, see [`Neighbours::record_palette_y_rect`]:
8733+ // colours of a size-0 neighbour are never read.
8734+ if y_size > 0 {
8735+ n.above_palette_colors[c + cell] = y_colors;
8736+ }
8737+ if uv_size > 0 {
8738+ n.above_palette_uv_colors[c + cell] = uv_colors;
8739+ }
87098740 }
87108741 }
87118742 }
@@ -8714,10 +8745,14 @@ fn record_strip_palette(
87148745 if n.left_palette_size.get(r + cell).is_none() {
87158746 break;
87168747 }
8717- n.left_palette_size[r + cell] = y_size;
8718- n.left_palette_colors[r + cell] = y_colors;
8719- n.left_palette_uv_size[r + cell] = uv_size;
8720- n.left_palette_uv_colors[r + cell] = uv_colors;
8748+ n.left_palette_size[r + cell] = y_size as u8;
8749+ n.left_palette_uv_size[r + cell] = uv_size as u8;
8750+ if y_size > 0 {
8751+ n.left_palette_colors[r + cell] = y_colors;
8752+ }
8753+ if uv_size > 0 {
8754+ n.left_palette_uv_colors[r + cell] = uv_colors;
8755+ }
87218756 }
87228757 }
87238758 }
@@ -11671,12 +11706,12 @@ fn decode_rect4_16_strip(
1167111706 // the left (mirrored under VERT_4).
1167211707 for cell in 0..mi_w {
1167311708 if let Some(slot) = neighbours.above_side_mi.get_mut(lmi.1 + cell) {
11674- *slot = bw;
11709+ *slot = bw as u8;
1167511710 }
1167611711 }
1167711712 for cell in 0..mi_h {
1167811713 if let Some(slot) = neighbours.left_side_mi.get_mut(lmi.0 + cell) {
11679- *slot = bh;
11714+ *slot = bh as u8;
1168011715 }
1168111716 }
1168211717 if has_chroma {
@@ -15745,8 +15780,8 @@ fn decode_leaf_rect8(
1574515780 // -- the mirror of `decode_leaf_split4`'s `{31, 31}`, which
1574615781 // `partition_ctx_mi` reads back off these side values.
1574715782 for cell in 0..2 {
15748- neighbours.above_side_mi[leaf_mi.1 + cell] = bw;
15749- neighbours.left_side_mi[leaf_mi.0 + cell] = bh;
15783+ neighbours.above_side_mi[leaf_mi.1 + cell] = bw as u8;
15784+ neighbours.left_side_mi[leaf_mi.0 + cell] = bh as u8;
1575015785 }
1575115786 let round_up_even = |n: usize| n.div_ceil(2) * 2;
1575215787 let bound_h = round_up_even(neighbours.mi_rows);
@@ -16543,10 +16578,10 @@ fn tx_size_context_txfm_rect(
1654316578 let mut above = usize::from(n.above_txfm[mi_c]) >= own_w;
1654416579 let mut left = usize::from(n.left_txfm[mi_r]) >= own_h;
1654516580 if has_above && n.above_inter[mi_c] {
16546- above = n.above_side_mi[mi_c] >= own_w;
16581+ above = usize::from(n.above_side_mi[mi_c]) >= own_w;
1654716582 }
1654816583 if has_left && n.left_inter[mi_r] {
16549- left = n.left_side_mi[mi_r] >= own_h;
16584+ left = usize::from(n.left_side_mi[mi_r]) >= own_h;
1655016585 }
1655116586 if crate::envflags::env_flag!("EC_TXCTX") {
1655216587 eprintln!(
@@ -16603,10 +16638,10 @@ fn tx_size_context_txfm(n: &Neighbours, (mi_r, mi_c): (usize, usize), side: usiz
1660316638 // then missed libaom's "an inter neighbour contributes its BLOCK size"
1660416639 // override and read `tx_size_cat1` row 1 where aomdec reads row 2.
1660516640 if has_above && n.above_inter[mi_c] {
16606- above = n.above_side_mi[mi_c] >= side;
16641+ above = usize::from(n.above_side_mi[mi_c]) >= side;
1660716642 }
1660816643 if has_left && n.left_inter[mi_r] {
16609- left = n.left_side_mi[mi_r] >= side;
16644+ left = usize::from(n.left_side_mi[mi_r]) >= side;
1661016645 }
1661116646 if crate::envflags::env_flag!("EC_TXCTX") {
1661216647 eprintln!(
@@ -29277,14 +29312,14 @@ fn decode_inter_sub8_rect2(
2927729312 if i == 1 {
2927829313 if vert {
2927929314 for cell in 0..h_mi {
29280- neighbours.left_side_mi[gr + cell] = bh;
29315+ neighbours.left_side_mi[gr + cell] = bh as u8;
2928129316 }
29282- neighbours.above_side_mi[gc] = bw;
29317+ neighbours.above_side_mi[gc] = bw as u8;
2928329318 } else {
2928429319 for cell in 0..w_mi {
29285- neighbours.above_side_mi[gc + cell] = bw;
29320+ neighbours.above_side_mi[gc + cell] = bw as u8;
2928629321 }
29287- neighbours.left_side_mi[gr] = bh;
29322+ neighbours.left_side_mi[gr] = bh as u8;
2928829323 }
2928929324 }
2929029325 let (rmi, cmi) = lmi;
@@ -29763,8 +29798,8 @@ fn decode_inter_sub8_rect2(
2976329798 // over the whole 8x8 span -- BLOCK_4X8's width above and height left, the
2976429799 // same values [`decode_leaf_rect8`] writes for the intra shape.
2976529800 for cell in 0..2usize {
29766- neighbours.above_side_mi[gc + cell] = bw;
29767- neighbours.left_side_mi[gr + cell] = bh;
29801+ neighbours.above_side_mi[gc + cell] = bw as u8;
29802+ neighbours.left_side_mi[gr + cell] = bh as u8;
2976829803 }
2976929804 Ok(())
2977029805 }
@@ -35839,6 +35874,33 @@ mod tests {
3583935874 assert!(n.palette_uv_cache((1, 1)).is_empty());
3584035875 }
3584135876
35877+ /// lane-publish2 (the mode-info publish surface narrowed): two invariants
35878+ /// the byte-exact stream gate only covers indirectly -- a size-0 palette
35879+ /// stamp leaves the PREVIOUS block's colours in place (spec 5.11.46
35880+ /// `get_palette_cache` reads a neighbour's colours only where its size is
35881+ /// non-zero, so writing 16 bytes of zeroes was pure traffic), and the
35882+ /// narrowed `(u16, u8)` mi maps keep their "never written" sentinel.
35883+ #[test]
35884+ fn narrowed_publish_surface_keeps_neighbour_semantics() {
35885+ assert_eq!(std::mem::size_of::<(u16, u8)>(), 4, "the narrowing must actually be 4 bytes");
35886+ let fctx = &crate::decode::FrameCtx::new();
35887+ let mut n = Neighbours::new(4, 4, 16, 16, fctx);
35888+ n.record_palette_y_rect((4, 4), 16, 16, 2, [7, 9, 0, 0, 0, 0, 0, 0]);
35889+ n.record_palette_y_rect((4, 4), 16, 16, 0, [0u16; 8]);
35890+ assert_eq!(n.above_palette_size[4], 0, "the size is what a reader gates on");
35891+ assert_eq!(
35892+ n.above_palette_colors[4],
35893+ [7, 9, 0, 0, 0, 0, 0, 0],
35894+ "a size-0 stamp deliberately leaves the stale colours behind"
35895+ );
35896+ let (ctx, cache) = n.palette_ctx_and_cache((1, 1));
35897+ assert_eq!(ctx, 0, "and they stay invisible to every reader");
35898+ assert!(cache.is_empty());
35899+ assert_eq!(n.mode_above_mi(4, 4), None, "u16::MAX sentinel = never written");
35900+ n.record_mode_mi(3, 4, 1, 1, DC_PRED);
35901+ assert_eq!(n.mode_above_mi(4, 4), Some(DC_PRED));
35902+ }
35903+
3584235904 /// [`cdf::COMPOUND_MODE_CTX_MAP`] folded by hand against libaom's
3584335905 /// `av1_mode_context_analyzer` compound branch (`mvref_common.h`):
3584435906 /// `comp_ctx = compound_mode_ctx_map[refmv_ctx >> 1][min(newmv_ctx, 4)]`