From 52da7db6934595d19a13415541fbb235197c809d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Sat, 5 Sep 2026 05:13:10 +0300 Subject: [PATCH] perf(av1): a compound inter block predicts on the worker too lane-wave4: the compound arm's whole prediction -- both references, the wedge/diffwtd/distance blend, all three planes -- becomes the same deferred closure the single-reference arm got. A compound block reads neither motion_mode nor interintra, so its build has nothing that must stay on the parsing thread. --- crates/ec-av1/src/decode.rs | 74 ++++++++++++++++++++++++------------- 1 file changed, 49 insertions(+), 25 deletions(-) diff --git a/crates/ec-av1/src/decode.rs b/crates/ec-av1/src/decode.rs index 457e3c8c..c3a7e9d6 100644 --- a/crates/ec-av1/src/decode.rs +++ b/crates/ec-av1/src/decode.rs @@ -24037,6 +24037,18 @@ fn decode_inter_block( MIXED_SCALE_COMPOUND_HITS.with(|c| c.set(c.get() + 1)); } + // lane-wave4 (the compound arm's half): this block's whole + // prediction -- both references, the wedge/diffwtd/distance + // blend, every plane -- as a closure, run here at one + // reconstruction thread and on the wavefront worker otherwise + // (see the single-reference arm below). A compound block reads + // neither `motion_mode` nor `interintra`, so nothing but the + // blend itself lives in here. + let build = move |_y: &mut PlaneBuf<'static>, + _u: &mut PlaneBuf<'static>, + _v: &mut PlaneBuf<'static>, + fctx: &crate::decode::FrameCtx| + -> [Vec; 3] { let mut inter0_y = vec![0i32; side * side]; mc::predict_compound_intermediate_kern( &py0.data, @@ -24263,6 +24275,26 @@ fn decode_inter_block( // lane-inter4 r2: a rectangular strip's transform tree starts from // its own rect `max_txsize_rect_lookup` entry, not a square one. + [pred_y, pred_u, pred_v] + }; + let (pred_y, pred_u, pred_v): (Vec, Vec, Vec); + let (sy, su, sv) = if recon_deferred(fctx) { + push_pred(fctx, build); + ( + Pred::Cur { plane: 0, stride: side, off: 0 }, + Pred::Cur { plane: 1, stride: chroma_side, off: 0 }, + Pred::Cur { plane: 2, stride: chroma_side, off: 0 }, + ) + } else { + let [by, bu, bv] = build(y, u, v, fctx); + (pred_y, pred_u, pred_v) = (by, bu, bv); + ( + Pred::Inline(&pred_y, side), + Pred::Inline(&pred_u, chroma_side), + Pred::Inline(&pred_v, chroma_side), + ) + }; + let rect_tu = (write_w, write_h) != (side, side); vartx_leaves = if rect_tu { read_block_tx_size_rect( @@ -24294,7 +24326,7 @@ fn decode_inter_block( side, write_w, write_h, - Pred::dense(&pred_y), + sy, &vec![0i32; side * side], fctx, ); push_mc_rect(1, @@ -24303,7 +24335,7 @@ fn decode_inter_block( chroma_side, write_chroma_w, write_chroma_h, - Pred::dense(&pred_u), + su, &vec![0i32; chroma_side * chroma_side], fctx, ); push_mc_rect(2, @@ -24312,7 +24344,7 @@ fn decode_inter_block( chroma_side, write_chroma_w, write_chroma_h, - Pred::dense(&pred_v), + sv, &vec![0i32; chroma_side * chroma_side], fctx, ); luma_grid = vec![0i32; side * side]; @@ -24346,11 +24378,7 @@ fn decode_inter_block( let (tu_px, tu_py) = (px + col * MI, py + row * MI); let (tu_grid, tu_tx_type) = if tw == th { let tx_px = tw; - let mut tu_pred = Vec::with_capacity(tx_px * tx_px); - for rr in 0..tx_px { - let start = (row * MI + rr) * side + col * MI; - tu_pred.extend_from_slice(&pred_y[start..start + tx_px]); - } + let tu_pred = sy.offset(row * MI * side + col * MI); let scan = default_scan(tx_px.min(32)); let tu_skip_ctx = neighbours.luma_skip_ctx(tu_mi, tx_px / MI); read_inter_plane( @@ -24366,7 +24394,7 @@ fn decode_inter_block( tu_py, tx_px, base_q_idx, - Pred::dense(&tu_pred), + tu_pred, None, Some(tu_skip_ctx), fctx, )? @@ -24394,7 +24422,7 @@ fn decode_inter_block( y, tu_px, tu_py, - Pred::dense(&pred_y[start..]), + sy.offset(start), None, Some(tu_skip_ctx), fctx, )? @@ -24428,16 +24456,12 @@ fn decode_inter_block( let cu_scan = default_scan(cu_tx); for plane_idx in 1..3 { let (src, buf) = if plane_idx == 1 { - (&pred_u, &mut *u) + (su, &mut *u) } else { - (&pred_v, &mut *v) + (sv, &mut *v) }; - let mut cu_pred = Vec::with_capacity(cu_tx * cu_tx); - for rr in 0..cu_tx { - let start = - (cr * cu_tx + rr) * chroma_side + cc * cu_tx; - cu_pred.extend_from_slice(&src[start..start + cu_tx]); - } + let cu_pred = + src.offset(cr * cu_tx * chroma_side + cc * cu_tx); let cu_grid = read_inter_plane( dec, cdfs, @@ -24451,7 +24475,7 @@ fn decode_inter_block( cu_y, cu_tx, base_q_idx, - Pred::dense(&cu_pred), + cu_pred, Some(first_tx_type), Some(3), fctx, )? @@ -24498,7 +24522,7 @@ fn decode_inter_block( y, px, py, - Pred::dense(&pred_y), + sy, None, None, fctx, )?; @@ -24518,7 +24542,7 @@ fn decode_inter_block( py, side, base_q_idx, - Pred::dense(&pred_y), + sy, None, None, fctx, )?; @@ -24548,7 +24572,7 @@ fn decode_inter_block( u, cpx, cpy, - Pred::dense(&pred_u), + su, Some(luma_tx_type), None, fctx, )? @@ -24570,7 +24594,7 @@ fn decode_inter_block( v, cpx, cpy, - Pred::dense(&pred_v), + sv, Some(luma_tx_type), None, fctx, )? @@ -24593,7 +24617,7 @@ fn decode_inter_block( cpy, chroma_side, base_q_idx, - Pred::dense(&pred_u), + su, Some(luma_tx_type), None, fctx, )? @@ -24611,7 +24635,7 @@ fn decode_inter_block( cpy, chroma_side, base_q_idx, - Pred::dense(&pred_v), + sv, Some(luma_tx_type), None, fctx, )?