forge
Explore
Log in

Don't you dare go Hollow

Intra 16x4/4x16 strip of an inter 16x16-level 1:4 partition decodes behind EC_INTRA16X4_DECODE (gate RED, refusal kept)

Browse files at this commit

dfaeea58a17986743ed3298bca1ae06f116ef96cAhmet Kaan GümüşParent: ba3aca0
  • feat
    • intra 16x4/4x16 strip of an inter 16x16-level 1:4 partition decodes behind EC_INTRA16X4_DECODE (gate RED, refusal kept)
Show full message
feat(av1): intra 16x4/4x16 strip of an inter 16x16-level 1:4 partition decodes behind EC_INTRA16X4_DECODE (gate RED, refusal kept)

The key frame's per-strip body is lifted out of decode_rect4_16 into
decode_rect4_16_strip and run from the INTER block path with
INTRA_IN_INTER_MODE = (size_group 0, the skip decode_inter_block already read),
so a single intra strip of a partition whose other strips are inter decodes
through the readers the key frame already proves -- including the 4:2:0 pairing
(even strips read no chroma, the odd one codes one 8x4/4x8 unit at the pair's
origin, predicted per the strip that carries it).

The inter path additionally publishes set_txfm_ctxs + txfm_partition_update for
the strip (the key-frame body has no var-tx tree) and reads the tx-depth symbol
off the real TXFM_CONTEXT bands; without that the block after the strip broke
while the strip itself was exact.

