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+146 -7
@@ -28733,9 +28733,13 @@ fn read_inter_chroma_lossless(
28733 if cpx + ox >= u.true_width || cpy + oy >= u.true_height {28733 if cpx + ox >= u.true_width || cpy + oy >= u.true_height {
28734 continue;28734 continue;
28735 }28735 }
28736- // The chroma neighbour bands are indexed in LUMA mi: 4 chroma28736+ // The chroma neighbour bands are indexed in LUMA mi: a 4-wide
28737- // pixels span 8 luma ones, i.e. 2 mi.28737+ // chroma unit spans `4 << ss` luma pixels, i.e. `4 >> ss` --
28738- let cu_mi = (at_mi.0 + oy / 2, at_mi.1 + ox / 2);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+ );
28739 // libaom's chroma entropy-context arrays are SUBSAMPLED:28743 // libaom's chroma entropy-context arrays are SUBSAMPLED:
28740 // `get_txb_ctx` reads exactly one entry per plane for a28744 // `get_txb_ctx` reads exactly one entry per plane for a
28741 // TX_4X4 chroma unit (`a[0]`/`l[0]`). Our bands are luma-mi28745 // TX_4X4 chroma unit (`a[0]`/`l[0]`). Our bands are luma-mi
@@ -28772,7 +28776,13 @@ fn read_inter_chroma_lossless(
28772 )?28776 )?
28773 .0;28777 .0;
28774 // Immediately, so the NEXT unit reads this one's context.28778 // 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+ );
28776 hit!(CHROMA_SPLIT_TX_HITS);28786 hit!(CHROMA_SPLIT_TX_HITS);
28777 let dst = mu_units(28787 let dst = mu_units(
28778 if plane_idx == 1 { &mut *u_out } else { &mut *v_out },28788 if plane_idx == 1 { &mut *u_out } else { &mut *v_out },
@@ -28788,6 +28798,39 @@ fn read_inter_chroma_lossless(
28788 Ok(())28798 Ok(())
28789 }28799 }
28790 28800
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+
28791 /// Spec 5.11.25's `single_ref_p1`..`p6` tree (reachable only once `comp_mode`28834 /// Spec 5.11.25's `single_ref_p1`..`p6` tree (reachable only once `comp_mode`
28792 /// is known `SINGLE_REFERENCE` -- `decode_stream` refuses any frame with28835 /// is known `SINGLE_REFERENCE` -- `decode_stream` refuses any frame with
28793 /// `reference_select` set before this is ever called, so that read is never28836 /// `reference_select` set before this is ever called, so that read is never
@@ -34471,17 +34514,37 @@ fn decode_inter_block(
34471 let cu = if lossless(fctx) { 4usize } else { 32usize };34514 let cu = if lossless(fctx) { 4usize } else { 32usize };
34472 let mut units = Vec::new();34515 let mut units = Vec::new();
34473 if lossless(fctx) {34516 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+ );
34475 for cr in 0..rows {34529 for cr in 0..rows {
34476 for cc in 0..cols {34530 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+ );
34478 for (plane, grid) in [(1usize, &u_grid), (2usize, &v_grid)] {34535 for (plane, grid) in [(1usize, &u_grid), (2usize, &v_grid)] {
34479 let mut unit = Vec::with_capacity(cu * cu);34536 let mut unit = Vec::with_capacity(cu * cu);
34480 for rr in 0..cu {34537 for rr in 0..cu {
34481 let start = (cr * cu + rr) * chroma_side + cc * cu;34538 let start = (cr * cu + rr) * chroma_side + cc * cu;
34482 unit.extend_from_slice(&grid[start..start + cu]);34539 unit.extend_from_slice(&grid[start..start + cu]);
34483 }34540 }
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+ ));
34485 }34548 }
34486 }34549 }
34487 }34550 }
@@ -36986,6 +37049,12 @@ fn decode_inter_block8(
36986 // stores `UV_DC_PRED`, exactly as [`decode_inter_block`] one level up.37049 // stores `UV_DC_PRED`, exactly as [`decode_inter_block`] one level up.
36987 let mut uv_predict_mode = DC_PRED;37050 let mut uv_predict_mode = DC_PRED;
36988 let (luma_grid, u_grid, v_grid);37051 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;
36989 let mut compound_ctx8: Option<(i8, i8, u8, u8)> = None;37058 let mut compound_ctx8: Option<(i8, i8, u8, u8)> = None;
36990 // lane-inter8 r1: this leaf's own resolved references, handed back so the37059 // lane-inter8 r1: this leaf's own resolved references, handed back so the
36991 // NEXT leaf of the same 16x16 can use them as its real above/left37060 // NEXT leaf of the same 16x16 can use them as its real above/left
@@ -37595,6 +37664,15 @@ fn decode_inter_block8(
37595 split8, fctx,37664 split8, fctx,
37596 )?;37665 )?;
37597 luma_grid = grid8;37666 luma_grid = grid8;
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 {
37598 u_grid = read_inter_plane(37676 u_grid = read_inter_plane(
37599 dec,37677 dec,
37600 cdfs,37678 cdfs,
@@ -37632,6 +37710,7 @@ fn decode_inter_block8(
37632 )?37710 )?
37633 .0;37711 .0;
37634 }37712 }
37713+ }
37635 // lane-inter8 r2: the COMPOUND leaf used to return here37714 // lane-inter8 r2: the COMPOUND leaf used to return here
37636 // WITHOUT the end-of-function `record_mi`/`fill_lf_grid` the37715 // WITHOUT the end-of-function `record_mi`/`fill_lf_grid` the
37637 // single-ref path falls through to -- so a compound 8x8 leaf37716 // single-ref path falls through to -- so a compound 8x8 leaf
@@ -37686,7 +37765,32 @@ fn decode_inter_block8(
37686 palette_record8.2,37765 palette_record8.2,
37687 palette_record8.3,37766 palette_record8.3,
37688 );37767 );
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+ });
37689 neighbours.record_mi(leaf_mi, 8, &[&luma_grid[..], &u_grid[..], &v_grid[..]]);37780 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+ }
37690 if let Some((left, above)) = saved_luma_ctx {37794 if let Some((left, above)) = saved_luma_ctx {
37691 for (cell, state) in left.into_iter().enumerate() {37795 for (cell, state) in left.into_iter().enumerate() {
37692 neighbours.left[leaf_mi.0 + cell][0] = state;37796 neighbours.left[leaf_mi.0 + cell][0] = state;
@@ -38308,6 +38412,15 @@ fn decode_inter_block8(
38308 split8, fctx,38412 split8, fctx,
38309 )?;38413 )?;
38310 luma_grid = grid8;38414 luma_grid = grid8;
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 {
38311 u_grid = read_inter_plane(38424 u_grid = read_inter_plane(
38312 dec,38425 dec,
38313 cdfs,38426 cdfs,
@@ -38345,6 +38458,7 @@ fn decode_inter_block8(
38345 )?38458 )?
38346 .0;38459 .0;
38347 }38460 }
38461+ }
38348 } else {38462 } else {
38349 let mode = dec.symbol(&mut cdfs.y_mode[SIZE_GROUP_8]);38463 let mode = dec.symbol(&mut cdfs.y_mode[SIZE_GROUP_8]);
38350 if mode >= 13 {38464 if mode >= 13 {
@@ -38900,7 +39014,32 @@ fn decode_inter_block8(
38900 palette_record8.2,39014 palette_record8.2,
38901 palette_record8.3,39015 palette_record8.3,
38902 );39016 );
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+ });
38903 neighbours.record_mi(leaf_mi, 8, &[&luma_grid[..], &u_grid[..], &v_grid[..]]);39029 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+ }
38904 // lane-uv8 r1: this leaf never stamped a mode band at all, so the block39043 // lane-uv8 r1: this leaf never stamped a mode band at all, so the block
38905 // below/right of it read whatever block last wrote the coarse [`SUB`]39044 // below/right of it read whatever block last wrote the coarse [`SUB`]
38906 // slot -- now that an intra leaf here can code a smooth/directional39045 // slot -- now that an intra leaf here can code a smooth/directional