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 commit8ff77a47dce838906dc9bc866cb3080557f29973Parent: 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
2 changed files +162 -9
- crates/ec-av1/src/decode.rs +141 -0
- crates/ec-av1/src/stream.rs +21 -9
crates/ec-av1/src/decode.rsmodified+141 -0
| @@ -1783,6 +1783,20 @@ pub(crate) fn compound_warp_hits() -> usize { | |||
| 1783 | COMPOUND_WARP_HITS.with(|c| c.get()) | 1783 | COMPOUND_WARP_HITS.with(|c| c.get()) |
| 1784 | } | 1784 | } |
| 1785 | 1785 | ||
| 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 | + | ||
| 1786 | // lane-gmaffine r1: how many blocks built their prediction from a | 1800 | // lane-gmaffine r1: how many blocks built their prediction from a |
| 1787 | // SIX-parameter (`AFFINE`) global-motion model through | 1801 | // SIX-parameter (`AFFINE`) global-motion model through |
| 1788 | // `crate::warp::global_warp_params` -- the gate's proof that a stream really | 1802 | // `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( | |||
| 14678 | // that isolate whether a decode-order frame's mismatch already exists | 14692 | // that isolate whether a decode-order frame's mismatch already exists |
| 14679 | // in reconstruction (this dump) vs is introduced by the loop filter | 14693 | // in reconstruction (this dump) vs is introduced by the loop filter |
| 14680 | // (EC_AV1_DECODE_ORDER_DUMP's post-filter dump). | 14694 | // (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 | + } | ||
| 14681 | dump_stage16("EC_AV1_PREFILT_DUMP16", &y, &u, &v, frame_width as usize, frame_height as usize); | 14702 | dump_stage16("EC_AV1_PREFILT_DUMP16", &y, &u, &v, frame_width as usize, frame_height as usize); |
| 14682 | if let Ok(path) = std::env::var("EC_AV1_PREFILT_DUMP") { | 14703 | if let Ok(path) = std::env::var("EC_AV1_PREFILT_DUMP") { |
| 14683 | use std::io::Write; | 14704 | use std::io::Write; |
| @@ -15742,6 +15763,71 @@ fn obmc_blend_h(dst: &mut [u16], stride: usize, ox: usize, oy: usize, w: usize, | |||
| 15742 | } | 15763 | } |
| 15743 | } | 15764 | } |
| 15744 | 15765 | ||
| 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 | + | ||
| 15745 | /// `av1_build_obmc_inter_prediction` (libaom `reconinter.c`): re-predicts | 15831 | /// `av1_build_obmc_inter_prediction` (libaom `reconinter.c`): re-predicts |
| 15746 | /// the overlap strip against each bordering above/left inter neighbour's own | 15832 | /// the overlap strip against each bordering above/left inter neighbour's own |
| 15747 | /// mv/ref/filter and blends it into this block's just-built single-reference | 15833 | /// mv/ref/filter and blends it into this block's just-built single-reference |
| @@ -15841,6 +15927,7 @@ fn obmc_blend( | |||
| 15841 | interp_fixed, | 15927 | interp_fixed, |
| 15842 | neighbours.above_filter[mi_col + off4], | 15928 | neighbours.above_filter[mi_col + off4], |
| 15843 | )?; | 15929 | )?; |
| 15930 | + ec_obmc_trace("above", mi_row, mi_col, write_w, write_h, off4, span4, &nb, h_kind, v_kind); | ||
| 15844 | let (ny, nu, nv) = ref_planes(nb.ref_frame, ref_y, ref_u, ref_v, other_refs)?; | 15931 | let (ny, nu, nv) = ref_planes(nb.ref_frame, ref_y, ref_u, ref_v, other_refs)?; |
| 15845 | let nb_scale = mc::scale_factor(ny.width, frame_width); | 15932 | let nb_scale = mc::scale_factor(ny.width, frame_width); |
| 15846 | let (bw, bh, ox) = (span4 * 4, overlap_above, off4 * 4); | 15933 | let (bw, bh, ox) = (span4 * 4, overlap_above, off4 * 4); |
| @@ -15860,6 +15947,7 @@ fn obmc_blend( | |||
| 15860 | interp_fixed, | 15947 | interp_fixed, |
| 15861 | neighbours.left_filter[mi_row + off4], | 15948 | neighbours.left_filter[mi_row + off4], |
| 15862 | )?; | 15949 | )?; |
| 15950 | + ec_obmc_trace("left", mi_row, mi_col, write_w, write_h, off4, span4, &nb, h_kind, v_kind); | ||
| 15863 | let (ny, nu, nv) = ref_planes(nb.ref_frame, ref_y, ref_u, ref_v, other_refs)?; | 15951 | let (ny, nu, nv) = ref_planes(nb.ref_frame, ref_y, ref_u, ref_v, other_refs)?; |
| 15864 | let nb_scale = mc::scale_factor(ny.width, frame_width); | 15952 | let nb_scale = mc::scale_factor(ny.width, frame_width); |
| 15865 | let (bw, bh, oy) = (overlap_left, span4 * 4, off4 * 4); | 15953 | let (bw, bh, oy) = (overlap_left, span4 * 4, off4 * 4); |
| @@ -19422,6 +19510,38 @@ fn decode_inter_block8( | |||
| 19422 | && global_motion[(ref0 - LAST_FRAME) as usize].model as u8 > 1; | 19510 | && global_motion[(ref0 - LAST_FRAME) as usize].model as u8 > 1; |
| 19423 | let is_global_mv1_c = is_globalmv_c | 19511 | let is_global_mv1_c = is_globalmv_c |
| 19424 | && global_motion[(ref1 - LAST_FRAME) as usize].model as u8 > 1; | 19512 | && 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 | + } | ||
| 19425 | for dr in 0..2 { | 19545 | for dr in 0..2 { |
| 19426 | for dc in 0..2 { | 19546 | for dc in 0..2 { |
| 19427 | grid.set( | 19547 | grid.set( |
| @@ -19459,6 +19579,13 @@ fn decode_inter_block8( | |||
| 19459 | v_filter, | 19579 | v_filter, |
| 19460 | &mut inter0_y, | 19580 | &mut inter0_y, |
| 19461 | ); | 19581 | ); |
| 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 | + } | ||
| 19462 | let mut inter1_y = vec![0i32; SIDE * SIDE]; | 19589 | let mut inter1_y = vec![0i32; SIDE * SIDE]; |
| 19463 | mc::predict_compound_intermediate( | 19590 | mc::predict_compound_intermediate( |
| 19464 | &py1.data, | 19591 | &py1.data, |
| @@ -19474,6 +19601,13 @@ fn decode_inter_block8( | |||
| 19474 | v_filter, | 19601 | v_filter, |
| 19475 | &mut inter1_y, | 19602 | &mut inter1_y, |
| 19476 | ); | 19603 | ); |
| 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 | + } | ||
| 19477 | let mut pred_y = vec![0u16; SIDE * SIDE]; | 19611 | let mut pred_y = vec![0u16; SIDE * SIDE]; |
| 19478 | let mut diffwtd_mask_y = Vec::new(); | 19612 | let mut diffwtd_mask_y = Vec::new(); |
| 19479 | let mask_y: Option<&[u8]> = if let Some(mask_type) = diffwtd_mask_type { | 19613 | 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( | |||
| 22587 | // that isolate whether a decode-order frame's mismatch already exists | 22721 | // that isolate whether a decode-order frame's mismatch already exists |
| 22588 | // in reconstruction (this dump) vs is introduced by the loop filter | 22722 | // in reconstruction (this dump) vs is introduced by the loop filter |
| 22589 | // (EC_AV1_DECODE_ORDER_DUMP's post-filter dump). | 22723 | // (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 | + } | ||
| 22590 | dump_stage16("EC_AV1_PREFILT_DUMP16", &y, &u, &v, frame_width as usize, frame_height as usize); | 22731 | dump_stage16("EC_AV1_PREFILT_DUMP16", &y, &u, &v, frame_width as usize, frame_height as usize); |
| 22591 | if let Ok(path) = std::env::var("EC_AV1_PREFILT_DUMP") { | 22732 | if let Ok(path) = std::env::var("EC_AV1_PREFILT_DUMP") { |
| 22592 | use std::io::Write; | 22733 | use std::io::Write; |
crates/ec-av1/src/stream.rsmodified+21 -9
| @@ -6319,15 +6319,20 @@ mod tests { | |||
| 6319 | // `decode_inter_block8`'s compound arm: `read_compound_ref_frames` was | 6319 | // `decode_inter_block8`'s compound arm: `read_compound_ref_frames` was |
| 6320 | // passed a hard-coded `LAST_FRAME` for every inter neighbour instead of | 6320 | // passed a hard-coded `LAST_FRAME` for every inter neighbour instead of |
| 6321 | // the real per-mi band, and the grid stamp cleared both per-slot | 6321 | // 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 | 6322 | + // `is_global_mv_block` flags. |
| 6323 | - // RECONSTRUCTION residue, not an entropy one: luma-only, |delta| <= 8, | 6323 | + // lane-interp3 r3: the luma reconstruction residue r2 left open is CLOSED |
| 6324 | - // first at decode frame 7 pixel (42,15) -- the 8x8 leaf at mi (10,4), | 6324 | + // and this gate is GREEN. Third instance of the same twin-drift class: |
| 6325 | - // spilling one pixel across its left/bottom deblock edges -- growing to | 6325 | + // libaom applies `allow_warp`'s GLOBAL branch to every |
| 6326 | - // 222 Y + 4 U + 1 V samples by frame 15 (pure propagation; chroma stays | 6326 | + // `is_global_mv_block` reference slot, compound included and independent |
| 6327 | - // exact until frame 14). Next round: the OBMC blend over a compound | 6327 | + // of `motion_mode` (`av1_init_warp_params` inside |
| 6328 | - // neighbour (the oracle's `EC_OBMC` rung prints `filt=` per neighbour; | 6328 | + // `build_inter_predictors_8x8_and_bigger`'s per-`ref` loop) -- the 16x16+ |
| 6329 | - // this decoder has no `EC_OBMC` emitter yet -- build it first). | 6329 | + // compound arm has warped since lane-cwarp r1, the 8x8 leaf's compound arm |
| 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))"] | 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. | ||
| 6331 | #[test] | 6336 | #[test] |
| 6332 | fn a_real_aomenc_dual_filter_obmc_8x8_inter_sequence_decodes_pixel_exact() { | 6337 | fn a_real_aomenc_dual_filter_obmc_8x8_inter_sequence_decodes_pixel_exact() { |
| 6333 | const NAME: &str = | 6338 | const NAME: &str = |
| @@ -6338,6 +6343,7 @@ mod tests { | |||
| 6338 | } | 6343 | } |
| 6339 | let before_dual = decode::dual_filter_diff_hits(); | 6344 | let before_dual = decode::dual_filter_diff_hits(); |
| 6340 | let before_obmc = decode::obmc_hits_8(); | 6345 | let before_obmc = decode::obmc_hits_8(); |
| 6346 | + let before_cwarp8 = decode::compound_warp_hits_8(); | ||
| 6341 | inter_sb_none_gate( | 6347 | inter_sb_none_gate( |
| 6342 | NAME, | 6348 | NAME, |
| 6343 | false, | 6349 | false, |
| @@ -6369,6 +6375,12 @@ mod tests { | |||
| 6369 | decode::obmc_hits_8() > before_obmc, | 6375 | decode::obmc_hits_8() > before_obmc, |
| 6370 | "{NAME}: no 8x8 OBMC blend fired -- --enable-obmc=1 did not arrive" | 6376 | "{NAME}: no 8x8 OBMC blend fired -- --enable-obmc=1 did not arrive" |
| 6371 | ); | 6377 | ); |
| 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 | + ); | ||
| 6372 | } | 6384 | } |
| 6373 | 6385 | ||
| 6374 | #[test] | 6386 | #[test] |