forge
Explore
Log in

Don't you dare go Hollow

ec-av1: lane-av1-422j -- size inter chroma skip residual from the write rect; refusal stays

Browse files at this commit

dfeffbcebd64426ceeebbf03214c8d6fe57282d6Ahmet Kaan GümüşParent: 3ed346e
decode_inter_block's chroma square was side >> ss_x, but reconstruct_mc_rect
indexes the prediction/residual buffers row * chroma_side + col over the
WRITE rect: at ss (1,0) that rect is side/2 x side, so frame 1's skipped
16-level VERT_B strip (4x16 chroma) read prediction[64..68] out of the
64-sample buffer. Size the square from the chroma rect's enclosing extents;
4:2:0 and 4:4:4 are bit-identical.

Same-shape sweep: both chroma skip arms (single-ref + compound) share the
fix; the luma arms are provably safe (side^2 >= (h-1)*side + w); the other
inter-path slices fit their forwarded dims. The square non-skip chroma arm
paired a chroma_side-square unit with the 4:2:0 scan (coefficient-count
assert) and now routes non-square chroma rects through read_inter_rect_chroma;
rect_inter_chroma_set and rect_scan gained the square rows the 4:2:2 strips'
square chroma plane blocks need.

Frontier moved to the intra-in-inter chroma read (intra machinery, not the
ZERO_RESIDUAL class; named stop). Stream not pixel-exact, so the 4:2:2
refusal stays; probe bypass reverted. 420 gates green (refusal-by-name 1/1,
aomenc skipped-8x8 tx-split 2/2), cargo check 0 warnings.
crates/ec-av1/src/decode.rsmodified+42 -3
@@ -22417,6 +22417,13 @@ fn rect_inter_chroma_set(w: usize, h: usize) -> Result<TxbSet> {
2241722417 // block (`av1_get_max_uv_txsize` adjusts `TX_64X32`/`TX_32X64` to
2241822418 // `TX_32X32`); `get_txsize_entropy_ctx(TX_32X32)` is the 32x32 set.
2241922419 (32, 32) => TxbSet::Chroma32,
22420+ // lane-av1-422j: square chroma units of a 4:2:2 strip -- a 16x8
22421+ // (8x16) luma strip's chroma plane block is 8x8 (16x16) square, and
22422+ // the square-block routing above sends it here. The sets are the
22423+ // exact `get_txsize_entropy_ctx` tables the square arms use.
22424+ (16, 16) => TxbSet::Chroma16,
22425+ (8, 8) => TxbSet::Chroma8,
22426+ (4, 4) => TxbSet::Chroma4,
2242022427 _ => {
2242122428 return Err(unsupported(
2242222429 "a rectangular inter chroma transform unit whose shape has no coefficient table set here",
@@ -22471,6 +22478,11 @@ fn rect_scan(w: usize, h: usize) -> Result<&'static [u16]> {
2247122478 (4, 8) => &SCAN_4X8,
2247222479 (32, 8) => &SCAN_32X8,
2247322480 (8, 32) => &SCAN_8X32,
22481+ // lane-av1-422j: square units routed through the rect reader -- a
22482+ // 4:2:2 strip's square chroma plane block (8x8 under a 16x8 strip,
22483+ // 16x16 under an 8x16 one). The default 2D scan is exactly what the
22484+ // square reader uses for the same side.
22485+ (w, h) if w == h => default_scan(w),
2247422486 _ => {
2247522487 return Err(unsupported(
2247622488 "a rectangular transform unit whose shape has no coefficient scan table here",
@@ -31223,7 +31235,17 @@ fn decode_inter_block(
3122331235 Some(s) if s.has_chroma => (s.pair_mi.1 * MI >> ss_x(fctx), s.pair_mi.0 * MI >> ss_y(fctx)),
3122431236 _ => (px >> ss_x(fctx), py >> ss_y(fctx)),
3122531237 };
31226- let chroma_side = side >> ss_x(fctx);
31238+ // lane-av1-422j: the chroma prediction/residual buffers are
31239+ // `chroma_side`-square and every consumer indexes them
31240+ // `row * chroma_side + col` over the WRITE rect (`write_chroma_w` x
31241+ // `write_chroma_h`). At ss (1,0) that rect is `side/2 x side` (an 8x16
31242+ // strip's 4x16 chroma), so a `side >> ss_x` square is shorter than
31243+ // `row * chroma_side + write_chroma_w` on rows `>= side/2` -- frame 1's
31244+ // skipped VERT_B strip read `prediction[64..68]` out of the 64-sample
31245+ // buffer (reconstruct_mc_rect panic, decode.rs:29094). The enclosing
31246+ // square of the chroma rect is the max: unchanged at 4:2:0 (side/2) and
31247+ // 4:4:4 (side), so only 4:2:2 changes shape.
31248+ let chroma_side = (side >> ss_x(fctx)).max(side >> ss_y(fctx));
3122731249 let (write_chroma_w, write_chroma_h) = match strip_chroma {
3122831250 Some(s) if s.has_chroma => {
3122931251 // 4:2:0: the PAIR's 8x4 / 4x8. 4:4:4: the strip's own 16x4 /
@@ -32698,9 +32720,19 @@ fn decode_inter_block(
3269832720 // whole-block record must not overwrite them with the
3269932721 // assembled grid (class `override-slot-on-one-arm`).
3270032722 mu_chroma = true;
32701- } else if rect_tu {
32723+ } else if rect_tu
32724+ || (write_chroma_w, write_chroma_h) != (chroma_side, chroma_side)
32725+ {
3270232726 // One chroma read for the whole strip at 4:2:0, two
3270332727 // 32-capped units at 4:4:4 -- see the helper.
32728+ // lane-av1-422j: a 4:2:2 square block's chroma plane is the
32729+ // (side/2 x side) rect (a 32x32 block's 16x32), never
32730+ // `chroma_side`-square -- the square read below would pair
32731+ // a `chroma_side`-square unit with the 4:2:0 unit scan
32732+ // (one-coefficient-per-position assert in
32733+ // inverse_transform_2d_typed_wh). The rect reader codes
32734+ // the exact `av1_get_max_uv_txsize` unit (TX_16X32,
32735+ // `rect_inter_chroma_set`'s tables).
3270432736 (u_grid, v_grid, rect_chroma_units) = read_inter_rect_chroma(
3270532737 dec,
3270632738 cdfs,
@@ -34198,9 +34230,16 @@ fn decode_inter_block(
3419834230 // whole-block record must not overwrite them with the
3419934231 // assembled grid (class `override-slot-on-one-arm`).
3420034232 mu_chroma = true;
34201- } else if rect_tu {
34233+ } else if rect_tu
34234+ || (write_chroma_w, write_chroma_h) != (chroma_side, chroma_side)
34235+ {
3420234236 // One chroma read for the whole strip at 4:2:0, two
3420334237 // 32-capped units at 4:4:4 -- see the helper.
34238+ // lane-av1-422j: same rule as the compound arm above -- a
34239+ // 4:2:2 square block's chroma plane is the
34240+ // (side/2 x side) rect, so the rect reader takes it
34241+ // instead of pairing a `chroma_side`-square unit with the
34242+ // 4:2:0 scan.
3420434243 (u_grid, v_grid, rect_chroma_units) = read_inter_rect_chroma(
3420534244 dec,
3420634245 cdfs,
lanes/av1422j.report.mdadded+99 -0
@@ -0,0 +1,99 @@
1+# lane-av1-422j — inter chroma skip residual sized from the write rect; frame 1 decodes past the VERT_B skip strip; refusal stays
2+
3+## Outcome
4+
5+The frame-1 panic at `decode.rs:29094:39` (`range end index 68 out of range
6+for slice of length 64`) is fixed by sizing `decode_inter_block`'s chroma
7+square from the write rect instead of the block side, and the same-shape sweep
8+found exactly one more instance of the class, sharing the same fix. The
9+16-frame stream is NOT pixel-exact — the frontier moved to the intra-in-inter
10+chroma read, a different machinery — so the 4:2:2 header refusal STAYS
11+(byte-identical, unconditional; the local `EC_AV1_ALLOW_422_PROBE` bypass was
12+reverted before commit).
13+
14+## Root cause and fix
15+
16+`decode_inter_block` computed `chroma_side = side >> ss_x(fctx)` (old
17+decode.rs:31227). Every consumer indexes the chroma prediction/residual
18+buffers `row * chroma_side + col` over the WRITE rect
19+(`write_chroma_w x write_chroma_h`), and at ss (1,0) that rect is
20+`side/2 x side`: frame 1's skipped 16-level VERT_B strip at mi(4,0)
21+(8x16 luma, tell 542) has a 4x16 chroma rect, so a `side >> ss_x` = 8 square
22+is shorter than `row * 8 + 4` on rows >= 8 — the all-zero-residual copy read
23+`prediction[64..68]` out of the 64-sample buffer (reconstruct_mc_rect's
24+`residual.is_empty()` branch, decode.rs:29094). Fixture
25+`/tmp/t422.obu` sha256
26+`d3fa4beeb1309033e4a03f5ae5c431c8fa8386ba1ada088684710423c7938129`
27+reproduced it before the change and passes the block after it.
28+
29+Fix: `let chroma_side = (side >> ss_x(fctx)).max(side >> ss_y(fctx));`
30+(decode.rs:31237) — the enclosing square of the chroma rect. Bit-identical at
31+4:2:0 (`side/2`) and 4:4:4 (`side`); only 4:2:2 changes shape.
32+
33+## Same-shape sweep (ZERO_RESIDUAL slices vs forwarded w/h)
34+
35+- `decode_inter_block` skip arms, single-ref (33803..) and compound (32325..):
36+ both chroma pushes forward `(write_chroma_w, write_chroma_h)` at stride
37+ `chroma_side` with `ZERO_RESIDUAL[..chroma_side * chroma_side]` — healed by
38+ the one-line fix (chroma_side >= both write dims now). The paired
39+ `Grid::Zero(chroma_side * chroma_side)` bookkeeping matches the slices.
40+- Luma skip arms (`ZERO_RESIDUAL[..side * side]`, stride `side`, rect
41+ `(write_w, write_h)` with w,h <= side): max index
42+ `(write_h-1)*side + write_w <= side*side` — provably safe, untouched.
43+- Other inter-path slices audited against their forwarded dims:
44+ `decode_block_rect4` skip arm (`side * bh` / `cside * ch` — stride*rows
45+ sizing, safe), `decode_intrabc_rect` (11682/12024, square >= rect, safe),
46+ 14205 (`side * bh`, safe), 37037/37187 (4:4:4-only, SIDE^2 >= rect, safe),
47+ 37338 sub8 tail (square push, safe). `decode_inter_block8`'s chroma
48+ `push_mc` (square) always fits its own square slice — no panic class there;
49+ its 4:2:2 8x8-leaf chroma is a latent half-write shape, NOT this class, and
50+ was left for its owning lane.
51+
52+## Frontier re-measure (EC_AV1_ALLOW_422_PROBE=1, local only)
53+
54+1. After the sizing fix the skip strip passes and the next stop was
55+ `transform.rs:1150` (`one coefficient per position`, 256 vs 1024): the
56+ square non-skip chroma arm read a `chroma_side`-SQUARE unit (32x32 after
57+ the fix) with the caller's 4:2:0 `scan_chroma` (TX_16X16) on the 32x32
58+ inter block at px=0 py=0. Fix: both chroma arms route non-square chroma
59+ rects through `read_inter_rect_chroma`
60+ (`rect_tu || (write_chroma_w, write_chroma_h) != (chroma_side,
61+ chroma_side)`, decode.rs:32712/34222) — a 32x32 block codes ONE TX_16X32
62+ chroma unit (`av1_get_max_uv_txsize` of BLOCK_16X32), exactly
63+ `rect_inter_chroma_set`'s (16,32) row. 4:2:0/4:4:4 squares keep the square
64+ arm (their chroma rect IS `chroma_side`-square).
65+2. Next stop: `rect_inter_chroma_set` refused (8,8) — a 4:2:2 HORZ_B 16x8
66+ strip's chroma plane block is 8x8 SQUARE and the rect reader now takes it.
67+ Added the square rows (16,16)->Chroma16, (8,8)->Chroma8, (4,4)->Chroma4
68+ (decode.rs:22420) — the exact `get_txsize_entropy_ctx` tables the square
69+ arms use; unreachable before this lane.
70+3. Next stop: `rect_scan` refused squares for the same units; added
71+ `(w, h) if w == h => default_scan(w)` (decode.rs:22485).
72+4. Current named stop: an INTRA 16x16 block inside frame 1 (px=192 py=96)
73+ panics in the intra-in-inter branch's chroma `read_plane`
74+ (`exec_intra` -> `reconstruct`, index len 128 idx 128, decode.rs:3845) —
75+ the intra chroma reader still predicts/reconstructs at square
76+ `chroma_side` shapes. That is intra prediction machinery, not the
77+ ZERO_RESIDUAL slice class, and reworking it means inventing chroma
78+ shapes beyond this lane's mandate; left as the named stop for the
79+ owning lane.
80+
81+4:2:2 chroma counters PROVE chroma units ran on the probe path:
82+`chroma422_square: 24`, `chroma422_rect: 96`, `chroma422_sub8: 26` — but the
83+stream is not pixel-exact, so the delete condition (pixel-exact + counter) is
84+unmet and the refusal stays.
85+
86+## State
87+
88+- Source change: `crates/ec-av1/src/decode.rs` only (chroma_side sizing, two
89+ rect-routing conditions, square set/scan rows). `git diff` = 42 insertions,
90+ 3 deletions. The stream.rs probe bypass is REVERTED; default refusal
91+ re-verified firing: `REFUSED: unsupported: AV1 decode_stream (a chroma
92+ format of 4:2:2 ...)`.
93+- 420 gates green (target dir `$HOME/.cache/cargo-target-av1422j`):
94+ `a_non_420_subsampled_sequence_header_is_refused_by_name` 1/1;
95+ `a_real_aomenc_stream_with_a_skipped_8x8_intra_leaf_whose_tx_split_decodes_
96+ pixel_exact` 2/2 (both bit depths) under `EC_AV1_REQUIRE_AOMENC=1` — a real
97+ 420 decode gate over the shared `decode_inter_block` path, confirming the
98+ changes are bit-neutral at 4:2:0. `cargo check -p ec-av1`: 0 warnings.
99+- No push. Probe traces left at /tmp/t422_probe.txt/.err.