From a050448e1fca7d1815f4d560c2bec6af411e6b8a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Wed, 16 Sep 2026 14:54:59 +0300 Subject: [PATCH] vp9kf: filter the luma internal-4x4 H edge on the frame's last MI row Reviewer finding (independent panel seat, PASS on the other five claims). The port gated the luma int4 H edge on `sbr + row != mi_rows - 1`, labelled "UV edge" - but skip_border_4x4_r lives only in the 4:2:0-chroma path (vp9_filter_block_plane_ss11, vp9_loopfilter.c:1382) and in non420 under ss_y. vp9_filter_block_plane_ss00 passes int_4x4_y & 0xff for every MI row (:1286-1311) and vp9_adjust_mask keeps the last row's bits (:798-805), so real content loses one filter tap set in the bottom 8 rows whenever the bottom MI row holds a 4x4-tx cell. Neither fixture does (last int4 anchors at y=200/204 vs last MI row 232-239), so no existing gate could see it. Witness, fails pre-fix: loopfilter::tests:: luma_int4_h_edge_is_filtered_on_the_last_mi_row - a 64x64 grid of BLOCK_4X4 cells at level 8, plane stepped by 4 at row 60 (sharper steps fail filter_mask's gradient test and move nothing), asserting rows 60-61 changed. With the guard restored it panics "was not filtered"; without it, green. lib 9/9, keyframe_exact 4/4, ec-vp9-syntax 13+3, warnings unchanged (5). --- crates/ec-vp9/src/loopfilter.rs | 66 +++++++++++++++++++++++++++++---- lanes/vp9kf.report.md | 26 +++++++++++++ 2 files changed, 85 insertions(+), 7 deletions(-) diff --git a/crates/ec-vp9/src/loopfilter.rs b/crates/ec-vp9/src/loopfilter.rs index db2408ff..a75bc9f9 100644 --- a/crates/ec-vp9/src/loopfilter.rs +++ b/crates/ec-vp9/src/loopfilter.rs @@ -614,13 +614,13 @@ impl LfGrids { } } } - // Internal 4x4 UV edge at yy + 4 (skipped on the - // frame's last MI row: `skip_border_4x4_r`). - if int4 & bit != 0 - && sbr + row != self.mi_rows - 1 - && yy + 8 <= y_h - && xx + 8 <= y_w - { + // Internal 4x4 luma edge at yy + 4. libvpx's luma + // path has NO last-row skip: `vp9_filter_block_plane_ + // ss00` passes `lfm->int_4x4_y & 0xff` for every MI row + // (vp9_loopfilter.c:1286-1311). `skip_border_4x4_r` + // exists only in the 4:2:0-chroma path (ss11, + // vp9_loopfilter.c:1382) and in non420 under `ss_y`. + if int4 & bit != 0 && yy + 8 <= y_h && xx + 8 <= y_w { lpf_edge(y, (yy + 4) * stride + xx, stride, 0, 4, bl, li, th, 8); if std::env::var_os("LFTRACE").is_some() { eprintln!("H4I {} {}", xx, yy + 4); @@ -852,3 +852,55 @@ impl LfGrids { } } } + +#[cfg(test)] +mod tests { + use super::*; + use crate::tables::TX_4X4; + + /// One 64x64 frame (8x8 MI) where every cell is a BLOCK_4X4 at `level`. + fn grid(level: u8) -> LfGrids { + let (mi_cols, mi_rows) = (8usize, 8usize); + LfGrids { + level8: vec![level; mi_cols * mi_rows], + blk: vec![(0u8, 0, 0); mi_cols * mi_rows], // 0 == BLOCK_4X4 + otx: vec![TX_4X4 as u8; mi_cols * mi_rows], + mi_cols, + mi_rows, + } + } + + fn run(g: &LfGrids, y: &mut [u8]) { + let mut u = vec![128u8; 32 * 32]; + let mut v = vec![128u8; 32 * 32]; + g.filter_frame(y, 64, &mut u, &mut v, 32, 64, 64, 32, 32, 0); + } + + /// The luma internal-4x4 horizontal edge fires on the frame's LAST MI row. + /// + /// `vp9_filter_block_plane_ss00` passes `lfm->int_4x4_y & 0xff` for every + /// MI row (vp9_loopfilter.c:1286-1311) - there is no last-row skip in the + /// luma path. `skip_border_4x4_r` exists only for 4:2:0 chroma in + /// `vp9_filter_block_plane_ss11` (:1382) and in non420 under `ss_y`. + /// + /// Last MI row here is 56, so the internal edge sits at row 60 with taps + /// p1,p0 = rows 58,59 (100) and q0,q1 = rows 60,61 (150): q0 moves. + #[test] + fn luma_int4_h_edge_is_filtered_on_the_last_mi_row() { + let g = grid(8); + let stride = 64; + // A gentle step (4) between rows 59 and 60: sharp steps fail the + // filter_mask gradient test, and a flat pattern cannot move. + let mut y = vec![100u8; 64 * 64]; + for row in 60..64 { + y[row * stride..row * stride + 64].fill(104); + } + let before = y.clone(); + run(&g, &mut y); + assert!( + (60..62).any(|r| (0..64).any(|c| y[r * stride + c] != before[r * stride + c])), + "the internal 4x4 H edge on the last MI row (row 60) was not filtered" + ); + } +} + diff --git a/lanes/vp9kf.report.md b/lanes/vp9kf.report.md index f514289c..f5b12252 100644 --- a/lanes/vp9kf.report.md +++ b/lanes/vp9kf.report.md @@ -510,3 +510,29 @@ is wrong for >1 tile; "corrupt" is the wrong claim until that is known. fixture, otherwise "byte-exact" keeps meaning "testsrc2-exact". `scratch_tiledbg.rs` (header/tile-offset dump) is the companion probe. + +## REVIEWER FINDING CLOSED (2026-09-16) — luma last-row 4x4-int edge + +An independent reviewer (panel seat, diff `29f35b77..f86ef080`) returned PASS on all five +claims (iadst16 vs `inv_txfm.c:520-554` incl. the WRAPLOW casts; all eight mask tables +value-for-value vs `vp9_loopfilter.c:39-205`; the `vp9_setup_mask` walk case-for-case; the +V-before-H pass order; the tile-bounds test) and found ONE real port error: + +**The luma internal-4x4 horizontal edge was skipped on the frame's last MI row.** The port +gated it on `sbr + row != self.mi_rows - 1` (and mislabelled it "UV edge"), but +`skip_border_4x4_r` exists only in the 4:2:0-chroma path (`vp9_filter_block_plane_ss11`, +vp9_loopfilter.c:1382) and in non420 under `ss_y`; `vp9_filter_block_plane_ss00` passes +`lfm->int_4x4_y & 0xff` for every MI row (:1286-1311), and `vp9_adjust_mask`'s rows mask +deliberately keeps the last row's bits (:798-805). So real content loses one filtered edge +in the bottom 8 rows whenever the bottom MI row holds a 4x4-tx cell - which neither +fixture has (LFTRACE: the fixtures' last int4 anchors are y=200/y=204; their last MI row is +232-239), so no existing gate could catch it. + +Fixed, with a witness that fails pre-fix: +`loopfilter::tests::luma_int4_h_edge_is_filtered_on_the_last_mi_row` builds a 64x64 grid of +BLOCK_4X4 cells at level 8, steps the plane by 4 at row 60 (a sharper step fails the +filter_mask gradient test and moves nothing), and asserts rows 60-61 changed. With the old +guard restored the test fails ("...was not filtered"); without it, it passes. lib tests +9/9; keyframe_exact still 4/4; the real-content sweep numbers are unchanged (that content +does not reach the shape). +