Merge branch 'lane-mi' (7b15f443): mode-info grids filled per contiguous row span instead of per 4x4 cell, MiInfo size fields u8 (Option<MiInfo> 48 -> 28 bytes), record_mi_rect neighbour state as three contiguous runs; byte-exact, -1.0% instructions on the 4K segment
Browse files at this commit3 changed files +146 -186
- crates/ec-av1/src/decode.rs +115 -168
- crates/ec-av1/src/mvstack.rs +27 -14
- crates/ec-av1/src/tile.rs +4 -4
crates/ec-av1/src/decode.rsmodified+115 -168
| @@ -3190,8 +3190,8 @@ fn record_intrabc_mi(mi_r: usize, mi_c: usize, n4: usize, dv: Option<(i32, i32)> | ||
| 3190 | 3190 | is_new_mv: dv.is_some(), |
| 3191 | 3191 | is_global_mv0: false, |
| 3192 | 3192 | is_global_mv1: false, |
| 3193 | - size: n4, | |
| 3194 | - size_h: n4, | |
| 3193 | + size: n4 as u8, | |
| 3194 | + size_h: n4 as u8, | |
| 3195 | 3195 | }; |
| 3196 | 3196 | for r in mi_r..mi_r + n4 { |
| 3197 | 3197 | for c in mi_c..mi_c + n4 { |
| @@ -6028,6 +6028,21 @@ struct Neighbour { | ||
| 6028 | 6028 | dc: Option<bool>, |
| 6029 | 6029 | } |
| 6030 | 6030 | |
| 6031 | +/// `dst[start .. start + n] = v`, with the same per-cell bounds behaviour the | |
| 6032 | +/// per-4x4-cell `get_mut` loops it replaces had: a cell past the end of the | |
| 6033 | +/// grid is dropped, never a panic. One `memset` per grid row instead of a | |
| 6034 | +/// bounds check per cell (lane-mi) -- the index span a row of a mi rect covers | |
| 6035 | +/// is contiguous, so this writes exactly the cells the cell loop did, | |
| 6036 | +/// including the ones a `mi_c + cc` past `skip_grid_cols_mi` folded into the | |
| 6037 | +/// next row. | |
| 6038 | +#[inline] | |
| 6039 | +fn fill_span<T: Copy>(dst: &mut [T], start: usize, n: usize, v: T) { | |
| 6040 | + let end = (start + n).min(dst.len()); | |
| 6041 | + if start < end { | |
| 6042 | + dst[start..end].fill(v); | |
| 6043 | + } | |
| 6044 | +} | |
| 6045 | + | |
| 6031 | 6046 | fn neighbour_state(grid: &[i32]) -> Neighbour { |
| 6032 | 6047 | let cul: u32 = grid.iter().map(|&l| l.unsigned_abs()).sum(); |
| 6033 | 6048 | Neighbour { |
| @@ -6651,15 +6666,9 @@ impl Neighbours { | ||
| 6651 | 6666 | let (mi_r, mi_c) = at_mi; |
| 6652 | 6667 | let (uv_w, uv_h) = ((w_mi * MI / 2).max(4) as u8, (h_mi * MI / 2).max(4) as u8); |
| 6653 | 6668 | for rr in 0..h_mi { |
| 6654 | - for cc in 0..w_mi { | |
| 6655 | - let idx = (mi_r + rr) * self.skip_grid_cols_mi + (mi_c + cc); | |
| 6656 | - if let Some(cell) = self.uv_tx_grid.get_mut(idx) { | |
| 6657 | - *cell = uv_w; | |
| 6658 | - } | |
| 6659 | - if let Some(cell) = self.uv_tx_h_grid.get_mut(idx) { | |
| 6660 | - *cell = uv_h; | |
| 6661 | - } | |
| 6662 | - } | |
| 6669 | + let start = (mi_r + rr) * self.skip_grid_cols_mi + mi_c; | |
| 6670 | + fill_span(&mut self.uv_tx_grid, start, w_mi, uv_w); | |
| 6671 | + fill_span(&mut self.uv_tx_h_grid, start, w_mi, uv_h); | |
| 6663 | 6672 | } |
| 6664 | 6673 | } |
| 6665 | 6674 | |
| @@ -6688,27 +6697,13 @@ impl Neighbours { | ||
| 6688 | 6697 | [cur[0].clamp(-63, 63) as i8; 4] |
| 6689 | 6698 | }; |
| 6690 | 6699 | for rr in 0..h_mi { |
| 6691 | - for cc in 0..w_mi { | |
| 6692 | - let idx = (mi_r + rr) * self.skip_grid_cols_mi + (mi_c + cc); | |
| 6693 | - if let Some(cell) = self.tx_grid.get_mut(idx) { | |
| 6694 | - *cell = tx_px; | |
| 6695 | - } | |
| 6696 | - if let Some(cell) = self.tx_h_grid.get_mut(idx) { | |
| 6697 | - *cell = tx_h_px; | |
| 6698 | - } | |
| 6699 | - if let Some(cell) = self.uv_tx_grid.get_mut(idx) { | |
| 6700 | - *cell = uv_tx_w; | |
| 6701 | - } | |
| 6702 | - if let Some(cell) = self.uv_tx_h_grid.get_mut(idx) { | |
| 6703 | - *cell = uv_tx_h; | |
| 6704 | - } | |
| 6705 | - if let Some(cell) = self.ref_grid.get_mut(idx) { | |
| 6706 | - *cell = ref_frame; | |
| 6707 | - } | |
| 6708 | - if let Some(cell) = self.delta_lf_grid.get_mut(idx) { | |
| 6709 | - *cell = snapshot; | |
| 6710 | - } | |
| 6711 | - } | |
| 6700 | + let start = (mi_r + rr) * self.skip_grid_cols_mi + mi_c; | |
| 6701 | + fill_span(&mut self.tx_grid, start, w_mi, tx_px); | |
| 6702 | + fill_span(&mut self.tx_h_grid, start, w_mi, tx_h_px); | |
| 6703 | + fill_span(&mut self.uv_tx_grid, start, w_mi, uv_tx_w); | |
| 6704 | + fill_span(&mut self.uv_tx_h_grid, start, w_mi, uv_tx_h); | |
| 6705 | + fill_span(&mut self.ref_grid, start, w_mi, ref_frame); | |
| 6706 | + fill_span(&mut self.delta_lf_grid, start, w_mi, snapshot); | |
| 6712 | 6707 | } |
| 6713 | 6708 | } |
| 6714 | 6709 | |
| @@ -6733,15 +6728,9 @@ impl Neighbours { | ||
| 6733 | 6728 | eprintln!("EC_LFLEAF mi_row={mi_r} mi_col={mi_c} w_mi={w_mi} h_mi={h_mi} tx_px={tx_px} tx_h_px={tx_h_px}"); |
| 6734 | 6729 | } |
| 6735 | 6730 | for rr in 0..h_mi { |
| 6736 | - for cc in 0..w_mi { | |
| 6737 | - let idx = (mi_r + rr) * self.skip_grid_cols_mi + (mi_c + cc); | |
| 6738 | - if let Some(cell) = self.tx_grid.get_mut(idx) { | |
| 6739 | - *cell = tx_px; | |
| 6740 | - } | |
| 6741 | - if let Some(cell) = self.tx_h_grid.get_mut(idx) { | |
| 6742 | - *cell = tx_h_px; | |
| 6743 | - } | |
| 6744 | - } | |
| 6731 | + let start = (mi_r + rr) * self.skip_grid_cols_mi + mi_c; | |
| 6732 | + fill_span(&mut self.tx_grid, start, w_mi, tx_px); | |
| 6733 | + fill_span(&mut self.tx_h_grid, start, w_mi, tx_h_px); | |
| 6745 | 6734 | } |
| 6746 | 6735 | } |
| 6747 | 6736 | |
| @@ -6760,21 +6749,11 @@ impl Neighbours { | ||
| 6760 | 6749 | RECT_SKIP_BAND_HITS.with(|c| c.set(c.get() + 1)); |
| 6761 | 6750 | } |
| 6762 | 6751 | for rr in 0..h_mi { |
| 6763 | - for cc in 0..w_mi { | |
| 6764 | - let idx = (mi_r + rr) * self.skip_grid_cols_mi + (mi_c + cc); | |
| 6765 | - if let Some(cell) = self.skip_grid.get_mut(idx) { | |
| 6766 | - *cell = skip; | |
| 6767 | - } | |
| 6768 | - if let Some(cell) = self.skip_written.get_mut(idx) { | |
| 6769 | - *cell = true; | |
| 6770 | - } | |
| 6771 | - if let Some(org) = self.blk_org_grid.get_mut(idx) { | |
| 6772 | - *org = [mi_r as u16, mi_c as u16]; | |
| 6773 | - } | |
| 6774 | - if let Some(dim) = self.blk_dim_grid.get_mut(idx) { | |
| 6775 | - *dim = [w_mi as u8, h_mi as u8]; | |
| 6776 | - } | |
| 6777 | - } | |
| 6752 | + let start = (mi_r + rr) * self.skip_grid_cols_mi + mi_c; | |
| 6753 | + fill_span(&mut self.skip_grid, start, w_mi, skip); | |
| 6754 | + fill_span(&mut self.skip_written, start, w_mi, true); | |
| 6755 | + fill_span(&mut self.blk_org_grid, start, w_mi, [mi_r as u16, mi_c as u16]); | |
| 6756 | + fill_span(&mut self.blk_dim_grid, start, w_mi, [w_mi as u8, h_mi as u8]); | |
| 6778 | 6757 | } |
| 6779 | 6758 | } |
| 6780 | 6759 | |
| @@ -6936,34 +6915,30 @@ impl Neighbours { | ||
| 6936 | 6915 | self.record_uv_mode_mi(r, c, w_mi, h_mi, DC_PRED); |
| 6937 | 6916 | } |
| 6938 | 6917 | let altref = is_inter && ref_frame == crate::mvstack::ALTREF_FRAME; |
| 6939 | - for cell in 0..w_mi { | |
| 6940 | - self.above_skip[c + cell] = skip; | |
| 6941 | - self.above_skip_mode[c + cell] = skip_mode; | |
| 6942 | - self.above_inter[c + cell] = is_inter; | |
| 6943 | - self.above_ref[c + cell] = ref_frame; | |
| 6944 | - // lane-av1comp: no caller of `record_inter` ever decodes a | |
| 6945 | - // compound block yet (see [`Self::above_ref1`]'s doc); the | |
| 6946 | - // parameter this becomes lands with `read_ref_frames`. | |
| 6947 | - self.above_ref1[c + cell] = None; | |
| 6948 | - // libaom `get_comp_group_idx_context`/`get_comp_index_context`'s | |
| 6949 | - // single-ref special case: `ref_frame[0] == ALTREF_FRAME` reads | |
| 6950 | - // as `3`/`1` even though this block has no second reference. | |
| 6951 | - // `record_compound_ctx` overwrites this with the real bit for an | |
| 6952 | - // actual compound block's cells, called right after this one. | |
| 6953 | - self.above_comp_group_idx[c + cell] = if altref { 3 } else { 0 }; | |
| 6954 | - self.above_compound_idx[c + cell] = u8::from(altref); | |
| 6955 | - self.above_filter[c + cell] = filter; | |
| 6956 | - } | |
| 6957 | - for cell in 0..h_mi { | |
| 6958 | - self.left_skip[r + cell] = skip; | |
| 6959 | - self.left_skip_mode[r + cell] = skip_mode; | |
| 6960 | - self.left_inter[r + cell] = is_inter; | |
| 6961 | - self.left_ref[r + cell] = ref_frame; | |
| 6962 | - self.left_ref1[r + cell] = None; | |
| 6963 | - self.left_comp_group_idx[r + cell] = if altref { 3 } else { 0 }; | |
| 6964 | - self.left_compound_idx[r + cell] = u8::from(altref); | |
| 6965 | - self.left_filter[r + cell] = filter; | |
| 6966 | - } | |
| 6918 | + self.above_skip[c..c + w_mi].fill(skip); | |
| 6919 | + self.above_skip_mode[c..c + w_mi].fill(skip_mode); | |
| 6920 | + self.above_inter[c..c + w_mi].fill(is_inter); | |
| 6921 | + self.above_ref[c..c + w_mi].fill(ref_frame); | |
| 6922 | + // lane-av1comp: no caller of `record_inter` ever decodes a | |
| 6923 | + // compound block yet (see [`Self::above_ref1`]'s doc); the | |
| 6924 | + // parameter this becomes lands with `read_ref_frames`. | |
| 6925 | + self.above_ref1[c..c + w_mi].fill(None); | |
| 6926 | + // libaom `get_comp_group_idx_context`/`get_comp_index_context`'s | |
| 6927 | + // single-ref special case: `ref_frame[0] == ALTREF_FRAME` reads | |
| 6928 | + // as `3`/`1` even though this block has no second reference. | |
| 6929 | + // `record_compound_ctx` overwrites this with the real bit for an | |
| 6930 | + // actual compound block's cells, called right after this one. | |
| 6931 | + self.above_comp_group_idx[c..c + w_mi].fill(if altref { 3 } else { 0 }); | |
| 6932 | + self.above_compound_idx[c..c + w_mi].fill(u8::from(altref)); | |
| 6933 | + self.above_filter[c..c + w_mi].fill(filter); | |
| 6934 | + self.left_skip[r..r + h_mi].fill(skip); | |
| 6935 | + self.left_skip_mode[r..r + h_mi].fill(skip_mode); | |
| 6936 | + self.left_inter[r..r + h_mi].fill(is_inter); | |
| 6937 | + self.left_ref[r..r + h_mi].fill(ref_frame); | |
| 6938 | + self.left_ref1[r..r + h_mi].fill(None); | |
| 6939 | + self.left_comp_group_idx[r..r + h_mi].fill(if altref { 3 } else { 0 }); | |
| 6940 | + self.left_compound_idx[r..r + h_mi].fill(u8::from(altref)); | |
| 6941 | + self.left_filter[r..r + h_mi].fill(filter); | |
| 6967 | 6942 | } |
| 6968 | 6943 | |
| 6969 | 6944 | /// Overwrites [`Self::record_inter`]'s ALTREF-special-case default with |
| @@ -7249,27 +7224,14 @@ impl Neighbours { | ||
| 7249 | 7224 | uv_mode: usize, |
| 7250 | 7225 | ) { |
| 7251 | 7226 | let (last_r, last_c) = (mi_r + mi_h - 1, mi_c + mi_w - 1); |
| 7252 | - for cell in 0..mi_w { | |
| 7253 | - if let Some(slot) = self.uv_mode_col.get_mut(mi_c + cell) { | |
| 7254 | - *slot = (last_r, uv_mode); | |
| 7255 | - } | |
| 7256 | - } | |
| 7257 | - for cell in 0..mi_h { | |
| 7258 | - if let Some(slot) = self.uv_mode_row.get_mut(mi_r + cell) { | |
| 7259 | - *slot = (last_c, uv_mode); | |
| 7260 | - } | |
| 7261 | - } | |
| 7227 | + fill_span(&mut self.uv_mode_col, mi_c, mi_w, (last_r, uv_mode)); | |
| 7228 | + fill_span(&mut self.uv_mode_row, mi_r, mi_h, (last_c, uv_mode)); | |
| 7262 | 7229 | // libaom writes one `MB_MODE_INFO` pointer into every mi cell a block |
| 7263 | 7230 | // covers, so the chroma neighbour read below is a plain grid read. |
| 7264 | 7231 | let stride = self.uv_grid_cols; |
| 7232 | + let n = stride.saturating_sub(mi_c).min(last_c + 1 - mi_c); | |
| 7265 | 7233 | for row in mi_r..=last_r { |
| 7266 | - for col in mi_c..=last_c { | |
| 7267 | - if col < stride | |
| 7268 | - && let Some(cell) = self.uv_mode_grid.get_mut(row * stride + col) | |
| 7269 | - { | |
| 7270 | - *cell = uv_mode as u8; | |
| 7271 | - } | |
| 7272 | - } | |
| 7234 | + fill_span(&mut self.uv_mode_grid, row * stride + mi_c, n, uv_mode as u8); | |
| 7273 | 7235 | } |
| 7274 | 7236 | } |
| 7275 | 7237 | |
| @@ -7506,16 +7468,8 @@ impl Neighbours { | ||
| 7506 | 7468 | if crate::envflags::env_flag!("EC_ECPUB") { |
| 7507 | 7469 | eprintln!("EC_ECPUB blk mi=({mi_r},{mi_c}) wh=({w},{h}) lvl={}", states[0].level); |
| 7508 | 7470 | } |
| 7509 | - for cell in 0..h_mi { | |
| 7510 | - if let Some(slot) = self.left_side_mi.get_mut(mi_r + cell) { | |
| 7511 | - *slot = h; | |
| 7512 | - } | |
| 7513 | - } | |
| 7514 | - for cell in 0..w_mi { | |
| 7515 | - if let Some(slot) = self.above_side_mi.get_mut(mi_c + cell) { | |
| 7516 | - *slot = w; | |
| 7517 | - } | |
| 7518 | - } | |
| 7471 | + fill_span(&mut self.left_side_mi, mi_r, h_mi, h); | |
| 7472 | + fill_span(&mut self.above_side_mi, mi_c, w_mi, w); | |
| 7519 | 7473 | // A chroma 4x4 unit straddling the true luma edge is still whole in |
| 7520 | 7474 | // chroma's own halved grid, so libaom rounds the luma bound up to the |
| 7521 | 7475 | // plane's own 4x4 unit before clamping a subsampled plane |
| @@ -7531,34 +7485,35 @@ impl Neighbours { | ||
| 7531 | 7485 | round_up_even(self.mi_cols), |
| 7532 | 7486 | round_up_even(self.mi_cols), |
| 7533 | 7487 | ]; |
| 7534 | - for cell in 0..h_mi { | |
| 7535 | - // lane-sb128c r7: a 128x64 at the bottom frame edge names mi rows | |
| 7536 | - // past the padded side arrays (mi_rows 198, block rows 192..208); | |
| 7537 | - // libaom's own arrays are superblock-sized, so those cells simply | |
| 7538 | - // have no reader. Same guard the `left_side_mi` loop above uses. | |
| 7539 | - let Some(left_slot) = self.left.get_mut(mi_r + cell) else { | |
| 7540 | - break; | |
| 7541 | - }; | |
| 7542 | - *left_slot = std::array::from_fn(|plane| { | |
| 7543 | - if cell < h_mi.min(bound_h[plane].saturating_sub(mi_r)) { | |
| 7544 | - states[plane] | |
| 7545 | - } else { | |
| 7546 | - Default::default() | |
| 7547 | - } | |
| 7548 | - }); | |
| 7549 | - } | |
| 7550 | - for cell in 0..w_mi { | |
| 7551 | - let Some(above_slot) = self.above.get_mut(mi_c + cell) else { | |
| 7552 | - break; | |
| 7553 | - }; | |
| 7554 | - *above_slot = std::array::from_fn(|plane| { | |
| 7555 | - if cell < w_mi.min(bound_w[plane].saturating_sub(mi_c)) { | |
| 7556 | - states[plane] | |
| 7557 | - } else { | |
| 7558 | - Default::default() | |
| 7559 | - } | |
| 7560 | - }); | |
| 7561 | - } | |
| 7488 | + // lane-sb128c r7: a 128x64 at the bottom frame edge names mi rows | |
| 7489 | + // past the padded side arrays (mi_rows 198, block rows 192..208); | |
| 7490 | + // libaom's own arrays are superblock-sized, so those cells simply | |
| 7491 | + // have no reader -- [`fill_span`] drops them, as the `break` did. | |
| 7492 | + // `bound_h[1] == bound_h[2] >= bound_h[0]`, so the per-cell plane | |
| 7493 | + // predicate is three contiguous runs: all planes, chroma only, none | |
| 7494 | + // (lane-mi). | |
| 7495 | + let luma_h = h_mi.min(bound_h[0].saturating_sub(mi_r)); | |
| 7496 | + let chroma_h = h_mi.min(bound_h[1].saturating_sub(mi_r)); | |
| 7497 | + let uv_only = [Neighbour::default(), states[1], states[2]]; | |
| 7498 | + fill_span(&mut self.left, mi_r, luma_h, states); | |
| 7499 | + fill_span(&mut self.left, mi_r + luma_h, chroma_h - luma_h, uv_only); | |
| 7500 | + fill_span( | |
| 7501 | + &mut self.left, | |
| 7502 | + mi_r + chroma_h, | |
| 7503 | + h_mi - chroma_h, | |
| 7504 | + [Neighbour::default(); 3], | |
| 7505 | + ); | |
| 7506 | + let luma_w = w_mi.min(bound_w[0].saturating_sub(mi_c)); | |
| 7507 | + let chroma_w = w_mi.min(bound_w[1].saturating_sub(mi_c)); | |
| 7508 | + let uv_only_w = [Neighbour::default(), states[1], states[2]]; | |
| 7509 | + fill_span(&mut self.above, mi_c, luma_w, states); | |
| 7510 | + fill_span(&mut self.above, mi_c + luma_w, chroma_w - luma_w, uv_only_w); | |
| 7511 | + fill_span( | |
| 7512 | + &mut self.above, | |
| 7513 | + mi_c + chroma_w, | |
| 7514 | + w_mi - chroma_w, | |
| 7515 | + [Neighbour::default(); 3], | |
| 7516 | + ); | |
| 7562 | 7517 | } |
| 7563 | 7518 | |
| 7564 | 7519 | /// [`Self::record_mi`]'s plane-0 half only, for one luma transform unit |
| @@ -7703,16 +7658,8 @@ impl Neighbours { | ||
| 7703 | 7658 | let (w_mi, h_mi) = (w / MI, h / MI); |
| 7704 | 7659 | self.record_mode_mi(mi_r, mi_c, w_mi, h_mi, mode); |
| 7705 | 7660 | self.record_uv_mode_mi(mi_r, mi_c, w_mi, h_mi, uv_mode); |
| 7706 | - for cell in 0..h_mi { | |
| 7707 | - if let Some(slot) = self.left_side_mi.get_mut(mi_r + cell) { | |
| 7708 | - *slot = h; | |
| 7709 | - } | |
| 7710 | - } | |
| 7711 | - for cell in 0..w_mi { | |
| 7712 | - if let Some(slot) = self.above_side_mi.get_mut(mi_c + cell) { | |
| 7713 | - *slot = w; | |
| 7714 | - } | |
| 7715 | - } | |
| 7661 | + fill_span(&mut self.left_side_mi, mi_r, h_mi, h); | |
| 7662 | + fill_span(&mut self.above_side_mi, mi_c, w_mi, w); | |
| 7716 | 7663 | let round_up_even = |n: usize| n.div_ceil(2) * 2; |
| 7717 | 7664 | let (bound_h, bound_w) = (round_up_even(self.mi_rows), round_up_even(self.mi_cols)); |
| 7718 | 7665 | for (plane_idx, grid) in chroma_grids.into_iter().enumerate() { |
| @@ -22077,7 +22024,7 @@ fn overlappable_above( | ||
| 22077 | 22024 | let mut col = mi_col; |
| 22078 | 22025 | while col < end_col && out.len() < max_neighbors { |
| 22079 | 22026 | let cell = grid.get(mi_row - 1, col); |
| 22080 | - let mut step = cell.map_or(1, |c| c.size).max(1).min(SB_MI as usize); | |
| 22027 | + let mut step = cell.map_or(1, |c| c.size as usize).max(1).min(SB_MI as usize); | |
| 22081 | 22028 | let mut nb = cell; |
| 22082 | 22029 | // lane-obmcrec r1: the mi the neighbour's `MiInfo` is actually taken |
| 22083 | 22030 | // from -- the pair merge below moves it, and libaom reads that same |
| @@ -22132,7 +22079,7 @@ fn overlappable_left( | ||
| 22132 | 22079 | let cell = grid.get(row, mi_col - 1); |
| 22133 | 22080 | // Vertical walk steps by the neighbour's HEIGHT -- a 32x16 strip's |
| 22134 | 22081 | // width (8) would swallow the strip below it. |
| 22135 | - let mut step = cell.map_or(1, |c| c.size_h).max(1).min(SB_MI as usize); | |
| 22082 | + let mut step = cell.map_or(1, |c| c.size_h as usize).max(1).min(SB_MI as usize); | |
| 22136 | 22083 | let mut nb = cell; |
| 22137 | 22084 | // lane-obmcrec r1: see `overlappable_above`'s `src`. |
| 22138 | 22085 | let mut src = row; |
| @@ -22229,7 +22176,7 @@ fn find_samples( | ||
| 22229 | 22176 | 'outer: { |
| 22230 | 22177 | if up_available { |
| 22231 | 22178 | let above = grid.get(mi_row - 1, mi_col); |
| 22232 | - let superblock_width = above.map_or(1, |c| c.size).max(1); | |
| 22179 | + let superblock_width = above.map_or(1, |c| c.size as usize).max(1); | |
| 22233 | 22180 | if bw4 <= superblock_width { |
| 22234 | 22181 | let col_offset = -((mi_col % superblock_width) as isize); |
| 22235 | 22182 | if col_offset < 0 { |
| @@ -22251,7 +22198,7 @@ fn find_samples( | ||
| 22251 | 22198 | let limit = bw4.min(mi_cols.saturating_sub(mi_col)); |
| 22252 | 22199 | while i < limit { |
| 22253 | 22200 | let cell = grid.get(mi_row - 1, mi_col + i); |
| 22254 | - let sw = cell.map_or(1, |c| c.size).max(1); | |
| 22201 | + let sw = cell.map_or(1, |c| c.size as usize).max(1); | |
| 22255 | 22202 | if let Some(info) = cell { |
| 22256 | 22203 | if single_ref_match(info) { |
| 22257 | 22204 | samples.push(rec(info, 0, -1, i as i32, 1)); |
| @@ -22267,7 +22214,7 @@ fn find_samples( | ||
| 22267 | 22214 | |
| 22268 | 22215 | if left_available { |
| 22269 | 22216 | let left = grid.get(mi_row, mi_col - 1); |
| 22270 | - let superblock_height = left.map_or(1, |c| c.size_h).max(1); | |
| 22217 | + let superblock_height = left.map_or(1, |c| c.size_h as usize).max(1); | |
| 22271 | 22218 | if bh4 <= superblock_height { |
| 22272 | 22219 | let row_offset = -((mi_row % superblock_height) as isize); |
| 22273 | 22220 | if row_offset < 0 { |
| @@ -22286,7 +22233,7 @@ fn find_samples( | ||
| 22286 | 22233 | let limit = bh4.min(mi_rows.saturating_sub(mi_row)); |
| 22287 | 22234 | while i < limit { |
| 22288 | 22235 | let cell = grid.get(mi_row + i, mi_col - 1); |
| 22289 | - let sh = cell.map_or(1, |c| c.size_h).max(1); | |
| 22236 | + let sh = cell.map_or(1, |c| c.size_h as usize).max(1); | |
| 22290 | 22237 | if let Some(info) = cell { |
| 22291 | 22238 | if single_ref_match(info) { |
| 22292 | 22239 | samples.push(rec(info, i as i32, 1, 0, -1)); |
| @@ -22717,7 +22664,7 @@ nbmv=({},{}) nbref={} nbbsize={} filt={}", | ||
| 22717 | 22664 | nb.mv.0, |
| 22718 | 22665 | nb.mv.1, |
| 22719 | 22666 | nb.ref_frame, |
| 22720 | - ec_obmc_bsize(nb.size, nb.size_h), | |
| 22667 | + ec_obmc_bsize(nb.size as usize, nb.size_h as usize), | |
| 22721 | 22668 | sym(v_kind) | (sym(h_kind) << 16), |
| 22722 | 22669 | ); |
| 22723 | 22670 | } |
| @@ -23851,8 +23798,8 @@ fn decode_inter_block( | ||
| 23851 | 23798 | mv1: Some(mv1), |
| 23852 | 23799 | mv: mv0, |
| 23853 | 23800 | is_new_mv: matches!(compound_mode, 2 | 3 | 4 | 5 | 7), |
| 23854 | - size: bw4, | |
| 23855 | - size_h: bh4, | |
| 23801 | + size: bw4 as u8, | |
| 23802 | + size_h: bh4 as u8, | |
| 23856 | 23803 | // libaom `is_global_mv_block`: per-ref-slot, mode |
| 23857 | 23804 | // GLOBAL_GLOBALMV, block >= 8x8, and THAT slot's |
| 23858 | 23805 | // own gm model > TRANSLATION (IDENTITY excluded |
| @@ -25413,8 +25360,8 @@ fn decode_inter_block( | ||
| 25413 | 25360 | mv1: None, |
| 25414 | 25361 | mv, |
| 25415 | 25362 | is_new_mv, |
| 25416 | - size: bw4, | |
| 25417 | - size_h: bh4, | |
| 25363 | + size: bw4 as u8, | |
| 25364 | + size_h: bh4 as u8, | |
| 25418 | 25365 | is_global_mv0: is_global_mv_block, |
| 25419 | 25366 | is_global_mv1: false, |
| 25420 | 25367 | }, |
| @@ -26239,8 +26186,8 @@ fn decode_inter_block( | ||
| 26239 | 26186 | mv1: None, |
| 26240 | 26187 | mv: (0, 0), |
| 26241 | 26188 | is_new_mv: false, |
| 26242 | - size: write_w / MI, | |
| 26243 | - size_h: write_h / MI, | |
| 26189 | + size: (write_w / MI) as u8, | |
| 26190 | + size_h: (write_h / MI) as u8, | |
| 26244 | 26191 | is_global_mv0: false, |
| 26245 | 26192 | is_global_mv1: false, |
| 26246 | 26193 | }, |
| @@ -26463,8 +26410,8 @@ fn decode_inter_block( | ||
| 26463 | 26410 | mv1: None, |
| 26464 | 26411 | mv: (0, 0), |
| 26465 | 26412 | is_new_mv: false, |
| 26466 | - size: side / 4, | |
| 26467 | - size_h: side / 4, | |
| 26413 | + size: (side / 4) as u8, | |
| 26414 | + size_h: (side / 4) as u8, | |
| 26468 | 26415 | is_global_mv0: false, |
| 26469 | 26416 | is_global_mv1: false, |
| 26470 | 26417 | }, |
| @@ -27914,8 +27861,8 @@ fn decode_intra_sub8_leaf( | ||
| 27914 | 27861 | mv1: None, |
| 27915 | 27862 | mv: (0, 0), |
| 27916 | 27863 | is_new_mv: false, |
| 27917 | - size: w_mi, | |
| 27918 | - size_h: h_mi, | |
| 27864 | + size: w_mi as u8, | |
| 27865 | + size_h: h_mi as u8, | |
| 27919 | 27866 | is_global_mv0: false, |
| 27920 | 27867 | is_global_mv1: false, |
| 27921 | 27868 | }, |
| @@ -28619,8 +28566,8 @@ fn grid_stamp_rect( | ||
| 28619 | 28566 | mv1: None, |
| 28620 | 28567 | mv, |
| 28621 | 28568 | is_new_mv, |
| 28622 | - size: w_mi, | |
| 28623 | - size_h: h_mi, | |
| 28569 | + size: w_mi as u8, | |
| 28570 | + size_h: h_mi as u8, | |
| 28624 | 28571 | is_global_mv0: false, |
| 28625 | 28572 | is_global_mv1: false, |
| 28626 | 28573 | }, |
crates/ec-av1/src/mvstack.rsmodified+27 -14
| @@ -196,11 +196,11 @@ pub struct MiInfo { | ||
| 196 | 196 | /// inter -- libaom's `scan_row_mbmi` advances `processed_rows` from any |
| 197 | 197 | /// candidate's `bsize` regardless of whether it also casts a vote (that |
| 198 | 198 | /// requires a ref-frame match, checked separately in `add_ref_mv_candidate`). |
| 199 | - pub size: usize, | |
| 199 | + pub size: u8, | |
| 200 | 200 | /// The unit's height in 4x4 mi cells (== `size` for every square block; |
| 201 | 201 | /// differs only for rect partition strips, lane-rect r2). Row scans step |
| 202 | 202 | /// and weight by `size` (width), column scans by `size_h`. |
| 203 | - pub size_h: usize, | |
| 203 | + pub size_h: u8, | |
| 204 | 204 | } |
| 205 | 205 | |
| 206 | 206 | /// The whole frame's `mi` grid, one [`MiInfo`] per 4x4 unit, in raster order. |
| @@ -549,7 +549,7 @@ fn scan_row( | ||
| 549 | 549 | i += 1; |
| 550 | 550 | continue; |
| 551 | 551 | }; |
| 552 | - let n4 = info.size; | |
| 552 | + let n4 = info.size as usize; | |
| 553 | 553 | let mut len = bw4.min(n4); |
| 554 | 554 | if use_step_16 { |
| 555 | 555 | len = len.max(4); |
| @@ -561,7 +561,7 @@ fn scan_row( | ||
| 561 | 561 | // `xd->width >= mi_size_wide[BLOCK_8X8]` as well: a 4-wide block (a 1:4 |
| 562 | 562 | // strip, a sub-8x8 leaf) keeps weight 2 and leaves `processed_rows` alone. |
| 563 | 563 | if bw4 >= 2 && bw4 <= n4 { |
| 564 | - let inc = ((-max_row_offset + row_offset + 1) as usize).min(info.size_h); | |
| 564 | + let inc = ((-max_row_offset + row_offset + 1) as usize).min(info.size_h as usize); | |
| 565 | 565 | weight = weight.max(inc as u32); |
| 566 | 566 | *processed_rows = (inc as isize - row_offset - 1).max(0) as usize; |
| 567 | 567 | } |
| @@ -637,7 +637,7 @@ fn scan_col( | ||
| 637 | 637 | i += 1; |
| 638 | 638 | continue; |
| 639 | 639 | }; |
| 640 | - let n4 = info.size_h; | |
| 640 | + let n4 = info.size_h as usize; | |
| 641 | 641 | let mut len = bh4.min(n4); |
| 642 | 642 | if use_step_16 { |
| 643 | 643 | len = len.max(4); |
| @@ -649,7 +649,7 @@ fn scan_col( | ||
| 649 | 649 | // mi_size_high[BLOCK_8X8]` gates this branch, so a 4-high block keeps |
| 650 | 650 | // weight 2 and leaves `processed_cols` alone. |
| 651 | 651 | if bh4 >= 2 && bh4 <= n4 { |
| 652 | - let inc = ((-max_col_offset + col_offset + 1) as usize).min(info.size); | |
| 652 | + let inc = ((-max_col_offset + col_offset + 1) as usize).min(info.size as usize); | |
| 653 | 653 | weight = weight.max(inc as u32); |
| 654 | 654 | *processed_cols = (inc as isize - col_offset - 1).max(0) as usize; |
| 655 | 655 | } |
| @@ -1217,7 +1217,7 @@ pub fn find_mv_stack_with_sign_bias( | ||
| 1217 | 1217 | let mut idx = 0usize; |
| 1218 | 1218 | while idx < mi_size && candidates.len() < MAX_MV_REF_CANDIDATES { |
| 1219 | 1219 | let cand = grid.get(mi_row - 1, mi_col + idx); |
| 1220 | - let step = cand.map_or(1, |c| c.size).max(1); | |
| 1220 | + let step = cand.map_or(1, |c| c.size as usize).max(1); | |
| 1221 | 1221 | if let Some(c) = cand { |
| 1222 | 1222 | process_single_ref_mv_candidate(c, ref_frame, sign_bias_table, &mut candidates); |
| 1223 | 1223 | } |
| @@ -1228,7 +1228,7 @@ pub fn find_mv_stack_with_sign_bias( | ||
| 1228 | 1228 | let mut idx = 0usize; |
| 1229 | 1229 | while idx < mi_size && candidates.len() < MAX_MV_REF_CANDIDATES { |
| 1230 | 1230 | let cand = grid.get(mi_row + idx, mi_col - 1); |
| 1231 | - let step = cand.map_or(1, |c| c.size_h).max(1); | |
| 1231 | + let step = cand.map_or(1, |c| c.size_h as usize).max(1); | |
| 1232 | 1232 | if let Some(c) = cand { |
| 1233 | 1233 | process_single_ref_mv_candidate(c, ref_frame, sign_bias_table, &mut candidates); |
| 1234 | 1234 | } |
| @@ -1441,7 +1441,7 @@ fn scan_row_compound( | ||
| 1441 | 1441 | i += 1; |
| 1442 | 1442 | continue; |
| 1443 | 1443 | }; |
| 1444 | - let n4 = info.size; | |
| 1444 | + let n4 = info.size as usize; | |
| 1445 | 1445 | let mut len = bw4.min(n4); |
| 1446 | 1446 | if use_step_16 { |
| 1447 | 1447 | len = len.max(4); |
| @@ -1453,7 +1453,7 @@ fn scan_row_compound( | ||
| 1453 | 1453 | // `xd->width >= mi_size_wide[BLOCK_8X8]` as well: a 4-wide block (a 1:4 |
| 1454 | 1454 | // strip, a sub-8x8 leaf) keeps weight 2 and leaves `processed_rows` alone. |
| 1455 | 1455 | if bw4 >= 2 && bw4 <= n4 { |
| 1456 | - let inc = ((-max_row_offset + row_offset + 1) as usize).min(info.size_h); | |
| 1456 | + let inc = ((-max_row_offset + row_offset + 1) as usize).min(info.size_h as usize); | |
| 1457 | 1457 | weight = weight.max(inc as u32); |
| 1458 | 1458 | *processed_rows = (inc as isize - row_offset - 1).max(0) as usize; |
| 1459 | 1459 | } |
| @@ -1504,7 +1504,7 @@ fn scan_col_compound( | ||
| 1504 | 1504 | i += 1; |
| 1505 | 1505 | continue; |
| 1506 | 1506 | }; |
| 1507 | - let n4 = info.size_h; | |
| 1507 | + let n4 = info.size_h as usize; | |
| 1508 | 1508 | let mut len = bh4.min(n4); |
| 1509 | 1509 | if use_step_16 { |
| 1510 | 1510 | len = len.max(4); |
| @@ -1516,7 +1516,7 @@ fn scan_col_compound( | ||
| 1516 | 1516 | // mi_size_high[BLOCK_8X8]` gates this branch, so a 4-high block keeps |
| 1517 | 1517 | // weight 2 and leaves `processed_cols` alone. |
| 1518 | 1518 | if bh4 >= 2 && bh4 <= n4 { |
| 1519 | - let inc = ((-max_col_offset + col_offset + 1) as usize).min(info.size); | |
| 1519 | + let inc = ((-max_col_offset + col_offset + 1) as usize).min(info.size as usize); | |
| 1520 | 1520 | weight = weight.max(inc as u32); |
| 1521 | 1521 | *processed_cols = (inc as isize - col_offset - 1).max(0) as usize; |
| 1522 | 1522 | } |
| @@ -1995,7 +1995,7 @@ pub fn find_mv_stack_compound( | ||
| 1995 | 1995 | let mut idx = 0usize; |
| 1996 | 1996 | while idx < mi_size { |
| 1997 | 1997 | let cand = grid.get(mi_row - 1, mi_col + idx); |
| 1998 | - let step = cand.map_or(1, |c| c.size).max(1); | |
| 1998 | + let step = cand.map_or(1, |c| c.size as usize).max(1); | |
| 1999 | 1999 | if let Some(c) = cand { |
| 2000 | 2000 | process_compound_ref_mv_candidate(c, ref_frame, sign_bias_table, &mut lists); |
| 2001 | 2001 | } |
| @@ -2006,7 +2006,7 @@ pub fn find_mv_stack_compound( | ||
| 2006 | 2006 | let mut idx = 0usize; |
| 2007 | 2007 | while idx < mi_size { |
| 2008 | 2008 | let cand = grid.get(mi_row + idx, mi_col - 1); |
| 2009 | - let step = cand.map_or(1, |c| c.size_h).max(1); | |
| 2009 | + let step = cand.map_or(1, |c| c.size_h as usize).max(1); | |
| 2010 | 2010 | if let Some(c) = cand { |
| 2011 | 2011 | process_compound_ref_mv_candidate(c, ref_frame, sign_bias_table, &mut lists); |
| 2012 | 2012 | } |
| @@ -2390,6 +2390,19 @@ pub(crate) fn comp_reference_type_ctx( | ||
| 2390 | 2390 | |
| 2391 | 2391 | #[cfg(test)] |
| 2392 | 2392 | mod tests { |
| 2393 | + /// lane-mi: a 4K frame's grid is ~518k cells, refilled per frame, and | |
| 2394 | + /// every mv-stack scan walks it -- `size`/`size_h` as `u8` keep the | |
| 2395 | + /// option under 32 bytes. Widening a field here is a measurable | |
| 2396 | + /// regression, not a free change. | |
| 2397 | + #[test] | |
| 2398 | + fn mi_info_stays_small_enough_for_a_4k_grid() { | |
| 2399 | + assert!( | |
| 2400 | + std::mem::size_of::<Option<MiInfo>>() <= 32, | |
| 2401 | + "Option<MiInfo> grew to {} bytes", | |
| 2402 | + std::mem::size_of::<Option<MiInfo>>() | |
| 2403 | + ); | |
| 2404 | + } | |
| 2405 | + | |
| 2393 | 2406 | use super::*; |
| 2394 | 2407 | |
| 2395 | 2408 | fn inter(mv: (i32, i32)) -> MiInfo { |
crates/ec-av1/src/tile.rsmodified+4 -4
| @@ -2634,8 +2634,8 @@ fn write_inter_frame_leaf( | ||
| 2634 | 2634 | mv1: None, |
| 2635 | 2635 | mv, |
| 2636 | 2636 | is_new_mv, |
| 2637 | - size: SUB_MI as usize, | |
| 2638 | - size_h: SUB_MI as usize, | |
| 2637 | + size: SUB_MI as usize as u8, | |
| 2638 | + size_h: SUB_MI as usize as u8, | |
| 2639 | 2639 | is_global_mv0: false, |
| 2640 | 2640 | is_global_mv1: false, |
| 2641 | 2641 | }, |
| @@ -2666,8 +2666,8 @@ fn write_inter_frame_leaf( | ||
| 2666 | 2666 | mv1: None, |
| 2667 | 2667 | mv: (0, 0), |
| 2668 | 2668 | is_new_mv: false, |
| 2669 | - size: SUB_MI as usize, | |
| 2670 | - size_h: SUB_MI as usize, | |
| 2669 | + size: SUB_MI as usize as u8, | |
| 2670 | + size_h: SUB_MI as usize as u8, | |
| 2671 | 2671 | is_global_mv0: false, |
| 2672 | 2672 | is_global_mv1: false, |
| 2673 | 2673 | }, |