The sub-8x8 group predictions build on the recon worker too
Browse files at this commit9137abf43e3f9fc12aed232a3b7a8b1dc32d81baParent: 36b27a7- perf
- the sub-8x8 group predictions build on the recon worker too
1 changed file +229 -129
- crates/ec-av1/src/decode.rs +229 -129
crates/ec-av1/src/decode.rsmodified+229 -129
| @@ -2253,8 +2253,8 @@ fn dense_residual(residual: &[i32], n: usize) -> &[i32] { | ||
| 2253 | 2253 | /// block then reads its window out of that slot ([`Pred::Cur`]). |
| 2254 | 2254 | #[derive(Clone, Copy)] |
| 2255 | 2255 | pub(crate) enum Pred<'a> { |
| 2256 | - /// A prediction the parse thread already built. `stride == 0` means "the | |
| 2257 | - /// reader's own `stride` argument", which is every pre-lane-wave4 site. | |
| 2256 | + /// A prediction the parse thread already built, at its own stride | |
| 2257 | + /// (`stride == 0` means "the reader's own `stride` argument"). | |
| 2258 | 2258 | Inline(&'a [u16], usize), |
| 2259 | 2259 | /// The current block's deferred prediction: plane, its stride, and this |
| 2260 | 2260 | /// unit's offset into it. |
| @@ -2262,9 +2262,6 @@ pub(crate) enum Pred<'a> { | ||
| 2262 | 2262 | } |
| 2263 | 2263 | |
| 2264 | 2264 | impl<'a> Pred<'a> { |
| 2265 | - fn dense(buf: &'a [u16]) -> Self { | |
| 2266 | - Self::Inline(buf, 0) | |
| 2267 | - } | |
| 2268 | 2265 | /// The same prediction read at an explicit stride. |
| 2269 | 2266 | fn view(self, stride: usize) -> Self { |
| 2270 | 2267 | match self { |
| @@ -28686,12 +28683,14 @@ fn decode_inter_sub8_split4( | ||
| 28686 | 28683 | neighbours.left_ref[rmi], |
| 28687 | 28684 | neighbours.left_ref1[rmi], |
| 28688 | 28685 | ); |
| 28689 | - let (sref_y, _sref_u, _sref_v) = ref_planes(ref_frame, refpix)?; | |
| 28686 | + // lane-sub8group: this piece's reference SIZE at parse, its pictures | |
| 28687 | + // inside the prediction closure below. | |
| 28688 | + let (ref_width, _) = ref_dims(ref_frame, refpix)?; | |
| 28690 | 28689 | // lane-t900 r28: refusal lifted -- this sub-block's own reference may |
| 28691 | 28690 | // be scaled (superres); spec 7.11.3.3's walk is per reference, and |
| 28692 | 28691 | // each of the group's pieces (luma and its 2x2 chroma) carries its |
| 28693 | 28692 | // OWN factor because each can name a different `ref_frame`. |
| 28694 | - let luma_scale = mc::scale_factor(sref_y.width, frame_width); | |
| 28693 | + let luma_scale = mc::scale_factor(ref_width, frame_width); | |
| 28695 | 28694 | if luma_scale != mc::REF_NO_SCALE { |
| 28696 | 28695 | SCALED_SUB8_HITS.with(|c| c.set(c.get() + 1)); |
| 28697 | 28696 | } |
| @@ -28854,27 +28853,51 @@ fn decode_inter_sub8_split4( | ||
| 28854 | 28853 | }, |
| 28855 | 28854 | ); |
| 28856 | 28855 | piece[i] = Some((ref_frame, mv, h_filter, v_filter)); |
| 28857 | - let mut pred_y = vec![0u16; B4 * B4]; | |
| 28858 | - mc::predict_maybe_scaled( | |
| 28859 | - &sref_y.data, | |
| 28860 | - sref_y.width, | |
| 28861 | - sref_y.true_width, | |
| 28862 | - sref_y.true_height, | |
| 28863 | - mv_to_q4(px, mv.1, true), | |
| 28864 | - mv_to_q4(py, mv.0, true), | |
| 28865 | - luma_scale, | |
| 28866 | - B4, | |
| 28867 | - B4, | |
| 28868 | - h_filter, | |
| 28869 | - v_filter, | |
| 28870 | - &mut pred_y, fctx, | |
| 28871 | - ); | |
| 28856 | + // lane-sub8group: this piece's prediction as a closure, so it runs | |
| 28857 | + // where its writes run -- on a recon worker at more than one | |
| 28858 | + // reconstruction thread, exactly like the 8x8 leaf's. | |
| 28859 | + let build = move |_y: &mut PlaneBuf<'static>, | |
| 28860 | + _u: &mut PlaneBuf<'static>, | |
| 28861 | + _v: &mut PlaneBuf<'static>, | |
| 28862 | + fctx: &crate::decode::FrameCtx, | |
| 28863 | + out: &mut [Vec<u16>; 3]| { | |
| 28864 | + let Some((sref_y, _, _)) = ref_planes_deferred(ref_frame, refpix) else { | |
| 28865 | + return; | |
| 28866 | + }; | |
| 28867 | + let mut pred_y = refill(std::mem::take(&mut out[0]), B4 * B4); | |
| 28868 | + mc::predict_maybe_scaled( | |
| 28869 | + &sref_y.data, | |
| 28870 | + sref_y.width, | |
| 28871 | + sref_y.true_width, | |
| 28872 | + sref_y.true_height, | |
| 28873 | + mv_to_q4(px, mv.1, true), | |
| 28874 | + mv_to_q4(py, mv.0, true), | |
| 28875 | + luma_scale, | |
| 28876 | + B4, | |
| 28877 | + B4, | |
| 28878 | + h_filter, | |
| 28879 | + v_filter, | |
| 28880 | + &mut pred_y, fctx, | |
| 28881 | + ); | |
| 28882 | + out[0] = pred_y; | |
| 28883 | + }; | |
| 28884 | + let pred_y: Vec<u16>; | |
| 28885 | + let sy = if recon_deferred(fctx) { | |
| 28886 | + push_pred(fctx, build); | |
| 28887 | + Pred::Cur { plane: 0, stride: B4, off: 0 } | |
| 28888 | + } else { | |
| 28889 | + let mut built: [Vec<u16>; 3] = Default::default(); | |
| 28890 | + build(y, u, v, fctx, &mut built); | |
| 28891 | + let [by, _, _] = built; | |
| 28892 | + pred_y = by; | |
| 28893 | + Pred::Inline(&pred_y, B4) | |
| 28894 | + }; | |
| 28872 | 28895 | // `BLOCK_4X4` never signals a transform size, so the luma unit is the |
| 28873 | 28896 | // whole block and `get_txb_ctx` takes its `plane_bsize == |
| 28874 | 28897 | // txsize_to_bsize[tx_size]` branch (`txb_skip_ctx = 0`, which |
| 28875 | 28898 | // `read_inter_plane`'s `plane_idx == 0` arm already assumes). |
| 28876 | 28899 | if skip { |
| 28877 | - push_mc(0, px, py, B4, Pred::dense(&pred_y), &ZERO_RESIDUAL[..B4 * B4], fctx); | |
| 28900 | + push_mc(0, px, py, B4, sy, &ZERO_RESIDUAL[..B4 * B4], fctx); | |
| 28878 | 28901 | neighbours.record_mi_luma_rect(lmi, B4, B4, &ZERO_RESIDUAL[..B4 * B4]); |
| 28879 | 28902 | } else { |
| 28880 | 28903 | let around = neighbours.around_mi(lmi, B4); |
| @@ -28895,7 +28918,7 @@ fn decode_inter_sub8_split4( | ||
| 28895 | 28918 | py, |
| 28896 | 28919 | B4, |
| 28897 | 28920 | base_q_idx, |
| 28898 | - Pred::dense(&pred_y), | |
| 28921 | + sy, | |
| 28899 | 28922 | None, |
| 28900 | 28923 | None, fctx, |
| 28901 | 28924 | )?; |
| @@ -28934,8 +28957,6 @@ fn decode_inter_sub8_split4( | ||
| 28934 | 28957 | // Chroma, once for the whole group, on the last sub-block's own `skip` |
| 28935 | 28958 | // flag -- prediction from all four sub-blocks (2x2 pieces), residual as |
| 28936 | 28959 | // one TX_4X4 unit per plane. |
| 28937 | - let mut pred_u = vec![0u16; B4 * B4]; | |
| 28938 | - let mut pred_v = vec![0u16; B4 * B4]; | |
| 28939 | 28960 | // `is_sub8x8_inter` (reconinter_template.inc:54) is false as soon as ANY |
| 28940 | 28961 | // mi of the group is intra: the group's 4x4 chroma is then predicted WHOLE |
| 28941 | 28962 | // from the chroma-reference (last) sub-block's own mv, not in 2x2 pieces. |
| @@ -28947,61 +28968,89 @@ fn decode_inter_sub8_split4( | ||
| 28947 | 28968 | h.set(st); |
| 28948 | 28969 | }); |
| 28949 | 28970 | } |
| 28950 | - for i in 0..4usize { | |
| 28951 | - let (dr, dc) = (i / 2, i % 2); | |
| 28952 | - if mixed && i != 3 { | |
| 28953 | - continue; | |
| 28954 | - } | |
| 28955 | - let Some((ref_frame, mv, h_filter, v_filter)) = piece[i] else { | |
| 28956 | - continue; | |
| 28957 | - }; | |
| 28958 | - let (piece_ref_y, sref_u, sref_v) = | |
| 28959 | - ref_planes(ref_frame, refpix)?; | |
| 28960 | - let piece_scale = mc::scale_factor(piece_ref_y.width, frame_width); | |
| 28961 | - let (ox, oy) = if mixed { | |
| 28962 | - (cpx, cpy) | |
| 28963 | - } else { | |
| 28964 | - (cpx + dc * 2, cpy + dr * 2) | |
| 28965 | - }; | |
| 28966 | - let (pw, ph) = if mixed { (B4, B4) } else { (2, 2) }; | |
| 28967 | - let (row0, col0) = if mixed { (0, 0) } else { (dr * 2, dc * 2) }; | |
| 28968 | - for (plane, dst) in [(sref_u, &mut pred_u), (sref_v, &mut pred_v)] { | |
| 28969 | - let mut buf = vec![0u16; pw * ph]; | |
| 28970 | - mc::predict_maybe_scaled( | |
| 28971 | - &plane.data, | |
| 28972 | - plane.width, | |
| 28973 | - plane.true_width, | |
| 28974 | - plane.true_height, | |
| 28975 | - mv_to_q4(ox, mv.1, false), | |
| 28976 | - mv_to_q4(oy, mv.0, false), | |
| 28977 | - piece_scale, | |
| 28978 | - pw, | |
| 28979 | - ph, | |
| 28980 | - h_filter, | |
| 28981 | - v_filter, | |
| 28982 | - &mut buf, fctx, | |
| 28983 | - ); | |
| 28984 | - for row in 0..ph { | |
| 28985 | - for col in 0..pw { | |
| 28986 | - dst[(row0 + row) * B4 + col0 + col] = buf[row * pw + col]; | |
| 28971 | + // lane-sub8group: the group's chroma pieces, built on the worker that | |
| 28972 | + // writes them -- the pieces' refs/mvs/filters travel by value. | |
| 28973 | + let build = move |_y: &mut PlaneBuf<'static>, | |
| 28974 | + _u: &mut PlaneBuf<'static>, | |
| 28975 | + _v: &mut PlaneBuf<'static>, | |
| 28976 | + fctx: &crate::decode::FrameCtx, | |
| 28977 | + out: &mut [Vec<u16>; 3]| { | |
| 28978 | + let mut pred_u = refill(std::mem::take(&mut out[1]), B4 * B4); | |
| 28979 | + let mut pred_v = refill(std::mem::take(&mut out[2]), B4 * B4); | |
| 28980 | + for i in 0..4usize { | |
| 28981 | + let (dr, dc) = (i / 2, i % 2); | |
| 28982 | + if mixed && i != 3 { | |
| 28983 | + continue; | |
| 28984 | + } | |
| 28985 | + let Some((ref_frame, mv, h_filter, v_filter)) = piece[i] else { | |
| 28986 | + continue; | |
| 28987 | + }; | |
| 28988 | + let Some((piece_ref_y, sref_u, sref_v)) = ref_planes_deferred(ref_frame, refpix) | |
| 28989 | + else { | |
| 28990 | + continue; | |
| 28991 | + }; | |
| 28992 | + let piece_scale = mc::scale_factor(piece_ref_y.width, frame_width); | |
| 28993 | + let (ox, oy) = if mixed { | |
| 28994 | + (cpx, cpy) | |
| 28995 | + } else { | |
| 28996 | + (cpx + dc * 2, cpy + dr * 2) | |
| 28997 | + }; | |
| 28998 | + let (pw, ph) = if mixed { (B4, B4) } else { (2, 2) }; | |
| 28999 | + let (row0, col0) = if mixed { (0, 0) } else { (dr * 2, dc * 2) }; | |
| 29000 | + for (plane, dst) in [(sref_u, &mut pred_u), (sref_v, &mut pred_v)] { | |
| 29001 | + let mut buf = vec![0u16; pw * ph]; | |
| 29002 | + mc::predict_maybe_scaled( | |
| 29003 | + &plane.data, | |
| 29004 | + plane.width, | |
| 29005 | + plane.true_width, | |
| 29006 | + plane.true_height, | |
| 29007 | + mv_to_q4(ox, mv.1, false), | |
| 29008 | + mv_to_q4(oy, mv.0, false), | |
| 29009 | + piece_scale, | |
| 29010 | + pw, | |
| 29011 | + ph, | |
| 29012 | + h_filter, | |
| 29013 | + v_filter, | |
| 29014 | + &mut buf, fctx, | |
| 29015 | + ); | |
| 29016 | + for row in 0..ph { | |
| 29017 | + for col in 0..pw { | |
| 29018 | + dst[(row0 + row) * B4 + col0 + col] = buf[row * pw + col]; | |
| 29019 | + } | |
| 28987 | 29020 | } |
| 28988 | 29021 | } |
| 28989 | 29022 | } |
| 28990 | - } | |
| 29023 | + out[1] = pred_u; | |
| 29024 | + out[2] = pred_v; | |
| 29025 | + }; | |
| 29026 | + let (pred_u, pred_v): (Vec<u16>, Vec<u16>); | |
| 29027 | + let (su, sv) = if recon_deferred(fctx) { | |
| 29028 | + push_pred(fctx, build); | |
| 29029 | + ( | |
| 29030 | + Pred::Cur { plane: 1, stride: B4, off: 0 }, | |
| 29031 | + Pred::Cur { plane: 2, stride: B4, off: 0 }, | |
| 29032 | + ) | |
| 29033 | + } else { | |
| 29034 | + let mut built: [Vec<u16>; 3] = Default::default(); | |
| 29035 | + build(y, u, v, fctx, &mut built); | |
| 29036 | + let [_, bu, bv] = built; | |
| 29037 | + (pred_u, pred_v) = (bu, bv); | |
| 29038 | + (Pred::Inline(&pred_u, B4), Pred::Inline(&pred_v, B4)) | |
| 29039 | + }; | |
| 28991 | 29040 | let (u_grid, v_grid) = if last_skip { |
| 28992 | - push_mc(1, cpx, cpy, B4, Pred::dense(&pred_u), &ZERO_RESIDUAL[..B4 * B4], fctx); | |
| 28993 | - push_mc(2, cpx, cpy, B4, Pred::dense(&pred_v), &ZERO_RESIDUAL[..B4 * B4], fctx); | |
| 29041 | + push_mc(1, cpx, cpy, B4, su, &ZERO_RESIDUAL[..B4 * B4], fctx); | |
| 29042 | + push_mc(2, cpx, cpy, B4, sv, &ZERO_RESIDUAL[..B4 * B4], fctx); | |
| 28994 | 29043 | (Grid::Zero(B4 * B4), Grid::Zero(B4 * B4)) |
| 28995 | 29044 | } else { |
| 28996 | 29045 | let around = neighbours.around_mi(group_mi, 8); |
| 28997 | 29046 | let ug = read_inter_plane( |
| 28998 | 29047 | dec, cdfs, TxbSet::Chroma4, scan4, 1, around[1], 0, u, cpx, cpy, B4, base_q_idx, |
| 28999 | - Pred::dense(&pred_u), Some(first_tx_type), None, fctx, | |
| 29048 | + su, Some(first_tx_type), None, fctx, | |
| 29000 | 29049 | )? |
| 29001 | 29050 | .0; |
| 29002 | 29051 | let vg = read_inter_plane( |
| 29003 | 29052 | dec, cdfs, TxbSet::Chroma4, scan4, 2, around[2], 0, v, cpx, cpy, B4, base_q_idx, |
| 29004 | - Pred::dense(&pred_v), Some(first_tx_type), None, fctx, | |
| 29053 | + sv, Some(first_tx_type), None, fctx, | |
| 29005 | 29054 | )? |
| 29006 | 29055 | .0; |
| 29007 | 29056 | let coded = ug.iter().chain(vg.iter()).any(|&c| c != 0); |
| @@ -29656,9 +29705,11 @@ fn decode_inter_sub8_rect2( | ||
| 29656 | 29705 | neighbours.left_ref[rmi], |
| 29657 | 29706 | neighbours.left_ref1[rmi], |
| 29658 | 29707 | ); |
| 29659 | - let (sref_y, _, _) = ref_planes(ref_frame, refpix)?; | |
| 29708 | + // lane-sub8group: this piece's reference SIZE at parse, its pictures | |
| 29709 | + // inside the prediction closure below. | |
| 29710 | + let (ref_width, _) = ref_dims(ref_frame, refpix)?; | |
| 29660 | 29711 | // lane-t900 r28: refusal lifted -- see the split arm above. |
| 29661 | - let luma_scale = mc::scale_factor(sref_y.width, frame_width); | |
| 29712 | + let luma_scale = mc::scale_factor(ref_width, frame_width); | |
| 29662 | 29713 | if luma_scale != mc::REF_NO_SCALE { |
| 29663 | 29714 | SCALED_SUB8_HITS.with(|c| c.set(c.get() + 1)); |
| 29664 | 29715 | } |
| @@ -29820,8 +29871,18 @@ fn decode_inter_sub8_rect2( | ||
| 29820 | 29871 | // Prediction over the leaf's true footprint, laid out at the group's |
| 29821 | 29872 | // square stride (what `reconstruct_mc_rect` and `read_inter_plane_rect` |
| 29822 | 29873 | // index with). |
| 29823 | - let mut pred_y = vec![0u16; SIDE * SIDE]; | |
| 29824 | - { | |
| 29874 | + // lane-sub8group: this piece's prediction as a closure, so it runs | |
| 29875 | + // where its writes run -- on a recon worker at more than one | |
| 29876 | + // reconstruction thread, exactly like the 8x8 leaf's. | |
| 29877 | + let build = move |_y: &mut PlaneBuf<'static>, | |
| 29878 | + _u: &mut PlaneBuf<'static>, | |
| 29879 | + _v: &mut PlaneBuf<'static>, | |
| 29880 | + fctx: &crate::decode::FrameCtx, | |
| 29881 | + out: &mut [Vec<u16>; 3]| { | |
| 29882 | + let Some((sref_y, _, _)) = ref_planes_deferred(ref_frame, refpix) else { | |
| 29883 | + return; | |
| 29884 | + }; | |
| 29885 | + let mut pred_y = refill(std::mem::take(&mut out[0]), SIDE * SIDE); | |
| 29825 | 29886 | let mut dense = vec![0u16; bw * bh]; |
| 29826 | 29887 | mc::predict_maybe_scaled( |
| 29827 | 29888 | &sref_y.data, |
| @@ -29840,9 +29901,21 @@ fn decode_inter_sub8_rect2( | ||
| 29840 | 29901 | for row in 0..bh { |
| 29841 | 29902 | pred_y[row * SIDE..][..bw].copy_from_slice(&dense[row * bw..][..bw]); |
| 29842 | 29903 | } |
| 29843 | - } | |
| 29904 | + out[0] = pred_y; | |
| 29905 | + }; | |
| 29906 | + let pred_y: Vec<u16>; | |
| 29907 | + let sy = if recon_deferred(fctx) { | |
| 29908 | + push_pred(fctx, build); | |
| 29909 | + Pred::Cur { plane: 0, stride: SIDE, off: 0 } | |
| 29910 | + } else { | |
| 29911 | + let mut built: [Vec<u16>; 3] = Default::default(); | |
| 29912 | + build(y, u, v, fctx, &mut built); | |
| 29913 | + let [by, _, _] = built; | |
| 29914 | + pred_y = by; | |
| 29915 | + Pred::Inline(&pred_y, SIDE) | |
| 29916 | + }; | |
| 29844 | 29917 | if skip { |
| 29845 | - push_mc_rect(0, px, py, SIDE, bw, bh, Pred::dense(&pred_y), &ZERO_RESIDUAL[..SIDE * SIDE], fctx); | |
| 29918 | + push_mc_rect(0, px, py, SIDE, bw, bh, sy, &ZERO_RESIDUAL[..SIDE * SIDE], fctx); | |
| 29846 | 29919 | neighbours.record_mi_luma_rect(lmi, bw, bh, &ZERO_RESIDUAL[..bw * bh]); |
| 29847 | 29920 | neighbours.fill_lf_grid_rect(lmi, w_mi, h_mi, bw as u8, bh as u8, ref_frame.max(LAST_FRAME), fctx); |
| 29848 | 29921 | } else { |
| @@ -29850,16 +29923,18 @@ fn decode_inter_sub8_rect2( | ||
| 29850 | 29923 | for (idx, &(row, col, tw, th)) in leaves.iter().enumerate() { |
| 29851 | 29924 | let tu_mi = (rmi + row, cmi + col); |
| 29852 | 29925 | let (tu_px, tu_py) = (px + col * MI, py + row * MI); |
| 29926 | + // This unit's offset into the block prediction (lane-sub8group). | |
| 29927 | + let start = row * MI * SIDE + col * MI; | |
| 29853 | 29928 | let (tu_grid, tu_tx_type) = if tw == th { |
| 29854 | 29929 | // A split `TX_4X4` unit: square reader, its own |
| 29855 | 29930 | // `get_txb_ctx_general` neighbour context (the unit is |
| 29856 | 29931 | // smaller than its plane block, so the lone-TU 0 does not |
| 29857 | 29932 | // apply). |
| 29858 | - let mut tu_pred = Vec::with_capacity(tw * th); | |
| 29859 | - for rr in 0..th { | |
| 29860 | - let start = (row * MI + rr) * SIDE + col * MI; | |
| 29861 | - tu_pred.extend_from_slice(&pred_y[start..start + tw]); | |
| 29862 | - } | |
| 29933 | + // lane-sub8group: the unit's window of the block | |
| 29934 | + // prediction, at the block's stride -- the dense copy the | |
| 29935 | + // parse thread used to make is the recorded op's own | |
| 29936 | + // ([`push_mc_rect_tx`]), and a deferred prediction has no | |
| 29937 | + // buffer here to copy out of. | |
| 29863 | 29938 | let tu_skip_ctx = neighbours.luma_skip_ctx_rect(tu_mi, tw / MI, th / MI); |
| 29864 | 29939 | read_inter_plane( |
| 29865 | 29940 | dec, |
| @@ -29878,7 +29953,7 @@ fn decode_inter_sub8_rect2( | ||
| 29878 | 29953 | tu_py, |
| 29879 | 29954 | tw, |
| 29880 | 29955 | base_q_idx, |
| 29881 | - Pred::dense(&tu_pred), | |
| 29956 | + sy.offset(start), | |
| 29882 | 29957 | None, |
| 29883 | 29958 | Some(tu_skip_ctx), fctx, |
| 29884 | 29959 | )? |
| @@ -29886,7 +29961,6 @@ fn decode_inter_sub8_rect2( | ||
| 29886 | 29961 | // The whole leaf as one `TX_8X4`/`TX_4X8` unit: it IS the |
| 29887 | 29962 | // plane block, so `get_txb_ctx_general` fixes `txb_skip_ctx` |
| 29888 | 29963 | // at 0 (`luma_skip_ctx: None`). |
| 29889 | - let start = row * MI * SIDE + col * MI; | |
| 29890 | 29964 | read_inter_plane_rect( |
| 29891 | 29965 | dec, |
| 29892 | 29966 | cdfs, |
| @@ -29903,7 +29977,7 @@ fn decode_inter_sub8_rect2( | ||
| 29903 | 29977 | y, |
| 29904 | 29978 | tu_px, |
| 29905 | 29979 | tu_py, |
| 29906 | - Pred::dense(&pred_y[start..]), | |
| 29980 | + sy.offset(start), | |
| 29907 | 29981 | None, |
| 29908 | 29982 | None, fctx, |
| 29909 | 29983 | )? |
| @@ -29942,8 +30016,6 @@ fn decode_inter_sub8_rect2( | ||
| 29942 | 30016 | // The group's single 4x4 chroma unit per plane, on the chroma-reference |
| 29943 | 30017 | // (second) sub-block's own skip flag. |
| 29944 | 30018 | const B4: usize = 4; |
| 29945 | - let mut pred_u = vec![0u16; B4 * B4]; | |
| 29946 | - let mut pred_v = vec![0u16; B4 * B4]; | |
| 29947 | 30019 | // `is_sub8x8_inter` (reconinter_template.inc:54) is false as soon as ANY |
| 29948 | 30020 | // mi of the group is intra, so a group whose chroma reference is inter but |
| 29949 | 30021 | // whose sibling is INTRA does NOT get the two-piece sub8x8 prediction: the |
| @@ -29963,64 +30035,92 @@ fn decode_inter_sub8_rect2( | ||
| 29963 | 30035 | (false, true) => (2usize, 4usize), |
| 29964 | 30036 | (false, false) => (4usize, 2usize), |
| 29965 | 30037 | }; |
| 29966 | - for i in 0..2usize { | |
| 29967 | - let Some((ref_frame, mv, h_filter, v_filter)) = piece[i] else { | |
| 29968 | - continue; | |
| 29969 | - }; | |
| 29970 | - let (piece_ref_y, sref_u, sref_v) = | |
| 29971 | - ref_planes(ref_frame, refpix)?; | |
| 29972 | - let piece_scale = mc::scale_factor(piece_ref_y.width, frame_width); | |
| 29973 | - let (ox, oy) = if mixed { | |
| 29974 | - (cpx, cpy) | |
| 29975 | - } else if vert { | |
| 29976 | - (cpx + i * piece_w, cpy) | |
| 29977 | - } else { | |
| 29978 | - (cpx, cpy + i * piece_h) | |
| 29979 | - }; | |
| 29980 | - let (dc, dr) = if mixed { | |
| 29981 | - (0, 0) | |
| 29982 | - } else if vert { | |
| 29983 | - (i * piece_w, 0) | |
| 29984 | - } else { | |
| 29985 | - (0, i * piece_h) | |
| 29986 | - }; | |
| 29987 | - for (plane, dst) in [(sref_u, &mut pred_u), (sref_v, &mut pred_v)] { | |
| 29988 | - let mut buf = vec![0u16; piece_w * piece_h]; | |
| 29989 | - mc::predict_maybe_scaled( | |
| 29990 | - &plane.data, | |
| 29991 | - plane.width, | |
| 29992 | - plane.true_width, | |
| 29993 | - plane.true_height, | |
| 29994 | - mv_to_q4(ox, mv.1, false), | |
| 29995 | - mv_to_q4(oy, mv.0, false), | |
| 29996 | - piece_scale, | |
| 29997 | - piece_w, | |
| 29998 | - piece_h, | |
| 29999 | - h_filter, | |
| 30000 | - v_filter, | |
| 30001 | - &mut buf, fctx, | |
| 30002 | - ); | |
| 30003 | - for row in 0..piece_h { | |
| 30004 | - for col in 0..piece_w { | |
| 30005 | - dst[(dr + row) * B4 + dc + col] = buf[row * piece_w + col]; | |
| 30038 | + // lane-sub8group: the group's chroma pieces, built on the worker that | |
| 30039 | + // writes them -- the pieces' refs/mvs/filters travel by value. | |
| 30040 | + let build = move |_y: &mut PlaneBuf<'static>, | |
| 30041 | + _u: &mut PlaneBuf<'static>, | |
| 30042 | + _v: &mut PlaneBuf<'static>, | |
| 30043 | + fctx: &crate::decode::FrameCtx, | |
| 30044 | + out: &mut [Vec<u16>; 3]| { | |
| 30045 | + let mut pred_u = refill(std::mem::take(&mut out[1]), B4 * B4); | |
| 30046 | + let mut pred_v = refill(std::mem::take(&mut out[2]), B4 * B4); | |
| 30047 | + for i in 0..2usize { | |
| 30048 | + let Some((ref_frame, mv, h_filter, v_filter)) = piece[i] else { | |
| 30049 | + continue; | |
| 30050 | + }; | |
| 30051 | + let Some((piece_ref_y, sref_u, sref_v)) = ref_planes_deferred(ref_frame, refpix) | |
| 30052 | + else { | |
| 30053 | + continue; | |
| 30054 | + }; | |
| 30055 | + let piece_scale = mc::scale_factor(piece_ref_y.width, frame_width); | |
| 30056 | + let (ox, oy) = if mixed { | |
| 30057 | + (cpx, cpy) | |
| 30058 | + } else if vert { | |
| 30059 | + (cpx + i * piece_w, cpy) | |
| 30060 | + } else { | |
| 30061 | + (cpx, cpy + i * piece_h) | |
| 30062 | + }; | |
| 30063 | + let (dc, dr) = if mixed { | |
| 30064 | + (0, 0) | |
| 30065 | + } else if vert { | |
| 30066 | + (i * piece_w, 0) | |
| 30067 | + } else { | |
| 30068 | + (0, i * piece_h) | |
| 30069 | + }; | |
| 30070 | + for (plane, dst) in [(sref_u, &mut pred_u), (sref_v, &mut pred_v)] { | |
| 30071 | + let mut buf = vec![0u16; piece_w * piece_h]; | |
| 30072 | + mc::predict_maybe_scaled( | |
| 30073 | + &plane.data, | |
| 30074 | + plane.width, | |
| 30075 | + plane.true_width, | |
| 30076 | + plane.true_height, | |
| 30077 | + mv_to_q4(ox, mv.1, false), | |
| 30078 | + mv_to_q4(oy, mv.0, false), | |
| 30079 | + piece_scale, | |
| 30080 | + piece_w, | |
| 30081 | + piece_h, | |
| 30082 | + h_filter, | |
| 30083 | + v_filter, | |
| 30084 | + &mut buf, fctx, | |
| 30085 | + ); | |
| 30086 | + for row in 0..piece_h { | |
| 30087 | + for col in 0..piece_w { | |
| 30088 | + dst[(dr + row) * B4 + dc + col] = buf[row * piece_w + col]; | |
| 30089 | + } | |
| 30006 | 30090 | } |
| 30007 | 30091 | } |
| 30008 | 30092 | } |
| 30009 | - } | |
| 30093 | + out[1] = pred_u; | |
| 30094 | + out[2] = pred_v; | |
| 30095 | + }; | |
| 30096 | + let (pred_u, pred_v): (Vec<u16>, Vec<u16>); | |
| 30097 | + let (su, sv) = if recon_deferred(fctx) { | |
| 30098 | + push_pred(fctx, build); | |
| 30099 | + ( | |
| 30100 | + Pred::Cur { plane: 1, stride: B4, off: 0 }, | |
| 30101 | + Pred::Cur { plane: 2, stride: B4, off: 0 }, | |
| 30102 | + ) | |
| 30103 | + } else { | |
| 30104 | + let mut built: [Vec<u16>; 3] = Default::default(); | |
| 30105 | + build(y, u, v, fctx, &mut built); | |
| 30106 | + let [_, bu, bv] = built; | |
| 30107 | + (pred_u, pred_v) = (bu, bv); | |
| 30108 | + (Pred::Inline(&pred_u, B4), Pred::Inline(&pred_v, B4)) | |
| 30109 | + }; | |
| 30010 | 30110 | let (u_grid, v_grid) = if last_skip { |
| 30011 | - push_mc(1, cpx, cpy, B4, Pred::dense(&pred_u), &ZERO_RESIDUAL[..B4 * B4], fctx); | |
| 30012 | - push_mc(2, cpx, cpy, B4, Pred::dense(&pred_v), &ZERO_RESIDUAL[..B4 * B4], fctx); | |
| 30111 | + push_mc(1, cpx, cpy, B4, su, &ZERO_RESIDUAL[..B4 * B4], fctx); | |
| 30112 | + push_mc(2, cpx, cpy, B4, sv, &ZERO_RESIDUAL[..B4 * B4], fctx); | |
| 30013 | 30113 | (Grid::Zero(B4 * B4), Grid::Zero(B4 * B4)) |
| 30014 | 30114 | } else { |
| 30015 | 30115 | let around = neighbours.around_mi(group_mi, 8); |
| 30016 | 30116 | let ug = read_inter_plane( |
| 30017 | 30117 | dec, cdfs, TxbSet::Chroma4, scan4, 1, around[1], 0, u, cpx, cpy, B4, base_q_idx, |
| 30018 | - Pred::dense(&pred_u), Some(first_tx_type), None, fctx, | |
| 30118 | + su, Some(first_tx_type), None, fctx, | |
| 30019 | 30119 | )? |
| 30020 | 30120 | .0; |
| 30021 | 30121 | let vg = read_inter_plane( |
| 30022 | 30122 | dec, cdfs, TxbSet::Chroma4, scan4, 2, around[2], 0, v, cpx, cpy, B4, base_q_idx, |
| 30023 | - Pred::dense(&pred_v), Some(first_tx_type), None, fctx, | |
| 30123 | + sv, Some(first_tx_type), None, fctx, | |
| 30024 | 30124 | )? |
| 30025 | 30125 | .0; |
| 30026 | 30126 | let coded = ug.iter().chain(vg.iter()).any(|&c| c != 0); |