forge
Explore
Log in

Don't you dare go Hollow

The 8x8 COMPOUND leaf predicted both taps translationally -- libaom warps every is_global_mv_block slot independently of motion_mode, so a GLOBAL_GLOBALMV 8x8 compound leaf under a non-TRANSLATION model drifted a few luma levels

Browse files at this commit

8ff77a47dce838906dc9bc866cb3080557f29973Ahmet Kaan GümüşParent: a65c70e
  • fix
    • the 8x8 COMPOUND leaf predicted both taps translationally -- libaom warps every is_global_mv_block slot independently of motion_mode, so a GLOBAL_GLOBALMV 8x8 compound leaf under a non-TRANSLATION model drifted a few luma levels
    • the 16-frame dual-filter/OBMC gate is now pre-filter byte-exact on all 16 decode-order frames and un-ignored
Show full message
fix(av1): the 8x8 COMPOUND leaf predicted both taps translationally -- libaom warps every is_global_mv_block slot independently of motion_mode, so a GLOBAL_GLOBALMV 8x8 compound leaf under a non-TRANSLATION model drifted a few luma levels; the 16-frame dual-filter/OBMC gate is now pre-filter byte-exact on all 16 decode-order frames and un-ignored

Third instance of the twin-functions-drift class in this lane: decode_inter_block's
compound arm has applied allow_warp's GLOBAL branch per reference slot since
lane-cwarp r1, decode_inter_block8's compound arm never did.

