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(
1884318843 if src != col {
1884418844 OBMC_PAIR_FILTER_HITS.with(|c| c.set(c.get() + 1));
1884518845 }
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));
1884718853 }
1884818854 }
1884918855 col += step;
@@ -18889,7 +18895,9 @@ fn overlappable_left(
1888918895 if src != row {
1889018896 OBMC_PAIR_FILTER_HITS.with(|c| c.set(c.get() + 1));
1889118897 }
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));
1889318901 }
1889418902 }
1889518903 row += step;
@@ -19355,13 +19363,17 @@ fn interintra_blend(
1935519363 }
1935619364 }
1935719365
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]) {
1935919371 let mask = obmc_mask(h);
1936019372 for row in 0..h {
1936119373 let m = u32::from(mask[row]);
1936219374 for col in 0..w {
1936319375 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]);
1936519377 *d = ((m * u32::from(*d) + (64 - m) * t + 32) >> 6) as u16;
1936619378 }
1936719379 }
@@ -19586,8 +19598,10 @@ fn obmc_blend(
1958619598 let (ny, nu, nv) = ref_planes(nb.ref_frame, ref_y, ref_u, ref_v, other_refs)?;
1958719599 let nb_scale = mc::scale_factor(ny.width, frame_width);
1958819600 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.
1958919603 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);
1959119605 if !skip_chroma_above {
1959219606 // lane-t900 r13 (measured, NOT a defect): libaom's min-4 clamp
1959319607 // (`dec_build_prediction_by_above_pred`) sizes only the OBMC
@@ -19597,10 +19611,11 @@ fn obmc_blend(
1959719611 // 1920x792 cut that went 36 differing frames -> 266, worst
1959819612 // 13 B -> 11007 B.
1959919613 let (cbw, cbh, cox) = (bw / 2, overlap_above / 2, ox / 2);
19614+ let cw = cbw.min(write_w / 2 - cox);
1960019615 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);
1960219617 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);
1960419619 }
1960519620 }
1960619621
@@ -19617,12 +19632,23 @@ fn obmc_blend(
1961719632 let nb_scale = mc::scale_factor(ny.width, frame_width);
1961819633 let (bw, bh, oy) = (overlap_left, span4 * 4, off4 * 4);
1961919634 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);
1962119636 let (cbw, cbh, coy) = (overlap_left / 2, bh / 2, oy / 2);
1962219637 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);
1962419650 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);
1962619652 }
1962719653 if let Some((_, _, idx)) = ec_mcb {
1962819654 for r in 0..write_h / 2 {