forge
Explore
Log in

Don't you dare go Hollow

Merge branch 'lane-defer8' (ffaef710): 8x8-leaf, OBMC (planned at parse, run on the worker) and sub-8x8 chroma-piece predictions build inside PredBuild closures, and reference pictures are resolved on the worker (parse reads only ref_dims); deferred failures parked on RefPix and taken after the tile loop; byte-exact on 16 gate hashes + 6 film cuts, two-stage default unchanged

Browse files at this commit

36b27a7d095226effdd448ab2c85c78adb0d6998Ahmet Kaan GümüşParent: 14f4482fb24177
crates/ec-av1/src/decode.rsmodified+471 -213
@@ -23210,11 +23210,16 @@ fn read_single_ref(
23210 /// way with a coarser (`LAST_FRAME`-only) neighbour shape.23210 /// way with a coarser (`LAST_FRAME`-only) neighbour shape.
23211 /// lane-twostage: this frame's references as DIMENSIONS now and PIXELS on23211 /// lane-twostage: this frame's references as DIMENSIONS now and PIXELS on
23212 /// demand. An inter tile's parse reads reference SIZES (`mc::scale_factor`)23212 /// demand. An inter tile's parse reads reference SIZES (`mc::scale_factor`)
23213-/// but touches no reference PIXEL until its first prediction -- measured 4.2%23213+/// only, so the pictures are resolved at the first [`ref_planes`] call
23214-/// of a 4K tile's parse into it -- so the pictures are resolved here, at the23214+/// rather than at frame entry. On the threaded path that resolution is a
23215-/// first [`ref_planes`] call, rather than at frame entry. On the threaded23215+/// WAIT on the producing frame's pixels, which is what lets a consumer parse
23216-/// path that resolution is a WAIT on the producing frame's pixels, which is23216+/// while its references are still being filtered.
23217-/// what lets a consumer parse while its references are still being filtered.23217+/// lane-defer8: at more than one reconstruction thread that first call now
23218+/// happens on a recon WORKER -- every whole-block prediction (the 16x16+
23219+/// paths, the 8x8 leaf, OBMC and the sub-8x8 chroma piece) is built inside
23220+/// its [`PredBuild`] closure, and the parse thread only ever asks for
23221+/// [`ref_dims`]. The sub-8x8 GROUP paths (4xN/Nx4 partitions) still predict
23222+/// inline and are the last parse-thread reference readers.
23218 pub(crate) struct RefPix<'p> {23223 pub(crate) struct RefPix<'p> {
23219 /// `(width, height)` per `ref_frame` index (`LAST_FRAME` = 1). `None` is23224 /// `(width, height)` per `ref_frame` index (`LAST_FRAME` = 1). `None` is
23220 /// a slot this frame may not use: empty, or -- for a non-`LAST_FRAME`23225 /// a slot this frame may not use: empty, or -- for a non-`LAST_FRAME`
@@ -23223,6 +23228,10 @@ pub(crate) struct RefPix<'p> {
23223 dims: [Option<(usize, usize)>; 8],23228 dims: [Option<(usize, usize)>; 8],
23224 src: RefSrc<'p>,23229 src: RefSrc<'p>,
23225 bufs: std::sync::OnceLock<[Option<(PlaneBuf<'p>, PlaneBuf<'p>, PlaneBuf<'p>)>; 8]>,23230 bufs: std::sync::OnceLock<[Option<(PlaneBuf<'p>, PlaneBuf<'p>, PlaneBuf<'p>)>; 8]>,
23231+ /// lane-defer8: a DEFERRED prediction's [`ref_planes`] failure, parked
23232+ /// here for the frame decoder to take ([`take_err`](Self::take_err)) --
23233+ /// a recon worker replaying a recorded op has no `?` of its own.
23234+ err: std::sync::Mutex<Option<Error>>,
23226 }23235 }
23227 23236
23228 /// Where a [`RefPix`] gets its pictures: already in hand, or behind a wait23237 /// Where a [`RefPix`] gets its pictures: already in hand, or behind a wait
@@ -23242,7 +23251,7 @@ impl<'p> RefPix<'p> {
23242 let dims = Self::compatible(std::array::from_fn(|i| {23251 let dims = Self::compatible(std::array::from_fn(|i| {
23243 refs[i].map(|p| (p.width, p.height))23252 refs[i].map(|p| (p.width, p.height))
23244 }));23253 }));
23245- Self { dims, src: RefSrc::Ready(refs), bufs: std::sync::OnceLock::new() }23254+ Self { dims, src: RefSrc::Ready(refs), bufs: std::sync::OnceLock::new(), err: std::sync::Mutex::new(None) }
23246 }23255 }
23247 23256
23248 /// References whose sizes are known (from their producers' headers) but23257 /// References whose sizes are known (from their producers' headers) but
@@ -23251,7 +23260,12 @@ impl<'p> RefPix<'p> {
23251 dims: [Option<(usize, usize)>; 8],23260 dims: [Option<(usize, usize)>; 8],
23252 wait: &'p (dyn Fn() -> Result<[Option<&'p Picture>; 8]> + Send + Sync + 'p),23261 wait: &'p (dyn Fn() -> Result<[Option<&'p Picture>; 8]> + Send + Sync + 'p),
23253 ) -> Self {23262 ) -> Self {
23254- Self { dims: Self::compatible(dims), src: RefSrc::Lazy(wait), bufs: std::sync::OnceLock::new() }23263+ Self {
23264+ dims: Self::compatible(dims),
23265+ src: RefSrc::Lazy(wait),
23266+ bufs: std::sync::OnceLock::new(),
23267+ err: std::sync::Mutex::new(None),
23268+ }
23255 }23269 }
23256 23270
23257 /// Spec 7.9's compatible-size rule: a non-`LAST_FRAME` slot at a23271 /// Spec 7.9's compatible-size rule: a non-`LAST_FRAME` slot at a
@@ -23272,6 +23286,23 @@ impl<'p> RefPix<'p> {
23272 self.dims.get(ref_frame as usize).copied().flatten()23286 self.dims.get(ref_frame as usize).copied().flatten()
23273 }23287 }
23274 23288
23289+ /// Parks a deferred prediction's failure (first one wins).
23290+ fn park_err(&self, e: Error) {
23291+ let mut slot = self.err.lock().expect("the parked-error slot is never poisoned");
23292+ if slot.is_none() {
23293+ *slot = Some(e);
23294+ }
23295+ }
23296+
23297+ /// The first failure any deferred prediction parked, taken once every
23298+ /// recon worker of the frame has been joined.
23299+ pub(crate) fn take_err(&self) -> Result<()> {
23300+ match self.err.lock().expect("the parked-error slot is never poisoned").take() {
23301+ Some(e) => Err(e),
23302+ None => Ok(()),
23303+ }
23304+ }
23305+
23275 /// Every usable slot's three planes, resolving (and, on the threaded23306 /// Every usable slot's three planes, resolving (and, on the threaded
23276 /// path, waiting for) the pictures on the first call.23307 /// path, waiting for) the pictures on the first call.
23277 fn planes(&self) -> Result<&[Option<(PlaneBuf<'p>, PlaneBuf<'p>, PlaneBuf<'p>)>; 8]> {23308 fn planes(&self) -> Result<&[Option<(PlaneBuf<'p>, PlaneBuf<'p>, PlaneBuf<'p>)>; 8]> {
@@ -23297,6 +23328,37 @@ impl<'p> RefPix<'p> {
23297 }23328 }
23298 }23329 }
23299 23330
23331+/// This slot's picture SIZE, with [`ref_planes`]' own error when the slot
23332+/// carries no usable picture -- `dims` is `None` exactly when `planes()`
23333+/// would have nothing there, so the parse thread keeps refusing the same
23334+/// streams at the same block WITHOUT waiting for a producer's pixels
23335+/// (lane-defer8).
23336+fn ref_dims(ref_frame: i8, refpix: &RefPix<'_>) -> Result<(usize, usize)> {
23337+ refpix.dims(ref_frame).ok_or_else(|| {
23338+ unsupported(
23339+ "a reference frame selected with no picture at this frame's own \
23340+ ref_frame_idx slot for it",
23341+ )
23342+ })
23343+}
23344+
23345+/// [`ref_planes`] from inside a DEFERRED prediction, where there is no `?`
23346+/// to take: the error is parked on the [`RefPix`] and taken by the frame
23347+/// decoder once the workers are joined ([`RefPix::take_err`]). The block's
23348+/// prediction is left zeroed -- the frame is failing either way.
23349+fn ref_planes_deferred<'a, 'p>(
23350+ ref_frame: i8,
23351+ refpix: &'a RefPix<'p>,
23352+) -> Option<(&'a PlaneBuf<'p>, &'a PlaneBuf<'p>, &'a PlaneBuf<'p>)> {
23353+ match ref_planes(ref_frame, refpix) {
23354+ Ok(planes) => Some(planes),
23355+ Err(e) => {
23356+ refpix.park_err(e);
23357+ None
23358+ }
23359+ }
23360+}
23361+
23300 /// A whole reference plane as a [`PlaneBuf`]: no tile window, no margin.23362 /// A whole reference plane as a [`PlaneBuf`]: no tile window, no margin.
23301 fn whole_plane(data: &[u16], width: usize, height: usize) -> PlaneBuf<'_> {23363 fn whole_plane(data: &[u16], width: usize, height: usize) -> PlaneBuf<'_> {
23302 PlaneBuf {23364 PlaneBuf {
@@ -24022,7 +24084,7 @@ nbmv=({},{}) nbref={} nbbsize={} filt={}",
24022 /// how many bordering blocks actually get blended, separate from the24084 /// how many bordering blocks actually get blended, separate from the
24023 /// eligibility scan's own unbounded ("any at all") walk.24085 /// eligibility scan's own unbounded ("any at all") walk.
24024 #[allow(clippy::too_many_arguments)]24086 #[allow(clippy::too_many_arguments)]
24025-fn obmc_blend(24087+fn obmc_plan(
24026 grid: &MiGrid,24088 grid: &MiGrid,
24027 neighbours: &Neighbours,24089 neighbours: &Neighbours,
24028 mi_row: usize,24090 mi_row: usize,
@@ -24047,10 +24109,7 @@ fn obmc_blend(
24047 // `av1_setup_build_prediction_by_above_pred` passing that ref's own24109 // `av1_setup_build_prediction_by_above_pred` passing that ref's own
24048 // `scale_factors`).24110 // `scale_factors`).
24049 frame_width: usize,24111 frame_width: usize,
24050- pred_y: &mut [u16],24112+) -> Result<ObmcPlan> {
24051- pred_u: &mut [u16],
24052- pred_v: &mut [u16], fctx: &crate::decode::FrameCtx,
24053-) -> Result<()> {
24054 // lane-rect r2 (libaom av1_build_obmc_inter_prediction): each pass has24113 // lane-rect r2 (libaom av1_build_obmc_inter_prediction): each pass has
24055 // its OWN neighbour cap (width-log2 for above, height-log2 for left) and24114 // its OWN neighbour cap (width-log2 for above, height-log2 for left) and
24056 // overlap (bh/2 rows above, bw/2 cols left) -- one square `side` was24115 // overlap (bh/2 rows above, bw/2 cols left) -- one square `side` was
@@ -24070,31 +24129,151 @@ fn obmc_blend(
24070 5..=8 => 3,24129 5..=8 => 3,
24071 _ => 4,24130 _ => 4,
24072 };24131 };
24073- // lane-inter4 r4: r3 refused OBMC on a 16x8/8x16 leaf (5302 luma pixels24132+ // lane-inter4 r4: r3 refused OBMC on a 16x8/8x16 leaf; re-measured
24074- // of one frame wrong). Re-measured on this tree with an `EC_OBMC` rung in24133+ // byte-exact against an instrumented aomdec, the refusal is gone and the
24075- // both decoders on that exact stream: the neighbour lists agree entry for24134+ // counter below is what the gate's `--enable-obmc=1` arm reads.
24076- // entry (position, span, mv, ref, size, filter) and all six pre-filter
24077- // frames are byte-identical to the instrumented aomdec's. The refusal is
24078- // gone; the counter below is what the gate's `--enable-obmc=1` arm reads.
24079- // The only decode-path change between r3's measurement and this one is the
24080- // lane-interbis merge (`build_motion_field`'s compound slot walk), which
24081- // moves temporal MV candidates -- not bisected further.
24082 if matches!((write_w, write_h), (16, 8) | (8, 16)) {24135 if matches!((write_w, write_h), (16, 8) | (8, 16)) {
24083 OBMC_RECT_LEAF_HITS.with(|c| c.set(c.get() + 1));24136 OBMC_RECT_LEAF_HITS.with(|c| c.set(c.get() + 1));
24084 }24137 }
24085 // lane-sb128c r1: libaom caps the overlap strip at a 64x64 block's own24138 // lane-sb128c r1: libaom caps the overlap strip at a 64x64 block's own
24086- // half (`reconinter.c` 860/899: `AOMMIN(block_size_high[bsize],24139+ // half (`reconinter.c` 860/899), inert below 128.
24087- // block_size_high[BLOCK_64X64]) >> 1`, and the `block_size_wide` mirror) --
24088- // inert below 128, where a 128x128 block would otherwise blend a 64-row
24089- // strip `obmc_mask` has no table for.
24090 let overlap_above = write_h.min(64) / 2;24140 let overlap_above = write_h.min(64) / 2;
24091 let overlap_left = write_w.min(64) / 2;24141 let overlap_left = write_w.min(64) / 2;
24092 // lane-inter8 r1 / lane-scaledref r1: `av1_skip_u4x4_pred_in_obmc`24142 // lane-inter8 r1 / lane-scaledref r1: `av1_skip_u4x4_pred_in_obmc`
24093- // (`reconinter.c` 820, `DISABLE_CHROMA_U8X8_OBMC == 0` -- "one-sided24143+ // (`reconinter.c` 820) returns `dir == 0` when the chroma plane's own
24094- // obmc") returns `dir == 0` when the chroma plane's own block is24144+ // block is BLOCK_4X4/8X4/4X8 (an 8x8, 16x8 or 8x16 luma block at 4:2:0):
24095- // BLOCK_4X4/8X4/4X8 (an 8x8, 16x8 or 8x16 luma block at 4:2:0): the24145+ // the ABOVE pass skips chroma entirely, the LEFT pass still blends it.
24096- // ABOVE pass skips chroma entirely, the LEFT pass still blends it.
24097 let skip_chroma_above = matches!((write_w, write_h), (8, 8) | (16, 8) | (8, 16));24146 let skip_chroma_above = matches!((write_w, write_h), (8, 8) | (16, 8) | (8, 16));
24147+ let mut above = Vec::new();
24148+ for (off4, span4, nb, src4) in overlappable_above(grid, mi_row, mi_col, bw4, mi_cols, max_nb(bw4))
24149+ {
24150+ // `Neighbours::above_filter` is indexed in `SUB`(16px)-wide columns,
24151+ // one step coarser than the mi(4px) units `overlappable_above` walks
24152+ // in -- divide back down to that column. lane-gmaffine r2: the
24153+ // neighbour's OWN mi-granular filter (libaom
24154+ // `av1_setup_build_prediction_by_above_pred` reads
24155+ // `above_mbmi->interp_filters`).
24156+ let above_syms = neighbours.above_filter[mi_col + src4];
24157+ obmcrec_probe(
24158+ "above", mi_row, mi_col, write_w, write_h, off4, span4, &nb, above_syms,
24159+ grid.get(mi_row - 1, mi_col + src4), interp_fixed.is_some(),
24160+ );
24161+ let (h_kind, v_kind) = neighbour_filter(interp_fixed, above_syms)?;
24162+ ec_obmc_trace("above", mi_row, mi_col, write_w, write_h, off4, span4, &nb, h_kind, v_kind);
24163+ let (nb_width, _) = ref_dims(nb.ref_frame, refpix)?;
24164+ if mi_col + off4 + span4 > mi_cols {
24165+ OBMC_EDGE_SPAN_HITS.with(|c| c.set(c.get() + 1));
24166+ }
24167+ above.push(ObmcNb {
24168+ off4,
24169+ span4,
24170+ mv: mv32(nb.mv),
24171+ ref_frame: nb.ref_frame,
24172+ h_kind,
24173+ v_kind,
24174+ scale: mc::scale_factor(nb_width, frame_width),
24175+ });
24176+ }
24177+ let mut left = Vec::new();
24178+ for (off4, span4, nb, src4) in overlappable_left(grid, mi_row, mi_col, bh4, mi_rows, max_nb(bh4))
24179+ {
24180+ let left_syms = neighbours.left_filter[mi_row + src4];
24181+ obmcrec_probe(
24182+ "left", mi_row, mi_col, write_w, write_h, off4, span4, &nb, left_syms,
24183+ grid.get(mi_row + src4, mi_col - 1), interp_fixed.is_some(),
24184+ );
24185+ let (h_kind, v_kind) = neighbour_filter(interp_fixed, left_syms)?;
24186+ ec_obmc_trace("left", mi_row, mi_col, write_w, write_h, off4, span4, &nb, h_kind, v_kind);
24187+ let (nb_width, _) = ref_dims(nb.ref_frame, refpix)?;
24188+ if mi_row + off4 + span4 > mi_rows {
24189+ OBMC_EDGE_SPAN_HITS.with(|c| c.set(c.get() + 1));
24190+ }
24191+ left.push(ObmcNb {
24192+ off4,
24193+ span4,
24194+ mv: mv32(nb.mv),
24195+ ref_frame: nb.ref_frame,
24196+ h_kind,
24197+ v_kind,
24198+ scale: mc::scale_factor(nb_width, frame_width),
24199+ });
24200+ }
24201+ Ok(ObmcPlan {
24202+ above,
24203+ left,
24204+ side,
24205+ chroma_side,
24206+ write_w,
24207+ write_h,
24208+ px,
24209+ py,
24210+ cpx,
24211+ cpy,
24212+ overlap_above,
24213+ overlap_left,
24214+ skip_chroma_above,
24215+ })
24216+}
24217+
24218+/// One OBMC neighbour as the PARSE thread resolved it (lane-defer8): every
24219+/// value [`obmc_run`] needs that lives in the mode-info grid or the
24220+/// neighbour bands, which the parse keeps overwriting as it walks on.
24221+struct ObmcNb {
24222+ off4: usize,
24223+ span4: usize,
24224+ mv: (i32, i32),
24225+ ref_frame: i8,
24226+ h_kind: mc::InterpFilterKind,
24227+ v_kind: mc::InterpFilterKind,
24228+ /// spec 7.11.3.3's `x_scale_fp` for THIS neighbour's own reference.
24229+ scale: i64,
24230+}
24231+
24232+/// [`obmc_plan`]'s result: the two neighbour passes plus this block's own
24233+/// geometry, everything [`obmc_run`] reads apart from reference PIXELS.
24234+pub(crate) struct ObmcPlan {
24235+ above: Vec<ObmcNb>,
24236+ left: Vec<ObmcNb>,
24237+ side: usize,
24238+ chroma_side: usize,
24239+ write_w: usize,
24240+ write_h: usize,
24241+ px: usize,
24242+ py: usize,
24243+ cpx: usize,
24244+ cpy: usize,
24245+ overlap_above: usize,
24246+ overlap_left: usize,
24247+ skip_chroma_above: bool,
24248+}
24249+
24250+/// The reference-pixel half of OBMC: re-predicts every planned neighbour
24251+/// over this block's own edge strips and blends it into the prediction
24252+/// (libaom `av1_build_obmc_inter_prediction`). Reads nothing but reference
24253+/// pixels and the plan, so it runs wherever the block's prediction is built
24254+/// -- on a recon worker when that prediction is deferred (lane-defer8).
24255+fn obmc_run(
24256+ plan: &ObmcPlan,
24257+ refpix: &RefPix<'_>,
24258+ pred_y: &mut [u16],
24259+ pred_u: &mut [u16],
24260+ pred_v: &mut [u16],
24261+ fctx: &crate::decode::FrameCtx,
24262+) {
24263+ let &ObmcPlan {
24264+ side,
24265+ chroma_side,
24266+ write_w,
24267+ write_h,
24268+ px,
24269+ py,
24270+ cpx,
24271+ cpy,
24272+ overlap_above,
24273+ overlap_left,
24274+ skip_chroma_above,
24275+ ..
24276+ } = plan;
24098 // lane-alloc: one neighbour-prediction buffer per plane for the whole24277 // lane-alloc: one neighbour-prediction buffer per plane for the whole
24099 // block, reused by every neighbour of the above and left passes.24278 // block, reused by every neighbour of the above and left passes.
24100 let (mut tmp_y, mut tmp_u, mut tmp_v) = (Vec::new(), Vec::new(), Vec::new());24279 let (mut tmp_y, mut tmp_u, mut tmp_v) = (Vec::new(), Vec::new(), Vec::new());
@@ -24132,74 +24311,41 @@ fn obmc_blend(
24132 eprintln!("OUR_MCB prerow{r}: {row:?}");24311 eprintln!("OUR_MCB prerow{r}: {row:?}");
24133 }24312 }
24134 }24313 }
24135- for (off4, span4, nb, src4) in overlappable_above(grid, mi_row, mi_col, bw4, mi_cols, max_nb(bw4))24314+ for nb in &plan.above {
24136- {24315+ let Some((ny, nu, nv)) = ref_planes_deferred(nb.ref_frame, refpix) else {
24137- // `Neighbours::above_filter` is indexed in `SUB`(16px)-wide columns24316+ return;
24138- // (this decoder's own outer block-loop granularity), one step24317+ };
24139- // coarser than the mi(4px) units `overlappable_above` walks in --24318+ let (bw, bh, ox) = (nb.span4 * 4, overlap_above, nb.off4 * 4);
24140- // divide back down to that column.
24141- // lane-gmaffine r2: the neighbour's OWN mi-granular filter
24142- // (libaom `av1_setup_build_prediction_by_above_pred` reads
24143- // `above_mbmi->interp_filters`); the 16px-granular `Neighbours` slot
24144- // stays as the fallback for paths that do not record one yet
24145- // (compound), which is what every earlier round used.
24146- let above_syms = neighbours.above_filter[mi_col + src4];
24147- obmcrec_probe(
24148- "above", mi_row, mi_col, write_w, write_h, off4, span4, &nb, above_syms,
24149- grid.get(mi_row - 1, mi_col + src4), interp_fixed.is_some(),
24150- );
24151- let (h_kind, v_kind) = neighbour_filter(interp_fixed, above_syms)?;
24152- ec_obmc_trace("above", mi_row, mi_col, write_w, write_h, off4, span4, &nb, h_kind, v_kind);
24153- let (ny, nu, nv) = ref_planes(nb.ref_frame, refpix)?;
24154- let nb_scale = mc::scale_factor(ny.width, frame_width);
24155- if mi_col + off4 + span4 > mi_cols {
24156- OBMC_EDGE_SPAN_HITS.with(|c| c.set(c.get() + 1));
24157- }
24158- let (bw, bh, ox) = (span4 * 4, overlap_above, off4 * 4);
24159 // lane-t900 r14: the prediction is `op_mi_size` wide (kernel choice24319 // lane-t900 r14: the prediction is `op_mi_size` wide (kernel choice
24160 // included); only the WRITE is clipped to this block's own buffer.24320 // included); only the WRITE is clipped to this block's own buffer.
24161- obmc_neighbour_pred(ny, px + ox, py, mv32(nb.mv), bw, bh, true, h_kind, v_kind, nb_scale, &mut tmp_y, fctx);24321+ obmc_neighbour_pred(ny, px + ox, py, nb.mv, bw, bh, true, nb.h_kind, nb.v_kind, nb.scale, &mut tmp_y, fctx);
24162 obmc_blend_v(pred_y, side, ox, 0, bw.min(write_w - ox), bh, bw, &tmp_y);24322 obmc_blend_v(pred_y, side, ox, 0, bw.min(write_w - ox), bh, bw, &tmp_y);
24163 if !skip_chroma_above {24323 if !skip_chroma_above {
24164 // lane-t900 r13 (measured, NOT a defect): libaom's min-4 clamp24324 // lane-t900 r13 (measured, NOT a defect): libaom's min-4 clamp
24165- // (`dec_build_prediction_by_above_pred`) sizes only the OBMC24325+ // sizes only the OBMC PREDICTION buffer; the blend length is the
24166- // PREDICTION buffer; the blend length is the plain half24326+ // plain half (`build_obmc_inter_pred_above`: `overlap >> ss_y`).
24167- // (`build_obmc_inter_pred_above`: `overlap >> ss_y`), so flooring
24168- // this at 4 blends rows libaom never blends -- on a 10-bit
24169- // 1920x792 cut that went 36 differing frames -> 266, worst
24170- // 13 B -> 11007 B.
24171 let (cbw, cbh, cox) = (bw / 2, overlap_above / 2, ox / 2);24327 let (cbw, cbh, cox) = (bw / 2, overlap_above / 2, ox / 2);
24172 let cw = cbw.min(write_w / 2 - cox);24328 let cw = cbw.min(write_w / 2 - cox);
24173- obmc_neighbour_pred(nu, cpx + cox, cpy, mv32(nb.mv), cbw, cbh, false, h_kind, v_kind, nb_scale, &mut tmp_u, fctx);24329+ obmc_neighbour_pred(nu, cpx + cox, cpy, nb.mv, cbw, cbh, false, nb.h_kind, nb.v_kind, nb.scale, &mut tmp_u, fctx);
24174 obmc_blend_v(pred_u, chroma_side, cox, 0, cw, cbh, cbw, &tmp_u);24330 obmc_blend_v(pred_u, chroma_side, cox, 0, cw, cbh, cbw, &tmp_u);
24175- obmc_neighbour_pred(nv, cpx + cox, cpy, mv32(nb.mv), cbw, cbh, false, h_kind, v_kind, nb_scale, &mut tmp_v, fctx);24331+ obmc_neighbour_pred(nv, cpx + cox, cpy, nb.mv, cbw, cbh, false, nb.h_kind, nb.v_kind, nb.scale, &mut tmp_v, fctx);
24176 obmc_blend_v(pred_v, chroma_side, cox, 0, cw, cbh, cbw, &tmp_v);24332 obmc_blend_v(pred_v, chroma_side, cox, 0, cw, cbh, cbw, &tmp_v);
24177 }24333 }
24178 }24334 }
24179 24335
24180- for (off4, span4, nb, src4) in overlappable_left(grid, mi_row, mi_col, bh4, mi_rows, max_nb(bh4))24336+ for nb in &plan.left {
24181- {24337+ let Some((ny, nu, nv)) = ref_planes_deferred(nb.ref_frame, refpix) else {
24182- let left_syms = neighbours.left_filter[mi_row + src4];24338+ return;
24183- obmcrec_probe(24339+ };
24184- "left", mi_row, mi_col, write_w, write_h, off4, span4, &nb, left_syms,24340+ let (bw, bh, oy) = (overlap_left, nb.span4 * 4, nb.off4 * 4);
24185- grid.get(mi_row + src4, mi_col - 1), interp_fixed.is_some(),24341+ obmc_neighbour_pred(ny, px, py + oy, nb.mv, bw, bh, true, nb.h_kind, nb.v_kind, nb.scale, &mut tmp_y, fctx);
24186- );
24187- let (h_kind, v_kind) = neighbour_filter(interp_fixed, left_syms)?;
24188- ec_obmc_trace("left", mi_row, mi_col, write_w, write_h, off4, span4, &nb, h_kind, v_kind);
24189- let (ny, nu, nv) = ref_planes(nb.ref_frame, refpix)?;
24190- let nb_scale = mc::scale_factor(ny.width, frame_width);
24191- if mi_row + off4 + span4 > mi_rows {
24192- OBMC_EDGE_SPAN_HITS.with(|c| c.set(c.get() + 1));
24193- }
24194- let (bw, bh, oy) = (overlap_left, span4 * 4, off4 * 4);
24195- obmc_neighbour_pred(ny, px, py + oy, mv32(nb.mv), bw, bh, true, h_kind, v_kind, nb_scale, &mut tmp_y, fctx);
24196 obmc_blend_h(pred_y, side, 0, oy, bw, bh.min(write_h - oy), &tmp_y);24342 obmc_blend_h(pred_y, side, 0, oy, bw, bh.min(write_h - oy), &tmp_y);
24197 let (cbw, cbh, coy) = (overlap_left / 2, bh / 2, oy / 2);24343 let (cbw, cbh, coy) = (overlap_left / 2, bh / 2, oy / 2);
24198- obmc_neighbour_pred(nu, cpx, cpy + coy, mv32(nb.mv), cbw, cbh, false, h_kind, v_kind, nb_scale, &mut tmp_u, fctx);24344+ obmc_neighbour_pred(nu, cpx, cpy + coy, nb.mv, cbw, cbh, false, nb.h_kind, nb.v_kind, nb.scale, &mut tmp_u, fctx);
24199 if let Some((_, _, idx)) = ec_mcb {24345 if let Some((_, _, idx)) = ec_mcb {
24200 eprintln!(24346 eprintln!(
24201- "OUR_MCB left f={idx} off4={off4} span4={span4} cbw={cbw} cbh={cbh} coy={coy} mv=({},{}) ref0={}",24347+ "OUR_MCB left f={idx} off4={} span4={} cbw={cbw} cbh={cbh} coy={coy} mv=({},{}) ref0={}",
24202- nb.mv.0, nb.mv.1, nb.ref_frame24348+ nb.off4, nb.span4, nb.mv.0, nb.mv.1, nb.ref_frame
24203 );24349 );
24204 for r in 0..cbh {24350 for r in 0..cbh {
24205 let row: Vec<u16> = (0..cbw).map(|c| tmp_u[r * cbw + c]).collect();24351 let row: Vec<u16> = (0..cbw).map(|c| tmp_u[r * cbw + c]).collect();
@@ -24208,7 +24354,7 @@ fn obmc_blend(
24208 }24354 }
24209 let ch = cbh.min(write_h / 2 - coy);24355 let ch = cbh.min(write_h / 2 - coy);
24210 obmc_blend_h(pred_u, chroma_side, 0, coy, cbw, ch, &tmp_u);24356 obmc_blend_h(pred_u, chroma_side, 0, coy, cbw, ch, &tmp_u);
24211- obmc_neighbour_pred(nv, cpx, cpy + coy, mv32(nb.mv), cbw, cbh, false, h_kind, v_kind, nb_scale, &mut tmp_v, fctx);24357+ obmc_neighbour_pred(nv, cpx, cpy + coy, nb.mv, cbw, cbh, false, nb.h_kind, nb.v_kind, nb.scale, &mut tmp_v, fctx);
24212 obmc_blend_h(pred_v, chroma_side, 0, coy, cbw, ch, &tmp_v);24358 obmc_blend_h(pred_v, chroma_side, 0, coy, cbw, ch, &tmp_v);
24213 }24359 }
24214 if let Some((_, _, idx)) = ec_mcb {24360 if let Some((_, _, idx)) = ec_mcb {
@@ -24217,7 +24363,6 @@ fn obmc_blend(
24217 eprintln!("OUR_MCB post f={idx} row{r}: {row:?}");24363 eprintln!("OUR_MCB post f={idx} row{r}: {row:?}");
24218 }24364 }
24219 }24365 }
24220- Ok(())
24221 }24366 }
24222 24367
24223 /// `is_any_masked_compound_used` (libaom `reconinter.h`), specialised to24368 /// `is_any_masked_compound_used` (libaom `reconinter.h`), specialised to
@@ -25037,8 +25182,8 @@ fn decode_inter_block(
25037 if gm_nontrans_models && !gm_nontrans {25182 if gm_nontrans_models && !gm_nontrans {
25038 GM_NONTRANS_SMALL_SIDE_HITS.with(|c| c.set(c.get() + 1));25183 GM_NONTRANS_SMALL_SIDE_HITS.with(|c| c.set(c.get() + 1));
25039 }25184 }
25040- let (py0, pu0, pv0) = ref_planes(ref0, refpix)?;25185+ // lane-defer8: both slots' pictures are resolved inside the
25041- let (py1, pu1, pv1) = ref_planes(ref1, refpix)?;25186+ // prediction closure; the parse only needs their SIZES.
25042 // lane-cwarp r1: `is_global_mv_block` (blockd.h:421-429) is25187 // lane-cwarp r1: `is_global_mv_block` (blockd.h:421-429) is
25043 // PER REFERENCE SLOT -- mode GLOBAL_GLOBALMV, block >= 8x8, and25188 // PER REFERENCE SLOT -- mode GLOBAL_GLOBALMV, block >= 8x8, and
25044 // THAT slot's own gm model > TRANSLATION. `bw4`/`bh4` come from25189 // THAT slot's own gm model > TRANSLATION. `bw4`/`bh4` come from
@@ -25080,10 +25225,9 @@ fn decode_inter_block(
25080 // scaled (superres) is predicted translationally while its25225 // scaled (superres) is predicted translationally while its
25081 // sibling may still warp.25226 // sibling may still warp.
25082 let ref_unscaled = |rf: i8| {25227 let ref_unscaled = |rf: i8| {
25083- ref_planes(rf, refpix)25228+ refpix
25084- .is_ok_and(|(py, _, _)| {25229+ .dims(rf)
25085- mc::scale_factor(py.width, frame_width) == mc::REF_NO_SCALE25230+ .is_some_and(|(w, _)| mc::scale_factor(w, frame_width) == mc::REF_NO_SCALE)
25086- })
25087 };25231 };
25088 let warp0 = compound_warp(ref0, is_global_mv0).filter(|_| ref_unscaled(ref0));25232 let warp0 = compound_warp(ref0, is_global_mv0).filter(|_| ref_unscaled(ref0));
25089 let warp1 = compound_warp(ref1, is_global_mv1).filter(|_| ref_unscaled(ref1));25233 let warp1 = compound_warp(ref1, is_global_mv1).filter(|_| ref_unscaled(ref1));
@@ -25505,8 +25649,8 @@ fn decode_inter_block(
25505 // different ratios in the same block. `REF_NO_SCALE` reduces25649 // different ratios in the same block. `REF_NO_SCALE` reduces
25506 // `predict_compound_intermediate`'s walk to the ordinary25650 // `predict_compound_intermediate`'s walk to the ordinary
25507 // stride-1 one, so the unscaled case is unchanged.25651 // stride-1 one, so the unscaled case is unchanged.
25508- let scale0 = mc::scale_factor(py0.width, frame_width);25652+ let scale0 = mc::scale_factor(ref_dims(ref0, refpix)?.0, frame_width);
25509- let scale1 = mc::scale_factor(py1.width, frame_width);25653+ let scale1 = mc::scale_factor(ref_dims(ref1, refpix)?.0, frame_width);
25510 if scale0 != mc::REF_NO_SCALE || scale1 != mc::REF_NO_SCALE {25654 if scale0 != mc::REF_NO_SCALE || scale1 != mc::REF_NO_SCALE {
25511 SCALED_COMPOUND_HITS.with(|c| c.set(c.get() + 1));25655 SCALED_COMPOUND_HITS.with(|c| c.set(c.get() + 1));
25512 }25656 }
@@ -25529,6 +25673,11 @@ fn decode_inter_block(
25529 _v: &mut PlaneBuf<'static>,25673 _v: &mut PlaneBuf<'static>,
25530 fctx: &crate::decode::FrameCtx,25674 fctx: &crate::decode::FrameCtx,
25531 out: &mut [Vec<u16>; 3]| {25675 out: &mut [Vec<u16>; 3]| {
25676+ let (Some((py0, pu0, pv0)), Some((py1, pu1, pv1))) =
25677+ (ref_planes_deferred(ref0, refpix), ref_planes_deferred(ref1, refpix))
25678+ else {
25679+ return;
25680+ };
25532 let mut inter0_y = vec![0i32; side * side];25681 let mut inter0_y = vec![0i32; side * side];
25533 mc::predict_compound_intermediate_kern(25682 mc::predict_compound_intermediate_kern(
25534 &py0.data,25683 &py0.data,
@@ -26161,7 +26310,10 @@ fn decode_inter_block(
26161 // below same as every other non-`LAST_FRAME` reference. lane-av1refs26310 // below same as every other non-`LAST_FRAME` reference. lane-av1refs
26162 // widens this from GOLDEN alone to every reference `read_single_ref`26311 // widens this from GOLDEN alone to every reference `read_single_ref`
26163 // can name.26312 // can name.
26164- let (py_ref, pu_ref, pv_ref) = ref_planes(ref_frame, refpix)?;26313+ // lane-defer8: SIZE here (spec 7.11.3.3's scale factor), pixels
26314+ // inside the prediction closure -- the parse thread of a threaded
26315+ // decode must never wait on a reference picture.
26316+ let (ref_width, _) = ref_dims(ref_frame, refpix)?;
26165 26317
26166 let (mi_row, mi_col) = (rmi, cmi);26318 let (mi_row, mi_col) = (rmi, cmi);
26167 // lane-rect r2: the mv stack must be queried with the block's26319 // lane-rect r2: the mv stack must be queried with the block's
@@ -26497,7 +26649,7 @@ fn decode_inter_block(
26497 // picture whose height does not match this frame's own true26649 // picture whose height does not match this frame's own true
26498 // size", ~14681). Whoever lifts that refusal adds the y term.26650 // size", ~14681). Whoever lifts that refusal adds the y term.
26499 let ref_is_scaled =26651 let ref_is_scaled =
26500- mc::scale_factor(py_ref.width, frame_width) != mc::REF_NO_SCALE;26652+ mc::scale_factor(ref_width, frame_width) != mc::REF_NO_SCALE;
26501 let proj_ok = num_proj_ref(26653 let proj_ok = num_proj_ref(
26502 grid,26654 grid,
26503 mi_row,26655 mi_row,
@@ -26711,7 +26863,7 @@ fn decode_inter_block(
26711 // by name instead of silently sampling a scaled reference wrong26863 // by name instead of silently sampling a scaled reference wrong
26712 // (warp_params/obmc_selected/interintra_mode are all resolved by26864 // (warp_params/obmc_selected/interintra_mode are all resolved by
26713 // this point, every symbol for this block already read).26865 // this point, every symbol for this block already read).
26714- let luma_scale = mc::scale_factor(py_ref.width, frame_width);26866+ let luma_scale = mc::scale_factor(ref_width, frame_width);
26715 if luma_scale != mc::REF_NO_SCALE {26867 if luma_scale != mc::REF_NO_SCALE {
26716 // lane-scaledref r1: libaom `allow_warp`26868 // lane-scaledref r1: libaom `allow_warp`
26717 // (av1/common/reconinter.c:41) suppresses BOTH local and26869 // (av1/common/reconinter.c:41) suppresses BOTH local and
@@ -26737,8 +26889,23 @@ fn decode_inter_block(
26737 // (reconinter_template.inc:75-82); record them for the next 1:426889 // (reconinter_template.inc:75-82); record them for the next 1:4
26738 // strip, which is the only reader.26890 // strip, which is the only reader.
26739 fctx.inter_last_mc.with(|c| c.set(Some((ref_frame, mv, h_filter, v_filter))));26891 fctx.inter_last_mc.with(|c| c.set(Some((ref_frame, mv, h_filter, v_filter))));
26740- let sub8_piece =26892+ // lane-defer8: the sub-8x8 chroma piece's own reference resolved to
26741- strip_chroma.filter(|s| s.has_chroma).and_then(|s| s.prev).is_some();26893+ // a SIZE here and to pixels inside the closure, like the block's own.
26894+ let sub8 = match strip_chroma.filter(|s| s.has_chroma).and_then(|s| s.prev.map(|p| (s.horz, p))) {
26895+ Some((horz, (prev_ref, prev_mv, prev_h, prev_v))) => {
26896+ let (prev_width, _) = ref_dims(prev_ref, refpix)?;
26897+ INTER16_SUB8_PIECE_HITS.with(|c| c.set(c.get() + 1));
26898+ Some((
26899+ horz,
26900+ prev_ref,
26901+ prev_mv,
26902+ prev_h,
26903+ prev_v,
26904+ mc::scale_factor(prev_width, frame_width),
26905+ ))
26906+ }
26907+ None => None,
26908+ };
26742 // lane-wave4: the whole-block prediction (motion compensation +26909 // lane-wave4: the whole-block prediction (motion compensation +
26743 // warp + the interintra blend) as a closure, so it runs where the26910 // warp + the interintra blend) as a closure, so it runs where the
26744 // writes it feeds run. At one reconstruction thread that is right26911 // writes it feeds run. At one reconstruction thread that is right
@@ -26747,11 +26914,42 @@ fn decode_inter_block(
26747 // ([`push_pred`]), which is what takes mc off the parse thread.26914 // ([`push_pred`]), which is what takes mc off the parse thread.
26748 // OBMC and the sub-8x8 chroma piece stay here: both can fail, and26915 // OBMC and the sub-8x8 chroma piece stay here: both can fail, and
26749 // a recorded op has no way to report it.26916 // a recorded op has no way to report it.
26917+ // lane-defer8: OBMC's neighbour walk reads the mode-info grid and
26918+ // the neighbour bands, both of which the parse keeps rewriting --
26919+ // so the walk happens here and the blend inside the closure.
26920+ let obmc = if obmc_selected {
26921+ Some(obmc_plan(
26922+ grid,
26923+ neighbours,
26924+ mi_row,
26925+ mi_col,
26926+ bw4,
26927+ bh4,
26928+ mi_rows as usize,
26929+ mi_cols as usize,
26930+ side,
26931+ write_w,
26932+ write_h,
26933+ chroma_side,
26934+ px,
26935+ py,
26936+ cpx,
26937+ cpy,
26938+ refpix,
26939+ interp_fixed,
26940+ frame_width,
26941+ )?)
26942+ } else {
26943+ None
26944+ };
26750 let build = move |y: &mut PlaneBuf<'static>,26945 let build = move |y: &mut PlaneBuf<'static>,
26751 u: &mut PlaneBuf<'static>,26946 u: &mut PlaneBuf<'static>,
26752 v: &mut PlaneBuf<'static>,26947 v: &mut PlaneBuf<'static>,
26753 fctx: &crate::decode::FrameCtx,26948 fctx: &crate::decode::FrameCtx,
26754 out: &mut [Vec<u16>; 3]| {26949 out: &mut [Vec<u16>; 3]| {
26950+ let Some((py_ref, pu_ref, pv_ref)) = ref_planes_deferred(ref_frame, refpix) else {
26951+ return;
26952+ };
26755 let mut pred_y = refill(std::mem::take(&mut out[0]), side * side);26953 let mut pred_y = refill(std::mem::take(&mut out[0]), side * side);
26756 let mut pred_u = refill(std::mem::take(&mut out[1]), chroma_side * chroma_side);26954 let mut pred_u = refill(std::mem::take(&mut out[1]), chroma_side * chroma_side);
26757 let mut pred_v = refill(std::mem::take(&mut out[2]), chroma_side * chroma_side);26955 let mut pred_v = refill(std::mem::take(&mut out[2]), chroma_side * chroma_side);
@@ -26911,14 +27109,56 @@ fn decode_inter_block(
26911 &mut pred_v, fctx,27109 &mut pred_v, fctx,
26912 );27110 );
26913 }27111 }
27112+ if let Some(plan) = &obmc {
27113+ obmc_run(plan, refpix, &mut pred_y, &mut pred_u, &mut pred_v, fctx);
27114+ }
27115+ // lane-inter16ab r2: libaom `build_inter_predictors_sub8x8`
27116+ // (reconinter_template.inc:87-160). A 4:2:0 chroma block under a
27117+ // 16x4 (4x16) luma pair covers TWO luma blocks, so it is built in
27118+ // `b4_w x b4_h` = 8x2 (2x8) pieces, each from its own strip's
27119+ // mv/ref/filters. The bottom (right) piece is this strip's own mv
27120+ // over its own rows, which the whole-block prediction above
27121+ // already wrote there (MC is position-invariant for a fixed mv),
27122+ // so only the FIRST piece has to be rebuilt -- and only when
27123+ // `is_sub8x8_inter` holds. lane-t900 r28: it scales off the
27124+ // PREVIOUS strip's own reference, not this block's.
27125+ if let Some((horz, prev_ref, prev_mv, prev_h, prev_v, prev_scale)) = sub8 {
27126+ let Some((_, prev_u, prev_v_plane)) = ref_planes_deferred(prev_ref, refpix) else {
27127+ return;
27128+ };
27129+ let (piece_w, piece_h) = if horz { (8usize, 2usize) } else { (2usize, 8usize) };
27130+ for (src, dst) in [(prev_u, &mut pred_u), (prev_v_plane, &mut pred_v)] {
27131+ let mut piece = vec![0u16; piece_w * piece_h];
27132+ mc::predict_maybe_scaled(
27133+ &src.data,
27134+ src.width,
27135+ src.true_width,
27136+ src.true_height,
27137+ mv_to_q4(cpx, prev_mv.1, false),
27138+ mv_to_q4(cpy, prev_mv.0, false),
27139+ prev_scale,
27140+ piece_w,
27141+ piece_h,
27142+ prev_h,
27143+ prev_v,
27144+ &mut piece, fctx,
27145+ );
27146+ for row in 0..piece_h {
27147+ dst[row * chroma_side..row * chroma_side + piece_w]
27148+ .copy_from_slice(&piece[row * piece_w..(row + 1) * piece_w]);
27149+ }
27150+ }
27151+ }
26914 *out = [pred_y, pred_u, pred_v];27152 *out = [pred_y, pred_u, pred_v];
26915 };27153 };
26916 // OBMC and interintra are mutually exclusive (`motion_mode` is27154 // OBMC and interintra are mutually exclusive (`motion_mode` is
26917 // never read for an interintra block), so blending interintra27155 // never read for an interintra block), so blending interintra
26918 // inside `build` and OBMC after it is still the coded order.27156 // inside `build` and OBMC after it is still the coded order.
26919 debug_assert!(!(obmc_selected && interintra_mode.is_some()));27157 debug_assert!(!(obmc_selected && interintra_mode.is_some()));
26920- let deferred = recon_deferred(fctx) && !obmc_selected && !sub8_piece;27158+ // lane-defer8: OBMC and the sub-8x8 piece now live inside `build`,
26921- let (mut pred_y, mut pred_u, mut pred_v): (Vec<u16>, Vec<u16>, Vec<u16>);27159+ // so nothing about this block keeps its prediction on this thread.
27160+ let deferred = recon_deferred(fctx);
27161+ let (pred_y, pred_u, pred_v): (Vec<u16>, Vec<u16>, Vec<u16>);
26922 let (sy, su, sv) = if deferred {27162 let (sy, su, sv) = if deferred {
26923 // The interintra predictor inside `build` reads this block's27163 // The interintra predictor inside `build` reads this block's
26924 // own above/left edges: by the wavefront rule ((r-1, c+1) and27164 // own above/left edges: by the wavefront rule ((r-1, c+1) and
@@ -26940,32 +27180,6 @@ fn decode_inter_block(
26940 build(y, u, v, fctx, &mut built);27180 build(y, u, v, fctx, &mut built);
26941 let [by, bu, bv] = built;27181 let [by, bu, bv] = built;
26942 (pred_y, pred_u, pred_v) = (by, bu, bv);27182 (pred_y, pred_u, pred_v) = (by, bu, bv);
26943- if obmc_selected {
26944- obmc_blend(
26945- grid,
26946- neighbours,
26947- mi_row,
26948- mi_col,
26949- bw4,
26950- bh4,
26951- mi_rows as usize,
26952- mi_cols as usize,
26953- side,
26954- write_w,
26955- write_h,
26956- chroma_side,
26957- px,
26958- py,
26959- cpx,
26960- cpy,
26961- refpix,
26962- interp_fixed,
26963- frame_width,
26964- &mut pred_y,
26965- &mut pred_u,
26966- &mut pred_v, fctx,
26967- )?;
26968- }
26969 27183
26970 // lane-inter16ab r2: libaom `build_inter_predictors_sub8x8`27184 // lane-inter16ab r2: libaom `build_inter_predictors_sub8x8`
26971 // (reconinter_template.inc:87-160). A 4:2:0 chroma block under a27185 // (reconinter_template.inc:87-160). A 4:2:0 chroma block under a
@@ -26978,40 +27192,6 @@ fn decode_inter_block(
26978 // `is_sub8x8_inter` holds, i.e. the previous strip was itself a27192 // `is_sub8x8_inter` holds, i.e. the previous strip was itself a
26979 // single-reference inter block (`prev`), else libaom falls27193 // single-reference inter block (`prev`), else libaom falls
26980 // through to the ordinary whole-block predictor.27194 // through to the ordinary whole-block predictor.
26981- if let Some(s) = strip_chroma.filter(|s| s.has_chroma)
26982- && let Some((prev_ref, prev_mv, prev_h, prev_v)) = s.prev
26983- {
26984- let (piece_w, piece_h) = if s.horz { (8usize, 2usize) } else { (2usize, 8usize) };
26985- // lane-t900 r28 (same-shape sweep of the sub-8x8 scaled-ref
26986- // lift): this piece used to be SKIPPED when the block's
26987- // reference was scaled, which silently left the whole-block
26988- // prediction in place instead of refusing. It scales off the
26989- // PREVIOUS strip's own reference, not this block's.
26990- let (prev_y_plane, prev_u, prev_v_plane) = ref_planes(prev_ref, refpix)?;
26991- let prev_scale = mc::scale_factor(prev_y_plane.width, frame_width);
26992- for (src, dst) in [(prev_u, &mut pred_u), (prev_v_plane, &mut pred_v)] {
26993- let mut piece = vec![0u16; piece_w * piece_h];
26994- mc::predict_maybe_scaled(
26995- &src.data,
26996- src.width,
26997- src.true_width,
26998- src.true_height,
26999- mv_to_q4(cpx, prev_mv.1, false),
27000- mv_to_q4(cpy, prev_mv.0, false),
27001- prev_scale,
27002- piece_w,
27003- piece_h,
27004- prev_h,
27005- prev_v,
27006- &mut piece, fctx,
27007- );
27008- for row in 0..piece_h {
27009- dst[row * chroma_side..row * chroma_side + piece_w]
27010- .copy_from_slice(&piece[row * piece_w..(row + 1) * piece_w]);
27011- }
27012- }
27013- INTER16_SUB8_PIECE_HITS.with(|c| c.set(c.get() + 1));
27014- }
27015 (27195 (
27016 Pred::Inline(&pred_y, side),27196 Pred::Inline(&pred_y, side),
27017 Pred::Inline(&pred_u, chroma_side),27197 Pred::Inline(&pred_u, chroma_side),
@@ -30404,10 +30584,9 @@ fn decode_inter_block8(
30404 COMPOUND8_FILTER_HITS.with(|c| c.set(c.get() + 1));30584 COMPOUND8_FILTER_HITS.with(|c| c.set(c.get() + 1));
30405 }30585 }
30406 30586
30407- let (py0, pu0, pv0) = ref_planes(ref0, refpix)?;30587+ // lane-defer8: both slots' SIZES at parse, pictures in the closure.
30408- let (py1, pu1, pv1) = ref_planes(ref1, refpix)?;30588+ let scale0 = mc::scale_factor(ref_dims(ref0, refpix)?.0, frame_width);
30409- let scale0 = mc::scale_factor(py0.width, frame_width);30589+ let scale1 = mc::scale_factor(ref_dims(ref1, refpix)?.0, frame_width);
30410- let scale1 = mc::scale_factor(py1.width, frame_width);
30411 if scale0 != mc::REF_NO_SCALE || scale1 != mc::REF_NO_SCALE {30590 if scale0 != mc::REF_NO_SCALE || scale1 != mc::REF_NO_SCALE {
30412 SCALED_COMPOUND_HITS.with(|c| c.set(c.get() + 1));30591 SCALED_COMPOUND_HITS.with(|c| c.set(c.get() + 1));
30413 SCALED_BLOCK8_HITS.with(|c| c.set(c.get() + 1));30592 SCALED_BLOCK8_HITS.with(|c| c.set(c.get() + 1));
@@ -30458,10 +30637,9 @@ fn decode_inter_block8(
30458 // lane-t900 r28: same per-slot `allow_warp` scale bail-out as30637 // lane-t900 r28: same per-slot `allow_warp` scale bail-out as
30459 // the 16x16-and-bigger compound path above.30638 // the 16x16-and-bigger compound path above.
30460 let leaf_ref_unscaled = |rf: i8| {30639 let leaf_ref_unscaled = |rf: i8| {
30461- ref_planes(rf, refpix)30640+ refpix
30462- .is_ok_and(|(py, _, _)| {30641+ .dims(rf)
30463- mc::scale_factor(py.width, frame_width) == mc::REF_NO_SCALE30642+ .is_some_and(|(w, _)| mc::scale_factor(w, frame_width) == mc::REF_NO_SCALE)
30464- })
30465 };30643 };
30466 let warp0_c =30644 let warp0_c =
30467 leaf_compound_warp(ref0, is_global_mv0_c).filter(|_| leaf_ref_unscaled(ref0));30645 leaf_compound_warp(ref0, is_global_mv0_c).filter(|_| leaf_ref_unscaled(ref0));
@@ -30491,6 +30669,19 @@ fn decode_inter_block8(
30491 );30669 );
30492 mode_for_tx = 0;30670 mode_for_tx = 0;
30493 30671
30672+ // lane-defer8: this leaf's whole prediction as a closure, so it runs
30673+ // where its writes run -- on a recon worker at more than one
30674+ // reconstruction thread, exactly like [`decode_inter_block`]'s.
30675+ let build = move |_y: &mut PlaneBuf<'static>,
30676+ _u: &mut PlaneBuf<'static>,
30677+ _v: &mut PlaneBuf<'static>,
30678+ fctx: &crate::decode::FrameCtx,
30679+ out: &mut [Vec<u16>; 3]| {
30680+ let (Some((py0, pu0, pv0)), Some((py1, pu1, pv1))) =
30681+ (ref_planes_deferred(ref0, refpix), ref_planes_deferred(ref1, refpix))
30682+ else {
30683+ return;
30684+ };
30494 let mut inter0_y = vec![0i32; SIDE * SIDE];30685 let mut inter0_y = vec![0i32; SIDE * SIDE];
30495 mc::predict_compound_intermediate(30686 mc::predict_compound_intermediate(
30496 &py0.data,30687 &py0.data,
@@ -30535,7 +30726,7 @@ fn decode_inter_block8(
30535 SIDE as i32, SIDE as i32, 0, 0, fctx,30726 SIDE as i32, SIDE as i32, 0, 0, fctx,
30536 );30727 );
30537 }30728 }
30538- let mut pred_y = vec![0u16; SIDE * SIDE];30729+ let mut pred_y = refill(std::mem::take(&mut out[0]), SIDE * SIDE);
30539 let mut diffwtd_mask_y;30730 let mut diffwtd_mask_y;
30540 let mask_y: Option<&[u8]> = if let Some(mask_type) = diffwtd_mask_type {30731 let mask_y: Option<&[u8]> = if let Some(mask_type) = diffwtd_mask_type {
30541 diffwtd_mask_y = vec![0u8; SIDE * SIDE];30732 diffwtd_mask_y = vec![0u8; SIDE * SIDE];
@@ -30583,7 +30774,7 @@ fn decode_inter_block8(
30583 v_filter,30774 v_filter,
30584 &mut inter1_u,30775 &mut inter1_u,
30585 );30776 );
30586- let mut pred_u = vec![0u16; CHROMA_SIDE * CHROMA_SIDE];30777+ let mut pred_u = refill(std::mem::take(&mut out[1]), CHROMA_SIDE * CHROMA_SIDE);
30587 if let Some(mask_y) = mask_y {30778 if let Some(mask_y) = mask_y {
30588 mc::blend_masked_compound(30779 mc::blend_masked_compound(
30589 &inter0_u,30780 &inter0_u,
@@ -30629,7 +30820,7 @@ fn decode_inter_block8(
30629 v_filter,30820 v_filter,
30630 &mut inter1_v,30821 &mut inter1_v,
30631 );30822 );
30632- let mut pred_v = vec![0u16; CHROMA_SIDE * CHROMA_SIDE];30823+ let mut pred_v = refill(std::mem::take(&mut out[2]), CHROMA_SIDE * CHROMA_SIDE);
30633 if let Some(mask_y) = mask_y {30824 if let Some(mask_y) = mask_y {
30634 mc::blend_masked_compound(30825 mc::blend_masked_compound(
30635 &inter0_v,30826 &inter0_v,
@@ -30645,6 +30836,28 @@ fn decode_inter_block8(
30645 mc::combine_compound(&inter0_v, &inter1_v, fwd_offset, bck_offset, &mut pred_v, fctx);30836 mc::combine_compound(&inter0_v, &inter1_v, fwd_offset, bck_offset, &mut pred_v, fctx);
30646 }30837 }
30647 30838
30839+ *out = [pred_y, pred_u, pred_v];
30840+ };
30841+ let deferred = recon_deferred(fctx);
30842+ let (pred_y, pred_u, pred_v): (Vec<u16>, Vec<u16>, Vec<u16>);
30843+ let (sy, su, sv) = if deferred {
30844+ push_pred(fctx, build);
30845+ (
30846+ Pred::Cur { plane: 0, stride: SIDE, off: 0 },
30847+ Pred::Cur { plane: 1, stride: CHROMA_SIDE, off: 0 },
30848+ Pred::Cur { plane: 2, stride: CHROMA_SIDE, off: 0 },
30849+ )
30850+ } else {
30851+ let mut built: [Vec<u16>; 3] = Default::default();
30852+ build(y, u, v, fctx, &mut built);
30853+ let [by, bu, bv] = built;
30854+ (pred_y, pred_u, pred_v) = (by, bu, bv);
30855+ (
30856+ Pred::Inline(&pred_y, SIDE),
30857+ Pred::Inline(&pred_u, CHROMA_SIDE),
30858+ Pred::Inline(&pred_v, CHROMA_SIDE),
30859+ )
30860+ };
30648 split8 = read_block_tx_size(30861 split8 = read_block_tx_size(
30649 dec,30862 dec,
30650 cdfs,30863 cdfs,
@@ -30658,19 +30871,19 @@ fn decode_inter_block8(
30658 .130871 .1
30659 .is_some();30872 .is_some();
30660 if skip {30873 if skip {
30661- push_mc(0, px, py, SIDE, Pred::dense(&pred_y), &ZERO_RESIDUAL[..SIDE * SIDE], fctx);30874+ push_mc(0, px, py, SIDE, sy, &ZERO_RESIDUAL[..SIDE * SIDE], fctx);
30662 push_mc(1, 30875 push_mc(1,
30663 cpx,30876 cpx,
30664 cpy,30877 cpy,
30665 CHROMA_SIDE,30878 CHROMA_SIDE,
30666- Pred::dense(&pred_u),30879+ su,
30667 &ZERO_RESIDUAL[..CHROMA_SIDE * CHROMA_SIDE], fctx,30880 &ZERO_RESIDUAL[..CHROMA_SIDE * CHROMA_SIDE], fctx,
30668 );30881 );
30669 push_mc(2, 30882 push_mc(2,
30670 cpx,30883 cpx,
30671 cpy,30884 cpy,
30672 CHROMA_SIDE,30885 CHROMA_SIDE,
30673- Pred::dense(&pred_v),30886+ sv,
30674 &ZERO_RESIDUAL[..CHROMA_SIDE * CHROMA_SIDE], fctx,30887 &ZERO_RESIDUAL[..CHROMA_SIDE * CHROMA_SIDE], fctx,
30675 );30888 );
30676 luma_grid = Grid::Zero(SIDE * SIDE);30889 luma_grid = Grid::Zero(SIDE * SIDE);
@@ -30686,7 +30899,7 @@ fn decode_inter_block8(
30686 y,30899 y,
30687 px,30900 px,
30688 py,30901 py,
30689- Pred::dense(&pred_y),30902+ sy,
30690 mode_for_tx,30903 mode_for_tx,
30691 base_q_idx,30904 base_q_idx,
30692 scan8,30905 scan8,
@@ -30708,7 +30921,7 @@ fn decode_inter_block8(
30708 cpy,30921 cpy,
30709 CHROMA_SIDE,30922 CHROMA_SIDE,
30710 base_q_idx,30923 base_q_idx,
30711- Pred::dense(&pred_u),30924+ su,
30712 Some(luma_tx_type),30925 Some(luma_tx_type),
30713 None, fctx,30926 None, fctx,
30714 )?30927 )?
@@ -30726,7 +30939,7 @@ fn decode_inter_block8(
30726 cpy,30939 cpy,
30727 CHROMA_SIDE,30940 CHROMA_SIDE,
30728 base_q_idx,30941 base_q_idx,
30729- Pred::dense(&pred_v),30942+ sv,
30730 Some(luma_tx_type),30943 Some(luma_tx_type),
30731 None, fctx,30944 None, fctx,
30732 )?30945 )?
@@ -30833,7 +31046,9 @@ fn decode_inter_block8(
30833 neighbours.left_ref1[rmi],31046 neighbours.left_ref1[rmi],
30834 );31047 );
30835 leaf_refs = (ref_frame, None);31048 leaf_refs = (ref_frame, None);
30836- let (sref_y, sref_u, sref_v) = ref_planes(ref_frame, refpix)?;31049+ // lane-defer8: this leaf's reference SIZE at parse, its pictures
31050+ // inside the prediction closure below.
31051+ let (ref_width, _) = ref_dims(ref_frame, refpix)?;
30837 31052
30838 let (mi_row, mi_col) = leaf_mi;31053 let (mi_row, mi_col) = leaf_mi;
30839 // lane-inter8 r2: the frame's temporal mv candidates, keyed on THIS31054 // lane-inter8 r2: the frame's temporal mv candidates, keyed on THIS
@@ -31009,7 +31224,7 @@ fn decode_inter_block8(
31009 // desynced every warped-motion superres stream at its first31224 // desynced every warped-motion superres stream at its first
31010 // eligible 8x8 leaf).31225 // eligible 8x8 leaf).
31011 let ref_is_scaled =31226 let ref_is_scaled =
31012- mc::scale_factor(sref_y.width, frame_width) != mc::REF_NO_SCALE;31227+ mc::scale_factor(ref_width, frame_width) != mc::REF_NO_SCALE;
31013 let warp_eligible =31228 let warp_eligible =
31014 allow_warped_motion && !ref_is_scaled && !force_integer_mv && proj_ok;31229 allow_warped_motion && !ref_is_scaled && !force_integer_mv && proj_ok;
31015 if allow_warped_motion && proj_ok && ref_is_scaled {31230 if allow_warped_motion && proj_ok && ref_is_scaled {
@@ -31171,13 +31386,49 @@ fn decode_inter_block8(
31171 // lane-scaledref r1: this leaf's own prediction is always `Regular`31386 // lane-scaledref r1: this leaf's own prediction is always `Regular`
31172 // (documented corner-cut above); under a scaled reference the same31387 // (documented corner-cut above); under a scaled reference the same
31173 // fixed kernel runs through spec 7.11.3.3's scaled walk instead.31388 // fixed kernel runs through spec 7.11.3.3's scaled walk instead.
31174- let luma_scale = mc::scale_factor(sref_y.width, frame_width);31389+ let luma_scale = mc::scale_factor(ref_width, frame_width);
31175 if luma_scale != mc::REF_NO_SCALE {31390 if luma_scale != mc::REF_NO_SCALE {
31176 SCALED_BLOCK8_HITS.with(|c| c.set(c.get() + 1));31391 SCALED_BLOCK8_HITS.with(|c| c.set(c.get() + 1));
31177 }31392 }
31178- let mut pred_y = vec![0u16; SIDE * SIDE];31393+ let obmc = if obmc_selected {
31179- let mut pred_u = vec![0u16; CHROMA_SIDE * CHROMA_SIDE];31394+ Some(obmc_plan(
31180- let mut pred_v = vec![0u16; CHROMA_SIDE * CHROMA_SIDE];31395+ grid,
31396+ neighbours,
31397+ mi_row,
31398+ mi_col,
31399+ 2,
31400+ 2,
31401+ mi_rows as usize,
31402+ mi_cols as usize,
31403+ SIDE,
31404+ SIDE,
31405+ SIDE,
31406+ CHROMA_SIDE,
31407+ px,
31408+ py,
31409+ cpx,
31410+ cpy,
31411+ refpix,
31412+ interp_fixed,
31413+ frame_width,
31414+ )?)
31415+ } else {
31416+ None
31417+ };
31418+ // lane-defer8: this leaf's whole prediction as a closure, so it runs
31419+ // where its writes run -- on a recon worker at more than one
31420+ // reconstruction thread, exactly like [`decode_inter_block`]'s.
31421+ let build = move |y: &mut PlaneBuf<'static>,
31422+ u: &mut PlaneBuf<'static>,
31423+ v: &mut PlaneBuf<'static>,
31424+ fctx: &crate::decode::FrameCtx,
31425+ out: &mut [Vec<u16>; 3]| {
31426+ let Some((sref_y, sref_u, sref_v)) = ref_planes_deferred(ref_frame, refpix) else {
31427+ return;
31428+ };
31429+ let mut pred_y = refill(std::mem::take(&mut out[0]), SIDE * SIDE);
31430+ let mut pred_u = refill(std::mem::take(&mut out[1]), CHROMA_SIDE * CHROMA_SIDE);
31431+ let mut pred_v = refill(std::mem::take(&mut out[2]), CHROMA_SIDE * CHROMA_SIDE);
31181 // Merge of lane-gmaffine (this leaf's own switchable filters) with31432 // Merge of lane-gmaffine (this leaf's own switchable filters) with
31182 // lane-scaledref (spec 7.11.3.3's scaled walk): same kernels either31433 // lane-scaledref (spec 7.11.3.3's scaled walk): same kernels either
31183 // way, only the sample walk differs.31434 // way, only the sample walk differs.
@@ -31250,37 +31501,13 @@ fn decode_inter_block8(
31250 }31501 }
31251 }31502 }
31252 31503
31253- if obmc_selected {31504+ if let Some(plan) = &obmc {
31254- obmc_blend(31505+ obmc_run(plan, refpix, &mut pred_y, &mut pred_u, &mut pred_v, fctx);
31255- grid,
31256- neighbours,
31257- mi_row,
31258- mi_col,
31259- 2,
31260- 2,
31261- mi_rows as usize,
31262- mi_cols as usize,
31263- SIDE,
31264- SIDE,
31265- SIDE,
31266- CHROMA_SIDE,
31267- px,
31268- py,
31269- cpx,
31270- cpy,
31271- refpix,
31272- interp_fixed,
31273- frame_width,
31274- &mut pred_y,
31275- &mut pred_u,
31276- &mut pred_v, fctx,
31277- )?;
31278 }31506 }
31279 31507
31280 // Non-wedge interintra blend, mutually exclusive with OBMC (the31508 // Non-wedge interintra blend, mutually exclusive with OBMC (the
31281 // motion_mode symbol is not read for an interintra block).31509 // motion_mode symbol is not read for an interintra block).
31282 if let Some(ii) = interintra_mode {31510 if let Some(ii) = interintra_mode {
31283- flush_recon(fctx, y, u, v);
31284 interintra_blend(y, px, py, SIDE, SIDE, SIDE, ii, wedge_mask, &mut pred_y, fctx);31511 interintra_blend(y, px, py, SIDE, SIDE, SIDE, ii, wedge_mask, &mut pred_y, fctx);
31285 interintra_blend(31512 interintra_blend(
31286 u, cpx, cpy, CHROMA_SIDE, CHROMA_SIDE, CHROMA_SIDE, ii, wedge_mask, &mut pred_u, fctx,31513 u, cpx, cpy, CHROMA_SIDE, CHROMA_SIDE, CHROMA_SIDE, ii, wedge_mask, &mut pred_u, fctx,
@@ -31290,6 +31517,34 @@ fn decode_inter_block8(
31290 );31517 );
31291 }31518 }
31292 31519
31520+ *out = [pred_y, pred_u, pred_v];
31521+ };
31522+ let deferred = recon_deferred(fctx);
31523+ let (pred_y, pred_u, pred_v): (Vec<u16>, Vec<u16>, Vec<u16>);
31524+ let (sy, su, sv) = if deferred {
31525+ push_pred(fctx, build);
31526+ (
31527+ Pred::Cur { plane: 0, stride: SIDE, off: 0 },
31528+ Pred::Cur { plane: 1, stride: CHROMA_SIDE, off: 0 },
31529+ Pred::Cur { plane: 2, stride: CHROMA_SIDE, off: 0 },
31530+ )
31531+ } else {
31532+ // The interintra predictor reads this block's own above/left
31533+ // edges: deferred, the wavefront rule has them written by the time
31534+ // the worker runs; inline, the queue has to drain first.
31535+ if interintra_mode.is_some() {
31536+ flush_recon(fctx, y, u, v);
31537+ }
31538+ let mut built: [Vec<u16>; 3] = Default::default();
31539+ build(y, u, v, fctx, &mut built);
31540+ let [by, bu, bv] = built;
31541+ (pred_y, pred_u, pred_v) = (by, bu, bv);
31542+ (
31543+ Pred::Inline(&pred_y, SIDE),
31544+ Pred::Inline(&pred_u, CHROMA_SIDE),
31545+ Pred::Inline(&pred_v, CHROMA_SIDE),
31546+ )
31547+ };
31293 split8 = read_block_tx_size(31548 split8 = read_block_tx_size(
31294 dec,31549 dec,
31295 cdfs,31550 cdfs,
@@ -31303,19 +31558,19 @@ fn decode_inter_block8(
31303 .131558 .1
31304 .is_some();31559 .is_some();
31305 if skip {31560 if skip {
31306- push_mc(0, px, py, SIDE, Pred::dense(&pred_y), &ZERO_RESIDUAL[..SIDE * SIDE], fctx);31561+ push_mc(0, px, py, SIDE, sy, &ZERO_RESIDUAL[..SIDE * SIDE], fctx);
31307 push_mc(1, 31562 push_mc(1,
31308 cpx,31563 cpx,
31309 cpy,31564 cpy,
31310 CHROMA_SIDE,31565 CHROMA_SIDE,
31311- Pred::dense(&pred_u),31566+ su,
31312 &ZERO_RESIDUAL[..CHROMA_SIDE * CHROMA_SIDE], fctx,31567 &ZERO_RESIDUAL[..CHROMA_SIDE * CHROMA_SIDE], fctx,
31313 );31568 );
31314 push_mc(2, 31569 push_mc(2,
31315 cpx,31570 cpx,
31316 cpy,31571 cpy,
31317 CHROMA_SIDE,31572 CHROMA_SIDE,
31318- Pred::dense(&pred_v),31573+ sv,
31319 &ZERO_RESIDUAL[..CHROMA_SIDE * CHROMA_SIDE], fctx,31574 &ZERO_RESIDUAL[..CHROMA_SIDE * CHROMA_SIDE], fctx,
31320 );31575 );
31321 luma_grid = Grid::Zero(SIDE * SIDE);31576 luma_grid = Grid::Zero(SIDE * SIDE);
@@ -31331,7 +31586,7 @@ fn decode_inter_block8(
31331 y,31586 y,
31332 px,31587 px,
31333 py,31588 py,
31334- Pred::dense(&pred_y),31589+ sy,
31335 mode_for_tx,31590 mode_for_tx,
31336 base_q_idx,31591 base_q_idx,
31337 scan8,31592 scan8,
@@ -31353,7 +31608,7 @@ fn decode_inter_block8(
31353 cpy,31608 cpy,
31354 CHROMA_SIDE,31609 CHROMA_SIDE,
31355 base_q_idx,31610 base_q_idx,
31356- Pred::dense(&pred_u),31611+ su,
31357 Some(luma_tx_type),31612 Some(luma_tx_type),
31358 None, fctx,31613 None, fctx,
31359 )?31614 )?
@@ -31371,7 +31626,7 @@ fn decode_inter_block8(
31371 cpy,31626 cpy,
31372 CHROMA_SIDE,31627 CHROMA_SIDE,
31373 base_q_idx,31628 base_q_idx,
31374- Pred::dense(&pred_v),31629+ sv,
31375 Some(luma_tx_type),31630 Some(luma_tx_type),
31376 None, fctx,31631 None, fctx,
31377 )?31632 )?
@@ -34721,6 +34976,9 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
34721 result_cdfs = cdfs;34976 result_cdfs = cdfs;
34722 }34977 }
34723 }34978 }
34979+ // lane-defer8: every tile's recon workers are joined by its own
34980+ // `WaveGuard`, so a deferred prediction's parked failure is complete here.
34981+ refpix.take_err()?;
34724 crate::timeline::recon_done();34982 crate::timeline::recon_done();
34725 // lane-twostage: the motion field is built from the mode-info grid alone34983 // lane-twostage: the motion field is built from the mode-info grid alone
34726 // (no pixel), so it moves up here with the CDFs -- everything a34984 // (no pixel), so it moves up here with the CDFs -- everything a