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