ec-av1: lane-av1-422g r1 -- sub-8 even-column chroma-ref arm in decode_leaf_split4, behind the header refusal
Browse files at this commit6130e75cdd0c74aa0e083fc0898ab0830bc8c8abParent: 4f088532 changed files +172 -2
crates/ec-av1/examples/decode_probe.rsmodified+1 -0
| @@ -41,6 +41,7 @@ fn main() { | |||
| 41 | ec_av1::decode::chroma422_square_hits() | 41 | ec_av1::decode::chroma422_square_hits() |
| 42 | ); | 42 | ); |
| 43 | println!("chroma422_rect: {}", ec_av1::decode::chroma422_rect_hits()); | 43 | println!("chroma422_rect: {}", ec_av1::decode::chroma422_rect_hits()); |
| 44 | + println!("chroma422_sub8: {}", ec_av1::decode::chroma422_sub8_hits()); | ||
| 44 | let (h, v, c) = ec_av1::stream::rect4_32_counters(); | 45 | let (h, v, c) = ec_av1::stream::rect4_32_counters(); |
| 45 | println!("rect4_32: horz={h} vert={v} coded={c}"); | 46 | println!("rect4_32: horz={h} vert={v} coded={c}"); |
| 46 | println!( | 47 | println!( |
crates/ec-av1/src/decode.rsmodified+171 -2
| @@ -2054,6 +2054,21 @@ pub fn chroma422_rect_hits() -> usize { | |||
| 2054 | CHROMA422_RECT_HITS.with(|c| c.get()) | 2054 | CHROMA422_RECT_HITS.with(|c| c.get()) |
| 2055 | } | 2055 | } |
| 2056 | 2056 | ||
| 2057 | +// lane-av1-422g: how many PER-LEAF TX_4X4 chroma coefficient units the | ||
| 2058 | +// sub-8x8 split4 path read on a 4:2:2 frame (ss 1,0) -- one per even-column | ||
| 2059 | +// leaf per plane (`is_chroma_reference`'s `!(mi_col & ss_x)`). A 4:2:0 frame | ||
| 2060 | +// codes no sub-8 chroma at all and 4:4:4 goes through `sub8_leaf_chroma444`, | ||
| 2061 | +// so a witness gate reading 0 here proves the per-leaf 4:2:2 arm never ran. | ||
| 2062 | +thread_local! { | ||
| 2063 | + static CHROMA422_SUB8_HITS: std::cell::Cell<usize> = | ||
| 2064 | + const { std::cell::Cell::new(0) }; | ||
| 2065 | +} | ||
| 2066 | + | ||
| 2067 | +/// Current value of [`CHROMA422_SUB8_HITS`]. | ||
| 2068 | +pub fn chroma422_sub8_hits() -> usize { | ||
| 2069 | + CHROMA422_SUB8_HITS.with(|c| c.get()) | ||
| 2070 | +} | ||
| 2071 | + | ||
| 2057 | // How many HORZ/VERT intra strips actually predicted with filter intra | 2072 | // How many HORZ/VERT intra strips actually predicted with filter intra |
| 2058 | // (lane-rectsplit r1) -- the case `decode_block_rect` refused by name | 2073 | // (lane-rectsplit r1) -- the case `decode_block_rect` refused by name |
| 2059 | // ("this decoder predicts square-only") until `predict_filter_intra` took | 2074 | // ("this decoder predicts square-only") until `predict_filter_intra` took |
| @@ -19481,6 +19496,124 @@ fn sub8_leaf_chroma444( | |||
| 19481 | } | 19496 | } |
| 19482 | 19497 | ||
| 19483 | 19498 | ||
| 19499 | +/// [`sub8_leaf_chroma444`] for 4:2:2 (lane-av1-422g): an even-mi-column 4x4 | ||
| 19500 | +/// leaf is its plane's own chroma reference (`is_chroma_reference`'s | ||
| 19501 | +/// `!(mi_col & ss_x)` at ss_x 1 -- every even-column leaf, not 4:2:0's single | ||
| 19502 | +/// bottom-right one) and codes ONE TX_4X4 chroma unit per plane right after | ||
| 19503 | +/// its luma: `ss_size_lookup[BLOCK_4X4][1][0]` is BLOCK_4X4, so the (2, 4) | ||
| 19504 | +/// plane area rounds up to the square 4x4 read. The unit sits at the chroma | ||
| 19505 | +/// position (`px >> ss_x`), and its 4 chroma-px width spans TWO luma mi | ||
| 19506 | +/// columns, so the context reads go through | ||
| 19507 | +/// [`Neighbours::around_mi_422_chroma`] and the entropy stamp covers both | ||
| 19508 | +/// columns with the unit's whole-unit state. | ||
| 19509 | +#[allow(clippy::too_many_arguments)] | ||
| 19510 | +fn sub8_leaf_chroma422( | ||
| 19511 | + dec: &mut SymbolDecoder, | ||
| 19512 | + cdfs: &mut Cdfs, | ||
| 19513 | + neighbours: &mut Neighbours, | ||
| 19514 | + lmi: (usize, usize), | ||
| 19515 | + uv_mode: usize, | ||
| 19516 | + angle_delta_uv: i32, | ||
| 19517 | + alpha: Option<(i32, i32)>, | ||
| 19518 | + skip: bool, | ||
| 19519 | + intrabc_dv: Option<(i32, i32)>, | ||
| 19520 | + y: &PlaneBuf<'static>, | ||
| 19521 | + u: &mut PlaneBuf<'static>, | ||
| 19522 | + v: &mut PlaneBuf<'static>, | ||
| 19523 | + scan4: &[u16], | ||
| 19524 | + base_q_idx: u8, | ||
| 19525 | + smooth_neighbor_uv: bool, | ||
| 19526 | + fctx: &crate::decode::FrameCtx, | ||
| 19527 | +) -> Result<(Grid, Grid)> { | ||
| 19528 | + let uv_predict_mode = if uv_mode == UV_CFL_PRED { DC_PRED } else { uv_mode }; | ||
| 19529 | + neighbours.record_uv_mode_mi(lmi.0, lmi.1, 1, 1, uv_predict_mode); | ||
| 19530 | + let (px, py) = (lmi.1 * MI, lmi.0 * MI); | ||
| 19531 | + let (cpx, cpy) = (px >> ss_x(fctx), py >> ss_y(fctx)); | ||
| 19532 | + // The square unit takes the leaf's own `Reach::of` (its luma's), the way | ||
| 19533 | + // [`decode_leaf8`]'s 422 arm passes the enclosing block's luma reach. | ||
| 19534 | + let reach = Reach::of(4, px, py, y.width, y.height, fctx); | ||
| 19535 | + let chroma_around = neighbours.around_mi_422_chroma(lmi, 8, 4); | ||
| 19536 | + let ac = alpha.map(|_| cfl_src_rect(px, py, 8, 4)); | ||
| 19537 | + let grids: (Grid, Grid) = if skip { | ||
| 19538 | + // A skipped chroma-reference leaf still predicts (the CfL contribution | ||
| 19539 | + // survives a skip); no coefficient symbol exists. | ||
| 19540 | + if alpha.is_some() { | ||
| 19541 | + hit!(CHROMA_SKIP_CFL_HITS); | ||
| 19542 | + hit!(SKIP_CFL_HITS); | ||
| 19543 | + } | ||
| 19544 | + push_intra(1, cpx, cpy, 4, uv_predict_mode, angle_delta_uv, reach, &ZERO_RESIDUAL[..16], alpha.zip(ac).map(|((au, _), ac)| (au, ac)), None, smooth_neighbor_uv, fctx); | ||
| 19545 | + push_intra(2, cpx, cpy, 4, uv_predict_mode, angle_delta_uv, reach, &ZERO_RESIDUAL[..16], alpha.zip(ac).map(|((_, av), ac)| (av, ac)), None, smooth_neighbor_uv, fctx); | ||
| 19546 | + // The same arm-without-clear route the 4:2:0 tails count: a skipped | ||
| 19547 | + // leaf reads no coefficient, so an armed intrabc slot is dropped. | ||
| 19548 | + if fctx.intrabc_chroma_tx.with(std::cell::Cell::get).is_some() { | ||
| 19549 | + hit!(SKIPPED_INTRABC_CHROMA_ARM_HITS); | ||
| 19550 | + fctx.intrabc_chroma_tx.with(|c| c.set(None)); | ||
| 19551 | + } | ||
| 19552 | + (Grid::Zero(16), Grid::Zero(16)) | ||
| 19553 | + } else if let Some(dv) = intrabc_dv { | ||
| 19554 | + hit!(CHROMA422_SUB8_HITS); | ||
| 19555 | + // Frame copy at the DV; the residual still reads the ordinary chroma | ||
| 19556 | + // tables with the inherited luma `tx_type` (see the 4:2:0 tails). | ||
| 19557 | + let mut ub = vec![0u16; 16]; | ||
| 19558 | + mc::predict_with_filter( | ||
| 19559 | + &u.data, u.width, u.true_width, u.true_height, | ||
| 19560 | + mv_to_q4(cpx, dv.1, ss_x(fctx)), mv_to_q4(cpy, dv.0, ss_y(fctx)), | ||
| 19561 | + 4, 4, mc::InterpFilterKind::Bilinear, &mut ub, fctx, | ||
| 19562 | + ); | ||
| 19563 | + let mut vb = vec![0u16; 16]; | ||
| 19564 | + mc::predict_with_filter( | ||
| 19565 | + &v.data, v.width, v.true_width, v.true_height, | ||
| 19566 | + mv_to_q4(cpx, dv.1, ss_x(fctx)), mv_to_q4(cpy, dv.0, ss_y(fctx)), | ||
| 19567 | + 4, 4, mc::InterpFilterKind::Bilinear, &mut vb, fctx, | ||
| 19568 | + ); | ||
| 19569 | + set_palette_pred(ub, fctx); | ||
| 19570 | + let ug = read_plane( | ||
| 19571 | + dec, cdfs, TxbSet::Chroma4, scan4, 1, chroma_around[1], DC_PRED, DC_PRED, | ||
| 19572 | + 0, reach, u, cpx, cpy, 4, TX4, base_q_idx, | ||
| 19573 | + None, None, None, smooth_neighbor_uv, fctx, | ||
| 19574 | + )?; | ||
| 19575 | + set_palette_pred(vb, fctx); | ||
| 19576 | + let vg = read_plane( | ||
| 19577 | + dec, cdfs, TxbSet::Chroma4, scan4, 2, chroma_around[2], DC_PRED, DC_PRED, | ||
| 19578 | + 0, reach, v, cpx, cpy, 4, TX4, base_q_idx, | ||
| 19579 | + None, None, None, smooth_neighbor_uv, fctx, | ||
| 19580 | + )?; | ||
| 19581 | + fctx.intrabc_chroma_tx.with(|c| c.set(None)); | ||
| 19582 | + (ug, vg) | ||
| 19583 | + } else { | ||
| 19584 | + hit!(CHROMA422_SUB8_HITS); | ||
| 19585 | + let ug = read_plane( | ||
| 19586 | + dec, cdfs, TxbSet::Chroma4, scan4, 1, chroma_around[1], uv_mode, uv_predict_mode, | ||
| 19587 | + angle_delta_uv, reach, u, cpx, cpy, 4, TX4, base_q_idx, | ||
| 19588 | + alpha.zip(ac).map(|((au, _), ac)| (au, ac)), None, None, smooth_neighbor_uv, fctx, | ||
| 19589 | + )?; | ||
| 19590 | + let vg = read_plane( | ||
| 19591 | + dec, cdfs, TxbSet::Chroma4, scan4, 2, chroma_around[2], uv_mode, uv_predict_mode, | ||
| 19592 | + angle_delta_uv, reach, v, cpx, cpy, 4, TX4, base_q_idx, | ||
| 19593 | + alpha.zip(ac).map(|((_, av), ac)| (av, ac)), None, None, smooth_neighbor_uv, fctx, | ||
| 19594 | + )?; | ||
| 19595 | + (ug, vg) | ||
| 19596 | + }; | ||
| 19597 | + // libaom `av1_set_entropy_contexts` stamps above/left PER TRANSFORM UNIT: | ||
| 19598 | + // the unit's own chroma span -- 1 mi row tall, TWO luma mi columns wide | ||
| 19599 | + // (one chroma column) -- not the 8x8 group's. | ||
| 19600 | + let (u_grid, v_grid) = grids; | ||
| 19601 | + let u_state = neighbour_state(&u_grid); | ||
| 19602 | + let v_state = neighbour_state(&v_grid); | ||
| 19603 | + if lmi.0 < neighbours.mi_rows { | ||
| 19604 | + neighbours.left[lmi.0][1] = u_state; | ||
| 19605 | + neighbours.left[lmi.0][2] = v_state; | ||
| 19606 | + } | ||
| 19607 | + for cell in 0..2 { | ||
| 19608 | + if lmi.1 + cell < neighbours.mi_cols { | ||
| 19609 | + neighbours.above[lmi.1 + cell][1] = u_state; | ||
| 19610 | + neighbours.above[lmi.1 + cell][2] = v_state; | ||
| 19611 | + } | ||
| 19612 | + } | ||
| 19613 | + Ok((u_grid, v_grid)) | ||
| 19614 | +} | ||
| 19615 | + | ||
| 19616 | + | ||
| 19484 | /// Decodes a `PARTITION_SPLIT` of one 8x8 block into four `BLOCK_4X4` leaves | 19617 | /// Decodes a `PARTITION_SPLIT` of one 8x8 block into four `BLOCK_4X4` leaves |
| 19485 | /// (spec `decode_partition`'s recursion bottom), sharing [`decode_leaf8`]'s | 19618 | /// (spec `decode_partition`'s recursion bottom), sharing [`decode_leaf8`]'s |
| 19486 | /// own signature so its caller's `prev_leaf`/`above_mode`/`left_mode` | 19619 | /// own signature so its caller's `prev_leaf`/`above_mode`/`left_mode` |
| @@ -19538,9 +19671,14 @@ fn decode_leaf_split4( | |||
| 19538 | // `uv_mode` and codes its own full-resolution 4x4 chroma unit right | 19671 | // `uv_mode` and codes its own full-resolution 4x4 chroma unit right |
| 19539 | // after its luma -- there is no shared group unit at all. | 19672 | // after its luma -- there is no shared group unit at all. |
| 19540 | let chroma_444 = ss_x(fctx) == 0 && ss_y(fctx) == 0; | 19673 | let chroma_444 = ss_x(fctx) == 0 && ss_y(fctx) == 0; |
| 19674 | + // lane-av1-422g: at ss (1,0) every even-mi-column leaf is its plane's own | ||
| 19675 | + // chroma reference (`is_chroma_reference`'s `!(mi_col & ss_x)`) and codes | ||
| 19676 | + // one TX_4X4 chroma unit per plane; odd-column leaves read no chroma. | ||
| 19677 | + let chroma_422 = ss_x(fctx) == 1 && ss_y(fctx) == 0; | ||
| 19541 | // The last leaf's own `uv_predict_mode`, for the coarse above/left slots | 19678 | // The last leaf's own `uv_predict_mode`, for the coarse above/left slots |
| 19542 | // the 4:2:0 tail fills from the group's single unit. | 19679 | // the 4:2:0 tail fills from the group's single unit. |
| 19543 | let mut last_uv444 = DC_PRED; | 19680 | let mut last_uv444 = DC_PRED; |
| 19681 | + let mut last_uv422 = DC_PRED; | ||
| 19544 | for i in 0..4usize { | 19682 | for i in 0..4usize { |
| 19545 | let (dr, dc) = (i / 2, i % 2); | 19683 | let (dr, dc) = (i / 2, i % 2); |
| 19546 | let lmi = (leaf_mi.0 + dr, leaf_mi.1 + dc); | 19684 | let lmi = (leaf_mi.0 + dr, leaf_mi.1 + dc); |
| @@ -19558,7 +19696,13 @@ fn decode_leaf_split4( | |||
| 19558 | } else { | 19696 | } else { |
| 19559 | leaf_modes[i - 1] | 19697 | leaf_modes[i - 1] |
| 19560 | }; | 19698 | }; |
| 19561 | - let has_chroma = chroma_444 || i == 3; | 19699 | + let has_chroma = if chroma_444 { |
| 19700 | + true | ||
| 19701 | + } else if chroma_422 { | ||
| 19702 | + (lmi.1 & 1) == 0 | ||
| 19703 | + } else { | ||
| 19704 | + i == 3 | ||
| 19705 | + }; | ||
| 19562 | let skip_ctx = neighbours.skip_txfm_ctx(lmi.0, lmi.1); | 19706 | let skip_ctx = neighbours.skip_txfm_ctx(lmi.0, lmi.1); |
| 19563 | let (skip, mode, angle_delta_y, chroma, filter_intra, intrabc) = read_intra_mode_sub8( | 19707 | let (skip, mode, angle_delta_y, chroma, filter_intra, intrabc) = read_intra_mode_sub8( |
| 19564 | dec, cdfs, leaf_above, leaf_left, has_chroma, enable_filter_intra, | 19708 | dec, cdfs, leaf_above, leaf_left, has_chroma, enable_filter_intra, |
| @@ -19647,6 +19791,13 @@ fn decode_leaf_split4( | |||
| 19647 | neighbours.smooth_uv_neighbour(lmi.0, lmi.1, r, c, fctx), fctx, | 19791 | neighbours.smooth_uv_neighbour(lmi.0, lmi.1, r, c, fctx), fctx, |
| 19648 | )?; | 19792 | )?; |
| 19649 | last_uv444 = DC_PRED; | 19793 | last_uv444 = DC_PRED; |
| 19794 | + } else if chroma_422 { | ||
| 19795 | + sub8_leaf_chroma422( | ||
| 19796 | + dec, cdfs, neighbours, lmi, DC_PRED, 0, None, skip, | ||
| 19797 | + Some(dv), y, u, v, scan4, base_q_idx, | ||
| 19798 | + neighbours.smooth_uv_neighbour(lmi.0, lmi.1, r, c, fctx), fctx, | ||
| 19799 | + )?; | ||
| 19800 | + last_uv422 = DC_PRED; | ||
| 19650 | } else { | 19801 | } else { |
| 19651 | last_uv = Some((DC_PRED, 0, None)); | 19802 | last_uv = Some((DC_PRED, 0, None)); |
| 19652 | // lane-av1txbands: the group's chroma is the CHROMA-REFERENCE | 19803 | // lane-av1txbands: the group's chroma is the CHROMA-REFERENCE |
| @@ -19712,6 +19863,15 @@ fn decode_leaf_split4( | |||
| 19712 | neighbours.smooth_uv_neighbour(lmi.0, lmi.1, r, c, fctx), fctx, | 19863 | neighbours.smooth_uv_neighbour(lmi.0, lmi.1, r, c, fctx), fctx, |
| 19713 | )?; | 19864 | )?; |
| 19714 | last_uv444 = if uv_mode == UV_CFL_PRED { DC_PRED } else { uv_mode }; | 19865 | last_uv444 = if uv_mode == UV_CFL_PRED { DC_PRED } else { uv_mode }; |
| 19866 | + } else if chroma_422 { | ||
| 19867 | + let (uv_mode, angle_delta_uv, alpha) = | ||
| 19868 | + chroma.expect("4:2:2 reads uv_mode on even-column leaves"); | ||
| 19869 | + sub8_leaf_chroma422( | ||
| 19870 | + dec, cdfs, neighbours, lmi, uv_mode, angle_delta_uv, alpha, skip, | ||
| 19871 | + None, y, u, v, scan4, base_q_idx, | ||
| 19872 | + neighbours.smooth_uv_neighbour(lmi.0, lmi.1, r, c, fctx), fctx, | ||
| 19873 | + )?; | ||
| 19874 | + last_uv422 = if uv_mode == UV_CFL_PRED { DC_PRED } else { uv_mode }; | ||
| 19715 | } else { | 19875 | } else { |
| 19716 | last_uv = chroma; | 19876 | last_uv = chroma; |
| 19717 | } | 19877 | } |
| @@ -19729,6 +19889,14 @@ fn decode_leaf_split4( | |||
| 19729 | neighbours.above_uv_mode[c] = last_uv444; | 19889 | neighbours.above_uv_mode[c] = last_uv444; |
| 19730 | neighbours.left_uv_mode[r] = last_uv444; | 19890 | neighbours.left_uv_mode[r] = last_uv444; |
| 19731 | (Grid::Zero(16), Grid::Zero(16)) | 19891 | (Grid::Zero(16), Grid::Zero(16)) |
| 19892 | + } else if chroma_422 { | ||
| 19893 | + // lane-av1-422g: each even-column leaf coded and reconstructed its | ||
| 19894 | + // own TX_4X4 chroma unit in the loop above (sub8_leaf_chroma422 | ||
| 19895 | + // stamped the per-leaf entropy state); only the coarse slots remain, | ||
| 19896 | + // filled from the group's last chroma-reference leaf (bottom-left). | ||
| 19897 | + neighbours.above_uv_mode[c] = last_uv422; | ||
| 19898 | + neighbours.left_uv_mode[r] = last_uv422; | ||
| 19899 | + (Grid::Zero(16), Grid::Zero(16)) | ||
| 19732 | } else { | 19900 | } else { |
| 19733 | let (gpx, gpy) = (leaf_mi.1 * MI, leaf_mi.0 * MI); | 19901 | let (gpx, gpy) = (leaf_mi.1 * MI, leaf_mi.0 * MI); |
| 19734 | let (cpx, cpy) = (gpx >> ss_x(fctx), gpy >> ss_y(fctx)); | 19902 | let (cpx, cpy) = (gpx >> ss_x(fctx), gpy >> ss_y(fctx)); |
| @@ -19840,7 +20008,8 @@ fn decode_leaf_split4( | |||
| 19840 | } | 20008 | } |
| 19841 | // lane-av1-444: at 4:4:4 [`sub8_leaf_chroma444`] already stamped each | 20009 | // lane-av1-444: at 4:4:4 [`sub8_leaf_chroma444`] already stamped each |
| 19842 | // leaf's own span as it decoded; these placeholder grids carry no state. | 20010 | // leaf's own span as it decoded; these placeholder grids carry no state. |
| 19843 | - if !chroma_444 { | 20011 | + // lane-av1-422g: the 4:2:2 per-leaf units stamp the same way. |
| 20012 | + if !chroma_444 && !chroma_422 { | ||
| 19844 | let round_up_even = |n: usize| n.div_ceil(2) * 2; | 20013 | let round_up_even = |n: usize| n.div_ceil(2) * 2; |
| 19845 | let bound_h = round_up_even(neighbours.mi_rows); | 20014 | let bound_h = round_up_even(neighbours.mi_rows); |
| 19846 | let bound_w = round_up_even(neighbours.mi_cols); | 20015 | let bound_w = round_up_even(neighbours.mi_cols); |