forge
Explore
Log in

Don't you dare go Hollow

Merge branch 'lane-wave1' (384ed8e6): reconstruction recorded as replayable ops with an inline fast path at one recon thread; superblock-row wavefront workers behind EC_AV1_RECON_THREADS (default 1, measured no gain yet: parse still builds predictions); byte-exact at all thread settings, default path 0.6% fewer instructions

Browse files at this commit

34a3d010e734c1a8a7ebbfaab58a1dc9bf0c65f0Ahmet Kaan GümüşParent: 1a45793c28f320
crates/ec-av1/src/decode.rsmodified+924 -187

Diff too large; view file

@@ -79,6 +79,20 @@ pub(crate) struct FrameCtx {
7979 pub(crate) last_frame_wide_margin: std::cell::RefCell<Option<Picture>>,
8080 pub(crate) reach_sb_px: std::cell::Cell<usize>,
8181 pub(crate) grain_bit_depth: std::cell::Cell<u32>,
82+ /// lane-wave1 step (i): this superblock's recorded pixel writes, see
83+ /// [`ReconOp`]. Pushed by parse, replayed by [`flush_recon`].
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>>,
88+ /// lane-wave1 step (ii): the tile decoder's own planes, registered by
89+ /// [`ReconInline`] while reconstruction runs INLINE (one recon thread).
90+ /// `None` while the queue is in use (wavefront workers) and outside a
91+ /// tile. See [`push_op`].
92+ pub(crate) recon_planes: std::cell::Cell<Option<ReconPlanes>>,
93+ /// lane-wave1 step (ii): the superblock wavefront this tile's recorded
94+ /// writes are handed to, at more than one reconstruction thread.
95+ pub(crate) wave: std::cell::RefCell<Option<std::sync::Arc<WaveState>>>,
8296 }
8397
8498 impl std::fmt::Debug for FrameCtx {
@@ -136,6 +150,10 @@ impl FrameCtx {
136150 last_frame_wide_margin: std::cell::RefCell::new(None),
137151 reach_sb_px: std::cell::Cell::new(crate::encode::SUPERBLOCK),
138152 grain_bit_depth: std::cell::Cell::new(8),
153+ recon_ops: std::cell::RefCell::new(Vec::new()),
154+ recon_spare: std::cell::RefCell::new(Vec::new()),
155+ recon_planes: std::cell::Cell::new(None),
156+ wave: std::cell::RefCell::new(None),
139157 }
140158 }
141159 }
@@ -2010,6 +2028,635 @@ fn take_palette_pred(fctx: &crate::decode::FrameCtx) -> Option<Vec<u16>> {
20102028 got
20112029 }
20122030
2031+/// The luma window a `UV_CFL_PRED` chroma block averages its AC signal over
2032+/// (lane-wave1 step (i)). Parse records the window; [`flush_recon`] reads the
2033+/// pixels, because at parse time this block's own luma is still queued.
2034+#[derive(Clone, Copy, Debug)]
2035+pub(crate) struct CflSrc {
2036+ px: usize,
2037+ py: usize,
2038+ bw: usize,
2039+ bh: usize,
2040+ /// Which averager the parse site asked for -- [`cfl_ac_q3_rect`] and
2041+ /// [`cfl_ac_q3`] are not the same function at `bw == bh`.
2042+ rect: bool,
2043+}
2044+
2045+fn cfl_src(px: usize, py: usize, side: usize) -> CflSrc {
2046+ CflSrc { px, py, bw: side, bh: side, rect: false }
2047+}
2048+
2049+fn cfl_src_rect(px: usize, py: usize, bw: usize, bh: usize) -> CflSrc {
2050+ CflSrc { px, py, bw, bh, rect: true }
2051+}
2052+
2053+/// lane-wave1 step (i): the pixel-writing half of block decoding, recorded
2054+/// instead of executed. Each variant is the resolved argument tuple of the
2055+/// `PlaneBuf::reconstruct*` call it replaces, so replaying the queue in push
2056+/// order performs exactly the same writes in exactly the same order --
2057+/// entropy parsing no longer touches the frame's own planes (except the two
2058+/// sites named in [`flush_recon`]'s doc), which is what lets step (ii) run
2059+/// the replay on a superblock-row wavefront worker.
2060+pub(crate) enum ReconOp {
2061+ Intra {
2062+ plane: usize,
2063+ x: usize,
2064+ y: usize,
2065+ bw: usize,
2066+ bh: usize,
2067+ /// `true` when the parse site called `reconstruct_rect` (whose
2068+ /// `edges_rect` differs from `edges` even at `bw == bh`).
2069+ rect: bool,
2070+ mode: usize,
2071+ angle_delta: i32,
2072+ reach: Reach,
2073+ residual: Vec<i32>,
2074+ cfl: Option<(i32, CflSrc)>,
2075+ filter_intra: Option<usize>,
2076+ smooth_neighbor: bool,
2077+ /// The palette/intrabc prediction override, taken off
2078+ /// [`FrameCtx::palette_pred`] at PUSH time (parse order), never read
2079+ /// from that slot by the replay.
2080+ pred: Option<Vec<u16>>,
2081+ },
2082+ Mc {
2083+ plane: usize,
2084+ x: usize,
2085+ y: usize,
2086+ stride: usize,
2087+ w: usize,
2088+ h: usize,
2089+ prediction: Vec<u16>,
2090+ residual: Vec<i32>,
2091+ },
2092+}
2093+
2094+/// The three planes of the tile currently being decoded, as raw pointers.
2095+///
2096+/// corner-cut: at one reconstruction thread a recorded write must cost
2097+/// nothing -- deferring it to the end of the superblock is +1.2%
2098+/// instructions and +4.5% wall on 4K, because the residual is written at
2099+/// parse and read back cache-cold at replay. So the recorded op is performed
2100+/// at the push site instead, through the pointers the tile decoder registers
2101+/// once ([`ReconInline`]), which is the same thread, the same order and the
2102+/// same writes as before lane-wave1 -- but the `&mut PlaneBuf` the parse
2103+/// stack still holds aliases them, exactly the [`crate::par::Shared`]
2104+/// trade-off (Miri's stacked borrows would flag both). The upgrade path is
2105+/// threading the three planes down every `read_plane`/`read_inter_plane`
2106+/// call site (~40) so the push site owns the borrow it writes through.
2107+#[derive(Clone, Copy)]
2108+pub(crate) struct ReconPlanes(
2109+ *mut PlaneBuf<'static>,
2110+ *mut PlaneBuf<'static>,
2111+ *mut PlaneBuf<'static>,
2112+);
2113+
2114+// SAFETY: a `FrameCtx` sent to another thread (a frame worker, or
2115+// [`filter_ctx_copy`]) is always one whose guard is not installed, so the
2116+// value travelling is `None`; the pointers never leave the tile decoder's
2117+// own thread.
2118+#[allow(unsafe_code)]
2119+unsafe impl Send for ReconPlanes {}
2120+// SAFETY: the wavefront's workers share one `ReconPlanes` and write provably
2121+// disjoint superblocks of it (see [`WaveState`]) -- the [`crate::par::Shared`]
2122+// contract, one superblock per band instead of one row band.
2123+#[allow(unsafe_code)]
2124+unsafe impl Sync for ReconPlanes {}
2125+
2126+/// Registers the tile's planes for inline reconstruction and unregisters them
2127+/// on every exit from the tile decoder, including the `?` ones -- a stale
2128+/// pointer here would outlive the planes, since [`FrameCtx`] outlives the
2129+/// tile.
2130+pub(crate) struct ReconInline<'a>(&'a crate::decode::FrameCtx);
2131+
2132+#[allow(unsafe_code)]
2133+impl<'a> ReconInline<'a> {
2134+ /// Installs the guard for this tile when reconstruction is inline
2135+ /// (`EC_AV1_RECON_THREADS == 1`, the default); `None` hands every write
2136+ /// to the queue instead, for the wavefront workers to replay.
2137+ fn install(
2138+ fctx: &'a crate::decode::FrameCtx,
2139+ y: &mut PlaneBuf<'static>,
2140+ u: &mut PlaneBuf<'static>,
2141+ v: &mut PlaneBuf<'static>,
2142+ ) -> Option<Self> {
2143+ if crate::par::recon_threads() != 1 {
2144+ return None;
2145+ }
2146+ // SAFETY: the planes are locals of the tile decoder and outlive the
2147+ // guard, which is dropped on every exit from it (including `?`); see
2148+ // [`ReconPlanes`] for the aliasing trade-off.
2149+ let planes = ReconPlanes(
2150+ std::ptr::from_mut(y),
2151+ std::ptr::from_mut(u),
2152+ std::ptr::from_mut(v),
2153+ );
2154+ fctx.recon_planes.with(|c| c.set(Some(planes)));
2155+ Some(Self(fctx))
2156+ }
2157+}
2158+
2159+impl Drop for ReconInline<'_> {
2160+ fn drop(&mut self) {
2161+ self.0.recon_planes.with(|c| c.set(None));
2162+ }
2163+}
2164+
2165+#[allow(unsafe_code)]
2166+fn push_op(fctx: &crate::decode::FrameCtx, op: ReconOp) {
2167+ if let Some(ReconPlanes(y, u, v)) = fctx.recon_planes.with(std::cell::Cell::get) {
2168+ // SAFETY: see [`ReconPlanes`] -- one thread, and the write is the one
2169+ // the parse site would have performed itself before lane-wave1.
2170+ unsafe { exec_op(op, &mut *y, &mut *u, &mut *v, fctx) };
2171+ return;
2172+ }
2173+ fctx.recon_ops.with(|c| c.borrow_mut().push(op));
2174+}
2175+
2176+/// lane-wave1 step (ii): the superblock-row wavefront a tile's recorded
2177+/// writes are reconstructed on when `EC_AV1_RECON_THREADS > 1`.
2178+///
2179+/// The parser keeps parsing and never touches the planes; each superblock's
2180+/// drained `Vec<ReconOp>` becomes one job, keyed by the superblock's own
2181+/// `(row, column)` inside the tile (128x128 superblocks are one job for all
2182+/// four of their 64x64 visits, since a 128 block writes across quadrants).
2183+/// A worker may start job `(r, c)` once `(r - 1, min(c + 1, last_col))` and
2184+/// `(r, c - 1)` are complete -- the classic wavefront rule, which covers
2185+/// every pixel an intra predictor can read (its edges reach one block right
2186+/// along the row above and one block down the column to the left, both
2187+/// inside those two neighbours) and every CfL AC read (this block's own
2188+/// luma, written by this same job). Jobs are handed out in raster order, so
2189+/// the oldest outstanding one always has its dependencies met: no deadlock.
2190+///
2191+/// Gate counters incremented inside `reconstruct*`/`intra`/`mc` are
2192+/// `thread_local!` and miss every worker, which is why the default is 1.
2193+pub(crate) struct WaveState {
2194+ q: std::sync::Mutex<WaveQueue>,
2195+ cv: std::sync::Condvar,
2196+ planes: ReconPlanes,
2197+ /// The two [`FrameCtx`] fields reconstruction reads (`sample_max` is
2198+ /// `bit_depth`'s; everything else a `reconstruct*` needs is in the op).
2199+ bit_depth: u8,
2200+ enable_edge_filter: bool,
2201+ last_col: usize,
2202+}
2203+
2204+struct WaveQueue {
2205+ jobs: std::collections::VecDeque<(usize, usize, Vec<ReconOp>)>,
2206+ /// Per superblock row, the last column reconstructed (-1 = none yet).
2207+ done: Vec<isize>,
2208+ /// Jobs popped but not finished -- what [`wave_barrier`] waits out.
2209+ active: usize,
2210+ closed: bool,
2211+}
2212+
2213+#[allow(unsafe_code)]
2214+fn wave_worker(st: &WaveState) {
2215+ let fctx = FrameCtx::new();
2216+ fctx.bit_depth.set(st.bit_depth);
2217+ fctx.enable_edge_filter.set(st.enable_edge_filter);
2218+ loop {
2219+ let mut q = st.q.lock().unwrap();
2220+ let (r, c, ops) = loop {
2221+ if let Some(job) = q.jobs.pop_front() {
2222+ break job;
2223+ }
2224+ if q.closed {
2225+ return;
2226+ }
2227+ q = st.cv.wait(q).unwrap();
2228+ };
2229+ q.active += 1;
2230+ loop {
2231+ let above = r == 0 || q.done[r - 1] >= (c + 1).min(st.last_col) as isize;
2232+ let left = c == 0 || q.done[r] >= c as isize - 1;
2233+ if above && left {
2234+ break;
2235+ }
2236+ q = st.cv.wait(q).unwrap();
2237+ }
2238+ drop(q);
2239+ let ReconPlanes(y, u, v) = st.planes;
2240+ // SAFETY: this job writes only superblock (r, c)'s own pixels, and
2241+ // every superblock that could have written or be reading them is
2242+ // complete by the wavefront rule above.
2243+ unsafe {
2244+ for op in ops {
2245+ exec_op(op, &mut *y, &mut *u, &mut *v, &fctx);
2246+ }
2247+ }
2248+ let mut q = st.q.lock().unwrap();
2249+ q.done[r] = c as isize;
2250+ q.active -= 1;
2251+ st.cv.notify_all();
2252+ }
2253+}
2254+
2255+/// Installs the wavefront for one tile and joins its workers on every exit
2256+/// from the tile decoder, including the `?` ones -- the jobs hold raw
2257+/// pointers into the tile's planes, so no worker may outlive them.
2258+pub(crate) struct WaveGuard<'a>(&'a crate::decode::FrameCtx, Vec<std::thread::JoinHandle<()>>);
2259+
2260+#[allow(unsafe_code)]
2261+impl<'a> WaveGuard<'a> {
2262+ fn install(
2263+ fctx: &'a crate::decode::FrameCtx,
2264+ y: &mut PlaneBuf<'static>,
2265+ u: &mut PlaneBuf<'static>,
2266+ v: &mut PlaneBuf<'static>,
2267+ rows: usize,
2268+ cols: usize,
2269+ ) -> Option<Self> {
2270+ let threads = crate::par::recon_threads();
2271+ if threads == 1 || rows == 0 || cols == 0 {
2272+ return None;
2273+ }
2274+ let st = std::sync::Arc::new(WaveState {
2275+ q: std::sync::Mutex::new(WaveQueue {
2276+ jobs: std::collections::VecDeque::new(),
2277+ done: vec![-1; rows],
2278+ active: 0,
2279+ closed: false,
2280+ }),
2281+ cv: std::sync::Condvar::new(),
2282+ // SAFETY: the planes are locals of the tile decoder and outlive
2283+ // this guard, which joins every worker in `drop`.
2284+ planes: ReconPlanes(
2285+ std::ptr::from_mut(y),
2286+ std::ptr::from_mut(u),
2287+ std::ptr::from_mut(v),
2288+ ),
2289+ bit_depth: fctx.bit_depth.with(std::cell::Cell::get),
2290+ enable_edge_filter: fctx.enable_edge_filter.with(std::cell::Cell::get),
2291+ last_col: cols - 1,
2292+ });
2293+ let workers = (0..threads)
2294+ .map(|_| {
2295+ let st = std::sync::Arc::clone(&st);
2296+ std::thread::spawn(move || wave_worker(&st))
2297+ })
2298+ .collect();
2299+ fctx.wave.with(|w| *w.borrow_mut() = Some(st));
2300+ Some(Self(fctx, workers))
2301+ }
2302+}
2303+
2304+impl Drop for WaveGuard<'_> {
2305+ fn drop(&mut self) {
2306+ let st = self.0.wave.with(|w| w.borrow_mut().take());
2307+ if let Some(st) = st {
2308+ st.q.lock().unwrap().closed = true;
2309+ st.cv.notify_all();
2310+ }
2311+ for h in self.1.drain(..) {
2312+ let _ = h.join();
2313+ }
2314+ }
2315+}
2316+
2317+/// Hands superblock `(r, c)`'s recorded writes to the wavefront. `false`
2318+/// when there is no wavefront (one reconstruction thread), in which case the
2319+/// caller replays them itself.
2320+fn wave_submit(fctx: &crate::decode::FrameCtx, r: usize, c: usize) -> bool {
2321+ let st = fctx.wave.with(|w| w.borrow().clone());
2322+ let Some(st) = st else { return false };
2323+ let ops = fctx.recon_ops.with(|c| std::mem::take(&mut *c.borrow_mut()));
2324+ if !ops.is_empty() {
2325+ st.q.lock().unwrap().jobs.push_back((r, c, ops));
2326+ st.cv.notify_all();
2327+ }
2328+ true
2329+}
2330+
2331+/// Waits until every submitted job is reconstructed, so the parser may read
2332+/// the planes itself (the intrabc source fetch and the interintra intra
2333+/// predictor -- see [`flush_recon`]).
2334+fn wave_barrier(fctx: &crate::decode::FrameCtx) {
2335+ let st = fctx.wave.with(|w| w.borrow().clone());
2336+ let Some(st) = st else { return };
2337+ let mut q = st.q.lock().unwrap();
2338+ while !q.jobs.is_empty() || q.active > 0 {
2339+ q = st.cv.wait(q).unwrap();
2340+ }
2341+}
2342+
2343+/// Performs an intra write at its push site when the tile registered its
2344+/// planes for inline reconstruction ([`ReconPlanes`]); `false` when the
2345+/// caller must record it for the wavefront workers instead.
2346+#[allow(unsafe_code)]
2347+#[allow(clippy::too_many_arguments)]
2348+fn inline_intra(
2349+ plane: usize,
2350+ x: usize,
2351+ oy: usize,
2352+ bw: usize,
2353+ bh: usize,
2354+ rect: bool,
2355+ mode: usize,
2356+ angle_delta: i32,
2357+ reach: Reach,
2358+ residual: &[i32],
2359+ cfl: Option<(i32, CflSrc)>,
2360+ filter_intra: Option<usize>,
2361+ smooth_neighbor: bool,
2362+ fctx: &crate::decode::FrameCtx,
2363+) -> bool {
2364+ let Some(ReconPlanes(y, u, v)) = fctx.recon_planes.with(std::cell::Cell::get) else {
2365+ return false;
2366+ };
2367+ let pred = take_palette_pred(fctx);
2368+ // SAFETY: see [`ReconPlanes`].
2369+ unsafe {
2370+ exec_intra(
2371+ &mut *y, &mut *u, &mut *v, plane, x, oy, bw, bh, rect, mode, angle_delta, reach,
2372+ residual, cfl, filter_intra, smooth_neighbor, pred, fctx,
2373+ );
2374+ }
2375+ true
2376+}
2377+
2378+/// [`inline_intra`] for a motion-compensated write.
2379+#[allow(unsafe_code)]
2380+#[allow(clippy::too_many_arguments)]
2381+fn inline_mc(
2382+ plane: usize,
2383+ x: usize,
2384+ oy: usize,
2385+ stride: usize,
2386+ w: usize,
2387+ h: usize,
2388+ prediction: &[u16],
2389+ residual: &[i32],
2390+ fctx: &crate::decode::FrameCtx,
2391+) -> bool {
2392+ let Some(ReconPlanes(y, u, v)) = fctx.recon_planes.with(std::cell::Cell::get) else {
2393+ return false;
2394+ };
2395+ // SAFETY: see [`ReconPlanes`].
2396+ unsafe {
2397+ exec_mc(&mut *y, &mut *u, &mut *v, plane, x, oy, stride, w, h, prediction, residual, fctx);
2398+ }
2399+ true
2400+}
2401+
2402+/// [`PlaneBuf::reconstruct`], recorded (lane-wave1 step (i)).
2403+#[allow(clippy::too_many_arguments)]
2404+fn push_intra(
2405+ plane: usize,
2406+ x: usize,
2407+ y: usize,
2408+ side: usize,
2409+ mode: usize,
2410+ angle_delta: i32,
2411+ reach: Reach,
2412+ residual: &[i32],
2413+ cfl: Option<(i32, CflSrc)>,
2414+ filter_intra: Option<usize>,
2415+ smooth_neighbor: bool, fctx: &crate::decode::FrameCtx,
2416+) {
2417+ if inline_intra(
2418+ plane, x, y, side, side, false, mode, angle_delta, reach, residual, cfl, filter_intra,
2419+ smooth_neighbor, fctx,
2420+ ) {
2421+ return;
2422+ }
2423+ let pred = take_palette_pred(fctx);
2424+ push_op(fctx, ReconOp::Intra {
2425+ plane, x, y, bw: side, bh: side, rect: false, mode, angle_delta, reach,
2426+ residual: residual.to_vec(), cfl, filter_intra, smooth_neighbor, pred,
2427+ });
2428+}
2429+
2430+/// [`push_intra`] for a caller whose residual is dead after the record --
2431+/// the three fused coefficient readers, i.e. nearly every recorded write.
2432+#[allow(clippy::too_many_arguments)]
2433+fn push_intra_owned(
2434+ plane: usize,
2435+ x: usize,
2436+ y: usize,
2437+ side: usize,
2438+ mode: usize,
2439+ angle_delta: i32,
2440+ reach: Reach,
2441+ residual: Vec<i32>,
2442+ cfl: Option<(i32, CflSrc)>,
2443+ filter_intra: Option<usize>,
2444+ smooth_neighbor: bool, fctx: &crate::decode::FrameCtx,
2445+) {
2446+ if inline_intra(
2447+ plane, x, y, side, side, false, mode, angle_delta, reach, &residual, cfl, filter_intra,
2448+ smooth_neighbor, fctx,
2449+ ) {
2450+ return;
2451+ }
2452+ let pred = take_palette_pred(fctx);
2453+ push_op(fctx, ReconOp::Intra {
2454+ plane, x, y, bw: side, bh: side, rect: false, mode, angle_delta, reach,
2455+ residual, cfl, filter_intra, smooth_neighbor, pred,
2456+ });
2457+}
2458+
2459+/// [`push_mc_rect`] with the residual moved in -- see [`push_intra_owned`].
2460+#[allow(clippy::too_many_arguments)]
2461+fn push_mc_rect_owned(
2462+ plane: usize,
2463+ x: usize,
2464+ y: usize,
2465+ stride: usize,
2466+ w: usize,
2467+ h: usize,
2468+ prediction: &[u16],
2469+ residual: Vec<i32>, fctx: &crate::decode::FrameCtx,
2470+) {
2471+ if inline_mc(plane, x, y, stride, w, h, prediction, &residual, fctx) {
2472+ return;
2473+ }
2474+ push_op(fctx, ReconOp::Mc {
2475+ plane, x, y, stride, w, h, prediction: prediction.to_vec(), residual,
2476+ });
2477+}
2478+
2479+/// [`PlaneBuf::reconstruct_rect`], recorded (lane-wave1 step (i)).
2480+#[allow(clippy::too_many_arguments)]
2481+fn push_intra_rect(
2482+ plane: usize,
2483+ x: usize,
2484+ y: usize,
2485+ bw: usize,
2486+ bh: usize,
2487+ mode: usize,
2488+ angle_delta: i32,
2489+ reach: Reach,
2490+ residual: &[i32],
2491+ cfl: Option<(i32, CflSrc)>,
2492+ filter_intra: Option<usize>,
2493+ smooth_neighbor: bool, fctx: &crate::decode::FrameCtx,
2494+) {
2495+ if inline_intra(
2496+ plane, x, y, bw, bh, true, mode, angle_delta, reach, residual, cfl, filter_intra,
2497+ smooth_neighbor, fctx,
2498+ ) {
2499+ return;
2500+ }
2501+ let pred = take_palette_pred(fctx);
2502+ push_op(fctx, ReconOp::Intra {
2503+ plane, x, y, bw, bh, rect: true, mode, angle_delta, reach,
2504+ residual: residual.to_vec(), cfl, filter_intra, smooth_neighbor, pred,
2505+ });
2506+}
2507+
2508+/// [`PlaneBuf::reconstruct_mc_rect`] at `stride == w == h == side`, recorded.
2509+fn push_mc(
2510+ plane: usize,
2511+ x: usize,
2512+ y: usize,
2513+ side: usize,
2514+ prediction: &[u16],
2515+ residual: &[i32], fctx: &crate::decode::FrameCtx,
2516+) {
2517+ push_mc_rect(plane, x, y, side, side, side, prediction, residual, fctx);
2518+}
2519+
2520+/// [`PlaneBuf::reconstruct_mc_rect`], recorded (lane-wave1 step (i)).
2521+#[allow(clippy::too_many_arguments)]
2522+fn push_mc_rect(
2523+ plane: usize,
2524+ x: usize,
2525+ y: usize,
2526+ stride: usize,
2527+ w: usize,
2528+ h: usize,
2529+ prediction: &[u16],
2530+ residual: &[i32], fctx: &crate::decode::FrameCtx,
2531+) {
2532+ if inline_mc(plane, x, y, stride, w, h, prediction, residual, fctx) {
2533+ return;
2534+ }
2535+ push_op(fctx, ReconOp::Mc {
2536+ plane, x, y, stride, w, h,
2537+ prediction: prediction.to_vec(), residual: residual.to_vec(),
2538+ });
2539+}
2540+
2541+/// Replays every recorded [`ReconOp`] into the frame's planes, in push order,
2542+/// and empties the queue (lane-wave1 step (i)).
2543+///
2544+/// Called at the top of each superblock visit and at the end of each tile, so
2545+/// a whole superblock's parsing runs with no plane access at all; the two
2546+/// parse-time pixel READS that survive -- the intrabc source fetch and the
2547+/// interintra intra predictor -- flush ahead of themselves instead, which
2548+/// keeps them byte-exact and names exactly what step (ii) still has to move.
2549+fn flush_recon(
2550+ fctx: &crate::decode::FrameCtx,
2551+ y: &mut PlaneBuf<'static>,
2552+ u: &mut PlaneBuf<'static>,
2553+ v: &mut PlaneBuf<'static>,
2554+) {
2555+ // lane-wave1 step (ii): a parse-time pixel READ needs every worker's
2556+ // writes in place, not just this superblock's queue.
2557+ wave_barrier(fctx);
2558+ let mut ops = fctx.recon_spare.with(|c| std::mem::take(&mut *c.borrow_mut()));
2559+ fctx.recon_ops.with(|c| std::mem::swap(&mut *c.borrow_mut(), &mut ops));
2560+ for op in ops.drain(..) {
2561+ exec_op(op, y, u, v, fctx);
2562+ }
2563+ fctx.recon_spare.with(|c| *c.borrow_mut() = ops);
2564+}
2565+
2566+/// Performs one recorded write: the body [`flush_recon`] replays, and the
2567+/// body [`push_op`] runs immediately when reconstruction is inline.
2568+fn exec_op(
2569+ op: ReconOp,
2570+ y: &mut PlaneBuf<'static>,
2571+ u: &mut PlaneBuf<'static>,
2572+ v: &mut PlaneBuf<'static>,
2573+ fctx: &crate::decode::FrameCtx,
2574+) {
2575+ match op {
2576+ ReconOp::Intra {
2577+ plane, x, y: oy, bw, bh, rect, mode, angle_delta, reach, residual, cfl,
2578+ filter_intra, smooth_neighbor, pred,
2579+ } => exec_intra(
2580+ y, u, v, plane, x, oy, bw, bh, rect, mode, angle_delta, reach, &residual, cfl,
2581+ filter_intra, smooth_neighbor, pred, fctx,
2582+ ),
2583+ ReconOp::Mc { plane, x, y: oy, stride, w, h, prediction, residual } => {
2584+ exec_mc(y, u, v, plane, x, oy, stride, w, h, &prediction, &residual, fctx);
2585+ }
2586+ }
2587+}
2588+
2589+/// [`ReconOp::Intra`] performed. Its arguments are borrowed, so the inline
2590+/// path ([`push_op`]'s registered planes) reaches it without ever building
2591+/// the record -- which is what keeps one reconstruction thread at the cost of
2592+/// the pre-lane-wave1 decoder.
2593+#[allow(clippy::too_many_arguments)]
2594+fn exec_intra(
2595+ y: &mut PlaneBuf<'static>,
2596+ u: &mut PlaneBuf<'static>,
2597+ v: &mut PlaneBuf<'static>,
2598+ plane: usize,
2599+ x: usize,
2600+ oy: usize,
2601+ bw: usize,
2602+ bh: usize,
2603+ rect: bool,
2604+ mode: usize,
2605+ angle_delta: i32,
2606+ reach: Reach,
2607+ residual: &[i32],
2608+ cfl: Option<(i32, CflSrc)>,
2609+ filter_intra: Option<usize>,
2610+ smooth_neighbor: bool,
2611+ pred: Option<Vec<u16>>,
2612+ fctx: &crate::decode::FrameCtx,
2613+) {
2614+ // The CfL AC signal is read HERE, off the luma that has already been
2615+ // written for this block -- at parse time it would have been the previous
2616+ // frame's samples.
2617+ let ac = cfl.map(|(alpha, src)| {
2618+ let sig = if src.rect {
2619+ cfl_ac_q3_rect(&*y, src.px, src.py, src.bw, src.bh)
2620+ } else {
2621+ cfl_ac_q3(&*y, src.px, src.py, src.bw)
2622+ };
2623+ (alpha, sig)
2624+ });
2625+ let cfl = ac.as_ref().map(|(a, sig)| (*a, sig.as_slice()));
2626+ let target: &mut PlaneBuf<'static> = match plane { 0 => &mut *y, 1 => &mut *u, _ => &mut *v };
2627+ if rect {
2628+ target.reconstruct_rect(
2629+ x, oy, bw, bh, mode, angle_delta, reach, residual, cfl, filter_intra,
2630+ smooth_neighbor, pred, fctx,
2631+ );
2632+ } else {
2633+ target.reconstruct(
2634+ x, oy, bw, mode, angle_delta, reach, residual, cfl, filter_intra,
2635+ smooth_neighbor, pred, fctx,
2636+ );
2637+ }
2638+}
2639+
2640+/// [`ReconOp::Mc`] performed -- see [`exec_intra`].
2641+#[allow(clippy::too_many_arguments)]
2642+fn exec_mc(
2643+ y: &mut PlaneBuf<'static>,
2644+ u: &mut PlaneBuf<'static>,
2645+ v: &mut PlaneBuf<'static>,
2646+ plane: usize,
2647+ x: usize,
2648+ oy: usize,
2649+ stride: usize,
2650+ w: usize,
2651+ h: usize,
2652+ prediction: &[u16],
2653+ residual: &[i32],
2654+ fctx: &crate::decode::FrameCtx,
2655+) {
2656+ let target: &mut PlaneBuf<'static> = match plane { 0 => &mut *y, 1 => &mut *u, _ => &mut *v };
2657+ target.reconstruct_mc_rect(x, oy, stride, w, h, prediction, residual, fctx);
2658+}
2659+
20132660 thread_local! {
20142661 /// The current frame's `mi` grid, kept only while a frame header set
20152662 /// `allow_intrabc` -- an intrabc block's DV predictor is the ordinary
@@ -7693,7 +8340,7 @@ fn decode_rect_split(
76938340 set_palette_pred(tu_buf, fctx);
76948341 }
76958342 if m.skip {
7696- y.reconstruct_rect(
8343+ push_intra_rect(0,
76978344 tu_px,
76988345 tu_py,
76998346 tx_w,
@@ -7751,7 +8398,7 @@ fn decode_rect_split(
77518398 plane_q_delta(0, fctx).1,
77528399 tu_tx_type,
77538400 );
7754- y.reconstruct_rect(
8401+ push_intra_rect(0,
77558402 tu_px,
77568403 tu_py,
77578404 tx_w,
@@ -7807,7 +8454,7 @@ fn decode_rect_split(
78078454 plane_q_delta(0, fctx).1,
78088455 tu_tx_type,
78098456 );
7810- y.reconstruct_rect(
8457+ push_intra_rect(0,
78118458 tu_px,
78128459 tu_py,
78138460 tx_w,
@@ -7854,23 +8501,23 @@ fn decode_rect_split(
78548501 }
78558502 }
78568503 // CHROMA: one un-split rect transform for the whole strip.
7857- let ac = m.alpha.map(|_| cfl_ac_q3_rect(y, px, py, bw, bh));
8504+ let ac = m.alpha.map(|_| cfl_src_rect(px, py, bw, bh));
78588505 let reach = block_reach;
78598506 let (u_grid, v_grid) = if m.skip {
78608507 let zero = vec![0i32; chroma_w * chroma_h];
78618508 if let Some((ub, _)) = &m.palette_uv {
78628509 set_palette_pred(ub.clone(), fctx);
78638510 }
7864- u.reconstruct_rect(
8511+ push_intra_rect(1,
78658512 cpx, cpy, chroma_w, chroma_h, m.uv_predict_mode, m.angle_delta_uv, reach, &zero,
7866- m.alpha.zip(ac.as_deref()).map(|((au, _), ac)| (au, ac)), None, m.smooth_neighbor_uv, fctx,
8513+ m.alpha.zip(ac).map(|((au, _), ac)| (au, ac)), None, m.smooth_neighbor_uv, fctx,
78678514 );
78688515 if let Some((_, vb)) = &m.palette_uv {
78698516 set_palette_pred(vb.clone(), fctx);
78708517 }
7871- v.reconstruct_rect(
8518+ push_intra_rect(2,
78728519 cpx, cpy, chroma_w, chroma_h, m.uv_predict_mode, m.angle_delta_uv, reach, &zero,
7873- m.alpha.zip(ac.as_deref()).map(|((_, av), ac)| (av, ac)), None, m.smooth_neighbor_uv, fctx,
8520+ m.alpha.zip(ac).map(|((_, av), ac)| (av, ac)), None, m.smooth_neighbor_uv, fctx,
78748521 );
78758522 (zero.clone(), zero)
78768523 } else {
@@ -7918,14 +8565,14 @@ fn decode_rect_split(
79188565 );
79198566 let cfl = m
79208567 .alpha
7921- .zip(ac.as_deref())
8568+ .zip(ac)
79228569 .map(|((au, av), ac)| (if plane_idx == 1 { au } else { av }, ac));
7923- let plane = if plane_idx == 1 { &mut *u } else { &mut *v };
8570+ let _plane = if plane_idx == 1 { &mut *u } else { &mut *v };
79248571 if let Some((ub, vb)) = &m.palette_uv {
79258572 let buf = if plane_idx == 1 { ub } else { vb };
79268573 set_palette_pred(buf.clone(), fctx);
79278574 }
7928- plane.reconstruct_rect(
8575+ push_intra_rect(plane_idx,
79298576 cpx,
79308577 cpy,
79318578 chroma_w,
@@ -8888,7 +9535,7 @@ fn decode_block_rect(
88889535 )
88899536 });
88909537 if skip {
8891- y.reconstruct_rect(
9538+ push_intra_rect(0,
88929539 px,
88939540 py,
88949541 bw,
@@ -8901,11 +9548,11 @@ fn decode_block_rect(
89019548 filter_intra,
89029549 smooth_neighbor, fctx,
89039550 );
8904- let ac = alpha.map(|_| cfl_ac_q3_rect(y, px, py, bw, bh));
9551+ let ac = alpha.map(|_| cfl_src_rect(px, py, bw, bh));
89059552 if let Some((ub, _)) = &palette_uv_bufs {
89069553 set_palette_pred(ub.clone(), fctx);
89079554 }
8908- u.reconstruct_rect(
9555+ push_intra_rect(1,
89099556 cpx,
89109557 cpy,
89119558 chroma_w,
@@ -8914,14 +9561,14 @@ fn decode_block_rect(
89149561 angle_delta_uv,
89159562 reach,
89169563 &vec![0i32; chroma_w * chroma_h],
8917- alpha.zip(ac.as_deref()).map(|((au, _), ac)| (au, ac)),
9564+ alpha.zip(ac).map(|((au, _), ac)| (au, ac)),
89189565 None,
89199566 smooth_neighbor_uv, fctx,
89209567 );
89219568 if let Some((_, vb)) = &palette_uv_bufs {
89229569 set_palette_pred(vb.clone(), fctx);
89239570 }
8924- v.reconstruct_rect(
9571+ push_intra_rect(2,
89259572 cpx,
89269573 cpy,
89279574 chroma_w,
@@ -8930,7 +9577,7 @@ fn decode_block_rect(
89309577 angle_delta_uv,
89319578 reach,
89329579 &vec![0i32; chroma_w * chroma_h],
8933- alpha.zip(ac.as_deref()).map(|((_, av), ac)| (av, ac)),
9580+ alpha.zip(ac).map(|((_, av), ac)| (av, ac)),
89349581 None,
89359582 smooth_neighbor_uv, fctx,
89369583 );
@@ -9018,7 +9665,7 @@ fn decode_block_rect(
90189665 plane_q_delta(0, fctx).1,
90199666 luma_tx_type,
90209667 );
9021- y.reconstruct_rect(
9668+ push_intra_rect(0,
90229669 px,
90239670 py,
90249671 bw,
@@ -9031,7 +9678,7 @@ fn decode_block_rect(
90319678 filter_intra,
90329679 smooth_neighbor, fctx,
90339680 );
9034- let ac = alpha.map(|_| cfl_ac_q3_rect(y, px, py, bw, bh));
9681+ let ac = alpha.map(|_| cfl_src_rect(px, py, bw, bh));
90359682 if let Some((ub, _)) = &palette_uv_bufs {
90369683 set_palette_pred(ub.clone(), fctx);
90379684 }
@@ -9062,7 +9709,7 @@ fn decode_block_rect(
90629709 plane_q_delta(1, fctx).1,
90639710 u_tx_type,
90649711 );
9065- u.reconstruct_rect(
9712+ push_intra_rect(1,
90669713 cpx,
90679714 cpy,
90689715 chroma_w,
@@ -9071,7 +9718,7 @@ fn decode_block_rect(
90719718 angle_delta_uv,
90729719 reach,
90739720 &u_residual,
9074- alpha.zip(ac.as_deref()).map(|((au, _), ac)| (au, ac)),
9721+ alpha.zip(ac).map(|((au, _), ac)| (au, ac)),
90759722 None,
90769723 smooth_neighbor_uv, fctx,
90779724 );
@@ -9105,7 +9752,7 @@ fn decode_block_rect(
91059752 plane_q_delta(2, fctx).1,
91069753 v_tx_type,
91079754 );
9108- v.reconstruct_rect(
9755+ push_intra_rect(2,
91099756 cpx,
91109757 cpy,
91119758 chroma_w,
@@ -9114,7 +9761,7 @@ fn decode_block_rect(
91149761 angle_delta_uv,
91159762 reach,
91169763 &v_residual,
9117- alpha.zip(ac.as_deref()).map(|((_, av), ac)| (av, ac)),
9764+ alpha.zip(ac).map(|((_, av), ac)| (av, ac)),
91189765 None,
91199766 smooth_neighbor_uv, fctx,
91209767 );
@@ -9359,24 +10006,24 @@ fn decode_leaf_rect(
935910006 if let Some(b) = &palette_y_buf {
936010007 set_palette_pred(b.clone(), fctx);
936110008 }
9362- y.reconstruct_rect(
10009+ push_intra_rect(0,
936310010 px, py, bw, bh, mode, angle_delta_y, reach, &luma_levels, None, filter_intra,
936410011 smooth_neighbor, fctx,
936510012 );
9366- let ac = alpha.map(|_| cfl_ac_q3_rect(y, px, py, bw, bh));
10013+ let ac = alpha.map(|_| cfl_src_rect(px, py, bw, bh));
936710014 if let Some((ub, _)) = &palette_uv_bufs {
936810015 set_palette_pred(ub.clone(), fctx);
936910016 }
9370- u.reconstruct_rect(
10017+ push_intra_rect(1,
937110018 cpx, cpy, chroma_w, chroma_h, uv_predict_mode, angle_delta_uv, reach, &u_levels,
9372- alpha.zip(ac.as_deref()).map(|((au, _), ac)| (au, ac)), None, smooth_neighbor_uv, fctx,
10019+ alpha.zip(ac).map(|((au, _), ac)| (au, ac)), None, smooth_neighbor_uv, fctx,
937310020 );
937410021 if let Some((_, vb)) = &palette_uv_bufs {
937510022 set_palette_pred(vb.clone(), fctx);
937610023 }
9377- v.reconstruct_rect(
10024+ push_intra_rect(2,
937810025 cpx, cpy, chroma_w, chroma_h, uv_predict_mode, angle_delta_uv, reach, &v_levels,
9379- alpha.zip(ac.as_deref()).map(|((_, av), ac)| (av, ac)), None, smooth_neighbor_uv, fctx,
10026+ alpha.zip(ac).map(|((_, av), ac)| (av, ac)), None, smooth_neighbor_uv, fctx,
938010027 );
938110028 } else {
938210029 // lane-rectx: a genuine 16x8/8x16 luma transform (`TxbSet::LumaRect16x8`,
@@ -9412,11 +10059,11 @@ fn decode_leaf_rect(
941210059 if let Some(b) = &palette_y_buf {
941310060 set_palette_pred(b.clone(), fctx);
941410061 }
9415- y.reconstruct_rect(
10062+ push_intra_rect(0,
941610063 px, py, bw, bh, mode, angle_delta_y, reach, &luma_residual, None, filter_intra,
941710064 smooth_neighbor, fctx,
941810065 );
9419- let ac = alpha.map(|_| cfl_ac_q3_rect(y, px, py, bw, bh));
10066+ let ac = alpha.map(|_| cfl_src_rect(px, py, bw, bh));
942010067 let u_default_tx = default_intra_tx_type(uv_predict_mode as u8);
942110068 let u_skip_ctx = usize::from(around[1].0) + usize::from(around[1].1);
942210069 let mut u_coding = cdfs.txb(TxbSet::ChromaRect8x4, uv_predict_mode);
@@ -9432,9 +10079,9 @@ fn decode_leaf_rect(
943210079 if let Some((ub, _)) = &palette_uv_bufs {
943310080 set_palette_pred(ub.clone(), fctx);
943410081 }
9435- u.reconstruct_rect(
10082+ push_intra_rect(1,
943610083 cpx, cpy, chroma_w, chroma_h, uv_predict_mode, angle_delta_uv, reach, &u_residual,
9437- alpha.zip(ac.as_deref()).map(|((au, _), ac)| (au, ac)), None, smooth_neighbor_uv, fctx,
10084+ alpha.zip(ac).map(|((au, _), ac)| (au, ac)), None, smooth_neighbor_uv, fctx,
943810085 );
943910086 let v_default_tx = default_intra_tx_type(uv_predict_mode as u8);
944010087 let v_skip_ctx = usize::from(around[2].0) + usize::from(around[2].1);
@@ -9451,9 +10098,9 @@ fn decode_leaf_rect(
945110098 if let Some((_, vb)) = &palette_uv_bufs {
945210099 set_palette_pred(vb.clone(), fctx);
945310100 }
9454- v.reconstruct_rect(
10101+ push_intra_rect(2,
945510102 cpx, cpy, chroma_w, chroma_h, uv_predict_mode, angle_delta_uv, reach, &v_residual,
9456- alpha.zip(ac.as_deref()).map(|((_, av), ac)| (av, ac)), None, smooth_neighbor_uv, fctx,
10103+ alpha.zip(ac).map(|((_, av), ac)| (av, ac)), None, smooth_neighbor_uv, fctx,
945710104 );
945810105 RECT_LEAF_COEFF_HITS.with(|c| c.set(c.get() + 1));
945910106 }
@@ -9798,7 +10445,7 @@ fn decode_block_rect4(
979810445 if let Some(b) = &palette_y_buf {
979910446 set_palette_pred(b.clone(), fctx);
980010447 }
9801- y.reconstruct_rect(
10448+ push_intra_rect(0,
980210449 px,
980310450 py,
980410451 bw,
@@ -9811,8 +10458,8 @@ fn decode_block_rect4(
981110458 filter_intra,
981210459 smooth_neighbor, fctx,
981310460 );
9814- let ac = alpha.map(|_| cfl_ac_q3_rect(y, px, py, bw, bh));
9815- for (plane, buf, levels, tx_type) in [
10461+ let ac = alpha.map(|_| cfl_src_rect(px, py, bw, bh));
10462+ for (plane, _buf, levels, tx_type) in [
981610463 (1usize, &mut *u, &u_levels, u_tx_type),
981710464 (2, &mut *v, &v_levels, v_tx_type),
981810465 ] {
@@ -9829,7 +10476,7 @@ fn decode_block_rect4(
982910476 if let Some((ub, vb)) = &palette_uv_bufs {
983010477 set_palette_pred(if plane == 1 { ub.clone() } else { vb.clone() }, fctx);
983110478 }
9832- buf.reconstruct_rect(
10479+ push_intra_rect(plane,
983310480 cpx,
983410481 cpy,
983510482 chroma_w,
@@ -9839,7 +10486,7 @@ fn decode_block_rect4(
983910486 reach,
984010487 &residual,
984110488 alpha
9842- .zip(ac.as_deref())
10489+ .zip(ac)
984310490 .map(|((au, av), ac)| (if plane == 1 { au } else { av }, ac)),
984410491 None,
984510492 smooth_neighbor_uv, fctx,
@@ -9874,7 +10521,7 @@ fn decode_block_rect4(
987410521 if let Some(b) = &palette_y_buf {
987510522 set_palette_pred(b.clone(), fctx);
987610523 }
9877- y.reconstruct_rect(
10524+ push_intra_rect(0,
987810525 px,
987910526 py,
988010527 bw,
@@ -9887,11 +10534,11 @@ fn decode_block_rect4(
988710534 filter_intra,
988810535 smooth_neighbor, fctx,
988910536 );
9890- let ac = alpha.map(|_| cfl_ac_q3_rect(y, px, py, bw, bh));
10537+ let ac = alpha.map(|_| cfl_src_rect(px, py, bw, bh));
989110538 if let Some((ub, _)) = &palette_uv_bufs {
989210539 set_palette_pred(ub.clone(), fctx);
989310540 }
9894- u.reconstruct_rect(
10541+ push_intra_rect(1,
989510542 cpx,
989610543 cpy,
989710544 chroma_w,
@@ -9900,14 +10547,14 @@ fn decode_block_rect4(
990010547 angle_delta_uv,
990110548 reach,
990210549 &u_levels,
9903- alpha.zip(ac.as_deref()).map(|((au, _), ac)| (au, ac)),
10550+ alpha.zip(ac).map(|((au, _), ac)| (au, ac)),
990410551 None,
990510552 smooth_neighbor_uv, fctx,
990610553 );
990710554 if let Some((_, vb)) = &palette_uv_bufs {
990810555 set_palette_pred(vb.clone(), fctx);
990910556 }
9910- v.reconstruct_rect(
10557+ push_intra_rect(2,
991110558 cpx,
991210559 cpy,
991310560 chroma_w,
@@ -9916,7 +10563,7 @@ fn decode_block_rect4(
991610563 angle_delta_uv,
991710564 reach,
991810565 &v_levels,
9919- alpha.zip(ac.as_deref()).map(|((_, av), ac)| (av, ac)),
10566+ alpha.zip(ac).map(|((_, av), ac)| (av, ac)),
992010567 None,
992110568 smooth_neighbor_uv, fctx,
992210569 );
@@ -10200,7 +10847,7 @@ fn decode_rect4_16_strip(
1020010847 set_palette_pred(tu_buf, fctx);
1020110848 }
1020210849 if skip {
10203- y.reconstruct_rect(
10850+ push_intra_rect(0,
1020410851 tu_px, tu_py, tx_w, tx_h, mode, angle_delta_y, tu_reach, &zero_tu,
1020510852 None, filter_intra, smooth_neighbor, fctx,
1020610853 );
@@ -10239,7 +10886,7 @@ fn decode_rect4_16_strip(
1023910886 plane_q_delta(0, fctx).1,
1024010887 tu_tx_type,
1024110888 );
10242- y.reconstruct_rect(
10889+ push_intra_rect(0,
1024310890 tu_px, tu_py, tx_w, tx_h, mode, angle_delta_y, tu_reach, &residual,
1024410891 None, filter_intra, smooth_neighbor, fctx,
1024510892 );
@@ -10285,7 +10932,7 @@ fn decode_rect4_16_strip(
1028510932 if let Some(b) = &palette_y_buf {
1028610933 set_palette_pred(b.clone(), fctx);
1028710934 }
10288- y.reconstruct_rect(
10935+ push_intra_rect(0,
1028910936 px, py, bw, bh, mode, angle_delta_y, reach, &zeros, None, filter_intra,
1029010937 smooth_neighbor, fctx,
1029110938 );
@@ -10324,7 +10971,7 @@ fn decode_rect4_16_strip(
1032410971 if let Some(b) = &palette_y_buf {
1032510972 set_palette_pred(b.clone(), fctx);
1032610973 }
10327- y.reconstruct_rect(
10974+ push_intra_rect(0,
1032810975 px, py, bw, bh, mode, angle_delta_y, reach, &residual, None, filter_intra,
1032910976 smooth_neighbor, fctx,
1033010977 );
@@ -10388,15 +11035,15 @@ fn decode_rect4_16_strip(
1038811035 // `mbmi->skip_txfm`, so a skipped `UV_CFL_PRED` block is still
1038911036 // DC + alpha * luma-AC. Dropping the CfL term here left a
1039011037 // chroma-only bounded box on ReelC's key frames.
10391- let ac = alpha.map(|_| cfl_ac_q3_rect(y, ppx, ppy, pw, ph));
11038+ let ac = alpha.map(|_| cfl_src_rect(ppx, ppy, pw, ph));
1039211039 if alpha.is_some() {
1039311040 CHROMA_SKIP_CFL_HITS.with(|h| h.set(h.get() + 1));
1039411041 }
10395- for (buf, plane) in [(&mut *u, 1usize), (&mut *v, 2)] {
11042+ for (_buf, plane) in [(&mut *u, 1usize), (&mut *v, 2)] {
1039611043 if let Some((ub, vb)) = &palette_uv_bufs {
1039711044 set_palette_pred(if plane == 1 { ub.clone() } else { vb.clone() }, fctx);
1039811045 }
10399- buf.reconstruct_rect(
11046+ push_intra_rect(plane,
1040011047 cpx,
1040111048 cpy,
1040211049 cw,
@@ -10406,7 +11053,7 @@ fn decode_rect4_16_strip(
1040611053 pair_reach,
1040711054 &zeros,
1040811055 alpha
10409- .zip(ac.as_deref())
11056+ .zip(ac)
1041011057 .map(|((au, av), ac)| (if plane == 1 { au } else { av }, ac)),
1041111058 None,
1041211059 smooth_neighbor_uv, fctx,
@@ -10436,8 +11083,8 @@ fn decode_rect4_16_strip(
1043611083 let (u_levels, u_tx_type) = planes.pop().expect("plane 1");
1043711084 // CfL averages the luma of the WHOLE pair, the region this one
1043811085 // chroma transform covers.
10439- let ac = alpha.map(|_| cfl_ac_q3_rect(y, ppx, ppy, pw, ph));
10440- for (plane, buf, levels, tx_type) in [
11086+ let ac = alpha.map(|_| cfl_src_rect(ppx, ppy, pw, ph));
11087+ for (plane, _buf, levels, tx_type) in [
1044111088 (1usize, &mut *u, &u_levels, u_tx_type),
1044211089 (2, &mut *v, &v_levels, v_tx_type),
1044311090 ] {
@@ -10454,7 +11101,7 @@ fn decode_rect4_16_strip(
1045411101 if let Some((ub, vb)) = &palette_uv_bufs {
1045511102 set_palette_pred(if plane == 1 { ub.clone() } else { vb.clone() }, fctx);
1045611103 }
10457- buf.reconstruct_rect(
11104+ push_intra_rect(plane,
1045811105 cpx,
1045911106 cpy,
1046011107 cw,
@@ -10464,7 +11111,7 @@ fn decode_rect4_16_strip(
1046411111 pair_reach,
1046511112 &residual,
1046611113 alpha
10467- .zip(ac.as_deref())
11114+ .zip(ac)
1046811115 .map(|((au, av), ac)| (if plane == 1 { au } else { av }, ac)),
1046911116 None,
1047011117 smooth_neighbor_uv, fctx,
@@ -10757,7 +11404,7 @@ fn decode_block_rect64(
1075711404 )
1075811405 });
1075911406 if skip {
10760- y.reconstruct_rect(
11407+ push_intra_rect(0,
1076111408 px,
1076211409 py,
1076311410 bw,
@@ -10770,11 +11417,11 @@ fn decode_block_rect64(
1077011417 filter_intra,
1077111418 smooth_neighbor, fctx,
1077211419 );
10773- let ac = alpha.map(|_| cfl_ac_q3_rect(y, px, py, bw, bh));
11420+ let ac = alpha.map(|_| cfl_src_rect(px, py, bw, bh));
1077411421 if let Some((ub, _)) = &palette_uv_bufs {
1077511422 set_palette_pred(ub.clone(), fctx);
1077611423 }
10777- u.reconstruct_rect(
11424+ push_intra_rect(1,
1077811425 cpx,
1077911426 cpy,
1078011427 chroma_w,
@@ -10783,14 +11430,14 @@ fn decode_block_rect64(
1078311430 angle_delta_uv,
1078411431 reach,
1078511432 &vec![0i32; chroma_w * chroma_h],
10786- alpha.zip(ac.as_deref()).map(|((au, _), ac)| (au, ac)),
11433+ alpha.zip(ac).map(|((au, _), ac)| (au, ac)),
1078711434 None,
1078811435 smooth_neighbor_uv, fctx,
1078911436 );
1079011437 if let Some((_, vb)) = &palette_uv_bufs {
1079111438 set_palette_pred(vb.clone(), fctx);
1079211439 }
10793- v.reconstruct_rect(
11440+ push_intra_rect(2,
1079411441 cpx,
1079511442 cpy,
1079611443 chroma_w,
@@ -10799,7 +11446,7 @@ fn decode_block_rect64(
1079911446 angle_delta_uv,
1080011447 reach,
1080111448 &vec![0i32; chroma_w * chroma_h],
10802- alpha.zip(ac.as_deref()).map(|((_, av), ac)| (av, ac)),
11449+ alpha.zip(ac).map(|((_, av), ac)| (av, ac)),
1080311450 None,
1080411451 smooth_neighbor_uv, fctx,
1080511452 );
@@ -10896,7 +11543,7 @@ fn decode_block_rect64(
1089611543 plane_q_delta(0, fctx).1,
1089711544 luma_tx_type,
1089811545 );
10899- y.reconstruct_rect(
11546+ push_intra_rect(0,
1090011547 px,
1090111548 py,
1090211549 bw,
@@ -10925,7 +11572,7 @@ fn decode_block_rect64(
1092511572 }
1092611573 // CHROMA: a real, untruncated chroma_w x chroma_h transform -- no
1092711574 // corner crop needed (see doc comment).
10928- let ac = alpha.map(|_| cfl_ac_q3_rect(y, px, py, bw, bh));
11575+ let ac = alpha.map(|_| cfl_src_rect(px, py, bw, bh));
1092911576 // The chroma plane is never truncated (both axes <= 32 after
1093011577 // subsampling). Under a 1:4 strip it is a true 32x8/8x32:
1093111578 // `get_txsize_entropy_ctx(TX_32X8)` = (TX_8X8 + TX_32X32 + 1) >> 1 =
@@ -10989,7 +11636,7 @@ fn decode_block_rect64(
1098911636 if let Some((ub, _)) = &palette_uv_bufs {
1099011637 set_palette_pred(ub.clone(), fctx);
1099111638 }
10992- u.reconstruct_rect(
11639+ push_intra_rect(1,
1099311640 cpx,
1099411641 cpy,
1099511642 chroma_w,
@@ -10998,7 +11645,7 @@ fn decode_block_rect64(
1099811645 angle_delta_uv,
1099911646 reach,
1100011647 &u_residual,
11001- alpha.zip(ac.as_deref()).map(|((au, _), ac)| (au, ac)),
11648+ alpha.zip(ac).map(|((au, _), ac)| (au, ac)),
1100211649 None,
1100311650 smooth_neighbor_uv, fctx,
1100411651 );
@@ -11046,7 +11693,7 @@ fn decode_block_rect64(
1104611693 if let Some((_, vb)) = &palette_uv_bufs {
1104711694 set_palette_pred(vb.clone(), fctx);
1104811695 }
11049- v.reconstruct_rect(
11696+ push_intra_rect(2,
1105011697 cpx,
1105111698 cpy,
1105211699 chroma_w,
@@ -11055,7 +11702,7 @@ fn decode_block_rect64(
1105511702 angle_delta_uv,
1105611703 reach,
1105711704 &v_residual,
11058- alpha.zip(ac.as_deref()).map(|((_, av), ac)| (av, ac)),
11705+ alpha.zip(ac).map(|((_, av), ac)| (av, ac)),
1105911706 None,
1106011707 smooth_neighbor_uv, fctx,
1106111708 );
@@ -11719,12 +12366,16 @@ impl PlaneBuf<'_> {
1171912366 residual: &[i32],
1172012367 cfl: Option<(i32, &[i32])>,
1172112368 filter_intra: Option<usize>,
11722- smooth_neighbor: bool, fctx: &crate::decode::FrameCtx,
12369+ smooth_neighbor: bool,
12370+ // lane-wave1 step (i): the palette/intrabc prediction override, taken
12371+ // off `FrameCtx::palette_pred` by the PUSH site (parse order) rather
12372+ // than by this replay.
12373+ pred: Option<Vec<u16>>, fctx: &crate::decode::FrameCtx,
1172312374 ) {
1172412375 // As [`Self::reconstruct`]'s own [`PALETTE_PRED`] override
1172512376 // (lane-palette2 r4): a palette block's prediction is the
1172612377 // reconstructed colour-index map, needing no edge pixels at all.
11727- let prediction = if let Some(buf) = take_palette_pred(fctx) {
12378+ let prediction = if let Some(buf) = pred {
1172812379 buf
1172912380 } else {
1173012381 let (above, left, corner) = self.edges_rect(x, y, bw, bh, reach);
@@ -11823,12 +12474,16 @@ impl PlaneBuf<'_> {
1182312474 // callers until a smooth/paeth `uv_mode` can reach this call at all
1182412475 // (still refused in `read_intra_mode`/`read_intra_mode_rect`), which
1182512476 // keeps `false` exact for chroma without this fn needing to know why.
11826- smooth_neighbor: bool, fctx: &crate::decode::FrameCtx,
12477+ smooth_neighbor: bool,
12478+ // lane-wave1 step (i): the palette/intrabc prediction override, taken
12479+ // off `FrameCtx::palette_pred` by the PUSH site (parse order) rather
12480+ // than by this replay.
12481+ pred: Option<Vec<u16>>, fctx: &crate::decode::FrameCtx,
1182712482 ) {
1182812483 // A palette block's own [`PALETTE_PRED`] override (lane-palette r2)
1182912484 // takes priority over `predict()`/`predict_filter_intra` entirely --
1183012485 // palette prediction needs no edge pixels at all.
11831- let prediction = if let Some(buf) = take_palette_pred(fctx) {
12486+ let prediction = if let Some(buf) = pred {
1183212487 buf
1183312488 } else {
1183412489 let (above, left, corner) = self.edges(x, y, side, reach);
@@ -11922,13 +12577,17 @@ fn read_plane(
1192212577 predict_mode: usize,
1192312578 angle_delta: i32,
1192412579 reach: Reach,
11925- plane: &mut PlaneBuf<'static>,
12580+ // lane-wave1 step (i): unread -- this reader records its write
12581+ // ([`push_intra`]/[`push_mc`]) instead of performing it; the borrow
12582+ // stays in the signature so every call site still proves the plane is
12583+ // exclusively held while its coefficients are parsed.
12584+ _plane: &mut PlaneBuf<'static>,
1192612585 x: usize,
1192712586 y: usize,
1192812587 side: usize,
1192912588 tx_side: usize,
1193012589 base_q_idx: u8,
11931- cfl: Option<(i32, &[i32])>,
12590+ cfl: Option<(i32, CflSrc)>,
1193212591 filter_intra: Option<usize>,
1193312592 // Only meaningful for `plane_idx == 0`: `Some` when this transform unit is
1193412593 // smaller than its own block (spec `get_txb_ctx_general`'s
@@ -12019,14 +12678,15 @@ fn read_plane(
1201912678 "TRACE dequant plane={plane_idx} base_q_idx={base_q_idx} tx_type={tx_type:?} side={side} levels={levels:?} residual={residual:?}",
1202012679 );
1202112680 }
12022- plane.reconstruct(
12681+ push_intra_owned(
12682+ plane_idx,
1202312683 x,
1202412684 y,
1202512685 side,
1202612686 predict_mode,
1202712687 angle_delta,
1202812688 reach,
12029- &residual,
12689+ residual,
1203012690 cfl,
1203112691 filter_intra,
1203212692 smooth_neighbor, fctx,
@@ -12215,6 +12875,7 @@ fn decode_block(
1221512875 // block vector, with the BILINEAR kernel libaom forces for intrabc --
1221612876 // luma is a straight copy, chroma lands half-pel whenever the luma DV is
1221712877 // odd, which is exactly what the bilinear taps then interpolate.
12878+ flush_recon(fctx, y, u, v);
1221812879 let intrabc_bufs = intrabc_dv.map(|(dv_row, dv_col)| {
1221912880 let mut yb = vec![0u16; side * side];
1222012881 mc::predict_with_filter(
@@ -12333,7 +12994,7 @@ fn decode_block(
1233312994 y.width,
1233412995 y.height, fctx,
1233512996 );
12336- y.reconstruct(
12997+ push_intra(0,
1233712998 tu_px,
1233812999 tu_py,
1233913000 logical_tx,
@@ -12348,7 +13009,7 @@ fn decode_block(
1234813009 }
1234913010 }
1235013011 } else {
12351- y.reconstruct(
13012+ push_intra(0,
1235213013 px,
1235313014 py,
1235413015 side,
@@ -12361,7 +13022,7 @@ fn decode_block(
1236113022 smooth_neighbor, fctx,
1236213023 );
1236313024 }
12364- let ac = alpha.map(|_| cfl_ac_q3(y, px, py, side));
13025+ let ac = alpha.map(|_| cfl_src(px, py, side));
1236513026 let cn = (chroma_side / chroma_tx).max(1);
1236613027 for cu_row in 0..cn {
1236713028 for cu_col in 0..cn {
@@ -12379,7 +13040,7 @@ fn decode_block(
1237913040 if let Some((ub, _)) = &palette_uv_bufs {
1238013041 set_palette_pred(ub.clone(), fctx);
1238113042 }
12382- u.reconstruct(
13043+ push_intra(1,
1238313044 cu_x,
1238413045 cu_y,
1238513046 chroma_tx,
@@ -12387,14 +13048,14 @@ fn decode_block(
1238713048 angle_delta_uv,
1238813049 cu_r,
1238913050 &vec![0i32; chroma_tx * chroma_tx],
12390- alpha.zip(ac.as_deref()).map(|((au, _), ac)| (au, ac)),
13051+ alpha.zip(ac).map(|((au, _), ac)| (au, ac)),
1239113052 None,
1239213053 smooth_neighbor_uv, fctx,
1239313054 );
1239413055 if let Some((_, vb)) = &palette_uv_bufs {
1239513056 set_palette_pred(vb.clone(), fctx);
1239613057 }
12397- v.reconstruct(
13058+ push_intra(2,
1239813059 cu_x,
1239913060 cu_y,
1240013061 chroma_tx,
@@ -12402,7 +13063,7 @@ fn decode_block(
1240213063 angle_delta_uv,
1240313064 cu_r,
1240413065 &vec![0i32; chroma_tx * chroma_tx],
12405- alpha.zip(ac.as_deref()).map(|((_, av), ac)| (av, ac)),
13066+ alpha.zip(ac).map(|((_, av), ac)| (av, ac)),
1240613067 None,
1240713068 smooth_neighbor_uv, fctx,
1240813069 );
@@ -12444,7 +13105,7 @@ fn decode_block(
1244413105 None,
1244513106 smooth_neighbor, fctx,
1244613107 )?;
12447- let ac = alpha.map(|_| cfl_ac_q3(y, px, py, side));
13108+ let ac = alpha.map(|_| cfl_src(px, py, side));
1244813109 // Armed for exactly this block's two chroma reads (see
1244913110 // [`INTRABC_CHROMA_TX`]); the luma call above just set
1245013111 // [`LUMA_TX_TYPE`] to the type it coded.
@@ -12471,7 +13132,7 @@ fn decode_block(
1247113132 chroma_side,
1247213133 chroma_tx,
1247313134 base_q_idx,
12474- alpha.zip(ac.as_deref()).map(|((au, _), ac)| (au, ac)),
13135+ alpha.zip(ac).map(|((au, _), ac)| (au, ac)),
1247513136 None,
1247613137 None,
1247713138 smooth_neighbor_uv, fctx,
@@ -12502,7 +13163,7 @@ fn decode_block(
1250213163 chroma_side,
1250313164 chroma_tx,
1250413165 base_q_idx,
12505- alpha.zip(ac.as_deref()).map(|((_, av), ac)| (av, ac)),
13166+ alpha.zip(ac).map(|((_, av), ac)| (av, ac)),
1250613167 None,
1250713168 None,
1250813169 smooth_neighbor_uv, fctx,
@@ -12622,7 +13283,7 @@ fn decode_block(
1262213283 }
1262313284 // CfL is only allowed up to 32x32, i.e. only at `nchunk == 1`, where
1262413285 // this still runs after every luma unit of the block.
12625- let ac = alpha.map(|_| cfl_ac_q3(y, px, py, side));
13286+ let ac = alpha.map(|_| cfl_src(px, py, side));
1262613287 // The block's uv plane block is `chroma_side` across but its uv
1262713288 // transform is `chroma_tx` (`av1_get_max_uv_txsize` =
1262813289 // `av1_get_adjusted_tx_size(max_txsize_rect_lookup[uv_plane_bsize])`):
@@ -12657,7 +13318,7 @@ fn decode_block(
1265713318 dec, cdfs, chroma_set, scans.1, 1, cu_around[1], mode,
1265813319 uv_predict_mode, angle_delta_uv, cu_reach, u, cu_x, cu_y,
1265913320 chroma_tx, chroma_tx, base_q_idx,
12660- alpha.zip(ac.as_deref()).map(|((au, _), ac)| (au, ac)),
13321+ alpha.zip(ac).map(|((au, _), ac)| (au, ac)),
1266113322 None, chroma_ctx_offset, smooth_neighbor_uv, fctx,
1266213323 )?;
1266313324 if let Some((_, vb)) = &palette_uv_bufs {
@@ -12667,7 +13328,7 @@ fn decode_block(
1266713328 dec, cdfs, chroma_set, scans.1, 2, cu_around[2], mode,
1266813329 uv_predict_mode, angle_delta_uv, cu_reach, v, cu_x, cu_y,
1266913330 chroma_tx, chroma_tx, base_q_idx,
12670- alpha.zip(ac.as_deref()).map(|((_, av), ac)| (av, ac)),
13331+ alpha.zip(ac).map(|((_, av), ac)| (av, ac)),
1267113332 None, chroma_ctx_offset, smooth_neighbor_uv, fctx,
1267213333 )?;
1267313334 if cn > 1 {
@@ -12930,7 +13591,7 @@ fn decode_block_128rect(
1293013591 y.height, fctx,
1293113592 );
1293213593 if skip {
12933- y.reconstruct(
13594+ push_intra(0,
1293413595 tu_px, tu_py, logical_tx, mode, angle_delta_y, tu_r, &zero_tu, None,
1293513596 None, smooth_neighbor, fctx,
1293613597 );
@@ -12987,11 +13648,11 @@ fn decode_block_128rect(
1298713648 );
1298813649 let (cu_x, cu_y) = (cpx + ch_col * chroma_tx, cpy + ch_row * chroma_tx);
1298913650 if skip {
12990- u.reconstruct(
13651+ push_intra(1,
1299113652 cu_x, cu_y, chroma_tx, uv_predict_mode, angle_delta_uv, cu_r, &zero_cu, None,
1299213653 None, smooth_neighbor_uv, fctx,
1299313654 );
12994- v.reconstruct(
13655+ push_intra(2,
1299513656 cu_x, cu_y, chroma_tx, uv_predict_mode, angle_delta_uv, cu_r, &zero_cu, None,
1299613657 None, smooth_neighbor_uv, fctx,
1299713658 );
@@ -13287,6 +13948,7 @@ fn decode_leaf8(
1328713948 // the CURRENT frame's own pre-loop-filter reconstruction (every loop
1328813949 // filter is off whenever `allow_intrabc`, frame.rs:194/210/252/272) at
1328913950 // the full-pel block vector, with the BILINEAR kernel libaom forces.
13951+ flush_recon(fctx, y, u, v);
1329013952 let intrabc_bufs = intrabc_dv.map(|(dv_row, dv_col)| {
1329113953 let mut yb = vec![0u16; 8 * 8];
1329213954 mc::predict_with_filter(
@@ -13349,7 +14011,7 @@ fn decode_leaf8(
1334914011 y.width,
1335014012 y.height, fctx,
1335114013 );
13352- y.reconstruct(
14014+ push_intra(0,
1335314015 tu_px,
1335414016 tu_py,
1335514017 4,
@@ -13367,7 +14029,7 @@ fn decode_leaf8(
1336714029 if let Some(buf) = &palette_y_buf {
1336814030 set_palette_pred(buf.clone(), fctx);
1336914031 }
13370- y.reconstruct(
14032+ push_intra(0,
1337114033 px,
1337214034 py,
1337314035 8,
@@ -13380,13 +14042,13 @@ fn decode_leaf8(
1338014042 smooth_neighbor, fctx,
1338114043 );
1338214044 }
13383- let ac = alpha.map(|_| cfl_ac_q3(y, px, py, 8));
14045+ let ac = alpha.map(|_| cfl_src(px, py, 8));
1338414046 if let Some((_, ub, _)) = &intrabc_bufs {
1338514047 set_palette_pred(ub.clone(), fctx);
1338614048 } else if let Some((ub, _)) = &palette_uv_bufs {
1338714049 set_palette_pred(ub.clone(), fctx);
1338814050 }
13389- u.reconstruct(
14051+ push_intra(1,
1339014052 cpx,
1339114053 cpy,
1339214054 4,
@@ -13394,7 +14056,7 @@ fn decode_leaf8(
1339414056 angle_delta_uv,
1339514057 reach,
1339614058 &vec![0i32; 16],
13397- alpha.zip(ac.as_deref()).map(|((au, _), ac)| (au, ac)),
14059+ alpha.zip(ac).map(|((au, _), ac)| (au, ac)),
1339814060 None,
1339914061 smooth_neighbor_uv, fctx,
1340014062 );
@@ -13403,7 +14065,7 @@ fn decode_leaf8(
1340314065 } else if let Some((_, vb)) = &palette_uv_bufs {
1340414066 set_palette_pred(vb.clone(), fctx);
1340514067 }
13406- v.reconstruct(
14068+ push_intra(2,
1340714069 cpx,
1340814070 cpy,
1340914071 4,
@@ -13411,7 +14073,7 @@ fn decode_leaf8(
1341114073 angle_delta_uv,
1341214074 reach,
1341314075 &vec![0i32; 16],
13414- alpha.zip(ac.as_deref()).map(|((_, av), ac)| (av, ac)),
14076+ alpha.zip(ac).map(|((_, av), ac)| (av, ac)),
1341514077 None,
1341614078 smooth_neighbor_uv, fctx,
1341714079 );
@@ -13457,7 +14119,7 @@ fn decode_leaf8(
1345714119 if intrabc_dv.is_some() {
1345814120 fctx.intrabc_chroma_tx.with(|c| c.set(Some(fctx.luma_tx_type.with(std::cell::Cell::get))));
1345914121 }
13460- let ac = alpha.map(|_| cfl_ac_q3(y, px, py, 8));
14122+ let ac = alpha.map(|_| cfl_src(px, py, 8));
1346114123 if let Some((_, ub, _)) = &intrabc_bufs {
1346214124 set_palette_pred(ub.clone(), fctx);
1346314125 } else if let Some((ub, _)) = &palette_uv_bufs {
@@ -13480,7 +14142,7 @@ fn decode_leaf8(
1348014142 4,
1348114143 TX4,
1348214144 base_q_idx,
13483- alpha.zip(ac.as_deref()).map(|((au, _), ac)| (au, ac)),
14145+ alpha.zip(ac).map(|((au, _), ac)| (au, ac)),
1348414146 None,
1348514147 None,
1348614148 smooth_neighbor_uv, fctx,
@@ -13507,7 +14169,7 @@ fn decode_leaf8(
1350714169 4,
1350814170 TX4,
1350914171 base_q_idx,
13510- alpha.zip(ac.as_deref()).map(|((_, av), ac)| (av, ac)),
14172+ alpha.zip(ac).map(|((_, av), ac)| (av, ac)),
1351114173 None,
1351214174 None,
1351314175 smooth_neighbor_uv, fctx,
@@ -13597,7 +14259,7 @@ fn decode_leaf8(
1359714259 neighbours.record_mi_luma(tu_mi, 4, &tu_grid);
1359814260 }
1359914261 }
13600- let ac = alpha.map(|_| cfl_ac_q3(y, px, py, 8));
14262+ let ac = alpha.map(|_| cfl_src(px, py, 8));
1360114263 let chroma_around = neighbours.around_mi(leaf_mi, 8);
1360214264 if let Some((ub, _)) = &palette_uv_bufs {
1360314265 set_palette_pred(ub.clone(), fctx);
@@ -13619,7 +14281,7 @@ fn decode_leaf8(
1361914281 4,
1362014282 TX4,
1362114283 base_q_idx,
13622- alpha.zip(ac.as_deref()).map(|((au, _), ac)| (au, ac)),
14284+ alpha.zip(ac).map(|((au, _), ac)| (au, ac)),
1362314285 None,
1362414286 None,
1362514287 smooth_neighbor_uv, fctx,
@@ -13644,7 +14306,7 @@ fn decode_leaf8(
1364414306 4,
1364514307 TX4,
1364614308 base_q_idx,
13647- alpha.zip(ac.as_deref()).map(|((_, av), ac)| (av, ac)),
14309+ alpha.zip(ac).map(|((_, av), ac)| (av, ac)),
1364814310 None,
1364914311 None,
1365014312 smooth_neighbor_uv, fctx,
@@ -13907,7 +14569,7 @@ fn decode_leaf_split4(
1390714569 let (px, py) = (lmi.1 * MI, lmi.0 * MI);
1390814570 let reach = Reach::of(4, px, py, y.width, y.height, fctx);
1390914571 if skip {
13910- y.reconstruct(px, py, 4, mode, angle_delta_y, reach, &vec![0i32; 16], None, filter_intra, smooth_neighbor, fctx);
14572+ push_intra(0, px, py, 4, mode, angle_delta_y, reach, &vec![0i32; 16], None, filter_intra, smooth_neighbor, fctx);
1391114573 neighbours.record_mi_luma(lmi, 4, &vec![0i32; 16]);
1391214574 } else {
1391314575 let tu_around = neighbours.around_mi(lmi, 4)[0];
@@ -13964,26 +14626,26 @@ fn decode_leaf_split4(
1396414626 // lane-reelckf and lane-kf1200 fixed THIS SAME arm independently; the
1396514627 // merge keeps one fix and feeds both lanes' counters so neither of
1396614628 // their gates goes vacuous.
13967- let ac = alpha.map(|_| cfl_ac_q3(y, gpx, gpy, 8));
14629+ let ac = alpha.map(|_| cfl_src(gpx, gpy, 8));
1396814630 if alpha.is_some() {
1396914631 CHROMA_SKIP_CFL_HITS.with(|h| h.set(h.get() + 1));
1397014632 SKIP_CFL_HITS.with(|c| c.set(c.get() + 1));
1397114633 }
13972- u.reconstruct(cpx, cpy, 4, uv_predict_mode, angle_delta_uv, group_reach, &vec![0i32; 16], alpha.zip(ac.as_deref()).map(|((au, _), ac)| (au, ac)), None, smooth_neighbor_uv, fctx);
13973- v.reconstruct(cpx, cpy, 4, uv_predict_mode, angle_delta_uv, group_reach, &vec![0i32; 16], alpha.zip(ac.as_deref()).map(|((_, av), ac)| (av, ac)), None, smooth_neighbor_uv, fctx);
14634+ 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);
14635+ 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);
1397414636 (vec![0i32; 16], vec![0i32; 16])
1397514637 } else {
13976- let ac = alpha.map(|_| cfl_ac_q3(y, gpx, gpy, 8));
14638+ let ac = alpha.map(|_| cfl_src(gpx, gpy, 8));
1397714639 let chroma_around = neighbours.around_mi(leaf_mi, 8);
1397814640 let ug = read_plane(
1397914641 dec, cdfs, TxbSet::Chroma4, scan4, 1, chroma_around[1], uv_mode, uv_predict_mode,
1398014642 angle_delta_uv, group_reach, u, cpx, cpy, 4, TX4, base_q_idx,
13981- alpha.zip(ac.as_deref()).map(|((au, _), ac)| (au, ac)), None, None, smooth_neighbor_uv, fctx,
14643+ alpha.zip(ac).map(|((au, _), ac)| (au, ac)), None, None, smooth_neighbor_uv, fctx,
1398214644 )?;
1398314645 let vg = read_plane(
1398414646 dec, cdfs, TxbSet::Chroma4, scan4, 2, chroma_around[2], uv_mode, uv_predict_mode,
1398514647 angle_delta_uv, group_reach, v, cpx, cpy, 4, TX4, base_q_idx,
13986- alpha.zip(ac.as_deref()).map(|((_, av), ac)| (av, ac)), None, None, smooth_neighbor_uv, fctx,
14648+ alpha.zip(ac).map(|((_, av), ac)| (av, ac)), None, None, smooth_neighbor_uv, fctx,
1398714649 )?;
1398814650 (ug, vg)
1398914651 };
@@ -14194,7 +14856,7 @@ fn decode_leaf_rect8(
1419414856 // one's reconstruction, which is NOT what a single 4x8
1419514857 // prediction of the same mode produces.
1419614858 let zeros = vec![0i32; 16];
14197- y.reconstruct(
14859+ push_intra(0,
1419814860 tu_px, tu_py, 4, mode, angle_delta_y, tu_reach, &zeros, None,
1419914861 filter_intra, smooth_neighbor, fctx,
1420014862 );
@@ -14248,7 +14910,7 @@ fn decode_leaf_rect8(
1424814910 }
1424914911 let grid = if skip {
1425014912 let zeros = vec![0i32; bw * bh];
14251- y.reconstruct_rect(
14913+ push_intra_rect(0,
1425214914 px, py, bw, bh, mode, angle_delta_y, reach, &zeros, None, filter_intra,
1425314915 smooth_neighbor, fctx,
1425414916 );
@@ -14291,7 +14953,7 @@ fn decode_leaf_rect8(
1429114953 plane_q_delta(0, fctx).1,
1429214954 tx_type,
1429314955 );
14294- y.reconstruct_rect(
14956+ push_intra_rect(0,
1429514957 px, py, bw, bh, mode, angle_delta_y, reach, &residual, None, filter_intra,
1429614958 smooth_neighbor, fctx,
1429714959 );
@@ -14336,26 +14998,26 @@ fn decode_leaf_rect8(
1433614998 // lane-reelckf and lane-kf1200 fixed THIS SAME arm independently; the
1433714999 // merge keeps one fix and feeds both lanes' counters so neither of
1433815000 // their gates goes vacuous.
14339- let ac = alpha.map(|_| cfl_ac_q3(y, gpx, gpy, 8));
15001+ let ac = alpha.map(|_| cfl_src(gpx, gpy, 8));
1434015002 if alpha.is_some() {
1434115003 CHROMA_SKIP_CFL_HITS.with(|h| h.set(h.get() + 1));
1434215004 SKIP_CFL_HITS.with(|c| c.set(c.get() + 1));
1434315005 }
14344- u.reconstruct(cpx, cpy, 4, uv_predict_mode, angle_delta_uv, group_reach, &vec![0i32; 16], alpha.zip(ac.as_deref()).map(|((au, _), ac)| (au, ac)), None, smooth_neighbor_uv, fctx);
14345- v.reconstruct(cpx, cpy, 4, uv_predict_mode, angle_delta_uv, group_reach, &vec![0i32; 16], alpha.zip(ac.as_deref()).map(|((_, av), ac)| (av, ac)), None, smooth_neighbor_uv, fctx);
15006+ 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);
15007+ 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);
1434615008 (vec![0i32; 16], vec![0i32; 16])
1434715009 } else {
14348- let ac = alpha.map(|_| cfl_ac_q3(y, gpx, gpy, 8));
15010+ let ac = alpha.map(|_| cfl_src(gpx, gpy, 8));
1434915011 let chroma_around = neighbours.around_mi(leaf_mi, 8);
1435015012 let ug = read_plane(
1435115013 dec, cdfs, TxbSet::Chroma4, scan4, 1, chroma_around[1], uv_mode, uv_predict_mode,
1435215014 angle_delta_uv, group_reach, u, cpx, cpy, 4, TX4, base_q_idx,
14353- alpha.zip(ac.as_deref()).map(|((au, _), ac)| (au, ac)), None, None, smooth_neighbor_uv, fctx,
15015+ alpha.zip(ac).map(|((au, _), ac)| (au, ac)), None, None, smooth_neighbor_uv, fctx,
1435415016 )?;
1435515017 let vg = read_plane(
1435615018 dec, cdfs, TxbSet::Chroma4, scan4, 2, chroma_around[2], uv_mode, uv_predict_mode,
1435715019 angle_delta_uv, group_reach, v, cpx, cpy, 4, TX4, base_q_idx,
14358- alpha.zip(ac.as_deref()).map(|((_, av), ac)| (av, ac)), None, None, smooth_neighbor_uv, fctx,
15020+ alpha.zip(ac).map(|((_, av), ac)| (av, ac)), None, None, smooth_neighbor_uv, fctx,
1435915021 )?;
1436015022 (ug, vg)
1436115023 };
@@ -16138,7 +16800,11 @@ fn read_inter_plane_rect(
1613816800 plane_idx: usize,
1613916801 around: (bool, bool, i32),
1614016802 tx_mode: usize,
16141- plane: &mut PlaneBuf<'static>,
16803+ // lane-wave1 step (i): unread -- this reader records its write
16804+ // ([`push_intra`]/[`push_mc`]) instead of performing it; the borrow
16805+ // stays in the signature so every call site still proves the plane is
16806+ // exclusively held while its coefficients are parsed.
16807+ _plane: &mut PlaneBuf<'static>,
1614216808 x: usize,
1614316809 y: usize,
1614416810 prediction: &[u16],
@@ -16230,7 +16896,7 @@ fn read_inter_plane_rect(
1623016896 for row in 0..h {
1623116897 strided[row * stride..][..w].copy_from_slice(&residual[row * w..][..w]);
1623216898 }
16233- plane.reconstruct_mc_rect(x, y, stride, w, h, prediction, &strided, fctx);
16899+ push_mc_rect_owned(plane_idx, x, y, stride, w, h, prediction, strided, fctx);
1623416900 Ok((grid, tx_type))
1623516901 }
1623616902
@@ -18364,7 +19030,39 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
1836419030 // its one block covers all four 64x64 quadrants, so the remaining three
1836519031 // visits of this superblock code nothing at all.
1836619032 let mut sb128_none = false;
19033+ // lane-wave1 step (ii): at one reconstruction thread the recorded writes
19034+ // are performed at their push sites (nothing reaches the queue below).
19035+ let _recon_inline = ReconInline::install(fctx, &mut y, &mut u, &mut v);
19036+ // lane-wave1 step (ii): one job per superblock (per 128x128 superblock
19037+ // when `sb128`, since a 128 block writes across its four 64x64 visits).
19038+ let wave_shift = u32::from(sb128);
19039+ let (wave_r0, wave_c0) = ((sb_r0 >> wave_shift) as usize, (sb_c0 >> wave_shift) as usize);
19040+ let (wave_rows, wave_cols) = if sb_r1 > sb_r0 && sb_c1 > sb_c0 {
19041+ (
19042+ ((sb_r1 - 1) >> wave_shift) as usize - wave_r0 + 1,
19043+ ((sb_c1 - 1) >> wave_shift) as usize - wave_c0 + 1,
19044+ )
19045+ } else {
19046+ (0, 0)
19047+ };
19048+ let _wave = WaveGuard::install(fctx, &mut y, &mut u, &mut v, wave_rows, wave_cols);
19049+ let waving = fctx.wave.with(|w| w.borrow().is_some());
19050+ let mut wave_job = (0usize, 0usize);
1836719051 for (sb_r, sb_c, row_start, sb_start) in sb_visit_order(sb_r0, sb_r1, sb_c0, sb_c1, sb128) {
19052+ // lane-wave1: the previous superblock's recorded writes -- handed to
19053+ // the wavefront workers, or replayed here at one recon thread (where
19054+ // the queue is empty, every write having run at its push site).
19055+ if waving {
19056+ if sb_start {
19057+ wave_submit(fctx, wave_job.0, wave_job.1);
19058+ wave_job = (
19059+ (sb_r >> wave_shift) as usize - wave_r0,
19060+ (sb_c >> wave_shift) as usize - wave_c0,
19061+ );
19062+ }
19063+ } else {
19064+ flush_recon(fctx, &mut y, &mut u, &mut v);
19065+ }
1836819066 if row_start {
1836919067 neighbours.start_row();
1837019068 }
@@ -20105,6 +20803,10 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
2010520803 }
2010620804 }
2010720805 }
20806+ if waving {
20807+ wave_submit(fctx, wave_job.0, wave_job.1);
20808+ }
20809+ flush_recon(fctx, &mut y, &mut u, &mut v);
2010820810
2010920811 if tile_num == tile_info.context_update_tile_id {
2011020812 result_cdfs = cdfs;
@@ -20589,18 +21291,7 @@ impl PlaneBuf<'_> {
2058921291 /// compensation's output, rather than [`predict`]'s intra one), writing
2059021292 /// the clamped reconstruction into the plane at `(x, y)` -- the inter
2059121293 /// counterpart of [`PlaneBuf::reconstruct`].
20592- fn reconstruct_mc(
20593- &mut self,
20594- x: usize,
20595- y: usize,
20596- side: usize,
20597- prediction: &[u16],
20598- residual: &[i32], fctx: &crate::decode::FrameCtx,
20599- ) {
20600- self.reconstruct_mc_rect(x, y, side, side, side, prediction, residual, fctx);
20601- }
20602-
20603- /// [`Self::reconstruct_mc`], writing only a `w`x`h` sub-rectangle of the
21294+ /// [`Self::reconstruct_mc_rect`], writing only a `w`x`h` sub-rectangle of the
2060421295 /// `side`x`side` `prediction`/`residual` buffers (which stay `side`-square
2060521296 /// for stride/indexing) -- lane-partitions r1: a true rectangular HORZ/
2060621297 /// VERT strip is predicted at its enclosing square `side` (matching
@@ -20656,7 +21347,11 @@ fn read_inter_plane(
2065621347 plane_idx: usize,
2065721348 around: (bool, bool, i32),
2065821349 tx_mode: usize,
20659- plane: &mut PlaneBuf<'static>,
21350+ // lane-wave1 step (i): unread -- this reader records its write
21351+ // ([`push_intra`]/[`push_mc`]) instead of performing it; the borrow
21352+ // stays in the signature so every call site still proves the plane is
21353+ // exclusively held while its coefficients are parsed.
21354+ _plane: &mut PlaneBuf<'static>,
2066021355 x: usize,
2066121356 y: usize,
2066221357 side: usize,
@@ -20727,7 +21422,7 @@ fn read_inter_plane(
2072721422 };
2072821423 let (dc_delta, ac_delta) = plane_q_delta(plane_idx, fctx);
2072921424 let residual = dequant_and_inverse_typed(&grid, side, bit_depth(fctx), block_q_idx(fctx), dc_delta, ac_delta, tx_type);
20730- plane.reconstruct_mc(x, y, side, prediction, &residual, fctx);
21425+ push_mc_rect_owned(plane_idx, x, y, side, side, side, prediction, residual, fctx);
2073121426 Ok((grid, tx_type))
2073221427 }
2073321428
@@ -23244,7 +23939,7 @@ fn decode_inter_block(
2324423939 .1
2324523940 };
2324623941 if skip {
23247- y.reconstruct_mc_rect(
23942+ push_mc_rect(0,
2324823943 px,
2324923944 py,
2325023945 side,
@@ -23253,7 +23948,7 @@ fn decode_inter_block(
2325323948 &pred_y,
2325423949 &vec![0i32; side * side], fctx,
2325523950 );
23256- u.reconstruct_mc_rect(
23951+ push_mc_rect(1,
2325723952 cpx,
2325823953 cpy,
2325923954 chroma_side,
@@ -23262,7 +23957,7 @@ fn decode_inter_block(
2326223957 &pred_u,
2326323958 &vec![0i32; chroma_side * chroma_side], fctx,
2326423959 );
23265- v.reconstruct_mc_rect(
23960+ push_mc_rect(2,
2326623961 cpx,
2326723962 cpy,
2326823963 chroma_side,
@@ -24367,6 +25062,7 @@ fn decode_inter_block(
2436725062 // result, all planes (reconinter.c av1_build_interintra_predictor
2436825063 // plane loop).
2436925064 if let Some(ii) = interintra_mode {
25065+ flush_recon(fctx, y, u, v);
2437025066 if write_w != write_h {
2437125067 INTERINTRA_RECT_HITS.with(|c| c.set(c.get() + 1));
2437225068 }
@@ -24454,7 +25150,7 @@ fn decode_inter_block(
2445425150 .1
2445525151 };
2445625152 if skip {
24457- y.reconstruct_mc_rect(
25153+ push_mc_rect(0,
2445825154 px,
2445925155 py,
2446025156 side,
@@ -24464,7 +25160,7 @@ fn decode_inter_block(
2446425160 &vec![0i32; side * side], fctx,
2446525161 );
2446625162 if has_chroma {
24467- u.reconstruct_mc_rect(
25163+ push_mc_rect(1,
2446825164 cpx,
2446925165 cpy,
2447025166 chroma_side,
@@ -24473,7 +25169,7 @@ fn decode_inter_block(
2447325169 &pred_u,
2447425170 &vec![0i32; chroma_side * chroma_side], fctx,
2447525171 );
24476- v.reconstruct_mc_rect(
25172+ push_mc_rect(2,
2447725173 cpx,
2447825174 cpy,
2447925175 chroma_side,
@@ -25216,7 +25912,7 @@ fn decode_inter_block(
2521625912 set_palette_pred(window, fctx);
2521725913 }
2521825914 let tu_grid = if skip {
25219- y.reconstruct(
25915+ push_intra(0,
2522025916 tu_px,
2522125917 tu_py,
2522225918 tx_px,
@@ -25286,7 +25982,7 @@ fn decode_inter_block(
2528625982 for plane_idx in 1..3 {
2528725983 let buf: &mut PlaneBuf<'static> = if plane_idx == 1 { &mut *u } else { &mut *v };
2528825984 let cu_grid = if skip {
25289- buf.reconstruct(
25985+ push_intra(plane_idx,
2529025986 cu_x,
2529125987 cu_y,
2529225988 cu_tx,
@@ -25356,7 +26052,7 @@ fn decode_inter_block(
2535626052 if let Some(buf) = &palette_y_buf {
2535726053 set_palette_pred(buf.clone(), fctx);
2535826054 }
25359- y.reconstruct(
26055+ push_intra(0,
2536026056 px,
2536126057 py,
2536226058 side,
@@ -25369,11 +26065,11 @@ fn decode_inter_block(
2536926065 smooth_neighbor, fctx,
2537026066 );
2537126067 }
25372- let ac = alpha.map(|_| cfl_ac_q3(y, px, py, side));
26068+ let ac = alpha.map(|_| cfl_src(px, py, side));
2537326069 if let Some((ub, _)) = &palette_uv_bufs {
2537426070 set_palette_pred(ub.clone(), fctx);
2537526071 }
25376- u.reconstruct(
26072+ push_intra(1,
2537726073 cpx,
2537826074 cpy,
2537926075 chroma_side,
@@ -25381,14 +26077,14 @@ fn decode_inter_block(
2538126077 angle_delta_uv,
2538226078 reach,
2538326079 &vec![0i32; chroma_side * chroma_side],
25384- alpha.zip(ac.as_deref()).map(|((au, _), ac)| (au, ac)),
26080+ alpha.zip(ac).map(|((au, _), ac)| (au, ac)),
2538526081 None,
2538626082 smooth_neighbor_uv, fctx,
2538726083 );
2538826084 if let Some((_, vb)) = &palette_uv_bufs {
2538926085 set_palette_pred(vb.clone(), fctx);
2539026086 }
25391- v.reconstruct(
26087+ push_intra(2,
2539226088 cpx,
2539326089 cpy,
2539426090 chroma_side,
@@ -25396,7 +26092,7 @@ fn decode_inter_block(
2539626092 angle_delta_uv,
2539726093 reach,
2539826094 &vec![0i32; chroma_side * chroma_side],
25399- alpha.zip(ac.as_deref()).map(|((_, av), ac)| (av, ac)),
26095+ alpha.zip(ac).map(|((_, av), ac)| (av, ac)),
2540026096 None,
2540126097 smooth_neighbor_uv, fctx,
2540226098 );
@@ -25437,7 +26133,7 @@ fn decode_inter_block(
2543726133 smooth_neighbor, fctx,
2543826134 )?
2543926135 };
25440- let ac = alpha.map(|_| cfl_ac_q3(y, px, py, side));
26136+ let ac = alpha.map(|_| cfl_src(px, py, side));
2544126137 if let Some((ub, _)) = &palette_uv_bufs {
2544226138 set_palette_pred(ub.clone(), fctx);
2544326139 }
@@ -25458,7 +26154,7 @@ fn decode_inter_block(
2545826154 chroma_side,
2545926155 chroma_tx,
2546026156 base_q_idx,
25461- alpha.zip(ac.as_deref()).map(|((au, _), ac)| (au, ac)),
26157+ alpha.zip(ac).map(|((au, _), ac)| (au, ac)),
2546226158 None,
2546326159 None,
2546426160 smooth_neighbor_uv, fctx,
@@ -25483,7 +26179,7 @@ fn decode_inter_block(
2548326179 chroma_side,
2548426180 chroma_tx,
2548526181 base_q_idx,
25486- alpha.zip(ac.as_deref()).map(|((_, av), ac)| (av, ac)),
26182+ alpha.zip(ac).map(|((_, av), ac)| (av, ac)),
2548726183 None,
2548826184 None,
2548926185 smooth_neighbor_uv, fctx,
@@ -26094,7 +26790,7 @@ fn decode_inter_sub8_split4(
2609426790 // txsize_to_bsize[tx_size]` branch (`txb_skip_ctx = 0`, which
2609526791 // `read_inter_plane`'s `plane_idx == 0` arm already assumes).
2609626792 if skip {
26097- y.reconstruct_mc(px, py, B4, &pred_y, &vec![0i32; B4 * B4], fctx);
26793+ push_mc(0, px, py, B4, &pred_y, &vec![0i32; B4 * B4], fctx);
2609826794 neighbours.record_mi_luma_rect(lmi, B4, B4, &vec![0i32; B4 * B4]);
2609926795 } else {
2610026796 let around = neighbours.around_mi(lmi, B4);
@@ -26209,8 +26905,8 @@ fn decode_inter_sub8_split4(
2620926905 }
2621026906 }
2621126907 let (u_grid, v_grid) = if last_skip {
26212- u.reconstruct_mc(cpx, cpy, B4, &pred_u, &vec![0i32; B4 * B4], fctx);
26213- v.reconstruct_mc(cpx, cpy, B4, &pred_v, &vec![0i32; B4 * B4], fctx);
26908+ push_mc(1, cpx, cpy, B4, &pred_u, &vec![0i32; B4 * B4], fctx);
26909+ push_mc(2, cpx, cpy, B4, &pred_v, &vec![0i32; B4 * B4], fctx);
2621426910 (vec![0i32; B4 * B4], vec![0i32; B4 * B4])
2621526911 } else {
2621626912 let around = neighbours.around_mi(group_mi, 8);
@@ -26439,7 +27135,7 @@ fn decode_intra_sub8_leaf(
2643927135 );
2644027136 if skip {
2644127137 let zeros = vec![0i32; 16];
26442- y.reconstruct(
27138+ push_intra(0,
2644327139 tu_px, tu_py, 4, mode, angle_delta_y, tu_reach, &zeros, None, filter_intra,
2644427140 smooth_neighbor, fctx,
2644527141 );
@@ -26481,7 +27177,7 @@ fn decode_intra_sub8_leaf(
2648127177 // fixes `txb_skip_ctx` at 0 (`luma_skip_ctx: None`) -- the same square
2648227178 // reader [`decode_leaf_split4`] uses.
2648327179 if skip {
26484- y.reconstruct(
27180+ push_intra(0,
2648527181 px, py, 4, mode, angle_delta_y, reach, &vec![0i32; 16], None, filter_intra,
2648627182 smooth_neighbor, fctx,
2648727183 );
@@ -26519,7 +27215,7 @@ fn decode_intra_sub8_leaf(
2651927215 } else {
2652027216 let grid_levels = if skip {
2652127217 let zeros = vec![0i32; bw * bh];
26522- y.reconstruct_rect(
27218+ push_intra_rect(0,
2652327219 px, py, bw, bh, mode, angle_delta_y, reach, &zeros, None, filter_intra,
2652427220 smooth_neighbor, fctx,
2652527221 );
@@ -26554,7 +27250,7 @@ fn decode_intra_sub8_leaf(
2655427250 plane_q_delta(0, fctx).1,
2655527251 tx_type,
2655627252 );
26557- y.reconstruct_rect(
27253+ push_intra_rect(0,
2655827254 px, py, bw, bh, mode, angle_delta_y, reach, &residual, None, filter_intra,
2655927255 smooth_neighbor, fctx,
2656027256 );
@@ -26649,26 +27345,26 @@ fn decode_intra_sub8_leaf(
2664927345 // needs `bsize >= BLOCK_8X8`), so the group always clears.
2665027346 record_strip_palette(neighbours, (gr, gc), 8, 8, 0, [0u16; 8], 0, [0u16; 8]);
2665127347
26652- let ac = alpha.map(|_| cfl_ac_q3(y, gpx, gpy, 8));
27348+ let ac = alpha.map(|_| cfl_src(gpx, gpy, 8));
2665327349 let (u_grid, v_grid): (Vec<i32>, Vec<i32>) = if skip {
2665427350 if alpha.is_some() {
2665527351 CHROMA_SKIP_CFL_HITS.with(|h| h.set(h.get() + 1));
2665627352 SKIP_CFL_HITS.with(|c| c.set(c.get() + 1));
2665727353 }
26658- u.reconstruct(cpx, cpy, 4, uv_predict_mode, angle_delta_uv, group_reach, &vec![0i32; 16], alpha.zip(ac.as_deref()).map(|((au, _), ac)| (au, ac)), None, smooth_neighbor_uv, fctx);
26659- v.reconstruct(cpx, cpy, 4, uv_predict_mode, angle_delta_uv, group_reach, &vec![0i32; 16], alpha.zip(ac.as_deref()).map(|((_, av), ac)| (av, ac)), None, smooth_neighbor_uv, fctx);
27354+ 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);
27355+ 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);
2666027356 (vec![0i32; 16], vec![0i32; 16])
2666127357 } else {
2666227358 let chroma_around = neighbours.around_mi(group_mi, 8);
2666327359 let ug = read_plane(
2666427360 dec, cdfs, TxbSet::Chroma4, scan4, 1, chroma_around[1], uv_mode, uv_predict_mode,
2666527361 angle_delta_uv, group_reach, u, cpx, cpy, 4, TX4, base_q_idx,
26666- alpha.zip(ac.as_deref()).map(|((au, _), ac)| (au, ac)), None, None, smooth_neighbor_uv, fctx,
27362+ alpha.zip(ac).map(|((au, _), ac)| (au, ac)), None, None, smooth_neighbor_uv, fctx,
2666727363 )?;
2666827364 let vg = read_plane(
2666927365 dec, cdfs, TxbSet::Chroma4, scan4, 2, chroma_around[2], uv_mode, uv_predict_mode,
2667027366 angle_delta_uv, group_reach, v, cpx, cpy, 4, TX4, base_q_idx,
26671- alpha.zip(ac.as_deref()).map(|((_, av), ac)| (av, ac)), None, None, smooth_neighbor_uv, fctx,
27367+ alpha.zip(ac).map(|((_, av), ac)| (av, ac)), None, None, smooth_neighbor_uv, fctx,
2667227368 )?;
2667327369 (ug, vg)
2667427370 };
@@ -27067,7 +27763,7 @@ fn decode_inter_sub8_rect2(
2706727763 }
2706827764 }
2706927765 if skip {
27070- y.reconstruct_mc_rect(px, py, SIDE, bw, bh, &pred_y, &vec![0i32; SIDE * SIDE], fctx);
27766+ push_mc_rect(0, px, py, SIDE, bw, bh, &pred_y, &vec![0i32; SIDE * SIDE], fctx);
2707127767 neighbours.record_mi_luma_rect(lmi, bw, bh, &vec![0i32; bw * bh]);
2707227768 neighbours.fill_lf_grid_rect(lmi, w_mi, h_mi, bw as u8, bh as u8, ref_frame.max(LAST_FRAME), fctx);
2707327769 } else {
@@ -27233,8 +27929,8 @@ fn decode_inter_sub8_rect2(
2723327929 }
2723427930 }
2723527931 let (u_grid, v_grid) = if last_skip {
27236- u.reconstruct_mc(cpx, cpy, B4, &pred_u, &vec![0i32; B4 * B4], fctx);
27237- v.reconstruct_mc(cpx, cpy, B4, &pred_v, &vec![0i32; B4 * B4], fctx);
27932+ push_mc(1, cpx, cpy, B4, &pred_u, &vec![0i32; B4 * B4], fctx);
27933+ push_mc(2, cpx, cpy, B4, &pred_v, &vec![0i32; B4 * B4], fctx);
2723827934 (vec![0i32; B4 * B4], vec![0i32; B4 * B4])
2723927935 } else {
2724027936 let around = neighbours.around_mi(group_mi, 8);
@@ -28070,15 +28766,15 @@ fn decode_inter_block8(
2807028766 .1
2807128767 .is_some();
2807228768 if skip {
28073- y.reconstruct_mc(px, py, SIDE, &pred_y, &vec![0i32; SIDE * SIDE], fctx);
28074- u.reconstruct_mc(
28769+ push_mc(0, px, py, SIDE, &pred_y, &vec![0i32; SIDE * SIDE], fctx);
28770+ push_mc(1,
2807528771 cpx,
2807628772 cpy,
2807728773 CHROMA_SIDE,
2807828774 &pred_u,
2807928775 &vec![0i32; CHROMA_SIDE * CHROMA_SIDE], fctx,
2808028776 );
28081- v.reconstruct_mc(
28777+ push_mc(2,
2808228778 cpx,
2808328779 cpy,
2808428780 CHROMA_SIDE,
@@ -28697,6 +29393,7 @@ fn decode_inter_block8(
2869729393 // Non-wedge interintra blend, mutually exclusive with OBMC (the
2869829394 // motion_mode symbol is not read for an interintra block).
2869929395 if let Some(ii) = interintra_mode {
29396+ flush_recon(fctx, y, u, v);
2870029397 interintra_blend(y, px, py, SIDE, SIDE, SIDE, ii, wedge_mask, &mut pred_y, fctx);
2870129398 interintra_blend(
2870229399 u, cpx, cpy, CHROMA_SIDE, CHROMA_SIDE, CHROMA_SIDE, ii, wedge_mask, &mut pred_u, fctx,
@@ -28719,15 +29416,15 @@ fn decode_inter_block8(
2871929416 .1
2872029417 .is_some();
2872129418 if skip {
28722- y.reconstruct_mc(px, py, SIDE, &pred_y, &vec![0i32; SIDE * SIDE], fctx);
28723- u.reconstruct_mc(
29419+ push_mc(0, px, py, SIDE, &pred_y, &vec![0i32; SIDE * SIDE], fctx);
29420+ push_mc(1,
2872429421 cpx,
2872529422 cpy,
2872629423 CHROMA_SIDE,
2872729424 &pred_u,
2872829425 &vec![0i32; CHROMA_SIDE * CHROMA_SIDE], fctx,
2872929426 );
28730- v.reconstruct_mc(
29427+ push_mc(2,
2873129428 cpx,
2873229429 cpy,
2873329430 CHROMA_SIDE,
@@ -29090,7 +29787,7 @@ fn decode_inter_block8(
2909029787 set_palette_pred(window, fctx);
2909129788 }
2909229789 let tu_grid = if skip {
29093- y.reconstruct(
29790+ push_intra(0,
2909429791 tu_px,
2909529792 tu_py,
2909629793 tx_px,
@@ -29143,7 +29840,7 @@ fn decode_inter_block8(
2914329840 if let Some(buf) = &palette_y_buf {
2914429841 set_palette_pred(buf.clone(), fctx);
2914529842 }
29146- y.reconstruct(
29843+ push_intra(0,
2914729844 px,
2914829845 py,
2914929846 SIDE,
@@ -29158,11 +29855,11 @@ fn decode_inter_block8(
2915829855 }
2915929856 // CfL's AC contribution is the luma this leaf just reconstructed,
2916029857 // averaged over the 4x4 chroma block (`cfl_ac_q3`, spec 7.11.5).
29161- let ac = alpha.map(|_| cfl_ac_q3(y, px, py, SIDE));
29858+ let ac = alpha.map(|_| cfl_src(px, py, SIDE));
2916229859 if let Some((ub, _)) = &palette_uv_bufs {
2916329860 set_palette_pred(ub.clone(), fctx);
2916429861 }
29165- u.reconstruct(
29862+ push_intra(1,
2916629863 cpx,
2916729864 cpy,
2916829865 CHROMA_SIDE,
@@ -29170,14 +29867,14 @@ fn decode_inter_block8(
2917029867 angle_delta_uv,
2917129868 reach,
2917229869 &vec![0i32; CHROMA_SIDE * CHROMA_SIDE],
29173- alpha.zip(ac.as_deref()).map(|((au, _), ac)| (au, ac)),
29870+ alpha.zip(ac).map(|((au, _), ac)| (au, ac)),
2917429871 None,
2917529872 smooth_neighbor_uv, fctx,
2917629873 );
2917729874 if let Some((_, vb)) = &palette_uv_bufs {
2917829875 set_palette_pred(vb.clone(), fctx);
2917929876 }
29180- v.reconstruct(
29877+ push_intra(2,
2918129878 cpx,
2918229879 cpy,
2918329880 CHROMA_SIDE,
@@ -29185,7 +29882,7 @@ fn decode_inter_block8(
2918529882 angle_delta_uv,
2918629883 reach,
2918729884 &vec![0i32; CHROMA_SIDE * CHROMA_SIDE],
29188- alpha.zip(ac.as_deref()).map(|((_, av), ac)| (av, ac)),
29885+ alpha.zip(ac).map(|((_, av), ac)| (av, ac)),
2918929886 None,
2919029887 smooth_neighbor_uv, fctx,
crates/ec-av1/src/par.rsmodified+28 -0
@@ -133,3 +133,31 @@ where
133133 }
134134 }
135135 }
136+
137+/// `EC_AV1_RECON_THREADS`, the number of worker threads a tile's
138+/// reconstruction (lane-wave1) is spread across, in superblock-row wavefront
139+/// order (default 1 = reconstruct inline at the parse site, i.e. exactly the
140+/// pre-wavefront decoder). Read once per process, same shape as
141+/// [`filter_threads`].
142+static RECON_THREADS: std::sync::atomic::AtomicUsize = std::sync::atomic::AtomicUsize::new(0);
143+
144+pub(crate) fn recon_threads() -> usize {
145+ match RECON_THREADS.load(std::sync::atomic::Ordering::Relaxed) {
146+ 0 => {
147+ let n = crate::envflags::var("EC_AV1_RECON_THREADS")
148+ .ok()
149+ .and_then(|v| v.trim().parse::<usize>().ok())
150+ .unwrap_or(1)
151+ .clamp(1, 64);
152+ RECON_THREADS.store(n, std::sync::atomic::Ordering::Relaxed);
153+ n
154+ }
155+ n => n,
156+ }
157+}
158+
159+/// Test-only override of [`recon_threads`] -- see [`set_filter_threads`].
160+#[cfg(test)]
161+pub(crate) fn set_recon_threads(n: usize) {
162+ RECON_THREADS.store(n.clamp(1, 64), std::sync::atomic::Ordering::Relaxed);
163+}
crates/ec-av1/src/stream.rsmodified+44 -0
@@ -6106,6 +6106,50 @@ mod tests {
61066106 /// `--denoise-noise-level=25` stream whose frames carry film grain
61076107 /// parameters (small enough that 4 bands is one block row each, which is
61086108 /// what exercises the grain band's one-row `prelude` replay).
6109+ /// lane-wave1 step (ii): the superblock-row wavefront
6110+ /// (`EC_AV1_RECON_THREADS`) reconstructs every output frame byte for
6111+ /// byte as the inline path does, on a hidden-ARF 10-bit stream (no-show
6112+ /// frames, CfL, 128 superblocks) and on the two screen-content streams
6113+ /// whose palette/intrabc blocks READ the current frame's pixels while
6114+ /// parsing -- the sites that make the workers barrier.
6115+ #[test]
6116+ fn a_real_stream_reconstructs_identically_with_one_and_four_recon_threads() {
6117+ const NAME: &str = "a_real_stream_reconstructs_identically_with_one_and_four_recon_threads";
6118+ let _gate_lock = lock_gate_counters();
6119+ for fixture in [
6120+ "reelb_arf_witness.obu",
6121+ "palette_screen_witness.obu",
6122+ "palette_screen_witness_10bit.obu",
6123+ ] {
6124+ let path = std::path::Path::new(env!("CARGO_MANIFEST_DIR"))
6125+ .join("fixtures")
6126+ .join(fixture);
6127+ let stream = std::fs::read(&path)
6128+ .unwrap_or_else(|e| panic!("{NAME}: reading {}: {e}", path.display()));
6129+ crate::par::set_recon_threads(1);
6130+ let one = match decode_stream(&stream) {
6131+ Ok(frames) => frames,
6132+ Err(e) => panic!("{NAME}: {fixture} refused at 1 recon thread: {e}"),
6133+ };
6134+ crate::par::set_recon_threads(4);
6135+ let four = match decode_stream(&stream) {
6136+ Ok(frames) => frames,
6137+ Err(e) => {
6138+ crate::par::set_recon_threads(1);
6139+ panic!("{NAME}: {fixture} refused at 4 recon threads: {e}")
6140+ }
6141+ };
6142+ crate::par::set_recon_threads(1);
6143+ assert!(!one.is_empty(), "{NAME}: {fixture} decoded nothing");
6144+ assert_eq!(one.len(), four.len(), "{NAME}: {fixture} frame count");
6145+ for (i, (a, b)) in one.iter().zip(four.iter()).enumerate() {
6146+ assert_eq!(a.y, b.y, "{NAME}: {fixture} frame {i} luma differs at 4 recon threads");
6147+ assert_eq!(a.u, b.u, "{NAME}: {fixture} frame {i} U differs at 4 recon threads");
6148+ assert_eq!(a.v, b.v, "{NAME}: {fixture} frame {i} V differs at 4 recon threads");
6149+ }
6150+ }
6151+ }
6152+
61096153 #[test]
61106154 fn a_real_stream_filters_identically_with_one_and_four_filter_threads() {
61116155 const NAME: &str = "a_real_stream_filters_identically_with_one_and_four_filter_threads";