forge
Explore
Log in

Don't you dare go Hollow

lane-av1-llinter2: port 84acbd09, 444 lossless inter chroma raster

Browse files at this commit

988e528e1df323b2f6b0ddea2d709eb0b1b35b76Ahmet Kaan GümüşParent: f3e2fd4
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.rsmodified+218 -79
@@ -28733,9 +28733,13 @@ fn read_inter_chroma_lossless(
2873328733 if cpx + ox >= u.true_width || cpy + oy >= u.true_height {
2873428734 continue;
2873528735 }
28736- // The chroma neighbour bands are indexed in LUMA mi: 4 chroma
28737- // pixels span 8 luma ones, i.e. 2 mi.
28738- let cu_mi = (at_mi.0 + oy / 2, at_mi.1 + ox / 2);
28736+ // The chroma neighbour bands are indexed in LUMA mi: a 4-wide
28737+ // chroma unit spans `4 << ss` luma pixels, i.e. `4 >> ss` --
28738+ // 2 mi cells at 4:2:0, one at 4:4:4.
28739+ let cu_mi = (
28740+ at_mi.0 + oy / (4 >> ss_y(fctx)),
28741+ at_mi.1 + ox / (4 >> ss_x(fctx)),
28742+ );
2873928743 // libaom's chroma entropy-context arrays are SUBSAMPLED:
2874028744 // `get_txb_ctx` reads exactly one entry per plane for a
2874128745 // TX_4X4 chroma unit (`a[0]`/`l[0]`). Our bands are luma-mi
@@ -28772,7 +28776,13 @@ fn read_inter_chroma_lossless(
2877228776 )?
2877328777 .0;
2877428778 // Immediately, so the NEXT unit reads this one's context.
28775- neighbours.record_mi_chroma(cu_mi, 8, 8, plane_idx, &cu_grid);
28779+ neighbours.record_mi_chroma(
28780+ cu_mi,
28781+ 4 << ss_x(fctx),
28782+ 4 << ss_y(fctx),
28783+ plane_idx,
28784+ &cu_grid,
28785+ );
2877628786 hit!(CHROMA_SPLIT_TX_HITS);
2877728787 let dst = mu_units(
2877828788 if plane_idx == 1 { &mut *u_out } else { &mut *v_out },
@@ -28788,6 +28798,39 @@ fn read_inter_chroma_lossless(
2878828798 Ok(())
2878928799 }
2879028800
28801+/// The 8x8 inter leaf's lossless 4:4:4 chroma arm (lane-av1-llinter), shared
28802+/// by the single-ref and compound paths: the plane block is a 2x2 raster of
28803+/// TX_4X4 units (`av1_get_tx_size`: lossless returns TX_4X4 for EVERY plane,
28804+/// not just luma), read by the same per-unit walk the bigger inter blocks
28805+/// run. Returns the two block grids composed at stride 8 (`Grid::Zero` when
28806+/// every unit hung off the frame edge) and leaves each unit's own coefficient
28807+/// context stamped in the neighbour bands -- the caller's tail must not let
28808+/// its whole-block `record_mi` overwrite them.
28809+#[allow(clippy::too_many_arguments)]
28810+fn leaf8_inter_chroma_lossless(
28811+ dec: &mut SymbolDecoder,
28812+ cdfs: &mut Cdfs,
28813+ neighbours: &mut Neighbours,
28814+ u: &mut PlaneBuf<'static>,
28815+ v: &mut PlaneBuf<'static>,
28816+ su: Pred<'_>,
28817+ sv: Pred<'_>,
28818+ at_mi: (usize, usize),
28819+ (cpx, cpy): (usize, usize),
28820+ base_q_idx: u8, fctx: &crate::decode::FrameCtx,
28821+) -> Result<(Grid, Grid)> {
28822+ let (mut uo, mut vo) = (Vec::new(), Vec::new());
28823+ read_inter_chroma_lossless(
28824+ dec, cdfs, neighbours, u, v, su, sv,
28825+ at_mi, (cpx, cpy), (0, 0), (8, 8), (8, 8), 8, 0,
28826+ base_q_idx, &mut uo, &mut vo, fctx,
28827+ )?;
28828+ Ok((
28829+ if uo.is_empty() { Grid::Zero(64) } else { Grid::Own(uo) },
28830+ if vo.is_empty() { Grid::Zero(64) } else { Grid::Own(vo) },
28831+ ))
28832+}
28833+
2879128834 /// Spec 5.11.25's `single_ref_p1`..`p6` tree (reachable only once `comp_mode`
2879228835 /// is known `SINGLE_REFERENCE` -- `decode_stream` refuses any frame with
2879328836 /// `reference_select` set before this is ever called, so that read is never
@@ -34471,17 +34514,37 @@ fn decode_inter_block(
3447134514 let cu = if lossless(fctx) { 4usize } else { 32usize };
3447234515 let mut units = Vec::new();
3447334516 if lossless(fctx) {
34474- let (rows, cols) = ((write_h / 2).div_ceil(cu), (write_w / 2).div_ceil(cu));
34517+ // lane-av1-llinter: a TX_4X4 chroma unit covers `4 << ss` LUMA
34518+ // pixels (8, x2-per-unit, at 4:2:0; 4, x1, at 4:4:4) -- the
34519+ // composed plane grid then holds a full cu-row per chroma row and
34520+ // each unit's own origin sits `(cu << ss) / MI` mi cells out.
34521+ // The hardcoded 4:2:0 /2-and-x2 math stamped half the plane with
34522+ // double spans at 4:4:4 and corrupted the next block's
34523+ // `txb_skip_ctx` (dodge2 frame 1, U unit mi (4,16) read row 11
34524+ // where the oracle reads row 10).
34525+ let (rows, cols) = (
34526+ (write_h >> ss_y(fctx)).div_ceil(cu),
34527+ (write_w >> ss_x(fctx)).div_ceil(cu),
34528+ );
3447534529 for cr in 0..rows {
3447634530 for cc in 0..cols {
34477- let cu_mi = (at.0 + cr * (cu * 2 / MI), at.1 + cc * (cu * 2 / MI));
34531+ let cu_mi = (
34532+ at.0 + cr * ((cu << ss_y(fctx)) / MI),
34533+ at.1 + cc * ((cu << ss_x(fctx)) / MI),
34534+ );
3447834535 for (plane, grid) in [(1usize, &u_grid), (2usize, &v_grid)] {
3447934536 let mut unit = Vec::with_capacity(cu * cu);
3448034537 for rr in 0..cu {
3448134538 let start = (cr * cu + rr) * chroma_side + cc * cu;
3448234539 unit.extend_from_slice(&grid[start..start + cu]);
3448334540 }
34484- units.push((cu_mi, plane, Grid::Own(unit), cu * 2, cu * 2));
34541+ units.push((
34542+ cu_mi,
34543+ plane,
34544+ Grid::Own(unit),
34545+ cu << ss_x(fctx),
34546+ cu << ss_y(fctx),
34547+ ));
3448534548 }
3448634549 }
3448734550 }
@@ -36986,6 +37049,12 @@ fn decode_inter_block8(
3698637049 // stores `UV_DC_PRED`, exactly as [`decode_inter_block`] one level up.
3698737050 let mut uv_predict_mode = DC_PRED;
3698837051 let (luma_grid, u_grid, v_grid);
37052+ // lane-av1-llinter: set when a lossless 4:4:4 leaf's chroma went through
37053+ // the per-unit walk (`read_inter_chroma_lossless`) -- the walk stamps each
37054+ // TX_4X4 unit's own coefficient context, so the tail's whole-block
37055+ // `record_mi` gets its chroma half saved/restored around, exactly like
37056+ // `saved_luma_ctx` does for a `split8` luma.
37057+ let mut chroma_stamped_per_unit = false;
3698937058 let mut compound_ctx8: Option<(i8, i8, u8, u8)> = None;
3699037059 // lane-inter8 r1: this leaf's own resolved references, handed back so the
3699137060 // NEXT leaf of the same 16x16 can use them as its real above/left
@@ -37595,42 +37664,52 @@ fn decode_inter_block8(
3759537664 split8, fctx,
3759637665 )?;
3759737666 luma_grid = grid8;
37598- u_grid = read_inter_plane(
37599- dec,
37600- cdfs,
37601- chroma_set,
37602- chroma_scan,
37603- 1,
37604- around[1],
37605- mode_for_tx,
37606- u,
37607- cpx,
37608- cpy,
37609- chroma_side,
37610- base_q_idx,
37611- su,
37612- Some(luma_tx_type),
37613- None, fctx,
37614- )?
37615- .0;
37616- v_grid = read_inter_plane(
37617- dec,
37618- cdfs,
37619- chroma_set,
37620- chroma_scan,
37621- 2,
37622- around[2],
37623- mode_for_tx,
37624- v,
37625- cpx,
37626- cpy,
37627- chroma_side,
37628- base_q_idx,
37629- sv,
37630- Some(luma_tx_type),
37631- None, fctx,
37632- )?
37633- .0;
37667+ if chroma_side == 8 && lossless(fctx) && !mono(fctx) {
37668+ let (ug, vg) = leaf8_inter_chroma_lossless(
37669+ dec, cdfs, neighbours, u, v, su, sv,
37670+ leaf_mi, (cpx, cpy), base_q_idx, fctx,
37671+ )?;
37672+ u_grid = ug;
37673+ v_grid = vg;
37674+ chroma_stamped_per_unit = true;
37675+ } else {
37676+ u_grid = read_inter_plane(
37677+ dec,
37678+ cdfs,
37679+ chroma_set,
37680+ chroma_scan,
37681+ 1,
37682+ around[1],
37683+ mode_for_tx,
37684+ u,
37685+ cpx,
37686+ cpy,
37687+ chroma_side,
37688+ base_q_idx,
37689+ su,
37690+ Some(luma_tx_type),
37691+ None, fctx,
37692+ )?
37693+ .0;
37694+ v_grid = read_inter_plane(
37695+ dec,
37696+ cdfs,
37697+ chroma_set,
37698+ chroma_scan,
37699+ 2,
37700+ around[2],
37701+ mode_for_tx,
37702+ v,
37703+ cpx,
37704+ cpy,
37705+ chroma_side,
37706+ base_q_idx,
37707+ sv,
37708+ Some(luma_tx_type),
37709+ None, fctx,
37710+ )?
37711+ .0;
37712+ }
3763437713 }
3763537714 // lane-inter8 r2: the COMPOUND leaf used to return here
3763637715 // WITHOUT the end-of-function `record_mi`/`fill_lf_grid` the
@@ -37686,7 +37765,32 @@ fn decode_inter_block8(
3768637765 palette_record8.2,
3768737766 palette_record8.3,
3768837767 );
37768+ let saved_chroma_ctx = chroma_stamped_per_unit.then(|| {
37769+ (
37770+ [
37771+ [neighbours.left[leaf_mi.0][1], neighbours.left[leaf_mi.0][2]],
37772+ [neighbours.left[leaf_mi.0 + 1][1], neighbours.left[leaf_mi.0 + 1][2]],
37773+ ],
37774+ [
37775+ [neighbours.above[leaf_mi.1][1], neighbours.above[leaf_mi.1][2]],
37776+ [neighbours.above[leaf_mi.1 + 1][1], neighbours.above[leaf_mi.1 + 1][2]],
37777+ ],
37778+ )
37779+ });
3768937780 neighbours.record_mi(leaf_mi, 8, &[&luma_grid[..], &u_grid[..], &v_grid[..]]);
37781+ if let Some((left, above)) = saved_chroma_ctx {
37782+ // The walk's per-unit stamps are the block's real chroma
37783+ // coefficient contexts (`av1_set_contexts` per TX_4X4
37784+ // unit); put them back over `record_mi`'s composed state.
37785+ for (cell, uv) in left.into_iter().enumerate() {
37786+ neighbours.left[leaf_mi.0 + cell][1] = uv[0];
37787+ neighbours.left[leaf_mi.0 + cell][2] = uv[1];
37788+ }
37789+ for (cell, uv) in above.into_iter().enumerate() {
37790+ neighbours.above[leaf_mi.1 + cell][1] = uv[0];
37791+ neighbours.above[leaf_mi.1 + cell][2] = uv[1];
37792+ }
37793+ }
3769037794 if let Some((left, above)) = saved_luma_ctx {
3769137795 for (cell, state) in left.into_iter().enumerate() {
3769237796 neighbours.left[leaf_mi.0 + cell][0] = state;
@@ -38308,42 +38412,52 @@ fn decode_inter_block8(
3830838412 split8, fctx,
3830938413 )?;
3831038414 luma_grid = grid8;
38311- u_grid = read_inter_plane(
38312- dec,
38313- cdfs,
38314- chroma_set,
38315- chroma_scan,
38316- 1,
38317- around[1],
38318- mode_for_tx,
38319- u,
38320- cpx,
38321- cpy,
38322- chroma_side,
38323- base_q_idx,
38324- su,
38325- Some(luma_tx_type),
38326- None, fctx,
38327- )?
38328- .0;
38329- v_grid = read_inter_plane(
38330- dec,
38331- cdfs,
38332- chroma_set,
38333- chroma_scan,
38334- 2,
38335- around[2],
38336- mode_for_tx,
38337- v,
38338- cpx,
38339- cpy,
38340- chroma_side,
38341- base_q_idx,
38342- sv,
38343- Some(luma_tx_type),
38344- None, fctx,
38345- )?
38346- .0;
38415+ if chroma_side == 8 && lossless(fctx) && !mono(fctx) {
38416+ let (ug, vg) = leaf8_inter_chroma_lossless(
38417+ dec, cdfs, neighbours, u, v, su, sv,
38418+ leaf_mi, (cpx, cpy), base_q_idx, fctx,
38419+ )?;
38420+ u_grid = ug;
38421+ v_grid = vg;
38422+ chroma_stamped_per_unit = true;
38423+ } else {
38424+ u_grid = read_inter_plane(
38425+ dec,
38426+ cdfs,
38427+ chroma_set,
38428+ chroma_scan,
38429+ 1,
38430+ around[1],
38431+ mode_for_tx,
38432+ u,
38433+ cpx,
38434+ cpy,
38435+ chroma_side,
38436+ base_q_idx,
38437+ su,
38438+ Some(luma_tx_type),
38439+ None, fctx,
38440+ )?
38441+ .0;
38442+ v_grid = read_inter_plane(
38443+ dec,
38444+ cdfs,
38445+ chroma_set,
38446+ chroma_scan,
38447+ 2,
38448+ around[2],
38449+ mode_for_tx,
38450+ v,
38451+ cpx,
38452+ cpy,
38453+ chroma_side,
38454+ base_q_idx,
38455+ sv,
38456+ Some(luma_tx_type),
38457+ None, fctx,
38458+ )?
38459+ .0;
38460+ }
3834738461 }
3834838462 } else {
3834938463 let mode = dec.symbol(&mut cdfs.y_mode[SIZE_GROUP_8]);
@@ -38900,7 +39014,32 @@ fn decode_inter_block8(
3890039014 palette_record8.2,
3890139015 palette_record8.3,
3890239016 );
39017+ let saved_chroma_ctx = chroma_stamped_per_unit.then(|| {
39018+ (
39019+ [
39020+ [neighbours.left[leaf_mi.0][1], neighbours.left[leaf_mi.0][2]],
39021+ [neighbours.left[leaf_mi.0 + 1][1], neighbours.left[leaf_mi.0 + 1][2]],
39022+ ],
39023+ [
39024+ [neighbours.above[leaf_mi.1][1], neighbours.above[leaf_mi.1][2]],
39025+ [neighbours.above[leaf_mi.1 + 1][1], neighbours.above[leaf_mi.1 + 1][2]],
39026+ ],
39027+ )
39028+ });
3890339029 neighbours.record_mi(leaf_mi, 8, &[&luma_grid[..], &u_grid[..], &v_grid[..]]);
39030+ if let Some((left, above)) = saved_chroma_ctx {
39031+ // The walk's per-unit stamps are the block's real chroma coefficient
39032+ // contexts (`av1_set_contexts` per TX_4X4 unit); put them back over
39033+ // `record_mi`'s one composed state.
39034+ for (cell, uv) in left.into_iter().enumerate() {
39035+ neighbours.left[leaf_mi.0 + cell][1] = uv[0];
39036+ neighbours.left[leaf_mi.0 + cell][2] = uv[1];
39037+ }
39038+ for (cell, uv) in above.into_iter().enumerate() {
39039+ neighbours.above[leaf_mi.1 + cell][1] = uv[0];
39040+ neighbours.above[leaf_mi.1 + cell][2] = uv[1];
39041+ }
39042+ }
3890439043 // lane-uv8 r1: this leaf never stamped a mode band at all, so the block
3890539044 // below/right of it read whatever block last wrote the coarse [`SUB`]
3890639045 // slot -- now that an intra leaf here can code a smooth/directional