forge
Explore
Log in

Don't you dare go Hollow

Heap-free MV stack and row-fill mi publication

Browse files at this commit

fc982dba9c966e5570f227a90fd6d8d1879d35f9Ahmet Kaan GümüşParent: 5b55d04
  • perf
    • heap-free MV stack and row-fill mi publication
Show full message
perf(av1): heap-free MV stack and row-fill mi publication

The MV stack was two heap allocations per inter block (`entries` plus
`drl_ctx`); both lists are bounded by a spec constant, so they move into a
fixed-capacity inline `SmallVec` that derefs to the same slice API. Mode-info
publication stamped its block footprint cell by cell through `MiGrid::set`;
rows are contiguous, so `MiGrid::fill_rect` fills each row with one
`slice::fill` of the `Copy` cell instead.

Byte-exact: all four gate streams hash unchanged at 1 thread.
instructions:u on the 4K segment 412.376 -> 410.629 G at 1 thread,
421.419 -> 419.746 G at (16,4,2).
crates/ec-av1/src/decode.rsmodified+45 -63
@@ -24231,11 +24231,11 @@ fn decode_inter_block(
24231 // too -- a square `bw4`x`bw4` stamp here claims a rect strip's24231 // too -- a square `bw4`x`bw4` stamp here claims a rect strip's
24232 // NEXT strip's own rows/cols before it decodes, corrupting24232 // NEXT strip's own rows/cols before it decodes, corrupting
24233 // every later mvstack scan that reads this cell back.24233 // every later mvstack scan that reads this cell back.
24234- for dr in 0..bh4 {24234+ grid.fill_rect(
24235- for dc in 0..bw4 {24235+ mi_row,
24236- grid.set(24236+ mi_col,
24237- mi_row + dr,24237+ bh4,
24238- mi_col + dc,24238+ bw4,
24239 MiInfo {24239 MiInfo {
24240 is_inter: true,24240 is_inter: true,
24241 ref_frame: ref0,24241 ref_frame: ref0,
@@ -24254,8 +24254,6 @@ fn decode_inter_block(
24254 is_global_mv1,24254 is_global_mv1,
24255 },24255 },
24256 );24256 );
24257- }
24258- }
24259 // spec 5.11.25's `comp_group_idx`/`compound_idx`: only read when24257 // spec 5.11.25's `comp_group_idx`/`compound_idx`: only read when
24260 // masked compound / distance-weighted compound are actually24258 // masked compound / distance-weighted compound are actually
24261 // enabled for this stream -- `is_any_masked_compound_used_here`24259 // enabled for this stream -- `is_any_masked_compound_used_here`
@@ -25787,11 +25785,11 @@ fn decode_inter_block(
25787 // lane-rect r2: see the compound path's matching comment above --25785 // lane-rect r2: see the compound path's matching comment above --
25788 // `grid` must be stamped with the block's true bh4/bw4 span, not25786 // `grid` must be stamped with the block's true bh4/bw4 span, not
25789 // a square `bw4`x`bw4` guess.25787 // a square `bw4`x`bw4` guess.
25790- for dr in 0..bh4 {25788+ grid.fill_rect(
25791- for dc in 0..bw4 {25789+ mi_row,
25792- grid.set(25790+ mi_col,
25793- mi_row + dr,25791+ bh4,
25794- mi_col + dc,25792+ bw4,
25795 MiInfo {25793 MiInfo {
25796 is_inter: true,25794 is_inter: true,
25797 ref_frame,25795 ref_frame,
@@ -25811,8 +25809,6 @@ fn decode_inter_block(
25811 is_global_mv1: false,25809 is_global_mv1: false,
25812 },25810 },
25813 );25811 );
25814- }
25815- }
25816 mode_for_tx = 0;25812 mode_for_tx = 0;
25817 uv_predict_mode = DC_PRED;25813 uv_predict_mode = DC_PRED;
25818 25814
@@ -26619,11 +26615,11 @@ fn decode_inter_block(
26619 // lane's `r * SUB_MI` re-derivation would snap a sub-SUB strip to26615 // lane's `r * SUB_MI` re-derivation would snap a sub-SUB strip to
26620 // its enclosing 16-px cell.26616 // its enclosing 16-px cell.
26621 let (mi_r0, mi_c0) = (rmi, cmi);26617 let (mi_r0, mi_c0) = (rmi, cmi);
26622- for dr in 0..write_h / MI {26618+ grid.fill_rect(
26623- for dc in 0..write_w / MI {26619+ mi_r0,
26624- grid.set(26620+ mi_c0,
26625- mi_r0 + dr,26621+ write_h / MI,
26626- mi_c0 + dc,26622+ write_w / MI,
26627 MiInfo {26623 MiInfo {
26628 is_inter: false,26624 is_inter: false,
26629 ref_frame: -1,26625 ref_frame: -1,
@@ -26637,8 +26633,6 @@ fn decode_inter_block(
26637 is_global_mv1: false,26633 is_global_mv1: false,
26638 },26634 },
26639 );26635 );
26640- }
26641- }
26642 neighbours.record_inter_rect_mi(26636 neighbours.record_inter_rect_mi(
26643 at,26637 at,
26644 write_w / MI,26638 write_w / MI,
@@ -26843,11 +26837,11 @@ fn decode_inter_block(
26843 ref_frame_for_lf = 0;26837 ref_frame_for_lf = 0;
26844 globalmv_for_lf = false;26838 globalmv_for_lf = false;
26845 let (mi_row, mi_col) = (rmi, cmi);26839 let (mi_row, mi_col) = (rmi, cmi);
26846- for dr in 0..side / 4 {26840+ grid.fill_rect(
26847- for dc in 0..side / 4 {26841+ mi_row,
26848- grid.set(26842+ mi_col,
26849- mi_row + dr,26843+ side / 4,
26850- mi_col + dc,26844+ side / 4,
26851 MiInfo {26845 MiInfo {
26852 is_inter: false,26846 is_inter: false,
26853 ref_frame: -1,26847 ref_frame: -1,
@@ -26861,8 +26855,6 @@ fn decode_inter_block(
26861 is_global_mv1: false,26855 is_global_mv1: false,
26862 },26856 },
26863 );26857 );
26864- }
26865- }
26866 26858
26867 // lane-intrainter r1: an intra block in an inter frame reads the same26859 // lane-intrainter r1: an intra block in an inter frame reads the same
26868 // `tx_depth` symbol a key-frame block does, and when it splits, the26860 // `tx_depth` symbol a key-frame block does, and when it splits, the
@@ -28294,11 +28286,11 @@ fn decode_intra_sub8_leaf(
28294 // intra-in-inter block writes them: `is_inter = 0`, `INTRA_FRAME` ref, no28286 // intra-in-inter block writes them: `is_inter = 0`, `INTRA_FRAME` ref, no
28295 // interpolation filter, no skip mode.28287 // interpolation filter, no skip mode.
28296 neighbours.record_inter_rect_mi(lmi, w_mi, h_mi, skip, false, 0, [3, 3], false);28288 neighbours.record_inter_rect_mi(lmi, w_mi, h_mi, skip, false, 0, [3, 3], false);
28297- for dr in 0..h_mi {28289+ grid.fill_rect(
28298- for dc in 0..w_mi {28290+ lmi.0,
28299- grid.set(28291+ lmi.1,
28300- lmi.0 + dr,28292+ h_mi,
28301- lmi.1 + dc,28293+ w_mi,
28302 MiInfo {28294 MiInfo {
28303 is_inter: false,28295 is_inter: false,
28304 ref_frame: -1,28296 ref_frame: -1,
@@ -28312,8 +28304,6 @@ fn decode_intra_sub8_leaf(
28312 is_global_mv1: false,28304 is_global_mv1: false,
28313 },28305 },
28314 );28306 );
28315- }
28316- }
28317 SUB8_INTRA_RECT_HITS.with(|h| {28307 SUB8_INTRA_RECT_HITS.with(|h| {
28318 let mut s = h.get();28308 let mut s = h.get();
28319 s[usize::from(vert)] += 1;28309 s[usize::from(vert)] += 1;
@@ -28999,11 +28989,11 @@ fn grid_stamp_rect(
28999 mv: (i32, i32),28989 mv: (i32, i32),
29000 is_new_mv: bool,28990 is_new_mv: bool,
29001 ) {28991 ) {
29002- for dr in 0..h_mi {28992+ grid.fill_rect(
29003- for dc in 0..w_mi {28993+ mi_row,
29004- grid.set(28994+ mi_col,
29005- mi_row + dr,28995+ h_mi,
29006- mi_col + dc,28996+ w_mi,
29007 MiInfo {28997 MiInfo {
29008 is_inter: true,28998 is_inter: true,
29009 ref_frame,28999 ref_frame,
@@ -29018,8 +29008,6 @@ fn grid_stamp_rect(
29018 },29008 },
29019 );29009 );
29020 }29010 }
29021- }
29022-}
29023 29011
29024 /// Decodes one 8x8 leaf of a straddling 16x16 inter-frame block29012 /// Decodes one 8x8 leaf of a straddling 16x16 inter-frame block
29025 /// (lane-av1inter8), mirroring [`crate::tile::write_inter_frame_leaf8`]'s29013 /// (lane-av1inter8), mirroring [`crate::tile::write_inter_frame_leaf8`]'s
@@ -29580,11 +29568,11 @@ fn decode_inter_block8(
29580 COMPOUND_WARP_HITS.with(|c| c.set(c.get() + 1));29568 COMPOUND_WARP_HITS.with(|c| c.set(c.get() + 1));
29581 COMPOUND_WARP_HITS_8.with(|c| c.set(c.get() + 1));29569 COMPOUND_WARP_HITS_8.with(|c| c.set(c.get() + 1));
29582 }29570 }
29583- for dr in 0..2 {29571+ grid.fill_rect(
29584- for dc in 0..2 {29572+ mi_row,
29585- grid.set(29573+ mi_col,
29586- mi_row + dr,29574+ 2,
29587- mi_col + dc,29575+ 2,
29588 MiInfo {29576 MiInfo {
29589 is_inter: true,29577 is_inter: true,
29590 ref_frame: ref0,29578 ref_frame: ref0,
@@ -29598,8 +29586,6 @@ fn decode_inter_block8(
29598 is_global_mv1: is_global_mv1_c,29586 is_global_mv1: is_global_mv1_c,
29599 },29587 },
29600 );29588 );
29601- }
29602- }
29603 mode_for_tx = 0;29589 mode_for_tx = 0;
29604 29590
29605 let mut inter0_y = vec![0i32; SIDE * SIDE];29591 let mut inter0_y = vec![0i32; SIDE * SIDE];
@@ -30257,11 +30243,11 @@ fn decode_inter_block8(
30257 warp_params.is_some(),30243 warp_params.is_some(),
30258 );30244 );
30259 }30245 }
30260- for dr in 0..2 {30246+ grid.fill_rect(
30261- for dc in 0..2 {30247+ mi_row,
30262- grid.set(30248+ mi_col,
30263- mi_row + dr,30249+ 2,
30264- mi_col + dc,30250+ 2,
30265 MiInfo {30251 MiInfo {
30266 is_inter: true,30252 is_inter: true,
30267 ref_frame,30253 ref_frame,
@@ -30277,8 +30263,6 @@ fn decode_inter_block8(
30277 is_global_mv1: false,30263 is_global_mv1: false,
30278 },30264 },
30279 );30265 );
30280- }
30281- }
30282 mode_for_tx = 0;30266 mode_for_tx = 0;
30283 30267
30284 // lane-scaledref r1: this leaf's own prediction is always `Regular`30268 // lane-scaledref r1: this leaf's own prediction is always `Regular`
@@ -30721,11 +30705,11 @@ fn decode_inter_block8(
30721 });30705 });
30722 mode_for_tx = mode;30706 mode_for_tx = mode;
30723 let (mi_row, mi_col) = leaf_mi;30707 let (mi_row, mi_col) = leaf_mi;
30724- for dr in 0..2 {30708+ grid.fill_rect(
30725- for dc in 0..2 {30709+ mi_row,
30726- grid.set(30710+ mi_col,
30727- mi_row + dr,30711+ 2,
30728- mi_col + dc,30712+ 2,
30729 MiInfo {30713 MiInfo {
30730 is_inter: false,30714 is_inter: false,
30731 ref_frame: -1,30715 ref_frame: -1,
@@ -30739,8 +30723,6 @@ fn decode_inter_block8(
30739 is_global_mv1: false,30723 is_global_mv1: false,
30740 },30724 },
30741 );30725 );
30742- }
30743- }
30744 30726
30745 // lane-leaf8tx r1: the 8x8 leaf's own intra `tx_depth` (libaom30727 // lane-leaf8tx r1: the 8x8 leaf's own intra `tx_depth` (libaom
30746 // `read_tx_size` -> `read_selected_tx_size`, max depth 1 at30728 // `read_tx_size` -> `read_selected_tx_size`, max depth 1 at
crates/ec-av1/src/mvstack.rsmodified+117 -21
@@ -272,6 +272,23 @@ impl MiGrid {
272 }272 }
273 }273 }
274 274
275+ /// Records one block's whole `bh4` x `bw4` footprint at once. Every
276+ /// caller published a block cell-by-cell through [`Self::set`]; the rows
277+ /// are contiguous, so this fills each of them with one `slice::fill` of
278+ /// the (`Copy`) cell instead, the way the neighbour grids' own span fills
279+ /// do.
280+ pub fn fill_rect(&mut self, row: usize, col: usize, h: usize, w: usize, info: MiInfo) {
281+ if col >= self.cols || row >= self.rows {
282+ return;
283+ }
284+ let w = w.min(self.cols - col);
285+ let cell = Some(info);
286+ for r in row..(row + h).min(self.rows) {
287+ let base = r * self.cols + col;
288+ self.cells[base..base + w].fill(cell);
289+ }
290+ }
291+
275 /// The unit at `(row, col)`, or `None` when it is outside the grid, hasn't292 /// The unit at `(row, col)`, or `None` when it is outside the grid, hasn't
276 /// been coded, or sits outside the current tile's own bounds ([`Self::set_tile_bounds`]).293 /// been coded, or sits outside the current tile's own bounds ([`Self::set_tile_bounds`]).
277 pub fn get(&self, row: usize, col: usize) -> Option<&MiInfo> {294 pub fn get(&self, row: usize, col: usize) -> Option<&MiInfo> {
@@ -307,7 +324,7 @@ impl MiGrid {
307 324
308 /// One entry of the reference MV stack: a candidate motion vector and the325 /// One entry of the reference MV stack: a candidate motion vector and the
309 /// total weight the neighbours that agreed on it contributed.326 /// total weight the neighbours that agreed on it contributed.
310-#[derive(Clone, Copy, Debug, PartialEq, Eq)]327+#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
311 pub struct StackEntry {328 pub struct StackEntry {
312 /// The candidate `(row, col)` motion vector.329 /// The candidate `(row, col)` motion vector.
313 pub mv: (i32, i32),330 pub mv: (i32, i32),
@@ -315,6 +332,85 @@ pub struct StackEntry {
315 pub weight: u32,332 pub weight: u32,
316 }333 }
317 334
335+/// A fixed-capacity, heap-free candidate list. The MV stack is rebuilt for
336+/// EVERY inter block, so the `Vec` this replaces was one malloc/free pair per
337+/// block (plus one for `drl_ctx`); capacity is a spec constant
338+/// ([`MAX_STACK_SIZE`]), so the storage is inline and `Deref` hands every
339+/// consumer the same slice API a `Vec` did.
340+#[derive(Clone, Copy, Debug)]
341+pub struct SmallVec<T: Copy, const N: usize> {
342+ len: u8,
343+ buf: [T; N],
344+}
345+
346+impl<T: Copy + Default, const N: usize> Default for SmallVec<T, N> {
347+ fn default() -> Self {
348+ Self {
349+ len: 0,
350+ buf: [T::default(); N],
351+ }
352+ }
353+}
354+
355+impl<T: Copy, const N: usize> SmallVec<T, N> {
356+ /// Appends `v`. Callers gate on [`MAX_STACK_SIZE`] before pushing (the
357+ /// spec drops the overflowing candidate at insertion), so a full list
358+ /// here is a bug, not a stream property.
359+ pub fn push(&mut self, v: T) {
360+ debug_assert!((self.len as usize) < N);
361+ self.buf[self.len as usize] = v;
362+ self.len += 1;
363+ }
364+
365+ /// `Vec::truncate`.
366+ pub fn truncate(&mut self, n: usize) {
367+ if n < self.len as usize {
368+ self.len = n as u8;
369+ }
370+ }
371+}
372+
373+impl<T: Copy + Default, const N: usize> FromIterator<T> for SmallVec<T, N> {
374+ fn from_iter<I: IntoIterator<Item = T>>(iter: I) -> Self {
375+ let mut out = Self::default();
376+ for v in iter {
377+ out.push(v);
378+ }
379+ out
380+ }
381+}
382+
383+impl<T: Copy, const N: usize> std::ops::Deref for SmallVec<T, N> {
384+ type Target = [T];
385+ fn deref(&self) -> &[T] {
386+ &self.buf[..self.len as usize]
387+ }
388+}
389+
390+impl<T: Copy, const N: usize> std::ops::DerefMut for SmallVec<T, N> {
391+ fn deref_mut(&mut self) -> &mut [T] {
392+ &mut self.buf[..self.len as usize]
393+ }
394+}
395+
396+impl<T: Copy + PartialEq, const N: usize> PartialEq for SmallVec<T, N> {
397+ fn eq(&self, other: &Self) -> bool {
398+ **self == **other
399+ }
400+}
401+
402+impl<T: Copy + Eq, const N: usize> Eq for SmallVec<T, N> {}
403+
404+/// The single-reference MV stack's own list type.
405+pub type StackVec = SmallVec<StackEntry, MAX_STACK_SIZE>;
406+
407+/// The compound MV stack's own list type.
408+pub type CompoundStackVec = SmallVec<CompoundStackEntry, MAX_STACK_SIZE>;
409+
410+/// `drl_ctx`: one context per adjacent stack pair, so at most
411+/// `MAX_STACK_SIZE - 1` of them.
412+pub type DrlVec = SmallVec<usize, MAX_STACK_SIZE>;
413+
318 /// The result of [`find_mv_stack`]: the sorted candidate list, the two414 /// The result of [`find_mv_stack`]: the sorted candidate list, the two
319 /// predictors a `NEARESTMV`/`NEARMV` block reads from it, the predictor a415 /// predictors a `NEARESTMV`/`NEARMV` block reads from it, the predictor a
320 /// `NEWMV` residual is coded against, and the symbol contexts the block's416 /// `NEWMV` residual is coded against, and the symbol contexts the block's
@@ -323,7 +419,7 @@ pub struct StackEntry {
323 pub struct MvStack {419 pub struct MvStack {
324 /// The candidates, highest weight first (ties keep scan order: above,420 /// The candidates, highest weight first (ties keep scan order: above,
325 /// then left, then top-right).421 /// then left, then top-right).
326- pub entries: Vec<StackEntry>,422+ pub entries: StackVec,
327 /// `RefStackMv[0]`, or `(0, 0)` when the stack is empty.423 /// `RefStackMv[0]`, or `(0, 0)` when the stack is empty.
328 pub nearest_mv: (i32, i32),424 pub nearest_mv: (i32, i32),
329 /// `RefStackMv[1]`, or `(0, 0)` when the stack has fewer than two425 /// `RefStackMv[1]`, or `(0, 0)` when the stack has fewer than two
@@ -340,7 +436,7 @@ pub struct MvStack {
340 pub zero_mv_ctx: usize,436 pub zero_mv_ctx: usize,
341 /// Context for each `drl_mode` symbol between consecutive stack437 /// Context for each `drl_mode` symbol between consecutive stack
342 /// entries, `entries.len().saturating_sub(1)` long.438 /// entries, `entries.len().saturating_sub(1)` long.
343- pub drl_ctx: Vec<usize>,439+ pub drl_ctx: DrlVec,
344 }440 }
345 441
346 /// Spec 7.10.2.8's threshold a candidate's weight is compared against to442 /// Spec 7.10.2.8's threshold a candidate's weight is compared against to
@@ -377,7 +473,7 @@ const MVREF_ROW_COLS: usize = 3;
377 /// Adds one candidate MV with `weight` to `candidates`, merging it into an473 /// Adds one candidate MV with `weight` to `candidates`, merging it into an
378 /// existing entry with the same MV rather than duplicating it (spec474 /// existing entry with the same MV rather than duplicating it (spec
379 /// `add_ref_mv_candidate`, 7.10.2.5).475 /// `add_ref_mv_candidate`, 7.10.2.5).
380-fn add_candidate(candidates: &mut Vec<StackEntry>, mv: (i32, i32), weight: u32) {476+fn add_candidate(candidates: &mut StackVec, mv: (i32, i32), weight: u32) {
381 if let Some(entry) = candidates.iter_mut().find(|e| e.mv == mv) {477 if let Some(entry) = candidates.iter_mut().find(|e| e.mv == mv) {
382 entry.weight += weight;478 entry.weight += weight;
383 } else if candidates.len() >= MAX_STACK_SIZE {479 } else if candidates.len() >= MAX_STACK_SIZE {
@@ -468,7 +564,7 @@ fn process_single_ref_mv_candidate(
468 candidate: &MiInfo,564 candidate: &MiInfo,
469 ref_frame: i8,565 ref_frame: i8,
470 sign_bias_table: &SignBiasTable,566 sign_bias_table: &SignBiasTable,
471- candidates: &mut Vec<StackEntry>,567+ candidates: &mut StackVec,
472 ) {568 ) {
473 if !candidate.is_inter {569 if !candidate.is_inter {
474 return;570 return;
@@ -538,7 +634,7 @@ fn scan_row(
538 max_row_offset: isize,634 max_row_offset: isize,
539 ref_frame: i8,635 ref_frame: i8,
540 gm: &GmMvTable,636 gm: &GmMvTable,
541- candidates: &mut Vec<StackEntry>,637+ candidates: &mut StackVec,
542 newmv_count: &mut u32,638 newmv_count: &mut u32,
543 processed_rows: &mut usize,639 processed_rows: &mut usize,
544 ) -> bool {640 ) -> bool {
@@ -626,7 +722,7 @@ fn scan_col(
626 max_col_offset: isize,722 max_col_offset: isize,
627 ref_frame: i8,723 ref_frame: i8,
628 gm: &GmMvTable,724 gm: &GmMvTable,
629- candidates: &mut Vec<StackEntry>,725+ candidates: &mut StackVec,
630 newmv_count: &mut u32,726 newmv_count: &mut u32,
631 processed_cols: &mut usize,727 processed_cols: &mut usize,
632 ) -> bool {728 ) -> bool {
@@ -762,7 +858,7 @@ fn scan_top_right(
762 bw4: usize,858 bw4: usize,
763 ref_frame: i8,859 ref_frame: i8,
764 gm: &GmMvTable,860 gm: &GmMvTable,
765- candidates: &mut Vec<StackEntry>,861+ candidates: &mut StackVec,
766 newmv_count: &mut u32,862 newmv_count: &mut u32,
767 ) -> bool {863 ) -> bool {
768 let Some(row) = mi_row.checked_sub(1) else {864 let Some(row) = mi_row.checked_sub(1) else {
@@ -791,7 +887,7 @@ fn scan_corner(
791 mi_col: usize,887 mi_col: usize,
792 ref_frame: i8,888 ref_frame: i8,
793 gm: &GmMvTable,889 gm: &GmMvTable,
794- candidates: &mut Vec<StackEntry>,890+ candidates: &mut StackVec,
795 newmv_count: &mut u32,891 newmv_count: &mut u32,
796 ) -> bool {892 ) -> bool {
797 let (Some(row), Some(col)) = (mi_row.checked_sub(1), mi_col.checked_sub(1)) else {893 let (Some(row), Some(col)) = (mi_row.checked_sub(1), mi_col.checked_sub(1)) else {
@@ -919,7 +1015,7 @@ pub fn find_mv_stack_with_sign_bias(
919 ) -> MvStack {1015 ) -> MvStack {
920 // lane-alloc: the stack is capped at MAX_STACK_SIZE entries, so the pushes1016 // lane-alloc: the stack is capped at MAX_STACK_SIZE entries, so the pushes
921 // below grew (and memcpy'd) a fresh allocation up to 4 times per block.1017 // below grew (and memcpy'd) a fresh allocation up to 4 times per block.
922- let mut candidates = Vec::with_capacity(MAX_STACK_SIZE);1018+ let mut candidates = StackVec::default();
923 let mut newmv_count = 0u32;1019 let mut newmv_count = 0u32;
924 1020
925 // libaom's `max_row_offset`/`max_col_offset` (`setup_ref_mv_list`): how1021 // libaom's `max_row_offset`/`max_col_offset` (`setup_ref_mv_list`): how
@@ -1011,7 +1107,7 @@ pub fn find_mv_stack_with_sign_bias(
1011 // av1_find_mv_stack boosts only the entries the immediate scan found —1107 // av1_find_mv_stack boosts only the entries the immediate scan found —
1012 // exactly `candidates` at this point, before the corner probe (below)1108 // exactly `candidates` at this point, before the corner probe (below)
1013 // can add anything else (mvref_common.c ~line 544-545).1109 // can add anything else (mvref_common.c ~line 544-545).
1014- for entry in &mut candidates {1110+ for entry in candidates.iter_mut() {
1015 entry.weight += REF_CAT_LEVEL;1111 entry.weight += REF_CAT_LEVEL;
1016 }1112 }
1017 1113
@@ -1371,7 +1467,7 @@ pub fn find_mv_stack_with_sign_bias(
1371 /// combined weight — spec 7.10.2's compound half of `add_ref_mv_candidate`1467 /// combined weight — spec 7.10.2's compound half of `add_ref_mv_candidate`
1372 /// (libaom `mvref_common.c`, the `is_compound` branch of `scan_row_mbmi`/1468 /// (libaom `mvref_common.c`, the `is_compound` branch of `scan_row_mbmi`/
1373 /// `scan_col_mbmi`/`scan_blk_mbmi`).1469 /// `scan_col_mbmi`/`scan_blk_mbmi`).
1374-#[derive(Clone, Copy, Debug, PartialEq, Eq)]1470+#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
1375 pub struct CompoundStackEntry {1471 pub struct CompoundStackEntry {
1376 /// The candidate's vote for `RefFrame[0]`'s motion vector.1472 /// The candidate's vote for `RefFrame[0]`'s motion vector.
1377 pub mv0: (i32, i32),1473 pub mv0: (i32, i32),
@@ -1386,7 +1482,7 @@ pub struct CompoundStackEntry {
1386 #[derive(Clone, Debug, PartialEq, Eq)]1482 #[derive(Clone, Debug, PartialEq, Eq)]
1387 pub struct CompoundMvStack {1483 pub struct CompoundMvStack {
1388 /// The candidates, highest weight first.1484 /// The candidates, highest weight first.
1389- pub entries: Vec<CompoundStackEntry>,1485+ pub entries: CompoundStackVec,
1390 /// `RefStackMv[0]` for both refs, or `((0,0),(0,0))` when the stack is1486 /// `RefStackMv[0]` for both refs, or `((0,0),(0,0))` when the stack is
1391 /// empty.1487 /// empty.
1392 pub nearest_mv: ((i32, i32), (i32, i32)),1488 pub nearest_mv: ((i32, i32), (i32, i32)),
@@ -1403,12 +1499,12 @@ pub struct CompoundMvStack {
1403 /// Context for the compound `zero_mv` symbol.1499 /// Context for the compound `zero_mv` symbol.
1404 pub zero_mv_ctx: usize,1500 pub zero_mv_ctx: usize,
1405 /// Context for each `drl_mode` symbol between consecutive stack entries.1501 /// Context for each `drl_mode` symbol between consecutive stack entries.
1406- pub drl_ctx: Vec<usize>,1502+ pub drl_ctx: DrlVec,
1407 }1503 }
1408 1504
1409 /// [`add_candidate`], doubled: dedupes on the whole `(mv0, mv1)` pair.1505 /// [`add_candidate`], doubled: dedupes on the whole `(mv0, mv1)` pair.
1410 fn add_compound_candidate(1506 fn add_compound_candidate(
1411- candidates: &mut Vec<CompoundStackEntry>,1507+ candidates: &mut CompoundStackVec,
1412 mv0: (i32, i32),1508 mv0: (i32, i32),
1413 mv1: (i32, i32),1509 mv1: (i32, i32),
1414 weight: u32,1510 weight: u32,
@@ -1443,7 +1539,7 @@ fn scan_row_compound(
1443 max_row_offset: isize,1539 max_row_offset: isize,
1444 ref_frame: (i8, i8),1540 ref_frame: (i8, i8),
1445 gm: &GmMvTable,1541 gm: &GmMvTable,
1446- candidates: &mut Vec<CompoundStackEntry>,1542+ candidates: &mut CompoundStackVec,
1447 newmv_count: &mut u32,1543 newmv_count: &mut u32,
1448 processed_rows: &mut usize,1544 processed_rows: &mut usize,
1449 ) -> bool {1545 ) -> bool {
@@ -1506,7 +1602,7 @@ fn scan_col_compound(
1506 max_col_offset: isize,1602 max_col_offset: isize,
1507 ref_frame: (i8, i8),1603 ref_frame: (i8, i8),
1508 gm: &GmMvTable,1604 gm: &GmMvTable,
1509- candidates: &mut Vec<CompoundStackEntry>,1605+ candidates: &mut CompoundStackVec,
1510 newmv_count: &mut u32,1606 newmv_count: &mut u32,
1511 processed_cols: &mut usize,1607 processed_cols: &mut usize,
1512 ) -> bool {1608 ) -> bool {
@@ -1566,7 +1662,7 @@ fn scan_top_right_compound(
1566 bw4: usize,1662 bw4: usize,
1567 ref_frame: (i8, i8),1663 ref_frame: (i8, i8),
1568 gm: &GmMvTable,1664 gm: &GmMvTable,
1569- candidates: &mut Vec<CompoundStackEntry>,1665+ candidates: &mut CompoundStackVec,
1570 newmv_count: &mut u32,1666 newmv_count: &mut u32,
1571 ) -> bool {1667 ) -> bool {
1572 let Some(row) = mi_row.checked_sub(1) else {1668 let Some(row) = mi_row.checked_sub(1) else {
@@ -1597,7 +1693,7 @@ fn scan_corner_compound(
1597 mi_col: usize,1693 mi_col: usize,
1598 ref_frame: (i8, i8),1694 ref_frame: (i8, i8),
1599 gm: &GmMvTable,1695 gm: &GmMvTable,
1600- candidates: &mut Vec<CompoundStackEntry>,1696+ candidates: &mut CompoundStackVec,
1601 newmv_count: &mut u32,1697 newmv_count: &mut u32,
1602 ) -> bool {1698 ) -> bool {
1603 let (Some(row), Some(col)) = (mi_row.checked_sub(1), mi_col.checked_sub(1)) else {1699 let (Some(row), Some(col)) = (mi_row.checked_sub(1), mi_col.checked_sub(1)) else {
@@ -1748,7 +1844,7 @@ pub fn find_mv_stack_compound(
1748 gm: &GmMvTable,1844 gm: &GmMvTable,
1749 tpl: Option<CompoundTplArgs>,1845 tpl: Option<CompoundTplArgs>,
1750 ) -> CompoundMvStack {1846 ) -> CompoundMvStack {
1751- let mut candidates: Vec<CompoundStackEntry> = Vec::with_capacity(MAX_STACK_SIZE);1847+ let mut candidates = CompoundStackVec::default();
1752 let mut newmv_count = 0u32;1848 let mut newmv_count = 0u32;
1753 1849
1754 let row_adj = bh4 < 2 && mi_row % 2 == 1;1850 let row_adj = bh4 < 2 && mi_row % 2 == 1;
@@ -1828,7 +1924,7 @@ pub fn find_mv_stack_compound(
1828 let row_matched = found_above || found_top_right;1924 let row_matched = found_above || found_top_right;
1829 let nearest_match = usize::from(row_matched) + usize::from(found_left);1925 let nearest_match = usize::from(row_matched) + usize::from(found_left);
1830 1926
1831- for entry in &mut candidates {1927+ for entry in candidates.iter_mut() {
1832 entry.weight += REF_CAT_LEVEL;1928 entry.weight += REF_CAT_LEVEL;
1833 }1929 }
1834 1930