lane-av1-llinter2: port 84acbd09, 444 lossless inter chroma raster
Browse files at this commit988e528e1df323b2f6b0ddea2d709eb0b1b35b76Parent: f3e2fd41 changed file +218 -79
- crates/ec-av1/src/decode.rs +218 -79
crates/ec-av1/src/decode.rsmodified+218 -79
| @@ -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 chroma | 28736 | + // 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 a | 28744 | // `get_txb_ctx` reads exactly one entry per plane for a |
| 28741 | // TX_4X4 chroma unit (`a[0]`/`l[0]`). Our bands are luma-mi | 28745 | // 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 with | 28835 | /// is known `SINGLE_REFERENCE` -- `decode_stream` refuses any frame with |
| 28793 | /// `reference_select` set before this is ever called, so that read is never | 28836 | /// `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 the | 37059 | // 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/left | 37060 | // NEXT leaf of the same 16x16 can use them as its real above/left |
| @@ -37595,42 +37664,52 @@ fn decode_inter_block8( | |||
| 37595 | split8, fctx, | 37664 | split8, fctx, |
| 37596 | )?; | 37665 | )?; |
| 37597 | luma_grid = grid8; | 37666 | luma_grid = grid8; |
| 37598 | - u_grid = read_inter_plane( | 37667 | + if chroma_side == 8 && lossless(fctx) && !mono(fctx) { |
| 37599 | - dec, | 37668 | + let (ug, vg) = leaf8_inter_chroma_lossless( |
| 37600 | - cdfs, | 37669 | + dec, cdfs, neighbours, u, v, su, sv, |
| 37601 | - chroma_set, | 37670 | + leaf_mi, (cpx, cpy), base_q_idx, fctx, |
| 37602 | - chroma_scan, | 37671 | + )?; |
| 37603 | - 1, | 37672 | + u_grid = ug; |
| 37604 | - around[1], | 37673 | + v_grid = vg; |
| 37605 | - mode_for_tx, | 37674 | + chroma_stamped_per_unit = true; |
| 37606 | - u, | 37675 | + } else { |
| 37607 | - cpx, | 37676 | + u_grid = read_inter_plane( |
| 37608 | - cpy, | 37677 | + dec, |
| 37609 | - chroma_side, | 37678 | + cdfs, |
| 37610 | - base_q_idx, | 37679 | + chroma_set, |
| 37611 | - su, | 37680 | + chroma_scan, |
| 37612 | - Some(luma_tx_type), | 37681 | + 1, |
| 37613 | - None, fctx, | 37682 | + around[1], |
| 37614 | - )? | 37683 | + mode_for_tx, |
| 37615 | - .0; | 37684 | + u, |
| 37616 | - v_grid = read_inter_plane( | 37685 | + cpx, |
| 37617 | - dec, | 37686 | + cpy, |
| 37618 | - cdfs, | 37687 | + chroma_side, |
| 37619 | - chroma_set, | 37688 | + base_q_idx, |
| 37620 | - chroma_scan, | 37689 | + su, |
| 37621 | - 2, | 37690 | + Some(luma_tx_type), |
| 37622 | - around[2], | 37691 | + None, fctx, |
| 37623 | - mode_for_tx, | 37692 | + )? |
| 37624 | - v, | 37693 | + .0; |
| 37625 | - cpx, | 37694 | + v_grid = read_inter_plane( |
| 37626 | - cpy, | 37695 | + dec, |
| 37627 | - chroma_side, | 37696 | + cdfs, |
| 37628 | - base_q_idx, | 37697 | + chroma_set, |
| 37629 | - sv, | 37698 | + chroma_scan, |
| 37630 | - Some(luma_tx_type), | 37699 | + 2, |
| 37631 | - None, fctx, | 37700 | + around[2], |
| 37632 | - )? | 37701 | + mode_for_tx, |
| 37633 | - .0; | 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 | + } | ||
| 37634 | } | 37713 | } |
| 37635 | // lane-inter8 r2: the COMPOUND leaf used to return here | 37714 | // lane-inter8 r2: the COMPOUND leaf used to return here |
| 37636 | // WITHOUT the end-of-function `record_mi`/`fill_lf_grid` the | 37715 | // WITHOUT the end-of-function `record_mi`/`fill_lf_grid` the |
| @@ -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,42 +38412,52 @@ fn decode_inter_block8( | |||
| 38308 | split8, fctx, | 38412 | split8, fctx, |
| 38309 | )?; | 38413 | )?; |
| 38310 | luma_grid = grid8; | 38414 | luma_grid = grid8; |
| 38311 | - u_grid = read_inter_plane( | 38415 | + if chroma_side == 8 && lossless(fctx) && !mono(fctx) { |
| 38312 | - dec, | 38416 | + let (ug, vg) = leaf8_inter_chroma_lossless( |
| 38313 | - cdfs, | 38417 | + dec, cdfs, neighbours, u, v, su, sv, |
| 38314 | - chroma_set, | 38418 | + leaf_mi, (cpx, cpy), base_q_idx, fctx, |
| 38315 | - chroma_scan, | 38419 | + )?; |
| 38316 | - 1, | 38420 | + u_grid = ug; |
| 38317 | - around[1], | 38421 | + v_grid = vg; |
| 38318 | - mode_for_tx, | 38422 | + chroma_stamped_per_unit = true; |
| 38319 | - u, | 38423 | + } else { |
| 38320 | - cpx, | 38424 | + u_grid = read_inter_plane( |
| 38321 | - cpy, | 38425 | + dec, |
| 38322 | - chroma_side, | 38426 | + cdfs, |
| 38323 | - base_q_idx, | 38427 | + chroma_set, |
| 38324 | - su, | 38428 | + chroma_scan, |
| 38325 | - Some(luma_tx_type), | 38429 | + 1, |
| 38326 | - None, fctx, | 38430 | + around[1], |
| 38327 | - )? | 38431 | + mode_for_tx, |
| 38328 | - .0; | 38432 | + u, |
| 38329 | - v_grid = read_inter_plane( | 38433 | + cpx, |
| 38330 | - dec, | 38434 | + cpy, |
| 38331 | - cdfs, | 38435 | + chroma_side, |
| 38332 | - chroma_set, | 38436 | + base_q_idx, |
| 38333 | - chroma_scan, | 38437 | + su, |
| 38334 | - 2, | 38438 | + Some(luma_tx_type), |
| 38335 | - around[2], | 38439 | + None, fctx, |
| 38336 | - mode_for_tx, | 38440 | + )? |
| 38337 | - v, | 38441 | + .0; |
| 38338 | - cpx, | 38442 | + v_grid = read_inter_plane( |
| 38339 | - cpy, | 38443 | + dec, |
| 38340 | - chroma_side, | 38444 | + cdfs, |
| 38341 | - base_q_idx, | 38445 | + chroma_set, |
| 38342 | - sv, | 38446 | + chroma_scan, |
| 38343 | - Some(luma_tx_type), | 38447 | + 2, |
| 38344 | - None, fctx, | 38448 | + around[2], |
| 38345 | - )? | 38449 | + mode_for_tx, |
| 38346 | - .0; | 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 | + } | ||
| 38347 | } | 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]); |
| @@ -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 block | 39043 | // 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/directional | 39045 | // slot -- now that an intra leaf here can code a smooth/directional |