diff --git a/crates/ec-av1/src/decode.rs b/crates/ec-av1/src/decode.rs index aff6ebb2..2f131e1e 100644 --- a/crates/ec-av1/src/decode.rs +++ b/crates/ec-av1/src/decode.rs @@ -22417,6 +22417,13 @@ fn rect_inter_chroma_set(w: usize, h: usize) -> Result { // block (`av1_get_max_uv_txsize` adjusts `TX_64X32`/`TX_32X64` to // `TX_32X32`); `get_txsize_entropy_ctx(TX_32X32)` is the 32x32 set. (32, 32) => TxbSet::Chroma32, + // lane-av1-422j: square chroma units of a 4:2:2 strip -- a 16x8 + // (8x16) luma strip's chroma plane block is 8x8 (16x16) square, and + // the square-block routing above sends it here. The sets are the + // exact `get_txsize_entropy_ctx` tables the square arms use. + (16, 16) => TxbSet::Chroma16, + (8, 8) => TxbSet::Chroma8, + (4, 4) => TxbSet::Chroma4, _ => { return Err(unsupported( "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]> { (4, 8) => &SCAN_4X8, (32, 8) => &SCAN_32X8, (8, 32) => &SCAN_8X32, + // lane-av1-422j: square units routed through the rect reader -- a + // 4:2:2 strip's square chroma plane block (8x8 under a 16x8 strip, + // 16x16 under an 8x16 one). The default 2D scan is exactly what the + // square reader uses for the same side. + (w, h) if w == h => default_scan(w), _ => { return Err(unsupported( "a rectangular transform unit whose shape has no coefficient scan table here", @@ -31223,7 +31235,17 @@ fn decode_inter_block( Some(s) if s.has_chroma => (s.pair_mi.1 * MI >> ss_x(fctx), s.pair_mi.0 * MI >> ss_y(fctx)), _ => (px >> ss_x(fctx), py >> ss_y(fctx)), }; - let chroma_side = side >> ss_x(fctx); + // lane-av1-422j: the chroma prediction/residual buffers are + // `chroma_side`-square and every consumer indexes them + // `row * chroma_side + col` over the WRITE rect (`write_chroma_w` x + // `write_chroma_h`). At ss (1,0) that rect is `side/2 x side` (an 8x16 + // strip's 4x16 chroma), so a `side >> ss_x` square is shorter than + // `row * chroma_side + write_chroma_w` on rows `>= side/2` -- frame 1's + // skipped VERT_B strip read `prediction[64..68]` out of the 64-sample + // buffer (reconstruct_mc_rect panic, decode.rs:29094). The enclosing + // square of the chroma rect is the max: unchanged at 4:2:0 (side/2) and + // 4:4:4 (side), so only 4:2:2 changes shape. + let chroma_side = (side >> ss_x(fctx)).max(side >> ss_y(fctx)); let (write_chroma_w, write_chroma_h) = match strip_chroma { Some(s) if s.has_chroma => { // 4:2:0: the PAIR's 8x4 / 4x8. 4:4:4: the strip's own 16x4 / @@ -32698,9 +32720,19 @@ fn decode_inter_block( // whole-block record must not overwrite them with the // assembled grid (class `override-slot-on-one-arm`). mu_chroma = true; - } else if rect_tu { + } else if rect_tu + || (write_chroma_w, write_chroma_h) != (chroma_side, chroma_side) + { // One chroma read for the whole strip at 4:2:0, two // 32-capped units at 4:4:4 -- see the helper. + // lane-av1-422j: a 4:2:2 square block's chroma plane is the + // (side/2 x side) rect (a 32x32 block's 16x32), never + // `chroma_side`-square -- the square read below would pair + // a `chroma_side`-square unit with the 4:2:0 unit scan + // (one-coefficient-per-position assert in + // inverse_transform_2d_typed_wh). The rect reader codes + // the exact `av1_get_max_uv_txsize` unit (TX_16X32, + // `rect_inter_chroma_set`'s tables). (u_grid, v_grid, rect_chroma_units) = read_inter_rect_chroma( dec, cdfs, @@ -34198,9 +34230,16 @@ fn decode_inter_block( // whole-block record must not overwrite them with the // assembled grid (class `override-slot-on-one-arm`). mu_chroma = true; - } else if rect_tu { + } else if rect_tu + || (write_chroma_w, write_chroma_h) != (chroma_side, chroma_side) + { // One chroma read for the whole strip at 4:2:0, two // 32-capped units at 4:4:4 -- see the helper. + // lane-av1-422j: same rule as the compound arm above -- a + // 4:2:2 square block's chroma plane is the + // (side/2 x side) rect, so the rect reader takes it + // instead of pairing a `chroma_side`-square unit with the + // 4:2:0 scan. (u_grid, v_grid, rect_chroma_units) = read_inter_rect_chroma( dec, cdfs, diff --git a/lanes/av1422j.report.md b/lanes/av1422j.report.md new file mode 100644 index 00000000..0332f8d5 --- /dev/null +++ b/lanes/av1422j.report.md @@ -0,0 +1,99 @@ +# lane-av1-422j — inter chroma skip residual sized from the write rect; frame 1 decodes past the VERT_B skip strip; refusal stays + +## Outcome + +The frame-1 panic at `decode.rs:29094:39` (`range end index 68 out of range +for slice of length 64`) is fixed by sizing `decode_inter_block`'s chroma +square from the write rect instead of the block side, and the same-shape sweep +found exactly one more instance of the class, sharing the same fix. The +16-frame stream is NOT pixel-exact — the frontier moved to the intra-in-inter +chroma read, a different machinery — so the 4:2:2 header refusal STAYS +(byte-identical, unconditional; the local `EC_AV1_ALLOW_422_PROBE` bypass was +reverted before commit). + +## Root cause and fix + +`decode_inter_block` computed `chroma_side = side >> ss_x(fctx)` (old +decode.rs:31227). Every consumer indexes the chroma prediction/residual +buffers `row * chroma_side + col` over the WRITE rect +(`write_chroma_w x write_chroma_h`), and at ss (1,0) that rect is +`side/2 x side`: frame 1's skipped 16-level VERT_B strip at mi(4,0) +(8x16 luma, tell 542) has a 4x16 chroma rect, so a `side >> ss_x` = 8 square +is shorter than `row * 8 + 4` on rows >= 8 — the all-zero-residual copy read +`prediction[64..68]` out of the 64-sample buffer (reconstruct_mc_rect's +`residual.is_empty()` branch, decode.rs:29094). Fixture +`/tmp/t422.obu` sha256 +`d3fa4beeb1309033e4a03f5ae5c431c8fa8386ba1ada088684710423c7938129` +reproduced it before the change and passes the block after it. + +Fix: `let chroma_side = (side >> ss_x(fctx)).max(side >> ss_y(fctx));` +(decode.rs:31237) — the enclosing square of the chroma rect. Bit-identical at +4:2:0 (`side/2`) and 4:4:4 (`side`); only 4:2:2 changes shape. + +## Same-shape sweep (ZERO_RESIDUAL slices vs forwarded w/h) + +- `decode_inter_block` skip arms, single-ref (33803..) and compound (32325..): + both chroma pushes forward `(write_chroma_w, write_chroma_h)` at stride + `chroma_side` with `ZERO_RESIDUAL[..chroma_side * chroma_side]` — healed by + the one-line fix (chroma_side >= both write dims now). The paired + `Grid::Zero(chroma_side * chroma_side)` bookkeeping matches the slices. +- Luma skip arms (`ZERO_RESIDUAL[..side * side]`, stride `side`, rect + `(write_w, write_h)` with w,h <= side): max index + `(write_h-1)*side + write_w <= side*side` — provably safe, untouched. +- Other inter-path slices audited against their forwarded dims: + `decode_block_rect4` skip arm (`side * bh` / `cside * ch` — stride*rows + sizing, safe), `decode_intrabc_rect` (11682/12024, square >= rect, safe), + 14205 (`side * bh`, safe), 37037/37187 (4:4:4-only, SIDE^2 >= rect, safe), + 37338 sub8 tail (square push, safe). `decode_inter_block8`'s chroma + `push_mc` (square) always fits its own square slice — no panic class there; + its 4:2:2 8x8-leaf chroma is a latent half-write shape, NOT this class, and + was left for its owning lane. + +## Frontier re-measure (EC_AV1_ALLOW_422_PROBE=1, local only) + +1. After the sizing fix the skip strip passes and the next stop was + `transform.rs:1150` (`one coefficient per position`, 256 vs 1024): the + square non-skip chroma arm read a `chroma_side`-SQUARE unit (32x32 after + the fix) with the caller's 4:2:0 `scan_chroma` (TX_16X16) on the 32x32 + inter block at px=0 py=0. Fix: both chroma arms route non-square chroma + rects through `read_inter_rect_chroma` + (`rect_tu || (write_chroma_w, write_chroma_h) != (chroma_side, + chroma_side)`, decode.rs:32712/34222) — a 32x32 block codes ONE TX_16X32 + chroma unit (`av1_get_max_uv_txsize` of BLOCK_16X32), exactly + `rect_inter_chroma_set`'s (16,32) row. 4:2:0/4:4:4 squares keep the square + arm (their chroma rect IS `chroma_side`-square). +2. Next stop: `rect_inter_chroma_set` refused (8,8) — a 4:2:2 HORZ_B 16x8 + strip's chroma plane block is 8x8 SQUARE and the rect reader now takes it. + Added the square rows (16,16)->Chroma16, (8,8)->Chroma8, (4,4)->Chroma4 + (decode.rs:22420) — the exact `get_txsize_entropy_ctx` tables the square + arms use; unreachable before this lane. +3. Next stop: `rect_scan` refused squares for the same units; added + `(w, h) if w == h => default_scan(w)` (decode.rs:22485). +4. Current named stop: an INTRA 16x16 block inside frame 1 (px=192 py=96) + panics in the intra-in-inter branch's chroma `read_plane` + (`exec_intra` -> `reconstruct`, index len 128 idx 128, decode.rs:3845) — + the intra chroma reader still predicts/reconstructs at square + `chroma_side` shapes. That is intra prediction machinery, not the + ZERO_RESIDUAL slice class, and reworking it means inventing chroma + shapes beyond this lane's mandate; left as the named stop for the + owning lane. + +4:2:2 chroma counters PROVE chroma units ran on the probe path: +`chroma422_square: 24`, `chroma422_rect: 96`, `chroma422_sub8: 26` — but the +stream is not pixel-exact, so the delete condition (pixel-exact + counter) is +unmet and the refusal stays. + +## State + +- Source change: `crates/ec-av1/src/decode.rs` only (chroma_side sizing, two + rect-routing conditions, square set/scan rows). `git diff` = 42 insertions, + 3 deletions. The stream.rs probe bypass is REVERTED; default refusal + re-verified firing: `REFUSED: unsupported: AV1 decode_stream (a chroma + format of 4:2:2 ...)`. +- 420 gates green (target dir `$HOME/.cache/cargo-target-av1422j`): + `a_non_420_subsampled_sequence_header_is_refused_by_name` 1/1; + `a_real_aomenc_stream_with_a_skipped_8x8_intra_leaf_whose_tx_split_decodes_ + pixel_exact` 2/2 (both bit depths) under `EC_AV1_REQUIRE_AOMENC=1` — a real + 420 decode gate over the shared `decode_inter_block` path, confirming the + changes are bit-neutral at 4:2:0. `cargo check -p ec-av1`: 0 warnings. +- No push. Probe traces left at /tmp/t422_probe.txt/.err.