forge
Explore
Log in

Don't you dare go Hollow

Merge branch 'lane-partitions' (incl. lane-maskcomp2): DIFFWTD masked-compound blend decodes; rect write-footprint plumbing; HORZ/VERT strip mvstack defect pinned + refused for r2

Browse files at this commit

9cec3a2c64b0ad76273e428ce85cab6e2349bae5Ahmet Kaan GümüşParent: 37a88199dc3c1e
crates/ec-av1/src/decode.rsmodified+409 -68
@@ -41,6 +41,8 @@ use crate::tile::{INTRA_MODE_CTX, block_grid, has_half};
4141 use crate::transform::{TxType, dequant_and_inverse_typed};
4242
4343 const PARTITION_NONE: usize = 0;
44+const PARTITION_HORZ: usize = 1;
45+const PARTITION_VERT: usize = 2;
4446 const PARTITION_SPLIT: usize = 3;
4547 const PARTITION_HORZ_B: usize = 5;
4648 const SB_MI: u32 = 16;
@@ -233,6 +235,18 @@ pub(crate) fn extended_partition_hits() -> usize {
233235 EXTENDED_PARTITION_HITS.load(std::sync::atomic::Ordering::Relaxed)
234236 }
235237
238+/// lane-partitions r1: how many 32x32 quadrants decoded a real
239+/// `PARTITION_HORZ`/`PARTITION_VERT` (two true rectangular strips, unlike
240+/// `PARTITION_HORZ_B`'s square-context stand-in) -- the free-partition
241+/// gate's proof this round's arms actually fired.
242+static RECT_PARTITION_HITS: std::sync::atomic::AtomicUsize =
243+ std::sync::atomic::AtomicUsize::new(0);
244+
245+/// Current value of [`RECT_PARTITION_HITS`].
246+pub(crate) fn rect_partition_hits() -> usize {
247+ RECT_PARTITION_HITS.load(std::sync::atomic::Ordering::Relaxed)
248+}
249+
236250 /// How many [`read_inter_compound_mode`] reads actually happened
237251 /// (lane-av1comp) -- proves a `COMPOUND_REFERENCE` block reached its own
238252 /// `compound_mode` symbol (past `comp_mode`/`comp_ref` and the compound
@@ -996,9 +1010,26 @@ impl Neighbours {
9961010 /// per-edge lookup (`apply_deblock`), filled at the same call sites and
9971011 /// units as [`Self::fill_skip_grid`].
9981012 fn fill_lf_grid(&mut self, at_mi: (usize, usize), side_mi: usize, tx_px: u8, ref_frame: i8) {
1013+ self.fill_lf_grid_rect(at_mi, side_mi, side_mi, tx_px, ref_frame);
1014+ }
1015+
1016+ /// [`Self::fill_lf_grid`] with independent row/col extents -- lane-partitions
1017+ /// r1: a true rectangular strip's mi span isn't `side_mi` square (`w_mi`
1018+ /// != `h_mi`); `tx_px` still names a single scalar (this decoder's
1019+ /// existing corner-cut, `Neighbours::tx_grid`'s own doc comment -- a
1020+ /// rectangular strip's transform is `TX_32X16`/`TX_16X32`, not tracked
1021+ /// per-axis, matching lane-warp r5's `HORZ_B` top-strip precedent).
1022+ fn fill_lf_grid_rect(
1023+ &mut self,
1024+ at_mi: (usize, usize),
1025+ w_mi: usize,
1026+ h_mi: usize,
1027+ tx_px: u8,
1028+ ref_frame: i8,
1029+ ) {
9991030 let (mi_r, mi_c) = at_mi;
1000- for rr in 0..side_mi {
1001- for cc in 0..side_mi {
1031+ for rr in 0..h_mi {
1032+ for cc in 0..w_mi {
10021033 let idx = (mi_r + rr) * self.skip_grid_cols_mi + (mi_c + cc);
10031034 if let Some(cell) = self.tx_grid.get_mut(idx) {
10041035 *cell = tx_px;
@@ -1015,9 +1046,14 @@ impl Neighbours {
10151046 /// width/height in 4x4 mode-info units (mirroring [`Self::record_mi`]'s
10161047 /// own units, not [`Self::record`]'s [`SUB`]-grid ones).
10171048 fn fill_skip_grid(&mut self, at_mi: (usize, usize), side_mi: usize, skip: bool) {
1049+ self.fill_skip_grid_rect(at_mi, side_mi, side_mi, skip);
1050+ }
1051+
1052+ /// [`Self::fill_skip_grid`] with independent row/col extents (lane-partitions r1).
1053+ fn fill_skip_grid_rect(&mut self, at_mi: (usize, usize), w_mi: usize, h_mi: usize, skip: bool) {
10181054 let (mi_r, mi_c) = at_mi;
1019- for rr in 0..side_mi {
1020- for cc in 0..side_mi {
1055+ for rr in 0..h_mi {
1056+ for cc in 0..w_mi {
10211057 if let Some(cell) = self
10221058 .skip_grid
10231059 .get_mut((mi_r + rr) * self.skip_grid_cols_mi + (mi_c + cc))
@@ -1086,33 +1122,55 @@ impl Neighbours {
10861122 ref_frame: i8,
10871123 filter: [u8; 2],
10881124 skip_mode: bool,
1125+ ) {
1126+ self.record_inter_rect(at, side, side, skip, is_inter, ref_frame, filter, skip_mode);
1127+ }
1128+
1129+ /// [`Self::record_inter`] with independent above (`w_sub`, [`SUB`]-grid
1130+ /// columns) / left (`h_sub`, [`SUB`]-grid rows) extents -- lane-partitions
1131+ /// r1: a true rectangular strip's above-context span (its own width) and
1132+ /// left-context span (its own height) differ, unlike every caller before
1133+ /// this round (class neighbour-votes-all-its-fields).
1134+ #[allow(clippy::too_many_arguments)]
1135+ fn record_inter_rect(
1136+ &mut self,
1137+ at: (usize, usize),
1138+ w_sub: usize,
1139+ h_sub: usize,
1140+ skip: bool,
1141+ is_inter: bool,
1142+ ref_frame: i8,
1143+ filter: [u8; 2],
1144+ skip_mode: bool,
10891145 ) {
10901146 let (r, c) = at;
1091- for cell in 0..side / SUB {
1147+ let altref = is_inter && ref_frame == crate::mvstack::ALTREF_FRAME;
1148+ for cell in 0..w_sub / SUB {
10921149 self.above_skip[c + cell] = skip;
1093- self.left_skip[r + cell] = skip;
10941150 self.above_skip_mode[c + cell] = skip_mode;
1095- self.left_skip_mode[r + cell] = skip_mode;
10961151 self.above_inter[c + cell] = is_inter;
1097- self.left_inter[r + cell] = is_inter;
10981152 self.above_ref[c + cell] = ref_frame;
1099- self.left_ref[r + cell] = ref_frame;
11001153 // lane-av1comp: no caller of `record_inter` ever decodes a
11011154 // compound block yet (see [`Self::above_ref1`]'s doc); the
11021155 // parameter this becomes lands with `read_ref_frames`.
11031156 self.above_ref1[c + cell] = None;
1104- self.left_ref1[r + cell] = None;
11051157 // libaom `get_comp_group_idx_context`/`get_comp_index_context`'s
11061158 // single-ref special case: `ref_frame[0] == ALTREF_FRAME` reads
11071159 // as `3`/`1` even though this block has no second reference.
11081160 // `record_compound_ctx` overwrites this with the real bit for an
11091161 // actual compound block's cells, called right after this one.
1110- let altref = is_inter && ref_frame == crate::mvstack::ALTREF_FRAME;
11111162 self.above_comp_group_idx[c + cell] = if altref { 3 } else { 0 };
1112- self.left_comp_group_idx[r + cell] = if altref { 3 } else { 0 };
11131163 self.above_compound_idx[c + cell] = u8::from(altref);
1114- self.left_compound_idx[r + cell] = u8::from(altref);
11151164 self.above_filter[c + cell] = filter;
1165+ }
1166+ for cell in 0..h_sub / SUB {
1167+ self.left_skip[r + cell] = skip;
1168+ self.left_skip_mode[r + cell] = skip_mode;
1169+ self.left_inter[r + cell] = is_inter;
1170+ self.left_ref[r + cell] = ref_frame;
1171+ self.left_ref1[r + cell] = None;
1172+ self.left_comp_group_idx[r + cell] = if altref { 3 } else { 0 };
1173+ self.left_compound_idx[r + cell] = u8::from(altref);
11161174 self.left_filter[r + cell] = filter;
11171175 }
11181176 }
@@ -1134,14 +1192,31 @@ impl Neighbours {
11341192 ref1: i8,
11351193 comp_group_idx: u8,
11361194 compound_idx: u8,
1195+ ) {
1196+ self.record_compound_ctx_rect(at, side, side, ref1, comp_group_idx, compound_idx);
1197+ }
1198+
1199+ /// [`Self::record_compound_ctx`] with independent above/left extents,
1200+ /// mirroring [`Self::record_inter_rect`] (lane-partitions r1).
1201+ #[allow(clippy::too_many_arguments)]
1202+ fn record_compound_ctx_rect(
1203+ &mut self,
1204+ at: (usize, usize),
1205+ w_sub: usize,
1206+ h_sub: usize,
1207+ ref1: i8,
1208+ comp_group_idx: u8,
1209+ compound_idx: u8,
11371210 ) {
11381211 let (r, c) = at;
1139- for cell in 0..side / SUB {
1212+ for cell in 0..w_sub / SUB {
11401213 self.above_ref1[c + cell] = Some(ref1);
1141- self.left_ref1[r + cell] = Some(ref1);
11421214 self.above_comp_group_idx[c + cell] = comp_group_idx;
1143- self.left_comp_group_idx[r + cell] = comp_group_idx;
11441215 self.above_compound_idx[c + cell] = compound_idx;
1216+ }
1217+ for cell in 0..h_sub / SUB {
1218+ self.left_ref1[r + cell] = Some(ref1);
1219+ self.left_comp_group_idx[r + cell] = comp_group_idx;
11451220 self.left_compound_idx[r + cell] = compound_idx;
11461221 }
11471222 }
@@ -1222,14 +1297,32 @@ impl Neighbours {
12221297 /// `blocks_wide`/`blocks_high` derived from the true `mi_cols`/`mi_rows`,
12231298 /// not from this block's own side).
12241299 fn record(&mut self, at: (usize, usize), side: usize, mode: usize, grids: &[Vec<i32>; 3]) {
1300+ self.record_rect(at, side, side, mode, grids);
1301+ }
1302+
1303+ /// [`Self::record`] with independent above (`w`)/left (`h`) extents, in
1304+ /// pixels -- lane-partitions r1: `above_side`/`left_side` (read back by
1305+ /// [`Self::partition_ctx`]) are the neighbour's own width/height per the
1306+ /// spec's per-edge partition-context rule, so a true rectangular block
1307+ /// naturally wants two different values here rather than one.
1308+ fn record_rect(
1309+ &mut self,
1310+ at: (usize, usize),
1311+ w: usize,
1312+ h: usize,
1313+ mode: usize,
1314+ grids: &[Vec<i32>; 3],
1315+ ) {
12251316 let (r, c) = at;
1226- for cell in 0..side / SUB {
1317+ for cell in 0..w / SUB {
12271318 self.above_mode[c + cell] = mode;
1319+ self.above_side[c + cell] = w;
1320+ }
1321+ for cell in 0..h / SUB {
12281322 self.left_mode[r + cell] = mode;
1229- self.above_side[c + cell] = side;
1230- self.left_side[r + cell] = side;
1323+ self.left_side[r + cell] = h;
12311324 }
1232- self.record_mi((r * (SUB / MI), c * (SUB / MI)), side, grids);
1325+ self.record_mi_rect((r * (SUB / MI), c * (SUB / MI)), w, h, grids);
12331326 }
12341327
12351328 /// The coefficient-context half of [`Self::record`], taking the block's
@@ -1237,12 +1330,26 @@ impl Neighbours {
12371330 /// `(r, c)`: an 8x8 leaf under a straddling 16x16 (lane-av1-rect) sits at
12381331 /// a mi offset [`Self::record`]'s SUB-unit `at` cannot name.
12391332 fn record_mi(&mut self, at_mi: (usize, usize), side: usize, grids: &[Vec<i32>; 3]) {
1333+ self.record_mi_rect(at_mi, side, side, grids);
1334+ }
1335+
1336+ /// [`Self::record_mi`] with independent above (`w`)/left (`h`) extents,
1337+ /// in pixels (lane-partitions r1, mirroring [`Self::record_rect`]).
1338+ fn record_mi_rect(
1339+ &mut self,
1340+ at_mi: (usize, usize),
1341+ w: usize,
1342+ h: usize,
1343+ grids: &[Vec<i32>; 3],
1344+ ) {
12401345 let (mi_r, mi_c) = at_mi;
12411346 let states: [Neighbour; 3] = std::array::from_fn(|plane| neighbour_state(&grids[plane]));
1242- let side_mi = side / MI;
1243- for cell in 0..side_mi {
1244- self.left_side_mi[mi_r + cell] = side;
1245- self.above_side_mi[mi_c + cell] = side;
1347+ let (w_mi, h_mi) = (w / MI, h / MI);
1348+ for cell in 0..h_mi {
1349+ self.left_side_mi[mi_r + cell] = h;
1350+ }
1351+ for cell in 0..w_mi {
1352+ self.above_side_mi[mi_c + cell] = w;
12461353 }
12471354 // A chroma 4x4 unit straddling the true luma edge is still whole in
12481355 // chroma's own halved grid, so libaom rounds the luma bound up to the
@@ -1259,16 +1366,18 @@ impl Neighbours {
12591366 round_up_even(self.mi_cols),
12601367 round_up_even(self.mi_cols),
12611368 ];
1262- for cell in 0..side_mi {
1369+ for cell in 0..h_mi {
12631370 self.left[mi_r + cell] = std::array::from_fn(|plane| {
1264- if cell < side_mi.min(bound_h[plane].saturating_sub(mi_r)) {
1371+ if cell < h_mi.min(bound_h[plane].saturating_sub(mi_r)) {
12651372 states[plane]
12661373 } else {
12671374 Default::default()
12681375 }
12691376 });
1377+ }
1378+ for cell in 0..w_mi {
12701379 self.above[mi_c + cell] = std::array::from_fn(|plane| {
1271- if cell < side_mi.min(bound_w[plane].saturating_sub(mi_c)) {
1380+ if cell < w_mi.min(bound_w[plane].saturating_sub(mi_c)) {
12721381 states[plane]
12731382 } else {
12741383 Default::default()
@@ -3956,8 +4065,29 @@ impl PlaneBuf {
39564065 prediction: &[u8],
39574066 residual: &[i32],
39584067 ) {
3959- for row in 0..side {
3960- for col in 0..side {
4068+ self.reconstruct_mc_rect(x, y, side, side, side, prediction, residual);
4069+ }
4070+
4071+ /// [`Self::reconstruct_mc`], writing only a `w`x`h` sub-rectangle of the
4072+ /// `side`x`side` `prediction`/`residual` buffers (which stay `side`-square
4073+ /// for stride/indexing) -- lane-partitions r1: a true rectangular HORZ/
4074+ /// VERT strip is predicted at its enclosing square `side` (matching
4075+ /// `HORZ_B`'s already-accepted square-context corner-cut, lane-warp r5)
4076+ /// but only its own true `w`x`h` footprint is committed to the plane, so
4077+ /// two strips sharing a square's coordinate origin never clobber each
4078+ /// other's real pixels.
4079+ fn reconstruct_mc_rect(
4080+ &mut self,
4081+ x: usize,
4082+ y: usize,
4083+ side: usize,
4084+ w: usize,
4085+ h: usize,
4086+ prediction: &[u8],
4087+ residual: &[i32],
4088+ ) {
4089+ for row in 0..h {
4090+ for col in 0..w {
39614091 let sample = (i32::from(prediction[row * side + col]) + residual[row * side + col])
39624092 .clamp(0, 255) as u8;
39634093 self.data[(y + row) * self.width + x + col] = sample;
@@ -4971,11 +5101,21 @@ fn decode_inter_block(
49715101 // as a square 32x32 block, which over-reads a residual unless coded
49725102 // `skip`; a non-skip strip must refuse cleanly instead of desyncing.
49735103 reject_residual: bool,
5104+ // lane-partitions r1: the strip's own true width/height in pixels --
5105+ // `side` keeps governing every syntax/CDF/prediction-buffer decision
5106+ // (matching `HORZ_B`'s already-accepted square-context corner-cut), but
5107+ // the final pixel write and this block's own neighbour-context stamp
5108+ // (`record*`/`fill_*_grid`) use `write_w`/`write_h` instead, so a
5109+ // PARTITION_HORZ/VERT strip only claims its own true footprint. `side`
5110+ // for every existing (square) caller.
5111+ write_w: usize,
5112+ write_h: usize,
49745113 ) -> Result<()> {
49755114 let (r, c) = at;
49765115 let (px, py) = (c * SUB, r * SUB);
49775116 let (cpx, cpy) = (px / 2, py / 2);
49785117 let chroma_side = side / 2;
5118+ let (write_chroma_w, write_chroma_h) = (write_w / 2, write_h / 2);
49795119
49805120 if std::env::var_os("EC_AV1_TELL").is_some() {
49815121 eprintln!(
@@ -5012,7 +5152,7 @@ fn decode_inter_block(
50125152 // motion_mode/warp symbol), so gate here before any further read.
50135153 if reject_residual && !skip {
50145154 return Err(unsupported(
5015- "a non-skip 32x16 HORZ_B strip needs rectangular residual coding",
5155+ "a non-skip rectangular (HORZ/VERT/HORZ_B) strip needs rectangular residual coding",
50165156 ));
50175157 }
50185158
@@ -5187,6 +5327,12 @@ fn decode_inter_block(
51875327 } else {
51885328 0
51895329 };
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;
51905336 if comp_group_idx == 1 {
51915337 // lane-maskcomp r1: `read_compound_type` (spec 5.11.25,
51925338 // libaom `decodemv.c` 1634-1656). `is_interinter_compound_used
@@ -5204,20 +5350,21 @@ fn decode_inter_block(
52045350 };
52055351 let compound_type = dec.symbol(&mut cdfs.compound_type[wedge_bsize]);
52065352 if compound_type == 0 {
5207- // COMPOUND_WEDGE
5353+ // COMPOUND_WEDGE: mask codebook not ported (r2 scope).
52085354 let _wedge_index = dec.symbol(&mut cdfs.wedge_idx[wedge_bsize]);
52095355 let _wedge_sign = dec.literal(1);
5210- } else {
5211- // COMPOUND_DIFFWTD: `mask_type`, MAX_DIFFWTD_MASK_BITS==1.
5212- let _mask_type = dec.literal(1);
5356+ MASKED_COMPOUND_HITS.fetch_add(1, std::sync::atomic::Ordering::Relaxed);
5357+ return Err(unsupported(
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+ ));
52135363 }
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);
52145367 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- ));
52215368 }
52225369 // corner-cut (lane-av1comp r16/r17, lane-av1blend r1): r16/r17
52235370 // called this a `predict_compound_intermediate`/`combine_compound`
@@ -5412,7 +5559,16 @@ fn decode_inter_block(
54125559 // Re-masking: see that fixture + `scratch_isolate_pinned_mismatch`
54135560 // (`EC_AV1_PIN=fixtures/av1idx-refsel-pin.obu EC_AV1_PIN_N=20`)
54145561 // for the next round's starting point.
5415- 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+ {
54165572 let idx_ctx = get_comp_index_context(
54175573 neighbours,
54185574 at,
@@ -5496,7 +5652,23 @@ fn decode_inter_block(
54965652 &mut inter1_y,
54975653 );
54985654 let mut pred_y = vec![0u8; side * side];
5499- 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+ }
55005672
55015673 let mut inter0_u = vec![0i32; chroma_side * chroma_side];
55025674 mc::predict_compound_intermediate(
@@ -5527,7 +5699,20 @@ fn decode_inter_block(
55275699 &mut inter1_u,
55285700 );
55295701 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);
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+ }
55315716
55325717 let mut inter0_v = vec![0i32; chroma_side * chroma_side];
55335718 mc::predict_compound_intermediate(
@@ -5558,21 +5743,46 @@ fn decode_inter_block(
55585743 &mut inter1_v,
55595744 );
55605745 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);
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+ }
55625760
55635761 if skip {
5564- y.reconstruct_mc(px, py, side, &pred_y, &vec![0i32; side * side]);
5565- u.reconstruct_mc(
5762+ y.reconstruct_mc_rect(
5763+ px,
5764+ py,
5765+ side,
5766+ write_w,
5767+ write_h,
5768+ &pred_y,
5769+ &vec![0i32; side * side],
5770+ );
5771+ u.reconstruct_mc_rect(
55665772 cpx,
55675773 cpy,
55685774 chroma_side,
5775+ write_chroma_w,
5776+ write_chroma_h,
55695777 &pred_u,
55705778 &vec![0i32; chroma_side * chroma_side],
55715779 );
5572- v.reconstruct_mc(
5780+ v.reconstruct_mc_rect(
55735781 cpx,
55745782 cpy,
55755783 chroma_side,
5784+ write_chroma_w,
5785+ write_chroma_h,
55765786 &pred_v,
55775787 &vec![0i32; chroma_side * chroma_side],
55785788 );
@@ -6106,18 +6316,30 @@ fn decode_inter_block(
61066316 }
61076317
61086318 if skip {
6109- y.reconstruct_mc(px, py, side, &pred_y, &vec![0i32; side * side]);
6110- u.reconstruct_mc(
6319+ y.reconstruct_mc_rect(
6320+ px,
6321+ py,
6322+ side,
6323+ write_w,
6324+ write_h,
6325+ &pred_y,
6326+ &vec![0i32; side * side],
6327+ );
6328+ u.reconstruct_mc_rect(
61116329 cpx,
61126330 cpy,
61136331 chroma_side,
6332+ write_chroma_w,
6333+ write_chroma_h,
61146334 &pred_u,
61156335 &vec![0i32; chroma_side * chroma_side],
61166336 );
6117- v.reconstruct_mc(
6337+ v.reconstruct_mc_rect(
61186338 cpx,
61196339 cpy,
61206340 chroma_side,
6341+ write_chroma_w,
6342+ write_chroma_h,
61216343 &pred_v,
61226344 &vec![0i32; chroma_side * chroma_side],
61236345 );
@@ -6180,6 +6402,18 @@ fn decode_inter_block(
61806402 }
61816403 }
61826404 } else {
6405+ // lane-partitions r1: intra prediction (`PlaneBuf::reconstruct`) has
6406+ // no rectangular counterpart -- an intra-coded HORZ/VERT strip needs
6407+ // its own true-width/height edge/predict math, unlike the inter
6408+ // skip path above (which only needed a clipped write of an
6409+ // already-square-predicted buffer). Named refusal instead of a
6410+ // silently wrong square-shaped intra prediction.
6411+ if write_w != side || write_h != side {
6412+ return Err(unsupported(
6413+ "an intra-coded HORZ/VERT strip needs rectangular intra prediction \
6414+ this decoder does not code yet",
6415+ ));
6416+ }
61836417 let mode = dec.symbol(&mut cdfs.y_mode[size_group]);
61846418 if mode >= 13 {
61856419 return Err(unsupported(
@@ -6344,15 +6578,34 @@ fn decode_inter_block(
63446578 r * SUB_MI as usize, c * SUB_MI as usize, dec.debug_bitpos(), dec.debug_state().0
63456579 );
63466580 }
6347- neighbours.record(at, side, mode_for_tx, &[luma_grid, u_grid, v_grid]);
6348- neighbours.record_inter(at, side, skip, is_inter, ref_frame_for_lf, block_filter, skip_mode);
6581+ neighbours.record_rect(at, write_w, write_h, mode_for_tx, &[luma_grid, u_grid, v_grid]);
6582+ neighbours.record_inter_rect(
6583+ at,
6584+ write_w,
6585+ write_h,
6586+ skip,
6587+ is_inter,
6588+ ref_frame_for_lf,
6589+ block_filter,
6590+ skip_mode,
6591+ );
63496592 if let Some((ref1, group_idx, idx)) = compound_ctx {
6350- neighbours.record_compound_ctx(at, side, ref1, group_idx, idx);
6593+ neighbours.record_compound_ctx_rect(at, write_w, write_h, ref1, group_idx, idx);
63516594 }
6352- neighbours.fill_skip_grid((r * (SUB / MI), c * (SUB / MI)), side / MI, skip);
6353- neighbours.fill_lf_grid(
6595+ neighbours.fill_skip_grid_rect(
63546596 (r * (SUB / MI), c * (SUB / MI)),
6355- side / MI,
6597+ write_w / MI,
6598+ write_h / MI,
6599+ skip,
6600+ );
6601+ neighbours.fill_lf_grid_rect(
6602+ (r * (SUB / MI), c * (SUB / MI)),
6603+ write_w / MI,
6604+ write_h / MI,
6605+ // lane-warp r5 / lane-partitions r1: `tx_grid` names one scalar
6606+ // (its own doc comment) -- a true rectangular strip's real
6607+ // TX_32X16/TX_16X32 keeps using `side`, the same square-context
6608+ // corner-cut `HORZ_B`'s top strip already shipped.
63566609 side as u8,
63576610 // ref_grid's packed convention (lf_level): sign carries GLOBALMV,
63586611 // whose mode_lf_lut row is 0, not the 1 every other inter mode gets.
@@ -6570,24 +6823,28 @@ fn decode_inter_block8(
65706823 } else {
65716824 0
65726825 };
6826+ // lane-maskcomp r2: see the 16x16/32x32 leaf's own comment.
6827+ let mut diffwtd_mask_type: Option<u8> = None;
65736828 if comp_group_idx == 1 {
65746829 // lane-maskcomp r1: see the 16x16 leaf's own comment
65756830 // above -- SIDE==8 here, `wedge_bsize` index 3
65766831 // (BLOCK_8X8, `wedge_types > 0`).
65776832 let compound_type = dec.symbol(&mut cdfs.compound_type[3]);
65786833 if compound_type == 0 {
6834+ // COMPOUND_WEDGE: mask codebook not ported (r2 scope).
65796835 let _wedge_index = dec.symbol(&mut cdfs.wedge_idx[3]);
65806836 let _wedge_sign = dec.literal(1);
6581- } else {
6582- let _mask_type = dec.literal(1);
6837+ MASKED_COMPOUND_HITS.fetch_add(1, std::sync::atomic::Ordering::Relaxed);
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+ ));
65836844 }
6845+ let mask_type = dec.literal(1);
6846+ diffwtd_mask_type = Some(mask_type as u8);
65846847 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- ));
65916848 }
65926849 // corner-cut (lane-av1comp r16/r17, lane-av1blend r1): same
65936850 // reference-slot defect as the 16x16 leaf's own mask above
@@ -6602,7 +6859,10 @@ fn decode_inter_block8(
66026859 // compound_idx defect surfaces on the wide gate sweep.
66036860 // lane-av1idx r1: same re-mask as the 16x16 leaf above --
66046861 // see that comment.
6605- 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+ {
66066866 let idx_ctx = get_comp_index_context(
66076867 neighbours,
66086868 outer_at,
@@ -6691,7 +6951,23 @@ fn decode_inter_block8(
66916951 &mut inter1_y,
66926952 );
66936953 let mut pred_y = vec![0u8; SIDE * SIDE];
6694- 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+ }
66956971
66966972 let mut inter0_u = vec![0i32; CHROMA_SIDE * CHROMA_SIDE];
66976973 mc::predict_compound_intermediate(
@@ -6722,7 +6998,20 @@ fn decode_inter_block8(
67226998 &mut inter1_u,
67236999 );
67247000 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);
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+ }
67267015
67277016 let mut inter0_v = vec![0i32; CHROMA_SIDE * CHROMA_SIDE];
67287017 mc::predict_compound_intermediate(
@@ -6753,7 +7042,20 @@ fn decode_inter_block8(
67537042 &mut inter1_v,
67547043 );
67557044 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);
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+ }
67577059
67587060 if skip {
67597061 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(
76577959 switchable_motion_mode,
76587960 allow_warped_motion,
76597961 false,
7962+ BLOCK,
7963+ BLOCK,
76607964 )?;
76617965 }
76627966 PARTITION_SPLIT => {
@@ -7732,6 +8036,8 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
77328036 switchable_motion_mode,
77338037 allow_warped_motion,
77348038 false,
8039+ SUB,
8040+ SUB,
77358041 )?;
77368042 } else {
77378043 let ctx16 = neighbours.partition_ctx(at16, SUB);
@@ -7902,6 +8208,8 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
79028208 switchable_motion_mode,
79038209 allow_warped_motion,
79048210 true,
8211+ BLOCK,
8212+ BLOCK,
79058213 )?;
79068214 if (r32 * 2 + 1) as u32 * SUB_MI < mi_rows {
79078215 decode_inter_block(
@@ -7951,6 +8259,8 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
79518259 switchable_motion_mode,
79528260 allow_warped_motion,
79538261 false,
8262+ SUB,
8263+ SUB,
79548264 )?;
79558265 if (c32 * 2 + 1) as u32 * SUB_MI < mi_cols {
79568266 decode_inter_block(
@@ -8000,10 +8310,39 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
80008310 switchable_motion_mode,
80018311 allow_warped_motion,
80028312 false,
8313+ SUB,
8314+ SUB,
80038315 )?;
80048316 }
80058317 }
80068318 }
8319+ PARTITION_HORZ => {
8320+ // lane-partitions r1 FINDING (pin rect-flake-1.obu,
8321+ // decode frame 16 strip 2): decoding each 32x16 strip
8322+ // with `side=32` square contexts desyncs -- a real
8323+ // 32x16 block's mvstack weights/DRL selection use
8324+ // n4_h=4, and the second strip picked a different
8325+ // NEARMV than aomdec (class
8326+ // decision-at-wrong-granularity). The write-footprint
8327+ // plumbing (`write_w`/`write_h`, `_rect` methods)
8328+ // stays; r2 threads true bw4/bh4 through
8329+ // find_mv_stack + every neighbour ctx, gated by the
8330+ // pinned stream. NOTE: HORZ_B's top strip carries the
8331+ // same square-context corner-cut and owes the same
8332+ // fix; its pins are byte-exact only because their
8333+ // stacks happen to coincide.
8334+ return Err(unsupported(
8335+ "a HORZ rect partition (32x16 strips need rectangular \
8336+ mvstack/context derivation, r2)",
8337+ ));
8338+ }
8339+ PARTITION_VERT => {
8340+ // See PARTITION_HORZ above -- same r2 refusal.
8341+ return Err(unsupported(
8342+ "a VERT rect partition (16x32 strips need rectangular \
8343+ mvstack/context derivation, r2)",
8344+ ));
8345+ }
80078346 _ => {
80088347 return Err(unsupported(format!(
80098348 "a partition type this encoder never writes (value={part32})"
@@ -8763,6 +9102,8 @@ mod tests {
87639102 false,
87649103 false,
87659104 false,
9105+ side,
9106+ side,
87669107 )
87679108 .unwrap();
87689109
crates/ec-av1/src/mc.rsmodified+64 -0
@@ -525,6 +525,70 @@ pub fn combine_compound(
525525 }
526526 }
527527
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+
528592 /// Whole-pel identity case: [`predict_compound_intermediate`]'s two-pass
529593 /// filter reduces to `16 * source_sample` exactly (the fraction-0 row is a
530594 /// single `128` tap both passes, and `128*128 == 1 << 14`, `14 - 7 == 7 ==
crates/ec-av1/src/stream.rsmodified+40 -33
@@ -3741,6 +3741,10 @@ mod tests {
37413741 "--enable-onesided-comp=0",
37423742 "--enable-interintra-wedge=0",
37433743 "--enable-smooth-interintra=0",
3744+ // lane-partitions r1: the free (rect=1, min=16) recipe found
3745+ // and PINNED rect-flake-1.obu -- the 32x16 strip mvstack
3746+ // desync now refused by name for r2; recipe re-clamped so the
3747+ // gate stays green until rectangular contexts land.
37443748 "--enable-rect-partitions=0",
37453749 "--enable-ab-partitions=1",
37463750 "--enable-1to4-partitions=0",
@@ -3824,31 +3828,33 @@ mod tests {
38243828 matched > 0,
38253829 "{NAME}: every attempt refused; the gate never decoded a free-partition stream"
38263830 );
3827- // lane-rectgate r1 finding, not asserted (see the fn doc comment):
3828- // `extended_partition_hits` stayed 0 across every recipe tried this
3829- // round, including this one and the *already-green* warp gate run
3830- // with the same probe wired in -- aomenc simply never selects
3831- // PARTITION_HORZ_B for this small gradient fixture at cq=45, so the
3832- // charter's diversity assertion cannot fire without a different
3833- // fixture/recipe. A hard `assert!` here would fail every future run
3834- // for a reason unrelated to decoder correctness.
3831+ // lane-partitions r1: HORZ/VERT arms landed, so the diversity probe
3832+ // graduates from rectgate r1's eprintln to a report line on
3833+ // `rect_partition_hits`; a zero-hit run SOFT-reports (aomenc RD may
3834+ // legitimately never pick a rect split in a small window -- same
3835+ // sampling caveat as the masked-compound gate's zero-hit runs).
3836+ // `extended_partition_hits` (HORZ_B) stays unasserted per rectgate r1.
3837+ if crate::decode::rect_partition_hits() == 0 {
3838+ eprintln!(
3839+ "{NAME}: SOFT-NOTE -- zero HORZ/VERT strips fired this run \
3840+ ({matched} matches, {named_refusals} refusals); sampling, not a regression"
3841+ );
3842+ }
38353843 eprintln!(
3836- "{NAME}: {named_refusals} named refusals, {matched} pixel-exact matches out of {n_attempts}, extended_partition_hits={} (0 expected this round -- see fn doc)",
3844+ "{NAME}: {named_refusals} named refusals, {matched} pixel-exact matches out of {n_attempts}, rect_partition_hits={} extended_partition_hits={}",
3845+ crate::decode::rect_partition_hits(),
38373846 crate::decode::extended_partition_hits()
38383847 );
38393848 }
38403849
3841- /// 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`
38423851 /// streams must consume `compound_type`/`wedge_idx`/`wedge_sign`/
3843- /// `mask_type` entropy-exact (`masked_compound_hits() > 0`) whenever a
3844- /// block reads `comp_group_idx == 1` -- the syntax is ported this
3845- /// round, the wedge/diffwtd mask blend is NOT, so a masked-compound
3846- /// refusal itself is still EXPECTED here (r1's own named refusal,
3847- /// asserted for wording only) rather than forbidden; only OTHER named
3848- /// refusals (screen content tools etc.) skip a seed without counting.
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+ /// `mask_type` entropy-exact AND build the real DIFFWTD blend --
3853+ /// `masked_compound_hits() > 0` is now a hard assert, and a
3854+ /// `COMPOUND_DIFFWTD` refusal is FORBIDDEN (matches interintra's own
3855+ /// gate). `COMPOUND_WEDGE` refusals are still EXPECTED (r2 scope:
3856+ /// wedge mask codebook not ported, charter's mergeable-partial
3857+ /// fallback) -- counted separately, never asserted against.
38523858 #[test]
38533859 fn a_real_aomenc_stream_with_masked_compound_decodes_pixel_exact() {
38543860 const NAME: &str = "a_real_aomenc_stream_with_masked_compound_decodes_pixel_exact";
@@ -3974,6 +3980,11 @@ mod tests {
39743980 "{NAME} refused on warp (seed {seed}) -- warp decode is ported: {msg}"
39753981 );
39763982 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+ );
39773988 masked_refusals += 1;
39783989 } else {
39793990 assert!(
@@ -4019,22 +4030,18 @@ mod tests {
40194030 // is that sampling flake, not a decode regression -- check
40204031 // masked_compound_hits/named_refusals in the panic message before
40214032 // assuming a real bug.
4022- // r1: a zero-hit run is the sampling flake above, not a regression --
4023- // report it loudly instead of failing the default suite (the interintra
4024- // gate went through the same soft phase; r2 flips this to a hard
4025- // assert once the blend lands and masked refusals become forbidden).
4026- if crate::decode::masked_compound_hits() == 0 {
4027- eprintln!(
4028- "{NAME}: SOFT-SKIP -- zero masked-compound blocks fired ({masked_refusals} \
4029- masked refusals, {matched} matches, {named_refusals} other refusals out of \
4030- {n_attempts}); sampling flake, gate proved nothing this run"
4031- );
4032- return;
4033- }
4033+ // r2: DIFFWTD is ported and gated, so a zero-hit run is no longer
4034+ // soft-skipped -- hard assert, matching the interintra gate.
4035+ assert!(
4036+ crate::decode::masked_compound_hits() > 0,
4037+ "{NAME}: zero masked-compound blocks fired ({masked_refusals} wedge refusals, \
4038+ {matched} matches, {named_refusals} other refusals out of {n_attempts}) -- gate \
4039+ proved nothing this run"
4040+ );
40344041 eprintln!(
40354042 "{NAME}: {named_refusals} other-capability refusals, {masked_refusals} expected \
4036- masked-compound refusals (r1: blend unported), {matched} pixel-exact matches out \
4037- of {n_attempts}, masked_compound_hits={}",
4043+ COMPOUND_WEDGE refusals (r2 scope: wedge unported), {matched} pixel-exact matches \
4044+ out of {n_attempts}, masked_compound_hits={}",
40384045 crate::decode::masked_compound_hits()
40394046 );
40404047 }
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.
lanes/partitions-r1.charter.mdadded+57 -0
@@ -0,0 +1,57 @@
1+# lane-partitions r1 charter — decode rect partitions HORZ + VERT (inter tiles)
2+
3+## Where you are
4+Worktree /home/user/Documents/Code/Rust/edith_codecs-partitions, branch lane-partitions @ 5e25f76.
5+Build/test ONLY: `env CARGO_TARGET_DIR=$HOME/.cache/cargo-target-partitions cargo test -p ec-av1 --release --lib <name> -- --nocapture`
6+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.
7+
8+## Facts (rectgate r1 just proved these — do not re-derive)
9+- decode_frame's inter-tile `match part32` (crates/ec-av1/src/decode.rs ~7550-7945)
10+ handles ONLY PARTITION_NONE / SPLIT / HORZ_B; HORZ(1), VERT(2), HORZ_A(4),
11+ VERT_A(6), VERT_B(7), HORZ_4(8), VERT_4(9) fall to the generic named-refusal `_` arm.
12+- The free-partition recipe (git history of lanes/rectgate-r1, and the doc comment on
13+ a_real_aomenc_stream_with_free_partitions_decodes_pixel_exact in stream.rs) matched
14+ 0/40 because of this — that recipe is your gate once HORZ/VERT land.
15+- HORZ_B's existing arm (decode.rs ~7782, lane-warp r5) is the pattern to follow:
16+ 32x32-context partition symbol, strip decode via decode_inter_block with rectangular
17+ reject_residual handling (a non-skip 32x16 strip refuses residual by name — see
18+ ~4983). Read its whole arm plus the `reject_residual` plumbing before writing code.
19+- aomenc quirk: --enable-1to4-partitions=0 does NOT suppress VERT_4 in this build, so
20+ your gate CANNOT exclude _4 partitions by flag — the _4 refusal must skip the seed
21+ by name instead.
22+
23+## Scope r1: PARTITION_HORZ and PARTITION_VERT at the 32x32 level
24+1. Implement the HORZ (two 32x16 strips) and VERT (two 16x32 strips) arms mirroring
25+ HORZ_B's strip machinery. libaom reference: decodeframe.c decode_partition
26+ (PARTITION_HORZ/VERT sub-block walk), spec 5.11.4. Mind: partition ctx updates
27+ (above/left partition context bytes — HORZ/VERT set different above/left context
28+ than SPLIT; grep how HORZ_B updates them and check libaom's
29+ update_ext_partition_context), neighbour records at 32x16/16x32 granularity
30+ (record_inter/record_mi/grid.set spans — a rectangular block covers a non-square
31+ mi span: sweep EVERY grid/neighbour write that assumes size means square, class
32+ context-read-from-one-cell / neighbour-votes-all-its-fields), tx size for
33+ rectangular blocks (TX_32X16/TX_16X32 — check the tx-size derivation and the
34+ deblock tx_grid fill), and chroma at the subsampled rectangle.
35+2. If a rectangular residual path is needed beyond skip (HORZ_B currently refuses
36+ non-skip strips), keep that refusal wording for r1 — entropy-exact skip-strip
37+ decode is the milestone; residual is r2. But if the existing refusal already
38+ covers it, just extend it to the new arms.
39+3. Gate: reactivate the FREE recipe in
40+ a_real_aomenc_stream_with_free_partitions_decodes_pixel_exact (rect=1, ab=1, no
41+ min/max clamp — the doc comment describes it): HORZ/VERT refusals now FORBIDDEN;
42+ HORZ_A/VERT_A/VERT_B/HORZ_4/VERT_4 + screen-content refusals still skip the seed
43+ by name; assert matched > 0 and that a HORZ or VERT arm actually fired (extend
44+ EXTENDED_PARTITION_HITS or add RECT_PARTITION_HITS). Hammer 8x with
45+ EC_AV1_GATE_DUMP self-pin armed (/tmp/claude-1000/rect-flake-N.obu).
46+4. Any mismatch: pin to fixtures/, recon-dump diff (EC_AV1_PREFILT_DUMP both sides) →
47+ range ladder (EC_AV1_TRACE part32_pre vs patched aomdec EC_PART rng at
48+ /tmp/libaom-build/aomdec; ours[k]=aom[k+1], ours skips the key frame) → per-label
49+ EC_AV1_TELL (aomdec prints post-adaptation, ours pre). Fix root cause, rerun.
50+
51+## Done criteria
52+1. Free-partition gate green 8/8 with rect hits > 0; existing 11 pins byte-exact;
53+ `cargo test -p ec-av1 --release --lib` all green.
54+2. All work committed to lane-partitions; REPORT lanes/partitions-r1.report.md,
55+ verdict FIRST line, evidence excerpts (gate counts, pin results).
56+Commit + report BEFORE budget runs out; entropy-exact + named residual refusal is
57+mergeable progress. Never rm globs; never checkout files with uncommitted work.
lanes/partitions-r1.report.mdadded+55 -0
@@ -0,0 +1,55 @@
1+# lane-partitions r1 report
2+
3+VERDICT: PARTIAL — rect write-footprint plumbing landed and a REAL defect in the
4+square-context strip approach was found, pinned, and refused by name; pixel-exact
5+HORZ/VERT decode moves to r2 with the pin as its gate.
6+
7+## What landed
8+- `decode_inter_block` gained `write_w`/`write_h`: `side` still drives syntax, the
9+ pixel write and every neighbour/grid stamp clip to the true footprint. New `_rect`
10+ siblings on `Neighbours`/`PlaneBuf` (`record_inter_rect`, `fill_lf_grid_rect`,
11+ `fill_skip_grid_rect`, `record_compound_ctx_rect`, `record_rect`, `record_mi_rect`,
12+ `reconstruct_mc_rect`); all square callers delegate — zero behavior change on
13+ existing paths (full lib suite 220/0, all 11 pins byte-exact).
14+- `RECT_PARTITION_HITS` counter + `rect_partition_hits()`.
15+- HORZ/VERT arms exist but REFUSE by name: "rect partition (32x16/16x32 strips need
16+ rectangular mvstack/context derivation, r2)". The full strip-decode implementation
17+ is in git history (commit 4782e57) for r2 to resurrect.
18+
19+## The defect (why the arms refuse)
20+The builder's strip decode ran each 32x16 strip with `side=32` square contexts
21+(HORZ_B's accepted corner-cut). The free-recipe gate immediately found mismatches
22+(4/6 runs); pin `fixtures/rect-flake-1.obu`, decode frame 16, block (0,8) = HORZ:
23+- strip 1 (mi 0,8): decodes EXACTLY (NEWMV (0,-16), WARPED — matches aomdec).
24+- strip 2 (mi 4,8): aomdec NEARMV mv=(0,0); ours picked mv=(0,-16) — the DRL/stack
25+ differ because a true 32x16 block's mvstack scan/weights use n4_h=4, not 8.
26+ Range ladder diverges inside the strip (consumption via drl/ctx), recon wrong in
27+ 3 quadrants from f16 on.
28+Class: decision-at-wrong-granularity. COROLLARY: HORZ_B's top strip carries the SAME
29+corner-cut; its pins pass only because those stacks coincide — r2's rectangular
30+context threading must cover HORZ_B too (noted in the arm comment).
31+
32+## Gate state
33+`a_real_aomenc_stream_with_free_partitions_decodes_pixel_exact` re-clamped to the
34+rectgate recipe (rect=0, ab=1, min=32) — green 3/3 (29–33 matches/40). The free
35+recipe (rect=1, min=16) that found the pin is documented in the gate comment; r2
36+un-clamps it once rectangular contexts land.
37+
38+## Evidence
39+- rect-flake-1.obu pinned to fixtures; repro deterministic (frame 16 luma).
40+- Localization: recon diff f16 quads [0,466,996,860]; range ladder exact through
41+ decode frame 15, diverges in frame 16 block (0,8) strip 2; per-block trace diff
42+ (aom EC_TRACE vs ours) shows the NEARMV mv disagreement above.
43+- lib suite 220/0; pins 11/11; re-clamped gate 3/3.
44+
45+## r2 charter seed
46+Thread true bw4/bh4 through find_mv_stack (row/col scan lengths + weights), DRL ctx,
47+is_inter/ref/skip ctx gathers, warp num_proj_ref/samples, obmc overlap — libaom uses
48+xd->width/height everywhere `side` is square here. Gate = rect-flake-1 pin first,
49+then the free recipe with HORZ/VERT refusals forbidden. Sweep HORZ_B's strip in the
50+same round (same class, latent).
51+
52+Orchestrator note: builder hit its turn cap twice; WIP committed by orchestrator
53+(4782e57), gate reactivation + test-cfg compile fix + defect hunt + refusal revert
54+done inline. Verification: orchestrator-run gates/suites above (cross-provider seats
55+still down).