forge
Explore
Log in

Don't you dare go Hollow

wip(av1): decode HORZ/VERT rect partitions (32x16/16x32 skip strips), rect-footprint neighbour/grid writes

Browse files at this commit

1d71087691c3c74cab1c9abd19c97bffd1517c11Ahmet Kaan GümüşParent: 37a8819
crates/ec-av1/src/decode.rsmodified+448 -42
@@ -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
@@ -5561,18 +5701,30 @@ fn decode_inter_block(
55615701 mc::combine_compound(&inter0_v, &inter1_v, fwd_offset, bck_offset, &mut pred_v);
55625702
55635703 if skip {
5564- y.reconstruct_mc(px, py, side, &pred_y, &vec![0i32; side * side]);
5565- u.reconstruct_mc(
5704+ y.reconstruct_mc_rect(
5705+ px,
5706+ py,
5707+ side,
5708+ write_w,
5709+ write_h,
5710+ &pred_y,
5711+ &vec![0i32; side * side],
5712+ );
5713+ u.reconstruct_mc_rect(
55665714 cpx,
55675715 cpy,
55685716 chroma_side,
5717+ write_chroma_w,
5718+ write_chroma_h,
55695719 &pred_u,
55705720 &vec![0i32; chroma_side * chroma_side],
55715721 );
5572- v.reconstruct_mc(
5722+ v.reconstruct_mc_rect(
55735723 cpx,
55745724 cpy,
55755725 chroma_side,
5726+ write_chroma_w,
5727+ write_chroma_h,
55765728 &pred_v,
55775729 &vec![0i32; chroma_side * chroma_side],
55785730 );
@@ -6106,18 +6258,30 @@ fn decode_inter_block(
61066258 }
61076259
61086260 if skip {
6109- y.reconstruct_mc(px, py, side, &pred_y, &vec![0i32; side * side]);
6110- u.reconstruct_mc(
6261+ y.reconstruct_mc_rect(
6262+ px,
6263+ py,
6264+ side,
6265+ write_w,
6266+ write_h,
6267+ &pred_y,
6268+ &vec![0i32; side * side],
6269+ );
6270+ u.reconstruct_mc_rect(
61116271 cpx,
61126272 cpy,
61136273 chroma_side,
6274+ write_chroma_w,
6275+ write_chroma_h,
61146276 &pred_u,
61156277 &vec![0i32; chroma_side * chroma_side],
61166278 );
6117- v.reconstruct_mc(
6279+ v.reconstruct_mc_rect(
61186280 cpx,
61196281 cpy,
61206282 chroma_side,
6283+ write_chroma_w,
6284+ write_chroma_h,
61216285 &pred_v,
61226286 &vec![0i32; chroma_side * chroma_side],
61236287 );
@@ -6180,6 +6344,18 @@ fn decode_inter_block(
61806344 }
61816345 }
61826346 } else {
6347+ // lane-partitions r1: intra prediction (`PlaneBuf::reconstruct`) has
6348+ // no rectangular counterpart -- an intra-coded HORZ/VERT strip needs
6349+ // its own true-width/height edge/predict math, unlike the inter
6350+ // skip path above (which only needed a clipped write of an
6351+ // already-square-predicted buffer). Named refusal instead of a
6352+ // silently wrong square-shaped intra prediction.
6353+ if write_w != side || write_h != side {
6354+ return Err(unsupported(
6355+ "an intra-coded HORZ/VERT strip needs rectangular intra prediction \
6356+ this decoder does not code yet",
6357+ ));
6358+ }
61836359 let mode = dec.symbol(&mut cdfs.y_mode[size_group]);
61846360 if mode >= 13 {
61856361 return Err(unsupported(
@@ -6344,15 +6520,34 @@ fn decode_inter_block(
63446520 r * SUB_MI as usize, c * SUB_MI as usize, dec.debug_bitpos(), dec.debug_state().0
63456521 );
63466522 }
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);
6523+ neighbours.record_rect(at, write_w, write_h, mode_for_tx, &[luma_grid, u_grid, v_grid]);
6524+ neighbours.record_inter_rect(
6525+ at,
6526+ write_w,
6527+ write_h,
6528+ skip,
6529+ is_inter,
6530+ ref_frame_for_lf,
6531+ block_filter,
6532+ skip_mode,
6533+ );
63496534 if let Some((ref1, group_idx, idx)) = compound_ctx {
6350- neighbours.record_compound_ctx(at, side, ref1, group_idx, idx);
6535+ neighbours.record_compound_ctx_rect(at, write_w, write_h, ref1, group_idx, idx);
63516536 }
6352- neighbours.fill_skip_grid((r * (SUB / MI), c * (SUB / MI)), side / MI, skip);
6353- neighbours.fill_lf_grid(
6537+ neighbours.fill_skip_grid_rect(
63546538 (r * (SUB / MI), c * (SUB / MI)),
6355- side / MI,
6539+ write_w / MI,
6540+ write_h / MI,
6541+ skip,
6542+ );
6543+ neighbours.fill_lf_grid_rect(
6544+ (r * (SUB / MI), c * (SUB / MI)),
6545+ write_w / MI,
6546+ write_h / MI,
6547+ // lane-warp r5 / lane-partitions r1: `tx_grid` names one scalar
6548+ // (its own doc comment) -- a true rectangular strip's real
6549+ // TX_32X16/TX_16X32 keeps using `side`, the same square-context
6550+ // corner-cut `HORZ_B`'s top strip already shipped.
63566551 side as u8,
63576552 // ref_grid's packed convention (lf_level): sign carries GLOBALMV,
63586553 // whose mode_lf_lut row is 0, not the 1 every other inter mode gets.
@@ -7657,6 +7852,8 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
76577852 switchable_motion_mode,
76587853 allow_warped_motion,
76597854 false,
7855+ BLOCK,
7856+ BLOCK,
76607857 )?;
76617858 }
76627859 PARTITION_SPLIT => {
@@ -7732,6 +7929,8 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
77327929 switchable_motion_mode,
77337930 allow_warped_motion,
77347931 false,
7932+ SUB,
7933+ SUB,
77357934 )?;
77367935 } else {
77377936 let ctx16 = neighbours.partition_ctx(at16, SUB);
@@ -7902,6 +8101,8 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
79028101 switchable_motion_mode,
79038102 allow_warped_motion,
79048103 true,
8104+ BLOCK,
8105+ BLOCK,
79058106 )?;
79068107 if (r32 * 2 + 1) as u32 * SUB_MI < mi_rows {
79078108 decode_inter_block(
@@ -7951,6 +8152,8 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
79518152 switchable_motion_mode,
79528153 allow_warped_motion,
79538154 false,
8155+ SUB,
8156+ SUB,
79548157 )?;
79558158 if (c32 * 2 + 1) as u32 * SUB_MI < mi_cols {
79568159 decode_inter_block(
@@ -8000,10 +8203,213 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
80008203 switchable_motion_mode,
80018204 allow_warped_motion,
80028205 false,
8206+ SUB,
8207+ SUB,
80038208 )?;
80048209 }
80058210 }
80068211 }
8212+ PARTITION_HORZ => {
8213+ // lane-partitions r1: 32x32 -> two 32x16 strips. Both
8214+ // read at `side=BLOCK` (matching HORZ_B's already-
8215+ // accepted square-context corner-cut, lane-warp r5)
8216+ // but each writes only its own true 32x16 footprint
8217+ // (`write_w=32, write_h=16`); the bottom strip's `at`
8218+ // is one SUB-row down, same offset HORZ_B's own
8219+ // bottom leaves use.
8220+ RECT_PARTITION_HITS.fetch_add(1, std::sync::atomic::Ordering::Relaxed);
8221+ decode_inter_block(
8222+ &mut dec,
8223+ &mut cdfs,
8224+ &mut neighbours,
8225+ &mut grid,
8226+ at,
8227+ BLOCK,
8228+ mi_cols,
8229+ mi_rows,
8230+ &mut y,
8231+ &mut u,
8232+ &mut v,
8233+ &ref_y,
8234+ &ref_u,
8235+ &ref_v,
8236+ &ref_slots,
8237+ &sign_bias_table,
8238+ base_q_idx,
8239+ TxbSet::Luma32,
8240+ TxbSet::Luma32Inter,
8241+ TxbSet::Chroma16,
8242+ TX32,
8243+ TX16,
8244+ &scan32,
8245+ &scan16,
8246+ 3,
8247+ allow_high_precision_mv,
8248+ force_integer_mv,
8249+ interp_fixed,
8250+ enable_dual_filter,
8251+ tpl_frame.as_ref(),
8252+ reference_select,
8253+ enable_masked_compound,
8254+ enable_interintra_compound,
8255+ enable_jnt_comp,
8256+ order_hint_bits,
8257+ order_hint,
8258+ ref_order_hints,
8259+ skip_mode_present,
8260+ skip_mode_frame,
8261+ switchable_motion_mode,
8262+ allow_warped_motion,
8263+ true,
8264+ BLOCK,
8265+ SUB,
8266+ )?;
8267+ decode_inter_block(
8268+ &mut dec,
8269+ &mut cdfs,
8270+ &mut neighbours,
8271+ &mut grid,
8272+ (r32 as usize * 2 + 1, c32 as usize * 2),
8273+ BLOCK,
8274+ mi_cols,
8275+ mi_rows,
8276+ &mut y,
8277+ &mut u,
8278+ &mut v,
8279+ &ref_y,
8280+ &ref_u,
8281+ &ref_v,
8282+ &ref_slots,
8283+ &sign_bias_table,
8284+ base_q_idx,
8285+ TxbSet::Luma32,
8286+ TxbSet::Luma32Inter,
8287+ TxbSet::Chroma16,
8288+ TX32,
8289+ TX16,
8290+ &scan32,
8291+ &scan16,
8292+ 3,
8293+ allow_high_precision_mv,
8294+ force_integer_mv,
8295+ interp_fixed,
8296+ enable_dual_filter,
8297+ tpl_frame.as_ref(),
8298+ reference_select,
8299+ enable_masked_compound,
8300+ enable_interintra_compound,
8301+ enable_jnt_comp,
8302+ order_hint_bits,
8303+ order_hint,
8304+ ref_order_hints,
8305+ skip_mode_present,
8306+ skip_mode_frame,
8307+ switchable_motion_mode,
8308+ allow_warped_motion,
8309+ true,
8310+ BLOCK,
8311+ SUB,
8312+ )?;
8313+ }
8314+ PARTITION_VERT => {
8315+ // lane-partitions r1: 32x32 -> two 16x32 strips,
8316+ // mirroring PARTITION_HORZ above with width/height
8317+ // swapped; the right strip's `at` is one SUB-column
8318+ // right.
8319+ RECT_PARTITION_HITS.fetch_add(1, std::sync::atomic::Ordering::Relaxed);
8320+ decode_inter_block(
8321+ &mut dec,
8322+ &mut cdfs,
8323+ &mut neighbours,
8324+ &mut grid,
8325+ at,
8326+ BLOCK,
8327+ mi_cols,
8328+ mi_rows,
8329+ &mut y,
8330+ &mut u,
8331+ &mut v,
8332+ &ref_y,
8333+ &ref_u,
8334+ &ref_v,
8335+ &ref_slots,
8336+ &sign_bias_table,
8337+ base_q_idx,
8338+ TxbSet::Luma32,
8339+ TxbSet::Luma32Inter,
8340+ TxbSet::Chroma16,
8341+ TX32,
8342+ TX16,
8343+ &scan32,
8344+ &scan16,
8345+ 3,
8346+ allow_high_precision_mv,
8347+ force_integer_mv,
8348+ interp_fixed,
8349+ enable_dual_filter,
8350+ tpl_frame.as_ref(),
8351+ reference_select,
8352+ enable_masked_compound,
8353+ enable_interintra_compound,
8354+ enable_jnt_comp,
8355+ order_hint_bits,
8356+ order_hint,
8357+ ref_order_hints,
8358+ skip_mode_present,
8359+ skip_mode_frame,
8360+ switchable_motion_mode,
8361+ allow_warped_motion,
8362+ true,
8363+ SUB,
8364+ BLOCK,
8365+ )?;
8366+ decode_inter_block(
8367+ &mut dec,
8368+ &mut cdfs,
8369+ &mut neighbours,
8370+ &mut grid,
8371+ (r32 as usize * 2, c32 as usize * 2 + 1),
8372+ BLOCK,
8373+ mi_cols,
8374+ mi_rows,
8375+ &mut y,
8376+ &mut u,
8377+ &mut v,
8378+ &ref_y,
8379+ &ref_u,
8380+ &ref_v,
8381+ &ref_slots,
8382+ &sign_bias_table,
8383+ base_q_idx,
8384+ TxbSet::Luma32,
8385+ TxbSet::Luma32Inter,
8386+ TxbSet::Chroma16,
8387+ TX32,
8388+ TX16,
8389+ &scan32,
8390+ &scan16,
8391+ 3,
8392+ allow_high_precision_mv,
8393+ force_integer_mv,
8394+ interp_fixed,
8395+ enable_dual_filter,
8396+ tpl_frame.as_ref(),
8397+ reference_select,
8398+ enable_masked_compound,
8399+ enable_interintra_compound,
8400+ enable_jnt_comp,
8401+ order_hint_bits,
8402+ order_hint,
8403+ ref_order_hints,
8404+ skip_mode_present,
8405+ skip_mode_frame,
8406+ switchable_motion_mode,
8407+ allow_warped_motion,
8408+ true,
8409+ SUB,
8410+ BLOCK,
8411+ )?;
8412+ }
80078413 _ => {
80088414 return Err(unsupported(format!(
80098415 "a partition type this encoder never writes (value={part32})"
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.