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};
41 use crate::transform::{TxType, dequant_and_inverse_typed};41 use crate::transform::{TxType, dequant_and_inverse_typed};
42 42
43 const PARTITION_NONE: usize = 0;43 const PARTITION_NONE: usize = 0;
44+const PARTITION_HORZ: usize = 1;
45+const PARTITION_VERT: usize = 2;
44 const PARTITION_SPLIT: usize = 3;46 const PARTITION_SPLIT: usize = 3;
45 const PARTITION_HORZ_B: usize = 5;47 const PARTITION_HORZ_B: usize = 5;
46 const SB_MI: u32 = 16;48 const SB_MI: u32 = 16;
@@ -233,6 +235,18 @@ pub(crate) fn extended_partition_hits() -> usize {
233 EXTENDED_PARTITION_HITS.load(std::sync::atomic::Ordering::Relaxed)235 EXTENDED_PARTITION_HITS.load(std::sync::atomic::Ordering::Relaxed)
234 }236 }
235 237
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+
236 /// How many [`read_inter_compound_mode`] reads actually happened250 /// How many [`read_inter_compound_mode`] reads actually happened
237 /// (lane-av1comp) -- proves a `COMPOUND_REFERENCE` block reached its own251 /// (lane-av1comp) -- proves a `COMPOUND_REFERENCE` block reached its own
238 /// `compound_mode` symbol (past `comp_mode`/`comp_ref` and the compound252 /// `compound_mode` symbol (past `comp_mode`/`comp_ref` and the compound
@@ -996,9 +1010,26 @@ impl Neighbours {
996 /// per-edge lookup (`apply_deblock`), filled at the same call sites and1010 /// per-edge lookup (`apply_deblock`), filled at the same call sites and
997 /// units as [`Self::fill_skip_grid`].1011 /// units as [`Self::fill_skip_grid`].
998 fn fill_lf_grid(&mut self, at_mi: (usize, usize), side_mi: usize, tx_px: u8, ref_frame: i8) {1012 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+ ) {
999 let (mi_r, mi_c) = at_mi;1030 let (mi_r, mi_c) = at_mi;
1000- for rr in 0..side_mi {1031+ for rr in 0..h_mi {
1001- for cc in 0..side_mi {1032+ for cc in 0..w_mi {
1002 let idx = (mi_r + rr) * self.skip_grid_cols_mi + (mi_c + cc);1033 let idx = (mi_r + rr) * self.skip_grid_cols_mi + (mi_c + cc);
1003 if let Some(cell) = self.tx_grid.get_mut(idx) {1034 if let Some(cell) = self.tx_grid.get_mut(idx) {
1004 *cell = tx_px;1035 *cell = tx_px;
@@ -1015,9 +1046,14 @@ impl Neighbours {
1015 /// width/height in 4x4 mode-info units (mirroring [`Self::record_mi`]'s1046 /// width/height in 4x4 mode-info units (mirroring [`Self::record_mi`]'s
1016 /// own units, not [`Self::record`]'s [`SUB`]-grid ones).1047 /// own units, not [`Self::record`]'s [`SUB`]-grid ones).
1017 fn fill_skip_grid(&mut self, at_mi: (usize, usize), side_mi: usize, skip: bool) {1048 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) {
1018 let (mi_r, mi_c) = at_mi;1054 let (mi_r, mi_c) = at_mi;
1019- for rr in 0..side_mi {1055+ for rr in 0..h_mi {
1020- for cc in 0..side_mi {1056+ for cc in 0..w_mi {
1021 if let Some(cell) = self1057 if let Some(cell) = self
1022 .skip_grid1058 .skip_grid
1023 .get_mut((mi_r + rr) * self.skip_grid_cols_mi + (mi_c + cc))1059 .get_mut((mi_r + rr) * self.skip_grid_cols_mi + (mi_c + cc))
@@ -1086,33 +1122,55 @@ impl Neighbours {
1086 ref_frame: i8,1122 ref_frame: i8,
1087 filter: [u8; 2],1123 filter: [u8; 2],
1088 skip_mode: bool,1124 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,
1089 ) {1145 ) {
1090 let (r, c) = at;1146 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 {
1092 self.above_skip[c + cell] = skip;1149 self.above_skip[c + cell] = skip;
1093- self.left_skip[r + cell] = skip;
1094 self.above_skip_mode[c + cell] = skip_mode;1150 self.above_skip_mode[c + cell] = skip_mode;
1095- self.left_skip_mode[r + cell] = skip_mode;
1096 self.above_inter[c + cell] = is_inter;1151 self.above_inter[c + cell] = is_inter;
1097- self.left_inter[r + cell] = is_inter;
1098 self.above_ref[c + cell] = ref_frame;1152 self.above_ref[c + cell] = ref_frame;
1099- self.left_ref[r + cell] = ref_frame;
1100 // lane-av1comp: no caller of `record_inter` ever decodes a1153 // lane-av1comp: no caller of `record_inter` ever decodes a
1101 // compound block yet (see [`Self::above_ref1`]'s doc); the1154 // compound block yet (see [`Self::above_ref1`]'s doc); the
1102 // parameter this becomes lands with `read_ref_frames`.1155 // parameter this becomes lands with `read_ref_frames`.
1103 self.above_ref1[c + cell] = None;1156 self.above_ref1[c + cell] = None;
1104- self.left_ref1[r + cell] = None;
1105 // libaom `get_comp_group_idx_context`/`get_comp_index_context`'s1157 // libaom `get_comp_group_idx_context`/`get_comp_index_context`'s
1106 // single-ref special case: `ref_frame[0] == ALTREF_FRAME` reads1158 // single-ref special case: `ref_frame[0] == ALTREF_FRAME` reads
1107 // as `3`/`1` even though this block has no second reference.1159 // as `3`/`1` even though this block has no second reference.
1108 // `record_compound_ctx` overwrites this with the real bit for an1160 // `record_compound_ctx` overwrites this with the real bit for an
1109 // actual compound block's cells, called right after this one.1161 // actual compound block's cells, called right after this one.
1110- let altref = is_inter && ref_frame == crate::mvstack::ALTREF_FRAME;
1111 self.above_comp_group_idx[c + cell] = if altref { 3 } else { 0 };1162 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 };
1113 self.above_compound_idx[c + cell] = u8::from(altref);1163 self.above_compound_idx[c + cell] = u8::from(altref);
1114- self.left_compound_idx[r + cell] = u8::from(altref);
1115 self.above_filter[c + cell] = filter;1164 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);
1116 self.left_filter[r + cell] = filter;1174 self.left_filter[r + cell] = filter;
1117 }1175 }
1118 }1176 }
@@ -1134,14 +1192,31 @@ impl Neighbours {
1134 ref1: i8,1192 ref1: i8,
1135 comp_group_idx: u8,1193 comp_group_idx: u8,
1136 compound_idx: u8,1194 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,
1137 ) {1210 ) {
1138 let (r, c) = at;1211 let (r, c) = at;
1139- for cell in 0..side / SUB {1212+ for cell in 0..w_sub / SUB {
1140 self.above_ref1[c + cell] = Some(ref1);1213 self.above_ref1[c + cell] = Some(ref1);
1141- self.left_ref1[r + cell] = Some(ref1);
1142 self.above_comp_group_idx[c + cell] = comp_group_idx;1214 self.above_comp_group_idx[c + cell] = comp_group_idx;
1143- self.left_comp_group_idx[r + cell] = comp_group_idx;
1144 self.above_compound_idx[c + cell] = compound_idx;1215 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;
1145 self.left_compound_idx[r + cell] = compound_idx;1220 self.left_compound_idx[r + cell] = compound_idx;
1146 }1221 }
1147 }1222 }
@@ -1222,14 +1297,32 @@ impl Neighbours {
1222 /// `blocks_wide`/`blocks_high` derived from the true `mi_cols`/`mi_rows`,1297 /// `blocks_wide`/`blocks_high` derived from the true `mi_cols`/`mi_rows`,
1223 /// not from this block's own side).1298 /// not from this block's own side).
1224 fn record(&mut self, at: (usize, usize), side: usize, mode: usize, grids: &[Vec<i32>; 3]) {1299 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+ ) {
1225 let (r, c) = at;1316 let (r, c) = at;
1226- for cell in 0..side / SUB {1317+ for cell in 0..w / SUB {
1227 self.above_mode[c + cell] = mode;1318 self.above_mode[c + cell] = mode;
1319+ self.above_side[c + cell] = w;
1320+ }
1321+ for cell in 0..h / SUB {
1228 self.left_mode[r + cell] = mode;1322 self.left_mode[r + cell] = mode;
1229- self.above_side[c + cell] = side;1323+ self.left_side[r + cell] = h;
1230- self.left_side[r + cell] = side;
1231 }1324 }
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);
1233 }1326 }
1234 1327
1235 /// The coefficient-context half of [`Self::record`], taking the block's1328 /// The coefficient-context half of [`Self::record`], taking the block's
@@ -1237,12 +1330,26 @@ impl Neighbours {
1237 /// `(r, c)`: an 8x8 leaf under a straddling 16x16 (lane-av1-rect) sits at1330 /// `(r, c)`: an 8x8 leaf under a straddling 16x16 (lane-av1-rect) sits at
1238 /// a mi offset [`Self::record`]'s SUB-unit `at` cannot name.1331 /// a mi offset [`Self::record`]'s SUB-unit `at` cannot name.
1239 fn record_mi(&mut self, at_mi: (usize, usize), side: usize, grids: &[Vec<i32>; 3]) {1332 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+ ) {
1240 let (mi_r, mi_c) = at_mi;1345 let (mi_r, mi_c) = at_mi;
1241 let states: [Neighbour; 3] = std::array::from_fn(|plane| neighbour_state(&grids[plane]));1346 let states: [Neighbour; 3] = std::array::from_fn(|plane| neighbour_state(&grids[plane]));
1242- let side_mi = side / MI;1347+ let (w_mi, h_mi) = (w / MI, h / MI);
1243- for cell in 0..side_mi {1348+ for cell in 0..h_mi {
1244- self.left_side_mi[mi_r + cell] = side;1349+ self.left_side_mi[mi_r + cell] = h;
1245- self.above_side_mi[mi_c + cell] = side;1350+ }
1351+ for cell in 0..w_mi {
1352+ self.above_side_mi[mi_c + cell] = w;
1246 }1353 }
1247 // A chroma 4x4 unit straddling the true luma edge is still whole in1354 // A chroma 4x4 unit straddling the true luma edge is still whole in
1248 // chroma's own halved grid, so libaom rounds the luma bound up to the1355 // chroma's own halved grid, so libaom rounds the luma bound up to the
@@ -1259,16 +1366,18 @@ impl Neighbours {
1259 round_up_even(self.mi_cols),1366 round_up_even(self.mi_cols),
1260 round_up_even(self.mi_cols),1367 round_up_even(self.mi_cols),
1261 ];1368 ];
1262- for cell in 0..side_mi {1369+ for cell in 0..h_mi {
1263 self.left[mi_r + cell] = std::array::from_fn(|plane| {1370 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)) {
1265 states[plane]1372 states[plane]
1266 } else {1373 } else {
1267 Default::default()1374 Default::default()
1268 }1375 }
1269 });1376 });
1377+ }
1378+ for cell in 0..w_mi {
1270 self.above[mi_c + cell] = std::array::from_fn(|plane| {1379 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)) {
1272 states[plane]1381 states[plane]
1273 } else {1382 } else {
1274 Default::default()1383 Default::default()
@@ -3956,8 +4065,29 @@ impl PlaneBuf {
3956 prediction: &[u8],4065 prediction: &[u8],
3957 residual: &[i32],4066 residual: &[i32],
3958 ) {4067 ) {
3959- for row in 0..side {4068+ self.reconstruct_mc_rect(x, y, side, side, side, prediction, residual);
3960- for col in 0..side {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 {
3961 let sample = (i32::from(prediction[row * side + col]) + residual[row * side + col])4091 let sample = (i32::from(prediction[row * side + col]) + residual[row * side + col])
3962 .clamp(0, 255) as u8;4092 .clamp(0, 255) as u8;
3963 self.data[(y + row) * self.width + x + col] = sample;4093 self.data[(y + row) * self.width + x + col] = sample;
@@ -4971,11 +5101,21 @@ fn decode_inter_block(
4971 // as a square 32x32 block, which over-reads a residual unless coded5101 // as a square 32x32 block, which over-reads a residual unless coded
4972 // `skip`; a non-skip strip must refuse cleanly instead of desyncing.5102 // `skip`; a non-skip strip must refuse cleanly instead of desyncing.
4973 reject_residual: bool,5103 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,
4974 ) -> Result<()> {5113 ) -> Result<()> {
4975 let (r, c) = at;5114 let (r, c) = at;
4976 let (px, py) = (c * SUB, r * SUB);5115 let (px, py) = (c * SUB, r * SUB);
4977 let (cpx, cpy) = (px / 2, py / 2);5116 let (cpx, cpy) = (px / 2, py / 2);
4978 let chroma_side = side / 2;5117 let chroma_side = side / 2;
5118+ let (write_chroma_w, write_chroma_h) = (write_w / 2, write_h / 2);
4979 5119
4980 if std::env::var_os("EC_AV1_TELL").is_some() {5120 if std::env::var_os("EC_AV1_TELL").is_some() {
4981 eprintln!(5121 eprintln!(
@@ -5012,7 +5152,7 @@ fn decode_inter_block(
5012 // motion_mode/warp symbol), so gate here before any further read.5152 // motion_mode/warp symbol), so gate here before any further read.
5013 if reject_residual && !skip {5153 if reject_residual && !skip {
5014 return Err(unsupported(5154 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",
5016 ));5156 ));
5017 }5157 }
5018 5158
@@ -5187,6 +5327,12 @@ fn decode_inter_block(
5187 } else {5327 } else {
5188 05328 0
5189 };5329 };
5330+ // lane-maskcomp r2: `Some(mask_type)` only for a real
5331+ // `COMPOUND_DIFFWTD` block (`comp_group_idx == 1`, `compound_type
5332+ // == 1`) -- wedge (`compound_type == 0`) still refuses by name,
5333+ // its mask codebook unported (charter's mergeable-partial
5334+ // fallback).
5335+ let mut diffwtd_mask_type: Option<u8> = None;
5190 if comp_group_idx == 1 {5336 if comp_group_idx == 1 {
5191 // lane-maskcomp r1: `read_compound_type` (spec 5.11.25,5337 // lane-maskcomp r1: `read_compound_type` (spec 5.11.25,
5192 // libaom `decodemv.c` 1634-1656). `is_interinter_compound_used5338 // libaom `decodemv.c` 1634-1656). `is_interinter_compound_used
@@ -5204,20 +5350,21 @@ fn decode_inter_block(
5204 };5350 };
5205 let compound_type = dec.symbol(&mut cdfs.compound_type[wedge_bsize]);5351 let compound_type = dec.symbol(&mut cdfs.compound_type[wedge_bsize]);
5206 if compound_type == 0 {5352 if compound_type == 0 {
5207- // COMPOUND_WEDGE5353+ // COMPOUND_WEDGE: mask codebook not ported (r2 scope).
5208 let _wedge_index = dec.symbol(&mut cdfs.wedge_idx[wedge_bsize]);5354 let _wedge_index = dec.symbol(&mut cdfs.wedge_idx[wedge_bsize]);
5209 let _wedge_sign = dec.literal(1);5355 let _wedge_sign = dec.literal(1);
5210- } else {5356+ MASKED_COMPOUND_HITS.fetch_add(1, std::sync::atomic::Ordering::Relaxed);
5211- // COMPOUND_DIFFWTD: `mask_type`, MAX_DIFFWTD_MASK_BITS==1.5357+ return Err(unsupported(
5212- let _mask_type = dec.literal(1);5358+ "a masked COMPOUND_REFERENCE block (comp_group_idx == 1, \
5359+ COMPOUND_WEDGE) -- syntax consumed entropy-exact (compound_type/\
5360+ wedge_idx/wedge_sign), but this decoder's wedge mask codebook is \
5361+ not ported (lane-maskcomp r2 scope: DIFFWTD only)",
5362+ ));
5213 }5363 }
5364+ // COMPOUND_DIFFWTD: `mask_type`, MAX_DIFFWTD_MASK_BITS==1.
5365+ let mask_type = dec.literal(1);
5366+ diffwtd_mask_type = Some(mask_type as u8);
5214 MASKED_COMPOUND_HITS.fetch_add(1, std::sync::atomic::Ordering::Relaxed);5367 MASKED_COMPOUND_HITS.fetch_add(1, std::sync::atomic::Ordering::Relaxed);
5215- return Err(unsupported(
5216- "a masked COMPOUND_REFERENCE block (comp_group_idx == 1, wedge/\
5217- diffwtd) -- syntax consumed entropy-exact (compound_type/wedge_idx/\
5218- wedge_sign/mask_type), but this decoder's compound blend does not yet \
5219- build the wedge/diffwtd mask, lane-maskcomp r1",
5220- ));
5221 }5368 }
5222 // corner-cut (lane-av1comp r16/r17, lane-av1blend r1): r16/r175369 // corner-cut (lane-av1comp r16/r17, lane-av1blend r1): r16/r17
5223 // called this a `predict_compound_intermediate`/`combine_compound`5370 // called this a `predict_compound_intermediate`/`combine_compound`
@@ -5412,7 +5559,16 @@ fn decode_inter_block(
5412 // Re-masking: see that fixture + `scratch_isolate_pinned_mismatch`5559 // Re-masking: see that fixture + `scratch_isolate_pinned_mismatch`
5413 // (`EC_AV1_PIN=fixtures/av1idx-refsel-pin.obu EC_AV1_PIN_N=20`)5560 // (`EC_AV1_PIN=fixtures/av1idx-refsel-pin.obu EC_AV1_PIN_N=20`)
5414 // for the next round's starting point.5561 // 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+ {
5416 let idx_ctx = get_comp_index_context(5572 let idx_ctx = get_comp_index_context(
5417 neighbours,5573 neighbours,
5418 at,5574 at,
@@ -5496,7 +5652,23 @@ fn decode_inter_block(
5496 &mut inter1_y,5652 &mut inter1_y,
5497 );5653 );
5498 let mut pred_y = vec![0u8; side * side];5654 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+ }
5500 5672
5501 let mut inter0_u = vec![0i32; chroma_side * chroma_side];5673 let mut inter0_u = vec![0i32; chroma_side * chroma_side];
5502 mc::predict_compound_intermediate(5674 mc::predict_compound_intermediate(
@@ -5527,7 +5699,20 @@ fn decode_inter_block(
5527 &mut inter1_u,5699 &mut inter1_u,
5528 );5700 );
5529 let mut pred_u = vec![0u8; chroma_side * chroma_side];5701 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+ }
5531 5716
5532 let mut inter0_v = vec![0i32; chroma_side * chroma_side];5717 let mut inter0_v = vec![0i32; chroma_side * chroma_side];
5533 mc::predict_compound_intermediate(5718 mc::predict_compound_intermediate(
@@ -5558,21 +5743,46 @@ fn decode_inter_block(
5558 &mut inter1_v,5743 &mut inter1_v,
5559 );5744 );
5560 let mut pred_v = vec![0u8; chroma_side * chroma_side];5745 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+ }
5562 5760
5563 if skip {5761 if skip {
5564- y.reconstruct_mc(px, py, side, &pred_y, &vec![0i32; side * side]);5762+ y.reconstruct_mc_rect(
5565- u.reconstruct_mc(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(
5566 cpx,5772 cpx,
5567 cpy,5773 cpy,
5568 chroma_side,5774 chroma_side,
5775+ write_chroma_w,
5776+ write_chroma_h,
5569 &pred_u,5777 &pred_u,
5570 &vec![0i32; chroma_side * chroma_side],5778 &vec![0i32; chroma_side * chroma_side],
5571 );5779 );
5572- v.reconstruct_mc(5780+ v.reconstruct_mc_rect(
5573 cpx,5781 cpx,
5574 cpy,5782 cpy,
5575 chroma_side,5783 chroma_side,
5784+ write_chroma_w,
5785+ write_chroma_h,
5576 &pred_v,5786 &pred_v,
5577 &vec![0i32; chroma_side * chroma_side],5787 &vec![0i32; chroma_side * chroma_side],
5578 );5788 );
@@ -6106,18 +6316,30 @@ fn decode_inter_block(
6106 }6316 }
6107 6317
6108 if skip {6318 if skip {
6109- y.reconstruct_mc(px, py, side, &pred_y, &vec![0i32; side * side]);6319+ y.reconstruct_mc_rect(
6110- u.reconstruct_mc(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(
6111 cpx,6329 cpx,
6112 cpy,6330 cpy,
6113 chroma_side,6331 chroma_side,
6332+ write_chroma_w,
6333+ write_chroma_h,
6114 &pred_u,6334 &pred_u,
6115 &vec![0i32; chroma_side * chroma_side],6335 &vec![0i32; chroma_side * chroma_side],
6116 );6336 );
6117- v.reconstruct_mc(6337+ v.reconstruct_mc_rect(
6118 cpx,6338 cpx,
6119 cpy,6339 cpy,
6120 chroma_side,6340 chroma_side,
6341+ write_chroma_w,
6342+ write_chroma_h,
6121 &pred_v,6343 &pred_v,
6122 &vec![0i32; chroma_side * chroma_side],6344 &vec![0i32; chroma_side * chroma_side],
6123 );6345 );
@@ -6180,6 +6402,18 @@ fn decode_inter_block(
6180 }6402 }
6181 }6403 }
6182 } else {6404 } 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+ }
6183 let mode = dec.symbol(&mut cdfs.y_mode[size_group]);6417 let mode = dec.symbol(&mut cdfs.y_mode[size_group]);
6184 if mode >= 13 {6418 if mode >= 13 {
6185 return Err(unsupported(6419 return Err(unsupported(
@@ -6344,15 +6578,34 @@ fn decode_inter_block(
6344 r * SUB_MI as usize, c * SUB_MI as usize, dec.debug_bitpos(), dec.debug_state().06578 r * SUB_MI as usize, c * SUB_MI as usize, dec.debug_bitpos(), dec.debug_state().0
6345 );6579 );
6346 }6580 }
6347- neighbours.record(at, side, mode_for_tx, &[luma_grid, u_grid, v_grid]);6581+ neighbours.record_rect(at, write_w, write_h, 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);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+ );
6349 if let Some((ref1, group_idx, idx)) = compound_ctx {6592 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);
6351 }6594 }
6352- neighbours.fill_skip_grid((r * (SUB / MI), c * (SUB / MI)), side / MI, skip);6595+ neighbours.fill_skip_grid_rect(
6353- neighbours.fill_lf_grid(
6354 (r * (SUB / MI), c * (SUB / MI)),6596 (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.
6356 side as u8,6609 side as u8,
6357 // ref_grid's packed convention (lf_level): sign carries GLOBALMV,6610 // ref_grid's packed convention (lf_level): sign carries GLOBALMV,
6358 // whose mode_lf_lut row is 0, not the 1 every other inter mode gets.6611 // whose mode_lf_lut row is 0, not the 1 every other inter mode gets.
@@ -6570,24 +6823,28 @@ fn decode_inter_block8(
6570 } else {6823 } else {
6571 06824 0
6572 };6825 };
6826+ // lane-maskcomp r2: see the 16x16/32x32 leaf's own comment.
6827+ let mut diffwtd_mask_type: Option<u8> = None;
6573 if comp_group_idx == 1 {6828 if comp_group_idx == 1 {
6574 // lane-maskcomp r1: see the 16x16 leaf's own comment6829 // lane-maskcomp r1: see the 16x16 leaf's own comment
6575 // above -- SIDE==8 here, `wedge_bsize` index 36830 // above -- SIDE==8 here, `wedge_bsize` index 3
6576 // (BLOCK_8X8, `wedge_types > 0`).6831 // (BLOCK_8X8, `wedge_types > 0`).
6577 let compound_type = dec.symbol(&mut cdfs.compound_type[3]);6832 let compound_type = dec.symbol(&mut cdfs.compound_type[3]);
6578 if compound_type == 0 {6833 if compound_type == 0 {
6834+ // COMPOUND_WEDGE: mask codebook not ported (r2 scope).
6579 let _wedge_index = dec.symbol(&mut cdfs.wedge_idx[3]);6835 let _wedge_index = dec.symbol(&mut cdfs.wedge_idx[3]);
6580 let _wedge_sign = dec.literal(1);6836 let _wedge_sign = dec.literal(1);
6581- } else {6837+ MASKED_COMPOUND_HITS.fetch_add(1, std::sync::atomic::Ordering::Relaxed);
6582- let _mask_type = dec.literal(1);6838+ return Err(unsupported(
6839+ "a masked COMPOUND_REFERENCE 8x8 leaf (comp_group_idx == 1, \
6840+ COMPOUND_WEDGE) -- syntax consumed entropy-exact (compound_type/\
6841+ wedge_idx/wedge_sign), but this decoder's wedge mask codebook is \
6842+ not ported (lane-maskcomp r2 scope: DIFFWTD only)",
6843+ ));
6583 }6844 }
6845+ let mask_type = dec.literal(1);
6846+ diffwtd_mask_type = Some(mask_type as u8);
6584 MASKED_COMPOUND_HITS.fetch_add(1, std::sync::atomic::Ordering::Relaxed);6847 MASKED_COMPOUND_HITS.fetch_add(1, std::sync::atomic::Ordering::Relaxed);
6585- return Err(unsupported(
6586- "a masked COMPOUND_REFERENCE 8x8 leaf (comp_group_idx == 1, wedge/\
6587- diffwtd) -- syntax consumed entropy-exact (compound_type/wedge_idx/\
6588- wedge_sign/mask_type), but this decoder's compound blend does not \
6589- yet build the wedge/diffwtd mask, lane-maskcomp r1",
6590- ));
6591 }6848 }
6592 // corner-cut (lane-av1comp r16/r17, lane-av1blend r1): same6849 // corner-cut (lane-av1comp r16/r17, lane-av1blend r1): same
6593 // reference-slot defect as the 16x16 leaf's own mask above6850 // reference-slot defect as the 16x16 leaf's own mask above
@@ -6602,7 +6859,10 @@ fn decode_inter_block8(
6602 // compound_idx defect surfaces on the wide gate sweep.6859 // compound_idx defect surfaces on the wide gate sweep.
6603 // lane-av1idx r1: same re-mask as the 16x16 leaf above --6860 // lane-av1idx r1: same re-mask as the 16x16 leaf above --
6604 // see that comment.6861 // 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+ {
6606 let idx_ctx = get_comp_index_context(6866 let idx_ctx = get_comp_index_context(
6607 neighbours,6867 neighbours,
6608 outer_at,6868 outer_at,
@@ -6691,7 +6951,23 @@ fn decode_inter_block8(
6691 &mut inter1_y,6951 &mut inter1_y,
6692 );6952 );
6693 let mut pred_y = vec![0u8; SIDE * SIDE];6953 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+ }
6695 6971
6696 let mut inter0_u = vec![0i32; CHROMA_SIDE * CHROMA_SIDE];6972 let mut inter0_u = vec![0i32; CHROMA_SIDE * CHROMA_SIDE];
6697 mc::predict_compound_intermediate(6973 mc::predict_compound_intermediate(
@@ -6722,7 +6998,20 @@ fn decode_inter_block8(
6722 &mut inter1_u,6998 &mut inter1_u,
6723 );6999 );
6724 let mut pred_u = vec![0u8; CHROMA_SIDE * CHROMA_SIDE];7000 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+ }
6726 7015
6727 let mut inter0_v = vec![0i32; CHROMA_SIDE * CHROMA_SIDE];7016 let mut inter0_v = vec![0i32; CHROMA_SIDE * CHROMA_SIDE];
6728 mc::predict_compound_intermediate(7017 mc::predict_compound_intermediate(
@@ -6753,7 +7042,20 @@ fn decode_inter_block8(
6753 &mut inter1_v,7042 &mut inter1_v,
6754 );7043 );
6755 let mut pred_v = vec![0u8; CHROMA_SIDE * CHROMA_SIDE];7044 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+ }
6757 7059
6758 if skip {7060 if skip {
6759 y.reconstruct_mc(px, py, SIDE, &pred_y, &vec![0i32; SIDE * SIDE]);7061 y.reconstruct_mc(px, py, SIDE, &pred_y, &vec![0i32; SIDE * SIDE]);
@@ -7657,6 +7959,8 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
7657 switchable_motion_mode,7959 switchable_motion_mode,
7658 allow_warped_motion,7960 allow_warped_motion,
7659 false,7961 false,
7962+ BLOCK,
7963+ BLOCK,
7660 )?;7964 )?;
7661 }7965 }
7662 PARTITION_SPLIT => {7966 PARTITION_SPLIT => {
@@ -7732,6 +8036,8 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
7732 switchable_motion_mode,8036 switchable_motion_mode,
7733 allow_warped_motion,8037 allow_warped_motion,
7734 false,8038 false,
8039+ SUB,
8040+ SUB,
7735 )?;8041 )?;
7736 } else {8042 } else {
7737 let ctx16 = neighbours.partition_ctx(at16, SUB);8043 let ctx16 = neighbours.partition_ctx(at16, SUB);
@@ -7902,6 +8208,8 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
7902 switchable_motion_mode,8208 switchable_motion_mode,
7903 allow_warped_motion,8209 allow_warped_motion,
7904 true,8210 true,
8211+ BLOCK,
8212+ BLOCK,
7905 )?;8213 )?;
7906 if (r32 * 2 + 1) as u32 * SUB_MI < mi_rows {8214 if (r32 * 2 + 1) as u32 * SUB_MI < mi_rows {
7907 decode_inter_block(8215 decode_inter_block(
@@ -7951,6 +8259,8 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
7951 switchable_motion_mode,8259 switchable_motion_mode,
7952 allow_warped_motion,8260 allow_warped_motion,
7953 false,8261 false,
8262+ SUB,
8263+ SUB,
7954 )?;8264 )?;
7955 if (c32 * 2 + 1) as u32 * SUB_MI < mi_cols {8265 if (c32 * 2 + 1) as u32 * SUB_MI < mi_cols {
7956 decode_inter_block(8266 decode_inter_block(
@@ -8000,10 +8310,39 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
8000 switchable_motion_mode,8310 switchable_motion_mode,
8001 allow_warped_motion,8311 allow_warped_motion,
8002 false,8312 false,
8313+ SUB,
8314+ SUB,
8003 )?;8315 )?;
8004 }8316 }
8005 }8317 }
8006 }8318 }
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+ }
8007 _ => {8346 _ => {
8008 return Err(unsupported(format!(8347 return Err(unsupported(format!(
8009 "a partition type this encoder never writes (value={part32})"8348 "a partition type this encoder never writes (value={part32})"
@@ -8763,6 +9102,8 @@ mod tests {
8763 false,9102 false,
8764 false,9103 false,
8765 false,9104 false,
9105+ side,
9106+ side,
8766 )9107 )
8767 .unwrap();9108 .unwrap();
8768 9109
crates/ec-av1/src/mc.rsmodified+64 -0
@@ -525,6 +525,70 @@ pub fn combine_compound(
525 }525 }
526 }526 }
527 527
528+/// lane-maskcomp r2: `build_compound_diffwtd_mask` (reconinter.c) --
529+/// `DIFFWTD_38`/`DIFFWTD_38_INV` (`mask_type` bit: 0/1). Operates directly on
530+/// the two [`predict_compound_intermediate`] outputs: libaom's own
531+/// `av1_build_compound_diffwtd_mask_d16_c` runs on its CONV_BUF domain (which
532+/// carries a constant `round_offset` bias baked into every sample by its
533+/// convolve stage), but `abs(src0 - src1)` cancels an equal bias on both
534+/// sides exactly, so the unbiased `i32` intermediates this crate already
535+/// produces give the identical `diff` libaom computes. `round` is
536+/// `2*FILTER_BITS - round_0 - round_1 + (bd-8)` == [`INTER_POST_ROUND`] for
537+/// 8-bit content (`round_0=3`, compound `round_1=7`, `bd=8`).
538+pub fn diffwtd_mask(pred0: &[i32], pred1: &[i32], inv: bool, mask: &mut [u8]) {
539+ assert_eq!(pred0.len(), pred1.len(), "both refs predict the same block");
540+ assert_eq!(mask.len(), pred0.len(), "one mask byte per pixel");
541+ for i in 0..mask.len() {
542+ let diff = round2((pred0[i] - pred1[i]).abs(), INTER_POST_ROUND);
543+ let m = (38 + diff / 16).clamp(0, 64);
544+ mask[i] = if inv { (64 - m) as u8 } else { m as u8 };
545+ }
546+}
547+
548+/// lane-maskcomp r2: `aom_lowbd_blend_a64_d16_mask_c` (blend_a64_mask.c),
549+/// algebraically simplified to this crate's unbiased `i32` intermediate
550+/// domain the same way [`diffwtd_mask`]'s doc comment derives -- libaom's
551+/// `res -= round_offset` step cancels exactly against the bias `m + (64-m)
552+/// == 64` contributes equally from both inputs, leaving `(m*pred0 +
553+/// (64-m)*pred1) >> 6` (a plain, unrounded shift, matching the C `>>` on
554+/// `int32_t`) then one final [`round2`] by [`INTER_POST_ROUND`]. `mask` is
555+/// always the LUMA-resolution mask (`mask_stride` == luma block width);
556+/// `subsampled` selects the 2x2-average chroma read (spec 7.11.3.14 /
557+/// libaom's `subw == 1 && subh == 1` branch) vs. the direct luma read.
558+#[allow(clippy::too_many_arguments)]
559+pub fn blend_masked_compound(
560+ pred0: &[i32],
561+ pred1: &[i32],
562+ mask: &[u8],
563+ mask_stride: usize,
564+ w: usize,
565+ h: usize,
566+ subsampled: bool,
567+ dst: &mut [u8],
568+) {
569+ assert_eq!(pred0.len(), w * h, "pred0 is the destination-sized block");
570+ assert_eq!(pred1.len(), w * h, "pred1 is the destination-sized block");
571+ assert_eq!(dst.len(), w * h, "the destination is the block");
572+ for i in 0..h {
573+ for j in 0..w {
574+ let m = if subsampled {
575+ let idx = (2 * i) * mask_stride + 2 * j;
576+ round2(
577+ i32::from(mask[idx])
578+ + i32::from(mask[idx + 1])
579+ + i32::from(mask[idx + mask_stride])
580+ + i32::from(mask[idx + mask_stride + 1]),
581+ 2,
582+ )
583+ } else {
584+ i32::from(mask[i * mask_stride + j])
585+ };
586+ let res = (m * pred0[i * w + j] + (64 - m) * pred1[i * w + j]) >> 6;
587+ dst[i * w + j] = round2(res, INTER_POST_ROUND).clamp(0, 255) as u8;
588+ }
589+ }
590+}
591+
528 /// Whole-pel identity case: [`predict_compound_intermediate`]'s two-pass592 /// Whole-pel identity case: [`predict_compound_intermediate`]'s two-pass
529 /// filter reduces to `16 * source_sample` exactly (the fraction-0 row is a593 /// filter reduces to `16 * source_sample` exactly (the fraction-0 row is a
530 /// single `128` tap both passes, and `128*128 == 1 << 14`, `14 - 7 == 7 ==594 /// single `128` tap both passes, and `128*128 == 1 << 14`, `14 - 7 == 7 ==
crates/ec-av1/src/stream.rsmodified+40 -33
@@ -3741,6 +3741,10 @@ mod tests {
3741 "--enable-onesided-comp=0",3741 "--enable-onesided-comp=0",
3742 "--enable-interintra-wedge=0",3742 "--enable-interintra-wedge=0",
3743 "--enable-smooth-interintra=0",3743 "--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.
3744 "--enable-rect-partitions=0",3748 "--enable-rect-partitions=0",
3745 "--enable-ab-partitions=1",3749 "--enable-ab-partitions=1",
3746 "--enable-1to4-partitions=0",3750 "--enable-1to4-partitions=0",
@@ -3824,31 +3828,33 @@ mod tests {
3824 matched > 0,3828 matched > 0,
3825 "{NAME}: every attempt refused; the gate never decoded a free-partition stream"3829 "{NAME}: every attempt refused; the gate never decoded a free-partition stream"
3826 );3830 );
3827- // lane-rectgate r1 finding, not asserted (see the fn doc comment):3831+ // lane-partitions r1: HORZ/VERT arms landed, so the diversity probe
3828- // `extended_partition_hits` stayed 0 across every recipe tried this3832+ // graduates from rectgate r1's eprintln to a report line on
3829- // round, including this one and the *already-green* warp gate run3833+ // `rect_partition_hits`; a zero-hit run SOFT-reports (aomenc RD may
3830- // with the same probe wired in -- aomenc simply never selects3834+ // legitimately never pick a rect split in a small window -- same
3831- // PARTITION_HORZ_B for this small gradient fixture at cq=45, so the3835+ // sampling caveat as the masked-compound gate's zero-hit runs).
3832- // charter's diversity assertion cannot fire without a different3836+ // `extended_partition_hits` (HORZ_B) stays unasserted per rectgate r1.
3833- // fixture/recipe. A hard `assert!` here would fail every future run3837+ if crate::decode::rect_partition_hits() == 0 {
3834- // for a reason unrelated to decoder correctness.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+ }
3835 eprintln!(3843 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(),
3837 crate::decode::extended_partition_hits()3846 crate::decode::extended_partition_hits()
3838 );3847 );
3839 }3848 }
3840 3849
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`
3842 /// streams must consume `compound_type`/`wedge_idx`/`wedge_sign`/3851 /// streams must consume `compound_type`/`wedge_idx`/`wedge_sign`/
3843- /// `mask_type` entropy-exact (`masked_compound_hits() > 0`) whenever a3852+ /// `mask_type` entropy-exact AND build the real DIFFWTD blend --
3844- /// block reads `comp_group_idx == 1` -- the syntax is ported this3853+ /// `masked_compound_hits() > 0` is now a hard assert, and a
3845- /// round, the wedge/diffwtd mask blend is NOT, so a masked-compound3854+ /// `COMPOUND_DIFFWTD` refusal is FORBIDDEN (matches interintra's own
3846- /// refusal itself is still EXPECTED here (r1's own named refusal,3855+ /// gate). `COMPOUND_WEDGE` refusals are still EXPECTED (r2 scope:
3847- /// asserted for wording only) rather than forbidden; only OTHER named3856+ /// wedge mask codebook not ported, charter's mergeable-partial
3848- /// refusals (screen content tools etc.) skip a seed without counting.3857+ /// fallback) -- counted separately, never asserted against.
3849- /// Once the blend lands, this gate's own masked-compound refusal
3850- /// becomes forbidden like `a_real_aomenc_stream_with_interintra_...`
3851- /// above's wedge case was for non-wedge interintra.
3852 #[test]3858 #[test]
3853 fn a_real_aomenc_stream_with_masked_compound_decodes_pixel_exact() {3859 fn a_real_aomenc_stream_with_masked_compound_decodes_pixel_exact() {
3854 const NAME: &str = "a_real_aomenc_stream_with_masked_compound_decodes_pixel_exact";3860 const NAME: &str = "a_real_aomenc_stream_with_masked_compound_decodes_pixel_exact";
@@ -3974,6 +3980,11 @@ mod tests {
3974 "{NAME} refused on warp (seed {seed}) -- warp decode is ported: {msg}"3980 "{NAME} refused on warp (seed {seed}) -- warp decode is ported: {msg}"
3975 );3981 );
3976 if msg.contains("masked COMPOUND_REFERENCE") {3982 if msg.contains("masked COMPOUND_REFERENCE") {
3983+ assert!(
3984+ msg.contains("COMPOUND_WEDGE"),
3985+ "{NAME} refused a non-wedge masked-compound block (seed {seed}) \
3986+ -- DIFFWTD blend is ported, this refusal is forbidden: {msg}"
3987+ );
3977 masked_refusals += 1;3988 masked_refusals += 1;
3978 } else {3989 } else {
3979 assert!(3990 assert!(
@@ -4019,22 +4030,18 @@ mod tests {
4019 // is that sampling flake, not a decode regression -- check4030 // is that sampling flake, not a decode regression -- check
4020 // masked_compound_hits/named_refusals in the panic message before4031 // masked_compound_hits/named_refusals in the panic message before
4021 // assuming a real bug.4032 // assuming a real bug.
4022- // r1: a zero-hit run is the sampling flake above, not a regression --4033+ // r2: DIFFWTD is ported and gated, so a zero-hit run is no longer
4023- // report it loudly instead of failing the default suite (the interintra4034+ // soft-skipped -- hard assert, matching the interintra gate.
4024- // gate went through the same soft phase; r2 flips this to a hard4035+ assert!(
4025- // assert once the blend lands and masked refusals become forbidden).4036+ crate::decode::masked_compound_hits() > 0,
4026- if crate::decode::masked_compound_hits() == 0 {4037+ "{NAME}: zero masked-compound blocks fired ({masked_refusals} wedge refusals, \
4027- eprintln!(4038+ {matched} matches, {named_refusals} other refusals out of {n_attempts}) -- gate \
4028- "{NAME}: SOFT-SKIP -- zero masked-compound blocks fired ({masked_refusals} \4039+ proved nothing this run"
4029- masked refusals, {matched} matches, {named_refusals} other refusals out of \4040+ );
4030- {n_attempts}); sampling flake, gate proved nothing this run"
4031- );
4032- return;
4033- }
4034 eprintln!(4041 eprintln!(
4035 "{NAME}: {named_refusals} other-capability refusals, {masked_refusals} expected \4042 "{NAME}: {named_refusals} other-capability refusals, {masked_refusals} expected \
4036- masked-compound refusals (r1: blend unported), {matched} pixel-exact matches out \4043+ COMPOUND_WEDGE refusals (r2 scope: wedge unported), {matched} pixel-exact matches \
4037- of {n_attempts}, masked_compound_hits={}",4044+ out of {n_attempts}, masked_compound_hits={}",
4038 crate::decode::masked_compound_hits()4045 crate::decode::masked_compound_hits()
4039 );4046 );
4040 }4047 }
lanes/maskcomp-r2.charter.mdadded+46 -0
@@ -0,0 +1,46 @@
1+# lane-maskcomp r2 charter — port the wedge/diffwtd masked-compound BLEND
2+
3+## Where you are
4+Worktree /home/user/Documents/Code/Rust/edith_codecs-maskcomp2, branch lane-maskcomp2 @ 5e25f76.
5+Build/test ONLY: `env CARGO_TARGET_DIR=$HOME/.cache/cargo-target-maskcomp2 cargo test -p ec-av1 --release --lib <name> -- --nocapture`
6+FOREGROUND, `nice -n 19`, `CARGO_BUILD_JOBS=4`. Never push; never touch other worktrees; fixtures/ is a symlink — only new pinned .obu streams go in.
7+
8+## Current state (r1 landed in 5e25f76 — do not re-derive)
9+- comp_group_idx==1 syntax is entropy-exact at BOTH refusal sites (decode.rs ~5176
10+ leaf16/32, ~6558 leaf8): compound_type, wedge_idx (16-ary), wedge_sign (literal),
11+ mask_type (literal) are consumed, then the blend refuses by name. Read
12+ lanes/maskcomp-r1.report.md first.
13+- Gate a_real_aomenc_stream_with_masked_compound_decodes_pixel_exact exists; its own
14+ masked-compound refusal is currently EXPECTED and a zero-hit run SOFT-SKIPs.
15+- Interintra blend (interintra_blend, decode.rs ~4410) is the shape to mirror for a
16+ 64-scale mask blend: (mask*p0 + (64-mask)*p1 + 32) >> 6.
17+
18+## Scope r2: the blend
19+1. Wedge masks: port libaom's wedge codebook for the bsizes this decoder reaches
20+ (8x8..32x32 squares; wedge is only used where av1_is_wedge_used(bsize)) —
21+ reconinter.c av1_wedge_params_lookup + init_wedge_masks/init_wedge_master_masks
22+ (the 64x64 master masks are built from wedge_master_oblique/vertical tables then
23+ cropped/flipped per code + sign). Build them at first use or as consts; verify a
24+ handful of mask rows against a C-side dump (patch a printf into
25+ /tmp/libaom-src reconinter.c, rebuild /tmp/libaom-build with ninja) — do NOT
26+ trust a hand transcription unchecked (class shared-oracle-blindness).
27+2. DIFFWTD masks: build_compound_diffwtd_mask (reconinter.c): per-pixel
28+ mask = clamp(38 + (|p0-p1|) >> shift, 0, 64) for DIFFWTD_38, inverted for _INV
29+ — port exactly, mind the bit-depth shift chain (class mirror-the-decoder-shift).
30+3. Chroma: av1_get_compound_type_mask + the subsampling path (chroma reads the luma
31+ mask subsampled by 2x2 averaging? read av1_build_masked_compound /
32+ aom_blend_a64_d16-vs-8bit paths carefully; this decoder is 8-bit).
33+4. Flip the gate: masked-compound refusals FORBIDDEN; zero-hit SOFT-SKIP becomes a
34+ hard assert (hits > 0) with EC_MASKCOMP_GATE_ATTEMPTS=80 default kept. Hammer 8x
35+ with EC_AV1_GATE_DUMP self-pin (/tmp/claude-1000/mc-flake-N.obu).
36+5. Any mismatch: pin to fixtures/, recon-dump (EC_AV1_PREFILT_DUMP) → range ladder
37+ (exact ladder = prediction-side, i.e., your mask; ours[k]=aom[k+1]) → for mask
38+ bugs dump the mask array both sides (add an env-gated eprintln; patch aomdec's
39+ av1_make_masked_inter_predictor likewise).
40+
41+## Done criteria
42+1. Gate green with hard hits assert, 8/8 hammer; 11 pins byte-exact; lib suite green.
43+2. Committed to lane-maskcomp2; REPORT lanes/maskcomp-r2.report.md, verdict FIRST.
44+Commit + report BEFORE budget runs out. If the wedge codebook cannot be finished
45+verified, land DIFFWTD alone (flip only the diffwtd refusal) — partial capability
46+with exact naming is mergeable; an unverified wedge table is not.
lanes/maskcomp-r2.report.mdadded+59 -0
@@ -0,0 +1,59 @@
1+# lane-maskcomp r2 report
2+
3+VERDICT: MERGEABLE PARTIAL -- DIFFWTD masked-compound blend ported and gated (hard assert, forbidden refusal, 8/8 hammer green, no pixel mismatches); wedge blend NOT ported, still refused by name (charter's mergeable-partial fallback: "land DIFFWTD alone").
4+
5+## What landed
6+- `crates/ec-av1/src/mc.rs`: `diffwtd_mask` (`build_compound_diffwtd_mask`, reconinter.c) and
7+ `blend_masked_compound` (`aom_lowbd_blend_a64_d16_mask_c`, blend_a64_mask.c), both algebraically
8+ re-derived onto this crate's unbiased `i32` `predict_compound_intermediate` domain instead of
9+ libaom's biased CONV_BUF representation -- proved on paper (doc comments) that libaom's
10+ `round_offset` bias cancels exactly in both functions (`abs(src0-src1)` for the mask, `m + (64-m)
11+ == 64` for the blend weight sum), so no offset bookkeeping is needed on our side. `round =
12+ 2*FILTER_BITS - round_0 - round_1 + (bd-8)` reduces to the crate's existing `INTER_POST_ROUND`
13+ (4) for 8-bit content, confirmed against the crate's own `INTER_ROUND_0`/`INTER_ROUND_1_COMPOUND`
14+ constants (3/7) rather than hand-copied.
15+- `crates/ec-av1/src/decode.rs`: both `comp_group_idx == 1` sites (`decode_inter_block`'s
16+ 16x16/32x32 leaf, `decode_inter_block8`'s 8x8 leaf) now split on `compound_type`:
17+ `COMPOUND_WEDGE` (`compound_type == 0`) still refuses by name (wedge mask codebook out of scope
18+ this round); `COMPOUND_DIFFWTD` (`compound_type == 1`) reads `mask_type` and falls through to
19+ build+apply the real blend instead of erroring. Real bug fixed while wiring this in:
20+ `compound_idx` (the distance-weighted-average symbol) was being read unconditionally on
21+ `!skip_mode && enable_jnt_comp`, missing libaom's `comp_group_idx == 0` outer gate
22+ (`decodemv.c:1606`) -- dead code before this round (the masked path always errored earlier so it
23+ never executed with `comp_group_idx == 1` in practice), now gated correctly at both sites.
24+- `crates/ec-av1/src/stream.rs`: `a_real_aomenc_stream_with_masked_compound_decodes_pixel_exact`
25+ flipped from r1's soft-skip/expected-refusal shape to r2's hard shape: `masked_compound_hits() >
26+ 0` is now a hard `assert!` (was a soft-skip), a `COMPOUND_DIFFWTD` refusal is now FORBIDDEN
27+ (asserted against, matching how the interintra gate treats its own ported capability), and a
28+ `COMPOUND_WEDGE` refusal is still counted as expected/unasserted (r2 scope boundary).
29+
30+## Verification
31+- `cargo check -p ec-av1 --release`: clean (only pre-existing missing-doc warnings, same set as
32+ before this round).
33+- Gate `a_real_aomenc_stream_with_masked_compound_decodes_pixel_exact`, hammered 8/8 (fresh
34+ `EC_AV1_GATE_DUMP` self-pin path per run, `/tmp/claude-1000/mc-flake/mc-flake-{1..8}.obu`): all 8
35+ green, `masked_compound_hits` in {2,3,3,3,4,3,5,3} per run (never zero), zero `COMPOUND_WEDGE`
36+ refusals fired in any run (content never picked wedge for this synthetic-gradients recipe, so the
37+ wedge-still-refuses path is untested live this round -- syntax-level only, per r1), zero pixel
38+ mismatches across all 80-attempt runs x 8 (`23-30 other-capability refusals` [screen-content-tools
39+ RD flake, pre-existing/documented], `50-64 pixel-exact matches` per run).
40+- `cargo test -p ec-av1 --release --lib` (full scoped suite): 220 passed, 0 failed, 17 ignored,
41+ finished in 140.58s -- includes all pre-existing pinned bit-exact regression tests, unaffected.
42+
43+## Deferred
44+- deferred: wedge mask codebook (`av1_wedge_params_lookup` + `init_wedge_master_masks`/
45+ `init_wedge_masks`, reconinter.c) -- explicitly out of r2 per the charter's mergeable-partial
46+ fallback ("DIFFWTD alone... is mergeable; an unverified wedge table is not"). Unblocks by
47+ transcribing `wedge_master_oblique_even/odd`/`wedge_master_vertical` + `wedge_codebook_16_*` +
48+ `wedge_signflip_lookup`, building the 64x64 master masks and cropping/flipping per
49+ `wedge_index`/`wedge_sign`, verifying a handful of mask rows against a live C-side printf dump
50+ (per charter, not a hand transcription unchecked), then flipping the `COMPOUND_WEDGE` refusal
51+ the same way this round flipped `COMPOUND_DIFFWTD`.
52+- deferred: a live gate run that actually exercises the `COMPOUND_WEDGE`-still-refuses path (to
53+ prove the r2 gate's own `assert!(msg.contains("COMPOUND_WEDGE"))` line is reachable, not just
54+ syntactically present) -- unblocks by a higher wedge-yield encoder recipe (aomenc's cpu-used=0 RD
55+ never picked wedge over diffwtd/plain-average in any of this round's 8x80 = 640 attempts).
56+
57+## Commit
58+`feat(av1): port the DIFFWTD masked-compound blend (comp_group_idx==1), wedge still refused` on
59+branch lane-maskcomp2.
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).