forge
Explore
Log in

Don't you dare go Hollow

The recorded residual moves, and the record queue keeps its capacity

Browse files at this commit

d5fa0c1dfe136570798b743511c569e58c590a07Ahmet Kaan GümüşParent: 1499973
  • perf
    • the recorded residual moves, and the record queue keeps its capacity
Show full message
perf(av1): the recorded residual moves, and the record queue keeps its capacity

Two costs the plain record/replay split paid for nothing: the three fused
coefficient readers copied a residual that is dead the instant it is
recorded (now moved through `push_intra_owned`/`push_mc_rect_owned`), and
`flush_recon` dropped the whole queue's allocation every superblock, so the
next one regrew it from zero (now swapped through `recon_spare`).

seg4k instructions:u 616.06 G -> 614.25 G, seg1080 193.18 G -> 192.37 G.
Byte-exact on all four gate inputs, unchanged.
crates/ec-av1/src/decode.rsmodified+53 -6
@@ -82,6 +82,9 @@ pub(crate) struct FrameCtx {
8282 /// lane-wave1 step (i): this superblock's recorded pixel writes, see
8383 /// [`ReconOp`]. Pushed by parse, replayed by [`flush_recon`].
8484 pub(crate) recon_ops: std::cell::RefCell<Vec<ReconOp>>,
85+ /// The queue buffer [`flush_recon`] just drained, kept for its capacity
86+ /// so a superblock's records do not regrow the vector from nothing.
87+ pub(crate) recon_spare: std::cell::RefCell<Vec<ReconOp>>,
8588 }
8689
8790 impl std::fmt::Debug for FrameCtx {
@@ -140,6 +143,7 @@ impl FrameCtx {
140143 reach_sb_px: std::cell::Cell::new(crate::encode::SUPERBLOCK),
141144 grain_bit_depth: std::cell::Cell::new(8),
142145 recon_ops: std::cell::RefCell::new(Vec::new()),
146+ recon_spare: std::cell::RefCell::new(Vec::new()),
143147 }
144148 }
145149 }
@@ -2103,6 +2107,46 @@ fn push_intra(
21032107 });
21042108 }
21052109
2110+/// [`push_intra`] for a caller whose residual is dead after the record --
2111+/// the three fused coefficient readers, i.e. nearly every recorded write.
2112+#[allow(clippy::too_many_arguments)]
2113+fn push_intra_owned(
2114+ plane: usize,
2115+ x: usize,
2116+ y: usize,
2117+ side: usize,
2118+ mode: usize,
2119+ angle_delta: i32,
2120+ reach: Reach,
2121+ residual: Vec<i32>,
2122+ cfl: Option<(i32, CflSrc)>,
2123+ filter_intra: Option<usize>,
2124+ smooth_neighbor: bool, fctx: &crate::decode::FrameCtx,
2125+) {
2126+ let pred = take_palette_pred(fctx);
2127+ push_op(fctx, ReconOp::Intra {
2128+ plane, x, y, bw: side, bh: side, rect: false, mode, angle_delta, reach,
2129+ residual, cfl, filter_intra, smooth_neighbor, pred,
2130+ });
2131+}
2132+
2133+/// [`push_mc_rect`] with the residual moved in -- see [`push_intra_owned`].
2134+#[allow(clippy::too_many_arguments)]
2135+fn push_mc_rect_owned(
2136+ plane: usize,
2137+ x: usize,
2138+ y: usize,
2139+ stride: usize,
2140+ w: usize,
2141+ h: usize,
2142+ prediction: &[u16],
2143+ residual: Vec<i32>, fctx: &crate::decode::FrameCtx,
2144+) {
2145+ push_op(fctx, ReconOp::Mc {
2146+ plane, x, y, stride, w, h, prediction: prediction.to_vec(), residual,
2147+ });
2148+}
2149+
21062150 /// [`PlaneBuf::reconstruct_rect`], recorded (lane-wave1 step (i)).
21072151 #[allow(clippy::too_many_arguments)]
21082152 fn push_intra_rect(
@@ -2170,8 +2214,9 @@ fn flush_recon(
21702214 u: &mut PlaneBuf<'static>,
21712215 v: &mut PlaneBuf<'static>,
21722216 ) {
2173- let ops = fctx.recon_ops.with(|c| std::mem::take(&mut *c.borrow_mut()));
2174- for op in ops {
2217+ let mut ops = fctx.recon_spare.with(|c| std::mem::take(&mut *c.borrow_mut()));
2218+ fctx.recon_ops.with(|c| std::mem::swap(&mut *c.borrow_mut(), &mut ops));
2219+ for op in ops.drain(..) {
21752220 match op {
21762221 ReconOp::Intra {
21772222 plane, x, y: oy, bw, bh, rect, mode, angle_delta, reach, residual, cfl,
@@ -2210,6 +2255,7 @@ fn flush_recon(
22102255 }
22112256 }
22122257 }
2258+ fctx.recon_spare.with(|c| *c.borrow_mut() = ops);
22132259 }
22142260
22152261 thread_local! {
@@ -12233,14 +12279,15 @@ fn read_plane(
1223312279 "TRACE dequant plane={plane_idx} base_q_idx={base_q_idx} tx_type={tx_type:?} side={side} levels={levels:?} residual={residual:?}",
1223412280 );
1223512281 }
12236- push_intra(plane_idx,
12282+ push_intra_owned(
12283+ plane_idx,
1223712284 x,
1223812285 y,
1223912286 side,
1224012287 predict_mode,
1224112288 angle_delta,
1224212289 reach,
12243- &residual,
12290+ residual,
1224412291 cfl,
1224512292 filter_intra,
1224612293 smooth_neighbor, fctx,
@@ -16450,7 +16497,7 @@ fn read_inter_plane_rect(
1645016497 for row in 0..h {
1645116498 strided[row * stride..][..w].copy_from_slice(&residual[row * w..][..w]);
1645216499 }
16453- push_mc_rect(plane_idx, x, y, stride, w, h, prediction, &strided, fctx);
16500+ push_mc_rect_owned(plane_idx, x, y, stride, w, h, prediction, strided, fctx);
1645416501 Ok((grid, tx_type))
1645516502 }
1645616503
@@ -20943,7 +20990,7 @@ fn read_inter_plane(
2094320990 };
2094420991 let (dc_delta, ac_delta) = plane_q_delta(plane_idx, fctx);
2094520992 let residual = dequant_and_inverse_typed(&grid, side, bit_depth(fctx), block_q_idx(fctx), dc_delta, ac_delta, tx_type);
20946- push_mc(plane_idx, x, y, side, prediction, &residual, fctx);
20993+ push_mc_rect_owned(plane_idx, x, y, side, side, side, prediction, residual, fctx);
2094720994 Ok((grid, tx_type))
2094820995 }
2094920996