forge
Explore
Log in

Don't you dare go Hollow

Merge branch 'lane-recoparse' (9cdc32d8): recorded reconstruction ops index per-superblock coefficient/prediction arenas moved into the wavefront job (no Vec per transform unit, no cross-thread free), empty inter residual reconstructs as a prediction copy; byte-exact, -1.3% instructions at the composed setting on the 4K segment

Browse files at this commit

5b55d0448f9f7739fea59b57c1780a99904eb10aAhmet Kaan GümüşParent: 84ddd14c5b674a
crates/ec-av1/src/decode.rsmodified+158 -38
@@ -85,6 +85,20 @@ pub(crate) struct FrameCtx {
85 /// The queue buffer [`flush_recon`] just drained, kept for its capacity85 /// The queue buffer [`flush_recon`] just drained, kept for its capacity
86 /// so a superblock's records do not regrow the vector from nothing.86 /// so a superblock's records do not regrow the vector from nothing.
87 pub(crate) recon_spare: std::cell::RefCell<Vec<ReconOp>>,87 pub(crate) recon_spare: std::cell::RefCell<Vec<ReconOp>>,
88+ /// lane-recoparse: the coefficient grids of the recorded ops above, one
89+ /// buffer instead of a `Vec` per transform unit -- a recorded unit is
90+ /// `(offset, len)` into it ([`Residual::Coeffs`]). Written by parse
91+ /// before the op is published, read only by whoever replays that op, and
92+ /// handed over WITH the ops at every drain point ([`wave_submit`],
93+ /// [`flush_recon`]), so offsets are always relative to the live arena.
94+ pub(crate) coeff_arena: std::cell::RefCell<Vec<i32>>,
95+ /// [`recon_spare`](Self::recon_spare) for the arena, on the inline drain
96+ /// path (a submitted job's arena travels to its worker instead).
97+ pub(crate) coeff_spare: std::cell::RefCell<Vec<i32>>,
98+ /// [`coeff_arena`](Self::coeff_arena) for the recorded PREDICTIONS
99+ /// ([`PredSrc::Owned`]): same lifetime, same drain points.
100+ pub(crate) pred_arena: std::cell::RefCell<Vec<u16>>,
101+ pub(crate) pred_spare: std::cell::RefCell<Vec<u16>>,
88 /// lane-wave1 step (ii): the tile decoder's own planes, registered by102 /// lane-wave1 step (ii): the tile decoder's own planes, registered by
89 /// [`ReconInline`] while reconstruction runs INLINE (one recon thread).103 /// [`ReconInline`] while reconstruction runs INLINE (one recon thread).
90 /// `None` while the queue is in use (wavefront workers) and outside a104 /// `None` while the queue is in use (wavefront workers) and outside a
@@ -155,6 +169,10 @@ impl FrameCtx {
155 grain_bit_depth: std::cell::Cell::new(8),169 grain_bit_depth: std::cell::Cell::new(8),
156 recon_ops: std::cell::RefCell::new(Vec::new()),170 recon_ops: std::cell::RefCell::new(Vec::new()),
157 recon_spare: std::cell::RefCell::new(Vec::new()),171 recon_spare: std::cell::RefCell::new(Vec::new()),
172+ coeff_arena: std::cell::RefCell::new(Vec::new()),
173+ coeff_spare: std::cell::RefCell::new(Vec::new()),
174+ pred_arena: std::cell::RefCell::new(Vec::new()),
175+ pred_spare: std::cell::RefCell::new(Vec::new()),
158 recon_planes: std::cell::Cell::new(None),176 recon_planes: std::cell::Cell::new(None),
159 wave: std::cell::RefCell::new(None),177 wave: std::cell::RefCell::new(None),
160 wave_mark: std::cell::Cell::new(None),178 wave_mark: std::cell::Cell::new(None),
@@ -2108,29 +2126,66 @@ impl TxParams {
2108 /// A recorded write's residual: already transformed, or the coefficients and2126 /// A recorded write's residual: already transformed, or the coefficients and
2109 /// [`TxParams`] the worker transforms itself.2127 /// [`TxParams`] the worker transforms itself.
2110 pub(crate) enum Residual {2128 pub(crate) enum Residual {
2111- Done(Vec<i32>),2129+ /// An already-transformed residual in the arena, `(offset, len)`; a zero
2112- Coeffs(TxParams, Vec<i32>),2130+ /// `len` is the all-zero marker [`dense_residual`] expands.
2131+ Done(u32, u32),
2132+ /// The coefficients live in the pushing tile's arena
2133+ /// ([`crate::decode::FrameCtx::coeff_arena`]); this is their `(offset,
2134+ /// len)` in it.
2135+ Coeffs(TxParams, u32, u32),
2113 }2136 }
2114 2137
2115 impl Residual {2138 impl Residual {
2116 /// The record for a transform unit whose coefficient grid is all zero:2139 /// The record for a transform unit whose coefficient grid is all zero:
2117 /// the empty marker, so neither the grid nor the residual is cloned and2140 /// the empty marker, so neither the grid nor the residual is cloned and
2118 /// the worker never runs the transform (60% of the 4K segment's units).2141 /// the worker never runs the transform (60% of the 4K segment's units).
2119- fn coeffs(tx: TxParams, grid: &[i32]) -> Self {2142+ fn coeffs(tx: TxParams, grid: &[i32], fctx: &crate::decode::FrameCtx) -> Self {
2120 if grid.iter().all(|&c| c == 0) {2143 if grid.iter().all(|&c| c == 0) {
2121- return Self::Done(Vec::new());2144+ return Self::Done(0, 0);
2122 }2145 }
2123- Self::Coeffs(tx, grid.to_vec())2146+ Self::Coeffs(tx, push_coeffs(grid, fctx), grid.len() as u32)
2124 }2147 }
2125 2148
2126- fn resolve(self) -> Vec<i32> {2149+ /// A residual the parse thread already transformed, kept in the arena
2150+ /// instead of its own `Vec`.
2151+ fn done(residual: &[i32], fctx: &crate::decode::FrameCtx) -> Self {
2152+ Self::Done(push_coeffs(residual, fctx), residual.len() as u32)
2153+ }
2154+
2155+ /// The residual to reconstruct with; `scratch` is where a transform run
2156+ /// on this thread lands, so the caller owns that buffer.
2157+ fn resolve<'a>(self, arena: &'a [i32], scratch: &'a mut Vec<i32>) -> &'a [i32] {
2127 match self {2158 match self {
2128- Self::Done(v) => v,2159+ Self::Done(off, len) => &arena[off as usize..][..len as usize],
2129- Self::Coeffs(p, grid) => p.run(&grid),2160+ Self::Coeffs(p, off, len) => {
2161+ *scratch = p.run(&arena[off as usize..][..len as usize]);
2162+ scratch
2163+ }
2130 }2164 }
2131 }2165 }
2132 }2166 }
2133 2167
2168+/// Appends to the tile's coefficient arena, returning the offset the record
2169+/// carries; see [`crate::decode::FrameCtx::coeff_arena`].
2170+fn push_coeffs(v: &[i32], fctx: &crate::decode::FrameCtx) -> u32 {
2171+ fctx.coeff_arena.with(|a| {
2172+ let mut a = a.borrow_mut();
2173+ let off = a.len();
2174+ a.extend_from_slice(v);
2175+ off as u32
2176+ })
2177+}
2178+
2179+/// [`push_coeffs`] for a recorded prediction.
2180+fn push_pred_samples(v: &[u16], fctx: &crate::decode::FrameCtx) -> u32 {
2181+ fctx.pred_arena.with(|a| {
2182+ let mut a = a.borrow_mut();
2183+ let off = a.len();
2184+ a.extend_from_slice(v);
2185+ off as u32
2186+ })
2187+}
2188+
2134 /// An all-zero residual, for the transform units that code no coefficient:2189 /// An all-zero residual, for the transform units that code no coefficient:
2135 /// [`crate::transform::dequant_and_inverse_typed_wh`] returns those EMPTY,2190 /// [`crate::transform::dequant_and_inverse_typed_wh`] returns those EMPTY,
2136 /// and the reconstruction loops below read this instead of a per-unit2191 /// and the reconstruction loops below read this instead of a per-unit
@@ -2192,7 +2247,8 @@ impl<'a> Pred<'a> {
2192 2247
2193 /// [`Pred`], resolved into what a recorded op carries.2248 /// [`Pred`], resolved into what a recorded op carries.
2194 pub(crate) enum PredSrc {2249 pub(crate) enum PredSrc {
2195- Owned(Vec<u16>),2250+ /// A prediction window in the tile's prediction arena, `(offset, len)`.
2251+ Owned(u32, u32),
2196 /// A window of the block prediction: its plane, its offset, and the2252 /// A window of the block prediction: its plane, its offset, and the
2197 /// stride it is read at -- which is the block's, not necessarily the2253 /// stride it is read at -- which is the block's, not necessarily the
2198 /// op's (a transform unit's residual stays dense, so the worker takes2254 /// op's (a transform unit's residual stays dense, so the worker takes
@@ -2255,6 +2311,14 @@ fn push_pred<'a>(
2255 push_op(fctx, ReconOp::Pred(PredBuild(boxed)));2311 push_op(fctx, ReconOp::Pred(PredBuild(boxed)));
2256 }2312 }
2257 2313
2314+/// One superblock's recorded writes plus the two arenas they index -- the
2315+/// unit a wavefront worker takes off the queue (lane-recoparse).
2316+pub(crate) struct ReconJob {
2317+ ops: Vec<ReconOp>,
2318+ coeffs: Vec<i32>,
2319+ preds: Vec<u16>,
2320+}
2321+
2258 pub(crate) enum ReconOp {2322 pub(crate) enum ReconOp {
2259 /// lane-wave4: build this block's prediction into the worker's slot.2323 /// lane-wave4: build this block's prediction into the worker's slot.
2260 Pred(PredBuild),2324 Pred(PredBuild),
@@ -2367,7 +2431,11 @@ fn push_op(fctx: &crate::decode::FrameCtx, op: ReconOp) {
2367 if let Some(ReconPlanes(y, u, v)) = fctx.recon_planes.with(std::cell::Cell::get) {2431 if let Some(ReconPlanes(y, u, v)) = fctx.recon_planes.with(std::cell::Cell::get) {
2368 // SAFETY: see [`ReconPlanes`] -- one thread, and the write is the one2432 // SAFETY: see [`ReconPlanes`] -- one thread, and the write is the one
2369 // the parse site would have performed itself before lane-wave1.2433 // the parse site would have performed itself before lane-wave1.
2370- unsafe { exec_op(op, &mut *y, &mut *u, &mut *v, &mut Default::default(), fctx) };2434+ // The inline path never records coefficients (the transform runs at
2435+ // the push site), so the arena is not read here.
2436+ unsafe {
2437+ exec_op(op, &mut *y, &mut *u, &mut *v, &mut Default::default(), &[], &[], fctx)
2438+ };
2371 return;2439 return;
2372 }2440 }
2373 fctx.recon_ops.with(|c| c.borrow_mut().push(op));2441 fctx.recon_ops.with(|c| c.borrow_mut().push(op));
@@ -2408,7 +2476,7 @@ struct WaveQueue {
2408 /// dependencies are met. Popping the raster-oldest job instead (what2476 /// dependencies are met. Popping the raster-oldest job instead (what
2409 /// this replaced) put every worker on the SAME row, where the wavefront2477 /// this replaced) put every worker on the SAME row, where the wavefront
2410 /// rule serialises them, which is why 4 workers ran the tile at 1.2x.2478 /// rule serialises them, which is why 4 workers ran the tile at 1.2x.
2411- rows: Vec<std::collections::VecDeque<(usize, Vec<ReconOp>)>>,2479+ rows: Vec<std::collections::VecDeque<(usize, ReconJob)>>,
2412 /// Jobs sitting in `rows`, so a worker knows the queue is empty without2480 /// Jobs sitting in `rows`, so a worker knows the queue is empty without
2413 /// walking it.2481 /// walking it.
2414 queued: usize,2482 queued: usize,
@@ -2422,7 +2490,11 @@ struct WaveQueue {
2422 impl WaveQueue {2490 impl WaveQueue {
2423 /// The lowest-row queued job whose wavefront dependencies are satisfied,2491 /// The lowest-row queued job whose wavefront dependencies are satisfied,
2424 /// or `None` (with the blocking condition counted when instrumented).2492 /// or `None` (with the blocking condition counted when instrumented).
2425- fn take_runnable(&mut self, last_col: usize, stats: bool) -> Option<(usize, usize, Vec<ReconOp>)> {2493+ fn take_runnable(
2494+ &mut self,
2495+ last_col: usize,
2496+ stats: bool,
2497+ ) -> Option<(usize, usize, ReconJob)> {
2426 let mut blocked: Option<bool> = None;2498 let mut blocked: Option<bool> = None;
2427 for r in 0..self.rows.len() {2499 for r in 0..self.rows.len() {
2428 let Some(front) = self.rows[r].front() else {2500 let Some(front) = self.rows[r].front() else {
@@ -2432,9 +2504,9 @@ impl WaveQueue {
2432 let above = r == 0 || self.done[r - 1] >= (c + 1).min(last_col) as isize;2504 let above = r == 0 || self.done[r - 1] >= (c + 1).min(last_col) as isize;
2433 let left = c == 0 || self.done[r] >= c as isize - 1;2505 let left = c == 0 || self.done[r] >= c as isize - 1;
2434 if above && left {2506 if above && left {
2435- let (c, ops) = self.rows[r].pop_front().expect("front checked above");2507+ let (c, job) = self.rows[r].pop_front().expect("front checked above");
2436 self.queued -= 1;2508 self.queued -= 1;
2437- return Some((r, c, ops));2509+ return Some((r, c, job));
2438 }2510 }
2439 if blocked.is_none() {2511 if blocked.is_none() {
2440 blocked = Some(above);2512 blocked = Some(above);
@@ -2528,7 +2600,7 @@ fn wave_worker(st: &WaveState, idx: usize) {
2528 loop {2600 loop {
2529 let t0 = std::time::Instant::now();2601 let t0 = std::time::Instant::now();
2530 let mut q = st.q.lock().unwrap();2602 let mut q = st.q.lock().unwrap();
2531- let (r, c, ops) = loop {2603+ let (r, c, job) = loop {
2532 if let Some(job) = q.take_runnable(st.last_col, stats) {2604 if let Some(job) = q.take_runnable(st.last_col, stats) {
2533 break job;2605 break job;
2534 }2606 }
@@ -2542,7 +2614,7 @@ fn wave_worker(st: &WaveState, idx: usize) {
2542 if stats {2614 if stats {
2543 WS_WAIT[slot].fetch_add(t0.elapsed().as_nanos() as u64, Relaxed);2615 WS_WAIT[slot].fetch_add(t0.elapsed().as_nanos() as u64, Relaxed);
2544 WS_JOBS[slot].fetch_add(1, Relaxed);2616 WS_JOBS[slot].fetch_add(1, Relaxed);
2545- WS_OPS[slot].fetch_add(ops.len() as u64, Relaxed);2617+ WS_OPS[slot].fetch_add(job.ops.len() as u64, Relaxed);
2546 }2618 }
2547 let t1 = std::time::Instant::now();2619 let t1 = std::time::Instant::now();
2548 let ReconPlanes(y, u, v) = st.planes;2620 let ReconPlanes(y, u, v) = st.planes;
@@ -2551,8 +2623,8 @@ fn wave_worker(st: &WaveState, idx: usize) {
2551 // complete by the wavefront rule above.2623 // complete by the wavefront rule above.
2552 let mut cur: [Vec<u16>; 3] = Default::default();2624 let mut cur: [Vec<u16>; 3] = Default::default();
2553 unsafe {2625 unsafe {
2554- for op in ops {2626+ for op in job.ops {
2555- exec_op(op, &mut *y, &mut *u, &mut *v, &mut cur, &fctx);2627+ exec_op(op, &mut *y, &mut *u, &mut *v, &mut cur, &job.coeffs, &job.preds, &fctx);
2556 }2628 }
2557 }2629 }
2558 if stats {2630 if stats {
@@ -2646,9 +2718,22 @@ fn wave_submit(fctx: &crate::decode::FrameCtx, r: usize, c: usize) -> bool {
2646 let st = fctx.wave.with(|w| w.borrow().clone());2718 let st = fctx.wave.with(|w| w.borrow().clone());
2647 let Some(st) = st else { return false };2719 let Some(st) = st else { return false };
2648 let ops = fctx.recon_ops.with(|c| std::mem::take(&mut *c.borrow_mut()));2720 let ops = fctx.recon_ops.with(|c| std::mem::take(&mut *c.borrow_mut()));
2721+ // The job owns its coefficients: the arena is replaced by an empty one
2722+ // sized for the next superblock, so parse never regrows from nothing and
2723+ // the worker frees this buffer once, instead of once per unit.
2724+ let coeffs = fctx.coeff_arena.with(|c| {
2725+ let mut c = c.borrow_mut();
2726+ let cap = c.len();
2727+ std::mem::replace(&mut *c, Vec::with_capacity(cap))
2728+ });
2729+ let preds = fctx.pred_arena.with(|c| {
2730+ let mut c = c.borrow_mut();
2731+ let cap = c.len();
2732+ std::mem::replace(&mut *c, Vec::with_capacity(cap))
2733+ });
2649 if !ops.is_empty() {2734 if !ops.is_empty() {
2650 let mut q = st.q.lock().unwrap();2735 let mut q = st.q.lock().unwrap();
2651- q.rows[r].push_back((c, ops));2736+ q.rows[r].push_back((c, ReconJob { ops, coeffs, preds }));
2652 q.queued += 1;2737 q.queued += 1;
2653 drop(q);2738 drop(q);
2654 st.cv.notify_all();2739 st.cv.notify_all();
@@ -2764,7 +2849,7 @@ fn push_intra(
2764 let pred = take_palette_pred(fctx);2849 let pred = take_palette_pred(fctx);
2765 push_op(fctx, ReconOp::Intra {2850 push_op(fctx, ReconOp::Intra {
2766 plane, x, y, bw: side, bh: side, rect: false, mode, angle_delta, reach,2851 plane, x, y, bw: side, bh: side, rect: false, mode, angle_delta, reach,
2767- residual: Residual::Done(residual.to_vec()), cfl, filter_intra, smooth_neighbor, pred,2852+ residual: Residual::done(residual, fctx), cfl, filter_intra, smooth_neighbor, pred,
2768 });2853 });
2769 }2854 }
2770 2855
@@ -2793,7 +2878,7 @@ fn push_intra_rect(
2793 let pred = take_palette_pred(fctx);2878 let pred = take_palette_pred(fctx);
2794 push_op(fctx, ReconOp::Intra {2879 push_op(fctx, ReconOp::Intra {
2795 plane, x, y, bw, bh, rect: true, mode, angle_delta, reach,2880 plane, x, y, bw, bh, rect: true, mode, angle_delta, reach,
2796- residual: Residual::Done(residual.to_vec()), cfl, filter_intra, smooth_neighbor, pred,2881+ residual: Residual::done(residual, fctx), cfl, filter_intra, smooth_neighbor, pred,
2797 });2882 });
2798 }2883 }
2799 2884
@@ -2828,7 +2913,7 @@ fn push_mc_rect(
2828 push_op(fctx, ReconOp::Mc {2913 push_op(fctx, ReconOp::Mc {
2829 plane, x, y, stride: ss, w, h,2914 plane, x, y, stride: ss, w, h,
2830 prediction: PredSrc::Cur { plane: sp, off, src: ss },2915 prediction: PredSrc::Cur { plane: sp, off, src: ss },
2831- residual: Residual::Done(residual.to_vec()),2916+ residual: Residual::done(residual, fctx),
2832 });2917 });
2833 return;2918 return;
2834 }2919 }
@@ -2838,7 +2923,10 @@ fn push_mc_rect(
2838 }2923 }
2839 push_op(fctx, ReconOp::Mc {2924 push_op(fctx, ReconOp::Mc {
2840 plane, x, y, stride, w, h,2925 plane, x, y, stride, w, h,
2841- prediction: PredSrc::Owned(src.to_vec()), residual: Residual::Done(residual.to_vec()),2926+ // The whole window `reconstruct_mc_rect` reads at `stride`, not
2927+ // `w * h`: the record keeps exactly what `src.to_vec()` carried.
2928+ prediction: PredSrc::Owned(push_pred_samples(src, fctx), src.len() as u32),
2929+ residual: Residual::done(residual, fctx),
2842 });2930 });
2843 }2931 }
2844 2932
@@ -2873,7 +2961,7 @@ fn push_intra_tx(
2873 let pred = take_palette_pred(fctx);2961 let pred = take_palette_pred(fctx);
2874 push_op(fctx, ReconOp::Intra {2962 push_op(fctx, ReconOp::Intra {
2875 plane, x, y, bw, bh, rect, mode, angle_delta, reach,2963 plane, x, y, bw, bh, rect, mode, angle_delta, reach,
2876- residual: Residual::coeffs(tx, grid), cfl, filter_intra, smooth_neighbor, pred,2964+ residual: Residual::coeffs(tx, grid, fctx), cfl, filter_intra, smooth_neighbor, pred,
2877 });2965 });
2878 }2966 }
2879 2967
@@ -2904,7 +2992,7 @@ fn push_mc_rect_tx(
2904 push_op(fctx, ReconOp::Mc {2992 push_op(fctx, ReconOp::Mc {
2905 plane, x, y, stride: w, w, h,2993 plane, x, y, stride: w, w, h,
2906 prediction: PredSrc::Cur { plane: sp, off, src: ss },2994 prediction: PredSrc::Cur { plane: sp, off, src: ss },
2907- residual: Residual::coeffs(tx, grid),2995+ residual: Residual::coeffs(tx, grid, fctx),
2908 });2996 });
2909 return;2997 return;
2910 }2998 }
@@ -2937,15 +3025,19 @@ fn push_mc_rect_tx(
2937 // copied 64*64 samples on the PARSING thread before. The residual is then3025 // copied 64*64 samples on the PARSING thread before. The residual is then
2938 // produced dense too (`TxParams::stride = 0`), which is the same numbers3026 // produced dense too (`TxParams::stride = 0`), which is the same numbers
2939 // in the same places at stride `w`.3027 // in the same places at stride `w`.
2940- let mut window = Vec::with_capacity(w * h);3028+ let off = fctx.pred_arena.with(|a| {
2941- for row in 0..h {3029+ let mut a = a.borrow_mut();
2942- window.extend_from_slice(&prediction[row * stride..][..w]);3030+ let off = a.len();
2943- }3031+ for row in 0..h {
3032+ a.extend_from_slice(&prediction[row * stride..][..w]);
3033+ }
3034+ off as u32
3035+ });
2944 let mut tx = tx;3036 let mut tx = tx;
2945 tx.stride = 0;3037 tx.stride = 0;
2946 push_op(fctx, ReconOp::Mc {3038 push_op(fctx, ReconOp::Mc {
2947- plane, x, y, stride: w, w, h, prediction: PredSrc::Owned(window),3039+ plane, x, y, stride: w, w, h, prediction: PredSrc::Owned(off, (w * h) as u32),
2948- residual: Residual::coeffs(tx, grid),3040+ residual: Residual::coeffs(tx, grid, fctx),
2949 });3041 });
2950 }3042 }
2951 3043
@@ -2968,11 +3060,19 @@ fn flush_recon(
2968 wave_barrier(fctx);3060 wave_barrier(fctx);
2969 let mut ops = fctx.recon_spare.with(|c| std::mem::take(&mut *c.borrow_mut()));3061 let mut ops = fctx.recon_spare.with(|c| std::mem::take(&mut *c.borrow_mut()));
2970 fctx.recon_ops.with(|c| std::mem::swap(&mut *c.borrow_mut(), &mut ops));3062 fctx.recon_ops.with(|c| std::mem::swap(&mut *c.borrow_mut(), &mut ops));
3063+ let mut coeffs = fctx.coeff_spare.with(|c| std::mem::take(&mut *c.borrow_mut()));
3064+ fctx.coeff_arena.with(|c| std::mem::swap(&mut *c.borrow_mut(), &mut coeffs));
3065+ let mut preds = fctx.pred_spare.with(|c| std::mem::take(&mut *c.borrow_mut()));
3066+ fctx.pred_arena.with(|c| std::mem::swap(&mut *c.borrow_mut(), &mut preds));
2971 let mut cur: [Vec<u16>; 3] = Default::default();3067 let mut cur: [Vec<u16>; 3] = Default::default();
2972 for op in ops.drain(..) {3068 for op in ops.drain(..) {
2973- exec_op(op, y, u, v, &mut cur, fctx);3069+ exec_op(op, y, u, v, &mut cur, &coeffs, &preds, fctx);
2974 }3070 }
3071+ coeffs.clear();
3072+ preds.clear();
2975 fctx.recon_spare.with(|c| *c.borrow_mut() = ops);3073 fctx.recon_spare.with(|c| *c.borrow_mut() = ops);
3074+ fctx.coeff_spare.with(|c| *c.borrow_mut() = coeffs);
3075+ fctx.pred_spare.with(|c| *c.borrow_mut() = preds);
2976 }3076 }
2977 3077
2978 /// Performs one recorded write: the body [`flush_recon`] replays, and the3078 /// Performs one recorded write: the body [`flush_recon`] replays, and the
@@ -2983,27 +3083,32 @@ fn exec_op(
2983 u: &mut PlaneBuf<'static>,3083 u: &mut PlaneBuf<'static>,
2984 v: &mut PlaneBuf<'static>,3084 v: &mut PlaneBuf<'static>,
2985 cur: &mut [Vec<u16>; 3],3085 cur: &mut [Vec<u16>; 3],
3086+ coeffs: &[i32],
3087+ preds: &[u16],
2986 fctx: &crate::decode::FrameCtx,3088 fctx: &crate::decode::FrameCtx,
2987 ) {3089 ) {
3090+ let mut scratch = Vec::new();
2988 match op {3091 match op {
2989 ReconOp::Pred(b) => *cur = (b.0)(y, u, v, fctx),3092 ReconOp::Pred(b) => *cur = (b.0)(y, u, v, fctx),
2990 ReconOp::Intra {3093 ReconOp::Intra {
2991 plane, x, y: oy, bw, bh, rect, mode, angle_delta, reach, residual, cfl,3094 plane, x, y: oy, bw, bh, rect, mode, angle_delta, reach, residual, cfl,
2992 filter_intra, smooth_neighbor, pred,3095 filter_intra, smooth_neighbor, pred,
2993 } => exec_intra(3096 } => exec_intra(
2994- y, u, v, plane, x, oy, bw, bh, rect, mode, angle_delta, reach, &residual.resolve(),3097+ y, u, v, plane, x, oy, bw, bh, rect, mode, angle_delta, reach,
3098+ residual.resolve(coeffs, &mut scratch),
2995 cfl, filter_intra, smooth_neighbor, pred, fctx,3099 cfl, filter_intra, smooth_neighbor, pred, fctx,
2996 ),3100 ),
2997 ReconOp::Mc { plane, x, y: oy, stride, w, h, prediction, residual } => {3101 ReconOp::Mc { plane, x, y: oy, stride, w, h, prediction, residual } => {
2998- let residual = residual.resolve();3102+ let residual = residual.resolve(coeffs, &mut scratch);
2999 match prediction {3103 match prediction {
3000- PredSrc::Owned(p) => {3104+ PredSrc::Owned(off, len) => {
3001- exec_mc(y, u, v, plane, x, oy, stride, w, h, &p, &residual, fctx);3105+ let p = &preds[off as usize..][..len as usize];
3106+ exec_mc(y, u, v, plane, x, oy, stride, w, h, p, residual, fctx);
3002 }3107 }
3003 PredSrc::Cur { plane: sp, off, src } => {3108 PredSrc::Cur { plane: sp, off, src } => {
3004 let block = std::mem::take(&mut cur[sp]);3109 let block = std::mem::take(&mut cur[sp]);
3005 if src == stride {3110 if src == stride {
3006- exec_mc(y, u, v, plane, x, oy, stride, w, h, &block[off..], &residual, fctx);3111+ exec_mc(y, u, v, plane, x, oy, stride, w, h, &block[off..], residual, fctx);
3007 } else {3112 } else {
3008 // A transform unit's residual is dense, so its window3113 // A transform unit's residual is dense, so its window
3009 // of the block prediction is taken out dense too --3114 // of the block prediction is taken out dense too --
@@ -3012,7 +3117,7 @@ fn exec_op(
3012 for row in 0..h {3117 for row in 0..h {
3013 window.extend_from_slice(&block[off + row * src..][..w]);3118 window.extend_from_slice(&block[off + row * src..][..w]);
3014 }3119 }
3015- exec_mc(y, u, v, plane, x, oy, stride, w, h, &window, &residual, fctx);3120+ exec_mc(y, u, v, plane, x, oy, stride, w, h, &window, residual, fctx);
3016 }3121 }
3017 cur[sp] = block;3122 cur[sp] = block;
3018 }3123 }
@@ -22121,6 +22226,21 @@ impl PlaneBuf<'_> {
22121 // three row bases are computed once per row instead of a22226 // three row bases are computed once per row instead of a
22122 // multiply-add per sample (the samples themselves are unchanged).22227 // multiply-add per sample (the samples themselves are unchanged).
22123 let max = crate::decode::sample_max(fctx);22228 let max = crate::decode::sample_max(fctx);
22229+ // lane-recoparse: an all-zero residual (60% of the units) is a plain
22230+ // prediction copy -- the same arithmetic with `r == 0`, without
22231+ // reading `side * h` zeros out of [`ZERO_RESIDUAL`].
22232+ if residual.is_empty() {
22233+ for row in 0..h {
22234+ let src = row * side;
22235+ let dst = (y + row) * self.width + x;
22236+ let pred = &prediction[src..src + w];
22237+ let out = &mut self.data.to_mut()[dst..dst + w];
22238+ for (o, &p) in out.iter_mut().zip(pred) {
22239+ *o = i32::from(p).clamp(0, max) as u16;
22240+ }
22241+ }
22242+ return;
22243+ }
22124 let residual = dense_residual(residual, side * h);22244 let residual = dense_residual(residual, side * h);
22125 for row in 0..h {22245 for row in 0..h {
22126 let src = row * side;22246 let src = row * side;