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(
2794 }2794 }
2795 };2795 };
2796 if fctx.recon_planes.with(std::cell::Cell::get).is_some() {2796 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);
2798 return;2816 return;
2799 }2817 }
2800 // `reconstruct_mc_rect` reads exactly rows `0..h`, columns `0..w` of the2818 // `reconstruct_mc_rect` reads exactly rows `0..h`, columns `0..w` of the
@@ -25216,6 +25234,21 @@ fn decode_inter_block(
25216 // (reconinter_template.inc:75-82); record them for the next 1:425234 // (reconinter_template.inc:75-82); record them for the next 1:4
25217 // strip, which is the only reader.25235 // strip, which is the only reader.
25218 fctx.inter_last_mc.with(|c| c.set(Some((ref_frame, mv, h_filter, v_filter))));25236 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] {
25219 let mut pred_y = vec![0u16; side * side];25252 let mut pred_y = vec![0u16; side * side];
25220 let mut pred_u = vec![0u16; chroma_side * chroma_side];25253 let mut pred_u = vec![0u16; chroma_side * chroma_side];
25221 let mut pred_v = vec![0u16; chroma_side * chroma_side];25254 let mut pred_v = vec![0u16; chroma_side * chroma_side];
@@ -25357,7 +25390,51 @@ fn decode_inter_block(
25357 );25390 );
25358 }25391 }
25359 }25392 }
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);
25361 if obmc_selected {25438 if obmc_selected {
25362 obmc_blend(25439 obmc_blend(
25363 grid,25440 grid,
@@ -25388,26 +25465,6 @@ fn decode_inter_block(
25388 )?;25465 )?;
25389 }25466 }
25390 25467
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-
25411 // lane-inter16ab r2: libaom `build_inter_predictors_sub8x8`25468 // lane-inter16ab r2: libaom `build_inter_predictors_sub8x8`
25412 // (reconinter_template.inc:87-160). A 4:2:0 chroma block under a25469 // (reconinter_template.inc:87-160). A 4:2:0 chroma block under a
25413 // 16x4 (4x16) luma pair covers TWO luma blocks, so it is built in25470 // 16x4 (4x16) luma pair covers TWO luma blocks, so it is built in
@@ -25453,6 +25510,13 @@ fn decode_inter_block(
25453 }25510 }
25454 INTER16_SUB8_PIECE_HITS.with(|c| c.set(c.get() + 1));25511 INTER16_SUB8_PIECE_HITS.with(|c| c.set(c.get() + 1));
25455 }25512 }
25513+ (
25514+ Pred::Inline(&pred_y, side),
25515+ Pred::Inline(&pred_u, chroma_side),
25516+ Pred::Inline(&pred_v, chroma_side),
25517+ )
25518+ };
25519+
25456 25520
25457 // lane-inter4 r2: a rectangular strip's transform tree starts from25521 // lane-inter4 r2: a rectangular strip's transform tree starts from
25458 // its own rect `max_txsize_rect_lookup` entry, not a square one.25522 // its own rect `max_txsize_rect_lookup` entry, not a square one.
@@ -25487,7 +25551,7 @@ fn decode_inter_block(
25487 side,25551 side,
25488 write_w,25552 write_w,
25489 write_h,25553 write_h,
25490- Pred::dense(&pred_y),25554+ sy,
25491 &vec![0i32; side * side], fctx,25555 &vec![0i32; side * side], fctx,
25492 );25556 );
25493 if has_chroma {25557 if has_chroma {
@@ -25497,7 +25561,7 @@ fn decode_inter_block(
25497 chroma_side,25561 chroma_side,
25498 write_chroma_w,25562 write_chroma_w,
25499 write_chroma_h,25563 write_chroma_h,
25500- Pred::dense(&pred_u),25564+ su,
25501 &vec![0i32; chroma_side * chroma_side], fctx,25565 &vec![0i32; chroma_side * chroma_side], fctx,
25502 );25566 );
25503 push_mc_rect(2, 25567 push_mc_rect(2,
@@ -25506,7 +25570,7 @@ fn decode_inter_block(
25506 chroma_side,25570 chroma_side,
25507 write_chroma_w,25571 write_chroma_w,
25508 write_chroma_h,25572 write_chroma_h,
25509- Pred::dense(&pred_v),25573+ sv,
25510 &vec![0i32; chroma_side * chroma_side], fctx,25574 &vec![0i32; chroma_side * chroma_side], fctx,
25511 );25575 );
25512 }25576 }
@@ -25553,11 +25617,7 @@ fn decode_inter_block(
25553 let (tu_px, tu_py) = (px + col * MI, py + row * MI);25617 let (tu_px, tu_py) = (px + col * MI, py + row * MI);
25554 let (tu_grid, tu_tx_type) = if tw == th {25618 let (tu_grid, tu_tx_type) = if tw == th {
25555 let tx_px = tw;25619 let tx_px = tw;
25556- let mut tu_pred = Vec::with_capacity(tx_px * tx_px);25620+ let tu_pred = sy.offset(row * MI * side + col * MI);
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- }
25561 let scan = default_scan(tx_px.min(32));25621 let scan = default_scan(tx_px.min(32));
25562 let tu_skip_ctx = neighbours.luma_skip_ctx(tu_mi, tx_px / MI);25622 let tu_skip_ctx = neighbours.luma_skip_ctx(tu_mi, tx_px / MI);
25563 read_inter_plane(25623 read_inter_plane(
@@ -25573,7 +25633,7 @@ fn decode_inter_block(
25573 tu_py,25633 tu_py,
25574 tx_px,25634 tx_px,
25575 base_q_idx,25635 base_q_idx,
25576- Pred::dense(&tu_pred),25636+ tu_pred,
25577 None,25637 None,
25578 Some(tu_skip_ctx), fctx,25638 Some(tu_skip_ctx), fctx,
25579 )?25639 )?
@@ -25601,7 +25661,7 @@ fn decode_inter_block(
25601 y,25661 y,
25602 tu_px,25662 tu_px,
25603 tu_py,25663 tu_py,
25604- Pred::dense(&pred_y[start..]),25664+ sy.offset(start),
25605 None,25665 None,
25606 Some(tu_skip_ctx), fctx,25666 Some(tu_skip_ctx), fctx,
25607 )?25667 )?
@@ -25635,16 +25695,12 @@ fn decode_inter_block(
25635 let cu_scan = default_scan(cu_tx);25695 let cu_scan = default_scan(cu_tx);
25636 for plane_idx in 1..3 {25696 for plane_idx in 1..3 {
25637 let (src, buf) = if plane_idx == 1 {25697 let (src, buf) = if plane_idx == 1 {
25638- (&pred_u, &mut *u)25698+ (su, &mut *u)
25639 } else {25699 } else {
25640- (&pred_v, &mut *v)25700+ (sv, &mut *v)
25641 };25701 };
25642- let mut cu_pred = Vec::with_capacity(cu_tx * cu_tx);25702+ let cu_pred =
25643- for rr in 0..cu_tx {25703+ src.offset(cr * cu_tx * chroma_side + cc * 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- }
25648 let cu_grid = read_inter_plane(25704 let cu_grid = read_inter_plane(
25649 dec,25705 dec,
25650 cdfs,25706 cdfs,
@@ -25658,7 +25714,7 @@ fn decode_inter_block(
25658 cu_y,25714 cu_y,
25659 cu_tx,25715 cu_tx,
25660 base_q_idx,25716 base_q_idx,
25661- Pred::dense(&cu_pred),25717+ cu_pred,
25662 Some(first_tx_type),25718 Some(first_tx_type),
25663 Some(3), fctx,25719 Some(3), fctx,
25664 )?25720 )?
@@ -25705,7 +25761,7 @@ fn decode_inter_block(
25705 y,25761 y,
25706 px,25762 px,
25707 py,25763 py,
25708- Pred::dense(&pred_y),25764+ sy,
25709 None,25765 None,
25710 None, fctx,25766 None, fctx,
25711 )?;25767 )?;
@@ -25725,7 +25781,7 @@ fn decode_inter_block(
25725 py,25781 py,
25726 side,25782 side,
25727 base_q_idx,25783 base_q_idx,
25728- Pred::dense(&pred_y),25784+ sy,
25729 None,25785 None,
25730 None, fctx,25786 None, fctx,
25731 )?;25787 )?;
@@ -25764,7 +25820,7 @@ fn decode_inter_block(
25764 u,25820 u,
25765 cpx,25821 cpx,
25766 cpy,25822 cpy,
25767- Pred::dense(&pred_u),25823+ su,
25768 Some(luma_tx_type),25824 Some(luma_tx_type),
25769 None, fctx,25825 None, fctx,
25770 )?25826 )?
@@ -25786,7 +25842,7 @@ fn decode_inter_block(
25786 v,25842 v,
25787 cpx,25843 cpx,
25788 cpy,25844 cpy,
25789- Pred::dense(&pred_v),25845+ sv,
25790 Some(luma_tx_type),25846 Some(luma_tx_type),
25791 None, fctx,25847 None, fctx,
25792 )?25848 )?
@@ -25809,7 +25865,7 @@ fn decode_inter_block(
25809 cpy,25865 cpy,
25810 chroma_side,25866 chroma_side,
25811 base_q_idx,25867 base_q_idx,
25812- Pred::dense(&pred_u),25868+ su,
25813 Some(luma_tx_type),25869 Some(luma_tx_type),
25814 None, fctx,25870 None, fctx,
25815 )?25871 )?
@@ -25827,7 +25883,7 @@ fn decode_inter_block(
25827 cpy,25883 cpy,
25828 chroma_side,25884 chroma_side,
25829 base_q_idx,25885 base_q_idx,
25830- Pred::dense(&pred_v),25886+ sv,
25831 Some(luma_tx_type),25887 Some(luma_tx_type),
25832 None, fctx,25888 None, fctx,
25833 )?25889 )?