ec-av1: lane-av1-422j -- size inter chroma skip residual from the write rect; refusal stays
Browse files at this commitdfeffbcebd64426ceeebbf03214c8d6fe57282d6Parent: 3ed346e2 changed files +141 -3
- crates/ec-av1/src/decode.rs +42 -3
- lanes/av1422j.report.md +99 -0
crates/ec-av1/src/decode.rsmodified+42 -3
| @@ -22417,6 +22417,13 @@ fn rect_inter_chroma_set(w: usize, h: usize) -> Result<TxbSet> { | |||
| 22417 | // block (`av1_get_max_uv_txsize` adjusts `TX_64X32`/`TX_32X64` to | 22417 | // block (`av1_get_max_uv_txsize` adjusts `TX_64X32`/`TX_32X64` to |
| 22418 | // `TX_32X32`); `get_txsize_entropy_ctx(TX_32X32)` is the 32x32 set. | 22418 | // `TX_32X32`); `get_txsize_entropy_ctx(TX_32X32)` is the 32x32 set. |
| 22419 | (32, 32) => TxbSet::Chroma32, | 22419 | (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, | ||
| 22420 | _ => { | 22427 | _ => { |
| 22421 | return Err(unsupported( | 22428 | return Err(unsupported( |
| 22422 | "a rectangular inter chroma transform unit whose shape has no coefficient table set here", | 22429 | "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]> { | |||
| 22471 | (4, 8) => &SCAN_4X8, | 22478 | (4, 8) => &SCAN_4X8, |
| 22472 | (32, 8) => &SCAN_32X8, | 22479 | (32, 8) => &SCAN_32X8, |
| 22473 | (8, 32) => &SCAN_8X32, | 22480 | (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), | ||
| 22474 | _ => { | 22486 | _ => { |
| 22475 | return Err(unsupported( | 22487 | return Err(unsupported( |
| 22476 | "a rectangular transform unit whose shape has no coefficient scan table here", | 22488 | "a rectangular transform unit whose shape has no coefficient scan table here", |
| @@ -31223,7 +31235,17 @@ fn decode_inter_block( | |||
| 31223 | Some(s) if s.has_chroma => (s.pair_mi.1 * MI >> ss_x(fctx), s.pair_mi.0 * MI >> ss_y(fctx)), | 31235 | Some(s) if s.has_chroma => (s.pair_mi.1 * MI >> ss_x(fctx), s.pair_mi.0 * MI >> ss_y(fctx)), |
| 31224 | _ => (px >> ss_x(fctx), py >> ss_y(fctx)), | 31236 | _ => (px >> ss_x(fctx), py >> ss_y(fctx)), |
| 31225 | }; | 31237 | }; |
| 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)); | ||
| 31227 | let (write_chroma_w, write_chroma_h) = match strip_chroma { | 31249 | let (write_chroma_w, write_chroma_h) = match strip_chroma { |
| 31228 | Some(s) if s.has_chroma => { | 31250 | Some(s) if s.has_chroma => { |
| 31229 | // 4:2:0: the PAIR's 8x4 / 4x8. 4:4:4: the strip's own 16x4 / | 31251 | // 4:2:0: the PAIR's 8x4 / 4x8. 4:4:4: the strip's own 16x4 / |
| @@ -32698,9 +32720,19 @@ fn decode_inter_block( | |||
| 32698 | // whole-block record must not overwrite them with the | 32720 | // whole-block record must not overwrite them with the |
| 32699 | // assembled grid (class `override-slot-on-one-arm`). | 32721 | // assembled grid (class `override-slot-on-one-arm`). |
| 32700 | mu_chroma = true; | 32722 | 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 | + { | ||
| 32702 | // One chroma read for the whole strip at 4:2:0, two | 32726 | // One chroma read for the whole strip at 4:2:0, two |
| 32703 | // 32-capped units at 4:4:4 -- see the helper. | 32727 | // 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). | ||
| 32704 | (u_grid, v_grid, rect_chroma_units) = read_inter_rect_chroma( | 32736 | (u_grid, v_grid, rect_chroma_units) = read_inter_rect_chroma( |
| 32705 | dec, | 32737 | dec, |
| 32706 | cdfs, | 32738 | cdfs, |
| @@ -34198,9 +34230,16 @@ fn decode_inter_block( | |||
| 34198 | // whole-block record must not overwrite them with the | 34230 | // whole-block record must not overwrite them with the |
| 34199 | // assembled grid (class `override-slot-on-one-arm`). | 34231 | // assembled grid (class `override-slot-on-one-arm`). |
| 34200 | mu_chroma = true; | 34232 | 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 | + { | ||
| 34202 | // One chroma read for the whole strip at 4:2:0, two | 34236 | // One chroma read for the whole strip at 4:2:0, two |
| 34203 | // 32-capped units at 4:4:4 -- see the helper. | 34237 | // 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. | ||
| 34204 | (u_grid, v_grid, rect_chroma_units) = read_inter_rect_chroma( | 34243 | (u_grid, v_grid, rect_chroma_units) = read_inter_rect_chroma( |
| 34205 | dec, | 34244 | dec, |
| 34206 | cdfs, | 34245 | 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. | ||