From 3d6af60965840fa9620794ed5f5139f40c564afa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Sat, 5 Sep 2026 05:27:44 +0300 Subject: [PATCH] perf(av1): a deferred transform unit takes its window on the worker, not a strided residual lane-wave4: recording a unit's prediction as an offset into the block made the worker lay its residual out at the block's stride again (a 4x4 unit of a 64-wide block meant a 64x64 i32 grid). The residual stays dense and the worker copies the w x h window out of the block prediction instead -- the copy the parsing thread used to make. Byte-exact, wall unchanged. --- crates/ec-av1/src/decode.rs | 36 +++++++++++++++++++++++++++--------- 1 file changed, 27 insertions(+), 9 deletions(-) diff --git a/crates/ec-av1/src/decode.rs b/crates/ec-av1/src/decode.rs index c3a7e9d6..61482e40 100644 --- a/crates/ec-av1/src/decode.rs +++ b/crates/ec-av1/src/decode.rs @@ -2162,7 +2162,11 @@ impl<'a> Pred<'a> { /// [`Pred`], resolved into what a recorded op carries. pub(crate) enum PredSrc { Owned(Vec), - Cur { plane: usize, off: usize }, + /// A window of the block prediction: its plane, its offset, and the + /// stride it is read at -- which is the block's, not necessarily the + /// op's (a transform unit's residual stays dense, so the worker takes + /// its window out of the block prediction itself). + Cur { plane: usize, off: usize, src: usize }, } /// One block's whole-block prediction build, deferred to a recon worker. @@ -2639,7 +2643,8 @@ fn push_mc_rect_owned( None => { let Pred::Cur { plane: sp, stride: ss, off } = prediction else { unreachable!() }; push_op(fctx, ReconOp::Mc { - plane, x, y, stride: ss, w, h, prediction: PredSrc::Cur { plane: sp, off }, + plane, x, y, stride: ss, w, h, + prediction: PredSrc::Cur { plane: sp, off, src: ss }, residual: Residual::Done(residual), }); return; @@ -2712,7 +2717,8 @@ fn push_mc_rect( None => { let Pred::Cur { plane: sp, stride: ss, off } = prediction else { unreachable!() }; push_op(fctx, ReconOp::Mc { - plane, x, y, stride: ss, w, h, prediction: PredSrc::Cur { plane: sp, off }, + plane, x, y, stride: ss, w, h, + prediction: PredSrc::Cur { plane: sp, off, src: ss }, residual: Residual::Done(residual.to_vec()), }); return; @@ -2785,9 +2791,10 @@ fn push_mc_rect_tx( None => { let Pred::Cur { plane: sp, stride: ss, off } = prediction else { unreachable!() }; let mut tx = tx; - tx.stride = ss; + tx.stride = 0; push_op(fctx, ReconOp::Mc { - plane, x, y, stride: ss, w, h, prediction: PredSrc::Cur { plane: sp, off }, + plane, x, y, stride: w, w, h, + prediction: PredSrc::Cur { plane: sp, off, src: ss }, residual: Residual::Coeffs(tx, grid.to_vec()), }); return; @@ -2884,10 +2891,21 @@ fn exec_op( PredSrc::Owned(p) => { exec_mc(y, u, v, plane, x, oy, stride, w, h, &p, &residual, fctx); } - PredSrc::Cur { plane: sp, off } => { - let src = std::mem::take(&mut cur[sp]); - exec_mc(y, u, v, plane, x, oy, stride, w, h, &src[off..], &residual, fctx); - cur[sp] = src; + PredSrc::Cur { plane: sp, off, src } => { + let block = std::mem::take(&mut cur[sp]); + if src == stride { + exec_mc(y, u, v, plane, x, oy, stride, w, h, &block[off..], &residual, fctx); + } else { + // A transform unit's residual is dense, so its window + // of the block prediction is taken out dense too -- + // the copy the parsing thread used to make, made here. + let mut window = Vec::with_capacity(w * h); + for row in 0..h { + window.extend_from_slice(&block[off + row * src..][..w]); + } + exec_mc(y, u, v, plane, x, oy, stride, w, h, &window, &residual, fctx); + } + cur[sp] = block; } } }