forge
Explore
Log in

Don't you dare go Hollow

OBMC neighbour prediction size is the block's own width/height, not the frame-edge clamp

Browse files at this commit

715a65dc5fde63c5c46103b474cce943f71ca9ccAhmet Kaan GümüşParent: deea6ff
  • fix
    • OBMC neighbour prediction size is the block's own width/height, not the frame-edge clamp
Show full message
fix(av1): OBMC neighbour prediction size is the block's own width/height, not the frame-edge clamp

libaom's foreach_overlappable_nb_above/left pass op_mi_size =
AOMMIN(xd->width|height, mi_step); we clamped the span to end_col/end_row
(mi_cols/mi_rows), so a block overhanging the frame edge predicted a SHORTER
neighbour strip -- and at 4 chroma rows that flips the vertical kernel to the
4-tap narrow one (class narrow-block-sharp-kernel), giving a 1-off in the
last valid chroma row of the blend. Predict at the full op_mi_size and clip
only the write into this block's own buffer (obmc_blend_v gains the tmp
stride). 10-bit 1920x792 267-frame cut: 36 differing frames (worst 13 B) -> 0.
crates/ec-av1/src/decode.rsmodified+36 -10
@@ -18843,7 +18843,13 @@ fn overlappable_above(
18843 if src != col {18843 if src != col {
18844 OBMC_PAIR_FILTER_HITS.with(|c| c.set(c.get() + 1));18844 OBMC_PAIR_FILTER_HITS.with(|c| c.set(c.get() + 1));
18845 }18845 }
18846- out.push((col - mi_col, step.min(end_col - col), *info, src - mi_col));18846+ // lane-t900 r14: libaom passes `AOMMIN(xd->width, mi_step)`
18847+ // as `op_mi_size` -- the block's OWN width, never the
18848+ // frame-edge clamp `end_col` carries. Clamping here shrank the
18849+ // neighbour PREDICTION at a frame edge, which picks the
18850+ // 4-tap kernel below 8 px (class narrow-block-sharp-kernel);
18851+ // the destination clip stays in `obmc_blend`.
18852+ out.push((col - mi_col, step.min(bw4), *info, src - mi_col));
18847 }18853 }
18848 }18854 }
18849 col += step;18855 col += step;
@@ -18889,7 +18895,9 @@ fn overlappable_left(
18889 if src != row {18895 if src != row {
18890 OBMC_PAIR_FILTER_HITS.with(|c| c.set(c.get() + 1));18896 OBMC_PAIR_FILTER_HITS.with(|c| c.set(c.get() + 1));
18891 }18897 }
18892- out.push((row - mi_row, step.min(end_row - row), *info, src - mi_row));18898+ // lane-t900 r14: `AOMMIN(xd->height, mi_step)` -- see
18899+ // `overlappable_above`.
18900+ out.push((row - mi_row, step.min(bh4), *info, src - mi_row));
18893 }18901 }
18894 }18902 }
18895 row += step;18903 row += step;
@@ -19355,13 +19363,17 @@ fn interintra_blend(
19355 }19363 }
19356 }19364 }
19357 19365
19358-fn obmc_blend_v(dst: &mut [u16], stride: usize, ox: usize, oy: usize, w: usize, h: usize, tmp: &[u16]) {19366+/// `w` is the number of columns actually written (clipped to the block's own
19367+/// buffer at a frame edge); `ts` is `tmp`'s own stride, the neighbour
19368+/// prediction's full width.
19369+#[allow(clippy::too_many_arguments)]
19370+fn obmc_blend_v(dst: &mut [u16], stride: usize, ox: usize, oy: usize, w: usize, h: usize, ts: usize, tmp: &[u16]) {
19359 let mask = obmc_mask(h);19371 let mask = obmc_mask(h);
19360 for row in 0..h {19372 for row in 0..h {
19361 let m = u32::from(mask[row]);19373 let m = u32::from(mask[row]);
19362 for col in 0..w {19374 for col in 0..w {
19363 let d = &mut dst[(oy + row) * stride + ox + col];19375 let d = &mut dst[(oy + row) * stride + ox + col];
19364- let t = u32::from(tmp[row * w + col]);19376+ let t = u32::from(tmp[row * ts + col]);
19365 *d = ((m * u32::from(*d) + (64 - m) * t + 32) >> 6) as u16;19377 *d = ((m * u32::from(*d) + (64 - m) * t + 32) >> 6) as u16;
19366 }19378 }
19367 }19379 }
@@ -19586,8 +19598,10 @@ fn obmc_blend(
19586 let (ny, nu, nv) = ref_planes(nb.ref_frame, ref_y, ref_u, ref_v, other_refs)?;19598 let (ny, nu, nv) = ref_planes(nb.ref_frame, ref_y, ref_u, ref_v, other_refs)?;
19587 let nb_scale = mc::scale_factor(ny.width, frame_width);19599 let nb_scale = mc::scale_factor(ny.width, frame_width);
19588 let (bw, bh, ox) = (span4 * 4, overlap_above, off4 * 4);19600 let (bw, bh, ox) = (span4 * 4, overlap_above, off4 * 4);
19601+ // lane-t900 r14: the prediction is `op_mi_size` wide (kernel choice
19602+ // included); only the WRITE is clipped to this block's own buffer.
19589 let tmp_y = obmc_neighbour_pred(ny, px + ox, py, nb.mv, bw, bh, true, h_kind, v_kind, nb_scale);19603 let tmp_y = obmc_neighbour_pred(ny, px + ox, py, nb.mv, bw, bh, true, h_kind, v_kind, nb_scale);
19590- obmc_blend_v(pred_y, side, ox, 0, bw, bh, &tmp_y);19604+ obmc_blend_v(pred_y, side, ox, 0, bw.min(write_w - ox), bh, bw, &tmp_y);
19591 if !skip_chroma_above {19605 if !skip_chroma_above {
19592 // lane-t900 r13 (measured, NOT a defect): libaom's min-4 clamp19606 // lane-t900 r13 (measured, NOT a defect): libaom's min-4 clamp
19593 // (`dec_build_prediction_by_above_pred`) sizes only the OBMC19607 // (`dec_build_prediction_by_above_pred`) sizes only the OBMC
@@ -19597,10 +19611,11 @@ fn obmc_blend(
19597 // 1920x792 cut that went 36 differing frames -> 266, worst19611 // 1920x792 cut that went 36 differing frames -> 266, worst
19598 // 13 B -> 11007 B.19612 // 13 B -> 11007 B.
19599 let (cbw, cbh, cox) = (bw / 2, overlap_above / 2, ox / 2);19613 let (cbw, cbh, cox) = (bw / 2, overlap_above / 2, ox / 2);
19614+ let cw = cbw.min(write_w / 2 - cox);
19600 let tmp_u = obmc_neighbour_pred(nu, cpx + cox, cpy, nb.mv, cbw, cbh, false, h_kind, v_kind, nb_scale);19615 let tmp_u = obmc_neighbour_pred(nu, cpx + cox, cpy, nb.mv, cbw, cbh, false, h_kind, v_kind, nb_scale);
19601- obmc_blend_v(pred_u, chroma_side, cox, 0, cbw, cbh, &tmp_u);19616+ obmc_blend_v(pred_u, chroma_side, cox, 0, cw, cbh, cbw, &tmp_u);
19602 let tmp_v = obmc_neighbour_pred(nv, cpx + cox, cpy, nb.mv, cbw, cbh, false, h_kind, v_kind, nb_scale);19617 let tmp_v = obmc_neighbour_pred(nv, cpx + cox, cpy, nb.mv, cbw, cbh, false, h_kind, v_kind, nb_scale);
19603- obmc_blend_v(pred_v, chroma_side, cox, 0, cbw, cbh, &tmp_v);19618+ obmc_blend_v(pred_v, chroma_side, cox, 0, cw, cbh, cbw, &tmp_v);
19604 }19619 }
19605 }19620 }
19606 19621
@@ -19617,12 +19632,23 @@ fn obmc_blend(
19617 let nb_scale = mc::scale_factor(ny.width, frame_width);19632 let nb_scale = mc::scale_factor(ny.width, frame_width);
19618 let (bw, bh, oy) = (overlap_left, span4 * 4, off4 * 4);19633 let (bw, bh, oy) = (overlap_left, span4 * 4, off4 * 4);
19619 let tmp_y = obmc_neighbour_pred(ny, px, py + oy, nb.mv, bw, bh, true, h_kind, v_kind, nb_scale);19634 let tmp_y = obmc_neighbour_pred(ny, px, py + oy, nb.mv, bw, bh, true, h_kind, v_kind, nb_scale);
19620- obmc_blend_h(pred_y, side, 0, oy, bw, bh, &tmp_y);19635+ obmc_blend_h(pred_y, side, 0, oy, bw, bh.min(write_h - oy), &tmp_y);
19621 let (cbw, cbh, coy) = (overlap_left / 2, bh / 2, oy / 2);19636 let (cbw, cbh, coy) = (overlap_left / 2, bh / 2, oy / 2);
19622 let tmp_u = obmc_neighbour_pred(nu, cpx, cpy + coy, nb.mv, cbw, cbh, false, h_kind, v_kind, nb_scale);19637 let tmp_u = obmc_neighbour_pred(nu, cpx, cpy + coy, nb.mv, cbw, cbh, false, h_kind, v_kind, nb_scale);
19623- obmc_blend_h(pred_u, chroma_side, 0, coy, cbw, cbh, &tmp_u);19638+ if let Some((_, _, idx)) = ec_mcb {
19639+ eprintln!(
19640+ "OUR_MCB left f={idx} off4={off4} span4={span4} cbw={cbw} cbh={cbh} coy={coy} mv=({},{}) ref0={}",
19641+ nb.mv.0, nb.mv.1, nb.ref_frame
19642+ );
19643+ for r in 0..cbh {
19644+ let row: Vec<u16> = (0..cbw).map(|c| tmp_u[r * cbw + c]).collect();
19645+ eprintln!("OUR_MCB lrow{r}: {row:?}");
19646+ }
19647+ }
19648+ let ch = cbh.min(write_h / 2 - coy);
19649+ obmc_blend_h(pred_u, chroma_side, 0, coy, cbw, ch, &tmp_u);
19624 let tmp_v = obmc_neighbour_pred(nv, cpx, cpy + coy, nb.mv, cbw, cbh, false, h_kind, v_kind, nb_scale);19650 let tmp_v = obmc_neighbour_pred(nv, cpx, cpy + coy, nb.mv, cbw, cbh, false, h_kind, v_kind, nb_scale);
19625- obmc_blend_h(pred_v, chroma_side, 0, coy, cbw, cbh, &tmp_v);19651+ obmc_blend_h(pred_v, chroma_side, 0, coy, cbw, ch, &tmp_v);
19626 }19652 }
19627 if let Some((_, _, idx)) = ec_mcb {19653 if let Some((_, _, idx)) = ec_mcb {
19628 for r in 0..write_h / 2 {19654 for r in 0..write_h / 2 {