From ddb5bef7b455cd95b15033d675d18fd41d526127 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Sat, 29 Aug 2026 00:04:10 +0300 Subject: [PATCH] feat(av1): port the DIFFWTD masked-compound blend (comp_group_idx==1), wedge still refused diffwtd_mask/blend_masked_compound in mc.rs, algebraically re-derived onto this crate's unbiased predict_compound_intermediate domain (libaom's round_offset bias cancels exactly in both the mask diff and the blend weight sum, proven in the doc comments -- no offset bookkeeping needed). Both comp_group_idx==1 decode.rs sites now build+apply the real blend for COMPOUND_DIFFWTD; COMPOUND_WEDGE still refuses by name (wedge codebook out of r2 scope per the charter's mergeable-partial fallback). Fixed a real latent bug while wiring this in: compound_idx was read unconditionally, missing libaom's comp_group_idx==0 outer gate (dead code before this round since the masked path always errored earlier). Gate a_real_aomenc_stream_with_masked_compound_decodes_pixel_exact flipped to hard assert (masked_compound_hits() > 0) with DIFFWTD refusals now forbidden; hammered 8/8 green, zero pixel mismatches. Full ec-av1 lib suite: 220 passed, 0 failed, 17 ignored. --- crates/ec-av1/src/decode.rs | 159 +++++++++++++++++++++++++++++------ crates/ec-av1/src/mc.rs | 64 ++++++++++++++ crates/ec-av1/src/stream.rs | 46 +++++----- lanes/maskcomp-r2.charter.md | 46 ++++++++++ lanes/maskcomp-r2.report.md | 59 +++++++++++++ 5 files changed, 324 insertions(+), 50 deletions(-) create mode 100644 lanes/maskcomp-r2.charter.md create mode 100644 lanes/maskcomp-r2.report.md diff --git a/crates/ec-av1/src/decode.rs b/crates/ec-av1/src/decode.rs index d3685bf3..927d7558 100644 --- a/crates/ec-av1/src/decode.rs +++ b/crates/ec-av1/src/decode.rs @@ -5187,6 +5187,12 @@ fn decode_inter_block( } else { 0 }; + // lane-maskcomp r2: `Some(mask_type)` only for a real + // `COMPOUND_DIFFWTD` block (`comp_group_idx == 1`, `compound_type + // == 1`) -- wedge (`compound_type == 0`) still refuses by name, + // its mask codebook unported (charter's mergeable-partial + // fallback). + let mut diffwtd_mask_type: Option = None; if comp_group_idx == 1 { // lane-maskcomp r1: `read_compound_type` (spec 5.11.25, // libaom `decodemv.c` 1634-1656). `is_interinter_compound_used @@ -5204,20 +5210,21 @@ fn decode_inter_block( }; let compound_type = dec.symbol(&mut cdfs.compound_type[wedge_bsize]); if compound_type == 0 { - // COMPOUND_WEDGE + // COMPOUND_WEDGE: mask codebook not ported (r2 scope). let _wedge_index = dec.symbol(&mut cdfs.wedge_idx[wedge_bsize]); let _wedge_sign = dec.literal(1); - } else { - // COMPOUND_DIFFWTD: `mask_type`, MAX_DIFFWTD_MASK_BITS==1. - let _mask_type = dec.literal(1); + MASKED_COMPOUND_HITS.fetch_add(1, std::sync::atomic::Ordering::Relaxed); + return Err(unsupported( + "a masked COMPOUND_REFERENCE block (comp_group_idx == 1, \ + COMPOUND_WEDGE) -- syntax consumed entropy-exact (compound_type/\ + wedge_idx/wedge_sign), but this decoder's wedge mask codebook is \ + not ported (lane-maskcomp r2 scope: DIFFWTD only)", + )); } + // COMPOUND_DIFFWTD: `mask_type`, MAX_DIFFWTD_MASK_BITS==1. + let mask_type = dec.literal(1); + diffwtd_mask_type = Some(mask_type as u8); MASKED_COMPOUND_HITS.fetch_add(1, std::sync::atomic::Ordering::Relaxed); - return Err(unsupported( - "a masked COMPOUND_REFERENCE block (comp_group_idx == 1, wedge/\ - diffwtd) -- syntax consumed entropy-exact (compound_type/wedge_idx/\ - wedge_sign/mask_type), but this decoder's compound blend does not yet \ - build the wedge/diffwtd mask, lane-maskcomp r1", - )); } // corner-cut (lane-av1comp r16/r17, lane-av1blend r1): r16/r17 // called this a `predict_compound_intermediate`/`combine_compound` @@ -5412,7 +5419,16 @@ fn decode_inter_block( // Re-masking: see that fixture + `scratch_isolate_pinned_mismatch` // (`EC_AV1_PIN=fixtures/av1idx-refsel-pin.obu EC_AV1_PIN_N=20`) // for the next round's starting point. - let (fwd_offset, bck_offset, compound_idx) = if !skip_mode && enable_jnt_comp { + // lane-maskcomp r2: `compound_idx` is only read when + // `comp_group_idx == 0` (libaom `decodemv.c:1606`) -- a masked + // (wedge/diffwtd) block never also carries a distance-weighted + // split. This gate was missing before r2 (dead code: the masked + // path always refused earlier, so it never executed with + // `comp_group_idx == 1` in practice). + let (fwd_offset, bck_offset, compound_idx) = if comp_group_idx == 0 + && !skip_mode + && enable_jnt_comp + { let idx_ctx = get_comp_index_context( neighbours, at, @@ -5496,7 +5512,23 @@ fn decode_inter_block( &mut inter1_y, ); let mut pred_y = vec![0u8; side * side]; - mc::combine_compound(&inter0_y, &inter1_y, fwd_offset, bck_offset, &mut pred_y); + let mut diffwtd_mask_y = Vec::new(); + if let Some(mask_type) = diffwtd_mask_type { + diffwtd_mask_y = vec![0u8; side * side]; + mc::diffwtd_mask(&inter0_y, &inter1_y, mask_type == 1, &mut diffwtd_mask_y); + mc::blend_masked_compound( + &inter0_y, + &inter1_y, + &diffwtd_mask_y, + side, + side, + side, + false, + &mut pred_y, + ); + } else { + mc::combine_compound(&inter0_y, &inter1_y, fwd_offset, bck_offset, &mut pred_y); + } let mut inter0_u = vec![0i32; chroma_side * chroma_side]; mc::predict_compound_intermediate( @@ -5527,7 +5559,20 @@ fn decode_inter_block( &mut inter1_u, ); let mut pred_u = vec![0u8; chroma_side * chroma_side]; - mc::combine_compound(&inter0_u, &inter1_u, fwd_offset, bck_offset, &mut pred_u); + if diffwtd_mask_type.is_some() { + mc::blend_masked_compound( + &inter0_u, + &inter1_u, + &diffwtd_mask_y, + side, + chroma_side, + chroma_side, + true, + &mut pred_u, + ); + } else { + mc::combine_compound(&inter0_u, &inter1_u, fwd_offset, bck_offset, &mut pred_u); + } let mut inter0_v = vec![0i32; chroma_side * chroma_side]; mc::predict_compound_intermediate( @@ -5558,7 +5603,20 @@ fn decode_inter_block( &mut inter1_v, ); let mut pred_v = vec![0u8; chroma_side * chroma_side]; - mc::combine_compound(&inter0_v, &inter1_v, fwd_offset, bck_offset, &mut pred_v); + if diffwtd_mask_type.is_some() { + mc::blend_masked_compound( + &inter0_v, + &inter1_v, + &diffwtd_mask_y, + side, + chroma_side, + chroma_side, + true, + &mut pred_v, + ); + } else { + mc::combine_compound(&inter0_v, &inter1_v, fwd_offset, bck_offset, &mut pred_v); + } if skip { y.reconstruct_mc(px, py, side, &pred_y, &vec![0i32; side * side]); @@ -6570,24 +6628,28 @@ fn decode_inter_block8( } else { 0 }; + // lane-maskcomp r2: see the 16x16/32x32 leaf's own comment. + let mut diffwtd_mask_type: Option = None; if comp_group_idx == 1 { // lane-maskcomp r1: see the 16x16 leaf's own comment // above -- SIDE==8 here, `wedge_bsize` index 3 // (BLOCK_8X8, `wedge_types > 0`). let compound_type = dec.symbol(&mut cdfs.compound_type[3]); if compound_type == 0 { + // COMPOUND_WEDGE: mask codebook not ported (r2 scope). let _wedge_index = dec.symbol(&mut cdfs.wedge_idx[3]); let _wedge_sign = dec.literal(1); - } else { - let _mask_type = dec.literal(1); + MASKED_COMPOUND_HITS.fetch_add(1, std::sync::atomic::Ordering::Relaxed); + return Err(unsupported( + "a masked COMPOUND_REFERENCE 8x8 leaf (comp_group_idx == 1, \ + COMPOUND_WEDGE) -- syntax consumed entropy-exact (compound_type/\ + wedge_idx/wedge_sign), but this decoder's wedge mask codebook is \ + not ported (lane-maskcomp r2 scope: DIFFWTD only)", + )); } + let mask_type = dec.literal(1); + diffwtd_mask_type = Some(mask_type as u8); MASKED_COMPOUND_HITS.fetch_add(1, std::sync::atomic::Ordering::Relaxed); - return Err(unsupported( - "a masked COMPOUND_REFERENCE 8x8 leaf (comp_group_idx == 1, wedge/\ - diffwtd) -- syntax consumed entropy-exact (compound_type/wedge_idx/\ - wedge_sign/mask_type), but this decoder's compound blend does not \ - yet build the wedge/diffwtd mask, lane-maskcomp r1", - )); } // corner-cut (lane-av1comp r16/r17, lane-av1blend r1): same // reference-slot defect as the 16x16 leaf's own mask above @@ -6602,7 +6664,10 @@ fn decode_inter_block8( // compound_idx defect surfaces on the wide gate sweep. // lane-av1idx r1: same re-mask as the 16x16 leaf above -- // see that comment. - let (fwd_offset, bck_offset, compound_idx) = if !skip_mode && enable_jnt_comp { + let (fwd_offset, bck_offset, compound_idx) = if comp_group_idx == 0 + && !skip_mode + && enable_jnt_comp + { let idx_ctx = get_comp_index_context( neighbours, outer_at, @@ -6691,7 +6756,23 @@ fn decode_inter_block8( &mut inter1_y, ); let mut pred_y = vec![0u8; SIDE * SIDE]; - mc::combine_compound(&inter0_y, &inter1_y, fwd_offset, bck_offset, &mut pred_y); + let mut diffwtd_mask_y = Vec::new(); + if let Some(mask_type) = diffwtd_mask_type { + diffwtd_mask_y = vec![0u8; SIDE * SIDE]; + mc::diffwtd_mask(&inter0_y, &inter1_y, mask_type == 1, &mut diffwtd_mask_y); + mc::blend_masked_compound( + &inter0_y, + &inter1_y, + &diffwtd_mask_y, + SIDE, + SIDE, + SIDE, + false, + &mut pred_y, + ); + } else { + mc::combine_compound(&inter0_y, &inter1_y, fwd_offset, bck_offset, &mut pred_y); + } let mut inter0_u = vec![0i32; CHROMA_SIDE * CHROMA_SIDE]; mc::predict_compound_intermediate( @@ -6722,7 +6803,20 @@ fn decode_inter_block8( &mut inter1_u, ); let mut pred_u = vec![0u8; CHROMA_SIDE * CHROMA_SIDE]; - mc::combine_compound(&inter0_u, &inter1_u, fwd_offset, bck_offset, &mut pred_u); + if diffwtd_mask_type.is_some() { + mc::blend_masked_compound( + &inter0_u, + &inter1_u, + &diffwtd_mask_y, + SIDE, + CHROMA_SIDE, + CHROMA_SIDE, + true, + &mut pred_u, + ); + } else { + mc::combine_compound(&inter0_u, &inter1_u, fwd_offset, bck_offset, &mut pred_u); + } let mut inter0_v = vec![0i32; CHROMA_SIDE * CHROMA_SIDE]; mc::predict_compound_intermediate( @@ -6753,7 +6847,20 @@ fn decode_inter_block8( &mut inter1_v, ); let mut pred_v = vec![0u8; CHROMA_SIDE * CHROMA_SIDE]; - mc::combine_compound(&inter0_v, &inter1_v, fwd_offset, bck_offset, &mut pred_v); + if diffwtd_mask_type.is_some() { + mc::blend_masked_compound( + &inter0_v, + &inter1_v, + &diffwtd_mask_y, + SIDE, + CHROMA_SIDE, + CHROMA_SIDE, + true, + &mut pred_v, + ); + } else { + mc::combine_compound(&inter0_v, &inter1_v, fwd_offset, bck_offset, &mut pred_v); + } if skip { y.reconstruct_mc(px, py, SIDE, &pred_y, &vec![0i32; SIDE * SIDE]); diff --git a/crates/ec-av1/src/mc.rs b/crates/ec-av1/src/mc.rs index ed3965da..30ad0e42 100644 --- a/crates/ec-av1/src/mc.rs +++ b/crates/ec-av1/src/mc.rs @@ -525,6 +525,70 @@ pub fn combine_compound( } } +/// lane-maskcomp r2: `build_compound_diffwtd_mask` (reconinter.c) -- +/// `DIFFWTD_38`/`DIFFWTD_38_INV` (`mask_type` bit: 0/1). Operates directly on +/// the two [`predict_compound_intermediate`] outputs: libaom's own +/// `av1_build_compound_diffwtd_mask_d16_c` runs on its CONV_BUF domain (which +/// carries a constant `round_offset` bias baked into every sample by its +/// convolve stage), but `abs(src0 - src1)` cancels an equal bias on both +/// sides exactly, so the unbiased `i32` intermediates this crate already +/// produces give the identical `diff` libaom computes. `round` is +/// `2*FILTER_BITS - round_0 - round_1 + (bd-8)` == [`INTER_POST_ROUND`] for +/// 8-bit content (`round_0=3`, compound `round_1=7`, `bd=8`). +pub fn diffwtd_mask(pred0: &[i32], pred1: &[i32], inv: bool, mask: &mut [u8]) { + assert_eq!(pred0.len(), pred1.len(), "both refs predict the same block"); + assert_eq!(mask.len(), pred0.len(), "one mask byte per pixel"); + for i in 0..mask.len() { + let diff = round2((pred0[i] - pred1[i]).abs(), INTER_POST_ROUND); + let m = (38 + diff / 16).clamp(0, 64); + mask[i] = if inv { (64 - m) as u8 } else { m as u8 }; + } +} + +/// lane-maskcomp r2: `aom_lowbd_blend_a64_d16_mask_c` (blend_a64_mask.c), +/// algebraically simplified to this crate's unbiased `i32` intermediate +/// domain the same way [`diffwtd_mask`]'s doc comment derives -- libaom's +/// `res -= round_offset` step cancels exactly against the bias `m + (64-m) +/// == 64` contributes equally from both inputs, leaving `(m*pred0 + +/// (64-m)*pred1) >> 6` (a plain, unrounded shift, matching the C `>>` on +/// `int32_t`) then one final [`round2`] by [`INTER_POST_ROUND`]. `mask` is +/// always the LUMA-resolution mask (`mask_stride` == luma block width); +/// `subsampled` selects the 2x2-average chroma read (spec 7.11.3.14 / +/// libaom's `subw == 1 && subh == 1` branch) vs. the direct luma read. +#[allow(clippy::too_many_arguments)] +pub fn blend_masked_compound( + pred0: &[i32], + pred1: &[i32], + mask: &[u8], + mask_stride: usize, + w: usize, + h: usize, + subsampled: bool, + dst: &mut [u8], +) { + assert_eq!(pred0.len(), w * h, "pred0 is the destination-sized block"); + assert_eq!(pred1.len(), w * h, "pred1 is the destination-sized block"); + assert_eq!(dst.len(), w * h, "the destination is the block"); + for i in 0..h { + for j in 0..w { + let m = if subsampled { + let idx = (2 * i) * mask_stride + 2 * j; + round2( + i32::from(mask[idx]) + + i32::from(mask[idx + 1]) + + i32::from(mask[idx + mask_stride]) + + i32::from(mask[idx + mask_stride + 1]), + 2, + ) + } else { + i32::from(mask[i * mask_stride + j]) + }; + let res = (m * pred0[i * w + j] + (64 - m) * pred1[i * w + j]) >> 6; + dst[i * w + j] = round2(res, INTER_POST_ROUND).clamp(0, 255) as u8; + } + } +} + /// Whole-pel identity case: [`predict_compound_intermediate`]'s two-pass /// filter reduces to `16 * source_sample` exactly (the fraction-0 row is a /// single `128` tap both passes, and `128*128 == 1 << 14`, `14 - 7 == 7 == diff --git a/crates/ec-av1/src/stream.rs b/crates/ec-av1/src/stream.rs index 0f1b6744..94f4a45c 100644 --- a/crates/ec-av1/src/stream.rs +++ b/crates/ec-av1/src/stream.rs @@ -3838,17 +3838,14 @@ mod tests { ); } - /// lane-maskcomp r1: `--enable-masked-comp=1 --enable-dist-wtd-comp=1` + /// lane-maskcomp r2: `--enable-masked-comp=1 --enable-dist-wtd-comp=1` /// streams must consume `compound_type`/`wedge_idx`/`wedge_sign`/ - /// `mask_type` entropy-exact (`masked_compound_hits() > 0`) whenever a - /// block reads `comp_group_idx == 1` -- the syntax is ported this - /// round, the wedge/diffwtd mask blend is NOT, so a masked-compound - /// refusal itself is still EXPECTED here (r1's own named refusal, - /// asserted for wording only) rather than forbidden; only OTHER named - /// refusals (screen content tools etc.) skip a seed without counting. - /// Once the blend lands, this gate's own masked-compound refusal - /// becomes forbidden like `a_real_aomenc_stream_with_interintra_...` - /// above's wedge case was for non-wedge interintra. + /// `mask_type` entropy-exact AND build the real DIFFWTD blend -- + /// `masked_compound_hits() > 0` is now a hard assert, and a + /// `COMPOUND_DIFFWTD` refusal is FORBIDDEN (matches interintra's own + /// gate). `COMPOUND_WEDGE` refusals are still EXPECTED (r2 scope: + /// wedge mask codebook not ported, charter's mergeable-partial + /// fallback) -- counted separately, never asserted against. #[test] fn a_real_aomenc_stream_with_masked_compound_decodes_pixel_exact() { const NAME: &str = "a_real_aomenc_stream_with_masked_compound_decodes_pixel_exact"; @@ -3974,6 +3971,11 @@ mod tests { "{NAME} refused on warp (seed {seed}) -- warp decode is ported: {msg}" ); if msg.contains("masked COMPOUND_REFERENCE") { + assert!( + msg.contains("COMPOUND_WEDGE"), + "{NAME} refused a non-wedge masked-compound block (seed {seed}) \ + -- DIFFWTD blend is ported, this refusal is forbidden: {msg}" + ); masked_refusals += 1; } else { assert!( @@ -4019,22 +4021,18 @@ mod tests { // is that sampling flake, not a decode regression -- check // masked_compound_hits/named_refusals in the panic message before // assuming a real bug. - // r1: a zero-hit run is the sampling flake above, not a regression -- - // report it loudly instead of failing the default suite (the interintra - // gate went through the same soft phase; r2 flips this to a hard - // assert once the blend lands and masked refusals become forbidden). - if crate::decode::masked_compound_hits() == 0 { - eprintln!( - "{NAME}: SOFT-SKIP -- zero masked-compound blocks fired ({masked_refusals} \ - masked refusals, {matched} matches, {named_refusals} other refusals out of \ - {n_attempts}); sampling flake, gate proved nothing this run" - ); - return; - } + // r2: DIFFWTD is ported and gated, so a zero-hit run is no longer + // soft-skipped -- hard assert, matching the interintra gate. + assert!( + crate::decode::masked_compound_hits() > 0, + "{NAME}: zero masked-compound blocks fired ({masked_refusals} wedge refusals, \ + {matched} matches, {named_refusals} other refusals out of {n_attempts}) -- gate \ + proved nothing this run" + ); eprintln!( "{NAME}: {named_refusals} other-capability refusals, {masked_refusals} expected \ - masked-compound refusals (r1: blend unported), {matched} pixel-exact matches out \ - of {n_attempts}, masked_compound_hits={}", + COMPOUND_WEDGE refusals (r2 scope: wedge unported), {matched} pixel-exact matches \ + out of {n_attempts}, masked_compound_hits={}", crate::decode::masked_compound_hits() ); } diff --git a/lanes/maskcomp-r2.charter.md b/lanes/maskcomp-r2.charter.md new file mode 100644 index 00000000..6be60602 --- /dev/null +++ b/lanes/maskcomp-r2.charter.md @@ -0,0 +1,46 @@ +# lane-maskcomp r2 charter — port the wedge/diffwtd masked-compound BLEND + +## Where you are +Worktree /home/user/Documents/Code/Rust/edith_codecs-maskcomp2, branch lane-maskcomp2 @ 5e25f76. +Build/test ONLY: `env CARGO_TARGET_DIR=$HOME/.cache/cargo-target-maskcomp2 cargo test -p ec-av1 --release --lib -- --nocapture` +FOREGROUND, `nice -n 19`, `CARGO_BUILD_JOBS=4`. Never push; never touch other worktrees; fixtures/ is a symlink — only new pinned .obu streams go in. + +## Current state (r1 landed in 5e25f76 — do not re-derive) +- comp_group_idx==1 syntax is entropy-exact at BOTH refusal sites (decode.rs ~5176 + leaf16/32, ~6558 leaf8): compound_type, wedge_idx (16-ary), wedge_sign (literal), + mask_type (literal) are consumed, then the blend refuses by name. Read + lanes/maskcomp-r1.report.md first. +- Gate a_real_aomenc_stream_with_masked_compound_decodes_pixel_exact exists; its own + masked-compound refusal is currently EXPECTED and a zero-hit run SOFT-SKIPs. +- Interintra blend (interintra_blend, decode.rs ~4410) is the shape to mirror for a + 64-scale mask blend: (mask*p0 + (64-mask)*p1 + 32) >> 6. + +## Scope r2: the blend +1. Wedge masks: port libaom's wedge codebook for the bsizes this decoder reaches + (8x8..32x32 squares; wedge is only used where av1_is_wedge_used(bsize)) — + reconinter.c av1_wedge_params_lookup + init_wedge_masks/init_wedge_master_masks + (the 64x64 master masks are built from wedge_master_oblique/vertical tables then + cropped/flipped per code + sign). Build them at first use or as consts; verify a + handful of mask rows against a C-side dump (patch a printf into + /tmp/libaom-src reconinter.c, rebuild /tmp/libaom-build with ninja) — do NOT + trust a hand transcription unchecked (class shared-oracle-blindness). +2. DIFFWTD masks: build_compound_diffwtd_mask (reconinter.c): per-pixel + mask = clamp(38 + (|p0-p1|) >> shift, 0, 64) for DIFFWTD_38, inverted for _INV + — port exactly, mind the bit-depth shift chain (class mirror-the-decoder-shift). +3. Chroma: av1_get_compound_type_mask + the subsampling path (chroma reads the luma + mask subsampled by 2x2 averaging? read av1_build_masked_compound / + aom_blend_a64_d16-vs-8bit paths carefully; this decoder is 8-bit). +4. Flip the gate: masked-compound refusals FORBIDDEN; zero-hit SOFT-SKIP becomes a + hard assert (hits > 0) with EC_MASKCOMP_GATE_ATTEMPTS=80 default kept. Hammer 8x + with EC_AV1_GATE_DUMP self-pin (/tmp/claude-1000/mc-flake-N.obu). +5. Any mismatch: pin to fixtures/, recon-dump (EC_AV1_PREFILT_DUMP) → range ladder + (exact ladder = prediction-side, i.e., your mask; ours[k]=aom[k+1]) → for mask + bugs dump the mask array both sides (add an env-gated eprintln; patch aomdec's + av1_make_masked_inter_predictor likewise). + +## Done criteria +1. Gate green with hard hits assert, 8/8 hammer; 11 pins byte-exact; lib suite green. +2. Committed to lane-maskcomp2; REPORT lanes/maskcomp-r2.report.md, verdict FIRST. +Commit + report BEFORE budget runs out. If the wedge codebook cannot be finished +verified, land DIFFWTD alone (flip only the diffwtd refusal) — partial capability +with exact naming is mergeable; an unverified wedge table is not. diff --git a/lanes/maskcomp-r2.report.md b/lanes/maskcomp-r2.report.md new file mode 100644 index 00000000..26cb5cee --- /dev/null +++ b/lanes/maskcomp-r2.report.md @@ -0,0 +1,59 @@ +# lane-maskcomp r2 report + +VERDICT: MERGEABLE PARTIAL -- DIFFWTD masked-compound blend ported and gated (hard assert, forbidden refusal, 8/8 hammer green, no pixel mismatches); wedge blend NOT ported, still refused by name (charter's mergeable-partial fallback: "land DIFFWTD alone"). + +## What landed +- `crates/ec-av1/src/mc.rs`: `diffwtd_mask` (`build_compound_diffwtd_mask`, reconinter.c) and + `blend_masked_compound` (`aom_lowbd_blend_a64_d16_mask_c`, blend_a64_mask.c), both algebraically + re-derived onto this crate's unbiased `i32` `predict_compound_intermediate` domain instead of + libaom's biased CONV_BUF representation -- proved on paper (doc comments) that libaom's + `round_offset` bias cancels exactly in both functions (`abs(src0-src1)` for the mask, `m + (64-m) + == 64` for the blend weight sum), so no offset bookkeeping is needed on our side. `round = + 2*FILTER_BITS - round_0 - round_1 + (bd-8)` reduces to the crate's existing `INTER_POST_ROUND` + (4) for 8-bit content, confirmed against the crate's own `INTER_ROUND_0`/`INTER_ROUND_1_COMPOUND` + constants (3/7) rather than hand-copied. +- `crates/ec-av1/src/decode.rs`: both `comp_group_idx == 1` sites (`decode_inter_block`'s + 16x16/32x32 leaf, `decode_inter_block8`'s 8x8 leaf) now split on `compound_type`: + `COMPOUND_WEDGE` (`compound_type == 0`) still refuses by name (wedge mask codebook out of scope + this round); `COMPOUND_DIFFWTD` (`compound_type == 1`) reads `mask_type` and falls through to + build+apply the real blend instead of erroring. Real bug fixed while wiring this in: + `compound_idx` (the distance-weighted-average symbol) was being read unconditionally on + `!skip_mode && enable_jnt_comp`, missing libaom's `comp_group_idx == 0` outer gate + (`decodemv.c:1606`) -- dead code before this round (the masked path always errored earlier so it + never executed with `comp_group_idx == 1` in practice), now gated correctly at both sites. +- `crates/ec-av1/src/stream.rs`: `a_real_aomenc_stream_with_masked_compound_decodes_pixel_exact` + flipped from r1's soft-skip/expected-refusal shape to r2's hard shape: `masked_compound_hits() > + 0` is now a hard `assert!` (was a soft-skip), a `COMPOUND_DIFFWTD` refusal is now FORBIDDEN + (asserted against, matching how the interintra gate treats its own ported capability), and a + `COMPOUND_WEDGE` refusal is still counted as expected/unasserted (r2 scope boundary). + +## Verification +- `cargo check -p ec-av1 --release`: clean (only pre-existing missing-doc warnings, same set as + before this round). +- Gate `a_real_aomenc_stream_with_masked_compound_decodes_pixel_exact`, hammered 8/8 (fresh + `EC_AV1_GATE_DUMP` self-pin path per run, `/tmp/claude-1000/mc-flake/mc-flake-{1..8}.obu`): all 8 + green, `masked_compound_hits` in {2,3,3,3,4,3,5,3} per run (never zero), zero `COMPOUND_WEDGE` + refusals fired in any run (content never picked wedge for this synthetic-gradients recipe, so the + wedge-still-refuses path is untested live this round -- syntax-level only, per r1), zero pixel + mismatches across all 80-attempt runs x 8 (`23-30 other-capability refusals` [screen-content-tools + RD flake, pre-existing/documented], `50-64 pixel-exact matches` per run). +- `cargo test -p ec-av1 --release --lib` (full scoped suite): 220 passed, 0 failed, 17 ignored, + finished in 140.58s -- includes all pre-existing pinned bit-exact regression tests, unaffected. + +## Deferred +- deferred: wedge mask codebook (`av1_wedge_params_lookup` + `init_wedge_master_masks`/ + `init_wedge_masks`, reconinter.c) -- explicitly out of r2 per the charter's mergeable-partial + fallback ("DIFFWTD alone... is mergeable; an unverified wedge table is not"). Unblocks by + transcribing `wedge_master_oblique_even/odd`/`wedge_master_vertical` + `wedge_codebook_16_*` + + `wedge_signflip_lookup`, building the 64x64 master masks and cropping/flipping per + `wedge_index`/`wedge_sign`, verifying a handful of mask rows against a live C-side printf dump + (per charter, not a hand transcription unchecked), then flipping the `COMPOUND_WEDGE` refusal + the same way this round flipped `COMPOUND_DIFFWTD`. +- deferred: a live gate run that actually exercises the `COMPOUND_WEDGE`-still-refuses path (to + prove the r2 gate's own `assert!(msg.contains("COMPOUND_WEDGE"))` line is reachable, not just + syntactically present) -- unblocks by a higher wedge-yield encoder recipe (aomenc's cpu-used=0 RD + never picked wedge over diffwtd/plain-average in any of this round's 8x80 = 640 attempts). + +## Commit +`feat(av1): port the DIFFWTD masked-compound blend (comp_group_idx==1), wedge still refused` on +branch lane-maskcomp2.