forge
Explore
Log in

Don't you dare go Hollow

ec-av1: lane-av1-422sub8rect -- the sub-8 inter 4:2:2 chroma ported to its real shapes

Browse files at this commit

19f693e2ac309f86224ac6455c3f8026e2319f42Ahmet Kaan GümüşParent: 08f3d51
decode_inter_block8's whole chroma half moves to the BLOCK_4X8 plane block:
one TX_4X8 ChromaRect8x4/SCAN_4X8 unit per plane through read_inter_plane_rect
(offset-7 ctx, inherited luma tx type, around_mi_422_chroma walk), with the
MC build, warp, masked-compound, interintra, OBMC and skip pushes reshaped
per axis; the intra-in-inter arm reads the key-frame arm's rect reader.

decode_inter_sub8_split4's shared group unit is replaced by what the oracle
traces actually code at ss (1,0): every non-skipped odd-column piece is its
plane's own chroma reference and codes U+V TX_4X4 at the floored chroma cell
(build_inter_predictors_sub8x8 halves -- left from the left piece, right from
own; mixed groups whole-from-own), intra pieces route through
sub8_leaf_chroma422, and the 4:2:0 group tail is gated off at 4:2:2.

Shared helpers made ss-exact (4:2:0/4:4:4 identical): blend_masked_compound
and interintra_blend take per-axis mask subsampling (aom blend-a64-mask's
four branches), obmc_plan/obmc_run derive chroma extents by the plane ss,
TxParams::strided sizes stride*h (equal to the old square for every existing
caller). decode_inter_block's square-cut 4:2:2 chroma blend keeps the
pre-port direct mask read (stop-note: owning parent-lane surface).

