A single-reference inter block predicts on the worker that reconstructs it
Browse files at this commit4a7d65a9d8226eecd60f97b19583499a9fee52f5Parent: 8aa7db1- perf
- a single-reference inter block predicts on the worker that reconstructs it
1 changed file +103 -47
- crates/ec-av1/src/decode.rs +103 -47
crates/ec-av1/src/decode.rsmodified+103 -47
| @@ -2794,7 +2794,25 @@ fn push_mc_rect_tx( | ||
| 2794 | 2794 | } |
| 2795 | 2795 | }; |
| 2796 | 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 | 2816 | return; |
| 2799 | 2817 | } |
| 2800 | 2818 | // `reconstruct_mc_rect` reads exactly rows `0..h`, columns `0..w` of the |
| @@ -25216,6 +25234,21 @@ fn decode_inter_block( | ||
| 25216 | 25234 | // (reconinter_template.inc:75-82); record them for the next 1:4 |
| 25217 | 25235 | // strip, which is the only reader. |
| 25218 | 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 | 25252 | let mut pred_y = vec![0u16; side * side]; |
| 25220 | 25253 | let mut pred_u = vec![0u16; chroma_side * chroma_side]; |
| 25221 | 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 | 25438 | if obmc_selected { |
| 25362 | 25439 | obmc_blend( |
| 25363 | 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 | 25468 | // lane-inter16ab r2: libaom `build_inter_predictors_sub8x8` |
| 25412 | 25469 | // (reconinter_template.inc:87-160). A 4:2:0 chroma block under a |
| 25413 | 25470 | // 16x4 (4x16) luma pair covers TWO luma blocks, so it is built in |
| @@ -25453,6 +25510,13 @@ fn decode_inter_block( | ||
| 25453 | 25510 | } |
| 25454 | 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 | 25521 | // lane-inter4 r2: a rectangular strip's transform tree starts from |
| 25458 | 25522 | // its own rect `max_txsize_rect_lookup` entry, not a square one. |
| @@ -25487,7 +25551,7 @@ fn decode_inter_block( | ||
| 25487 | 25551 | side, |
| 25488 | 25552 | write_w, |
| 25489 | 25553 | write_h, |
| 25490 | - Pred::dense(&pred_y), | |
| 25554 | + sy, | |
| 25491 | 25555 | &vec![0i32; side * side], fctx, |
| 25492 | 25556 | ); |
| 25493 | 25557 | if has_chroma { |
| @@ -25497,7 +25561,7 @@ fn decode_inter_block( | ||
| 25497 | 25561 | chroma_side, |
| 25498 | 25562 | write_chroma_w, |
| 25499 | 25563 | write_chroma_h, |
| 25500 | - Pred::dense(&pred_u), | |
| 25564 | + su, | |
| 25501 | 25565 | &vec![0i32; chroma_side * chroma_side], fctx, |
| 25502 | 25566 | ); |
| 25503 | 25567 | push_mc_rect(2, |
| @@ -25506,7 +25570,7 @@ fn decode_inter_block( | ||
| 25506 | 25570 | chroma_side, |
| 25507 | 25571 | write_chroma_w, |
| 25508 | 25572 | write_chroma_h, |
| 25509 | - Pred::dense(&pred_v), | |
| 25573 | + sv, | |
| 25510 | 25574 | &vec![0i32; chroma_side * chroma_side], fctx, |
| 25511 | 25575 | ); |
| 25512 | 25576 | } |
| @@ -25553,11 +25617,7 @@ fn decode_inter_block( | ||
| 25553 | 25617 | let (tu_px, tu_py) = (px + col * MI, py + row * MI); |
| 25554 | 25618 | let (tu_grid, tu_tx_type) = if tw == th { |
| 25555 | 25619 | 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); | |
| 25561 | 25621 | let scan = default_scan(tx_px.min(32)); |
| 25562 | 25622 | let tu_skip_ctx = neighbours.luma_skip_ctx(tu_mi, tx_px / MI); |
| 25563 | 25623 | read_inter_plane( |
| @@ -25573,7 +25633,7 @@ fn decode_inter_block( | ||
| 25573 | 25633 | tu_py, |
| 25574 | 25634 | tx_px, |
| 25575 | 25635 | base_q_idx, |
| 25576 | - Pred::dense(&tu_pred), | |
| 25636 | + tu_pred, | |
| 25577 | 25637 | None, |
| 25578 | 25638 | Some(tu_skip_ctx), fctx, |
| 25579 | 25639 | )? |
| @@ -25601,7 +25661,7 @@ fn decode_inter_block( | ||
| 25601 | 25661 | y, |
| 25602 | 25662 | tu_px, |
| 25603 | 25663 | tu_py, |
| 25604 | - Pred::dense(&pred_y[start..]), | |
| 25664 | + sy.offset(start), | |
| 25605 | 25665 | None, |
| 25606 | 25666 | Some(tu_skip_ctx), fctx, |
| 25607 | 25667 | )? |
| @@ -25635,16 +25695,12 @@ fn decode_inter_block( | ||
| 25635 | 25695 | let cu_scan = default_scan(cu_tx); |
| 25636 | 25696 | for plane_idx in 1..3 { |
| 25637 | 25697 | let (src, buf) = if plane_idx == 1 { |
| 25638 | - (&pred_u, &mut *u) | |
| 25698 | + (su, &mut *u) | |
| 25639 | 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); | |
| 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); | |
| 25648 | 25704 | let cu_grid = read_inter_plane( |
| 25649 | 25705 | dec, |
| 25650 | 25706 | cdfs, |
| @@ -25658,7 +25714,7 @@ fn decode_inter_block( | ||
| 25658 | 25714 | cu_y, |
| 25659 | 25715 | cu_tx, |
| 25660 | 25716 | base_q_idx, |
| 25661 | - Pred::dense(&cu_pred), | |
| 25717 | + cu_pred, | |
| 25662 | 25718 | Some(first_tx_type), |
| 25663 | 25719 | Some(3), fctx, |
| 25664 | 25720 | )? |
| @@ -25705,7 +25761,7 @@ fn decode_inter_block( | ||
| 25705 | 25761 | y, |
| 25706 | 25762 | px, |
| 25707 | 25763 | py, |
| 25708 | - Pred::dense(&pred_y), | |
| 25764 | + sy, | |
| 25709 | 25765 | None, |
| 25710 | 25766 | None, fctx, |
| 25711 | 25767 | )?; |
| @@ -25725,7 +25781,7 @@ fn decode_inter_block( | ||
| 25725 | 25781 | py, |
| 25726 | 25782 | side, |
| 25727 | 25783 | base_q_idx, |
| 25728 | - Pred::dense(&pred_y), | |
| 25784 | + sy, | |
| 25729 | 25785 | None, |
| 25730 | 25786 | None, fctx, |
| 25731 | 25787 | )?; |
| @@ -25764,7 +25820,7 @@ fn decode_inter_block( | ||
| 25764 | 25820 | u, |
| 25765 | 25821 | cpx, |
| 25766 | 25822 | cpy, |
| 25767 | - Pred::dense(&pred_u), | |
| 25823 | + su, | |
| 25768 | 25824 | Some(luma_tx_type), |
| 25769 | 25825 | None, fctx, |
| 25770 | 25826 | )? |
| @@ -25786,7 +25842,7 @@ fn decode_inter_block( | ||
| 25786 | 25842 | v, |
| 25787 | 25843 | cpx, |
| 25788 | 25844 | cpy, |
| 25789 | - Pred::dense(&pred_v), | |
| 25845 | + sv, | |
| 25790 | 25846 | Some(luma_tx_type), |
| 25791 | 25847 | None, fctx, |
| 25792 | 25848 | )? |
| @@ -25809,7 +25865,7 @@ fn decode_inter_block( | ||
| 25809 | 25865 | cpy, |
| 25810 | 25866 | chroma_side, |
| 25811 | 25867 | base_q_idx, |
| 25812 | - Pred::dense(&pred_u), | |
| 25868 | + su, | |
| 25813 | 25869 | Some(luma_tx_type), |
| 25814 | 25870 | None, fctx, |
| 25815 | 25871 | )? |
| @@ -25827,7 +25883,7 @@ fn decode_inter_block( | ||
| 25827 | 25883 | cpy, |
| 25828 | 25884 | chroma_side, |
| 25829 | 25885 | base_q_idx, |
| 25830 | - Pred::dense(&pred_v), | |
| 25886 | + sv, | |
| 25831 | 25887 | Some(luma_tx_type), |
| 25832 | 25888 | None, fctx, |
| 25833 | 25889 | )? |