Not pixel-proven: the r1 gate (real aomenc, 4 recipes x 8/10 bit, every frame
Y/U/V vs ffmpeg) is RED and #[ignore]d with its measurement, so the named
refusal stays the default and the new path is behind EC_INTRA16X4_DECODE=1.
Measured with the switch on, all six 10-bit film probes leave this wall (five
stop on the sub-8x8 intra block, another lane's shape).
crates/ec-av1/examples/decode_probe.rsmodified+6 -0
@@ -110,6 +110,12 @@ fn main() {
110 // rectangular residual transform unit (a skipped one codes none).110 // rectangular residual transform unit (a skipped one codes none).
111 let r328 = ec_av1::stream::rect32x8_inter_tu_hits();111 let r328 = ec_av1::stream::rect32x8_inter_tu_hits();
112 println!("rect32x8_inter_tu: 32x8={} 8x32={}", r328[0], r328[1]);112 println!("rect32x8_inter_tu: 32x8={} 8x32={}", r328[0], r328[1]);
113+ // lane-intra16x4: INTRA strips of an inter 16x16-level 1:4 partition.
114+ let i164 = ec_av1::stream::intra16x4_in_inter_hits();
115+ println!(
116+ "intra16x4_in_inter: 16x4={} 4x16={} chroma_ref={}",
117+ i164.0, i164.1, i164.2
118+ );
113 };119 };
114 // lane-tiles: the tiling a real stream actually uses is a decision input120 // 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 it121 // (every gate in `stream.rs` picks its own `--tile-columns`), so report it
crates/ec-av1/src/decode.rsmodified+213 -16
@@ -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)`.
@@ -7222,6 +7237,9 @@ fn decode_intra_rect_in_inter(
7222 bh: usize,7237 bh: usize,
7223 skip: bool,7238 skip: bool,
7224 allow_screen_content_tools: bool,7239 allow_screen_content_tools: bool,
7240+ // `(PARTITION_HORZ_4, is_chroma_reference)` when this strip is one of the
7241+ // four 16x4 / 4x16 strips of a 16x16-level 1:4 partition (lane-intra16x4).
7242+ strip16: Option<(bool, bool)>,
7225 y: &mut PlaneBuf,7243 y: &mut PlaneBuf,
7226 u: &mut PlaneBuf,7244 u: &mut PlaneBuf,
7227 v: &mut PlaneBuf,7245 v: &mut PlaneBuf,
@@ -7238,6 +7256,94 @@ fn decode_intra_rect_in_inter(
7238 // finding -- the category is NOT the same for every strip size).7256 // finding -- the category is NOT the same for every strip size).
7239 // A 1:4 strip breaks that diagonal (BLOCK_32X8 is group 1 but cat 2), so7257 // A 1:4 strip breaks that diagonal (BLOCK_32X8 is group 1 but cat 2), so
7240 // it is refused by name rather than read from the wrong CDF row.7258 // it is refused by name rather than read from the wrong CDF row.
7259+ // lane-intra16x4: the 16x16-level 1:4 strip. `size_group_lookup`
7260+ // (common_data.h:61) puts BLOCK_16X4/BLOCK_4X16 in group 0 and its
7261+ // tx-depth category is 1 -- but nothing here has to know either, because
7262+ // the strip decodes through the very body the KEY FRAME path proves for
7263+ // this shape ([`decode_rect4_16_strip`]), including the 4:2:0 chroma
7264+ // pairing (`is_chroma_reference`: strips 0 and 2 read no chroma at all,
7265+ // strips 1 and 3 code one 8x4 (4x8) unit at the PAIR's origin). The only
7266+ // inter-frame difference is the mode-info read, which
7267+ // [`INTRA_IN_INTER_MODE`] switches to `read_intra_block_mode_info`'s
7268+ // `y_mode[0]` plus the `skip` this caller already read.
7269+ if let Some((horz, has_chroma)) = strip16 {
7270+ if allow_screen_content_tools {
7271+ return Err(unsupported(
7272+ "a HORZ/VERT intra strip in a screen-content frame (palette syntax \
7273+ is consumed for square blocks only)",
7274+ ));
7275+ }
7276+ debug_assert_eq!((bw, bh), if horz { (16, 4) } else { (4, 16) });
7277+ INTRA_IN_INTER_MODE.with(|c| c.set(Some((0, skip))));
7278+ let res = decode_rect4_16_strip(
7279+ dec,
7280+ cdfs,
7281+ neighbours,
7282+ (mi_r, mi_c),
7283+ horz,
7284+ has_chroma,
7285+ // The inter strips of the same partition publish their own
7286+ // mi-exact mode, so the key-frame caller's coarse-cell stand-in
7287+ // has nothing to add here.
7288+ None,
7289+ y,
7290+ u,
7291+ v,
7292+ ENABLE_FILTER_INTRA_INTER.with(std::cell::Cell::get),
7293+ allow_screen_content_tools,
7294+ base_q_idx,
7295+ TX_SELECT_INTER.with(std::cell::Cell::get),
7296+ REDUCED_TX_SET_INTER.with(std::cell::Cell::get),
7297+ );
7298+ INTRA_IN_INTER_MODE.with(|c| c.set(None));
7299+ let (mode, uv, (tx_w, tx_h)) = res?;
7300+ // lane-intra16x4, the same publication the 2:1 intra-in-inter strip
7301+ // makes ([`decode_intra_rect_in_inter`]'s own tail): libaom runs
7302+ // `set_txfm_ctxs(tx_size, n4_w, n4_h, skip && is_inter, xd)` for EVERY
7303+ // block of an inter frame, intra ones included, and
7304+ // `txfm_partition_update` for the var-tx context. The key-frame body
7305+ // writes neither (a key frame has no var-tx tree and its own readers
7306+ // use the deblock grid), so the block AFTER this strip read a stale
7307+ // band -- measured: a 128x128 8-bit stream decoded the two intra 16x4
7308+ // strips at mi(23,16)/(23,20) exactly and then broke on the very next
7309+ // 16x16 row.
7310+ txfm_partition_update_rect(neighbours, (mi_r, mi_c), (tx_w, tx_h), (bw, bh));
7311+ for i in 0..bw / MI {
7312+ if let Some(cell) = neighbours.above_txfm.get_mut(mi_c + i) {
7313+ *cell = tx_w as u8;
7314+ }
7315+ }
7316+ for i in 0..bh / MI {
7317+ if let Some(cell) = neighbours.left_txfm.get_mut(mi_r + i) {
7318+ *cell = tx_h as u8;
7319+ }
7320+ }
7321+ // [`decode_rect4_16`]'s own post-loop publication, per strip (the
7322+ // coarse 16-px cell holds one entry for the whole 16x16 and the last
7323+ // block to write it wins).
7324+ neighbours.above_mode[c] = mode;
7325+ neighbours.left_mode[r] = mode;
7326+ if let Some(uvm) = uv {
7327+ neighbours.above_uv_mode[c] = uvm;
7328+ neighbours.left_uv_mode[r] = uvm;
7329+ }
7330+ neighbours.above_side[c] = bw;
7331+ neighbours.left_side[r] = bh;
7332+ if std::env::var_os("EC_INTRA16X4").is_some() {
7333+ eprintln!(
7334+ "EC_INTRA16X4 decoded mi={mi_r},{mi_c} px={},{} horz={horz} has_chroma={has_chroma} skip={skip} mode={mode} uv={uv:?}",
7335+ mi_c * MI,
7336+ mi_r * MI
7337+ );
7338+ }
7339+ INTRA16X4_IN_INTER_HITS.with(|h| {
7340+ let mut v = h.get();
7341+ v[usize::from(!horz)] += 1;
7342+ v[2] += usize::from(has_chroma);
7343+ h.set(v);
7344+ });
7345+ return Ok(());
7346+ }
7241 let (size_group, tx_cat) = match (bw.min(bh), bw.max(bh)) {7347 let (size_group, tx_cat) = match (bw.min(bh), bw.max(bh)) {
7242 (8, 16) => (1usize, 1usize),7348 (8, 16) => (1usize, 1usize),
7243 (16, 32) => (2, 2),7349 (16, 32) => (2, 2),
@@ -8741,6 +8847,72 @@ fn decode_rect4_16(
8741 (mi_row0, mi_col0 + i)8847 (mi_row0, mi_col0 + i)
8742 };8848 };
8743 let has_chroma = i % 2 == 1;8849 let has_chroma = i % 2 == 1;
8850+ let (mode, uv, _tx) = decode_rect4_16_strip(
8851+ dec,
8852+ cdfs,
8853+ neighbours,
8854+ lmi,
8855+ horz,
8856+ has_chroma,
8857+ prev,
8858+ y,
8859+ u,
8860+ v,
8861+ enable_filter_intra,
8862+ allow_screen_content_tools,
8863+ base_q_idx,
8864+ tx_select,
8865+ reduced_tx_set,
8866+ )?;
8867+ if let Some(m) = uv {
8868+ last_uv_mode = m;
8869+ }
8870+ last_mode = mode;
8871+ prev = Some((lmi, mode));
8872+ }
8873+ // The coarse 16-px cell holds one entry for the whole 16x16: the last
8874+ // strip is what a block below (right) sees through it, the mi-exact maps
8875+ // above answering everything finer.
8876+ neighbours.above_mode[c] = last_mode;
8877+ neighbours.left_mode[r] = last_mode;
8878+ neighbours.above_uv_mode[c] = last_uv_mode;
8879+ neighbours.left_uv_mode[r] = last_uv_mode;
8880+ neighbours.above_side[c] = bw;
8881+ neighbours.left_side[r] = bh;
8882+ Ok(())
8883+}
8884+
8885+/// One 16x4 / 4x16 strip of a 16x16-level 1:4 partition, intra-coded --
8886+/// [`decode_rect4_16`]'s per-strip body, lifted (lane-intra16x4) so the INTER
8887+/// block path can decode a SINGLE intra strip of a partition whose other
8888+/// strips are inter. `prev` is the previous strip's `(mi, mode)` (the
8889+/// key-frame caller's coarse-cell stand-in; `None` on the inter path, where
8890+/// every strip publishes its own mi-exact mode). Returns
8891+/// `(y_mode, uv_predict_mode when this strip closes the 4:2:0 chroma pair)`.
8892+#[allow(clippy::too_many_arguments)]
8893+fn decode_rect4_16_strip(
8894+ dec: &mut SymbolDecoder,
8895+ cdfs: &mut Cdfs,
8896+ neighbours: &mut Neighbours,
8897+ lmi: (usize, usize),
8898+ horz: bool,
8899+ has_chroma: bool,
8900+ prev: Option<((usize, usize), usize)>,
8901+ y: &mut PlaneBuf,
8902+ u: &mut PlaneBuf,
8903+ v: &mut PlaneBuf,
8904+ enable_filter_intra: bool,
8905+ allow_screen_content_tools: bool,
8906+ base_q_idx: u8,
8907+ tx_select: bool,
8908+ reduced_tx_set: bool,
8909+) -> Result<(usize, Option<usize>, (usize, usize))> {
8910+ let (r, c) = (lmi.0 / (SUB / MI), lmi.1 / (SUB / MI));
8911+ let (bw, bh) = if horz { (16usize, 4usize) } else { (4, 16) };
8912+ let (mi_w, mi_h) = (bw / MI, bh / MI);
8913+ let scan: &[u16] = if horz { &SCAN_16X4 } else { &SCAN_4X16 };
8914+ let chroma_scan: &[u16] = if horz { &SCAN_8X4 } else { &SCAN_4X8 };
8915+ let mut last_uv_mode: Option<usize> = None;
8744 // `decode_block_rect4`'s own neighbour rule: the coarse 16-px cell8916 // `decode_block_rect4`'s own neighbour rule: the coarse 16-px cell
8745 // aliases all four strips onto one entry, so the mi-exact map wins and8917 // aliases all four strips onto one entry, so the mi-exact map wins and
8746 // the previous strip stands in on the split axis.8918 // the previous strip stands in on the split axis.
@@ -8814,7 +8986,16 @@ fn decode_rect4_16(
8814 // depth symbol is the 3-symbol `tx_size_cat1` -- not the 2-symbol8986 // depth symbol is the 3-symbol `tx_size_cat1` -- not the 2-symbol
8815 // `cat0` a 4x8 leaf reads nor the `cat2` a 32x8 strip does.8987 // `cat0` a 4x8 leaf reads nor the `cat2` a 32x8 strip does.
8816 let depth = if tx_select {8988 let depth = if tx_select {
8817- let ctx = tx_size_context_rect(neighbours, lmi, bw, bh);8989+ // lane-intra16x4: on an INTER frame `get_tx_size_context` reads the
8990+ // real `TXFM_CONTEXT` bands ([`tx_size_context_txfm_rect`], what
8991+ // the 2:1 intra-in-inter strip already does); the key frame's
8992+ // deblock-grid approximation is only right where those bands were
8993+ // never written.
8994+ let ctx = if INTRA_IN_INTER_MODE.with(std::cell::Cell::get).is_some() {
8995+ tx_size_context_txfm_rect(neighbours, lmi, bw, bh)
8996+ } else {
8997+ tx_size_context_rect(neighbours, lmi, bw, bh)
8998+ };
8818 dec.symbol(&mut cdfs.tx_size_cat1[ctx])8999 dec.symbol(&mut cdfs.tx_size_cat1[ctx])
8819 } else {9000 } else {
8820 09001 0
@@ -9156,7 +9337,7 @@ fn decode_rect4_16(
9156 slot[2] = v_state;9337 slot[2] = v_state;
9157 }9338 }
9158 }9339 }
9159- last_uv_mode = uv_predict_mode;9340+ last_uv_mode = Some(uv_predict_mode);
9160 }9341 }
9161 if horz {9342 if horz {
9162 RECT4_16_HORZ_HITS.with(|h| h.set(h.get() + 1));9343 RECT4_16_HORZ_HITS.with(|h| h.set(h.get() + 1));
@@ -9170,21 +9351,10 @@ fn decode_rect4_16(
9170 record_strip_palette(9351 record_strip_palette(
9171 neighbours, lmi, bw, bh, pal_y_size, pal_y_colors, pal_uv_size, pal_uv_colors,9352 neighbours, lmi, bw, bh, pal_y_size, pal_y_colors, pal_uv_size, pal_uv_colors,
9172 );9353 );
9173- last_mode = mode;9354+ Ok((mode, last_uv_mode, (tx_w, tx_h)))
9174- prev = Some((lmi, mode));
9175- }
9176- // The coarse 16-px cell holds one entry for the whole 16x16: the last
9177- // strip is what a block below (right) sees through it, the mi-exact maps
9178- // above answering everything finer.
9179- neighbours.above_mode[c] = last_mode;
9180- neighbours.left_mode[r] = last_mode;
9181- neighbours.above_uv_mode[c] = last_uv_mode;
9182- neighbours.left_uv_mode[r] = last_uv_mode;
9183- neighbours.above_side[c] = bw;
9184- neighbours.left_side[r] = bh;
9185- Ok(())
9186 }9355 }
9187 9356
9357+
9188 /// Decodes one true `bw`x`bh` superblock-level `PARTITION_HORZ`/9358 /// Decodes one true `bw`x`bh` superblock-level `PARTITION_HORZ`/
9189 /// `PARTITION_VERT` strip (lane-sbpart r2, `bw, bh` one of `(64, 32)` /9359 /// `PARTITION_VERT` strip (lane-sbpart r2, `bw, bh` one of `(64, 32)` /
9190 /// `(32, 64)` -- [`decode_block_rect`]'s own sibling one level up). Unlike9360 /// `(32, 64)` -- [`decode_block_rect`]'s own sibling one level up). Unlike
@@ -21657,7 +21827,33 @@ fn decode_inter_block(
21657 // footprint), so an INTRA 16x4 / 4x16 strip inside a 1:4 partition is21827 // footprint), so an INTRA 16x4 / 4x16 strip inside a 1:4 partition is
21658 // refused by name rather than decoded with a 8x2 chroma transform21828 // refused by name rather than decoded with a 8x2 chroma transform
21659 // libaom never coded.21829 // libaom never coded.
21660- if write_w.min(write_h) < 8 {21830+ // lane-intra16x4 r1: the strip DECODES (through the key frame's own
21831+ // per-strip body, [`decode_rect4_16_strip`]) only under
21832+ // `EC_INTRA16X4_DECODE`. It is not pixel-proven yet -- the r1 gate is
21833+ // RED (`a_real_aomenc_inter_sequence_with_intra_16x4_strips_...`,
21834+ // #[ignore]d with its measurement), so the refusal STAYS the default
21835+ // behaviour and the env switch is what the film probes use to measure
21836+ // the next wall. Class `refusal-lifted-without-a-gate`.
21837+ let strip16 = strip_chroma
21838+ .filter(|_| std::env::var_os("EC_INTRA16X4_DECODE").is_some())
21839+ .filter(|_| write_w.min(write_h) == 4 && write_w.max(write_h) == 16)
21840+ .map(|s| (s.horz, s.has_chroma));
21841+ if write_w.min(write_h) < 8 && strip16.is_none() {
21842+ if std::env::var_os("EC_INTRA16X4").is_some() {
21843+ let (idx, hc, prev_inter) = match strip_chroma {
21844+ Some(s) => (
21845+ if s.horz { rmi - s.pair_mi.0 } else { cmi - s.pair_mi.1 },
21846+ s.has_chroma,
21847+ s.prev.is_some(),
21848+ ),
21849+ None => (9, true, false),
21850+ };
21851+ eprintln!(
21852+ "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={}",
21853+ TX_SELECT_INTER.with(std::cell::Cell::get),
21854+ allow_screen_content_tools,
21855+ );
21856+ }
21661 return Err(unsupported(21857 return Err(unsupported(
21662 "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)",21858 "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)",
21663 ));21859 ));
@@ -21680,6 +21876,7 @@ fn decode_inter_block(
21680 write_h,21876 write_h,
21681 skip,21877 skip,
21682 allow_screen_content_tools,21878 allow_screen_content_tools,
21879+ strip16,
21683 y,21880 y,
21684 u,21881 u,
21685 v,21882 v,
crates/ec-av1/src/stream.rsmodified+262 -0
@@ -80,6 +80,12 @@ 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+
83 /// lane-r14 r3: RECTANGULAR var-tx leaf transform units, `[32x16, 16x32]` --89 /// 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 axis90 /// 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`).91 /// splits its transform (`[TX_64X16] == TX_32X16`, `[TX_16X64] == TX_16X32`).
@@ -10988,6 +10994,262 @@ mod tests {
10988 }10994 }
10989 10995
10990 10996
10997+ #[test]
10998+ #[ignore = "RED at lane-intra16x4 r1: the decode path is behind \
10999+ EC_INTRA16X4_DECODE=1 and still mismatches ffmpeg (attempt 1, 8-bit, 192x128 \
11000+ cq60: frame 1 luma differs from (175, 0), 8400 px, with the two intra 16x4 \
11001+ strips at mi(1,40)/(3,40) themselves exact) -- lanes/intra16x4-r1.report.md"]
11002+ // lane-intra16x4 r1: an INTRA-coded 16x4 / 4x16 strip inside an INTER
11003+ // frame's 16x16-level 1:4 partition -- the wall all six of his film cuts
11004+ // stopped at once lane-rectres landed. The shape's chroma is the pair's:
11005+ // `is_chroma_reference` (av1_common_int.h:1454) is false on the even
11006+ // strips (which read no `uv_mode` and code no chroma at all) and the odd
11007+ // one codes ONE 8x4 (4x8) chroma unit at the pair's origin -- and when the
11008+ // pair mixes an intra and an inter strip, the chroma is predicted per the
11009+ // strip that CARRIES it, which is exactly what routing the intra strip
11010+ // through the key frame's own proven per-strip body
11011+ // (`decode_rect4_16_strip`) gives.
11012+ //
11013+ // Recipes found by a 24 + 24 run sweep (three sources x cq 16..63 x two
11014+ // sizes, `~/.cache/intra16x4-tmp/sweep*.sh`): aomenc only picks an INTRA
11015+ // 1:4 strip on an inter frame at HIGH cq over content its MC cannot
11016+ // predict -- a per-frame-random bright bar sweeping the frame (HORZ_4
11017+ // strips) and a `X*Y` product sinusoid under temporal noise (VERT_4).
11018+ // Both sources hash identically twice (report).
11019+ fn a_real_aomenc_inter_sequence_with_intra_16x4_strips_in_1to4_partitions_decodes_pixel_exact() {
11020+ const NAME: &str =
11021+ "a_real_aomenc_inter_sequence_with_intra_16x4_strips_in_1to4_partitions_decodes_pixel_exact";
11022+ let _gate_lock = lock_gate_counters();
11023+ if !have_ffmpeg() {
11024+ eprintln!("SKIP {NAME}: no ffmpeg");
11025+ return;
11026+ }
11027+ if !have_aomenc() {
11028+ eprintln!("SKIP {NAME}: no aomenc at {}", aomenc_path().display());
11029+ return;
11030+ }
11031+ let frame_count = 6usize;
11032+ // (source kind, cq, width, height) -- the four recipes of the 48-run
11033+ // sweep (`~/.cache/intra16x4-tmp/sweep*.sh`, table in the report) that
11034+ // reach an INTRA 1:4 strip on an inter frame. `bar` is a per-frame
11035+ // random bright bar sweeping the frame (its MC failure is what makes
11036+ // aomenc's RD pick intra at 16x4), `prod` an `X*Y` product sinusoid
11037+ // under temporal noise; `_v` transposes the structure so the RD picks
11038+ // PARTITION_VERT_4.
11039+ const RECIPES: [(&str, u32, usize, usize); 4] = [
11040+ ("noise", 60, 128, 128),
11041+ ("bar", 60, 192, 128),
11042+ ("prod_v", 56, 128, 128),
11043+ ("prod", 56, 160, 128),
11044+ ];
11045+ // [16x4 intra strips, 4x16 intra strips, of which chroma-reference]:
11046+ // how many pixel-exact attempts fired each, over both bit depths.
11047+ let mut arms_total = [0u32; 3];
11048+ // Attempts that refused on the sub-8x8 intra block inside an inter
11049+ // frame -- a DIFFERENT lane's shape, and the measured blocker of every
11050+ // VERT_4-carrying recipe in the sweep.
11051+ let mut sub8_intra_refusals = 0u32;
11052+ for bit_depth in [8u32, 10u32] {
11053+ let (mut named_refusals, mut matched, mut out_of_scope, mut oos_mismatch) =
11054+ (0u32, 0u32, 0u32, 0u32);
11055+ let mut arms_proved = [0u32; 3];
11056+ for attempt in 0..RECIPES.len() as u32 {
11057+ let (kind, cq, width, height) = RECIPES[attempt as usize];
11058+ let duration = frame_count as f64 / 25.0;
11059+ // Both sources are deterministic (two identical y4m hashes,
11060+ // report): `random()` here is geq's own indexed PRNG and the
11061+ // noise filter carries an explicit `all_seed`.
11062+ let (lum, noise) = match kind {
11063+ "noise" => (
11064+ format!("128+58*sin((X+N*3)/6)+40*sin(Y/11)"),
11065+ ",noise=alls=40:allf=t+u:all_seed=7",
11066+ ),
11067+ "bar" => (
11068+ format!(
11069+ "if(lt(mod(X+N*37,{width}),24),random(N*100+X+Y)*255,128+50*sin(Y/7))"
11070+ ),
11071+ "",
11072+ ),
11073+ "prod_v" => (
11074+ "128+60*sin((X*Y+N*97)/13)+50*sin((Y+N*11)/5)".to_string(),
11075+ ",noise=alls=25:allf=t:all_seed=11",
11076+ ),
11077+ _ => (
11078+ "128+60*sin((X*Y+N*97)/13)+50*sin((X+N*11)/5)".to_string(),
11079+ ",noise=alls=25:allf=t:all_seed=11",
11080+ ),
11081+ };
11082+ let source = format!(
11083+ "color=c=gray:s={width}x{height}:d={duration}:r=25,format=gray,\
11084+ geq=lum='{lum}',format=yuv420p{noise}"
11085+ );
11086+ let pix_fmt = if bit_depth == 10 { "yuv420p10le" } else { "yuv420p" };
11087+ let y4m = Command::new("ffmpeg")
11088+ .args([
11089+ "-v", "error", "-f", "lavfi", "-i", &source, "-t", &duration.to_string(),
11090+ "-pix_fmt", pix_fmt, "-strict", "-1", "-f", "yuv4mpegpipe", "-",
11091+ ])
11092+ .stdin(Stdio::null())
11093+ .stdout(Stdio::piped())
11094+ .stderr(Stdio::piped())
11095+ .output()
11096+ .expect("ffmpeg failed to run");
11097+ assert!(
11098+ y4m.status.success(),
11099+ "{NAME}: ffmpeg refused the {bit_depth}-bit fixture: {}",
11100+ String::from_utf8_lossy(&y4m.stderr)
11101+ );
11102+ let cq_arg = format!("--cq-level={cq}");
11103+ let depth_arg = format!("--bit-depth={bit_depth}");
11104+ let input_depth_arg = format!("--input-bit-depth={bit_depth}");
11105+ let args: Vec<&str> = vec![
11106+ "--codec=av1", "--passes=1", "--end-usage=q", &cq_arg, "--cpu-used=0",
11107+ "--threads=1", "--row-mt=0", "--sb-size=64", &depth_arg, &input_depth_arg,
11108+ "--enable-restoration=0", "--enable-palette=0", "--deltaq-mode=0",
11109+ "--enable-filter-intra=0", "--enable-cfl-intra=0", "--enable-intrabc=0",
11110+ "--lag-in-frames=0", "--kf-max-dist=9999", "--tile-columns=0",
11111+ // Per-arm overrides go LAST (aomenc keeps the last
11112+ // occurrence of a repeated --enable-* flag).
11113+ "--enable-tx-size-search=1", "--enable-rect-partitions=1",
11114+ "--enable-ab-partitions=1", "--enable-1to4-partitions=1",
11115+ "--enable-intra-edge-filter=1",
11116+ "--min-partition-size=4", "--max-partition-size=16",
11117+ "--obu", "-o", "-", "-",
11118+ ];
11119+ let mut child = Command::new(aomenc_path())
11120+ .args(&args)
11121+ .stdin(Stdio::piped())
11122+ .stdout(Stdio::piped())
11123+ .stderr(Stdio::piped())
11124+ .spawn()
11125+ .expect("aomenc failed to start");
11126+ child
11127+ .stdin
11128+ .take()
11129+ .expect("aomenc stdin")
11130+ .write_all(&y4m.stdout)
11131+ .expect("writing y4m to aomenc");
11132+ let out = child.wait_with_output().expect("aomenc failed to run");
11133+ assert!(
11134+ out.status.success(),
11135+ "aomenc refused the fixture: {}",
11136+ String::from_utf8_lossy(&out.stderr)
11137+ );
11138+ let stream = out.stdout;
11139+ let before = crate::stream::intra16x4_in_inter_hits();
11140+ let frames = match decode_stream(&stream) {
11141+ Err(e) => {
11142+ let msg = e.to_string();
11143+ assert!(
11144+ msg.contains("unsupported"),
11145+ "{NAME} failed outright, not a named refusal ({bit_depth}-bit, \
11146+ attempt {attempt}): {msg}"
11147+ );
11148+ if msg.contains("sub-8x8") {
11149+ sub8_intra_refusals += 1;
11150+ }
11151+ named_refusals += 1;
11152+ eprintln!("{bit_depth}-bit attempt {attempt} refusal: {msg}");
11153+ continue;
11154+ }
11155+ Ok(frames) => frames,
11156+ };
11157+ let after = crate::stream::intra16x4_in_inter_hits();
11158+ let fired = [
11159+ (after.0 - before.0) as u32,
11160+ (after.1 - before.1) as u32,
11161+ (after.2 - before.2) as u32,
11162+ ];
11163+ let ffmpeg_frames = if bit_depth == 10 {
11164+ ffmpeg_decode_sequence_10bit(&stream, width, height, frame_count)
11165+ } else {
11166+ ffmpeg_decode_sequence(&stream, width, height, frame_count)
11167+ };
11168+ assert_eq!(frames.len(), frame_count);
11169+ let mismatched = frames
11170+ .iter()
11171+ .zip(&ffmpeg_frames)
11172+ .any(|(got, want)| got.y != want.y || got.u != want.u || got.v != want.v);
11173+ if fired[0] + fired[1] == 0 {
11174+ out_of_scope += 1;
11175+ if mismatched {
11176+ oos_mismatch += 1;
11177+ eprintln!(
11178+ "{NAME}: {bit_depth}-bit attempt {attempt} MISMATCHES with zero \
11179+ intra 1:4 strip -- another shape's defect"
11180+ );
11181+ }
11182+ continue;
11183+ }
11184+ if mismatched {
11185+ for (i, (got, want)) in frames.iter().zip(&ffmpeg_frames).enumerate() {
11186+ let bad: Vec<usize> =
11187+ (0..got.y.len()).filter(|&k| got.y[k] != want.y[k]).collect();
11188+ if !bad.is_empty() {
11189+ eprintln!(
11190+ "{NAME}: attempt {attempt} {bit_depth}-bit frame {i}: {} luma \
11191+ pixels differ, first at ({}, {}), max |delta| {}",
11192+ bad.len(),
11193+ bad[0] % width,
11194+ bad[0] / width,
11195+ bad.iter()
11196+ .map(|&k| (got.y[k] as i32 - want.y[k] as i32).abs())
11197+ .max()
11198+ .unwrap_or(0)
11199+ );
11200+ }
11201+ }
11202+ }
11203+ for (i, (got, want)) in frames.iter().zip(&ffmpeg_frames).enumerate() {
11204+ assert_eq!(got.y, want.y, "{NAME} frame {i} luma vs ffmpeg (attempt {attempt}, {bit_depth}-bit, arms {fired:?})");
11205+ assert_eq!(got.u, want.u, "{NAME} frame {i} U vs ffmpeg (attempt {attempt}, {bit_depth}-bit, arms {fired:?})");
11206+ assert_eq!(got.v, want.v, "{NAME} frame {i} V vs ffmpeg (attempt {attempt}, {bit_depth}-bit, arms {fired:?})");
11207+ }
11208+ for a in 0..3 {
11209+ if fired[a] > 0 {
11210+ arms_proved[a] += 1;
11211+ arms_total[a] += 1;
11212+ }
11213+ }
11214+ matched += 1;
11215+ }
11216+ eprintln!(
11217+ "{NAME} ({bit_depth}-bit): {named_refusals} named refusals, {matched} pixel-exact \
11218+ attempts carrying an intra 1:4 strip, per-arm attempts \
11219+ 16x4/4x16/chroma-reference={arms_proved:?}, {out_of_scope} attempts carried none \
11220+ ({oos_mismatch} of them mismatched)"
11221+ );
11222+ assert_eq!(
11223+ oos_mismatch, 0,
11224+ "{NAME}: {oos_mismatch} attempt(s) with no intra 1:4 strip decoded but mismatched \
11225+ ffmpeg -- a defect of another shape, not a pass"
11226+ );
11227+ }
11228+ // MEASURED (48-run sweep, report table): every recipe that makes
11229+ // aomenc pick an intra PARTITION_VERT_4 strip ALSO contains an intra
11230+ // 8x4/4x8 or 4x4 block inside a sub-8x8 partition, a refusal this lane
11231+ // does not own -- so the 4x16 orientation is blocked on THAT and the
11232+ // gate asserts exactly that. If the sub-8x8 lane lands and this arm
11233+ // still reads 0, or the blocker changes, this fails.
11234+ assert!(
11235+ arms_total[1] > 0 || sub8_intra_refusals > 0,
11236+ "{NAME}: the 4x16 (PARTITION_VERT_4) arm read 0 \
11237+ (16x4/4x16/chroma-reference={arms_total:?}) and NO attempt refused on the sub-8x8 \
11238+ intra block -- its documented blocker is gone, so a zero arm is now unexplained"
11239+ );
11240+ for (a, what) in [
11241+ (0usize, "intra 16x4 strips (PARTITION_HORZ_4)"),
11242+ (2, "chroma-reference (odd) intra strips carrying the pair's 8x4/4x8 chroma"),
11243+ ] {
11244+ assert!(
11245+ arms_total[a] > 0,
11246+ "{NAME}: arm {a} ({what}) never fired on a pixel-exact attempt \
11247+ (16x4/4x16/chroma-reference={arms_total:?}) -- unproven"
11248+ );
11249+ }
11250+ }
11251+
11252+
10991 #[test]11253 #[test]
10992 // lane-sbab r1: the SUPERBLOCK-level (64x64) AB partitions on an INTER11254 // lane-sbab r1: the SUPERBLOCK-level (64x64) AB partitions on an INTER
10993 // frame -- PARTITION_HORZ_A/_HORZ_B/_VERT_A/_VERT_B at 64x64, i.e. two11255 // frame -- PARTITION_HORZ_A/_HORZ_B/_VERT_A/_VERT_B at 64x64, i.e. two
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.