From 988e528e1df323b2f6b0ddea2d709eb0b1b35b76 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 12:09:47 +0300 Subject: [PATCH] lane-av1-llinter2: port 84acbd09, 444 lossless inter chroma raster Same-panic port. This tree's lossless inter path panicked exactly as the sibling's parent did: release 'range end index 24 out of range for slice of length 16' in reconstruct_mc_rect (inlined into exec_mc), debug the WHT assert (8, 8) != (4, 4), both through decode_inter_block8 -> read_inter_plane -> push_mc_rect_tx. Ported fixes 1-3 verbatim: the 8x8 inter leaf's single-ref and compound chroma arms route chroma_side == 8 && lossless && !mono through the new leaf8_inter_chroma_lossless per-unit walk with the tail record's chroma half saved/restored; read_inter_chroma_lossless and decode_inter_block's mu_chroma_units replay made subsampling-aware. Fix 4 (decode_rect_split) already present from lane-av1-llband2 and kept (with its RECT_SPLIT_LOSSLESS_CHROMA444_HITS counter); fix 5 (decode_rect4_16_strip span walk) EXCLUDED -- that function is owned by a live lane. 4:2:0 arithmetic unchanged everywhere (4 << 1 = 8). --- crates/ec-av1/src/decode.rs | 297 ++++++++++++++++++++++++++---------- 1 file changed, 218 insertions(+), 79 deletions(-) diff --git a/crates/ec-av1/src/decode.rs b/crates/ec-av1/src/decode.rs index bcb8d9d9..c62e404a 100644 --- a/crates/ec-av1/src/decode.rs +++ b/crates/ec-av1/src/decode.rs @@ -28733,9 +28733,13 @@ fn read_inter_chroma_lossless( if cpx + ox >= u.true_width || cpy + oy >= u.true_height { continue; } - // The chroma neighbour bands are indexed in LUMA mi: 4 chroma - // pixels span 8 luma ones, i.e. 2 mi. - let cu_mi = (at_mi.0 + oy / 2, at_mi.1 + ox / 2); + // The chroma neighbour bands are indexed in LUMA mi: a 4-wide + // chroma unit spans `4 << ss` luma pixels, i.e. `4 >> ss` -- + // 2 mi cells at 4:2:0, one at 4:4:4. + let cu_mi = ( + at_mi.0 + oy / (4 >> ss_y(fctx)), + at_mi.1 + ox / (4 >> ss_x(fctx)), + ); // libaom's chroma entropy-context arrays are SUBSAMPLED: // `get_txb_ctx` reads exactly one entry per plane for a // TX_4X4 chroma unit (`a[0]`/`l[0]`). Our bands are luma-mi @@ -28772,7 +28776,13 @@ fn read_inter_chroma_lossless( )? .0; // Immediately, so the NEXT unit reads this one's context. - neighbours.record_mi_chroma(cu_mi, 8, 8, plane_idx, &cu_grid); + neighbours.record_mi_chroma( + cu_mi, + 4 << ss_x(fctx), + 4 << ss_y(fctx), + plane_idx, + &cu_grid, + ); hit!(CHROMA_SPLIT_TX_HITS); let dst = mu_units( if plane_idx == 1 { &mut *u_out } else { &mut *v_out }, @@ -28788,6 +28798,39 @@ fn read_inter_chroma_lossless( Ok(()) } +/// The 8x8 inter leaf's lossless 4:4:4 chroma arm (lane-av1-llinter), shared +/// by the single-ref and compound paths: the plane block is a 2x2 raster of +/// TX_4X4 units (`av1_get_tx_size`: lossless returns TX_4X4 for EVERY plane, +/// not just luma), read by the same per-unit walk the bigger inter blocks +/// run. Returns the two block grids composed at stride 8 (`Grid::Zero` when +/// every unit hung off the frame edge) and leaves each unit's own coefficient +/// context stamped in the neighbour bands -- the caller's tail must not let +/// its whole-block `record_mi` overwrite them. +#[allow(clippy::too_many_arguments)] +fn leaf8_inter_chroma_lossless( + dec: &mut SymbolDecoder, + cdfs: &mut Cdfs, + neighbours: &mut Neighbours, + u: &mut PlaneBuf<'static>, + v: &mut PlaneBuf<'static>, + su: Pred<'_>, + sv: Pred<'_>, + at_mi: (usize, usize), + (cpx, cpy): (usize, usize), + base_q_idx: u8, fctx: &crate::decode::FrameCtx, +) -> Result<(Grid, Grid)> { + let (mut uo, mut vo) = (Vec::new(), Vec::new()); + read_inter_chroma_lossless( + dec, cdfs, neighbours, u, v, su, sv, + at_mi, (cpx, cpy), (0, 0), (8, 8), (8, 8), 8, 0, + base_q_idx, &mut uo, &mut vo, fctx, + )?; + Ok(( + if uo.is_empty() { Grid::Zero(64) } else { Grid::Own(uo) }, + if vo.is_empty() { Grid::Zero(64) } else { Grid::Own(vo) }, + )) +} + /// Spec 5.11.25's `single_ref_p1`..`p6` tree (reachable only once `comp_mode` /// is known `SINGLE_REFERENCE` -- `decode_stream` refuses any frame with /// `reference_select` set before this is ever called, so that read is never @@ -34471,17 +34514,37 @@ fn decode_inter_block( let cu = if lossless(fctx) { 4usize } else { 32usize }; let mut units = Vec::new(); if lossless(fctx) { - let (rows, cols) = ((write_h / 2).div_ceil(cu), (write_w / 2).div_ceil(cu)); + // lane-av1-llinter: a TX_4X4 chroma unit covers `4 << ss` LUMA + // pixels (8, x2-per-unit, at 4:2:0; 4, x1, at 4:4:4) -- the + // composed plane grid then holds a full cu-row per chroma row and + // each unit's own origin sits `(cu << ss) / MI` mi cells out. + // The hardcoded 4:2:0 /2-and-x2 math stamped half the plane with + // double spans at 4:4:4 and corrupted the next block's + // `txb_skip_ctx` (dodge2 frame 1, U unit mi (4,16) read row 11 + // where the oracle reads row 10). + let (rows, cols) = ( + (write_h >> ss_y(fctx)).div_ceil(cu), + (write_w >> ss_x(fctx)).div_ceil(cu), + ); for cr in 0..rows { for cc in 0..cols { - let cu_mi = (at.0 + cr * (cu * 2 / MI), at.1 + cc * (cu * 2 / MI)); + let cu_mi = ( + at.0 + cr * ((cu << ss_y(fctx)) / MI), + at.1 + cc * ((cu << ss_x(fctx)) / MI), + ); for (plane, grid) in [(1usize, &u_grid), (2usize, &v_grid)] { let mut unit = Vec::with_capacity(cu * cu); for rr in 0..cu { let start = (cr * cu + rr) * chroma_side + cc * cu; unit.extend_from_slice(&grid[start..start + cu]); } - units.push((cu_mi, plane, Grid::Own(unit), cu * 2, cu * 2)); + units.push(( + cu_mi, + plane, + Grid::Own(unit), + cu << ss_x(fctx), + cu << ss_y(fctx), + )); } } } @@ -36986,6 +37049,12 @@ fn decode_inter_block8( // stores `UV_DC_PRED`, exactly as [`decode_inter_block`] one level up. let mut uv_predict_mode = DC_PRED; let (luma_grid, u_grid, v_grid); + // lane-av1-llinter: set when a lossless 4:4:4 leaf's chroma went through + // the per-unit walk (`read_inter_chroma_lossless`) -- the walk stamps each + // TX_4X4 unit's own coefficient context, so the tail's whole-block + // `record_mi` gets its chroma half saved/restored around, exactly like + // `saved_luma_ctx` does for a `split8` luma. + let mut chroma_stamped_per_unit = false; let mut compound_ctx8: Option<(i8, i8, u8, u8)> = None; // lane-inter8 r1: this leaf's own resolved references, handed back so the // NEXT leaf of the same 16x16 can use them as its real above/left @@ -37595,42 +37664,52 @@ fn decode_inter_block8( split8, fctx, )?; luma_grid = grid8; - u_grid = read_inter_plane( - dec, - cdfs, - chroma_set, - chroma_scan, - 1, - around[1], - mode_for_tx, - u, - cpx, - cpy, - chroma_side, - base_q_idx, - su, - Some(luma_tx_type), - None, fctx, - )? - .0; - v_grid = read_inter_plane( - dec, - cdfs, - chroma_set, - chroma_scan, - 2, - around[2], - mode_for_tx, - v, - cpx, - cpy, - chroma_side, - base_q_idx, - sv, - Some(luma_tx_type), - None, fctx, - )? - .0; + if chroma_side == 8 && lossless(fctx) && !mono(fctx) { + let (ug, vg) = leaf8_inter_chroma_lossless( + dec, cdfs, neighbours, u, v, su, sv, + leaf_mi, (cpx, cpy), base_q_idx, fctx, + )?; + u_grid = ug; + v_grid = vg; + chroma_stamped_per_unit = true; + } else { + u_grid = read_inter_plane( + dec, + cdfs, + chroma_set, + chroma_scan, + 1, + around[1], + mode_for_tx, + u, + cpx, + cpy, + chroma_side, + base_q_idx, + su, + Some(luma_tx_type), + None, fctx, + )? + .0; + v_grid = read_inter_plane( + dec, + cdfs, + chroma_set, + chroma_scan, + 2, + around[2], + mode_for_tx, + v, + cpx, + cpy, + chroma_side, + base_q_idx, + sv, + Some(luma_tx_type), + None, fctx, + )? + .0; + } } // lane-inter8 r2: the COMPOUND leaf used to return here // WITHOUT the end-of-function `record_mi`/`fill_lf_grid` the @@ -37686,7 +37765,32 @@ fn decode_inter_block8( palette_record8.2, palette_record8.3, ); + let saved_chroma_ctx = chroma_stamped_per_unit.then(|| { + ( + [ + [neighbours.left[leaf_mi.0][1], neighbours.left[leaf_mi.0][2]], + [neighbours.left[leaf_mi.0 + 1][1], neighbours.left[leaf_mi.0 + 1][2]], + ], + [ + [neighbours.above[leaf_mi.1][1], neighbours.above[leaf_mi.1][2]], + [neighbours.above[leaf_mi.1 + 1][1], neighbours.above[leaf_mi.1 + 1][2]], + ], + ) + }); neighbours.record_mi(leaf_mi, 8, &[&luma_grid[..], &u_grid[..], &v_grid[..]]); + if let Some((left, above)) = saved_chroma_ctx { + // The walk's per-unit stamps are the block's real chroma + // coefficient contexts (`av1_set_contexts` per TX_4X4 + // unit); put them back over `record_mi`'s composed state. + for (cell, uv) in left.into_iter().enumerate() { + neighbours.left[leaf_mi.0 + cell][1] = uv[0]; + neighbours.left[leaf_mi.0 + cell][2] = uv[1]; + } + for (cell, uv) in above.into_iter().enumerate() { + neighbours.above[leaf_mi.1 + cell][1] = uv[0]; + neighbours.above[leaf_mi.1 + cell][2] = uv[1]; + } + } if let Some((left, above)) = saved_luma_ctx { for (cell, state) in left.into_iter().enumerate() { neighbours.left[leaf_mi.0 + cell][0] = state; @@ -38308,42 +38412,52 @@ fn decode_inter_block8( split8, fctx, )?; luma_grid = grid8; - u_grid = read_inter_plane( - dec, - cdfs, - chroma_set, - chroma_scan, - 1, - around[1], - mode_for_tx, - u, - cpx, - cpy, - chroma_side, - base_q_idx, - su, - Some(luma_tx_type), - None, fctx, - )? - .0; - v_grid = read_inter_plane( - dec, - cdfs, - chroma_set, - chroma_scan, - 2, - around[2], - mode_for_tx, - v, - cpx, - cpy, - chroma_side, - base_q_idx, - sv, - Some(luma_tx_type), - None, fctx, - )? - .0; + if chroma_side == 8 && lossless(fctx) && !mono(fctx) { + let (ug, vg) = leaf8_inter_chroma_lossless( + dec, cdfs, neighbours, u, v, su, sv, + leaf_mi, (cpx, cpy), base_q_idx, fctx, + )?; + u_grid = ug; + v_grid = vg; + chroma_stamped_per_unit = true; + } else { + u_grid = read_inter_plane( + dec, + cdfs, + chroma_set, + chroma_scan, + 1, + around[1], + mode_for_tx, + u, + cpx, + cpy, + chroma_side, + base_q_idx, + su, + Some(luma_tx_type), + None, fctx, + )? + .0; + v_grid = read_inter_plane( + dec, + cdfs, + chroma_set, + chroma_scan, + 2, + around[2], + mode_for_tx, + v, + cpx, + cpy, + chroma_side, + base_q_idx, + sv, + Some(luma_tx_type), + None, fctx, + )? + .0; + } } } else { let mode = dec.symbol(&mut cdfs.y_mode[SIZE_GROUP_8]); @@ -38900,7 +39014,32 @@ fn decode_inter_block8( palette_record8.2, palette_record8.3, ); + let saved_chroma_ctx = chroma_stamped_per_unit.then(|| { + ( + [ + [neighbours.left[leaf_mi.0][1], neighbours.left[leaf_mi.0][2]], + [neighbours.left[leaf_mi.0 + 1][1], neighbours.left[leaf_mi.0 + 1][2]], + ], + [ + [neighbours.above[leaf_mi.1][1], neighbours.above[leaf_mi.1][2]], + [neighbours.above[leaf_mi.1 + 1][1], neighbours.above[leaf_mi.1 + 1][2]], + ], + ) + }); neighbours.record_mi(leaf_mi, 8, &[&luma_grid[..], &u_grid[..], &v_grid[..]]); + if let Some((left, above)) = saved_chroma_ctx { + // The walk's per-unit stamps are the block's real chroma coefficient + // contexts (`av1_set_contexts` per TX_4X4 unit); put them back over + // `record_mi`'s one composed state. + for (cell, uv) in left.into_iter().enumerate() { + neighbours.left[leaf_mi.0 + cell][1] = uv[0]; + neighbours.left[leaf_mi.0 + cell][2] = uv[1]; + } + for (cell, uv) in above.into_iter().enumerate() { + neighbours.above[leaf_mi.1 + cell][1] = uv[0]; + neighbours.above[leaf_mi.1 + cell][2] = uv[1]; + } + } // lane-uv8 r1: this leaf never stamped a mode band at all, so the block // below/right of it read whatever block last wrote the coarse [`SUB`] // slot -- now that an intra leaf here can code a smooth/directional