ec-av1: lane-av1-422k -- size intra-in-inter chroma prediction from the plane block; refusal stays
Browse files at this commita8807233d019bd103b101790e2226566b49135c7Parent: dfeffbc2 changed files +188 -52
- crates/ec-av1/src/decode.rs +109 -52
- lanes/av1422k.report.md +79 -0
crates/ec-av1/src/decode.rsmodified+109 -52
| @@ -34942,6 +34942,17 @@ fn decode_inter_block( | |||
| 34942 | } | 34942 | } |
| 34943 | } | 34943 | } |
| 34944 | } | 34944 | } |
| 34945 | + // lane-av1-422k: the chroma PREDICTION shape is the plane block | ||
| 34946 | + // (`side >> ss_x`, `side >> ss_y`) -- square at 4:2:0/4:4:4, a | ||
| 34947 | + // (side/2, side) rect at 4:2:2. `chroma_side` (the 422j enclosing | ||
| 34948 | + // square of that rect) is the right size for BOOKKEEPING buffers but | ||
| 34949 | + // the wrong SHAPE to predict and reconstruct at: an intra-in-inter | ||
| 34950 | + // block's chroma prediction indexes its CFL signal and residual | ||
| 34951 | + // `row * chroma_w + col` over the plane block, and a 16x16 luma | ||
| 34952 | + // block's 8x16 chroma CFL signal is 128 samples -- predicting at the | ||
| 34953 | + // 16x16 square read `ac[128]` out of it (frame 1, px=192 py=96). | ||
| 34954 | + let chroma_w = side >> ss_x(fctx); | ||
| 34955 | + let chroma_h = side >> ss_y(fctx); | ||
| 34945 | if side > 64 { | 34956 | if side > 64 { |
| 34946 | // Chroma is already coded and reconstructed per mu chunk above. | 34957 | // Chroma is already coded and reconstructed per mu chunk above. |
| 34947 | luma_grid = Grid::Zero(side * side); | 34958 | luma_grid = Grid::Zero(side * side); |
| @@ -34978,14 +34989,15 @@ fn decode_inter_block( | |||
| 34978 | if let Some((ub, _)) = &palette_uv_bufs { | 34989 | if let Some((ub, _)) = &palette_uv_bufs { |
| 34979 | set_palette_pred(ub.clone(), fctx); | 34990 | set_palette_pred(ub.clone(), fctx); |
| 34980 | } | 34991 | } |
| 34981 | - push_intra(1, | 34992 | + push_intra_unit(1, |
| 34982 | cpx, | 34993 | cpx, |
| 34983 | cpy, | 34994 | cpy, |
| 34984 | - chroma_side, | 34995 | + chroma_w, |
| 34996 | + chroma_h, | ||
| 34985 | uv_predict_mode, | 34997 | uv_predict_mode, |
| 34986 | angle_delta_uv, | 34998 | angle_delta_uv, |
| 34987 | reach, | 34999 | reach, |
| 34988 | - &ZERO_RESIDUAL[..chroma_side * chroma_side], | 35000 | + &ZERO_RESIDUAL[..chroma_w * chroma_h], |
| 34989 | alpha.zip(ac).map(|((au, _), ac)| (au, ac)), | 35001 | alpha.zip(ac).map(|((au, _), ac)| (au, ac)), |
| 34990 | None, | 35002 | None, |
| 34991 | smooth_neighbor_uv, fctx, | 35003 | smooth_neighbor_uv, fctx, |
| @@ -34993,21 +35005,22 @@ fn decode_inter_block( | |||
| 34993 | if let Some((_, vb)) = &palette_uv_bufs { | 35005 | if let Some((_, vb)) = &palette_uv_bufs { |
| 34994 | set_palette_pred(vb.clone(), fctx); | 35006 | set_palette_pred(vb.clone(), fctx); |
| 34995 | } | 35007 | } |
| 34996 | - push_intra(2, | 35008 | + push_intra_unit(2, |
| 34997 | cpx, | 35009 | cpx, |
| 34998 | cpy, | 35010 | cpy, |
| 34999 | - chroma_side, | 35011 | + chroma_w, |
| 35012 | + chroma_h, | ||
| 35000 | uv_predict_mode, | 35013 | uv_predict_mode, |
| 35001 | angle_delta_uv, | 35014 | angle_delta_uv, |
| 35002 | reach, | 35015 | reach, |
| 35003 | - &ZERO_RESIDUAL[..chroma_side * chroma_side], | 35016 | + &ZERO_RESIDUAL[..chroma_w * chroma_h], |
| 35004 | alpha.zip(ac).map(|((_, av), ac)| (av, ac)), | 35017 | alpha.zip(ac).map(|((_, av), ac)| (av, ac)), |
| 35005 | None, | 35018 | None, |
| 35006 | smooth_neighbor_uv, fctx, | 35019 | smooth_neighbor_uv, fctx, |
| 35007 | ); | 35020 | ); |
| 35008 | luma_grid = Grid::Zero(side * side); | 35021 | luma_grid = Grid::Zero(side * side); |
| 35009 | - u_grid = Grid::Zero(chroma_side * chroma_side); | 35022 | + u_grid = Grid::Zero(chroma_w * chroma_h); |
| 35010 | - v_grid = Grid::Zero(chroma_side * chroma_side); | 35023 | + v_grid = Grid::Zero(chroma_w * chroma_h); |
| 35011 | } else { | 35024 | } else { |
| 35012 | let around = neighbours.around_mi(at, side); | 35025 | let around = neighbours.around_mi(at, side); |
| 35013 | if split_luma { | 35026 | if split_luma { |
| @@ -35060,56 +35073,100 @@ fn decode_inter_block( | |||
| 35060 | v_grid = if vo.is_empty() { Grid::Zero(zero) } else { Grid::Own(vo) }; | 35073 | v_grid = if vo.is_empty() { Grid::Zero(zero) } else { Grid::Own(vo) }; |
| 35061 | mu_chroma = true; | 35074 | mu_chroma = true; |
| 35062 | } else { | 35075 | } else { |
| 35076 | + // lane-av1-422k: the chroma plane block is (`chroma_w`, | ||
| 35077 | + // `chroma_h`) -- the square read above at 4:2:0/4:4:4, one rect | ||
| 35078 | + // TX_{side/2}X{side} unit through [`read_rect_chroma_unit`] at | ||
| 35079 | + // 4:2:2 (the key-frame path's proven set/scan rows, and the | ||
| 35080 | + // per-chroma-cell context read [`around_mi_422_chroma`]). | ||
| 35081 | + let chroma_around = if chroma_w == chroma_h { | ||
| 35082 | + around | ||
| 35083 | + } else { | ||
| 35084 | + neighbours.around_mi_422_chroma(at, side, side) | ||
| 35085 | + }; | ||
| 35063 | if let Some((ub, _)) = &palette_uv_bufs { | 35086 | if let Some((ub, _)) = &palette_uv_bufs { |
| 35064 | set_palette_pred(ub.clone(), fctx); | 35087 | set_palette_pred(ub.clone(), fctx); |
| 35065 | } | 35088 | } |
| 35066 | - u_grid = read_plane( | 35089 | + u_grid = if chroma_w == chroma_h { |
| 35067 | - dec, | 35090 | + read_plane( |
| 35068 | - cdfs, | 35091 | + dec, |
| 35069 | - chroma_set, | 35092 | + cdfs, |
| 35070 | - scan_chroma, | 35093 | + chroma_set, |
| 35071 | - 1, | 35094 | + scan_chroma, |
| 35072 | - around[1], | 35095 | + 1, |
| 35073 | - mode, | 35096 | + chroma_around[1], |
| 35074 | - uv_predict_mode, | 35097 | + mode, |
| 35075 | - angle_delta_uv, | 35098 | + uv_predict_mode, |
| 35076 | - reach, | 35099 | + angle_delta_uv, |
| 35077 | - u, | 35100 | + reach, |
| 35078 | - cpx, | 35101 | + u, |
| 35079 | - cpy, | 35102 | + cpx, |
| 35080 | - chroma_side, | 35103 | + cpy, |
| 35081 | - chroma_tx, | 35104 | + chroma_side, |
| 35082 | - base_q_idx, | 35105 | + chroma_tx, |
| 35083 | - alpha.zip(ac).map(|((au, _), ac)| (au, ac)), | 35106 | + base_q_idx, |
| 35084 | - None, | 35107 | + alpha.zip(ac).map(|((au, _), ac)| (au, ac)), |
| 35085 | - None, | 35108 | + None, |
| 35086 | - smooth_neighbor_uv, fctx, | 35109 | + None, |
| 35087 | - )?; | 35110 | + smooth_neighbor_uv, fctx, |
| 35111 | + )? | ||
| 35112 | + } else { | ||
| 35113 | + let (rect_set, rect_scan): (TxbSet, &[u16]) = match side { | ||
| 35114 | + 4 => (TxbSet::Chroma4, default_scan(4)), | ||
| 35115 | + 8 => (TxbSet::ChromaRect8x4, &SCAN_4X8[..]), | ||
| 35116 | + 16 => (TxbSet::ChromaRect16x8, &SCAN_8X16[..]), | ||
| 35117 | + 32 => (TxbSet::ChromaRect32x16, &SCAN_16X32[..]), | ||
| 35118 | + _ => (TxbSet::Chroma32, default_scan(32)), | ||
| 35119 | + }; | ||
| 35120 | + read_rect_chroma_unit( | ||
| 35121 | + dec, cdfs, rect_set, rect_scan, chroma_w, chroma_h, 1, | ||
| 35122 | + chroma_around[1], uv_predict_mode, angle_delta_uv, reach, u, | ||
| 35123 | + cpx, cpy, base_q_idx, | ||
| 35124 | + alpha.zip(ac).map(|((au, _), ac)| (au, ac)), | ||
| 35125 | + smooth_neighbor_uv, fctx, | ||
| 35126 | + )? | ||
| 35127 | + }; | ||
| 35088 | if let Some((_, vb)) = &palette_uv_bufs { | 35128 | if let Some((_, vb)) = &palette_uv_bufs { |
| 35089 | set_palette_pred(vb.clone(), fctx); | 35129 | set_palette_pred(vb.clone(), fctx); |
| 35090 | } | 35130 | } |
| 35091 | - v_grid = read_plane( | 35131 | + v_grid = if chroma_w == chroma_h { |
| 35092 | - dec, | 35132 | + read_plane( |
| 35093 | - cdfs, | 35133 | + dec, |
| 35094 | - chroma_set, | 35134 | + cdfs, |
| 35095 | - scan_chroma, | 35135 | + chroma_set, |
| 35096 | - 2, | 35136 | + scan_chroma, |
| 35097 | - around[2], | 35137 | + 2, |
| 35098 | - mode, | 35138 | + chroma_around[2], |
| 35099 | - uv_predict_mode, | 35139 | + mode, |
| 35100 | - angle_delta_uv, | 35140 | + uv_predict_mode, |
| 35101 | - reach, | 35141 | + angle_delta_uv, |
| 35102 | - v, | 35142 | + reach, |
| 35103 | - cpx, | 35143 | + v, |
| 35104 | - cpy, | 35144 | + cpx, |
| 35105 | - chroma_side, | 35145 | + cpy, |
| 35106 | - chroma_tx, | 35146 | + chroma_side, |
| 35107 | - base_q_idx, | 35147 | + chroma_tx, |
| 35108 | - alpha.zip(ac).map(|((_, av), ac)| (av, ac)), | 35148 | + base_q_idx, |
| 35109 | - None, | 35149 | + alpha.zip(ac).map(|((_, av), ac)| (av, ac)), |
| 35110 | - None, | 35150 | + None, |
| 35111 | - smooth_neighbor_uv, fctx, | 35151 | + None, |
| 35112 | - )?; | 35152 | + smooth_neighbor_uv, fctx, |
| 35153 | + )? | ||
| 35154 | + } else { | ||
| 35155 | + let (rect_set, rect_scan): (TxbSet, &[u16]) = match side { | ||
| 35156 | + 4 => (TxbSet::Chroma4, default_scan(4)), | ||
| 35157 | + 8 => (TxbSet::ChromaRect8x4, &SCAN_4X8[..]), | ||
| 35158 | + 16 => (TxbSet::ChromaRect16x8, &SCAN_8X16[..]), | ||
| 35159 | + 32 => (TxbSet::ChromaRect32x16, &SCAN_16X32[..]), | ||
| 35160 | + _ => (TxbSet::Chroma32, default_scan(32)), | ||
| 35161 | + }; | ||
| 35162 | + read_rect_chroma_unit( | ||
| 35163 | + dec, cdfs, rect_set, rect_scan, chroma_w, chroma_h, 2, | ||
| 35164 | + chroma_around[2], uv_predict_mode, angle_delta_uv, reach, v, | ||
| 35165 | + cpx, cpy, base_q_idx, | ||
| 35166 | + alpha.zip(ac).map(|((_, av), ac)| (av, ac)), | ||
| 35167 | + smooth_neighbor_uv, fctx, | ||
| 35168 | + )? | ||
| 35169 | + }; | ||
| 35113 | } | 35170 | } |
| 35114 | } | 35171 | } |
| 35115 | } | 35172 | } |
lanes/av1422k.report.mdadded+79 -0
| @@ -0,0 +1,79 @@ | |||
| 1 | +# lane-av1-422k — intra-in-inter chroma prediction sized from the plane block; frame 1's INTRA 16x16 passes; refusal stays | ||
| 2 | + | ||
| 3 | +## Outcome | ||
| 4 | + | ||
| 5 | +The frame-1 panic at `decode.rs:3845` (`index out of bounds: the len is 128 | ||
| 6 | +but the index is 128`) is fixed by sizing `decode_inter_block`'s INTRA arm's | ||
| 7 | +chroma prediction/reconstruction from the 4:2:2 plane block | ||
| 8 | +(`side >> ss_x`, `side >> ss_y`) instead of the enclosing square. The panic | ||
| 9 | +was NOT the residual-slice class: the len-128 slice was the CfL AC SIGNAL. | ||
| 10 | +The 16-frame stream is NOT pixel-exact — the frontier moved to the INTER | ||
| 11 | +chroma rect-set table (a clean named refusal, different machinery) — so the | ||
| 12 | +4:2:2 header refusal STAYS (re-verified firing by default; the local | ||
| 13 | +`EC_AV1_ALLOW_422_PROBE` bypass was reverted before commit). | ||
| 14 | + | ||
| 15 | +## Root cause and fix | ||
| 16 | + | ||
| 17 | +Frame 1's block at px=192 py=96 is a SKIPPED 16x16 INTRA block inside the | ||
| 18 | +inter frame (DC_PRED + CFL, zero residual), decoded by `decode_inter_block`'s | ||
| 19 | +intra arm. That arm pushed/read chroma at the 422j enclosing square | ||
| 20 | +`chroma_side = max(side >> ss_x, side >> ss_y)` = 16 for a 16x16 luma block, | ||
| 21 | +but the 4:2:2 chroma plane block is 8x16: | ||
| 22 | + | ||
| 23 | +- The skip arm (`push_intra(1/2, cpx, cpy, chroma_side, ...)`) pushed a | ||
| 24 | + SQUARE 16x16 op with `ZERO_RESIDUAL` and CFL armed. `ac = cfl_src(px, py, | ||
| 25 | + side)` builds the AC signal over the LUMA 16x16, which `cfl_ac_ss` | ||
| 26 | + downsamples to the true plane shape 8x16 = 128 samples. The square | ||
| 27 | + `reconstruct` walked `row * 16 + col` and read `ac_q3[128]` — the panic. | ||
| 28 | + (Instrumented `exec_intra`: `plane=1 x=96 y=96 bw=16 bh=16 rect=false | ||
| 29 | + res_len=0 cfl=true`.) Even without the panic the square predict would have | ||
| 30 | + written 8 columns of wrong chroma past the plane block. | ||
| 31 | + | ||
| 32 | +Fix (decode.rs, intra arm only): | ||
| 33 | + | ||
| 34 | +1. `let chroma_w = side >> ss_x(fctx); let chroma_h = side >> ss_y(fctx);` | ||
| 35 | +2. Skip arm: `push_intra_unit(1/2, cpx, cpy, chroma_w, chroma_h, ...)` with | ||
| 36 | + `ZERO_RESIDUAL[..chroma_w * chroma_h]` (routes rect to | ||
| 37 | + `push_intra_rect`/`reconstruct_rect`); the neighbour write-back grids are | ||
| 38 | + `Grid::Zero(chroma_w * chroma_h)`. | ||
| 39 | +3. Non-skip arm: `chroma_w == chroma_h` keeps the square `read_plane` | ||
| 40 | + verbatim; at 4:2:2 both planes go through `read_rect_chroma_unit` with the | ||
| 41 | + key-frame path's proven set/scan rows keyed on the LUMA side (16 -> | ||
| 42 | + `ChromaRect16x8` + `SCAN_8X16`, 8 -> `ChromaRect8x4`, 32 -> | ||
| 43 | + `ChromaRect32x16`) and the per-chroma-cell context read | ||
| 44 | + (`around_mi_422_chroma`), exactly the decode_block 422f idiom. | ||
| 45 | + | ||
| 46 | +Byte-identical at 4:2:0 and 4:4:4: `chroma_w == chroma_h == chroma_side` | ||
| 47 | +there, so every replaced call keeps its exact arguments and | ||
| 48 | +`push_intra_unit` routes to the same square `push_intra`. | ||
| 49 | + | ||
| 50 | +Fixture `/tmp/t422.obu` sha256 | ||
| 51 | +`d3fa4beeb1309033e4a03f5ae5c431c8fa8386ba1ada088684710423c7938129` | ||
| 52 | +panicked before the change and passes the block after it. | ||
| 53 | + | ||
| 54 | +## Frontier (EC_AV1_ALLOW_422_PROBE=1, local only, bypass since reverted) | ||
| 55 | + | ||
| 56 | +Next stop is a clean refusal, not a panic: | ||
| 57 | +`rect_inter_chroma_set` (decode.rs:22401, refusal string at decode.rs:22429) | ||
| 58 | +— "a rectangular inter chroma transform unit whose shape has no coefficient | ||
| 59 | +table set here". A later inter block in frame 1 codes a chroma rect unit | ||
| 60 | +whose (w, h) has no row in that table (the 422j square rows (16,16)/(8,8)/(4,4) | ||
| 61 | +and the rect rows listed there are present; the new shape is none of them). | ||
| 62 | +That is the inter chroma entropy-set table, not the intra prediction class | ||
| 63 | +this lane owns — left as the named stop; an `EC_*` print of the refusing | ||
| 64 | +(w, h) at that site is the first step for the owning lane. | ||
| 65 | + | ||
| 66 | +## State | ||
| 67 | + | ||
| 68 | +- Source change: `crates/ec-av1/src/decode.rs` only (intra-arm chroma_w/h, | ||
| 69 | + skip-arm unit pushes + grid sizes, non-skip rect routing). Temporary | ||
| 70 | + exec_intra/push_intra traces and the stream.rs probe bypass are REVERTED; | ||
| 71 | + default refusal re-verified firing: `REFUSED: unsupported: AV1 decode_stream | ||
| 72 | + (a chroma format of 4:2:2 ...)`. | ||
| 73 | +- 420 gates green (target dir `$HOME/.cache/cargo-target-av1422k`): | ||
| 74 | + `a_non_420_subsampled_sequence_header_is_refused_by_name` + | ||
| 75 | + `a_real_aomenc_stream_with_a_skipped_8x8_intra_leaf_whose_tx_split_decodes_ | ||
| 76 | + pixel_exact` under `EC_AV1_REQUIRE_AOMENC=1`: 3 passed, 0 failed. Real | ||
| 77 | + 420 decode over the shared intra arm, confirming the change is bit-neutral | ||
| 78 | + at 4:2:0. `cargo check -p ec-av1`: 0 warnings. | ||
| 79 | +- No push. | ||