forge
Explore
Log in

Don't you dare go Hollow

Merge branch 'main' into lane-vartxsplit

Browse files at this commit

4730c95f76c3e4ec48f19fc3f3fcd5005099d540Ahmet Kaan GümüşParent: 8fd6019c249957
# Conflicts:
#	crates/ec-av1/src/decode.rs

15 changed files +2601 -162

crates/ec-av1/examples/decode_probe.rsmodified+11 -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={} split4x4={}",
51+ si.0, si.1, si.2, si.3, si.4
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
@@ -110,6 +115,12 @@ fn main() {
110 // rectangular residual transform unit (a skipped one codes none).115 // rectangular residual transform unit (a skipped one codes none).
111 let r328 = ec_av1::stream::rect32x8_inter_tu_hits();116 let r328 = ec_av1::stream::rect32x8_inter_tu_hits();
112 println!("rect32x8_inter_tu: 32x8={} 8x32={}", r328[0], r328[1]);117 println!("rect32x8_inter_tu: 32x8={} 8x32={}", r328[0], r328[1]);
118+ // lane-intra16x4: INTRA strips of an inter 16x16-level 1:4 partition.
119+ let i164 = ec_av1::stream::intra16x4_in_inter_hits();
120+ println!(
121+ "intra16x4_in_inter: 16x4={} 4x16={} chroma_ref={}",
122+ i164.0, i164.1, i164.2
123+ );
113 };124 };
114 // lane-tiles: the tiling a real stream actually uses is a decision input125 // lane-tiles: the tiling a real stream actually uses is a decision input
115 // (every gate in `stream.rs` picks its own `--tile-columns`), so report it126 // (every gate in `stream.rs` picks its own `--tile-columns`), so report it
crates/ec-av1/fixtures/reelb_rect64_intra16x4_witness.obuadded+0 -0

Binary file changed

