Merge branch 'lane-maskcomp2' into lane-partitions (integration)
Browse files at this commit5 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
| @@ -5327,6 +5327,12 @@ fn decode_inter_block( | |||
| 5327 | } else { | 5327 | } else { |
| 5328 | 0 | 5328 | 0 |
| 5329 | }; | 5329 | }; |
| 5330 | + // lane-maskcomp r2: `Some(mask_type)` only for a real | ||
| 5331 | + // `COMPOUND_DIFFWTD` block (`comp_group_idx == 1`, `compound_type | ||
| 5332 | + // == 1`) -- wedge (`compound_type == 0`) still refuses by name, | ||
| 5333 | + // its mask codebook unported (charter's mergeable-partial | ||
| 5334 | + // fallback). | ||
| 5335 | + let mut diffwtd_mask_type: Option<u8> = None; | ||
| 5330 | if comp_group_idx == 1 { | 5336 | if comp_group_idx == 1 { |
| 5331 | // lane-maskcomp r1: `read_compound_type` (spec 5.11.25, | 5337 | // lane-maskcomp r1: `read_compound_type` (spec 5.11.25, |
| 5332 | // libaom `decodemv.c` 1634-1656). `is_interinter_compound_used | 5338 | // libaom `decodemv.c` 1634-1656). `is_interinter_compound_used |
| @@ -5344,20 +5350,21 @@ fn decode_inter_block( | |||
| 5344 | }; | 5350 | }; |
| 5345 | let compound_type = dec.symbol(&mut cdfs.compound_type[wedge_bsize]); | 5351 | let compound_type = dec.symbol(&mut cdfs.compound_type[wedge_bsize]); |
| 5346 | if compound_type == 0 { | 5352 | if compound_type == 0 { |
| 5347 | - // COMPOUND_WEDGE | 5353 | + // COMPOUND_WEDGE: mask codebook not ported (r2 scope). |
| 5348 | let _wedge_index = dec.symbol(&mut cdfs.wedge_idx[wedge_bsize]); | 5354 | let _wedge_index = dec.symbol(&mut cdfs.wedge_idx[wedge_bsize]); |
| 5349 | let _wedge_sign = dec.literal(1); | 5355 | let _wedge_sign = dec.literal(1); |
| 5350 | - } else { | 5356 | + MASKED_COMPOUND_HITS.fetch_add(1, std::sync::atomic::Ordering::Relaxed); |
| 5351 | - // COMPOUND_DIFFWTD: `mask_type`, MAX_DIFFWTD_MASK_BITS==1. | 5357 | + return Err(unsupported( |
| 5352 | - let _mask_type = dec.literal(1); | 5358 | + "a masked COMPOUND_REFERENCE block (comp_group_idx == 1, \ |
| 5359 | + COMPOUND_WEDGE) -- syntax consumed entropy-exact (compound_type/\ | ||
| 5360 | + wedge_idx/wedge_sign), but this decoder's wedge mask codebook is \ | ||
| 5361 | + not ported (lane-maskcomp r2 scope: DIFFWTD only)", | ||
| 5362 | + )); | ||
| 5353 | } | 5363 | } |
| 5364 | + // COMPOUND_DIFFWTD: `mask_type`, MAX_DIFFWTD_MASK_BITS==1. | ||
| 5365 | + let mask_type = dec.literal(1); | ||
| 5366 | + diffwtd_mask_type = Some(mask_type as u8); | ||
| 5354 | MASKED_COMPOUND_HITS.fetch_add(1, std::sync::atomic::Ordering::Relaxed); | 5367 | MASKED_COMPOUND_HITS.fetch_add(1, std::sync::atomic::Ordering::Relaxed); |
| 5355 | - return Err(unsupported( | ||
| 5356 | - "a masked COMPOUND_REFERENCE block (comp_group_idx == 1, wedge/\ | ||
| 5357 | - diffwtd) -- syntax consumed entropy-exact (compound_type/wedge_idx/\ | ||
| 5358 | - wedge_sign/mask_type), but this decoder's compound blend does not yet \ | ||
| 5359 | - build the wedge/diffwtd mask, lane-maskcomp r1", | ||
| 5360 | - )); | ||
| 5361 | } | 5368 | } |
| 5362 | // corner-cut (lane-av1comp r16/r17, lane-av1blend r1): r16/r17 | 5369 | // corner-cut (lane-av1comp r16/r17, lane-av1blend r1): r16/r17 |
| 5363 | // called this a `predict_compound_intermediate`/`combine_compound` | 5370 | // called this a `predict_compound_intermediate`/`combine_compound` |
| @@ -5552,7 +5559,16 @@ fn decode_inter_block( | |||
| 5552 | // Re-masking: see that fixture + `scratch_isolate_pinned_mismatch` | 5559 | // Re-masking: see that fixture + `scratch_isolate_pinned_mismatch` |
| 5553 | // (`EC_AV1_PIN=fixtures/av1idx-refsel-pin.obu EC_AV1_PIN_N=20`) | 5560 | // (`EC_AV1_PIN=fixtures/av1idx-refsel-pin.obu EC_AV1_PIN_N=20`) |
| 5554 | // for the next round's starting point. | 5561 | // for the next round's starting point. |
| 5555 | - let (fwd_offset, bck_offset, compound_idx) = if !skip_mode && enable_jnt_comp { | 5562 | + // lane-maskcomp r2: `compound_idx` is only read when |
| 5563 | + // `comp_group_idx == 0` (libaom `decodemv.c:1606`) -- a masked | ||
| 5564 | + // (wedge/diffwtd) block never also carries a distance-weighted | ||
| 5565 | + // split. This gate was missing before r2 (dead code: the masked | ||
| 5566 | + // path always refused earlier, so it never executed with | ||
| 5567 | + // `comp_group_idx == 1` in practice). | ||
| 5568 | + let (fwd_offset, bck_offset, compound_idx) = if comp_group_idx == 0 | ||
| 5569 | + && !skip_mode | ||
| 5570 | + && enable_jnt_comp | ||
| 5571 | + { | ||
| 5556 | let idx_ctx = get_comp_index_context( | 5572 | let idx_ctx = get_comp_index_context( |
| 5557 | neighbours, | 5573 | neighbours, |
| 5558 | at, | 5574 | at, |
| @@ -5636,7 +5652,23 @@ fn decode_inter_block( | |||
| 5636 | &mut inter1_y, | 5652 | &mut inter1_y, |
| 5637 | ); | 5653 | ); |
| 5638 | let mut pred_y = vec![0u8; side * side]; | 5654 | let mut pred_y = vec![0u8; side * side]; |
| 5639 | - mc::combine_compound(&inter0_y, &inter1_y, fwd_offset, bck_offset, &mut pred_y); | 5655 | + let mut diffwtd_mask_y = Vec::new(); |
| 5656 | + if let Some(mask_type) = diffwtd_mask_type { | ||
| 5657 | + diffwtd_mask_y = vec![0u8; side * side]; | ||
| 5658 | + mc::diffwtd_mask(&inter0_y, &inter1_y, mask_type == 1, &mut diffwtd_mask_y); | ||
| 5659 | + mc::blend_masked_compound( | ||
| 5660 | + &inter0_y, | ||
| 5661 | + &inter1_y, | ||
| 5662 | + &diffwtd_mask_y, | ||
| 5663 | + side, | ||
| 5664 | + side, | ||
| 5665 | + side, | ||
| 5666 | + false, | ||
| 5667 | + &mut pred_y, | ||
| 5668 | + ); | ||
| 5669 | + } else { | ||
| 5670 | + mc::combine_compound(&inter0_y, &inter1_y, fwd_offset, bck_offset, &mut pred_y); | ||
| 5671 | + } | ||
| 5640 | 5672 | ||
| 5641 | let mut inter0_u = vec![0i32; chroma_side * chroma_side]; | 5673 | let mut inter0_u = vec![0i32; chroma_side * chroma_side]; |
| 5642 | mc::predict_compound_intermediate( | 5674 | mc::predict_compound_intermediate( |
| @@ -5667,7 +5699,20 @@ fn decode_inter_block( | |||
| 5667 | &mut inter1_u, | 5699 | &mut inter1_u, |
| 5668 | ); | 5700 | ); |
| 5669 | let mut pred_u = vec![0u8; chroma_side * chroma_side]; | 5701 | let mut pred_u = vec![0u8; chroma_side * chroma_side]; |
| 5670 | - mc::combine_compound(&inter0_u, &inter1_u, fwd_offset, bck_offset, &mut pred_u); | 5702 | + if diffwtd_mask_type.is_some() { |
| 5703 | + mc::blend_masked_compound( | ||
| 5704 | + &inter0_u, | ||
| 5705 | + &inter1_u, | ||
| 5706 | + &diffwtd_mask_y, | ||
| 5707 | + side, | ||
| 5708 | + chroma_side, | ||
| 5709 | + chroma_side, | ||
| 5710 | + true, | ||
| 5711 | + &mut pred_u, | ||
| 5712 | + ); | ||
| 5713 | + } else { | ||
| 5714 | + mc::combine_compound(&inter0_u, &inter1_u, fwd_offset, bck_offset, &mut pred_u); | ||
| 5715 | + } | ||
| 5671 | 5716 | ||
| 5672 | let mut inter0_v = vec![0i32; chroma_side * chroma_side]; | 5717 | let mut inter0_v = vec![0i32; chroma_side * chroma_side]; |
| 5673 | mc::predict_compound_intermediate( | 5718 | mc::predict_compound_intermediate( |
| @@ -5698,7 +5743,20 @@ fn decode_inter_block( | |||
| 5698 | &mut inter1_v, | 5743 | &mut inter1_v, |
| 5699 | ); | 5744 | ); |
| 5700 | let mut pred_v = vec![0u8; chroma_side * chroma_side]; | 5745 | let mut pred_v = vec![0u8; chroma_side * chroma_side]; |
| 5701 | - mc::combine_compound(&inter0_v, &inter1_v, fwd_offset, bck_offset, &mut pred_v); | 5746 | + if diffwtd_mask_type.is_some() { |
| 5747 | + mc::blend_masked_compound( | ||
| 5748 | + &inter0_v, | ||
| 5749 | + &inter1_v, | ||
| 5750 | + &diffwtd_mask_y, | ||
| 5751 | + side, | ||
| 5752 | + chroma_side, | ||
| 5753 | + chroma_side, | ||
| 5754 | + true, | ||
| 5755 | + &mut pred_v, | ||
| 5756 | + ); | ||
| 5757 | + } else { | ||
| 5758 | + mc::combine_compound(&inter0_v, &inter1_v, fwd_offset, bck_offset, &mut pred_v); | ||
| 5759 | + } | ||
| 5702 | 5760 | ||
| 5703 | if skip { | 5761 | if skip { |
| 5704 | y.reconstruct_mc_rect( | 5762 | y.reconstruct_mc_rect( |
| @@ -6765,24 +6823,28 @@ fn decode_inter_block8( | |||
| 6765 | } else { | 6823 | } else { |
| 6766 | 0 | 6824 | 0 |
| 6767 | }; | 6825 | }; |
| 6826 | + // lane-maskcomp r2: see the 16x16/32x32 leaf's own comment. | ||
| 6827 | + let mut diffwtd_mask_type: Option<u8> = None; | ||
| 6768 | if comp_group_idx == 1 { | 6828 | if comp_group_idx == 1 { |
| 6769 | // lane-maskcomp r1: see the 16x16 leaf's own comment | 6829 | // lane-maskcomp r1: see the 16x16 leaf's own comment |
| 6770 | // above -- SIDE==8 here, `wedge_bsize` index 3 | 6830 | // above -- SIDE==8 here, `wedge_bsize` index 3 |
| 6771 | // (BLOCK_8X8, `wedge_types > 0`). | 6831 | // (BLOCK_8X8, `wedge_types > 0`). |
| 6772 | let compound_type = dec.symbol(&mut cdfs.compound_type[3]); | 6832 | let compound_type = dec.symbol(&mut cdfs.compound_type[3]); |
| 6773 | if compound_type == 0 { | 6833 | if compound_type == 0 { |
| 6834 | + // COMPOUND_WEDGE: mask codebook not ported (r2 scope). | ||
| 6774 | let _wedge_index = dec.symbol(&mut cdfs.wedge_idx[3]); | 6835 | let _wedge_index = dec.symbol(&mut cdfs.wedge_idx[3]); |
| 6775 | let _wedge_sign = dec.literal(1); | 6836 | let _wedge_sign = dec.literal(1); |
| 6776 | - } else { | 6837 | + MASKED_COMPOUND_HITS.fetch_add(1, std::sync::atomic::Ordering::Relaxed); |
| 6777 | - let _mask_type = dec.literal(1); | 6838 | + return Err(unsupported( |
| 6839 | + "a masked COMPOUND_REFERENCE 8x8 leaf (comp_group_idx == 1, \ | ||
| 6840 | + COMPOUND_WEDGE) -- syntax consumed entropy-exact (compound_type/\ | ||
| 6841 | + wedge_idx/wedge_sign), but this decoder's wedge mask codebook is \ | ||
| 6842 | + not ported (lane-maskcomp r2 scope: DIFFWTD only)", | ||
| 6843 | + )); | ||
| 6778 | } | 6844 | } |
| 6845 | + let mask_type = dec.literal(1); | ||
| 6846 | + diffwtd_mask_type = Some(mask_type as u8); | ||
| 6779 | MASKED_COMPOUND_HITS.fetch_add(1, std::sync::atomic::Ordering::Relaxed); | 6847 | MASKED_COMPOUND_HITS.fetch_add(1, std::sync::atomic::Ordering::Relaxed); |
| 6780 | - return Err(unsupported( | ||
| 6781 | - "a masked COMPOUND_REFERENCE 8x8 leaf (comp_group_idx == 1, wedge/\ | ||
| 6782 | - diffwtd) -- syntax consumed entropy-exact (compound_type/wedge_idx/\ | ||
| 6783 | - wedge_sign/mask_type), but this decoder's compound blend does not \ | ||
| 6784 | - yet build the wedge/diffwtd mask, lane-maskcomp r1", | ||
| 6785 | - )); | ||
| 6786 | } | 6848 | } |
| 6787 | // corner-cut (lane-av1comp r16/r17, lane-av1blend r1): same | 6849 | // corner-cut (lane-av1comp r16/r17, lane-av1blend r1): same |
| 6788 | // reference-slot defect as the 16x16 leaf's own mask above | 6850 | // reference-slot defect as the 16x16 leaf's own mask above |
| @@ -6797,7 +6859,10 @@ fn decode_inter_block8( | |||
| 6797 | // compound_idx defect surfaces on the wide gate sweep. | 6859 | // compound_idx defect surfaces on the wide gate sweep. |
| 6798 | // lane-av1idx r1: same re-mask as the 16x16 leaf above -- | 6860 | // lane-av1idx r1: same re-mask as the 16x16 leaf above -- |
| 6799 | // see that comment. | 6861 | // see that comment. |
| 6800 | - let (fwd_offset, bck_offset, compound_idx) = if !skip_mode && enable_jnt_comp { | 6862 | + let (fwd_offset, bck_offset, compound_idx) = if comp_group_idx == 0 |
| 6863 | + && !skip_mode | ||
| 6864 | + && enable_jnt_comp | ||
| 6865 | + { | ||
| 6801 | let idx_ctx = get_comp_index_context( | 6866 | let idx_ctx = get_comp_index_context( |
| 6802 | neighbours, | 6867 | neighbours, |
| 6803 | outer_at, | 6868 | outer_at, |
| @@ -6886,7 +6951,23 @@ fn decode_inter_block8( | |||
| 6886 | &mut inter1_y, | 6951 | &mut inter1_y, |
| 6887 | ); | 6952 | ); |
| 6888 | let mut pred_y = vec![0u8; SIDE * SIDE]; | 6953 | let mut pred_y = vec![0u8; SIDE * SIDE]; |
| 6889 | - mc::combine_compound(&inter0_y, &inter1_y, fwd_offset, bck_offset, &mut pred_y); | 6954 | + let mut diffwtd_mask_y = Vec::new(); |
| 6955 | + if let Some(mask_type) = diffwtd_mask_type { | ||
| 6956 | + diffwtd_mask_y = vec![0u8; SIDE * SIDE]; | ||
| 6957 | + mc::diffwtd_mask(&inter0_y, &inter1_y, mask_type == 1, &mut diffwtd_mask_y); | ||
| 6958 | + mc::blend_masked_compound( | ||
| 6959 | + &inter0_y, | ||
| 6960 | + &inter1_y, | ||
| 6961 | + &diffwtd_mask_y, | ||
| 6962 | + SIDE, | ||
| 6963 | + SIDE, | ||
| 6964 | + SIDE, | ||
| 6965 | + false, | ||
| 6966 | + &mut pred_y, | ||
| 6967 | + ); | ||
| 6968 | + } else { | ||
| 6969 | + mc::combine_compound(&inter0_y, &inter1_y, fwd_offset, bck_offset, &mut pred_y); | ||
| 6970 | + } | ||
| 6890 | 6971 | ||
| 6891 | let mut inter0_u = vec![0i32; CHROMA_SIDE * CHROMA_SIDE]; | 6972 | let mut inter0_u = vec![0i32; CHROMA_SIDE * CHROMA_SIDE]; |
| 6892 | mc::predict_compound_intermediate( | 6973 | mc::predict_compound_intermediate( |
| @@ -6917,7 +6998,20 @@ fn decode_inter_block8( | |||
| 6917 | &mut inter1_u, | 6998 | &mut inter1_u, |
| 6918 | ); | 6999 | ); |
| 6919 | let mut pred_u = vec![0u8; CHROMA_SIDE * CHROMA_SIDE]; | 7000 | let mut pred_u = vec![0u8; CHROMA_SIDE * CHROMA_SIDE]; |
| 6920 | - mc::combine_compound(&inter0_u, &inter1_u, fwd_offset, bck_offset, &mut pred_u); | 7001 | + if diffwtd_mask_type.is_some() { |
| 7002 | + mc::blend_masked_compound( | ||
| 7003 | + &inter0_u, | ||
| 7004 | + &inter1_u, | ||
| 7005 | + &diffwtd_mask_y, | ||
| 7006 | + SIDE, | ||
| 7007 | + CHROMA_SIDE, | ||
| 7008 | + CHROMA_SIDE, | ||
| 7009 | + true, | ||
| 7010 | + &mut pred_u, | ||
| 7011 | + ); | ||
| 7012 | + } else { | ||
| 7013 | + mc::combine_compound(&inter0_u, &inter1_u, fwd_offset, bck_offset, &mut pred_u); | ||
| 7014 | + } | ||
| 6921 | 7015 | ||
| 6922 | let mut inter0_v = vec![0i32; CHROMA_SIDE * CHROMA_SIDE]; | 7016 | let mut inter0_v = vec![0i32; CHROMA_SIDE * CHROMA_SIDE]; |
| 6923 | mc::predict_compound_intermediate( | 7017 | mc::predict_compound_intermediate( |
| @@ -6948,7 +7042,20 @@ fn decode_inter_block8( | |||
| 6948 | &mut inter1_v, | 7042 | &mut inter1_v, |
| 6949 | ); | 7043 | ); |
| 6950 | let mut pred_v = vec![0u8; CHROMA_SIDE * CHROMA_SIDE]; | 7044 | let mut pred_v = vec![0u8; CHROMA_SIDE * CHROMA_SIDE]; |
| 6951 | - mc::combine_compound(&inter0_v, &inter1_v, fwd_offset, bck_offset, &mut pred_v); | 7045 | + if diffwtd_mask_type.is_some() { |
| 7046 | + mc::blend_masked_compound( | ||
| 7047 | + &inter0_v, | ||
| 7048 | + &inter1_v, | ||
| 7049 | + &diffwtd_mask_y, | ||
| 7050 | + SIDE, | ||
| 7051 | + CHROMA_SIDE, | ||
| 7052 | + CHROMA_SIDE, | ||
| 7053 | + true, | ||
| 7054 | + &mut pred_v, | ||
| 7055 | + ); | ||
| 7056 | + } else { | ||
| 7057 | + mc::combine_compound(&inter0_v, &inter1_v, fwd_offset, bck_offset, &mut pred_v); | ||
| 7058 | + } | ||
| 6952 | 7059 | ||
| 6953 | if skip { | 7060 | if skip { |
| 6954 | y.reconstruct_mc(px, py, SIDE, &pred_y, &vec![0i32; SIDE * SIDE]); | 7061 | 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
| @@ -3847,17 +3847,14 @@ mod tests { | |||
| 3847 | ); | 3847 | ); |
| 3848 | } | 3848 | } |
| 3849 | 3849 | ||
| 3850 | - /// lane-maskcomp r1: `--enable-masked-comp=1 --enable-dist-wtd-comp=1` | 3850 | + /// lane-maskcomp r2: `--enable-masked-comp=1 --enable-dist-wtd-comp=1` |
| 3851 | /// streams must consume `compound_type`/`wedge_idx`/`wedge_sign`/ | 3851 | /// streams must consume `compound_type`/`wedge_idx`/`wedge_sign`/ |
| 3852 | - /// `mask_type` entropy-exact (`masked_compound_hits() > 0`) whenever a | 3852 | + /// `mask_type` entropy-exact AND build the real DIFFWTD blend -- |
| 3853 | - /// block reads `comp_group_idx == 1` -- the syntax is ported this | 3853 | + /// `masked_compound_hits() > 0` is now a hard assert, and a |
| 3854 | - /// round, the wedge/diffwtd mask blend is NOT, so a masked-compound | 3854 | + /// `COMPOUND_DIFFWTD` refusal is FORBIDDEN (matches interintra's own |
| 3855 | - /// refusal itself is still EXPECTED here (r1's own named refusal, | 3855 | + /// gate). `COMPOUND_WEDGE` refusals are still EXPECTED (r2 scope: |
| 3856 | - /// asserted for wording only) rather than forbidden; only OTHER named | 3856 | + /// wedge mask codebook not ported, charter's mergeable-partial |
| 3857 | - /// refusals (screen content tools etc.) skip a seed without counting. | 3857 | + /// fallback) -- counted separately, never asserted against. |
| 3858 | - /// Once the blend lands, this gate's own masked-compound refusal | ||
| 3859 | - /// becomes forbidden like `a_real_aomenc_stream_with_interintra_...` | ||
| 3860 | - /// above's wedge case was for non-wedge interintra. | ||
| 3861 | #[test] | 3858 | #[test] |
| 3862 | fn a_real_aomenc_stream_with_masked_compound_decodes_pixel_exact() { | 3859 | fn a_real_aomenc_stream_with_masked_compound_decodes_pixel_exact() { |
| 3863 | const NAME: &str = "a_real_aomenc_stream_with_masked_compound_decodes_pixel_exact"; | 3860 | const NAME: &str = "a_real_aomenc_stream_with_masked_compound_decodes_pixel_exact"; |
| @@ -3983,6 +3980,11 @@ mod tests { | |||
| 3983 | "{NAME} refused on warp (seed {seed}) -- warp decode is ported: {msg}" | 3980 | "{NAME} refused on warp (seed {seed}) -- warp decode is ported: {msg}" |
| 3984 | ); | 3981 | ); |
| 3985 | if msg.contains("masked COMPOUND_REFERENCE") { | 3982 | if msg.contains("masked COMPOUND_REFERENCE") { |
| 3983 | + assert!( | ||
| 3984 | + msg.contains("COMPOUND_WEDGE"), | ||
| 3985 | + "{NAME} refused a non-wedge masked-compound block (seed {seed}) \ | ||
| 3986 | + -- DIFFWTD blend is ported, this refusal is forbidden: {msg}" | ||
| 3987 | + ); | ||
| 3986 | masked_refusals += 1; | 3988 | masked_refusals += 1; |
| 3987 | } else { | 3989 | } else { |
| 3988 | assert!( | 3990 | assert!( |
| @@ -4028,22 +4030,18 @@ mod tests { | |||
| 4028 | // is that sampling flake, not a decode regression -- check | 4030 | // is that sampling flake, not a decode regression -- check |
| 4029 | // masked_compound_hits/named_refusals in the panic message before | 4031 | // masked_compound_hits/named_refusals in the panic message before |
| 4030 | // assuming a real bug. | 4032 | // assuming a real bug. |
| 4031 | - // r1: a zero-hit run is the sampling flake above, not a regression -- | 4033 | + // r2: DIFFWTD is ported and gated, so a zero-hit run is no longer |
| 4032 | - // report it loudly instead of failing the default suite (the interintra | 4034 | + // soft-skipped -- hard assert, matching the interintra gate. |
| 4033 | - // gate went through the same soft phase; r2 flips this to a hard | 4035 | + assert!( |
| 4034 | - // assert once the blend lands and masked refusals become forbidden). | 4036 | + crate::decode::masked_compound_hits() > 0, |
| 4035 | - if crate::decode::masked_compound_hits() == 0 { | 4037 | + "{NAME}: zero masked-compound blocks fired ({masked_refusals} wedge refusals, \ |
| 4036 | - eprintln!( | 4038 | + {matched} matches, {named_refusals} other refusals out of {n_attempts}) -- gate \ |
| 4037 | - "{NAME}: SOFT-SKIP -- zero masked-compound blocks fired ({masked_refusals} \ | 4039 | + proved nothing this run" |
| 4038 | - masked refusals, {matched} matches, {named_refusals} other refusals out of \ | 4040 | + ); |
| 4039 | - {n_attempts}); sampling flake, gate proved nothing this run" | ||
| 4040 | - ); | ||
| 4041 | - return; | ||
| 4042 | - } | ||
| 4043 | eprintln!( | 4041 | eprintln!( |
| 4044 | "{NAME}: {named_refusals} other-capability refusals, {masked_refusals} expected \ | 4042 | "{NAME}: {named_refusals} other-capability refusals, {masked_refusals} expected \ |
| 4045 | - masked-compound refusals (r1: blend unported), {matched} pixel-exact matches out \ | 4043 | + COMPOUND_WEDGE refusals (r2 scope: wedge unported), {matched} pixel-exact matches \ |
| 4046 | - of {n_attempts}, masked_compound_hits={}", | 4044 | + out of {n_attempts}, masked_compound_hits={}", |
| 4047 | crate::decode::masked_compound_hits() | 4045 | crate::decode::masked_compound_hits() |
| 4048 | ); | 4046 | ); |
| 4049 | } | 4047 | } |
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. | ||