From dfaeea58a17986743ed3298bca1ae06f116ef96c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Wed, 2 Sep 2026 17:14:13 +0300 Subject: [PATCH] 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.rs | 6 + crates/ec-av1/src/decode.rs | 229 +++++++++++++++++++-- crates/ec-av1/src/stream.rs | 262 +++++++++++++++++++++++++ lanes/intra16x4-r1.report.md | 110 +++++++++++ 4 files changed, 591 insertions(+), 16 deletions(-) create mode 100644 lanes/intra16x4-r1.report.md diff --git a/crates/ec-av1/examples/decode_probe.rs b/crates/ec-av1/examples/decode_probe.rs index 64efabcf..fb8fc195 100644 --- a/crates/ec-av1/examples/decode_probe.rs +++ b/crates/ec-av1/examples/decode_probe.rs @@ -110,6 +110,12 @@ fn main() { // rectangular residual transform unit (a skipped one codes none). let r328 = ec_av1::stream::rect32x8_inter_tu_hits(); println!("rect32x8_inter_tu: 32x8={} 8x32={}", r328[0], r328[1]); + // lane-intra16x4: INTRA strips of an inter 16x16-level 1:4 partition. + let i164 = ec_av1::stream::intra16x4_in_inter_hits(); + println!( + "intra16x4_in_inter: 16x4={} 4x16={} chroma_ref={}", + i164.0, i164.1, i164.2 + ); }; // lane-tiles: the tiling a real stream actually uses is a decision input // (every gate in `stream.rs` picks its own `--tile-columns`), so report it diff --git a/crates/ec-av1/src/decode.rs b/crates/ec-av1/src/decode.rs index 5f0a0812..5528a793 100644 --- a/crates/ec-av1/src/decode.rs +++ b/crates/ec-av1/src/decode.rs @@ -2691,6 +2691,21 @@ thread_local! { static INTER16_SUB8_PIECE_HITS: std::cell::Cell = const { std::cell::Cell::new(0) }; } +// lane-intra16x4: INTRA-coded strips of an inter 16x16-level 1:4 partition -- +// [0] 16x4, [1] 4x16, [2] the odd (chroma-reference) ones, which carry the +// pair's single 8x4 (4x8) chroma unit for BOTH strips. +thread_local! { + static INTRA16X4_IN_INTER_HITS: std::cell::Cell<[usize; 3]> = + const { std::cell::Cell::new([0; 3]) }; +} + +/// `(intra 16x4 strips, intra 4x16 strips, of which chroma-reference)` decoded +/// inside an INTER 16x16-level 1:4 partition (lane-intra16x4). +pub fn intra16x4_in_inter_hits() -> (usize, usize, usize) { + let v = INTRA16X4_IN_INTER_HITS.with(std::cell::Cell::get); + (v[0], v[1], v[2]) +} + /// Current values of the inter 16x16-level 1:4 counters: `(16x4 strips, 4x16 /// strips, chroma pairs closed, chroma pairs built from two different /// strips' motion vectors)`. @@ -7222,6 +7237,9 @@ fn decode_intra_rect_in_inter( bh: usize, skip: bool, allow_screen_content_tools: bool, + // `(PARTITION_HORZ_4, is_chroma_reference)` when this strip is one of the + // four 16x4 / 4x16 strips of a 16x16-level 1:4 partition (lane-intra16x4). + strip16: Option<(bool, bool)>, y: &mut PlaneBuf, u: &mut PlaneBuf, v: &mut PlaneBuf, @@ -7238,6 +7256,94 @@ fn decode_intra_rect_in_inter( // finding -- the category is NOT the same for every strip size). // A 1:4 strip breaks that diagonal (BLOCK_32X8 is group 1 but cat 2), so // it is refused by name rather than read from the wrong CDF row. + // lane-intra16x4: the 16x16-level 1:4 strip. `size_group_lookup` + // (common_data.h:61) puts BLOCK_16X4/BLOCK_4X16 in group 0 and its + // tx-depth category is 1 -- but nothing here has to know either, because + // the strip decodes through the very body the KEY FRAME path proves for + // this shape ([`decode_rect4_16_strip`]), including the 4:2:0 chroma + // pairing (`is_chroma_reference`: strips 0 and 2 read no chroma at all, + // strips 1 and 3 code one 8x4 (4x8) unit at the PAIR's origin). The only + // inter-frame difference is the mode-info read, which + // [`INTRA_IN_INTER_MODE`] switches to `read_intra_block_mode_info`'s + // `y_mode[0]` plus the `skip` this caller already read. + if let Some((horz, has_chroma)) = strip16 { + if allow_screen_content_tools { + return Err(unsupported( + "a HORZ/VERT intra strip in a screen-content frame (palette syntax \ + is consumed for square blocks only)", + )); + } + debug_assert_eq!((bw, bh), if horz { (16, 4) } else { (4, 16) }); + INTRA_IN_INTER_MODE.with(|c| c.set(Some((0, skip)))); + let res = decode_rect4_16_strip( + dec, + cdfs, + neighbours, + (mi_r, mi_c), + horz, + has_chroma, + // The inter strips of the same partition publish their own + // mi-exact mode, so the key-frame caller's coarse-cell stand-in + // has nothing to add here. + None, + y, + u, + v, + ENABLE_FILTER_INTRA_INTER.with(std::cell::Cell::get), + allow_screen_content_tools, + base_q_idx, + TX_SELECT_INTER.with(std::cell::Cell::get), + REDUCED_TX_SET_INTER.with(std::cell::Cell::get), + ); + INTRA_IN_INTER_MODE.with(|c| c.set(None)); + let (mode, uv, (tx_w, tx_h)) = res?; + // lane-intra16x4, the same publication the 2:1 intra-in-inter strip + // makes ([`decode_intra_rect_in_inter`]'s own tail): libaom runs + // `set_txfm_ctxs(tx_size, n4_w, n4_h, skip && is_inter, xd)` for EVERY + // block of an inter frame, intra ones included, and + // `txfm_partition_update` for the var-tx context. The key-frame body + // writes neither (a key frame has no var-tx tree and its own readers + // use the deblock grid), so the block AFTER this strip read a stale + // band -- measured: a 128x128 8-bit stream decoded the two intra 16x4 + // strips at mi(23,16)/(23,20) exactly and then broke on the very next + // 16x16 row. + txfm_partition_update_rect(neighbours, (mi_r, mi_c), (tx_w, tx_h), (bw, bh)); + for i in 0..bw / MI { + if let Some(cell) = neighbours.above_txfm.get_mut(mi_c + i) { + *cell = tx_w as u8; + } + } + for i in 0..bh / MI { + if let Some(cell) = neighbours.left_txfm.get_mut(mi_r + i) { + *cell = tx_h as u8; + } + } + // [`decode_rect4_16`]'s own post-loop publication, per strip (the + // coarse 16-px cell holds one entry for the whole 16x16 and the last + // block to write it wins). + neighbours.above_mode[c] = mode; + neighbours.left_mode[r] = mode; + if let Some(uvm) = uv { + neighbours.above_uv_mode[c] = uvm; + neighbours.left_uv_mode[r] = uvm; + } + neighbours.above_side[c] = bw; + neighbours.left_side[r] = bh; + if std::env::var_os("EC_INTRA16X4").is_some() { + eprintln!( + "EC_INTRA16X4 decoded mi={mi_r},{mi_c} px={},{} horz={horz} has_chroma={has_chroma} skip={skip} mode={mode} uv={uv:?}", + mi_c * MI, + mi_r * MI + ); + } + INTRA16X4_IN_INTER_HITS.with(|h| { + let mut v = h.get(); + v[usize::from(!horz)] += 1; + v[2] += usize::from(has_chroma); + h.set(v); + }); + return Ok(()); + } let (size_group, tx_cat) = match (bw.min(bh), bw.max(bh)) { (8, 16) => (1usize, 1usize), (16, 32) => (2, 2), @@ -8741,6 +8847,72 @@ fn decode_rect4_16( (mi_row0, mi_col0 + i) }; let has_chroma = i % 2 == 1; + let (mode, uv, _tx) = decode_rect4_16_strip( + dec, + cdfs, + neighbours, + lmi, + horz, + has_chroma, + prev, + y, + u, + v, + enable_filter_intra, + allow_screen_content_tools, + base_q_idx, + tx_select, + reduced_tx_set, + )?; + if let Some(m) = uv { + last_uv_mode = m; + } + last_mode = mode; + prev = Some((lmi, mode)); + } + // The coarse 16-px cell holds one entry for the whole 16x16: the last + // strip is what a block below (right) sees through it, the mi-exact maps + // above answering everything finer. + neighbours.above_mode[c] = last_mode; + neighbours.left_mode[r] = last_mode; + neighbours.above_uv_mode[c] = last_uv_mode; + neighbours.left_uv_mode[r] = last_uv_mode; + neighbours.above_side[c] = bw; + neighbours.left_side[r] = bh; + Ok(()) +} + +/// One 16x4 / 4x16 strip of a 16x16-level 1:4 partition, intra-coded -- +/// [`decode_rect4_16`]'s per-strip body, lifted (lane-intra16x4) so the INTER +/// block path can decode a SINGLE intra strip of a partition whose other +/// strips are inter. `prev` is the previous strip's `(mi, mode)` (the +/// key-frame caller's coarse-cell stand-in; `None` on the inter path, where +/// every strip publishes its own mi-exact mode). Returns +/// `(y_mode, uv_predict_mode when this strip closes the 4:2:0 chroma pair)`. +#[allow(clippy::too_many_arguments)] +fn decode_rect4_16_strip( + dec: &mut SymbolDecoder, + cdfs: &mut Cdfs, + neighbours: &mut Neighbours, + lmi: (usize, usize), + horz: bool, + has_chroma: bool, + prev: Option<((usize, usize), usize)>, + y: &mut PlaneBuf, + u: &mut PlaneBuf, + v: &mut PlaneBuf, + enable_filter_intra: bool, + allow_screen_content_tools: bool, + base_q_idx: u8, + tx_select: bool, + reduced_tx_set: bool, +) -> Result<(usize, Option, (usize, usize))> { + let (r, c) = (lmi.0 / (SUB / MI), lmi.1 / (SUB / MI)); + let (bw, bh) = if horz { (16usize, 4usize) } else { (4, 16) }; + let (mi_w, mi_h) = (bw / MI, bh / MI); + let scan: &[u16] = if horz { &SCAN_16X4 } else { &SCAN_4X16 }; + let chroma_scan: &[u16] = if horz { &SCAN_8X4 } else { &SCAN_4X8 }; + let mut last_uv_mode: Option = None; // `decode_block_rect4`'s own neighbour rule: the coarse 16-px cell // aliases all four strips onto one entry, so the mi-exact map wins and // the previous strip stands in on the split axis. @@ -8814,7 +8986,16 @@ fn decode_rect4_16( // depth symbol is the 3-symbol `tx_size_cat1` -- not the 2-symbol // `cat0` a 4x8 leaf reads nor the `cat2` a 32x8 strip does. let depth = if tx_select { - let ctx = tx_size_context_rect(neighbours, lmi, bw, bh); + // lane-intra16x4: on an INTER frame `get_tx_size_context` reads the + // real `TXFM_CONTEXT` bands ([`tx_size_context_txfm_rect`], what + // the 2:1 intra-in-inter strip already does); the key frame's + // deblock-grid approximation is only right where those bands were + // never written. + let ctx = if INTRA_IN_INTER_MODE.with(std::cell::Cell::get).is_some() { + tx_size_context_txfm_rect(neighbours, lmi, bw, bh) + } else { + tx_size_context_rect(neighbours, lmi, bw, bh) + }; dec.symbol(&mut cdfs.tx_size_cat1[ctx]) } else { 0 @@ -9156,7 +9337,7 @@ fn decode_rect4_16( slot[2] = v_state; } } - last_uv_mode = uv_predict_mode; + last_uv_mode = Some(uv_predict_mode); } if horz { RECT4_16_HORZ_HITS.with(|h| h.set(h.get() + 1)); @@ -9170,21 +9351,10 @@ fn decode_rect4_16( record_strip_palette( neighbours, lmi, bw, bh, pal_y_size, pal_y_colors, pal_uv_size, pal_uv_colors, ); - last_mode = mode; - prev = Some((lmi, mode)); - } - // The coarse 16-px cell holds one entry for the whole 16x16: the last - // strip is what a block below (right) sees through it, the mi-exact maps - // above answering everything finer. - neighbours.above_mode[c] = last_mode; - neighbours.left_mode[r] = last_mode; - neighbours.above_uv_mode[c] = last_uv_mode; - neighbours.left_uv_mode[r] = last_uv_mode; - neighbours.above_side[c] = bw; - neighbours.left_side[r] = bh; - Ok(()) + Ok((mode, last_uv_mode, (tx_w, tx_h))) } + /// Decodes one true `bw`x`bh` superblock-level `PARTITION_HORZ`/ /// `PARTITION_VERT` strip (lane-sbpart r2, `bw, bh` one of `(64, 32)` / /// `(32, 64)` -- [`decode_block_rect`]'s own sibling one level up). Unlike @@ -21657,7 +21827,33 @@ fn decode_inter_block( // footprint), so an INTRA 16x4 / 4x16 strip inside a 1:4 partition is // refused by name rather than decoded with a 8x2 chroma transform // libaom never coded. - if write_w.min(write_h) < 8 { + // lane-intra16x4 r1: the strip DECODES (through the key frame's own + // per-strip body, [`decode_rect4_16_strip`]) only under + // `EC_INTRA16X4_DECODE`. It is not pixel-proven yet -- the r1 gate is + // RED (`a_real_aomenc_inter_sequence_with_intra_16x4_strips_...`, + // #[ignore]d with its measurement), so the refusal STAYS the default + // behaviour and the env switch is what the film probes use to measure + // the next wall. Class `refusal-lifted-without-a-gate`. + let strip16 = strip_chroma + .filter(|_| std::env::var_os("EC_INTRA16X4_DECODE").is_some()) + .filter(|_| write_w.min(write_h) == 4 && write_w.max(write_h) == 16) + .map(|s| (s.horz, s.has_chroma)); + if write_w.min(write_h) < 8 && strip16.is_none() { + if std::env::var_os("EC_INTRA16X4").is_some() { + let (idx, hc, prev_inter) = match strip_chroma { + Some(s) => ( + if s.horz { rmi - s.pair_mi.0 } else { cmi - s.pair_mi.1 }, + s.has_chroma, + s.prev.is_some(), + ), + None => (9, true, false), + }; + eprintln!( + "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={}", + TX_SELECT_INTER.with(std::cell::Cell::get), + allow_screen_content_tools, + ); + } return Err(unsupported( "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)", )); @@ -21680,6 +21876,7 @@ fn decode_inter_block( write_h, skip, allow_screen_content_tools, + strip16, y, u, v, diff --git a/crates/ec-av1/src/stream.rs b/crates/ec-av1/src/stream.rs index 9aebbe31..33115438 100644 --- a/crates/ec-av1/src/stream.rs +++ b/crates/ec-av1/src/stream.rs @@ -80,6 +80,12 @@ pub fn rect32x8_inter_tu_hits() -> [usize; 2] { crate::decode::rect32x8_inter_tu_hits() } +/// lane-intra16x4: `(16x4, 4x16, chroma-reference)` INTRA strips decoded inside +/// an inter 16x16-level 1:4 partition. +pub fn intra16x4_in_inter_hits() -> (usize, usize, usize) { + crate::decode::intra16x4_in_inter_hits() +} + /// lane-r14 r3: RECTANGULAR var-tx leaf transform units, `[32x16, 16x32]` -- /// the leaves `sub_tx_size_map` produces when a 1:4 strip with a 64-px axis /// splits its transform (`[TX_64X16] == TX_32X16`, `[TX_16X64] == TX_16X32`). @@ -10988,6 +10994,262 @@ mod tests { } + #[test] + #[ignore = "RED at lane-intra16x4 r1: the decode path is behind \ + EC_INTRA16X4_DECODE=1 and still mismatches ffmpeg (attempt 1, 8-bit, 192x128 \ + cq60: frame 1 luma differs from (175, 0), 8400 px, with the two intra 16x4 \ + strips at mi(1,40)/(3,40) themselves exact) -- lanes/intra16x4-r1.report.md"] + // lane-intra16x4 r1: an INTRA-coded 16x4 / 4x16 strip inside an INTER + // frame's 16x16-level 1:4 partition -- the wall all six of his film cuts + // stopped at once lane-rectres landed. The shape's chroma is the pair's: + // `is_chroma_reference` (av1_common_int.h:1454) is false on the even + // strips (which read no `uv_mode` and code no chroma at all) and the odd + // one codes ONE 8x4 (4x8) chroma unit at the pair's origin -- and when the + // pair mixes an intra and an inter strip, the chroma is predicted per the + // strip that CARRIES it, which is exactly what routing the intra strip + // through the key frame's own proven per-strip body + // (`decode_rect4_16_strip`) gives. + // + // Recipes found by a 24 + 24 run sweep (three sources x cq 16..63 x two + // sizes, `~/.cache/intra16x4-tmp/sweep*.sh`): aomenc only picks an INTRA + // 1:4 strip on an inter frame at HIGH cq over content its MC cannot + // predict -- a per-frame-random bright bar sweeping the frame (HORZ_4 + // strips) and a `X*Y` product sinusoid under temporal noise (VERT_4). + // Both sources hash identically twice (report). + fn a_real_aomenc_inter_sequence_with_intra_16x4_strips_in_1to4_partitions_decodes_pixel_exact() { + const NAME: &str = + "a_real_aomenc_inter_sequence_with_intra_16x4_strips_in_1to4_partitions_decodes_pixel_exact"; + let _gate_lock = lock_gate_counters(); + if !have_ffmpeg() { + eprintln!("SKIP {NAME}: no ffmpeg"); + return; + } + if !have_aomenc() { + eprintln!("SKIP {NAME}: no aomenc at {}", aomenc_path().display()); + return; + } + let frame_count = 6usize; + // (source kind, cq, width, height) -- the four recipes of the 48-run + // sweep (`~/.cache/intra16x4-tmp/sweep*.sh`, table in the report) that + // reach an INTRA 1:4 strip on an inter frame. `bar` is a per-frame + // random bright bar sweeping the frame (its MC failure is what makes + // aomenc's RD pick intra at 16x4), `prod` an `X*Y` product sinusoid + // under temporal noise; `_v` transposes the structure so the RD picks + // PARTITION_VERT_4. + const RECIPES: [(&str, u32, usize, usize); 4] = [ + ("noise", 60, 128, 128), + ("bar", 60, 192, 128), + ("prod_v", 56, 128, 128), + ("prod", 56, 160, 128), + ]; + // [16x4 intra strips, 4x16 intra strips, of which chroma-reference]: + // how many pixel-exact attempts fired each, over both bit depths. + let mut arms_total = [0u32; 3]; + // Attempts that refused on the sub-8x8 intra block inside an inter + // frame -- a DIFFERENT lane's shape, and the measured blocker of every + // VERT_4-carrying recipe in the sweep. + let mut sub8_intra_refusals = 0u32; + for bit_depth in [8u32, 10u32] { + let (mut named_refusals, mut matched, mut out_of_scope, mut oos_mismatch) = + (0u32, 0u32, 0u32, 0u32); + let mut arms_proved = [0u32; 3]; + for attempt in 0..RECIPES.len() as u32 { + let (kind, cq, width, height) = RECIPES[attempt as usize]; + let duration = frame_count as f64 / 25.0; + // Both sources are deterministic (two identical y4m hashes, + // report): `random()` here is geq's own indexed PRNG and the + // noise filter carries an explicit `all_seed`. + let (lum, noise) = match kind { + "noise" => ( + format!("128+58*sin((X+N*3)/6)+40*sin(Y/11)"), + ",noise=alls=40:allf=t+u:all_seed=7", + ), + "bar" => ( + format!( + "if(lt(mod(X+N*37,{width}),24),random(N*100+X+Y)*255,128+50*sin(Y/7))" + ), + "", + ), + "prod_v" => ( + "128+60*sin((X*Y+N*97)/13)+50*sin((Y+N*11)/5)".to_string(), + ",noise=alls=25:allf=t:all_seed=11", + ), + _ => ( + "128+60*sin((X*Y+N*97)/13)+50*sin((X+N*11)/5)".to_string(), + ",noise=alls=25:allf=t:all_seed=11", + ), + }; + let source = format!( + "color=c=gray:s={width}x{height}:d={duration}:r=25,format=gray,\ + geq=lum='{lum}',format=yuv420p{noise}" + ); + let pix_fmt = if bit_depth == 10 { "yuv420p10le" } else { "yuv420p" }; + let y4m = Command::new("ffmpeg") + .args([ + "-v", "error", "-f", "lavfi", "-i", &source, "-t", &duration.to_string(), + "-pix_fmt", pix_fmt, "-strict", "-1", "-f", "yuv4mpegpipe", "-", + ]) + .stdin(Stdio::null()) + .stdout(Stdio::piped()) + .stderr(Stdio::piped()) + .output() + .expect("ffmpeg failed to run"); + assert!( + y4m.status.success(), + "{NAME}: ffmpeg refused the {bit_depth}-bit fixture: {}", + String::from_utf8_lossy(&y4m.stderr) + ); + let cq_arg = format!("--cq-level={cq}"); + let depth_arg = format!("--bit-depth={bit_depth}"); + let input_depth_arg = format!("--input-bit-depth={bit_depth}"); + let args: Vec<&str> = vec![ + "--codec=av1", "--passes=1", "--end-usage=q", &cq_arg, "--cpu-used=0", + "--threads=1", "--row-mt=0", "--sb-size=64", &depth_arg, &input_depth_arg, + "--enable-restoration=0", "--enable-palette=0", "--deltaq-mode=0", + "--enable-filter-intra=0", "--enable-cfl-intra=0", "--enable-intrabc=0", + "--lag-in-frames=0", "--kf-max-dist=9999", "--tile-columns=0", + // Per-arm overrides go LAST (aomenc keeps the last + // occurrence of a repeated --enable-* flag). + "--enable-tx-size-search=1", "--enable-rect-partitions=1", + "--enable-ab-partitions=1", "--enable-1to4-partitions=1", + "--enable-intra-edge-filter=1", + "--min-partition-size=4", "--max-partition-size=16", + "--obu", "-o", "-", "-", + ]; + let mut child = Command::new(aomenc_path()) + .args(&args) + .stdin(Stdio::piped()) + .stdout(Stdio::piped()) + .stderr(Stdio::piped()) + .spawn() + .expect("aomenc failed to start"); + child + .stdin + .take() + .expect("aomenc stdin") + .write_all(&y4m.stdout) + .expect("writing y4m to aomenc"); + let out = child.wait_with_output().expect("aomenc failed to run"); + assert!( + out.status.success(), + "aomenc refused the fixture: {}", + String::from_utf8_lossy(&out.stderr) + ); + let stream = out.stdout; + let before = crate::stream::intra16x4_in_inter_hits(); + let frames = match decode_stream(&stream) { + Err(e) => { + let msg = e.to_string(); + assert!( + msg.contains("unsupported"), + "{NAME} failed outright, not a named refusal ({bit_depth}-bit, \ + attempt {attempt}): {msg}" + ); + if msg.contains("sub-8x8") { + sub8_intra_refusals += 1; + } + named_refusals += 1; + eprintln!("{bit_depth}-bit attempt {attempt} refusal: {msg}"); + continue; + } + Ok(frames) => frames, + }; + let after = crate::stream::intra16x4_in_inter_hits(); + let fired = [ + (after.0 - before.0) as u32, + (after.1 - before.1) as u32, + (after.2 - before.2) as u32, + ]; + let ffmpeg_frames = if bit_depth == 10 { + ffmpeg_decode_sequence_10bit(&stream, width, height, frame_count) + } else { + ffmpeg_decode_sequence(&stream, width, height, frame_count) + }; + assert_eq!(frames.len(), frame_count); + let mismatched = frames + .iter() + .zip(&ffmpeg_frames) + .any(|(got, want)| got.y != want.y || got.u != want.u || got.v != want.v); + if fired[0] + fired[1] == 0 { + out_of_scope += 1; + if mismatched { + oos_mismatch += 1; + eprintln!( + "{NAME}: {bit_depth}-bit attempt {attempt} MISMATCHES with zero \ + intra 1:4 strip -- another shape's defect" + ); + } + continue; + } + if mismatched { + for (i, (got, want)) in frames.iter().zip(&ffmpeg_frames).enumerate() { + let bad: Vec = + (0..got.y.len()).filter(|&k| got.y[k] != want.y[k]).collect(); + if !bad.is_empty() { + eprintln!( + "{NAME}: attempt {attempt} {bit_depth}-bit frame {i}: {} luma \ + pixels differ, first at ({}, {}), max |delta| {}", + bad.len(), + bad[0] % width, + bad[0] / width, + bad.iter() + .map(|&k| (got.y[k] as i32 - want.y[k] as i32).abs()) + .max() + .unwrap_or(0) + ); + } + } + } + for (i, (got, want)) in frames.iter().zip(&ffmpeg_frames).enumerate() { + assert_eq!(got.y, want.y, "{NAME} frame {i} luma vs ffmpeg (attempt {attempt}, {bit_depth}-bit, arms {fired:?})"); + assert_eq!(got.u, want.u, "{NAME} frame {i} U vs ffmpeg (attempt {attempt}, {bit_depth}-bit, arms {fired:?})"); + assert_eq!(got.v, want.v, "{NAME} frame {i} V vs ffmpeg (attempt {attempt}, {bit_depth}-bit, arms {fired:?})"); + } + for a in 0..3 { + if fired[a] > 0 { + arms_proved[a] += 1; + arms_total[a] += 1; + } + } + matched += 1; + } + eprintln!( + "{NAME} ({bit_depth}-bit): {named_refusals} named refusals, {matched} pixel-exact \ + attempts carrying an intra 1:4 strip, per-arm attempts \ + 16x4/4x16/chroma-reference={arms_proved:?}, {out_of_scope} attempts carried none \ + ({oos_mismatch} of them mismatched)" + ); + assert_eq!( + oos_mismatch, 0, + "{NAME}: {oos_mismatch} attempt(s) with no intra 1:4 strip decoded but mismatched \ + ffmpeg -- a defect of another shape, not a pass" + ); + } + // MEASURED (48-run sweep, report table): every recipe that makes + // aomenc pick an intra PARTITION_VERT_4 strip ALSO contains an intra + // 8x4/4x8 or 4x4 block inside a sub-8x8 partition, a refusal this lane + // does not own -- so the 4x16 orientation is blocked on THAT and the + // gate asserts exactly that. If the sub-8x8 lane lands and this arm + // still reads 0, or the blocker changes, this fails. + assert!( + arms_total[1] > 0 || sub8_intra_refusals > 0, + "{NAME}: the 4x16 (PARTITION_VERT_4) arm read 0 \ + (16x4/4x16/chroma-reference={arms_total:?}) and NO attempt refused on the sub-8x8 \ + intra block -- its documented blocker is gone, so a zero arm is now unexplained" + ); + for (a, what) in [ + (0usize, "intra 16x4 strips (PARTITION_HORZ_4)"), + (2, "chroma-reference (odd) intra strips carrying the pair's 8x4/4x8 chroma"), + ] { + assert!( + arms_total[a] > 0, + "{NAME}: arm {a} ({what}) never fired on a pixel-exact attempt \ + (16x4/4x16/chroma-reference={arms_total:?}) -- unproven" + ); + } + } + + #[test] // lane-sbab r1: the SUPERBLOCK-level (64x64) AB partitions on an INTER // frame -- PARTITION_HORZ_A/_HORZ_B/_VERT_A/_VERT_B at 64x64, i.e. two diff --git a/lanes/intra16x4-r1.report.md b/lanes/intra16x4-r1.report.md new file mode 100644 index 00000000..05ca66e4 --- /dev/null +++ b/lanes/intra16x4-r1.report.md @@ -0,0 +1,110 @@ +# lane-intra16x4 r1 — an INTRA 16x4/4x16 strip inside an inter 16x16-level 1:4 partition + +## Step 1 MEASURE — what the six film probes actually stop on + +Env-gated print at the refusal site (`crates/ec-av1/src/decode.rs`, `EC_INTRA16X4=1`), +each probe under `systemd-run --scope -p MemoryMax=6G`, `EC_RECT64_SPLIT=1`: + +| probe | shape | pair parity | has_chroma | prev strip single-ref inter | skip | tx_select | screen tools | +|---|---|---|---|---|---|---|---| +| 10-bit 3840x1608 cut 0 | 16x4 | 0 (EVEN) | false | – | 0 | 1 | 0 | +| 10-bit 3840x1608 cut 300 | 4x16 | 0 | false | – | 0 | 1 | 0 | +| 10-bit 1920x792 @900 | 4x16 | 0 | false | – | 0 | 1 | 0 | +| 10-bit 1920x792 @5400 | 16x4 | 0 | false | – | 0 | 1 | 0 | +| 10-bit 1920x792 @6300 | 16x4 | 0 | false | – | 0 | 1 | 0 | +| 10-bit 1920x792 @8100 | 4x16 | 0 | false | – | 0 | 1 | 0 | + +6 of 6 first fire on an EVEN strip: `is_chroma_reference` false, so that strip reads no +`uv_mode` and codes no chroma at all. All non-skip, all with `--enable-tx-size-search` +on, none in a screen-content frame. + +EVIDENCE: shell probe, 6 streams | `EC_RECT64_SPLIT=1 EC_INTRA16X4=1 decode_probe ` | 3x 16x4 + 3x 4x16, all pair-parity 0 / has_chroma=false / skip=0 + +## Step 2 IMPLEMENT + +* `decode.rs` `decode_rect4_16_strip` (new) — the per-strip body of the KEY FRAME's + `decode_rect4_16`, lifted verbatim into its own function (mode info, luma TU or split + walk, the pair's 8x4/4x8 chroma when `has_chroma`, palette bands, skip/lf/partition + bands). `decode_rect4_16` now calls it four times; no behaviour change on the key-frame + path (the whole suite is the check). +* `decode.rs` `decode_intra_rect_in_inter` — new `strip16: Option<(horz, has_chroma)>` + parameter and a 16x4/4x16 arm that runs that body with `INTRA_IN_INTER_MODE = Some((0, + skip))`: `size_group_lookup[BLOCK_16X4] == size_group_lookup[BLOCK_4X16] == 0` + (oracle `common_data.h:61`, indices 16/17), so the mode is `y_mode[0]` and `skip` is + the one `decode_inter_block` already read. Chroma needs NO new code: the lifted body + already codes one 8x4 (4x8) unit at the PAIR's origin on the odd strip only, which is + exactly "predicted per the carrying strip's own type" for a mixed intra/inter pair; + the inter side's `InterStripChroma::prev == None` arm already covers intra-then-inter. +* Same arm publishes what the key-frame body does not and an INTER frame needs + (`set_txfm_ctxs` + `txfm_partition_update`, libaom `decodeframe.c:1078`): the strip's + tx size into `above_txfm`/`left_txfm` and the var-tx partition context — the 2:1 + intra-in-inter strip already does this. On the inter path the tx-depth symbol also + reads `tx_size_context_txfm_rect` (the real TXFM_CONTEXT bands) instead of the key + frame's deblock-grid approximation. +* Counter `INTRA16X4_IN_INTER_HITS` `[16x4, 4x16, chroma-reference]`, + `stream::intra16x4_in_inter_hits()`, printed by `decode_probe` as `intra16x4_in_inter:`. + +**The path is behind `EC_INTRA16X4_DECODE=1`; the refusal is still the default.** It is +not pixel-proven (below), and a refusal is lifted only with a green gate. + +## Step 3 GATE — RED, and what it measured + +`a_real_aomenc_inter_sequence_with_intra_16x4_strips_in_1to4_partitions_decodes_pixel_exact` +(`stream.rs`, `#[ignore]`d with its own measurement in the reason string): real aomenc, +`--enable-1to4-partitions=1 --enable-intra-edge-filter=1 --min-partition-size=4 +--max-partition-size=16` (per-arm overrides last), 4 recipes x {8, 10} bit, every +decode-order frame Y/U/V vs ffmpeg, refusals counted never SKIPped, `oos_mismatch == 0`. + +Recipe search: 48 + 48 runs (`~/.cache/intra16x4-tmp/sweep.sh`, `sweep2.sh`, logs +`sweep.log`/`sweep2.log`/`sweep3.log`). aomenc picks an INTRA 1:4 strip on an inter frame +only at HIGH cq (>= 56) over content its MC cannot predict. Both gate sources hash +identically twice. + +RED, with the strips themselves exact: + +* 192x128 cq60 "bar" source, 8-bit, 4 intra 16x4 strips (2 chroma-reference): frame 0 + exact, frame 1 luma differs from (175, 0), 8400 px. The strips are at mi(1,40)/(3,40) + = px x 160..175, y 4..15 — the first differing pixel is at y=0, i.e. in the EVEN + (inter) strip ABOVE them, and chroma of the pair is exact. +* 128x128 cq60 "noise" source, 8-bit, 2 skipped intra 16x4 strips at px(80,112)/(80,120): + frame 1 differs from (122, 13) — 99 rows ABOVE the first strip, so that arm's mismatch + is not this shape at all (an unrelated defect this recipe exposes; the gate's + `oos_mismatch` cannot separate it because the stream does carry strips). +* The txfm-context publication above was found the same way and DID fix a first + measurement: before it, a 128x128 stream decoded its two intra strips at mi(23,16)/ + (23,20) exactly and broke on the very next 16x16 row (rows 96+, x>=62), chroma exact. + +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 + +## Film frontier — before / after (with `EC_INTRA16X4_DECODE=1`) + +All six probes leave the 16x4/4x16 wall. Before: every one stopped on +`an intra 16x4/4x16 strip inside an inter 16x16-level 1:4 partition ...`. +After (counters are strips decoded): + +| probe | new refusal | intra16x4_in_inter | +|---|---|---| +| hg cut 0 | an intra 8x4/4x8 block inside an inter frame's sub-8x8 HORZ/VERT partition | 16x4=14 | +| hg cut 300 | same | 4x16=8 | +| 1920x792 @900 | same | 4x16=4 | +| 1920x792 @5400 | same | 16x4=1 4x16=2 | +| 1920x792 @6300 | same | 16x4=1 4x16=1 | +| 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 | + +Since the walls are unproven pixel-wise, this is a REACH measurement, not a decode claim. + +EVIDENCE: 6 probes | `EC_RECT64_SPLIT=1 EC_INTRA16X4_DECODE=1 decode_probe ` | refusal string moves to the sub-8x8 intra wall on 5 of 6, counters 1..14 strips each + +## Residue + +* fix-now (next round): the r1 gate is RED. The defect is NOT in the strip's own pixels + (they match) but in what the strip leaves behind for its neighbours — after the + txfm-context fix, the surviving mismatch starts in the pair's EVEN (inter) strip above + the intra one, which points at the pair's chroma/mv bookkeeping or the deblock grid + the intra strip publishes over the pair, not at its luma. +* deferred: `EC_RECT64_SPLIT` bypass removal — no witness; the rect64 hits still live + inside frames that refuse (confirms lane-rect64port r1 and lane-rectres r1). +* deferred: the 4x16 (VERT_4) orientation is unprovable by aomenc today — every + VERT_4-carrying recipe in the 96-run sweep also contains an intra 8x4/4x8 or 4x4 + sub-8x8 block, another lane's refusal. The gate asserts exactly that blocker. +* accepted: `refusal_inventory.rs` / `gate_coverage.rs` unchanged — no refusal was lifted.