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};
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
@@ -5561,18 +5701,30 @@ fn decode_inter_block(
5561 mc::combine_compound(&inter0_v, &inter1_v, fwd_offset, bck_offset, &mut pred_v);5701 mc::combine_compound(&inter0_v, &inter1_v, fwd_offset, bck_offset, &mut pred_v);
5562 5702
5563 if skip {5703 if skip {
5564- y.reconstruct_mc(px, py, side, &pred_y, &vec![0i32; side * side]);5704+ y.reconstruct_mc_rect(
5565- u.reconstruct_mc(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(
5566 cpx,5714 cpx,
5567 cpy,5715 cpy,
5568 chroma_side,5716 chroma_side,
5717+ write_chroma_w,
5718+ write_chroma_h,
5569 &pred_u,5719 &pred_u,
5570 &vec![0i32; chroma_side * chroma_side],5720 &vec![0i32; chroma_side * chroma_side],
5571 );5721 );
5572- v.reconstruct_mc(5722+ v.reconstruct_mc_rect(
5573 cpx,5723 cpx,
5574 cpy,5724 cpy,
5575 chroma_side,5725 chroma_side,
5726+ write_chroma_w,
5727+ write_chroma_h,
5576 &pred_v,5728 &pred_v,
5577 &vec![0i32; chroma_side * chroma_side],5729 &vec![0i32; chroma_side * chroma_side],
5578 );5730 );
@@ -6106,18 +6258,30 @@ fn decode_inter_block(
6106 }6258 }
6107 6259
6108 if skip {6260 if skip {
6109- y.reconstruct_mc(px, py, side, &pred_y, &vec![0i32; side * side]);6261+ y.reconstruct_mc_rect(
6110- u.reconstruct_mc(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(
6111 cpx,6271 cpx,
6112 cpy,6272 cpy,
6113 chroma_side,6273 chroma_side,
6274+ write_chroma_w,
6275+ write_chroma_h,
6114 &pred_u,6276 &pred_u,
6115 &vec![0i32; chroma_side * chroma_side],6277 &vec![0i32; chroma_side * chroma_side],
6116 );6278 );
6117- v.reconstruct_mc(6279+ v.reconstruct_mc_rect(
6118 cpx,6280 cpx,
6119 cpy,6281 cpy,
6120 chroma_side,6282 chroma_side,
6283+ write_chroma_w,
6284+ write_chroma_h,
6121 &pred_v,6285 &pred_v,
6122 &vec![0i32; chroma_side * chroma_side],6286 &vec![0i32; chroma_side * chroma_side],
6123 );6287 );
@@ -6180,6 +6344,18 @@ fn decode_inter_block(
6180 }6344 }
6181 }6345 }
6182 } else {6346 } 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+ }
6183 let mode = dec.symbol(&mut cdfs.y_mode[size_group]);6359 let mode = dec.symbol(&mut cdfs.y_mode[size_group]);
6184 if mode >= 13 {6360 if mode >= 13 {
6185 return Err(unsupported(6361 return Err(unsupported(
@@ -6344,15 +6520,34 @@ fn decode_inter_block(
6344 r * SUB_MI as usize, c * SUB_MI as usize, dec.debug_bitpos(), dec.debug_state().06520 r * SUB_MI as usize, c * SUB_MI as usize, dec.debug_bitpos(), dec.debug_state().0
6345 );6521 );
6346 }6522 }
6347- neighbours.record(at, side, mode_for_tx, &[luma_grid, u_grid, v_grid]);6523+ 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);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+ );
6349 if let Some((ref1, group_idx, idx)) = compound_ctx {6534 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);
6351 }6536 }
6352- neighbours.fill_skip_grid((r * (SUB / MI), c * (SUB / MI)), side / MI, skip);6537+ neighbours.fill_skip_grid_rect(
6353- neighbours.fill_lf_grid(
6354 (r * (SUB / MI), c * (SUB / MI)),6538 (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.
6356 side as u8,6551 side as u8,
6357 // ref_grid's packed convention (lf_level): sign carries GLOBALMV,6552 // 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.6553 // 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(
7657 switchable_motion_mode,7852 switchable_motion_mode,
7658 allow_warped_motion,7853 allow_warped_motion,
7659 false,7854 false,
7855+ BLOCK,
7856+ BLOCK,
7660 )?;7857 )?;
7661 }7858 }
7662 PARTITION_SPLIT => {7859 PARTITION_SPLIT => {
@@ -7732,6 +7929,8 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
7732 switchable_motion_mode,7929 switchable_motion_mode,
7733 allow_warped_motion,7930 allow_warped_motion,
7734 false,7931 false,
7932+ SUB,
7933+ SUB,
7735 )?;7934 )?;
7736 } else {7935 } else {
7737 let ctx16 = neighbours.partition_ctx(at16, SUB);7936 let ctx16 = neighbours.partition_ctx(at16, SUB);
@@ -7902,6 +8101,8 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
7902 switchable_motion_mode,8101 switchable_motion_mode,
7903 allow_warped_motion,8102 allow_warped_motion,
7904 true,8103 true,
8104+ BLOCK,
8105+ BLOCK,
7905 )?;8106 )?;
7906 if (r32 * 2 + 1) as u32 * SUB_MI < mi_rows {8107 if (r32 * 2 + 1) as u32 * SUB_MI < mi_rows {
7907 decode_inter_block(8108 decode_inter_block(
@@ -7951,6 +8152,8 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
7951 switchable_motion_mode,8152 switchable_motion_mode,
7952 allow_warped_motion,8153 allow_warped_motion,
7953 false,8154 false,
8155+ SUB,
8156+ SUB,
7954 )?;8157 )?;
7955 if (c32 * 2 + 1) as u32 * SUB_MI < mi_cols {8158 if (c32 * 2 + 1) as u32 * SUB_MI < mi_cols {
7956 decode_inter_block(8159 decode_inter_block(
@@ -8000,10 +8203,213 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
8000 switchable_motion_mode,8203 switchable_motion_mode,
8001 allow_warped_motion,8204 allow_warped_motion,
8002 false,8205 false,
8206+ SUB,
8207+ SUB,
8003 )?;8208 )?;
8004 }8209 }
8005 }8210 }
8006 }8211 }
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+ }
8007 _ => {8413 _ => {
8008 return Err(unsupported(format!(8414 return Err(unsupported(format!(
8009 "a partition type this encoder never writes (value={part32})"8415 "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.