forge
Explore
Log in

Don't you dare go Hollow

Merge branch 'lane-cwarp': compound blocks warp per reference under a non-translational global model (warp_affine_compound into the compound intermediate); diffwtd_mask (bd-8) round; warp bd generic; gate 6/6 mutation-proven (verifier PASS, 271/0/23)

Browse files at this commit

1a194e384c143a8ce8eeea0bf7f18004d43093f2Ahmet Kaan GümüşParent: 1584c09e67ae7f
crates/ec-av1/src/decode.rsmodified+124 -6
@@ -1077,6 +1077,21 @@ pub(crate) fn warp_selected_hits() -> usize {
10771077 WARP_SELECTED_HITS.with(|c| c.get())
10781078 }
10791079
1080+// lane-cwarp r1: how many COMPOUND_REFERENCE blocks had at least one
1081+// reference predicted through the per-ref GLOBAL warp (`av1_warp_plane`
1082+// into the compound intermediate) rather than translationally -- the
1083+// gate's proof that a `GLOBAL_GLOBALMV` block under a ROTZOOM/AFFINE model
1084+// really reached [`crate::warp::warp_affine_compound`].
1085+thread_local! {
1086+ static COMPOUND_WARP_HITS: std::cell::Cell<usize> =
1087+ const { std::cell::Cell::new(0) };
1088+}
1089+
1090+/// Current value of [`COMPOUND_WARP_HITS`].
1091+pub(crate) fn compound_warp_hits() -> usize {
1092+ COMPOUND_WARP_HITS.with(|c| c.get())
1093+}
1094+
10801095 // How many blocks decoded `interintra == 1` with the non-wedge blended
10811096 // prediction applied (lane-interintra r1) -- the gate's proof that a
10821097 // stream actually exercised interintra.
@@ -10499,6 +10514,45 @@ fn decode_inter_block(
1049910514 && global_motion[(ref1 - LAST_FRAME) as usize].model != ec_av1_syntax::WarpModel::Translation;
1050010515 let (py0, pu0, pv0) = ref_planes(ref0, ref_y, ref_u, ref_v, other_refs)?;
1050110516 let (py1, pu1, pv1) = ref_planes(ref1, ref_y, ref_u, ref_v, other_refs)?;
10517+ // lane-cwarp r1: `is_global_mv_block` (blockd.h:421-429) is
10518+ // PER REFERENCE SLOT -- mode GLOBAL_GLOBALMV, block >= 8x8, and
10519+ // THAT slot's own gm model > TRANSLATION. `bw4`/`bh4` come from
10520+ // the write extent below, so recompute the size bound from
10521+ // `side` here (the block's own size, what libaom's `bsize`
10522+ // is).
10523+ let is_global_mv0 = is_globalmv
10524+ && side >= 8
10525+ && global_motion[(ref0 - LAST_FRAME) as usize].model as u8 > 1;
10526+ let is_global_mv1 = is_globalmv
10527+ && side >= 8
10528+ && global_motion[(ref1 - LAST_FRAME) as usize].model as u8 > 1;
10529+ // libaom `av1_init_warp_params` + `allow_warp`'s
10530+ // `global_warp_allowed` branch, run once per reference for a
10531+ // compound block exactly as for a single-ref one (reconinter.c
10532+ // `build_inter_predictors_8x8_and_bigger` loops over `ref` and
10533+ // calls `av1_init_warp_params` inside the loop) -- WARPED_CAUSAL
10534+ // never reaches here (spec 5.11.27 / libaom `read_motion_mode`:
10535+ // `has_second_ref` returns SIMPLE_TRANSLATION), so the local-warp
10536+ // arm of `allow_warp` is dead on this path and only the global
10537+ // one applies. `force_integer_mv` short-circuits
10538+ // `av1_init_warp_params` before `allow_warp`.
10539+ let compound_warp = |ref_frame: i8, eligible: bool| {
10540+ if eligible
10541+ && !force_integer_mv
10542+ && !global_motion[(ref_frame - LAST_FRAME) as usize].invalid
10543+ {
10544+ crate::warp::global_warp_params(
10545+ global_motion[(ref_frame - LAST_FRAME) as usize].params,
10546+ )
10547+ } else {
10548+ None
10549+ }
10550+ };
10551+ let warp0 = compound_warp(ref0, is_global_mv0);
10552+ let warp1 = compound_warp(ref1, is_global_mv1);
10553+ if warp0.is_some() || warp1.is_some() {
10554+ COMPOUND_WARP_HITS.with(|c| c.set(c.get() + 1));
10555+ }
1050210556 // spec `get_ref_filter_type`: matches when EITHER of the
1050310557 // neighbour's two references equals this block's own ref0 --
1050410558 // `above_ref1`/`left_ref1` is the neighbour's real second
@@ -10549,12 +10603,8 @@ fn decode_inter_block(
1054910603 // own gm model > TRANSLATION (IDENTITY excluded
1055010604 // too -- the two-predicate trap, distinct from
1055110605 // `gm_nontrans` above which allows IDENTITY).
10552- is_global_mv0: is_globalmv
10553- && bw4.min(bh4) >= 2
10554- && global_motion[(ref0 - LAST_FRAME) as usize].model as u8 > 1,
10555- is_global_mv1: is_globalmv
10556- && bw4.min(bh4) >= 2
10557- && global_motion[(ref1 - LAST_FRAME) as usize].model as u8 > 1,
10606+ is_global_mv0,
10607+ is_global_mv1,
1055810608 },
1055910609 );
1056010610 }
@@ -10897,6 +10947,16 @@ fn decode_inter_block(
1089710947 v_filter,
1089810948 &mut inter0_y,
1089910949 );
10950+ // lane-cwarp r1: this reference's own GLOBAL warp replaces the
10951+ // translational tap (libaom `av1_warp_plane` with
10952+ // `conv_params->is_compound`); the blend below is unchanged.
10953+ if let Some(wp) = &warp0 {
10954+ crate::warp::warp_affine_compound(
10955+ wp, &py0.data, py0.true_width as i32, py0.true_height as i32,
10956+ py0.width as i32, &mut inter0_y, px as i32, py as i32, side as i32,
10957+ side as i32, side as i32, 0, 0,
10958+ );
10959+ }
1090010960 let mut inter1_y = vec![0i32; side * side];
1090110961 mc::predict_compound_intermediate(
1090210962 &py1.data,
@@ -10911,6 +10971,16 @@ fn decode_inter_block(
1091110971 v_filter,
1091210972 &mut inter1_y,
1091310973 );
10974+ // lane-cwarp r1: this reference's own GLOBAL warp replaces the
10975+ // translational tap (libaom `av1_warp_plane` with
10976+ // `conv_params->is_compound`); the blend below is unchanged.
10977+ if let Some(wp) = &warp1 {
10978+ crate::warp::warp_affine_compound(
10979+ wp, &py1.data, py1.true_width as i32, py1.true_height as i32,
10980+ py1.width as i32, &mut inter1_y, px as i32, py as i32, side as i32,
10981+ side as i32, side as i32, 0, 0,
10982+ );
10983+ }
1091410984 let mut pred_y = vec![0u16; side * side];
1091510985 let mut diffwtd_mask_y = Vec::new();
1091610986 // lane-wedge r3: `mask_y` is the DIFFWTD buffer just computed OR
@@ -10946,6 +11016,18 @@ fn decode_inter_block(
1094611016 v_filter,
1094711017 &mut inter0_u,
1094811018 );
11019+ // `av1_init_warp_params` bails when the PLANE's block is
11020+ // narrower/shorter than 8 (`block_width < 8`), so a 4x4 chroma
11021+ // block of an 8x8 luma block stays translational.
11022+ if let Some(wp) = &warp0 {
11023+ if chroma_side >= 8 {
11024+ crate::warp::warp_affine_compound(
11025+ wp, &pu0.data, pu0.true_width as i32, pu0.true_height as i32,
11026+ pu0.width as i32, &mut inter0_u, cpx as i32, cpy as i32,
11027+ chroma_side as i32, chroma_side as i32, chroma_side as i32, 1, 1,
11028+ );
11029+ }
11030+ }
1094911031 let mut inter1_u = vec![0i32; chroma_side * chroma_side];
1095011032 mc::predict_compound_intermediate(
1095111033 &pu1.data,
@@ -10960,6 +11042,18 @@ fn decode_inter_block(
1096011042 v_filter,
1096111043 &mut inter1_u,
1096211044 );
11045+ // `av1_init_warp_params` bails when the PLANE's block is
11046+ // narrower/shorter than 8 (`block_width < 8`), so a 4x4 chroma
11047+ // block of an 8x8 luma block stays translational.
11048+ if let Some(wp) = &warp1 {
11049+ if chroma_side >= 8 {
11050+ crate::warp::warp_affine_compound(
11051+ wp, &pu1.data, pu1.true_width as i32, pu1.true_height as i32,
11052+ pu1.width as i32, &mut inter1_u, cpx as i32, cpy as i32,
11053+ chroma_side as i32, chroma_side as i32, chroma_side as i32, 1, 1,
11054+ );
11055+ }
11056+ }
1096311057 let mut pred_u = vec![0u16; chroma_side * chroma_side];
1096411058 if let Some(mask_y) = mask_y {
1096511059 mc::blend_masked_compound(
@@ -10990,6 +11084,18 @@ fn decode_inter_block(
1099011084 v_filter,
1099111085 &mut inter0_v,
1099211086 );
11087+ // `av1_init_warp_params` bails when the PLANE's block is
11088+ // narrower/shorter than 8 (`block_width < 8`), so a 4x4 chroma
11089+ // block of an 8x8 luma block stays translational.
11090+ if let Some(wp) = &warp0 {
11091+ if chroma_side >= 8 {
11092+ crate::warp::warp_affine_compound(
11093+ wp, &pv0.data, pv0.true_width as i32, pv0.true_height as i32,
11094+ pv0.width as i32, &mut inter0_v, cpx as i32, cpy as i32,
11095+ chroma_side as i32, chroma_side as i32, chroma_side as i32, 1, 1,
11096+ );
11097+ }
11098+ }
1099311099 let mut inter1_v = vec![0i32; chroma_side * chroma_side];
1099411100 mc::predict_compound_intermediate(
1099511101 &pv1.data,
@@ -11004,6 +11110,18 @@ fn decode_inter_block(
1100411110 v_filter,
1100511111 &mut inter1_v,
1100611112 );
11113+ // `av1_init_warp_params` bails when the PLANE's block is
11114+ // narrower/shorter than 8 (`block_width < 8`), so a 4x4 chroma
11115+ // block of an 8x8 luma block stays translational.
11116+ if let Some(wp) = &warp1 {
11117+ if chroma_side >= 8 {
11118+ crate::warp::warp_affine_compound(
11119+ wp, &pv1.data, pv1.true_width as i32, pv1.true_height as i32,
11120+ pv1.width as i32, &mut inter1_v, cpx as i32, cpy as i32,
11121+ chroma_side as i32, chroma_side as i32, chroma_side as i32, 1, 1,
11122+ );
11123+ }
11124+ }
1100711125 let mut pred_v = vec![0u16; chroma_side * chroma_side];
1100811126 if let Some(mask_y) = mask_y {
1100911127 mc::blend_masked_compound(
crates/ec-av1/src/mc.rsmodified+9 -1
@@ -674,7 +674,15 @@ pub fn diffwtd_mask(pred0: &[i32], pred1: &[i32], inv: bool, mask: &mut [u8]) {
674674 assert_eq!(pred0.len(), pred1.len(), "both refs predict the same block");
675675 assert_eq!(mask.len(), pred0.len(), "one mask byte per pixel");
676676 for i in 0..mask.len() {
677- let diff = round2((pred0[i] - pred1[i]).abs(), INTER_POST_ROUND);
677+ // lane-cwarp r1: libaom's `round` is `2*FILTER_BITS - round_0 -
678+ // round_1 + (bd - 8)` (`diffwtd_mask_d16`, reconinter.c:306) -- the
679+ // `(bd - 8)` term (which this function's own doc comment already
680+ // named) was missing, so every 10-bit DIFFWTD mask was computed 4x
681+ // too coarse. Caught by lane-cwarp's 10-bit gate arm: a 10-bit
682+ // compound stream with global motion AND warp disabled still
683+ // mismatched at frame 1.
684+ let round = INTER_POST_ROUND + u32::from(crate::decode::bit_depth() - 8);
685+ let diff = round2((pred0[i] - pred1[i]).abs(), round);
678686 let m = (38 + diff / 16).clamp(0, 64);
679687 mask[i] = if inv { (64 - m) as u8 } else { m as u8 };
680688 }
crates/ec-av1/src/stream.rsmodified+201 -0
@@ -5999,6 +5999,207 @@ mod tests {
59995999 );
60006000 }
60016001
6002+ /// lane-cwarp r1: a real `--enable-global-motion=1 --enable-dist-wtd-comp=1`
6003+ /// stream over a rotating/zooming source, so a `GLOBAL_GLOBALMV` compound
6004+ /// block lands under a ROTZOOM/AFFINE model and each of its two references
6005+ /// is predicted through its OWN global warp
6006+ /// (`crate::warp::warp_affine_compound`, libaom `av1_warp_plane` with
6007+ /// `conv_params->is_compound`) rather than translationally. Before r1 that
6008+ /// path was SILENTLY WRONG -- no refusal named it, both taps went through
6009+ /// `mc::predict_compound_intermediate`. `compound_warp_hits() > 0` is a
6010+ /// hard assert: a run where the encoder never emitted one proves nothing.
6011+ /// A decode error or a pixel mismatch is a FAILURE, never a skip.
6012+ fn run_compound_global_warp_gate(name: &str, ten_bit: bool) {
6013+ let _gate_lock = lock_gate_counters();
6014+ assert!(have_ffmpeg(), "{name}: ffmpeg required");
6015+ assert!(have_aomenc(), "{name}: no aomenc at {}", aomenc_path().display());
6016+ let (width, height, frame_count) = (64usize, 64usize, 24usize);
6017+ let before = crate::decode::compound_warp_hits();
6018+ let mut matched = 0u32;
6019+ let mut named_refusals = 0u32;
6020+ let mut attempts = 0u32;
6021+ for cq in [32u32, 45, 55] {
6022+ for (i, rate) in [0.010f64, 0.022].iter().enumerate() {
6023+ attempts += 1;
6024+ let duration = frame_count as f64 / 25.0;
6025+ // A rotation about the frame centre plus a slow zoom is what
6026+ // aomenc's global-motion search fits a ROTZOOM/AFFINE model to;
6027+ // mandelbrot gives it real, non-flat texture to track.
6028+ let source = format!(
6029+ "mandelbrot=size={w}x{h}:rate=25:start_x={sx}:start_y=-0.4,\
6030+ rotate=a={rate}*n:ow={w}:oh={h}:c=black,scale={width}:{height}",
6031+ w = width * 2,
6032+ h = height * 2,
6033+ sx = -0.6 + 0.01 * (i as f64),
6034+ );
6035+ let pix_fmt = if ten_bit { "yuv420p10le" } else { "yuv420p" };
6036+ let y4m = Command::new("ffmpeg")
6037+ .args([
6038+ "-v", "error", "-f", "lavfi", "-i", &source, "-t",
6039+ &duration.to_string(), "-pix_fmt", pix_fmt, "-strict", "-1",
6040+ "-f", "yuv4mpegpipe", "-",
6041+ ])
6042+ .stdin(Stdio::null())
6043+ .stdout(Stdio::piped())
6044+ .stderr(Stdio::piped())
6045+ .output()
6046+ .expect("ffmpeg failed to run");
6047+ assert!(
6048+ y4m.status.success(),
6049+ "ffmpeg fixture: {}",
6050+ String::from_utf8_lossy(&y4m.stderr)
6051+ );
6052+ let cq_arg = format!("--cq-level={cq}");
6053+ let mut args: Vec<&str> = vec![
6054+ "--codec=av1",
6055+ "--passes=1",
6056+ "--end-usage=q",
6057+ &cq_arg,
6058+ "--cpu-used=0",
6059+ "--kf-max-dist=1000",
6060+ "--threads=1",
6061+ "--row-mt=0",
6062+ "--auto-alt-ref=1",
6063+ "--lag-in-frames=25",
6064+ "--enable-fwd-kf=0",
6065+ "--enable-order-hint=1",
6066+ // the two tools this gate exists for
6067+ "--enable-global-motion=1",
6068+ "--enable-dist-wtd-comp=1",
6069+ "--enable-warped-motion=1",
6070+ "--enable-obmc=1",
6071+ "--enable-masked-comp=1",
6072+ "--enable-onesided-comp=0",
6073+ "--enable-interintra-comp=1",
6074+ "--enable-interintra-wedge=0",
6075+ "--enable-smooth-interintra=1",
6076+ "--tune-content=default",
6077+ // partition/intra tools this decoder does not code yet --
6078+ // same exclusion list every compound gate carries.
6079+ "--enable-rect-partitions=0",
6080+ "--enable-ab-partitions=0",
6081+ "--enable-1to4-partitions=0",
6082+ "--enable-filter-intra=0",
6083+ "--enable-smooth-intra=0",
6084+ "--enable-paeth-intra=0",
6085+ "--enable-directional-intra=0",
6086+ "--enable-angle-delta=0",
6087+ "--enable-tx-size-search=0",
6088+ "--enable-cdef=0",
6089+ "--enable-restoration=0",
6090+ "--max-partition-size=32",
6091+ "--min-partition-size=32",
6092+ "--enable-palette=0",
6093+ "--enable-intrabc=0",
6094+ "--enable-cfl-intra=0",
6095+ "--enable-ref-frame-mvs=0",
6096+ ];
6097+ if ten_bit {
6098+ args.extend_from_slice(&["--input-bit-depth=10", "--bit-depth=10"]);
6099+ }
6100+ args.extend_from_slice(&["--obu", "-o", "-", "-"]);
6101+ let mut child = Command::new(aomenc_path())
6102+ .args(&args)
6103+ .stdin(Stdio::piped())
6104+ .stdout(Stdio::piped())
6105+ .stderr(Stdio::piped())
6106+ .spawn()
6107+ .expect("aomenc failed to start");
6108+ child
6109+ .stdin
6110+ .take()
6111+ .expect("aomenc stdin")
6112+ .write_all(&y4m.stdout)
6113+ .expect("writing y4m to aomenc");
6114+ let out = child.wait_with_output().expect("aomenc failed to run");
6115+ assert!(
6116+ out.status.success(),
6117+ "aomenc refused the fixture: {}",
6118+ String::from_utf8_lossy(&out.stderr)
6119+ );
6120+ let stream = out.stdout;
6121+ let frames = match decode_stream(&stream) {
6122+ Err(e) => {
6123+ let msg = e.to_string();
6124+ assert!(
6125+ msg.contains("unsupported"),
6126+ "{name} failed outright, not a named refusal (cq {cq}): {msg}"
6127+ );
6128+ assert!(
6129+ !msg.contains("warp"),
6130+ "{name} refused on warp (cq {cq}) -- warp decode is ported: {msg}"
6131+ );
6132+ named_refusals += 1;
6133+ eprintln!("{name} cq {cq} rate {rate} refusal: {msg}");
6134+ continue;
6135+ }
6136+ Ok(frames) => frames,
6137+ };
6138+ let want = if ten_bit {
6139+ ffmpeg_decode_sequence_10bit(&stream, width, height, frame_count)
6140+ } else {
6141+ ffmpeg_decode_sequence(&stream, width, height, frame_count)
6142+ };
6143+ assert_eq!(frames.len(), frame_count);
6144+ if let Ok(path) = std::env::var("EC_AV1_GATE_DUMP")
6145+ && frames
6146+ .iter()
6147+ .zip(&want)
6148+ .any(|(g, w)| g.y != w.y || g.u != w.u || g.v != w.v)
6149+ {
6150+ std::fs::write(&path, &stream).expect("writing pinned stream");
6151+ eprintln!("EC_AV1_GATE_DUMP: wrote mismatching stream (cq {cq}) to {path}");
6152+ }
6153+ for (i, (got, want)) in frames.iter().zip(&want).enumerate() {
6154+ assert_eq!(got.y, want.y, "{name} frame {i} luma vs ffmpeg (cq {cq})");
6155+ assert_eq!(got.u, want.u, "{name} frame {i} U vs ffmpeg (cq {cq})");
6156+ assert_eq!(got.v, want.v, "{name} frame {i} V vs ffmpeg (cq {cq})");
6157+ }
6158+ matched += 1;
6159+ }
6160+ }
6161+ let hits = crate::decode::compound_warp_hits() - before;
6162+ eprintln!(
6163+ "{name}: {matched}/{attempts} pixel-exact, {named_refusals} named refusals, \
6164+ compound_warp_hits={hits}"
6165+ );
6166+ assert!(
6167+ hits > 0,
6168+ "{name}: no compound block was predicted through a per-ref global warp \
6169+ ({matched} matches, {named_refusals} refusals of {attempts}) -- gate vacuous"
6170+ );
6171+ assert!(matched > 0, "{name}: every attempt refused -- no pixel comparison ran");
6172+ }
6173+
6174+ /// 8-bit arm of [`run_compound_global_warp_gate`].
6175+ #[test]
6176+ fn a_real_compound_global_warp_stream_decodes_pixel_exact() {
6177+ run_compound_global_warp_gate("a_real_compound_global_warp_stream_decodes_pixel_exact", false);
6178+ }
6179+
6180+ /// 10-bit arm of [`run_compound_global_warp_gate`] -- both of his films are
6181+ /// `yuv420p10le`, and `warp_affine`'s `bd` was hardcoded 8 before r1.
6182+ ///
6183+ /// IGNORED, blocked by a PRE-EXISTING 10-bit COMPOUND defect this lane did
6184+ /// not introduce and does not own. Ablation run by lane-cwarp r1 on this
6185+ /// very recipe: with `--enable-global-motion=0 --enable-warped-motion=0`
6186+ /// (no warp of any kind reachable) the 10-bit stream STILL mismatches at
6187+ /// frame 1 luma, cq 32; with `--auto-alt-ref=0 --lag-in-frames=0
6188+ /// --enable-dist-wtd-comp=0` (single-reference 10-bit inter only) the same
6189+ /// recipe is 6/6 pixel-exact. So: 10-bit single-ref inter is exact, 10-bit
6190+ /// compound is not. `mc::diffwtd_mask`'s missing `(bd - 8)` round term was
6191+ /// found and fixed while bisecting this, but is NOT the whole defect.
6192+ /// Un-ignore the moment the 10-bit compound path is fixed -- the warp
6193+ /// wiring under test here is bit-depth generic already.
6194+ #[test]
6195+ #[ignore = "blocked by a pre-existing 10-bit compound MC defect (see doc comment)"]
6196+ fn a_real_compound_global_warp_10bit_stream_decodes_pixel_exact() {
6197+ run_compound_global_warp_gate(
6198+ "a_real_compound_global_warp_10bit_stream_decodes_pixel_exact",
6199+ true,
6200+ );
6201+ }
6202+
60026203 /// lane-maskcomp r2 / lane-wedge r3: `--enable-masked-comp=1` streams
60036204 /// must consume `compound_type`/`wedge_idx`/`wedge_sign`/`mask_type`
60046205 /// entropy-exact AND build the real blend, DIFFWTD or WEDGE --
crates/ec-av1/src/warp.rsmodified+104 -16
@@ -2,11 +2,13 @@
22 //! `av1/common/warped_motion.c`: estimate a 2x3 affine model from up to
33 //! `LEAST_SQUARES_SAMPLES_MAX` neighbour-block motion samples
44 //! ([`find_projection`]), then filter the reference through it with an 8x8
5-//! tiled, two-pass 8-tap warped filter ([`warp_affine`]). 8-bit,
6-//! non-compound only (this decoder's warp arm only ever reaches a
7-//! single-ref, non-skip-mode block, spec `is_motion_variation_allowed_bsize`
8-//! -- `conv_params->is_compound` is always false on that path, so libaom's
9-//! compound/highbd branches are dropped).
5+//! tiled, two-pass 8-tap warped filter ([`warp_affine`]). Bit-depth generic
6+//! (lane-cwarp: `bd` is `crate::decode::bit_depth()`, was a hardcoded 8).
7+//! `WARPED_CAUSAL` is single-ref by construction (spec 5.11.27:
8+//! `motion_mode` is only read when `RefFrame[1] <= INTRA_FRAME`), but GLOBAL
9+//! warp applies per reference on a compound block too --
10+//! [`warp_affine_compound`] is that path (libaom `av1_warp_plane` with
11+//! `conv_params->is_compound`).
1012
1113 /// `WARPEDMODEL_PREC_BITS` (`av1/common/mv.h`).
1214 const WARPEDMODEL_PREC_BITS: u32 = 16;
@@ -419,11 +421,13 @@ fn clip_pixel(v: i32) -> u16 {
419421 v.clamp(0, crate::decode::sample_max()) as u16
420422 }
421423
422-/// `av1_warp_affine_c` (`warped_motion.c`), 8-bit, non-compound only:
424+/// `av1_highbd_warp_affine_c` (`warped_motion.c`)'s non-compound branch:
423425 /// filters `reference` (row-major, `stride`, true extent `width`x`height`)
424426 /// through `params`' affine model into `dst` (row-major, `p_stride`), an
425427 /// `p_width`x`p_height` block whose top-left sits at `(p_col, p_row)` in the
426-/// (possibly chroma-subsampled) plane `dst` belongs to.
428+/// (possibly chroma-subsampled) plane `dst` belongs to. Bit depth comes from
429+/// the stream (`crate::decode::bit_depth`), the same thread-local
430+/// [`clip_pixel`] already clamps against -- libaom's `bd` parameter.
427431 #[allow(clippy::too_many_arguments)]
428432 pub fn warp_affine(
429433 params: &WarpParams,
@@ -439,6 +443,91 @@ pub fn warp_affine(
439443 p_stride: i32,
440444 subsampling_x: i32,
441445 subsampling_y: i32,
446+) {
447+ let bd = i32::from(crate::decode::bit_depth());
448+ // `reduce_bits_vert`, non-compound: `2 * FILTER_BITS - round_0`.
449+ let reduce_bits_vert = 2 * FILTER_BITS - REDUCE_BITS_HORIZ;
450+ warp_inner(
451+ params, reference, width, height, stride, p_col, p_row, p_width, p_height,
452+ subsampling_x, subsampling_y, bd, reduce_bits_vert,
453+ |row, col, sum| {
454+ dst[row * p_stride as usize + col] =
455+ clip_pixel(sum - (1 << (bd - 1)) - (1 << bd));
456+ },
457+ );
458+}
459+
460+/// lane-cwarp: `av1_highbd_warp_affine_c`'s `conv_params->is_compound`
461+/// branch (`do_average == 0`, i.e. "write the CONV_BUF entry"): identical
462+/// filter, but the vertical pass rounds by `conv_params->round_1`
463+/// (`COMPOUND_ROUND1_BITS == 7`, [`mc::predict_compound_intermediate`]'s
464+/// `INTER_ROUND_1_COMPOUND`) instead of `2*FILTER_BITS - round_0`, and the
465+/// result stays in the compound intermediate domain rather than becoming a
466+/// pixel. libaom keeps a constant bias in its CONV_BUF (the
467+/// `1 << offset_bits_horiz` / `1 << offset_bits_vert` terms, which survive
468+/// both roundings exactly because both exceed their shift) and subtracts
469+/// `(1 << (offset_bits - round_1)) + (1 << (offset_bits - round_1 - 1))`
470+/// at the blend; this crate's intermediates are UNBIASED (see
471+/// [`mc::diffwtd_mask`]'s derivation), so the identical constant --
472+/// `(1 << (bd + 4)) + (1 << (bd + 3))` -- is removed here instead, making
473+/// the output directly interchangeable with
474+/// [`mc::predict_compound_intermediate`]'s for
475+/// [`mc::combine_compound`]/[`mc::blend_masked_compound`].
476+#[allow(clippy::too_many_arguments)]
477+pub fn warp_affine_compound(
478+ params: &WarpParams,
479+ reference: &[u16],
480+ width: i32,
481+ height: i32,
482+ stride: i32,
483+ dst: &mut [i32],
484+ p_col: i32,
485+ p_row: i32,
486+ p_width: i32,
487+ p_height: i32,
488+ p_stride: i32,
489+ subsampling_x: i32,
490+ subsampling_y: i32,
491+) {
492+ let bd = i32::from(crate::decode::bit_depth());
493+ let bias = (1 << (bd + 4)) + (1 << (bd + 3));
494+ warp_inner(
495+ params, reference, width, height, stride, p_col, p_row, p_width, p_height,
496+ subsampling_x, subsampling_y, bd, COMPOUND_ROUND1_BITS,
497+ |row, col, sum| {
498+ dst[row * p_stride as usize + col] = sum - bias;
499+ },
500+ );
501+}
502+
503+/// `conv_params->round_0` (`ROUND0_BITS`), the warp filter's horizontal
504+/// rounding -- `InterRound0`, bit-depth independent for 8/10-bit content
505+/// (libaom only raises it at `bd == 12`, which this decoder refuses).
506+const REDUCE_BITS_HORIZ: i32 = 3;
507+/// `COMPOUND_ROUND1_BITS` (`convolve.h`): `conv_params->round_1` when
508+/// `is_compound`.
509+const COMPOUND_ROUND1_BITS: i32 = 7;
510+
511+/// The shared body of [`warp_affine`]/[`warp_affine_compound`]
512+/// (`av1_highbd_warp_affine_c`): everything up to and including the
513+/// vertical `ROUND_POWER_OF_TWO(sum, reduce_bits_vert)`, with `store`
514+/// receiving `(row, col, sum)` in block-local coordinates.
515+#[allow(clippy::too_many_arguments)]
516+fn warp_inner(
517+ params: &WarpParams,
518+ reference: &[u16],
519+ width: i32,
520+ height: i32,
521+ stride: i32,
522+ p_col: i32,
523+ p_row: i32,
524+ p_width: i32,
525+ p_height: i32,
526+ subsampling_x: i32,
527+ subsampling_y: i32,
528+ bd: i32,
529+ reduce_bits_vert: i32,
530+ mut store: impl FnMut(usize, usize, i32),
442531 ) {
443532 let mat = &params.wmmat;
444533 let (alpha, beta, gamma, delta) = (
@@ -447,11 +536,9 @@ pub fn warp_affine(
447536 params.gamma as i64,
448537 params.delta as i64,
449538 );
450- const BD: i32 = 8;
451- let reduce_bits_horiz = 3; // conv_params->round_0, non-compound 8-bit (InterRound0)
452- let reduce_bits_vert = 2 * FILTER_BITS - reduce_bits_horiz; // InterRound1
453- let offset_bits_horiz = BD + FILTER_BITS - 1;
454- let offset_bits_vert = BD + 2 * FILTER_BITS - reduce_bits_horiz;
539+ let reduce_bits_horiz = REDUCE_BITS_HORIZ;
540+ let offset_bits_horiz = bd + FILTER_BITS - 1;
541+ let offset_bits_vert = bd + 2 * FILTER_BITS - reduce_bits_horiz;
455542
456543 let mut i = p_row;
457544 while i < p_row + p_height {
@@ -509,10 +596,11 @@ pub fn warp_affine(
509596 sum += tmp[(k + m + 4) as usize][(l + 4) as usize] * coeffs[m as usize] as i32;
510597 }
511598 sum = round2(sum as i64, reduce_bits_vert as u32) as i32;
512- let out_row = (i - p_row + k + 4) as usize;
513- let out_col = (j - p_col + l + 4) as usize;
514- dst[out_row * p_stride as usize + out_col] =
515- clip_pixel(sum - (1 << (BD - 1)) - (1 << BD));
599+ store(
600+ (i - p_row + k + 4) as usize,
601+ (j - p_col + l + 4) as usize,
602+ sum,
603+ );
516604 sy += gamma;
517605 l += 1;
518606 }
lanes/cwarp-r1.report.mdadded+98 -0
@@ -0,0 +1,98 @@
1+# lane-cwarp r1 -- per-reference GLOBAL warp on compound blocks
2+
3+VERDICT: DONE for the 8-bit path (new hard gate green, 37 real compound-warp
4+blocks). 10-bit arm is written but `#[ignore]`d, blocked by a PRE-EXISTING
5+10-bit *compound* MC defect this lane isolated but does not own.
6+
7+## Defect (charter premise re-measured, held)
8+`decode_inter_block`'s COMPOUND_REFERENCE branch predicted BOTH taps
9+translationally through `mc::predict_compound_intermediate`. libaom runs
10+`av1_init_warp_params` inside its per-reference loop
11+(`reconinter.c build_inter_predictors_8x8_and_bigger`), so each reference of a
12+`GLOBAL_GLOBALMV` block whose own gm model is > TRANSLATION is filtered through
13+`av1_warp_plane` into the compound intermediate. No refusal named this: the
14+pixels were silently wrong. Confirmed live -- the new gate hits 37 such blocks
15+in 6 real aomenc streams.
16+
17+`WARPED_CAUSAL` on a compound block: confirmed impossible, left alone.
18+libaom `decodemv.c read_motion_mode` -> `motion_mode_allowed` returns
19+SIMPLE_TRANSLATION for `has_second_ref(mbmi)`; spec 5.11.27 the same. So only
20+the GLOBAL arm of `allow_warp` is live on the compound path.
21+
22+## Changed
23+- `crates/ec-av1/src/warp.rs`
24+ - `warp_affine` split into a shared `warp_inner` + a store closure; the old
25+ hardcoded `const BD: i32 = 8` is now `crate::decode::bit_depth()` (the same
26+ thread-local `clip_pixel`/`sample_max` already use, so no call site moved).
27+ `REDUCE_BITS_HORIZ`/`COMPOUND_ROUND1_BITS` named from libaom's
28+ `conv_params->round_0`/`COMPOUND_ROUND1_BITS`.
29+ NOTE for lane-hbdinter: this is the whole of the warp bit-depth change --
30+ one `bd` local and two offset expressions, no signature change.
31+ - new `warp_affine_compound`: `av1_highbd_warp_affine_c`'s
32+ `conv_params->is_compound && !do_average` branch -- vertical pass rounds by
33+ `round_1 == 7` and the output stays in the compound intermediate domain.
34+ libaom's CONV_BUF carries a constant bias that its blend subtracts
35+ (`(1 << (offset_bits - round_1)) + (1 << (offset_bits - round_1 - 1))`);
36+ this crate's intermediates are unbiased, so exactly that constant --
37+ `(1 << (bd+4)) + (1 << (bd+3))` -- is removed here, making the output
38+ interchangeable with `mc::predict_compound_intermediate`'s for
39+ `combine_compound`/`blend_masked_compound`. Both offset terms survive their
40+ roundings exactly (each exceeds its shift), so bias removal is bit-exact,
41+ not an approximation.
42+- `crates/ec-av1/src/decode.rs`
43+ - compound branch: `is_global_mv0`/`is_global_mv1` hoisted out of the MiGrid
44+ stamp (and their size bound corrected from `bw4.min(bh4) >= 2`, which used
45+ the frame-CLIPPED write extent, to `side >= 8`, libaom's unclipped `bsize`
46+ -- differs only for a block whose visible extent is 4px);
47+ `compound_warp(ref, eligible)` builds each ref's `global_warp_params`
48+ (skipped on `force_integer_mv` or `gm.invalid`, mirroring
49+ `av1_init_warp_params` + `allow_warp`), and each of the six
50+ `predict_compound_intermediate` outputs is replaced by
51+ `warp_affine_compound` when that ref warps. Chroma is gated on
52+ `chroma_side >= 8` -- `av1_init_warp_params` returns early on
53+ `block_width < 8`, and that is the PLANE's block, so an 8x8 luma block's
54+ 4x4 chroma stays translational.
55+ - new `COMPOUND_WARP_HITS` counter + `compound_warp_hits()`.
56+- `crates/ec-av1/src/mc.rs` -- `diffwtd_mask`'s round is
57+ `2*FILTER_BITS - round_0 - round_1 + (bd - 8)` (libaom `diffwtd_mask_d16`,
58+ reconinter.c:306); the `(bd - 8)` term was missing (this function's own doc
59+ comment already named it), so every 10-bit DIFFWTD mask was 4x too coarse.
60+ Found while bisecting the 10-bit failure. 8-bit unaffected (`bd-8 == 0`).
61+ UNGATED: the only 10-bit compound gate is the ignored one below.
62+- `crates/ec-av1/src/stream.rs` -- `run_compound_global_warp_gate` + the two
63+ gates below. No refusal string existed for this defect, so none is lifted;
64+ `refusal_inventory.rs`/`gate_coverage.rs` needed no change (both green).
65+
66+## Gate
67+`a_real_compound_global_warp_stream_decodes_pixel_exact` (8-bit): rotating
68+mandelbrot (`rotate=a=RATE*n` over a 2x source, scaled to 64x64), 24 frames,
69+`--enable-global-motion=1 --enable-dist-wtd-comp=1 --lag-in-frames=25
70+--auto-alt-ref=1 --enable-warped-motion=1 --enable-masked-comp=1`, 3 cq x 2
71+rotation rates. Hard-asserts `compound_warp_hits() > 0` and `matched > 0`; a
72+decode error or a pixel mismatch is a panic, never a skip.
73+
74+EVIDENCE: cargo test -p ec-av1 --release --lib -- a_real_compound_global_warp --nocapture (EC_AV1_REQUIRE_AOMENC=1) | 6 real aomenc encodes, every display frame's Y/U/V vs ffmpeg | `6/6 pixel-exact, 0 named refusals, compound_warp_hits=37`
75+
76+EVIDENCE: same command with `--enable-global-motion=0 --enable-warped-motion=0` and, separately, `--auto-alt-ref=0 --lag-in-frames=0 --enable-dist-wtd-comp=0` (10-bit arm) | 2 ablation runs | warp-free 10-bit compound FAILS at frame 1 luma cq 32; 10-bit single-ref inter is 6/6 pixel-exact -> the residual is 10-bit COMPOUND, not warp
77+
78+EVIDENCE: cargo test -p ec-av1 --release --lib (EC_AV1_REQUIRE_AOMENC=1) | whole ec-av1 lib suite | **271 passed, 0 failed, 23 ignored**, 312s
79+
80+Hidden frames: the gate encodes with `--auto-alt-ref=1 --lag-in-frames=25`, so
81+hidden alt-refs exist and every shown frame that references them is compared;
82+a wrong hidden-frame reconstruction propagates into those. There is no
83+decode-order oracle compare here (the repo's `EC_AV1_DECODE_ORDER_DUMP` rung is
84+8-bit-only and manual) -- same standard as the other compound gates.
85+
86+## Residue
87+- deferred(the 10-bit compound MC defect): `a_real_compound_global_warp_10bit_stream_decodes_pixel_exact`
88+ is `#[ignore]`d with the ablation in its doc comment. Unblocked by whoever
89+ owns 10-bit compound MC; un-ignore it then -- the warp path under it is
90+ already bit-depth generic.
91+- flagged (same defect shape, NOT fixed): `decode_inter_block8`'s compound
92+ branch (decode.rs ~10969-11072 on this branch) has the identical
93+ translational-only compound prediction. For an 8x8 leaf the luma block is
94+ exactly 8x8, so libaom WOULD warp luma there (chroma 4x4 would not). Not
95+ wired this round: the 8x8 leaf's own gates are the subject of lane-gmaffine
96+ and a change here would land untested.
97+- accepted: `mc::diffwtd_mask`'s `(bd - 8)` fix is source-verified against
98+ libaom but has no green 10-bit gate behind it yet (see above).