From a8807233d019bd103b101790e2226566b49135c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Fri, 25 Sep 2026 10:16:27 +0300 Subject: [PATCH] ec-av1: lane-av1-422k -- size intra-in-inter chroma prediction from the plane block; refusal stays --- crates/ec-av1/src/decode.rs | 161 ++++++++++++++++++++++++------------ lanes/av1422k.report.md | 79 ++++++++++++++++++ 2 files changed, 188 insertions(+), 52 deletions(-) create mode 100644 lanes/av1422k.report.md diff --git a/crates/ec-av1/src/decode.rs b/crates/ec-av1/src/decode.rs index 2f131e1e..5107799b 100644 --- a/crates/ec-av1/src/decode.rs +++ b/crates/ec-av1/src/decode.rs @@ -34942,6 +34942,17 @@ fn decode_inter_block( } } } + // lane-av1-422k: the chroma PREDICTION shape is the plane block + // (`side >> ss_x`, `side >> ss_y`) -- square at 4:2:0/4:4:4, a + // (side/2, side) rect at 4:2:2. `chroma_side` (the 422j enclosing + // square of that rect) is the right size for BOOKKEEPING buffers but + // the wrong SHAPE to predict and reconstruct at: an intra-in-inter + // block's chroma prediction indexes its CFL signal and residual + // `row * chroma_w + col` over the plane block, and a 16x16 luma + // block's 8x16 chroma CFL signal is 128 samples -- predicting at the + // 16x16 square read `ac[128]` out of it (frame 1, px=192 py=96). + let chroma_w = side >> ss_x(fctx); + let chroma_h = side >> ss_y(fctx); if side > 64 { // Chroma is already coded and reconstructed per mu chunk above. luma_grid = Grid::Zero(side * side); @@ -34978,14 +34989,15 @@ fn decode_inter_block( if let Some((ub, _)) = &palette_uv_bufs { set_palette_pred(ub.clone(), fctx); } - push_intra(1, + push_intra_unit(1, cpx, cpy, - chroma_side, + chroma_w, + chroma_h, uv_predict_mode, angle_delta_uv, reach, - &ZERO_RESIDUAL[..chroma_side * chroma_side], + &ZERO_RESIDUAL[..chroma_w * chroma_h], alpha.zip(ac).map(|((au, _), ac)| (au, ac)), None, smooth_neighbor_uv, fctx, @@ -34993,21 +35005,22 @@ fn decode_inter_block( if let Some((_, vb)) = &palette_uv_bufs { set_palette_pred(vb.clone(), fctx); } - push_intra(2, + push_intra_unit(2, cpx, cpy, - chroma_side, + chroma_w, + chroma_h, uv_predict_mode, angle_delta_uv, reach, - &ZERO_RESIDUAL[..chroma_side * chroma_side], + &ZERO_RESIDUAL[..chroma_w * chroma_h], alpha.zip(ac).map(|((_, av), ac)| (av, ac)), None, smooth_neighbor_uv, fctx, ); luma_grid = Grid::Zero(side * side); - u_grid = Grid::Zero(chroma_side * chroma_side); - v_grid = Grid::Zero(chroma_side * chroma_side); + u_grid = Grid::Zero(chroma_w * chroma_h); + v_grid = Grid::Zero(chroma_w * chroma_h); } else { let around = neighbours.around_mi(at, side); if split_luma { @@ -35060,56 +35073,100 @@ fn decode_inter_block( v_grid = if vo.is_empty() { Grid::Zero(zero) } else { Grid::Own(vo) }; mu_chroma = true; } else { + // lane-av1-422k: the chroma plane block is (`chroma_w`, + // `chroma_h`) -- the square read above at 4:2:0/4:4:4, one rect + // TX_{side/2}X{side} unit through [`read_rect_chroma_unit`] at + // 4:2:2 (the key-frame path's proven set/scan rows, and the + // per-chroma-cell context read [`around_mi_422_chroma`]). + let chroma_around = if chroma_w == chroma_h { + around + } else { + neighbours.around_mi_422_chroma(at, side, side) + }; if let Some((ub, _)) = &palette_uv_bufs { set_palette_pred(ub.clone(), fctx); } - u_grid = read_plane( - dec, - cdfs, - chroma_set, - scan_chroma, - 1, - around[1], - mode, - uv_predict_mode, - angle_delta_uv, - reach, - u, - cpx, - cpy, - chroma_side, - chroma_tx, - base_q_idx, - alpha.zip(ac).map(|((au, _), ac)| (au, ac)), - None, - None, - smooth_neighbor_uv, fctx, - )?; + u_grid = if chroma_w == chroma_h { + read_plane( + dec, + cdfs, + chroma_set, + scan_chroma, + 1, + chroma_around[1], + mode, + uv_predict_mode, + angle_delta_uv, + reach, + u, + cpx, + cpy, + chroma_side, + chroma_tx, + base_q_idx, + alpha.zip(ac).map(|((au, _), ac)| (au, ac)), + None, + None, + smooth_neighbor_uv, fctx, + )? + } else { + let (rect_set, rect_scan): (TxbSet, &[u16]) = match side { + 4 => (TxbSet::Chroma4, default_scan(4)), + 8 => (TxbSet::ChromaRect8x4, &SCAN_4X8[..]), + 16 => (TxbSet::ChromaRect16x8, &SCAN_8X16[..]), + 32 => (TxbSet::ChromaRect32x16, &SCAN_16X32[..]), + _ => (TxbSet::Chroma32, default_scan(32)), + }; + read_rect_chroma_unit( + dec, cdfs, rect_set, rect_scan, chroma_w, chroma_h, 1, + chroma_around[1], uv_predict_mode, angle_delta_uv, reach, u, + cpx, cpy, base_q_idx, + alpha.zip(ac).map(|((au, _), ac)| (au, ac)), + smooth_neighbor_uv, fctx, + )? + }; if let Some((_, vb)) = &palette_uv_bufs { set_palette_pred(vb.clone(), fctx); } - v_grid = read_plane( - dec, - cdfs, - chroma_set, - scan_chroma, - 2, - around[2], - mode, - uv_predict_mode, - angle_delta_uv, - reach, - v, - cpx, - cpy, - chroma_side, - chroma_tx, - base_q_idx, - alpha.zip(ac).map(|((_, av), ac)| (av, ac)), - None, - None, - smooth_neighbor_uv, fctx, - )?; + v_grid = if chroma_w == chroma_h { + read_plane( + dec, + cdfs, + chroma_set, + scan_chroma, + 2, + chroma_around[2], + mode, + uv_predict_mode, + angle_delta_uv, + reach, + v, + cpx, + cpy, + chroma_side, + chroma_tx, + base_q_idx, + alpha.zip(ac).map(|((_, av), ac)| (av, ac)), + None, + None, + smooth_neighbor_uv, fctx, + )? + } else { + let (rect_set, rect_scan): (TxbSet, &[u16]) = match side { + 4 => (TxbSet::Chroma4, default_scan(4)), + 8 => (TxbSet::ChromaRect8x4, &SCAN_4X8[..]), + 16 => (TxbSet::ChromaRect16x8, &SCAN_8X16[..]), + 32 => (TxbSet::ChromaRect32x16, &SCAN_16X32[..]), + _ => (TxbSet::Chroma32, default_scan(32)), + }; + read_rect_chroma_unit( + dec, cdfs, rect_set, rect_scan, chroma_w, chroma_h, 2, + chroma_around[2], uv_predict_mode, angle_delta_uv, reach, v, + cpx, cpy, base_q_idx, + alpha.zip(ac).map(|((_, av), ac)| (av, ac)), + smooth_neighbor_uv, fctx, + )? + }; } } } diff --git a/lanes/av1422k.report.md b/lanes/av1422k.report.md new file mode 100644 index 00000000..7dd5701c --- /dev/null +++ b/lanes/av1422k.report.md @@ -0,0 +1,79 @@ +# lane-av1-422k — intra-in-inter chroma prediction sized from the plane block; frame 1's INTRA 16x16 passes; refusal stays + +## Outcome + +The frame-1 panic at `decode.rs:3845` (`index out of bounds: the len is 128 +but the index is 128`) is fixed by sizing `decode_inter_block`'s INTRA arm's +chroma prediction/reconstruction from the 4:2:2 plane block +(`side >> ss_x`, `side >> ss_y`) instead of the enclosing square. The panic +was NOT the residual-slice class: the len-128 slice was the CfL AC SIGNAL. +The 16-frame stream is NOT pixel-exact — the frontier moved to the INTER +chroma rect-set table (a clean named refusal, different machinery) — so the +4:2:2 header refusal STAYS (re-verified firing by default; the local +`EC_AV1_ALLOW_422_PROBE` bypass was reverted before commit). + +## Root cause and fix + +Frame 1's block at px=192 py=96 is a SKIPPED 16x16 INTRA block inside the +inter frame (DC_PRED + CFL, zero residual), decoded by `decode_inter_block`'s +intra arm. That arm pushed/read chroma at the 422j enclosing square +`chroma_side = max(side >> ss_x, side >> ss_y)` = 16 for a 16x16 luma block, +but the 4:2:2 chroma plane block is 8x16: + +- The skip arm (`push_intra(1/2, cpx, cpy, chroma_side, ...)`) pushed a + SQUARE 16x16 op with `ZERO_RESIDUAL` and CFL armed. `ac = cfl_src(px, py, + side)` builds the AC signal over the LUMA 16x16, which `cfl_ac_ss` + downsamples to the true plane shape 8x16 = 128 samples. The square + `reconstruct` walked `row * 16 + col` and read `ac_q3[128]` — the panic. + (Instrumented `exec_intra`: `plane=1 x=96 y=96 bw=16 bh=16 rect=false + res_len=0 cfl=true`.) Even without the panic the square predict would have + written 8 columns of wrong chroma past the plane block. + +Fix (decode.rs, intra arm only): + +1. `let chroma_w = side >> ss_x(fctx); let chroma_h = side >> ss_y(fctx);` +2. Skip arm: `push_intra_unit(1/2, cpx, cpy, chroma_w, chroma_h, ...)` with + `ZERO_RESIDUAL[..chroma_w * chroma_h]` (routes rect to + `push_intra_rect`/`reconstruct_rect`); the neighbour write-back grids are + `Grid::Zero(chroma_w * chroma_h)`. +3. Non-skip arm: `chroma_w == chroma_h` keeps the square `read_plane` + verbatim; at 4:2:2 both planes go through `read_rect_chroma_unit` with the + key-frame path's proven set/scan rows keyed on the LUMA side (16 -> + `ChromaRect16x8` + `SCAN_8X16`, 8 -> `ChromaRect8x4`, 32 -> + `ChromaRect32x16`) and the per-chroma-cell context read + (`around_mi_422_chroma`), exactly the decode_block 422f idiom. + +Byte-identical at 4:2:0 and 4:4:4: `chroma_w == chroma_h == chroma_side` +there, so every replaced call keeps its exact arguments and +`push_intra_unit` routes to the same square `push_intra`. + +Fixture `/tmp/t422.obu` sha256 +`d3fa4beeb1309033e4a03f5ae5c431c8fa8386ba1ada088684710423c7938129` +panicked before the change and passes the block after it. + +## Frontier (EC_AV1_ALLOW_422_PROBE=1, local only, bypass since reverted) + +Next stop is a clean refusal, not a panic: +`rect_inter_chroma_set` (decode.rs:22401, refusal string at decode.rs:22429) +— "a rectangular inter chroma transform unit whose shape has no coefficient +table set here". A later inter block in frame 1 codes a chroma rect unit +whose (w, h) has no row in that table (the 422j square rows (16,16)/(8,8)/(4,4) +and the rect rows listed there are present; the new shape is none of them). +That is the inter chroma entropy-set table, not the intra prediction class +this lane owns — left as the named stop; an `EC_*` print of the refusing +(w, h) at that site is the first step for the owning lane. + +## State + +- Source change: `crates/ec-av1/src/decode.rs` only (intra-arm chroma_w/h, + skip-arm unit pushes + grid sizes, non-skip rect routing). Temporary + exec_intra/push_intra traces and the stream.rs probe bypass are 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-av1422k`): + `a_non_420_subsampled_sequence_header_is_refused_by_name` + + `a_real_aomenc_stream_with_a_skipped_8x8_intra_leaf_whose_tx_split_decodes_ + pixel_exact` under `EC_AV1_REQUIRE_AOMENC=1`: 3 passed, 0 failed. Real + 420 decode over the shared intra arm, confirming the change is bit-neutral + at 4:2:0. `cargo check -p ec-av1`: 0 warnings. +- No push.