From 4280e519b85b8586d5cd7ef99c259c03ce09742d 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 05:46:30 +0300 Subject: [PATCH] ec-av1: lane-av1-422d r1 -- 8x8 leaf chroma is one 4x8 rect unit per plane at ss (1,0), behind the header refusal decode_leaf8's non-444 arm hardcoded a 4x4 TxbSet::Chroma4 unit for every subsampled format. At ss (1,0) an 8x8 leaf's chroma plane block is 4x8, ONE rect unit per plane (av1_get_max_uv_txsize(BLOCK_8X8) = max_txsize_rect_lookup[BLOCK_4X8] = TX_4X8): all three arms (skip, single 8x8 unit, TX4) now read it through leaf8_chroma422_unit in the ChromaRect8x4 class with SCAN_4X8, mirroring sub8_leaf_chroma444's rect arm at the leaf's halved position. The intrabc DV copy covers the whole 4x8 plane block, and the leaf's UV palette colour-index map decodes over the true (side >> ss_x, side >> ss_y) extent instead of the squared (side >> ss_x). 4:2:0 keeps the 4x4 arm exactly; 4:4:4 untouched. Measured against the aom oracle on the lane fixture: all four leaf8 chroma rect reads of the first HORZ_A pair rng-for-rng through their full coefficient bodies. The stream still desyncs later at decode_leaf_rect's chroma arm (a 16x8 strip's 8x8 plane block read as a 4x8 rect), so the header refusal stays. Next site named in lanes/av1422d.report.md. Gate: a_real_aomenc_stream_with_a_skipped_8x8_intra_leaf_whose_tx_split_ decodes_pixel_exact (+ 10-bit twin) green, 6/6 pixel-exact matches. --- crates/ec-av1/src/decode.rs | 235 +++++++++++++++++++++++++++++------- lanes/av1422d.report.md | 92 ++++++++++++++ 2 files changed, 286 insertions(+), 41 deletions(-) create mode 100644 lanes/av1422d.report.md diff --git a/crates/ec-av1/src/decode.rs b/crates/ec-av1/src/decode.rs index 45803b64..27c39a23 100644 --- a/crates/ec-av1/src/decode.rs +++ b/crates/ec-av1/src/decode.rs @@ -15805,7 +15805,13 @@ fn read_intra_mode( (side >> ss_x(fctx), side >> ss_y(fctx)), (ss_x(fctx), ss_y(fctx)), ); - let map = decode_color_index_map(dec, cdfs, n, side >> ss_x(fctx), on, true); + // lane-av1-422d: the chroma map's extent is the PLANE BLOCK + // `(side >> ss_x) x (side >> ss_y)` -- 4x8 at ss (1,0), not the + // square call's `(side >> ss_x)`-squared (4x4), which left a + // 16-entry map for a 32-sample unit and panicked the reconstruct. + let map = decode_color_index_map_wh( + dec, cdfs, n, side >> ss_x(fctx), side >> ss_y(fctx), on, true, + ); hit!(PALETTE_UV_HITS); if trace { eprintln!( @@ -18229,7 +18235,16 @@ fn decode_leaf8( let (cpx, cpy) = (px >> ss_x(fctx), py >> ss_y(fctx)); // 4:4:4: this 8x8 block's chroma plane block is 8x8 (same scan as luma, // `scans.0`). 4:2:0 stays the 4x4 unit this leaf was written for. + // lane-av1-422d: 4:2:2 (ss 1/0) halves only the width, so the plane block + // is 4x8 -- ONE rect transform unit per plane (`av1_get_max_uv_txsize( + // BLOCK_8X8)` at ss (1,0) is `max_txsize_rect_lookup[BLOCK_4X8]` == + // TX_4X8): one txb_skip + one scan per plane in the + // [`TxbSet::ChromaRect8x4`] class [`decode_rect_split`] proves for the + // shape, read through [`leaf8_chroma422_unit`] in each arm below. The + // `(csz, cset, cscan)` selection keeps serving the square arms (444's + // 8x8, 420's 4x4); the rect arms branch on [`chroma_422`] instead. let chroma_444 = ss_x(fctx) == 0 && ss_y(fctx) == 0; + let chroma_422 = ss_x(fctx) == 1 && ss_y(fctx) == 0; let (csz, cset, cscan) = if chroma_444 { (8usize, TxbSet::Chroma8, scans.0) } else { @@ -18247,17 +18262,22 @@ fn decode_leaf8( mv_to_q4(px, dv_col, 0), mv_to_q4(py, dv_row, 0), 8, 8, mc::InterpFilterKind::Bilinear, &mut yb, fctx, ); - let mut ub = vec![0u16; 4 * 4]; + // lane-av1-422d: the DV copy covers the leaf's whole CHROMA PLANE + // block -- 4x8 at ss (1,0), 4x4 at 4:2:0/4:4:4 (the 4:4:4 8x8 leaf's + // own unit read is 8x8, so its 4x4 window here predates that lane's + // rect walk and is untouched by this one). + let (icw, ich) = if chroma_422 { (4usize, 8usize) } else { (4usize, 4usize) }; + let mut ub = vec![0u16; icw * ich]; mc::predict_with_filter( &u.data, u.width, u.true_width, u.true_height, mv_to_q4(cpx, dv_col, ss_x(fctx)), mv_to_q4(cpy, dv_row, ss_y(fctx)), - 4, 4, mc::InterpFilterKind::Bilinear, &mut ub, fctx, + icw, ich, mc::InterpFilterKind::Bilinear, &mut ub, fctx, ); - let mut vb = vec![0u16; 4 * 4]; + let mut vb = vec![0u16; icw * ich]; mc::predict_with_filter( &v.data, v.width, v.true_width, v.true_height, mv_to_q4(cpx, dv_col, ss_x(fctx)), mv_to_q4(cpy, dv_row, ss_y(fctx)), - 4, 4, mc::InterpFilterKind::Bilinear, &mut vb, fctx, + icw, ich, mc::InterpFilterKind::Bilinear, &mut vb, fctx, ); (yb, ub, vb) }); @@ -18345,43 +18365,65 @@ fn decode_leaf8( ); } let ac = alpha.map(|_| cfl_src(px, py, 8)); - if let Some((_, ub, _)) = &intrabc_bufs { - set_palette_pred(ub.clone(), fctx); - } else if let Some((ub, _)) = &palette_uv_bufs { - set_palette_pred(ub.clone(), fctx); - } - push_intra(1, - cpx, - cpy, - csz, - uv_predict_mode, - angle_delta_uv, - reach, - &ZERO_RESIDUAL[..csz * csz], - alpha.zip(ac).map(|((au, _), ac)| (au, ac)), - None, - smooth_neighbor_uv, fctx, - ); - if let Some((_, _, vb)) = &intrabc_bufs { - set_palette_pred(vb.clone(), fctx); - } else if let Some((_, vb)) = &palette_uv_bufs { - set_palette_pred(vb.clone(), fctx); + if chroma_422 { + // lane-av1-422d: a skipped leaf still predicts its 4x8 rect unit + // per plane (CfL keeps its contribution, [`decode_block`]'s own + // skip-arm rule); no coefficient symbol exists, so the entropy + // context never enters the rect read. + u_grid = leaf8_chroma422_unit( + dec, cdfs, (false, false, 0), uv_predict_mode, angle_delta_uv, reach, + 1, alpha.zip(ac).map(|((au, _), ac)| (au, ac)), true, + intrabc_bufs.as_ref().map(|(_, ub, _)| ub.clone()) + .or_else(|| palette_uv_bufs.as_ref().map(|(ub, _)| ub.clone())), + u, cpx, cpy, smooth_neighbor_uv, fctx, + )?; + v_grid = leaf8_chroma422_unit( + dec, cdfs, (false, false, 0), uv_predict_mode, angle_delta_uv, reach, + 2, alpha.zip(ac).map(|((_, av), ac)| (av, ac)), true, + intrabc_bufs.as_ref().map(|(_, _, vb)| vb.clone()) + .or_else(|| palette_uv_bufs.as_ref().map(|(_, vb)| vb.clone())), + v, cpx, cpy, smooth_neighbor_uv, fctx, + )?; + luma_grid = Grid::Zero(64); + } else { + if let Some((_, ub, _)) = &intrabc_bufs { + set_palette_pred(ub.clone(), fctx); + } else if let Some((ub, _)) = &palette_uv_bufs { + set_palette_pred(ub.clone(), fctx); + } + push_intra(1, + cpx, + cpy, + csz, + uv_predict_mode, + angle_delta_uv, + reach, + &ZERO_RESIDUAL[..csz * csz], + alpha.zip(ac).map(|((au, _), ac)| (au, ac)), + None, + smooth_neighbor_uv, fctx, + ); + if let Some((_, _, vb)) = &intrabc_bufs { + set_palette_pred(vb.clone(), fctx); + } else if let Some((_, vb)) = &palette_uv_bufs { + set_palette_pred(vb.clone(), fctx); + } + push_intra(2, + cpx, + cpy, + csz, + uv_predict_mode, + angle_delta_uv, + reach, + &ZERO_RESIDUAL[..csz * csz], + alpha.zip(ac).map(|((_, av), ac)| (av, ac)), + None, + smooth_neighbor_uv, fctx, + ); + luma_grid = Grid::Zero(64); + u_grid = Grid::Zero(csz * csz); + v_grid = Grid::Zero(csz * csz); } - push_intra(2, - cpx, - cpy, - csz, - uv_predict_mode, - angle_delta_uv, - reach, - &ZERO_RESIDUAL[..csz * csz], - alpha.zip(ac).map(|((_, av), ac)| (av, ac)), - None, - smooth_neighbor_uv, fctx, - ); - luma_grid = Grid::Zero(64); - u_grid = Grid::Zero(csz * csz); - v_grid = Grid::Zero(csz * csz); } else if resolved != 4 { let around = neighbours.around_mi(leaf_mi, 8); if let Some(buf) = &palette_y_buf { @@ -18422,6 +18464,25 @@ fn decode_leaf8( fctx.intrabc_chroma_tx.with(|c| c.set(Some(fctx.luma_tx_type.with(std::cell::Cell::get)))); } let ac = alpha.map(|_| cfl_src(px, py, 8)); + if chroma_422 { + // lane-av1-422d: ONE 4x8 rect unit per plane (`av1_get_max_uv_txsize` + // at ss (1,0) == TX_4X8), covering the plane block exactly, off the + // leaf's own 8x8-span entropy context (`chroma_tiled`'s convention). + u_grid = leaf8_chroma422_unit( + dec, cdfs, around[1], uv_predict_mode, angle_delta_uv, reach, + 1, alpha.zip(ac).map(|((au, _), ac)| (au, ac)), false, + intrabc_bufs.as_ref().map(|(_, ub, _)| ub.clone()) + .or_else(|| palette_uv_bufs.as_ref().map(|(ub, _)| ub.clone())), + u, cpx, cpy, smooth_neighbor_uv, fctx, + )?; + v_grid = leaf8_chroma422_unit( + dec, cdfs, around[2], uv_predict_mode, angle_delta_uv, reach, + 2, alpha.zip(ac).map(|((_, av), ac)| (av, ac)), false, + intrabc_bufs.as_ref().map(|(_, _, vb)| vb.clone()) + .or_else(|| palette_uv_bufs.as_ref().map(|(_, vb)| vb.clone())), + v, cpx, cpy, smooth_neighbor_uv, fctx, + )?; + } else { if let Some((_, ub, _)) = &intrabc_bufs { set_palette_pred(ub.clone(), fctx); } else if let Some((ub, _)) = &palette_uv_bufs { @@ -18476,6 +18537,7 @@ fn decode_leaf8( None, smooth_neighbor_uv, fctx, )?; + } // Disarm: `INTRABC_CHROMA_TX` is `Some` across exactly this block's // two chroma reads (`decode_block`'s own tail does the same) -- left // set, every later chroma block would inherit this luma tx_type, @@ -18592,6 +18654,25 @@ fn decode_leaf8( if fctx.intrabc_chroma_tx.with(std::cell::Cell::get).is_some() { hit!(INTRABC_TX4_CHROMA_COPY_HITS); } + if chroma_422 { + // lane-av1-422d: the chroma unit does NOT follow the luma var-tx + // split -- `uv_txsize` is `av1_get_max_uv_txsize` of the block, + // still the one 4x8 rect unit per plane at ss (1,0). + u_grid = leaf8_chroma422_unit( + dec, cdfs, chroma_around[1], uv_predict_mode, angle_delta_uv, reach, + 1, alpha.zip(ac).map(|((au, _), ac)| (au, ac)), false, + intrabc_bufs.as_ref().map(|(_, ub, _)| ub.clone()) + .or_else(|| palette_uv_bufs.as_ref().map(|(ub, _)| ub.clone())), + u, cpx, cpy, smooth_neighbor_uv, fctx, + )?; + v_grid = leaf8_chroma422_unit( + dec, cdfs, chroma_around[2], uv_predict_mode, angle_delta_uv, reach, + 2, alpha.zip(ac).map(|((_, av), ac)| (av, ac)), false, + intrabc_bufs.as_ref().map(|(_, _, vb)| vb.clone()) + .or_else(|| palette_uv_bufs.as_ref().map(|(_, vb)| vb.clone())), + v, cpx, cpy, smooth_neighbor_uv, fctx, + )?; + } else { if let Some((ub, _)) = &palette_uv_bufs { set_palette_pred(ub.clone(), fctx); } @@ -18642,6 +18723,7 @@ fn decode_leaf8( None, smooth_neighbor_uv, fctx, )?; + } // The two chroma reads above are the only consulters of this leaf's // armed [`INTRABC_CHROMA_TX`]; leaving it set would make the NEXT // leaf's chroma inherit this leaf's luma type instead of its own @@ -18734,6 +18816,77 @@ fn decode_leaf8( Ok(mode) } +/// lane-av1-422d: ONE 4:2:2 chroma transform unit of an 8x8 leaf +/// ([`decode_leaf8`]). At ss (1,0) the plane block is 4x8 and +/// `av1_get_max_uv_txsize(BLOCK_8X8)` resolves to +/// `max_txsize_rect_lookup[BLOCK_4X8]` == TX_4X8, so the WHOLE plane block is +/// a single rect unit -- one txb_skip + one scan per plane in the +/// [`TxbSet::ChromaRect8x4`] class [`decode_rect_split`] proves for the +/// shape. Mirrors [`sub8_leaf_chroma444`]'s rect arm at the leaf's halved +/// position: the entropy context is the leaf's own 8x8 luma-span +/// above/left state (the `chroma_tiled` arm's convention; no `+3` +/// plane-block-bigger term -- the unit covers the plane block exactly), the +/// CFL source is the leaf's whole 8x8 luma block, and the plane's predicted +/// mode supplies the mode-derived default `tx_type` unless an armed +/// [`INTRABC_CHROMA_TX`] slot carries the intrabc luma's own (the caller +/// arms and disarms it, exactly as it does around its square reads). +#[allow(clippy::too_many_arguments)] +fn leaf8_chroma422_unit( + dec: &mut SymbolDecoder, + cdfs: &mut Cdfs, + around: (bool, bool, i32), + uv_predict_mode: usize, + angle_delta_uv: i32, + reach: Reach, + plane_idx: usize, + cfl: Option<(i32, CflSrc)>, + skip: bool, + // The prediction override the square arms feed through + // `set_palette_pred`: an intrabc leaf's frame copy at the DV takes + // priority over a palette block's colour-index map. + pred_override: Option>, + // Unread, like [`read_plane`]'s own: the borrow proves the caller holds + // the plane exclusively while the unit's coefficients are parsed. + _plane: &mut PlaneBuf<'static>, + cpx: usize, + cpy: usize, + smooth_neighbor_uv: bool, fctx: &crate::decode::FrameCtx, +) -> Result { + // The unit's prediction runs whether or not a residual follows it -- a + // skipped leaf still predicts (the CfL contribution survives a skip), + // and a skipped intrabc leaf still copies the frame at its DV. + if let Some(buf) = pred_override { + set_palette_pred(buf, fctx); + } + if skip { + push_intra_rect( + plane_idx, cpx, cpy, 4, 8, uv_predict_mode, angle_delta_uv, reach, + &ZERO_RESIDUAL[..4 * 8], cfl, None, smooth_neighbor_uv, fctx, + ); + return Ok(Grid::Zero(4 * 8)); + } + let default_tx = fctx + .intrabc_chroma_tx + .with(std::cell::Cell::get) + .unwrap_or_else(|| default_intra_tx_type(uv_predict_mode as u8)); + let mut coding = cdfs.txb(TxbSet::ChromaRect8x4, uv_predict_mode); + let (levels, tx_type) = read_coeffs_rect( + dec, &mut coding, &SCAN_4X8, 4, 8, + usize::from(around.0) + usize::from(around.1), + dc_sign_ctx(around.2), default_tx, + )?; + let residual = dequant_and_inverse_typed_wh( + &levels, 4, 8, crate::decode::bit_depth(fctx), block_q_idx(fctx), + plane_q_delta(plane_idx, fctx).0, plane_q_delta(plane_idx, fctx).1, + tx_type, block_iqmatrix(fctx, plane_idx, 4, 8, tx_type), + ); + push_intra_rect( + plane_idx, cpx, cpy, 4, 8, uv_predict_mode, angle_delta_uv, reach, + &residual, cfl, None, smooth_neighbor_uv, fctx, + ); + Ok(levels) +} + /// `read_intra_frame_mode_info`'s mode-info read for one `BLOCK_4X4` leaf /// below an 8x8 partition (spec `decode_partition`'s `bSize < BLOCK_8X8` /// bottom, where no partition symbol is read at all -- `decode_block` runs diff --git a/lanes/av1422d.report.md b/lanes/av1422d.report.md new file mode 100644 index 00000000..162bca15 --- /dev/null +++ b/lanes/av1422d.report.md @@ -0,0 +1,92 @@ +# lane-av1-422d — 8x8 leaf chroma unit ported at ss (1,0); refusal stays + +## Outcome + +STOP with the 4:2:2 header refusal in place. `decode_leaf8`'s chroma walk now +ports the 4:2:2 leaf unit (ONE 4x8 rect transform unit per plane, +`TxbSet::ChromaRect8x4` + `SCAN_4X8`, one txb_skip + one scan), and every leaf8 +chroma read on the measured fixture is rng-for-rng EXACT against the oracle. +The stream still desyncs LATER, at `decode_leaf_rect`'s chroma arm (next +section), so the refusal is retained byte-identical and the probe bypass was +reverted before commit. + +## Change (all inside decode_leaf8's own chroma scope) + +- `decode_leaf8` (decode.rs): `chroma_422 = ss_x == 1 && ss_y == 0`; all three + arms (skip, single-8x8-unit, TX4) branch to `leaf8_chroma422_unit` for the + rect unit. The 4:2:0 `(4, TxbSet::Chroma4, scans.1)` selection and the 4:4:4 + arm are untouched. The chroma unit does NOT follow the luma var-tx split + (`uv_txsize` is `av1_get_max_uv_txsize` of the block, still one 4x8 unit + when luma resolves TX_4X4). The intrabc DV copy covers the whole plane block + (4x8) at ss (1,0). +- `leaf8_chroma422_unit` (new, next to `decode_leaf8`): mirrors + `sub8_leaf_chroma444`'s rect arm at the leaf's halved position — entropy + context from the leaf's own 8x8 luma-span above/left state (no `+3`, the + unit covers the plane block exactly), CFL source the leaf's whole 8x8 luma + block, mode-derived default `tx_type` unless `INTRABC_CHROMA_TX` is armed, + prediction override (intrabc DV over palette) set inside, skip predicts with + `ZERO_RESIDUAL`. +- UV palette map extent (decode.rs:15808, leaf8's mode-info reader): the map + is decoded over `(side >> ss_x, side >> ss_y)` = 4x8 via + `decode_color_index_map_wh`, not the square call's `(side >> ss_x)`-squared + 4x4 (class: plane-block extent squared a rect). At 4:2:0/4:4:4 the arguments + evaluate identically; only ss (1,0) changes. Found live: the 16-entry map + fed a 16-sample prediction override into the first 32-sample rect unit and + panicked `reconstruct_rect` (`index out of bounds: the len is 16 but the + index is 16`). + +## Measurement + +Fixture `/tmp/t422.obu`, sha256 +`d3fa4beeb1309033e4a03f5ae5c431c8fa8386ba1ada088684710423c7938129` (reused +from av1422b/c by hash). Oracle `$HOME/.cache/aom-oracle/build/aomdec` +`EC_TRACE=1 EC_TRACE_MODE_STEP=1 EC_TRACE_COEFF=1`; ours `decode_probe` (debug, +private target dir) same env plus `EC_AV1_ALLOW_422_PROBE=1` (LOCAL bypass, +reverted). + +Coefficient-unit pairing (all_zero entry rng -> post rng), first HORZ_A 16x16 +of frame 0: + +- leaf (0,0): 4x luma TX_4X4 ✓, U `tx_size=5` entry 46416 -> 35360 ✓, V + entry 34824 -> 41920 ✓ (both my rect reads). +- leaf (0,2): luma TX_8X8 ✓ (post 45770 = oracle), U entry 37668 -> 33728 ✓, + V entry 60936 -> 58556 ✓. +- 16x8 strip: luma `tx_size=8` entry 59680 -> 58977 ✓. + +All four leaf8 chroma rect reads match the oracle rng-for-rng through their +full coefficient bodies (each next unit's entry rng proves the previous +body's bit consumption). + +## First remaining divergence (named next site) + +`decode_leaf_rect`'s chroma arm, decode.rs:13060-13067. For a 16x8/8x16 rect +leaf at ss (1,0) the chroma plane block is 8x8 — SQUARE +(`TxbSet::Chroma8` + `default_scan(8)` through `read_plane`, the +`chroma_tiled` (8,8) shape) — but the code picks `TxbSet::ChromaRect8x4` + +`SCAN_8X4`/`SCAN_4X8` keyed on `ss_x == 0`. Measured: the HORZ_A's 16x8 strip +(mi_row=2, mi_col=0) — oracle U/V units are `tx_size=1` (TX_8X8 class, 64- +position eob alphabet, ctx=8); ours enters the U unit's txb_skip at the same +rng 38672 and coincidentally matches that one symbol (the offset-7 row shares +`txb_skip_chroma_8`), then reads eob off the 32-position chroma-rect alphabet +(eob=27 vs oracle eob=32) and desyncs. Everything after shifts. + +## Second site behind it + +`decode_rect_split`'s chroma shape table (decode.rs:10114-10133) has no 4:2:2 +rows: a 16x64 luma strip's `(8, 64)` plane block fires +`EC_RECTCHROMA_GAP luma=16x64 tx=16x32 chroma=8x64` (decode stops at mi_row=16 +once the leaf_rect site is passed). Same class likely holds for other +unhalved-height plane blocks in that table. + +## State + +- Refusal `a chroma format of 4:2:2 (subsampling_x != subsampling_y)...` + byte-identical (bypass reverted; `git diff` shows only decode.rs). +- `decode_leaf_split4`, `sub8_leaf_chroma444`, `reconstruct_mc_rect`, the + resize header reader, decode.rs 34390-34440: untouched. +- 420 gate green: + `a_real_aomenc_stream_with_a_skipped_8x8_intra_leaf_whose_tx_split_decodes_pixel_exact` + + its 10-bit twin — 6/6 pixel-exact matches each, 0 refusals (the gate + exercises the skip and TX4 arms this lane restructured). +- `cargo check -p ec-av1`: 0 warnings. +- No push.