forge
Explore
Log in

Don't you dare go Hollow

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 commit

6130e75cdd0c74aa0e083fc0898ab0830bc8c8abAhmet Kaan GümüşParent: 4f08853
4:2:2 (ss 1,0): every even-mi-column 4x4 leaf is its plane's own chroma
reference (is_chroma_reference's !(mi_col & ss_x)) and codes one TX_4X4
chroma unit per plane (ss_size_lookup[BLOCK_4X4][1][0] rounds the 2x4
plane area up to BLOCK_4X4), not 4:2:0's single bottom-right group unit.
has_chroma now keys on the leaf's mi column at ss (1,0); new
sub8_leaf_chroma422 reads the square unit through read_plane's Chroma4
route at the chroma position, with around_mi_422_chroma context reads
(one chroma column spans two luma mi), per-leaf entropy stamping, and
the skip/intrabc arms. New CHROMA422_SUB8_HITS witness counter.

STOP: the arm is unproven on t422 -- the frame-0 walk never reaches
decode_leaf_split4 (zero split8 calls before decode_rect4_16_strip's
closed-shape panic at the 32x64 strip whose 16x64 chroma has no table
row), so the divergence the 422f report attributed to the mi(9,10)
sub-8 chroma begins EARLIER, at the 8x8 partition symbol. Refusal
byte-identical; bypass reverted.
crates/ec-av1/examples/decode_probe.rsmodified+1 -0
@@ -41,6 +41,7 @@ fn main() {
4141 ec_av1::decode::chroma422_square_hits()
4242 );
4343 println!("chroma422_rect: {}", ec_av1::decode::chroma422_rect_hits());
44+ println!("chroma422_sub8: {}", ec_av1::decode::chroma422_sub8_hits());
4445 let (h, v, c) = ec_av1::stream::rect4_32_counters();
4546 println!("rect4_32: horz={h} vert={v} coded={c}");
4647 println!(
crates/ec-av1/src/decode.rsmodified+171 -2
@@ -2054,6 +2054,21 @@ pub fn chroma422_rect_hits() -> usize {
20542054 CHROMA422_RECT_HITS.with(|c| c.get())
20552055 }
20562056
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+
20572072 // How many HORZ/VERT intra strips actually predicted with filter intra
20582073 // (lane-rectsplit r1) -- the case `decode_block_rect` refused by name
20592074 // ("this decoder predicts square-only") until `predict_filter_intra` took
@@ -19481,6 +19496,124 @@ fn sub8_leaf_chroma444(
1948119496 }
1948219497
1948319498
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+
1948419617 /// Decodes a `PARTITION_SPLIT` of one 8x8 block into four `BLOCK_4X4` leaves
1948519618 /// (spec `decode_partition`'s recursion bottom), sharing [`decode_leaf8`]'s
1948619619 /// own signature so its caller's `prev_leaf`/`above_mode`/`left_mode`
@@ -19538,9 +19671,14 @@ fn decode_leaf_split4(
1953819671 // `uv_mode` and codes its own full-resolution 4x4 chroma unit right
1953919672 // after its luma -- there is no shared group unit at all.
1954019673 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;
1954119678 // The last leaf's own `uv_predict_mode`, for the coarse above/left slots
1954219679 // the 4:2:0 tail fills from the group's single unit.
1954319680 let mut last_uv444 = DC_PRED;
19681+ let mut last_uv422 = DC_PRED;
1954419682 for i in 0..4usize {
1954519683 let (dr, dc) = (i / 2, i % 2);
1954619684 let lmi = (leaf_mi.0 + dr, leaf_mi.1 + dc);
@@ -19558,7 +19696,13 @@ fn decode_leaf_split4(
1955819696 } else {
1955919697 leaf_modes[i - 1]
1956019698 };
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+ };
1956219706 let skip_ctx = neighbours.skip_txfm_ctx(lmi.0, lmi.1);
1956319707 let (skip, mode, angle_delta_y, chroma, filter_intra, intrabc) = read_intra_mode_sub8(
1956419708 dec, cdfs, leaf_above, leaf_left, has_chroma, enable_filter_intra,
@@ -19647,6 +19791,13 @@ fn decode_leaf_split4(
1964719791 neighbours.smooth_uv_neighbour(lmi.0, lmi.1, r, c, fctx), fctx,
1964819792 )?;
1964919793 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;
1965019801 } else {
1965119802 last_uv = Some((DC_PRED, 0, None));
1965219803 // lane-av1txbands: the group's chroma is the CHROMA-REFERENCE
@@ -19712,6 +19863,15 @@ fn decode_leaf_split4(
1971219863 neighbours.smooth_uv_neighbour(lmi.0, lmi.1, r, c, fctx), fctx,
1971319864 )?;
1971419865 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 };
1971519875 } else {
1971619876 last_uv = chroma;
1971719877 }
@@ -19729,6 +19889,14 @@ fn decode_leaf_split4(
1972919889 neighbours.above_uv_mode[c] = last_uv444;
1973019890 neighbours.left_uv_mode[r] = last_uv444;
1973119891 (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))
1973219900 } else {
1973319901 let (gpx, gpy) = (leaf_mi.1 * MI, leaf_mi.0 * MI);
1973419902 let (cpx, cpy) = (gpx >> ss_x(fctx), gpy >> ss_y(fctx));
@@ -19840,7 +20008,8 @@ fn decode_leaf_split4(
1984020008 }
1984120009 // lane-av1-444: at 4:4:4 [`sub8_leaf_chroma444`] already stamped each
1984220010 // 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 {
1984420013 let round_up_even = |n: usize| n.div_ceil(2) * 2;
1984520014 let bound_h = round_up_even(neighbours.mi_rows);
1984620015 let bound_w = round_up_even(neighbours.mi_cols);