From aad8b594d36d41560a4eaa03ecd4a51c076ec871 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 12:57:19 +0300 Subject: [PATCH] fix(av1): 4-tap subpel filters for blocks 4 wide or tall Spec 7.11.3.4 selects the filter table per axis: an output dimension of 4 or less reads Subpel_Filters' narrow counterpart (av1_sub_pel_filters_4), whose outer two taps on each side are zero. We fed every block the 8-tap table, so 4:2:0 chroma under an 8x8 luma leaf -- the common chroma shape, not a corner -- reached 3 samples past its edge with nonzero weights and came out +-1 against the reference decoder wherever the extra taps mattered. Found by diffing libaom's dec_calc_subpel_params against ours: the phase matched, the tap table did not. Closes the 640x360 inter straddle sequence's frame-2 U-plane desync; the whole sequence now round-trips through ffmpeg pixel-exact. --- crates/ec-av1/src/mc.rs | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/crates/ec-av1/src/mc.rs b/crates/ec-av1/src/mc.rs index 4ddcfb05..93f7d0cf 100644 --- a/crates/ec-av1/src/mc.rs +++ b/crates/ec-av1/src/mc.rs @@ -52,6 +52,33 @@ const SUBPEL_FILTERS: [[i32; 8]; 16] = [ [0, 0, -2, 8, 126, -6, 2, 0], ]; +/// `Subpel_Filters[EIGHTTAP]`'s narrow-block counterpart (spec 7.11.3.4's +/// filter selection is per-axis: a `predict` axis whose output block +/// dimension is 4 or less reads this table instead of [`SUBPEL_FILTERS`]), +/// mirroring `av1_sub_pel_filters_4` (`filter.h`): the same 8-slot shape but +/// zeroed at taps 0/1/6/7, so a 4-wide (or 4-tall) block's filter never +/// reaches a full 3 samples past its own edge. Every 4:2:0 chroma block +/// under an 8x8 (or smaller) luma leaf hits this on at least one axis -- +/// this is not an edge case, it is the common chroma shape. +const SUBPEL_FILTERS_4: [[i32; 8]; 16] = [ + [0, 0, 0, 128, 0, 0, 0, 0], + [0, 0, -4, 126, 8, -2, 0, 0], + [0, 0, -8, 122, 18, -4, 0, 0], + [0, 0, -10, 116, 28, -6, 0, 0], + [0, 0, -12, 110, 38, -8, 0, 0], + [0, 0, -12, 102, 48, -10, 0, 0], + [0, 0, -14, 94, 58, -10, 0, 0], + [0, 0, -12, 84, 66, -10, 0, 0], + [0, 0, -12, 76, 76, -12, 0, 0], + [0, 0, -10, 66, 84, -12, 0, 0], + [0, 0, -10, 58, 94, -14, 0, 0], + [0, 0, -10, 48, 102, -12, 0, 0], + [0, 0, -8, 38, 110, -12, 0, 0], + [0, 0, -6, 28, 116, -10, 0, 0], + [0, 0, -4, 18, 122, -8, 0, 0], + [0, 0, -2, 8, 126, -4, 0, 0], +]; + /// A reference sample at `(x, y)`, clamped to the frame's true (unpadded) /// extent -- `true_width`/`true_height`, which can be narrower than /// `stride` -- rather than read out of range (spec 7.11.3.4's `Clip3` @@ -137,8 +164,8 @@ pub fn predict( return; } - let h_filter = &SUBPEL_FILTERS[xfrac]; - let v_filter = &SUBPEL_FILTERS[yfrac]; + let h_filter = if block_w <= 4 { &SUBPEL_FILTERS_4[xfrac] } else { &SUBPEL_FILTERS[xfrac] }; + let v_filter = if block_h <= 4 { &SUBPEL_FILTERS_4[yfrac] } else { &SUBPEL_FILTERS[yfrac] }; // The vertical pass reads 3 rows above and 4 below the block, so the // horizontal pass must produce that many extra intermediate rows.