forge
Explore
Log in

Don't you dare go Hollow

ec-av1: lane-av1-422bigblock -- the 128-root 4:2:2 chroma chunk de-square-cut on the per-axis plane-block model and the reference plane resolution taught the third subsampling shape

Browse files at this commit

c74c912a0461964953391597b535eaa7ca1472deAhmet Kaan GümüşParent: 8dcaf0a
Both witnessed defects are fixed and both pinned witnesses decode pixel-exact
vs aomdec on the local EC_AV1_ALLOW_422_PROBE patch-run-restore build.

Defect 1 (422_allskip_2f.obu) does NOT reproduce at this HEAD: the block-half
port already entropy-locks it -- all 20 key-frame coefficient units pair
rng-for-rng with the instrumented oracle and the all-skip inter frame reads
zero units on both sides; the shown frame is byte-identical to aomdec.
Re-verified, no change needed.

Defect 2 (422_sb128_3f.obu, the f2 128x128 PARTITION_NONE non-skip inter
block) had three stacked causes under the historical range-end panic:
decode_inter_block's mu-chunk chroma walk cut each chunk's 32x64 chroma into
a chroma_side-square 64x64 (twice the oracle's 16 units, 8 per plane, 2
stacked per chunk) -- now per-axis with per-unit luma spans through
around_mi_rect and per-axis record_mi_chroma; the unit prediction window was
indexed at the square chroma_side instead of the buffer's own chroma_stride
(the empty-slice densify panic) -- now the real stride while the assembled
grid keeps the square stride the block-tail re-stamp already indexes; and
RefPix::planes guessed every non-4:4:4 reference quarter-height, so inter
prediction off the slot read a clamped row-63 edge over chroma rows 64..127
-- now a three-way length inference (luma-sized, half-width, quarter) that is
exact for every dimension.

Defect 3 (s2.obu crash, via parent IRC): the same class in
decode_block_128rect's intra chroma walk -- square cn, chunk offsets and
clamp strides, square around_mi/tu_reach -- now per-axis; s2 decodes all 16
frames with no panic. Its remaining frame-0 divergence is named in the report
for the owning lane: an entropy desync from coefficient unit 38, a plane-2
TX_4X8 chroma unit at mi(12,24) (oracle 1089 units, ours 541), the sub-8
4:2:2 class, pre-existing -- the base tree panics at frame 0 and never
produced pixels. decode_intrabc_128rect carries the same square-cut walk
unwitnessed; deferred with its unblock named in the report.

4:2:0/4:4:4 identity: the 10-bit inter sequence gate, the two-tile-rows
aomenc gate, the 4:4:4 lossless sb128 gate and both 128-root encoder
round-trip gates are green; t422 frame 0 stays byte-exact vs the instrumented
oracle at PREFILT, POSTDEBLOCK, POSTCDEF and FINAL on all three planes.
Both witnesses are pinned with git add -f and gated by
the_pinned_422_bigblock_witnesses_are_present_and_refuse_by_name (byte pins
plus the unconditional refusal-by-name contract; the decode-level assertions
are probe-measured and reproducible from the report's recipe because
decode_stream still refuses 4:2:2 unconditionally). cargo check: 0 warnings.
crates/ec-av1/fixtures/422_allskip_2f.obuadded+0 -0

Binary file changed

crates/ec-av1/fixtures/422_sb128_3f.obuadded+0 -0

Binary file changed