Also adds the EC_OBMC rung (aomdec's own byte format) plus an EC_PICT
decode-order frame marker; the 325 EC_OBMC lines diff clean against the
instrumented aomdec, which exonerates the OBMC neighbour fields the r2
handoff suspected.
crates/ec-av1/src/decode.rsmodified+141 -0
@@ -1783,6 +1783,20 @@ pub(crate) fn compound_warp_hits() -> usize {
17831783 COMPOUND_WARP_HITS.with(|c| c.get())
17841784 }
17851785
1786+// lane-interp3 r3: the same proof narrowed to the 8x8 LEAF's own compound
1787+// arm ([`decode_inter_block8`]) -- that arm predicted both taps
1788+// translationally until r3, so a gate needs to tell a warped 8x8 compound
1789+// leaf apart from a warped 16x16+ one (both bump [`COMPOUND_WARP_HITS`]).
1790+thread_local! {
1791+ static COMPOUND_WARP_HITS_8: std::cell::Cell<usize> =
1792+ const { std::cell::Cell::new(0) };
1793+}
1794+
1795+/// Current value of [`COMPOUND_WARP_HITS_8`].
1796+pub(crate) fn compound_warp_hits_8() -> usize {
1797+ COMPOUND_WARP_HITS_8.with(|c| c.get())
1798+}
1799+
17861800 // lane-gmaffine r1: how many blocks built their prediction from a
17871801 // SIX-parameter (`AFFINE`) global-motion model through
17881802 // `crate::warp::global_warp_params` -- the gate's proof that a stream really
@@ -14678,6 +14692,13 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
1467814692 // that isolate whether a decode-order frame's mismatch already exists
1467914693 // in reconstruction (this dump) vs is introduced by the loop filter
1468014694 // (EC_AV1_DECODE_ORDER_DUMP's post-filter dump).
14695+ // Decode-order frame marker for the EC_OBMC / EC_TRACE_MODE ladders.
14696+ if std::env::var_os("EC_OBMC").is_some() || std::env::var_os("EC_TRACE_MODE").is_some() {
14697+ eprintln!(
14698+ "EC_PICT idx={}",
14699+ PREFILT_PICTURE_IDX.load(std::sync::atomic::Ordering::SeqCst)
14700+ );
14701+ }
1468114702 dump_stage16("EC_AV1_PREFILT_DUMP16", &y, &u, &v, frame_width as usize, frame_height as usize);
1468214703 if let Ok(path) = std::env::var("EC_AV1_PREFILT_DUMP") {
1468314704 use std::io::Write;
@@ -15742,6 +15763,71 @@ fn obmc_blend_h(dst: &mut [u16], stride: usize, ox: usize, oy: usize, w: usize,
1574215763 }
1574315764 }
1574415765
15766+/// libaom's own `BLOCK_SIZE` enum index for a `w4`x`h4` (mi-unit) block --
15767+/// only for the `EC_OBMC` trace rung below, so it reads byte-identical to
15768+/// the instrumented aomdec's `backup_mbmi.bsize`.
15769+fn ec_obmc_bsize(w4: usize, h4: usize) -> i32 {
15770+ match (w4, h4) {
15771+ (1, 1) => 0,
15772+ (1, 2) => 1,
15773+ (2, 1) => 2,
15774+ (2, 2) => 3,
15775+ (2, 4) => 4,
15776+ (4, 2) => 5,
15777+ (4, 4) => 6,
15778+ (4, 8) => 7,
15779+ (8, 4) => 8,
15780+ (8, 8) => 9,
15781+ (8, 16) => 10,
15782+ (16, 8) => 11,
15783+ (16, 16) => 12,
15784+ (1, 4) => 16,
15785+ (4, 1) => 17,
15786+ (2, 8) => 18,
15787+ (8, 2) => 19,
15788+ (4, 16) => 20,
15789+ (16, 4) => 21,
15790+ _ => -1,
15791+ }
15792+}
15793+
15794+/// The `EC_OBMC` rung: one line per blended neighbour, in the instrumented
15795+/// aomdec's own byte format (`decodeframe.c`
15796+/// `dec_build_prediction_by_{above,left}_pred`), so the two decoders' OBMC
15797+/// neighbour lists diff line for line. `filt` is libaom's packed
15798+/// `interp_filters.as_int` = `y_filter | (x_filter << 16)`.
15799+#[allow(clippy::too_many_arguments)]
15800+fn ec_obmc_trace(
15801+ dir: &str,
15802+ mi_row: usize,
15803+ mi_col: usize,
15804+ write_w: usize,
15805+ write_h: usize,
15806+ rel: usize,
15807+ op: usize,
15808+ nb: &MiInfo,
15809+ h_kind: mc::InterpFilterKind,
15810+ v_kind: mc::InterpFilterKind,
15811+) {
15812+ if std::env::var_os("EC_OBMC").is_none() {
15813+ return;
15814+ }
15815+ let sym = |k: mc::InterpFilterKind| match k {
15816+ mc::InterpFilterKind::Smooth => 1u32,
15817+ mc::InterpFilterKind::Sharp => 2,
15818+ _ => 0,
15819+ };
15820+ eprintln!(
15821+ "EC_OBMC {dir} mi=({mi_row},{mi_col}) wh=({write_w}x{write_h}) rel={rel} op={op} \
15822+nbmv=({},{}) nbref={} nbbsize={} filt={}",
15823+ nb.mv.0,
15824+ nb.mv.1,
15825+ nb.ref_frame,
15826+ ec_obmc_bsize(nb.size, nb.size_h),
15827+ sym(v_kind) | (sym(h_kind) << 16),
15828+ );
15829+}
15830+
1574515831 /// `av1_build_obmc_inter_prediction` (libaom `reconinter.c`): re-predicts
1574615832 /// the overlap strip against each bordering above/left inter neighbour's own
1574715833 /// mv/ref/filter and blends it into this block's just-built single-reference
@@ -15841,6 +15927,7 @@ fn obmc_blend(
1584115927 interp_fixed,
1584215928 neighbours.above_filter[mi_col + off4],
1584315929 )?;
15930+ ec_obmc_trace("above", mi_row, mi_col, write_w, write_h, off4, span4, &nb, h_kind, v_kind);
1584415931 let (ny, nu, nv) = ref_planes(nb.ref_frame, ref_y, ref_u, ref_v, other_refs)?;
1584515932 let nb_scale = mc::scale_factor(ny.width, frame_width);
1584615933 let (bw, bh, ox) = (span4 * 4, overlap_above, off4 * 4);
@@ -15860,6 +15947,7 @@ fn obmc_blend(
1586015947 interp_fixed,
1586115948 neighbours.left_filter[mi_row + off4],
1586215949 )?;
15950+ ec_obmc_trace("left", mi_row, mi_col, write_w, write_h, off4, span4, &nb, h_kind, v_kind);
1586315951 let (ny, nu, nv) = ref_planes(nb.ref_frame, ref_y, ref_u, ref_v, other_refs)?;
1586415952 let nb_scale = mc::scale_factor(ny.width, frame_width);
1586515953 let (bw, bh, oy) = (overlap_left, span4 * 4, off4 * 4);
@@ -19422,6 +19510,38 @@ fn decode_inter_block8(
1942219510 && global_motion[(ref0 - LAST_FRAME) as usize].model as u8 > 1;
1942319511 let is_global_mv1_c = is_globalmv_c
1942419512 && global_motion[(ref1 - LAST_FRAME) as usize].model as u8 > 1;
19513+ // lane-interp3 r3 (class twin-functions-drift, second
19514+ // instance): libaom applies `allow_warp`'s GLOBAL branch
19515+ // (`reconinter.c:33-55`, reached from `av1_init_warp_params`
19516+ // inside `build_inter_predictors_8x8_and_bigger`'s per-`ref`
19517+ // loop) to EVERY `is_global_mv_block` slot, compound
19518+ // included and independently of `motion_mode` -- the 16x16+
19519+ // compound arm has done this since lane-cwarp r1, this leaf
19520+ // predicted both taps translationally, so a GLOBAL_GLOBALMV
19521+ // 8x8 compound leaf under a non-TRANSLATION model drifted by
19522+ // a few luma levels, growing away from the block origin.
19523+ // `force_integer_mv` short-circuits `av1_init_warp_params`
19524+ // before `allow_warp`; chroma is 4x4 here, below
19525+ // `av1_init_warp_params`'s own 8px per-plane bound, so only
19526+ // luma warps (same rule as this leaf's single-ref arm).
19527+ let leaf_compound_warp = |ref_frame: i8, eligible: bool| {
19528+ if eligible
19529+ && !force_integer_mv
19530+ && !global_motion[(ref_frame - LAST_FRAME) as usize].invalid
19531+ {
19532+ crate::warp::global_warp_params(
19533+ global_motion[(ref_frame - LAST_FRAME) as usize].params,
19534+ )
19535+ } else {
19536+ None
19537+ }
19538+ };
19539+ let warp0_c = leaf_compound_warp(ref0, is_global_mv0_c);
19540+ let warp1_c = leaf_compound_warp(ref1, is_global_mv1_c);
19541+ if warp0_c.is_some() || warp1_c.is_some() {
19542+ COMPOUND_WARP_HITS.with(|c| c.set(c.get() + 1));
19543+ COMPOUND_WARP_HITS_8.with(|c| c.set(c.get() + 1));
19544+ }
1942519545 for dr in 0..2 {
1942619546 for dc in 0..2 {
1942719547 grid.set(
@@ -19459,6 +19579,13 @@ fn decode_inter_block8(
1945919579 v_filter,
1946019580 &mut inter0_y,
1946119581 );
19582+ if let Some(wp) = &warp0_c {
19583+ crate::warp::warp_affine_compound(
19584+ wp, &py0.data, py0.true_width as i32, py0.true_height as i32,
19585+ py0.width as i32, &mut inter0_y, px as i32, py as i32, SIDE as i32,
19586+ SIDE as i32, SIDE as i32, 0, 0,
19587+ );
19588+ }
1946219589 let mut inter1_y = vec![0i32; SIDE * SIDE];
1946319590 mc::predict_compound_intermediate(
1946419591 &py1.data,
@@ -19474,6 +19601,13 @@ fn decode_inter_block8(
1947419601 v_filter,
1947519602 &mut inter1_y,
1947619603 );
19604+ if let Some(wp) = &warp1_c {
19605+ crate::warp::warp_affine_compound(
19606+ wp, &py1.data, py1.true_width as i32, py1.true_height as i32,
19607+ py1.width as i32, &mut inter1_y, px as i32, py as i32, SIDE as i32,
19608+ SIDE as i32, SIDE as i32, 0, 0,
19609+ );
19610+ }
1947719611 let mut pred_y = vec![0u16; SIDE * SIDE];
1947819612 let mut diffwtd_mask_y = Vec::new();
1947919613 let mask_y: Option<&[u8]> = if let Some(mask_type) = diffwtd_mask_type {
@@ -22587,6 +22721,13 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
2258722721 // that isolate whether a decode-order frame's mismatch already exists
2258822722 // in reconstruction (this dump) vs is introduced by the loop filter
2258922723 // (EC_AV1_DECODE_ORDER_DUMP's post-filter dump).
22724+ // Decode-order frame marker for the EC_OBMC / EC_TRACE_MODE ladders.
22725+ if std::env::var_os("EC_OBMC").is_some() || std::env::var_os("EC_TRACE_MODE").is_some() {
22726+ eprintln!(
22727+ "EC_PICT idx={}",
22728+ PREFILT_PICTURE_IDX.load(std::sync::atomic::Ordering::SeqCst)
22729+ );
22730+ }
2259022731 dump_stage16("EC_AV1_PREFILT_DUMP16", &y, &u, &v, frame_width as usize, frame_height as usize);
2259122732 if let Ok(path) = std::env::var("EC_AV1_PREFILT_DUMP") {
2259222733 use std::io::Write;
crates/ec-av1/src/stream.rsmodified+21 -9
@@ -6319,15 +6319,20 @@ mod tests {
63196319 // `decode_inter_block8`'s compound arm: `read_compound_ref_frames` was
63206320 // passed a hard-coded `LAST_FRAME` for every inter neighbour instead of
63216321 // the real per-mi band, and the grid stamp cleared both per-slot
6322- // `is_global_mv_block` flags. This gate stays RED and ignored on a
6323- // RECONSTRUCTION residue, not an entropy one: luma-only, |delta| <= 8,
6324- // first at decode frame 7 pixel (42,15) -- the 8x8 leaf at mi (10,4),
6325- // spilling one pixel across its left/bottom deblock edges -- growing to
6326- // 222 Y + 4 U + 1 V samples by frame 15 (pure propagation; chroma stays
6327- // exact until frame 14). Next round: the OBMC blend over a compound
6328- // neighbour (the oracle's `EC_OBMC` rung prints `filt=` per neighbour;
6329- // this decoder has no `EC_OBMC` emitter yet -- build it first).
6330- #[ignore = "lane-interp3 r2: entropy is now exact on the whole stream (range ladder 570/570); RED on a luma-only reconstruction residue from decode frame 7 (|delta| <= 8, first at the 8x8 leaf mi (10,4))"]
6322+ // `is_global_mv_block` flags.
6323+ // lane-interp3 r3: the luma reconstruction residue r2 left open is CLOSED
6324+ // and this gate is GREEN. Third instance of the same twin-drift class:
6325+ // libaom applies `allow_warp`'s GLOBAL branch to every
6326+ // `is_global_mv_block` reference slot, compound included and independent
6327+ // of `motion_mode` (`av1_init_warp_params` inside
6328+ // `build_inter_predictors_8x8_and_bigger`'s per-`ref` loop) -- the 16x16+
6329+ // compound arm has warped since lane-cwarp r1, the 8x8 leaf's compound arm
6330+ // predicted BOTH taps translationally, so a GLOBAL_GLOBALMV 8x8 compound
6331+ // leaf under a non-TRANSLATION model drifted a few luma levels, growing
6332+ // away from the block origin. It was NOT OBMC: the `EC_OBMC` emitter this
6333+ // round added to `decode.rs` diffs 325/325 lines against the instrumented
6334+ // aomdec's own rung (position, span, neighbour mv/ref/bsize/filter) with
6335+ // zero differences.
63316336 #[test]
63326337 fn a_real_aomenc_dual_filter_obmc_8x8_inter_sequence_decodes_pixel_exact() {
63336338 const NAME: &str =
@@ -6338,6 +6343,7 @@ mod tests {
63386343 }
63396344 let before_dual = decode::dual_filter_diff_hits();
63406345 let before_obmc = decode::obmc_hits_8();
6346+ let before_cwarp8 = decode::compound_warp_hits_8();
63416347 inter_sb_none_gate(
63426348 NAME,
63436349 false,
@@ -6369,6 +6375,12 @@ mod tests {
63696375 decode::obmc_hits_8() > before_obmc,
63706376 "{NAME}: no 8x8 OBMC blend fired -- --enable-obmc=1 did not arrive"
63716377 );
6378+ assert!(
6379+ decode::compound_warp_hits_8() > before_cwarp8,
6380+ "{NAME}: no 8x8 COMPOUND leaf was predicted through the per-ref GLOBAL \
6381+ warp -- the r3 root-cause path never fired, so this stream no longer \
6382+ proves it"
6383+ );
63726384 }
63736385
63746386 #[test]