From d5ca61c8a32a27cffe7ba172a1f7e237d5ac509e 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 07:12:17 +0300 Subject: [PATCH] wip(sb128): r3 state -- compound tpl extension samples ported, inter refusal lifted --- crates/ec-av1/src/decode.rs | 16 ++++++++++ crates/ec-av1/src/mvstack.rs | 41 ++++++++++++++++++++++++++ crates/ec-av1/src/refusal_inventory.rs | 1 - crates/ec-av1/src/stream.rs | 15 ---------- 4 files changed, 57 insertions(+), 16 deletions(-) diff --git a/crates/ec-av1/src/decode.rs b/crates/ec-av1/src/decode.rs index b0b50c24..3b4649b4 100644 --- a/crates/ec-av1/src/decode.rs +++ b/crates/ec-av1/src/decode.rs @@ -14616,6 +14616,22 @@ fn decode_inter_block( force_integer_mv, (gm_table[(ref0 - LAST_FRAME) as usize], gm_table[(ref1 - LAST_FRAME) as usize]), ); + if std::env::var_os("EC_TRACE_MODE").is_some() { + eprintln!( + "EC_MODE_VAL mi_row={mi_row} mi_col={mi_col} mode={} ref0={ref0} ref1={ref1} mv0=({},{}) stack={} rng={}", + compound_mode + 17, + mv0.0, + mv0.1, + comp_stack.entries.len(), + dec.debug_state().0 + ); + for (i, e) in comp_stack.entries.iter().enumerate() { + eprintln!( + "EC_STACK mi_row={mi_row} mi_col={mi_col} i={i} this=({},{}) comp=({},{}) w={}", + e.mv0.0, e.mv0.1, e.mv1.0, e.mv1.1, e.weight + ); + } + } let is_globalmv = compound_mode == 6; // GLOBAL_GLOBALMV // spec `is_nontrans_global_motion`: ALL active refs' models must // be non-TRANSLATION (IDENTITY counts) for the compound block's diff --git a/crates/ec-av1/src/mvstack.rs b/crates/ec-av1/src/mvstack.rs index 6c77a20b..300fa320 100644 --- a/crates/ec-av1/src/mvstack.rs +++ b/crates/ec-av1/src/mvstack.rs @@ -1660,6 +1660,47 @@ pub fn find_mv_stack_compound( } blk_row += step_h; } + // lane-sb128 r3: libaom's three `tpl_sample_pos` EXTENSION samples + // (mvref_common.c:591), which the single-ref twin already ports and + // this compound path dropped. `check_sb_border`'s mask is libaom's + // hardcoded `mi_size_wide[BLOCK_64X64]` (16), NOT the sequence's + // superblock size. Missing them cost one weight-2 vote on a + // candidate, which reordered the stack and gave a NEW_NEWMV block a + // different predictor -- 957 wrong pixels on one 32x32 block of one + // frame with the entropy stream in sync. + let allow_extension = (2..16).contains(&bh4) && (2..16).contains(&bw4); + if allow_extension { + let (voffset, hoffset) = (bh4.max(2) as isize, bw4.max(2) as isize); + let sb_mask = 16isize; + for (row_off, col_off) in [ + (voffset, -2isize), + (voffset, hoffset), + (voffset - 2, hoffset), + ] { + let row = (mi_row as isize & (sb_mask - 1)) + row_off; + let col = (mi_col as isize & (sb_mask - 1)) + col_off; + if row < 0 || row >= sb_mask || col < 0 || col >= sb_mask { + continue; + } + let cand0 = crate::motion_field::add_tpl_ref_mv( + field, mi_row, mi_col, row_off, col_off, cur_offset_0, + allow_high_precision_mv, + ); + let cand1 = crate::motion_field::add_tpl_ref_mv( + field, mi_row, mi_col, row_off, col_off, cur_offset_1, + allow_high_precision_mv, + ); + if cand0.is_some() || cand1.is_some() { + any_hit = true; + add_compound_candidate( + &mut candidates, + cand0.map_or((0, 0), |c| c.mv), + cand1.map_or((0, 0), |c| c.mv), + 2, + ); + } + } + } if any_hit { TMV_HITS.fetch_add(1, std::sync::atomic::Ordering::Relaxed); } diff --git a/crates/ec-av1/src/refusal_inventory.rs b/crates/ec-av1/src/refusal_inventory.rs index 357febfd..32c5c199 100644 --- a/crates/ec-av1/src/refusal_inventory.rs +++ b/crates/ec-av1/src/refusal_inventory.rs @@ -45,7 +45,6 @@ const REFUSALS: &[&str] = &[ "a superblock-level partition value outside PARTITION_NONE..PARTITION_VERT_4", "a 128x128 superblock partition other than SPLIT (NONE/HORZ/VERT and the four AB arms at the 128 root are not decoded)", "intrabc under a 128x128 superblock (libaom's av1_is_dv_valid derives the block-vector delay from sb_size, which this decoder hardcodes to 64)", - "an inter frame under a 128x128 superblock (this decoder's inter tile path recurses a 64x64 superblock root only)", "a palette block on a HORZ/VERT intra strip below 16x16 (reconstruction not ported)", "a palette block with a real transform on a superblock-level HORZ/VERT strip (corner-cropped luma coefficients not ported for palette)", "a block that actually uses a palette (UV) -- reconstruction is out of scope", diff --git a/crates/ec-av1/src/stream.rs b/crates/ec-av1/src/stream.rs index e189a7c7..bd856bf9 100644 --- a/crates/ec-av1/src/stream.rs +++ b/crates/ec-av1/src/stream.rs @@ -492,19 +492,6 @@ pub fn decode_stream(data: &[u8]) -> Result> { .is_some_and(|seq| seq.use_128x128_superblock); let sb128_active = use_sb128 && (header.mi_cols > 16 || header.mi_rows > 16); crate::decode::set_sb128(sb128_active); - // lane-sb128 r2 RESIDUAL: the inter tile loop now reads the 128 root - // and walks libaom's quadrant order, and 8 of the 9 decode-order - // frames of the r2 gate stream are pixel-exact -- but frame 6 still - // differs (996 luma bytes, entropy in sync), and the SAME content at - // `--sb-size=64` is exact (`sb128_r2_control_sb64`), so the residual is - // sb128-specific. The refusal stays until that frame is exact: silent - // wrong pixels on his films are worse than a named stop. - if sb128_active && header.frame_type != FrameType::Key { - return Err(Error::unsupported( - "AV1 decode_stream", - "an inter frame under a 128x128 superblock (this decoder's inter tile path recurses a 64x64 superblock root only)", - )); - } // lane-hbd r5: `BIT_DEPTH` (decode.rs) drives `crate::decode::sample_max`, // which every dequant/inverse-transform clamp reads -- set per frame, // not once per process, for the same cross-sequence-on-one-thread @@ -16224,8 +16211,6 @@ mod tests { /// superblock), and temporal MV candidates (the inter-only path). Both bit /// depths -- his films are `yuv420p10le`. Only a missing tool SKIPs. #[test] - #[ignore = "lane-sb128 r2: reproducer for the residual frame-6 mismatch; the \ - product path still refuses inter frames at sb128 (see decode_stream)"] fn a_real_aomenc_inter_sequence_with_128x128_superblocks_decodes_pixel_exact() { const NAME: &str = "a_real_aomenc_inter_sequence_with_128x128_superblocks_decodes_pixel_exact";