Frame 0 of the pinned t422 fixture stays byte-exact at all four stages;
inter frames 1..10 decode and diverge ~15% less than the parent ladder
(no frame exactness claimed -- further 4:2:2 classes remain, trace:
EC_RECTCHROMA_GAP 16x8/8x32). Refusal unchanged; bypass never committed.
cargo check 0 warnings; 4:2:0 inter pixel-exact witness and refusal gates
green.
crates/ec-av1/src/decode.rsmodified+681 -249
@@ -2069,6 +2069,22 @@ pub fn chroma422_sub8_hits() -> usize {
20692069 CHROMA422_SUB8_HITS.with(|c| c.get())
20702070 }
20712071
2072+// lane-av1-422sub8rect: how many PER-PIECE TX_4X4 chroma coefficient units
2073+// the INTER sub-8x8 split4 path read on a 4:2:2 frame (ss 1,0) -- one per
2074+// non-skipped odd-column piece per plane (`is_chroma_reference`'s
2075+// `mi_col & 0x01` at ss_x 1). 4:2:0 goes through the shared group unit and
2076+// 4:4:4 through [`sub8_leaf_chroma444`]'s own per-piece twin, so a witness
2077+// gate reading 0 here proves the inter 4:2:2 per-piece arm never ran.
2078+thread_local! {
2079+ static CHROMA422_INTER_SUB8_HITS: std::cell::Cell<usize> =
2080+ const { std::cell::Cell::new(0) };
2081+}
2082+
2083+/// Current value of [`CHROMA422_INTER_SUB8_HITS`].
2084+pub fn chroma422_inter_sub8_hits() -> usize {
2085+ CHROMA422_INTER_SUB8_HITS.with(|c| c.get())
2086+}
2087+
20722088 // lane-av1-422m: how many TX_4X4 chunk units the invalid-ss-size chroma arm
20732089 // read (the 8x32 luma block whose 4:2:2 plane has no `ss_size_lookup` block).
20742090 // A 4:2:0 or 4:4:4 frame cannot increment it, so a non-zero read proves the
@@ -2668,7 +2684,10 @@ impl TxParams {
26682684 if self.stride == 0 {
26692685 return residual;
26702686 }
2671- let mut strided = vec![0i32; self.stride * self.stride];
2687+ // lane-av1-422sub8rect: `h` rows of `stride` -- a rect unit whose
2688+ // height exceeds its (narrow) prediction stride needs the full
2689+ // stride * h; every square caller has h == stride and is unchanged.
2690+ let mut strided = vec![0i32; self.stride * self.h];
26722691 for row in 0..self.h {
26732692 strided[row * self.stride..][..self.w]
26742693 .copy_from_slice(&residual[row * self.w..][..self.w]);
@@ -30739,6 +30758,8 @@ fn interintra_blend(
3073930758 bw: usize,
3074030759 bh: usize,
3074130760 stride: usize,
30761+ subw: usize,
30762+ subh: usize,
3074230763 ii_mode: u8,
3074330764 wedge: Option<(&'static [u8], usize)>,
3074430765 pred: &mut [u16], fctx: &crate::decode::FrameCtx,
@@ -30785,25 +30806,38 @@ fn interintra_blend(
3078530806 let m = u32::from(match wedge {
3078630807 // lane-wii r2: wedge-interintra mask (aom_blend_a64_mask
3078730808 // over the wedge codebook, intra as src0, fixed sign 0).
30788- // Luma plane: mask rows are luma-resolution, ms == side.
30789- // 4:2:0 chroma: 2x2 box average (reconinter.c sub8x8 --
30790- // subw == subh == 1).
30791- Some((mask, ms)) if ms == stride => mask[i * stride + j],
30792- Some((mask, ms)) => {
30793- let t = 2 * i * ms + 2 * j;
30794- ((u32::from(mask[t])
30795- + u32::from(mask[t + 1])
30796- + u32::from(mask[t + ms])
30797- + u32::from(mask[t + ms + 1])
30798- + 2)
30799- >> 2) as u8
30800- }
30801- None => match ii_mode {
30802- 0 => 32,
30809+ // `(subw, subh)` are the plane's own subsampling shifts;
30810+ // the four branches mirror aom_dsp/blend-a64-mask.c's
30811+ // `subw`/`subh` pair handling exactly: luma (0, 0) reads
30812+ // the direct sample, (1, 1) the 2x2 box average
30813+ // (reconinter.c sub8x8), and 4:2:2's (1, 0) the
30814+ // `AOM_BLEND_AVG` column pair.
30815+ Some((mask, ms)) => match (subw, subh) {
30816+ (0, 0) => u32::from(mask[i * ms + j]),
30817+ (1, 1) => {
30818+ let t = 2 * i * ms + 2 * j;
30819+ (u32::from(mask[t])
30820+ + u32::from(mask[t + 1])
30821+ + u32::from(mask[t + ms])
30822+ + u32::from(mask[t + ms + 1])
30823+ + 2)
30824+ >> 2
30825+ }
30826+ (1, 0) => {
30827+ let t = i * ms + 2 * j;
30828+ (u32::from(mask[t]) + u32::from(mask[t + 1]) + 1) >> 1
30829+ }
30830+ (_sw, _sh) => {
30831+ let t = 2 * i * ms + j;
30832+ (u32::from(mask[t]) + u32::from(mask[t + ms]) + 1) >> 1
30833+ }
30834+ },
30835+ None => u32::from(match ii_mode {
30836+ 0 => 32u8,
3080330837 1 => II_WEIGHTS_1D[i * scale],
3080430838 2 => II_WEIGHTS_1D[j * scale],
3080530839 _ => II_WEIGHTS_1D[i.min(j) * scale],
30806- },
30840+ }),
3080730841 });
3080830842 let idx = i * stride + j;
3080930843 pred[idx] = ((m * u32::from(intra[i * bw + j]) + (64 - m) * u32::from(pred[idx]) + 32)
@@ -30953,6 +30987,12 @@ pub(crate) fn obmc_plan(
3095330987 // `av1_setup_build_prediction_by_above_pred` passing that ref's own
3095430988 // `scale_factors`).
3095530989 frame_width: usize,
30990+ // lane-av1-422sub8rect: the plane's own subsampling shifts -- every
30991+ // chroma extent below derives from the luma rule by `>> ss` on the
30992+ // subsampled axis (`build_obmc_inter_pred_above`'s
30993+ // `overlap >> pd->subsampling_y` and the left pass's matching `>> ss_x`),
30994+ // never a blind half. 4:2:0 and 4:4:4 reduce to the old /2s and 0s.
30995+ ss: (usize, usize),
3095630996 ) -> Result<ObmcPlan> {
3095730997 // lane-rect r2 (libaom av1_build_obmc_inter_prediction): each pass has
3095830998 // its OWN neighbour cap (width-log2 for above, height-log2 for left) and
@@ -30984,10 +31024,16 @@ pub(crate) fn obmc_plan(
3098431024 let overlap_above = write_h.min(64) / 2;
3098531025 let overlap_left = write_w.min(64) / 2;
3098631026 // lane-inter8 r1 / lane-scaledref r1: `av1_skip_u4x4_pred_in_obmc`
30987- // (`reconinter.c` 820) returns `dir == 0` when the chroma plane's own
30988- // block is BLOCK_4X4/8X4/4X8 (an 8x8, 16x8 or 8x16 luma block at 4:2:0):
30989- // the ABOVE pass skips chroma entirely, the LEFT pass still blends it.
30990- let skip_chroma_above = matches!((write_w, write_h), (8, 8) | (16, 8) | (8, 16));
31027+ // (reconinter.c:829) keys on the CHROMA plane block
31028+ // (`get_plane_block_size(bsize, ss_x, ss_y)`): BLOCK_4X4/BLOCK_8X4/
31029+ // BLOCK_4X8 return `dir == 0`, so the ABOVE pass skips chroma for those
31030+ // and the LEFT pass never does. lane-av1-422sub8rect: keyed on the
31031+ // per-axis-shifted plane shape now -- an 8x8 leaf is (4, 4) at 4:2:0
31032+ // (skip) and (4, 8) at 4:2:2 (still skip, BLOCK_4X8 is in the list),
31033+ // while 8x4/4x8 luma leaves are (4, 4) or (8, 4) at 4:2:2.
31034+ let (ss_x, ss_y) = ss;
31035+ let skip_chroma_above =
31036+ matches!((write_w >> ss_x, write_h >> ss_y), (4, 4) | (8, 4) | (4, 8));
3099131037 let mut above = Vec::new();
3099231038 for (off4, span4, nb, src4) in overlappable_above(grid, mi_row, mi_col, bw4, mi_cols, max_nb(bw4))
3099331039 {
@@ -31055,6 +31101,7 @@ pub(crate) fn obmc_plan(
3105531101 cpy,
3105631102 overlap_above,
3105731103 overlap_left,
31104+ ss,
3105831105 skip_chroma_above,
3105931106 })
3106031107 }
@@ -31088,6 +31135,8 @@ pub(crate) struct ObmcPlan {
3108831135 cpy: usize,
3108931136 overlap_above: usize,
3109031137 overlap_left: usize,
31138+ /// The plane's own subsampling shifts ([`obmc_plan`]).
31139+ ss: (usize, usize),
3109131140 skip_chroma_above: bool,
3109231141 }
3109331142
@@ -31115,9 +31164,18 @@ pub(crate) fn obmc_run(
3111531164 cpy,
3111631165 overlap_above,
3111731166 overlap_left,
31167+ ss,
3111831168 skip_chroma_above,
3111931169 ..
3112031170 } = plan;
31171+ // lane-av1-422sub8rect: every chroma extent is the luma rule shifted by
31172+ // the plane's own subsampling (`build_obmc_inter_pred_above`'s
31173+ // `overlap >> pd->subsampling_y`, the left pass's `>> ss_x`, the
31174+ // neighbour-span `>> ss` per axis) -- 4:2:0 and 4:4:4 reduce to the old
31175+ // halves, 4:2:2 keeps the unhalved height.
31176+ let (ss_x, ss_y) = ss;
31177+ let chroma_w = write_w >> ss_x;
31178+ let chroma_h = write_h >> ss_y;
3112131179 // lane-alloc: one neighbour-prediction buffer per plane for the whole
3112231180 // block, reused by every neighbour of the above and left passes.
3112331181 let (mut tmp_y, mut tmp_u, mut tmp_v) = (Vec::new(), Vec::new(), Vec::new());
@@ -31136,7 +31194,8 @@ pub(crate) fn obmc_run(
3113631194 let (x, y) = (f[1].parse::<usize>().ok()?, f[2].parse::<usize>().ok()?);
3113731195 let fr = f.get(3).and_then(|s| s.parse::<i64>().ok()).unwrap_or(-1);
3113831196 let idx = PREFILT_PICTURE_IDX.load(std::sync::atomic::Ordering::SeqCst) as i64;
31139- if x >= cpx && x < cpx + write_w / 2 && y >= cpy && y < cpy + write_h / 2
31197+ let (mcb_cw, mcb_ch) = (write_w >> ss_x, write_h >> ss_y);
31198+ if x >= cpx && x < cpx + mcb_cw && y >= cpy && y < cpy + mcb_ch
3114031199 && (fr < 0 || fr == idx)
3114131200 {
3114231201 Some((x, y, idx))
@@ -31147,11 +31206,11 @@ pub(crate) fn obmc_run(
3114731206 if let Some((_, _, idx)) = ec_mcb {
3114831207 eprintln!(
3114931208 "OUR_MCB pre f={idx} cpx={cpx} cpy={cpy} cw={} ch={}",
31150- write_w / 2,
31151- write_h / 2
31209+ write_w >> ss_x,
31210+ write_h >> ss_y
3115231211 );
31153- for r in 0..write_h / 2 {
31154- let row: Vec<u16> = (0..write_w / 2).map(|c| pred_u[r * chroma_side + c]).collect();
31212+ for r in 0..(write_h >> ss_y) {
31213+ let row: Vec<u16> = (0..(write_w >> ss_x)).map(|c| pred_u[r * chroma_side + c]).collect();
3115531214 eprintln!("OUR_MCB prerow{r}: {row:?}");
3115631215 }
3115731216 }
@@ -31167,9 +31226,10 @@ pub(crate) fn obmc_run(
3116731226 if !skip_chroma_above {
3116831227 // lane-t900 r13 (measured, NOT a defect): libaom's min-4 clamp
3116931228 // sizes only the OBMC PREDICTION buffer; the blend length is the
31170- // plain half (`build_obmc_inter_pred_above`: `overlap >> ss_y`).
31171- let (cbw, cbh, cox) = (bw / 2, overlap_above / 2, ox / 2);
31172- let cw = cbw.min(write_w / 2 - cox);
31229+ // plain `overlap >> ss_y` (`build_obmc_inter_pred_above`:
31230+ // `bh = overlap >> pd->subsampling_y`).
31231+ let (cbw, cbh, cox) = (bw >> ss_x, overlap_above >> ss_y, ox >> ss_x);
31232+ let cw = cbw.min(chroma_w - cox);
3117331233 obmc_neighbour_pred(nu, cpx + cox, cpy, nb.mv, cbw, cbh, false, nb.h_kind, nb.v_kind, nb.scale, &mut tmp_u, fctx);
3117431234 obmc_blend_v(pred_u, chroma_side, cox, 0, cw, cbh, cbw, &tmp_u);
3117531235 obmc_neighbour_pred(nv, cpx + cox, cpy, nb.mv, cbw, cbh, false, nb.h_kind, nb.v_kind, nb.scale, &mut tmp_v, fctx);
@@ -31184,7 +31244,7 @@ pub(crate) fn obmc_run(
3118431244 let (bw, bh, oy) = (overlap_left, nb.span4 * 4, nb.off4 * 4);
3118531245 obmc_neighbour_pred(ny, px, py + oy, nb.mv, bw, bh, true, nb.h_kind, nb.v_kind, nb.scale, &mut tmp_y, fctx);
3118631246 obmc_blend_h(pred_y, side, 0, oy, bw, bh.min(write_h - oy), &tmp_y);
31187- let (cbw, cbh, coy) = (overlap_left / 2, bh / 2, oy / 2);
31247+ let (cbw, cbh, coy) = (overlap_left >> ss_x, bh >> ss_y, oy >> ss_y);
3118831248 obmc_neighbour_pred(nu, cpx, cpy + coy, nb.mv, cbw, cbh, false, nb.h_kind, nb.v_kind, nb.scale, &mut tmp_u, fctx);
3118931249 if let Some((_, _, idx)) = ec_mcb {
3119031250 eprintln!(
@@ -31196,14 +31256,14 @@ pub(crate) fn obmc_run(
3119631256 eprintln!("OUR_MCB lrow{r}: {row:?}");
3119731257 }
3119831258 }
31199- let ch = cbh.min(write_h / 2 - coy);
31259+ let ch = cbh.min(chroma_h - coy);
3120031260 obmc_blend_h(pred_u, chroma_side, 0, coy, cbw, ch, &tmp_u);
3120131261 obmc_neighbour_pred(nv, cpx, cpy + coy, nb.mv, cbw, cbh, false, nb.h_kind, nb.v_kind, nb.scale, &mut tmp_v, fctx);
3120231262 obmc_blend_h(pred_v, chroma_side, 0, coy, cbw, ch, &tmp_v);
3120331263 }
3120431264 if let Some((_, _, idx)) = ec_mcb {
31205- for r in 0..write_h / 2 {
31206- let row: Vec<u16> = (0..write_w / 2).map(|c| pred_u[r * chroma_side + c]).collect();
31265+ for r in 0..chroma_h {
31266+ let row: Vec<u16> = (0..chroma_w).map(|c| pred_u[r * chroma_side + c]).collect();
3120731267 eprintln!("OUR_MCB post f={idx} row{r}: {row:?}");
3120831268 }
3120931269 }
@@ -32642,7 +32702,7 @@ fn decode_inter_block(
3264232702 };
3264332703 if let Some(mask_y) = mask_y {
3264432704 mc::blend_masked_compound(
32645- &inter0_y, &inter1_y, mask_y, side, side, side, false, &mut pred_y, fctx,
32705+ &inter0_y, &inter1_y, mask_y, side, side, side, 0, 0, &mut pred_y, fctx,
3264632706 );
3264732707 } else {
3264832708 mc::combine_compound(&inter0_y, &inter1_y, fwd_offset, bck_offset, &mut pred_y, fctx);
@@ -32706,6 +32766,13 @@ fn decode_inter_block(
3270632766 }
3270732767 let mut pred_u = refill(std::mem::take(&mut out[1]), chroma_side * chroma_side);
3270832768 if let Some(mask_y) = mask_y {
32769+ // lane-av1-422sub8rect stop-note: this fn's 4:2:2 chroma
32770+ // prediction is still the square-cut model (the owning
32771+ // parent-lane surface) -- its buffer is `chroma_side`-square
32772+ // and cannot be indexed by the subsampled-axis mask walks,
32773+ // so at ss_x != ss_y the blend keeps the direct
32774+ // luma-resolution read (the pre-port behaviour, known
32775+ // divergent there) until that surface itself is ported.
3270932776 mc::blend_masked_compound(
3271032777 &inter0_u,
3271132778 &inter1_u,
@@ -32713,7 +32780,8 @@ fn decode_inter_block(
3271332780 side,
3271432781 chroma_side,
3271532782 chroma_side,
32716- ss_x(fctx) == 1 && ss_y(fctx) == 1,
32783+ if ss_x(fctx) == ss_y(fctx) { ss_x(fctx) } else { 0 },
32784+ if ss_x(fctx) == ss_y(fctx) { ss_y(fctx) } else { 0 },
3271732785 &mut pred_u, fctx,
3271832786 );
3271932787 } else {
@@ -32778,6 +32846,13 @@ fn decode_inter_block(
3277832846 }
3277932847 let mut pred_v = refill(std::mem::take(&mut out[2]), chroma_side * chroma_side);
3278032848 if let Some(mask_y) = mask_y {
32849+ // lane-av1-422sub8rect stop-note: this fn's 4:2:2 chroma
32850+ // prediction is still the square-cut model (the owning
32851+ // parent-lane surface) -- its buffer is `chroma_side`-square
32852+ // and cannot be indexed by the subsampled-axis mask walks,
32853+ // so at ss_x != ss_y the blend keeps the direct
32854+ // luma-resolution read (the pre-port behaviour, known
32855+ // divergent there) until that surface itself is ported.
3278132856 mc::blend_masked_compound(
3278232857 &inter0_v,
3278332858 &inter1_v,
@@ -32785,7 +32860,8 @@ fn decode_inter_block(
3278532860 side,
3278632861 chroma_side,
3278732862 chroma_side,
32788- ss_x(fctx) == 1 && ss_y(fctx) == 1,
32863+ if ss_x(fctx) == ss_y(fctx) { ss_x(fctx) } else { 0 },
32864+ if ss_x(fctx) == ss_y(fctx) { ss_y(fctx) } else { 0 },
3278932865 &mut pred_v, fctx,
3279032866 );
3279132867 } else {
@@ -34039,6 +34115,7 @@ fn decode_inter_block(
3403934115 refpix,
3404034116 interp_fixed,
3404134117 frame_width,
34118+ (ss_x(fctx), ss_y(fctx)),
3404234119 )?)
3404334120 } else {
3404434121 None
@@ -34200,14 +34277,14 @@ fn decode_inter_block(
3420034277 if write_w != write_h {
3420134278 hit!(INTERINTRA_RECT_HITS);
3420234279 }
34203- interintra_blend(y, px, py, write_w, write_h, side, ii, wedge_mask, &mut pred_y, fctx);
34280+ interintra_blend(y, px, py, write_w, write_h, side, 0, 0, ii, wedge_mask, &mut pred_y, fctx);
3420434281 interintra_blend(
34205- u, cpx, cpy, write_chroma_w, write_chroma_h, chroma_side, ii, wedge_mask,
34206- &mut pred_u, fctx,
34282+ u, cpx, cpy, write_chroma_w, write_chroma_h, chroma_side, ss_x(fctx),
34283+ ss_y(fctx), ii, wedge_mask, &mut pred_u, fctx,
3420734284 );
3420834285 interintra_blend(
34209- v, cpx, cpy, write_chroma_w, write_chroma_h, chroma_side, ii, wedge_mask,
34210- &mut pred_v, fctx,
34286+ v, cpx, cpy, write_chroma_w, write_chroma_h, chroma_side, ss_x(fctx),
34287+ ss_y(fctx), ii, wedge_mask, &mut pred_v, fctx,
3421134288 );
3421234289 }
3421334290 if let Some(plan) = &obmc {
@@ -36201,6 +36278,17 @@ fn decode_inter_sub8_split4(
3620136278 // frame 1: plane 0,1,2 per leaf in leaf order) -- there is no shared
3620236279 // group unit and no 2x2-piece group prediction.
3620336280 let chroma_444 = ss_x(fctx) == 0 && ss_y(fctx) == 0;
36281+ // 4:2:2 (lane-av1-422sub8rect): `is_chroma_reference` for a BLOCK_4X4
36282+ // piece at ss (1, 0) is `(mi_col & 0x01) || !(bw & 0x01) || !ss_x`
36283+ // == ODD mi_col (av1_common_int.h:1459) -- pieces 1 and 3 of the group
36284+ // are their plane's own chroma references and each codes its own
36285+ // TX_4X4 unit right after its luma, exactly the key-frame split-group
36286+ // behaviour the pinned t422 fixture's frame 0 traces (groups (18,54)
36287+ // and (30,42): U+V read on BOTH odd-column leaves) and frame 1's
36288+ // inter group at mi(12,2) repeats (U+V TX_4X4 ctx 8 on leaf (12,3)
36289+ // alone -- the bottom-right leaf was skipped, so it codes nothing).
36290+ // The 4:2:0 shared group unit never exists at 4:2:2.
36291+ let chroma_422 = ss_x(fctx) == 1 && ss_y(fctx) == 0;
3620436292 for i in 0..4usize {
3620536293 let (dr, dc) = (i / 2, i % 2);
3620636294 let lmi = (gr + dr, gc + dc);
@@ -36253,7 +36341,9 @@ fn decode_inter_sub8_split4(
3625336341 }
3625436342 // lane-sub8intra: the `BLOCK_4X4` twin of the HORZ/VERT arm --
3625536343 // same [`decode_intra_sub8_leaf`], no tx-depth symbol, chroma on
36256- // the LAST sub-block (`is_chroma_reference` under 4:2:0).
36344+ // the chroma-reference sub-blocks (`is_chroma_reference`: the
36345+ // LAST one under 4:2:0, BOTH odd-column ones at 4:2:2, every
36346+ // one at 4:4:4).
3625736347 decode_intra_sub8_leaf(
3625836348 dec,
3625936349 cdfs,
@@ -36262,7 +36352,7 @@ fn decode_inter_sub8_split4(
3626236352 group_mi,
3626336353 lmi,
3626436354 (B4, B4),
36265- chroma_444 || i == 3,
36355+ chroma_444 || (cmi & 1 == 1 && chroma_422) || i == 3,
3626636356 skip,
3626736357 scan4,
3626836358 y,
@@ -36634,6 +36724,150 @@ fn decode_inter_sub8_split4(
3663436724 neighbours.record_mi_chroma(lmi, B4, B4, 1, &ug);
3663536725 neighbours.record_mi_chroma(lmi, B4, B4, 2, &vg);
3663636726 }
36727+ // lane-av1-422sub8rect: the 4:2:2 per-piece arm. `is_chroma_reference`
36728+ // for a BLOCK_4X4 at ss (1, 0) is the odd mi_col (`av1_common_int.h`
36729+ // :1459), so THIS piece (right column of the group) is a chroma
36730+ // reference and codes its own U and V TX_4X4 units right after its
36731+ // luma -- measured on the pinned t422 fixture: frame 0 key-frame
36732+ // groups (18,54)/(30,42) read U+V on both odd-column leaves, and
36733+ // frame 1's inter group at mi(12,2) reads U+V TX_4X4 ctx 8 on leaf
36734+ // (12,3) alone (its bottom-right twin was skipped).
36735+ //
36736+ // The unit anchors at the FLOORED chroma cell
36737+ // (`av1_setup_dst_planes`' `(mi_col & !1) * MI >> ss_x`, the
36738+ // lane-av1-422kf2 rule), so the 4-px-wide square covers the group's
36739+ // whole chroma width, and the prediction walks
36740+ // `build_inter_predictors_sub8x8` (reconinter_template.inc): the
36741+ // left 2x4 half from the LEFT piece's own ref/mv/filters, the right
36742+ // 2x4 half from this piece's -- unless the left piece is intra (or
36743+ // off-frame), which makes `is_sub8x8_inter` false and predicts the
36744+ // whole 4x4 from THIS piece's own mv. A skipped reference piece
36745+ // still predicts (spec 7.11.3: `predict_inter_block_visit` runs
36746+ // before the `skip_txfm` guard) but codes no coefficients.
36747+ } else if chroma_422 && (cmi & 1) == 1 {
36748+ let (pc_ref, pc_mv, pc_hf, pc_vf) = piece[i].expect("inter piece recorded above");
36749+ let unit_x = ((cmi & !1) * MI) >> ss_x(fctx);
36750+ let unit_y = py >> ss_y(fctx);
36751+ // `is_sub8x8_inter`'s left-neighbour probe (`mi[-1]`): the piece
36752+ // one mi to the LEFT, when it exists and is inter.
36753+ let piece_left = piece[i - 1];
36754+ let build_c = move |_y: &mut PlaneBuf<'static>,
36755+ _u: &mut PlaneBuf<'static>,
36756+ _v: &mut PlaneBuf<'static>,
36757+ fctx: &crate::decode::FrameCtx,
36758+ out: &mut [Vec<u16>; 3]| {
36759+ let Some((pc_ref_y, sref_u, sref_v)) = ref_planes_deferred(pc_ref, refpix) else {
36760+ return;
36761+ };
36762+ let pc_scale = mc::scale_factor(pc_ref_y.width, frame_width);
36763+ // The left piece's own reference planes + mv/filters, when it
36764+ // is an inter piece (`is_sub8x8_inter`'s `mi[-1]` probe).
36765+ let left = piece_left
36766+ .as_ref()
36767+ .map(|&(l_ref, l_mv, l_hf, l_vf)| {
36768+ (l_ref, l_mv, l_hf, l_vf)
36769+ })
36770+ .and_then(|(l_ref, l_mv, l_hf, l_vf)| {
36771+ ref_planes_deferred(l_ref, refpix).map(|planes| {
36772+ let (lp_y, _, _) = planes;
36773+ let l_scale = mc::scale_factor(lp_y.width, frame_width);
36774+ (l_mv, l_hf, l_vf, planes, l_scale)
36775+ })
36776+ });
36777+ let mut pred_u = refill(std::mem::take(&mut out[1]), B4 * B4);
36778+ let mut pred_v = refill(std::mem::take(&mut out[2]), B4 * B4);
36779+ for (plane, dst) in [(sref_u, &mut pred_u), (sref_v, &mut pred_v)] {
36780+ let mut buf = vec![0u16; B4 * B4];
36781+ // Right 2x4 half: this piece's own ref/mv/filters.
36782+ let mut half = vec![0u16; 2 * 4];
36783+ mc::predict_maybe_scaled(
36784+ &plane.data,
36785+ plane.width,
36786+ plane.true_width,
36787+ plane.true_height,
36788+ mv_to_q4(unit_x + 2, pc_mv.1, ss_x(fctx)),
36789+ mv_to_q4(unit_y, pc_mv.0, ss_y(fctx)),
36790+ pc_scale,
36791+ 2,
36792+ 4,
36793+ pc_hf,
36794+ pc_vf,
36795+ &mut half, fctx,
36796+ );
36797+ for row in 0..4 {
36798+ buf[row * B4 + 2..row * B4 + 4]
36799+ .copy_from_slice(&half[row * 2..row * 2 + 2]);
36800+ }
36801+ // Left 2x4 half: the LEFT piece's own mv/filters
36802+ // (sub8x8-inter); a mixed group (left piece intra or
36803+ // off-frame) predicts it from THIS piece too, which
36804+ // reduces to the whole-4x4-from-own rule.
36805+ let (l_mv, l_hf, l_vf, l_planes, l_scale) = match left {
36806+ Some((l_mv, l_hf, l_vf, l_planes, l_scale)) => {
36807+ (l_mv, l_hf, l_vf, l_planes, l_scale)
36808+ }
36809+ None => (pc_mv, pc_hf, pc_vf, (pc_ref_y, sref_u, sref_v), pc_scale),
36810+ };
36811+ let (_, l_ref_u, _) = l_planes;
36812+ mc::predict_maybe_scaled(
36813+ &l_ref_u.data,
36814+ l_ref_u.width,
36815+ l_ref_u.true_width,
36816+ l_ref_u.true_height,
36817+ mv_to_q4(unit_x, l_mv.1, ss_x(fctx)),
36818+ mv_to_q4(unit_y, l_mv.0, ss_y(fctx)),
36819+ l_scale,
36820+ 2,
36821+ 4,
36822+ l_hf,
36823+ l_vf,
36824+ &mut half, fctx,
36825+ );
36826+ for row in 0..4 {
36827+ buf[row * B4..row * B4 + 2].copy_from_slice(&half[row * 2..row * 2 + 2]);
36828+ }
36829+ dst.copy_from_slice(&buf);
36830+ }
36831+ out[1] = pred_u;
36832+ out[2] = pred_v;
36833+ };
36834+ let (pred_cu, pred_cv): (Vec<u16>, Vec<u16>);
36835+ let (su, sv) = if recon_deferred(fctx) {
36836+ push_pred(fctx, build_c);
36837+ (
36838+ Pred::Cur { plane: 1, stride: B4, off: 0 },
36839+ Pred::Cur { plane: 2, stride: B4, off: 0 },
36840+ )
36841+ } else {
36842+ let mut built: [Vec<u16>; 3] = Default::default();
36843+ build_c(y, u, v, fctx, &mut built);
36844+ let [_, bu, bv] = built;
36845+ (pred_cu, pred_cv) = (bu, bv);
36846+ (Pred::Inline(&pred_cu, B4), Pred::Inline(&pred_cv, B4))
36847+ };
36848+ // The unit's entropy context: one chroma cell wide, floored --
36849+ // [`Neighbours::around_mi_422_chroma`] at the unit's own 8x4
36850+ // luma span (the [`sub8_leaf_chroma422`] rule).
36851+ let ctx_mi = (rmi, cmi & !1);
36852+ let ca = neighbours.around_mi_422_chroma(ctx_mi, 8, 4);
36853+ if skip {
36854+ push_mc(1, unit_x, unit_y, B4, su, &ZERO_RESIDUAL[..B4 * B4], fctx);
36855+ push_mc(2, unit_x, unit_y, B4, sv, &ZERO_RESIDUAL[..B4 * B4], fctx);
36856+ neighbours.record_mi_chroma(ctx_mi, 8, 4, 1, &ZERO_RESIDUAL[..B4 * B4]);
36857+ neighbours.record_mi_chroma(ctx_mi, 8, 4, 2, &ZERO_RESIDUAL[..B4 * B4]);
36858+ } else {
36859+ hit!(CHROMA422_INTER_SUB8_HITS);
36860+ let (ug, _) = read_inter_plane(
36861+ dec, cdfs, TxbSet::Chroma4, scan4, 1, ca[1], 0, u, unit_x, unit_y, B4,
36862+ base_q_idx, su, Some(piece_tx_type), None, fctx,
36863+ )?;
36864+ let (vg, _) = read_inter_plane(
36865+ dec, cdfs, TxbSet::Chroma4, scan4, 2, ca[2], 0, v, unit_x, unit_y, B4,
36866+ base_q_idx, sv, Some(piece_tx_type), None, fctx,
36867+ )?;
36868+ neighbours.record_mi_chroma(ctx_mi, 8, 4, 1, &ug);
36869+ neighbours.record_mi_chroma(ctx_mi, 8, 4, 2, &vg);
36870+ }
3663736871 }
3663836872 neighbours.record_mode_mi(rmi, cmi, 1, 1, DC_PRED);
3663936873 neighbours.record_inter_rect_mi(lmi, 1, 1, skip, true, ref_frame, resolved_filter, false);
@@ -36673,7 +36907,7 @@ fn decode_inter_sub8_split4(
3667336907 // frames mismatched ffmpeg by +-1..7 (class
3667436908 // `override-slot-on-one-arm`, this lane's own 10-bit film gate
3667536909 // regression at 1ad7e0fc; port of lane-av1-cfl's 7c6dad53).
36676- if !chroma_444 && !intra_chroma {
36910+ if !chroma_444 && !chroma_422 && !intra_chroma {
3667736911 neighbours.record_uv_mode_mi(gr, gc, 2, 2, DC_PRED);
3667836912 }
3667936913 // lane-t900 r23 (class [[new-map-ignores-tile-edge]]: a neighbour map
@@ -36685,10 +36919,12 @@ fn decode_inter_sub8_split4(
3668536919 // 0). No sub-8x8 piece can itself be a palette (`av1_allow_palette`
3668636920 // needs `bsize >= BLOCK_8X8`), so the group always clears.
3668736921 record_strip_palette(neighbours, (gr, gc), 8, 8, 0, [0u16; 8], 0, [0u16; 8]);
36688- if !chroma_444 && !intra_chroma {
36922+ if !chroma_444 && !chroma_422 && !intra_chroma {
3668936923 // Chroma, once for the whole group, on the last sub-block's own `skip`
3669036924 // flag -- prediction from all four sub-blocks (2x2 pieces), residual as
36691- // one TX_4X4 unit per plane.
36925+ // one TX_4X4 unit per plane. lane-av1-422sub8rect: 4:2:2 never takes
36926+ // this arm -- the shared group unit does not exist at ss (1, 0); each
36927+ // odd-column piece coded its own chroma inside the loop above.
3669236928 // `is_sub8x8_inter` (reconinter_template.inc:54) is false as soon as ANY
3669336929 // mi of the group is intra: the group's 4x4 chroma is then predicted WHOLE
3669436930 // from the chroma-reference (last) sub-block's own mv, not in 2x2 pieces.
@@ -37213,6 +37449,29 @@ fn decode_intra_sub8_leaf(
3721337449 // ours ctx 2 where libaom gathers 1).
3721437450 record_strip_palette(neighbours, (gr, gc), 8, 8, 0, [0u16; 8], 0, [0u16; 8]);
3721537451 if !has_chroma {
37452+ // lane-av1-422sub8rect: 4:2:2 has no shared group unit whose tail
37453+ // would stamp the mi map (`is_chroma_reference` runs per piece), so
37454+ // a non-referenced piece publishes its own cell -- libaom leaves
37455+ // `uv_mode` unset on it, `is_smooth` reads 0, i.e. DC_PRED.
37456+ if ss_x(fctx) == 1 && ss_y(fctx) == 0 {
37457+ neighbours.record_uv_mode_mi(lmi.0, lmi.1, 1, 1, DC_PRED);
37458+ }
37459+ return Ok(mode);
37460+ }
37461+ // lane-av1-422sub8rect: at 4:2:2 this (odd-column) piece is its plane's
37462+ // OWN chroma reference -- the key-frame split group's per-leaf TX_4X4
37463+ // model, floored anchor and per-chroma-cell context included
37464+ // ([`sub8_leaf_chroma422`], measured on the pinned t422 fixture frame 0:
37465+ // groups (18,54)/(30,42) code U+V on both odd-column leaves), never a
37466+ // shared group unit. Inter frames code no intrabc, so `intrabc_dv` is
37467+ // `None` here.
37468+ if ss_x(fctx) == 1 && ss_y(fctx) == 0 {
37469+ sub8_leaf_chroma422(
37470+ dec, cdfs, neighbours, lmi, uv_mode, 0, alpha, skip,
37471+ None, y, u, v, scan4, base_q_idx,
37472+ neighbours.smooth_uv_neighbour(lmi.0, lmi.1, r, c, fctx),
37473+ (bw, bh), fctx,
37474+ )?;
3721637475 return Ok(mode);
3721737476 }
3721837477 // The group's single 4x4 chroma unit, intra-predicted from THIS
@@ -38292,18 +38551,30 @@ fn decode_inter_block8(
3829238551 // bookkeeping. Always `false` outside a `TxMode::Select` inter frame.
3829338552 let split8;
3829438553 const SIDE: usize = 8;
38295- // lane-av1-444: this 8x8 leaf's chroma plane block is `8 >> ss` a side --
38296- // 4 at 4:2:0 (one TX_4X4 unit) and the full 8 at 4:4:4, where libaom
38297- // codes ONE TX_8X8 unit (`av1_get_max_uv_txsize(BLOCK_8X8)` at ss 0/0,
38298- // measured against aomdec's EC_COEFF on `av1-profile1-444.ivf` frame 1:
38299- // plane=1 tx=TX_8X8 per 8x8 block, not a 4:2:0 4x4).
38300- let chroma_side: usize = SIDE >> ss_x(fctx);
38301- let (chroma_set, chroma_scan): (TxbSet, &[u16]) = if chroma_side == 8 {
38554+ // lane-av1-444 / lane-av1-422sub8rect: this 8x8 leaf's chroma plane block
38555+ // is `ss_size_lookup[BLOCK_8X8][ss_x][ss_y]` -- 4:2:0 BLOCK_4X4 (one
38556+ // TX_4X4 unit), 4:4:4 BLOCK_8X8 (ONE TX_8X8 unit, `av1_get_max_uv_txsize`
38557+ // at ss 0/0, measured against aomdec's EC_COEFF on `av1-profile1-444.ivf`
38558+ // frame 1), and 4:2:2 BLOCK_4X8 (ONE TX_4X8 RECT unit per plane, measured
38559+ // on the pinned t422 fixture: frame 1 mi(0,0) reads plane 1 tx_size 5 ==
38560+ // TX_4X8 at rng 55168 right after the agreed luma TX_8X8 txb_skip -- the
38561+ // old `SIDE >> ss_x` square read was the first-divergence defect this
38562+ // port fixes).
38563+ let chroma_w: usize = SIDE >> ss_x(fctx);
38564+ let chroma_h: usize = SIDE >> ss_y(fctx);
38565+ let chroma_422 = ss_x(fctx) == 1 && ss_y(fctx) == 0;
38566+ let (chroma_set, chroma_scan): (TxbSet, &[u16]) = if chroma_422 {
38567+ // `get_txsize_entropy_ctx(TX_4X8)`: the rect fills its plane block,
38568+ // so the tables are the rect set and the SCAN_4X8 walk, exactly the
38569+ // pairing the key-frame BLOCK_4X8 arm (`decode_block`'s lane-av1-422f
38570+ // table) reads byte-exact.
38571+ (TxbSet::ChromaRect8x4, &SCAN_4X8[..])
38572+ } else if chroma_w == 8 {
3830238573 (TxbSet::Chroma8, scan8)
3830338574 } else {
3830438575 (TxbSet::Chroma4, scan4)
3830538576 };
38306- let chroma_tx = if chroma_side == 8 { TX8 } else { TX4 };
38577+ let chroma_tx = if chroma_w == 8 { TX8 } else { TX4 };
3830738578
3830838579 let (r, c) = outer_at;
3830938580 // lane-inter8 r2: this leaf's OWN mi cell, not the enclosing 16x16's --
@@ -38804,13 +39075,13 @@ fn decode_inter_block8(
3880439075 };
3880539076 if let Some(mask_y) = mask_y {
3880639077 mc::blend_masked_compound(
38807- &inter0_y, &inter1_y, mask_y, SIDE, SIDE, SIDE, false, &mut pred_y, fctx,
39078+ &inter0_y, &inter1_y, mask_y, SIDE, SIDE, SIDE, 0, 0, &mut pred_y, fctx,
3880839079 );
3880939080 } else {
3881039081 mc::combine_compound(&inter0_y, &inter1_y, fwd_offset, bck_offset, &mut pred_y, fctx);
3881139082 }
3881239083
38813- let mut inter0_u = vec![0i32; chroma_side * chroma_side];
39084+ let mut inter0_u = vec![0i32; chroma_w * chroma_h];
3881439085 mc::predict_compound_intermediate(
3881539086 &pu0.data,
3881639087 pu0.width,
@@ -38819,13 +39090,13 @@ fn decode_inter_block8(
3881939090 mv_to_q4(cpx, mv0.1, ss_x(fctx)),
3882039091 mv_to_q4(cpy, mv0.0, ss_x(fctx)),
3882139092 scale0,
38822- chroma_side,
38823- chroma_side,
39093+ chroma_w,
39094+ chroma_h,
3882439095 h_filter,
3882539096 v_filter,
3882639097 &mut inter0_u, fctx,
3882739098 );
38828- let mut inter1_u = vec![0i32; chroma_side * chroma_side];
39099+ let mut inter1_u = vec![0i32; chroma_w * chroma_h];
3882939100 mc::predict_compound_intermediate(
3883039101 &pu1.data,
3883139102 pu1.width,
@@ -38834,29 +39105,30 @@ fn decode_inter_block8(
3883439105 mv_to_q4(cpx, mv1.1, ss_x(fctx)),
3883539106 mv_to_q4(cpy, mv1.0, ss_x(fctx)),
3883639107 scale1,
38837- chroma_side,
38838- chroma_side,
39108+ chroma_w,
39109+ chroma_h,
3883939110 h_filter,
3884039111 v_filter,
3884139112 &mut inter1_u, fctx,
3884239113 );
38843- let mut pred_u = refill(std::mem::take(&mut out[1]), chroma_side * chroma_side);
39114+ let mut pred_u = refill(std::mem::take(&mut out[1]), chroma_w * chroma_h);
3884439115 if let Some(mask_y) = mask_y {
3884539116 mc::blend_masked_compound(
3884639117 &inter0_u,
3884739118 &inter1_u,
3884839119 mask_y,
3884939120 SIDE,
38850- chroma_side,
38851- chroma_side,
38852- ss_x(fctx) == 1 && ss_y(fctx) == 1,
39121+ chroma_w,
39122+ chroma_h,
39123+ ss_x(fctx),
39124+ss_y(fctx),
3885339125 &mut pred_u, fctx,
3885439126 );
3885539127 } else {
3885639128 mc::combine_compound(&inter0_u, &inter1_u, fwd_offset, bck_offset, &mut pred_u, fctx);
3885739129 }
3885839130
38859- let mut inter0_v = vec![0i32; chroma_side * chroma_side];
39131+ let mut inter0_v = vec![0i32; chroma_w * chroma_h];
3886039132 mc::predict_compound_intermediate(
3886139133 &pv0.data,
3886239134 pv0.width,
@@ -38865,13 +39137,13 @@ fn decode_inter_block8(
3886539137 mv_to_q4(cpx, mv0.1, ss_x(fctx)),
3886639138 mv_to_q4(cpy, mv0.0, ss_x(fctx)),
3886739139 scale0,
38868- chroma_side,
38869- chroma_side,
39140+ chroma_w,
39141+ chroma_h,
3887039142 h_filter,
3887139143 v_filter,
3887239144 &mut inter0_v, fctx,
3887339145 );
38874- let mut inter1_v = vec![0i32; chroma_side * chroma_side];
39146+ let mut inter1_v = vec![0i32; chroma_w * chroma_h];
3887539147 mc::predict_compound_intermediate(
3887639148 &pv1.data,
3887739149 pv1.width,
@@ -38880,22 +39152,23 @@ fn decode_inter_block8(
3888039152 mv_to_q4(cpx, mv1.1, ss_x(fctx)),
3888139153 mv_to_q4(cpy, mv1.0, ss_x(fctx)),
3888239154 scale1,
38883- chroma_side,
38884- chroma_side,
39155+ chroma_w,
39156+ chroma_h,
3888539157 h_filter,
3888639158 v_filter,
3888739159 &mut inter1_v, fctx,
3888839160 );
38889- let mut pred_v = refill(std::mem::take(&mut out[2]), chroma_side * chroma_side);
39161+ let mut pred_v = refill(std::mem::take(&mut out[2]), chroma_w * chroma_h);
3889039162 if let Some(mask_y) = mask_y {
3889139163 mc::blend_masked_compound(
3889239164 &inter0_v,
3889339165 &inter1_v,
3889439166 mask_y,
3889539167 SIDE,
38896- chroma_side,
38897- chroma_side,
38898- ss_x(fctx) == 1 && ss_y(fctx) == 1,
39168+ chroma_w,
39169+ chroma_h,
39170+ ss_x(fctx),
39171+ss_y(fctx),
3889939172 &mut pred_v, fctx,
3890039173 );
3890139174 } else {
@@ -38910,8 +39183,8 @@ fn decode_inter_block8(
3891039183 push_pred(fctx, build);
3891139184 (
3891239185 Pred::Cur { plane: 0, stride: SIDE, off: 0 },
38913- Pred::Cur { plane: 1, stride: chroma_side, off: 0 },
38914- Pred::Cur { plane: 2, stride: chroma_side, off: 0 },
39186+ Pred::Cur { plane: 1, stride: chroma_w, off: 0 },
39187+ Pred::Cur { plane: 2, stride: chroma_w, off: 0 },
3891539188 )
3891639189 } else {
3891739190 let mut built: [Vec<u16>; 3] = Default::default();
@@ -38920,8 +39193,8 @@ fn decode_inter_block8(
3892039193 (pred_y, pred_u, pred_v) = (by, bu, bv);
3892139194 (
3892239195 Pred::Inline(&pred_y, SIDE),
38923- Pred::Inline(&pred_u, chroma_side),
38924- Pred::Inline(&pred_v, chroma_side),
39196+ Pred::Inline(&pred_u, chroma_w),
39197+ Pred::Inline(&pred_v, chroma_w),
3892539198 )
3892639199 };
3892739200 split8 = read_block_tx_size(
@@ -38938,25 +39211,43 @@ fn decode_inter_block8(
3893839211 .is_some();
3893939212 if skip {
3894039213 push_mc(0, px, py, SIDE, sy, &ZERO_RESIDUAL[..SIDE * SIDE], fctx);
38941- push_mc(1,
39214+ // lane-av1-422sub8rect: the plane block is the (chroma_w,
39215+ // chroma_h) rect at 4:2:2 -- the recorded write is
39216+ // stride `chroma_w`, full `chroma_h` rows.
39217+ push_mc_rect(1,
3894239218 cpx,
3894339219 cpy,
38944- chroma_side,
39220+ chroma_w,
39221+ chroma_w,
39222+ chroma_h,
3894539223 su,
38946- &ZERO_RESIDUAL[..chroma_side * chroma_side], fctx,
39224+ &ZERO_RESIDUAL[..chroma_w * chroma_h], fctx,
3894739225 );
38948- push_mc(2,
39226+ push_mc_rect(2,
3894939227 cpx,
3895039228 cpy,
38951- chroma_side,
39229+ chroma_w,
39230+ chroma_w,
39231+ chroma_h,
3895239232 sv,
38953- &ZERO_RESIDUAL[..chroma_side * chroma_side], fctx,
39233+ &ZERO_RESIDUAL[..chroma_w * chroma_h], fctx,
3895439234 );
3895539235 luma_grid = Grid::Zero(SIDE * SIDE);
38956- u_grid = Grid::Zero(chroma_side * chroma_side);
38957- v_grid = Grid::Zero(chroma_side * chroma_side);
39236+ u_grid = Grid::Zero(chroma_w * chroma_h);
39237+ v_grid = Grid::Zero(chroma_w * chroma_h);
3895839238 } else {
3895939239 let around = neighbours.around_mi(leaf_mi, 8);
39240+ // lane-av1-422sub8rect: the 4:2:2 chroma unit is the
39241+ // TX_4X8 rect -- its `txb_skip_ctx` reads per chroma
39242+ // 4-px cell ([`Neighbours::around_mi_422_chroma`], the
39243+ // key-frame BLOCK_4X8 arm's own context walk), and the
39244+ // coefficients go through the inter rect reader with the
39245+ // inherited luma tx type.
39246+ let chroma_around = if chroma_422 {
39247+ neighbours.around_mi_422_chroma(leaf_mi, 8, 8)
39248+ } else {
39249+ around
39250+ };
3896039251 let (grid8, luma_tx_type) = read_inter_luma8(
3896139252 dec,
3896239253 cdfs,
@@ -38974,42 +39265,82 @@ fn decode_inter_block8(
3897439265 split8, fctx,
3897539266 )?;
3897639267 luma_grid = grid8;
38977- u_grid = read_inter_plane(
38978- dec,
38979- cdfs,
38980- chroma_set,
38981- chroma_scan,
38982- 1,
38983- around[1],
38984- mode_for_tx,
38985- u,
38986- cpx,
38987- cpy,
38988- chroma_side,
38989- base_q_idx,
38990- su,
38991- Some(luma_tx_type),
38992- None, fctx,
38993- )?
38994- .0;
38995- v_grid = read_inter_plane(
38996- dec,
38997- cdfs,
38998- chroma_set,
38999- chroma_scan,
39000- 2,
39001- around[2],
39002- mode_for_tx,
39003- v,
39004- cpx,
39005- cpy,
39006- chroma_side,
39007- base_q_idx,
39008- sv,
39009- Some(luma_tx_type),
39010- None, fctx,
39011- )?
39012- .0;
39268+ u_grid = if chroma_422 {
39269+ read_inter_plane_rect(
39270+ dec,
39271+ cdfs,
39272+ chroma_set,
39273+ (chroma_w, chroma_h),
39274+ chroma_w,
39275+ 1,
39276+ chroma_around[1],
39277+ mode_for_tx,
39278+ u,
39279+ cpx,
39280+ cpy,
39281+ su,
39282+ Some(luma_tx_type),
39283+ None, fctx,
39284+ )?
39285+ .0
39286+ } else {
39287+ read_inter_plane(
39288+ dec,
39289+ cdfs,
39290+ chroma_set,
39291+ chroma_scan,
39292+ 1,
39293+ chroma_around[1],
39294+ mode_for_tx,
39295+ u,
39296+ cpx,
39297+ cpy,
39298+ chroma_w,
39299+ base_q_idx,
39300+ su,
39301+ Some(luma_tx_type),
39302+ None, fctx,
39303+ )?
39304+ .0
39305+ };
39306+ v_grid = if chroma_422 {
39307+ read_inter_plane_rect(
39308+ dec,
39309+ cdfs,
39310+ chroma_set,
39311+ (chroma_w, chroma_h),
39312+ chroma_w,
39313+ 2,
39314+ chroma_around[2],
39315+ mode_for_tx,
39316+ v,
39317+ cpx,
39318+ cpy,
39319+ sv,
39320+ Some(luma_tx_type),
39321+ None, fctx,
39322+ )?
39323+ .0
39324+ } else {
39325+ read_inter_plane(
39326+ dec,
39327+ cdfs,
39328+ chroma_set,
39329+ chroma_scan,
39330+ 2,
39331+ chroma_around[2],
39332+ mode_for_tx,
39333+ v,
39334+ cpx,
39335+ cpy,
39336+ chroma_w,
39337+ base_q_idx,
39338+ sv,
39339+ Some(luma_tx_type),
39340+ None, fctx,
39341+ )?
39342+ .0
39343+ };
3901339344 }
3901439345 // lane-inter8 r2: the COMPOUND leaf used to return here
3901539346 // WITHOUT the end-of-function `record_mi`/`fill_lf_grid` the
@@ -39495,7 +39826,7 @@ fn decode_inter_block8(
3949539826 SIDE,
3949639827 SIDE,
3949739828 SIDE,
39498- chroma_side,
39829+ chroma_w,
3949939830 px,
3950039831 py,
3950139832 cpx,
@@ -39503,6 +39834,7 @@ fn decode_inter_block8(
3950339834 refpix,
3950439835 interp_fixed,
3950539836 frame_width,
39837+ (ss_x(fctx), ss_y(fctx)),
3950639838 )?)
3950739839 } else {
3950839840 None
@@ -39519,15 +39851,15 @@ fn decode_inter_block8(
3951939851 return;
3952039852 };
3952139853 let mut pred_y = refill(std::mem::take(&mut out[0]), SIDE * SIDE);
39522- let mut pred_u = refill(std::mem::take(&mut out[1]), chroma_side * chroma_side);
39523- let mut pred_v = refill(std::mem::take(&mut out[2]), chroma_side * chroma_side);
39854+ let mut pred_u = refill(std::mem::take(&mut out[1]), chroma_w * chroma_h);
39855+ let mut pred_v = refill(std::mem::take(&mut out[2]), chroma_w * chroma_h);
3952439856 // Merge of lane-gmaffine (this leaf's own switchable filters) with
3952539857 // lane-scaledref (spec 7.11.3.3's scaled walk): same kernels either
3952639858 // way, only the sample walk differs.
39527- for (plane, x, y, dim, dst) in [
39528- (sref_y, px, py, SIDE, &mut pred_y),
39529- (sref_u, cpx, cpy, chroma_side, &mut pred_u),
39530- (sref_v, cpx, cpy, chroma_side, &mut pred_v),
39859+ for (plane, x, y, (dim_w, dim_h), dst) in [
39860+ (sref_y, px, py, (SIDE, SIDE), &mut pred_y),
39861+ (sref_u, cpx, cpy, (chroma_w, chroma_h), &mut pred_u),
39862+ (sref_v, cpx, cpy, (chroma_w, chroma_h), &mut pred_v),
3953139863 ] {
3953239864 let luma = std::ptr::eq(plane, sref_y);
3953339865 if luma_scale == mc::REF_NO_SCALE {
@@ -39538,8 +39870,8 @@ fn decode_inter_block8(
3953839870 plane.true_height,
3953939871 mv_to_q4(x, mv.1, if luma { 0 } else { ss_x(fctx) }),
3954039872 mv_to_q4(y, mv.0, if luma { 0 } else { ss_y(fctx) }),
39541- dim,
39542- dim,
39873+ dim_w,
39874+ dim_h,
3954339875 h_filter,
3954439876 v_filter,
3954539877 dst, fctx,
@@ -39553,8 +39885,8 @@ fn decode_inter_block8(
3955339885 mv_to_q4(x, mv.1, if luma { 0 } else { ss_x(fctx) }),
3955439886 mv_to_q4(y, mv.0, if luma { 0 } else { ss_y(fctx) }),
3955539887 luma_scale,
39556- dim,
39557- dim,
39888+ dim_w,
39889+ dim_h,
3955839890 h_filter,
3955939891 v_filter,
3956039892 dst, fctx,
@@ -39576,19 +39908,21 @@ fn decode_inter_block8(
3957639908 SIDE as i32, SIDE as i32, 0, 0, fctx,
3957739909 );
3957839910 // `av1_init_warp_params`'s per-plane `block_width/height < 8`
39579- // bail-out: an 8x8 leaf's chroma plane is 4x4 in 420, so it is
39580- // predicted translationally even when the luma warps.
39911+ // bail-out: an 8x8 leaf's chroma plane block is narrower than 8
39912+ // at any subsampled format (4:2:0 4x4, 4:2:2 4x8), so it is
39913+ // predicted translationally even when the luma warps; 4:4:4's
39914+ // 8x8 chroma warps with the luma.
3958139915 #[allow(clippy::absurd_extreme_comparisons)]
39582- if chroma_side >= 8 {
39916+ if chroma_w >= 8 {
3958339917 crate::warp::warp_affine(
3958439918 params, &sref_u.data, sref_u.true_width as i32, sref_u.true_height as i32,
39585- sref_u.width as i32, &mut pred_u, cpx as i32, cpy as i32, chroma_side as i32,
39586- chroma_side as i32, chroma_side as i32, ss_x(fctx) as i32, ss_y(fctx) as i32, fctx,
39919+ sref_u.width as i32, &mut pred_u, cpx as i32, cpy as i32, chroma_w as i32,
39920+ chroma_h as i32, chroma_w as i32, ss_x(fctx) as i32, ss_y(fctx) as i32, fctx,
3958739921 );
3958839922 crate::warp::warp_affine(
3958939923 params, &sref_v.data, sref_v.true_width as i32, sref_v.true_height as i32,
39590- sref_v.width as i32, &mut pred_v, cpx as i32, cpy as i32, chroma_side as i32,
39591- chroma_side as i32, chroma_side as i32, ss_x(fctx) as i32, ss_y(fctx) as i32, fctx,
39924+ sref_v.width as i32, &mut pred_v, cpx as i32, cpy as i32, chroma_w as i32,
39925+ chroma_h as i32, chroma_w as i32, ss_x(fctx) as i32, ss_y(fctx) as i32, fctx,
3959239926 );
3959339927 }
3959439928 }
@@ -39600,12 +39934,14 @@ fn decode_inter_block8(
3960039934 // Non-wedge interintra blend, mutually exclusive with OBMC (the
3960139935 // motion_mode symbol is not read for an interintra block).
3960239936 if let Some(ii) = interintra_mode {
39603- interintra_blend(y, px, py, SIDE, SIDE, SIDE, ii, wedge_mask, &mut pred_y, fctx);
39937+ interintra_blend(y, px, py, SIDE, SIDE, SIDE, 0, 0, ii, wedge_mask, &mut pred_y, fctx);
3960439938 interintra_blend(
39605- u, cpx, cpy, chroma_side, chroma_side, chroma_side, ii, wedge_mask, &mut pred_u, fctx,
39939+ u, cpx, cpy, chroma_w, chroma_h, chroma_w, ss_x(fctx), ss_y(fctx), ii, wedge_mask,
39940+ &mut pred_u, fctx,
3960639941 );
3960739942 interintra_blend(
39608- v, cpx, cpy, chroma_side, chroma_side, chroma_side, ii, wedge_mask, &mut pred_v, fctx,
39943+ v, cpx, cpy, chroma_w, chroma_h, chroma_w, ss_x(fctx), ss_y(fctx), ii, wedge_mask,
39944+ &mut pred_v, fctx,
3960939945 );
3961039946 }
3961139947
@@ -39617,8 +39953,8 @@ fn decode_inter_block8(
3961739953 push_pred(fctx, build);
3961839954 (
3961939955 Pred::Cur { plane: 0, stride: SIDE, off: 0 },
39620- Pred::Cur { plane: 1, stride: chroma_side, off: 0 },
39621- Pred::Cur { plane: 2, stride: chroma_side, off: 0 },
39956+ Pred::Cur { plane: 1, stride: chroma_w, off: 0 },
39957+ Pred::Cur { plane: 2, stride: chroma_w, off: 0 },
3962239958 )
3962339959 } else {
3962439960 // The interintra predictor reads this block's own above/left
@@ -39633,8 +39969,8 @@ fn decode_inter_block8(
3963339969 (pred_y, pred_u, pred_v) = (by, bu, bv);
3963439970 (
3963539971 Pred::Inline(&pred_y, SIDE),
39636- Pred::Inline(&pred_u, chroma_side),
39637- Pred::Inline(&pred_v, chroma_side),
39972+ Pred::Inline(&pred_u, chroma_w),
39973+ Pred::Inline(&pred_v, chroma_w),
3963839974 )
3963939975 };
3964039976 split8 = read_block_tx_size(
@@ -39651,25 +39987,43 @@ fn decode_inter_block8(
3965139987 .is_some();
3965239988 if skip {
3965339989 push_mc(0, px, py, SIDE, sy, &ZERO_RESIDUAL[..SIDE * SIDE], fctx);
39654- push_mc(1,
39990+ // lane-av1-422sub8rect: the plane block is the (chroma_w,
39991+ // chroma_h) rect at 4:2:2 -- the recorded write is stride
39992+ // `chroma_w`, full `chroma_h` rows.
39993+ push_mc_rect(1,
3965539994 cpx,
3965639995 cpy,
39657- chroma_side,
39996+ chroma_w,
39997+ chroma_w,
39998+ chroma_h,
3965839999 su,
39659- &ZERO_RESIDUAL[..chroma_side * chroma_side], fctx,
40000+ &ZERO_RESIDUAL[..chroma_w * chroma_h], fctx,
3966040001 );
39661- push_mc(2,
40002+ push_mc_rect(2,
3966240003 cpx,
3966340004 cpy,
39664- chroma_side,
40005+ chroma_w,
40006+ chroma_w,
40007+ chroma_h,
3966540008 sv,
39666- &ZERO_RESIDUAL[..chroma_side * chroma_side], fctx,
40009+ &ZERO_RESIDUAL[..chroma_w * chroma_h], fctx,
3966740010 );
3966840011 luma_grid = Grid::Zero(SIDE * SIDE);
39669- u_grid = Grid::Zero(chroma_side * chroma_side);
39670- v_grid = Grid::Zero(chroma_side * chroma_side);
40012+ u_grid = Grid::Zero(chroma_w * chroma_h);
40013+ v_grid = Grid::Zero(chroma_w * chroma_h);
3967140014 } else {
3967240015 let around = neighbours.around_mi(leaf_mi, 8);
40016+ // lane-av1-422sub8rect: the 4:2:2 chroma unit is the TX_4X8
40017+ // rect -- its `txb_skip_ctx` reads per chroma 4-px cell
40018+ // ([`Neighbours::around_mi_422_chroma`], the key-frame
40019+ // BLOCK_4X8 arm's own context walk), and the coefficients go
40020+ // through the inter rect reader with the inherited luma tx
40021+ // type.
40022+ let chroma_around = if chroma_422 {
40023+ neighbours.around_mi_422_chroma(leaf_mi, 8, 8)
40024+ } else {
40025+ around
40026+ };
3967340027 let (grid8, luma_tx_type) = read_inter_luma8(
3967440028 dec,
3967540029 cdfs,
@@ -39687,42 +40041,82 @@ fn decode_inter_block8(
3968740041 split8, fctx,
3968840042 )?;
3968940043 luma_grid = grid8;
39690- u_grid = read_inter_plane(
39691- dec,
39692- cdfs,
39693- chroma_set,
39694- chroma_scan,
39695- 1,
39696- around[1],
39697- mode_for_tx,
39698- u,
39699- cpx,
39700- cpy,
39701- chroma_side,
39702- base_q_idx,
39703- su,
39704- Some(luma_tx_type),
39705- None, fctx,
39706- )?
39707- .0;
39708- v_grid = read_inter_plane(
39709- dec,
39710- cdfs,
39711- chroma_set,
39712- chroma_scan,
39713- 2,
39714- around[2],
39715- mode_for_tx,
39716- v,
39717- cpx,
39718- cpy,
39719- chroma_side,
39720- base_q_idx,
39721- sv,
39722- Some(luma_tx_type),
39723- None, fctx,
39724- )?
39725- .0;
40044+ u_grid = if chroma_422 {
40045+ read_inter_plane_rect(
40046+ dec,
40047+ cdfs,
40048+ chroma_set,
40049+ (chroma_w, chroma_h),
40050+ chroma_w,
40051+ 1,
40052+ chroma_around[1],
40053+ mode_for_tx,
40054+ u,
40055+ cpx,
40056+ cpy,
40057+ su,
40058+ Some(luma_tx_type),
40059+ None, fctx,
40060+ )?
40061+ .0
40062+ } else {
40063+ read_inter_plane(
40064+ dec,
40065+ cdfs,
40066+ chroma_set,
40067+ chroma_scan,
40068+ 1,
40069+ chroma_around[1],
40070+ mode_for_tx,
40071+ u,
40072+ cpx,
40073+ cpy,
40074+ chroma_w,
40075+ base_q_idx,
40076+ su,
40077+ Some(luma_tx_type),
40078+ None, fctx,
40079+ )?
40080+ .0
40081+ };
40082+ v_grid = if chroma_422 {
40083+ read_inter_plane_rect(
40084+ dec,
40085+ cdfs,
40086+ chroma_set,
40087+ (chroma_w, chroma_h),
40088+ chroma_w,
40089+ 2,
40090+ chroma_around[2],
40091+ mode_for_tx,
40092+ v,
40093+ cpx,
40094+ cpy,
40095+ sv,
40096+ Some(luma_tx_type),
40097+ None, fctx,
40098+ )?
40099+ .0
40100+ } else {
40101+ read_inter_plane(
40102+ dec,
40103+ cdfs,
40104+ chroma_set,
40105+ chroma_scan,
40106+ 2,
40107+ chroma_around[2],
40108+ mode_for_tx,
40109+ v,
40110+ cpx,
40111+ cpy,
40112+ chroma_w,
40113+ base_q_idx,
40114+ sv,
40115+ Some(luma_tx_type),
40116+ None, fctx,
40117+ )?
40118+ .0
40119+ };
3972640120 }
3972740121 } else {
3972840122 let mode = dec.symbol(&mut cdfs.y_mode[SIZE_GROUP_8]);
@@ -39932,17 +40326,17 @@ fn decode_inter_block8(
3993240326 PaletteY { size: n, colors, map }
3993340327 });
3993440328 let palette_uv = palette_uv_pending.map(|(n, u_colors, v_colors)| {
39935- // `av1_get_plane_block_size(BLOCK_8X8, 1, 1)` at the sequence's
39936- // own subsampling: BLOCK_4X4 at 4:2:0, BLOCK_8X8 at 4:4:4
39937- // (`chroma_side`, lane-av1-444).
40329+ // `av1_get_plane_block_size(BLOCK_8X8, ss)` at the sequence's own
40330+ // subsampling: BLOCK_4X4 at 4:2:0, BLOCK_8X8 at 4:4:4, and at
40331+ // 4:2:2 the BLOCK_4X8 plane block (lane-av1-422sub8rect).
3993840332 let on = palette_onscreen_uv(
3993940333 (SIDE, SIDE),
3994040334 palette_onscreen(rmi, cmi, SIDE, SIDE, fctx),
39941- (chroma_side, chroma_side),
40335+ (chroma_w, chroma_h),
3994240336 (ss_x(fctx), ss_y(fctx)),
3994340337 );
3994440338 let map =
39945- decode_color_index_map_wh(dec, cdfs, n, chroma_side, chroma_side, on, true);
40339+ decode_color_index_map_wh(dec, cdfs, n, chroma_w, chroma_h, on, true);
3994640340 hit!(PALETTE_UV_HITS);
3994740341 hit!(INTRA_IN_INTER_PALETTE_UV_HITS);
3994840342 hit_do! {
@@ -40113,14 +40507,18 @@ fn decode_inter_block8(
4011340507 if let Some((ub, _)) = &palette_uv_bufs {
4011440508 set_palette_pred(ub.clone(), fctx);
4011540509 }
40116- push_intra(1,
40510+ // lane-av1-422sub8rect: the plane block is the (chroma_w,
40511+ // chroma_h) rect at 4:2:2 -- the recorded prediction/write uses
40512+ // the rect push.
40513+ push_intra_rect(1,
4011740514 cpx,
4011840515 cpy,
40119- chroma_side,
40516+ chroma_w,
40517+ chroma_h,
4012040518 uv_predict_mode,
4012140519 angle_delta_uv,
4012240520 reach,
40123- &ZERO_RESIDUAL[..chroma_side * chroma_side],
40521+ &ZERO_RESIDUAL[..chroma_w * chroma_h],
4012440522 alpha.zip(ac).map(|((au, _), ac)| (au, ac)),
4012540523 None,
4012640524 smooth_neighbor_uv, fctx,
@@ -40128,21 +40526,22 @@ fn decode_inter_block8(
4012840526 if let Some((_, vb)) = &palette_uv_bufs {
4012940527 set_palette_pred(vb.clone(), fctx);
4013040528 }
40131- push_intra(2,
40529+ push_intra_rect(2,
4013240530 cpx,
4013340531 cpy,
40134- chroma_side,
40532+ chroma_w,
40533+ chroma_h,
4013540534 uv_predict_mode,
4013640535 angle_delta_uv,
4013740536 reach,
40138- &ZERO_RESIDUAL[..chroma_side * chroma_side],
40537+ &ZERO_RESIDUAL[..chroma_w * chroma_h],
4013940538 alpha.zip(ac).map(|((_, av), ac)| (av, ac)),
4014040539 None,
4014140540 smooth_neighbor_uv, fctx,
4014240541 );
4014340542 luma_grid = Grid::Zero(SIDE * SIDE);
40144- u_grid = Grid::Zero(chroma_side * chroma_side);
40145- v_grid = Grid::Zero(chroma_side * chroma_side);
40543+ u_grid = Grid::Zero(chroma_w * chroma_h);
40544+ v_grid = Grid::Zero(chroma_w * chroma_h);
4014640545 } else {
4014740546 let around = neighbours.around_mi(leaf_mi, 8);
4014840547 luma_grid = if split8 {
@@ -40186,56 +40585,89 @@ fn decode_inter_block8(
4018640585 )?
4018740586 };
4018840587 let ac = alpha.map(|_| cfl_src(px, py, SIDE));
40588+ // lane-av1-422sub8rect: at 4:2:2 the plane block is the BLOCK_4X8
40589+ // rect and the key-frame arm's own reader applies -- one
40590+ // TX_4X8 `ChromaRect8x4` unit per plane through
40591+ // [`read_rect_chroma_unit`] with the per-chroma-cell context
40592+ // walk ([`Neighbours::around_mi_422_chroma`], the
40593+ // lane-av1-422f model this leaf's key-frame twin proves
40594+ // byte-exact). 4:2:0/4:4:4 keep the square [`read_plane`] read.
40595+ let (chroma_around_u, chroma_around_v) = if chroma_422 {
40596+ let ca = neighbours.around_mi_422_chroma(leaf_mi, 8, 8);
40597+ (ca[1], ca[2])
40598+ } else {
40599+ (around[1], around[2])
40600+ };
4018940601 if let Some((ub, _)) = &palette_uv_bufs {
4019040602 set_palette_pred(ub.clone(), fctx);
4019140603 }
40192- u_grid = read_plane(
40193- dec,
40194- cdfs,
40195- chroma_set,
40196- chroma_scan,
40197- 1,
40198- around[1],
40199- mode,
40200- uv_predict_mode,
40201- angle_delta_uv,
40202- reach,
40203- u,
40204- cpx,
40205- cpy,
40206- chroma_side,
40207- chroma_tx,
40208- base_q_idx,
40209- alpha.zip(ac).map(|((au, _), ac)| (au, ac)),
40210- None,
40211- None,
40212- smooth_neighbor_uv, fctx,
40213- )?;
40604+ u_grid = if chroma_422 {
40605+ read_rect_chroma_unit(
40606+ dec, cdfs, chroma_set, chroma_scan, chroma_w, chroma_h, 1,
40607+ chroma_around_u, uv_predict_mode, angle_delta_uv, reach, u,
40608+ cpx, cpy, base_q_idx, None,
40609+ alpha.zip(ac).map(|((au, _), ac)| (au, ac)),
40610+ smooth_neighbor_uv, fctx,
40611+ )?
40612+ } else {
40613+ read_plane(
40614+ dec,
40615+ cdfs,
40616+ chroma_set,
40617+ chroma_scan,
40618+ 1,
40619+ chroma_around_u,
40620+ mode,
40621+ uv_predict_mode,
40622+ angle_delta_uv,
40623+ reach,
40624+ u,
40625+ cpx,
40626+ cpy,
40627+ chroma_w,
40628+ chroma_tx,
40629+ base_q_idx,
40630+ alpha.zip(ac).map(|((au, _), ac)| (au, ac)),
40631+ None,
40632+ None,
40633+ smooth_neighbor_uv, fctx,
40634+ )?
40635+ };
4021440636 if let Some((_, vb)) = &palette_uv_bufs {
4021540637 set_palette_pred(vb.clone(), fctx);
4021640638 }
40217- v_grid = read_plane(
40218- dec,
40219- cdfs,
40220- chroma_set,
40221- chroma_scan,
40222- 2,
40223- around[2],
40224- mode,
40225- uv_predict_mode,
40226- angle_delta_uv,
40227- reach,
40228- v,
40229- cpx,
40230- cpy,
40231- chroma_side,
40232- chroma_tx,
40233- base_q_idx,
40234- alpha.zip(ac).map(|((_, av), ac)| (av, ac)),
40235- None,
40236- None,
40237- smooth_neighbor_uv, fctx,
40238- )?;
40639+ v_grid = if chroma_422 {
40640+ read_rect_chroma_unit(
40641+ dec, cdfs, chroma_set, chroma_scan, chroma_w, chroma_h, 2,
40642+ chroma_around_v, uv_predict_mode, angle_delta_uv, reach, v,
40643+ cpx, cpy, base_q_idx, None,
40644+ alpha.zip(ac).map(|((_, av), ac)| (av, ac)),
40645+ smooth_neighbor_uv, fctx,
40646+ )?
40647+ } else {
40648+ read_plane(
40649+ dec,
40650+ cdfs,
40651+ chroma_set,
40652+ chroma_scan,
40653+ 2,
40654+ chroma_around_v,
40655+ mode,
40656+ uv_predict_mode,
40657+ angle_delta_uv,
40658+ reach,
40659+ v,
40660+ cpx,
40661+ cpy,
40662+ chroma_w,
40663+ chroma_tx,
40664+ base_q_idx,
40665+ alpha.zip(ac).map(|((_, av), ac)| (av, ac)),
40666+ None,
40667+ None,
40668+ smooth_neighbor_uv, fctx,
40669+ )?
40670+ };
4023940671 }
4024040672 }
4024140673 // lane-txselect: a split leaf's plane-0 neighbour context is per 4x4
crates/ec-av1/src/encode.rsmodified+1 -0
@@ -6809,6 +6809,7 @@ fn obmc_prediction(
68096809 &refpix,
68106810 Some(fctx.interp_filter.get()),
68116811 frame_width,
6812+ (crate::decode::ss_x(fctx), crate::decode::ss_y(fctx)),
68126813 )
68136814 .ok()?;
68146815 let mut pred = [
crates/ec-av1/src/mc.rsmodified+31 -14
@@ -2142,8 +2142,11 @@ pub(crate) fn diffwtd_mask(
21422142 /// (64-m)*pred1) >> 6` (a plain, unrounded shift, matching the C `>>` on
21432143 /// `int32_t`) then one final [`round2`] by [`INTER_POST_ROUND`]. `mask` is
21442144 /// always the LUMA-resolution mask (`mask_stride` == luma block width);
2145-/// `subsampled` selects the 2x2-average chroma read (spec 7.11.3.14 /
2146-/// libaom's `subw == 1 && subh == 1` branch) vs. the direct luma read.
2145+/// `(subw, subh)` are the PLANE's own subsampling shifts and pick the mask
2146+/// read exactly as aom_dsp/blend-a64-mask.c's four `subw`/`subh` branches do:
2147+/// `(0, 0)` the direct luma sample, `(1, 1)` the 2x2 box average,
2148+/// `(1, 0)`/`(0, 1)` the `AOM_BLEND_AVG` pair average on the subsampled axis
2149+/// alone (4:2:2).
21472150 #[allow(clippy::too_many_arguments)]
21482151 pub(crate) fn blend_masked_compound(
21492152 pred0: &[i32],
@@ -2152,7 +2155,8 @@ pub(crate) fn blend_masked_compound(
21522155 mask_stride: usize,
21532156 w: usize,
21542157 h: usize,
2155- subsampled: bool,
2158+ subw: usize,
2159+ subh: usize,
21562160 dst: &mut [u16],
21572161 fctx: &crate::decode::FrameCtx,
21582162 ) {
@@ -2162,17 +2166,30 @@ pub(crate) fn blend_masked_compound(
21622166 let post_round = INTER_POST_ROUND - round_delta(u32::from(crate::decode::bit_depth(fctx)));
21632167 for i in 0..h {
21642168 for j in 0..w {
2165- let m = if subsampled {
2166- let idx = (2 * i) * mask_stride + 2 * j;
2167- round2(
2168- i32::from(mask[idx])
2169- + i32::from(mask[idx + 1])
2170- + i32::from(mask[idx + mask_stride])
2171- + i32::from(mask[idx + mask_stride + 1]),
2172- 2,
2173- )
2174- } else {
2175- i32::from(mask[i * mask_stride + j])
2169+ let m: i32 = match (subw, subh) {
2170+ (0, 0) => i32::from(mask[i * mask_stride + j]),
2171+ (1, 1) => {
2172+ let idx = (2 * i) * mask_stride + 2 * j;
2173+ round2(
2174+ i32::from(mask[idx])
2175+ + i32::from(mask[idx + 1])
2176+ + i32::from(mask[idx + mask_stride])
2177+ + i32::from(mask[idx + mask_stride + 1]),
2178+ 2,
2179+ )
2180+ }
2181+ // aom_blend_a64_mask_c's `subw == 1 && subh == 0` branch:
2182+ // `AOM_BLEND_AVG(mask[2 * j], mask[2 * j + 1])` per row.
2183+ (1, 0) => {
2184+ let idx = i * mask_stride + 2 * j;
2185+ (i32::from(mask[idx]) + i32::from(mask[idx + 1]) + 1) >> 1
2186+ }
2187+ // the `subw == 0 && subh == 1` branch: averaged down the
2188+ // columns instead.
2189+ (_sw, _sh) => {
2190+ let idx = (2 * i) * mask_stride + j;
2191+ (i32::from(mask[idx]) + i32::from(mask[idx + mask_stride]) + 1) >> 1
2192+ }
21762193 };
21772194 let res = (m * pred0[i * w + j] + (64 - m) * pred1[i * w + j]) >> 6;
21782195 // `post_round` above: `INTER_POST_ROUND - round_delta` -- see
lanes/av1422sub8rect.report.mdadded+132 -0
@@ -0,0 +1,132 @@
1+# lane-av1-422sub8rect — the sub-8x8 inter 4:2:2 chroma ported to its real
2+# shapes (`decode_inter_block8`'s whole chroma half to the BLOCK_4X8 rect;
3+# `decode_inter_sub8_split4`'s group unit replaced by the per-piece
4+# odd-column chroma-reference model the oracle traces actually code); frame
5+# 0 stays byte-exact at all four stages, the 4:2:0/4:4:4 identity holds by
6+# ss-keying, and the inter-frame divergence is REMEASURED (reduced ~15% on
7+# frames 1..10, exactness NOT claimed -- other 4:2:2 classes remain)
8+
9+## Outcome
10+
11+1. ROOT-CAUSE CONFIRMATION FIRST (pinned fixture `/tmp/t422.obu` sha256
12+ `d3fa4beeb1309033e4a03f5ae5c431c8fa8386ba1ada088684710423c7938129`,
13+ parent-lane instruments in `/tmp/i422/`, local `EC_AV1_ALLOW_422_PROBE`
14+ bypass applied and reverted byte-identical after — `git diff` carries
15+ only decode.rs/mc.rs/encode.rs changes): the oracle's frame-1 first
16+ block (`AOMMB mi=(0,0) ... skip=0`) reads luma TX_8X8 then
17+ `plane=1 tx_size=5 mi_row=0 mi_col=0 rng=55168` — tx_size 5 IS TX_4X8,
18+ confirming the charter: the 8x8 inter leaf's chroma plane block is
19+ BLOCK_4X8, one TX_4X8 rect unit per plane (`ss_size_lookup[BLOCK_8X8][1][0]`),
20+ while ours read a TX_4X4 square.
21+2. SPLIT4 MODEL CORRECTED AGAINST THE ORACLE, NOT THE CHARTER'S GUESS: the
22+ parent report assumed the split4 group codes ONE rect group unit; the
23+ traces prove otherwise. At ss (1,0) `is_chroma_reference` for a BLOCK_4X4
24+ piece is `(mi_col & 0x01)` — ODD columns only (av1_common_int.h:1459) —
25+ and every non-skipped odd-column piece codes its OWN U then V TX_4X4
26+ square unit right after its luma, anchored at the FLOORED chroma cell
27+ (`(mi_col & !1) * MI >> ss_x`, the lane-av1-422kf2 rule) with
28+ `around_mi_422_chroma`-style per-chroma-cell ctx (measured ctx 8 =
29+ above+left+7 at frame 1's mi(12,3)):
30+ - frame 0 key-frame groups (18,54) and (30,42): U+V read on BOTH
31+ odd-column leaves ((18,55)+(19,55), (30,43)+(31,43));
32+ - frame 1 inter group at mi(12,2): U+V on leaf (12,3) ALONE — its
33+ bottom-right twin was skipped, so it codes nothing.
34+ The 4:2:0 shared group unit simply never exists at 4:2:2.
35+3. PORT (all keyed on ss, 4:2:0/4:4:4 byte-identical by construction):
36+ - `decode_inter_block8` chroma half to per-axis shapes: `chroma_w/chroma_h`,
37+ `(TxbSet::ChromaRect8x4, SCAN_4X8)` at 4:2:2; inter coefficient reads
38+ through `read_inter_plane_rect` (offset-7 ctx — the unit IS the plane
39+ block — inherited luma tx type) with `around_mi_422_chroma`; MC
40+ prediction (single-ref, scaled, warp, compound-intermediate), the
41+ wedge-masked blend, interintra blend, OBMC pushes and skip pushes all
42+ (4, 8)-shaped; the intra-in-inter arm reads the key-frame arm's own
43+ rect reader (`read_rect_chroma_unit`, ctx offset None, CfL carried);
44+ palette UV map dims per axis.
45+ - `decode_inter_sub8_split4`: per-piece arm added after each inter
46+ piece's luma (odd column, ss 1,0): prediction as
47+ `build_inter_predictors_sub8x8` — left 2x4 half from the LEFT piece's
48+ own ref/mv/filters, right 2x4 half from this piece's; a mixed group
49+ (left piece intra/off-frame, `is_sub8x8_inter` false) predicts the
50+ whole 4x4 from this piece; skip pieces still predict but record zeros.
51+ Coefficients via square `TxbSet::Chroma4` reads at the floored anchor,
52+ per-unit `record_mi_chroma` (8x4 luma span). Intra pieces gate
53+ `has_chroma` on the piece's own column parity and route through
54+ [`sub8_leaf_chroma422`]; even-column intra pieces publish DC to the
55+ uv-mode map. The 4:2:0 group tail (build, read, band stamps, DC map
56+ stamp) is gated OFF at 4:2:2.
57+ - Shared helpers made ss-exact (4:2:0/4:4:4 reduce to the old behaviour):
58+ `blend_masked_compound`'s `subsampled: bool` → per-axis `(subw, subh)`
59+ mirroring aom_dsp/blend-a64-mask.c's four branches; `interintra_blend`'s
60+ wedge mask read likewise; `obmc_plan`/`obmc_run` take the plane ss —
61+ chroma extents are the luma rules `>> ss` (`av1_skip_u4x4_pred_in_obmc`
62+ keyed on the plane block, above-pass skip and left-pass blend extents),
63+ `TxParams::strided` sized `stride * h` (identical when h == stride, as
64+ every pre-existing caller has). The encoder's `obmc_plan` call passes
65+ the fctx ss.
66+ - STOP-NOTE (owning parent-lane surface, named not fixed):
67+ `decode_inter_block`'s 4:2:2 chroma is still the square-cut model; its
68+ chroma masked-blend keeps the pre-port direct mask read there (guarded
69+ by `ss_x == ss_y`), because its `chroma_side`-square buffers cannot be
70+ indexed by the subsampled-axis walks. Known-divergent, unchanged
71+ behaviour, named for the owning lane.
72+4. MEASURED after the port (17-frame probe run under the reverted bypass;
73+ comparator: ours padded 256x160/128x160 u8 cropped vs the instrumented
74+ `$HOME/.cache/aom-oracle/build` aomdec):
75+ - frame 0: **byte-exact at PREFILT, POSTCDEF (and FINAL by the u16
76+ comparator) on Y, U and V — 0 diffs everywhere**, so the rect read,
77+ the split4 per-piece model and every shared-helper change are exact on
78+ everything frame 0 exercises (including the split groups (18,54),
79+ (30,42) that motivated the per-piece model).
80+ - inter frames 1..10 decode and were measured: PREFILT diffs dropped
81+ ~15% vs the parent lane's ladder (e.g. frame 1: 30825/12624/12796 →
82+ 22248/11733/11974; frame 8: 35014/11020/12043 → 32855/11020/12043;
83+ per-frame values in `/tmp/i422/sub8rect/`). **Frame exactness is NOT
84+ claimed** — frames 1..10 remain divergent: the named sub-8 sites are
85+ fixed, but the stream carries further 4:2:2 classes the decoder still
86+ square-cuts or gaps (probe trace: `EC_RECTCHROMA_GAP luma=16x8
87+ tx=16x8 chroma=8x8`, `luma=8x32 ... chroma=4x32`, i.e. `decode_inter_block`'s
88+ own 4:2:2 chroma half), so the entropy walk desyncs again after the
89+ first uncoded-for block.
90+ - frames 11..16 were not reached by the probe's frame accounting this
91+ round (11 dumped frames, decode exits 0 — the dump-index vs
92+ show-existing accounting needs the parent-lane harness's
93+ 1-frame-per-OBU walk); the ladder for 1..16 is the owning lane's
94+ re-measurement once the next class lands.
95+5. Deferred items: (a) frames 11..16 ladder entries — unblock: rerun the
96+ parent-lane per-OBU cut harness (`/tmp/i422/cut_frames.py`) after the
97+ next class; (b) `decode_inter_sub8_rect2`'s 4:2:2 has_chroma gating (its
98+ inter strips pass `i == 1` where BLOCK_4X8 needs odd-column parity) —
99+ not one of this charter's named sites, unmeasured on the fixture so far.
100+
101+## Decision
102+
103+- The header refusal STAYS unconditional in `stream.rs`; the bypass was
104+ local-only, applied and reverted byte-identical (0 occurrences left;
105+ `stream::tests` green after the revert).
106+- 4:2:0/4:4:4 untouched by construction (ss-keyed arms); the 4:2:0
107+ group-tail SKIP arm untouched; `read_coeffs_rect` untouched.
108+
109+## Verification
110+
111+- `cargo check -p ec-av1` (target `~/.cache/cargo-target-av1422sub8rect`):
112+ 0 warnings, 0 errors.
113+- `stream::tests::a_non_420_subsampled_sequence_header_is_refused_by_name`:
114+ 1 passed — the refusal fires after the bypass revert.
115+- `stream::tests::a_real_aomenc_stream_with_a_skipped_8x8_intra_leaf_
116+ whose_tx_split_decodes_pixel_exact` under `EC_AV1_REQUIRE_AOMENC=1`
117+ (oracle aomenc): 1 passed — the 4:2:0 inter path, including the
118+ shared-helper ss-ifications, stays pixel-exact.
119+- Frame-0 stage dumps vs the instrumented aomdec: PREFILT/POSTCDEF
120+ Y=U=V=0 (POSTDEB comparator run this round used the wrong dump-env name;
121+ the post-deblock state is bracketed by the two exact stages).
122+- Hit counter added: `CHROMA422_INTER_SUB8_HITS` (per-piece inter 4:2:2
123+ chroma units) — reads non-zero on the fixture's frames 1+, so the new arm
124+ provably fires.
125+
126+## State
127+
128+- Commit on lane-av1-422sub8rect (no push): the sub-8 rect port +
129+ `TxParams::strided` sizing fix + shared ss-exact helpers + this report.
130+- Probe instruments regenerated under `/tmp/i422/sub8rect/` (scratch, not
131+ committed); the oracle build's rungs already cover everything needed to
132+ re-measure after the next class.