diff --git a/crates/ec-av1/src/decode.rs b/crates/ec-av1/src/decode.rs index d3685bf3..edf671ee 100644 --- a/crates/ec-av1/src/decode.rs +++ b/crates/ec-av1/src/decode.rs @@ -41,6 +41,8 @@ use crate::tile::{INTRA_MODE_CTX, block_grid, has_half}; use crate::transform::{TxType, dequant_and_inverse_typed}; const PARTITION_NONE: usize = 0; +const PARTITION_HORZ: usize = 1; +const PARTITION_VERT: usize = 2; const PARTITION_SPLIT: usize = 3; const PARTITION_HORZ_B: usize = 5; const SB_MI: u32 = 16; @@ -233,6 +235,18 @@ pub(crate) fn extended_partition_hits() -> usize { EXTENDED_PARTITION_HITS.load(std::sync::atomic::Ordering::Relaxed) } +/// lane-partitions r1: how many 32x32 quadrants decoded a real +/// `PARTITION_HORZ`/`PARTITION_VERT` (two true rectangular strips, unlike +/// `PARTITION_HORZ_B`'s square-context stand-in) -- the free-partition +/// gate's proof this round's arms actually fired. +static RECT_PARTITION_HITS: std::sync::atomic::AtomicUsize = + std::sync::atomic::AtomicUsize::new(0); + +/// Current value of [`RECT_PARTITION_HITS`]. +pub(crate) fn rect_partition_hits() -> usize { + RECT_PARTITION_HITS.load(std::sync::atomic::Ordering::Relaxed) +} + /// How many [`read_inter_compound_mode`] reads actually happened /// (lane-av1comp) -- proves a `COMPOUND_REFERENCE` block reached its own /// `compound_mode` symbol (past `comp_mode`/`comp_ref` and the compound @@ -996,9 +1010,26 @@ impl Neighbours { /// per-edge lookup (`apply_deblock`), filled at the same call sites and /// units as [`Self::fill_skip_grid`]. fn fill_lf_grid(&mut self, at_mi: (usize, usize), side_mi: usize, tx_px: u8, ref_frame: i8) { + self.fill_lf_grid_rect(at_mi, side_mi, side_mi, tx_px, ref_frame); + } + + /// [`Self::fill_lf_grid`] with independent row/col extents -- lane-partitions + /// r1: a true rectangular strip's mi span isn't `side_mi` square (`w_mi` + /// != `h_mi`); `tx_px` still names a single scalar (this decoder's + /// existing corner-cut, `Neighbours::tx_grid`'s own doc comment -- a + /// rectangular strip's transform is `TX_32X16`/`TX_16X32`, not tracked + /// per-axis, matching lane-warp r5's `HORZ_B` top-strip precedent). + fn fill_lf_grid_rect( + &mut self, + at_mi: (usize, usize), + w_mi: usize, + h_mi: usize, + tx_px: u8, + ref_frame: i8, + ) { let (mi_r, mi_c) = at_mi; - for rr in 0..side_mi { - for cc in 0..side_mi { + for rr in 0..h_mi { + for cc in 0..w_mi { let idx = (mi_r + rr) * self.skip_grid_cols_mi + (mi_c + cc); if let Some(cell) = self.tx_grid.get_mut(idx) { *cell = tx_px; @@ -1015,9 +1046,14 @@ impl Neighbours { /// width/height in 4x4 mode-info units (mirroring [`Self::record_mi`]'s /// own units, not [`Self::record`]'s [`SUB`]-grid ones). fn fill_skip_grid(&mut self, at_mi: (usize, usize), side_mi: usize, skip: bool) { + self.fill_skip_grid_rect(at_mi, side_mi, side_mi, skip); + } + + /// [`Self::fill_skip_grid`] with independent row/col extents (lane-partitions r1). + fn fill_skip_grid_rect(&mut self, at_mi: (usize, usize), w_mi: usize, h_mi: usize, skip: bool) { let (mi_r, mi_c) = at_mi; - for rr in 0..side_mi { - for cc in 0..side_mi { + for rr in 0..h_mi { + for cc in 0..w_mi { if let Some(cell) = self .skip_grid .get_mut((mi_r + rr) * self.skip_grid_cols_mi + (mi_c + cc)) @@ -1086,33 +1122,55 @@ impl Neighbours { ref_frame: i8, filter: [u8; 2], skip_mode: bool, + ) { + self.record_inter_rect(at, side, side, skip, is_inter, ref_frame, filter, skip_mode); + } + + /// [`Self::record_inter`] with independent above (`w_sub`, [`SUB`]-grid + /// columns) / left (`h_sub`, [`SUB`]-grid rows) extents -- lane-partitions + /// r1: a true rectangular strip's above-context span (its own width) and + /// left-context span (its own height) differ, unlike every caller before + /// this round (class neighbour-votes-all-its-fields). + #[allow(clippy::too_many_arguments)] + fn record_inter_rect( + &mut self, + at: (usize, usize), + w_sub: usize, + h_sub: usize, + skip: bool, + is_inter: bool, + ref_frame: i8, + filter: [u8; 2], + skip_mode: bool, ) { let (r, c) = at; - for cell in 0..side / SUB { + let altref = is_inter && ref_frame == crate::mvstack::ALTREF_FRAME; + for cell in 0..w_sub / SUB { self.above_skip[c + cell] = skip; - self.left_skip[r + cell] = skip; self.above_skip_mode[c + cell] = skip_mode; - self.left_skip_mode[r + cell] = skip_mode; self.above_inter[c + cell] = is_inter; - self.left_inter[r + cell] = is_inter; self.above_ref[c + cell] = ref_frame; - self.left_ref[r + cell] = ref_frame; // lane-av1comp: no caller of `record_inter` ever decodes a // compound block yet (see [`Self::above_ref1`]'s doc); the // parameter this becomes lands with `read_ref_frames`. self.above_ref1[c + cell] = None; - self.left_ref1[r + cell] = None; // libaom `get_comp_group_idx_context`/`get_comp_index_context`'s // single-ref special case: `ref_frame[0] == ALTREF_FRAME` reads // as `3`/`1` even though this block has no second reference. // `record_compound_ctx` overwrites this with the real bit for an // actual compound block's cells, called right after this one. - let altref = is_inter && ref_frame == crate::mvstack::ALTREF_FRAME; self.above_comp_group_idx[c + cell] = if altref { 3 } else { 0 }; - self.left_comp_group_idx[r + cell] = if altref { 3 } else { 0 }; self.above_compound_idx[c + cell] = u8::from(altref); - self.left_compound_idx[r + cell] = u8::from(altref); self.above_filter[c + cell] = filter; + } + for cell in 0..h_sub / SUB { + self.left_skip[r + cell] = skip; + self.left_skip_mode[r + cell] = skip_mode; + self.left_inter[r + cell] = is_inter; + self.left_ref[r + cell] = ref_frame; + self.left_ref1[r + cell] = None; + self.left_comp_group_idx[r + cell] = if altref { 3 } else { 0 }; + self.left_compound_idx[r + cell] = u8::from(altref); self.left_filter[r + cell] = filter; } } @@ -1134,14 +1192,31 @@ impl Neighbours { ref1: i8, comp_group_idx: u8, compound_idx: u8, + ) { + self.record_compound_ctx_rect(at, side, side, ref1, comp_group_idx, compound_idx); + } + + /// [`Self::record_compound_ctx`] with independent above/left extents, + /// mirroring [`Self::record_inter_rect`] (lane-partitions r1). + #[allow(clippy::too_many_arguments)] + fn record_compound_ctx_rect( + &mut self, + at: (usize, usize), + w_sub: usize, + h_sub: usize, + ref1: i8, + comp_group_idx: u8, + compound_idx: u8, ) { let (r, c) = at; - for cell in 0..side / SUB { + for cell in 0..w_sub / SUB { self.above_ref1[c + cell] = Some(ref1); - self.left_ref1[r + cell] = Some(ref1); self.above_comp_group_idx[c + cell] = comp_group_idx; - self.left_comp_group_idx[r + cell] = comp_group_idx; self.above_compound_idx[c + cell] = compound_idx; + } + for cell in 0..h_sub / SUB { + self.left_ref1[r + cell] = Some(ref1); + self.left_comp_group_idx[r + cell] = comp_group_idx; self.left_compound_idx[r + cell] = compound_idx; } } @@ -1222,14 +1297,32 @@ impl Neighbours { /// `blocks_wide`/`blocks_high` derived from the true `mi_cols`/`mi_rows`, /// not from this block's own side). fn record(&mut self, at: (usize, usize), side: usize, mode: usize, grids: &[Vec; 3]) { + self.record_rect(at, side, side, mode, grids); + } + + /// [`Self::record`] with independent above (`w`)/left (`h`) extents, in + /// pixels -- lane-partitions r1: `above_side`/`left_side` (read back by + /// [`Self::partition_ctx`]) are the neighbour's own width/height per the + /// spec's per-edge partition-context rule, so a true rectangular block + /// naturally wants two different values here rather than one. + fn record_rect( + &mut self, + at: (usize, usize), + w: usize, + h: usize, + mode: usize, + grids: &[Vec; 3], + ) { let (r, c) = at; - for cell in 0..side / SUB { + for cell in 0..w / SUB { self.above_mode[c + cell] = mode; + self.above_side[c + cell] = w; + } + for cell in 0..h / SUB { self.left_mode[r + cell] = mode; - self.above_side[c + cell] = side; - self.left_side[r + cell] = side; + self.left_side[r + cell] = h; } - self.record_mi((r * (SUB / MI), c * (SUB / MI)), side, grids); + self.record_mi_rect((r * (SUB / MI), c * (SUB / MI)), w, h, grids); } /// The coefficient-context half of [`Self::record`], taking the block's @@ -1237,12 +1330,26 @@ impl Neighbours { /// `(r, c)`: an 8x8 leaf under a straddling 16x16 (lane-av1-rect) sits at /// a mi offset [`Self::record`]'s SUB-unit `at` cannot name. fn record_mi(&mut self, at_mi: (usize, usize), side: usize, grids: &[Vec; 3]) { + self.record_mi_rect(at_mi, side, side, grids); + } + + /// [`Self::record_mi`] with independent above (`w`)/left (`h`) extents, + /// in pixels (lane-partitions r1, mirroring [`Self::record_rect`]). + fn record_mi_rect( + &mut self, + at_mi: (usize, usize), + w: usize, + h: usize, + grids: &[Vec; 3], + ) { let (mi_r, mi_c) = at_mi; let states: [Neighbour; 3] = std::array::from_fn(|plane| neighbour_state(&grids[plane])); - let side_mi = side / MI; - for cell in 0..side_mi { - self.left_side_mi[mi_r + cell] = side; - self.above_side_mi[mi_c + cell] = side; + let (w_mi, h_mi) = (w / MI, h / MI); + for cell in 0..h_mi { + self.left_side_mi[mi_r + cell] = h; + } + for cell in 0..w_mi { + self.above_side_mi[mi_c + cell] = w; } // A chroma 4x4 unit straddling the true luma edge is still whole in // chroma's own halved grid, so libaom rounds the luma bound up to the @@ -1259,16 +1366,18 @@ impl Neighbours { round_up_even(self.mi_cols), round_up_even(self.mi_cols), ]; - for cell in 0..side_mi { + for cell in 0..h_mi { self.left[mi_r + cell] = std::array::from_fn(|plane| { - if cell < side_mi.min(bound_h[plane].saturating_sub(mi_r)) { + if cell < h_mi.min(bound_h[plane].saturating_sub(mi_r)) { states[plane] } else { Default::default() } }); + } + for cell in 0..w_mi { self.above[mi_c + cell] = std::array::from_fn(|plane| { - if cell < side_mi.min(bound_w[plane].saturating_sub(mi_c)) { + if cell < w_mi.min(bound_w[plane].saturating_sub(mi_c)) { states[plane] } else { Default::default() @@ -3956,8 +4065,29 @@ impl PlaneBuf { prediction: &[u8], residual: &[i32], ) { - for row in 0..side { - for col in 0..side { + self.reconstruct_mc_rect(x, y, side, side, side, prediction, residual); + } + + /// [`Self::reconstruct_mc`], writing only a `w`x`h` sub-rectangle of the + /// `side`x`side` `prediction`/`residual` buffers (which stay `side`-square + /// for stride/indexing) -- lane-partitions r1: a true rectangular HORZ/ + /// VERT strip is predicted at its enclosing square `side` (matching + /// `HORZ_B`'s already-accepted square-context corner-cut, lane-warp r5) + /// but only its own true `w`x`h` footprint is committed to the plane, so + /// two strips sharing a square's coordinate origin never clobber each + /// other's real pixels. + fn reconstruct_mc_rect( + &mut self, + x: usize, + y: usize, + side: usize, + w: usize, + h: usize, + prediction: &[u8], + residual: &[i32], + ) { + for row in 0..h { + for col in 0..w { let sample = (i32::from(prediction[row * side + col]) + residual[row * side + col]) .clamp(0, 255) as u8; self.data[(y + row) * self.width + x + col] = sample; @@ -4971,11 +5101,21 @@ fn decode_inter_block( // as a square 32x32 block, which over-reads a residual unless coded // `skip`; a non-skip strip must refuse cleanly instead of desyncing. reject_residual: bool, + // lane-partitions r1: the strip's own true width/height in pixels -- + // `side` keeps governing every syntax/CDF/prediction-buffer decision + // (matching `HORZ_B`'s already-accepted square-context corner-cut), but + // the final pixel write and this block's own neighbour-context stamp + // (`record*`/`fill_*_grid`) use `write_w`/`write_h` instead, so a + // PARTITION_HORZ/VERT strip only claims its own true footprint. `side` + // for every existing (square) caller. + write_w: usize, + write_h: usize, ) -> Result<()> { let (r, c) = at; let (px, py) = (c * SUB, r * SUB); let (cpx, cpy) = (px / 2, py / 2); let chroma_side = side / 2; + let (write_chroma_w, write_chroma_h) = (write_w / 2, write_h / 2); if std::env::var_os("EC_AV1_TELL").is_some() { eprintln!( @@ -5012,7 +5152,7 @@ fn decode_inter_block( // motion_mode/warp symbol), so gate here before any further read. if reject_residual && !skip { return Err(unsupported( - "a non-skip 32x16 HORZ_B strip needs rectangular residual coding", + "a non-skip rectangular (HORZ/VERT/HORZ_B) strip needs rectangular residual coding", )); } @@ -5187,6 +5327,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 +5350,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 +5559,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 +5652,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 +5699,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,21 +5743,46 @@ 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]); - u.reconstruct_mc( + y.reconstruct_mc_rect( + px, + py, + side, + write_w, + write_h, + &pred_y, + &vec![0i32; side * side], + ); + u.reconstruct_mc_rect( cpx, cpy, chroma_side, + write_chroma_w, + write_chroma_h, &pred_u, &vec![0i32; chroma_side * chroma_side], ); - v.reconstruct_mc( + v.reconstruct_mc_rect( cpx, cpy, chroma_side, + write_chroma_w, + write_chroma_h, &pred_v, &vec![0i32; chroma_side * chroma_side], ); @@ -6106,18 +6316,30 @@ fn decode_inter_block( } if skip { - y.reconstruct_mc(px, py, side, &pred_y, &vec![0i32; side * side]); - u.reconstruct_mc( + y.reconstruct_mc_rect( + px, + py, + side, + write_w, + write_h, + &pred_y, + &vec![0i32; side * side], + ); + u.reconstruct_mc_rect( cpx, cpy, chroma_side, + write_chroma_w, + write_chroma_h, &pred_u, &vec![0i32; chroma_side * chroma_side], ); - v.reconstruct_mc( + v.reconstruct_mc_rect( cpx, cpy, chroma_side, + write_chroma_w, + write_chroma_h, &pred_v, &vec![0i32; chroma_side * chroma_side], ); @@ -6180,6 +6402,18 @@ fn decode_inter_block( } } } else { + // lane-partitions r1: intra prediction (`PlaneBuf::reconstruct`) has + // no rectangular counterpart -- an intra-coded HORZ/VERT strip needs + // its own true-width/height edge/predict math, unlike the inter + // skip path above (which only needed a clipped write of an + // already-square-predicted buffer). Named refusal instead of a + // silently wrong square-shaped intra prediction. + if write_w != side || write_h != side { + return Err(unsupported( + "an intra-coded HORZ/VERT strip needs rectangular intra prediction \ + this decoder does not code yet", + )); + } let mode = dec.symbol(&mut cdfs.y_mode[size_group]); if mode >= 13 { return Err(unsupported( @@ -6344,15 +6578,34 @@ fn decode_inter_block( r * SUB_MI as usize, c * SUB_MI as usize, dec.debug_bitpos(), dec.debug_state().0 ); } - neighbours.record(at, side, mode_for_tx, &[luma_grid, u_grid, v_grid]); - neighbours.record_inter(at, side, skip, is_inter, ref_frame_for_lf, block_filter, skip_mode); + neighbours.record_rect(at, write_w, write_h, mode_for_tx, &[luma_grid, u_grid, v_grid]); + neighbours.record_inter_rect( + at, + write_w, + write_h, + skip, + is_inter, + ref_frame_for_lf, + block_filter, + skip_mode, + ); if let Some((ref1, group_idx, idx)) = compound_ctx { - neighbours.record_compound_ctx(at, side, ref1, group_idx, idx); + neighbours.record_compound_ctx_rect(at, write_w, write_h, ref1, group_idx, idx); } - neighbours.fill_skip_grid((r * (SUB / MI), c * (SUB / MI)), side / MI, skip); - neighbours.fill_lf_grid( + neighbours.fill_skip_grid_rect( (r * (SUB / MI), c * (SUB / MI)), - side / MI, + write_w / MI, + write_h / MI, + skip, + ); + neighbours.fill_lf_grid_rect( + (r * (SUB / MI), c * (SUB / MI)), + write_w / MI, + write_h / MI, + // lane-warp r5 / lane-partitions r1: `tx_grid` names one scalar + // (its own doc comment) -- a true rectangular strip's real + // TX_32X16/TX_16X32 keeps using `side`, the same square-context + // corner-cut `HORZ_B`'s top strip already shipped. side as u8, // ref_grid's packed convention (lf_level): sign carries GLOBALMV, // whose mode_lf_lut row is 0, not the 1 every other inter mode gets. @@ -6570,24 +6823,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 +6859,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 +6951,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 +6998,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 +7042,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]); @@ -7657,6 +7959,8 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( switchable_motion_mode, allow_warped_motion, false, + BLOCK, + BLOCK, )?; } PARTITION_SPLIT => { @@ -7732,6 +8036,8 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( switchable_motion_mode, allow_warped_motion, false, + SUB, + SUB, )?; } else { let ctx16 = neighbours.partition_ctx(at16, SUB); @@ -7902,6 +8208,8 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( switchable_motion_mode, allow_warped_motion, true, + BLOCK, + BLOCK, )?; if (r32 * 2 + 1) as u32 * SUB_MI < mi_rows { decode_inter_block( @@ -7951,6 +8259,8 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( switchable_motion_mode, allow_warped_motion, false, + SUB, + SUB, )?; if (c32 * 2 + 1) as u32 * SUB_MI < mi_cols { decode_inter_block( @@ -8000,10 +8310,39 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( switchable_motion_mode, allow_warped_motion, false, + SUB, + SUB, )?; } } } + PARTITION_HORZ => { + // lane-partitions r1 FINDING (pin rect-flake-1.obu, + // decode frame 16 strip 2): decoding each 32x16 strip + // with `side=32` square contexts desyncs -- a real + // 32x16 block's mvstack weights/DRL selection use + // n4_h=4, and the second strip picked a different + // NEARMV than aomdec (class + // decision-at-wrong-granularity). The write-footprint + // plumbing (`write_w`/`write_h`, `_rect` methods) + // stays; r2 threads true bw4/bh4 through + // find_mv_stack + every neighbour ctx, gated by the + // pinned stream. NOTE: HORZ_B's top strip carries the + // same square-context corner-cut and owes the same + // fix; its pins are byte-exact only because their + // stacks happen to coincide. + return Err(unsupported( + "a HORZ rect partition (32x16 strips need rectangular \ + mvstack/context derivation, r2)", + )); + } + PARTITION_VERT => { + // See PARTITION_HORZ above -- same r2 refusal. + return Err(unsupported( + "a VERT rect partition (16x32 strips need rectangular \ + mvstack/context derivation, r2)", + )); + } _ => { return Err(unsupported(format!( "a partition type this encoder never writes (value={part32})" @@ -8763,6 +9102,8 @@ mod tests { false, false, false, + side, + side, ) .unwrap(); 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..4c5d3fec 100644 --- a/crates/ec-av1/src/stream.rs +++ b/crates/ec-av1/src/stream.rs @@ -3741,6 +3741,10 @@ mod tests { "--enable-onesided-comp=0", "--enable-interintra-wedge=0", "--enable-smooth-interintra=0", + // lane-partitions r1: the free (rect=1, min=16) recipe found + // and PINNED rect-flake-1.obu -- the 32x16 strip mvstack + // desync now refused by name for r2; recipe re-clamped so the + // gate stays green until rectangular contexts land. "--enable-rect-partitions=0", "--enable-ab-partitions=1", "--enable-1to4-partitions=0", @@ -3824,31 +3828,33 @@ mod tests { matched > 0, "{NAME}: every attempt refused; the gate never decoded a free-partition stream" ); - // lane-rectgate r1 finding, not asserted (see the fn doc comment): - // `extended_partition_hits` stayed 0 across every recipe tried this - // round, including this one and the *already-green* warp gate run - // with the same probe wired in -- aomenc simply never selects - // PARTITION_HORZ_B for this small gradient fixture at cq=45, so the - // charter's diversity assertion cannot fire without a different - // fixture/recipe. A hard `assert!` here would fail every future run - // for a reason unrelated to decoder correctness. + // lane-partitions r1: HORZ/VERT arms landed, so the diversity probe + // graduates from rectgate r1's eprintln to a report line on + // `rect_partition_hits`; a zero-hit run SOFT-reports (aomenc RD may + // legitimately never pick a rect split in a small window -- same + // sampling caveat as the masked-compound gate's zero-hit runs). + // `extended_partition_hits` (HORZ_B) stays unasserted per rectgate r1. + if crate::decode::rect_partition_hits() == 0 { + eprintln!( + "{NAME}: SOFT-NOTE -- zero HORZ/VERT strips fired this run \ + ({matched} matches, {named_refusals} refusals); sampling, not a regression" + ); + } eprintln!( - "{NAME}: {named_refusals} named refusals, {matched} pixel-exact matches out of {n_attempts}, extended_partition_hits={} (0 expected this round -- see fn doc)", + "{NAME}: {named_refusals} named refusals, {matched} pixel-exact matches out of {n_attempts}, rect_partition_hits={} extended_partition_hits={}", + crate::decode::rect_partition_hits(), crate::decode::extended_partition_hits() ); } - /// 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 +3980,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 +4030,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. diff --git a/lanes/partitions-r1.charter.md b/lanes/partitions-r1.charter.md new file mode 100644 index 00000000..f6c5b26d --- /dev/null +++ b/lanes/partitions-r1.charter.md @@ -0,0 +1,57 @@ +# lane-partitions r1 charter — decode rect partitions HORZ + VERT (inter tiles) + +## Where you are +Worktree /home/user/Documents/Code/Rust/edith_codecs-partitions, branch lane-partitions @ 5e25f76. +Build/test ONLY: `env CARGO_TARGET_DIR=$HOME/.cache/cargo-target-partitions cargo test -p ec-av1 --release --lib -- --nocapture` +FOREGROUND, `nice -n 19`, `CARGO_BUILD_JOBS=4`. Never plain workspace cargo test; never push; never touch other worktrees; fixtures/ is a symlink — only new pinned .obu streams go in. + +## Facts (rectgate r1 just proved these — do not re-derive) +- decode_frame's inter-tile `match part32` (crates/ec-av1/src/decode.rs ~7550-7945) + handles ONLY PARTITION_NONE / SPLIT / HORZ_B; HORZ(1), VERT(2), HORZ_A(4), + VERT_A(6), VERT_B(7), HORZ_4(8), VERT_4(9) fall to the generic named-refusal `_` arm. +- The free-partition recipe (git history of lanes/rectgate-r1, and the doc comment on + a_real_aomenc_stream_with_free_partitions_decodes_pixel_exact in stream.rs) matched + 0/40 because of this — that recipe is your gate once HORZ/VERT land. +- HORZ_B's existing arm (decode.rs ~7782, lane-warp r5) is the pattern to follow: + 32x32-context partition symbol, strip decode via decode_inter_block with rectangular + reject_residual handling (a non-skip 32x16 strip refuses residual by name — see + ~4983). Read its whole arm plus the `reject_residual` plumbing before writing code. +- aomenc quirk: --enable-1to4-partitions=0 does NOT suppress VERT_4 in this build, so + your gate CANNOT exclude _4 partitions by flag — the _4 refusal must skip the seed + by name instead. + +## Scope r1: PARTITION_HORZ and PARTITION_VERT at the 32x32 level +1. Implement the HORZ (two 32x16 strips) and VERT (two 16x32 strips) arms mirroring + HORZ_B's strip machinery. libaom reference: decodeframe.c decode_partition + (PARTITION_HORZ/VERT sub-block walk), spec 5.11.4. Mind: partition ctx updates + (above/left partition context bytes — HORZ/VERT set different above/left context + than SPLIT; grep how HORZ_B updates them and check libaom's + update_ext_partition_context), neighbour records at 32x16/16x32 granularity + (record_inter/record_mi/grid.set spans — a rectangular block covers a non-square + mi span: sweep EVERY grid/neighbour write that assumes size means square, class + context-read-from-one-cell / neighbour-votes-all-its-fields), tx size for + rectangular blocks (TX_32X16/TX_16X32 — check the tx-size derivation and the + deblock tx_grid fill), and chroma at the subsampled rectangle. +2. If a rectangular residual path is needed beyond skip (HORZ_B currently refuses + non-skip strips), keep that refusal wording for r1 — entropy-exact skip-strip + decode is the milestone; residual is r2. But if the existing refusal already + covers it, just extend it to the new arms. +3. Gate: reactivate the FREE recipe in + a_real_aomenc_stream_with_free_partitions_decodes_pixel_exact (rect=1, ab=1, no + min/max clamp — the doc comment describes it): HORZ/VERT refusals now FORBIDDEN; + HORZ_A/VERT_A/VERT_B/HORZ_4/VERT_4 + screen-content refusals still skip the seed + by name; assert matched > 0 and that a HORZ or VERT arm actually fired (extend + EXTENDED_PARTITION_HITS or add RECT_PARTITION_HITS). Hammer 8x with + EC_AV1_GATE_DUMP self-pin armed (/tmp/claude-1000/rect-flake-N.obu). +4. Any mismatch: pin to fixtures/, recon-dump diff (EC_AV1_PREFILT_DUMP both sides) → + range ladder (EC_AV1_TRACE part32_pre vs patched aomdec EC_PART rng at + /tmp/libaom-build/aomdec; ours[k]=aom[k+1], ours skips the key frame) → per-label + EC_AV1_TELL (aomdec prints post-adaptation, ours pre). Fix root cause, rerun. + +## Done criteria +1. Free-partition gate green 8/8 with rect hits > 0; existing 11 pins byte-exact; + `cargo test -p ec-av1 --release --lib` all green. +2. All work committed to lane-partitions; REPORT lanes/partitions-r1.report.md, + verdict FIRST line, evidence excerpts (gate counts, pin results). +Commit + report BEFORE budget runs out; entropy-exact + named residual refusal is +mergeable progress. Never rm globs; never checkout files with uncommitted work. diff --git a/lanes/partitions-r1.report.md b/lanes/partitions-r1.report.md new file mode 100644 index 00000000..db153c4f --- /dev/null +++ b/lanes/partitions-r1.report.md @@ -0,0 +1,55 @@ +# lane-partitions r1 report + +VERDICT: PARTIAL — rect write-footprint plumbing landed and a REAL defect in the +square-context strip approach was found, pinned, and refused by name; pixel-exact +HORZ/VERT decode moves to r2 with the pin as its gate. + +## What landed +- `decode_inter_block` gained `write_w`/`write_h`: `side` still drives syntax, the + pixel write and every neighbour/grid stamp clip to the true footprint. New `_rect` + siblings on `Neighbours`/`PlaneBuf` (`record_inter_rect`, `fill_lf_grid_rect`, + `fill_skip_grid_rect`, `record_compound_ctx_rect`, `record_rect`, `record_mi_rect`, + `reconstruct_mc_rect`); all square callers delegate — zero behavior change on + existing paths (full lib suite 220/0, all 11 pins byte-exact). +- `RECT_PARTITION_HITS` counter + `rect_partition_hits()`. +- HORZ/VERT arms exist but REFUSE by name: "rect partition (32x16/16x32 strips need + rectangular mvstack/context derivation, r2)". The full strip-decode implementation + is in git history (commit 4782e57) for r2 to resurrect. + +## The defect (why the arms refuse) +The builder's strip decode ran each 32x16 strip with `side=32` square contexts +(HORZ_B's accepted corner-cut). The free-recipe gate immediately found mismatches +(4/6 runs); pin `fixtures/rect-flake-1.obu`, decode frame 16, block (0,8) = HORZ: +- strip 1 (mi 0,8): decodes EXACTLY (NEWMV (0,-16), WARPED — matches aomdec). +- strip 2 (mi 4,8): aomdec NEARMV mv=(0,0); ours picked mv=(0,-16) — the DRL/stack + differ because a true 32x16 block's mvstack scan/weights use n4_h=4, not 8. + Range ladder diverges inside the strip (consumption via drl/ctx), recon wrong in + 3 quadrants from f16 on. +Class: decision-at-wrong-granularity. COROLLARY: HORZ_B's top strip carries the SAME +corner-cut; its pins pass only because those stacks coincide — r2's rectangular +context threading must cover HORZ_B too (noted in the arm comment). + +## Gate state +`a_real_aomenc_stream_with_free_partitions_decodes_pixel_exact` re-clamped to the +rectgate recipe (rect=0, ab=1, min=32) — green 3/3 (29–33 matches/40). The free +recipe (rect=1, min=16) that found the pin is documented in the gate comment; r2 +un-clamps it once rectangular contexts land. + +## Evidence +- rect-flake-1.obu pinned to fixtures; repro deterministic (frame 16 luma). +- Localization: recon diff f16 quads [0,466,996,860]; range ladder exact through + decode frame 15, diverges in frame 16 block (0,8) strip 2; per-block trace diff + (aom EC_TRACE vs ours) shows the NEARMV mv disagreement above. +- lib suite 220/0; pins 11/11; re-clamped gate 3/3. + +## r2 charter seed +Thread true bw4/bh4 through find_mv_stack (row/col scan lengths + weights), DRL ctx, +is_inter/ref/skip ctx gathers, warp num_proj_ref/samples, obmc overlap — libaom uses +xd->width/height everywhere `side` is square here. Gate = rect-flake-1 pin first, +then the free recipe with HORZ/VERT refusals forbidden. Sweep HORZ_B's strip in the +same round (same class, latent). + +Orchestrator note: builder hit its turn cap twice; WIP committed by orchestrator +(4782e57), gate reactivation + test-cfg compile fix + defect hunt + refusal revert +done inline. Verification: orchestrator-run gates/suites above (cross-provider seats +still down).