crates/ec-av1/src/decode.rsmodified+194 -76
@@ -18566,8 +18566,19 @@ fn decode_block_128rect(
1856618566 let mi_rows = 2 * y.true_height.div_ceil(8);
1856718567 let max_w_mi = (bw / MI).min(mi_cols.saturating_sub(mi_c));
1856818568 let max_h_mi = (bh / MI).min(mi_rows.saturating_sub(mi_r));
18569- // Non-lossless: one 32x32 chroma unit per mu chunk, per plane.
18570- debug_assert!(lossless_frame || (chroma_w / chroma_tx, chroma_h / chroma_tx) == (nch_x, nch_y));
18569+ // Non-lossless: per mu chunk, the chroma units per axis are
18570+ // ((64 >> ss_x) / chroma_tx, (64 >> ss_y) / chroma_tx) -- one 32x32 unit
18571+ // per chunk at 4:2:0, TWO stacked on the tall axis at 4:2:2 (the chunk's
18572+ // chroma plane block is 32x64), four at 4:4:4. The old square-cut assert
18573+ // demanded one unit per chunk on BOTH axes, which no 4:2:2 stream can
18574+ // satisfy (lane-av1-422bigblock: the s2.obu witness).
18575+ let chunk_cw = (64usize) >> ss_x(fctx);
18576+ let chunk_ch = (64usize) >> ss_y(fctx);
18577+ debug_assert!(
18578+ lossless_frame
18579+ || (nch_x * (chunk_cw / chroma_tx), nch_y * (chunk_ch / chroma_tx))
18580+ == (chroma_w / chroma_tx, chroma_h / chroma_tx)
18581+ );
1857118582 let tpc = 64 / logical_tx;
1857218583 let zero_tu = vec![0i32; logical_tx * logical_tx];
1857318584 let zero_cu = vec![0i32; chroma_tx * chroma_tx];
@@ -18576,6 +18587,7 @@ fn decode_block_128rect(
1857618587 // The chroma context arrays are indexed in LUMA mi; every chroma unit of
1857718588 // every chunk shares this luma span (2 chroma pixels per luma unit).
1857818589 let luma_span = chroma_tx << ss_x(fctx);
18590+ let luma_span_h = chroma_tx << ss_y(fctx);
1857918591 for ch_row in 0..nch_y {
1858018592 for ch_col in 0..nch_x {
1858118593 for tu_row in ch_row * tpc..(ch_row + 1) * tpc {
@@ -18645,9 +18657,12 @@ fn decode_block_128rect(
1864518657 neighbours.record_mi_luma(tu_mi, logical_tx, &tu_grid);
1864618658 }
1864718659 }
18648- // Transform units per axis inside this mu chunk's 32x32 chroma
18649- // span: one 32x32 unit normally, 8x8 TX_4X4 units when lossless.
18650- let cn = (32 / chroma_tx).max(1);
18660+ // Transform units per axis inside this mu chunk's chroma span
18661+ // -- (64 >> ss_x) x (64 >> ss_y): one 32x32 unit at 4:2:0, TWO
18662+ // stacked TX_32X32 at 4:2:2, four at 4:4:4; 8x8 TX_4X4 units
18663+ // when lossless.
18664+ let cn_w = (chunk_cw / chroma_tx).max(1);
18665+ let cn_h = (chunk_ch / chroma_tx).max(1);
1865118666 // libaom's per-chunk `unit_width/height` (plane-mi units of the
1865218667 // luma mi grid): `min(mu_blocks + col, max_blocks) >> ss`.
1865318668 let unit_w = ((ch_col + 1) * 16).min(max_w_mi) >> ss_x(fctx);
@@ -18659,25 +18674,28 @@ fn decode_block_128rect(
1865918674 // symbol order the interleaved pair used to read; a lossless
1866018675 // frame's 4x4 chroma units are where it becomes observable.
1866118676 for plane_pass in 1..=2usize {
18662- for ci_row in 0..cn {
18663- for ci_col in 0..cn {
18664- if ch_col * 8 + ci_col * stepc >= unit_w
18665- || ch_row * 8 + ci_row * stepc >= unit_h
18677+ for ci_row in 0..cn_h {
18678+ for ci_col in 0..cn_w {
18679+ // The clamp strides are the CHUNK's chroma mi extent
18680+ // per axis: 16 luma mi >> the axis's own ss.
18681+ if ch_col * (16 >> ss_x(fctx)) + ci_col * stepc >= unit_w
18682+ || ch_row * (16 >> ss_y(fctx)) + ci_row * stepc >= unit_h
1866618683 {
1866718684 continue;
1866818685 }
18669- let cu_x = cpx + ch_col * 32 + ci_col * chroma_tx;
18670- let cu_y = cpy + ch_row * 32 + ci_row * chroma_tx;
18686+ let cu_x = cpx + ch_col * chunk_cw + ci_col * chroma_tx;
18687+ let cu_y = cpy + ch_row * chunk_ch + ci_row * chroma_tx;
1867118688 let cu_mi = (
1867218689 mi_r + ch_row * 16 + ci_row * ((chroma_tx << ss_y(fctx)) / 4),
1867318690 mi_c + ch_col * 16 + ci_col * ((chroma_tx << ss_x(fctx)) / 4),
1867418691 );
18675- let cu_r = tu_reach(
18692+ let cu_r = tu_reach_rect(
1867618693 bw,
1867718694 bh,
1867818695 ch_col * 64 + ci_col * luma_span,
18679- ch_row * 64 + ci_row * luma_span,
18696+ ch_row * 64 + ci_row * luma_span_h,
1868018697 luma_span,
18698+ luma_span_h,
1868118699 reach,
1868218700 px,
1868318701 py,
@@ -18691,7 +18709,8 @@ fn decode_block_128rect(
1869118709 );
1869218710 continue;
1869318711 }
18694- let cu_around = neighbours.around_mi(cu_mi, luma_span);
18712+ let cu_around =
18713+ neighbours.around_mi_rect(cu_mi, luma_span, luma_span_h);
1869518714 let buf: &mut PlaneBuf<'static> =
1869618715 if plane_pass == 1 { &mut *u } else { &mut *v };
1869718716 let grid = read_plane(
@@ -18705,7 +18724,13 @@ fn decode_block_128rect(
1870518724 // reads this one's coefficient context; replayed after
1870618725 // `record_split_luma_rect` below, which would otherwise
1870718726 // clobber them whole-block.
18708- neighbours.record_mi_chroma(cu_mi, luma_span, luma_span, plane_pass, &grid);
18727+ neighbours.record_mi_chroma(
18728+ cu_mi,
18729+ luma_span,
18730+ luma_span_h,
18731+ plane_pass,
18732+ &grid,
18733+ );
1870918734 units.push((plane_pass, cu_mi, grid));
1871018735 }
1871118736 }
@@ -30233,15 +30258,42 @@ impl<'p> RefPix<'p> {
3023330258 (
3023430259 whole_plane(&g.y, g.width, g.height),
3023530260 {
30236- // Reference pictures carry no subsampling field. A
30237- // 4:4:4 chroma plane is luma-sized; 4:2:0 is the quarter.
30238- let full = g.u.len() == g.width * g.height;
30239- let (cw, ch) = if full { (g.width, g.height) } else { (g.width / 2, g.height / 2) };
30261+ // Reference pictures carry no subsampling field -- the
30262+ // plane's own shape is inferred from its length:
30263+ // luma-sized is 4:4:4, `halfw x height` is 4:2:2
30264+ // (ss_x 1, ss_y 0 -- the chroma plane is HALF-width
30265+ // and FULL-height), `halfw x halfh` is 4:2:0. The
30266+ // three lengths are pairwise distinct for every
30267+ // w, h >= 1, so the guess is exact. The old
30268+ // two-way guess read every 4:2:2 reference as
30269+ // quarter-height: a 128x128 frame's chroma resolved
30270+ // 64x64, the bottom mu-chunk row's prediction
30271+ // sampled a clamped row-63 edge and the frame's
30272+ // own pixels were right (the crop is ss-aware) --
30273+ // only INTER prediction off the slot was wrong
30274+ // (lane-av1-422bigblock: the sb128 witness's
30275+ // frame-2 chroma, rows 64..127).
30276+ let halfw = (g.width + 1) / 2;
30277+ let halfh = (g.height + 1) / 2;
30278+ let (cw, ch) = if g.u.len() == g.width * g.height {
30279+ (g.width, g.height)
30280+ } else if g.u.len() == halfw * g.height {
30281+ (halfw, g.height)
30282+ } else {
30283+ (halfw, halfh)
30284+ };
3024030285 whole_plane(&g.u, cw, ch)
3024130286 },
3024230287 {
30243- let full = g.v.len() == g.width * g.height;
30244- let (cw, ch) = if full { (g.width, g.height) } else { (g.width / 2, g.height / 2) };
30288+ let halfw = (g.width + 1) / 2;
30289+ let halfh = (g.height + 1) / 2;
30290+ let (cw, ch) = if g.v.len() == g.width * g.height {
30291+ (g.width, g.height)
30292+ } else if g.v.len() == halfw * g.height {
30293+ (halfw, g.height)
30294+ } else {
30295+ (halfw, halfh)
30296+ };
3024530297 whole_plane(&g.v, cw, ch)
3024630298 },
3024730299 )
@@ -32828,7 +32880,7 @@ fn decode_inter_block(
3282832880 pu0.true_width,
3282932881 pu0.true_height,
3283032882 mv_to_q4(cpx, mv0.1, ss_x(fctx)),
32831- mv_to_q4(cpy, mv0.0, ss_x(fctx)),
32883+ mv_to_q4(cpy, mv0.0, ss_y(fctx)),
3283232884 scale0,
3283332885 chroma_stride,
3283432886 chroma_buf_h,
@@ -32856,7 +32908,7 @@ fn decode_inter_block(
3285632908 pu1.true_width,
3285732909 pu1.true_height,
3285832910 mv_to_q4(cpx, mv1.1, ss_x(fctx)),
32859- mv_to_q4(cpy, mv1.0, ss_x(fctx)),
32911+ mv_to_q4(cpy, mv1.0, ss_y(fctx)),
3286032912 scale1,
3286132913 chroma_stride,
3286232914 chroma_buf_h,
@@ -32906,7 +32958,7 @@ fn decode_inter_block(
3290632958 pv0.true_width,
3290732959 pv0.true_height,
3290832960 mv_to_q4(cpx, mv0.1, ss_x(fctx)),
32909- mv_to_q4(cpy, mv0.0, ss_x(fctx)),
32961+ mv_to_q4(cpy, mv0.0, ss_y(fctx)),
3291032962 scale0,
3291132963 chroma_stride,
3291232964 chroma_buf_h,
@@ -32934,7 +32986,7 @@ fn decode_inter_block(
3293432986 pv1.true_width,
3293532987 pv1.true_height,
3293632988 mv_to_q4(cpx, mv1.1, ss_x(fctx)),
32937- mv_to_q4(cpy, mv1.0, ss_x(fctx)),
32989+ mv_to_q4(cpy, mv1.0, ss_y(fctx)),
3293832990 scale1,
3293932991 chroma_stride,
3294032992 chroma_buf_h,
@@ -33176,18 +33228,35 @@ fn decode_inter_block(
3317633228 // this arm has always coded. `chroma_side`
3317733229 // already carries the subsampling.
3317833230 let cu_tx = 32usize;
33179- let chunk_chroma = chroma_side * 64 / side;
33180- let units = chunk_chroma / cu_tx;
33231+ // lane-av1-422bigblock: a 64x64 mu chunk's
33232+ // chroma plane block is PER-AXIS
33233+ // (64 >> ss_x) x (64 >> ss_y) -- 32x64 at
33234+ // ss (1,0), i.e. TWO stacked TX_32X32 units
33235+ // per plane (`av1_get_max_uv_txsize` caps the
33236+ // unit at 32 on each axis). The old square-cut
33237+ // model walked `chroma_side`-square chunks:
33238+ // twice the units the oracle codes at 4:2:2,
33239+ // prediction windows indexed at the square
33240+ // `chroma_side` instead of the prediction
33241+ // buffer's own `chroma_stride`, and chunk
33242+ // columns at 64.. of a 64-wide chroma plane.
33243+ let chunk_chroma_w = (64usize) >> ss_x(fctx);
33244+ let chunk_chroma_h = (64usize) >> ss_y(fctx);
33245+ let units_w = chunk_chroma_w / cu_tx;
33246+ let units_h = chunk_chroma_h / cu_tx;
3318133247 // The unit's own footprint on the LUMA mi
33182- // grid: 64 px (16 mi) at 4:2:0, 32 px (8 mi)
33183- // at ss 0/0. `around_mi` reads and
33248+ // grid, per axis (32 << ss) px: 64x64 (16x16
33249+ // mi) at 4:2:0, 32x32 (8x8 mi) at 4:4:4,
33250+ // 64x32 (16x8 mi) at 4:2:2. `around_mi_rect`
33251+ // reads and
3318433252 // `record_mi_chroma` stamps span exactly the
3318533253 // unit's own cells -- `get_txb_ctx` reads the
3318633254 // 8 context cells of the TX_32X32 itself, and
3318733255 // `av1_set_entropy_contexts` memsets the same
3318833256 // 8, so the unit over never sees this unit's
3318933257 // state and the unit below always does.
33190- let unit_luma = cu_tx * (side / chroma_side);
33258+ let unit_luma_w = cu_tx << ss_x(fctx);
33259+ let unit_luma_h = cu_tx << ss_y(fctx);
3319133260 let cu_scan = default_scan(cu_tx);
3319233261 if lossless(fctx) {
3319333262 // lane-lossless2: TX_4X4 units over this
@@ -33195,8 +33264,8 @@ fn decode_inter_block(
3319533264 read_inter_chroma_lossless(
3319633265 dec, cdfs, neighbours, u, v, su, sv,
3319733266 at_mi, (cpx, cpy),
33198- (cc * chunk_chroma, cr * chunk_chroma),
33199- (chunk_chroma, chunk_chroma),
33267+ (cc * chunk_chroma_w, cr * chunk_chroma_h),
33268+ (chunk_chroma_w, chunk_chroma_h),
3320033269 (write_chroma_w, write_chroma_h),
3320133270 chroma_side, mode_for_tx, base_q_idx,
3320233271 &mut u_units, &mut v_units, fctx,
@@ -33213,24 +33282,28 @@ fn decode_inter_block(
3321333282 // Plane-major per chunk (libaom's plane
3321433283 // loop is outermost inside the mu walk);
3321533284 // within a plane the units walk raster.
33216- for ur in 0..units {
33217- for uc in 0..units {
33285+ for ur in 0..units_h {
33286+ for uc in 0..units_w {
3321833287 let unit_mi = (
3321933288 at_mi.0 + cr * 16
33220- + ur * (unit_luma / MI),
33289+ + ur * (unit_luma_h / MI),
3322133290 at_mi.1 + cc * 16
33222- + uc * (unit_luma / MI),
33291+ + uc * (unit_luma_w / MI),
3322333292 );
3322433293 // Per unit, AFTER the earlier
3322533294 // units' stamps: this unit's
3322633295 // coefficient context must see
3322733296 // them.
3322833297 let cu_around = neighbours
33229- .around_mi(unit_mi, unit_luma);
33298+ .around_mi_rect(
33299+ unit_mi,
33300+ unit_luma_w,
33301+ unit_luma_h,
33302+ );
3323033303 let (cu_x, cu_y) = (
33231- cpx + cc * chunk_chroma
33304+ cpx + cc * chunk_chroma_w
3323233305 + uc * cu_tx,
33233- cpy + cr * chunk_chroma
33306+ cpy + cr * chunk_chroma_h
3323433307 + ur * cu_tx,
3323533308 );
3323633309 // `av1_get_tx_type` (blockd.h:
@@ -33261,11 +33334,16 @@ fn decode_inter_block(
3326133334 },
3326233335 )
3326333336 .map(|(_, _, _, _, t)| t);
33337+ // The prediction buffer is
33338+ // `chroma_stride`-strided (the
33339+ // plane block's own width at
33340+ // 4:2:2), not the square
33341+ // `chroma_side`.
3326433342 let cu_pred = src.offset(
33265- (cr * chunk_chroma
33343+ (cr * chunk_chroma_h
3326633344 + ur * cu_tx)
33267- * chroma_side
33268- + cc * chunk_chroma
33345+ * chroma_stride
33346+ + cc * chunk_chroma_w
3326933347 + uc * cu_tx,
3327033348 );
3327133349 let cu_grid = read_inter_plane(
@@ -33295,8 +33373,8 @@ fn decode_inter_block(
3329533373 // context.
3329633374 neighbours.record_mi_chroma(
3329733375 unit_mi,
33298- unit_luma,
33299- unit_luma,
33376+ unit_luma_w,
33377+ unit_luma_h,
3330033378 plane_idx,
3330133379 &cu_grid,
3330233380 );
@@ -33311,11 +33389,18 @@ fn decode_inter_block(
3331133389 chroma_side * chroma_side,
3331233390 );
3331333391 for rr in 0..cu_tx {
33314- let start = (cr * chunk_chroma
33392+ // The ASSEMBLED grid stays at
33393+ // the square `chroma_side`
33394+ // stride the block tail's
33395+ // `mu_chroma_units` re-stamp
33396+ // indexes; the unit's true
33397+ // per-axis position is what
33398+ // changes.
33399+ let start = (cr * chunk_chroma_h
3331533400 + ur * cu_tx
3331633401 + rr)
3331733402 * chroma_side
33318- + cc * chunk_chroma
33403+ + cc * chunk_chroma_w
3331933404 + uc * cu_tx;
3332033405 dst[start..start + cu_tx]
3332133406 .copy_from_slice(
@@ -34262,7 +34347,7 @@ fn decode_inter_block(
3426234347 pu_ref.true_width,
3426334348 pu_ref.true_height,
3426434349 mv_to_q4(cpx, mv.1, ss_x(fctx)),
34265- mv_to_q4(cpy, mv.0, ss_x(fctx)),
34350+ mv_to_q4(cpy, mv.0, ss_y(fctx)),
3426634351 chroma_stride,
3426734352 chroma_buf_h,
3426834353 write_chroma_w,
@@ -34277,7 +34362,7 @@ fn decode_inter_block(
3427734362 pv_ref.true_width,
3427834363 pv_ref.true_height,
3427934364 mv_to_q4(cpx, mv.1, ss_x(fctx)),
34280- mv_to_q4(cpy, mv.0, ss_x(fctx)),
34365+ mv_to_q4(cpy, mv.0, ss_y(fctx)),
3428134366 chroma_stride,
3428234367 chroma_buf_h,
3428334368 write_chroma_w,
@@ -34309,7 +34394,7 @@ fn decode_inter_block(
3430934394 pu_ref.true_width,
3431034395 pu_ref.true_height,
3431134396 mv_to_q4(cpx, mv.1, ss_x(fctx)),
34312- mv_to_q4(cpy, mv.0, ss_x(fctx)),
34397+ mv_to_q4(cpy, mv.0, ss_y(fctx)),
3431334398 luma_scale,
3431434399 chroma_stride,
3431534400 chroma_buf_h,
@@ -34325,7 +34410,7 @@ fn decode_inter_block(
3432534410 pv_ref.true_width,
3432634411 pv_ref.true_height,
3432734412 mv_to_q4(cpx, mv.1, ss_x(fctx)),
34328- mv_to_q4(cpy, mv.0, ss_x(fctx)),
34413+ mv_to_q4(cpy, mv.0, ss_y(fctx)),
3432934414 luma_scale,
3433034415 chroma_stride,
3433134416 chroma_buf_h,
@@ -34420,7 +34505,7 @@ fn decode_inter_block(
3442034505 src.true_width,
3442134506 src.true_height,
3442234507 mv_to_q4(cpx, prev_mv.1, ss_x(fctx)),
34423- mv_to_q4(cpy, prev_mv.0, ss_x(fctx)),
34508+ mv_to_q4(cpy, prev_mv.0, ss_y(fctx)),
3442434509 prev_scale,
3442534510 piece_w,
3442634511 piece_h,
@@ -34676,18 +34761,35 @@ fn decode_inter_block(
3467634761 // this arm has always coded. `chroma_side`
3467734762 // already carries the subsampling.
3467834763 let cu_tx = 32usize;
34679- let chunk_chroma = chroma_side * 64 / side;
34680- let units = chunk_chroma / cu_tx;
34764+ // lane-av1-422bigblock: a 64x64 mu chunk's
34765+ // chroma plane block is PER-AXIS
34766+ // (64 >> ss_x) x (64 >> ss_y) -- 32x64 at
34767+ // ss (1,0), i.e. TWO stacked TX_32X32 units
34768+ // per plane (`av1_get_max_uv_txsize` caps the
34769+ // unit at 32 on each axis). The old square-cut
34770+ // model walked `chroma_side`-square chunks:
34771+ // twice the units the oracle codes at 4:2:2,
34772+ // prediction windows indexed at the square
34773+ // `chroma_side` instead of the prediction
34774+ // buffer's own `chroma_stride`, and chunk
34775+ // columns at 64.. of a 64-wide chroma plane.
34776+ let chunk_chroma_w = (64usize) >> ss_x(fctx);
34777+ let chunk_chroma_h = (64usize) >> ss_y(fctx);
34778+ let units_w = chunk_chroma_w / cu_tx;
34779+ let units_h = chunk_chroma_h / cu_tx;
3468134780 // The unit's own footprint on the LUMA mi
34682- // grid: 64 px (16 mi) at 4:2:0, 32 px (8 mi)
34683- // at ss 0/0. `around_mi` reads and
34781+ // grid, per axis (32 << ss) px: 64x64 (16x16
34782+ // mi) at 4:2:0, 32x32 (8x8 mi) at 4:4:4,
34783+ // 64x32 (16x8 mi) at 4:2:2. `around_mi_rect`
34784+ // reads and
3468434785 // `record_mi_chroma` stamps span exactly the
3468534786 // unit's own cells -- `get_txb_ctx` reads the
3468634787 // 8 context cells of the TX_32X32 itself, and
3468734788 // `av1_set_entropy_contexts` memsets the same
3468834789 // 8, so the unit over never sees this unit's
3468934790 // state and the unit below always does.
34690- let unit_luma = cu_tx * (side / chroma_side);
34791+ let unit_luma_w = cu_tx << ss_x(fctx);
34792+ let unit_luma_h = cu_tx << ss_y(fctx);
3469134793 let cu_scan = default_scan(cu_tx);
3469234794 if lossless(fctx) {
3469334795 // lane-lossless2: TX_4X4 units over this
@@ -34695,8 +34797,8 @@ fn decode_inter_block(
3469534797 read_inter_chroma_lossless(
3469634798 dec, cdfs, neighbours, u, v, su, sv,
3469734799 at_mi, (cpx, cpy),
34698- (cc * chunk_chroma, cr * chunk_chroma),
34699- (chunk_chroma, chunk_chroma),
34800+ (cc * chunk_chroma_w, cr * chunk_chroma_h),
34801+ (chunk_chroma_w, chunk_chroma_h),
3470034802 (write_chroma_w, write_chroma_h),
3470134803 chroma_side, mode_for_tx, base_q_idx,
3470234804 &mut u_units, &mut v_units, fctx,
@@ -34713,24 +34815,28 @@ fn decode_inter_block(
3471334815 // Plane-major per chunk (libaom's plane
3471434816 // loop is outermost inside the mu walk);
3471534817 // within a plane the units walk raster.
34716- for ur in 0..units {
34717- for uc in 0..units {
34818+ for ur in 0..units_h {
34819+ for uc in 0..units_w {
3471834820 let unit_mi = (
3471934821 at_mi.0 + cr * 16
34720- + ur * (unit_luma / MI),
34822+ + ur * (unit_luma_h / MI),
3472134823 at_mi.1 + cc * 16
34722- + uc * (unit_luma / MI),
34824+ + uc * (unit_luma_w / MI),
3472334825 );
3472434826 // Per unit, AFTER the earlier
3472534827 // units' stamps: this unit's
3472634828 // coefficient context must see
3472734829 // them.
3472834830 let cu_around = neighbours
34729- .around_mi(unit_mi, unit_luma);
34831+ .around_mi_rect(
34832+ unit_mi,
34833+ unit_luma_w,
34834+ unit_luma_h,
34835+ );
3473034836 let (cu_x, cu_y) = (
34731- cpx + cc * chunk_chroma
34837+ cpx + cc * chunk_chroma_w
3473234838 + uc * cu_tx,
34733- cpy + cr * chunk_chroma
34839+ cpy + cr * chunk_chroma_h
3473434840 + ur * cu_tx,
3473534841 );
3473634842 // `av1_get_tx_type` (blockd.h:
@@ -34761,11 +34867,16 @@ fn decode_inter_block(
3476134867 },
3476234868 )
3476334869 .map(|(_, _, _, _, t)| t);
34870+ // The prediction buffer is
34871+ // `chroma_stride`-strided (the
34872+ // plane block's own width at
34873+ // 4:2:2), not the square
34874+ // `chroma_side`.
3476434875 let cu_pred = src.offset(
34765- (cr * chunk_chroma
34876+ (cr * chunk_chroma_h
3476634877 + ur * cu_tx)
34767- * chroma_side
34768- + cc * chunk_chroma
34878+ * chroma_stride
34879+ + cc * chunk_chroma_w
3476934880 + uc * cu_tx,
3477034881 );
3477134882 let cu_grid = read_inter_plane(
@@ -34795,8 +34906,8 @@ fn decode_inter_block(
3479534906 // context.
3479634907 neighbours.record_mi_chroma(
3479734908 unit_mi,
34798- unit_luma,
34799- unit_luma,
34909+ unit_luma_w,
34910+ unit_luma_h,
3480034911 plane_idx,
3480134912 &cu_grid,
3480234913 );
@@ -34811,11 +34922,18 @@ fn decode_inter_block(
3481134922 chroma_side * chroma_side,
3481234923 );
3481334924 for rr in 0..cu_tx {
34814- let start = (cr * chunk_chroma
34925+ // The ASSEMBLED grid stays at
34926+ // the square `chroma_side`
34927+ // stride the block tail's
34928+ // `mu_chroma_units` re-stamp
34929+ // indexes; the unit's true
34930+ // per-axis position is what
34931+ // changes.
34932+ let start = (cr * chunk_chroma_h
3481534933 + ur * cu_tx
3481634934 + rr)
3481734935 * chroma_side
34818- + cc * chunk_chroma
34936+ + cc * chunk_chroma_w
3481934937 + uc * cu_tx;
3482034938 dst[start..start + cu_tx]
3482134939 .copy_from_slice(
@@ -39382,7 +39500,7 @@ fn decode_inter_block8(
3938239500 pu0.true_width,
3938339501 pu0.true_height,
3938439502 mv_to_q4(cpx, mv0.1, ss_x(fctx)),
39385- mv_to_q4(cpy, mv0.0, ss_x(fctx)),
39503+ mv_to_q4(cpy, mv0.0, ss_y(fctx)),
3938639504 scale0,
3938739505 chroma_w,
3938839506 chroma_h,
@@ -39397,7 +39515,7 @@ fn decode_inter_block8(
3939739515 pu1.true_width,
3939839516 pu1.true_height,
3939939517 mv_to_q4(cpx, mv1.1, ss_x(fctx)),
39400- mv_to_q4(cpy, mv1.0, ss_x(fctx)),
39518+ mv_to_q4(cpy, mv1.0, ss_y(fctx)),
3940139519 scale1,
3940239520 chroma_w,
3940339521 chroma_h,
@@ -39429,7 +39547,7 @@ ss_y(fctx),
3942939547 pv0.true_width,
3943039548 pv0.true_height,
3943139549 mv_to_q4(cpx, mv0.1, ss_x(fctx)),
39432- mv_to_q4(cpy, mv0.0, ss_x(fctx)),
39550+ mv_to_q4(cpy, mv0.0, ss_y(fctx)),
3943339551 scale0,
3943439552 chroma_w,
3943539553 chroma_h,
@@ -39444,7 +39562,7 @@ ss_y(fctx),
3944439562 pv1.true_width,
3944539563 pv1.true_height,
3944639564 mv_to_q4(cpx, mv1.1, ss_x(fctx)),
39447- mv_to_q4(cpy, mv1.0, ss_x(fctx)),
39565+ mv_to_q4(cpy, mv1.0, ss_y(fctx)),
3944839566 scale1,
3944939567 chroma_w,
3945039568 chroma_h,
crates/ec-av1/src/stream.rsmodified+56 -0
@@ -2209,6 +2209,62 @@ pub(crate) mod tests {
22092209 let frames = decode_stream(&stream).expect("the 4:2:0 control must decode");
22102210 assert_eq!(frames.len(), 1, "{NAME}: the 4:2:0 control decoded no frame");
22112211 }
2212+ /// lane-av1-422bigblock: the two witnessed 4:2:2 big-block defects, pinned
2213+ /// as fixtures (`git add -f`; `fixtures/` is gitignored).
2214+ ///
2215+ /// `422_allskip_2f.obu` (62 bytes) is a 128x128 profile-2 key frame plus
2216+ /// its all-skip first inter frame: the pre-port decoder read phantom
2217+ /// coefficient units in the inter frame and then panicked in
2218+ /// `reconstruct_mc_rect` on a full-height 4:2:2 chroma rect. At this
2219+ /// lane's HEAD the block-half port's per-axis plane-block model already
2220+ /// has it entropy-locked (all 20 key-frame coefficient units pair
2221+ /// rng-for-rng with the instrumented oracle, the inter frame reads
2222+ /// zero, matching the oracle) and pixel-exact vs aomdec.
2223+ ///
2224+ /// `422_sb128_3f.obu` (12543 bytes) carries the f2 128x128
2225+ /// `PARTITION_NONE` non-skip inter block: the mu-chunk chroma walk cut
2226+ /// each chunk's 32x64 chroma into a `chroma_side`-square 64x64 (twice
2227+ /// the units the oracle codes), indexed the prediction buffer at the
2228+ /// square `chroma_side` instead of `chroma_stride` (the empty-slice
2229+ /// panic at `push_mc_rect_tx`'s densify), and the reference plane
2230+ /// resolution guessed every non-4:4:4 picture quarter-height, so the
2231+ /// bottom mu-chunk row predicted from a clamped row-63 edge. All fixed;
2232+ /// both witnesses decode pixel-exact vs aomdec on the lane's local
2233+ /// `EC_AV1_ALLOW_422_PROBE` patch-run-restore build (recipe and measured
2234+ /// numbers in `lanes/av1422bigblock.report.md`).
2235+ ///
2236+ /// `decode_stream` itself still refuses 4:2:2 at the sequence header --
2237+ /// unconditionally, per the standing family rule -- so the committed
2238+ /// assertion is the byte pin (fnv1a64, the same load-bearing-identity
2239+ /// fingerprint as the cdf-forwarding gate) plus the refusal-by-name
2240+ /// contract over the pinned bytes.
2241+ #[test]
2242+ fn the_pinned_422_bigblock_witnesses_are_present_and_refuse_by_name() {
2243+ const NAME: &str = "the_pinned_422_bigblock_witnesses_are_present_and_refuse_by_name";
2244+ const REFUSAL: &str = "a chroma format of 4:2:2";
2245+ for (file, bytes, fp) in [
2246+ ("422_allskip_2f.obu", 62usize, 0x7e4d69d3c728c55f_u64),
2247+ ("422_sb128_3f.obu", 12543, 0x5171e0aab8000da7),
2248+ ] {
2249+ let path = std::path::Path::new(env!("CARGO_MANIFEST_DIR"))
2250+ .join("fixtures")
2251+ .join(file);
2252+ let data = std::fs::read(&path).unwrap_or_else(|e| {
2253+ panic!(
2254+ "{NAME}: pinned witness {} is missing ({e}) -- the gate cannot run",
2255+ path.display()
2256+ )
2257+ });
2258+ assert_eq!(data.len(), bytes, "{NAME}: {file} size drifted");
2259+ assert_eq!(fnv1a64(&data), fp, "{NAME}: {file} bytes drifted");
2260+ let err = decode_stream(&data).unwrap_err().to_string();
2261+ assert!(
2262+ err.contains(REFUSAL),
2263+ "{NAME}: {file} must refuse by name, got: {err}"
2264+ );
2265+ }
2266+ }
2267+
22122268
22132269 /// lane-av1-qmatrix: WITNESS for the lifted `using_qmatrix` refusal (the
22142270 /// old gate `a_frame_using_quantisation_matrices_is_refused_by_name` is
lanes/av1422bigblock.report.mdadded+156 -0
@@ -0,0 +1,156 @@
1+# lane-av1-422bigblock — the two witnessed 4:2:2 big-block defects
2+
3+Branch `lane-av1-422bigblock`, HEAD `213c1eb0` (contains the block-half port).
4+Target dir `$HOME/.cache/cargo-target-av1422bigblock` throughout. No push.
5+
6+## Verdict
7+
8+Both witnessed defects are fixed and both witnesses are pixel-exact vs aomdec.
9+The panic the ticket predicted for defect 1 no longer reproduces at this HEAD —
10+the block-half port had already fixed the all-skip inter frame; re-verified, not
11+assumed. Defect 2 needed three fixes, two of them found below the historical
12+panic line. The 4:2:0/4:4:4 behavior is unchanged (targeted gates green, t422
13+frame 0 byte-exact at all four stages). Defect 3 (Main's IRC addition, the
14+s2.obu crash) is fixed as a crash; s2's remaining divergence is a pre-existing
15+sub-8 chroma class, fingerprinted for its owning lane. Committed code still
16+refuses 4:2:2 at the sequence header; the `EC_AV1_ALLOW_422_PROBE` bypass was
17+applied and reverted per probe run and is **not** in the commit.
18+
19+## Fixtures (pinned, `git add -f`; `fixtures/` is gitignored)
20+
21+| fixture | bytes | sha256 | fnv1a64 |
22+|---|---|---|---|
23+| `422_allskip_2f.obu` | 62 | `ba4932c14f95971b5f25321b04abce80c9fdd5de4b1fe6fffcdad82aaea87ce1` | `0x7e4d69d3c728c55f` |
24+| `422_sb128_3f.obu` | 12543 | `0b851799d99cb4d141a7d042138a3999aad7e0fb24d69c670bca1d38c286dce9` | `0x5171e0aab8000da7` |
25+
26+Provenance: the witness hunt's artifacts under `~/.cache/av1422sb128wit/`
27+(`422_allskip_2f.obu` = `b422_wit2f.obu`, `422_sb128_3f.obu` = `b422b_3f.obu`;
28+oracle refs `b422_wit.ref.yuv`). NOTE: the ticket said `422_sb128_3f.obu` is
29+10175 bytes; the live file is 12543 bytes and its sha256 matches the ticket —
30+the byte count in the charter is stale, the hash is authoritative.
31+
32+Gate: `the_pinned_422_bigblock_witnesses_are_present_and_refuse_by_name`
33+(stream.rs) asserts both byte pins and the refusal-by-name contract.
34+`decode_stream` still refuses 4:2:2 unconditionally in committed code, so a
35+committed gate cannot decode these streams; the decode-completes + counters +
36+pixel-exact assertions were measured through the probe build and are
37+reproducible from the recipe below. The counters over the sb128 witness:
38+`chroma422_square: 32`; over s2: `chroma422_square: 68, chroma422_rect: 222,
39+chroma422_sub8: 24, chroma422_chunk: 40`, `part128 none=3`.
40+
41+## Reproduce (patch-run-restore, local only)
42+
43+```
44+sed 's/if seq.subsampling_x != seq.subsampling_y {/if seq.subsampling_x != seq.subsampling_y \&\& std::env::var_os("EC_AV1_ALLOW_422_PROBE").is_none() {/' -i crates/ec-av1/src/stream.rs
45+CARGO_TARGET_DIR=$HOME/.cache/cargo-target-av1422bigblock cargo build -p ec-av1 --example decode_probe --features gate-counters
46+EC_AV1_ALLOW_422_PROBE=1 EC_PROBE_OUT=/tmp/ours.raw \
47+ $HOME/.cache/cargo-target-av1422bigblock/debug/examples/decode_probe crates/ec-av1/fixtures/422_sb128_3f.obu
48+$HOME/.cache/aom-oracle/build/aomdec --rawvideo -o /tmp/oracle.raw crates/ec-av1/fixtures/422_sb128_3f.obu
49+cmp /tmp/ours.raw /tmp/oracle.raw # identical
50+git checkout -- crates/ec-av1/src/stream.rs
51+```
52+
53+## Defect 1 — all-skip 422 inter desync: NOT REPRODUCING at HEAD (fixed upstream)
54+
55+At `213c1eb0` the witness decodes clean: `OK: 2 frames decoded, 128x128`, no
56+panic, no phantom reads. Evidence:
57+
58+- Entropy: our `EC_TRACE_COEFF` pairs rng-for-rng with the instrumented
59+ oracle's — frame 0 codes 20 coefficient units (one nonzero 32x32 luma unit +
60+ 4 stacked-chroma per 32x32 quadrant), identical rng sequence on both sides;
61+ frame 1 codes **zero** units on both sides (all-skip, as the oracle).
62+- Pixels: the shown frame is byte-identical to `aomdec --rawvideo`.
63+
64+The ticket's "~20 phantom units + reconstruct_mc_rect side=64 w=64 h=128 panic"
65+is the pre-blockhalf state; the per-axis plane-block model fixed both the
66+phantom reads and the geometry. No code change needed here. The full hunt
67+stream `b422_wit.obu` (6 frames) also decodes OK at HEAD.
68+
69+## Defect 2 — 128-root square-cut chroma chunking: three stacked causes
70+
71+The historical `range end 4128 > 4096` (decode.rs:34279) no longer reproduces;
72+at HEAD the same block panicked deeper, in `push_mc_rect_tx`'s stride-densify
73+(`range end index 32 out of range for slice of length 0`). The f2 128x128
74+PARTITION_NONE non-skip inter block carries all three causes; the oracle codes
75+16 chroma units (8 per plane, 2 stacked TX_32X32 per 64x64 mu chunk).
76+
77+1. **Square-cut chunking** (`decode_inter_block`, both the inter-luma and the
78+ intra-in-inter walk): `chunk_chroma = chroma_side * 64 / side` cut each
79+ chunk's per-axis `(64>>ss_x) x (64>>ss_y)` chroma into a
80+ `chroma_side`-square 64x64 — twice the units the oracle codes at 4:2:2.
81+ Fixed per-axis (`chunk_cw/chunk_ch`, `units_w/units_h`), unit luma spans
82+ `(32<<ss_x, 32<<ss_y)` via `around_mi_rect`/per-axis
83+ `record_mi_chroma`, and the assembled grid placement per-axis.
84+2. **Prediction stride**: `cu_pred = src.offset((cr*chunk + ur*cu_tx) *
85+ chroma_side + ...)` indexed the prediction buffer at the square
86+ `chroma_side` (128) while the 4:2:2 buffer is `chroma_stride`-strided (the
87+ plane block's own width, 64). Chunk (0,0)'s tall unit read buffer row 64 as
88+ row 32, and chunk (1,0) offset to `len` exactly — the empty slice. Fixed to
89+ `* chroma_stride`; the assembled grid stays at the square `chroma_side`
90+ stride the block-tail `mu_chroma_units` re-stamp already indexes per-axis
91+ (verified unit-for-unit against the walk).
92+3. **Reference plane resolution** (`RefPix::planes`): a `Picture` carries no
93+ subsampling field, and the two-way guess (luma-sized = 4:4:4, otherwise
94+ quarter = 4:2:0) resolved every 4:2:2 reference 64x64. The frame's own
95+ pixels were right (the crop is ss-aware) — only inter prediction off the
96+ slot was wrong, so the bottom mu-chunk row predicted from a clamped row-63
97+ edge (±1–2 diffs over chroma rows 64..127, 3.3–3.6k samples/plane). Fixed
98+ with a three-way length inference (`w*h` / `halfw*h` / `halfw*halfh` —
99+ pairwise distinct for every w,h ≥ 1).
100+
101+After the fixes: `422_sb128_3f.obu` and the full `b422_wit.obu` decode
102+pixel-exact vs aomdec; every coefficient unit of every frame pairs
103+rng-for-rng with the oracle (29/29, 32/32, 32/32).
104+
105+Class sweep of the same square-cut model:
106+- `decode_intrabc_128rect` has the same `cside * 64 / side` square chunk walk —
107+ **deferred** (same class, unwitnessed: no 4:2:2 intrabc 128-rect witness
108+ exists; unblock = one aomenc `--enable-intrabc` profile-2 128-SB hunt).
109+- The 444 branch of the inter walk degenerates to identical values (ss 0/0 ⇒
110+ per-axis == square, `chroma_stride == chroma_side`), verified by gate.
111+
112+## Defect 3 (Main's IRC) — s2.obu crash: crash fixed, residual named
113+
114+`/tmp/sa422/s2.obu` (recipe: `lanes/av1422stripanchor.report.md` "Observed, not
115+chased"; 420 control `b420_wit.obu`) panicked at `decode.rs:3709` at HEAD — the
116+same densify site, fed by defect 2's cause 3 (quarter-height reference) and the
117+intra 128-rect twin of the square-cut walk:
118+
119+- `decode_block_128rect`'s chroma walk was chunk-square (`cn = 32/chroma_tx`,
120+ `cu_y = cpy + ch_row*32`, clamp strides 8/8) with a `debug_assert!` that no
121+ 4:2:2 stream can satisfy. Fixed per-axis exactly like the inter walk
122+ (`cn_w/cn_h`, per-axis chunk offsets and clamp strides, `tu_reach_rect`,
123+ `around_mi_rect`, per-axis record spans). 420/444 degenerate to the old
124+ values; 4:4:4's previously-broken (assert-caught) non-lossless 128-rect
125+ chroma becomes correct as a side effect.
126+
127+Result: s2.obu decodes all 16 frames, no panic (`OK: 16 frames decoded,
128+256x144`). The crash the charter assigned is closed. **Deferred (named for its
129+owning lane):** s2's frame 0 diverges from aomdec (~45% of samples, maxabs
130+~180, Y first diff at sample 126) with an entropy desync: the oracle codes
131+1089 coefficient units in frame 0, ours 541, first divergence at unit 38 — a
132+plane-2 **TX_4X8** chroma unit at **mi(12,24)** (oracle `all_zero=0
133+rng=48745`, ours `rng=41584`). Class: sub-8/odd-strip 4:2:2 chroma under the
134+128-rect intra path (the `ss_size_lookup` BLOCK_INVALID family), pre-existing
135+— the base tree panics at frame 0's assert and never produced pixels. At base
136+the stream could not be measured at all; the pre-fix re-run log is
137+`/tmp/sa422/re-run-av1422ctxgather.log`. Fingerprint: `/tmp/sa422/s2f0.obu`,
138+unit 38, mi(12,24), TX_4X8, plane 2.
139+
140+## 4:2:0/4:4:4 identity + t422
141+
142+- `a_real_aomenc_10bit_inter_sequence_decodes_pixel_exact` — green.
143+- `a_real_aomenc_stream_with_two_tile_rows_decodes_through_decode_stream`
144+ (live aomenc, 420, inter, tiles) — green.
145+- `a_lossless_sb128_rect_intra_block_decodes_sample_exact` (4:4:4 lossless
146+ sb128) — green.
147+- `a_128_root_block_with_a_real_residual_decodes_exact_through_both_decoders`
148+ and `a_128_root_compound_block_decodes_exact_through_both_decoders` (solo,
149+ they pin the process-global superblock size) — green.
150+- t422 frame 0 (`/tmp/i422/t422_1f.obu`) byte-exact vs the instrumented oracle
151+ at PREFILT, POSTDEBLOCK, POSTCDEF and FINAL on Y, U and V; t422 16-frame
152+ stream decodes with the same frame count as the parent (15 shown of 16 frame
153+ OBUs, unchanged at HEAD — the 16th is an `OBU_TILE_LIST` quirk, not a
154+ regression).
155+
156+`cargo check -p ec-av1`: 0 warnings. Committed on the branch, no push.