forge
Explore
Log in

Don't you dare go Hollow

Intra 8x4/4x8 and 4x4 leaves of an inter frame's sub-8x8 partition decode behind EC_SUB8INTRA_DECODE (gate RED, refusals kept)

Browse files at this commit

2b05cf7c672af00c27ff4baa012fa6a6516fecfeAhmet Kaan GümüşParent: e5f8021
  • feat
    • intra 8x4/4x8 and 4x4 leaves of an inter frame's sub-8x8 partition decode behind EC_SUB8INTRA_DECODE (gate RED, refusals kept)
Show full message
feat(av1): intra 8x4/4x8 and 4x4 leaves of an inter frame's sub-8x8 partition decode behind EC_SUB8INTRA_DECODE (gate RED, refusals kept)

decode_intra_sub8_leaf reads read_intra_block_mode_info's syntax (y_mode[0], no
angle delta below 8x8, uv_mode + CfL only on the chroma reference, filter_intra
off the shape's own class row) and then decode_leaf_rect8's luma/chroma body,
with the INTER frame's tx-depth context and set_txfm_ctxs publication. Both
sub-8x8 callers guard their chroma tail when the chroma reference is intra, and
predict the group's 4x4 chroma WHOLE from the chroma-reference block's mv when a
sibling is intra (is_sub8x8_inter false).

