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 {
82 /// lane-wave1 step (i): this superblock's recorded pixel writes, see82 /// lane-wave1 step (i): this superblock's recorded pixel writes, see
83 /// [`ReconOp`]. Pushed by parse, replayed by [`flush_recon`].83 /// [`ReconOp`]. Pushed by parse, replayed by [`flush_recon`].
84 pub(crate) recon_ops: std::cell::RefCell<Vec<ReconOp>>,84 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>>,
85 }88 }
86 89
87 impl std::fmt::Debug for FrameCtx {90 impl std::fmt::Debug for FrameCtx {
@@ -140,6 +143,7 @@ impl FrameCtx {
140 reach_sb_px: std::cell::Cell::new(crate::encode::SUPERBLOCK),143 reach_sb_px: std::cell::Cell::new(crate::encode::SUPERBLOCK),
141 grain_bit_depth: std::cell::Cell::new(8),144 grain_bit_depth: std::cell::Cell::new(8),
142 recon_ops: std::cell::RefCell::new(Vec::new()),145 recon_ops: std::cell::RefCell::new(Vec::new()),
146+ recon_spare: std::cell::RefCell::new(Vec::new()),
143 }147 }
144 }148 }
145 }149 }
@@ -2103,6 +2107,46 @@ fn push_intra(
2103 });2107 });
2104 }2108 }
2105 2109
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+
2106 /// [`PlaneBuf::reconstruct_rect`], recorded (lane-wave1 step (i)).2150 /// [`PlaneBuf::reconstruct_rect`], recorded (lane-wave1 step (i)).
2107 #[allow(clippy::too_many_arguments)]2151 #[allow(clippy::too_many_arguments)]
2108 fn push_intra_rect(2152 fn push_intra_rect(
@@ -2170,8 +2214,9 @@ fn flush_recon(
2170 u: &mut PlaneBuf<'static>,2214 u: &mut PlaneBuf<'static>,
2171 v: &mut PlaneBuf<'static>,2215 v: &mut PlaneBuf<'static>,
2172 ) {2216 ) {
2173- let ops = fctx.recon_ops.with(|c| std::mem::take(&mut *c.borrow_mut()));2217+ let mut ops = fctx.recon_spare.with(|c| std::mem::take(&mut *c.borrow_mut()));
2174- for op in ops {2218+ fctx.recon_ops.with(|c| std::mem::swap(&mut *c.borrow_mut(), &mut ops));
2219+ for op in ops.drain(..) {
2175 match op {2220 match op {
2176 ReconOp::Intra {2221 ReconOp::Intra {
2177 plane, x, y: oy, bw, bh, rect, mode, angle_delta, reach, residual, cfl,2222 plane, x, y: oy, bw, bh, rect, mode, angle_delta, reach, residual, cfl,
@@ -2210,6 +2255,7 @@ fn flush_recon(
2210 }2255 }
2211 }2256 }
2212 }2257 }
2258+ fctx.recon_spare.with(|c| *c.borrow_mut() = ops);
2213 }2259 }
2214 2260
2215 thread_local! {2261 thread_local! {
@@ -12233,14 +12279,15 @@ fn read_plane(
12233 "TRACE dequant plane={plane_idx} base_q_idx={base_q_idx} tx_type={tx_type:?} side={side} levels={levels:?} residual={residual:?}",12279 "TRACE dequant plane={plane_idx} base_q_idx={base_q_idx} tx_type={tx_type:?} side={side} levels={levels:?} residual={residual:?}",
12234 );12280 );
12235 }12281 }
12236- push_intra(plane_idx, 12282+ push_intra_owned(
12283+ plane_idx,
12237 x,12284 x,
12238 y,12285 y,
12239 side,12286 side,
12240 predict_mode,12287 predict_mode,
12241 angle_delta,12288 angle_delta,
12242 reach,12289 reach,
12243- &residual,12290+ residual,
12244 cfl,12291 cfl,
12245 filter_intra,12292 filter_intra,
12246 smooth_neighbor, fctx,12293 smooth_neighbor, fctx,
@@ -16450,7 +16497,7 @@ fn read_inter_plane_rect(
16450 for row in 0..h {16497 for row in 0..h {
16451 strided[row * stride..][..w].copy_from_slice(&residual[row * w..][..w]);16498 strided[row * stride..][..w].copy_from_slice(&residual[row * w..][..w]);
16452 }16499 }
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);
16454 Ok((grid, tx_type))16501 Ok((grid, tx_type))
16455 }16502 }
16456 16503
@@ -20943,7 +20990,7 @@ fn read_inter_plane(
20943 };20990 };
20944 let (dc_delta, ac_delta) = plane_q_delta(plane_idx, fctx);20991 let (dc_delta, ac_delta) = plane_q_delta(plane_idx, fctx);
20945 let residual = dequant_and_inverse_typed(&grid, side, bit_depth(fctx), block_q_idx(fctx), dc_delta, ac_delta, tx_type);20992 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);
20947 Ok((grid, tx_type))20994 Ok((grid, tx_type))
20948 }20995 }
20949 20996