From ef383d94d4cfd6950441c03eef89ed5fa6d57048 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Thu, 27 Aug 2026 05:54:06 +0300 Subject: [PATCH] perf(av1): bypass sub-pel filtering for whole-pel motion prediction Profiled the inter path (stage_timing_breakdown_inter, 720p GOP): 403 of a 408ms motion-search bucket was crate::mc::predict, almost entirely from the search's own whole-pel log/diamond stage. SUBPEL_FILTERS[0] is the identity tap and both rounding shifts are exactly that filter's gain, so the two 8-tap passes reproduce the reference sample byte-for-byte at zero fraction (integer_mv_is_identity already pinned this) -- a clamped direct copy is bit-identical, not an approximation. Motion search bucket 408.55ms -> 181.85ms, frame total 818.88ms -> 585.24ms, same 997 output bytes. --- crates/ec-av1/src/mc.rs | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/crates/ec-av1/src/mc.rs b/crates/ec-av1/src/mc.rs index 74ec3049..4ddcfb05 100644 --- a/crates/ec-av1/src/mc.rs +++ b/crates/ec-av1/src/mc.rs @@ -111,6 +111,32 @@ pub fn predict( let y0 = y_q4.div_euclid(16); let yfrac = y_q4.rem_euclid(16) as usize; + // Whole-pel fast path: `SUBPEL_FILTERS[0]` is the identity tap (`128` at + // its centre, everything else `0`), and both rounding shifts are exactly + // that filter's own gain (see `INTER_ROUND_1`'s doc comment), so the two + // 8-tap passes reproduce the reference sample byte-for-byte here -- + // `integer_mv_is_identity` below pins that. Skipping straight to a + // clamped copy is bit-identical, not an approximation: it matters + // because the motion search's own log/diamond stage (`motion.rs`) is + // whole-pel-only and calls `predict` for every candidate it prices, so + // this path is what most of a search's `predict` calls actually hit + // (measured: `stage_timing_breakdown_inter` attributed 403 of a 720p + // inter frame's 408ms motion-search bucket to `predict`, almost all of + // it whole-pel candidates from stage 1). + if xfrac == 0 && yfrac == 0 { + for row in 0..block_h { + let y = y0 + row as i32; + for col in 0..block_w { + let x = x0 + col as i32; + dst[row * block_w + col] = + sample(reference, stride, true_width, true_height, x, y) as u8; + } + } + #[cfg(test)] + crate::encode::stage_add(1, stage_t.elapsed()); + return; + } + let h_filter = &SUBPEL_FILTERS[xfrac]; let v_filter = &SUBPEL_FILTERS[yfrac];