From 9385d73315fb0e11524a947e982449f9ea1e3d6f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Wed, 2 Sep 2026 21:18:43 +0300 Subject: [PATCH] fix(av1): the per-plane warp bail-out was gated on the square side, not the plane block's own width/height `av1_init_warp_params` (reconinter.c) returns before setting WARP_PRED when the PLANE's own block is `block_width < 8 || block_height < 8`, so in 4:2:0 the chroma of any luma block narrower or shorter than 16 is predicted translationally even while its luma warps. Every warp site gated that on `chroma_side` (`side / 2`, the SQUARE side), which for an 8x16 or 16x8 luma block is 8 while the real chroma block is 4x8 / 8x4 -- so we warped chroma libaom convolves. Same shape on the luma side: a PARTITION_HORZ/VERT strip is `write_w`x`write_h`, not `side`x`side`, so a 16x4 / 4x16 strip under global motion warped where libaom does not. Guards now read `write_chroma_w`/`write_chroma_h` (chroma) and `write_w`/`write_h` (luma) at all 5 chroma and 3 luma warp call sites (single-reference and both compound taps). On the 2-frame 10-bit 1920x792 128-superblock cut, decode-order compare vs the instrumented aomdec: frame 1 chroma residue U 98 / V 62 samples (11 superblocks, deltas -2..+3) -> 0, and both frames are now bit-exact pre-filter AND post-filter (was 258 differing bytes). --- crates/ec-av1/src/decode.rs | 39 +++++++++++++++++++++++-------------- 1 file changed, 24 insertions(+), 15 deletions(-) diff --git a/crates/ec-av1/src/decode.rs b/crates/ec-av1/src/decode.rs index 4d98d653..eb31496b 100644 --- a/crates/ec-av1/src/decode.rs +++ b/crates/ec-av1/src/decode.rs @@ -20563,7 +20563,7 @@ fn decode_inter_block( // lane-cwarp r1: this reference's own GLOBAL warp replaces the // translational tap (libaom `av1_warp_plane` with // `conv_params->is_compound`); the blend below is unchanged. - if let Some(wp) = &warp0 { + if let Some(wp) = warp0.as_ref().filter(|_| write_w >= 8 && write_h >= 8) { crate::warp::warp_affine_compound( wp, &py0.data, py0.true_width as i32, py0.true_height as i32, py0.width as i32, &mut inter0_y, px as i32, py as i32, side as i32, @@ -20590,7 +20590,7 @@ fn decode_inter_block( // lane-cwarp r1: this reference's own GLOBAL warp replaces the // translational tap (libaom `av1_warp_plane` with // `conv_params->is_compound`); the blend below is unchanged. - if let Some(wp) = &warp1 { + if let Some(wp) = warp1.as_ref().filter(|_| write_w >= 8 && write_h >= 8) { crate::warp::warp_affine_compound( wp, &py1.data, py1.true_width as i32, py1.true_height as i32, py1.width as i32, &mut inter1_y, px as i32, py as i32, side as i32, @@ -20640,7 +20640,7 @@ fn decode_inter_block( // narrower/shorter than 8 (`block_width < 8`), so a 4x4 chroma // block of an 8x8 luma block stays translational. if let Some(wp) = &warp0 { - if chroma_side >= 8 { + if write_chroma_w >= 8 && write_chroma_h >= 8 { crate::warp::warp_affine_compound( wp, &pu0.data, pu0.true_width as i32, pu0.true_height as i32, pu0.width as i32, &mut inter0_u, cpx as i32, cpy as i32, @@ -20669,7 +20669,7 @@ fn decode_inter_block( // narrower/shorter than 8 (`block_width < 8`), so a 4x4 chroma // block of an 8x8 luma block stays translational. if let Some(wp) = &warp1 { - if chroma_side >= 8 { + if write_chroma_w >= 8 && write_chroma_h >= 8 { crate::warp::warp_affine_compound( wp, &pu1.data, pu1.true_width as i32, pu1.true_height as i32, pu1.width as i32, &mut inter1_u, cpx as i32, cpy as i32, @@ -20714,7 +20714,7 @@ fn decode_inter_block( // narrower/shorter than 8 (`block_width < 8`), so a 4x4 chroma // block of an 8x8 luma block stays translational. if let Some(wp) = &warp0 { - if chroma_side >= 8 { + if write_chroma_w >= 8 && write_chroma_h >= 8 { crate::warp::warp_affine_compound( wp, &pv0.data, pv0.true_width as i32, pv0.true_height as i32, pv0.width as i32, &mut inter0_v, cpx as i32, cpy as i32, @@ -20743,7 +20743,7 @@ fn decode_inter_block( // narrower/shorter than 8 (`block_width < 8`), so a 4x4 chroma // block of an 8x8 luma block stays translational. if let Some(wp) = &warp1 { - if chroma_side >= 8 { + if write_chroma_w >= 8 && write_chroma_h >= 8 { crate::warp::warp_affine_compound( wp, &pv1.data, pv1.true_width as i32, pv1.true_height as i32, pv1.width as i32, &mut inter1_v, cpx as i32, cpy as i32, @@ -21839,19 +21839,28 @@ fn decode_inter_block( // motion_mode symbol was still read and warp_params still // resolved. Suppress the warp, keep every symbol read. if let Some(params) = warp_params.as_ref().filter(|_| luma_scale == mc::REF_NO_SCALE) { - crate::warp::warp_affine( - params, &py_ref.data, py_ref.true_width as i32, py_ref.true_height as i32, - py_ref.width as i32, &mut pred_y, px as i32, py as i32, side as i32, - side as i32, side as i32, 0, 0, - ); + // `av1_init_warp_params` is per PLANE: the luma plane's + // own block is `write_w`x`write_h` (a PARTITION_HORZ/VERT + // strip is not `side`x`side`), so a strip under 8 px in + // either direction keeps the translational prediction too. + if write_w >= 8 && write_h >= 8 { + crate::warp::warp_affine( + params, &py_ref.data, py_ref.true_width as i32, py_ref.true_height as i32, + py_ref.width as i32, &mut pred_y, px as i32, py as i32, side as i32, + side as i32, side as i32, 0, 0, + ); + } // libaom `av1_init_warp_params` (reconinter.c): warp is // per PLANE and bails out at `block_width < 8 || // block_height < 8`, so a plane whose own block is under // 8x8 keeps the translational prediction built above -- - // in 420 that is every chroma plane of a luma block below - // 16x16 (lane-gmaffine r4: chroma-only mismatch of a few - // levels on both 8x8-leaf motion gates). - if chroma_side >= 8 { + // in 420 that is every chroma plane whose own width or + // height is under 8 -- `write_chroma_w`/`write_chroma_h`, + // NOT the square `chroma_side` (lane-t900 r5: an 8x16 luma + // block has `chroma_side == 8` but a 4x8 chroma block, so + // the square side warped chroma libaom predicts + // translationally; lane-gmaffine r4 for the 8x8 leaf). + if write_chroma_w >= 8 && write_chroma_h >= 8 { crate::warp::warp_affine( params, &pu_ref.data, pu_ref.true_width as i32, pu_ref.true_height as i32, pu_ref.width as i32, &mut pred_u, cpx as i32, cpy as i32, chroma_side as i32,