Port the DIFFWTD masked-compound blend (comp_group_idx==1), wedge still refused
Browse files at this commitddb5bef7b455cd95b15033d675d18fd41d526127Parent: 37a8819- feat
- port the DIFFWTD masked-compound blend (comp_group_idx==1), wedge still refused
5 changed files +324 -50
- crates/ec-av1/src/decode.rs +133 -26
- crates/ec-av1/src/mc.rs +64 -0
- crates/ec-av1/src/stream.rs +22 -24
- lanes/maskcomp-r2.charter.md +46 -0
- lanes/maskcomp-r2.report.md +59 -0
crates/ec-av1/src/decode.rsmodified+133 -26
| @@ -5187,6 +5187,12 @@ fn decode_inter_block( | |||
| 5187 | } else { | 5187 | } else { |
| 5188 | 0 | 5188 | 0 |
| 5189 | }; | 5189 | }; |
| 5190 | + // lane-maskcomp r2: `Some(mask_type)` only for a real | ||
| 5191 | + // `COMPOUND_DIFFWTD` block (`comp_group_idx == 1`, `compound_type | ||
| 5192 | + // == 1`) -- wedge (`compound_type == 0`) still refuses by name, | ||
| 5193 | + // its mask codebook unported (charter's mergeable-partial | ||
| 5194 | + // fallback). | ||
| 5195 | + let mut diffwtd_mask_type: Option<u8> = None; | ||
| 5190 | if comp_group_idx == 1 { | 5196 | if comp_group_idx == 1 { |
| 5191 | // lane-maskcomp r1: `read_compound_type` (spec 5.11.25, | 5197 | // lane-maskcomp r1: `read_compound_type` (spec 5.11.25, |
| 5192 | // libaom `decodemv.c` 1634-1656). `is_interinter_compound_used | 5198 | // libaom `decodemv.c` 1634-1656). `is_interinter_compound_used |
| @@ -5204,20 +5210,21 @@ fn decode_inter_block( | |||
| 5204 | }; | 5210 | }; |
| 5205 | let compound_type = dec.symbol(&mut cdfs.compound_type[wedge_bsize]); | 5211 | let compound_type = dec.symbol(&mut cdfs.compound_type[wedge_bsize]); |
| 5206 | if compound_type == 0 { | 5212 | if compound_type == 0 { |
| 5207 | - // COMPOUND_WEDGE | 5213 | + // COMPOUND_WEDGE: mask codebook not ported (r2 scope). |
| 5208 | let _wedge_index = dec.symbol(&mut cdfs.wedge_idx[wedge_bsize]); | 5214 | let _wedge_index = dec.symbol(&mut cdfs.wedge_idx[wedge_bsize]); |
| 5209 | let _wedge_sign = dec.literal(1); | 5215 | let _wedge_sign = dec.literal(1); |
| 5210 | - } else { | 5216 | + MASKED_COMPOUND_HITS.fetch_add(1, std::sync::atomic::Ordering::Relaxed); |
| 5211 | - // COMPOUND_DIFFWTD: `mask_type`, MAX_DIFFWTD_MASK_BITS==1. | 5217 | + return Err(unsupported( |
| 5212 | - let _mask_type = dec.literal(1); | 5218 | + "a masked COMPOUND_REFERENCE block (comp_group_idx == 1, \ |
| 5219 | + COMPOUND_WEDGE) -- syntax consumed entropy-exact (compound_type/\ | ||
| 5220 | + wedge_idx/wedge_sign), but this decoder's wedge mask codebook is \ | ||
| 5221 | + not ported (lane-maskcomp r2 scope: DIFFWTD only)", | ||
| 5222 | + )); | ||
| 5213 | } | 5223 | } |
| 5224 | + // COMPOUND_DIFFWTD: `mask_type`, MAX_DIFFWTD_MASK_BITS==1. | ||
| 5225 | + let mask_type = dec.literal(1); | ||
| 5226 | + diffwtd_mask_type = Some(mask_type as u8); | ||
| 5214 | MASKED_COMPOUND_HITS.fetch_add(1, std::sync::atomic::Ordering::Relaxed); | 5227 | MASKED_COMPOUND_HITS.fetch_add(1, std::sync::atomic::Ordering::Relaxed); |
| 5215 | - return Err(unsupported( | ||
| 5216 | - "a masked COMPOUND_REFERENCE block (comp_group_idx == 1, wedge/\ | ||
| 5217 | - diffwtd) -- syntax consumed entropy-exact (compound_type/wedge_idx/\ | ||
| 5218 | - wedge_sign/mask_type), but this decoder's compound blend does not yet \ | ||
| 5219 | - build the wedge/diffwtd mask, lane-maskcomp r1", | ||
| 5220 | - )); | ||
| 5221 | } | 5228 | } |
| 5222 | // corner-cut (lane-av1comp r16/r17, lane-av1blend r1): r16/r17 | 5229 | // corner-cut (lane-av1comp r16/r17, lane-av1blend r1): r16/r17 |
| 5223 | // called this a `predict_compound_intermediate`/`combine_compound` | 5230 | // called this a `predict_compound_intermediate`/`combine_compound` |
| @@ -5412,7 +5419,16 @@ fn decode_inter_block( | |||
| 5412 | // Re-masking: see that fixture + `scratch_isolate_pinned_mismatch` | 5419 | // Re-masking: see that fixture + `scratch_isolate_pinned_mismatch` |
| 5413 | // (`EC_AV1_PIN=fixtures/av1idx-refsel-pin.obu EC_AV1_PIN_N=20`) | 5420 | // (`EC_AV1_PIN=fixtures/av1idx-refsel-pin.obu EC_AV1_PIN_N=20`) |
| 5414 | // for the next round's starting point. | 5421 | // for the next round's starting point. |
| 5415 | - let (fwd_offset, bck_offset, compound_idx) = if !skip_mode && enable_jnt_comp { | 5422 | + // lane-maskcomp r2: `compound_idx` is only read when |
| 5423 | + // `comp_group_idx == 0` (libaom `decodemv.c:1606`) -- a masked | ||
| 5424 | + // (wedge/diffwtd) block never also carries a distance-weighted | ||
| 5425 | + // split. This gate was missing before r2 (dead code: the masked | ||
| 5426 | + // path always refused earlier, so it never executed with | ||
| 5427 | + // `comp_group_idx == 1` in practice). | ||
| 5428 | + let (fwd_offset, bck_offset, compound_idx) = if comp_group_idx == 0 | ||
| 5429 | + && !skip_mode | ||
| 5430 | + && enable_jnt_comp | ||
| 5431 | + { | ||
| 5416 | let idx_ctx = get_comp_index_context( | 5432 | let idx_ctx = get_comp_index_context( |
| 5417 | neighbours, | 5433 | neighbours, |
| 5418 | at, | 5434 | at, |
| @@ -5496,7 +5512,23 @@ fn decode_inter_block( | |||
| 5496 | &mut inter1_y, | 5512 | &mut inter1_y, |
| 5497 | ); | 5513 | ); |
| 5498 | let mut pred_y = vec![0u8; side * side]; | 5514 | let mut pred_y = vec![0u8; side * side]; |
| 5499 | - mc::combine_compound(&inter0_y, &inter1_y, fwd_offset, bck_offset, &mut pred_y); | 5515 | + let mut diffwtd_mask_y = Vec::new(); |
| 5516 | + if let Some(mask_type) = diffwtd_mask_type { | ||
| 5517 | + diffwtd_mask_y = vec![0u8; side * side]; | ||
| 5518 | + mc::diffwtd_mask(&inter0_y, &inter1_y, mask_type == 1, &mut diffwtd_mask_y); | ||
| 5519 | + mc::blend_masked_compound( | ||
| 5520 | + &inter0_y, | ||
| 5521 | + &inter1_y, | ||
| 5522 | + &diffwtd_mask_y, | ||
| 5523 | + side, | ||
| 5524 | + side, | ||
| 5525 | + side, | ||
| 5526 | + false, | ||
| 5527 | + &mut pred_y, | ||
| 5528 | + ); | ||
| 5529 | + } else { | ||
| 5530 | + mc::combine_compound(&inter0_y, &inter1_y, fwd_offset, bck_offset, &mut pred_y); | ||
| 5531 | + } | ||
| 5500 | 5532 | ||
| 5501 | let mut inter0_u = vec![0i32; chroma_side * chroma_side]; | 5533 | let mut inter0_u = vec![0i32; chroma_side * chroma_side]; |
| 5502 | mc::predict_compound_intermediate( | 5534 | mc::predict_compound_intermediate( |
| @@ -5527,7 +5559,20 @@ fn decode_inter_block( | |||
| 5527 | &mut inter1_u, | 5559 | &mut inter1_u, |
| 5528 | ); | 5560 | ); |
| 5529 | let mut pred_u = vec![0u8; chroma_side * chroma_side]; | 5561 | let mut pred_u = vec![0u8; chroma_side * chroma_side]; |
| 5530 | - mc::combine_compound(&inter0_u, &inter1_u, fwd_offset, bck_offset, &mut pred_u); | 5562 | + if diffwtd_mask_type.is_some() { |
| 5563 | + mc::blend_masked_compound( | ||
| 5564 | + &inter0_u, | ||
| 5565 | + &inter1_u, | ||
| 5566 | + &diffwtd_mask_y, | ||
| 5567 | + side, | ||
| 5568 | + chroma_side, | ||
| 5569 | + chroma_side, | ||
| 5570 | + true, | ||
| 5571 | + &mut pred_u, | ||
| 5572 | + ); | ||
| 5573 | + } else { | ||
| 5574 | + mc::combine_compound(&inter0_u, &inter1_u, fwd_offset, bck_offset, &mut pred_u); | ||
| 5575 | + } | ||
| 5531 | 5576 | ||
| 5532 | let mut inter0_v = vec![0i32; chroma_side * chroma_side]; | 5577 | let mut inter0_v = vec![0i32; chroma_side * chroma_side]; |
| 5533 | mc::predict_compound_intermediate( | 5578 | mc::predict_compound_intermediate( |
| @@ -5558,7 +5603,20 @@ fn decode_inter_block( | |||
| 5558 | &mut inter1_v, | 5603 | &mut inter1_v, |
| 5559 | ); | 5604 | ); |
| 5560 | let mut pred_v = vec![0u8; chroma_side * chroma_side]; | 5605 | let mut pred_v = vec![0u8; chroma_side * chroma_side]; |
| 5561 | - mc::combine_compound(&inter0_v, &inter1_v, fwd_offset, bck_offset, &mut pred_v); | 5606 | + if diffwtd_mask_type.is_some() { |
| 5607 | + mc::blend_masked_compound( | ||
| 5608 | + &inter0_v, | ||
| 5609 | + &inter1_v, | ||
| 5610 | + &diffwtd_mask_y, | ||
| 5611 | + side, | ||
| 5612 | + chroma_side, | ||
| 5613 | + chroma_side, | ||
| 5614 | + true, | ||
| 5615 | + &mut pred_v, | ||
| 5616 | + ); | ||
| 5617 | + } else { | ||
| 5618 | + mc::combine_compound(&inter0_v, &inter1_v, fwd_offset, bck_offset, &mut pred_v); | ||
| 5619 | + } | ||
| 5562 | 5620 | ||
| 5563 | if skip { | 5621 | if skip { |
| 5564 | y.reconstruct_mc(px, py, side, &pred_y, &vec![0i32; side * side]); | 5622 | y.reconstruct_mc(px, py, side, &pred_y, &vec![0i32; side * side]); |
| @@ -6570,24 +6628,28 @@ fn decode_inter_block8( | |||
| 6570 | } else { | 6628 | } else { |
| 6571 | 0 | 6629 | 0 |
| 6572 | }; | 6630 | }; |
| 6631 | + // lane-maskcomp r2: see the 16x16/32x32 leaf's own comment. | ||
| 6632 | + let mut diffwtd_mask_type: Option<u8> = None; | ||
| 6573 | if comp_group_idx == 1 { | 6633 | if comp_group_idx == 1 { |
| 6574 | // lane-maskcomp r1: see the 16x16 leaf's own comment | 6634 | // lane-maskcomp r1: see the 16x16 leaf's own comment |
| 6575 | // above -- SIDE==8 here, `wedge_bsize` index 3 | 6635 | // above -- SIDE==8 here, `wedge_bsize` index 3 |
| 6576 | // (BLOCK_8X8, `wedge_types > 0`). | 6636 | // (BLOCK_8X8, `wedge_types > 0`). |
| 6577 | let compound_type = dec.symbol(&mut cdfs.compound_type[3]); | 6637 | let compound_type = dec.symbol(&mut cdfs.compound_type[3]); |
| 6578 | if compound_type == 0 { | 6638 | if compound_type == 0 { |
| 6639 | + // COMPOUND_WEDGE: mask codebook not ported (r2 scope). | ||
| 6579 | let _wedge_index = dec.symbol(&mut cdfs.wedge_idx[3]); | 6640 | let _wedge_index = dec.symbol(&mut cdfs.wedge_idx[3]); |
| 6580 | let _wedge_sign = dec.literal(1); | 6641 | let _wedge_sign = dec.literal(1); |
| 6581 | - } else { | 6642 | + MASKED_COMPOUND_HITS.fetch_add(1, std::sync::atomic::Ordering::Relaxed); |
| 6582 | - let _mask_type = dec.literal(1); | 6643 | + return Err(unsupported( |
| 6644 | + "a masked COMPOUND_REFERENCE 8x8 leaf (comp_group_idx == 1, \ | ||
| 6645 | + COMPOUND_WEDGE) -- syntax consumed entropy-exact (compound_type/\ | ||
| 6646 | + wedge_idx/wedge_sign), but this decoder's wedge mask codebook is \ | ||
| 6647 | + not ported (lane-maskcomp r2 scope: DIFFWTD only)", | ||
| 6648 | + )); | ||
| 6583 | } | 6649 | } |
| 6650 | + let mask_type = dec.literal(1); | ||
| 6651 | + diffwtd_mask_type = Some(mask_type as u8); | ||
| 6584 | MASKED_COMPOUND_HITS.fetch_add(1, std::sync::atomic::Ordering::Relaxed); | 6652 | MASKED_COMPOUND_HITS.fetch_add(1, std::sync::atomic::Ordering::Relaxed); |
| 6585 | - return Err(unsupported( | ||
| 6586 | - "a masked COMPOUND_REFERENCE 8x8 leaf (comp_group_idx == 1, wedge/\ | ||
| 6587 | - diffwtd) -- syntax consumed entropy-exact (compound_type/wedge_idx/\ | ||
| 6588 | - wedge_sign/mask_type), but this decoder's compound blend does not \ | ||
| 6589 | - yet build the wedge/diffwtd mask, lane-maskcomp r1", | ||
| 6590 | - )); | ||
| 6591 | } | 6653 | } |
| 6592 | // corner-cut (lane-av1comp r16/r17, lane-av1blend r1): same | 6654 | // corner-cut (lane-av1comp r16/r17, lane-av1blend r1): same |
| 6593 | // reference-slot defect as the 16x16 leaf's own mask above | 6655 | // reference-slot defect as the 16x16 leaf's own mask above |
| @@ -6602,7 +6664,10 @@ fn decode_inter_block8( | |||
| 6602 | // compound_idx defect surfaces on the wide gate sweep. | 6664 | // compound_idx defect surfaces on the wide gate sweep. |
| 6603 | // lane-av1idx r1: same re-mask as the 16x16 leaf above -- | 6665 | // lane-av1idx r1: same re-mask as the 16x16 leaf above -- |
| 6604 | // see that comment. | 6666 | // see that comment. |
| 6605 | - let (fwd_offset, bck_offset, compound_idx) = if !skip_mode && enable_jnt_comp { | 6667 | + let (fwd_offset, bck_offset, compound_idx) = if comp_group_idx == 0 |
| 6668 | + && !skip_mode | ||
| 6669 | + && enable_jnt_comp | ||
| 6670 | + { | ||
| 6606 | let idx_ctx = get_comp_index_context( | 6671 | let idx_ctx = get_comp_index_context( |
| 6607 | neighbours, | 6672 | neighbours, |
| 6608 | outer_at, | 6673 | outer_at, |
| @@ -6691,7 +6756,23 @@ fn decode_inter_block8( | |||
| 6691 | &mut inter1_y, | 6756 | &mut inter1_y, |
| 6692 | ); | 6757 | ); |
| 6693 | let mut pred_y = vec![0u8; SIDE * SIDE]; | 6758 | let mut pred_y = vec![0u8; SIDE * SIDE]; |
| 6694 | - mc::combine_compound(&inter0_y, &inter1_y, fwd_offset, bck_offset, &mut pred_y); | 6759 | + let mut diffwtd_mask_y = Vec::new(); |
| 6760 | + if let Some(mask_type) = diffwtd_mask_type { | ||
| 6761 | + diffwtd_mask_y = vec![0u8; SIDE * SIDE]; | ||
| 6762 | + mc::diffwtd_mask(&inter0_y, &inter1_y, mask_type == 1, &mut diffwtd_mask_y); | ||
| 6763 | + mc::blend_masked_compound( | ||
| 6764 | + &inter0_y, | ||
| 6765 | + &inter1_y, | ||
| 6766 | + &diffwtd_mask_y, | ||
| 6767 | + SIDE, | ||
| 6768 | + SIDE, | ||
| 6769 | + SIDE, | ||
| 6770 | + false, | ||
| 6771 | + &mut pred_y, | ||
| 6772 | + ); | ||
| 6773 | + } else { | ||
| 6774 | + mc::combine_compound(&inter0_y, &inter1_y, fwd_offset, bck_offset, &mut pred_y); | ||
| 6775 | + } | ||
| 6695 | 6776 | ||
| 6696 | let mut inter0_u = vec![0i32; CHROMA_SIDE * CHROMA_SIDE]; | 6777 | let mut inter0_u = vec![0i32; CHROMA_SIDE * CHROMA_SIDE]; |
| 6697 | mc::predict_compound_intermediate( | 6778 | mc::predict_compound_intermediate( |
| @@ -6722,7 +6803,20 @@ fn decode_inter_block8( | |||
| 6722 | &mut inter1_u, | 6803 | &mut inter1_u, |
| 6723 | ); | 6804 | ); |
| 6724 | let mut pred_u = vec![0u8; CHROMA_SIDE * CHROMA_SIDE]; | 6805 | let mut pred_u = vec![0u8; CHROMA_SIDE * CHROMA_SIDE]; |
| 6725 | - mc::combine_compound(&inter0_u, &inter1_u, fwd_offset, bck_offset, &mut pred_u); | 6806 | + if diffwtd_mask_type.is_some() { |
| 6807 | + mc::blend_masked_compound( | ||
| 6808 | + &inter0_u, | ||
| 6809 | + &inter1_u, | ||
| 6810 | + &diffwtd_mask_y, | ||
| 6811 | + SIDE, | ||
| 6812 | + CHROMA_SIDE, | ||
| 6813 | + CHROMA_SIDE, | ||
| 6814 | + true, | ||
| 6815 | + &mut pred_u, | ||
| 6816 | + ); | ||
| 6817 | + } else { | ||
| 6818 | + mc::combine_compound(&inter0_u, &inter1_u, fwd_offset, bck_offset, &mut pred_u); | ||
| 6819 | + } | ||
| 6726 | 6820 | ||
| 6727 | let mut inter0_v = vec![0i32; CHROMA_SIDE * CHROMA_SIDE]; | 6821 | let mut inter0_v = vec![0i32; CHROMA_SIDE * CHROMA_SIDE]; |
| 6728 | mc::predict_compound_intermediate( | 6822 | mc::predict_compound_intermediate( |
| @@ -6753,7 +6847,20 @@ fn decode_inter_block8( | |||
| 6753 | &mut inter1_v, | 6847 | &mut inter1_v, |
| 6754 | ); | 6848 | ); |
| 6755 | let mut pred_v = vec![0u8; CHROMA_SIDE * CHROMA_SIDE]; | 6849 | let mut pred_v = vec![0u8; CHROMA_SIDE * CHROMA_SIDE]; |
| 6756 | - mc::combine_compound(&inter0_v, &inter1_v, fwd_offset, bck_offset, &mut pred_v); | 6850 | + if diffwtd_mask_type.is_some() { |
| 6851 | + mc::blend_masked_compound( | ||
| 6852 | + &inter0_v, | ||
| 6853 | + &inter1_v, | ||
| 6854 | + &diffwtd_mask_y, | ||
| 6855 | + SIDE, | ||
| 6856 | + CHROMA_SIDE, | ||
| 6857 | + CHROMA_SIDE, | ||
| 6858 | + true, | ||
| 6859 | + &mut pred_v, | ||
| 6860 | + ); | ||
| 6861 | + } else { | ||
| 6862 | + mc::combine_compound(&inter0_v, &inter1_v, fwd_offset, bck_offset, &mut pred_v); | ||
| 6863 | + } | ||
| 6757 | 6864 | ||
| 6758 | if skip { | 6865 | if skip { |
| 6759 | y.reconstruct_mc(px, py, SIDE, &pred_y, &vec![0i32; SIDE * SIDE]); | 6866 | y.reconstruct_mc(px, py, SIDE, &pred_y, &vec![0i32; SIDE * SIDE]); |
crates/ec-av1/src/mc.rsmodified+64 -0
| @@ -525,6 +525,70 @@ pub fn combine_compound( | |||
| 525 | } | 525 | } |
| 526 | } | 526 | } |
| 527 | 527 | ||
| 528 | +/// lane-maskcomp r2: `build_compound_diffwtd_mask` (reconinter.c) -- | ||
| 529 | +/// `DIFFWTD_38`/`DIFFWTD_38_INV` (`mask_type` bit: 0/1). Operates directly on | ||
| 530 | +/// the two [`predict_compound_intermediate`] outputs: libaom's own | ||
| 531 | +/// `av1_build_compound_diffwtd_mask_d16_c` runs on its CONV_BUF domain (which | ||
| 532 | +/// carries a constant `round_offset` bias baked into every sample by its | ||
| 533 | +/// convolve stage), but `abs(src0 - src1)` cancels an equal bias on both | ||
| 534 | +/// sides exactly, so the unbiased `i32` intermediates this crate already | ||
| 535 | +/// produces give the identical `diff` libaom computes. `round` is | ||
| 536 | +/// `2*FILTER_BITS - round_0 - round_1 + (bd-8)` == [`INTER_POST_ROUND`] for | ||
| 537 | +/// 8-bit content (`round_0=3`, compound `round_1=7`, `bd=8`). | ||
| 538 | +pub fn diffwtd_mask(pred0: &[i32], pred1: &[i32], inv: bool, mask: &mut [u8]) { | ||
| 539 | + assert_eq!(pred0.len(), pred1.len(), "both refs predict the same block"); | ||
| 540 | + assert_eq!(mask.len(), pred0.len(), "one mask byte per pixel"); | ||
| 541 | + for i in 0..mask.len() { | ||
| 542 | + let diff = round2((pred0[i] - pred1[i]).abs(), INTER_POST_ROUND); | ||
| 543 | + let m = (38 + diff / 16).clamp(0, 64); | ||
| 544 | + mask[i] = if inv { (64 - m) as u8 } else { m as u8 }; | ||
| 545 | + } | ||
| 546 | +} | ||
| 547 | + | ||
| 548 | +/// lane-maskcomp r2: `aom_lowbd_blend_a64_d16_mask_c` (blend_a64_mask.c), | ||
| 549 | +/// algebraically simplified to this crate's unbiased `i32` intermediate | ||
| 550 | +/// domain the same way [`diffwtd_mask`]'s doc comment derives -- libaom's | ||
| 551 | +/// `res -= round_offset` step cancels exactly against the bias `m + (64-m) | ||
| 552 | +/// == 64` contributes equally from both inputs, leaving `(m*pred0 + | ||
| 553 | +/// (64-m)*pred1) >> 6` (a plain, unrounded shift, matching the C `>>` on | ||
| 554 | +/// `int32_t`) then one final [`round2`] by [`INTER_POST_ROUND`]. `mask` is | ||
| 555 | +/// always the LUMA-resolution mask (`mask_stride` == luma block width); | ||
| 556 | +/// `subsampled` selects the 2x2-average chroma read (spec 7.11.3.14 / | ||
| 557 | +/// libaom's `subw == 1 && subh == 1` branch) vs. the direct luma read. | ||
| 558 | +#[allow(clippy::too_many_arguments)] | ||
| 559 | +pub fn blend_masked_compound( | ||
| 560 | + pred0: &[i32], | ||
| 561 | + pred1: &[i32], | ||
| 562 | + mask: &[u8], | ||
| 563 | + mask_stride: usize, | ||
| 564 | + w: usize, | ||
| 565 | + h: usize, | ||
| 566 | + subsampled: bool, | ||
| 567 | + dst: &mut [u8], | ||
| 568 | +) { | ||
| 569 | + assert_eq!(pred0.len(), w * h, "pred0 is the destination-sized block"); | ||
| 570 | + assert_eq!(pred1.len(), w * h, "pred1 is the destination-sized block"); | ||
| 571 | + assert_eq!(dst.len(), w * h, "the destination is the block"); | ||
| 572 | + for i in 0..h { | ||
| 573 | + for j in 0..w { | ||
| 574 | + let m = if subsampled { | ||
| 575 | + let idx = (2 * i) * mask_stride + 2 * j; | ||
| 576 | + round2( | ||
| 577 | + i32::from(mask[idx]) | ||
| 578 | + + i32::from(mask[idx + 1]) | ||
| 579 | + + i32::from(mask[idx + mask_stride]) | ||
| 580 | + + i32::from(mask[idx + mask_stride + 1]), | ||
| 581 | + 2, | ||
| 582 | + ) | ||
| 583 | + } else { | ||
| 584 | + i32::from(mask[i * mask_stride + j]) | ||
| 585 | + }; | ||
| 586 | + let res = (m * pred0[i * w + j] + (64 - m) * pred1[i * w + j]) >> 6; | ||
| 587 | + dst[i * w + j] = round2(res, INTER_POST_ROUND).clamp(0, 255) as u8; | ||
| 588 | + } | ||
| 589 | + } | ||
| 590 | +} | ||
| 591 | + | ||
| 528 | /// Whole-pel identity case: [`predict_compound_intermediate`]'s two-pass | 592 | /// Whole-pel identity case: [`predict_compound_intermediate`]'s two-pass |
| 529 | /// filter reduces to `16 * source_sample` exactly (the fraction-0 row is a | 593 | /// filter reduces to `16 * source_sample` exactly (the fraction-0 row is a |
| 530 | /// single `128` tap both passes, and `128*128 == 1 << 14`, `14 - 7 == 7 == | 594 | /// single `128` tap both passes, and `128*128 == 1 << 14`, `14 - 7 == 7 == |
crates/ec-av1/src/stream.rsmodified+22 -24
| @@ -3838,17 +3838,14 @@ mod tests { | |||
| 3838 | ); | 3838 | ); |
| 3839 | } | 3839 | } |
| 3840 | 3840 | ||
| 3841 | - /// lane-maskcomp r1: `--enable-masked-comp=1 --enable-dist-wtd-comp=1` | 3841 | + /// lane-maskcomp r2: `--enable-masked-comp=1 --enable-dist-wtd-comp=1` |
| 3842 | /// streams must consume `compound_type`/`wedge_idx`/`wedge_sign`/ | 3842 | /// streams must consume `compound_type`/`wedge_idx`/`wedge_sign`/ |
| 3843 | - /// `mask_type` entropy-exact (`masked_compound_hits() > 0`) whenever a | 3843 | + /// `mask_type` entropy-exact AND build the real DIFFWTD blend -- |
| 3844 | - /// block reads `comp_group_idx == 1` -- the syntax is ported this | 3844 | + /// `masked_compound_hits() > 0` is now a hard assert, and a |
| 3845 | - /// round, the wedge/diffwtd mask blend is NOT, so a masked-compound | 3845 | + /// `COMPOUND_DIFFWTD` refusal is FORBIDDEN (matches interintra's own |
| 3846 | - /// refusal itself is still EXPECTED here (r1's own named refusal, | 3846 | + /// gate). `COMPOUND_WEDGE` refusals are still EXPECTED (r2 scope: |
| 3847 | - /// asserted for wording only) rather than forbidden; only OTHER named | 3847 | + /// wedge mask codebook not ported, charter's mergeable-partial |
| 3848 | - /// refusals (screen content tools etc.) skip a seed without counting. | 3848 | + /// fallback) -- counted separately, never asserted against. |
| 3849 | - /// Once the blend lands, this gate's own masked-compound refusal | ||
| 3850 | - /// becomes forbidden like `a_real_aomenc_stream_with_interintra_...` | ||
| 3851 | - /// above's wedge case was for non-wedge interintra. | ||
| 3852 | #[test] | 3849 | #[test] |
| 3853 | fn a_real_aomenc_stream_with_masked_compound_decodes_pixel_exact() { | 3850 | fn a_real_aomenc_stream_with_masked_compound_decodes_pixel_exact() { |
| 3854 | const NAME: &str = "a_real_aomenc_stream_with_masked_compound_decodes_pixel_exact"; | 3851 | const NAME: &str = "a_real_aomenc_stream_with_masked_compound_decodes_pixel_exact"; |
| @@ -3974,6 +3971,11 @@ mod tests { | |||
| 3974 | "{NAME} refused on warp (seed {seed}) -- warp decode is ported: {msg}" | 3971 | "{NAME} refused on warp (seed {seed}) -- warp decode is ported: {msg}" |
| 3975 | ); | 3972 | ); |
| 3976 | if msg.contains("masked COMPOUND_REFERENCE") { | 3973 | if msg.contains("masked COMPOUND_REFERENCE") { |
| 3974 | + assert!( | ||
| 3975 | + msg.contains("COMPOUND_WEDGE"), | ||
| 3976 | + "{NAME} refused a non-wedge masked-compound block (seed {seed}) \ | ||
| 3977 | + -- DIFFWTD blend is ported, this refusal is forbidden: {msg}" | ||
| 3978 | + ); | ||
| 3977 | masked_refusals += 1; | 3979 | masked_refusals += 1; |
| 3978 | } else { | 3980 | } else { |
| 3979 | assert!( | 3981 | assert!( |
| @@ -4019,22 +4021,18 @@ mod tests { | |||
| 4019 | // is that sampling flake, not a decode regression -- check | 4021 | // is that sampling flake, not a decode regression -- check |
| 4020 | // masked_compound_hits/named_refusals in the panic message before | 4022 | // masked_compound_hits/named_refusals in the panic message before |
| 4021 | // assuming a real bug. | 4023 | // assuming a real bug. |
| 4022 | - // r1: a zero-hit run is the sampling flake above, not a regression -- | 4024 | + // r2: DIFFWTD is ported and gated, so a zero-hit run is no longer |
| 4023 | - // report it loudly instead of failing the default suite (the interintra | 4025 | + // soft-skipped -- hard assert, matching the interintra gate. |
| 4024 | - // gate went through the same soft phase; r2 flips this to a hard | 4026 | + assert!( |
| 4025 | - // assert once the blend lands and masked refusals become forbidden). | 4027 | + crate::decode::masked_compound_hits() > 0, |
| 4026 | - if crate::decode::masked_compound_hits() == 0 { | 4028 | + "{NAME}: zero masked-compound blocks fired ({masked_refusals} wedge refusals, \ |
| 4027 | - eprintln!( | 4029 | + {matched} matches, {named_refusals} other refusals out of {n_attempts}) -- gate \ |
| 4028 | - "{NAME}: SOFT-SKIP -- zero masked-compound blocks fired ({masked_refusals} \ | 4030 | + proved nothing this run" |
| 4029 | - masked refusals, {matched} matches, {named_refusals} other refusals out of \ | 4031 | + ); |
| 4030 | - {n_attempts}); sampling flake, gate proved nothing this run" | ||
| 4031 | - ); | ||
| 4032 | - return; | ||
| 4033 | - } | ||
| 4034 | eprintln!( | 4032 | eprintln!( |
| 4035 | "{NAME}: {named_refusals} other-capability refusals, {masked_refusals} expected \ | 4033 | "{NAME}: {named_refusals} other-capability refusals, {masked_refusals} expected \ |
| 4036 | - masked-compound refusals (r1: blend unported), {matched} pixel-exact matches out \ | 4034 | + COMPOUND_WEDGE refusals (r2 scope: wedge unported), {matched} pixel-exact matches \ |
| 4037 | - of {n_attempts}, masked_compound_hits={}", | 4035 | + out of {n_attempts}, masked_compound_hits={}", |
| 4038 | crate::decode::masked_compound_hits() | 4036 | crate::decode::masked_compound_hits() |
| 4039 | ); | 4037 | ); |
| 4040 | } | 4038 | } |
lanes/maskcomp-r2.charter.mdadded+46 -0
| @@ -0,0 +1,46 @@ | |||
| 1 | +# lane-maskcomp r2 charter — port the wedge/diffwtd masked-compound BLEND | ||
| 2 | + | ||
| 3 | +## Where you are | ||
| 4 | +Worktree /home/user/Documents/Code/Rust/edith_codecs-maskcomp2, branch lane-maskcomp2 @ 5e25f76. | ||
| 5 | +Build/test ONLY: `env CARGO_TARGET_DIR=$HOME/.cache/cargo-target-maskcomp2 cargo test -p ec-av1 --release --lib <name> -- --nocapture` | ||
| 6 | +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. | ||
| 7 | + | ||
| 8 | +## Current state (r1 landed in 5e25f76 — do not re-derive) | ||
| 9 | +- comp_group_idx==1 syntax is entropy-exact at BOTH refusal sites (decode.rs ~5176 | ||
| 10 | + leaf16/32, ~6558 leaf8): compound_type, wedge_idx (16-ary), wedge_sign (literal), | ||
| 11 | + mask_type (literal) are consumed, then the blend refuses by name. Read | ||
| 12 | + lanes/maskcomp-r1.report.md first. | ||
| 13 | +- Gate a_real_aomenc_stream_with_masked_compound_decodes_pixel_exact exists; its own | ||
| 14 | + masked-compound refusal is currently EXPECTED and a zero-hit run SOFT-SKIPs. | ||
| 15 | +- Interintra blend (interintra_blend, decode.rs ~4410) is the shape to mirror for a | ||
| 16 | + 64-scale mask blend: (mask*p0 + (64-mask)*p1 + 32) >> 6. | ||
| 17 | + | ||
| 18 | +## Scope r2: the blend | ||
| 19 | +1. Wedge masks: port libaom's wedge codebook for the bsizes this decoder reaches | ||
| 20 | + (8x8..32x32 squares; wedge is only used where av1_is_wedge_used(bsize)) — | ||
| 21 | + reconinter.c av1_wedge_params_lookup + init_wedge_masks/init_wedge_master_masks | ||
| 22 | + (the 64x64 master masks are built from wedge_master_oblique/vertical tables then | ||
| 23 | + cropped/flipped per code + sign). Build them at first use or as consts; verify a | ||
| 24 | + handful of mask rows against a C-side dump (patch a printf into | ||
| 25 | + /tmp/libaom-src reconinter.c, rebuild /tmp/libaom-build with ninja) — do NOT | ||
| 26 | + trust a hand transcription unchecked (class shared-oracle-blindness). | ||
| 27 | +2. DIFFWTD masks: build_compound_diffwtd_mask (reconinter.c): per-pixel | ||
| 28 | + mask = clamp(38 + (|p0-p1|) >> shift, 0, 64) for DIFFWTD_38, inverted for _INV | ||
| 29 | + — port exactly, mind the bit-depth shift chain (class mirror-the-decoder-shift). | ||
| 30 | +3. Chroma: av1_get_compound_type_mask + the subsampling path (chroma reads the luma | ||
| 31 | + mask subsampled by 2x2 averaging? read av1_build_masked_compound / | ||
| 32 | + aom_blend_a64_d16-vs-8bit paths carefully; this decoder is 8-bit). | ||
| 33 | +4. Flip the gate: masked-compound refusals FORBIDDEN; zero-hit SOFT-SKIP becomes a | ||
| 34 | + hard assert (hits > 0) with EC_MASKCOMP_GATE_ATTEMPTS=80 default kept. Hammer 8x | ||
| 35 | + with EC_AV1_GATE_DUMP self-pin (/tmp/claude-1000/mc-flake-N.obu). | ||
| 36 | +5. Any mismatch: pin to fixtures/, recon-dump (EC_AV1_PREFILT_DUMP) → range ladder | ||
| 37 | + (exact ladder = prediction-side, i.e., your mask; ours[k]=aom[k+1]) → for mask | ||
| 38 | + bugs dump the mask array both sides (add an env-gated eprintln; patch aomdec's | ||
| 39 | + av1_make_masked_inter_predictor likewise). | ||
| 40 | + | ||
| 41 | +## Done criteria | ||
| 42 | +1. Gate green with hard hits assert, 8/8 hammer; 11 pins byte-exact; lib suite green. | ||
| 43 | +2. Committed to lane-maskcomp2; REPORT lanes/maskcomp-r2.report.md, verdict FIRST. | ||
| 44 | +Commit + report BEFORE budget runs out. If the wedge codebook cannot be finished | ||
| 45 | +verified, land DIFFWTD alone (flip only the diffwtd refusal) — partial capability | ||
| 46 | +with exact naming is mergeable; an unverified wedge table is not. | ||
lanes/maskcomp-r2.report.mdadded+59 -0
| @@ -0,0 +1,59 @@ | |||
| 1 | +# lane-maskcomp r2 report | ||
| 2 | + | ||
| 3 | +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"). | ||
| 4 | + | ||
| 5 | +## What landed | ||
| 6 | +- `crates/ec-av1/src/mc.rs`: `diffwtd_mask` (`build_compound_diffwtd_mask`, reconinter.c) and | ||
| 7 | + `blend_masked_compound` (`aom_lowbd_blend_a64_d16_mask_c`, blend_a64_mask.c), both algebraically | ||
| 8 | + re-derived onto this crate's unbiased `i32` `predict_compound_intermediate` domain instead of | ||
| 9 | + libaom's biased CONV_BUF representation -- proved on paper (doc comments) that libaom's | ||
| 10 | + `round_offset` bias cancels exactly in both functions (`abs(src0-src1)` for the mask, `m + (64-m) | ||
| 11 | + == 64` for the blend weight sum), so no offset bookkeeping is needed on our side. `round = | ||
| 12 | + 2*FILTER_BITS - round_0 - round_1 + (bd-8)` reduces to the crate's existing `INTER_POST_ROUND` | ||
| 13 | + (4) for 8-bit content, confirmed against the crate's own `INTER_ROUND_0`/`INTER_ROUND_1_COMPOUND` | ||
| 14 | + constants (3/7) rather than hand-copied. | ||
| 15 | +- `crates/ec-av1/src/decode.rs`: both `comp_group_idx == 1` sites (`decode_inter_block`'s | ||
| 16 | + 16x16/32x32 leaf, `decode_inter_block8`'s 8x8 leaf) now split on `compound_type`: | ||
| 17 | + `COMPOUND_WEDGE` (`compound_type == 0`) still refuses by name (wedge mask codebook out of scope | ||
| 18 | + this round); `COMPOUND_DIFFWTD` (`compound_type == 1`) reads `mask_type` and falls through to | ||
| 19 | + build+apply the real blend instead of erroring. Real bug fixed while wiring this in: | ||
| 20 | + `compound_idx` (the distance-weighted-average symbol) was being read unconditionally on | ||
| 21 | + `!skip_mode && enable_jnt_comp`, missing libaom's `comp_group_idx == 0` outer gate | ||
| 22 | + (`decodemv.c:1606`) -- dead code before this round (the masked path always errored earlier so it | ||
| 23 | + never executed with `comp_group_idx == 1` in practice), now gated correctly at both sites. | ||
| 24 | +- `crates/ec-av1/src/stream.rs`: `a_real_aomenc_stream_with_masked_compound_decodes_pixel_exact` | ||
| 25 | + flipped from r1's soft-skip/expected-refusal shape to r2's hard shape: `masked_compound_hits() > | ||
| 26 | + 0` is now a hard `assert!` (was a soft-skip), a `COMPOUND_DIFFWTD` refusal is now FORBIDDEN | ||
| 27 | + (asserted against, matching how the interintra gate treats its own ported capability), and a | ||
| 28 | + `COMPOUND_WEDGE` refusal is still counted as expected/unasserted (r2 scope boundary). | ||
| 29 | + | ||
| 30 | +## Verification | ||
| 31 | +- `cargo check -p ec-av1 --release`: clean (only pre-existing missing-doc warnings, same set as | ||
| 32 | + before this round). | ||
| 33 | +- Gate `a_real_aomenc_stream_with_masked_compound_decodes_pixel_exact`, hammered 8/8 (fresh | ||
| 34 | + `EC_AV1_GATE_DUMP` self-pin path per run, `/tmp/claude-1000/mc-flake/mc-flake-{1..8}.obu`): all 8 | ||
| 35 | + green, `masked_compound_hits` in {2,3,3,3,4,3,5,3} per run (never zero), zero `COMPOUND_WEDGE` | ||
| 36 | + refusals fired in any run (content never picked wedge for this synthetic-gradients recipe, so the | ||
| 37 | + wedge-still-refuses path is untested live this round -- syntax-level only, per r1), zero pixel | ||
| 38 | + mismatches across all 80-attempt runs x 8 (`23-30 other-capability refusals` [screen-content-tools | ||
| 39 | + RD flake, pre-existing/documented], `50-64 pixel-exact matches` per run). | ||
| 40 | +- `cargo test -p ec-av1 --release --lib` (full scoped suite): 220 passed, 0 failed, 17 ignored, | ||
| 41 | + finished in 140.58s -- includes all pre-existing pinned bit-exact regression tests, unaffected. | ||
| 42 | + | ||
| 43 | +## Deferred | ||
| 44 | +- deferred: wedge mask codebook (`av1_wedge_params_lookup` + `init_wedge_master_masks`/ | ||
| 45 | + `init_wedge_masks`, reconinter.c) -- explicitly out of r2 per the charter's mergeable-partial | ||
| 46 | + fallback ("DIFFWTD alone... is mergeable; an unverified wedge table is not"). Unblocks by | ||
| 47 | + transcribing `wedge_master_oblique_even/odd`/`wedge_master_vertical` + `wedge_codebook_16_*` + | ||
| 48 | + `wedge_signflip_lookup`, building the 64x64 master masks and cropping/flipping per | ||
| 49 | + `wedge_index`/`wedge_sign`, verifying a handful of mask rows against a live C-side printf dump | ||
| 50 | + (per charter, not a hand transcription unchecked), then flipping the `COMPOUND_WEDGE` refusal | ||
| 51 | + the same way this round flipped `COMPOUND_DIFFWTD`. | ||
| 52 | +- deferred: a live gate run that actually exercises the `COMPOUND_WEDGE`-still-refuses path (to | ||
| 53 | + prove the r2 gate's own `assert!(msg.contains("COMPOUND_WEDGE"))` line is reachable, not just | ||
| 54 | + syntactically present) -- unblocks by a higher wedge-yield encoder recipe (aomenc's cpu-used=0 RD | ||
| 55 | + never picked wedge over diffwtd/plain-average in any of this round's 8x80 = 640 attempts). | ||
| 56 | + | ||
| 57 | +## Commit | ||
| 58 | +`feat(av1): port the DIFFWTD masked-compound blend (comp_group_idx==1), wedge still refused` on | ||
| 59 | +branch lane-maskcomp2. | ||