forge
Explore
Log in

Don't you dare go Hollow

A single-reference inter block predicts on the worker that reconstructs it

Browse files at this commit

4a7d65a9d8226eecd60f97b19583499a9fee52f5Ahmet Kaan GümüşParent: 8aa7db1
  • perf
    • a single-reference inter block predicts on the worker that reconstructs it
Show full message
perf(av1): a single-reference inter block predicts on the worker that reconstructs it

lane-wave4: the whole-block prediction of `decode_inter_block`'s
single-reference arm (motion compensation + warp + the interintra blend) is
now a closure instead of a buffer. At one reconstruction thread the parse
thread runs it at the same point as before; at EC_AV1_RECON_THREADS > 1 it
is pushed as a `ReconOp::Pred` and runs on the wavefront worker, whose
transform units then read their windows out of it -- so mc no longer runs on
the parsing thread there. The interintra blend goes with it, which retires
that arm's `flush_recon` barrier: the wavefront rule already guarantees the
block's own edges. OBMC and the sub-8x8 chroma piece still build inline
(both can fail, and a recorded op cannot report it).

Also fixes the inline path stage 1 broke: a window handed over at the
block's stride was reconstructed against a dense residual.
crates/ec-av1/src/decode.rsmodified+103 -47
@@ -2794,7 +2794,25 @@ fn push_mc_rect_tx(
27942794 }
27952795 };
27962796 if fctx.recon_planes.with(std::cell::Cell::get).is_some() {
2797- inline_mc(plane, x, y, stride, w, h, prediction, &tx.run(grid), fctx);
2797+ // `reconstruct_mc_rect` reads the prediction and the residual at ONE
2798+ // stride, so a prediction handed over at the block's stride (a var-tx
2799+ // unit's window, lane-wave4) has to be densified for a dense residual
2800+ // -- which is exactly what the recorded path below does.
2801+ let residual = tx.run(grid);
2802+ let res_stride = if tx.stride == 0 { w } else { tx.stride };
2803+ let window;
2804+ let prediction = if stride == res_stride {
2805+ prediction
2806+ } else {
2807+ debug_assert_eq!(res_stride, w);
2808+ let mut win = Vec::with_capacity(w * h);
2809+ for row in 0..h {
2810+ win.extend_from_slice(&prediction[row * stride..][..w]);
2811+ }
2812+ window = win;
2813+ &window[..]
2814+ };
2815+ inline_mc(plane, x, y, res_stride, w, h, prediction, &residual, fctx);
27982816 return;
27992817 }
28002818 // `reconstruct_mc_rect` reads exactly rows `0..h`, columns `0..w` of the
@@ -25216,6 +25234,21 @@ fn decode_inter_block(
2521625234 // (reconinter_template.inc:75-82); record them for the next 1:4
2521725235 // strip, which is the only reader.
2521825236 fctx.inter_last_mc.with(|c| c.set(Some((ref_frame, mv, h_filter, v_filter))));
25237+ let sub8_piece =
25238+ strip_chroma.filter(|s| s.has_chroma).and_then(|s| s.prev).is_some();
25239+ // lane-wave4: the whole-block prediction (motion compensation +
25240+ // warp + the interintra blend) as a closure, so it runs where the
25241+ // writes it feeds run. At one reconstruction thread that is right
25242+ // here on the parsing thread, exactly as before; on the wavefront
25243+ // it travels with the block's recorded ops and runs on the worker
25244+ // ([`push_pred`]), which is what takes mc off the parse thread.
25245+ // OBMC and the sub-8x8 chroma piece stay here: both can fail, and
25246+ // a recorded op has no way to report it.
25247+ let build = move |y: &mut PlaneBuf<'static>,
25248+ u: &mut PlaneBuf<'static>,
25249+ v: &mut PlaneBuf<'static>,
25250+ fctx: &crate::decode::FrameCtx|
25251+ -> [Vec<u16>; 3] {
2521925252 let mut pred_y = vec![0u16; side * side];
2522025253 let mut pred_u = vec![0u16; chroma_side * chroma_side];
2522125254 let mut pred_v = vec![0u16; chroma_side * chroma_side];
@@ -25357,7 +25390,51 @@ fn decode_inter_block(
2535725390 );
2535825391 }
2535925392 }
25360-
25393+ // Mutually exclusive with warp/OBMC (motion_mode is not read for
25394+ // an interintra block): blend the intra predictor over the MC
25395+ // result, all planes (reconinter.c av1_build_interintra_predictor
25396+ // plane loop).
25397+ if let Some(ii) = interintra_mode {
25398+ if write_w != write_h {
25399+ INTERINTRA_RECT_HITS.with(|c| c.set(c.get() + 1));
25400+ }
25401+ interintra_blend(y, px, py, write_w, write_h, side, ii, wedge_mask, &mut pred_y, fctx);
25402+ interintra_blend(
25403+ u, cpx, cpy, write_chroma_w, write_chroma_h, chroma_side, ii, wedge_mask,
25404+ &mut pred_u, fctx,
25405+ );
25406+ interintra_blend(
25407+ v, cpx, cpy, write_chroma_w, write_chroma_h, chroma_side, ii, wedge_mask,
25408+ &mut pred_v, fctx,
25409+ );
25410+ }
25411+ [pred_y, pred_u, pred_v]
25412+ };
25413+ // OBMC and interintra are mutually exclusive (`motion_mode` is
25414+ // never read for an interintra block), so blending interintra
25415+ // inside `build` and OBMC after it is still the coded order.
25416+ debug_assert!(!(obmc_selected && interintra_mode.is_some()));
25417+ let deferred = recon_deferred(fctx) && !obmc_selected && !sub8_piece;
25418+ let (mut pred_y, mut pred_u, mut pred_v): (Vec<u16>, Vec<u16>, Vec<u16>);
25419+ let (sy, su, sv) = if deferred {
25420+ // The interintra predictor inside `build` reads this block's
25421+ // own above/left edges: by the wavefront rule ((r-1, c+1) and
25422+ // (r, c-1) complete) and this superblock's own ops replaying
25423+ // in push order ahead of it, they are written by the time the
25424+ // worker runs it -- which retires the `flush_recon` barrier
25425+ // this arm used to take for interintra.
25426+ push_pred(fctx, build);
25427+ (
25428+ Pred::Cur { plane: 0, stride: side, off: 0 },
25429+ Pred::Cur { plane: 1, stride: chroma_side, off: 0 },
25430+ Pred::Cur { plane: 2, stride: chroma_side, off: 0 },
25431+ )
25432+ } else {
25433+ if interintra_mode.is_some() {
25434+ flush_recon(fctx, y, u, v);
25435+ }
25436+ let [by, bu, bv] = build(y, u, v, fctx);
25437+ (pred_y, pred_u, pred_v) = (by, bu, bv);
2536125438 if obmc_selected {
2536225439 obmc_blend(
2536325440 grid,
@@ -25388,26 +25465,6 @@ fn decode_inter_block(
2538825465 )?;
2538925466 }
2539025467
25391- // Mutually exclusive with warp/OBMC (motion_mode is not read for
25392- // an interintra block): blend the intra predictor over the MC
25393- // result, all planes (reconinter.c av1_build_interintra_predictor
25394- // plane loop).
25395- if let Some(ii) = interintra_mode {
25396- flush_recon(fctx, y, u, v);
25397- if write_w != write_h {
25398- INTERINTRA_RECT_HITS.with(|c| c.set(c.get() + 1));
25399- }
25400- interintra_blend(y, px, py, write_w, write_h, side, ii, wedge_mask, &mut pred_y, fctx);
25401- interintra_blend(
25402- u, cpx, cpy, write_chroma_w, write_chroma_h, chroma_side, ii, wedge_mask,
25403- &mut pred_u, fctx,
25404- );
25405- interintra_blend(
25406- v, cpx, cpy, write_chroma_w, write_chroma_h, chroma_side, ii, wedge_mask,
25407- &mut pred_v, fctx,
25408- );
25409- }
25410-
2541125468 // lane-inter16ab r2: libaom `build_inter_predictors_sub8x8`
2541225469 // (reconinter_template.inc:87-160). A 4:2:0 chroma block under a
2541325470 // 16x4 (4x16) luma pair covers TWO luma blocks, so it is built in
@@ -25453,6 +25510,13 @@ fn decode_inter_block(
2545325510 }
2545425511 INTER16_SUB8_PIECE_HITS.with(|c| c.set(c.get() + 1));
2545525512 }
25513+ (
25514+ Pred::Inline(&pred_y, side),
25515+ Pred::Inline(&pred_u, chroma_side),
25516+ Pred::Inline(&pred_v, chroma_side),
25517+ )
25518+ };
25519+
2545625520
2545725521 // lane-inter4 r2: a rectangular strip's transform tree starts from
2545825522 // its own rect `max_txsize_rect_lookup` entry, not a square one.
@@ -25487,7 +25551,7 @@ fn decode_inter_block(
2548725551 side,
2548825552 write_w,
2548925553 write_h,
25490- Pred::dense(&pred_y),
25554+ sy,
2549125555 &vec![0i32; side * side], fctx,
2549225556 );
2549325557 if has_chroma {
@@ -25497,7 +25561,7 @@ fn decode_inter_block(
2549725561 chroma_side,
2549825562 write_chroma_w,
2549925563 write_chroma_h,
25500- Pred::dense(&pred_u),
25564+ su,
2550125565 &vec![0i32; chroma_side * chroma_side], fctx,
2550225566 );
2550325567 push_mc_rect(2,
@@ -25506,7 +25570,7 @@ fn decode_inter_block(
2550625570 chroma_side,
2550725571 write_chroma_w,
2550825572 write_chroma_h,
25509- Pred::dense(&pred_v),
25573+ sv,
2551025574 &vec![0i32; chroma_side * chroma_side], fctx,
2551125575 );
2551225576 }
@@ -25553,11 +25617,7 @@ fn decode_inter_block(
2555325617 let (tu_px, tu_py) = (px + col * MI, py + row * MI);
2555425618 let (tu_grid, tu_tx_type) = if tw == th {
2555525619 let tx_px = tw;
25556- let mut tu_pred = Vec::with_capacity(tx_px * tx_px);
25557- for rr in 0..tx_px {
25558- let start = (row * MI + rr) * side + col * MI;
25559- tu_pred.extend_from_slice(&pred_y[start..start + tx_px]);
25560- }
25620+ let tu_pred = sy.offset(row * MI * side + col * MI);
2556125621 let scan = default_scan(tx_px.min(32));
2556225622 let tu_skip_ctx = neighbours.luma_skip_ctx(tu_mi, tx_px / MI);
2556325623 read_inter_plane(
@@ -25573,7 +25633,7 @@ fn decode_inter_block(
2557325633 tu_py,
2557425634 tx_px,
2557525635 base_q_idx,
25576- Pred::dense(&tu_pred),
25636+ tu_pred,
2557725637 None,
2557825638 Some(tu_skip_ctx), fctx,
2557925639 )?
@@ -25601,7 +25661,7 @@ fn decode_inter_block(
2560125661 y,
2560225662 tu_px,
2560325663 tu_py,
25604- Pred::dense(&pred_y[start..]),
25664+ sy.offset(start),
2560525665 None,
2560625666 Some(tu_skip_ctx), fctx,
2560725667 )?
@@ -25635,16 +25695,12 @@ fn decode_inter_block(
2563525695 let cu_scan = default_scan(cu_tx);
2563625696 for plane_idx in 1..3 {
2563725697 let (src, buf) = if plane_idx == 1 {
25638- (&pred_u, &mut *u)
25698+ (su, &mut *u)
2563925699 } else {
25640- (&pred_v, &mut *v)
25700+ (sv, &mut *v)
2564125701 };
25642- let mut cu_pred = Vec::with_capacity(cu_tx * cu_tx);
25643- for rr in 0..cu_tx {
25644- let start =
25645- (cr * cu_tx + rr) * chroma_side + cc * cu_tx;
25646- cu_pred.extend_from_slice(&src[start..start + cu_tx]);
25647- }
25702+ let cu_pred =
25703+ src.offset(cr * cu_tx * chroma_side + cc * cu_tx);
2564825704 let cu_grid = read_inter_plane(
2564925705 dec,
2565025706 cdfs,
@@ -25658,7 +25714,7 @@ fn decode_inter_block(
2565825714 cu_y,
2565925715 cu_tx,
2566025716 base_q_idx,
25661- Pred::dense(&cu_pred),
25717+ cu_pred,
2566225718 Some(first_tx_type),
2566325719 Some(3), fctx,
2566425720 )?
@@ -25705,7 +25761,7 @@ fn decode_inter_block(
2570525761 y,
2570625762 px,
2570725763 py,
25708- Pred::dense(&pred_y),
25764+ sy,
2570925765 None,
2571025766 None, fctx,
2571125767 )?;
@@ -25725,7 +25781,7 @@ fn decode_inter_block(
2572525781 py,
2572625782 side,
2572725783 base_q_idx,
25728- Pred::dense(&pred_y),
25784+ sy,
2572925785 None,
2573025786 None, fctx,
2573125787 )?;
@@ -25764,7 +25820,7 @@ fn decode_inter_block(
2576425820 u,
2576525821 cpx,
2576625822 cpy,
25767- Pred::dense(&pred_u),
25823+ su,
2576825824 Some(luma_tx_type),
2576925825 None, fctx,
2577025826 )?
@@ -25786,7 +25842,7 @@ fn decode_inter_block(
2578625842 v,
2578725843 cpx,
2578825844 cpy,
25789- Pred::dense(&pred_v),
25845+ sv,
2579025846 Some(luma_tx_type),
2579125847 None, fctx,
2579225848 )?
@@ -25809,7 +25865,7 @@ fn decode_inter_block(
2580925865 cpy,
2581025866 chroma_side,
2581125867 base_q_idx,
25812- Pred::dense(&pred_u),
25868+ su,
2581325869 Some(luma_tx_type),
2581425870 None, fctx,
2581525871 )?
@@ -25827,7 +25883,7 @@ fn decode_inter_block(
2582725883 cpy,
2582825884 chroma_side,
2582925885 base_q_idx,
25830- Pred::dense(&pred_v),
25886+ sv,
2583125887 Some(luma_tx_type),
2583225888 None, fctx,
2583325889 )?