Measured: 5/6 film probes stop first on sub-block 0 of a HORZ/VERT pair, non-skip;
under the switch all six move to the next wall. The path is NOT proven: on an
8-bit 128x128 aomenc witness the intra leaf itself is bit-exact (mode + tx_depth
rng match the oracle) but the stream desyncs inside the next 8x8 group, so the
refusals stay the default behaviour and no gate is added.
crates/ec-av1/examples/decode_probe.rsmodified+5 -0
@@ -45,6 +45,11 @@ fn main() {
45 println!("sub8_inter_split: groups={}", ec_av1::decode::sub8_inter_split_hits());45 println!("sub8_inter_split: groups={}", ec_av1::decode::sub8_inter_split_hits());
46 let (h84, h48) = ec_av1::decode::sub8_inter_rect_hits();46 let (h84, h48) = ec_av1::decode::sub8_inter_rect_hits();
47 println!("sub8_inter_rect: horz8x4={h84} vert4x8={h48}");47 println!("sub8_inter_rect: horz8x4={h84} vert4x8={h48}");
48+ let si = ec_av1::stream::sub8_intra_rect_hits();
49+ println!(
50+ "sub8_intra_rect: horz8x4={} vert4x8={} chroma_ref={} mixed={}",
51+ si.0, si.1, si.2, si.3
52+ );
48 let leaf = ec_av1::stream::vartx_rect_leaf_hits();53 let leaf = ec_av1::stream::vartx_rect_leaf_hits();
49 println!("vartx_rect_leaf: 32x16={} 16x32={}", leaf[0], leaf[1]);54 println!("vartx_rect_leaf: 32x16={} 16x32={}", leaf[0], leaf[1]);
50 // lane-inter16ab r1: the 16x16-level inter AB arms, so a recipe sweep55 // lane-inter16ab r1: the 16x16-level inter AB arms, so a recipe sweep
crates/ec-av1/src/decode.rsmodified+582 -22
@@ -3117,6 +3117,21 @@ thread_local! {
3117 /// inter leaves (lane-intersub8 r3), indexed `[0] = HORZ` (two BLOCK_8X4),3117 /// inter leaves (lane-intersub8 r3), indexed `[0] = HORZ` (two BLOCK_8X4),
3118 /// `[1] = VERT` (two BLOCK_4X8).3118 /// `[1] = VERT` (two BLOCK_4X8).
3119 static SUB8_INTER_RECT_HITS: std::cell::Cell<[usize; 2]> = const { std::cell::Cell::new([0; 2]) };3119 static SUB8_INTER_RECT_HITS: std::cell::Cell<[usize; 2]> = const { std::cell::Cell::new([0; 2]) };
3120+ /// lane-sub8intra: INTRA leaves decoded inside an inter frame's sub-8x8
3121+ /// HORZ/VERT partition -- `[0]` 8x4, `[1]` 4x8, `[2]` of those that were
3122+ /// the chroma reference (so coded the group's 4x4 chroma intra), `[3]`
3123+ /// MIXED groups whose chroma reference is INTER while its sibling is
3124+ /// intra (the `is_sub8x8_inter` false path).
3125+ static SUB8_INTRA_RECT_HITS: std::cell::Cell<[usize; 4]> = const { std::cell::Cell::new([0; 4]) };
3126+}
3127+
3128+/// Current value of [`SUB8_INTRA_RECT_HITS`]: `(8x4, 4x8, chroma-reference,
3129+/// mixed groups)`.
3130+pub fn sub8_intra_rect_hits() -> (usize, usize, usize, usize) {
3131+ SUB8_INTRA_RECT_HITS.with(|c| {
3132+ let h = c.get();
3133+ (h[0], h[1], h[2], h[3])
3134+ })
3120 }3135 }
3121 3136
3122 /// Current value of [`SUB8_INTER_RECT_HITS`]: `(8x4 groups, 4x8 groups)`.3137 /// Current value of [`SUB8_INTER_RECT_HITS`]: `(8x4 groups, 4x8 groups)`.
@@ -22621,6 +22636,9 @@ fn decode_inter_sub8_split4(
22621 [None; 4];22636 [None; 4];
22622 let mut first_tx_type = TxType::DctDct;22637 let mut first_tx_type = TxType::DctDct;
22623 let mut last_skip = true;22638 let mut last_skip = true;
22639+ // Set when the chroma-reference (last) sub-block is INTRA: it coded the
22640+ // group's one chroma unit itself.
22641+ let mut intra_chroma = false;
22624 for i in 0..4usize {22642 for i in 0..4usize {
22625 let (dr, dc) = (i / 2, i % 2);22643 let (dr, dc) = (i / 2, i % 2);
22626 let lmi = (gr + dr, gc + dc);22644 let lmi = (gr + dr, gc + dc);
@@ -22649,11 +22667,49 @@ fn decode_inter_sub8_split4(
22649 );22667 );
22650 let is_inter = dec.symbol(&mut cdfs.intra_inter[ii_ctx]) == 1;22668 let is_inter = dec.symbol(&mut cdfs.intra_inter[ii_ctx]) == 1;
22651 if !is_inter {22669 if !is_inter {
22670+ if std::env::var_os("EC_SUB8INTRA").is_some() {
22671+ eprintln!(
22672+ "EC_SUB8INTRA shape=4x4 sub={i} has_chroma={} skip={skip} mi={rmi},{cmi} tx_select={}",
22673+ i == 3,
22674+ TX_SELECT_INTER.with(std::cell::Cell::get),
22675+ );
22676+ }
22677+ // lane-sub8intra: same `EC_SUB8INTRA_DECODE` switch as the
22678+ // HORZ/VERT arm; the refusal is the default until the gate is
22679+ // green.
22680+ if std::env::var_os("EC_SUB8INTRA_DECODE").is_none() {
22652 return Err(unsupported(22681 return Err(unsupported(
22653 "an intra 4x4 block inside an inter frame's sub-8x8 split (this decoder codes \22682 "an intra 4x4 block inside an inter frame's sub-8x8 split (this decoder codes \
22654 only inter 4x4 sub-blocks there)",22683 only inter 4x4 sub-blocks there)",
22655 ));22684 ));
22656 }22685 }
22686+ // lane-sub8intra: the `BLOCK_4X4` twin of the HORZ/VERT arm --
22687+ // same [`decode_intra_sub8_leaf`], no tx-depth symbol, chroma on
22688+ // the LAST sub-block (`is_chroma_reference` under 4:2:0).
22689+ decode_intra_sub8_leaf(
22690+ dec,
22691+ cdfs,
22692+ neighbours,
22693+ grid,
22694+ group_mi,
22695+ lmi,
22696+ (B4, B4),
22697+ i == 3,
22698+ skip,
22699+ scan4,
22700+ y,
22701+ u,
22702+ v,
22703+ base_q_idx,
22704+ ENABLE_FILTER_INTRA_INTER.with(std::cell::Cell::get),
22705+ TX_SELECT_INTER.with(std::cell::Cell::get),
22706+ reduced_tx_set,
22707+ )?;
22708+ if i == 3 {
22709+ intra_chroma = true;
22710+ }
22711+ continue;
22712+ }
22657 // Same print point as the oracle's `EC_MODE` (entry of22713 // Same print point as the oracle's `EC_MODE` (entry of
22658 // `read_inter_block_mode_info`, i.e. after skip / is_inter), so the22714 // `read_inter_block_mode_info`, i.e. after skip / is_inter), so the
22659 // two range ladders line up element for element.22715 // two range ladders line up element for element.
@@ -22873,11 +22929,14 @@ fn decode_inter_sub8_split4(
22873 None,22929 None,
22874 None,22930 None,
22875 )?;22931 )?;
22876- if i == 0 {22932+ if i == 0 || piece[0].is_none() {
22877 // `av1_get_tx_type`: an inter block's chroma inherits the22933 // `av1_get_tx_type`: an inter block's chroma inherits the
22878 // tx_type of the CO-LOCATED luma position, which for the22934 // tx_type of the CO-LOCATED luma position, which for the
22879 // group's one chroma unit is luma (0, 0) -- the FIRST22935 // group's one chroma unit is luma (0, 0) -- the FIRST
22880- // sub-block, not the last.22936+ // sub-block, not the last. lane-sub8intra: an INTRA first
22937+ // sub-block writes no inter tx_type there at all, so the
22938+ // later inter sub-blocks' own is what `xd->tx_type_map`
22939+ // holds.
22881 first_tx_type = tx_type;22940 first_tx_type = tx_type;
22882 }22941 }
22883 neighbours.record_mi_luma_rect(lmi, B4, B4, &luma_grid);22942 neighbours.record_mi_luma_rect(lmi, B4, B4, &luma_grid);
@@ -22894,20 +22953,43 @@ fn decode_inter_sub8_split4(
22894 neighbours.fill_lf_grid_rect(lmi, 1, 1, B4 as u8, B4 as u8, ref_frame.max(LAST_FRAME));22953 neighbours.fill_lf_grid_rect(lmi, 1, 1, B4 as u8, B4 as u8, ref_frame.max(LAST_FRAME));
22895 last_skip = skip;22954 last_skip = skip;
22896 }22955 }
22956+ // lane-sub8intra: when the chroma-reference sub-block was INTRA it coded
22957+ // and reconstructed the group's one chroma unit itself.
22958+ if !intra_chroma {
22897 // Chroma, once for the whole group, on the last sub-block's own `skip`22959 // Chroma, once for the whole group, on the last sub-block's own `skip`
22898 // flag -- prediction from all four sub-blocks (2x2 pieces), residual as22960 // flag -- prediction from all four sub-blocks (2x2 pieces), residual as
22899 // one TX_4X4 unit per plane.22961 // one TX_4X4 unit per plane.
22900 let mut pred_u = vec![0u16; B4 * B4];22962 let mut pred_u = vec![0u16; B4 * B4];
22901 let mut pred_v = vec![0u16; B4 * B4];22963 let mut pred_v = vec![0u16; B4 * B4];
22964+ // `is_sub8x8_inter` (reconinter_template.inc:54) is false as soon as ANY
22965+ // mi of the group is intra: the group's 4x4 chroma is then predicted WHOLE
22966+ // from the chroma-reference (last) sub-block's own mv, not in 2x2 pieces.
22967+ let mixed = piece.iter().any(Option::is_none);
22968+ if mixed {
22969+ SUB8_INTRA_RECT_HITS.with(|h| {
22970+ let mut st = h.get();
22971+ st[3] += 1;
22972+ h.set(st);
22973+ });
22974+ }
22902 for i in 0..4usize {22975 for i in 0..4usize {
22903 let (dr, dc) = (i / 2, i % 2);22976 let (dr, dc) = (i / 2, i % 2);
22977+ if mixed && i != 3 {
22978+ continue;
22979+ }
22904 let Some((ref_frame, mv, h_filter, v_filter)) = piece[i] else {22980 let Some((ref_frame, mv, h_filter, v_filter)) = piece[i] else {
22905 continue;22981 continue;
22906 };22982 };
22907 let (_, sref_u, sref_v) = ref_planes(ref_frame, ref_y, ref_u, ref_v, other_refs)?;22983 let (_, sref_u, sref_v) = ref_planes(ref_frame, ref_y, ref_u, ref_v, other_refs)?;
22908- let (ox, oy) = (cpx + dc * 2, cpy + dr * 2);22984+ let (ox, oy) = if mixed {
22985+ (cpx, cpy)
22986+ } else {
22987+ (cpx + dc * 2, cpy + dr * 2)
22988+ };
22989+ let (pw, ph) = if mixed { (B4, B4) } else { (2, 2) };
22990+ let (row0, col0) = if mixed { (0, 0) } else { (dr * 2, dc * 2) };
22909 for (plane, dst) in [(sref_u, &mut pred_u), (sref_v, &mut pred_v)] {22991 for (plane, dst) in [(sref_u, &mut pred_u), (sref_v, &mut pred_v)] {
22910- let mut buf = vec![0u16; 4];22992+ let mut buf = vec![0u16; pw * ph];
22911 mc::predict_with_filters(22993 mc::predict_with_filters(
22912 &plane.data,22994 &plane.data,
22913 plane.width,22995 plane.width,
@@ -22915,15 +22997,15 @@ fn decode_inter_sub8_split4(
22915 plane.true_height,22997 plane.true_height,
22916 mv_to_q4(ox, mv.1, false),22998 mv_to_q4(ox, mv.1, false),
22917 mv_to_q4(oy, mv.0, false),22999 mv_to_q4(oy, mv.0, false),
22918- 2,23000+ pw,
22919- 2,23001+ ph,
22920 h_filter,23002 h_filter,
22921 v_filter,23003 v_filter,
22922 &mut buf,23004 &mut buf,
22923 );23005 );
22924- for row in 0..2 {23006+ for row in 0..ph {
22925- for col in 0..2 {23007+ for col in 0..pw {
22926- dst[(dr * 2 + row) * B4 + dc * 2 + col] = buf[row * 2 + col];23008+ dst[(row0 + row) * B4 + col0 + col] = buf[row * pw + col];
22927 }23009 }
22928 }23010 }
22929 }23011 }
@@ -22947,6 +23029,22 @@ fn decode_inter_sub8_split4(
22947 (ug, vg)23029 (ug, vg)
22948 };23030 };
22949 neighbours.record_uv_mode_mi(gr, gc, 2, 2, DC_PRED);23031 neighbours.record_uv_mode_mi(gr, gc, 2, 2, DC_PRED);
23032+ let round_up_even = |n: usize| n.div_ceil(2) * 2;
23033+ let bound_h = round_up_even(neighbours.mi_rows);
23034+ let bound_w = round_up_even(neighbours.mi_cols);
23035+ let u_state = neighbour_state(&u_grid);
23036+ let v_state = neighbour_state(&v_grid);
23037+ for cell in 0..2usize {
23038+ if cell < 2usize.min(bound_h.saturating_sub(gr)) {
23039+ neighbours.left[gr + cell][1] = u_state;
23040+ neighbours.left[gr + cell][2] = v_state;
23041+ }
23042+ if cell < 2usize.min(bound_w.saturating_sub(gc)) {
23043+ neighbours.above[gc + cell][1] = u_state;
23044+ neighbours.above[gc + cell][2] = v_state;
23045+ }
23046+ }
23047+ }
22950 // Same two neighbour tails [`decode_leaf_split4`] runs: the partition23048 // Same two neighbour tails [`decode_leaf_split4`] runs: the partition
22951 // context of a `BLOCK_4X4` subsize (`partition_context_lookup` bit 0 = 1,23049 // context of a `BLOCK_4X4` subsize (`partition_context_lookup` bit 0 = 1,
22952 // reached by `side_mi = 4` here) and the group's chroma coefficient state.23050 // reached by `side_mi = 4` here) and the group's chroma coefficient state.
@@ -22954,6 +23052,389 @@ fn decode_inter_sub8_split4(
22954 neighbours.left_side_mi[gr + cell] = 4;23052 neighbours.left_side_mi[gr + cell] = 4;
22955 neighbours.above_side_mi[gc + cell] = 4;23053 neighbours.above_side_mi[gc + cell] = 4;
22956 }23054 }
23055+ Ok(())
23056+}
23057+
23058+/// One INTRA 8x4/4x8 leaf inside an INTER frame's sub-8x8 HORZ/VERT partition
23059+/// (lane-sub8intra) -- the shape [`decode_inter_sub8_rect2`] refused by name.
23060+/// Mode syntax is `read_intra_block_mode_info`'s (decodemv.c:1065), not the key
23061+/// frame's above/left pair: `y_mode[size_group_lookup[BLOCK_8X4] == 0]`, NO
23062+/// angle delta (`av1_use_angle_delta` needs `bsize >= BLOCK_8X8`), `uv_mode` +
23063+/// CfL alphas only on the chroma-reference sub-block (`is_chroma_reference`:
23064+/// the SECOND one under 4:2:0), then `filter_intra` off BLOCK_8X4/BLOCK_4X8's
23065+/// own class row (`av1_filter_intra_allowed_bsize` is `wide <= 32 && high <=
23066+/// 32`, so this shape is allowed). Everything below the mode read -- the tx
23067+/// depth symbol, the whole-leaf `TX_8X4`/`TX_4X8` or split `TX_4X4` walk, the
23068+/// 4x4 chroma unit at the group's origin -- is [`decode_leaf_rect8`]'s body for
23069+/// the same shape; the INTER-frame differences are the tx-depth context
23070+/// (`above_txfm`/`left_txfm`, not the key frame's deblock-grid approximation),
23071+/// `set_txfm_ctxs` publication, and the inter-side bands + mi map the caller's
23072+/// inter leaves also write (`is_inter = 0`, ref `INTRA_FRAME`, no interp
23073+/// filter).
23074+#[allow(clippy::too_many_arguments)]
23075+fn decode_intra_sub8_leaf(
23076+ dec: &mut SymbolDecoder,
23077+ cdfs: &mut Cdfs,
23078+ neighbours: &mut Neighbours,
23079+ grid: &mut MiGrid,
23080+ group_mi: (usize, usize),
23081+ lmi: (usize, usize),
23082+ // `(bw, bh)`: 8x4 / 4x8 under HORZ/VERT, 4x4 under SPLIT.
23083+ (bw, bh): (usize, usize),
23084+ has_chroma: bool,
23085+ skip: bool,
23086+ scan4: &[u16],
23087+ y: &mut PlaneBuf,
23088+ u: &mut PlaneBuf,
23089+ v: &mut PlaneBuf,
23090+ base_q_idx: u8,
23091+ enable_filter_intra: bool,
23092+ tx_select: bool,
23093+ reduced_tx_set: bool,
23094+) -> Result<usize> {
23095+ let vert = bw < bh;
23096+ let (w_mi, h_mi) = (bw / MI, bh / MI);
23097+ let (gr, gc) = group_mi;
23098+ let (r, c) = (gr / (SUB / MI), gc / (SUB / MI));
23099+ let (above_mode, left_mode) = neighbours.modes_above_left(r, c);
23100+ let leaf_above = neighbours
23101+ .mode_above_mi(lmi.0, lmi.1)
23102+ .unwrap_or(above_mode);
23103+ let leaf_left = neighbours.mode_left_mi(lmi.0, lmi.1).unwrap_or(left_mode);
23104+ let step = std::env::var_os("EC_TRACE_MODE_STEP").is_some();
23105+ // `size_group_lookup[BLOCK_8X4] == size_group_lookup[BLOCK_4X8] == 0`
23106+ // (libaom common_data.h:61).
23107+ let mode = dec.symbol(&mut cdfs.y_mode[0]);
23108+ if step {
23109+ eprintln!(
23110+ "EC_ISTEP mi_row={} mi_col={} name=mode val={mode} rng={}",
23111+ lmi.0,
23112+ lmi.1,
23113+ dec.debug_state().0
23114+ );
23115+ }
23116+ // No angle delta below 8x8 (`av1_use_angle_delta`), for luma or chroma.
23117+ let angle_delta_y = 0;
23118+ let (uv_mode, alpha) = if has_chroma {
23119+ // `is_cfl_allowed` is `wide <= 32 && high <= 32` -- true for this
23120+ // shape, so the 14-symbol CFL alphabet is the right one.
23121+ let uv_mode = dec.symbol(&mut cdfs.uv_mode_cfl[mode]);
23122+ if (9..=12).contains(&uv_mode) {
23123+ SMOOTH_UV_HITS.with(|c| c.set(c.get() + 1));
23124+ }
23125+ let alpha = if uv_mode == UV_CFL_PRED {
23126+ Some(read_cfl_alphas(dec, cdfs))
23127+ } else {
23128+ None
23129+ };
23130+ if (V_PRED..=D67_PRED).contains(&uv_mode) {
23131+ DIRECTIONAL_UV_HITS.with(|c| c.set(c.get() + 1));
23132+ }
23133+ (uv_mode, alpha)
23134+ } else {
23135+ (DC_PRED, None)
23136+ };
23137+ let mut filter_intra = None;
23138+ if mode == DC_PRED && enable_filter_intra {
23139+ let fi_class = if bw == bh {
23140+ filter_intra_size_class(bw).expect("BLOCK_4X4 has its own filter_intra row")
23141+ } else {
23142+ filter_intra_size_class_rect(bw, bh)
23143+ .expect("BLOCK_4X8/BLOCK_8X4 are inside av1_filter_intra_allowed_bsize")
23144+ };
23145+ if dec.symbol(&mut cdfs.filter_intra[fi_class]) != 0 {
23146+ FILTER_INTRA_HITS.with(|c| c.set(c.get() + 1));
23147+ FILTER_INTRA_RECT_HITS.with(|c| c.set(c.get() + 1));
23148+ FILTER_INTRA_RECT_SUB8_HITS.with(|c| c.set(c.get() + 1));
23149+ filter_intra = Some(dec.symbol(&mut cdfs.filter_intra_mode));
23150+ }
23151+ }
23152+ // `read_block_tx_size`' non-var-tx arm: an INTRA block of an inter frame
23153+ // reads `read_tx_size(allow_select = 1)` -- `bsize_to_tx_size_cat
23154+ // (BLOCK_4X8) == 0` (blockd.h:1344, depth table entry 1), the same
23155+ // 2-symbol category [`decode_leaf_rect8`] reads -- with the var-tx
23156+ // context bands, which on an inter frame are live.
23157+ // `block_signals_txsize(BLOCK_4X4)` is false (blockd.h:1027): the 4x4 leaf
23158+ // codes no depth symbol at all, its transform is its own size.
23159+ let depth = if tx_select && bw != bh {
23160+ let ctx = tx_size_context_txfm_rect(neighbours, lmi, bw, bh);
23161+ let d = dec.symbol(&mut cdfs.tx_size_cat0[ctx]);
23162+ if step {
23163+ eprintln!(
23164+ "EC_ISTEP mi_row={} mi_col={} name=tx_depth val={d} ctx={ctx} cat=0 rng={}",
23165+ lmi.0,
23166+ lmi.1,
23167+ dec.debug_state().0
23168+ );
23169+ }
23170+ d
23171+ } else {
23172+ 0
23173+ };
23174+ if depth != 0 {
23175+ TX_DEPTH_HITS.with(|c| c.set(c.get() + 1));
23176+ RECT8_SPLIT_TX_HITS.with(|c| c.set(c.get() + 1));
23177+ }
23178+ let split = depth != 0;
23179+ let (px, py) = (lmi.1 * MI, lmi.0 * MI);
23180+ let reach = if bw == bh {
23181+ Reach::of(bw, px, py, y.width, y.height)
23182+ } else {
23183+ Reach::of_rect(bw, bh, px, py, y.width, y.height)
23184+ };
23185+ let smooth_neighbor = is_smooth_mode(leaf_above) || is_smooth_mode(leaf_left);
23186+ if smooth_neighbor {
23187+ SMOOTH_LUMA_HITS.with(|c| c.set(c.get() + 1));
23188+ }
23189+ neighbours.record_mode_mi(lmi.0, lmi.1, w_mi, h_mi, mode);
23190+ let scan: &[u16] = if vert { &SCAN_4X8 } else { &SCAN_8X4 };
23191+ if split {
23192+ // `sub_tx_size_map[TX_4X8] == TX_4X4`: two 4x4 units along the long
23193+ // axis, each predicted off the previous one's reconstruction.
23194+ for tu in 0..2usize {
23195+ let tu_mi = if vert {
23196+ (lmi.0 + tu, lmi.1)
23197+ } else {
23198+ (lmi.0, lmi.1 + tu)
23199+ };
23200+ let (tu_px, tu_py) = (tu_mi.1 * MI, tu_mi.0 * MI);
23201+ let tu_reach = tu_reach(
23202+ bw,
23203+ bh,
23204+ tu_px - px,
23205+ tu_py - py,
23206+ 4,
23207+ reach,
23208+ px,
23209+ py,
23210+ y.width,
23211+ y.height,
23212+ );
23213+ if skip {
23214+ let zeros = vec![0i32; 16];
23215+ y.reconstruct(
23216+ tu_px, tu_py, 4, mode, angle_delta_y, tu_reach, &zeros, None, filter_intra,
23217+ smooth_neighbor,
23218+ );
23219+ neighbours.record_mi_luma(tu_mi, 4, &zeros);
23220+ continue;
23221+ }
23222+ let tu_around = neighbours.around_mi(tu_mi, 4)[0];
23223+ let tu_skip_ctx = neighbours.luma_skip_ctx(tu_mi, 1);
23224+ let tu_grid = read_plane(
23225+ dec,
23226+ cdfs,
23227+ if reduced_tx_set {
23228+ TxbSet::Luma4
23229+ } else {
23230+ TxbSet::Luma4Set1
23231+ },
23232+ scan4,
23233+ 0,
23234+ tu_around,
23235+ mode,
23236+ mode,
23237+ angle_delta_y,
23238+ tu_reach,
23239+ y,
23240+ tu_px,
23241+ tu_py,
23242+ 4,
23243+ TX4,
23244+ base_q_idx,
23245+ None,
23246+ filter_intra,
23247+ Some(tu_skip_ctx),
23248+ smooth_neighbor,
23249+ )?;
23250+ neighbours.record_mi_luma(tu_mi, 4, &tu_grid);
23251+ }
23252+ } else if bw == bh {
23253+ // A `BLOCK_4X4` leaf's luma TU *is* the whole block, so `get_txb_ctx`
23254+ // fixes `txb_skip_ctx` at 0 (`luma_skip_ctx: None`) -- the same square
23255+ // reader [`decode_leaf_split4`] uses.
23256+ if skip {
23257+ y.reconstruct(
23258+ px, py, 4, mode, angle_delta_y, reach, &vec![0i32; 16], None, filter_intra,
23259+ smooth_neighbor,
23260+ );
23261+ neighbours.record_mi_luma(lmi, 4, &vec![0i32; 16]);
23262+ } else {
23263+ let tu_around = neighbours.around_mi(lmi, 4)[0];
23264+ let tu_grid = read_plane(
23265+ dec,
23266+ cdfs,
23267+ if reduced_tx_set {
23268+ TxbSet::Luma4
23269+ } else {
23270+ TxbSet::Luma4Set1
23271+ },
23272+ scan4,
23273+ 0,
23274+ tu_around,
23275+ mode,
23276+ mode,
23277+ angle_delta_y,
23278+ reach,
23279+ y,
23280+ px,
23281+ py,
23282+ 4,
23283+ TX4,
23284+ base_q_idx,
23285+ None,
23286+ filter_intra,
23287+ None,
23288+ smooth_neighbor,
23289+ )?;
23290+ neighbours.record_mi_luma(lmi, 4, &tu_grid);
23291+ }
23292+ } else {
23293+ let grid_levels = if skip {
23294+ let zeros = vec![0i32; bw * bh];
23295+ y.reconstruct_rect(
23296+ px, py, bw, bh, mode, angle_delta_y, reach, &zeros, None, filter_intra,
23297+ smooth_neighbor,
23298+ );
23299+ zeros
23300+ } else {
23301+ // The leaf's luma TU *is* the leaf, so `get_txb_ctx` fixes
23302+ // `txb_skip_ctx` at 0.
23303+ let around = neighbours.around_mi_rect(lmi, bw, bh)[0];
23304+ let set = if reduced_tx_set {
23305+ TxbSet::LumaRect4x8
23306+ } else {
23307+ TxbSet::LumaRect4x8Set1
23308+ };
23309+ let mut coding = cdfs.txb(set, fi_tx_row(mode, filter_intra));
23310+ let (levels, tx_type) = read_coeffs_rect(
23311+ dec,
23312+ &mut coding,
23313+ scan,
23314+ bw,
23315+ bh,
23316+ 0,
23317+ dc_sign_ctx(around.2),
23318+ TxType::DctDct,
23319+ )?;
23320+ let residual = dequant_and_inverse_typed_wh(
23321+ &levels,
23322+ bw,
23323+ bh,
23324+ crate::decode::bit_depth(),
23325+ CURRENT_Q_IDX.with(|q| q.get()),
23326+ plane_q_delta(0).0,
23327+ plane_q_delta(0).1,
23328+ tx_type,
23329+ );
23330+ y.reconstruct_rect(
23331+ px, py, bw, bh, mode, angle_delta_y, reach, &residual, None, filter_intra,
23332+ smooth_neighbor,
23333+ );
23334+ levels
23335+ };
23336+ let state = neighbour_state(&grid_levels);
23337+ for cell in 0..h_mi {
23338+ if lmi.0 + cell < neighbours.mi_rows {
23339+ neighbours.left[lmi.0 + cell][0] = state;
23340+ }
23341+ }
23342+ for cell in 0..w_mi {
23343+ if lmi.1 + cell < neighbours.mi_cols {
23344+ neighbours.above[lmi.1 + cell][0] = state;
23345+ }
23346+ }
23347+ }
23348+ let (tx_w, tx_h) = if split { (4, 4) } else { (bw, bh) };
23349+ neighbours.fill_skip_grid_rect(lmi, w_mi, h_mi, skip);
23350+ neighbours.fill_lf_grid_rect(lmi, w_mi, h_mi, tx_w as u8, tx_h as u8, 0);
23351+ // `set_txfm_ctxs(tx_size, n4_w, n4_h, skip && is_inter == 0, xd)`: an
23352+ // intra block of an inter frame publishes its TRANSFORM dims, never its
23353+ // block dims (blockd.h). Missing this left the next block reading the
23354+ // previous block's band (the lane-intra16x4 finding for the 16x4 strip).
23355+ for i in 0..w_mi {
23356+ if let Some(cell) = neighbours.above_txfm.get_mut(lmi.1 + i) {
23357+ *cell = tx_w as u8;
23358+ }
23359+ }
23360+ for i in 0..h_mi {
23361+ if let Some(cell) = neighbours.left_txfm.get_mut(lmi.0 + i) {
23362+ *cell = tx_h as u8;
23363+ }
23364+ }
23365+ neighbours.above_mode[c] = mode;
23366+ neighbours.left_mode[r] = mode;
23367+ // The inter-side bands and the mi map, exactly as the square
23368+ // intra-in-inter block writes them: `is_inter = 0`, `INTRA_FRAME` ref, no
23369+ // interpolation filter, no skip mode.
23370+ neighbours.record_inter_rect_mi(lmi, w_mi, h_mi, skip, false, 0, [3, 3], false);
23371+ for dr in 0..h_mi {
23372+ for dc in 0..w_mi {
23373+ grid.set(
23374+ lmi.0 + dr,
23375+ lmi.1 + dc,
23376+ MiInfo {
23377+ is_inter: false,
23378+ ref_frame: -1,
23379+ ref_frame1: None,
23380+ mv1: None,
23381+ mv: (0, 0),
23382+ is_new_mv: false,
23383+ size: w_mi,
23384+ size_h: h_mi,
23385+ is_global_mv0: false,
23386+ is_global_mv1: false,
23387+ },
23388+ );
23389+ }
23390+ }
23391+ SUB8_INTRA_RECT_HITS.with(|h| {
23392+ let mut s = h.get();
23393+ s[usize::from(vert)] += 1;
23394+ s[2] += usize::from(has_chroma);
23395+ h.set(s);
23396+ });
23397+ if !has_chroma {
23398+ return Ok(mode);
23399+ }
23400+ // The group's single 4x4 chroma unit, intra-predicted from THIS
23401+ // (chroma-reference) sub-block's own `uv_mode` -- `is_sub8x8_inter`
23402+ // (reconinter_template.inc:54) returns false as soon as any mi of the
23403+ // group is intra, and the decoder reconstructs chroma with the
23404+ // chroma-reference block's own type. Same body as [`decode_leaf_rect8`]'s
23405+ // post-loop chroma.
23406+ let (gpx, gpy) = (gc * MI, gr * MI);
23407+ let (cpx, cpy) = (gpx / 2, gpy / 2);
23408+ let group_reach = Reach::of(8, gpx, gpy, y.width, y.height);
23409+ let smooth_neighbor_uv = neighbours.smooth_uv_neighbour(gr, gc, r, c);
23410+ let uv_predict_mode = if uv_mode == UV_CFL_PRED { DC_PRED } else { uv_mode };
23411+ let angle_delta_uv = 0;
23412+ neighbours.above_uv_mode[c] = uv_predict_mode;
23413+ neighbours.left_uv_mode[r] = uv_predict_mode;
23414+ neighbours.record_uv_mode_mi(gr, gc, 2, 2, uv_predict_mode);
23415+ let ac = alpha.map(|_| cfl_ac_q3(y, gpx, gpy, 8));
23416+ let (u_grid, v_grid): (Vec<i32>, Vec<i32>) = if skip {
23417+ if alpha.is_some() {
23418+ CHROMA_SKIP_CFL_HITS.with(|h| h.set(h.get() + 1));
23419+ SKIP_CFL_HITS.with(|c| c.set(c.get() + 1));
23420+ }
23421+ u.reconstruct(cpx, cpy, 4, uv_predict_mode, angle_delta_uv, group_reach, &vec![0i32; 16], alpha.zip(ac.as_deref()).map(|((au, _), ac)| (au, ac)), None, smooth_neighbor_uv);
23422+ v.reconstruct(cpx, cpy, 4, uv_predict_mode, angle_delta_uv, group_reach, &vec![0i32; 16], alpha.zip(ac.as_deref()).map(|((_, av), ac)| (av, ac)), None, smooth_neighbor_uv);
23423+ (vec![0i32; 16], vec![0i32; 16])
23424+ } else {
23425+ let chroma_around = neighbours.around_mi(group_mi, 8);
23426+ let ug = read_plane(
23427+ dec, cdfs, TxbSet::Chroma4, scan4, 1, chroma_around[1], uv_mode, uv_predict_mode,
23428+ angle_delta_uv, group_reach, u, cpx, cpy, 4, TX4, base_q_idx,
23429+ alpha.zip(ac.as_deref()).map(|((au, _), ac)| (au, ac)), None, None, smooth_neighbor_uv,
23430+ )?;
23431+ let vg = read_plane(
23432+ dec, cdfs, TxbSet::Chroma4, scan4, 2, chroma_around[2], uv_mode, uv_predict_mode,
23433+ angle_delta_uv, group_reach, v, cpx, cpy, 4, TX4, base_q_idx,
23434+ alpha.zip(ac.as_deref()).map(|((_, av), ac)| (av, ac)), None, None, smooth_neighbor_uv,
23435+ )?;
23436+ (ug, vg)
23437+ };
22957 let round_up_even = |n: usize| n.div_ceil(2) * 2;23438 let round_up_even = |n: usize| n.div_ceil(2) * 2;
22958 let bound_h = round_up_even(neighbours.mi_rows);23439 let bound_h = round_up_even(neighbours.mi_rows);
22959 let bound_w = round_up_even(neighbours.mi_cols);23440 let bound_w = round_up_even(neighbours.mi_cols);
@@ -22969,7 +23450,7 @@ fn decode_inter_sub8_split4(
22969 neighbours.above[gc + cell][2] = v_state;23450 neighbours.above[gc + cell][2] = v_state;
22970 }23451 }
22971 }23452 }
22972- Ok(())23453+ Ok(mode)
22973 }23454 }
22974 23455
22975 /// Decodes a `PARTITION_HORZ`/`PARTITION_VERT` of one 8x8 INTER block into two23456 /// Decodes a `PARTITION_HORZ`/`PARTITION_VERT` of one 8x8 INTER block into two
@@ -23059,6 +23540,9 @@ fn decode_inter_sub8_rect2(
23059 [None; 2];23540 [None; 2];
23060 let mut first_tx_type = TxType::DctDct;23541 let mut first_tx_type = TxType::DctDct;
23061 let mut last_skip = true;23542 let mut last_skip = true;
23543+ // Set when the chroma-reference sub-block is INTRA: it coded the group's
23544+ // one chroma unit itself.
23545+ let mut intra_chroma = false;
23062 for i in 0..2usize {23546 for i in 0..2usize {
23063 let lmi = if vert { (gr, gc + i) } else { (gr + i, gc) };23547 let lmi = if vert { (gr, gc + i) } else { (gr + i, gc) };
23064 if lmi.0 >= mi_rows as usize || lmi.1 >= mi_cols as usize {23548 if lmi.0 >= mi_rows as usize || lmi.1 >= mi_cols as usize {
@@ -23086,11 +23570,54 @@ fn decode_inter_sub8_rect2(
23086 );23570 );
23087 let is_inter = dec.symbol(&mut cdfs.intra_inter[ii_ctx]) == 1;23571 let is_inter = dec.symbol(&mut cdfs.intra_inter[ii_ctx]) == 1;
23088 if !is_inter {23572 if !is_inter {
23573+ if std::env::var_os("EC_SUB8INTRA").is_some() {
23574+ eprintln!(
23575+ "EC_SUB8INTRA shape={}x{} sub={i} has_chroma={} skip={skip} mi={rmi},{cmi} tx_select={}",
23576+ bw,
23577+ bh,
23578+ i == 1,
23579+ TX_SELECT_INTER.with(std::cell::Cell::get),
23580+ );
23581+ }
23582+ // lane-sub8intra: the leaf decodes ([`decode_intra_sub8_leaf`])
23583+ // only under `EC_SUB8INTRA_DECODE` -- the r1 gate is RED (a
23584+ // 128x128 8-bit witness desyncs a few blocks later), so the
23585+ // refusal stays the default behaviour (class
23586+ // `refusal-lifted-without-a-gate`).
23587+ if std::env::var_os("EC_SUB8INTRA_DECODE").is_none() {
23089 return Err(unsupported(23588 return Err(unsupported(
23090 "an intra 8x4/4x8 block inside an inter frame's sub-8x8 HORZ/VERT partition \23589 "an intra 8x4/4x8 block inside an inter frame's sub-8x8 HORZ/VERT partition \
23091 (this decoder codes only inter sub-blocks there)",23590 (this decoder codes only inter sub-blocks there)",
23092 ));23591 ));
23093 }23592 }
23593+ // Its chroma rule is `is_sub8x8_inter`'s: when the
23594+ // chroma-reference (second) sub-block is the intra one, the
23595+ // group's 4x4 chroma is coded and predicted INTRA there and the
23596+ // inter chroma tail below is skipped entirely.
23597+ decode_intra_sub8_leaf(
23598+ dec,
23599+ cdfs,
23600+ neighbours,
23601+ grid,
23602+ group_mi,
23603+ lmi,
23604+ (bw, bh),
23605+ i == 1,
23606+ skip,
23607+ scan4,
23608+ y,
23609+ u,
23610+ v,
23611+ base_q_idx,
23612+ ENABLE_FILTER_INTRA_INTER.with(std::cell::Cell::get),
23613+ TX_SELECT_INTER.with(std::cell::Cell::get),
23614+ reduced_tx_set,
23615+ )?;
23616+ if i == 1 {
23617+ intra_chroma = true;
23618+ }
23619+ continue;
23620+ }
23094 if std::env::var_os("EC_TRACE_MODE").is_some() {23621 if std::env::var_os("EC_TRACE_MODE").is_some() {
23095 eprintln!(23622 eprintln!(
23096 "EC_MODE mi_row={rmi} mi_col={cmi} rng={}",23623 "EC_MODE mi_row={rmi} mi_col={cmi} rng={}",
@@ -23349,10 +23876,13 @@ fn decode_inter_sub8_rect2(
23349 None,23876 None,
23350 )?23877 )?
23351 };23878 };
23352- if idx == 0 {23879+ if idx == 0 && (i == 0 || piece[0].is_none()) {
23353 // `av1_get_tx_type`: the group's one chroma unit scales23880 // `av1_get_tx_type`: the group's one chroma unit scales
23354 // back to luma (0, 0), i.e. the FIRST sub-block's first23881 // back to luma (0, 0), i.e. the FIRST sub-block's first
23355- // transform unit.23882+ // transform unit -- unless that sub-block is INTRA
23883+ // (lane-sub8intra), in which case it wrote no inter
23884+ // tx_type at all and `xd->tx_type_map[0]` of the
23885+ // chroma-reference block is this one's.
23356 first_tx_type = tu_tx_type;23886 first_tx_type = tu_tx_type;
23357 }23887 }
23358 neighbours.record_mi_luma_rect(tu_mi, tw, th, &tu_grid);23888 neighbours.record_mi_luma_rect(tu_mi, tw, th, &tu_grid);
@@ -23372,23 +23902,52 @@ fn decode_inter_sub8_rect2(
23372 neighbours.fill_skip_grid_rect(lmi, w_mi, h_mi, skip);23902 neighbours.fill_skip_grid_rect(lmi, w_mi, h_mi, skip);
23373 last_skip = skip;23903 last_skip = skip;
23374 }23904 }
23905+ // lane-sub8intra: when the chroma-reference sub-block was INTRA it coded
23906+ // and reconstructed the group's one chroma unit itself.
23907+ if !intra_chroma {
23375 // The group's single 4x4 chroma unit per plane, on the chroma-reference23908 // The group's single 4x4 chroma unit per plane, on the chroma-reference
23376 // (second) sub-block's own skip flag.23909 // (second) sub-block's own skip flag.
23377 const B4: usize = 4;23910 const B4: usize = 4;
23378 let mut pred_u = vec![0u16; B4 * B4];23911 let mut pred_u = vec![0u16; B4 * B4];
23379 let mut pred_v = vec![0u16; B4 * B4];23912 let mut pred_v = vec![0u16; B4 * B4];
23380- let (piece_w, piece_h) = if vert { (2usize, 4usize) } else { (4usize, 2usize) };23913+ // `is_sub8x8_inter` (reconinter_template.inc:54) is false as soon as ANY
23914+ // mi of the group is intra, so a group whose chroma reference is inter but
23915+ // whose sibling is INTRA does NOT get the two-piece sub8x8 prediction: the
23916+ // ordinary 8x8-and-bigger path predicts the WHOLE 4x4 chroma unit from the
23917+ // chroma-reference block's own mv, at the group's chroma origin
23918+ // (`row_start`/`col_start` shift `pre_x`/`pre_y` there either way).
23919+ let mixed = piece[0].is_none();
23920+ if mixed {
23921+ SUB8_INTRA_RECT_HITS.with(|h| {
23922+ let mut s = h.get();
23923+ s[3] += 1;
23924+ h.set(s);
23925+ });
23926+ }
23927+ let (piece_w, piece_h) = match (mixed, vert) {
23928+ (true, _) => (B4, B4),
23929+ (false, true) => (2usize, 4usize),
23930+ (false, false) => (4usize, 2usize),
23931+ };
23381 for i in 0..2usize {23932 for i in 0..2usize {
23382 let Some((ref_frame, mv, h_filter, v_filter)) = piece[i] else {23933 let Some((ref_frame, mv, h_filter, v_filter)) = piece[i] else {
23383 continue;23934 continue;
23384 };23935 };
23385 let (_, sref_u, sref_v) = ref_planes(ref_frame, ref_y, ref_u, ref_v, other_refs)?;23936 let (_, sref_u, sref_v) = ref_planes(ref_frame, ref_y, ref_u, ref_v, other_refs)?;
23386- let (ox, oy) = if vert {23937+ let (ox, oy) = if mixed {
23938+ (cpx, cpy)
23939+ } else if vert {
23387 (cpx + i * piece_w, cpy)23940 (cpx + i * piece_w, cpy)
23388 } else {23941 } else {
23389 (cpx, cpy + i * piece_h)23942 (cpx, cpy + i * piece_h)
23390 };23943 };
23391- let (dc, dr) = if vert { (i * piece_w, 0) } else { (0, i * piece_h) };23944+ let (dc, dr) = if mixed {
23945+ (0, 0)
23946+ } else if vert {
23947+ (i * piece_w, 0)
23948+ } else {
23949+ (0, i * piece_h)
23950+ };
23392 for (plane, dst) in [(sref_u, &mut pred_u), (sref_v, &mut pred_v)] {23951 for (plane, dst) in [(sref_u, &mut pred_u), (sref_v, &mut pred_v)] {
23393 let mut buf = vec![0u16; piece_w * piece_h];23952 let mut buf = vec![0u16; piece_w * piece_h];
23394 mc::predict_with_filters(23953 mc::predict_with_filters(
@@ -23430,13 +23989,6 @@ fn decode_inter_sub8_rect2(
23430 (ug, vg)23989 (ug, vg)
23431 };23990 };
23432 neighbours.record_uv_mode_mi(gr, gc, 2, 2, DC_PRED);23991 neighbours.record_uv_mode_mi(gr, gc, 2, 2, DC_PRED);
23433- // `update_partition_context` writes `partition_context_lookup[subsize]`
23434- // over the whole 8x8 span -- BLOCK_4X8's width above and height left, the
23435- // same values [`decode_leaf_rect8`] writes for the intra shape.
23436- for cell in 0..2usize {
23437- neighbours.above_side_mi[gc + cell] = bw;
23438- neighbours.left_side_mi[gr + cell] = bh;
23439- }
23440 let round_up_even = |n: usize| n.div_ceil(2) * 2;23992 let round_up_even = |n: usize| n.div_ceil(2) * 2;
23441 let bound_h = round_up_even(neighbours.mi_rows);23993 let bound_h = round_up_even(neighbours.mi_rows);
23442 let bound_w = round_up_even(neighbours.mi_cols);23994 let bound_w = round_up_even(neighbours.mi_cols);
@@ -23452,6 +24004,14 @@ fn decode_inter_sub8_rect2(
23452 neighbours.above[gc + cell][2] = v_state;24004 neighbours.above[gc + cell][2] = v_state;
23453 }24005 }
23454 }24006 }
24007+ }
24008+ // `update_partition_context` writes `partition_context_lookup[subsize]`
24009+ // over the whole 8x8 span -- BLOCK_4X8's width above and height left, the
24010+ // same values [`decode_leaf_rect8`] writes for the intra shape.
24011+ for cell in 0..2usize {
24012+ neighbours.above_side_mi[gc + cell] = bw;
24013+ neighbours.left_side_mi[gr + cell] = bh;
24014+ }
23455 Ok(())24015 Ok(())
23456 }24016 }
23457 24017
crates/ec-av1/src/stream.rsmodified+6 -0
@@ -86,6 +86,12 @@ pub fn intra16x4_in_inter_hits() -> (usize, usize, usize) {
86 crate::decode::intra16x4_in_inter_hits()86 crate::decode::intra16x4_in_inter_hits()
87 }87 }
88 88
89+/// lane-sub8intra: INTRA 8x4/4x8 leaves inside an inter frame's sub-8x8
90+/// HORZ/VERT partition, `(8x4, 4x8, chroma-reference, mixed groups)`.
91+pub fn sub8_intra_rect_hits() -> (usize, usize, usize, usize) {
92+ crate::decode::sub8_intra_rect_hits()
93+}
94+
89 /// lane-r14 r3: RECTANGULAR var-tx leaf transform units, `[32x16, 16x32]` --95 /// lane-r14 r3: RECTANGULAR var-tx leaf transform units, `[32x16, 16x32]` --
90 /// the leaves `sub_tx_size_map` produces when a 1:4 strip with a 64-px axis96 /// the leaves `sub_tx_size_map` produces when a 1:4 strip with a 64-px axis
91 /// splits its transform (`[TX_64X16] == TX_32X16`, `[TX_16X64] == TX_16X32`).97 /// splits its transform (`[TX_64X16] == TX_32X16`, `[TX_16X64] == TX_16X32`).
lanes/sub8intra-r1.handoff.mdadded+108 -0
@@ -0,0 +1,108 @@
1+# lane-sub8intra r1 HANDOFF (tip = this commit)
2+
3+Env switch: **`EC_SUB8INTRA_DECODE=1`** enables the decode path; `EC_SUB8INTRA=1` prints the
4+measurement line at the refusal sites. WITHOUT the switch both refusals are unchanged
5+(verified: hg-0 and the 1920x792 @900 cut both still stop at
6+"an intra 8x4/4x8 block inside an inter frame's sub-8x8 HORZ/VERT partition").
7+No refusal lifted, `refusal_inventory.rs` / `gate_coverage.rs` untouched, no gate added.
8+
9+## Step 1 measurement (`EC_SUB8INTRA=1 EC_RECT64_SPLIT=1 EC_INTRA16X4_DECODE=1`, decode_probe)
10+
11+| probe | shape | sub-block | is chroma ref | skip | tx_select |
12+|---|---|---|---|---|---|
13+| 10-bit 3840x1608 cut 0 | 4x8 | 0 | false | 0 | 1 |
14+| 10-bit 3840x1608 cut 300 | 8x4 | 0 | false | 0 | 1 |
15+| 10-bit 1920x792 @900 | 4x8 | 0 | false | 0 | 1 |
16+| 10-bit 1920x792 @5400 | 4x8 | 0 | false | 0 | 1 |
17+| 10-bit 1920x792 @6300 | 4x8 | 0 | false | 0 | 1 |
18+| 10-bit 1920x792 @8100 | -- (stops earlier on the clipped-16x4 arm) |
19+
20+5/6 fire first on sub-block 0 (NOT the chroma reference), non-skip, `--enable-tx-size-search` on.
21+The 4x4 SPLIT refusal is never the first wall, but becomes the wall on 3/6 probes once the
22+HORZ/VERT arm decodes, so both arms are implemented.
23+
24+## What is implemented (crates/ec-av1/src/decode.rs)
25+
26+* `decode_intra_sub8_leaf(.., (bw,bh), has_chroma, skip, ..)` -- one INTRA 8x4/4x8 **or 4x4**
27+ leaf on the inter path. Reads `y_mode[0]` (`size_group_lookup[BLOCK_8X4]==0`), NO angle delta
28+ (`av1_use_angle_delta` needs >= 8x8), `uv_mode` off `uv_mode_cfl[mode]` + CfL alphas only on
29+ the chroma reference, `filter_intra` off the shape's own class row
30+ (`filter_intra_size_class_rect` / `_class(4)`), then the tx-depth symbol
31+ (`tx_size_cat0`, ctx from `tx_size_context_txfm_rect` -- the INTER frame's live
32+ `above_txfm`/`left_txfm`, not the key frame's deblock approximation; `BLOCK_4X4` reads none,
33+ `block_signals_txsize` is false). Luma = `decode_leaf_rect8`'s body (whole `TX_8X4`/`TX_4X8`
34+ via `read_coeffs_rect` + `LumaRect4x8[Set1]` + `SCAN_8X4`/`SCAN_4X8`, or two `TX_4X4` units at
35+ depth 1; square `read_plane` for 4x4). Chroma, when this leaf IS the chroma reference: the
36+ group's one 4x4 unit intra-predicted at the 8x8 group origin with `group_reach = Reach::of(8,..)`,
37+ CfL AC from the group's 8x8 luma -- `decode_leaf_rect8`'s post-loop chroma verbatim.
38+ Publishes: mode into `record_mode_mi` + the coarse `above_mode`/`left_mode`, skip grid,
39+ lf grid at tx dims, `set_txfm_ctxs` equivalent (`above_txfm = tx_w`, `left_txfm = tx_h`),
40+ `record_inter_rect_mi(.., is_inter=false, ref 0, filter [3,3])`, and `MiInfo { is_inter:false,
41+ ref_frame:-1 }` over every mi cell.
42+* `decode_inter_sub8_rect2` / `decode_inter_sub8_split4`: the `!is_inter` arm calls it (behind
43+ the env switch), sets `intra_chroma` when the leaf was the chroma reference, and the whole
44+ chroma tail (prediction, residual, `record_uv_mode_mi`, the u/v neighbour-state loop) is
45+ guarded by `if !intra_chroma`.
46+* MIXED groups (chroma reference INTER, a sibling INTRA): `is_sub8x8_inter`
47+ (reconinter_template.inc:54) returns false as soon as any mi of the group is intra, so the
48+ chroma is predicted WHOLE 4x4 from the chroma-reference block's own mv at the group's chroma
49+ origin instead of in 2x2/4x2 pieces -- implemented in both functions (`mixed` flag).
50+* tx_type rule for that chroma: `first_tx_type` now comes from the chroma-reference block's own
51+ first TU when sub-block 0 is intra (`xd->tx_type_map[0]` of the current mi). NOTE the
52+ pre-existing all-inter rule ("FIRST sub-block") is untouched but looks wrong against
53+ blockd.h:1288 -- `xd->tx_type_map` is rebased to the CURRENT (chroma-reference) mi, so the
54+ co-located luma (0,0) is the LAST sub-block's, not the first's. Flagged, not changed.
55+* Counter `sub8_intra_rect_hits() -> (8x4, 4x8, chroma_ref, mixed)`, printed by decode_probe
56+ (`sub8_intra_rect: ...`), exported through `stream.rs`.
57+* `EC_TRACE_MODE_STEP` prints `name=mode` and `name=tx_depth val/ctx` for the leaf, in the
58+ oracle's EC_ISTEP format.
59+
60+## Pixel state under the bypass -- the gate is RED
61+
62+* Film: all six probes move past this wall (hg-0 7 leaves, hg-300 10, @900 21 (+2 mixed),
63+ @5400 28 (+2 mixed), @6300 2) and stop at the NEXT wall (4x4 split intra on 3 of them,
64+ the 16x4 strip arms on the others). No film pixel comparison is possible: every firing frame
65+ also carries the unproven intra-16x4 strip.
66+* aomenc witness sweep `~/.cache/sub8intra-tmp/sweep.sh` and `sweep2.sh` (recipe: 128x128 /
67+ 192x128 gray lavfi sources, cq 48..63, `--min-partition-size=4 --enable-1to4-partitions=0
68+ --max-partition-size=8|16 --enable-filter-intra=0 --sb-size=64 --enable-tx-size-search=1`),
69+ logs `sweep1.log` / `sweep2.log`: the counters fire on every arm (up to 293 8x4 leaves) but
70+ **only 1 of 24 arms decodes all 6 frames, and that one MISMATCHES at byte 24735**. Eleven
71+ arms encoded with `--max-partition-size=8` -- where a 16x4 block CANNOT exist -- still report
72+ "an intra 16x4/4x16 strip inside an inter 16x16-level 1:4 partition", i.e. the refusal is
73+ hallucinated by our own desync (class `refusal-from-own-desync`).
74+
75+## Where the desync is (bisected, do not redo this)
76+
77+Witness `~/.cache/sub8intra-tmp/x_1t_48_8_128x128.obu` (8-bit 128x128, cq48, max-partition 8;
78+1 intra 8x4 leaf then the bogus refusal).
79+
80+* EC_MODE ladder (ours vs instrumented aomdec, `r.l`/`o.l` in that dir): identical for 168
81+ entries; first divergence at `mi_row=24 mi_col=0` (ref rng=39238, ours rng=44268 and ours
82+ reads a 16-wide block where the reference reads four 4x4s).
83+* The intra leaf itself is EXACT: it is at mi(23,12) (HORZ pair with the inter leaf at
84+ mi(22,12), so the INTRA one is the chroma reference). Ours prints
85+ `EC_ISTEP mi_row=23 mi_col=12 name=mode val=0 rng=38508` and
86+ `name=tx_depth val=0 ctx=2 cat=0 rng=49194`; the oracle prints the identical tx_depth line
87+ (ref_step.log:2463). So `y_mode[0]`, the missing angle delta, the uv/CfL reads and the
88+ tx-depth ctx are all right.
89+* `tag=all_zero` ladder (`rz.l`/`oz.l`): the first 1405 luma/chroma transform units match
90+ exactly; unit 1406 diverges (ref `all_zero=0 rng=40294`, ours `all_zero=0 rng=52548`). Both
91+ decoders are still reading plane 0 there, so the divergence is in symbols read BETWEEN two
92+ luma TUs -- i.e. inside the block following the intra leaf (the group at mi(22..23,14), the
93+ 8x8 immediately to its right) or in that group's chroma.
94+
95+## Exact next step
96+
97+1. On that witness, ladder the group at mi(22,14)/(23,14) element by element (aomdec
98+ `EC_ISTEP2 name=interp` / `EC_MODE`, ours `EC_MODE_MV`/`EC_MODE_VALR`) -- the intra leaf at
99+ mi(23,12) is its LEFT neighbour, so the prime suspects are the left-side bands the intra
100+ leaf publishes: `left_txfm` (tx dims vs block dims), `left_ref`/`left_inter` from
101+ `record_inter_rect_mi(ref 0)` (INTRA_FRAME is 0 vs the `-1` the mi grid gets), the
102+ coefficient state `left[..][0..2]`, and `left_side_mi` (the caller writes the group's
103+ partition ctx AFTER the leaf, check the order).
104+2. Then re-check the chroma of the MIXED group at mi(22,12): its chroma is coded by the intra
105+ leaf, so the inter sibling's own `piece` is dropped -- confirm against
106+ `build_inter_predictors_sub8x8`'s `is_sub8x8_inter == false` path.
107+3. Only then re-run the sweep; a green arm needs `--max-partition-size=8` (no 16x4 shape can
108+ exist there, so any 1:4 refusal is proof of a remaining desync).