crates/ec-av1/src/decode.rsmodified+1000 -149
@@ -2691,6 +2691,21 @@ thread_local! {
2691 static INTER16_SUB8_PIECE_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };2691 static INTER16_SUB8_PIECE_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
2692 }2692 }
2693 2693
2694+// lane-intra16x4: INTRA-coded strips of an inter 16x16-level 1:4 partition --
2695+// [0] 16x4, [1] 4x16, [2] the odd (chroma-reference) ones, which carry the
2696+// pair's single 8x4 (4x8) chroma unit for BOTH strips.
2697+thread_local! {
2698+ static INTRA16X4_IN_INTER_HITS: std::cell::Cell<[usize; 3]> =
2699+ const { std::cell::Cell::new([0; 3]) };
2700+}
2701+
2702+/// `(intra 16x4 strips, intra 4x16 strips, of which chroma-reference)` decoded
2703+/// inside an INTER 16x16-level 1:4 partition (lane-intra16x4).
2704+pub fn intra16x4_in_inter_hits() -> (usize, usize, usize) {
2705+ let v = INTRA16X4_IN_INTER_HITS.with(std::cell::Cell::get);
2706+ (v[0], v[1], v[2])
2707+}
2708+
2694 /// Current values of the inter 16x16-level 1:4 counters: `(16x4 strips, 4x162709 /// Current values of the inter 16x16-level 1:4 counters: `(16x4 strips, 4x16
2695 /// strips, chroma pairs closed, chroma pairs built from two different2710 /// strips, chroma pairs closed, chroma pairs built from two different
2696 /// strips' motion vectors)`.2711 /// strips' motion vectors)`.
@@ -3108,6 +3123,24 @@ thread_local! {
3108 /// inter leaves (lane-intersub8 r3), indexed `[0] = HORZ` (two BLOCK_8X4),3123 /// inter leaves (lane-intersub8 r3), indexed `[0] = HORZ` (two BLOCK_8X4),
3109 /// `[1] = VERT` (two BLOCK_4X8).3124 /// `[1] = VERT` (two BLOCK_4X8).
3110 static SUB8_INTER_RECT_HITS: std::cell::Cell<[usize; 2]> = const { std::cell::Cell::new([0; 2]) };3125 static SUB8_INTER_RECT_HITS: std::cell::Cell<[usize; 2]> = const { std::cell::Cell::new([0; 2]) };
3126+ /// lane-sub8intra: INTRA leaves decoded inside an inter frame's sub-8x8
3127+ /// HORZ/VERT partition -- `[0]` 8x4, `[1]` 4x8, `[2]` of those that were
3128+ /// the chroma reference (so coded the group's 4x4 chroma intra), `[3]`
3129+ /// MIXED groups whose chroma reference is INTER while its sibling is
3130+ /// intra (the `is_sub8x8_inter` false path), `[4]` INTRA `BLOCK_4X4`
3131+ /// leaves of an inter frame's sub-8x8 `PARTITION_SPLIT` (lane-sub8x4 r2 --
3132+ /// the second lifted refusal's own witness; `[0]`/`[1]` count those too,
3133+ /// so only this cell separates the split arm from the HORZ/VERT one).
3134+ static SUB8_INTRA_RECT_HITS: std::cell::Cell<[usize; 5]> = const { std::cell::Cell::new([0; 5]) };
3135+}
3136+
3137+/// Current value of [`SUB8_INTRA_RECT_HITS`]: `(8x4, 4x8, chroma-reference,
3138+/// mixed groups, split 4x4 leaves)`.
3139+pub fn sub8_intra_rect_hits() -> (usize, usize, usize, usize, usize) {
3140+ SUB8_INTRA_RECT_HITS.with(|c| {
3141+ let h = c.get();
3142+ (h[0], h[1], h[2], h[3], h[4])
3143+ })
3111 }3144 }
3112 3145
3113 /// Current value of [`SUB8_INTER_RECT_HITS`]: `(8x4 groups, 4x8 groups)`.3146 /// Current value of [`SUB8_INTER_RECT_HITS`]: `(8x4 groups, 4x8 groups)`.
@@ -4986,6 +5019,9 @@ impl Neighbours {
4986 tx_h_px: u8,5019 tx_h_px: u8,
4987 ) {5020 ) {
4988 let (mi_r, mi_c) = at_mi;5021 let (mi_r, mi_c) = at_mi;
5022+ if std::env::var_os("EC_TXGRID_TRACE").is_some() {
5023+ eprintln!("EC_LFLEAF mi_row={mi_r} mi_col={mi_c} w_mi={w_mi} h_mi={h_mi} tx_px={tx_px} tx_h_px={tx_h_px}");
5024+ }
4989 for rr in 0..h_mi {5025 for rr in 0..h_mi {
4990 for cc in 0..w_mi {5026 for cc in 0..w_mi {
4991 let idx = (mi_r + rr) * self.skip_grid_cols_mi + (mi_c + cc);5027 let idx = (mi_r + rr) * self.skip_grid_cols_mi + (mi_c + cc);
@@ -5381,7 +5417,8 @@ impl Neighbours {
5381 let ctx = SKIP_CONTEXTS[(top as usize).min(4)][(left as usize).min(4)];5417 let ctx = SKIP_CONTEXTS[(top as usize).min(4)][(left as usize).min(4)];
5382 if std::env::var_os("EC_AV1_TRACE").is_some() {5418 if std::env::var_os("EC_AV1_TRACE").is_some() {
5383 eprintln!(5419 eprintln!(
5384- "TRACE luma_skip_ctx mi=({mi_r},{mi_c}) side_mi={side_mi} top={top} left={left} ctx={ctx}"5420+ "TRACE luma_skip_ctx mi=({mi_r},{mi_c}) side_mi={side_mi} top={top} left={left} ctx={ctx} band={:?}",
5421+ self.left.iter().map(|e| e[0].level).collect::<Vec<_>>()
5385 );5422 );
5386 }5423 }
5387 ctx5424 ctx
@@ -6866,14 +6903,14 @@ fn decode_rect_split(
6866 // the coded unit is the 32x32 corner [`decode_block_rect64`]'s own6903 // the coded unit is the 32x32 corner [`decode_block_rect64`]'s own
6867 // depth-0 arm already reads on the key-frame path.6904 // depth-0 arm already reads on the key-frame path.
6868 //6905 //
6869- // NO WITNESS YET (r1, measured): on both 10-bit 3840x1608 film cuts6906+ // lane-sub8x4 r3: WITNESS FOUND, so this is no longer behind
6870- // this arm fires (16x 64x32 + 2x 32x64 / 2x 32x64) but the SAME frame6907+ // `EC_RECT64_SPLIT`. r1's "no witness" was true only while the
6871- // then stops at "a non-skip rectangular (HORZ/VERT/HORZ_B) strip needs6908+ // sub-8x8 intra leaves still refused: with those lifted (r2) the
6872- // rectangular residual coding", so no frame containing it ever6909+ // first 50 frame OBUs of the 10-bit 3840x1608 stream's head decode
6873- // finishes and no pixel comparison is possible. A refusal is lifted6910+ // all 33 frames pixel-exact against ffmpeg while this arm fires 90x
6874- // only with a gate (COMMON charter), so the arm stays behind6911+ // 64x32 + 5x 32x64 -- pinned as `fixtures/reelb_rect64_intra16x4_witness.obu`
6875- // `EC_RECT64_SPLIT=1` and the refusal below is still the default.6912+ // and gated by `a_10bit_film_frames_with_intra_16x4_strips_and_rect64_corner_tus_decode_pixel_exact`.
6876- (64, 32) | (32, 64) if std::env::var_os("EC_RECT64_SPLIT").is_some() => None,6913+ (64, 32) | (32, 64) => None,
6877 _ => {6914 _ => {
6878 return Err(unsupported(format!(6915 return Err(unsupported(format!(
6879 "a split intra strip whose transform unit is {tx_w}x{tx_h} (no luma \6916 "a split intra strip whose transform unit is {tx_w}x{tx_h} (no luma \
@@ -7237,6 +7274,9 @@ fn decode_intra_rect_in_inter(
7237 bh: usize,7274 bh: usize,
7238 skip: bool,7275 skip: bool,
7239 allow_screen_content_tools: bool,7276 allow_screen_content_tools: bool,
7277+ // `(PARTITION_HORZ_4, is_chroma_reference)` when this strip is one of the
7278+ // four 16x4 / 4x16 strips of a 16x16-level 1:4 partition (lane-intra16x4).
7279+ strip16: Option<(bool, bool)>,
7240 y: &mut PlaneBuf,7280 y: &mut PlaneBuf,
7241 u: &mut PlaneBuf,7281 u: &mut PlaneBuf,
7242 v: &mut PlaneBuf,7282 v: &mut PlaneBuf,
@@ -7253,6 +7293,94 @@ fn decode_intra_rect_in_inter(
7253 // finding -- the category is NOT the same for every strip size).7293 // finding -- the category is NOT the same for every strip size).
7254 // A 1:4 strip breaks that diagonal (BLOCK_32X8 is group 1 but cat 2), so7294 // A 1:4 strip breaks that diagonal (BLOCK_32X8 is group 1 but cat 2), so
7255 // it is refused by name rather than read from the wrong CDF row.7295 // it is refused by name rather than read from the wrong CDF row.
7296+ // lane-intra16x4: the 16x16-level 1:4 strip. `size_group_lookup`
7297+ // (common_data.h:61) puts BLOCK_16X4/BLOCK_4X16 in group 0 and its
7298+ // tx-depth category is 1 -- but nothing here has to know either, because
7299+ // the strip decodes through the very body the KEY FRAME path proves for
7300+ // this shape ([`decode_rect4_16_strip`]), including the 4:2:0 chroma
7301+ // pairing (`is_chroma_reference`: strips 0 and 2 read no chroma at all,
7302+ // strips 1 and 3 code one 8x4 (4x8) unit at the PAIR's origin). The only
7303+ // inter-frame difference is the mode-info read, which
7304+ // [`INTRA_IN_INTER_MODE`] switches to `read_intra_block_mode_info`'s
7305+ // `y_mode[0]` plus the `skip` this caller already read.
7306+ if let Some((horz, has_chroma)) = strip16 {
7307+ if allow_screen_content_tools {
7308+ return Err(unsupported(
7309+ "a HORZ/VERT intra strip in a screen-content frame (palette syntax \
7310+ is consumed for square blocks only)",
7311+ ));
7312+ }
7313+ debug_assert_eq!((bw, bh), if horz { (16, 4) } else { (4, 16) });
7314+ INTRA_IN_INTER_MODE.with(|c| c.set(Some((0, skip))));
7315+ let res = decode_rect4_16_strip(
7316+ dec,
7317+ cdfs,
7318+ neighbours,
7319+ (mi_r, mi_c),
7320+ horz,
7321+ has_chroma,
7322+ // The inter strips of the same partition publish their own
7323+ // mi-exact mode, so the key-frame caller's coarse-cell stand-in
7324+ // has nothing to add here.
7325+ None,
7326+ y,
7327+ u,
7328+ v,
7329+ ENABLE_FILTER_INTRA_INTER.with(std::cell::Cell::get),
7330+ allow_screen_content_tools,
7331+ base_q_idx,
7332+ TX_SELECT_INTER.with(std::cell::Cell::get),
7333+ REDUCED_TX_SET_INTER.with(std::cell::Cell::get),
7334+ );
7335+ INTRA_IN_INTER_MODE.with(|c| c.set(None));
7336+ let (mode, uv, (tx_w, tx_h)) = res?;
7337+ // lane-intra16x4, the same publication the 2:1 intra-in-inter strip
7338+ // makes ([`decode_intra_rect_in_inter`]'s own tail): libaom runs
7339+ // `set_txfm_ctxs(tx_size, n4_w, n4_h, skip && is_inter, xd)` for EVERY
7340+ // block of an inter frame, intra ones included, and
7341+ // `txfm_partition_update` for the var-tx context. The key-frame body
7342+ // writes neither (a key frame has no var-tx tree and its own readers
7343+ // use the deblock grid), so the block AFTER this strip read a stale
7344+ // band -- measured: a 128x128 8-bit stream decoded the two intra 16x4
7345+ // strips at mi(23,16)/(23,20) exactly and then broke on the very next
7346+ // 16x16 row.
7347+ txfm_partition_update_rect(neighbours, (mi_r, mi_c), (tx_w, tx_h), (bw, bh));
7348+ for i in 0..bw / MI {
7349+ if let Some(cell) = neighbours.above_txfm.get_mut(mi_c + i) {
7350+ *cell = tx_w as u8;
7351+ }
7352+ }
7353+ for i in 0..bh / MI {
7354+ if let Some(cell) = neighbours.left_txfm.get_mut(mi_r + i) {
7355+ *cell = tx_h as u8;
7356+ }
7357+ }
7358+ // [`decode_rect4_16`]'s own post-loop publication, per strip (the
7359+ // coarse 16-px cell holds one entry for the whole 16x16 and the last
7360+ // block to write it wins).
7361+ neighbours.above_mode[c] = mode;
7362+ neighbours.left_mode[r] = mode;
7363+ if let Some(uvm) = uv {
7364+ neighbours.above_uv_mode[c] = uvm;
7365+ neighbours.left_uv_mode[r] = uvm;
7366+ }
7367+ neighbours.above_side[c] = bw;
7368+ neighbours.left_side[r] = bh;
7369+ if std::env::var_os("EC_INTRA16X4").is_some() {
7370+ eprintln!(
7371+ "EC_INTRA16X4 decoded mi={mi_r},{mi_c} px={},{} horz={horz} has_chroma={has_chroma} skip={skip} mode={mode} uv={uv:?}",
7372+ mi_c * MI,
7373+ mi_r * MI
7374+ );
7375+ }
7376+ INTRA16X4_IN_INTER_HITS.with(|h| {
7377+ let mut v = h.get();
7378+ v[usize::from(!horz)] += 1;
7379+ v[2] += usize::from(has_chroma);
7380+ h.set(v);
7381+ });
7382+ return Ok(());
7383+ }
7256 let (size_group, tx_cat) = match (bw.min(bh), bw.max(bh)) {7384 let (size_group, tx_cat) = match (bw.min(bh), bw.max(bh)) {
7257 (8, 16) => (1usize, 1usize),7385 (8, 16) => (1usize, 1usize),
7258 (16, 32) => (2, 2),7386 (16, 32) => (2, 2),
@@ -8756,6 +8884,72 @@ fn decode_rect4_16(
8756 (mi_row0, mi_col0 + i)8884 (mi_row0, mi_col0 + i)
8757 };8885 };
8758 let has_chroma = i % 2 == 1;8886 let has_chroma = i % 2 == 1;
8887+ let (mode, uv, _tx) = decode_rect4_16_strip(
8888+ dec,
8889+ cdfs,
8890+ neighbours,
8891+ lmi,
8892+ horz,
8893+ has_chroma,
8894+ prev,
8895+ y,
8896+ u,
8897+ v,
8898+ enable_filter_intra,
8899+ allow_screen_content_tools,
8900+ base_q_idx,
8901+ tx_select,
8902+ reduced_tx_set,
8903+ )?;
8904+ if let Some(m) = uv {
8905+ last_uv_mode = m;
8906+ }
8907+ last_mode = mode;
8908+ prev = Some((lmi, mode));
8909+ }
8910+ // The coarse 16-px cell holds one entry for the whole 16x16: the last
8911+ // strip is what a block below (right) sees through it, the mi-exact maps
8912+ // above answering everything finer.
8913+ neighbours.above_mode[c] = last_mode;
8914+ neighbours.left_mode[r] = last_mode;
8915+ neighbours.above_uv_mode[c] = last_uv_mode;
8916+ neighbours.left_uv_mode[r] = last_uv_mode;
8917+ neighbours.above_side[c] = bw;
8918+ neighbours.left_side[r] = bh;
8919+ Ok(())
8920+}
8921+
8922+/// One 16x4 / 4x16 strip of a 16x16-level 1:4 partition, intra-coded --
8923+/// [`decode_rect4_16`]'s per-strip body, lifted (lane-intra16x4) so the INTER
8924+/// block path can decode a SINGLE intra strip of a partition whose other
8925+/// strips are inter. `prev` is the previous strip's `(mi, mode)` (the
8926+/// key-frame caller's coarse-cell stand-in; `None` on the inter path, where
8927+/// every strip publishes its own mi-exact mode). Returns
8928+/// `(y_mode, uv_predict_mode when this strip closes the 4:2:0 chroma pair)`.
8929+#[allow(clippy::too_many_arguments)]
8930+fn decode_rect4_16_strip(
8931+ dec: &mut SymbolDecoder,
8932+ cdfs: &mut Cdfs,
8933+ neighbours: &mut Neighbours,
8934+ lmi: (usize, usize),
8935+ horz: bool,
8936+ has_chroma: bool,
8937+ prev: Option<((usize, usize), usize)>,
8938+ y: &mut PlaneBuf,
8939+ u: &mut PlaneBuf,
8940+ v: &mut PlaneBuf,
8941+ enable_filter_intra: bool,
8942+ allow_screen_content_tools: bool,
8943+ base_q_idx: u8,
8944+ tx_select: bool,
8945+ reduced_tx_set: bool,
8946+) -> Result<(usize, Option<usize>, (usize, usize))> {
8947+ let (r, c) = (lmi.0 / (SUB / MI), lmi.1 / (SUB / MI));
8948+ let (bw, bh) = if horz { (16usize, 4usize) } else { (4, 16) };
8949+ let (mi_w, mi_h) = (bw / MI, bh / MI);
8950+ let scan: &[u16] = if horz { &SCAN_16X4 } else { &SCAN_4X16 };
8951+ let chroma_scan: &[u16] = if horz { &SCAN_8X4 } else { &SCAN_4X8 };
8952+ let mut last_uv_mode: Option<usize> = None;
8759 // `decode_block_rect4`'s own neighbour rule: the coarse 16-px cell8953 // `decode_block_rect4`'s own neighbour rule: the coarse 16-px cell
8760 // aliases all four strips onto one entry, so the mi-exact map wins and8954 // aliases all four strips onto one entry, so the mi-exact map wins and
8761 // the previous strip stands in on the split axis.8955 // the previous strip stands in on the split axis.
@@ -8829,7 +9023,16 @@ fn decode_rect4_16(
8829 // depth symbol is the 3-symbol `tx_size_cat1` -- not the 2-symbol9023 // depth symbol is the 3-symbol `tx_size_cat1` -- not the 2-symbol
8830 // `cat0` a 4x8 leaf reads nor the `cat2` a 32x8 strip does.9024 // `cat0` a 4x8 leaf reads nor the `cat2` a 32x8 strip does.
8831 let depth = if tx_select {9025 let depth = if tx_select {
8832- let ctx = tx_size_context_rect(neighbours, lmi, bw, bh);9026+ // lane-intra16x4: on an INTER frame `get_tx_size_context` reads the
9027+ // real `TXFM_CONTEXT` bands ([`tx_size_context_txfm_rect`], what
9028+ // the 2:1 intra-in-inter strip already does); the key frame's
9029+ // deblock-grid approximation is only right where those bands were
9030+ // never written.
9031+ let ctx = if INTRA_IN_INTER_MODE.with(std::cell::Cell::get).is_some() {
9032+ tx_size_context_txfm_rect(neighbours, lmi, bw, bh)
9033+ } else {
9034+ tx_size_context_rect(neighbours, lmi, bw, bh)
9035+ };
8833 dec.symbol(&mut cdfs.tx_size_cat1[ctx])9036 dec.symbol(&mut cdfs.tx_size_cat1[ctx])
8834 } else {9037 } else {
8835 09038 0
@@ -9171,7 +9374,7 @@ fn decode_rect4_16(
9171 slot[2] = v_state;9374 slot[2] = v_state;
9172 }9375 }
9173 }9376 }
9174- last_uv_mode = uv_predict_mode;9377+ last_uv_mode = Some(uv_predict_mode);
9175 }9378 }
9176 if horz {9379 if horz {
9177 RECT4_16_HORZ_HITS.with(|h| h.set(h.get() + 1));9380 RECT4_16_HORZ_HITS.with(|h| h.set(h.get() + 1));
@@ -9185,21 +9388,10 @@ fn decode_rect4_16(
9185 record_strip_palette(9388 record_strip_palette(
9186 neighbours, lmi, bw, bh, pal_y_size, pal_y_colors, pal_uv_size, pal_uv_colors,9389 neighbours, lmi, bw, bh, pal_y_size, pal_y_colors, pal_uv_size, pal_uv_colors,
9187 );9390 );
9188- last_mode = mode;9391+ Ok((mode, last_uv_mode, (tx_w, tx_h)))
9189- prev = Some((lmi, mode));
9190- }
9191- // The coarse 16-px cell holds one entry for the whole 16x16: the last
9192- // strip is what a block below (right) sees through it, the mi-exact maps
9193- // above answering everything finer.
9194- neighbours.above_mode[c] = last_mode;
9195- neighbours.left_mode[r] = last_mode;
9196- neighbours.above_uv_mode[c] = last_uv_mode;
9197- neighbours.left_uv_mode[r] = last_uv_mode;
9198- neighbours.above_side[c] = bw;
9199- neighbours.left_side[r] = bh;
9200- Ok(())
9201 }9392 }
9202 9393
9394+
9203 /// Decodes one true `bw`x`bh` superblock-level `PARTITION_HORZ`/9395 /// Decodes one true `bw`x`bh` superblock-level `PARTITION_HORZ`/
9204 /// `PARTITION_VERT` strip (lane-sbpart r2, `bw, bh` one of `(64, 32)` /9396 /// `PARTITION_VERT` strip (lane-sbpart r2, `bw, bh` one of `(64, 32)` /
9205 /// `(32, 64)` -- [`decode_block_rect`]'s own sibling one level up). Unlike9397 /// `(32, 64)` -- [`decode_block_rect`]'s own sibling one level up). Unlike
@@ -13158,6 +13350,19 @@ fn tx_size_context_txfm_rect(
13158 if has_left && n.left_inter[mi_r] {13350 if has_left && n.left_inter[mi_r] {
13159 left = n.left_side_mi[mi_r] >= own_h;13351 left = n.left_side_mi[mi_r] >= own_h;
13160 }13352 }
13353+ if std::env::var_os("EC_TXCTX").is_some() {
13354+ eprintln!(
13355+ "EC_TXCTX mi={mi_r},{mi_c} own={own_w}x{own_h} ha={has_above} hl={has_left} \
13356+ above_txfm={} left_txfm={} above_inter={} left_inter={} above_side={} left_side={} \
13357+ above={above} left={left}",
13358+ n.above_txfm[mi_c],
13359+ n.left_txfm[mi_r],
13360+ n.above_inter[mi_c],
13361+ n.left_inter[mi_r],
13362+ n.above_side_mi[mi_c],
13363+ n.left_side_mi[mi_r],
13364+ );
13365+ }
13161 match (has_above, has_left) {13366 match (has_above, has_left) {
13162 (true, true) => usize::from(above) + usize::from(left),13367 (true, true) => usize::from(above) + usize::from(left),
13163 (true, false) => usize::from(above),13368 (true, false) => usize::from(above),
@@ -17929,10 +18134,17 @@ fn ref_planes<'a>(
17929 /// unit at a time, and does not itself count as a step). `max_neighbors`18134 /// unit at a time, and does not itself count as a step). `max_neighbors`
17930 /// caller-bounds the scan: `1` for the eligibility check (any hit at all),18135 /// caller-bounds the scan: `1` for the eligibility check (any hit at all),
17931 /// `av1_build_obmc_inter_prediction`'s own `max_neighbor_obmc` table for the18136 /// `av1_build_obmc_inter_prediction`'s own `max_neighbor_obmc` table for the
17932-/// real blend pass. Round 1 corner-cut: libaom's own "4-wide block, treat as18137+/// real blend pass. lane-intra16x4 r2: libaom's own "4-wide block, treat as
17933-/// half of a chroma pair" merge (`obmc.h`'s `mi_step == 1` special case) is18138+/// half of a chroma pair" merge (`obmc.h`'s `mi_step == 1` special case) IS
17934-/// not ported -- no block this decoder codes is narrower than 8px, so it18139+/// ported below -- the round-1 note that no block is narrower than 8px stopped
17935-/// never fires here regardless of what a neighbour's own decoder was.18140+/// being true when the 1:4 partitions landed. A 16x4 / 4x16 strip has
18141+/// `mi_size_high`/`mi_size_wide` 1, so libaom snaps the walk back to the pair's
18142+/// even index, reads the ODD (chroma-carrying) half as the neighbour and steps
18143+/// by 2. Measured: the 16x16 block right of a 16x16-level HORZ_4 partition
18144+/// whose strip 0 is inter and strips 1..3 intra counted that inter strip as
18145+/// overlappable here, while libaom's pair merge reads the INTRA strip 1 and
18146+/// counts none -- so we read a `motion_mode` symbol libaom never wrote (class
18147+/// `symbol-consumption-gap`), desyncing the tile at the next coefficient.
17936 fn overlappable_above(18148 fn overlappable_above(
17937 grid: &MiGrid,18149 grid: &MiGrid,
17938 mi_row: usize,18150 mi_row: usize,
@@ -17949,8 +18161,17 @@ fn overlappable_above(
17949 let mut col = mi_col;18161 let mut col = mi_col;
17950 while col < end_col && out.len() < max_neighbors {18162 while col < end_col && out.len() < max_neighbors {
17951 let cell = grid.get(mi_row - 1, col);18163 let cell = grid.get(mi_row - 1, col);
17952- let step = cell.map_or(1, |c| c.size).max(1);18164+ let mut step = cell.map_or(1, |c| c.size).max(1).min(SB_MI as usize);
17953- if let Some(info) = cell {18165+ let mut nb = cell;
18166+ if step == 1 {
18167+ // The pair merge: the walk snaps back to the pair's even column
18168+ // and the ODD half (the chroma-carrying one) is the neighbour for
18169+ // both -- a 4-wide 1:4 strip is never an OBMC source on its own.
18170+ col &= !1;
18171+ nb = grid.get(mi_row - 1, col + 1);
18172+ step = 2;
18173+ }
18174+ if let Some(info) = nb {
17954 if info.is_inter {18175 if info.is_inter {
17955 out.push((col - mi_col, step.min(end_col - col), *info));18176 out.push((col - mi_col, step.min(end_col - col), *info));
17956 }18177 }
@@ -17980,8 +18201,17 @@ fn overlappable_left(
17980 let cell = grid.get(row, mi_col - 1);18201 let cell = grid.get(row, mi_col - 1);
17981 // Vertical walk steps by the neighbour's HEIGHT -- a 32x16 strip's18202 // Vertical walk steps by the neighbour's HEIGHT -- a 32x16 strip's
17982 // width (8) would swallow the strip below it.18203 // width (8) would swallow the strip below it.
17983- let step = cell.map_or(1, |c| c.size_h).max(1);18204+ let mut step = cell.map_or(1, |c| c.size_h).max(1).min(SB_MI as usize);
17984- if let Some(info) = cell {18205+ let mut nb = cell;
18206+ if step == 1 {
18207+ // The pair merge, left-column mirror: a 4-TALL neighbour (a 16x4
18208+ // strip) is half of a chroma pair and the pair's SECOND row is the
18209+ // neighbour for both.
18210+ row &= !1;
18211+ nb = grid.get(row + 1, mi_col - 1);
18212+ step = 2;
18213+ }
18214+ if let Some(info) = nb {
17985 if info.is_inter {18215 if info.is_inter {
17986 out.push((row - mi_row, step.min(end_row - row), *info));18216 out.push((row - mi_row, step.min(end_row - row), *info));
17987 }18217 }
@@ -21672,7 +21902,38 @@ fn decode_inter_block(
21672 // footprint), so an INTRA 16x4 / 4x16 strip inside a 1:4 partition is21902 // footprint), so an INTRA 16x4 / 4x16 strip inside a 1:4 partition is
21673 // refused by name rather than decoded with a 8x2 chroma transform21903 // refused by name rather than decoded with a 8x2 chroma transform
21674 // libaom never coded.21904 // libaom never coded.
21675- if write_w.min(write_h) < 8 {21905+ // lane-intra16x4 r1: the strip DECODES through the key frame's own
21906+ // per-strip body, [`decode_rect4_16_strip`].
21907+ // lane-sub8x4 r3: pixel-proven, so `EC_INTRA16X4_DECODE` is gone. r1
21908+ // and r2 found no witness because every firing film frame ALSO carried
21909+ // a sub-8x8 intra block, which refused until r2 lifted it; on this tip
21910+ // the first 50 frame OBUs of the 10-bit 3840x1608 stream's head decode
21911+ // all 33 frames pixel-exact while this arm fires 31x 16x4 + 17x 4x16
21912+ // (23 of them chroma-paired). Pinned as
21913+ // `fixtures/reelb_rect64_intra16x4_witness.obu`, gated by
21914+ // `a_10bit_film_frames_with_intra_16x4_strips_and_rect64_corner_tus_decode_pixel_exact`.
21915+ // The refusal below is NARROWED, not deleted: it still stands for a
21916+ // 16x4/4x16 strip with no chroma-pair record and for every other
21917+ // sub-8 shape.
21918+ let strip16 = strip_chroma
21919+ .filter(|_| write_w.min(write_h) == 4 && write_w.max(write_h) == 16)
21920+ .map(|s| (s.horz, s.has_chroma));
21921+ if write_w.min(write_h) < 8 && strip16.is_none() {
21922+ if std::env::var_os("EC_INTRA16X4").is_some() {
21923+ let (idx, hc, prev_inter) = match strip_chroma {
21924+ Some(s) => (
21925+ if s.horz { rmi - s.pair_mi.0 } else { cmi - s.pair_mi.1 },
21926+ s.has_chroma,
21927+ s.prev.is_some(),
21928+ ),
21929+ None => (9, true, false),
21930+ };
21931+ eprintln!(
21932+ "EC_INTRA16X4 w={write_w} h={write_h} pair_parity={idx} has_chroma={hc} prev_single_inter={prev_inter} skip={skip} mi={rmi},{cmi} tx_select={} scr={}",
21933+ TX_SELECT_INTER.with(std::cell::Cell::get),
21934+ allow_screen_content_tools,
21935+ );
21936+ }
21676 return Err(unsupported(21937 return Err(unsupported(
21677 "an intra 16x4/4x16 strip inside an inter 16x16-level 1:4 partition (its 4:2:0 chroma pair is coded once for two strips; only the inter path implements that pairing)",21938 "an intra 16x4/4x16 strip inside an inter 16x16-level 1:4 partition (its 4:2:0 chroma pair is coded once for two strips; only the inter path implements that pairing)",
21678 ));21939 ));
@@ -21695,6 +21956,7 @@ fn decode_inter_block(
21695 write_h,21956 write_h,
21696 skip,21957 skip,
21697 allow_screen_content_tools,21958 allow_screen_content_tools,
21959+ strip16,
21698 y,21960 y,
21699 u,21961 u,
21700 v,21962 v,
@@ -22439,6 +22701,9 @@ fn decode_inter_sub8_split4(
22439 [None; 4];22701 [None; 4];
22440 let mut first_tx_type = TxType::DctDct;22702 let mut first_tx_type = TxType::DctDct;
22441 let mut last_skip = true;22703 let mut last_skip = true;
22704+ // Set when the chroma-reference (last) sub-block is INTRA: it coded the
22705+ // group's one chroma unit itself.
22706+ let mut intra_chroma = false;
22442 for i in 0..4usize {22707 for i in 0..4usize {
22443 let (dr, dc) = (i / 2, i % 2);22708 let (dr, dc) = (i / 2, i % 2);
22444 let lmi = (gr + dr, gc + dc);22709 let lmi = (gr + dr, gc + dc);
@@ -22467,10 +22732,48 @@ fn decode_inter_sub8_split4(
22467 );22732 );
22468 let is_inter = dec.symbol(&mut cdfs.intra_inter[ii_ctx]) == 1;22733 let is_inter = dec.symbol(&mut cdfs.intra_inter[ii_ctx]) == 1;
22469 if !is_inter {22734 if !is_inter {
22470- return Err(unsupported(22735+ if std::env::var_os("EC_SUB8INTRA").is_some() {
22471- "an intra 4x4 block inside an inter frame's sub-8x8 split (this decoder codes \22736+ eprintln!(
22472- only inter 4x4 sub-blocks there)",22737+ "EC_SUB8INTRA shape=4x4 sub={i} has_chroma={} skip={skip} mi={rmi},{cmi} tx_select={}",
22473- ));22738+ i == 3,
22739+ TX_SELECT_INTER.with(std::cell::Cell::get),
22740+ );
22741+ }
22742+ // lane-sub8x4 r2: the refusal and its `EC_SUB8INTRA_DECODE` bypass
22743+ // are gone -- `a_real_aomenc_inter_sequence_with_intra_sub8x8_
22744+ // leaves_decodes_pixel_exact` (stream.rs) decodes 12 real aomenc
22745+ // streams carrying this arm pixel-exact vs ffmpeg.
22746+ SUB8_INTRA_RECT_HITS.with(|h| {
22747+ let mut st = h.get();
22748+ st[4] += 1;
22749+ h.set(st);
22750+ });
22751+ // lane-sub8intra: the `BLOCK_4X4` twin of the HORZ/VERT arm --
22752+ // same [`decode_intra_sub8_leaf`], no tx-depth symbol, chroma on
22753+ // the LAST sub-block (`is_chroma_reference` under 4:2:0).
22754+ decode_intra_sub8_leaf(
22755+ dec,
22756+ cdfs,
22757+ neighbours,
22758+ grid,
22759+ group_mi,
22760+ lmi,
22761+ (B4, B4),
22762+ i == 3,
22763+ skip,
22764+ scan4,
22765+ y,
22766+ u,
22767+ v,
22768+ base_q_idx,
22769+ ENABLE_FILTER_INTRA_INTER.with(std::cell::Cell::get),
22770+ TX_SELECT_INTER.with(std::cell::Cell::get),
22771+ reduced_tx_set,
22772+ )?;
22773+ if i == 3 {
22774+ intra_chroma = true;
22775+ }
22776+ continue;
22474 }22777 }
22475 // Same print point as the oracle's `EC_MODE` (entry of22778 // Same print point as the oracle's `EC_MODE` (entry of
22476 // `read_inter_block_mode_info`, i.e. after skip / is_inter), so the22779 // `read_inter_block_mode_info`, i.e. after skip / is_inter), so the
@@ -22691,11 +22994,14 @@ fn decode_inter_sub8_split4(
22691 None,22994 None,
22692 None,22995 None,
22693 )?;22996 )?;
22694- if i == 0 {22997+ if i == 0 || piece[0].is_none() {
22695 // `av1_get_tx_type`: an inter block's chroma inherits the22998 // `av1_get_tx_type`: an inter block's chroma inherits the
22696 // tx_type of the CO-LOCATED luma position, which for the22999 // tx_type of the CO-LOCATED luma position, which for the
22697 // group's one chroma unit is luma (0, 0) -- the FIRST23000 // group's one chroma unit is luma (0, 0) -- the FIRST
22698- // sub-block, not the last.23001+ // sub-block, not the last. lane-sub8intra: an INTRA first
23002+ // sub-block writes no inter tx_type there at all, so the
23003+ // later inter sub-blocks' own is what `xd->tx_type_map`
23004+ // holds.
22699 first_tx_type = tx_type;23005 first_tx_type = tx_type;
22700 }23006 }
22701 neighbours.record_mi_luma_rect(lmi, B4, B4, &luma_grid);23007 neighbours.record_mi_luma_rect(lmi, B4, B4, &luma_grid);
@@ -22712,20 +23018,43 @@ fn decode_inter_sub8_split4(
22712 neighbours.fill_lf_grid_rect(lmi, 1, 1, B4 as u8, B4 as u8, ref_frame.max(LAST_FRAME));23018 neighbours.fill_lf_grid_rect(lmi, 1, 1, B4 as u8, B4 as u8, ref_frame.max(LAST_FRAME));
22713 last_skip = skip;23019 last_skip = skip;
22714 }23020 }
23021+ // lane-sub8intra: when the chroma-reference sub-block was INTRA it coded
23022+ // and reconstructed the group's one chroma unit itself.
23023+ if !intra_chroma {
22715 // Chroma, once for the whole group, on the last sub-block's own `skip`23024 // Chroma, once for the whole group, on the last sub-block's own `skip`
22716 // flag -- prediction from all four sub-blocks (2x2 pieces), residual as23025 // flag -- prediction from all four sub-blocks (2x2 pieces), residual as
22717 // one TX_4X4 unit per plane.23026 // one TX_4X4 unit per plane.
22718 let mut pred_u = vec![0u16; B4 * B4];23027 let mut pred_u = vec![0u16; B4 * B4];
22719 let mut pred_v = vec![0u16; B4 * B4];23028 let mut pred_v = vec![0u16; B4 * B4];
23029+ // `is_sub8x8_inter` (reconinter_template.inc:54) is false as soon as ANY
23030+ // mi of the group is intra: the group's 4x4 chroma is then predicted WHOLE
23031+ // from the chroma-reference (last) sub-block's own mv, not in 2x2 pieces.
23032+ let mixed = piece.iter().any(Option::is_none);
23033+ if mixed {
23034+ SUB8_INTRA_RECT_HITS.with(|h| {
23035+ let mut st = h.get();
23036+ st[3] += 1;
23037+ h.set(st);
23038+ });
23039+ }
22720 for i in 0..4usize {23040 for i in 0..4usize {
22721 let (dr, dc) = (i / 2, i % 2);23041 let (dr, dc) = (i / 2, i % 2);
23042+ if mixed && i != 3 {
23043+ continue;
23044+ }
22722 let Some((ref_frame, mv, h_filter, v_filter)) = piece[i] else {23045 let Some((ref_frame, mv, h_filter, v_filter)) = piece[i] else {
22723 continue;23046 continue;
22724 };23047 };
22725 let (_, sref_u, sref_v) = ref_planes(ref_frame, ref_y, ref_u, ref_v, other_refs)?;23048 let (_, sref_u, sref_v) = ref_planes(ref_frame, ref_y, ref_u, ref_v, other_refs)?;
22726- let (ox, oy) = (cpx + dc * 2, cpy + dr * 2);23049+ let (ox, oy) = if mixed {
23050+ (cpx, cpy)
23051+ } else {
23052+ (cpx + dc * 2, cpy + dr * 2)
23053+ };
23054+ let (pw, ph) = if mixed { (B4, B4) } else { (2, 2) };
23055+ let (row0, col0) = if mixed { (0, 0) } else { (dr * 2, dc * 2) };
22727 for (plane, dst) in [(sref_u, &mut pred_u), (sref_v, &mut pred_v)] {23056 for (plane, dst) in [(sref_u, &mut pred_u), (sref_v, &mut pred_v)] {
22728- let mut buf = vec![0u16; 4];23057+ let mut buf = vec![0u16; pw * ph];
22729 mc::predict_with_filters(23058 mc::predict_with_filters(
22730 &plane.data,23059 &plane.data,
22731 plane.width,23060 plane.width,
@@ -22733,15 +23062,15 @@ fn decode_inter_sub8_split4(
22733 plane.true_height,23062 plane.true_height,
22734 mv_to_q4(ox, mv.1, false),23063 mv_to_q4(ox, mv.1, false),
22735 mv_to_q4(oy, mv.0, false),23064 mv_to_q4(oy, mv.0, false),
22736- 2,23065+ pw,
22737- 2,23066+ ph,
22738 h_filter,23067 h_filter,
22739 v_filter,23068 v_filter,
22740 &mut buf,23069 &mut buf,
22741 );23070 );
22742- for row in 0..2 {23071+ for row in 0..ph {
22743- for col in 0..2 {23072+ for col in 0..pw {
22744- dst[(dr * 2 + row) * B4 + dc * 2 + col] = buf[row * 2 + col];23073+ dst[(row0 + row) * B4 + col0 + col] = buf[row * pw + col];
22745 }23074 }
22746 }23075 }
22747 }23076 }
@@ -22765,13 +23094,6 @@ fn decode_inter_sub8_split4(
22765 (ug, vg)23094 (ug, vg)
22766 };23095 };
22767 neighbours.record_uv_mode_mi(gr, gc, 2, 2, DC_PRED);23096 neighbours.record_uv_mode_mi(gr, gc, 2, 2, DC_PRED);
22768- // Same two neighbour tails [`decode_leaf_split4`] runs: the partition
22769- // context of a `BLOCK_4X4` subsize (`partition_context_lookup` bit 0 = 1,
22770- // reached by `side_mi = 4` here) and the group's chroma coefficient state.
22771- for cell in 0..2usize {
22772- neighbours.left_side_mi[gr + cell] = 4;
22773- neighbours.above_side_mi[gc + cell] = 4;
22774- }
22775 let round_up_even = |n: usize| n.div_ceil(2) * 2;23097 let round_up_even = |n: usize| n.div_ceil(2) * 2;
22776 let bound_h = round_up_even(neighbours.mi_rows);23098 let bound_h = round_up_even(neighbours.mi_rows);
22777 let bound_w = round_up_even(neighbours.mi_cols);23099 let bound_w = round_up_even(neighbours.mi_cols);
@@ -22787,101 +23109,548 @@ fn decode_inter_sub8_split4(
22787 neighbours.above[gc + cell][2] = v_state;23109 neighbours.above[gc + cell][2] = v_state;
22788 }23110 }
22789 }23111 }
23112+ }
23113+ // Same two neighbour tails [`decode_leaf_split4`] runs: the partition
23114+ // context of a `BLOCK_4X4` subsize (`partition_context_lookup` bit 0 = 1,
23115+ // reached by `side_mi = 4` here) and the group's chroma coefficient state.
23116+ for cell in 0..2usize {
23117+ neighbours.left_side_mi[gr + cell] = 4;
23118+ neighbours.above_side_mi[gc + cell] = 4;
23119+ }
22790 Ok(())23120 Ok(())
22791 }23121 }
22792 23122
22793-/// Decodes a `PARTITION_HORZ`/`PARTITION_VERT` of one 8x8 INTER block into two23123+/// One INTRA 8x4/4x8 leaf inside an INTER frame's sub-8x8 HORZ/VERT partition
22794-/// `BLOCK_8X4`/`BLOCK_4X8` inter leaves (lane-intersub8 r3) -- the inter twin of23124+/// (lane-sub8intra) -- the shape [`decode_inter_sub8_rect2`] refused by name.
22795-/// [`decode_leaf_rect8`] and the rectangular sibling of23125+/// Mode syntax is `read_intra_block_mode_info`'s (decodemv.c:1065), not the key
22796-/// [`decode_inter_sub8_split4`], whose element order it follows exactly.23126+/// frame's above/left pair: `y_mode[size_group_lookup[BLOCK_8X4] == 0]`, NO
22797-/// Per sub-block, in libaom `decodemv.c` `read_inter_frame_mode_info` order:23127+/// angle delta (`av1_use_angle_delta` needs `bsize >= BLOCK_8X8`), `uv_mode` +
22798-///23128+/// CfL alphas only on the chroma-reference sub-block (`is_chroma_reference`:
22799-/// * `segment_id`, `skip`, `cdef`/`delta_q`/`delta_lf`, `intra_inter`;23129+/// the SECOND one under 4:2:0), then `filter_intra` off BLOCK_8X4/BLOCK_4X8's
22800-/// * NO `skip_mode` symbol: `is_comp_ref_allowed(BLOCK_8X4)` is false23130+/// own class row (`av1_filter_intra_allowed_bsize` is `wide <= 32 && high <=
22801-/// (`av1_is_comp_ref_allowed` needs both sides >= 8), so23131+/// 32`, so this shape is allowed). Everything below the mode read -- the tx
22802-/// `read_skip_mode` returns 0 without reading and `comp_mode` is never read23132+/// depth symbol, the whole-leaf `TX_8X4`/`TX_4X8` or split `TX_4X4` walk, the
22803-/// either (`read_ref_frames`' `is_comp_ref_allowed` guard) -- single23133+/// 4x4 chroma unit at the group's origin -- is [`decode_leaf_rect8`]'s body for
22804-/// reference only;23134+/// the same shape; the INTER-frame differences are the tx-depth context
22805-/// * NO `interintra` and NO `motion_mode`/OBMC/warp symbol: every one of those23135+/// (`above_txfm`/`left_txfm`, not the key frame's deblock-grid approximation),
22806-/// gates needs `block_size_wide >= 8 && block_size_high >= 8`23136+/// `set_txfm_ctxs` publication, and the inter-side bands + mi map the caller's
22807-/// (`is_interintra_allowed_bsize`, `motion_mode_allowed`), and one side is 4;23137+/// inter leaves also write (`is_inter = 0`, ref `INTRA_FRAME`, no interp
22808-/// * `read_mb_interp_filter` DOES run for both sub-blocks.23138+/// filter).
22809-///
22810-/// The shape's own differences from the four-way split:
22811-///
22812-/// * `block_signals_txsize(BLOCK_8X4)` is true (`bsize > BLOCK_4X4`,
22813-/// blockd.h:1027), so a non-skipped sub-block reads ONE `txfm_partition`
22814-/// symbol under `TX_MODE_SELECT` at `max_txsize_rect_lookup[BLOCK_8X4] ==
22815-/// TX_8X4` ([`read_var_tx_size`]); split resolves to two `TX_4X4` units
22816-/// (`sub_tx_size_map[TX_8X4] == TX_4X4`, libaom's early return), no split to
22817-/// the whole-leaf `TX_8X4`;
22818-/// * the luma coefficient set is [`TxbSet::LumaRect8x4Inter`] (the 8x8
22819-/// coefficient class with a 32-position `eob_pt` and the INTER `TX_4X4`
22820-/// `tx_type` row) for the whole-leaf unit, and the square
22821-/// [`TxbSet::Luma4Inter`] for a split `TX_4X4` unit;
22822-/// * chroma is coded ONCE, on the sub-block that is the chroma reference:
22823-/// `is_chroma_reference` (`av1_common_int.h`) is
22824-/// `((mi_row & 1) || !(bh4 & 1) || !ss_y) && ((mi_col & 1) || !(bw4 & 1) ||
22825-/// !ss_x)`, i.e. under 4:2:0 the BOTTOM 8x4 (`bh4 == 1`, odd) and the RIGHT
22826-/// 4x8 (`bw4 == 1`) -- always the second sub-block here;
22827-/// * that chroma unit's prediction is the sub8x8 one (`reconinter.c`
22828-/// `build_inter_predictors_sub8x8`: `row_start = -(block_size_high == 4 &&
22829-/// ss_y)`, `col_start = -(block_size_wide == 4 && ss_x)`), two 4x2 (HORZ) or
22830-/// 2x4 (VERT) chroma pieces, each from its OWN sub-block's reference, mv and
22831-/// interpolation filters.
22832 #[allow(clippy::too_many_arguments)]23139 #[allow(clippy::too_many_arguments)]
22833-fn decode_inter_sub8_rect2(23140+fn decode_intra_sub8_leaf(
22834 dec: &mut SymbolDecoder,23141 dec: &mut SymbolDecoder,
22835 cdfs: &mut Cdfs,23142 cdfs: &mut Cdfs,
22836 neighbours: &mut Neighbours,23143 neighbours: &mut Neighbours,
22837 grid: &mut MiGrid,23144 grid: &mut MiGrid,
22838 group_mi: (usize, usize),23145 group_mi: (usize, usize),
22839- vert: bool,23146+ lmi: (usize, usize),
22840- mi_cols: u32,23147+ // `(bw, bh)`: 8x4 / 4x8 under HORZ/VERT, 4x4 under SPLIT.
22841- mi_rows: u32,23148+ (bw, bh): (usize, usize),
23149+ has_chroma: bool,
23150+ skip: bool,
23151+ scan4: &[u16],
22842 y: &mut PlaneBuf,23152 y: &mut PlaneBuf,
22843 u: &mut PlaneBuf,23153 u: &mut PlaneBuf,
22844 v: &mut PlaneBuf,23154 v: &mut PlaneBuf,
22845- ref_y: &PlaneBuf,
22846- ref_u: &PlaneBuf,
22847- ref_v: &PlaneBuf,
22848- other_refs: &RefSlots,
22849- sign_bias_table: &SignBiasTable,
22850- global_motion: &[ec_av1_syntax::WarpParams; 7],
22851 base_q_idx: u8,23155 base_q_idx: u8,
22852- scan4: &[u16],23156+ enable_filter_intra: bool,
22853- allow_high_precision_mv: bool,23157+ tx_select: bool,
22854- force_integer_mv: bool,
22855- interp_fixed: Option<mc::InterpFilterKind>,
22856- enable_dual_filter: bool,
22857- tpl_frame: Option<&TplFrameArgs>,
22858 reduced_tx_set: bool,23158 reduced_tx_set: bool,
22859- frame_width: usize,23159+) -> Result<usize> {
22860-) -> Result<()> {23160+ let vert = bw < bh;
22861- const LAST_FRAME: i8 = 1;
22862- // The 8x8 group's own square stride: both leaves' prediction buffers are
22863- // laid out at it, as every other rect inter unit here is.
22864- const SIDE: usize = 8;
22865- let (bw, bh) = if vert { (4usize, 8usize) } else { (8usize, 4usize) };
22866 let (w_mi, h_mi) = (bw / MI, bh / MI);23161 let (w_mi, h_mi) = (bw / MI, bh / MI);
22867- SUB8_INTER_RECT_HITS.with(|c| {
22868- let mut h = c.get();
22869- h[usize::from(vert)] += 1;
22870- c.set(h);
22871- });
22872 let (gr, gc) = group_mi;23162 let (gr, gc) = group_mi;
22873- let (gpx, gpy) = (gc * MI, gr * MI);23163+ let (r, c) = (gr / (SUB / MI), gc / (SUB / MI));
22874- let (cpx, cpy) = (gpx / 2, gpy / 2);23164+ let (above_mode, left_mode) = neighbours.modes_above_left(r, c);
23165+ let leaf_above = neighbours
23166+ .mode_above_mi(lmi.0, lmi.1)
23167+ .unwrap_or(above_mode);
23168+ let leaf_left = neighbours.mode_left_mi(lmi.0, lmi.1).unwrap_or(left_mode);
23169+ let step = std::env::var_os("EC_TRACE_MODE_STEP").is_some();
23170+ // `size_group_lookup[BLOCK_8X4] == size_group_lookup[BLOCK_4X8] == 0`
23171+ // (libaom common_data.h:61).
23172+ let mode = dec.symbol(&mut cdfs.y_mode[0]);
23173+ if step {
23174+ eprintln!(
23175+ "EC_ISTEP mi_row={} mi_col={} name=mode val={mode} rng={}",
23176+ lmi.0,
23177+ lmi.1,
23178+ dec.debug_state().0
23179+ );
23180+ }
23181+ // No angle delta below 8x8 (`av1_use_angle_delta`), for luma or chroma.
23182+ let angle_delta_y = 0;
23183+ let (uv_mode, alpha) = if has_chroma {
23184+ // `is_cfl_allowed` is `wide <= 32 && high <= 32` -- true for this
23185+ // shape, so the 14-symbol CFL alphabet is the right one.
23186+ let uv_mode = dec.symbol(&mut cdfs.uv_mode_cfl[mode]);
23187+ if (9..=12).contains(&uv_mode) {
23188+ SMOOTH_UV_HITS.with(|c| c.set(c.get() + 1));
23189+ }
23190+ let alpha = if uv_mode == UV_CFL_PRED {
23191+ Some(read_cfl_alphas(dec, cdfs))
23192+ } else {
23193+ None
23194+ };
23195+ if (V_PRED..=D67_PRED).contains(&uv_mode) {
23196+ DIRECTIONAL_UV_HITS.with(|c| c.set(c.get() + 1));
23197+ }
23198+ (uv_mode, alpha)
23199+ } else {
23200+ (DC_PRED, None)
23201+ };
23202+ let mut filter_intra = None;
23203+ if mode == DC_PRED && enable_filter_intra {
23204+ let fi_class = if bw == bh {
23205+ filter_intra_size_class(bw).expect("BLOCK_4X4 has its own filter_intra row")
23206+ } else {
23207+ filter_intra_size_class_rect(bw, bh)
23208+ .expect("BLOCK_4X8/BLOCK_8X4 are inside av1_filter_intra_allowed_bsize")
23209+ };
23210+ let use_fi = dec.symbol(&mut cdfs.filter_intra[fi_class]);
23211+ if step {
23212+ eprintln!(
23213+ "EC_ISTEP mi_row={} mi_col={} name=use_filter_intra val={use_fi} rng={}",
23214+ lmi.0,
23215+ lmi.1,
23216+ dec.debug_state().0
23217+ );
23218+ }
23219+ if use_fi != 0 {
23220+ FILTER_INTRA_HITS.with(|c| c.set(c.get() + 1));
23221+ FILTER_INTRA_RECT_HITS.with(|c| c.set(c.get() + 1));
23222+ FILTER_INTRA_RECT_SUB8_HITS.with(|c| c.set(c.get() + 1));
23223+ let fi = dec.symbol(&mut cdfs.filter_intra_mode);
23224+ if step {
23225+ eprintln!(
23226+ "EC_ISTEP mi_row={} mi_col={} name=filter_intra_mode val={fi} rng={}",
23227+ lmi.0,
23228+ lmi.1,
23229+ dec.debug_state().0
23230+ );
23231+ }
23232+ filter_intra = Some(fi);
23233+ }
23234+ }
23235+ // `read_block_tx_size`' non-var-tx arm: an INTRA block of an inter frame
23236+ // reads `read_tx_size(allow_select = 1)` -- `bsize_to_tx_size_cat
23237+ // (BLOCK_4X8) == 0` (blockd.h:1344, depth table entry 1), the same
23238+ // 2-symbol category [`decode_leaf_rect8`] reads -- with the var-tx
23239+ // context bands, which on an inter frame are live.
23240+ // `block_signals_txsize(BLOCK_4X4)` is false (blockd.h:1027): the 4x4 leaf
23241+ // codes no depth symbol at all, its transform is its own size.
23242+ let depth = if tx_select && bw != bh {
23243+ let ctx = tx_size_context_txfm_rect(neighbours, lmi, bw, bh);
23244+ let d = dec.symbol(&mut cdfs.tx_size_cat0[ctx]);
23245+ if step {
23246+ eprintln!(
23247+ "EC_ISTEP mi_row={} mi_col={} name=tx_depth val={d} ctx={ctx} cat=0 rng={}",
23248+ lmi.0,
23249+ lmi.1,
23250+ dec.debug_state().0
23251+ );
23252+ }
23253+ d
23254+ } else {
23255+ 0
23256+ };
23257+ if depth != 0 {
23258+ TX_DEPTH_HITS.with(|c| c.set(c.get() + 1));
23259+ RECT8_SPLIT_TX_HITS.with(|c| c.set(c.get() + 1));
23260+ }
23261+ let split = depth != 0;
23262+ let (px, py) = (lmi.1 * MI, lmi.0 * MI);
23263+ let reach = if bw == bh {
23264+ Reach::of(bw, px, py, y.width, y.height)
23265+ } else {
23266+ Reach::of_rect(bw, bh, px, py, y.width, y.height)
23267+ };
23268+ let smooth_neighbor = is_smooth_mode(leaf_above) || is_smooth_mode(leaf_left);
23269+ if smooth_neighbor {
23270+ SMOOTH_LUMA_HITS.with(|c| c.set(c.get() + 1));
23271+ }
23272+ neighbours.record_mode_mi(lmi.0, lmi.1, w_mi, h_mi, mode);
23273+ let scan: &[u16] = if vert { &SCAN_4X8 } else { &SCAN_8X4 };
23274+ if split {
23275+ // `sub_tx_size_map[TX_4X8] == TX_4X4`: two 4x4 units along the long
23276+ // axis, each predicted off the previous one's reconstruction.
23277+ for tu in 0..2usize {
23278+ let tu_mi = if vert {
23279+ (lmi.0 + tu, lmi.1)
23280+ } else {
23281+ (lmi.0, lmi.1 + tu)
23282+ };
23283+ let (tu_px, tu_py) = (tu_mi.1 * MI, tu_mi.0 * MI);
23284+ let tu_reach = tu_reach(
23285+ bw,
23286+ bh,
23287+ tu_px - px,
23288+ tu_py - py,
23289+ 4,
23290+ reach,
23291+ px,
23292+ py,
23293+ y.width,
23294+ y.height,
23295+ );
23296+ if skip {
23297+ let zeros = vec![0i32; 16];
23298+ y.reconstruct(
23299+ tu_px, tu_py, 4, mode, angle_delta_y, tu_reach, &zeros, None, filter_intra,
23300+ smooth_neighbor,
23301+ );
23302+ neighbours.record_mi_luma(tu_mi, 4, &zeros);
23303+ continue;
23304+ }
23305+ let tu_around = neighbours.around_mi(tu_mi, 4)[0];
23306+ let tu_skip_ctx = neighbours.luma_skip_ctx(tu_mi, 1);
23307+ let tu_grid = read_plane(
23308+ dec,
23309+ cdfs,
23310+ if reduced_tx_set {
23311+ TxbSet::Luma4
23312+ } else {
23313+ TxbSet::Luma4Set1
23314+ },
23315+ scan4,
23316+ 0,
23317+ tu_around,
23318+ mode,
23319+ mode,
23320+ angle_delta_y,
23321+ tu_reach,
23322+ y,
23323+ tu_px,
23324+ tu_py,
23325+ 4,
23326+ TX4,
23327+ base_q_idx,
23328+ None,
23329+ filter_intra,
23330+ Some(tu_skip_ctx),
23331+ smooth_neighbor,
23332+ )?;
23333+ neighbours.record_mi_luma(tu_mi, 4, &tu_grid);
23334+ }
23335+ } else if bw == bh {
23336+ // A `BLOCK_4X4` leaf's luma TU *is* the whole block, so `get_txb_ctx`
23337+ // fixes `txb_skip_ctx` at 0 (`luma_skip_ctx: None`) -- the same square
23338+ // reader [`decode_leaf_split4`] uses.
23339+ if skip {
23340+ y.reconstruct(
23341+ px, py, 4, mode, angle_delta_y, reach, &vec![0i32; 16], None, filter_intra,
23342+ smooth_neighbor,
23343+ );
23344+ neighbours.record_mi_luma(lmi, 4, &vec![0i32; 16]);
23345+ } else {
23346+ let tu_around = neighbours.around_mi(lmi, 4)[0];
23347+ let tu_grid = read_plane(
23348+ dec,
23349+ cdfs,
23350+ if reduced_tx_set {
23351+ TxbSet::Luma4
23352+ } else {
23353+ TxbSet::Luma4Set1
23354+ },
23355+ scan4,
23356+ 0,
23357+ tu_around,
23358+ mode,
23359+ mode,
23360+ angle_delta_y,
23361+ reach,
23362+ y,
23363+ px,
23364+ py,
23365+ 4,
23366+ TX4,
23367+ base_q_idx,
23368+ None,
23369+ filter_intra,
23370+ None,
23371+ smooth_neighbor,
23372+ )?;
23373+ neighbours.record_mi_luma(lmi, 4, &tu_grid);
23374+ }
23375+ } else {
23376+ let grid_levels = if skip {
23377+ let zeros = vec![0i32; bw * bh];
23378+ y.reconstruct_rect(
23379+ px, py, bw, bh, mode, angle_delta_y, reach, &zeros, None, filter_intra,
23380+ smooth_neighbor,
23381+ );
23382+ zeros
23383+ } else {
23384+ // The leaf's luma TU *is* the leaf, so `get_txb_ctx` fixes
23385+ // `txb_skip_ctx` at 0.
23386+ let around = neighbours.around_mi_rect(lmi, bw, bh)[0];
23387+ let set = if reduced_tx_set {
23388+ TxbSet::LumaRect4x8
23389+ } else {
23390+ TxbSet::LumaRect4x8Set1
23391+ };
23392+ let mut coding = cdfs.txb(set, fi_tx_row(mode, filter_intra));
23393+ let (levels, tx_type) = read_coeffs_rect(
23394+ dec,
23395+ &mut coding,
23396+ scan,
23397+ bw,
23398+ bh,
23399+ 0,
23400+ dc_sign_ctx(around.2),
23401+ TxType::DctDct,
23402+ )?;
23403+ let residual = dequant_and_inverse_typed_wh(
23404+ &levels,
23405+ bw,
23406+ bh,
23407+ crate::decode::bit_depth(),
23408+ CURRENT_Q_IDX.with(|q| q.get()),
23409+ plane_q_delta(0).0,
23410+ plane_q_delta(0).1,
23411+ tx_type,
23412+ );
23413+ y.reconstruct_rect(
23414+ px, py, bw, bh, mode, angle_delta_y, reach, &residual, None, filter_intra,
23415+ smooth_neighbor,
23416+ );
23417+ levels
23418+ };
23419+ let state = neighbour_state(&grid_levels);
23420+ for cell in 0..h_mi {
23421+ if lmi.0 + cell < neighbours.mi_rows {
23422+ neighbours.left[lmi.0 + cell][0] = state;
23423+ }
23424+ }
23425+ for cell in 0..w_mi {
23426+ if lmi.1 + cell < neighbours.mi_cols {
23427+ neighbours.above[lmi.1 + cell][0] = state;
23428+ }
23429+ }
23430+ }
23431+ let (tx_w, tx_h) = if split { (4, 4) } else { (bw, bh) };
23432+ neighbours.fill_skip_grid_rect(lmi, w_mi, h_mi, skip);
23433+ neighbours.fill_lf_grid_rect(lmi, w_mi, h_mi, tx_w as u8, tx_h as u8, 0);
23434+ // `set_txfm_ctxs(tx_size, n4_w, n4_h, skip && is_inter == 0, xd)`: an
23435+ // intra block of an inter frame publishes its TRANSFORM dims, never its
23436+ // block dims (blockd.h). Missing this left the next block reading the
23437+ // previous block's band (the lane-intra16x4 finding for the 16x4 strip).
23438+ for i in 0..w_mi {
23439+ if let Some(cell) = neighbours.above_txfm.get_mut(lmi.1 + i) {
23440+ *cell = tx_w as u8;
23441+ }
23442+ }
23443+ for i in 0..h_mi {
23444+ if let Some(cell) = neighbours.left_txfm.get_mut(lmi.0 + i) {
23445+ *cell = tx_h as u8;
23446+ }
23447+ }
23448+ neighbours.above_mode[c] = mode;
23449+ neighbours.left_mode[r] = mode;
23450+ // The inter-side bands and the mi map, exactly as the square
23451+ // intra-in-inter block writes them: `is_inter = 0`, `INTRA_FRAME` ref, no
23452+ // interpolation filter, no skip mode.
23453+ neighbours.record_inter_rect_mi(lmi, w_mi, h_mi, skip, false, 0, [3, 3], false);
23454+ for dr in 0..h_mi {
23455+ for dc in 0..w_mi {
23456+ grid.set(
23457+ lmi.0 + dr,
23458+ lmi.1 + dc,
23459+ MiInfo {
23460+ is_inter: false,
23461+ ref_frame: -1,
23462+ ref_frame1: None,
23463+ mv1: None,
23464+ mv: (0, 0),
23465+ is_new_mv: false,
23466+ size: w_mi,
23467+ size_h: h_mi,
23468+ is_global_mv0: false,
23469+ is_global_mv1: false,
23470+ },
23471+ );
23472+ }
23473+ }
23474+ SUB8_INTRA_RECT_HITS.with(|h| {
23475+ let mut s = h.get();
23476+ s[usize::from(vert)] += 1;
23477+ s[2] += usize::from(has_chroma);
23478+ h.set(s);
23479+ });
23480+ if !has_chroma {
23481+ return Ok(mode);
23482+ }
23483+ // The group's single 4x4 chroma unit, intra-predicted from THIS
23484+ // (chroma-reference) sub-block's own `uv_mode` -- `is_sub8x8_inter`
23485+ // (reconinter_template.inc:54) returns false as soon as any mi of the
23486+ // group is intra, and the decoder reconstructs chroma with the
23487+ // chroma-reference block's own type. Same body as [`decode_leaf_rect8`]'s
23488+ // post-loop chroma.
23489+ let (gpx, gpy) = (gc * MI, gr * MI);
23490+ let (cpx, cpy) = (gpx / 2, gpy / 2);
23491+ let group_reach = Reach::of(8, gpx, gpy, y.width, y.height);
23492+ let smooth_neighbor_uv = neighbours.smooth_uv_neighbour(gr, gc, r, c);
23493+ let uv_predict_mode = if uv_mode == UV_CFL_PRED { DC_PRED } else { uv_mode };
23494+ let angle_delta_uv = 0;
23495+ neighbours.above_uv_mode[c] = uv_predict_mode;
23496+ neighbours.left_uv_mode[r] = uv_predict_mode;
23497+ neighbours.record_uv_mode_mi(gr, gc, 2, 2, uv_predict_mode);
23498+ let ac = alpha.map(|_| cfl_ac_q3(y, gpx, gpy, 8));
23499+ let (u_grid, v_grid): (Vec<i32>, Vec<i32>) = if skip {
23500+ if alpha.is_some() {
23501+ CHROMA_SKIP_CFL_HITS.with(|h| h.set(h.get() + 1));
23502+ SKIP_CFL_HITS.with(|c| c.set(c.get() + 1));
23503+ }
23504+ 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);
23505+ 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);
23506+ (vec![0i32; 16], vec![0i32; 16])
23507+ } else {
23508+ let chroma_around = neighbours.around_mi(group_mi, 8);
23509+ let ug = read_plane(
23510+ dec, cdfs, TxbSet::Chroma4, scan4, 1, chroma_around[1], uv_mode, uv_predict_mode,
23511+ angle_delta_uv, group_reach, u, cpx, cpy, 4, TX4, base_q_idx,
23512+ alpha.zip(ac.as_deref()).map(|((au, _), ac)| (au, ac)), None, None, smooth_neighbor_uv,
23513+ )?;
23514+ let vg = read_plane(
23515+ dec, cdfs, TxbSet::Chroma4, scan4, 2, chroma_around[2], uv_mode, uv_predict_mode,
23516+ angle_delta_uv, group_reach, v, cpx, cpy, 4, TX4, base_q_idx,
23517+ alpha.zip(ac.as_deref()).map(|((_, av), ac)| (av, ac)), None, None, smooth_neighbor_uv,
23518+ )?;
23519+ (ug, vg)
23520+ };
23521+ let round_up_even = |n: usize| n.div_ceil(2) * 2;
23522+ let bound_h = round_up_even(neighbours.mi_rows);
23523+ let bound_w = round_up_even(neighbours.mi_cols);
23524+ let u_state = neighbour_state(&u_grid);
23525+ let v_state = neighbour_state(&v_grid);
23526+ for cell in 0..2usize {
23527+ if cell < 2usize.min(bound_h.saturating_sub(gr)) {
23528+ neighbours.left[gr + cell][1] = u_state;
23529+ neighbours.left[gr + cell][2] = v_state;
23530+ }
23531+ if cell < 2usize.min(bound_w.saturating_sub(gc)) {
23532+ neighbours.above[gc + cell][1] = u_state;
23533+ neighbours.above[gc + cell][2] = v_state;
23534+ }
23535+ }
23536+ Ok(mode)
23537+}
23538+
23539+/// Decodes a `PARTITION_HORZ`/`PARTITION_VERT` of one 8x8 INTER block into two
23540+/// `BLOCK_8X4`/`BLOCK_4X8` inter leaves (lane-intersub8 r3) -- the inter twin of
23541+/// [`decode_leaf_rect8`] and the rectangular sibling of
23542+/// [`decode_inter_sub8_split4`], whose element order it follows exactly.
23543+/// Per sub-block, in libaom `decodemv.c` `read_inter_frame_mode_info` order:
23544+///
23545+/// * `segment_id`, `skip`, `cdef`/`delta_q`/`delta_lf`, `intra_inter`;
23546+/// * NO `skip_mode` symbol: `is_comp_ref_allowed(BLOCK_8X4)` is false
23547+/// (`av1_is_comp_ref_allowed` needs both sides >= 8), so
23548+/// `read_skip_mode` returns 0 without reading and `comp_mode` is never read
23549+/// either (`read_ref_frames`' `is_comp_ref_allowed` guard) -- single
23550+/// reference only;
23551+/// * NO `interintra` and NO `motion_mode`/OBMC/warp symbol: every one of those
23552+/// gates needs `block_size_wide >= 8 && block_size_high >= 8`
23553+/// (`is_interintra_allowed_bsize`, `motion_mode_allowed`), and one side is 4;
23554+/// * `read_mb_interp_filter` DOES run for both sub-blocks.
23555+///
23556+/// The shape's own differences from the four-way split:
23557+///
23558+/// * `block_signals_txsize(BLOCK_8X4)` is true (`bsize > BLOCK_4X4`,
23559+/// blockd.h:1027), so a non-skipped sub-block reads ONE `txfm_partition`
23560+/// symbol under `TX_MODE_SELECT` at `max_txsize_rect_lookup[BLOCK_8X4] ==
23561+/// TX_8X4` ([`read_var_tx_size`]); split resolves to two `TX_4X4` units
23562+/// (`sub_tx_size_map[TX_8X4] == TX_4X4`, libaom's early return), no split to
23563+/// the whole-leaf `TX_8X4`;
23564+/// * the luma coefficient set is [`TxbSet::LumaRect8x4Inter`] (the 8x8
23565+/// coefficient class with a 32-position `eob_pt` and the INTER `TX_4X4`
23566+/// `tx_type` row) for the whole-leaf unit, and the square
23567+/// [`TxbSet::Luma4Inter`] for a split `TX_4X4` unit;
23568+/// * chroma is coded ONCE, on the sub-block that is the chroma reference:
23569+/// `is_chroma_reference` (`av1_common_int.h`) is
23570+/// `((mi_row & 1) || !(bh4 & 1) || !ss_y) && ((mi_col & 1) || !(bw4 & 1) ||
23571+/// !ss_x)`, i.e. under 4:2:0 the BOTTOM 8x4 (`bh4 == 1`, odd) and the RIGHT
23572+/// 4x8 (`bw4 == 1`) -- always the second sub-block here;
23573+/// * that chroma unit's prediction is the sub8x8 one (`reconinter.c`
23574+/// `build_inter_predictors_sub8x8`: `row_start = -(block_size_high == 4 &&
23575+/// ss_y)`, `col_start = -(block_size_wide == 4 && ss_x)`), two 4x2 (HORZ) or
23576+/// 2x4 (VERT) chroma pieces, each from its OWN sub-block's reference, mv and
23577+/// interpolation filters.
23578+#[allow(clippy::too_many_arguments)]
23579+fn decode_inter_sub8_rect2(
23580+ dec: &mut SymbolDecoder,
23581+ cdfs: &mut Cdfs,
23582+ neighbours: &mut Neighbours,
23583+ grid: &mut MiGrid,
23584+ group_mi: (usize, usize),
23585+ vert: bool,
23586+ mi_cols: u32,
23587+ mi_rows: u32,
23588+ y: &mut PlaneBuf,
23589+ u: &mut PlaneBuf,
23590+ v: &mut PlaneBuf,
23591+ ref_y: &PlaneBuf,
23592+ ref_u: &PlaneBuf,
23593+ ref_v: &PlaneBuf,
23594+ other_refs: &RefSlots,
23595+ sign_bias_table: &SignBiasTable,
23596+ global_motion: &[ec_av1_syntax::WarpParams; 7],
23597+ base_q_idx: u8,
23598+ scan4: &[u16],
23599+ allow_high_precision_mv: bool,
23600+ force_integer_mv: bool,
23601+ interp_fixed: Option<mc::InterpFilterKind>,
23602+ enable_dual_filter: bool,
23603+ tpl_frame: Option<&TplFrameArgs>,
23604+ reduced_tx_set: bool,
23605+ frame_width: usize,
23606+) -> Result<()> {
23607+ const LAST_FRAME: i8 = 1;
23608+ // The 8x8 group's own square stride: both leaves' prediction buffers are
23609+ // laid out at it, as every other rect inter unit here is.
23610+ const SIDE: usize = 8;
23611+ let (bw, bh) = if vert { (4usize, 8usize) } else { (8usize, 4usize) };
23612+ let (w_mi, h_mi) = (bw / MI, bh / MI);
23613+ SUB8_INTER_RECT_HITS.with(|c| {
23614+ let mut h = c.get();
23615+ h[usize::from(vert)] += 1;
23616+ c.set(h);
23617+ });
23618+ let (gr, gc) = group_mi;
23619+ let (gpx, gpy) = (gc * MI, gr * MI);
23620+ let (cpx, cpy) = (gpx / 2, gpy / 2);
22875 // Per-sub-block state the group's one chroma unit predicts from.23621 // Per-sub-block state the group's one chroma unit predicts from.
22876 let mut piece: [Option<(i8, (i32, i32), mc::InterpFilterKind, mc::InterpFilterKind)>; 2] =23622 let mut piece: [Option<(i8, (i32, i32), mc::InterpFilterKind, mc::InterpFilterKind)>; 2] =
22877 [None; 2];23623 [None; 2];
22878 let mut first_tx_type = TxType::DctDct;23624 let mut first_tx_type = TxType::DctDct;
22879 let mut last_skip = true;23625 let mut last_skip = true;
23626+ // Set when the chroma-reference sub-block is INTRA: it coded the group's
23627+ // one chroma unit itself.
23628+ let mut intra_chroma = false;
22880 for i in 0..2usize {23629 for i in 0..2usize {
22881 let lmi = if vert { (gr, gc + i) } else { (gr + i, gc) };23630 let lmi = if vert { (gr, gc + i) } else { (gr + i, gc) };
22882 if lmi.0 >= mi_rows as usize || lmi.1 >= mi_cols as usize {23631 if lmi.0 >= mi_rows as usize || lmi.1 >= mi_cols as usize {
22883 continue;23632 continue;
22884 }23633 }
23634+ // libaom's `xd->above_mbmi`/`xd->left_mbmi` are the neighbour block as
23635+ // DECODED, so leaf 1 sees leaf 0's own `bsize` -- the group tail below
23636+ // publishes the side bands only once both leaves are done, which left
23637+ // leaf 1 reading whatever block preceded the GROUP. `get_tx_size_context`
23638+ // (pred_common.h:342) takes `block_size_wide[above_mbmi->bsize]` from it,
23639+ // so an intra 8x4 leaf 1 read `tx_size_cat0` row 1 where aomdec reads
23640+ // row 2 (class tx-grid-published-block-side).
23641+ if i == 1 {
23642+ if vert {
23643+ for cell in 0..h_mi {
23644+ neighbours.left_side_mi[gr + cell] = bh;
23645+ }
23646+ neighbours.above_side_mi[gc] = bw;
23647+ } else {
23648+ for cell in 0..w_mi {
23649+ neighbours.above_side_mi[gc + cell] = bw;
23650+ }
23651+ neighbours.left_side_mi[gr] = bh;
23652+ }
23653+ }
22885 let (rmi, cmi) = lmi;23654 let (rmi, cmi) = lmi;
22886 let (px, py) = (cmi * MI, rmi * MI);23655 let (px, py) = (cmi * MI, rmi * MI);
22887 inter_segment_id(dec, cdfs, rmi, cmi, w_mi, h_mi, false, true);23656 inter_segment_id(dec, cdfs, rmi, cmi, w_mi, h_mi, false, true);
@@ -22904,10 +23673,44 @@ fn decode_inter_sub8_rect2(
22904 );23673 );
22905 let is_inter = dec.symbol(&mut cdfs.intra_inter[ii_ctx]) == 1;23674 let is_inter = dec.symbol(&mut cdfs.intra_inter[ii_ctx]) == 1;
22906 if !is_inter {23675 if !is_inter {
22907- return Err(unsupported(23676+ if std::env::var_os("EC_SUB8INTRA").is_some() {
22908- "an intra 8x4/4x8 block inside an inter frame's sub-8x8 HORZ/VERT partition \23677+ eprintln!(
22909- (this decoder codes only inter sub-blocks there)",23678+ "EC_SUB8INTRA shape={}x{} sub={i} has_chroma={} skip={skip} mi={rmi},{cmi} tx_select={}",
22910- ));23679+ bw,
23680+ bh,
23681+ i == 1,
23682+ TX_SELECT_INTER.with(std::cell::Cell::get),
23683+ );
23684+ }
23685+ // lane-sub8x4 r2: refusal and bypass lifted -- see the split arm's
23686+ // note above for the gate that proves this leaf.
23687+ // Its chroma rule is `is_sub8x8_inter`'s: when the
23688+ // chroma-reference (second) sub-block is the intra one, the
23689+ // group's 4x4 chroma is coded and predicted INTRA there and the
23690+ // inter chroma tail below is skipped entirely.
23691+ decode_intra_sub8_leaf(
23692+ dec,
23693+ cdfs,
23694+ neighbours,
23695+ grid,
23696+ group_mi,
23697+ lmi,
23698+ (bw, bh),
23699+ i == 1,
23700+ skip,
23701+ scan4,
23702+ y,
23703+ u,
23704+ v,
23705+ base_q_idx,
23706+ ENABLE_FILTER_INTRA_INTER.with(std::cell::Cell::get),
23707+ TX_SELECT_INTER.with(std::cell::Cell::get),
23708+ reduced_tx_set,
23709+ )?;
23710+ if i == 1 {
23711+ intra_chroma = true;
23712+ }
23713+ continue;
22911 }23714 }
22912 if std::env::var_os("EC_TRACE_MODE").is_some() {23715 if std::env::var_os("EC_TRACE_MODE").is_some() {
22913 eprintln!(23716 eprintln!(
@@ -23167,10 +23970,13 @@ fn decode_inter_sub8_rect2(
23167 None,23970 None,
23168 )?23971 )?
23169 };23972 };
23170- if idx == 0 {23973+ if idx == 0 && (i == 0 || piece[0].is_none()) {
23171 // `av1_get_tx_type`: the group's one chroma unit scales23974 // `av1_get_tx_type`: the group's one chroma unit scales
23172 // back to luma (0, 0), i.e. the FIRST sub-block's first23975 // back to luma (0, 0), i.e. the FIRST sub-block's first
23173- // transform unit.23976+ // transform unit -- unless that sub-block is INTRA
23977+ // (lane-sub8intra), in which case it wrote no inter
23978+ // tx_type at all and `xd->tx_type_map[0]` of the
23979+ // chroma-reference block is this one's.
23174 first_tx_type = tu_tx_type;23980 first_tx_type = tu_tx_type;
23175 }23981 }
23176 neighbours.record_mi_luma_rect(tu_mi, tw, th, &tu_grid);23982 neighbours.record_mi_luma_rect(tu_mi, tw, th, &tu_grid);
@@ -23190,23 +23996,52 @@ fn decode_inter_sub8_rect2(
23190 neighbours.fill_skip_grid_rect(lmi, w_mi, h_mi, skip);23996 neighbours.fill_skip_grid_rect(lmi, w_mi, h_mi, skip);
23191 last_skip = skip;23997 last_skip = skip;
23192 }23998 }
23999+ // lane-sub8intra: when the chroma-reference sub-block was INTRA it coded
24000+ // and reconstructed the group's one chroma unit itself.
24001+ if !intra_chroma {
23193 // The group's single 4x4 chroma unit per plane, on the chroma-reference24002 // The group's single 4x4 chroma unit per plane, on the chroma-reference
23194 // (second) sub-block's own skip flag.24003 // (second) sub-block's own skip flag.
23195 const B4: usize = 4;24004 const B4: usize = 4;
23196 let mut pred_u = vec![0u16; B4 * B4];24005 let mut pred_u = vec![0u16; B4 * B4];
23197 let mut pred_v = vec![0u16; B4 * B4];24006 let mut pred_v = vec![0u16; B4 * B4];
23198- let (piece_w, piece_h) = if vert { (2usize, 4usize) } else { (4usize, 2usize) };24007+ // `is_sub8x8_inter` (reconinter_template.inc:54) is false as soon as ANY
24008+ // mi of the group is intra, so a group whose chroma reference is inter but
24009+ // whose sibling is INTRA does NOT get the two-piece sub8x8 prediction: the
24010+ // ordinary 8x8-and-bigger path predicts the WHOLE 4x4 chroma unit from the
24011+ // chroma-reference block's own mv, at the group's chroma origin
24012+ // (`row_start`/`col_start` shift `pre_x`/`pre_y` there either way).
24013+ let mixed = piece[0].is_none();
24014+ if mixed {
24015+ SUB8_INTRA_RECT_HITS.with(|h| {
24016+ let mut s = h.get();
24017+ s[3] += 1;
24018+ h.set(s);
24019+ });
24020+ }
24021+ let (piece_w, piece_h) = match (mixed, vert) {
24022+ (true, _) => (B4, B4),
24023+ (false, true) => (2usize, 4usize),
24024+ (false, false) => (4usize, 2usize),
24025+ };
23199 for i in 0..2usize {24026 for i in 0..2usize {
23200 let Some((ref_frame, mv, h_filter, v_filter)) = piece[i] else {24027 let Some((ref_frame, mv, h_filter, v_filter)) = piece[i] else {
23201 continue;24028 continue;
23202 };24029 };
23203 let (_, sref_u, sref_v) = ref_planes(ref_frame, ref_y, ref_u, ref_v, other_refs)?;24030 let (_, sref_u, sref_v) = ref_planes(ref_frame, ref_y, ref_u, ref_v, other_refs)?;
23204- let (ox, oy) = if vert {24031+ let (ox, oy) = if mixed {
24032+ (cpx, cpy)
24033+ } else if vert {
23205 (cpx + i * piece_w, cpy)24034 (cpx + i * piece_w, cpy)
23206 } else {24035 } else {
23207 (cpx, cpy + i * piece_h)24036 (cpx, cpy + i * piece_h)
23208 };24037 };
23209- let (dc, dr) = if vert { (i * piece_w, 0) } else { (0, i * piece_h) };24038+ let (dc, dr) = if mixed {
24039+ (0, 0)
24040+ } else if vert {
24041+ (i * piece_w, 0)
24042+ } else {
24043+ (0, i * piece_h)
24044+ };
23210 for (plane, dst) in [(sref_u, &mut pred_u), (sref_v, &mut pred_v)] {24045 for (plane, dst) in [(sref_u, &mut pred_u), (sref_v, &mut pred_v)] {
23211 let mut buf = vec![0u16; piece_w * piece_h];24046 let mut buf = vec![0u16; piece_w * piece_h];
23212 mc::predict_with_filters(24047 mc::predict_with_filters(
@@ -23248,13 +24083,6 @@ fn decode_inter_sub8_rect2(
23248 (ug, vg)24083 (ug, vg)
23249 };24084 };
23250 neighbours.record_uv_mode_mi(gr, gc, 2, 2, DC_PRED);24085 neighbours.record_uv_mode_mi(gr, gc, 2, 2, DC_PRED);
23251- // `update_partition_context` writes `partition_context_lookup[subsize]`
23252- // over the whole 8x8 span -- BLOCK_4X8's width above and height left, the
23253- // same values [`decode_leaf_rect8`] writes for the intra shape.
23254- for cell in 0..2usize {
23255- neighbours.above_side_mi[gc + cell] = bw;
23256- neighbours.left_side_mi[gr + cell] = bh;
23257- }
23258 let round_up_even = |n: usize| n.div_ceil(2) * 2;24086 let round_up_even = |n: usize| n.div_ceil(2) * 2;
23259 let bound_h = round_up_even(neighbours.mi_rows);24087 let bound_h = round_up_even(neighbours.mi_rows);
23260 let bound_w = round_up_even(neighbours.mi_cols);24088 let bound_w = round_up_even(neighbours.mi_cols);
@@ -23270,6 +24098,14 @@ fn decode_inter_sub8_rect2(
23270 neighbours.above[gc + cell][2] = v_state;24098 neighbours.above[gc + cell][2] = v_state;
23271 }24099 }
23272 }24100 }
24101+ }
24102+ // `update_partition_context` writes `partition_context_lookup[subsize]`
24103+ // over the whole 8x8 span -- BLOCK_4X8's width above and height left, the
24104+ // same values [`decode_leaf_rect8`] writes for the intra shape.
24105+ for cell in 0..2usize {
24106+ neighbours.above_side_mi[gc + cell] = bw;
24107+ neighbours.left_side_mi[gr + cell] = bh;
24108+ }
23273 Ok(())24109 Ok(())
23274 }24110 }
23275 24111
@@ -24123,18 +24959,25 @@ fn decode_inter_block8(
24123 // there before. Every leaf of the gate's stream is compound,24959 // there before. Every leaf of the gate's stream is compound,
24124 // so the 16x16 below a split block read partition ctx 024960 // so the 16x16 below a split block read partition ctx 0
24125 // instead of 1 and mis-read PARTITION_SPLIT as NONE.24961 // instead of 1 and mis-read PARTITION_SPLIT as NONE.
24126- // lane-vartxsplit r1: the COMPOUND twin of `decode_leaf8`'s24962+ // lane-sub8x4 r1: the same plane-0 save/restore the fall-through
24127- // `saved_luma_ctx` (class: twin functions drift). When the24963+ // (single-ref) path runs below -- a `split8` leaf's plane-0
24128- // leaf's transform split, `read_inter_luma8` returns an24964+ // neighbour context is per 4x4 transform unit (written by
24129- // all-zero placeholder grid and each 4x4 TU has already24965+ // `record_mi_luma` inside `read_inter_luma8`), and `record_mi`
24130- // written its own plane-0 coefficient state through24966+ // rewrites all three planes from the whole-block grid, which is
24131- // `record_mi_luma`; recording the placeholder over all three24967+ // all-zero in the split case. Missing here, a compound var-tx 8x8
24132- // planes erased those four cul_level/DC-sign cells, so the24968+ // leaf published level 0 to its right/below neighbours: the next
24133- // NEXT block read `dc_sign_ctx` 1 where libaom reads 0.24969+ // block's first TU read `skip_contexts[4][0] = 3` where aomdec
24970+ // reads `[4][4] = 6` (class early-return-skips-tail).
24134 let saved_luma_ctx = split8.then(|| {24971 let saved_luma_ctx = split8.then(|| {
24135 (24972 (
24136- [neighbours.left[leaf_mi.0][0], neighbours.left[leaf_mi.0 + 1][0]],24973+ [
24137- [neighbours.above[leaf_mi.1][0], neighbours.above[leaf_mi.1 + 1][0]],24974+ neighbours.left[leaf_mi.0][0],
24975+ neighbours.left[leaf_mi.0 + 1][0],
24976+ ],
24977+ [
24978+ neighbours.above[leaf_mi.1][0],
24979+ neighbours.above[leaf_mi.1 + 1][0],
24980+ ],
24138 )24981 )
24139 });24982 });
24140 neighbours.record_mi(leaf_mi, 8, &[luma_grid, u_grid, v_grid]);24983 neighbours.record_mi(leaf_mi, 8, &[luma_grid, u_grid, v_grid]);
@@ -24154,10 +24997,18 @@ fn decode_inter_block8(
24154 // dlist excludes it (3 luma samples on a 192x128 inter frame).24997 // dlist excludes it (3 luma samples on a 192x128 inter frame).
24155 INTER8_SKIP_BAND_HITS.with(|c| c.set(c.get() + 1));24998 INTER8_SKIP_BAND_HITS.with(|c| c.set(c.get() + 1));
24156 neighbours.fill_skip_grid(leaf_mi, 2, skip);24999 neighbours.fill_skip_grid(leaf_mi, 2, skip);
25000+ // lane-sub8x4 r2: `split8` is this leaf's OWN var-tx split, so
25001+ // the deblock grid must publish the TX_4X4 leaves' width the
25002+ // same way the fall-through arm below does (libaom
25003+ // `get_transform_size`, av1_loopfilter.c:207, reads the per-TU
25004+ // `inter_tx_size` for a non-skip inter luma block). Hardcoding
25005+ // 8 here left a compound var-tx 8x8 leaf's interior vertical
25006+ // edge at x % 8 == 4 unfiltered -- class early-return-skips-tail,
25007+ // third instance in this same arm.
24157 neighbours.fill_lf_grid(25008 neighbours.fill_lf_grid(
24158 leaf_mi,25009 leaf_mi,
24159 2,25010 2,
24160- 8,25011+ if split8 { 4 } else { 8 },
24161 if is_inter { leaf_refs.0.max(LAST_FRAME) } else { 0 },25012 if is_inter { leaf_refs.0.max(LAST_FRAME) } else { 0 },
24162 );25013 );
24163 return Ok((25014 return Ok((
crates/ec-av1/src/mvstack.rsmodified+32 -8
@@ -532,7 +532,10 @@ fn scan_row(
532 let Some(row) = mi_row.checked_add_signed(row_offset) else {532 let Some(row) = mi_row.checked_add_signed(row_offset) else {
533 return false;533 return false;
534 };534 };
535- let col_shift: usize = if row_offset.unsigned_abs() > 1 { 1 } else { 0 };535+ // libaom `scan_row_mbmi` (mvref_common.c:157): the shift steps BACK on an odd
536+ // mi_col when the block is narrower than 8px (a 4-wide 1:4 strip / sub-8x8 leaf).
537+ let col_shift: usize =
538+ if row_offset.unsigned_abs() > 1 && !(mi_col & 1 != 0 && bw4 < 2) { 1 } else { 0 };
536 let use_step_16 = bw4 >= 16;539 let use_step_16 = bw4 >= 16;
537 let end_mi = bw4.min(16);540 let end_mi = bw4.min(16);
538 let mut found = false;541 let mut found = false;
@@ -550,7 +553,10 @@ fn scan_row(
550 len = len.max(2);553 len = len.max(2);
551 }554 }
552 let mut weight = ROW_COL_WEIGHT_FLOOR;555 let mut weight = ROW_COL_WEIGHT_FLOOR;
553- if bw4 <= n4 {556+ // libaom `scan_row_mbmi` (mvref_common.c:172) gates this on
557+ // `xd->width >= mi_size_wide[BLOCK_8X8]` as well: a 4-wide block (a 1:4
558+ // strip, a sub-8x8 leaf) keeps weight 2 and leaves `processed_rows` alone.
559+ if bw4 >= 2 && bw4 <= n4 {
554 let inc = ((-max_row_offset + row_offset + 1) as usize).min(info.size_h);560 let inc = ((-max_row_offset + row_offset + 1) as usize).min(info.size_h);
555 weight = weight.max(inc as u32);561 weight = weight.max(inc as u32);
556 *processed_rows = (inc as isize - row_offset - 1).max(0) as usize;562 *processed_rows = (inc as isize - row_offset - 1).max(0) as usize;
@@ -614,7 +620,10 @@ fn scan_col(
614 let Some(col) = mi_col.checked_add_signed(col_offset) else {620 let Some(col) = mi_col.checked_add_signed(col_offset) else {
615 return false;621 return false;
616 };622 };
617- let row_shift: usize = if col_offset.unsigned_abs() > 1 { 1 } else { 0 };623+ // libaom `scan_col_mbmi` (mvref_common.c:206): same step-back on an odd mi_row
624+ // under a 4-high block.
625+ let row_shift: usize =
626+ if col_offset.unsigned_abs() > 1 && !(mi_row & 1 != 0 && bh4 < 2) { 1 } else { 0 };
618 let use_step_16 = bh4 >= 16;627 let use_step_16 = bh4 >= 16;
619 let end_mi = bh4.min(16);628 let end_mi = bh4.min(16);
620 let mut found = false;629 let mut found = false;
@@ -632,7 +641,10 @@ fn scan_col(
632 len = len.max(2);641 len = len.max(2);
633 }642 }
634 let mut weight = ROW_COL_WEIGHT_FLOOR;643 let mut weight = ROW_COL_WEIGHT_FLOOR;
635- if bh4 <= n4 {644+ // libaom `scan_col_mbmi` (mvref_common.c:222): `xd->height >=
645+ // mi_size_high[BLOCK_8X8]` gates this branch, so a 4-high block keeps
646+ // weight 2 and leaves `processed_cols` alone.
647+ if bh4 >= 2 && bh4 <= n4 {
636 let inc = ((-max_col_offset + col_offset + 1) as usize).min(info.size);648 let inc = ((-max_col_offset + col_offset + 1) as usize).min(info.size);
637 weight = weight.max(inc as u32);649 weight = weight.max(inc as u32);
638 *processed_cols = (inc as isize - col_offset - 1).max(0) as usize;650 *processed_cols = (inc as isize - col_offset - 1).max(0) as usize;
@@ -1362,7 +1374,10 @@ fn scan_row_compound(
1362 let Some(row) = mi_row.checked_add_signed(row_offset) else {1374 let Some(row) = mi_row.checked_add_signed(row_offset) else {
1363 return false;1375 return false;
1364 };1376 };
1365- let col_shift: usize = if row_offset.unsigned_abs() > 1 { 1 } else { 0 };1377+ // libaom `scan_row_mbmi` (mvref_common.c:157): the shift steps BACK on an odd
1378+ // mi_col when the block is narrower than 8px (a 4-wide 1:4 strip / sub-8x8 leaf).
1379+ let col_shift: usize =
1380+ if row_offset.unsigned_abs() > 1 && !(mi_col & 1 != 0 && bw4 < 2) { 1 } else { 0 };
1366 let use_step_16 = bw4 >= 16;1381 let use_step_16 = bw4 >= 16;
1367 let end_mi = bw4.min(16);1382 let end_mi = bw4.min(16);
1368 let mut found = false;1383 let mut found = false;
@@ -1380,7 +1395,10 @@ fn scan_row_compound(
1380 len = len.max(2);1395 len = len.max(2);
1381 }1396 }
1382 let mut weight = ROW_COL_WEIGHT_FLOOR;1397 let mut weight = ROW_COL_WEIGHT_FLOOR;
1383- if bw4 <= n4 {1398+ // libaom `scan_row_mbmi` (mvref_common.c:172) gates this on
1399+ // `xd->width >= mi_size_wide[BLOCK_8X8]` as well: a 4-wide block (a 1:4
1400+ // strip, a sub-8x8 leaf) keeps weight 2 and leaves `processed_rows` alone.
1401+ if bw4 >= 2 && bw4 <= n4 {
1384 let inc = ((-max_row_offset + row_offset + 1) as usize).min(info.size_h);1402 let inc = ((-max_row_offset + row_offset + 1) as usize).min(info.size_h);
1385 weight = weight.max(inc as u32);1403 weight = weight.max(inc as u32);
1386 *processed_rows = (inc as isize - row_offset - 1).max(0) as usize;1404 *processed_rows = (inc as isize - row_offset - 1).max(0) as usize;
@@ -1419,7 +1437,10 @@ fn scan_col_compound(
1419 let Some(col) = mi_col.checked_add_signed(col_offset) else {1437 let Some(col) = mi_col.checked_add_signed(col_offset) else {
1420 return false;1438 return false;
1421 };1439 };
1422- let row_shift: usize = if col_offset.unsigned_abs() > 1 { 1 } else { 0 };1440+ // libaom `scan_col_mbmi` (mvref_common.c:206): same step-back on an odd mi_row
1441+ // under a 4-high block.
1442+ let row_shift: usize =
1443+ if col_offset.unsigned_abs() > 1 && !(mi_row & 1 != 0 && bh4 < 2) { 1 } else { 0 };
1423 let use_step_16 = bh4 >= 16;1444 let use_step_16 = bh4 >= 16;
1424 let end_mi = bh4.min(16);1445 let end_mi = bh4.min(16);
1425 let mut found = false;1446 let mut found = false;
@@ -1437,7 +1458,10 @@ fn scan_col_compound(
1437 len = len.max(2);1458 len = len.max(2);
1438 }1459 }
1439 let mut weight = ROW_COL_WEIGHT_FLOOR;1460 let mut weight = ROW_COL_WEIGHT_FLOOR;
1440- if bh4 <= n4 {1461+ // libaom `scan_col_mbmi` (mvref_common.c:222): `xd->height >=
1462+ // mi_size_high[BLOCK_8X8]` gates this branch, so a 4-high block keeps
1463+ // weight 2 and leaves `processed_cols` alone.
1464+ if bh4 >= 2 && bh4 <= n4 {
1441 let inc = ((-max_col_offset + col_offset + 1) as usize).min(info.size);1465 let inc = ((-max_col_offset + col_offset + 1) as usize).min(info.size);
1442 weight = weight.max(inc as u32);1466 weight = weight.max(inc as u32);
1443 *processed_cols = (inc as isize - col_offset - 1).max(0) as usize;1467 *processed_cols = (inc as isize - col_offset - 1).max(0) as usize;
crates/ec-av1/src/refusal_inventory.rsmodified+0 -2
@@ -32,8 +32,6 @@ const REFUSALS: &[&str] = &[
32 "a coded HORZ/VERT strip whose chroma transform has no rect coefficient tables here",32 "a coded HORZ/VERT strip whose chroma transform has no rect coefficient tables here",
33 "a split intra strip whose transform unit is {tx_w}x{tx_h} (no luma coefficient tables for that shape here)",33 "a split intra strip whose transform unit is {tx_w}x{tx_h} (no luma coefficient tables for that shape here)",
34 "an OBMC neighbour whose switchable interp filter was never recorded",34 "an OBMC neighbour whose switchable interp filter was never recorded",
35- "an intra 4x4 block inside an inter frame's sub-8x8 split (this decoder codes only inter 4x4 sub-blocks there)",
36- "an intra 8x4/4x8 block inside an inter frame's sub-8x8 HORZ/VERT partition (this decoder codes only inter sub-blocks there)",
37 "a sub-8x8 inter block under a scaled reference (superres, unimplemented)",35 "a sub-8x8 inter block under a scaled reference (superres, unimplemented)",
38 "a rectangular inter luma transform unit whose shape has no coefficient table set here",36 "a rectangular inter luma transform unit whose shape has no coefficient table set here",
39 "a rectangular inter chroma transform unit whose shape has no coefficient table set here",37 "a rectangular inter chroma transform unit whose shape has no coefficient table set here",
crates/ec-av1/src/stream.rsmodified+664 -3
@@ -80,6 +80,19 @@ pub fn rect32x8_inter_tu_hits() -> [usize; 2] {
80 crate::decode::rect32x8_inter_tu_hits()80 crate::decode::rect32x8_inter_tu_hits()
81 }81 }
82 82
83+/// lane-intra16x4: `(16x4, 4x16, chroma-reference)` INTRA strips decoded inside
84+/// an inter 16x16-level 1:4 partition.
85+pub fn intra16x4_in_inter_hits() -> (usize, usize, usize) {
86+ crate::decode::intra16x4_in_inter_hits()
87+}
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, split
91+/// 4x4 leaves)`.
92+pub fn sub8_intra_rect_hits() -> (usize, usize, usize, usize, usize) {
93+ crate::decode::sub8_intra_rect_hits()
94+}
95+
83 /// lane-r14 r3: RECTANGULAR var-tx leaf transform units, `[32x16, 16x32]` --96 /// lane-r14 r3: RECTANGULAR var-tx leaf transform units, `[32x16, 16x32]` --
84 /// the leaves `sub_tx_size_map` produces when a 1:4 strip with a 64-px axis97 /// the leaves `sub_tx_size_map` produces when a 1:4 strip with a 64-px axis
85 /// splits its transform (`[TX_64X16] == TX_32X16`, `[TX_16X64] == TX_16X32`).98 /// splits its transform (`[TX_64X16] == TX_32X16`, `[TX_16X64] == TX_16X32`).
@@ -11047,6 +11060,321 @@ mod tests {
11047 }11060 }
11048 11061
11049 11062
11063+ #[test]
11064+ #[ignore = "RED at lane-intra16x4 r2, but NOT on this lane's shape: the r2 OBMC \
11065+ pair-merge fix makes the decode entropy-exact through the intra 16x4 strips \
11066+ (620/620 all_zero symbols match aomdec, value and range), and the new arm 4 \
11067+ (bar_h, cq63, --min-partition-size=8, 192x128, 5 strips) decodes 6 frames \
11068+ bit-exact vs ffmpeg outside the harness. Attempt 0 (noise, cq60, 128x128) \
11069+ still mismatches from (122, 13) -- 99 rows ABOVE its first strip, measured in \
11070+ r1 as another shape's defect -- and panics before arm 4 runs. Un-ignore once \
11071+ attempt 0's defect is owned -- lanes/intra16x4-r2.handoff.md"]
11072+ // lane-intra16x4 r1: an INTRA-coded 16x4 / 4x16 strip inside an INTER
11073+ // frame's 16x16-level 1:4 partition -- the wall all six of his film cuts
11074+ // stopped at once lane-rectres landed. The shape's chroma is the pair's:
11075+ // `is_chroma_reference` (av1_common_int.h:1454) is false on the even
11076+ // strips (which read no `uv_mode` and code no chroma at all) and the odd
11077+ // one codes ONE 8x4 (4x8) chroma unit at the pair's origin -- and when the
11078+ // pair mixes an intra and an inter strip, the chroma is predicted per the
11079+ // strip that CARRIES it, which is exactly what routing the intra strip
11080+ // through the key frame's own proven per-strip body
11081+ // (`decode_rect4_16_strip`) gives.
11082+ //
11083+ // Recipes found by a 24 + 24 run sweep (three sources x cq 16..63 x two
11084+ // sizes, `~/.cache/intra16x4-tmp/sweep*.sh`): aomenc only picks an INTRA
11085+ // 1:4 strip on an inter frame at HIGH cq over content its MC cannot
11086+ // predict -- a per-frame-random bright bar sweeping the frame (HORZ_4
11087+ // strips) and a `X*Y` product sinusoid under temporal noise (VERT_4).
11088+ // Both sources hash identically twice (report).
11089+ fn a_real_aomenc_inter_sequence_with_intra_16x4_strips_in_1to4_partitions_decodes_pixel_exact() {
11090+ const NAME: &str =
11091+ "a_real_aomenc_inter_sequence_with_intra_16x4_strips_in_1to4_partitions_decodes_pixel_exact";
11092+ let _gate_lock = lock_gate_counters();
11093+ if !have_ffmpeg() {
11094+ eprintln!("SKIP {NAME}: no ffmpeg");
11095+ return;
11096+ }
11097+ if !have_aomenc() {
11098+ eprintln!("SKIP {NAME}: no aomenc at {}", aomenc_path().display());
11099+ return;
11100+ }
11101+ let frame_count = 6usize;
11102+ // (source kind, cq, width, height) -- the four recipes of the 48-run
11103+ // sweep (`~/.cache/intra16x4-tmp/sweep*.sh`, table in the report) that
11104+ // reach an INTRA 1:4 strip on an inter frame. `bar` is a per-frame
11105+ // random bright bar sweeping the frame (its MC failure is what makes
11106+ // aomenc's RD pick intra at 16x4), `prod` an `X*Y` product sinusoid
11107+ // under temporal noise; `_v` transposes the structure so the RD picks
11108+ // PARTITION_VERT_4.
11109+ // lane-intra16x4 r2: the last field is `--min-partition-size` -- the
11110+ // `bar_h` recipe (a horizontal bar sweeping DOWN the frame) at
11111+ // `--min-partition-size=8` is the one recipe of the r2 96-run sweep
11112+ // (`~/.cache/intra16x4-tmp/sweep_r2.sh`) that fires intra 16x4 strips
11113+ // WITHOUT also carrying the sub-8x8 intra block another lane refuses,
11114+ // so it is the arm that can be pixel-compared at all.
11115+ const RECIPES: [(&str, u32, usize, usize, u32); 5] = [
11116+ ("noise", 60, 128, 128, 4),
11117+ ("bar", 60, 192, 128, 4),
11118+ ("prod_v", 56, 128, 128, 4),
11119+ ("prod", 56, 160, 128, 4),
11120+ ("bar_h", 63, 192, 128, 8),
11121+ ];
11122+ // [16x4 intra strips, 4x16 intra strips, of which chroma-reference]:
11123+ // how many pixel-exact attempts fired each, over both bit depths.
11124+ let mut arms_total = [0u32; 3];
11125+ // Attempts that refused on the sub-8x8 intra block inside an inter
11126+ // frame -- a DIFFERENT lane's shape, and the measured blocker of every
11127+ // VERT_4-carrying recipe in the sweep.
11128+ let mut sub8_intra_refusals = 0u32;
11129+ // Every failure the sweep sees, asserted ONCE at the end.
11130+ let mut failures: Vec<String> = Vec::new();
11131+ // Per bit depth: attempts that decoded at all, and attempts that fired an
11132+ // intra 1:4 strip AND compared pixel-exact.
11133+ let mut decoded_per_depth = [0u32; 2];
11134+ let mut fired_exact_per_depth = [0u32; 2];
11135+ for (depth_idx, bit_depth) in [8u32, 10u32].into_iter().enumerate() {
11136+ let (mut named_refusals, mut matched, mut out_of_scope, mut oos_mismatch) =
11137+ (0u32, 0u32, 0u32, 0u32);
11138+ let mut arms_proved = [0u32; 3];
11139+ for attempt in 0..RECIPES.len() as u32 {
11140+ let (kind, cq, width, height, min_part) = RECIPES[attempt as usize];
11141+ let duration = frame_count as f64 / 25.0;
11142+ // Both sources are deterministic (two identical y4m hashes,
11143+ // report): `random()` here is geq's own indexed PRNG and the
11144+ // noise filter carries an explicit `all_seed`.
11145+ let (lum, noise) = match kind {
11146+ "noise" => (
11147+ format!("128+58*sin((X+N*3)/6)+40*sin(Y/11)"),
11148+ ",noise=alls=40:allf=t+u:all_seed=7",
11149+ ),
11150+ "bar" => (
11151+ format!(
11152+ "if(lt(mod(X+N*37,{width}),24),random(N*100+X+Y)*255,128+50*sin(Y/7))"
11153+ ),
11154+ "",
11155+ ),
11156+ "bar_h" => (
11157+ format!(
11158+ "if(lt(mod(Y+N*37,{height}),24),random(N*100+X+Y)*255,128+50*sin(X/7))"
11159+ ),
11160+ "",
11161+ ),
11162+ "prod_v" => (
11163+ "128+60*sin((X*Y+N*97)/13)+50*sin((Y+N*11)/5)".to_string(),
11164+ ",noise=alls=25:allf=t:all_seed=11",
11165+ ),
11166+ _ => (
11167+ "128+60*sin((X*Y+N*97)/13)+50*sin((X+N*11)/5)".to_string(),
11168+ ",noise=alls=25:allf=t:all_seed=11",
11169+ ),
11170+ };
11171+ let source = format!(
11172+ "color=c=gray:s={width}x{height}:d={duration}:r=25,format=gray,\
11173+ geq=lum='{lum}',format=yuv420p{noise}"
11174+ );
11175+ let pix_fmt = if bit_depth == 10 { "yuv420p10le" } else { "yuv420p" };
11176+ let y4m = Command::new("ffmpeg")
11177+ .args([
11178+ "-v", "error", "-f", "lavfi", "-i", &source, "-t", &duration.to_string(),
11179+ "-pix_fmt", pix_fmt, "-strict", "-1", "-f", "yuv4mpegpipe", "-",
11180+ ])
11181+ .stdin(Stdio::null())
11182+ .stdout(Stdio::piped())
11183+ .stderr(Stdio::piped())
11184+ .output()
11185+ .expect("ffmpeg failed to run");
11186+ assert!(
11187+ y4m.status.success(),
11188+ "{NAME}: ffmpeg refused the {bit_depth}-bit fixture: {}",
11189+ String::from_utf8_lossy(&y4m.stderr)
11190+ );
11191+ let cq_arg = format!("--cq-level={cq}");
11192+ let min_part_arg = format!("--min-partition-size={min_part}");
11193+ let depth_arg = format!("--bit-depth={bit_depth}");
11194+ let input_depth_arg = format!("--input-bit-depth={bit_depth}");
11195+ let args: Vec<&str> = vec![
11196+ "--codec=av1", "--passes=1", "--end-usage=q", &cq_arg, "--cpu-used=0",
11197+ "--threads=1", "--row-mt=0", "--sb-size=64", &depth_arg, &input_depth_arg,
11198+ "--enable-restoration=0", "--enable-palette=0", "--deltaq-mode=0",
11199+ "--enable-filter-intra=0", "--enable-cfl-intra=0", "--enable-intrabc=0",
11200+ "--lag-in-frames=0", "--kf-max-dist=9999", "--tile-columns=0",
11201+ // Per-arm overrides go LAST (aomenc keeps the last
11202+ // occurrence of a repeated --enable-* flag).
11203+ "--enable-tx-size-search=1", "--enable-rect-partitions=1",
11204+ "--enable-ab-partitions=1", "--enable-1to4-partitions=1",
11205+ "--enable-intra-edge-filter=1",
11206+ &min_part_arg, "--max-partition-size=16",
11207+ "--obu", "-o", "-", "-",
11208+ ];
11209+ let mut child = Command::new(aomenc_path())
11210+ .args(&args)
11211+ .stdin(Stdio::piped())
11212+ .stdout(Stdio::piped())
11213+ .stderr(Stdio::piped())
11214+ .spawn()
11215+ .expect("aomenc failed to start");
11216+ child
11217+ .stdin
11218+ .take()
11219+ .expect("aomenc stdin")
11220+ .write_all(&y4m.stdout)
11221+ .expect("writing y4m to aomenc");
11222+ let out = child.wait_with_output().expect("aomenc failed to run");
11223+ assert!(
11224+ out.status.success(),
11225+ "aomenc refused the fixture: {}",
11226+ String::from_utf8_lossy(&out.stderr)
11227+ );
11228+ let stream = out.stdout;
11229+ let before = crate::stream::intra16x4_in_inter_hits();
11230+ let frames = match decode_stream(&stream) {
11231+ Err(e) => {
11232+ let msg = e.to_string();
11233+ // lane-intra16x4 r3: the ONLY refusals the 120-run sweep
11234+ // (`~/.cache/intra16x4-tmp/sweep_r3.sh`, table in the
11235+ // report) reaches over these recipes -- each another
11236+ // lane's shape. A refusal outside this list is a new wall
11237+ // and fails the gate rather than being counted.
11238+ const MEASURED_REFUSALS: [&str; 3] = [
11239+ "an intra 8x4/4x8 block inside an inter frame's sub-8x8 HORZ/VERT partition",
11240+ "an intra 4x4 block inside an inter frame's sub-8x8 split",
11241+ "an OBMC neighbour whose switchable interp filter was never recorded",
11242+ ];
11243+ if !MEASURED_REFUSALS.iter().any(|r| msg.contains(r)) {
11244+ failures.push(format!(
11245+ "{bit_depth}-bit attempt {attempt}: refusal outside the measured \
11246+ list: {msg}"
11247+ ));
11248+ continue;
11249+ }
11250+ if msg.contains("sub-8x8") {
11251+ sub8_intra_refusals += 1;
11252+ }
11253+ named_refusals += 1;
11254+ eprintln!("{bit_depth}-bit attempt {attempt} refusal: {msg}");
11255+ continue;
11256+ }
11257+ Ok(frames) => frames,
11258+ };
11259+ decoded_per_depth[depth_idx] += 1;
11260+ let after = crate::stream::intra16x4_in_inter_hits();
11261+ let fired = [
11262+ (after.0 - before.0) as u32,
11263+ (after.1 - before.1) as u32,
11264+ (after.2 - before.2) as u32,
11265+ ];
11266+ let ffmpeg_frames = if bit_depth == 10 {
11267+ ffmpeg_decode_sequence_10bit(&stream, width, height, frame_count)
11268+ } else {
11269+ ffmpeg_decode_sequence(&stream, width, height, frame_count)
11270+ };
11271+ assert_eq!(frames.len(), frame_count);
11272+ let mismatched = frames
11273+ .iter()
11274+ .zip(&ffmpeg_frames)
11275+ .any(|(got, want)| got.y != want.y || got.u != want.u || got.v != want.v);
11276+ if fired[0] + fired[1] == 0 {
11277+ out_of_scope += 1;
11278+ if mismatched {
11279+ oos_mismatch += 1;
11280+ eprintln!(
11281+ "{NAME}: {bit_depth}-bit attempt {attempt} MISMATCHES with zero \
11282+ intra 1:4 strip -- another shape's defect"
11283+ );
11284+ }
11285+ continue;
11286+ }
11287+ if mismatched {
11288+ for (i, (got, want)) in frames.iter().zip(&ffmpeg_frames).enumerate() {
11289+ let bad: Vec<usize> =
11290+ (0..got.y.len()).filter(|&k| got.y[k] != want.y[k]).collect();
11291+ if !bad.is_empty() {
11292+ eprintln!(
11293+ "{NAME}: attempt {attempt} {bit_depth}-bit frame {i}: {} luma \
11294+ pixels differ, first at ({}, {}), max |delta| {}",
11295+ bad.len(),
11296+ bad[0] % width,
11297+ bad[0] / width,
11298+ bad.iter()
11299+ .map(|&k| (got.y[k] as i32 - want.y[k] as i32).abs())
11300+ .max()
11301+ .unwrap_or(0)
11302+ );
11303+ }
11304+ }
11305+ }
11306+ // lane-intra16x4 r3: continue-and-sweep -- a mismatching attempt is
11307+ // RECORDED and the sweep goes on, so one arm's defect can no longer
11308+ // hide every later arm (r2's attempt 0 panicked before arm 4 ran).
11309+ // The end-of-sweep assert below fails on any recorded mismatch.
11310+ if mismatched {
11311+ failures.push(format!(
11312+ "{bit_depth}-bit attempt {attempt} (arms {fired:?}) mismatched ffmpeg"
11313+ ));
11314+ continue;
11315+ }
11316+ for a in 0..3 {
11317+ if fired[a] > 0 {
11318+ arms_proved[a] += 1;
11319+ arms_total[a] += 1;
11320+ }
11321+ }
11322+ matched += 1;
11323+ fired_exact_per_depth[depth_idx] += 1;
11324+ }
11325+ eprintln!(
11326+ "{NAME} ({bit_depth}-bit): {named_refusals} named refusals, {matched} pixel-exact \
11327+ attempts carrying an intra 1:4 strip, per-arm attempts \
11328+ 16x4/4x16/chroma-reference={arms_proved:?}, {out_of_scope} attempts carried none \
11329+ ({oos_mismatch} of them mismatched)"
11330+ );
11331+ if oos_mismatch > 0 {
11332+ failures.push(format!(
11333+ "{bit_depth}-bit: {oos_mismatch} attempt(s) with no intra 1:4 strip decoded \
11334+ but mismatched ffmpeg -- another shape's defect, not a pass"
11335+ ));
11336+ }
11337+ }
11338+ assert!(
11339+ failures.is_empty(),
11340+ "{NAME}: {} sweep failure(s): {failures:#?}",
11341+ failures.len()
11342+ );
11343+ // The counter must have fired on a pixel-exact attempt at every bit depth
11344+ // the sweep actually decoded at.
11345+ for (depth_idx, bit_depth) in [8u32, 10u32].into_iter().enumerate() {
11346+ assert!(
11347+ decoded_per_depth[depth_idx] == 0 || fired_exact_per_depth[depth_idx] > 0,
11348+ "{NAME}: {bit_depth}-bit decoded {} attempt(s) but none of them fired an intra \
11349+ 1:4 strip on a pixel-exact compare",
11350+ decoded_per_depth[depth_idx]
11351+ );
11352+ }
11353+ // MEASURED (48-run sweep, report table): every recipe that makes
11354+ // aomenc pick an intra PARTITION_VERT_4 strip ALSO contains an intra
11355+ // 8x4/4x8 or 4x4 block inside a sub-8x8 partition, a refusal this lane
11356+ // does not own -- so the 4x16 orientation is blocked on THAT and the
11357+ // gate asserts exactly that. If the sub-8x8 lane lands and this arm
11358+ // still reads 0, or the blocker changes, this fails.
11359+ assert!(
11360+ arms_total[1] > 0 || sub8_intra_refusals > 0,
11361+ "{NAME}: the 4x16 (PARTITION_VERT_4) arm read 0 \
11362+ (16x4/4x16/chroma-reference={arms_total:?}) and NO attempt refused on the sub-8x8 \
11363+ intra block -- its documented blocker is gone, so a zero arm is now unexplained"
11364+ );
11365+ for (a, what) in [
11366+ (0usize, "intra 16x4 strips (PARTITION_HORZ_4)"),
11367+ (2, "chroma-reference (odd) intra strips carrying the pair's 8x4/4x8 chroma"),
11368+ ] {
11369+ assert!(
11370+ arms_total[a] > 0,
11371+ "{NAME}: arm {a} ({what}) never fired on a pixel-exact attempt \
11372+ (16x4/4x16/chroma-reference={arms_total:?}) -- unproven"
11373+ );
11374+ }
11375+ }
11376+
11377+
11050 #[test]11378 #[test]
11051 // lane-sbab r1: the SUPERBLOCK-level (64x64) AB partitions on an INTER11379 // lane-sbab r1: the SUPERBLOCK-level (64x64) AB partitions on an INTER
11052 // frame -- PARTITION_HORZ_A/_HORZ_B/_VERT_A/_VERT_B at 64x64, i.e. two11380 // frame -- PARTITION_HORZ_A/_HORZ_B/_VERT_A/_VERT_B at 64x64, i.e. two
@@ -29587,8 +29915,11 @@ mod tests {
29587 /// here)". The moment TX_64X32/TX_32X64 luma coefficient tables land, drop29915 /// here)". The moment TX_64X32/TX_32X64 luma coefficient tables land, drop
29588 /// the `#[ignore]` -- everything else this gate needs (the reader, the29916 /// the `#[ignore]` -- everything else this gate needs (the reader, the
29589 /// counter, the two-frame pixel compare) is in place and runs.29917 /// counter, the two-frame pixel compare) is in place and runs.
29918+ ///
29919+ /// lane-sub8x4 r3: un-`#[ignore]`d. The sibling refusal it waited on (the
29920+ /// un-split TX_64X32/TX_32X64 corner unit) is lifted in this round, so the
29921+ /// frame this gate exists for now finishes.
29590 #[test]29922 #[test]
29591- #[ignore = "blocked on a SIBLING refusal, not on this lane: the film frame that carries the intra 1:4 strips (16x64=3) stops at \"a split intra strip whose transform unit is 64x32 (no luma coefficient tables for that shape here)\" -- un-ignore when the 64x32/32x64 luma coefficient tables land"]
29592 fn a_10bit_film_inter_frame_with_intra_1to4_strips_decodes_pixel_exact() {29923 fn a_10bit_film_inter_frame_with_intra_1to4_strips_decodes_pixel_exact() {
29593 const NAME: &str = "a_10bit_film_inter_frame_with_intra_1to4_strips_decodes_pixel_exact";29924 const NAME: &str = "a_10bit_film_inter_frame_with_intra_1to4_strips_decodes_pixel_exact";
29594 if !have_ffmpeg() {29925 if !have_ffmpeg() {
@@ -29616,15 +29947,345 @@ mod tests {
29616 now.2 - before.2,29947 now.2 - before.2,
29617 now.3 - before.329948 now.3 - before.3
29618 );29949 );
29619- assert_eq!(frames.len(), 2, "{NAME}: key frame + one inter frame");29950+ // lane-sub8x4 r3, MEASURED when this gate first RAN: the fixture has
29951+ // TWO frame OBUs but only ONE SHOWN frame -- a raw
29952+ // `ffmpeg -i <fixture> -pix_fmt yuv420p10le -f rawvideo` writes exactly
29953+ // 18524160 bytes, one 3840x1608 10-bit frame, so the second is a
29954+ // no-show frame and `frames.len() == 2` was never true. The compare is
29955+ // not vacuous: ffmpeg's own frame count is asserted equal to ours.
29956+ assert_eq!(frames.len(), 1, "{NAME}: one shown frame (the second frame OBU is a no-show)");
29620 assert_eq!((frames[0].width, frames[0].height), (width, height));29957 assert_eq!((frames[0].width, frames[0].height), (width, height));
29621 let ffmpeg_frames = ffmpeg_decode_sequence_10bit(&stream, width, height, frames.len());29958 let ffmpeg_frames = ffmpeg_decode_sequence_10bit(&stream, width, height, frames.len());
29959+ assert_eq!(
29960+ ffmpeg_frames.len(),
29961+ frames.len(),
29962+ "{NAME}: ffmpeg returned {} frames, we decoded {}",
29963+ ffmpeg_frames.len(),
29964+ frames.len()
29965+ );
29622 for (i, (ours, theirs)) in frames.iter().zip(&ffmpeg_frames).enumerate() {29966 for (i, (ours, theirs)) in frames.iter().zip(&ffmpeg_frames).enumerate() {
29623 assert_eq!(ours.y, theirs.y, "{NAME}: frame {i} luma vs ffmpeg");29967 assert_eq!(ours.y, theirs.y, "{NAME}: frame {i} luma vs ffmpeg");
29624 assert_eq!(ours.u, theirs.u, "{NAME}: frame {i} U vs ffmpeg");29968 assert_eq!(ours.u, theirs.u, "{NAME}: frame {i} U vs ffmpeg");
29625 assert_eq!(ours.v, theirs.v, "{NAME}: frame {i} V vs ffmpeg");29969 assert_eq!(ours.v, theirs.v, "{NAME}: frame {i} V vs ffmpeg");
29626 }29970 }
29627- eprintln!("{NAME}: {fired} intra 1:4 strips in an inter frame, both frames pixel-exact");29971+ eprintln!("{NAME}: {fired} intra 1:4 strips in an inter frame, the shown frame pixel-exact");
29972+ }
29973+
29974+ /// lane-sub8x4 r3: the FILM witness that lifts BOTH the intra 16x4/4x16
29975+ /// strip inside an inter 16x16-level 1:4 partition and the un-split
29976+ /// TX_64X32/TX_32X64 corner unit of a split intra strip.
29977+ ///
29978+ /// `crates/ec-av1/fixtures/reelb_rect64_intra16x4_witness.obu`, 23472 bytes,
29979+ /// sha256 `c9e721088766163b9dbeb9fa8dd8b257ff0ec7f9157fc350de4d3c33cd9ec4e4`:
29980+ /// the first 50 frame-carrying OBUs of `ffmpeg -ss 0 -t 2 -i <3840x1608
29981+ /// 10-bit AV1 HDR10 mkv> -c:v copy -f obu`, cut twice from independent
29982+ /// ffmpeg runs that hashed identically. 33 decode-order frames.
29983+ ///
29984+ /// MEASURED, and why no earlier round had this: r1/r2 of two lanes
29985+ /// reported "no firing witness exists" because every film frame that fires
29986+ /// these two arms ALSO carries a sub-8x8 intra leaf, which refused until
29987+ /// this lane's r2 lifted it. On that tip the whole 33-frame prefix decodes
29988+ /// with no refusal and matches ffmpeg on every plane of every frame, while
29989+ /// both arms fire: `intra16x4_in_inter` 16x4=31 4x16=17 chroma_ref=23 and
29990+ /// `rect64_corner_tu` 64x32=90 32x64=5. (The full 48-frame 2 s segment
29991+ /// diverges at decode-order frame 36, which is a separate wall; the
29992+ /// fixture is the exact prefix, not a truncation chosen to hide it.)
29993+ ///
29994+ /// Both refusal strings stay in `refusal_inventory` because both are
29995+ /// NARROWED, not deleted: "a split intra strip whose transform unit is
29996+ /// {tx_w}x{tx_h}" still stands for every shape other than 64x32/32x64, and
29997+ /// "an intra 16x4/4x16 strip inside an inter 16x16-level 1:4 partition"
29998+ /// still stands for a strip with no chroma-pair record.
29999+ #[test]
30000+ fn a_10bit_film_frames_with_intra_16x4_strips_and_rect64_corner_tus_decode_pixel_exact() {
30001+ const NAME: &str =
30002+ "a_10bit_film_frames_with_intra_16x4_strips_and_rect64_corner_tus_decode_pixel_exact";
30003+ if !have_ffmpeg() {
30004+ eprintln!("SKIP {NAME}: no ffmpeg");
30005+ return;
30006+ }
30007+ let path = std::path::Path::new(env!("CARGO_MANIFEST_DIR"))
30008+ .join("fixtures/reelb_rect64_intra16x4_witness.obu");
30009+ let stream = std::fs::read(&path)
30010+ .unwrap_or_else(|e| panic!("{NAME}: reading {}: {e}", path.display()));
30011+ let (width, height) = (3840usize, 1608usize);
30012+ let before16 = crate::decode::intra16x4_in_inter_hits();
30013+ let before64 = (
30014+ crate::decode::rect64_corner_tu_hits(0),
30015+ crate::decode::rect64_corner_tu_hits(1),
30016+ );
30017+ let frames = match decode_stream(&stream) {
30018+ Ok(frames) => frames,
30019+ Err(e) => panic!("{NAME}: decode_stream refused: {e}"),
30020+ };
30021+ let now16 = crate::decode::intra16x4_in_inter_hits();
30022+ let fired16 = (
30023+ now16.0 - before16.0,
30024+ now16.1 - before16.1,
30025+ now16.2 - before16.2,
30026+ );
30027+ let fired64 = (
30028+ crate::decode::rect64_corner_tu_hits(0) - before64.0,
30029+ crate::decode::rect64_corner_tu_hits(1) - before64.1,
30030+ );
30031+ // Hard counter asserts: neither lift may rest on a stream that stopped
30032+ // carrying its shape (class `tool-disabled-in-every-gate`).
30033+ assert!(
30034+ fired16.0 > 0 && fired16.1 > 0 && fired16.2 > 0,
30035+ "{NAME}: the intra 16x4/4x16 strip arm did not fire (16x4={} 4x16={} chroma_ref={})",
30036+ fired16.0,
30037+ fired16.1,
30038+ fired16.2
30039+ );
30040+ assert!(
30041+ fired64.0 > 0 && fired64.1 > 0,
30042+ "{NAME}: the un-split TX_64X32/TX_32X64 corner arm did not fire (64x32={} 32x64={})",
30043+ fired64.0,
30044+ fired64.1
30045+ );
30046+ assert_eq!(frames.len(), 33, "{NAME}: 33 decode-order frames");
30047+ assert_eq!((frames[0].width, frames[0].height), (width, height));
30048+ let ffmpeg_frames = ffmpeg_decode_sequence_10bit(&stream, width, height, frames.len());
30049+ assert_eq!(
30050+ ffmpeg_frames.len(),
30051+ frames.len(),
30052+ "{NAME}: ffmpeg returned {} frames, we decoded {}",
30053+ ffmpeg_frames.len(),
30054+ frames.len()
30055+ );
30056+ for (i, (ours, theirs)) in frames.iter().zip(&ffmpeg_frames).enumerate() {
30057+ assert_eq!(ours.y, theirs.y, "{NAME}: frame {i} luma vs ffmpeg");
30058+ assert_eq!(ours.u, theirs.u, "{NAME}: frame {i} U vs ffmpeg");
30059+ assert_eq!(ours.v, theirs.v, "{NAME}: frame {i} V vs ffmpeg");
30060+ }
30061+ eprintln!(
30062+ "{NAME}: 33 frames pixel-exact, intra16x4_in_inter 16x4={} 4x16={} chroma_ref={}, \
30063+ rect64_corner_tu 64x32={} 32x64={}",
30064+ fired16.0, fired16.1, fired16.2, fired64.0, fired64.1
30065+ );
30066+ }
30067+
30068+
30069+ /// lane-sub8x4 r2, the gate that lifts BOTH sub-8x8 intra refusals ("an
30070+ /// intra 4x4 block inside an inter frame's sub-8x8 split" and "an intra
30071+ /// 8x4/4x8 block inside an inter frame's sub-8x8 HORZ/VERT partition").
30072+ ///
30073+ /// Recipe (measured, `~/.cache/sub8intra-tmp/sweep3.sh`): a 24-row band of
30074+ /// per-frame-moving noise over a smooth sinusoid, `--min-partition-size=4
30075+ /// --max-partition-size=8 --enable-1to4-partitions=0` -- at that maximum a
30076+ /// 16x4 shape cannot exist, so nothing here can be confused with the
30077+ /// still-refused intra 1:4 strip, and the noise band is what makes aomenc's
30078+ /// RD pick INTRA leaves inside an inter frame's 8x8 groups. 12 arms
30079+ /// (8/10-bit x cq 48/55/63 x 128x128/192x128) plus one `--tile-columns=1`
30080+ /// arm (COMMON's neighbour-map rule: these leaves publish per-mi side
30081+ /// bands), 6 frames each, every decode-order frame and all three planes
30082+ /// compared against ffmpeg. Continue-and-sweep: a NAMED refusal is
30083+ /// recorded and the arm skipped, any other decode error or any pixel
30084+ /// mismatch fails the gate on the spot.
30085+ ///
30086+ /// The end-of-sweep assert reads all five
30087+ /// [`decode::sub8_intra_rect_hits`] cells -- 8x4 leaves, 4x8 leaves, the
30088+ /// chroma-reference ones (which code the group's 4x4 chroma intra),
30089+ /// `is_sub8x8_inter`-false MIXED groups, and the `PARTITION_SPLIT` 4x4
30090+ /// leaves (the second refusal's own arm) -- so neither lifted refusal
30091+ /// rests on a stream that never carried its shape.
30092+ #[test]
30093+ fn a_real_aomenc_inter_sequence_with_intra_sub8x8_leaves_decodes_pixel_exact() {
30094+ const NAME: &str = "a_real_aomenc_inter_sequence_with_intra_sub8x8_leaves_decodes_pixel_exact";
30095+ if !have_ffmpeg() {
30096+ eprintln!("SKIP {NAME}: no ffmpeg");
30097+ return;
30098+ }
30099+ if !have_aomenc() {
30100+ let msg = format!("no aomenc at {}", aomenc_path().display());
30101+ assert!(
30102+ std::env::var_os("EC_AV1_REQUIRE_AOMENC").is_none(),
30103+ "EC_AV1_REQUIRE_AOMENC is set but {msg}"
30104+ );
30105+ eprintln!("SKIP {NAME}: {msg}");
30106+ return;
30107+ }
30108+ const FRAMES: usize = 6;
30109+ // One arm's stream, byte for byte: the lavfi source (a moving 24-row
30110+ // random band over `128+50*sin(x/7)`) feeds aomenc through a pipe.
30111+ let encode = |depth: u32, cq: u32, width: usize, height: usize, tiles: bool| -> Vec<u8> {
30112+ let pix = if depth == 10 { "yuv420p10le" } else { "yuv420p" };
30113+ let source = format!(
30114+ "color=c=gray:s={width}x{height}:d=0.24:r=25,format=gray,\
30115+ geq=lum='if(lt(mod(Y+N*37\\,{height})\\,24)\\,random(N*100+X+Y)*255\\,128+50*sin(X/7))',\
30116+ format={pix}"
30117+ );
30118+ let y4m = Command::new("ffmpeg")
30119+ .args([
30120+ "-v", "error", "-f", "lavfi", "-i", &source, "-t", "0.24", "-pix_fmt", pix,
30121+ "-strict", "-1", "-f", "yuv4mpegpipe", "-",
30122+ ])
30123+ .stdin(Stdio::null())
30124+ .stdout(Stdio::piped())
30125+ .stderr(Stdio::piped())
30126+ .output()
30127+ .expect("ffmpeg failed to run");
30128+ assert!(
30129+ y4m.status.success(),
30130+ "{NAME}: ffmpeg fixture (depth={depth} cq={cq} {width}x{height}): {}",
30131+ String::from_utf8_lossy(&y4m.stderr)
30132+ );
30133+ let cq_arg = format!("--cq-level={cq}");
30134+ let mut args: Vec<&str> = vec![
30135+ "--codec=av1",
30136+ "--passes=1",
30137+ "--end-usage=q",
30138+ &cq_arg,
30139+ "--cpu-used=0",
30140+ "--threads=1",
30141+ "--row-mt=0",
30142+ "--sb-size=64",
30143+ "--enable-restoration=0",
30144+ "--enable-palette=0",
30145+ "--deltaq-mode=0",
30146+ "--enable-intrabc=0",
30147+ "--lag-in-frames=0",
30148+ "--kf-max-dist=9999",
30149+ "--enable-tx-size-search=1",
30150+ "--enable-rect-partitions=1",
30151+ // The 16x4/4x16 intra strip is a DIFFERENT (still refused)
30152+ // shape; keeping 1:4 off is what makes a refusal here mean
30153+ // this gate's own arm.
30154+ "--enable-1to4-partitions=0",
30155+ "--min-partition-size=4",
30156+ "--max-partition-size=8",
30157+ ];
30158+ if depth == 10 {
30159+ args.push("--bit-depth=10");
30160+ args.push("--input-bit-depth=10");
30161+ }
30162+ // AOMENC FLAG PRECEDENCE (COMMON): the per-arm override goes last.
30163+ args.push(if tiles { "--tile-columns=1" } else { "--tile-columns=0" });
30164+ args.extend(["--obu", "-o", "-", "-"]);
30165+ let mut child = Command::new(aomenc_path())
30166+ .args(&args)
30167+ .stdin(Stdio::piped())
30168+ .stdout(Stdio::piped())
30169+ .stderr(Stdio::piped())
30170+ .spawn()
30171+ .expect("aomenc failed to start");
30172+ child
30173+ .stdin
30174+ .take()
30175+ .expect("aomenc stdin")
30176+ .write_all(&y4m.stdout)
30177+ .expect("writing y4m to aomenc");
30178+ let out = child.wait_with_output().expect("aomenc failed to run");
30179+ assert!(
30180+ out.status.success(),
30181+ "{NAME}: aomenc refused the fixture (depth={depth} cq={cq} {width}x{height}): {}",
30182+ String::from_utf8_lossy(&out.stderr)
30183+ );
30184+ out.stdout
30185+ };
30186+
30187+ let mut refusals: Vec<String> = Vec::new();
30188+ let mut exact_arms = 0u32;
30189+ let mut fired = [0usize; 5];
30190+ let mut checked_reproducible = false;
30191+ let mut arms: Vec<(u32, u32, usize, usize, bool)> = Vec::new();
30192+ for depth in [8u32, 10] {
30193+ for cq in [48u32, 55, 63] {
30194+ for (w, h) in [(128usize, 128usize), (192usize, 128usize)] {
30195+ arms.push((depth, cq, w, h, false));
30196+ }
30197+ }
30198+ }
30199+ // lane-sub8x4 r3: the `--tile-columns=1` arm COMMON's neighbour-map
30200+ // rule asks for. It was excluded in r2 because it desynced at
30201+ // decode-order frame 4 -- identically with `--min-partition-size=16
30202+ // --max-partition-size=16`, i.e. with no sub-8x8 block at all. That was
30203+ // main's `1d2259c` (the saved motion field kept only the LAST tile's
30204+ // columns), merged into this lane in r3; the arm is restored here.
30205+ arms.push((8, 63, 192, 128, true));
30206+ for (depth, cq, width, height, tiles) in arms {
30207+ let arm = format!("depth={depth} cq={cq} {width}x{height} tiles={tiles}");
30208+ let stream = encode(depth, cq, width, height, tiles);
30209+ if !checked_reproducible {
30210+ // seeded-fixture-not-reproducible: prove the recipe names ONE
30211+ // stream before any measurement rests on it.
30212+ let again = encode(depth, cq, width, height, tiles);
30213+ assert_eq!(
30214+ stream, again,
30215+ "{NAME}: the fixture recipe is not reproducible ({arm}, {} vs {} bytes)",
30216+ stream.len(),
30217+ again.len()
30218+ );
30219+ checked_reproducible = true;
30220+ }
30221+ let before = decode::sub8_intra_rect_hits();
30222+ let tiles_before = decode::tile_hits();
30223+ let frames = match decode_stream(&stream) {
30224+ Ok(frames) => frames,
30225+ Err(e) => {
30226+ let msg = e.to_string();
30227+ assert!(
30228+ msg.starts_with("unsupported: "),
30229+ "{NAME}: decode error that is not a named refusal ({arm}): {msg}"
30230+ );
30231+ refusals.push(format!("{arm}: {msg}"));
30232+ continue;
30233+ }
30234+ };
30235+ assert_eq!(frames.len(), FRAMES, "{NAME}: {arm} decoded {} frames", frames.len());
30236+ assert!(
30237+ !tiles || decode::tile_hits() - tiles_before >= 2,
30238+ "{NAME}: {arm} decoded only {} tile(s)",
30239+ decode::tile_hits() - tiles_before
30240+ );
30241+ let theirs = if depth == 10 {
30242+ ffmpeg_decode_sequence_10bit(&stream, width, height, FRAMES)
30243+ } else {
30244+ ffmpeg_decode_sequence(&stream, width, height, FRAMES)
30245+ };
30246+ for (i, (ours, theirs)) in frames.iter().zip(&theirs).enumerate() {
30247+ assert_eq!(ours.y, theirs.y, "{NAME}: {arm} frame {i} luma vs ffmpeg");
30248+ assert_eq!(ours.u, theirs.u, "{NAME}: {arm} frame {i} U vs ffmpeg");
30249+ assert_eq!(ours.v, theirs.v, "{NAME}: {arm} frame {i} V vs ffmpeg");
30250+ }
30251+ let now = decode::sub8_intra_rect_hits();
30252+ let delta = [
30253+ now.0 - before.0,
30254+ now.1 - before.1,
30255+ now.2 - before.2,
30256+ now.3 - before.3,
30257+ now.4 - before.4,
30258+ ];
30259+ exact_arms += 1;
30260+ for (slot, d) in fired.iter_mut().zip(delta) {
30261+ *slot += d;
30262+ }
30263+ eprintln!(
30264+ "{NAME}: {arm} EXACT 8x4={} 4x8={} chroma_ref={} mixed={} split4x4={}",
30265+ delta[0], delta[1], delta[2], delta[3], delta[4]
30266+ );
30267+ }
30268+ assert!(
30269+ exact_arms >= 12,
30270+ "{NAME}: only {exact_arms} arm(s) decoded and compared exact; refusals:\n{}",
30271+ refusals.join("\n")
30272+ );
30273+ for (cell, what) in fired.iter().zip([
30274+ "intra 8x4 leaves",
30275+ "intra 4x8 leaves",
30276+ "chroma-reference intra leaves",
30277+ "is_sub8x8_inter-false MIXED groups",
30278+ "intra 4x4 leaves of a sub-8x8 PARTITION_SPLIT",
30279+ ]) {
30280+ assert!(
30281+ *cell > 0,
30282+ "{NAME}: zero {what} over {exact_arms} pixel-exact arms -- the lifted refusal \
30283+ rests on nothing (counters {fired:?})"
30284+ );
30285+ }
30286+ eprintln!(
30287+ "{NAME}: {exact_arms} arms pixel-exact over {FRAMES} frames each, counters {fired:?}"
30288+ );
29628 }30289 }
29629 30290
29630 }30291 }
lanes/intra16x4-r1.handoff.mdadded+72 -0
@@ -0,0 +1,72 @@
1+# lane-intra16x4 r1 HANDOFF (tip 17462bc + this file)
2+
3+Env bypass name is **`EC_INTRA16X4_DECODE=1`** (decode path) and `EC_INTRA16X4=1` (traces
4+only) — the coordinator's message says `EC_INTRA16X4`; the decode switch is the `_DECODE`
5+one. Default behaviour without it: the original refusal, unchanged.
6+
7+## Step 1 measurement (env print at the refusal site, `EC_INTRA16X4=1`, `EC_RECT64_SPLIT=1`)
8+
9+| probe | shape | pair parity | has_chroma | prev strip single-ref inter | skip | tx_select |
10+|---|---|---|---|---|---|---|
11+| 10-bit 3840x1608 cut 0 | 16x4 | 0 (even) | false | – | 0 | 1 |
12+| 10-bit 3840x1608 cut 300 | 4x16 | 0 | false | – | 0 | 1 |
13+| 10-bit 1920x792 @900 | 4x16 | 0 | false | – | 0 | 1 |
14+| 10-bit 1920x792 @5400 | 16x4 | 0 | false | – | 0 | 1 |
15+| 10-bit 1920x792 @6300 | 16x4 | 0 | false | – | 0 | 1 |
16+| 10-bit 1920x792 @8100 | 4x16 | 0 | false | – | 0 | 1 |
17+
18+6/6 fire first on an EVEN strip (`is_chroma_reference` false: no `uv_mode`, no chroma
19+residual), non-skip, `--enable-tx-size-search` on, no screen-content tools.
20+
21+## What the path implements (all in crates/ec-av1/src/decode.rs)
22+
23+* `decode_rect4_16_strip` — the per-strip body of the key frame's `decode_rect4_16`,
24+ lifted verbatim (mode info, luma whole-TU or split walk, the pair's single 8x4/4x8
25+ chroma on the ODD strip at the pair's origin, palette/skip/lf/partition bands).
26+ `decode_rect4_16` now calls it 4x — key-frame behaviour unchanged.
27+* `decode_intra_rect_in_inter(.., strip16: Option<(horz, has_chroma)>, ..)` — new 16x4/
28+ 4x16 arm running that body with `INTRA_IN_INTER_MODE = Some((0, skip))`
29+ (`size_group_lookup[BLOCK_16X4] == 0`, oracle `common_data.h:61`). Mixed intra/inter
30+ pairs need no new chroma code: the odd strip carries the pair's chroma predicted per
31+ its own type, and the inter side's `InterStripChroma::prev == None` arm already covers
32+ intra-then-inter.
33+* The inter arm ALSO publishes `set_txfm_ctxs` (`above_txfm`/`left_txfm` = tx_w/tx_h) and
34+ `txfm_partition_update_rect`, and reads tx-depth from `tx_size_context_txfm_rect`.
35+ The key-frame body publishes none of that; without it the block AFTER the strip broke
36+ while the strip's own pixels were exact (128x128 8-bit: strips at mi(23,16)/(23,20)
37+ exact, damage from row 96, chroma exact).
38+* Counter `intra16x4_in_inter_hits()` `[16x4, 4x16, chroma-reference]`, printed by
39+ `decode_probe`.
40+
41+## Pixel state under the bypass
42+
43+* 10-bit 3840x1608 cut 0: no longer stops here — 14 intra 16x4 strips decoded, then
44+ `an intra 8x4/4x8 block inside an inter frame's sub-8x8 HORZ/VERT partition`
45+ (another lane). Same new refusal on cuts 300 / @900 / @5400 / @6300; @8100 stops on
46+ `an intra-coded 16x4/4x16 strip on the inter block path` — that is the `_` arm of
47+ `decode_intra_rect_in_inter` reached by a CLIPPED (frame-edge) shape, not a 1:4 strip.
48+ No pixel comparison is possible on any cut: every firing frame also carries the
49+ sub-8x8 intra block, so no OBU prefix decodes clean (hg-0 prefixes 50 and 52 both
50+ refuse inside the same frame).
51+* aomenc witness, 8-bit 192x128 cq60 "bar" recipe (`~/.cache/intra16x4-tmp/s5.obu`,
52+ ref `ref5.yuv`, ours `ours5.yuv`): 6 frames decoded, frame 0 exact, **frame 1 LUMA
53+ mismatches from (175, 0), 8400 px**; the two intra strips themselves (mi(1,40) and
54+ mi(3,40) = px x160..175, y4..15) are exact and all chroma is exact. The first bad
55+ pixel is in the EVEN (inter) strip ABOVE them.
56+* The gate `a_real_aomenc_inter_sequence_with_intra_16x4_strips_in_1to4_partitions_
57+ decodes_pixel_exact` (stream.rs) is written, red, and `#[ignore]`d with that
58+ measurement in its reason string. No refusal lifted; refusal_inventory/gate_coverage
59+ untouched.
60+
61+## Exact next step
62+
63+1. Reproduce with `~/.cache/intra16x4-tmp/s5.obu` (recipe in the report). Ladder the msac
64+ RANGE (ours `EC_TRACE_COEFF` vs instrumented aomdec) across frame 1's superblock at
65+ mi_col 40, mi_row 0..3 — decide first whether the (175,0) damage is entropy or
66+ reconstruction; chroma being exact while luma is wrong argues reconstruction/deblock.
67+2. Prime suspects, in order: (a) the deblock grid the intra strip writes over the PAIR
68+ (its `fill_lf_grid_rect` runs at strip granularity while the caller's tail also
69+ records the block), (b) the mv/mi field the tail stamps (`is_inter: false, ref -1`)
70+ over rows the EVEN inter strip owns, (c) `above_side_mi`/`left_side_mi` partition
71+ context published twice (strip body + caller tail).
72+3. Only then re-run the gate; the 4x16 arm stays blocked on the sub-8x8 intra lane.
lanes/intra16x4-r1.report.mdadded+110 -0
@@ -0,0 +1,110 @@
1+# lane-intra16x4 r1 — an INTRA 16x4/4x16 strip inside an inter 16x16-level 1:4 partition
2+
3+## Step 1 MEASURE — what the six film probes actually stop on
4+
5+Env-gated print at the refusal site (`crates/ec-av1/src/decode.rs`, `EC_INTRA16X4=1`),
6+each probe under `systemd-run --scope -p MemoryMax=6G`, `EC_RECT64_SPLIT=1`:
7+
8+| probe | shape | pair parity | has_chroma | prev strip single-ref inter | skip | tx_select | screen tools |
9+|---|---|---|---|---|---|---|---|
10+| 10-bit 3840x1608 cut 0 | 16x4 | 0 (EVEN) | false | – | 0 | 1 | 0 |
11+| 10-bit 3840x1608 cut 300 | 4x16 | 0 | false | – | 0 | 1 | 0 |
12+| 10-bit 1920x792 @900 | 4x16 | 0 | false | – | 0 | 1 | 0 |
13+| 10-bit 1920x792 @5400 | 16x4 | 0 | false | – | 0 | 1 | 0 |
14+| 10-bit 1920x792 @6300 | 16x4 | 0 | false | – | 0 | 1 | 0 |
15+| 10-bit 1920x792 @8100 | 4x16 | 0 | false | – | 0 | 1 | 0 |
16+
17+6 of 6 first fire on an EVEN strip: `is_chroma_reference` false, so that strip reads no
18+`uv_mode` and codes no chroma at all. All non-skip, all with `--enable-tx-size-search`
19+on, none in a screen-content frame.
20+
21+EVIDENCE: shell probe, 6 streams | `EC_RECT64_SPLIT=1 EC_INTRA16X4=1 decode_probe <cut>` | 3x 16x4 + 3x 4x16, all pair-parity 0 / has_chroma=false / skip=0
22+
23+## Step 2 IMPLEMENT
24+
25+* `decode.rs` `decode_rect4_16_strip` (new) — the per-strip body of the KEY FRAME's
26+ `decode_rect4_16`, lifted verbatim into its own function (mode info, luma TU or split
27+ walk, the pair's 8x4/4x8 chroma when `has_chroma`, palette bands, skip/lf/partition
28+ bands). `decode_rect4_16` now calls it four times; no behaviour change on the key-frame
29+ path (the whole suite is the check).
30+* `decode.rs` `decode_intra_rect_in_inter` — new `strip16: Option<(horz, has_chroma)>`
31+ parameter and a 16x4/4x16 arm that runs that body with `INTRA_IN_INTER_MODE = Some((0,
32+ skip))`: `size_group_lookup[BLOCK_16X4] == size_group_lookup[BLOCK_4X16] == 0`
33+ (oracle `common_data.h:61`, indices 16/17), so the mode is `y_mode[0]` and `skip` is
34+ the one `decode_inter_block` already read. Chroma needs NO new code: the lifted body
35+ already codes one 8x4 (4x8) unit at the PAIR's origin on the odd strip only, which is
36+ exactly "predicted per the carrying strip's own type" for a mixed intra/inter pair;
37+ the inter side's `InterStripChroma::prev == None` arm already covers intra-then-inter.
38+* Same arm publishes what the key-frame body does not and an INTER frame needs
39+ (`set_txfm_ctxs` + `txfm_partition_update`, libaom `decodeframe.c:1078`): the strip's
40+ tx size into `above_txfm`/`left_txfm` and the var-tx partition context — the 2:1
41+ intra-in-inter strip already does this. On the inter path the tx-depth symbol also
42+ reads `tx_size_context_txfm_rect` (the real TXFM_CONTEXT bands) instead of the key
43+ frame's deblock-grid approximation.
44+* Counter `INTRA16X4_IN_INTER_HITS` `[16x4, 4x16, chroma-reference]`,
45+ `stream::intra16x4_in_inter_hits()`, printed by `decode_probe` as `intra16x4_in_inter:`.
46+
47+**The path is behind `EC_INTRA16X4_DECODE=1`; the refusal is still the default.** It is
48+not pixel-proven (below), and a refusal is lifted only with a green gate.
49+
50+## Step 3 GATE — RED, and what it measured
51+
52+`a_real_aomenc_inter_sequence_with_intra_16x4_strips_in_1to4_partitions_decodes_pixel_exact`
53+(`stream.rs`, `#[ignore]`d with its own measurement in the reason string): real aomenc,
54+`--enable-1to4-partitions=1 --enable-intra-edge-filter=1 --min-partition-size=4
55+--max-partition-size=16` (per-arm overrides last), 4 recipes x {8, 10} bit, every
56+decode-order frame Y/U/V vs ffmpeg, refusals counted never SKIPped, `oos_mismatch == 0`.
57+
58+Recipe search: 48 + 48 runs (`~/.cache/intra16x4-tmp/sweep.sh`, `sweep2.sh`, logs
59+`sweep.log`/`sweep2.log`/`sweep3.log`). aomenc picks an INTRA 1:4 strip on an inter frame
60+only at HIGH cq (>= 56) over content its MC cannot predict. Both gate sources hash
61+identically twice.
62+
63+RED, with the strips themselves exact:
64+
65+* 192x128 cq60 "bar" source, 8-bit, 4 intra 16x4 strips (2 chroma-reference): frame 0
66+ exact, frame 1 luma differs from (175, 0), 8400 px. The strips are at mi(1,40)/(3,40)
67+ = px x 160..175, y 4..15 — the first differing pixel is at y=0, i.e. in the EVEN
68+ (inter) strip ABOVE them, and chroma of the pair is exact.
69+* 128x128 cq60 "noise" source, 8-bit, 2 skipped intra 16x4 strips at px(80,112)/(80,120):
70+ frame 1 differs from (122, 13) — 99 rows ABOVE the first strip, so that arm's mismatch
71+ is not this shape at all (an unrelated defect this recipe exposes; the gate's
72+ `oos_mismatch` cannot separate it because the stream does carry strips).
73+* The txfm-context publication above was found the same way and DID fix a first
74+ measurement: before it, a 128x128 stream decoded its two intra strips at mi(23,16)/
75+ (23,20) exactly and broke on the very next 16x16 row (rows 96+, x>=62), chroma exact.
76+
77+EVIDENCE: /home/user/.cache/intra16x4-gate2.log + ~/.cache/intra16x4-tmp/{s4,s5}.obu | aomenc -> our decode -> ffmpeg raw compare, per frame | frame 1 first luma diff (175, 0) 8400 px with both intra strips' own pixels exact
78+
79+## Film frontier — before / after (with `EC_INTRA16X4_DECODE=1`)
80+
81+All six probes leave the 16x4/4x16 wall. Before: every one stopped on
82+`an intra 16x4/4x16 strip inside an inter 16x16-level 1:4 partition ...`.
83+After (counters are strips decoded):
84+
85+| probe | new refusal | intra16x4_in_inter |
86+|---|---|---|
87+| hg cut 0 | an intra 8x4/4x8 block inside an inter frame's sub-8x8 HORZ/VERT partition | 16x4=14 |
88+| hg cut 300 | same | 4x16=8 |
89+| 1920x792 @900 | same | 4x16=4 |
90+| 1920x792 @5400 | same | 16x4=1 4x16=2 |
91+| 1920x792 @6300 | same | 16x4=1 4x16=1 |
92+| 1920x792 @8100 | an intra-coded 16x4/4x16 strip on the inter block path (its `_` arm: a CLIPPED shape, not a 1:4 strip) | 4x16=4 |
93+
94+Since the walls are unproven pixel-wise, this is a REACH measurement, not a decode claim.
95+
96+EVIDENCE: 6 probes | `EC_RECT64_SPLIT=1 EC_INTRA16X4_DECODE=1 decode_probe <cut>` | refusal string moves to the sub-8x8 intra wall on 5 of 6, counters 1..14 strips each
97+
98+## Residue
99+
100+* fix-now (next round): the r1 gate is RED. The defect is NOT in the strip's own pixels
101+ (they match) but in what the strip leaves behind for its neighbours — after the
102+ txfm-context fix, the surviving mismatch starts in the pair's EVEN (inter) strip above
103+ the intra one, which points at the pair's chroma/mv bookkeeping or the deblock grid
104+ the intra strip publishes over the pair, not at its luma.
105+* deferred: `EC_RECT64_SPLIT` bypass removal — no witness; the rect64 hits still live
106+ inside frames that refuse (confirms lane-rect64port r1 and lane-rectres r1).
107+* deferred: the 4x16 (VERT_4) orientation is unprovable by aomenc today — every
108+ VERT_4-carrying recipe in the 96-run sweep also contains an intra 8x4/4x8 or 4x4
109+ sub-8x8 block, another lane's refusal. The gate asserts exactly that blocker.
110+* accepted: `refusal_inventory.rs` / `gate_coverage.rs` unchanged — no refusal was lifted.
lanes/intra16x4-r2.handoff.mdadded+67 -0
@@ -0,0 +1,67 @@
1+# lane-intra16x4 r2 HANDOFF
2+
3+## Root cause (found, fixed, minimal)
4+
5+`overlappable_above` / `overlappable_left` (`crates/ec-av1/src/decode.rs` ~18092 / ~18130)
6+never ported libaom's `mi_step == 1` chroma-pair merge from
7+`av1/common/obmc.h` (`foreach_overlappable_nb_above` / `foreach_overlappable_nb_left`).
8+Round 1's doc comment declared it unreachable ("no block this decoder codes is narrower
9+than 8px") -- the 1:4 partitions made it reachable: a 16x4 / 4x16 strip has
10+`mi_size_high` / `mi_size_wide` == 1, so libaom snaps the walk back to the pair's EVEN
11+index, reads the ODD (chroma-carrying) half as the neighbour and steps by 2.
12+
13+Witness `~/.cache/intra16x4-tmp/s5.obu`, frame 1, block mi(0,44) (16x16, right of a
14+16x16-level HORZ_4 whose strip 0 is inter and strips 1..3 intra):
15+
16+* our walk read mi(0,43) = the INTER strip 0 -> 1 overlappable neighbour ->
17+ `motion_mode_allowed` true -> we READ a `motion_mode` symbol;
18+* libaom's pair merge reads mi(1,43) = the INTRA strip 1 -> 0 overlappable neighbours ->
19+ `read_motion_mode` returns SIMPLE_TRANSLATION WITHOUT reading a symbol.
20+
21+Class `symbol-consumption-gap`: rng 39440 -> ours 34918, aomdec 38204 (its
22+`EC_ISTEP2 name=motion_mode` print is unconditional, so an equal rng there means the
23+symbol was NOT read). The tile desynced at the very next coefficient: the first TU of
24+mi(0,44) read `all_zero=1` where libaom reads `all_zero=0, eob=59`, which is the
25+"prediction only, no residual" smooth block at px(176..178, 0..15) the r1 pixel
26+measurement saw as "first luma diff (175,0), 8400 px".
27+
28+The fix is inside the two walk functions only -- every caller (eligibility at ~20908 and
29+~24493, the OBMC blend pass at ~18716/18746) routes through them.
30+
31+## Proof
32+
33+* Entropy ladder AFTER the fix, `s5.obu`, ours `EC_TRACE_COEFF` vs instrumented aomdec
34+ `EC_TRACE_COEFF`: 620/620 `tag=all_zero` symbols identical in value AND range, up to the
35+ point our decoder stops on another lane's refusal ("an intra 8x4/4x8 block inside an
36+ inter frame's sub-8x8 HORZ/VERT partition"). Before the fix the first divergence was the
37+ 4th block of frame 1's 3rd superblock row.
38+* New green witness (r2 96-run sweep `~/.cache/intra16x4-tmp/sweep_r2.sh`):
39+ `bar_h` source (a horizontal bar sweeping DOWN), cq 63, `--min-partition-size=8`,
40+ 192x128, 8-bit -> 5 intra 16x4 strips (2 chroma-reference), 6 frames decoded and
41+ `cmp` EXACT against `ffmpeg -i ... -f rawvideo` (`~/.cache/intra16x4-tmp/g_8.obu`,
42+ md5 `2eaafd9eb56fbf9d597820ad74c9c4e3`). The 10-bit build of the same recipe decodes
43+ 6 frames but fires 0 strips (out of scope).
44+
45+## Gate + refusal state
46+
47+`a_real_aomenc_inter_sequence_with_intra_16x4_strips_in_1to4_partitions_decodes_pixel_exact`
48+gained that recipe as attempt 4 (`RECIPES` is now 5-wide with a per-arm
49+`--min-partition-size`). Run once with `--include-ignored --nocapture`: **RED, and not on
50+this lane's shape** -- attempt 0 (`noise`, cq60, 128x128) mismatches from (122, 13),
51+5466 px on frame 1, which r1 already measured as 99 rows ABOVE that stream's first strip
52+(strips at px(80,112)/(80,120)); it panics before attempt 4 runs. The test is therefore
53+still `#[ignore]`d, with that measurement in its reason string.
54+
55+**The refusal is NOT lifted**: `EC_INTRA16X4_DECODE=1` is still the bypass,
56+`refusal_inventory.rs` / `gate_coverage.rs` untouched.
57+
58+## Next step
59+
60+1. Own attempt 0's defect (128x128 cq60 `noise`, first diff (122,13) frame 1, arms
61+ [2,0,0]) -- ladder it the same way; it is a DIFFERENT shape and it is the only thing
62+ between this lane and a green gate.
63+2. Then reorder/prune `RECIPES` (or make the mismatch of an out-of-scope-for-this-shape
64+ arm non-fatal only with a named owner), un-ignore, lift the refusal, update
65+ `refusal_inventory.rs` + `gate_coverage.rs`.
66+3. Not run this round (turn cap): the full `cargo test -p ec-av1 --lib` suite and the film
67+ probes.
lanes/intra16x4-r3.handoff.mdadded+97 -0
@@ -0,0 +1,97 @@
1+# lane-intra16x4 r3 HANDOFF
2+
3+## 1. Attempt 0 verdict: OURS, root cause found and fixed (mv stack, 4-wide / 4-high blocks)
4+
5+Stream reproduced exactly as gate attempt 0 (`~/.cache/intra16x4-tmp/gen_a0.sh 8` ->
6+`a0_8.obu`, md5 `0c9c588bb3d19f2feb2cecd31aa829fe`; 128x128 cq60 `noise`, 8-bit).
7+Before the fix: 6 frames decoded, `cmp` vs ffmpeg differs at byte 26363 = frame 1 (122,13).
8+
9+Ladder (ours `EC_TRACE_MODE`/`EC_TRACE_MODE_STEP`/`EC_TRACE_COEFF` vs instrumented aomdec,
10+same rungs) -- first diverging element is NOT a coefficient: the `tag=all_zero` ladder
11+diverges at #515, but the mode ladder diverges earlier, at frame 1 block **mi(24,15)**, the
12+last 4x16 strip of a 16x16-level `PARTITION_VERT_4`:
13+
14+| | stack |
15+|---|---|
16+| ours | (12,28) w648, (-4,26) w648, (-4,18) w8 -> mv0 (-4,18) |
17+| aomdec | (12,28) w**650**, (-4,18) w648, (-4,26) w8, (6,332) w4 -> mv0 (-4,26) |
18+
19+`crates/ec-av1/src/mvstack.rs` `scan_row` / `scan_col` (and their `_compound` twins) were
20+missing two clauses of libaom `scan_row_mbmi` / `scan_col_mbmi`
21+(`~/.cache/aom-oracle/src/av1/common/mvref_common.c:143-236`):
22+
23+1. the weight / `processed_rows` branch is `if (xd->width >= mi_size_wide[BLOCK_8X8] &&
24+ xd->width <= n4_w)` -- we had only `bw4 <= n4`, so a **4-wide / 4-high** block (exactly a
25+ 1:4 strip or a sub-8x8 leaf) got a raised weight AND set `processed_rows`, which also
26+ moves the later outer scans (that is the missing 4th candidate);
27+2. `if (abs(row_offset) > 1) { col_offset = 1; if ((mi_col & 0x01) && xd->width < 2)
28+ --col_offset; }` -- the step-back on an odd mi_col under a sub-8px block was absent.
29+
30+Both clauses ported at all four sites (row, col, row-compound, col-compound).
31+AFTER: `a0_8.obu` is entropy-exact -- all **125** aomdec `EC_MODE` entries match ours as an
32+ordered subsequence (ours prints 5 extra `EC_MODE` lines for intra strips aomdec does not
33+print) -- and the decode now stops on ANOTHER lane's named refusal,
34+`an intra 8x4/4x8 block inside an inter frame's sub-8x8 HORZ/VERT partition`, instead of
35+producing wrong pixels. Aligner: `~/.cache/intra16x4-tmp/align.py o_m2.log r_m.log`.
36+
37+## 2. r2's `g_8.obu` "6 frames bit-exact" claim is FALSE (measured, class stale-measurement)
38+
39+`~/.cache/intra16x4-tmp/g_8.obu` (md5 `2eaafd9eb56fbf9d597820ad74c9c4e3`, the r2 witness)
40+does NOT decode pixel-exact, and did not before this round's fix either: a build of the
41+**unmodified HEAD f403337** mvstack.rs mismatches at the same byte 53825 = frame 2, luma
42+(64,88). aomdec and ffmpeg agree with each other, so the reference is not in doubt.
43+
44+Its first diverging element (`EC_TRACE_COEFF`, all_zero #913) is a DIFFERENT shape, not this
45+lane's: frame 2 block **mi(14,12)**, an 8x8 compound leaf (`ref0=1 ref1=4`, mode 17).
46+Mode info is exact through the interp read (both at rng 34722); then aomdec reads var-tx
47+`txfm_split` symbols (rng 34722 -> 62656) and its first luma TU has `txb_skip ctx=6`, while
48+we read NO tx-split symbol at all and use `ctx=3`. Owner: the sub-8x8 / var-tx inter lane,
49+not intra16x4.
50+
51+## 3. Gate state
52+
53+`a_real_aomenc_inter_sequence_with_intra_16x4_strips_in_1to4_partitions_decodes_pixel_exact`
54+(`crates/ec-av1/src/stream.rs:11023`) rewritten to **continue-and-sweep**:
55+* named refusals accepted ONLY from a measured 3-string list (sub-8x8 HORZ/VERT intra,
56+ sub-8x8 split intra 4x4, OBMC-neighbour interp) -- anything else is a failure;
57+* a mismatching attempt is RECORDED and the sweep continues (r2's attempt 0 panicked before
58+ arm 4 ran); every decoding attempt compares every decode-order frame Y/U/V;
59+* ONE end-of-sweep assert over all recorded failures (mismatches + out-of-scope mismatches +
60+ unmeasured refusals), then a per-bit-depth assert that the counter fired on >= 1
61+ pixel-exact attempt at every depth that decoded anything.
62+Still `#[ignore]`d and the refusal is **NOT lifted**: `EC_INTRA16X4_DECODE=1` remains the
63+bypass, `refusal_inventory.rs` / `gate_coverage.rs` untouched -- because no recipe found so
64+far gives a pixel-exact attempt with the counter > 0 (see 4).
65+
66+Sibling gates run (`cargo test -p ec-av1 --lib -- 1to4 obmc mv_stack refusal_inventory
67+gate_coverage vartx_rect`): **26 passed, 2 failed, 5 ignored**. The two failures are the two
68+gates the ledger already records as known-red firing-assert/recipe defects on main
69+(`..._16x16_level_1to4_partitions...`: "VERT_4/split-tx-8x4 arms read 0";
70+`real_aomenc_1to4_streams_..._rect_vartx_leaves_fire`: "rect var-tx leaf arm never fired").
71+Neither is a pixel mismatch, and both fail on a 0-count arm, i.e. recipe, not decode.
72+
73+## 4. Sweep (PARTIAL -- stopped at the turn cap, 49 of 120 rows)
74+
75+`~/.cache/intra16x4-tmp/sweep_r3.sh` -> `sweep_r3_partial.txt`: 5 sources x cq 55/60/63 x
76+192x128|176x144 x --min-partition-size 8|4 x 8/10-bit. 49 rows done, ALL 8-bit.
77+**0 EXACT.** Every row is either a named refusal (sub-8x8 intra, overwhelmingly) or a
78+MISMATCH; the mismatching rows all have `16x4=0 4x16=0`, i.e. out-of-scope shapes.
79+`--min-partition-size=4` is what makes strips fire (up to `16x4=3 4x16=10 chroma_ref=7`) and
80+is also what brings the sub-8x8 intra refusal. 10-bit rows were not reached -- rerun the
81+script (it is idempotent; it appends) to finish rows 50..120.
82+
83+## 5. Films (with the fix, `EC_RECT64_SPLIT=1 EC_INTRA16X4_DECODE=1`)
84+
85+`hg-0` 16x4=14, `hg-300` 4x16=8, `t900` 4x16=4, `t5400` 0/0, `t8100` 0/0 -> all stop at
86+`an intra 8x4/4x8 block inside an inter frame's sub-8x8 HORZ/VERT partition`; `t6300`
87+(16x4=1 4x16=1) stops at `an OBMC neighbour whose switchable interp filter was never
88+recorded`. Same wall as r1 reported; no before/after frame counts measured this round.
89+
90+## Next step
91+
92+1. Finish the sweep (rows 50..120, the 10-bit half) looking for one EXACT row with a
93+ counter > 0. If none exists, this lane cannot lift its refusal until the sub-8x8 intra
94+ lane lands -- every strip-firing recipe found so far also carries that block.
95+2. The gate's arm list still contains the r2 `bar_h` arm 4 whose stream (`g_8.obu`) carries
96+ the frame-2 8x8-compound var-tx defect of section 2; it will be recorded as a mismatch
97+ until that lane's defect is fixed.
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).
lanes/sub8intra-r2.handoff.mdadded+73 -0
@@ -0,0 +1,73 @@
1+# lane-sub8intra r2 HANDOFF (tip = this commit)
2+
3+## The band: NOT a band -- the mv-stack's second-outer COLUMN scan (`mvstack.rs`)
4+
5+r1's suspects (above/left txfm, inter, ref, skip, y_mode, coeff, side-mi bands published by
6+the intra leaf) were ALL innocent. The first diverging symbol on the r1 witness
7+`~/.cache/sub8intra-tmp/x_1t_48_8_128x128.obu` is the `refmv` symbol of the INTER 8x4 leaf at
8+mi(23,14) -- the block whose LEFT neighbour is the intra leaf at mi(23,12..13). Same decoded
9+value (NEARESTMV), different CDF ROW (class `wrong-alphabet-same-value` / `cdf-row-held-constant`):
10+
11+* instrumented aomdec (private build, see below): `mode_ctx=75` -> newmv 3, globalmv 1, **refmv 4**
12+* ours before the fix: newmv 3, globalmv 1, **refmv 3** -> rng 62378 where the reference has 47820
13+
14+`refmv 4` vs `3` is `ref_match_count == 2` vs `1` in `setup_ref_mv_list`'s `case 1:` switch
15+(mvref_common.c:638): libaom's second-outer column scan (`col_offset = -3`) found an inter
16+match at mi(23,11), ours found none.
17+
18+## Two defects fixed (crates/ec-av1/src/mvstack.rs, all FOUR scan functions)
19+
20+Both are pure sub-8x8 (a side < 2 mi) defects; every block main decodes today has both sides
21+>= 8px in at least one of the two axes checked, which is why they survived until this lane.
22+
23+1. **`scan_col_mbmi`'s odd-row snap was missing** (`scan_col` L~600, `scan_col_compound` L~1406):
24+ libaom does `row_offset = 1; if ((mi_row & 0x01) && xd->height < n8_h_8) --row_offset;`.
25+ For an 8x4 leaf on an ODD mi row our walk probed the row BELOW (undecoded), losing the
26+ match. Fixed as `col_offset.unsigned_abs() > 1 && !(mi_row % 2 == 1 && bh4 < 2)`.
27+ Transposed twin fixed in `scan_row`/`scan_row_compound`
28+ (`(mi_col & 1) && xd->width < n8_w_8`).
29+2. **the weight / `processed_rows|cols` guard dropped libaom's `>= n8_*_8` half**:
30+ libaom `if (xd->height >= n8_h_8 && xd->height <= n4_h)`; ours was `if (bh4 <= n4)`, so a
31+ 1-mi-tall query block set `processed_cols` and a boosted weight libaom never sets (which can
32+ also suppress the second-outer scan entirely). Now `bh4 >= 2 && bh4 <= n4` (and `bw4` twin).
33+
34+`cargo check -p ec-av1`: clean.
35+
36+## Ladder result on x_1t_48_8_128x128.obu (EC_SUB8INTRA_DECODE=1)
37+
38+* mi(24,0) EC_MODE: ref 39238, ours **39238** (was 44268) -- matches.
39+* `tag=all_zero` ladder: **2106/2106 units identical in value AND range, all 6 frames**
40+ (`diff rz2.l oz2.l` empty). r1's ladder stopped matching at 1405.
41+* `OK: 6 frames decoded, 128x128`, `sub8_intra_rect: horz8x4=19 vert4x8=2 chroma_ref=10 mixed=3`.
42+* Pixels: 3 residual clusters (frame 3 two 4x4 luma, frames 4/5 one +-1 pixel triple) --
43+ root-caused to the OBMC `mi_step == 1` chroma-pair merge, which is **already fixed on
44+ lane-intra16x4 as f403337** (`overlappable_above`/`overlappable_left`). NOT duplicated here
45+ (charter: those functions belong to that lane). With f403337's decode.rs hunk applied on top of
46+ this commit the witness is **cmp-EXACT vs `ffmpeg -pix_fmt yuv420p` on all 6 frames**
47+ (verified, then reverted out of this tree).
48+
49+## Oracle instrumentation added (additive, env-gated `EC_SUB8CTX`)
50+
51+`av1/decoder/decodemv.c` in `~/.cache/aom-oracle/src`: one print after `read_ref_frames`
52+(single-ref p1 ctx + rng) and one after `read_inter_mode` (mode_ctx split into
53+newmv/globalmv/refmv + ref_mv_count). Built into the PRIVATE dir
54+`~/.cache/sub8intra-tmp/aom-build` (`ninja aomdec`); `~/.cache/aom-oracle/build` untouched.
55+This print is what named the band in one step -- keep it.
56+
57+## Next step (r3)
58+
59+1. Sweep `~/.cache/sub8intra-tmp/sweep3.sh` (max-partition-size=8, 1:4 off, 8- and 10-bit,
60+ cq 48/55/63, 128x128 + 192x128) -- 5 of 12 arms already decode all 6 frames pixel-EXACT
61+ (`10 cq48 128x128`, `10 cq48 192x128`, `10 cq55 128x128`, `10 cq63 128x128`,
62+ `8 cq55 192x128`). Those are the gate arms.
63+2. The other arms still stop at a refusal naming a shape the encoder cannot have coded
64+ (`--max-partition-size=8` + `--enable-1to4-partitions=0`) -- class `refusal-from-own-desync`,
65+ one desync left. Bisected on `g_8_48_128x128.obu`: first divergence at all_zero unit 1581,
66+ block mi(25,2) -- the reference reads `use_filter_intra=1`, `filter_intra_mode=3`,
67+ `tx_depth=1` for an INTRA sub-8x8 leaf there (ra2.l:4370-4372) which OUR path never reads;
68+ ours continues the previous block's 4x4 units instead. So: filter_intra IS read on a
69+ sub-8x8 intra leaf in that stream, and the `tx_depth=1` split (two TX_4X4) path is the
70+ one to check first.
71+3. Then: gate + refusal lift (both sub-8x8 intra refusals), refusal_inventory.rs +
72+ gate_coverage.rs, suite, films. Also still open: the flagged all-inter `first_tx_type`
73+ rule (blockd.h:1288, LAST sub-block vs first) -- unmeasured this round.
lanes/sub8x4-r1.handoff.mdadded+138 -0
@@ -0,0 +1,138 @@
1+# lane-sub8x4 r1 HANDOFF (tip = `bb79462`, branch lane-sub8x4)
2+
3+Two commits on top of c1df2f2 (= lane-intra16x4 r3):
4+
5+* `1845281` merge of `367d873` (lane-sub8intra r2) + the sub-8x8 sibling-size fix
6+* `bb79462` compound 8x8 leaf early-return fix
7+
8+## 1. STEP 0 -- how the merge was resolved
9+
10+`git merge 367d873` conflicted in ONE file, `crates/ec-av1/src/mvstack.rs`, at 8 hunks
11+(4 functions x 2 hunks: `scan_row`, `scan_col`, `scan_row_compound`, `scan_col_compound`).
12+Every hunk was the SAME libaom clause ported twice, once per lane, with different comment
13+wording and `if/else` vs `usize::from` spelling -- **semantically identical on both sides**:
14+
15+1. the outer-scan step-back, `mvref_common.c:155-158` (`scan_row_mbmi`) and `:203-206`
16+ (`scan_col_mbmi`): `if (abs(row_offset) > 1) { col_offset = 1; if ((mi_col & 0x01) &&
17+ xd->width < width_8x8) --col_offset; }` and its transpose;
18+2. the weight / `processed_rows|cols` guard, `mvref_common.c:172` and `:222`:
19+ `if (xd->width >= width_8x8 && xd->width <= n4_w)` / `if (xd->height >= n8_h_8 &&
20+ xd->height <= n4_h)` -- the `>= mi_size_*[BLOCK_8X8]` half is what both lanes added.
21+
22+Resolution: kept the HEAD (intra16x4 r3) spelling of all 8 hunks, which cites the libaom
23+line numbers; the sub8intra rationale is preserved in this file. Both sides' `bw4 >= 2 &&
24+bw4 <= n4` / `bh4 >= 2 && bh4 <= n4` guard lines were already identical and auto-merged.
25+All four functions were then re-read whole against `mvref_common.c:143-236`: `end_mi`,
26+`use_step_16`, `len` floors (`width_16x16` / `width_8x8`), the weight `inc`, the
27+`processed_*` update and the `i += len` step all match.
28+
29+`decode.rs`, `stream.rs`, `examples/decode_probe.rs` auto-merged clean (both lanes' code
30+kept: the intra 16x4 strip path + OBMC pair merge from intra16x4, `decode_intra_sub8_leaf`
31++ the sub-8x8 chroma guards from sub8intra). Both env bypasses (`EC_SUB8INTRA_DECODE`,
32+`EC_INTRA16X4_DECODE`) are still in place; no refusal lifted this round.
33+
34+`cargo check -p ec-av1`: clean. Named gates run after the merge
35+(`cargo test -p ec-av1 --lib -- obmc mv_stack 1to4 sub8 refusal_inventory gate_coverage`):
36+**32 passed, 2 failed, 5 ignored**. The two failures are the two gates the ledger already
37+records as known-red RECIPE defects on main -- `a_real_aomenc_inter_sequence_with_16x16_
38+level_1to4_partitions_decodes_pixel_exact` ("VERT_4 / split-tx-8x4 arms read 0") and
39+`real_aomenc_1to4_streams_..._rect_vartx_leaves_fire` ("the rectangular var-tx leaf arm
40+never fired"). Both fail on a zero counter, neither on a pixel mismatch.
41+
42+## 2. Two defects found and fixed (both post-merge, both root-caused by ladder)
43+
44+### (a) `decode_inter_sub8_rect2`: leaf 1 never saw leaf 0's block size (`1845281`)
45+
46+libaom's `xd->above_mbmi`/`left_mbmi` are the neighbour block AS DECODED, so leaf 1 of an
47+8x8 HORZ/VERT group sees leaf 0's own bsize. We published `above_side_mi`/`left_side_mi`
48+only in the GROUP tail (after both leaves), so leaf 1 read the block preceding the whole
49+group. `get_tx_size_context` (`pred_common.h:342`) takes `block_size_wide[above_mbmi->bsize]`
50+from there.
51+
52+Witness `~/.cache/sub8intra-tmp/g_8_48_128x128.obu`, mi(25,2) (intra 8x4 leaf 1):
53+ours `tx_depth` **ctx=1** vs aomdec **ctx=2**, same decoded value 1, rng 35938 vs 55960.
54+`EC_TXCTX=1` (new env print in `tx_size_context_txfm_rect`) showed `above_side=4` where the
55+above neighbour is an inter 8x4 leaf of width 8. Class `tx-grid-published-block-side`.
56+
57+Fix: publish the leaf-0 side bands at the top of iteration `i == 1` of the leaf loop
58+(`decode.rs`, `decode_inter_sub8_rect2`). The group tail rewrites the same values, so
59+partition context is unchanged.
60+
61+### (b) `decode_leaf8` COMPOUND arm's early return clobbered its own per-TU luma ctx (`bb79462`)
62+
63+The compound arm `return`s before the fall-through tail, and that tail is where the
64+`split8` plane-0 save/restore around `record_mi` lives. A compound var-tx 8x8 leaf therefore
65+published the whole-block luma grid (all-zero when the transform is split into 4x4 units,
66+since `read_inter_luma8`'s `record_mi_luma` already wrote the per-unit state) into
67+`above[..][0]`/`left[..][0]`.
68+
69+Witness `~/.cache/intra16x4-tmp/g_8.obu` frame 2 mi(14,12), first luma TU: ours
70+`txb_skip` ctx=3 rng=43376 vs reference ctx=6 rng=61310 -- `get_txb_ctx`
71+(`txb_common.h:330`) `skip_contexts[4][0]=3` vs `[4][4]=6`; the block left of it, mi(14,10),
72+is a compound 8x8 whose four TX_4X4 units all read ctx=6 correctly and then had their
73+published levels zeroed. Class `early-return-skips-tail`.
74+
75+Fix: the same save/restore in the compound arm before/after its `record_mi`.
76+
77+## 3. Measured state (probe sweep, both bypasses on)
78+
79+`~/.cache/sub8x4-tmp/check.sh <obu>...` (decode + `cmp` vs `ffmpeg -f rawvideo`),
80+12 sub-8x8-intra streams `~/.cache/sub8intra-tmp/g_{8,10}_{48,55,63}_{128x128,192x128}.obu`:
81+
82+| state | before this round | after (a) | after (b) |
83+|---|---|---|---|
84+| pixel-EXACT (6/6 frames) | 5/12 | 10/12 | 10/12 |
85+| stops at a refusal | 2/12 | 2/12 | **1/12** |
86+
87+Remaining non-EXACT: `g_8_63_128x128.obu` (mismatch) and `g_10_55_192x128.obu` (was
88+"Golomb tail longer than this decoder reads", now decodes all 6 frames and mismatches).
89+
90+`~/.cache/intra16x4-tmp/g_8.obu` is now **entropy-exact end to end**: 2215/2215 `all_zero`
91+units identical in value AND range vs instrumented aomdec, with equal counts -- yet its
92+pixels still differ (frame 1 first at luma (64,88), 1185 px, max delta 20; frames 2..5
93+150-235 px each). That is a **reconstruction-only** residue (prediction / OBMC blend /
94+loop filter), not entropy. This supersedes the r3 handoff's section-2 diagnosis, whose
95+named cause (the 8x8 compound var-tx read) is now fixed.
96+
97+## 4. STEP 1 list, unchanged / re-measured
98+
99+* (a) sub-8x8 INTRA leaf reads `use_filter_intra` (+ `filter_intra_mode`): **premise was
100+ STALE -- already implemented** by sub8intra r2 in `decode_intra_sub8_leaf`
101+ (`decode.rs:23101`). Proven: with the new `EC_TRACE_MODE_STEP` prints added there, ours
102+ reads `use_filter_intra=1 rng=51020` then `filter_intra_mode=3 rng=45380` at mi(25,2),
103+ **bit-identical to aomdec**. `av1_filter_intra_allowed_bsize` is `reconintra.h:68`
104+ (`block_size_wide <= 32 && block_size_high <= 32`), so 8x4/4x8/4x4 are all allowed. No
105+ angle delta below 8x8 is likewise already implemented. What was actually wrong at that
106+ block was the tx_depth CDF ROW -- fix (a) above.
107+* (b) 8x8 COMPOUND inter leaf var-tx `txfm_split`: **premise partly stale** -- we DO read
108+ the symbol (ours `txfm_split val=1 ctx=19 rng=62656`, reference reaches the same 62656).
109+ The real defect was the `txb_skip` ctx, fix (b) above. DONE.
110+* (c) the flagged all-inter sub-8x8 chroma `first_tx_type` rule (`blockd.h:1288`,
111+ tx_type_map rebased to the chroma-reference = LAST sub-block): **NOT MEASURED this
112+ round.** Still open.
113+
114+## 5. Next step (r2)
115+
116+1. Root-cause the two remaining non-EXACT sub-8x8 streams and `g_8.obu`'s
117+ reconstruction-only residue (entropy is exact, so start at prediction: OBMC blend,
118+ sub-8x8 chroma MC, or the deblock grid a sub-8x8 group publishes).
119+2. Then the gates: **no sub-8x8-intra gate test exists yet in `stream.rs`** (only the
120+ `sub8_intra_rect_hits()` accessor at `stream.rs:91` and the 1:4 gate's refusal count).
121+ It must be WRITTEN, continue-and-sweep, over the now 10 EXACT arms of
122+ `~/.cache/sub8intra-tmp/sweep3.sh` (`--max-partition-size=8 --enable-1to4-partitions=0
123+ --min-partition-size=4`, 8/10-bit x cq 48/55/63 x 128x128/192x128). Only then lift
124+ `EC_SUB8INTRA_DECODE` + the two refusals at `refusal_inventory.rs:35-36`.
125+3. intra 16x4: still no EXACT witness; re-run `~/.cache/intra16x4-tmp/sweep_r3.sh` (it is
126+ idempotent and appends) now that both fixes landed -- r3 measured 0 EXACT of 49 rows
127+ BEFORE them.
128+4. Not run this round (turn cap): full `cargo test -p ec-av1 --lib` suite, film probes.
129+
130+## 6. New instrumentation on this branch (env-gated, keep)
131+
132+* `EC_TXCTX=1` -- `tx_size_context_txfm_rect` prints `above_txfm/left_txfm/above_inter/
133+ left_inter/above_side/left_side/above/left`; named defect (a) in one run.
134+* `EC_TRACE_MODE_STEP` now also prints `use_filter_intra` / `filter_intra_mode` from
135+ `decode_intra_sub8_leaf` (it read them silently before, which is what made the r2
136+ handoff conclude they were unread).
137+* `EC_AV1_TRACE` `luma_skip_ctx` line now dumps the whole `left[..][0]` level band;
138+ that dump is what localised defect (b).
lanes/sub8x4-r2.handoff.mdadded+118 -0
@@ -0,0 +1,118 @@
1+# lane-sub8x4 r2 HANDOFF (tip = `2515eb1`, branch lane-sub8x4)
2+
3+Two commits on top of `94bda2f`:
4+
5+* `f0bd09d` fix: compound 8x8 leaf published transform width 8 to the deblock grid even
6+ when its var-tx split it into 4x4 units
7+* `2515eb1` feat: both sub-8x8 intra refusals lifted behind the new gate
8+
9+## STEP A -- DONE, gate GREEN, both refusals LIFTED
10+
11+### The last defect (root cause, class `early-return-skips-tail`, 3rd instance in that arm)
12+
13+`decode_inter_block8`'s COMPOUND early return called
14+`neighbours.fill_lf_grid(leaf_mi, 2, 8, ..)` with a LITERAL 8 where the fall-through
15+single-ref tail writes `if split8 { 4 } else { 8 }` (decode.rs, ~line 24990 vs ~25980).
16+libaom `get_transform_size` (av1_loopfilter.c:207) reads the per-TU `inter_tx_size` for a
17+non-skip inter LUMA block, so a var-tx-split 8x8's interior edges at `x % 8 == 4` are real
18+filter edges; ours never filtered them and widened the neighbouring x=64 edge from filter4
19+to filter8.
20+
21+Ladder that named it, on `~/.cache/sub8intra-tmp/g_8_63_128x128.obu`:
22+* `EC_OBMC` trace ours vs instrumented aomdec: **404 = 404 lines, byte-identical** (OBMC
23+ neighbour lists are exact -- do not re-audit them).
24+* `EC_AV1_PREFILT_DUMP` (ours, no `EC_AV1_DEBUG_SKIP_CDEF`) vs aomdec's: decode frames
25+ 0,1,2 **SAME**; only f3+ differ (propagation).
26+* `EC_AV1_POSTDEBLOCK_DUMP` both sides: frame 2 differs, 12 luma px at rows 78..80 cols
27+ 58..63, max delta 3 -> the deblocker is the stage.
28+* `EC_AV1_DEBLOCK_TRACE_V`: no `VEDGE x0=60` in frame 2 where frames 0/1/3 have one;
29+ `EC_TXGRID_TRACE` (new `EC_LFLEAF` line added this round in `fill_lf_grid_leaf_luma`)
30+ showed the 8x8 at mi(20,14) publishing `tx_px=8` with no leaf fill.
31+
32+Probe sweep `~/.cache/sub8intra-tmp/sweep3.sh` (12 streams): **10/12 -> 12/12 pixel-EXACT**.
33+
34+### The gate
35+
36+`a_real_aomenc_inter_sequence_with_intra_sub8x8_leaves_decodes_pixel_exact`
37+(`crates/ec-av1/src/stream.rs`, end of the test module).
38+
39+* 12 arms: 8/10-bit x cq 48/55/63 x 128x128/192x128, recipe copied from sweep3.sh
40+ (`--min-partition-size=4 --max-partition-size=8 --enable-1to4-partitions=0
41+ --enable-rect-partitions=1 --cpu-used=0 --sb-size=64 --lag-in-frames=0`), streams
42+ re-encoded BY the gate, first arm encoded twice and compared byte for byte.
43+* 6 decode-order frames per arm, all three planes, vs `ffmpeg_decode_sequence` /
44+ `_10bit`. Continue-and-sweep: only `unsupported: ` is recorded and skipped; any other
45+ error or ANY pixel mismatch fails.
46+* End-of-sweep asserts `exact_arms >= 12` and all five `sub8_intra_rect_hits` cells > 0.
47+* **Result: 12/12 arms EXACT, counters `[8x4=362, 4x8=80, chroma_ref=156, mixed=153,
48+ split4x4=98]`, 7.42 s.**
49+* `SUB8_INTRA_RECT_HITS` grew a 5th cell (split 4x4 leaves); `decode_probe` prints
50+ `split4x4=`.
51+
52+Lifted: `EC_SUB8INTRA_DECODE` (both sites) and the two refusal strings, removed from
53+`refusal_inventory.rs` in the same commit. `gate_coverage.rs` needed no edit (this gate
54+spells no tool flag that was previously never-on); `refusal_inventory` + all 12
55+`gate_coverage` tests pass.
56+
57+Siblings re-run (`-- sub8 obmc mv_stack 1to4 refusal_inventory gate_coverage`):
58+**33 passed, 2 failed, 5 ignored**. The 2 failures are the pre-existing zero-COUNTER
59+recipe defects this branch already carried (`..._16x16_level_1to4_partitions...`
60+stream.rs:10994, `real_aomenc_1to4_streams_..._rect_vartx_leaves_fire` stream.rs:8876);
61+neither is a pixel mismatch and neither moved this round.
62+
63+### NOT in the gate: the `--tile-columns=1` arm (measured, not assumed)
64+
65+The arm was written, run, and **failed** at decode-order frame 4 (12056 luma px). It then
66+failed IDENTICALLY with `--min-partition-size=16 --max-partition-size=16` (frame 3, 13256
67+luma px) -- a stream with no sub-8x8 block of any kind -- so this is a PRE-EXISTING
68+multi-tile defect, not this lane's bands. Streams pinned:
69+`~/.cache/sub8x4-tmp/tiles.obu` (sub-8x8) and `~/.cache/sub8x4-tmp/t16.obu` (none);
70+`diff.py` in the same dir prints per-frame/plane deltas. The gate carries the repro in a
71+comment with the one line to restore. This is the single most valuable open item.
72+
73+## STEP B -- NOT DONE, its premise is STALE
74+
75+`~/.cache/intra16x4-tmp/g_8.obu` is NOT an intra-16x4 witness: re-measured this round with
76+`EC_INTRA16X4_DECODE=1`, it reports `intra16x4_in_inter: 16x4=0 4x16=0 chroma_ref=0` and
77+still mismatches at byte 53825. Its mismatch is another shape's defect (the ledger already
78+records the same stream as never-exact on unmodified HEAD). There is no firing witness at
79+all: the r3 49-row sweep found 0 EXACT rows and every row had `16x4=0`. Next step for B is
80+therefore NOT the prediction/OBMC/deblock comparison in the charter -- it is finding a
81+stream where the counter fires AND the rest of the frame is clean (r1's dead-end: every
82+firing film frame also carries a sub-8x8 intra block -- which is now DECODABLE, so re-run
83+`~/.cache/intra16x4-tmp/films.sh` and the reelb0-5x prefixes on this tip: that dead-end may
84+have expired with this commit).
85+
86+## STEP C -- suite armed, not read
87+
88+Unit `sub8x4-suite-r2-1788363069.service`, log **`$HOME/.cache/sub8x4-suite.log`**.
89+Check with a single `grep -E "^test result|FAILED" $HOME/.cache/sub8x4-suite.log`.
90+
91+## STEP D -- NOT RUN (turn cap). No film probe, no `EC_RECT64_SPLIT` measurement, no
92+fixture pinned. Inputs are in place: `~/.cache/hg-0.obu`, `~/.cache/hg-300.obu`,
93+`~/.cache/intra16x4-tmp/reelb0-{50,52,55}.obu`.
94+
95+## Next step, in order
96+
97+1. Read the suite log; if a gate outside this lane's files is red, bisect against `94bda2f`.
98+2. Re-run the film/reelb0 probes on this tip (STEP D) -- the sub-8x8 intra lift removes one of
99+ the two walls the r1 film sweep hit, so the refusal STRING each cut stops at has moved.
100+3. The multi-tile defect above (own lane; it is not sub-8x8 specific and it blocks the
101+ neighbour-map arm COMMON asks every lane for).
102+
103+## ADDENDUM (measured after the handoff above, while the suite ran)
104+
105+The suite's first failure is `a_frame_edge_straddling_band_decodes_pixel_exact`, and it is
106+NOT a regression: `git log --oneline main --not HEAD` shows this branch is missing main's
107+`1d2259c` ("the saved motion field kept only the LAST tile's columns --
108+`av1_copy_frame_mvs` read the mi grid through the per-tile reach clamp") and its merge
109+`9cca16e`. That gate is green on main only because of that commit; the charter forbids
110+rebasing this lane onto it.
111+
112+**Strong lead:** that same missing commit is the most likely cause of THIS lane's
113+multi-tile desync too -- a 2-tile-column stream whose temporal MV candidates come from the
114+saved motion field, going wrong only from decode-order frame 3/4 (i.e. the first frames
115+that read a motion field saved by a MULTI-TILE frame), with tile 1's pixels exact. Before
116+spending a round on it: merge main into the lane (or cherry-pick `1d2259c`), then re-run
117+`~/.cache/sub8x4-tmp/tiles.obu` + `t16.obu` and, if clean, restore the one commented-out
118+`arms.push((8, 63, 192, 128, true));` line in the gate.
lanes/sub8x4-r3.report.mdadded+111 -0
@@ -0,0 +1,111 @@
1+# lane-sub8x4 r3 report (branch `lane-sub8x4`, tip `f38f963`)
2+
3+Merged `main` @ `9cca16e` (clean auto-merge, **zero conflicts** -- no hand-resolved
4+function to re-read), then two commits.
5+
6+## r2 suite line (the unit that was still running at the start of this round)
7+
8+`test result: FAILED. 419 passed; 3 failed; 38 ignored; 0 measured; 0 filtered out; finished in 674.52s`
9+
10+The 3: `a_frame_edge_straddling_band_decodes_pixel_exact` (main's `1d2259c` was missing
11+from the lane -- fixed by the merge, see below) plus the two pre-existing zero-COUNTER
12+recipe defects this branch already carried (`..._16x16_level_1to4_partitions...`
13+stream.rs:11002, `real_aomenc_1to4_streams_..._rect_vartx_leaves_fire` stream.rs:8884).
14+Neither of those two is a pixel mismatch and neither moved this round.
15+
16+## STEP 1 -- `13cd475`: the `--tile-columns=1` arm is back, and r2's premise was right
17+
18+r2 excluded the arm with a measurement (desync at decode-order frame 4, identical with
19+`--min-partition-size=16 --max-partition-size=16`, i.e. a stream with no sub-8x8 block at
20+all) and named the suspect: main's `1d2259c`, "the saved motion field kept only the LAST
21+tile's columns -- `av1_copy_frame_mvs` read the mi grid through the per-tile reach clamp".
22+Confirmed: with the merge the arm is pixel-exact and the gate now carries the neighbour-map
23+tile arm COMMON asks every lane for (13 arms).
24+
25+EVIDENCE: crates/ec-av1/src/stream.rs:30038-30044 | `cargo test -p ec-av1 --lib -- sub8 straddling obmc mv_stack 1to4 refusal_inventory gate_coverage` | `34 passed; 2 failed; 5 ignored` in 141.28s -- the 2 are the same two recipe defects above; `a_real_aomenc_inter_sequence_with_intra_sub8x8_leaves_decodes_pixel_exact` and `a_frame_edge_straddling_band_decodes_pixel_exact` both green
26+
27+## STEP 2 -- film probes (release probe, each under `systemd-run --scope MemoryMax=6G`)
28+
29+**The r1/r2 "no witness exists" dead-end EXPIRED**, exactly as this lane's r2 predicted:
30+every firing frame also carried a sub-8x8 intra leaf, which refused until r2 lifted it.
31+
32+| cut | frames / wall | `intra16x4_in_inter` 16x4/4x16/chroma | `rect64_corner_tu` 64x32/32x64 |
33+|---|---|---|---|
34+| head of the 10-bit 3840x1608 stream (2 s) | **OK: 48 frames, no refusal** | 31 / 17 / 23 | 130 / 22 |
35+| same stream @ +300 s | REFUSED: a Golomb tail longer than this decoder reads | 175 / 1350 / 760 | 270 / 90 |
36+| 1080p 10-bit 128-SB cut @ 900 | REFUSED: an OBMC neighbour whose switchable interp filter was never recorded | 1 / 4 / 2 | 0 / 0 |
37+| same @ 5400 | REFUSED: same OBMC string | 15 / 49 / 35 | 0 / 0 |
38+| same @ 6300 | REFUSED: same OBMC string | 1 / 1 / 0 | 0 / 0 |
39+| same @ 8100 | REFUSED: an intra-coded 16x4/4x16 strip **on the inter block path** (decode.rs:7390 -- a DIFFERENT site from the one lifted here) | 0 / 0 / 0 | 1 / 0 |
40+
41+Pixel compare of the only cut that finishes (`EC_PROBE_OUT16` vs
42+`ffmpeg -pix_fmt yuv420p10le -f rawvideo`, `diff16.py`, 889159680 B each side):
43+**decode-order frames 0..35 are byte-identical**; frame 36 is the first differing one
44+(1992768 of 18524160 bytes) and 36..47 all differ -- one wall, propagating.
45+
46+EVIDENCE: ~/.cache/sub8x4-tmp/{o,r}.raw | release decode_probe + ffmpeg on the 2 s head cut, diff16.py 3840x1608 | frames 0-35 differ in 0 bytes, frame 36 in 1992768
47+
48+## STEP 3 -- `f38f963`: both refusals narrowed, one film gate, one sibling fixed
49+
50+* `EC_RECT64_SPLIT` removed (decode.rs:6890-6903): the un-split TX_64X32/TX_32X64 corner
51+ unit of a split intra strip is now the default path.
52+* `EC_INTRA16X4_DECODE` removed (decode.rs:21886-21903): the intra 16x4/4x16 strip inside
53+ an inter 16x16-level 1:4 partition decodes by default when it has a chroma-pair record.
54+* Fixture `crates/ec-av1/fixtures/reelb_rect64_intra16x4_witness.obu` (`git add -f`, in
55+ `git ls-files`), 23472 bytes, sha256
56+ `c9e721088766163b9dbeb9fa8dd8b257ff0ec7f9157fc350de4d3c33cd9ec4e4` -- the first 50
57+ frame-carrying OBUs of the 2 s head cut. Cut TWICE from independent
58+ `ffmpeg -ss 0 -t 2 ... -c:v copy -f obu` runs: both segments hashed
59+ `96940689a8c6...` and both truncations hashed `c9e7210887...`.
60+* Gate `a_10bit_film_frames_with_intra_16x4_strips_and_rect64_corner_tus_decode_pixel_exact`
61+ (stream.rs, after the intra14 gate): 33 decode-order frames, all three planes, hard
62+ asserts on all five counters AND on ffmpeg's own frame count (no vacuous compare).
63+* Why the fixture is 50 OBUs and not the whole 2 s segment is stated in its doc comment:
64+ the full segment diverges at frame 36, and the prefix is the exact one, not a
65+ truncation chosen to hide that.
66+* **Neither refusal string leaves `refusal_inventory`** -- both are NARROWED. "a split
67+ intra strip whose transform unit is {tx_w}x{tx_h}" still stands for every shape other
68+ than 64x32/32x64; the 16x4/4x16 one still stands for a strip with no chroma-pair record
69+ (and decode.rs:7390 is a separate string, untouched). `refusal_inventory` and all 12
70+ `gate_coverage` tests green with no edit.
71+
72+EVIDENCE: crates/ec-av1/fixtures/reelb_rect64_intra16x4_witness.obu | `cargo test -p ec-av1 --lib -- a_10bit_film_frames_with_intra_16x4 refusal_inventory gate_coverage` | `13 passed; 0 failed` in 62.64s, gate printed `33 frames pixel-exact, intra16x4_in_inter 16x4=31 4x16=17 chroma_ref=23, rect64_corner_tu 64x32=90 32x64=5`
73+
74+### Sibling sweep (COMMON's SIBLING GATES rule) -- found and fixed one
75+
76+`a_10bit_film_inter_frame_with_intra_1to4_strips_decodes_pixel_exact` was `#[ignore]`d
77+with the note "un-ignore when the 64x32/32x64 luma coefficient tables land". They landed
78+here, so it is un-ignored. Running it for the FIRST time (it had never executed) showed
79+its `frames.len() == 2` assert was an untested assumption: a raw
80+`ffmpeg -i <fixture> -pix_fmt yuv420p10le -f rawvideo` writes exactly 18524160 bytes =
81+ONE 3840x1608 10-bit frame, so the second frame OBU is a no-show. Corrected to 1, plus an
82+ffmpeg-frame-count equality assert so the compare cannot silently go vacuous.
83+
84+EVIDENCE: ~/.cache/sub8x4-tmp/{o,r}.raw on the intra14 fixture | release decode_probe + raw ffmpeg decode, diff16.py | 1 frame each side, `0:0` (zero differing bytes); gate green, `480 intra 1:4 strips in an inter frame, the shown frame pixel-exact`
85+
86+## STEP 4 -- full suite
87+
88+Unit `sub8x4-suite-r3-1788364529.service`, log `$HOME/.cache/sub8x4-suite-r3.log`
89+(private path per COMMON):
90+
91+`test result: FAILED. 422 passed; 2 failed; 37 ignored; 0 measured; 0 filtered out; finished in 676.59s`
92+
93+Against r2's `419 passed; 3 failed; 38 ignored`: +3 passed (the straddling gate the merge
94+fixed, plus this round's two film gates net of the un-ignore), -1 failed, -1 ignored (the
95+intra14 gate). The 2 remaining failures are the same two zero-COUNTER 1:4 recipe defects
96+r2 already carried, with the same messages; no new failure, no gate regressed.
97+
98+## Open residue
99+
100+* `fix-now (next round)` -- the head cut's wall at decode-order **frame 36**: 33 frames
101+ are pinned and exact, frames 36..47 differ. No refusal fires, so this is a silent
102+ reconstruction/entropy defect and the fixture at N=52/N=56 (still exact, 33/35 frames)
103+ brackets it: N=58 (37 frames) is the smallest truncation that includes it.
104+* `deferred(a lane that owns the OBMC interp-filter record)` -- three of the four 1080p
105+ 128-SB cuts now stop at "an OBMC neighbour whose switchable interp filter was never
106+ recorded", which is not this lane's shape.
107+* `deferred(the 16x16-level 1:4 INTER partition itself)` -- decode.rs:7390, the OTHER
108+ intra-16x4 refusal, on the inter block path; it is what the 8100 cut stops at and it is
109+ refused before the partition this round unblocked.
110+* `accepted` -- the two zero-COUNTER 1:4 recipe defects (stream.rs:8884, :11002) are pure
111+ gate-recipe defects carried in from before this lane and did not move this round.