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 {
79 pub(crate) last_frame_wide_margin: std::cell::RefCell<Option<Picture>>,79 pub(crate) last_frame_wide_margin: std::cell::RefCell<Option<Picture>>,
80 pub(crate) reach_sb_px: std::cell::Cell<usize>,80 pub(crate) reach_sb_px: std::cell::Cell<usize>,
81 pub(crate) grain_bit_depth: std::cell::Cell<u32>,81 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>>>,
82 }96 }
83 97
84 impl std::fmt::Debug for FrameCtx {98 impl std::fmt::Debug for FrameCtx {
@@ -136,6 +150,10 @@ impl FrameCtx {
136 last_frame_wide_margin: std::cell::RefCell::new(None),150 last_frame_wide_margin: std::cell::RefCell::new(None),
137 reach_sb_px: std::cell::Cell::new(crate::encode::SUPERBLOCK),151 reach_sb_px: std::cell::Cell::new(crate::encode::SUPERBLOCK),
138 grain_bit_depth: std::cell::Cell::new(8),152 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),
139 }157 }
140 }158 }
141 }159 }
@@ -2010,6 +2028,635 @@ fn take_palette_pred(fctx: &crate::decode::FrameCtx) -> Option<Vec<u16>> {
2010 got2028 got
2011 }2029 }
2012 2030
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+
2013 thread_local! {2660 thread_local! {
2014 /// The current frame's `mi` grid, kept only while a frame header set2661 /// The current frame's `mi` grid, kept only while a frame header set
2015 /// `allow_intrabc` -- an intrabc block's DV predictor is the ordinary2662 /// `allow_intrabc` -- an intrabc block's DV predictor is the ordinary
@@ -7693,7 +8340,7 @@ fn decode_rect_split(
7693 set_palette_pred(tu_buf, fctx);8340 set_palette_pred(tu_buf, fctx);
7694 }8341 }
7695 if m.skip {8342 if m.skip {
7696- y.reconstruct_rect(8343+ push_intra_rect(0,
7697 tu_px,8344 tu_px,
7698 tu_py,8345 tu_py,
7699 tx_w,8346 tx_w,
@@ -7751,7 +8398,7 @@ fn decode_rect_split(
7751 plane_q_delta(0, fctx).1,8398 plane_q_delta(0, fctx).1,
7752 tu_tx_type,8399 tu_tx_type,
7753 );8400 );
7754- y.reconstruct_rect(8401+ push_intra_rect(0,
7755 tu_px,8402 tu_px,
7756 tu_py,8403 tu_py,
7757 tx_w,8404 tx_w,
@@ -7807,7 +8454,7 @@ fn decode_rect_split(
7807 plane_q_delta(0, fctx).1,8454 plane_q_delta(0, fctx).1,
7808 tu_tx_type,8455 tu_tx_type,
7809 );8456 );
7810- y.reconstruct_rect(8457+ push_intra_rect(0,
7811 tu_px,8458 tu_px,
7812 tu_py,8459 tu_py,
7813 tx_w,8460 tx_w,
@@ -7854,23 +8501,23 @@ fn decode_rect_split(
7854 }8501 }
7855 }8502 }
7856 // CHROMA: one un-split rect transform for the whole strip.8503 // 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));
7858 let reach = block_reach;8505 let reach = block_reach;
7859 let (u_grid, v_grid) = if m.skip {8506 let (u_grid, v_grid) = if m.skip {
7860 let zero = vec![0i32; chroma_w * chroma_h];8507 let zero = vec![0i32; chroma_w * chroma_h];
7861 if let Some((ub, _)) = &m.palette_uv {8508 if let Some((ub, _)) = &m.palette_uv {
7862 set_palette_pred(ub.clone(), fctx);8509 set_palette_pred(ub.clone(), fctx);
7863 }8510 }
7864- u.reconstruct_rect(8511+ push_intra_rect(1,
7865 cpx, cpy, chroma_w, chroma_h, m.uv_predict_mode, m.angle_delta_uv, reach, &zero,8512 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,
7867 );8514 );
7868 if let Some((_, vb)) = &m.palette_uv {8515 if let Some((_, vb)) = &m.palette_uv {
7869 set_palette_pred(vb.clone(), fctx);8516 set_palette_pred(vb.clone(), fctx);
7870 }8517 }
7871- v.reconstruct_rect(8518+ push_intra_rect(2,
7872 cpx, cpy, chroma_w, chroma_h, m.uv_predict_mode, m.angle_delta_uv, reach, &zero,8519 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,
7874 );8521 );
7875 (zero.clone(), zero)8522 (zero.clone(), zero)
7876 } else {8523 } else {
@@ -7918,14 +8565,14 @@ fn decode_rect_split(
7918 );8565 );
7919 let cfl = m8566 let cfl = m
7920 .alpha8567 .alpha
7921- .zip(ac.as_deref())8568+ .zip(ac)
7922 .map(|((au, av), ac)| (if plane_idx == 1 { au } else { av }, ac));8569 .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 };
7924 if let Some((ub, vb)) = &m.palette_uv {8571 if let Some((ub, vb)) = &m.palette_uv {
7925 let buf = if plane_idx == 1 { ub } else { vb };8572 let buf = if plane_idx == 1 { ub } else { vb };
7926 set_palette_pred(buf.clone(), fctx);8573 set_palette_pred(buf.clone(), fctx);
7927 }8574 }
7928- plane.reconstruct_rect(8575+ push_intra_rect(plane_idx,
7929 cpx,8576 cpx,
7930 cpy,8577 cpy,
7931 chroma_w,8578 chroma_w,
@@ -8888,7 +9535,7 @@ fn decode_block_rect(
8888 )9535 )
8889 });9536 });
8890 if skip {9537 if skip {
8891- y.reconstruct_rect(9538+ push_intra_rect(0,
8892 px,9539 px,
8893 py,9540 py,
8894 bw,9541 bw,
@@ -8901,11 +9548,11 @@ fn decode_block_rect(
8901 filter_intra,9548 filter_intra,
8902 smooth_neighbor, fctx,9549 smooth_neighbor, fctx,
8903 );9550 );
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));
8905 if let Some((ub, _)) = &palette_uv_bufs {9552 if let Some((ub, _)) = &palette_uv_bufs {
8906 set_palette_pred(ub.clone(), fctx);9553 set_palette_pred(ub.clone(), fctx);
8907 }9554 }
8908- u.reconstruct_rect(9555+ push_intra_rect(1,
8909 cpx,9556 cpx,
8910 cpy,9557 cpy,
8911 chroma_w,9558 chroma_w,
@@ -8914,14 +9561,14 @@ fn decode_block_rect(
8914 angle_delta_uv,9561 angle_delta_uv,
8915 reach,9562 reach,
8916 &vec![0i32; chroma_w * chroma_h],9563 &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)),
8918 None,9565 None,
8919 smooth_neighbor_uv, fctx,9566 smooth_neighbor_uv, fctx,
8920 );9567 );
8921 if let Some((_, vb)) = &palette_uv_bufs {9568 if let Some((_, vb)) = &palette_uv_bufs {
8922 set_palette_pred(vb.clone(), fctx);9569 set_palette_pred(vb.clone(), fctx);
8923 }9570 }
8924- v.reconstruct_rect(9571+ push_intra_rect(2,
8925 cpx,9572 cpx,
8926 cpy,9573 cpy,
8927 chroma_w,9574 chroma_w,
@@ -8930,7 +9577,7 @@ fn decode_block_rect(
8930 angle_delta_uv,9577 angle_delta_uv,
8931 reach,9578 reach,
8932 &vec![0i32; chroma_w * chroma_h],9579 &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)),
8934 None,9581 None,
8935 smooth_neighbor_uv, fctx,9582 smooth_neighbor_uv, fctx,
8936 );9583 );
@@ -9018,7 +9665,7 @@ fn decode_block_rect(
9018 plane_q_delta(0, fctx).1,9665 plane_q_delta(0, fctx).1,
9019 luma_tx_type,9666 luma_tx_type,
9020 );9667 );
9021- y.reconstruct_rect(9668+ push_intra_rect(0,
9022 px,9669 px,
9023 py,9670 py,
9024 bw,9671 bw,
@@ -9031,7 +9678,7 @@ fn decode_block_rect(
9031 filter_intra,9678 filter_intra,
9032 smooth_neighbor, fctx,9679 smooth_neighbor, fctx,
9033 );9680 );
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));
9035 if let Some((ub, _)) = &palette_uv_bufs {9682 if let Some((ub, _)) = &palette_uv_bufs {
9036 set_palette_pred(ub.clone(), fctx);9683 set_palette_pred(ub.clone(), fctx);
9037 }9684 }
@@ -9062,7 +9709,7 @@ fn decode_block_rect(
9062 plane_q_delta(1, fctx).1,9709 plane_q_delta(1, fctx).1,
9063 u_tx_type,9710 u_tx_type,
9064 );9711 );
9065- u.reconstruct_rect(9712+ push_intra_rect(1,
9066 cpx,9713 cpx,
9067 cpy,9714 cpy,
9068 chroma_w,9715 chroma_w,
@@ -9071,7 +9718,7 @@ fn decode_block_rect(
9071 angle_delta_uv,9718 angle_delta_uv,
9072 reach,9719 reach,
9073 &u_residual,9720 &u_residual,
9074- alpha.zip(ac.as_deref()).map(|((au, _), ac)| (au, ac)),9721+ alpha.zip(ac).map(|((au, _), ac)| (au, ac)),
9075 None,9722 None,
9076 smooth_neighbor_uv, fctx,9723 smooth_neighbor_uv, fctx,
9077 );9724 );
@@ -9105,7 +9752,7 @@ fn decode_block_rect(
9105 plane_q_delta(2, fctx).1,9752 plane_q_delta(2, fctx).1,
9106 v_tx_type,9753 v_tx_type,
9107 );9754 );
9108- v.reconstruct_rect(9755+ push_intra_rect(2,
9109 cpx,9756 cpx,
9110 cpy,9757 cpy,
9111 chroma_w,9758 chroma_w,
@@ -9114,7 +9761,7 @@ fn decode_block_rect(
9114 angle_delta_uv,9761 angle_delta_uv,
9115 reach,9762 reach,
9116 &v_residual,9763 &v_residual,
9117- alpha.zip(ac.as_deref()).map(|((_, av), ac)| (av, ac)),9764+ alpha.zip(ac).map(|((_, av), ac)| (av, ac)),
9118 None,9765 None,
9119 smooth_neighbor_uv, fctx,9766 smooth_neighbor_uv, fctx,
9120 );9767 );
@@ -9359,24 +10006,24 @@ fn decode_leaf_rect(
9359 if let Some(b) = &palette_y_buf {10006 if let Some(b) = &palette_y_buf {
9360 set_palette_pred(b.clone(), fctx);10007 set_palette_pred(b.clone(), fctx);
9361 }10008 }
9362- y.reconstruct_rect(10009+ push_intra_rect(0,
9363 px, py, bw, bh, mode, angle_delta_y, reach, &luma_levels, None, filter_intra,10010 px, py, bw, bh, mode, angle_delta_y, reach, &luma_levels, None, filter_intra,
9364 smooth_neighbor, fctx,10011 smooth_neighbor, fctx,
9365 );10012 );
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));
9367 if let Some((ub, _)) = &palette_uv_bufs {10014 if let Some((ub, _)) = &palette_uv_bufs {
9368 set_palette_pred(ub.clone(), fctx);10015 set_palette_pred(ub.clone(), fctx);
9369 }10016 }
9370- u.reconstruct_rect(10017+ push_intra_rect(1,
9371 cpx, cpy, chroma_w, chroma_h, uv_predict_mode, angle_delta_uv, reach, &u_levels,10018 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,
9373 );10020 );
9374 if let Some((_, vb)) = &palette_uv_bufs {10021 if let Some((_, vb)) = &palette_uv_bufs {
9375 set_palette_pred(vb.clone(), fctx);10022 set_palette_pred(vb.clone(), fctx);
9376 }10023 }
9377- v.reconstruct_rect(10024+ push_intra_rect(2,
9378 cpx, cpy, chroma_w, chroma_h, uv_predict_mode, angle_delta_uv, reach, &v_levels,10025 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,
9380 );10027 );
9381 } else {10028 } else {
9382 // lane-rectx: a genuine 16x8/8x16 luma transform (`TxbSet::LumaRect16x8`,10029 // lane-rectx: a genuine 16x8/8x16 luma transform (`TxbSet::LumaRect16x8`,
@@ -9412,11 +10059,11 @@ fn decode_leaf_rect(
9412 if let Some(b) = &palette_y_buf {10059 if let Some(b) = &palette_y_buf {
9413 set_palette_pred(b.clone(), fctx);10060 set_palette_pred(b.clone(), fctx);
9414 }10061 }
9415- y.reconstruct_rect(10062+ push_intra_rect(0,
9416 px, py, bw, bh, mode, angle_delta_y, reach, &luma_residual, None, filter_intra,10063 px, py, bw, bh, mode, angle_delta_y, reach, &luma_residual, None, filter_intra,
9417 smooth_neighbor, fctx,10064 smooth_neighbor, fctx,
9418 );10065 );
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));
9420 let u_default_tx = default_intra_tx_type(uv_predict_mode as u8);10067 let u_default_tx = default_intra_tx_type(uv_predict_mode as u8);
9421 let u_skip_ctx = usize::from(around[1].0) + usize::from(around[1].1);10068 let u_skip_ctx = usize::from(around[1].0) + usize::from(around[1].1);
9422 let mut u_coding = cdfs.txb(TxbSet::ChromaRect8x4, uv_predict_mode);10069 let mut u_coding = cdfs.txb(TxbSet::ChromaRect8x4, uv_predict_mode);
@@ -9432,9 +10079,9 @@ fn decode_leaf_rect(
9432 if let Some((ub, _)) = &palette_uv_bufs {10079 if let Some((ub, _)) = &palette_uv_bufs {
9433 set_palette_pred(ub.clone(), fctx);10080 set_palette_pred(ub.clone(), fctx);
9434 }10081 }
9435- u.reconstruct_rect(10082+ push_intra_rect(1,
9436 cpx, cpy, chroma_w, chroma_h, uv_predict_mode, angle_delta_uv, reach, &u_residual,10083 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,
9438 );10085 );
9439 let v_default_tx = default_intra_tx_type(uv_predict_mode as u8);10086 let v_default_tx = default_intra_tx_type(uv_predict_mode as u8);
9440 let v_skip_ctx = usize::from(around[2].0) + usize::from(around[2].1);10087 let v_skip_ctx = usize::from(around[2].0) + usize::from(around[2].1);
@@ -9451,9 +10098,9 @@ fn decode_leaf_rect(
9451 if let Some((_, vb)) = &palette_uv_bufs {10098 if let Some((_, vb)) = &palette_uv_bufs {
9452 set_palette_pred(vb.clone(), fctx);10099 set_palette_pred(vb.clone(), fctx);
9453 }10100 }
9454- v.reconstruct_rect(10101+ push_intra_rect(2,
9455 cpx, cpy, chroma_w, chroma_h, uv_predict_mode, angle_delta_uv, reach, &v_residual,10102 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,
9457 );10104 );
9458 RECT_LEAF_COEFF_HITS.with(|c| c.set(c.get() + 1));10105 RECT_LEAF_COEFF_HITS.with(|c| c.set(c.get() + 1));
9459 }10106 }
@@ -9798,7 +10445,7 @@ fn decode_block_rect4(
9798 if let Some(b) = &palette_y_buf {10445 if let Some(b) = &palette_y_buf {
9799 set_palette_pred(b.clone(), fctx);10446 set_palette_pred(b.clone(), fctx);
9800 }10447 }
9801- y.reconstruct_rect(10448+ push_intra_rect(0,
9802 px,10449 px,
9803 py,10450 py,
9804 bw,10451 bw,
@@ -9811,8 +10458,8 @@ fn decode_block_rect4(
9811 filter_intra,10458 filter_intra,
9812 smooth_neighbor, fctx,10459 smooth_neighbor, fctx,
9813 );10460 );
9814- let ac = alpha.map(|_| cfl_ac_q3_rect(y, px, py, bw, bh));10461+ let ac = alpha.map(|_| cfl_src_rect(px, py, bw, bh));
9815- for (plane, buf, levels, tx_type) in [10462+ for (plane, _buf, levels, tx_type) in [
9816 (1usize, &mut *u, &u_levels, u_tx_type),10463 (1usize, &mut *u, &u_levels, u_tx_type),
9817 (2, &mut *v, &v_levels, v_tx_type),10464 (2, &mut *v, &v_levels, v_tx_type),
9818 ] {10465 ] {
@@ -9829,7 +10476,7 @@ fn decode_block_rect4(
9829 if let Some((ub, vb)) = &palette_uv_bufs {10476 if let Some((ub, vb)) = &palette_uv_bufs {
9830 set_palette_pred(if plane == 1 { ub.clone() } else { vb.clone() }, fctx);10477 set_palette_pred(if plane == 1 { ub.clone() } else { vb.clone() }, fctx);
9831 }10478 }
9832- buf.reconstruct_rect(10479+ push_intra_rect(plane,
9833 cpx,10480 cpx,
9834 cpy,10481 cpy,
9835 chroma_w,10482 chroma_w,
@@ -9839,7 +10486,7 @@ fn decode_block_rect4(
9839 reach,10486 reach,
9840 &residual,10487 &residual,
9841 alpha10488 alpha
9842- .zip(ac.as_deref())10489+ .zip(ac)
9843 .map(|((au, av), ac)| (if plane == 1 { au } else { av }, ac)),10490 .map(|((au, av), ac)| (if plane == 1 { au } else { av }, ac)),
9844 None,10491 None,
9845 smooth_neighbor_uv, fctx,10492 smooth_neighbor_uv, fctx,
@@ -9874,7 +10521,7 @@ fn decode_block_rect4(
9874 if let Some(b) = &palette_y_buf {10521 if let Some(b) = &palette_y_buf {
9875 set_palette_pred(b.clone(), fctx);10522 set_palette_pred(b.clone(), fctx);
9876 }10523 }
9877- y.reconstruct_rect(10524+ push_intra_rect(0,
9878 px,10525 px,
9879 py,10526 py,
9880 bw,10527 bw,
@@ -9887,11 +10534,11 @@ fn decode_block_rect4(
9887 filter_intra,10534 filter_intra,
9888 smooth_neighbor, fctx,10535 smooth_neighbor, fctx,
9889 );10536 );
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));
9891 if let Some((ub, _)) = &palette_uv_bufs {10538 if let Some((ub, _)) = &palette_uv_bufs {
9892 set_palette_pred(ub.clone(), fctx);10539 set_palette_pred(ub.clone(), fctx);
9893 }10540 }
9894- u.reconstruct_rect(10541+ push_intra_rect(1,
9895 cpx,10542 cpx,
9896 cpy,10543 cpy,
9897 chroma_w,10544 chroma_w,
@@ -9900,14 +10547,14 @@ fn decode_block_rect4(
9900 angle_delta_uv,10547 angle_delta_uv,
9901 reach,10548 reach,
9902 &u_levels,10549 &u_levels,
9903- alpha.zip(ac.as_deref()).map(|((au, _), ac)| (au, ac)),10550+ alpha.zip(ac).map(|((au, _), ac)| (au, ac)),
9904 None,10551 None,
9905 smooth_neighbor_uv, fctx,10552 smooth_neighbor_uv, fctx,
9906 );10553 );
9907 if let Some((_, vb)) = &palette_uv_bufs {10554 if let Some((_, vb)) = &palette_uv_bufs {
9908 set_palette_pred(vb.clone(), fctx);10555 set_palette_pred(vb.clone(), fctx);
9909 }10556 }
9910- v.reconstruct_rect(10557+ push_intra_rect(2,
9911 cpx,10558 cpx,
9912 cpy,10559 cpy,
9913 chroma_w,10560 chroma_w,
@@ -9916,7 +10563,7 @@ fn decode_block_rect4(
9916 angle_delta_uv,10563 angle_delta_uv,
9917 reach,10564 reach,
9918 &v_levels,10565 &v_levels,
9919- alpha.zip(ac.as_deref()).map(|((_, av), ac)| (av, ac)),10566+ alpha.zip(ac).map(|((_, av), ac)| (av, ac)),
9920 None,10567 None,
9921 smooth_neighbor_uv, fctx,10568 smooth_neighbor_uv, fctx,
9922 );10569 );
@@ -10200,7 +10847,7 @@ fn decode_rect4_16_strip(
10200 set_palette_pred(tu_buf, fctx);10847 set_palette_pred(tu_buf, fctx);
10201 }10848 }
10202 if skip {10849 if skip {
10203- y.reconstruct_rect(10850+ push_intra_rect(0,
10204 tu_px, tu_py, tx_w, tx_h, mode, angle_delta_y, tu_reach, &zero_tu,10851 tu_px, tu_py, tx_w, tx_h, mode, angle_delta_y, tu_reach, &zero_tu,
10205 None, filter_intra, smooth_neighbor, fctx,10852 None, filter_intra, smooth_neighbor, fctx,
10206 );10853 );
@@ -10239,7 +10886,7 @@ fn decode_rect4_16_strip(
10239 plane_q_delta(0, fctx).1,10886 plane_q_delta(0, fctx).1,
10240 tu_tx_type,10887 tu_tx_type,
10241 );10888 );
10242- y.reconstruct_rect(10889+ push_intra_rect(0,
10243 tu_px, tu_py, tx_w, tx_h, mode, angle_delta_y, tu_reach, &residual,10890 tu_px, tu_py, tx_w, tx_h, mode, angle_delta_y, tu_reach, &residual,
10244 None, filter_intra, smooth_neighbor, fctx,10891 None, filter_intra, smooth_neighbor, fctx,
10245 );10892 );
@@ -10285,7 +10932,7 @@ fn decode_rect4_16_strip(
10285 if let Some(b) = &palette_y_buf {10932 if let Some(b) = &palette_y_buf {
10286 set_palette_pred(b.clone(), fctx);10933 set_palette_pred(b.clone(), fctx);
10287 }10934 }
10288- y.reconstruct_rect(10935+ push_intra_rect(0,
10289 px, py, bw, bh, mode, angle_delta_y, reach, &zeros, None, filter_intra,10936 px, py, bw, bh, mode, angle_delta_y, reach, &zeros, None, filter_intra,
10290 smooth_neighbor, fctx,10937 smooth_neighbor, fctx,
10291 );10938 );
@@ -10324,7 +10971,7 @@ fn decode_rect4_16_strip(
10324 if let Some(b) = &palette_y_buf {10971 if let Some(b) = &palette_y_buf {
10325 set_palette_pred(b.clone(), fctx);10972 set_palette_pred(b.clone(), fctx);
10326 }10973 }
10327- y.reconstruct_rect(10974+ push_intra_rect(0,
10328 px, py, bw, bh, mode, angle_delta_y, reach, &residual, None, filter_intra,10975 px, py, bw, bh, mode, angle_delta_y, reach, &residual, None, filter_intra,
10329 smooth_neighbor, fctx,10976 smooth_neighbor, fctx,
10330 );10977 );
@@ -10388,15 +11035,15 @@ fn decode_rect4_16_strip(
10388 // `mbmi->skip_txfm`, so a skipped `UV_CFL_PRED` block is still11035 // `mbmi->skip_txfm`, so a skipped `UV_CFL_PRED` block is still
10389 // DC + alpha * luma-AC. Dropping the CfL term here left a11036 // DC + alpha * luma-AC. Dropping the CfL term here left a
10390 // chroma-only bounded box on ReelC's key frames.11037 // 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));
10392 if alpha.is_some() {11039 if alpha.is_some() {
10393 CHROMA_SKIP_CFL_HITS.with(|h| h.set(h.get() + 1));11040 CHROMA_SKIP_CFL_HITS.with(|h| h.set(h.get() + 1));
10394 }11041 }
10395- for (buf, plane) in [(&mut *u, 1usize), (&mut *v, 2)] {11042+ for (_buf, plane) in [(&mut *u, 1usize), (&mut *v, 2)] {
10396 if let Some((ub, vb)) = &palette_uv_bufs {11043 if let Some((ub, vb)) = &palette_uv_bufs {
10397 set_palette_pred(if plane == 1 { ub.clone() } else { vb.clone() }, fctx);11044 set_palette_pred(if plane == 1 { ub.clone() } else { vb.clone() }, fctx);
10398 }11045 }
10399- buf.reconstruct_rect(11046+ push_intra_rect(plane,
10400 cpx,11047 cpx,
10401 cpy,11048 cpy,
10402 cw,11049 cw,
@@ -10406,7 +11053,7 @@ fn decode_rect4_16_strip(
10406 pair_reach,11053 pair_reach,
10407 &zeros,11054 &zeros,
10408 alpha11055 alpha
10409- .zip(ac.as_deref())11056+ .zip(ac)
10410 .map(|((au, av), ac)| (if plane == 1 { au } else { av }, ac)),11057 .map(|((au, av), ac)| (if plane == 1 { au } else { av }, ac)),
10411 None,11058 None,
10412 smooth_neighbor_uv, fctx,11059 smooth_neighbor_uv, fctx,
@@ -10436,8 +11083,8 @@ fn decode_rect4_16_strip(
10436 let (u_levels, u_tx_type) = planes.pop().expect("plane 1");11083 let (u_levels, u_tx_type) = planes.pop().expect("plane 1");
10437 // CfL averages the luma of the WHOLE pair, the region this one11084 // CfL averages the luma of the WHOLE pair, the region this one
10438 // chroma transform covers.11085 // chroma transform covers.
10439- let ac = alpha.map(|_| cfl_ac_q3_rect(y, ppx, ppy, pw, ph));11086+ let ac = alpha.map(|_| cfl_src_rect(ppx, ppy, pw, ph));
10440- for (plane, buf, levels, tx_type) in [11087+ for (plane, _buf, levels, tx_type) in [
10441 (1usize, &mut *u, &u_levels, u_tx_type),11088 (1usize, &mut *u, &u_levels, u_tx_type),
10442 (2, &mut *v, &v_levels, v_tx_type),11089 (2, &mut *v, &v_levels, v_tx_type),
10443 ] {11090 ] {
@@ -10454,7 +11101,7 @@ fn decode_rect4_16_strip(
10454 if let Some((ub, vb)) = &palette_uv_bufs {11101 if let Some((ub, vb)) = &palette_uv_bufs {
10455 set_palette_pred(if plane == 1 { ub.clone() } else { vb.clone() }, fctx);11102 set_palette_pred(if plane == 1 { ub.clone() } else { vb.clone() }, fctx);
10456 }11103 }
10457- buf.reconstruct_rect(11104+ push_intra_rect(plane,
10458 cpx,11105 cpx,
10459 cpy,11106 cpy,
10460 cw,11107 cw,
@@ -10464,7 +11111,7 @@ fn decode_rect4_16_strip(
10464 pair_reach,11111 pair_reach,
10465 &residual,11112 &residual,
10466 alpha11113 alpha
10467- .zip(ac.as_deref())11114+ .zip(ac)
10468 .map(|((au, av), ac)| (if plane == 1 { au } else { av }, ac)),11115 .map(|((au, av), ac)| (if plane == 1 { au } else { av }, ac)),
10469 None,11116 None,
10470 smooth_neighbor_uv, fctx,11117 smooth_neighbor_uv, fctx,
@@ -10757,7 +11404,7 @@ fn decode_block_rect64(
10757 )11404 )
10758 });11405 });
10759 if skip {11406 if skip {
10760- y.reconstruct_rect(11407+ push_intra_rect(0,
10761 px,11408 px,
10762 py,11409 py,
10763 bw,11410 bw,
@@ -10770,11 +11417,11 @@ fn decode_block_rect64(
10770 filter_intra,11417 filter_intra,
10771 smooth_neighbor, fctx,11418 smooth_neighbor, fctx,
10772 );11419 );
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));
10774 if let Some((ub, _)) = &palette_uv_bufs {11421 if let Some((ub, _)) = &palette_uv_bufs {
10775 set_palette_pred(ub.clone(), fctx);11422 set_palette_pred(ub.clone(), fctx);
10776 }11423 }
10777- u.reconstruct_rect(11424+ push_intra_rect(1,
10778 cpx,11425 cpx,
10779 cpy,11426 cpy,
10780 chroma_w,11427 chroma_w,
@@ -10783,14 +11430,14 @@ fn decode_block_rect64(
10783 angle_delta_uv,11430 angle_delta_uv,
10784 reach,11431 reach,
10785 &vec![0i32; chroma_w * chroma_h],11432 &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)),
10787 None,11434 None,
10788 smooth_neighbor_uv, fctx,11435 smooth_neighbor_uv, fctx,
10789 );11436 );
10790 if let Some((_, vb)) = &palette_uv_bufs {11437 if let Some((_, vb)) = &palette_uv_bufs {
10791 set_palette_pred(vb.clone(), fctx);11438 set_palette_pred(vb.clone(), fctx);
10792 }11439 }
10793- v.reconstruct_rect(11440+ push_intra_rect(2,
10794 cpx,11441 cpx,
10795 cpy,11442 cpy,
10796 chroma_w,11443 chroma_w,
@@ -10799,7 +11446,7 @@ fn decode_block_rect64(
10799 angle_delta_uv,11446 angle_delta_uv,
10800 reach,11447 reach,
10801 &vec![0i32; chroma_w * chroma_h],11448 &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)),
10803 None,11450 None,
10804 smooth_neighbor_uv, fctx,11451 smooth_neighbor_uv, fctx,
10805 );11452 );
@@ -10896,7 +11543,7 @@ fn decode_block_rect64(
10896 plane_q_delta(0, fctx).1,11543 plane_q_delta(0, fctx).1,
10897 luma_tx_type,11544 luma_tx_type,
10898 );11545 );
10899- y.reconstruct_rect(11546+ push_intra_rect(0,
10900 px,11547 px,
10901 py,11548 py,
10902 bw,11549 bw,
@@ -10925,7 +11572,7 @@ fn decode_block_rect64(
10925 }11572 }
10926 // CHROMA: a real, untruncated chroma_w x chroma_h transform -- no11573 // CHROMA: a real, untruncated chroma_w x chroma_h transform -- no
10927 // corner crop needed (see doc comment).11574 // 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));
10929 // The chroma plane is never truncated (both axes <= 32 after11576 // The chroma plane is never truncated (both axes <= 32 after
10930 // subsampling). Under a 1:4 strip it is a true 32x8/8x32:11577 // subsampling). Under a 1:4 strip it is a true 32x8/8x32:
10931 // `get_txsize_entropy_ctx(TX_32X8)` = (TX_8X8 + TX_32X32 + 1) >> 1 =11578 // `get_txsize_entropy_ctx(TX_32X8)` = (TX_8X8 + TX_32X32 + 1) >> 1 =
@@ -10989,7 +11636,7 @@ fn decode_block_rect64(
10989 if let Some((ub, _)) = &palette_uv_bufs {11636 if let Some((ub, _)) = &palette_uv_bufs {
10990 set_palette_pred(ub.clone(), fctx);11637 set_palette_pred(ub.clone(), fctx);
10991 }11638 }
10992- u.reconstruct_rect(11639+ push_intra_rect(1,
10993 cpx,11640 cpx,
10994 cpy,11641 cpy,
10995 chroma_w,11642 chroma_w,
@@ -10998,7 +11645,7 @@ fn decode_block_rect64(
10998 angle_delta_uv,11645 angle_delta_uv,
10999 reach,11646 reach,
11000 &u_residual,11647 &u_residual,
11001- alpha.zip(ac.as_deref()).map(|((au, _), ac)| (au, ac)),11648+ alpha.zip(ac).map(|((au, _), ac)| (au, ac)),
11002 None,11649 None,
11003 smooth_neighbor_uv, fctx,11650 smooth_neighbor_uv, fctx,
11004 );11651 );
@@ -11046,7 +11693,7 @@ fn decode_block_rect64(
11046 if let Some((_, vb)) = &palette_uv_bufs {11693 if let Some((_, vb)) = &palette_uv_bufs {
11047 set_palette_pred(vb.clone(), fctx);11694 set_palette_pred(vb.clone(), fctx);
11048 }11695 }
11049- v.reconstruct_rect(11696+ push_intra_rect(2,
11050 cpx,11697 cpx,
11051 cpy,11698 cpy,
11052 chroma_w,11699 chroma_w,
@@ -11055,7 +11702,7 @@ fn decode_block_rect64(
11055 angle_delta_uv,11702 angle_delta_uv,
11056 reach,11703 reach,
11057 &v_residual,11704 &v_residual,
11058- alpha.zip(ac.as_deref()).map(|((_, av), ac)| (av, ac)),11705+ alpha.zip(ac).map(|((_, av), ac)| (av, ac)),
11059 None,11706 None,
11060 smooth_neighbor_uv, fctx,11707 smooth_neighbor_uv, fctx,
11061 );11708 );
@@ -11719,12 +12366,16 @@ impl PlaneBuf<'_> {
11719 residual: &[i32],12366 residual: &[i32],
11720 cfl: Option<(i32, &[i32])>,12367 cfl: Option<(i32, &[i32])>,
11721 filter_intra: Option<usize>,12368 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,
11723 ) {12374 ) {
11724 // As [`Self::reconstruct`]'s own [`PALETTE_PRED`] override12375 // As [`Self::reconstruct`]'s own [`PALETTE_PRED`] override
11725 // (lane-palette2 r4): a palette block's prediction is the12376 // (lane-palette2 r4): a palette block's prediction is the
11726 // reconstructed colour-index map, needing no edge pixels at all.12377 // 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 {
11728 buf12379 buf
11729 } else {12380 } else {
11730 let (above, left, corner) = self.edges_rect(x, y, bw, bh, reach);12381 let (above, left, corner) = self.edges_rect(x, y, bw, bh, reach);
@@ -11823,12 +12474,16 @@ impl PlaneBuf<'_> {
11823 // callers until a smooth/paeth `uv_mode` can reach this call at all12474 // callers until a smooth/paeth `uv_mode` can reach this call at all
11824 // (still refused in `read_intra_mode`/`read_intra_mode_rect`), which12475 // (still refused in `read_intra_mode`/`read_intra_mode_rect`), which
11825 // keeps `false` exact for chroma without this fn needing to know why.12476 // 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,
11827 ) {12482 ) {
11828 // A palette block's own [`PALETTE_PRED`] override (lane-palette r2)12483 // A palette block's own [`PALETTE_PRED`] override (lane-palette r2)
11829 // takes priority over `predict()`/`predict_filter_intra` entirely --12484 // takes priority over `predict()`/`predict_filter_intra` entirely --
11830 // palette prediction needs no edge pixels at all.12485 // 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 {
11832 buf12487 buf
11833 } else {12488 } else {
11834 let (above, left, corner) = self.edges(x, y, side, reach);12489 let (above, left, corner) = self.edges(x, y, side, reach);
@@ -11922,13 +12577,17 @@ fn read_plane(
11922 predict_mode: usize,12577 predict_mode: usize,
11923 angle_delta: i32,12578 angle_delta: i32,
11924 reach: Reach,12579 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>,
11926 x: usize,12585 x: usize,
11927 y: usize,12586 y: usize,
11928 side: usize,12587 side: usize,
11929 tx_side: usize,12588 tx_side: usize,
11930 base_q_idx: u8,12589 base_q_idx: u8,
11931- cfl: Option<(i32, &[i32])>,12590+ cfl: Option<(i32, CflSrc)>,
11932 filter_intra: Option<usize>,12591 filter_intra: Option<usize>,
11933 // Only meaningful for `plane_idx == 0`: `Some` when this transform unit is12592 // Only meaningful for `plane_idx == 0`: `Some` when this transform unit is
11934 // smaller than its own block (spec `get_txb_ctx_general`'s12593 // smaller than its own block (spec `get_txb_ctx_general`'s
@@ -12019,14 +12678,15 @@ fn read_plane(
12019 "TRACE dequant plane={plane_idx} base_q_idx={base_q_idx} tx_type={tx_type:?} side={side} levels={levels:?} residual={residual:?}",12678 "TRACE dequant plane={plane_idx} base_q_idx={base_q_idx} tx_type={tx_type:?} side={side} levels={levels:?} residual={residual:?}",
12020 );12679 );
12021 }12680 }
12022- plane.reconstruct(12681+ push_intra_owned(
12682+ plane_idx,
12023 x,12683 x,
12024 y,12684 y,
12025 side,12685 side,
12026 predict_mode,12686 predict_mode,
12027 angle_delta,12687 angle_delta,
12028 reach,12688 reach,
12029- &residual,12689+ residual,
12030 cfl,12690 cfl,
12031 filter_intra,12691 filter_intra,
12032 smooth_neighbor, fctx,12692 smooth_neighbor, fctx,
@@ -12215,6 +12875,7 @@ fn decode_block(
12215 // block vector, with the BILINEAR kernel libaom forces for intrabc --12875 // block vector, with the BILINEAR kernel libaom forces for intrabc --
12216 // luma is a straight copy, chroma lands half-pel whenever the luma DV is12876 // luma is a straight copy, chroma lands half-pel whenever the luma DV is
12217 // odd, which is exactly what the bilinear taps then interpolate.12877 // odd, which is exactly what the bilinear taps then interpolate.
12878+ flush_recon(fctx, y, u, v);
12218 let intrabc_bufs = intrabc_dv.map(|(dv_row, dv_col)| {12879 let intrabc_bufs = intrabc_dv.map(|(dv_row, dv_col)| {
12219 let mut yb = vec![0u16; side * side];12880 let mut yb = vec![0u16; side * side];
12220 mc::predict_with_filter(12881 mc::predict_with_filter(
@@ -12333,7 +12994,7 @@ fn decode_block(
12333 y.width,12994 y.width,
12334 y.height, fctx,12995 y.height, fctx,
12335 );12996 );
12336- y.reconstruct(12997+ push_intra(0,
12337 tu_px,12998 tu_px,
12338 tu_py,12999 tu_py,
12339 logical_tx,13000 logical_tx,
@@ -12348,7 +13009,7 @@ fn decode_block(
12348 }13009 }
12349 }13010 }
12350 } else {13011 } else {
12351- y.reconstruct(13012+ push_intra(0,
12352 px,13013 px,
12353 py,13014 py,
12354 side,13015 side,
@@ -12361,7 +13022,7 @@ fn decode_block(
12361 smooth_neighbor, fctx,13022 smooth_neighbor, fctx,
12362 );13023 );
12363 }13024 }
12364- let ac = alpha.map(|_| cfl_ac_q3(y, px, py, side));13025+ let ac = alpha.map(|_| cfl_src(px, py, side));
12365 let cn = (chroma_side / chroma_tx).max(1);13026 let cn = (chroma_side / chroma_tx).max(1);
12366 for cu_row in 0..cn {13027 for cu_row in 0..cn {
12367 for cu_col in 0..cn {13028 for cu_col in 0..cn {
@@ -12379,7 +13040,7 @@ fn decode_block(
12379 if let Some((ub, _)) = &palette_uv_bufs {13040 if let Some((ub, _)) = &palette_uv_bufs {
12380 set_palette_pred(ub.clone(), fctx);13041 set_palette_pred(ub.clone(), fctx);
12381 }13042 }
12382- u.reconstruct(13043+ push_intra(1,
12383 cu_x,13044 cu_x,
12384 cu_y,13045 cu_y,
12385 chroma_tx,13046 chroma_tx,
@@ -12387,14 +13048,14 @@ fn decode_block(
12387 angle_delta_uv,13048 angle_delta_uv,
12388 cu_r,13049 cu_r,
12389 &vec![0i32; chroma_tx * chroma_tx],13050 &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)),
12391 None,13052 None,
12392 smooth_neighbor_uv, fctx,13053 smooth_neighbor_uv, fctx,
12393 );13054 );
12394 if let Some((_, vb)) = &palette_uv_bufs {13055 if let Some((_, vb)) = &palette_uv_bufs {
12395 set_palette_pred(vb.clone(), fctx);13056 set_palette_pred(vb.clone(), fctx);
12396 }13057 }
12397- v.reconstruct(13058+ push_intra(2,
12398 cu_x,13059 cu_x,
12399 cu_y,13060 cu_y,
12400 chroma_tx,13061 chroma_tx,
@@ -12402,7 +13063,7 @@ fn decode_block(
12402 angle_delta_uv,13063 angle_delta_uv,
12403 cu_r,13064 cu_r,
12404 &vec![0i32; chroma_tx * chroma_tx],13065 &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)),
12406 None,13067 None,
12407 smooth_neighbor_uv, fctx,13068 smooth_neighbor_uv, fctx,
12408 );13069 );
@@ -12444,7 +13105,7 @@ fn decode_block(
12444 None,13105 None,
12445 smooth_neighbor, fctx,13106 smooth_neighbor, fctx,
12446 )?;13107 )?;
12447- let ac = alpha.map(|_| cfl_ac_q3(y, px, py, side));13108+ let ac = alpha.map(|_| cfl_src(px, py, side));
12448 // Armed for exactly this block's two chroma reads (see13109 // Armed for exactly this block's two chroma reads (see
12449 // [`INTRABC_CHROMA_TX`]); the luma call above just set13110 // [`INTRABC_CHROMA_TX`]); the luma call above just set
12450 // [`LUMA_TX_TYPE`] to the type it coded.13111 // [`LUMA_TX_TYPE`] to the type it coded.
@@ -12471,7 +13132,7 @@ fn decode_block(
12471 chroma_side,13132 chroma_side,
12472 chroma_tx,13133 chroma_tx,
12473 base_q_idx,13134 base_q_idx,
12474- alpha.zip(ac.as_deref()).map(|((au, _), ac)| (au, ac)),13135+ alpha.zip(ac).map(|((au, _), ac)| (au, ac)),
12475 None,13136 None,
12476 None,13137 None,
12477 smooth_neighbor_uv, fctx,13138 smooth_neighbor_uv, fctx,
@@ -12502,7 +13163,7 @@ fn decode_block(
12502 chroma_side,13163 chroma_side,
12503 chroma_tx,13164 chroma_tx,
12504 base_q_idx,13165 base_q_idx,
12505- alpha.zip(ac.as_deref()).map(|((_, av), ac)| (av, ac)),13166+ alpha.zip(ac).map(|((_, av), ac)| (av, ac)),
12506 None,13167 None,
12507 None,13168 None,
12508 smooth_neighbor_uv, fctx,13169 smooth_neighbor_uv, fctx,
@@ -12622,7 +13283,7 @@ fn decode_block(
12622 }13283 }
12623 // CfL is only allowed up to 32x32, i.e. only at `nchunk == 1`, where13284 // CfL is only allowed up to 32x32, i.e. only at `nchunk == 1`, where
12624 // this still runs after every luma unit of the block.13285 // 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));
12626 // The block's uv plane block is `chroma_side` across but its uv13287 // The block's uv plane block is `chroma_side` across but its uv
12627 // transform is `chroma_tx` (`av1_get_max_uv_txsize` =13288 // transform is `chroma_tx` (`av1_get_max_uv_txsize` =
12628 // `av1_get_adjusted_tx_size(max_txsize_rect_lookup[uv_plane_bsize])`):13289 // `av1_get_adjusted_tx_size(max_txsize_rect_lookup[uv_plane_bsize])`):
@@ -12657,7 +13318,7 @@ fn decode_block(
12657 dec, cdfs, chroma_set, scans.1, 1, cu_around[1], mode,13318 dec, cdfs, chroma_set, scans.1, 1, cu_around[1], mode,
12658 uv_predict_mode, angle_delta_uv, cu_reach, u, cu_x, cu_y,13319 uv_predict_mode, angle_delta_uv, cu_reach, u, cu_x, cu_y,
12659 chroma_tx, chroma_tx, base_q_idx,13320 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)),
12661 None, chroma_ctx_offset, smooth_neighbor_uv, fctx,13322 None, chroma_ctx_offset, smooth_neighbor_uv, fctx,
12662 )?;13323 )?;
12663 if let Some((_, vb)) = &palette_uv_bufs {13324 if let Some((_, vb)) = &palette_uv_bufs {
@@ -12667,7 +13328,7 @@ fn decode_block(
12667 dec, cdfs, chroma_set, scans.1, 2, cu_around[2], mode,13328 dec, cdfs, chroma_set, scans.1, 2, cu_around[2], mode,
12668 uv_predict_mode, angle_delta_uv, cu_reach, v, cu_x, cu_y,13329 uv_predict_mode, angle_delta_uv, cu_reach, v, cu_x, cu_y,
12669 chroma_tx, chroma_tx, base_q_idx,13330 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)),
12671 None, chroma_ctx_offset, smooth_neighbor_uv, fctx,13332 None, chroma_ctx_offset, smooth_neighbor_uv, fctx,
12672 )?;13333 )?;
12673 if cn > 1 {13334 if cn > 1 {
@@ -12930,7 +13591,7 @@ fn decode_block_128rect(
12930 y.height, fctx,13591 y.height, fctx,
12931 );13592 );
12932 if skip {13593 if skip {
12933- y.reconstruct(13594+ push_intra(0,
12934 tu_px, tu_py, logical_tx, mode, angle_delta_y, tu_r, &zero_tu, None,13595 tu_px, tu_py, logical_tx, mode, angle_delta_y, tu_r, &zero_tu, None,
12935 None, smooth_neighbor, fctx,13596 None, smooth_neighbor, fctx,
12936 );13597 );
@@ -12987,11 +13648,11 @@ fn decode_block_128rect(
12987 );13648 );
12988 let (cu_x, cu_y) = (cpx + ch_col * chroma_tx, cpy + ch_row * chroma_tx);13649 let (cu_x, cu_y) = (cpx + ch_col * chroma_tx, cpy + ch_row * chroma_tx);
12989 if skip {13650 if skip {
12990- u.reconstruct(13651+ push_intra(1,
12991 cu_x, cu_y, chroma_tx, uv_predict_mode, angle_delta_uv, cu_r, &zero_cu, None,13652 cu_x, cu_y, chroma_tx, uv_predict_mode, angle_delta_uv, cu_r, &zero_cu, None,
12992 None, smooth_neighbor_uv, fctx,13653 None, smooth_neighbor_uv, fctx,
12993 );13654 );
12994- v.reconstruct(13655+ push_intra(2,
12995 cu_x, cu_y, chroma_tx, uv_predict_mode, angle_delta_uv, cu_r, &zero_cu, None,13656 cu_x, cu_y, chroma_tx, uv_predict_mode, angle_delta_uv, cu_r, &zero_cu, None,
12996 None, smooth_neighbor_uv, fctx,13657 None, smooth_neighbor_uv, fctx,
12997 );13658 );
@@ -13287,6 +13948,7 @@ fn decode_leaf8(
13287 // the CURRENT frame's own pre-loop-filter reconstruction (every loop13948 // the CURRENT frame's own pre-loop-filter reconstruction (every loop
13288 // filter is off whenever `allow_intrabc`, frame.rs:194/210/252/272) at13949 // filter is off whenever `allow_intrabc`, frame.rs:194/210/252/272) at
13289 // the full-pel block vector, with the BILINEAR kernel libaom forces.13950 // the full-pel block vector, with the BILINEAR kernel libaom forces.
13951+ flush_recon(fctx, y, u, v);
13290 let intrabc_bufs = intrabc_dv.map(|(dv_row, dv_col)| {13952 let intrabc_bufs = intrabc_dv.map(|(dv_row, dv_col)| {
13291 let mut yb = vec![0u16; 8 * 8];13953 let mut yb = vec![0u16; 8 * 8];
13292 mc::predict_with_filter(13954 mc::predict_with_filter(
@@ -13349,7 +14011,7 @@ fn decode_leaf8(
13349 y.width,14011 y.width,
13350 y.height, fctx,14012 y.height, fctx,
13351 );14013 );
13352- y.reconstruct(14014+ push_intra(0,
13353 tu_px,14015 tu_px,
13354 tu_py,14016 tu_py,
13355 4,14017 4,
@@ -13367,7 +14029,7 @@ fn decode_leaf8(
13367 if let Some(buf) = &palette_y_buf {14029 if let Some(buf) = &palette_y_buf {
13368 set_palette_pred(buf.clone(), fctx);14030 set_palette_pred(buf.clone(), fctx);
13369 }14031 }
13370- y.reconstruct(14032+ push_intra(0,
13371 px,14033 px,
13372 py,14034 py,
13373 8,14035 8,
@@ -13380,13 +14042,13 @@ fn decode_leaf8(
13380 smooth_neighbor, fctx,14042 smooth_neighbor, fctx,
13381 );14043 );
13382 }14044 }
13383- let ac = alpha.map(|_| cfl_ac_q3(y, px, py, 8));14045+ let ac = alpha.map(|_| cfl_src(px, py, 8));
13384 if let Some((_, ub, _)) = &intrabc_bufs {14046 if let Some((_, ub, _)) = &intrabc_bufs {
13385 set_palette_pred(ub.clone(), fctx);14047 set_palette_pred(ub.clone(), fctx);
13386 } else if let Some((ub, _)) = &palette_uv_bufs {14048 } else if let Some((ub, _)) = &palette_uv_bufs {
13387 set_palette_pred(ub.clone(), fctx);14049 set_palette_pred(ub.clone(), fctx);
13388 }14050 }
13389- u.reconstruct(14051+ push_intra(1,
13390 cpx,14052 cpx,
13391 cpy,14053 cpy,
13392 4,14054 4,
@@ -13394,7 +14056,7 @@ fn decode_leaf8(
13394 angle_delta_uv,14056 angle_delta_uv,
13395 reach,14057 reach,
13396 &vec![0i32; 16],14058 &vec![0i32; 16],
13397- alpha.zip(ac.as_deref()).map(|((au, _), ac)| (au, ac)),14059+ alpha.zip(ac).map(|((au, _), ac)| (au, ac)),
13398 None,14060 None,
13399 smooth_neighbor_uv, fctx,14061 smooth_neighbor_uv, fctx,
13400 );14062 );
@@ -13403,7 +14065,7 @@ fn decode_leaf8(
13403 } else if let Some((_, vb)) = &palette_uv_bufs {14065 } else if let Some((_, vb)) = &palette_uv_bufs {
13404 set_palette_pred(vb.clone(), fctx);14066 set_palette_pred(vb.clone(), fctx);
13405 }14067 }
13406- v.reconstruct(14068+ push_intra(2,
13407 cpx,14069 cpx,
13408 cpy,14070 cpy,
13409 4,14071 4,
@@ -13411,7 +14073,7 @@ fn decode_leaf8(
13411 angle_delta_uv,14073 angle_delta_uv,
13412 reach,14074 reach,
13413 &vec![0i32; 16],14075 &vec![0i32; 16],
13414- alpha.zip(ac.as_deref()).map(|((_, av), ac)| (av, ac)),14076+ alpha.zip(ac).map(|((_, av), ac)| (av, ac)),
13415 None,14077 None,
13416 smooth_neighbor_uv, fctx,14078 smooth_neighbor_uv, fctx,
13417 );14079 );
@@ -13457,7 +14119,7 @@ fn decode_leaf8(
13457 if intrabc_dv.is_some() {14119 if intrabc_dv.is_some() {
13458 fctx.intrabc_chroma_tx.with(|c| c.set(Some(fctx.luma_tx_type.with(std::cell::Cell::get))));14120 fctx.intrabc_chroma_tx.with(|c| c.set(Some(fctx.luma_tx_type.with(std::cell::Cell::get))));
13459 }14121 }
13460- let ac = alpha.map(|_| cfl_ac_q3(y, px, py, 8));14122+ let ac = alpha.map(|_| cfl_src(px, py, 8));
13461 if let Some((_, ub, _)) = &intrabc_bufs {14123 if let Some((_, ub, _)) = &intrabc_bufs {
13462 set_palette_pred(ub.clone(), fctx);14124 set_palette_pred(ub.clone(), fctx);
13463 } else if let Some((ub, _)) = &palette_uv_bufs {14125 } else if let Some((ub, _)) = &palette_uv_bufs {
@@ -13480,7 +14142,7 @@ fn decode_leaf8(
13480 4,14142 4,
13481 TX4,14143 TX4,
13482 base_q_idx,14144 base_q_idx,
13483- alpha.zip(ac.as_deref()).map(|((au, _), ac)| (au, ac)),14145+ alpha.zip(ac).map(|((au, _), ac)| (au, ac)),
13484 None,14146 None,
13485 None,14147 None,
13486 smooth_neighbor_uv, fctx,14148 smooth_neighbor_uv, fctx,
@@ -13507,7 +14169,7 @@ fn decode_leaf8(
13507 4,14169 4,
13508 TX4,14170 TX4,
13509 base_q_idx,14171 base_q_idx,
13510- alpha.zip(ac.as_deref()).map(|((_, av), ac)| (av, ac)),14172+ alpha.zip(ac).map(|((_, av), ac)| (av, ac)),
13511 None,14173 None,
13512 None,14174 None,
13513 smooth_neighbor_uv, fctx,14175 smooth_neighbor_uv, fctx,
@@ -13597,7 +14259,7 @@ fn decode_leaf8(
13597 neighbours.record_mi_luma(tu_mi, 4, &tu_grid);14259 neighbours.record_mi_luma(tu_mi, 4, &tu_grid);
13598 }14260 }
13599 }14261 }
13600- let ac = alpha.map(|_| cfl_ac_q3(y, px, py, 8));14262+ let ac = alpha.map(|_| cfl_src(px, py, 8));
13601 let chroma_around = neighbours.around_mi(leaf_mi, 8);14263 let chroma_around = neighbours.around_mi(leaf_mi, 8);
13602 if let Some((ub, _)) = &palette_uv_bufs {14264 if let Some((ub, _)) = &palette_uv_bufs {
13603 set_palette_pred(ub.clone(), fctx);14265 set_palette_pred(ub.clone(), fctx);
@@ -13619,7 +14281,7 @@ fn decode_leaf8(
13619 4,14281 4,
13620 TX4,14282 TX4,
13621 base_q_idx,14283 base_q_idx,
13622- alpha.zip(ac.as_deref()).map(|((au, _), ac)| (au, ac)),14284+ alpha.zip(ac).map(|((au, _), ac)| (au, ac)),
13623 None,14285 None,
13624 None,14286 None,
13625 smooth_neighbor_uv, fctx,14287 smooth_neighbor_uv, fctx,
@@ -13644,7 +14306,7 @@ fn decode_leaf8(
13644 4,14306 4,
13645 TX4,14307 TX4,
13646 base_q_idx,14308 base_q_idx,
13647- alpha.zip(ac.as_deref()).map(|((_, av), ac)| (av, ac)),14309+ alpha.zip(ac).map(|((_, av), ac)| (av, ac)),
13648 None,14310 None,
13649 None,14311 None,
13650 smooth_neighbor_uv, fctx,14312 smooth_neighbor_uv, fctx,
@@ -13907,7 +14569,7 @@ fn decode_leaf_split4(
13907 let (px, py) = (lmi.1 * MI, lmi.0 * MI);14569 let (px, py) = (lmi.1 * MI, lmi.0 * MI);
13908 let reach = Reach::of(4, px, py, y.width, y.height, fctx);14570 let reach = Reach::of(4, px, py, y.width, y.height, fctx);
13909 if skip {14571 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);
13911 neighbours.record_mi_luma(lmi, 4, &vec![0i32; 16]);14573 neighbours.record_mi_luma(lmi, 4, &vec![0i32; 16]);
13912 } else {14574 } else {
13913 let tu_around = neighbours.around_mi(lmi, 4)[0];14575 let tu_around = neighbours.around_mi(lmi, 4)[0];
@@ -13964,26 +14626,26 @@ fn decode_leaf_split4(
13964 // lane-reelckf and lane-kf1200 fixed THIS SAME arm independently; the14626 // lane-reelckf and lane-kf1200 fixed THIS SAME arm independently; the
13965 // merge keeps one fix and feeds both lanes' counters so neither of14627 // merge keeps one fix and feeds both lanes' counters so neither of
13966 // their gates goes vacuous.14628 // 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));
13968 if alpha.is_some() {14630 if alpha.is_some() {
13969 CHROMA_SKIP_CFL_HITS.with(|h| h.set(h.get() + 1));14631 CHROMA_SKIP_CFL_HITS.with(|h| h.set(h.get() + 1));
13970 SKIP_CFL_HITS.with(|c| c.set(c.get() + 1));14632 SKIP_CFL_HITS.with(|c| c.set(c.get() + 1));
13971 }14633 }
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);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);
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);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);
13974 (vec![0i32; 16], vec![0i32; 16])14636 (vec![0i32; 16], vec![0i32; 16])
13975 } else {14637 } else {
13976- let ac = alpha.map(|_| cfl_ac_q3(y, gpx, gpy, 8));14638+ let ac = alpha.map(|_| cfl_src(gpx, gpy, 8));
13977 let chroma_around = neighbours.around_mi(leaf_mi, 8);14639 let chroma_around = neighbours.around_mi(leaf_mi, 8);
13978 let ug = read_plane(14640 let ug = read_plane(
13979 dec, cdfs, TxbSet::Chroma4, scan4, 1, chroma_around[1], uv_mode, uv_predict_mode,14641 dec, cdfs, TxbSet::Chroma4, scan4, 1, chroma_around[1], uv_mode, uv_predict_mode,
13980 angle_delta_uv, group_reach, u, cpx, cpy, 4, TX4, base_q_idx,14642 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,
13982 )?;14644 )?;
13983 let vg = read_plane(14645 let vg = read_plane(
13984 dec, cdfs, TxbSet::Chroma4, scan4, 2, chroma_around[2], uv_mode, uv_predict_mode,14646 dec, cdfs, TxbSet::Chroma4, scan4, 2, chroma_around[2], uv_mode, uv_predict_mode,
13985 angle_delta_uv, group_reach, v, cpx, cpy, 4, TX4, base_q_idx,14647 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,
13987 )?;14649 )?;
13988 (ug, vg)14650 (ug, vg)
13989 };14651 };
@@ -14194,7 +14856,7 @@ fn decode_leaf_rect8(
14194 // one's reconstruction, which is NOT what a single 4x814856 // one's reconstruction, which is NOT what a single 4x8
14195 // prediction of the same mode produces.14857 // prediction of the same mode produces.
14196 let zeros = vec![0i32; 16];14858 let zeros = vec![0i32; 16];
14197- y.reconstruct(14859+ push_intra(0,
14198 tu_px, tu_py, 4, mode, angle_delta_y, tu_reach, &zeros, None,14860 tu_px, tu_py, 4, mode, angle_delta_y, tu_reach, &zeros, None,
14199 filter_intra, smooth_neighbor, fctx,14861 filter_intra, smooth_neighbor, fctx,
14200 );14862 );
@@ -14248,7 +14910,7 @@ fn decode_leaf_rect8(
14248 }14910 }
14249 let grid = if skip {14911 let grid = if skip {
14250 let zeros = vec![0i32; bw * bh];14912 let zeros = vec![0i32; bw * bh];
14251- y.reconstruct_rect(14913+ push_intra_rect(0,
14252 px, py, bw, bh, mode, angle_delta_y, reach, &zeros, None, filter_intra,14914 px, py, bw, bh, mode, angle_delta_y, reach, &zeros, None, filter_intra,
14253 smooth_neighbor, fctx,14915 smooth_neighbor, fctx,
14254 );14916 );
@@ -14291,7 +14953,7 @@ fn decode_leaf_rect8(
14291 plane_q_delta(0, fctx).1,14953 plane_q_delta(0, fctx).1,
14292 tx_type,14954 tx_type,
14293 );14955 );
14294- y.reconstruct_rect(14956+ push_intra_rect(0,
14295 px, py, bw, bh, mode, angle_delta_y, reach, &residual, None, filter_intra,14957 px, py, bw, bh, mode, angle_delta_y, reach, &residual, None, filter_intra,
14296 smooth_neighbor, fctx,14958 smooth_neighbor, fctx,
14297 );14959 );
@@ -14336,26 +14998,26 @@ fn decode_leaf_rect8(
14336 // lane-reelckf and lane-kf1200 fixed THIS SAME arm independently; the14998 // lane-reelckf and lane-kf1200 fixed THIS SAME arm independently; the
14337 // merge keeps one fix and feeds both lanes' counters so neither of14999 // merge keeps one fix and feeds both lanes' counters so neither of
14338 // their gates goes vacuous.15000 // 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));
14340 if alpha.is_some() {15002 if alpha.is_some() {
14341 CHROMA_SKIP_CFL_HITS.with(|h| h.set(h.get() + 1));15003 CHROMA_SKIP_CFL_HITS.with(|h| h.set(h.get() + 1));
14342 SKIP_CFL_HITS.with(|c| c.set(c.get() + 1));15004 SKIP_CFL_HITS.with(|c| c.set(c.get() + 1));
14343 }15005 }
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);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);
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);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);
14346 (vec![0i32; 16], vec![0i32; 16])15008 (vec![0i32; 16], vec![0i32; 16])
14347 } else {15009 } else {
14348- let ac = alpha.map(|_| cfl_ac_q3(y, gpx, gpy, 8));15010+ let ac = alpha.map(|_| cfl_src(gpx, gpy, 8));
14349 let chroma_around = neighbours.around_mi(leaf_mi, 8);15011 let chroma_around = neighbours.around_mi(leaf_mi, 8);
14350 let ug = read_plane(15012 let ug = read_plane(
14351 dec, cdfs, TxbSet::Chroma4, scan4, 1, chroma_around[1], uv_mode, uv_predict_mode,15013 dec, cdfs, TxbSet::Chroma4, scan4, 1, chroma_around[1], uv_mode, uv_predict_mode,
14352 angle_delta_uv, group_reach, u, cpx, cpy, 4, TX4, base_q_idx,15014 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,
14354 )?;15016 )?;
14355 let vg = read_plane(15017 let vg = read_plane(
14356 dec, cdfs, TxbSet::Chroma4, scan4, 2, chroma_around[2], uv_mode, uv_predict_mode,15018 dec, cdfs, TxbSet::Chroma4, scan4, 2, chroma_around[2], uv_mode, uv_predict_mode,
14357 angle_delta_uv, group_reach, v, cpx, cpy, 4, TX4, base_q_idx,15019 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,
14359 )?;15021 )?;
14360 (ug, vg)15022 (ug, vg)
14361 };15023 };
@@ -16138,7 +16800,11 @@ fn read_inter_plane_rect(
16138 plane_idx: usize,16800 plane_idx: usize,
16139 around: (bool, bool, i32),16801 around: (bool, bool, i32),
16140 tx_mode: usize,16802 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>,
16142 x: usize,16808 x: usize,
16143 y: usize,16809 y: usize,
16144 prediction: &[u16],16810 prediction: &[u16],
@@ -16230,7 +16896,7 @@ fn read_inter_plane_rect(
16230 for row in 0..h {16896 for row in 0..h {
16231 strided[row * stride..][..w].copy_from_slice(&residual[row * w..][..w]);16897 strided[row * stride..][..w].copy_from_slice(&residual[row * w..][..w]);
16232 }16898 }
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);
16234 Ok((grid, tx_type))16900 Ok((grid, tx_type))
16235 }16901 }
16236 16902
@@ -18364,7 +19030,39 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
18364 // its one block covers all four 64x64 quadrants, so the remaining three19030 // its one block covers all four 64x64 quadrants, so the remaining three
18365 // visits of this superblock code nothing at all.19031 // visits of this superblock code nothing at all.
18366 let mut sb128_none = false;19032 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);
18367 for (sb_r, sb_c, row_start, sb_start) in sb_visit_order(sb_r0, sb_r1, sb_c0, sb_c1, sb128) {19051 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+ }
18368 if row_start {19066 if row_start {
18369 neighbours.start_row();19067 neighbours.start_row();
18370 }19068 }
@@ -20105,6 +20803,10 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
20105 }20803 }
20106 }20804 }
20107 }20805 }
20806+ if waving {
20807+ wave_submit(fctx, wave_job.0, wave_job.1);
20808+ }
20809+ flush_recon(fctx, &mut y, &mut u, &mut v);
20108 20810
20109 if tile_num == tile_info.context_update_tile_id {20811 if tile_num == tile_info.context_update_tile_id {
20110 result_cdfs = cdfs;20812 result_cdfs = cdfs;
@@ -20589,18 +21291,7 @@ impl PlaneBuf<'_> {
20589 /// compensation's output, rather than [`predict`]'s intra one), writing21291 /// compensation's output, rather than [`predict`]'s intra one), writing
20590 /// the clamped reconstruction into the plane at `(x, y)` -- the inter21292 /// the clamped reconstruction into the plane at `(x, y)` -- the inter
20591 /// counterpart of [`PlaneBuf::reconstruct`].21293 /// counterpart of [`PlaneBuf::reconstruct`].
20592- fn reconstruct_mc(21294+ /// [`Self::reconstruct_mc_rect`], writing only a `w`x`h` sub-rectangle of the
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
20604 /// `side`x`side` `prediction`/`residual` buffers (which stay `side`-square21295 /// `side`x`side` `prediction`/`residual` buffers (which stay `side`-square
20605 /// for stride/indexing) -- lane-partitions r1: a true rectangular HORZ/21296 /// for stride/indexing) -- lane-partitions r1: a true rectangular HORZ/
20606 /// VERT strip is predicted at its enclosing square `side` (matching21297 /// VERT strip is predicted at its enclosing square `side` (matching
@@ -20656,7 +21347,11 @@ fn read_inter_plane(
20656 plane_idx: usize,21347 plane_idx: usize,
20657 around: (bool, bool, i32),21348 around: (bool, bool, i32),
20658 tx_mode: usize,21349 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>,
20660 x: usize,21355 x: usize,
20661 y: usize,21356 y: usize,
20662 side: usize,21357 side: usize,
@@ -20727,7 +21422,7 @@ fn read_inter_plane(
20727 };21422 };
20728 let (dc_delta, ac_delta) = plane_q_delta(plane_idx, fctx);21423 let (dc_delta, ac_delta) = plane_q_delta(plane_idx, fctx);
20729 let residual = dequant_and_inverse_typed(&grid, side, bit_depth(fctx), block_q_idx(fctx), dc_delta, ac_delta, tx_type);21424 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);
20731 Ok((grid, tx_type))21426 Ok((grid, tx_type))
20732 }21427 }
20733 21428
@@ -23244,7 +23939,7 @@ fn decode_inter_block(
23244 .123939 .1
23245 };23940 };
23246 if skip {23941 if skip {
23247- y.reconstruct_mc_rect(23942+ push_mc_rect(0,
23248 px,23943 px,
23249 py,23944 py,
23250 side,23945 side,
@@ -23253,7 +23948,7 @@ fn decode_inter_block(
23253 &pred_y,23948 &pred_y,
23254 &vec![0i32; side * side], fctx,23949 &vec![0i32; side * side], fctx,
23255 );23950 );
23256- u.reconstruct_mc_rect(23951+ push_mc_rect(1,
23257 cpx,23952 cpx,
23258 cpy,23953 cpy,
23259 chroma_side,23954 chroma_side,
@@ -23262,7 +23957,7 @@ fn decode_inter_block(
23262 &pred_u,23957 &pred_u,
23263 &vec![0i32; chroma_side * chroma_side], fctx,23958 &vec![0i32; chroma_side * chroma_side], fctx,
23264 );23959 );
23265- v.reconstruct_mc_rect(23960+ push_mc_rect(2,
23266 cpx,23961 cpx,
23267 cpy,23962 cpy,
23268 chroma_side,23963 chroma_side,
@@ -24367,6 +25062,7 @@ fn decode_inter_block(
24367 // result, all planes (reconinter.c av1_build_interintra_predictor25062 // result, all planes (reconinter.c av1_build_interintra_predictor
24368 // plane loop).25063 // plane loop).
24369 if let Some(ii) = interintra_mode {25064 if let Some(ii) = interintra_mode {
25065+ flush_recon(fctx, y, u, v);
24370 if write_w != write_h {25066 if write_w != write_h {
24371 INTERINTRA_RECT_HITS.with(|c| c.set(c.get() + 1));25067 INTERINTRA_RECT_HITS.with(|c| c.set(c.get() + 1));
24372 }25068 }
@@ -24454,7 +25150,7 @@ fn decode_inter_block(
24454 .125150 .1
24455 };25151 };
24456 if skip {25152 if skip {
24457- y.reconstruct_mc_rect(25153+ push_mc_rect(0,
24458 px,25154 px,
24459 py,25155 py,
24460 side,25156 side,
@@ -24464,7 +25160,7 @@ fn decode_inter_block(
24464 &vec![0i32; side * side], fctx,25160 &vec![0i32; side * side], fctx,
24465 );25161 );
24466 if has_chroma {25162 if has_chroma {
24467- u.reconstruct_mc_rect(25163+ push_mc_rect(1,
24468 cpx,25164 cpx,
24469 cpy,25165 cpy,
24470 chroma_side,25166 chroma_side,
@@ -24473,7 +25169,7 @@ fn decode_inter_block(
24473 &pred_u,25169 &pred_u,
24474 &vec![0i32; chroma_side * chroma_side], fctx,25170 &vec![0i32; chroma_side * chroma_side], fctx,
24475 );25171 );
24476- v.reconstruct_mc_rect(25172+ push_mc_rect(2,
24477 cpx,25173 cpx,
24478 cpy,25174 cpy,
24479 chroma_side,25175 chroma_side,
@@ -25216,7 +25912,7 @@ fn decode_inter_block(
25216 set_palette_pred(window, fctx);25912 set_palette_pred(window, fctx);
25217 }25913 }
25218 let tu_grid = if skip {25914 let tu_grid = if skip {
25219- y.reconstruct(25915+ push_intra(0,
25220 tu_px,25916 tu_px,
25221 tu_py,25917 tu_py,
25222 tx_px,25918 tx_px,
@@ -25286,7 +25982,7 @@ fn decode_inter_block(
25286 for plane_idx in 1..3 {25982 for plane_idx in 1..3 {
25287 let buf: &mut PlaneBuf<'static> = if plane_idx == 1 { &mut *u } else { &mut *v };25983 let buf: &mut PlaneBuf<'static> = if plane_idx == 1 { &mut *u } else { &mut *v };
25288 let cu_grid = if skip {25984 let cu_grid = if skip {
25289- buf.reconstruct(25985+ push_intra(plane_idx,
25290 cu_x,25986 cu_x,
25291 cu_y,25987 cu_y,
25292 cu_tx,25988 cu_tx,
@@ -25356,7 +26052,7 @@ fn decode_inter_block(
25356 if let Some(buf) = &palette_y_buf {26052 if let Some(buf) = &palette_y_buf {
25357 set_palette_pred(buf.clone(), fctx);26053 set_palette_pred(buf.clone(), fctx);
25358 }26054 }
25359- y.reconstruct(26055+ push_intra(0,
25360 px,26056 px,
25361 py,26057 py,
25362 side,26058 side,
@@ -25369,11 +26065,11 @@ fn decode_inter_block(
25369 smooth_neighbor, fctx,26065 smooth_neighbor, fctx,
25370 );26066 );
25371 }26067 }
25372- let ac = alpha.map(|_| cfl_ac_q3(y, px, py, side));26068+ let ac = alpha.map(|_| cfl_src(px, py, side));
25373 if let Some((ub, _)) = &palette_uv_bufs {26069 if let Some((ub, _)) = &palette_uv_bufs {
25374 set_palette_pred(ub.clone(), fctx);26070 set_palette_pred(ub.clone(), fctx);
25375 }26071 }
25376- u.reconstruct(26072+ push_intra(1,
25377 cpx,26073 cpx,
25378 cpy,26074 cpy,
25379 chroma_side,26075 chroma_side,
@@ -25381,14 +26077,14 @@ fn decode_inter_block(
25381 angle_delta_uv,26077 angle_delta_uv,
25382 reach,26078 reach,
25383 &vec![0i32; chroma_side * chroma_side],26079 &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)),
25385 None,26081 None,
25386 smooth_neighbor_uv, fctx,26082 smooth_neighbor_uv, fctx,
25387 );26083 );
25388 if let Some((_, vb)) = &palette_uv_bufs {26084 if let Some((_, vb)) = &palette_uv_bufs {
25389 set_palette_pred(vb.clone(), fctx);26085 set_palette_pred(vb.clone(), fctx);
25390 }26086 }
25391- v.reconstruct(26087+ push_intra(2,
25392 cpx,26088 cpx,
25393 cpy,26089 cpy,
25394 chroma_side,26090 chroma_side,
@@ -25396,7 +26092,7 @@ fn decode_inter_block(
25396 angle_delta_uv,26092 angle_delta_uv,
25397 reach,26093 reach,
25398 &vec![0i32; chroma_side * chroma_side],26094 &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)),
25400 None,26096 None,
25401 smooth_neighbor_uv, fctx,26097 smooth_neighbor_uv, fctx,
25402 );26098 );
@@ -25437,7 +26133,7 @@ fn decode_inter_block(
25437 smooth_neighbor, fctx,26133 smooth_neighbor, fctx,
25438 )?26134 )?
25439 };26135 };
25440- let ac = alpha.map(|_| cfl_ac_q3(y, px, py, side));26136+ let ac = alpha.map(|_| cfl_src(px, py, side));
25441 if let Some((ub, _)) = &palette_uv_bufs {26137 if let Some((ub, _)) = &palette_uv_bufs {
25442 set_palette_pred(ub.clone(), fctx);26138 set_palette_pred(ub.clone(), fctx);
25443 }26139 }
@@ -25458,7 +26154,7 @@ fn decode_inter_block(
25458 chroma_side,26154 chroma_side,
25459 chroma_tx,26155 chroma_tx,
25460 base_q_idx,26156 base_q_idx,
25461- alpha.zip(ac.as_deref()).map(|((au, _), ac)| (au, ac)),26157+ alpha.zip(ac).map(|((au, _), ac)| (au, ac)),
25462 None,26158 None,
25463 None,26159 None,
25464 smooth_neighbor_uv, fctx,26160 smooth_neighbor_uv, fctx,
@@ -25483,7 +26179,7 @@ fn decode_inter_block(
25483 chroma_side,26179 chroma_side,
25484 chroma_tx,26180 chroma_tx,
25485 base_q_idx,26181 base_q_idx,
25486- alpha.zip(ac.as_deref()).map(|((_, av), ac)| (av, ac)),26182+ alpha.zip(ac).map(|((_, av), ac)| (av, ac)),
25487 None,26183 None,
25488 None,26184 None,
25489 smooth_neighbor_uv, fctx,26185 smooth_neighbor_uv, fctx,
@@ -26094,7 +26790,7 @@ fn decode_inter_sub8_split4(
26094 // txsize_to_bsize[tx_size]` branch (`txb_skip_ctx = 0`, which26790 // txsize_to_bsize[tx_size]` branch (`txb_skip_ctx = 0`, which
26095 // `read_inter_plane`'s `plane_idx == 0` arm already assumes).26791 // `read_inter_plane`'s `plane_idx == 0` arm already assumes).
26096 if skip {26792 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);
26098 neighbours.record_mi_luma_rect(lmi, B4, B4, &vec![0i32; B4 * B4]);26794 neighbours.record_mi_luma_rect(lmi, B4, B4, &vec![0i32; B4 * B4]);
26099 } else {26795 } else {
26100 let around = neighbours.around_mi(lmi, B4);26796 let around = neighbours.around_mi(lmi, B4);
@@ -26209,8 +26905,8 @@ fn decode_inter_sub8_split4(
26209 }26905 }
26210 }26906 }
26211 let (u_grid, v_grid) = if last_skip {26907 let (u_grid, v_grid) = if last_skip {
26212- u.reconstruct_mc(cpx, cpy, B4, &pred_u, &vec![0i32; B4 * B4], fctx);26908+ push_mc(1, cpx, cpy, B4, &pred_u, &vec![0i32; B4 * B4], fctx);
26213- v.reconstruct_mc(cpx, cpy, B4, &pred_v, &vec![0i32; B4 * B4], fctx);26909+ push_mc(2, cpx, cpy, B4, &pred_v, &vec![0i32; B4 * B4], fctx);
26214 (vec![0i32; B4 * B4], vec![0i32; B4 * B4])26910 (vec![0i32; B4 * B4], vec![0i32; B4 * B4])
26215 } else {26911 } else {
26216 let around = neighbours.around_mi(group_mi, 8);26912 let around = neighbours.around_mi(group_mi, 8);
@@ -26439,7 +27135,7 @@ fn decode_intra_sub8_leaf(
26439 );27135 );
26440 if skip {27136 if skip {
26441 let zeros = vec![0i32; 16];27137 let zeros = vec![0i32; 16];
26442- y.reconstruct(27138+ push_intra(0,
26443 tu_px, tu_py, 4, mode, angle_delta_y, tu_reach, &zeros, None, filter_intra,27139 tu_px, tu_py, 4, mode, angle_delta_y, tu_reach, &zeros, None, filter_intra,
26444 smooth_neighbor, fctx,27140 smooth_neighbor, fctx,
26445 );27141 );
@@ -26481,7 +27177,7 @@ fn decode_intra_sub8_leaf(
26481 // fixes `txb_skip_ctx` at 0 (`luma_skip_ctx: None`) -- the same square27177 // fixes `txb_skip_ctx` at 0 (`luma_skip_ctx: None`) -- the same square
26482 // reader [`decode_leaf_split4`] uses.27178 // reader [`decode_leaf_split4`] uses.
26483 if skip {27179 if skip {
26484- y.reconstruct(27180+ push_intra(0,
26485 px, py, 4, mode, angle_delta_y, reach, &vec![0i32; 16], None, filter_intra,27181 px, py, 4, mode, angle_delta_y, reach, &vec![0i32; 16], None, filter_intra,
26486 smooth_neighbor, fctx,27182 smooth_neighbor, fctx,
26487 );27183 );
@@ -26519,7 +27215,7 @@ fn decode_intra_sub8_leaf(
26519 } else {27215 } else {
26520 let grid_levels = if skip {27216 let grid_levels = if skip {
26521 let zeros = vec![0i32; bw * bh];27217 let zeros = vec![0i32; bw * bh];
26522- y.reconstruct_rect(27218+ push_intra_rect(0,
26523 px, py, bw, bh, mode, angle_delta_y, reach, &zeros, None, filter_intra,27219 px, py, bw, bh, mode, angle_delta_y, reach, &zeros, None, filter_intra,
26524 smooth_neighbor, fctx,27220 smooth_neighbor, fctx,
26525 );27221 );
@@ -26554,7 +27250,7 @@ fn decode_intra_sub8_leaf(
26554 plane_q_delta(0, fctx).1,27250 plane_q_delta(0, fctx).1,
26555 tx_type,27251 tx_type,
26556 );27252 );
26557- y.reconstruct_rect(27253+ push_intra_rect(0,
26558 px, py, bw, bh, mode, angle_delta_y, reach, &residual, None, filter_intra,27254 px, py, bw, bh, mode, angle_delta_y, reach, &residual, None, filter_intra,
26559 smooth_neighbor, fctx,27255 smooth_neighbor, fctx,
26560 );27256 );
@@ -26649,26 +27345,26 @@ fn decode_intra_sub8_leaf(
26649 // needs `bsize >= BLOCK_8X8`), so the group always clears.27345 // needs `bsize >= BLOCK_8X8`), so the group always clears.
26650 record_strip_palette(neighbours, (gr, gc), 8, 8, 0, [0u16; 8], 0, [0u16; 8]);27346 record_strip_palette(neighbours, (gr, gc), 8, 8, 0, [0u16; 8], 0, [0u16; 8]);
26651 27347
26652- let ac = alpha.map(|_| cfl_ac_q3(y, gpx, gpy, 8));27348+ let ac = alpha.map(|_| cfl_src(gpx, gpy, 8));
26653 let (u_grid, v_grid): (Vec<i32>, Vec<i32>) = if skip {27349 let (u_grid, v_grid): (Vec<i32>, Vec<i32>) = if skip {
26654 if alpha.is_some() {27350 if alpha.is_some() {
26655 CHROMA_SKIP_CFL_HITS.with(|h| h.set(h.get() + 1));27351 CHROMA_SKIP_CFL_HITS.with(|h| h.set(h.get() + 1));
26656 SKIP_CFL_HITS.with(|c| c.set(c.get() + 1));27352 SKIP_CFL_HITS.with(|c| c.set(c.get() + 1));
26657 }27353 }
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);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);
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);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);
26660 (vec![0i32; 16], vec![0i32; 16])27356 (vec![0i32; 16], vec![0i32; 16])
26661 } else {27357 } else {
26662 let chroma_around = neighbours.around_mi(group_mi, 8);27358 let chroma_around = neighbours.around_mi(group_mi, 8);
26663 let ug = read_plane(27359 let ug = read_plane(
26664 dec, cdfs, TxbSet::Chroma4, scan4, 1, chroma_around[1], uv_mode, uv_predict_mode,27360 dec, cdfs, TxbSet::Chroma4, scan4, 1, chroma_around[1], uv_mode, uv_predict_mode,
26665 angle_delta_uv, group_reach, u, cpx, cpy, 4, TX4, base_q_idx,27361 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,
26667 )?;27363 )?;
26668 let vg = read_plane(27364 let vg = read_plane(
26669 dec, cdfs, TxbSet::Chroma4, scan4, 2, chroma_around[2], uv_mode, uv_predict_mode,27365 dec, cdfs, TxbSet::Chroma4, scan4, 2, chroma_around[2], uv_mode, uv_predict_mode,
26670 angle_delta_uv, group_reach, v, cpx, cpy, 4, TX4, base_q_idx,27366 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,
26672 )?;27368 )?;
26673 (ug, vg)27369 (ug, vg)
26674 };27370 };
@@ -27067,7 +27763,7 @@ fn decode_inter_sub8_rect2(
27067 }27763 }
27068 }27764 }
27069 if skip {27765 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);
27071 neighbours.record_mi_luma_rect(lmi, bw, bh, &vec![0i32; bw * bh]);27767 neighbours.record_mi_luma_rect(lmi, bw, bh, &vec![0i32; bw * bh]);
27072 neighbours.fill_lf_grid_rect(lmi, w_mi, h_mi, bw as u8, bh as u8, ref_frame.max(LAST_FRAME), fctx);27768 neighbours.fill_lf_grid_rect(lmi, w_mi, h_mi, bw as u8, bh as u8, ref_frame.max(LAST_FRAME), fctx);
27073 } else {27769 } else {
@@ -27233,8 +27929,8 @@ fn decode_inter_sub8_rect2(
27233 }27929 }
27234 }27930 }
27235 let (u_grid, v_grid) = if last_skip {27931 let (u_grid, v_grid) = if last_skip {
27236- u.reconstruct_mc(cpx, cpy, B4, &pred_u, &vec![0i32; B4 * B4], fctx);27932+ push_mc(1, cpx, cpy, B4, &pred_u, &vec![0i32; B4 * B4], fctx);
27237- v.reconstruct_mc(cpx, cpy, B4, &pred_v, &vec![0i32; B4 * B4], fctx);27933+ push_mc(2, cpx, cpy, B4, &pred_v, &vec![0i32; B4 * B4], fctx);
27238 (vec![0i32; B4 * B4], vec![0i32; B4 * B4])27934 (vec![0i32; B4 * B4], vec![0i32; B4 * B4])
27239 } else {27935 } else {
27240 let around = neighbours.around_mi(group_mi, 8);27936 let around = neighbours.around_mi(group_mi, 8);
@@ -28070,15 +28766,15 @@ fn decode_inter_block8(
28070 .128766 .1
28071 .is_some();28767 .is_some();
28072 if skip {28768 if skip {
28073- y.reconstruct_mc(px, py, SIDE, &pred_y, &vec![0i32; SIDE * SIDE], fctx);28769+ push_mc(0, px, py, SIDE, &pred_y, &vec![0i32; SIDE * SIDE], fctx);
28074- u.reconstruct_mc(28770+ push_mc(1,
28075 cpx,28771 cpx,
28076 cpy,28772 cpy,
28077 CHROMA_SIDE,28773 CHROMA_SIDE,
28078 &pred_u,28774 &pred_u,
28079 &vec![0i32; CHROMA_SIDE * CHROMA_SIDE], fctx,28775 &vec![0i32; CHROMA_SIDE * CHROMA_SIDE], fctx,
28080 );28776 );
28081- v.reconstruct_mc(28777+ push_mc(2,
28082 cpx,28778 cpx,
28083 cpy,28779 cpy,
28084 CHROMA_SIDE,28780 CHROMA_SIDE,
@@ -28697,6 +29393,7 @@ fn decode_inter_block8(
28697 // Non-wedge interintra blend, mutually exclusive with OBMC (the29393 // Non-wedge interintra blend, mutually exclusive with OBMC (the
28698 // motion_mode symbol is not read for an interintra block).29394 // motion_mode symbol is not read for an interintra block).
28699 if let Some(ii) = interintra_mode {29395 if let Some(ii) = interintra_mode {
29396+ flush_recon(fctx, y, u, v);
28700 interintra_blend(y, px, py, SIDE, SIDE, SIDE, ii, wedge_mask, &mut pred_y, fctx);29397 interintra_blend(y, px, py, SIDE, SIDE, SIDE, ii, wedge_mask, &mut pred_y, fctx);
28701 interintra_blend(29398 interintra_blend(
28702 u, cpx, cpy, CHROMA_SIDE, CHROMA_SIDE, CHROMA_SIDE, ii, wedge_mask, &mut pred_u, fctx,29399 u, cpx, cpy, CHROMA_SIDE, CHROMA_SIDE, CHROMA_SIDE, ii, wedge_mask, &mut pred_u, fctx,
@@ -28719,15 +29416,15 @@ fn decode_inter_block8(
28719 .129416 .1
28720 .is_some();29417 .is_some();
28721 if skip {29418 if skip {
28722- y.reconstruct_mc(px, py, SIDE, &pred_y, &vec![0i32; SIDE * SIDE], fctx);29419+ push_mc(0, px, py, SIDE, &pred_y, &vec![0i32; SIDE * SIDE], fctx);
28723- u.reconstruct_mc(29420+ push_mc(1,
28724 cpx,29421 cpx,
28725 cpy,29422 cpy,
28726 CHROMA_SIDE,29423 CHROMA_SIDE,
28727 &pred_u,29424 &pred_u,
28728 &vec![0i32; CHROMA_SIDE * CHROMA_SIDE], fctx,29425 &vec![0i32; CHROMA_SIDE * CHROMA_SIDE], fctx,
28729 );29426 );
28730- v.reconstruct_mc(29427+ push_mc(2,
28731 cpx,29428 cpx,
28732 cpy,29429 cpy,
28733 CHROMA_SIDE,29430 CHROMA_SIDE,
@@ -29090,7 +29787,7 @@ fn decode_inter_block8(
29090 set_palette_pred(window, fctx);29787 set_palette_pred(window, fctx);
29091 }29788 }
29092 let tu_grid = if skip {29789 let tu_grid = if skip {
29093- y.reconstruct(29790+ push_intra(0,
29094 tu_px,29791 tu_px,
29095 tu_py,29792 tu_py,
29096 tx_px,29793 tx_px,
@@ -29143,7 +29840,7 @@ fn decode_inter_block8(
29143 if let Some(buf) = &palette_y_buf {29840 if let Some(buf) = &palette_y_buf {
29144 set_palette_pred(buf.clone(), fctx);29841 set_palette_pred(buf.clone(), fctx);
29145 }29842 }
29146- y.reconstruct(29843+ push_intra(0,
29147 px,29844 px,
29148 py,29845 py,
29149 SIDE,29846 SIDE,
@@ -29158,11 +29855,11 @@ fn decode_inter_block8(
29158 }29855 }
29159 // CfL's AC contribution is the luma this leaf just reconstructed,29856 // CfL's AC contribution is the luma this leaf just reconstructed,
29160 // averaged over the 4x4 chroma block (`cfl_ac_q3`, spec 7.11.5).29857 // 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));
29162 if let Some((ub, _)) = &palette_uv_bufs {29859 if let Some((ub, _)) = &palette_uv_bufs {
29163 set_palette_pred(ub.clone(), fctx);29860 set_palette_pred(ub.clone(), fctx);
29164 }29861 }
29165- u.reconstruct(29862+ push_intra(1,
29166 cpx,29863 cpx,
29167 cpy,29864 cpy,
29168 CHROMA_SIDE,29865 CHROMA_SIDE,
@@ -29170,14 +29867,14 @@ fn decode_inter_block8(
29170 angle_delta_uv,29867 angle_delta_uv,
29171 reach,29868 reach,
29172 &vec![0i32; CHROMA_SIDE * CHROMA_SIDE],29869 &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)),
29174 None,29871 None,
29175 smooth_neighbor_uv, fctx,29872 smooth_neighbor_uv, fctx,
29176 );29873 );
29177 if let Some((_, vb)) = &palette_uv_bufs {29874 if let Some((_, vb)) = &palette_uv_bufs {
29178 set_palette_pred(vb.clone(), fctx);29875 set_palette_pred(vb.clone(), fctx);
29179 }29876 }
29180- v.reconstruct(29877+ push_intra(2,
29181 cpx,29878 cpx,
29182 cpy,29879 cpy,
29183 CHROMA_SIDE,29880 CHROMA_SIDE,
@@ -29185,7 +29882,7 @@ fn decode_inter_block8(
29185 angle_delta_uv,29882 angle_delta_uv,
29186 reach,29883 reach,
29187 &vec![0i32; CHROMA_SIDE * CHROMA_SIDE],29884 &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)),
29189 None,29886 None,
29190 smooth_neighbor_uv, fctx,29887 smooth_neighbor_uv, fctx,
crates/ec-av1/src/par.rsmodified+28 -0
@@ -133,3 +133,31 @@ where
133 }133 }
134 }134 }
135 }135 }
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 {
6106 /// `--denoise-noise-level=25` stream whose frames carry film grain6106 /// `--denoise-noise-level=25` stream whose frames carry film grain
6107 /// parameters (small enough that 4 bands is one block row each, which is6107 /// parameters (small enough that 4 bands is one block row each, which is
6108 /// what exercises the grain band's one-row `prelude` replay).6108 /// 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+
6109 #[test]6153 #[test]
6110 fn a_real_stream_filters_identically_with_one_and_four_filter_threads() {6154 fn a_real_stream_filters_identically_with_one_and_four_filter_threads() {
6111 const NAME: &str = "a_real_stream_filters_identically_with_one_and_four_filter_threads";6155 const NAME: &str = "a_real_stream_filters_identically_with_one_and_four_filter_threads";