forge
Explore
Log in

Don't you dare go Hollow

Merge branch 'lane-sub8group' (35f7ba64): the four sub-8x8 group predictions build inside PredBuild closures (parse thread makes zero reference-pixel reads, instrumented), rect groups drop the per-unit prediction copy; EC_AV1_TWO_STAGE default ON (4K chain -11..-13% in interleaved runs; =0 restores the old publication point); byte-exact on 20 gate hashes + 6 film cuts

Browse files at this commit

b3aab18ac9fadf8ed2af1b8380f8cae06b6e2502Ahmet Kaan GümüşParent: 36b27a730b0391
crates/ec-av1/src/decode.rsmodified+229 -129
@@ -2253,8 +2253,8 @@ fn dense_residual(residual: &[i32], n: usize) -> &[i32] {
2253 /// block then reads its window out of that slot ([`Pred::Cur`]).2253 /// block then reads its window out of that slot ([`Pred::Cur`]).
2254 #[derive(Clone, Copy)]2254 #[derive(Clone, Copy)]
2255 pub(crate) enum Pred<'a> {2255 pub(crate) enum Pred<'a> {
2256- /// A prediction the parse thread already built. `stride == 0` means "the2256+ /// A prediction the parse thread already built, at its own stride
2257- /// reader's own `stride` argument", which is every pre-lane-wave4 site.2257+ /// (`stride == 0` means "the reader's own `stride` argument").
2258 Inline(&'a [u16], usize),2258 Inline(&'a [u16], usize),
2259 /// The current block's deferred prediction: plane, its stride, and this2259 /// The current block's deferred prediction: plane, its stride, and this
2260 /// unit's offset into it.2260 /// unit's offset into it.
@@ -2262,9 +2262,6 @@ pub(crate) enum Pred<'a> {
2262 }2262 }
2263 2263
2264 impl<'a> Pred<'a> {2264 impl<'a> Pred<'a> {
2265- fn dense(buf: &'a [u16]) -> Self {
2266- Self::Inline(buf, 0)
2267- }
2268 /// The same prediction read at an explicit stride.2265 /// The same prediction read at an explicit stride.
2269 fn view(self, stride: usize) -> Self {2266 fn view(self, stride: usize) -> Self {
2270 match self {2267 match self {
@@ -28686,12 +28683,14 @@ fn decode_inter_sub8_split4(
28686 neighbours.left_ref[rmi],28683 neighbours.left_ref[rmi],
28687 neighbours.left_ref1[rmi],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 // lane-t900 r28: refusal lifted -- this sub-block's own reference may28689 // lane-t900 r28: refusal lifted -- this sub-block's own reference may
28691 // be scaled (superres); spec 7.11.3.3's walk is per reference, and28690 // be scaled (superres); spec 7.11.3.3's walk is per reference, and
28692 // each of the group's pieces (luma and its 2x2 chroma) carries its28691 // each of the group's pieces (luma and its 2x2 chroma) carries its
28693 // OWN factor because each can name a different `ref_frame`.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 if luma_scale != mc::REF_NO_SCALE {28694 if luma_scale != mc::REF_NO_SCALE {
28696 SCALED_SUB8_HITS.with(|c| c.set(c.get() + 1));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 piece[i] = Some((ref_frame, mv, h_filter, v_filter));28855 piece[i] = Some((ref_frame, mv, h_filter, v_filter));
28857- let mut pred_y = vec![0u16; B4 * B4];28856+ // lane-sub8group: this piece's prediction as a closure, so it runs
28858- mc::predict_maybe_scaled(28857+ // where its writes run -- on a recon worker at more than one
28859- &sref_y.data,28858+ // reconstruction thread, exactly like the 8x8 leaf's.
28860- sref_y.width,28859+ let build = move |_y: &mut PlaneBuf<'static>,
28861- sref_y.true_width,28860+ _u: &mut PlaneBuf<'static>,
28862- sref_y.true_height,28861+ _v: &mut PlaneBuf<'static>,
28863- mv_to_q4(px, mv.1, true),28862+ fctx: &crate::decode::FrameCtx,
28864- mv_to_q4(py, mv.0, true),28863+ out: &mut [Vec<u16>; 3]| {
28865- luma_scale,28864+ let Some((sref_y, _, _)) = ref_planes_deferred(ref_frame, refpix) else {
28866- B4,28865+ return;
28867- B4,28866+ };
28868- h_filter,28867+ let mut pred_y = refill(std::mem::take(&mut out[0]), B4 * B4);
28869- v_filter,28868+ mc::predict_maybe_scaled(
28870- &mut pred_y, fctx,28869+ &sref_y.data,
28871- );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 // `BLOCK_4X4` never signals a transform size, so the luma unit is the28895 // `BLOCK_4X4` never signals a transform size, so the luma unit is the
28873 // whole block and `get_txb_ctx` takes its `plane_bsize ==28896 // whole block and `get_txb_ctx` takes its `plane_bsize ==
28874 // txsize_to_bsize[tx_size]` branch (`txb_skip_ctx = 0`, which28897 // txsize_to_bsize[tx_size]` branch (`txb_skip_ctx = 0`, which
28875 // `read_inter_plane`'s `plane_idx == 0` arm already assumes).28898 // `read_inter_plane`'s `plane_idx == 0` arm already assumes).
28876 if skip {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 neighbours.record_mi_luma_rect(lmi, B4, B4, &ZERO_RESIDUAL[..B4 * B4]);28901 neighbours.record_mi_luma_rect(lmi, B4, B4, &ZERO_RESIDUAL[..B4 * B4]);
28879 } else {28902 } else {
28880 let around = neighbours.around_mi(lmi, B4);28903 let around = neighbours.around_mi(lmi, B4);
@@ -28895,7 +28918,7 @@ fn decode_inter_sub8_split4(
28895 py,28918 py,
28896 B4,28919 B4,
28897 base_q_idx,28920 base_q_idx,
28898- Pred::dense(&pred_y),28921+ sy,
28899 None,28922 None,
28900 None, fctx,28923 None, fctx,
28901 )?;28924 )?;
@@ -28934,8 +28957,6 @@ fn decode_inter_sub8_split4(
28934 // Chroma, once for the whole group, on the last sub-block's own `skip`28957 // Chroma, once for the whole group, on the last sub-block's own `skip`
28935 // flag -- prediction from all four sub-blocks (2x2 pieces), residual as28958 // flag -- prediction from all four sub-blocks (2x2 pieces), residual as
28936 // one TX_4X4 unit per plane.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 // `is_sub8x8_inter` (reconinter_template.inc:54) is false as soon as ANY28960 // `is_sub8x8_inter` (reconinter_template.inc:54) is false as soon as ANY
28940 // mi of the group is intra: the group's 4x4 chroma is then predicted WHOLE28961 // mi of the group is intra: the group's 4x4 chroma is then predicted WHOLE
28941 // from the chroma-reference (last) sub-block's own mv, not in 2x2 pieces.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 h.set(st);28968 h.set(st);
28948 });28969 });
28949 }28970 }
28950- for i in 0..4usize {28971+ // lane-sub8group: the group's chroma pieces, built on the worker that
28951- let (dr, dc) = (i / 2, i % 2);28972+ // writes them -- the pieces' refs/mvs/filters travel by value.
28952- if mixed && i != 3 {28973+ let build = move |_y: &mut PlaneBuf<'static>,
28953- continue;28974+ _u: &mut PlaneBuf<'static>,
28954- }28975+ _v: &mut PlaneBuf<'static>,
28955- let Some((ref_frame, mv, h_filter, v_filter)) = piece[i] else {28976+ fctx: &crate::decode::FrameCtx,
28956- continue;28977+ out: &mut [Vec<u16>; 3]| {
28957- };28978+ let mut pred_u = refill(std::mem::take(&mut out[1]), B4 * B4);
28958- let (piece_ref_y, sref_u, sref_v) =28979+ let mut pred_v = refill(std::mem::take(&mut out[2]), B4 * B4);
28959- ref_planes(ref_frame, refpix)?;28980+ for i in 0..4usize {
28960- let piece_scale = mc::scale_factor(piece_ref_y.width, frame_width);28981+ let (dr, dc) = (i / 2, i % 2);
28961- let (ox, oy) = if mixed {28982+ if mixed && i != 3 {
28962- (cpx, cpy)28983+ continue;
28963- } else {28984+ }
28964- (cpx + dc * 2, cpy + dr * 2)28985+ let Some((ref_frame, mv, h_filter, v_filter)) = piece[i] else {
28965- };28986+ continue;
28966- let (pw, ph) = if mixed { (B4, B4) } else { (2, 2) };28987+ };
28967- let (row0, col0) = if mixed { (0, 0) } else { (dr * 2, dc * 2) };28988+ let Some((piece_ref_y, sref_u, sref_v)) = ref_planes_deferred(ref_frame, refpix)
28968- for (plane, dst) in [(sref_u, &mut pred_u), (sref_v, &mut pred_v)] {28989+ else {
28969- let mut buf = vec![0u16; pw * ph];28990+ continue;
28970- mc::predict_maybe_scaled(28991+ };
28971- &plane.data,28992+ let piece_scale = mc::scale_factor(piece_ref_y.width, frame_width);
28972- plane.width,28993+ let (ox, oy) = if mixed {
28973- plane.true_width,28994+ (cpx, cpy)
28974- plane.true_height,28995+ } else {
28975- mv_to_q4(ox, mv.1, false),28996+ (cpx + dc * 2, cpy + dr * 2)
28976- mv_to_q4(oy, mv.0, false),28997+ };
28977- piece_scale,28998+ let (pw, ph) = if mixed { (B4, B4) } else { (2, 2) };
28978- pw,28999+ let (row0, col0) = if mixed { (0, 0) } else { (dr * 2, dc * 2) };
28979- ph,29000+ for (plane, dst) in [(sref_u, &mut pred_u), (sref_v, &mut pred_v)] {
28980- h_filter,29001+ let mut buf = vec![0u16; pw * ph];
28981- v_filter,29002+ mc::predict_maybe_scaled(
28982- &mut buf, fctx,29003+ &plane.data,
28983- );29004+ plane.width,
28984- for row in 0..ph {29005+ plane.true_width,
28985- for col in 0..pw {29006+ plane.true_height,
28986- dst[(row0 + row) * B4 + col0 + col] = buf[row * pw + col];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 let (u_grid, v_grid) = if last_skip {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);29041+ push_mc(1, cpx, cpy, B4, su, &ZERO_RESIDUAL[..B4 * B4], fctx);
28993- push_mc(2, cpx, cpy, B4, Pred::dense(&pred_v), &ZERO_RESIDUAL[..B4 * B4], fctx);29042+ push_mc(2, cpx, cpy, B4, sv, &ZERO_RESIDUAL[..B4 * B4], fctx);
28994 (Grid::Zero(B4 * B4), Grid::Zero(B4 * B4))29043 (Grid::Zero(B4 * B4), Grid::Zero(B4 * B4))
28995 } else {29044 } else {
28996 let around = neighbours.around_mi(group_mi, 8);29045 let around = neighbours.around_mi(group_mi, 8);
28997 let ug = read_inter_plane(29046 let ug = read_inter_plane(
28998 dec, cdfs, TxbSet::Chroma4, scan4, 1, around[1], 0, u, cpx, cpy, B4, base_q_idx,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 .0;29050 .0;
29002 let vg = read_inter_plane(29051 let vg = read_inter_plane(
29003 dec, cdfs, TxbSet::Chroma4, scan4, 2, around[2], 0, v, cpx, cpy, B4, base_q_idx,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 .0;29055 .0;
29007 let coded = ug.iter().chain(vg.iter()).any(|&c| c != 0);29056 let coded = ug.iter().chain(vg.iter()).any(|&c| c != 0);
@@ -29656,9 +29705,11 @@ fn decode_inter_sub8_rect2(
29656 neighbours.left_ref[rmi],29705 neighbours.left_ref[rmi],
29657 neighbours.left_ref1[rmi],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 // lane-t900 r28: refusal lifted -- see the split arm above.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 if luma_scale != mc::REF_NO_SCALE {29713 if luma_scale != mc::REF_NO_SCALE {
29663 SCALED_SUB8_HITS.with(|c| c.set(c.get() + 1));29714 SCALED_SUB8_HITS.with(|c| c.set(c.get() + 1));
29664 }29715 }
@@ -29820,8 +29871,18 @@ fn decode_inter_sub8_rect2(
29820 // Prediction over the leaf's true footprint, laid out at the group's29871 // Prediction over the leaf's true footprint, laid out at the group's
29821 // square stride (what `reconstruct_mc_rect` and `read_inter_plane_rect`29872 // square stride (what `reconstruct_mc_rect` and `read_inter_plane_rect`
29822 // index with).29873 // index with).
29823- let mut pred_y = vec![0u16; SIDE * SIDE];29874+ // lane-sub8group: this piece's prediction as a closure, so it runs
29824- {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 let mut dense = vec![0u16; bw * bh];29886 let mut dense = vec![0u16; bw * bh];
29826 mc::predict_maybe_scaled(29887 mc::predict_maybe_scaled(
29827 &sref_y.data,29888 &sref_y.data,
@@ -29840,9 +29901,21 @@ fn decode_inter_sub8_rect2(
29840 for row in 0..bh {29901 for row in 0..bh {
29841 pred_y[row * SIDE..][..bw].copy_from_slice(&dense[row * bw..][..bw]);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 if skip {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 neighbours.record_mi_luma_rect(lmi, bw, bh, &ZERO_RESIDUAL[..bw * bh]);29919 neighbours.record_mi_luma_rect(lmi, bw, bh, &ZERO_RESIDUAL[..bw * bh]);
29847 neighbours.fill_lf_grid_rect(lmi, w_mi, h_mi, bw as u8, bh as u8, ref_frame.max(LAST_FRAME), fctx);29920 neighbours.fill_lf_grid_rect(lmi, w_mi, h_mi, bw as u8, bh as u8, ref_frame.max(LAST_FRAME), fctx);
29848 } else {29921 } else {
@@ -29850,16 +29923,18 @@ fn decode_inter_sub8_rect2(
29850 for (idx, &(row, col, tw, th)) in leaves.iter().enumerate() {29923 for (idx, &(row, col, tw, th)) in leaves.iter().enumerate() {
29851 let tu_mi = (rmi + row, cmi + col);29924 let tu_mi = (rmi + row, cmi + col);
29852 let (tu_px, tu_py) = (px + col * MI, py + row * MI);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 let (tu_grid, tu_tx_type) = if tw == th {29928 let (tu_grid, tu_tx_type) = if tw == th {
29854 // A split `TX_4X4` unit: square reader, its own29929 // A split `TX_4X4` unit: square reader, its own
29855 // `get_txb_ctx_general` neighbour context (the unit is29930 // `get_txb_ctx_general` neighbour context (the unit is
29856 // smaller than its plane block, so the lone-TU 0 does not29931 // smaller than its plane block, so the lone-TU 0 does not
29857 // apply).29932 // apply).
29858- let mut tu_pred = Vec::with_capacity(tw * th);29933+ // lane-sub8group: the unit's window of the block
29859- for rr in 0..th {29934+ // prediction, at the block's stride -- the dense copy the
29860- let start = (row * MI + rr) * SIDE + col * MI;29935+ // parse thread used to make is the recorded op's own
29861- tu_pred.extend_from_slice(&pred_y[start..start + tw]);29936+ // ([`push_mc_rect_tx`]), and a deferred prediction has no
29862- }29937+ // buffer here to copy out of.
29863 let tu_skip_ctx = neighbours.luma_skip_ctx_rect(tu_mi, tw / MI, th / MI);29938 let tu_skip_ctx = neighbours.luma_skip_ctx_rect(tu_mi, tw / MI, th / MI);
29864 read_inter_plane(29939 read_inter_plane(
29865 dec,29940 dec,
@@ -29878,7 +29953,7 @@ fn decode_inter_sub8_rect2(
29878 tu_py,29953 tu_py,
29879 tw,29954 tw,
29880 base_q_idx,29955 base_q_idx,
29881- Pred::dense(&tu_pred),29956+ sy.offset(start),
29882 None,29957 None,
29883 Some(tu_skip_ctx), fctx,29958 Some(tu_skip_ctx), fctx,
29884 )?29959 )?
@@ -29886,7 +29961,6 @@ fn decode_inter_sub8_rect2(
29886 // The whole leaf as one `TX_8X4`/`TX_4X8` unit: it IS the29961 // The whole leaf as one `TX_8X4`/`TX_4X8` unit: it IS the
29887 // plane block, so `get_txb_ctx_general` fixes `txb_skip_ctx`29962 // plane block, so `get_txb_ctx_general` fixes `txb_skip_ctx`
29888 // at 0 (`luma_skip_ctx: None`).29963 // at 0 (`luma_skip_ctx: None`).
29889- let start = row * MI * SIDE + col * MI;
29890 read_inter_plane_rect(29964 read_inter_plane_rect(
29891 dec,29965 dec,
29892 cdfs,29966 cdfs,
@@ -29903,7 +29977,7 @@ fn decode_inter_sub8_rect2(
29903 y,29977 y,
29904 tu_px,29978 tu_px,
29905 tu_py,29979 tu_py,
29906- Pred::dense(&pred_y[start..]),29980+ sy.offset(start),
29907 None,29981 None,
29908 None, fctx,29982 None, fctx,
29909 )?29983 )?
@@ -29942,8 +30016,6 @@ fn decode_inter_sub8_rect2(
29942 // The group's single 4x4 chroma unit per plane, on the chroma-reference30016 // The group's single 4x4 chroma unit per plane, on the chroma-reference
29943 // (second) sub-block's own skip flag.30017 // (second) sub-block's own skip flag.
29944 const B4: usize = 4;30018 const B4: usize = 4;
29945- let mut pred_u = vec![0u16; B4 * B4];
29946- let mut pred_v = vec![0u16; B4 * B4];
29947 // `is_sub8x8_inter` (reconinter_template.inc:54) is false as soon as ANY30019 // `is_sub8x8_inter` (reconinter_template.inc:54) is false as soon as ANY
29948 // mi of the group is intra, so a group whose chroma reference is inter but30020 // mi of the group is intra, so a group whose chroma reference is inter but
29949 // whose sibling is INTRA does NOT get the two-piece sub8x8 prediction: the30021 // whose sibling is INTRA does NOT get the two-piece sub8x8 prediction: the
@@ -29963,64 +30035,92 @@ fn decode_inter_sub8_rect2(
29963 (false, true) => (2usize, 4usize),30035 (false, true) => (2usize, 4usize),
29964 (false, false) => (4usize, 2usize),30036 (false, false) => (4usize, 2usize),
29965 };30037 };
29966- for i in 0..2usize {30038+ // lane-sub8group: the group's chroma pieces, built on the worker that
29967- let Some((ref_frame, mv, h_filter, v_filter)) = piece[i] else {30039+ // writes them -- the pieces' refs/mvs/filters travel by value.
29968- continue;30040+ let build = move |_y: &mut PlaneBuf<'static>,
29969- };30041+ _u: &mut PlaneBuf<'static>,
29970- let (piece_ref_y, sref_u, sref_v) =30042+ _v: &mut PlaneBuf<'static>,
29971- ref_planes(ref_frame, refpix)?;30043+ fctx: &crate::decode::FrameCtx,
29972- let piece_scale = mc::scale_factor(piece_ref_y.width, frame_width);30044+ out: &mut [Vec<u16>; 3]| {
29973- let (ox, oy) = if mixed {30045+ let mut pred_u = refill(std::mem::take(&mut out[1]), B4 * B4);
29974- (cpx, cpy)30046+ let mut pred_v = refill(std::mem::take(&mut out[2]), B4 * B4);
29975- } else if vert {30047+ for i in 0..2usize {
29976- (cpx + i * piece_w, cpy)30048+ let Some((ref_frame, mv, h_filter, v_filter)) = piece[i] else {
29977- } else {30049+ continue;
29978- (cpx, cpy + i * piece_h)30050+ };
29979- };30051+ let Some((piece_ref_y, sref_u, sref_v)) = ref_planes_deferred(ref_frame, refpix)
29980- let (dc, dr) = if mixed {30052+ else {
29981- (0, 0)30053+ continue;
29982- } else if vert {30054+ };
29983- (i * piece_w, 0)30055+ let piece_scale = mc::scale_factor(piece_ref_y.width, frame_width);
29984- } else {30056+ let (ox, oy) = if mixed {
29985- (0, i * piece_h)30057+ (cpx, cpy)
29986- };30058+ } else if vert {
29987- for (plane, dst) in [(sref_u, &mut pred_u), (sref_v, &mut pred_v)] {30059+ (cpx + i * piece_w, cpy)
29988- let mut buf = vec![0u16; piece_w * piece_h];30060+ } else {
29989- mc::predict_maybe_scaled(30061+ (cpx, cpy + i * piece_h)
29990- &plane.data,30062+ };
29991- plane.width,30063+ let (dc, dr) = if mixed {
29992- plane.true_width,30064+ (0, 0)
29993- plane.true_height,30065+ } else if vert {
29994- mv_to_q4(ox, mv.1, false),30066+ (i * piece_w, 0)
29995- mv_to_q4(oy, mv.0, false),30067+ } else {
29996- piece_scale,30068+ (0, i * piece_h)
29997- piece_w,30069+ };
29998- piece_h,30070+ for (plane, dst) in [(sref_u, &mut pred_u), (sref_v, &mut pred_v)] {
29999- h_filter,30071+ let mut buf = vec![0u16; piece_w * piece_h];
30000- v_filter,30072+ mc::predict_maybe_scaled(
30001- &mut buf, fctx,30073+ &plane.data,
30002- );30074+ plane.width,
30003- for row in 0..piece_h {30075+ plane.true_width,
30004- for col in 0..piece_w {30076+ plane.true_height,
30005- dst[(dr + row) * B4 + dc + col] = buf[row * piece_w + col];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 let (u_grid, v_grid) = if last_skip {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);30111+ push_mc(1, cpx, cpy, B4, su, &ZERO_RESIDUAL[..B4 * B4], fctx);
30012- push_mc(2, cpx, cpy, B4, Pred::dense(&pred_v), &ZERO_RESIDUAL[..B4 * B4], fctx);30112+ push_mc(2, cpx, cpy, B4, sv, &ZERO_RESIDUAL[..B4 * B4], fctx);
30013 (Grid::Zero(B4 * B4), Grid::Zero(B4 * B4))30113 (Grid::Zero(B4 * B4), Grid::Zero(B4 * B4))
30014 } else {30114 } else {
30015 let around = neighbours.around_mi(group_mi, 8);30115 let around = neighbours.around_mi(group_mi, 8);
30016 let ug = read_inter_plane(30116 let ug = read_inter_plane(
30017 dec, cdfs, TxbSet::Chroma4, scan4, 1, around[1], 0, u, cpx, cpy, B4, base_q_idx,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 .0;30120 .0;
30021 let vg = read_inter_plane(30121 let vg = read_inter_plane(
30022 dec, cdfs, TxbSet::Chroma4, scan4, 2, around[2], 0, v, cpx, cpy, B4, base_q_idx,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 .0;30125 .0;
30026 let coded = ug.iter().chain(vg.iter()).any(|&c| c != 0);30126 let coded = ug.iter().chain(vg.iter()).any(|&c| c != 0);
crates/ec-av1/src/stream.rsmodified+11 -12
@@ -1006,18 +1006,17 @@ pub fn decode_stream_with_threads(
1006 decode_idx,1006 decode_idx,
1007 shown_idx,1007 shown_idx,
1008 dump.as_deref(),1008 dump.as_deref(),
1009- // lane-twostage is OFF by default: it is byte-exact1009+ // lane-twostage publishes a frame's meta at its tile
1010- // and the chain shows the producer tail overlapped,1010+ // boundary instead of after its filters, so a consumer
1011- // but it does not move the wall (the consumer parses1011+ // parses over its producer's filter tail. It is ON by
1012- // only 4.2% of its tile before its first reference1012+ // default since lane-sub8group: with every reference
1013- // pixel read, which is shorter than the tail it1013+ // pixel read deferred to the recon workers, the
1014- // hides). `EC_AV1_TWO_STAGE=1` publishes a frame's1014+ // consumer parses its WHOLE tile before it needs a
1015- // meta at its tile boundary instead of after its1015+ // pixel, and the 4K critical chain shortens by 11-14%
1016- // filters; it pays only once the 8x8-leaf, OBMC and1016+ // in three interleaved pairs (14450/10594/14407 ms off
1017- // sub-8x8-piece predictions are deferred to the recon1017+ // vs 12790/9207/12463 ms on) where it moved 3-7%
1018- // workers as well.1018+ // before. `EC_AV1_TWO_STAGE=0` turns it back off.
1019- crate::envflags::var("EC_AV1_TWO_STAGE")1019+ (crate::envflags::var("EC_AV1_TWO_STAGE").as_deref() != Ok("0"))
1020- .is_ok_and(|v| v == "1")
1021 .then_some(&stage1 as &dyn Fn(_, _, _, _)),1020 .then_some(&stage1 as &dyn Fn(_, _, _, _)),
1022 )?;1021 )?;
1023 // Publish before grain synthesis: every frame waiting on1022 // Publish before grain synthesis: every frame waiting on