forge
Explore
Log in

Don't you dare go Hollow

Merge branch 'lane-blockmem' (43f29bb0): skipped blocks describe themselves through the static zero residual instead of allocating zero grids, the all-zero marker skips the coefficient arena copy, recon op list keeps its capacity across superblocks, prediction buffers refilled in place; byte-exact, -1.6% instructions at the composed setting

Browse files at this commit

cb9db45b4f17fcb4025f189b132c54f116d9aa41Ahmet Kaan GümüşParent: afb2b38e1f00c9
crates/ec-av1/src/decode.rsmodified+137 -101
@@ -2149,6 +2149,12 @@ impl Residual {
21492149 /// A residual the parse thread already transformed, kept in the arena
21502150 /// instead of its own `Vec`.
21512151 fn done(residual: &[i32], fctx: &crate::decode::FrameCtx) -> Self {
2152+ // lane-blockmem: a skipped block hands over [`ZERO_RESIDUAL`] itself,
2153+ // which is exactly the all-zero marker -- one pointer compare instead
2154+ // of copying up to 64 KB of zeros into the arena per block.
2155+ if std::ptr::eq(residual.as_ptr(), ZERO_RESIDUAL.as_ptr()) {
2156+ return Self::Done(0, 0);
2157+ }
21522158 Self::Done(push_coeffs(residual, fctx), residual.len() as u32)
21532159 }
21542160
@@ -2269,7 +2275,11 @@ pub(crate) struct PredBuild(
22692275 &mut PlaneBuf<'static>,
22702276 &mut PlaneBuf<'static>,
22712277 &crate::decode::FrameCtx,
2272- ) -> [Vec<u16>; 3],
2278+ // lane-blockmem: the previous block's three prediction buffers,
2279+ // refilled in place -- the build used to return three fresh
2280+ // `Vec`s per block and drop these.
2281+ &mut [Vec<u16>; 3],
2282+ ),
22732283 >,
22742284 );
22752285
@@ -2284,6 +2294,21 @@ fn recon_deferred(fctx: &crate::decode::FrameCtx) -> bool {
22842294 fctx.recon_planes.with(std::cell::Cell::get).is_none()
22852295 }
22862296
2297+/// The previous block's prediction buffer, cleared and zero-filled to `n`
2298+/// (lane-blockmem): the same bytes the `vec![0u16; n]` it replaces produced,
2299+/// without the per-block allocation and free.
2300+fn refill(mut v: Vec<u16>, n: usize) -> Vec<u16> {
2301+ // A buffer that has to grow anyway is cheaper allocated zeroed (`calloc`)
2302+ // than resized element by element -- which is every block on the inline
2303+ // path, where there is no previous buffer to reuse.
2304+ if v.capacity() < n {
2305+ return vec![0u16; n];
2306+ }
2307+ v.clear();
2308+ v.resize(n, 0);
2309+ v
2310+}
2311+
22872312 /// Records one block's prediction build for the worker that reconstructs it.
22882313 #[allow(unsafe_code)]
22892314 fn push_pred<'a>(
@@ -2293,17 +2318,16 @@ fn push_pred<'a>(
22932318 &mut PlaneBuf<'static>,
22942319 &mut PlaneBuf<'static>,
22952320 &crate::decode::FrameCtx,
2296- ) -> [Vec<u16>; 3]
2297- + 'a,
2321+ &mut [Vec<u16>; 3],
2322+ ) + 'a,
22982323 ) {
2299- type Built = [Vec<u16>; 3];
23002324 type Dyn<'x> = dyn FnOnce(
23012325 &mut PlaneBuf<'static>,
23022326 &mut PlaneBuf<'static>,
23032327 &mut PlaneBuf<'static>,
23042328 &crate::decode::FrameCtx,
2305- ) -> Built
2306- + 'x;
2329+ &mut [Vec<u16>; 3],
2330+ ) + 'x;
23072331 let boxed: Box<Dyn<'a>> = Box::new(f);
23082332 // SAFETY: see [`PredBuild`] -- every worker is joined by [`WaveGuard`]
23092333 // before the borrows the closure holds go out of scope.
@@ -2717,7 +2741,15 @@ impl Drop for WaveGuard<'_> {
27172741 fn wave_submit(fctx: &crate::decode::FrameCtx, r: usize, c: usize) -> bool {
27182742 let st = fctx.wave.with(|w| w.borrow().clone());
27192743 let Some(st) = st else { return false };
2720- let ops = fctx.recon_ops.with(|c| std::mem::take(&mut *c.borrow_mut()));
2744+ // lane-blockmem: the op list is replaced sized for the next superblock,
2745+ // exactly as the two arenas below are -- taking it left a zero-capacity
2746+ // `Vec` that regrew (and memmoved every recorded op) from nothing on
2747+ // every superblock.
2748+ let ops = fctx.recon_ops.with(|c| {
2749+ let mut c = c.borrow_mut();
2750+ let cap = c.len();
2751+ std::mem::replace(&mut *c, Vec::with_capacity(cap))
2752+ });
27212753 // The job owns its coefficients: the arena is replaced by an empty one
27222754 // sized for the next superblock, so parse never regrows from nothing and
27232755 // the worker frees this buffer once, instead of once per unit.
@@ -3089,7 +3121,7 @@ fn exec_op(
30893121 ) {
30903122 let mut scratch = Vec::new();
30913123 match op {
3092- ReconOp::Pred(b) => *cur = (b.0)(y, u, v, fctx),
3124+ ReconOp::Pred(b) => (b.0)(y, u, v, fctx, cur),
30933125 ReconOp::Intra {
30943126 plane, x, y: oy, bw, bh, rect, mode, angle_delta, reach, residual, cfl,
30953127 filter_intra, smooth_neighbor, pred,
@@ -7345,7 +7377,7 @@ impl Neighbours {
73457377 side: usize,
73467378 mode: usize,
73477379 uv_mode: usize,
7348- grids: &[Vec<i32>; 3],
7380+ grids: &[&[i32]; 3],
73497381 ) {
73507382 self.record_rect(at, side, side, mode, uv_mode, grids);
73517383 }
@@ -7590,7 +7622,7 @@ impl Neighbours {
75907622 h: usize,
75917623 mode: usize,
75927624 uv_mode: usize,
7593- grids: &[Vec<i32>; 3],
7625+ grids: &[&[i32]; 3],
75947626 ) {
75957627 self.record_rect_mi(sub16_to_mi(at), w, h, mode, uv_mode, grids);
75967628 }
@@ -7607,7 +7639,7 @@ impl Neighbours {
76077639 h: usize,
76087640 mode: usize,
76097641 uv_mode: usize,
7610- grids: &[Vec<i32>; 3],
7642+ grids: &[&[i32]; 3],
76117643 ) {
76127644 let (r, c) = (at_mi.0 / (SUB / MI), at_mi.1 / (SUB / MI));
76137645 // lane-inter4 r2: a strip whose own footprint runs past the frame's
@@ -7638,7 +7670,7 @@ impl Neighbours {
76387670 /// position directly in 4x4 mode-info units rather than [`SUB`]-grid
76397671 /// `(r, c)`: an 8x8 leaf under a straddling 16x16 (lane-av1-rect) sits at
76407672 /// a mi offset [`Self::record`]'s SUB-unit `at` cannot name.
7641- fn record_mi(&mut self, at_mi: (usize, usize), side: usize, grids: &[Vec<i32>; 3]) {
7673+ fn record_mi(&mut self, at_mi: (usize, usize), side: usize, grids: &[&[i32]; 3]) {
76427674 self.record_mi_rect(at_mi, side, side, grids);
76437675 }
76447676
@@ -7649,10 +7681,10 @@ impl Neighbours {
76497681 at_mi: (usize, usize),
76507682 w: usize,
76517683 h: usize,
7652- grids: &[Vec<i32>; 3],
7684+ grids: &[&[i32]; 3],
76537685 ) {
76547686 let (mi_r, mi_c) = at_mi;
7655- let states: [Neighbour; 3] = std::array::from_fn(|plane| neighbour_state(&grids[plane]));
7687+ let states: [Neighbour; 3] = std::array::from_fn(|plane| neighbour_state(grids[plane]));
76567688 let (w_mi, h_mi) = (w / MI, h / MI);
76577689 if crate::envflags::env_flag!("EC_ECPUB") {
76587690 eprintln!("EC_ECPUB blk mi=({mi_r},{mi_c}) wh=({w},{h}) lvl={}", states[0].level);
@@ -10114,7 +10146,7 @@ fn decode_block_rect(
1011410146 mode,
1011510147 angle_delta_y,
1011610148 reach,
10117- &vec![0i32; bw * bh],
10149+ &ZERO_RESIDUAL[..bw * bh],
1011810150 None,
1011910151 filter_intra,
1012010152 smooth_neighbor, fctx,
@@ -10131,7 +10163,7 @@ fn decode_block_rect(
1013110163 uv_predict_mode,
1013210164 angle_delta_uv,
1013310165 reach,
10134- &vec![0i32; chroma_w * chroma_h],
10166+ &ZERO_RESIDUAL[..chroma_w * chroma_h],
1013510167 alpha.zip(ac).map(|((au, _), ac)| (au, ac)),
1013610168 None,
1013710169 smooth_neighbor_uv, fctx,
@@ -10147,7 +10179,7 @@ fn decode_block_rect(
1014710179 uv_predict_mode,
1014810180 angle_delta_uv,
1014910181 reach,
10150- &vec![0i32; chroma_w * chroma_h],
10182+ &ZERO_RESIDUAL[..chroma_w * chroma_h],
1015110183 alpha.zip(ac).map(|((_, av), ac)| (av, ac)),
1015210184 None,
1015310185 smooth_neighbor_uv, fctx,
@@ -10159,9 +10191,9 @@ fn decode_block_rect(
1015910191 mode,
1016010192 uv_predict_mode,
1016110193 &[
10162- vec![0i32; bw * bh],
10163- vec![0i32; chroma_w * chroma_h],
10164- vec![0i32; chroma_w * chroma_h],
10194+ &ZERO_RESIDUAL[..bw * bh],
10195+ &ZERO_RESIDUAL[..chroma_w * chroma_h],
10196+ &ZERO_RESIDUAL[..chroma_w * chroma_h],
1016510197 ],
1016610198 );
1016710199 } else {
@@ -10336,7 +10368,7 @@ fn decode_block_rect(
1033610368 None,
1033710369 smooth_neighbor_uv, fctx,
1033810370 );
10339- neighbours.record_rect(at, bw, bh, mode, uv_predict_mode, &[luma_levels, u_levels, v_levels]);
10371+ neighbours.record_rect(at, bw, bh, mode, uv_predict_mode, &[&luma_levels[..], &u_levels[..], &v_levels[..]]);
1034010372 RECT_COEFF_HITS.with(|c| c.set(c.get() + 1));
1034110373 }
1034210374 }
@@ -10675,7 +10707,7 @@ fn decode_leaf_rect(
1067510707 );
1067610708 RECT_LEAF_COEFF_HITS.with(|c| c.set(c.get() + 1));
1067710709 }
10678- neighbours.record_mi_rect(leaf_mi, bw, bh, &[luma_levels, u_levels, v_levels]);
10710+ neighbours.record_mi_rect(leaf_mi, bw, bh, &[&luma_levels[..], &u_levels[..], &v_levels[..]]);
1067910711 neighbours.fill_skip_grid_rect(leaf_mi, mi_w, mi_h, skip);
1068010712 neighbours.fill_lf_grid_rect(leaf_mi, mi_w, mi_h, bw as u8, bh as u8, 0, fctx);
1068110713 // The leaf's own palette state (`0` clears, as this site always did
@@ -11067,7 +11099,7 @@ fn decode_block_rect4(
1106711099 (mi_r, mi_c),
1106811100 bw,
1106911101 bh,
11070- &[luma_levels, u_levels, v_levels],
11102+ &[&luma_levels[..], &u_levels[..], &v_levels[..]],
1107111103 );
1107211104 neighbours.fill_skip_grid_rect((mi_r, mi_c), mi_w, mi_h, skip);
1107311105 neighbours.fill_lf_grid_rect((mi_r, mi_c), mi_w, mi_h, bw as u8, bh as u8, 0, fctx);
@@ -11138,7 +11170,7 @@ fn decode_block_rect4(
1113811170 None,
1113911171 smooth_neighbor_uv, fctx,
1114011172 );
11141- neighbours.record_mi_rect((mi_r, mi_c), bw, bh, &[luma_levels.to_vec(), u_levels, v_levels]);
11173+ neighbours.record_mi_rect((mi_r, mi_c), bw, bh, &[&luma_levels[..], &u_levels[..], &v_levels[..]]);
1114211174 neighbours.fill_skip_grid_rect((mi_r, mi_c), mi_w, mi_h, skip);
1114311175 neighbours.fill_lf_grid_rect((mi_r, mi_c), mi_w, mi_h, bw as u8, bh as u8, 0, fctx);
1114411176 record_strip_palette(
@@ -11983,7 +12015,7 @@ fn decode_block_rect64(
1198312015 mode,
1198412016 angle_delta_y,
1198512017 reach,
11986- &vec![0i32; bw * bh],
12018+ &ZERO_RESIDUAL[..bw * bh],
1198712019 None,
1198812020 filter_intra,
1198912021 smooth_neighbor, fctx,
@@ -12000,7 +12032,7 @@ fn decode_block_rect64(
1200012032 uv_predict_mode,
1200112033 angle_delta_uv,
1200212034 reach,
12003- &vec![0i32; chroma_w * chroma_h],
12035+ &ZERO_RESIDUAL[..chroma_w * chroma_h],
1200412036 alpha.zip(ac).map(|((au, _), ac)| (au, ac)),
1200512037 None,
1200612038 smooth_neighbor_uv, fctx,
@@ -12016,7 +12048,7 @@ fn decode_block_rect64(
1201612048 uv_predict_mode,
1201712049 angle_delta_uv,
1201812050 reach,
12019- &vec![0i32; chroma_w * chroma_h],
12051+ &ZERO_RESIDUAL[..chroma_w * chroma_h],
1202012052 alpha.zip(ac).map(|((_, av), ac)| (av, ac)),
1202112053 None,
1202212054 smooth_neighbor_uv, fctx,
@@ -12028,9 +12060,9 @@ fn decode_block_rect64(
1202812060 mode,
1202912061 uv_predict_mode,
1203012062 &[
12031- vec![0i32; bw * bh],
12032- vec![0i32; chroma_w * chroma_h],
12033- vec![0i32; chroma_w * chroma_h],
12063+ &ZERO_RESIDUAL[..bw * bh],
12064+ &ZERO_RESIDUAL[..chroma_w * chroma_h],
12065+ &ZERO_RESIDUAL[..chroma_w * chroma_h],
1203412066 ],
1203512067 );
1203612068 } else {
@@ -12277,7 +12309,7 @@ fn decode_block_rect64(
1227712309 None,
1227812310 smooth_neighbor_uv, fctx,
1227912311 );
12280- neighbours.record_rect(at, bw, bh, mode, uv_predict_mode, &[luma_levels, u_levels, v_levels]);
12312+ neighbours.record_rect(at, bw, bh, mode, uv_predict_mode, &[&luma_levels[..], &u_levels[..], &v_levels[..]]);
1228112313 RECT_COEFF_HITS.with(|c| c.set(c.get() + 1));
1228212314 }
1228312315 let (py_size, py_colors) = palette_y.as_ref().map_or((0, [0u16; 8]), |p| (p.size, p.colors));
@@ -13581,7 +13613,7 @@ fn decode_block(
1358113613 mode,
1358213614 angle_delta_y,
1358313615 tu_reach,
13584- &vec![0i32; logical_tx * logical_tx],
13616+ &ZERO_RESIDUAL[..logical_tx * logical_tx],
1358513617 None,
1358613618 filter_intra,
1358713619 smooth_neighbor, fctx,
@@ -13596,7 +13628,7 @@ fn decode_block(
1359613628 mode,
1359713629 angle_delta_y,
1359813630 reach,
13599- &vec![0i32; side * side],
13631+ &ZERO_RESIDUAL[..side * side],
1360013632 None,
1360113633 filter_intra,
1360213634 smooth_neighbor, fctx,
@@ -13627,7 +13659,7 @@ fn decode_block(
1362713659 uv_predict_mode,
1362813660 angle_delta_uv,
1362913661 cu_r,
13630- &vec![0i32; chroma_tx * chroma_tx],
13662+ &ZERO_RESIDUAL[..chroma_tx * chroma_tx],
1363113663 alpha.zip(ac).map(|((au, _), ac)| (au, ac)),
1363213664 None,
1363313665 smooth_neighbor_uv, fctx,
@@ -13642,7 +13674,7 @@ fn decode_block(
1364213674 uv_predict_mode,
1364313675 angle_delta_uv,
1364413676 cu_r,
13645- &vec![0i32; chroma_tx * chroma_tx],
13677+ &ZERO_RESIDUAL[..chroma_tx * chroma_tx],
1364613678 alpha.zip(ac).map(|((_, av), ac)| (av, ac)),
1364713679 None,
1364813680 smooth_neighbor_uv, fctx,
@@ -13652,7 +13684,7 @@ fn decode_block(
1365213684 let luma_grid = vec![0i32; side * side];
1365313685 let u_grid = vec![0i32; chroma_side * chroma_side];
1365413686 let v_grid = vec![0i32; chroma_side * chroma_side];
13655- neighbours.record(at, side, mode, uv_predict_mode, &[luma_grid, u_grid, v_grid]);
13687+ neighbours.record(at, side, mode, uv_predict_mode, &[&luma_grid[..], &u_grid[..], &v_grid[..]]);
1365613688 } else if logical_tx == side {
1365713689 // lane-sb128b r1: the test used to be `!tx_select || logical_tx == side`.
1365813690 // Without `tx_select` `logical_tx` IS `side` at every size <= 64, so
@@ -13749,7 +13781,7 @@ fn decode_block(
1374913781 smooth_neighbor_uv, fctx,
1375013782 )?;
1375113783 fctx.intrabc_chroma_tx.with(|c| c.set(None));
13752- neighbours.record(at, side, mode, uv_predict_mode, &[luma_grid, u_grid, v_grid]);
13784+ neighbours.record(at, side, mode, uv_predict_mode, &[&luma_grid[..], &u_grid[..], &v_grid[..]]);
1375313785 } else {
1375413786 // Several luma transform units, raster order (spec
1375513787 // `transform_block`'s loop): the block's resolved transform is
@@ -14267,9 +14299,9 @@ fn decode_block_128rect(
1426714299 mode,
1426814300 uv_predict_mode,
1426914301 &[
14270- vec![0i32; bw * bh],
14271- vec![0i32; chroma_w * chroma_h],
14272- vec![0i32; chroma_w * chroma_h],
14302+ &ZERO_RESIDUAL[..bw * bh],
14303+ &ZERO_RESIDUAL[..chroma_w * chroma_h],
14304+ &ZERO_RESIDUAL[..chroma_w * chroma_h],
1427314305 ],
1427414306 );
1427514307 } else {
@@ -14598,7 +14630,7 @@ fn decode_leaf8(
1459814630 mode,
1459914631 angle_delta_y,
1460014632 tu_reach,
14601- &vec![0i32; 16],
14633+ &ZERO_RESIDUAL[..16],
1460214634 None,
1460314635 filter_intra,
1460414636 smooth_neighbor, fctx,
@@ -14616,7 +14648,7 @@ fn decode_leaf8(
1461614648 mode,
1461714649 angle_delta_y,
1461814650 reach,
14619- &vec![0i32; 64],
14651+ &ZERO_RESIDUAL[..64],
1462014652 None,
1462114653 filter_intra,
1462214654 smooth_neighbor, fctx,
@@ -14635,7 +14667,7 @@ fn decode_leaf8(
1463514667 uv_predict_mode,
1463614668 angle_delta_uv,
1463714669 reach,
14638- &vec![0i32; 16],
14670+ &ZERO_RESIDUAL[..16],
1463914671 alpha.zip(ac).map(|((au, _), ac)| (au, ac)),
1464014672 None,
1464114673 smooth_neighbor_uv, fctx,
@@ -14652,7 +14684,7 @@ fn decode_leaf8(
1465214684 uv_predict_mode,
1465314685 angle_delta_uv,
1465414686 reach,
14655- &vec![0i32; 16],
14687+ &ZERO_RESIDUAL[..16],
1465614688 alpha.zip(ac).map(|((_, av), ac)| (av, ac)),
1465714689 None,
1465814690 smooth_neighbor_uv, fctx,
@@ -14938,7 +14970,7 @@ fn decode_leaf8(
1493814970 record_intrabc_mi(leaf_mi.0, leaf_mi.1, 2, intrabc_dv, fctx);
1493914971 return Ok(mode);
1494014972 }
14941- neighbours.record_mi(leaf_mi, 8, &[luma_grid, u_grid, v_grid]);
14973+ neighbours.record_mi(leaf_mi, 8, &[&luma_grid[..], &u_grid[..], &v_grid[..]]);
1494214974 // This leaf's own palette state into the mi-granular above/left bands
1494314975 // (sizes 0 when it used none, which is what clears a previous block's
1494414976 // palette out of the next block's ctx and colour cache).
@@ -15149,8 +15181,8 @@ fn decode_leaf_split4(
1514915181 let (px, py) = (lmi.1 * MI, lmi.0 * MI);
1515015182 let reach = Reach::of(4, px, py, y.width, y.height, fctx);
1515115183 if skip {
15152- push_intra(0, px, py, 4, mode, angle_delta_y, reach, &vec![0i32; 16], None, filter_intra, smooth_neighbor, fctx);
15153- neighbours.record_mi_luma(lmi, 4, &vec![0i32; 16]);
15184+ push_intra(0, px, py, 4, mode, angle_delta_y, reach, &ZERO_RESIDUAL[..16], None, filter_intra, smooth_neighbor, fctx);
15185+ neighbours.record_mi_luma(lmi, 4, &ZERO_RESIDUAL[..16]);
1515415186 } else {
1515515187 let tu_around = neighbours.around_mi(lmi, 4)[0];
1515615188 // A `BLOCK_4X4` leaf's luma TU *is* the whole block, so libaom's
@@ -15211,8 +15243,8 @@ fn decode_leaf_split4(
1521115243 CHROMA_SKIP_CFL_HITS.with(|h| h.set(h.get() + 1));
1521215244 SKIP_CFL_HITS.with(|c| c.set(c.get() + 1));
1521315245 }
15214- push_intra(1, cpx, cpy, 4, uv_predict_mode, angle_delta_uv, group_reach, &vec![0i32; 16], alpha.zip(ac).map(|((au, _), ac)| (au, ac)), None, smooth_neighbor_uv, fctx);
15215- push_intra(2, cpx, cpy, 4, uv_predict_mode, angle_delta_uv, group_reach, &vec![0i32; 16], alpha.zip(ac).map(|((_, av), ac)| (av, ac)), None, smooth_neighbor_uv, fctx);
15246+ push_intra(1, cpx, cpy, 4, uv_predict_mode, angle_delta_uv, group_reach, &ZERO_RESIDUAL[..16], alpha.zip(ac).map(|((au, _), ac)| (au, ac)), None, smooth_neighbor_uv, fctx);
15247+ push_intra(2, cpx, cpy, 4, uv_predict_mode, angle_delta_uv, group_reach, &ZERO_RESIDUAL[..16], alpha.zip(ac).map(|((_, av), ac)| (av, ac)), None, smooth_neighbor_uv, fctx);
1521615248 (vec![0i32; 16], vec![0i32; 16])
1521715249 } else {
1521815250 let ac = alpha.map(|_| cfl_src(gpx, gpy, 8));
@@ -15583,8 +15615,8 @@ fn decode_leaf_rect8(
1558315615 CHROMA_SKIP_CFL_HITS.with(|h| h.set(h.get() + 1));
1558415616 SKIP_CFL_HITS.with(|c| c.set(c.get() + 1));
1558515617 }
15586- push_intra(1, cpx, cpy, 4, uv_predict_mode, angle_delta_uv, group_reach, &vec![0i32; 16], alpha.zip(ac).map(|((au, _), ac)| (au, ac)), None, smooth_neighbor_uv, fctx);
15587- push_intra(2, cpx, cpy, 4, uv_predict_mode, angle_delta_uv, group_reach, &vec![0i32; 16], alpha.zip(ac).map(|((_, av), ac)| (av, ac)), None, smooth_neighbor_uv, fctx);
15618+ push_intra(1, cpx, cpy, 4, uv_predict_mode, angle_delta_uv, group_reach, &ZERO_RESIDUAL[..16], alpha.zip(ac).map(|((au, _), ac)| (au, ac)), None, smooth_neighbor_uv, fctx);
15619+ push_intra(2, cpx, cpy, 4, uv_predict_mode, angle_delta_uv, group_reach, &ZERO_RESIDUAL[..16], alpha.zip(ac).map(|((_, av), ac)| (av, ac)), None, smooth_neighbor_uv, fctx);
1558815620 (vec![0i32; 16], vec![0i32; 16])
1558915621 } else {
1559015622 let ac = alpha.map(|_| cfl_src(gpx, gpy, 8));
@@ -24694,8 +24726,8 @@ fn decode_inter_block(
2469424726 let build = move |_y: &mut PlaneBuf<'static>,
2469524727 _u: &mut PlaneBuf<'static>,
2469624728 _v: &mut PlaneBuf<'static>,
24697- fctx: &crate::decode::FrameCtx|
24698- -> [Vec<u16>; 3] {
24729+ fctx: &crate::decode::FrameCtx,
24730+ out: &mut [Vec<u16>; 3]| {
2469924731 let mut inter0_y = vec![0i32; side * side];
2470024732 mc::predict_compound_intermediate_kern(
2470124733 &py0.data,
@@ -24750,7 +24782,7 @@ fn decode_inter_block(
2475024782 side as i32, side as i32, 0, 0, fctx,
2475124783 );
2475224784 }
24753- let mut pred_y = vec![0u16; side * side];
24785+ let mut pred_y = refill(std::mem::take(&mut out[0]), side * side);
2475424786 let mut diffwtd_mask_y;
2475524787 // lane-wedge r3: `mask_y` is the DIFFWTD buffer just computed OR
2475624788 // the wedge codebook lookup (comp_group_idx==1's two mutually
@@ -24830,7 +24862,7 @@ fn decode_inter_block(
2483024862 );
2483124863 }
2483224864 }
24833- let mut pred_u = vec![0u16; chroma_side * chroma_side];
24865+ let mut pred_u = refill(std::mem::take(&mut out[1]), chroma_side * chroma_side);
2483424866 if let Some(mask_y) = mask_y {
2483524867 mc::blend_masked_compound(
2483624868 &inter0_u,
@@ -24904,7 +24936,7 @@ fn decode_inter_block(
2490424936 );
2490524937 }
2490624938 }
24907- let mut pred_v = vec![0u16; chroma_side * chroma_side];
24939+ let mut pred_v = refill(std::mem::take(&mut out[2]), chroma_side * chroma_side);
2490824940 if let Some(mask_y) = mask_y {
2490924941 mc::blend_masked_compound(
2491024942 &inter0_v,
@@ -24922,7 +24954,7 @@ fn decode_inter_block(
2492224954
2492324955 // lane-inter4 r2: a rectangular strip's transform tree starts from
2492424956 // its own rect `max_txsize_rect_lookup` entry, not a square one.
24925- [pred_y, pred_u, pred_v]
24957+ *out = [pred_y, pred_u, pred_v];
2492624958 };
2492724959 let (pred_y, pred_u, pred_v): (Vec<u16>, Vec<u16>, Vec<u16>);
2492824960 let (sy, su, sv) = if recon_deferred(fctx) {
@@ -24933,7 +24965,9 @@ fn decode_inter_block(
2493324965 Pred::Cur { plane: 2, stride: chroma_side, off: 0 },
2493424966 )
2493524967 } else {
24936- let [by, bu, bv] = build(y, u, v, fctx);
24968+ let mut built: [Vec<u16>; 3] = Default::default();
24969+ build(y, u, v, fctx, &mut built);
24970+ let [by, bu, bv] = built;
2493724971 (pred_y, pred_u, pred_v) = (by, bu, bv);
2493824972 (
2493924973 Pred::Inline(&pred_y, side),
@@ -24974,7 +25008,7 @@ fn decode_inter_block(
2497425008 write_w,
2497525009 write_h,
2497625010 sy,
24977- &vec![0i32; side * side], fctx,
25011+ &ZERO_RESIDUAL[..side * side], fctx,
2497825012 );
2497925013 push_mc_rect(1,
2498025014 cpx,
@@ -24983,7 +25017,7 @@ fn decode_inter_block(
2498325017 write_chroma_w,
2498425018 write_chroma_h,
2498525019 su,
24986- &vec![0i32; chroma_side * chroma_side], fctx,
25020+ &ZERO_RESIDUAL[..chroma_side * chroma_side], fctx,
2498725021 );
2498825022 push_mc_rect(2,
2498925023 cpx,
@@ -24992,7 +25026,7 @@ fn decode_inter_block(
2499225026 write_chroma_w,
2499325027 write_chroma_h,
2499425028 sv,
24995- &vec![0i32; chroma_side * chroma_side], fctx,
25029+ &ZERO_RESIDUAL[..chroma_side * chroma_side], fctx,
2499625030 );
2499725031 luma_grid = vec![0i32; side * side];
2499825032 u_grid = vec![0i32; chroma_side * chroma_side];
@@ -25916,11 +25950,11 @@ fn decode_inter_block(
2591625950 let build = move |y: &mut PlaneBuf<'static>,
2591725951 u: &mut PlaneBuf<'static>,
2591825952 v: &mut PlaneBuf<'static>,
25919- fctx: &crate::decode::FrameCtx|
25920- -> [Vec<u16>; 3] {
25921- let mut pred_y = vec![0u16; side * side];
25922- let mut pred_u = vec![0u16; chroma_side * chroma_side];
25923- let mut pred_v = vec![0u16; chroma_side * chroma_side];
25953+ fctx: &crate::decode::FrameCtx,
25954+ out: &mut [Vec<u16>; 3]| {
25955+ let mut pred_y = refill(std::mem::take(&mut out[0]), side * side);
25956+ let mut pred_u = refill(std::mem::take(&mut out[1]), chroma_side * chroma_side);
25957+ let mut pred_v = refill(std::mem::take(&mut out[2]), chroma_side * chroma_side);
2592425958 if luma_scale == mc::REF_NO_SCALE {
2592525959 mc::predict_with_filters_kern(
2592625960 &py_ref.data,
@@ -26077,7 +26111,7 @@ fn decode_inter_block(
2607726111 &mut pred_v, fctx,
2607826112 );
2607926113 }
26080- [pred_y, pred_u, pred_v]
26114+ *out = [pred_y, pred_u, pred_v];
2608126115 };
2608226116 // OBMC and interintra are mutually exclusive (`motion_mode` is
2608326117 // never read for an interintra block), so blending interintra
@@ -26102,7 +26136,9 @@ fn decode_inter_block(
2610226136 if interintra_mode.is_some() {
2610326137 flush_recon(fctx, y, u, v);
2610426138 }
26105- let [by, bu, bv] = build(y, u, v, fctx);
26139+ let mut built: [Vec<u16>; 3] = Default::default();
26140+ build(y, u, v, fctx, &mut built);
26141+ let [by, bu, bv] = built;
2610626142 (pred_y, pred_u, pred_v) = (by, bu, bv);
2610726143 if obmc_selected {
2610826144 obmc_blend(
@@ -26221,7 +26257,7 @@ fn decode_inter_block(
2622126257 write_w,
2622226258 write_h,
2622326259 sy,
26224- &vec![0i32; side * side], fctx,
26260+ &ZERO_RESIDUAL[..side * side], fctx,
2622526261 );
2622626262 if has_chroma {
2622726263 push_mc_rect(1,
@@ -26231,7 +26267,7 @@ fn decode_inter_block(
2623126267 write_chroma_w,
2623226268 write_chroma_h,
2623326269 su,
26234- &vec![0i32; chroma_side * chroma_side], fctx,
26270+ &ZERO_RESIDUAL[..chroma_side * chroma_side], fctx,
2623526271 );
2623626272 push_mc_rect(2,
2623726273 cpx,
@@ -26240,7 +26276,7 @@ fn decode_inter_block(
2624026276 write_chroma_w,
2624126277 write_chroma_h,
2624226278 sv,
26243- &vec![0i32; chroma_side * chroma_side], fctx,
26279+ &ZERO_RESIDUAL[..chroma_side * chroma_side], fctx,
2624426280 );
2624526281 }
2624626282 luma_grid = vec![0i32; side * side];
@@ -26971,7 +27007,7 @@ fn decode_inter_block(
2697127007 mode,
2697227008 angle_delta_y,
2697327009 tu_reach,
26974- &vec![0i32; tx_px * tx_px],
27010+ &ZERO_RESIDUAL[..tx_px * tx_px],
2697527011 None,
2697627012 filter_intra,
2697727013 smooth_neighbor, fctx,
@@ -27041,7 +27077,7 @@ fn decode_inter_block(
2704127077 uv_predict_mode,
2704227078 angle_delta_uv,
2704327079 cu_reach,
27044- &vec![0i32; cu_tx * cu_tx],
27080+ &ZERO_RESIDUAL[..cu_tx * cu_tx],
2704527081 None,
2704627082 None,
2704727083 smooth_neighbor_uv, fctx,
@@ -27111,7 +27147,7 @@ fn decode_inter_block(
2711127147 mode,
2711227148 angle_delta_y,
2711327149 reach,
27114- &vec![0i32; side * side],
27150+ &ZERO_RESIDUAL[..side * side],
2711527151 None,
2711627152 filter_intra,
2711727153 smooth_neighbor, fctx,
@@ -27128,7 +27164,7 @@ fn decode_inter_block(
2712827164 uv_predict_mode,
2712927165 angle_delta_uv,
2713027166 reach,
27131- &vec![0i32; chroma_side * chroma_side],
27167+ &ZERO_RESIDUAL[..chroma_side * chroma_side],
2713227168 alpha.zip(ac).map(|((au, _), ac)| (au, ac)),
2713327169 None,
2713427170 smooth_neighbor_uv, fctx,
@@ -27143,7 +27179,7 @@ fn decode_inter_block(
2714327179 uv_predict_mode,
2714427180 angle_delta_uv,
2714527181 reach,
27146- &vec![0i32; chroma_side * chroma_side],
27182+ &ZERO_RESIDUAL[..chroma_side * chroma_side],
2714727183 alpha.zip(ac).map(|((_, av), ac)| (av, ac)),
2714827184 None,
2714927185 smooth_neighbor_uv, fctx,
@@ -27373,7 +27409,7 @@ fn decode_inter_block(
2737327409 write_h,
2737427410 mode_for_tx,
2737527411 uv_predict_mode,
27376- &[luma_grid, u_grid, v_grid],
27412+ &[&luma_grid[..], &u_grid[..], &v_grid[..]],
2737727413 );
2737827414 }
2737927415 if let Some((left, above)) = saved_chroma_ctx {
@@ -27842,8 +27878,8 @@ fn decode_inter_sub8_split4(
2784227878 // txsize_to_bsize[tx_size]` branch (`txb_skip_ctx = 0`, which
2784327879 // `read_inter_plane`'s `plane_idx == 0` arm already assumes).
2784427880 if skip {
27845- push_mc(0, px, py, B4, Pred::dense(&pred_y), &vec![0i32; B4 * B4], fctx);
27846- neighbours.record_mi_luma_rect(lmi, B4, B4, &vec![0i32; B4 * B4]);
27881+ push_mc(0, px, py, B4, Pred::dense(&pred_y), &ZERO_RESIDUAL[..B4 * B4], fctx);
27882+ neighbours.record_mi_luma_rect(lmi, B4, B4, &ZERO_RESIDUAL[..B4 * B4]);
2784727883 } else {
2784827884 let around = neighbours.around_mi(lmi, B4);
2784927885 let (luma_grid, tx_type) = read_inter_plane(
@@ -27957,8 +27993,8 @@ fn decode_inter_sub8_split4(
2795727993 }
2795827994 }
2795927995 let (u_grid, v_grid) = if last_skip {
27960- push_mc(1, cpx, cpy, B4, Pred::dense(&pred_u), &vec![0i32; B4 * B4], fctx);
27961- push_mc(2, cpx, cpy, B4, Pred::dense(&pred_v), &vec![0i32; B4 * B4], fctx);
27996+ push_mc(1, cpx, cpy, B4, Pred::dense(&pred_u), &ZERO_RESIDUAL[..B4 * B4], fctx);
27997+ push_mc(2, cpx, cpy, B4, Pred::dense(&pred_v), &ZERO_RESIDUAL[..B4 * B4], fctx);
2796227998 (vec![0i32; B4 * B4], vec![0i32; B4 * B4])
2796327999 } else {
2796428000 let around = neighbours.around_mi(group_mi, 8);
@@ -28230,10 +28266,10 @@ fn decode_intra_sub8_leaf(
2823028266 // reader [`decode_leaf_split4`] uses.
2823128267 if skip {
2823228268 push_intra(0,
28233- px, py, 4, mode, angle_delta_y, reach, &vec![0i32; 16], None, filter_intra,
28269+ px, py, 4, mode, angle_delta_y, reach, &ZERO_RESIDUAL[..16], None, filter_intra,
2823428270 smooth_neighbor, fctx,
2823528271 );
28236- neighbours.record_mi_luma(lmi, 4, &vec![0i32; 16]);
28272+ neighbours.record_mi_luma(lmi, 4, &ZERO_RESIDUAL[..16]);
2823728273 } else {
2823828274 let tu_around = neighbours.around_mi(lmi, 4)[0];
2823928275 let tu_grid = read_plane(
@@ -28401,8 +28437,8 @@ fn decode_intra_sub8_leaf(
2840128437 CHROMA_SKIP_CFL_HITS.with(|h| h.set(h.get() + 1));
2840228438 SKIP_CFL_HITS.with(|c| c.set(c.get() + 1));
2840328439 }
28404- push_intra(1, cpx, cpy, 4, uv_predict_mode, angle_delta_uv, group_reach, &vec![0i32; 16], alpha.zip(ac).map(|((au, _), ac)| (au, ac)), None, smooth_neighbor_uv, fctx);
28405- push_intra(2, cpx, cpy, 4, uv_predict_mode, angle_delta_uv, group_reach, &vec![0i32; 16], alpha.zip(ac).map(|((_, av), ac)| (av, ac)), None, smooth_neighbor_uv, fctx);
28440+ push_intra(1, cpx, cpy, 4, uv_predict_mode, angle_delta_uv, group_reach, &ZERO_RESIDUAL[..16], alpha.zip(ac).map(|((au, _), ac)| (au, ac)), None, smooth_neighbor_uv, fctx);
28441+ push_intra(2, cpx, cpy, 4, uv_predict_mode, angle_delta_uv, group_reach, &ZERO_RESIDUAL[..16], alpha.zip(ac).map(|((_, av), ac)| (av, ac)), None, smooth_neighbor_uv, fctx);
2840628442 (vec![0i32; 16], vec![0i32; 16])
2840728443 } else {
2840828444 let chroma_around = neighbours.around_mi(group_mi, 8);
@@ -28813,8 +28849,8 @@ fn decode_inter_sub8_rect2(
2881328849 }
2881428850 }
2881528851 if skip {
28816- push_mc_rect(0, px, py, SIDE, bw, bh, Pred::dense(&pred_y), &vec![0i32; SIDE * SIDE], fctx);
28817- neighbours.record_mi_luma_rect(lmi, bw, bh, &vec![0i32; bw * bh]);
28852+ push_mc_rect(0, px, py, SIDE, bw, bh, Pred::dense(&pred_y), &ZERO_RESIDUAL[..SIDE * SIDE], fctx);
28853+ neighbours.record_mi_luma_rect(lmi, bw, bh, &ZERO_RESIDUAL[..bw * bh]);
2881828854 neighbours.fill_lf_grid_rect(lmi, w_mi, h_mi, bw as u8, bh as u8, ref_frame.max(LAST_FRAME), fctx);
2881928855 } else {
2882028856 let (mut last_tw, mut last_th) = (bw, bh);
@@ -28979,8 +29015,8 @@ fn decode_inter_sub8_rect2(
2897929015 }
2898029016 }
2898129017 let (u_grid, v_grid) = if last_skip {
28982- push_mc(1, cpx, cpy, B4, Pred::dense(&pred_u), &vec![0i32; B4 * B4], fctx);
28983- push_mc(2, cpx, cpy, B4, Pred::dense(&pred_v), &vec![0i32; B4 * B4], fctx);
29018+ push_mc(1, cpx, cpy, B4, Pred::dense(&pred_u), &ZERO_RESIDUAL[..B4 * B4], fctx);
29019+ push_mc(2, cpx, cpy, B4, Pred::dense(&pred_v), &ZERO_RESIDUAL[..B4 * B4], fctx);
2898429020 (vec![0i32; B4 * B4], vec![0i32; B4 * B4])
2898529021 } else {
2898629022 let around = neighbours.around_mi(group_mi, 8);
@@ -29812,20 +29848,20 @@ fn decode_inter_block8(
2981229848 .1
2981329849 .is_some();
2981429850 if skip {
29815- push_mc(0, px, py, SIDE, Pred::dense(&pred_y), &vec![0i32; SIDE * SIDE], fctx);
29851+ push_mc(0, px, py, SIDE, Pred::dense(&pred_y), &ZERO_RESIDUAL[..SIDE * SIDE], fctx);
2981629852 push_mc(1,
2981729853 cpx,
2981829854 cpy,
2981929855 CHROMA_SIDE,
2982029856 Pred::dense(&pred_u),
29821- &vec![0i32; CHROMA_SIDE * CHROMA_SIDE], fctx,
29857+ &ZERO_RESIDUAL[..CHROMA_SIDE * CHROMA_SIDE], fctx,
2982229858 );
2982329859 push_mc(2,
2982429860 cpx,
2982529861 cpy,
2982629862 CHROMA_SIDE,
2982729863 Pred::dense(&pred_v),
29828- &vec![0i32; CHROMA_SIDE * CHROMA_SIDE], fctx,
29864+ &ZERO_RESIDUAL[..CHROMA_SIDE * CHROMA_SIDE], fctx,
2982929865 );
2983029866 luma_grid = vec![0i32; SIDE * SIDE];
2983129867 u_grid = vec![0i32; CHROMA_SIDE * CHROMA_SIDE];
@@ -29931,7 +29967,7 @@ fn decode_inter_block8(
2993129967 palette_record8.2,
2993229968 palette_record8.3,
2993329969 );
29934- neighbours.record_mi(leaf_mi, 8, &[luma_grid, u_grid, v_grid]);
29970+ neighbours.record_mi(leaf_mi, 8, &[&luma_grid[..], &u_grid[..], &v_grid[..]]);
2993529971 if let Some((left, above)) = saved_luma_ctx {
2993629972 for (cell, state) in left.into_iter().enumerate() {
2993729973 neighbours.left[leaf_mi.0 + cell][0] = state;
@@ -30460,20 +30496,20 @@ fn decode_inter_block8(
3046030496 .1
3046130497 .is_some();
3046230498 if skip {
30463- push_mc(0, px, py, SIDE, Pred::dense(&pred_y), &vec![0i32; SIDE * SIDE], fctx);
30499+ push_mc(0, px, py, SIDE, Pred::dense(&pred_y), &ZERO_RESIDUAL[..SIDE * SIDE], fctx);
3046430500 push_mc(1,
3046530501 cpx,
3046630502 cpy,
3046730503 CHROMA_SIDE,
3046830504 Pred::dense(&pred_u),
30469- &vec![0i32; CHROMA_SIDE * CHROMA_SIDE], fctx,
30505+ &ZERO_RESIDUAL[..CHROMA_SIDE * CHROMA_SIDE], fctx,
3047030506 );
3047130507 push_mc(2,
3047230508 cpx,
3047330509 cpy,
3047430510 CHROMA_SIDE,
3047530511 Pred::dense(&pred_v),
30476- &vec![0i32; CHROMA_SIDE * CHROMA_SIDE], fctx,
30512+ &ZERO_RESIDUAL[..CHROMA_SIDE * CHROMA_SIDE], fctx,
3047730513 );
3047830514 luma_grid = vec![0i32; SIDE * SIDE];
3047930515 u_grid = vec![0i32; CHROMA_SIDE * CHROMA_SIDE];
@@ -30836,7 +30872,7 @@ fn decode_inter_block8(
3083630872 mode,
3083730873 angle_delta_y,
3083830874 tu_reach,
30839- &vec![0i32; tx_px * tx_px],
30875+ &ZERO_RESIDUAL[..tx_px * tx_px],
3084030876 None,
3084130877 filter_intra,
3084230878 smooth_neighbor, fctx,
@@ -30889,7 +30925,7 @@ fn decode_inter_block8(
3088930925 mode,
3089030926 angle_delta_y,
3089130927 reach,
30892- &vec![0i32; SIDE * SIDE],
30928+ &ZERO_RESIDUAL[..SIDE * SIDE],
3089330929 None,
3089430930 filter_intra,
3089530931 smooth_neighbor, fctx,
@@ -30908,7 +30944,7 @@ fn decode_inter_block8(
3090830944 uv_predict_mode,
3090930945 angle_delta_uv,
3091030946 reach,
30911- &vec![0i32; CHROMA_SIDE * CHROMA_SIDE],
30947+ &ZERO_RESIDUAL[..CHROMA_SIDE * CHROMA_SIDE],
3091230948 alpha.zip(ac).map(|((au, _), ac)| (au, ac)),
3091330949 None,
3091430950 smooth_neighbor_uv, fctx,
@@ -30923,7 +30959,7 @@ fn decode_inter_block8(
3092330959 uv_predict_mode,
3092430960 angle_delta_uv,
3092530961 reach,
30926- &vec![0i32; CHROMA_SIDE * CHROMA_SIDE],
30962+ &ZERO_RESIDUAL[..CHROMA_SIDE * CHROMA_SIDE],
3092730963 alpha.zip(ac).map(|((_, av), ac)| (av, ac)),
3092830964 None,
3092930965 smooth_neighbor_uv, fctx,
@@ -31058,7 +31094,7 @@ fn decode_inter_block8(
3105831094 palette_record8.2,
3105931095 palette_record8.3,
3106031096 );
31061- neighbours.record_mi(leaf_mi, 8, &[luma_grid, u_grid, v_grid]);
31097+ neighbours.record_mi(leaf_mi, 8, &[&luma_grid[..], &u_grid[..], &v_grid[..]]);
3106231098 // lane-uv8 r1: this leaf never stamped a mode band at all, so the block
3106331099 // below/right of it read whatever block last wrote the coarse [`SUB`]
3106431100 // slot -- now that an intra leaf here can code a smooth/directional