diff --git a/crates/ec-av1/src/decode.rs b/crates/ec-av1/src/decode.rs index d6ac7628..8f321536 100644 --- a/crates/ec-av1/src/decode.rs +++ b/crates/ec-av1/src/decode.rs @@ -2149,6 +2149,12 @@ impl Residual { /// A residual the parse thread already transformed, kept in the arena /// instead of its own `Vec`. fn done(residual: &[i32], fctx: &crate::decode::FrameCtx) -> Self { + // lane-blockmem: a skipped block hands over [`ZERO_RESIDUAL`] itself, + // which is exactly the all-zero marker -- one pointer compare instead + // of copying up to 64 KB of zeros into the arena per block. + if std::ptr::eq(residual.as_ptr(), ZERO_RESIDUAL.as_ptr()) { + return Self::Done(0, 0); + } Self::Done(push_coeffs(residual, fctx), residual.len() as u32) } @@ -2269,7 +2275,11 @@ pub(crate) struct PredBuild( &mut PlaneBuf<'static>, &mut PlaneBuf<'static>, &crate::decode::FrameCtx, - ) -> [Vec; 3], + // lane-blockmem: the previous block's three prediction buffers, + // refilled in place -- the build used to return three fresh + // `Vec`s per block and drop these. + &mut [Vec; 3], + ), >, ); @@ -2284,6 +2294,21 @@ fn recon_deferred(fctx: &crate::decode::FrameCtx) -> bool { fctx.recon_planes.with(std::cell::Cell::get).is_none() } +/// The previous block's prediction buffer, cleared and zero-filled to `n` +/// (lane-blockmem): the same bytes the `vec![0u16; n]` it replaces produced, +/// without the per-block allocation and free. +fn refill(mut v: Vec, n: usize) -> Vec { + // A buffer that has to grow anyway is cheaper allocated zeroed (`calloc`) + // than resized element by element -- which is every block on the inline + // path, where there is no previous buffer to reuse. + if v.capacity() < n { + return vec![0u16; n]; + } + v.clear(); + v.resize(n, 0); + v +} + /// Records one block's prediction build for the worker that reconstructs it. #[allow(unsafe_code)] fn push_pred<'a>( @@ -2293,17 +2318,16 @@ fn push_pred<'a>( &mut PlaneBuf<'static>, &mut PlaneBuf<'static>, &crate::decode::FrameCtx, - ) -> [Vec; 3] - + 'a, + &mut [Vec; 3], + ) + 'a, ) { - type Built = [Vec; 3]; type Dyn<'x> = dyn FnOnce( &mut PlaneBuf<'static>, &mut PlaneBuf<'static>, &mut PlaneBuf<'static>, &crate::decode::FrameCtx, - ) -> Built - + 'x; + &mut [Vec; 3], + ) + 'x; let boxed: Box> = Box::new(f); // SAFETY: see [`PredBuild`] -- every worker is joined by [`WaveGuard`] // before the borrows the closure holds go out of scope. @@ -2717,7 +2741,15 @@ impl Drop for WaveGuard<'_> { fn wave_submit(fctx: &crate::decode::FrameCtx, r: usize, c: usize) -> bool { let st = fctx.wave.with(|w| w.borrow().clone()); let Some(st) = st else { return false }; - let ops = fctx.recon_ops.with(|c| std::mem::take(&mut *c.borrow_mut())); + // lane-blockmem: the op list is replaced sized for the next superblock, + // exactly as the two arenas below are -- taking it left a zero-capacity + // `Vec` that regrew (and memmoved every recorded op) from nothing on + // every superblock. + let ops = fctx.recon_ops.with(|c| { + let mut c = c.borrow_mut(); + let cap = c.len(); + std::mem::replace(&mut *c, Vec::with_capacity(cap)) + }); // The job owns its coefficients: the arena is replaced by an empty one // sized for the next superblock, so parse never regrows from nothing and // the worker frees this buffer once, instead of once per unit. @@ -3089,7 +3121,7 @@ fn exec_op( ) { let mut scratch = Vec::new(); match op { - ReconOp::Pred(b) => *cur = (b.0)(y, u, v, fctx), + ReconOp::Pred(b) => (b.0)(y, u, v, fctx, cur), ReconOp::Intra { plane, x, y: oy, bw, bh, rect, mode, angle_delta, reach, residual, cfl, filter_intra, smooth_neighbor, pred, @@ -7345,7 +7377,7 @@ impl Neighbours { side: usize, mode: usize, uv_mode: usize, - grids: &[Vec; 3], + grids: &[&[i32]; 3], ) { self.record_rect(at, side, side, mode, uv_mode, grids); } @@ -7590,7 +7622,7 @@ impl Neighbours { h: usize, mode: usize, uv_mode: usize, - grids: &[Vec; 3], + grids: &[&[i32]; 3], ) { self.record_rect_mi(sub16_to_mi(at), w, h, mode, uv_mode, grids); } @@ -7607,7 +7639,7 @@ impl Neighbours { h: usize, mode: usize, uv_mode: usize, - grids: &[Vec; 3], + grids: &[&[i32]; 3], ) { let (r, c) = (at_mi.0 / (SUB / MI), at_mi.1 / (SUB / MI)); // lane-inter4 r2: a strip whose own footprint runs past the frame's @@ -7638,7 +7670,7 @@ impl Neighbours { /// position directly in 4x4 mode-info units rather than [`SUB`]-grid /// `(r, c)`: an 8x8 leaf under a straddling 16x16 (lane-av1-rect) sits at /// a mi offset [`Self::record`]'s SUB-unit `at` cannot name. - fn record_mi(&mut self, at_mi: (usize, usize), side: usize, grids: &[Vec; 3]) { + fn record_mi(&mut self, at_mi: (usize, usize), side: usize, grids: &[&[i32]; 3]) { self.record_mi_rect(at_mi, side, side, grids); } @@ -7649,10 +7681,10 @@ impl Neighbours { at_mi: (usize, usize), w: usize, h: usize, - grids: &[Vec; 3], + grids: &[&[i32]; 3], ) { let (mi_r, mi_c) = at_mi; - let states: [Neighbour; 3] = std::array::from_fn(|plane| neighbour_state(&grids[plane])); + let states: [Neighbour; 3] = std::array::from_fn(|plane| neighbour_state(grids[plane])); let (w_mi, h_mi) = (w / MI, h / MI); if crate::envflags::env_flag!("EC_ECPUB") { eprintln!("EC_ECPUB blk mi=({mi_r},{mi_c}) wh=({w},{h}) lvl={}", states[0].level); @@ -10114,7 +10146,7 @@ fn decode_block_rect( mode, angle_delta_y, reach, - &vec![0i32; bw * bh], + &ZERO_RESIDUAL[..bw * bh], None, filter_intra, smooth_neighbor, fctx, @@ -10131,7 +10163,7 @@ fn decode_block_rect( uv_predict_mode, angle_delta_uv, reach, - &vec![0i32; chroma_w * chroma_h], + &ZERO_RESIDUAL[..chroma_w * chroma_h], alpha.zip(ac).map(|((au, _), ac)| (au, ac)), None, smooth_neighbor_uv, fctx, @@ -10147,7 +10179,7 @@ fn decode_block_rect( uv_predict_mode, angle_delta_uv, reach, - &vec![0i32; chroma_w * chroma_h], + &ZERO_RESIDUAL[..chroma_w * chroma_h], alpha.zip(ac).map(|((_, av), ac)| (av, ac)), None, smooth_neighbor_uv, fctx, @@ -10159,9 +10191,9 @@ fn decode_block_rect( mode, uv_predict_mode, &[ - vec![0i32; bw * bh], - vec![0i32; chroma_w * chroma_h], - vec![0i32; chroma_w * chroma_h], + &ZERO_RESIDUAL[..bw * bh], + &ZERO_RESIDUAL[..chroma_w * chroma_h], + &ZERO_RESIDUAL[..chroma_w * chroma_h], ], ); } else { @@ -10336,7 +10368,7 @@ fn decode_block_rect( None, smooth_neighbor_uv, fctx, ); - neighbours.record_rect(at, bw, bh, mode, uv_predict_mode, &[luma_levels, u_levels, v_levels]); + neighbours.record_rect(at, bw, bh, mode, uv_predict_mode, &[&luma_levels[..], &u_levels[..], &v_levels[..]]); RECT_COEFF_HITS.with(|c| c.set(c.get() + 1)); } } @@ -10675,7 +10707,7 @@ fn decode_leaf_rect( ); RECT_LEAF_COEFF_HITS.with(|c| c.set(c.get() + 1)); } - neighbours.record_mi_rect(leaf_mi, bw, bh, &[luma_levels, u_levels, v_levels]); + neighbours.record_mi_rect(leaf_mi, bw, bh, &[&luma_levels[..], &u_levels[..], &v_levels[..]]); neighbours.fill_skip_grid_rect(leaf_mi, mi_w, mi_h, skip); neighbours.fill_lf_grid_rect(leaf_mi, mi_w, mi_h, bw as u8, bh as u8, 0, fctx); // The leaf's own palette state (`0` clears, as this site always did @@ -11067,7 +11099,7 @@ fn decode_block_rect4( (mi_r, mi_c), bw, bh, - &[luma_levels, u_levels, v_levels], + &[&luma_levels[..], &u_levels[..], &v_levels[..]], ); neighbours.fill_skip_grid_rect((mi_r, mi_c), mi_w, mi_h, skip); 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( None, smooth_neighbor_uv, fctx, ); - neighbours.record_mi_rect((mi_r, mi_c), bw, bh, &[luma_levels.to_vec(), u_levels, v_levels]); + neighbours.record_mi_rect((mi_r, mi_c), bw, bh, &[&luma_levels[..], &u_levels[..], &v_levels[..]]); neighbours.fill_skip_grid_rect((mi_r, mi_c), mi_w, mi_h, skip); neighbours.fill_lf_grid_rect((mi_r, mi_c), mi_w, mi_h, bw as u8, bh as u8, 0, fctx); record_strip_palette( @@ -11983,7 +12015,7 @@ fn decode_block_rect64( mode, angle_delta_y, reach, - &vec![0i32; bw * bh], + &ZERO_RESIDUAL[..bw * bh], None, filter_intra, smooth_neighbor, fctx, @@ -12000,7 +12032,7 @@ fn decode_block_rect64( uv_predict_mode, angle_delta_uv, reach, - &vec![0i32; chroma_w * chroma_h], + &ZERO_RESIDUAL[..chroma_w * chroma_h], alpha.zip(ac).map(|((au, _), ac)| (au, ac)), None, smooth_neighbor_uv, fctx, @@ -12016,7 +12048,7 @@ fn decode_block_rect64( uv_predict_mode, angle_delta_uv, reach, - &vec![0i32; chroma_w * chroma_h], + &ZERO_RESIDUAL[..chroma_w * chroma_h], alpha.zip(ac).map(|((_, av), ac)| (av, ac)), None, smooth_neighbor_uv, fctx, @@ -12028,9 +12060,9 @@ fn decode_block_rect64( mode, uv_predict_mode, &[ - vec![0i32; bw * bh], - vec![0i32; chroma_w * chroma_h], - vec![0i32; chroma_w * chroma_h], + &ZERO_RESIDUAL[..bw * bh], + &ZERO_RESIDUAL[..chroma_w * chroma_h], + &ZERO_RESIDUAL[..chroma_w * chroma_h], ], ); } else { @@ -12277,7 +12309,7 @@ fn decode_block_rect64( None, smooth_neighbor_uv, fctx, ); - neighbours.record_rect(at, bw, bh, mode, uv_predict_mode, &[luma_levels, u_levels, v_levels]); + neighbours.record_rect(at, bw, bh, mode, uv_predict_mode, &[&luma_levels[..], &u_levels[..], &v_levels[..]]); RECT_COEFF_HITS.with(|c| c.set(c.get() + 1)); } 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( mode, angle_delta_y, tu_reach, - &vec![0i32; logical_tx * logical_tx], + &ZERO_RESIDUAL[..logical_tx * logical_tx], None, filter_intra, smooth_neighbor, fctx, @@ -13596,7 +13628,7 @@ fn decode_block( mode, angle_delta_y, reach, - &vec![0i32; side * side], + &ZERO_RESIDUAL[..side * side], None, filter_intra, smooth_neighbor, fctx, @@ -13627,7 +13659,7 @@ fn decode_block( uv_predict_mode, angle_delta_uv, cu_r, - &vec![0i32; chroma_tx * chroma_tx], + &ZERO_RESIDUAL[..chroma_tx * chroma_tx], alpha.zip(ac).map(|((au, _), ac)| (au, ac)), None, smooth_neighbor_uv, fctx, @@ -13642,7 +13674,7 @@ fn decode_block( uv_predict_mode, angle_delta_uv, cu_r, - &vec![0i32; chroma_tx * chroma_tx], + &ZERO_RESIDUAL[..chroma_tx * chroma_tx], alpha.zip(ac).map(|((_, av), ac)| (av, ac)), None, smooth_neighbor_uv, fctx, @@ -13652,7 +13684,7 @@ fn decode_block( let luma_grid = vec![0i32; side * side]; let u_grid = vec![0i32; chroma_side * chroma_side]; let v_grid = vec![0i32; chroma_side * chroma_side]; - neighbours.record(at, side, mode, uv_predict_mode, &[luma_grid, u_grid, v_grid]); + neighbours.record(at, side, mode, uv_predict_mode, &[&luma_grid[..], &u_grid[..], &v_grid[..]]); } else if logical_tx == side { // lane-sb128b r1: the test used to be `!tx_select || logical_tx == side`. // Without `tx_select` `logical_tx` IS `side` at every size <= 64, so @@ -13749,7 +13781,7 @@ fn decode_block( smooth_neighbor_uv, fctx, )?; fctx.intrabc_chroma_tx.with(|c| c.set(None)); - neighbours.record(at, side, mode, uv_predict_mode, &[luma_grid, u_grid, v_grid]); + neighbours.record(at, side, mode, uv_predict_mode, &[&luma_grid[..], &u_grid[..], &v_grid[..]]); } else { // Several luma transform units, raster order (spec // `transform_block`'s loop): the block's resolved transform is @@ -14267,9 +14299,9 @@ fn decode_block_128rect( mode, uv_predict_mode, &[ - vec![0i32; bw * bh], - vec![0i32; chroma_w * chroma_h], - vec![0i32; chroma_w * chroma_h], + &ZERO_RESIDUAL[..bw * bh], + &ZERO_RESIDUAL[..chroma_w * chroma_h], + &ZERO_RESIDUAL[..chroma_w * chroma_h], ], ); } else { @@ -14598,7 +14630,7 @@ fn decode_leaf8( mode, angle_delta_y, tu_reach, - &vec![0i32; 16], + &ZERO_RESIDUAL[..16], None, filter_intra, smooth_neighbor, fctx, @@ -14616,7 +14648,7 @@ fn decode_leaf8( mode, angle_delta_y, reach, - &vec![0i32; 64], + &ZERO_RESIDUAL[..64], None, filter_intra, smooth_neighbor, fctx, @@ -14635,7 +14667,7 @@ fn decode_leaf8( uv_predict_mode, angle_delta_uv, reach, - &vec![0i32; 16], + &ZERO_RESIDUAL[..16], alpha.zip(ac).map(|((au, _), ac)| (au, ac)), None, smooth_neighbor_uv, fctx, @@ -14652,7 +14684,7 @@ fn decode_leaf8( uv_predict_mode, angle_delta_uv, reach, - &vec![0i32; 16], + &ZERO_RESIDUAL[..16], alpha.zip(ac).map(|((_, av), ac)| (av, ac)), None, smooth_neighbor_uv, fctx, @@ -14938,7 +14970,7 @@ fn decode_leaf8( record_intrabc_mi(leaf_mi.0, leaf_mi.1, 2, intrabc_dv, fctx); return Ok(mode); } - neighbours.record_mi(leaf_mi, 8, &[luma_grid, u_grid, v_grid]); + neighbours.record_mi(leaf_mi, 8, &[&luma_grid[..], &u_grid[..], &v_grid[..]]); // This leaf's own palette state into the mi-granular above/left bands // (sizes 0 when it used none, which is what clears a previous block's // palette out of the next block's ctx and colour cache). @@ -15149,8 +15181,8 @@ fn decode_leaf_split4( let (px, py) = (lmi.1 * MI, lmi.0 * MI); let reach = Reach::of(4, px, py, y.width, y.height, fctx); if skip { - push_intra(0, px, py, 4, mode, angle_delta_y, reach, &vec![0i32; 16], None, filter_intra, smooth_neighbor, fctx); - neighbours.record_mi_luma(lmi, 4, &vec![0i32; 16]); + push_intra(0, px, py, 4, mode, angle_delta_y, reach, &ZERO_RESIDUAL[..16], None, filter_intra, smooth_neighbor, fctx); + neighbours.record_mi_luma(lmi, 4, &ZERO_RESIDUAL[..16]); } else { let tu_around = neighbours.around_mi(lmi, 4)[0]; // A `BLOCK_4X4` leaf's luma TU *is* the whole block, so libaom's @@ -15211,8 +15243,8 @@ fn decode_leaf_split4( CHROMA_SKIP_CFL_HITS.with(|h| h.set(h.get() + 1)); SKIP_CFL_HITS.with(|c| c.set(c.get() + 1)); } - 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); - 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); + 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); + 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); (vec![0i32; 16], vec![0i32; 16]) } else { let ac = alpha.map(|_| cfl_src(gpx, gpy, 8)); @@ -15583,8 +15615,8 @@ fn decode_leaf_rect8( CHROMA_SKIP_CFL_HITS.with(|h| h.set(h.get() + 1)); SKIP_CFL_HITS.with(|c| c.set(c.get() + 1)); } - 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); - 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); + 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); + 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); (vec![0i32; 16], vec![0i32; 16]) } else { let ac = alpha.map(|_| cfl_src(gpx, gpy, 8)); @@ -24694,8 +24726,8 @@ fn decode_inter_block( let build = move |_y: &mut PlaneBuf<'static>, _u: &mut PlaneBuf<'static>, _v: &mut PlaneBuf<'static>, - fctx: &crate::decode::FrameCtx| - -> [Vec; 3] { + fctx: &crate::decode::FrameCtx, + out: &mut [Vec; 3]| { let mut inter0_y = vec![0i32; side * side]; mc::predict_compound_intermediate_kern( &py0.data, @@ -24750,7 +24782,7 @@ fn decode_inter_block( side as i32, side as i32, 0, 0, fctx, ); } - let mut pred_y = vec![0u16; side * side]; + let mut pred_y = refill(std::mem::take(&mut out[0]), side * side); let mut diffwtd_mask_y; // lane-wedge r3: `mask_y` is the DIFFWTD buffer just computed OR // the wedge codebook lookup (comp_group_idx==1's two mutually @@ -24830,7 +24862,7 @@ fn decode_inter_block( ); } } - let mut pred_u = vec![0u16; chroma_side * chroma_side]; + let mut pred_u = refill(std::mem::take(&mut out[1]), chroma_side * chroma_side); if let Some(mask_y) = mask_y { mc::blend_masked_compound( &inter0_u, @@ -24904,7 +24936,7 @@ fn decode_inter_block( ); } } - let mut pred_v = vec![0u16; chroma_side * chroma_side]; + let mut pred_v = refill(std::mem::take(&mut out[2]), chroma_side * chroma_side); if let Some(mask_y) = mask_y { mc::blend_masked_compound( &inter0_v, @@ -24922,7 +24954,7 @@ fn decode_inter_block( // lane-inter4 r2: a rectangular strip's transform tree starts from // its own rect `max_txsize_rect_lookup` entry, not a square one. - [pred_y, pred_u, pred_v] + *out = [pred_y, pred_u, pred_v]; }; let (pred_y, pred_u, pred_v): (Vec, Vec, Vec); let (sy, su, sv) = if recon_deferred(fctx) { @@ -24933,7 +24965,9 @@ fn decode_inter_block( Pred::Cur { plane: 2, stride: chroma_side, off: 0 }, ) } else { - let [by, bu, bv] = build(y, u, v, fctx); + let mut built: [Vec; 3] = Default::default(); + build(y, u, v, fctx, &mut built); + let [by, bu, bv] = built; (pred_y, pred_u, pred_v) = (by, bu, bv); ( Pred::Inline(&pred_y, side), @@ -24974,7 +25008,7 @@ fn decode_inter_block( write_w, write_h, sy, - &vec![0i32; side * side], fctx, + &ZERO_RESIDUAL[..side * side], fctx, ); push_mc_rect(1, cpx, @@ -24983,7 +25017,7 @@ fn decode_inter_block( write_chroma_w, write_chroma_h, su, - &vec![0i32; chroma_side * chroma_side], fctx, + &ZERO_RESIDUAL[..chroma_side * chroma_side], fctx, ); push_mc_rect(2, cpx, @@ -24992,7 +25026,7 @@ fn decode_inter_block( write_chroma_w, write_chroma_h, sv, - &vec![0i32; chroma_side * chroma_side], fctx, + &ZERO_RESIDUAL[..chroma_side * chroma_side], fctx, ); luma_grid = vec![0i32; side * side]; u_grid = vec![0i32; chroma_side * chroma_side]; @@ -25916,11 +25950,11 @@ fn decode_inter_block( let build = move |y: &mut PlaneBuf<'static>, u: &mut PlaneBuf<'static>, v: &mut PlaneBuf<'static>, - fctx: &crate::decode::FrameCtx| - -> [Vec; 3] { - let mut pred_y = vec![0u16; side * side]; - let mut pred_u = vec![0u16; chroma_side * chroma_side]; - let mut pred_v = vec![0u16; chroma_side * chroma_side]; + fctx: &crate::decode::FrameCtx, + out: &mut [Vec; 3]| { + let mut pred_y = refill(std::mem::take(&mut out[0]), side * side); + let mut pred_u = refill(std::mem::take(&mut out[1]), chroma_side * chroma_side); + let mut pred_v = refill(std::mem::take(&mut out[2]), chroma_side * chroma_side); if luma_scale == mc::REF_NO_SCALE { mc::predict_with_filters_kern( &py_ref.data, @@ -26077,7 +26111,7 @@ fn decode_inter_block( &mut pred_v, fctx, ); } - [pred_y, pred_u, pred_v] + *out = [pred_y, pred_u, pred_v]; }; // OBMC and interintra are mutually exclusive (`motion_mode` is // never read for an interintra block), so blending interintra @@ -26102,7 +26136,9 @@ fn decode_inter_block( if interintra_mode.is_some() { flush_recon(fctx, y, u, v); } - let [by, bu, bv] = build(y, u, v, fctx); + let mut built: [Vec; 3] = Default::default(); + build(y, u, v, fctx, &mut built); + let [by, bu, bv] = built; (pred_y, pred_u, pred_v) = (by, bu, bv); if obmc_selected { obmc_blend( @@ -26221,7 +26257,7 @@ fn decode_inter_block( write_w, write_h, sy, - &vec![0i32; side * side], fctx, + &ZERO_RESIDUAL[..side * side], fctx, ); if has_chroma { push_mc_rect(1, @@ -26231,7 +26267,7 @@ fn decode_inter_block( write_chroma_w, write_chroma_h, su, - &vec![0i32; chroma_side * chroma_side], fctx, + &ZERO_RESIDUAL[..chroma_side * chroma_side], fctx, ); push_mc_rect(2, cpx, @@ -26240,7 +26276,7 @@ fn decode_inter_block( write_chroma_w, write_chroma_h, sv, - &vec![0i32; chroma_side * chroma_side], fctx, + &ZERO_RESIDUAL[..chroma_side * chroma_side], fctx, ); } luma_grid = vec![0i32; side * side]; @@ -26971,7 +27007,7 @@ fn decode_inter_block( mode, angle_delta_y, tu_reach, - &vec![0i32; tx_px * tx_px], + &ZERO_RESIDUAL[..tx_px * tx_px], None, filter_intra, smooth_neighbor, fctx, @@ -27041,7 +27077,7 @@ fn decode_inter_block( uv_predict_mode, angle_delta_uv, cu_reach, - &vec![0i32; cu_tx * cu_tx], + &ZERO_RESIDUAL[..cu_tx * cu_tx], None, None, smooth_neighbor_uv, fctx, @@ -27111,7 +27147,7 @@ fn decode_inter_block( mode, angle_delta_y, reach, - &vec![0i32; side * side], + &ZERO_RESIDUAL[..side * side], None, filter_intra, smooth_neighbor, fctx, @@ -27128,7 +27164,7 @@ fn decode_inter_block( uv_predict_mode, angle_delta_uv, reach, - &vec![0i32; chroma_side * chroma_side], + &ZERO_RESIDUAL[..chroma_side * chroma_side], alpha.zip(ac).map(|((au, _), ac)| (au, ac)), None, smooth_neighbor_uv, fctx, @@ -27143,7 +27179,7 @@ fn decode_inter_block( uv_predict_mode, angle_delta_uv, reach, - &vec![0i32; chroma_side * chroma_side], + &ZERO_RESIDUAL[..chroma_side * chroma_side], alpha.zip(ac).map(|((_, av), ac)| (av, ac)), None, smooth_neighbor_uv, fctx, @@ -27373,7 +27409,7 @@ fn decode_inter_block( write_h, mode_for_tx, uv_predict_mode, - &[luma_grid, u_grid, v_grid], + &[&luma_grid[..], &u_grid[..], &v_grid[..]], ); } if let Some((left, above)) = saved_chroma_ctx { @@ -27842,8 +27878,8 @@ fn decode_inter_sub8_split4( // txsize_to_bsize[tx_size]` branch (`txb_skip_ctx = 0`, which // `read_inter_plane`'s `plane_idx == 0` arm already assumes). if skip { - push_mc(0, px, py, B4, Pred::dense(&pred_y), &vec![0i32; B4 * B4], fctx); - neighbours.record_mi_luma_rect(lmi, B4, B4, &vec![0i32; B4 * B4]); + push_mc(0, px, py, B4, Pred::dense(&pred_y), &ZERO_RESIDUAL[..B4 * B4], fctx); + neighbours.record_mi_luma_rect(lmi, B4, B4, &ZERO_RESIDUAL[..B4 * B4]); } else { let around = neighbours.around_mi(lmi, B4); let (luma_grid, tx_type) = read_inter_plane( @@ -27957,8 +27993,8 @@ fn decode_inter_sub8_split4( } } let (u_grid, v_grid) = if last_skip { - push_mc(1, cpx, cpy, B4, Pred::dense(&pred_u), &vec![0i32; B4 * B4], fctx); - push_mc(2, cpx, cpy, B4, Pred::dense(&pred_v), &vec![0i32; B4 * B4], fctx); + push_mc(1, cpx, cpy, B4, Pred::dense(&pred_u), &ZERO_RESIDUAL[..B4 * B4], fctx); + push_mc(2, cpx, cpy, B4, Pred::dense(&pred_v), &ZERO_RESIDUAL[..B4 * B4], fctx); (vec![0i32; B4 * B4], vec![0i32; B4 * B4]) } else { let around = neighbours.around_mi(group_mi, 8); @@ -28230,10 +28266,10 @@ fn decode_intra_sub8_leaf( // reader [`decode_leaf_split4`] uses. if skip { push_intra(0, - px, py, 4, mode, angle_delta_y, reach, &vec![0i32; 16], None, filter_intra, + px, py, 4, mode, angle_delta_y, reach, &ZERO_RESIDUAL[..16], None, filter_intra, smooth_neighbor, fctx, ); - neighbours.record_mi_luma(lmi, 4, &vec![0i32; 16]); + neighbours.record_mi_luma(lmi, 4, &ZERO_RESIDUAL[..16]); } else { let tu_around = neighbours.around_mi(lmi, 4)[0]; let tu_grid = read_plane( @@ -28401,8 +28437,8 @@ fn decode_intra_sub8_leaf( CHROMA_SKIP_CFL_HITS.with(|h| h.set(h.get() + 1)); SKIP_CFL_HITS.with(|c| c.set(c.get() + 1)); } - 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); - 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); + 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); + 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); (vec![0i32; 16], vec![0i32; 16]) } else { let chroma_around = neighbours.around_mi(group_mi, 8); @@ -28813,8 +28849,8 @@ fn decode_inter_sub8_rect2( } } if skip { - push_mc_rect(0, px, py, SIDE, bw, bh, Pred::dense(&pred_y), &vec![0i32; SIDE * SIDE], fctx); - neighbours.record_mi_luma_rect(lmi, bw, bh, &vec![0i32; bw * bh]); + push_mc_rect(0, px, py, SIDE, bw, bh, Pred::dense(&pred_y), &ZERO_RESIDUAL[..SIDE * SIDE], fctx); + neighbours.record_mi_luma_rect(lmi, bw, bh, &ZERO_RESIDUAL[..bw * bh]); neighbours.fill_lf_grid_rect(lmi, w_mi, h_mi, bw as u8, bh as u8, ref_frame.max(LAST_FRAME), fctx); } else { let (mut last_tw, mut last_th) = (bw, bh); @@ -28979,8 +29015,8 @@ fn decode_inter_sub8_rect2( } } let (u_grid, v_grid) = if last_skip { - push_mc(1, cpx, cpy, B4, Pred::dense(&pred_u), &vec![0i32; B4 * B4], fctx); - push_mc(2, cpx, cpy, B4, Pred::dense(&pred_v), &vec![0i32; B4 * B4], fctx); + push_mc(1, cpx, cpy, B4, Pred::dense(&pred_u), &ZERO_RESIDUAL[..B4 * B4], fctx); + push_mc(2, cpx, cpy, B4, Pred::dense(&pred_v), &ZERO_RESIDUAL[..B4 * B4], fctx); (vec![0i32; B4 * B4], vec![0i32; B4 * B4]) } else { let around = neighbours.around_mi(group_mi, 8); @@ -29812,20 +29848,20 @@ fn decode_inter_block8( .1 .is_some(); if skip { - push_mc(0, px, py, SIDE, Pred::dense(&pred_y), &vec![0i32; SIDE * SIDE], fctx); + push_mc(0, px, py, SIDE, Pred::dense(&pred_y), &ZERO_RESIDUAL[..SIDE * SIDE], fctx); push_mc(1, cpx, cpy, CHROMA_SIDE, Pred::dense(&pred_u), - &vec![0i32; CHROMA_SIDE * CHROMA_SIDE], fctx, + &ZERO_RESIDUAL[..CHROMA_SIDE * CHROMA_SIDE], fctx, ); push_mc(2, cpx, cpy, CHROMA_SIDE, Pred::dense(&pred_v), - &vec![0i32; CHROMA_SIDE * CHROMA_SIDE], fctx, + &ZERO_RESIDUAL[..CHROMA_SIDE * CHROMA_SIDE], fctx, ); luma_grid = vec![0i32; SIDE * SIDE]; u_grid = vec![0i32; CHROMA_SIDE * CHROMA_SIDE]; @@ -29931,7 +29967,7 @@ fn decode_inter_block8( palette_record8.2, palette_record8.3, ); - neighbours.record_mi(leaf_mi, 8, &[luma_grid, u_grid, v_grid]); + neighbours.record_mi(leaf_mi, 8, &[&luma_grid[..], &u_grid[..], &v_grid[..]]); if let Some((left, above)) = saved_luma_ctx { for (cell, state) in left.into_iter().enumerate() { neighbours.left[leaf_mi.0 + cell][0] = state; @@ -30460,20 +30496,20 @@ fn decode_inter_block8( .1 .is_some(); if skip { - push_mc(0, px, py, SIDE, Pred::dense(&pred_y), &vec![0i32; SIDE * SIDE], fctx); + push_mc(0, px, py, SIDE, Pred::dense(&pred_y), &ZERO_RESIDUAL[..SIDE * SIDE], fctx); push_mc(1, cpx, cpy, CHROMA_SIDE, Pred::dense(&pred_u), - &vec![0i32; CHROMA_SIDE * CHROMA_SIDE], fctx, + &ZERO_RESIDUAL[..CHROMA_SIDE * CHROMA_SIDE], fctx, ); push_mc(2, cpx, cpy, CHROMA_SIDE, Pred::dense(&pred_v), - &vec![0i32; CHROMA_SIDE * CHROMA_SIDE], fctx, + &ZERO_RESIDUAL[..CHROMA_SIDE * CHROMA_SIDE], fctx, ); luma_grid = vec![0i32; SIDE * SIDE]; u_grid = vec![0i32; CHROMA_SIDE * CHROMA_SIDE]; @@ -30836,7 +30872,7 @@ fn decode_inter_block8( mode, angle_delta_y, tu_reach, - &vec![0i32; tx_px * tx_px], + &ZERO_RESIDUAL[..tx_px * tx_px], None, filter_intra, smooth_neighbor, fctx, @@ -30889,7 +30925,7 @@ fn decode_inter_block8( mode, angle_delta_y, reach, - &vec![0i32; SIDE * SIDE], + &ZERO_RESIDUAL[..SIDE * SIDE], None, filter_intra, smooth_neighbor, fctx, @@ -30908,7 +30944,7 @@ fn decode_inter_block8( uv_predict_mode, angle_delta_uv, reach, - &vec![0i32; CHROMA_SIDE * CHROMA_SIDE], + &ZERO_RESIDUAL[..CHROMA_SIDE * CHROMA_SIDE], alpha.zip(ac).map(|((au, _), ac)| (au, ac)), None, smooth_neighbor_uv, fctx, @@ -30923,7 +30959,7 @@ fn decode_inter_block8( uv_predict_mode, angle_delta_uv, reach, - &vec![0i32; CHROMA_SIDE * CHROMA_SIDE], + &ZERO_RESIDUAL[..CHROMA_SIDE * CHROMA_SIDE], alpha.zip(ac).map(|((_, av), ac)| (av, ac)), None, smooth_neighbor_uv, fctx, @@ -31058,7 +31094,7 @@ fn decode_inter_block8( palette_record8.2, palette_record8.3, ); - neighbours.record_mi(leaf_mi, 8, &[luma_grid, u_grid, v_grid]); + neighbours.record_mi(leaf_mi, 8, &[&luma_grid[..], &u_grid[..], &v_grid[..]]); // lane-uv8 r1: this leaf never stamped a mode band at all, so the block // below/right of it read whatever block last wrote the coarse [`SUB`] // slot -- now that an intra leaf here can code a smooth/directional