diff --git a/crates/ec-av1/examples/decode_probe.rs b/crates/ec-av1/examples/decode_probe.rs index 20c59892..c72e40b3 100644 --- a/crates/ec-av1/examples/decode_probe.rs +++ b/crates/ec-av1/examples/decode_probe.rs @@ -46,6 +46,11 @@ fn main() { println!("inter16_1to4: horz4={h4} vert4={v4} chroma_pairs={pairs} sub8_pieces={sub8}"); let leaf = ec_av1::stream::vartx_rect_leaf_hits(); println!("vartx_rect_leaf: 32x16={} 16x32={}", leaf[0], leaf[1]); + let i4 = ec_av1::stream::intra_rect4_in_inter_counters(); + println!( + "intra_rect4_in_inter: 64x16={} 16x64={} 32x8={} 8x32={}", + i4.0, i4.1, i4.2, i4.3 + ); let ir = ec_av1::stream::inter_rect_counters(); println!( "inter_rect: 32x8={} 8x32={} 64x32={} 32x64={} 64x16={} 16x64={}", diff --git a/crates/ec-av1/src/decode.rs b/crates/ec-av1/src/decode.rs index 1797c599..68271105 100644 --- a/crates/ec-av1/src/decode.rs +++ b/crates/ec-av1/src/decode.rs @@ -2012,6 +2012,33 @@ pub(crate) fn intra_rect_in_inter_split_tx_hits() -> [usize; 3] { INTRA_RECT_IN_INTER_SPLIT_TX_HITS.with(std::cell::Cell::get) } +// lane-intra14 r1: how many intra-coded 1:4 strips decoded on the INTER +// block path, per shape -- [0] 64x16, [1] 16x64, [2] 32x8, [3] 8x32. Every +// one of them was the named refusal "an intra-coded 1:4 (or other non-2:1) +// rect strip on the inter block path" before this round. +thread_local! { + static INTRA_RECT4_IN_INTER_HITS: std::cell::Cell<[usize; 4]> = + const { std::cell::Cell::new([0; 4]) }; +} + +/// Current value of [`INTRA_RECT4_IN_INTER_HITS`] for one shape +/// (0 = 64x16, 1 = 16x64, 2 = 32x8, 3 = 8x32). +pub(crate) fn intra_rect4_strip_in_inter_hits(shape: usize) -> usize { + INTRA_RECT4_IN_INTER_HITS.with(|c| c.get()[shape]) +} + +// lane-intra14 r1: set while an INTRA block of an INTER frame is decoded +// through one of the key-frame rect readers ([`decode_block_rect4`], +// [`decode_block_rect64`]). `Some((size_group, skip))` tells +// [`read_intra_mode_rect`] that (a) `skip`/segment id/cdef/delta-q were +// already read by [`decode_inter_block`] and (b) the luma mode comes off +// `y_mode_cdf[size_group_lookup[bsize]]` (libaom `read_intra_block_mode_info`, +// decodemv.c:1189), never the key frame's above/left `kf_y_mode` pair. +thread_local! { + static INTRA_IN_INTER_MODE: std::cell::Cell> = + const { std::cell::Cell::new(None) }; +} + // lane-rectx r5: how many times a NON-strip `kf_y_mode` reader // ([`decode_block`], [`decode_block_rect`], [`decode_block_rect64`]) took an // above/left mode from the mi-exact map that DIFFERS from its coarse 16x16 @@ -5652,6 +5679,13 @@ fn read_intra_mode_rect( } else { cfl }; + // lane-intra14 r1: on the INTER block path everything up to and including + // `is_inter` was already read by [`decode_inter_block`], so this reader + // starts at the mode syntax with the `skip` that caller read. + let inter = INTRA_IN_INTER_MODE.with(std::cell::Cell::get); + let skip = if let Some((_, skip)) = inter { + skip + } else { // Same `intra_segment_id` placement as the square reader above. let (seg_w_mi, seg_h_mi) = (bw / 4, bh / 4); if seg_id_pre_skip() { @@ -5670,9 +5704,18 @@ fn read_intra_mode_rect( maybe_read_delta_q(dec, cdfs, mi_r, mi_c, false, skip); maybe_read_delta_lf(dec, cdfs, mi_r, mi_c, false, skip); istep!("dq", 0); - let above_ctx = INTRA_MODE_CTX[above_mode]; - let left_ctx = INTRA_MODE_CTX[left_mode]; - let mode = dec.symbol(&mut cdfs.kf_y_mode[above_ctx][left_ctx]); + skip + }; + // libaom `read_intra_block_mode_info` (decodemv.c:1189) vs the key + // frame's `read_intra_frame_mode_info` (decodemv.c:1065 `read_intra_mode` + // off `kf_y_mode_cdf[above][left]`). + let mode = if let Some((size_group, _)) = inter { + dec.symbol(&mut cdfs.y_mode[size_group]) + } else { + let above_ctx = INTRA_MODE_CTX[above_mode]; + let left_ctx = INTRA_MODE_CTX[left_mode]; + dec.symbol(&mut cdfs.kf_y_mode[above_ctx][left_ctx]) + }; istep!("mode", mode as i32); let angle_delta_y = if (V_PRED..=D67_PRED).contains(&mode) { read_angle_delta(dec, &mut cdfs.angle_delta[mode - V_PRED]) @@ -6328,9 +6371,18 @@ fn decode_intra_rect_in_inter( (8, 16) => (1usize, 1usize), (16, 32) => (2, 2), (32, 64) => (3, 3), + // lane-intra14 r1: the 1:4 strips, read off libaom's own tables -- + // `size_group_lookup` (common_data.h:61) gives BLOCK_8X32/32X8 group + // 1 and BLOCK_16X64/64X16 group 2, while + // `bsize_to_tx_size_depth_table` (blockd.h:1347) gives them depth + // 3 and 4, i.e. tx categories 2 and 3 -- the diagonal a 2:1 strip + // keeps is genuinely broken here, which is why the shape was refused + // rather than read from the 2:1 row. + (8, 32) => (1, 2), + (16, 64) => (2, 3), _ => { return Err(unsupported( - "an intra-coded 1:4 (or other non-2:1) rect strip on the inter block path", + "an intra-coded 16x4/4x16 strip on the inter block path (the 16x16-level 1:4 inter partition is refused before this point)", )) } }; @@ -6343,6 +6395,70 @@ fn decode_intra_rect_in_inter( is consumed for square blocks only)", )); } + // lane-intra14 r1: a 1:4 strip decodes through the very readers the KEY + // FRAME path already proves for this shape ([`decode_block_rect4`] at the + // 32 level, [`decode_block_rect64`] at 64 -- both already handle the 1:4 + // luma/chroma transform tables, the per-unit split walk and the strip's + // own neighbour records). The ONLY difference on an inter frame is the + // mode-info read, which [`INTRA_IN_INTER_MODE`] switches to + // `read_intra_block_mode_info`'s `y_mode[size_group]` plus the `skip` + // this caller already read. `tx_cat` above is the same category those + // readers hardcode (cat 2 in `decode_block_rect4`, cat 3 in + // `decode_block_rect64`), asserted here so a future shape cannot drift. + if bw.max(bh) == 4 * bw.min(bh) { + debug_assert_eq!(tx_cat, if bw.max(bh) == 64 { 3 } else { 2 }); + INTRA_IN_INTER_MODE.with(|c| c.set(Some((size_group, skip)))); + let res = if bw.max(bh) == 64 { + decode_block_rect64( + dec, + cdfs, + neighbours, + (mi_r / (SUB / MI), mi_c / (SUB / MI)), + bw, + bh, + 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), + ) + } else { + decode_block_rect4( + dec, + cdfs, + neighbours, + (mi_r, mi_c), + bw, + bh, + 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), + ) + .map(|_| ()) + }; + INTRA_IN_INTER_MODE.with(|c| c.set(None)); + res?; + let shape = match (bw, bh) { + (64, 16) => 0, + (16, 64) => 1, + (32, 8) => 2, + _ => 3, + }; + INTRA_RECT4_IN_INTER_HITS.with(|h| { + let mut v = h.get(); + v[shape] += 1; + h.set(v); + }); + return Ok(()); + } let mode = dec.symbol(&mut cdfs.y_mode[size_group]); if mode >= 13 { return Err(unsupported( diff --git a/crates/ec-av1/src/refusal_inventory.rs b/crates/ec-av1/src/refusal_inventory.rs index b4406b5c..4f01eaa3 100644 --- a/crates/ec-av1/src/refusal_inventory.rs +++ b/crates/ec-av1/src/refusal_inventory.rs @@ -88,7 +88,7 @@ const REFUSALS: &[&str] = &[ // inter path's intra arm now routes 2:1 strips through `decode_rect_split`); // what is left is the 1:4 shape, whose `bsize_to_tx_size_cat` breaks the // size-group/category diagonal the 2:1 shapes share. - "an intra-coded 1:4 (or other non-2:1) rect strip on the inter block path", + "an intra-coded 16x4/4x16 strip on the inter block path (the 16x16-level 1:4 inter partition is refused before this point)", // The same arm's screen-content gate: palette/intrabc syntax is consumed // for square blocks only, so a strip in such a frame would skip symbols. "a HORZ/VERT intra strip in a screen-content frame (palette syntax is consumed for square blocks only)", diff --git a/crates/ec-av1/src/stream.rs b/crates/ec-av1/src/stream.rs index a00bbbfa..fd286162 100644 --- a/crates/ec-av1/src/stream.rs +++ b/crates/ec-av1/src/stream.rs @@ -68,6 +68,18 @@ pub fn inter_rect_counters() -> (usize, usize, usize, usize, usize, usize) { ) } +/// lane-intra14 r1: INTRA-coded 1:4 strips decoded on the INTER block path +/// (64x16, 16x64, 32x8, 8x32) -- the counters a recipe sweep needs from +/// outside the crate. +pub fn intra_rect4_in_inter_counters() -> (usize, usize, usize, usize) { + ( + crate::decode::intra_rect4_strip_in_inter_hits(0), + crate::decode::intra_rect4_strip_in_inter_hits(1), + crate::decode::intra_rect4_strip_in_inter_hits(2), + crate::decode::intra_rect4_strip_in_inter_hits(3), + ) +} + /// lane-r14 r2: luma transform units of an inter strip with a 64-px axis, /// coded as the truncated low-32 coefficient corner. pub fn rect64_inter_tu_hits() -> usize { @@ -4677,6 +4689,320 @@ mod tests { ); } + /// lane-intra14 r1's decisive gate: a real aomenc INTER sequence with + /// `--enable-1to4-partitions=1`, whose fast-zooming content makes aomenc + /// code INTRA blocks inside inter frames on 1:4 strip shapes (32x8/8x32 at + /// the 32 level, 64x16/16x64 at the superblock level). Every such block + /// was the named refusal "an intra-coded 1:4 (or other non-2:1) rect strip + /// on the inter block path" until this round; they now decode through the + /// same `decode_block_rect4` / `decode_block_rect64` readers the KEY FRAME + /// 1:4 paths already prove, with only the mode-info read switched to + /// `read_intra_block_mode_info` (libaom decodemv.c:1189). + /// + /// Hard-asserts `intra_rect4_strip_in_inter_hits` (0 = 64x16, 1 = 16x64, + /// 2 = 32x8, 3 = 8x32) summed over the attempts that were actually + /// pixel-compared, and every decode-order frame is compared. A decode that + /// succeeds is ALWAYS pixel-compared (class + /// [[gate-skips-on-its-own-failure]]); exhausting every attempt without a + /// counted strip is a FAILURE, never a SKIP. + #[test] + // r1 `#[ignore]`d this gate on "every stream with an intra 1:4 strip also + // hits the inter rect-strip refusal". r2 merged main 18bf7dc (lane-r14 + // a2e2e29 lifts exactly that refusal) and re-ran it: 3 of 40 attempts now + // decode whole and reach the pixel compare (0 before), one of them firing + // 64x16=4 16x64=3. But the compare fails on a defect this lane does not + // own -- MEASURED (r2, $HOME/.cache/intra14-r2-*.log): + // * seeds 46 and 54 fire ZERO 1:4 strips (`intra_rect4_strip_in_inter_hits` + // delta 0/0/0/0) and mismatch ffmpeg the same way as the firing seed 52: + // decode-order frame 3/4 luma ~3.7-4.5k samples, max |d| 6..17, then + // frames 5-7 drift to ~24k samples, max |d| ~220 as the references + // carry the error forward. + // * with `--enable-1to4-partitions=0` aomenc emits a BYTE-IDENTICAL + // stream at this recipe (same hits, same per-frame diff counts), so + // the 1:4 shape is not the discriminator either. + // i.e. this mandelbrot 192x128 source has a pre-existing INTER-frame + // pixel defect on this tree (r1 already recorded it as "open, NOT mine" + // with rect partitions off; it is now this gate's blocker). testsrc2 at + // 192x128 decodes pixel-exact on the same recipe but fires no 1:4 strip + // in 4 of 12 attempts that decode whole. So the gate stays `#[ignore]`d + // rather than weakened: a source whose baseline is exact AND that fires + // an intra 1:4 strip has not been found yet. + #[ignore = "blocked: the mandelbrot gate source has a pre-existing inter-frame pixel defect on this tree (zero-hit streams mismatch identically) -- see the MEASURED note above"] + fn a_real_aomenc_inter_sequence_with_an_intra_1to4_strip_decodes_pixel_exact() { + intra_rect4_in_inter_gate(8); + } + + /// The 10-bit arm (both of the user's films are `yuv420p10le`). + #[test] + // r1 `#[ignore]`d this gate on "every stream with an intra 1:4 strip also + // hits the inter rect-strip refusal". r2 merged main 18bf7dc (lane-r14 + // a2e2e29 lifts exactly that refusal) and re-ran it: 3 of 40 attempts now + // decode whole and reach the pixel compare (0 before), one of them firing + // 64x16=4 16x64=3. But the compare fails on a defect this lane does not + // own -- MEASURED (r2, $HOME/.cache/intra14-r2-*.log): + // * seeds 46 and 54 fire ZERO 1:4 strips (`intra_rect4_strip_in_inter_hits` + // delta 0/0/0/0) and mismatch ffmpeg the same way as the firing seed 52: + // decode-order frame 3/4 luma ~3.7-4.5k samples, max |d| 6..17, then + // frames 5-7 drift to ~24k samples, max |d| ~220 as the references + // carry the error forward. + // * with `--enable-1to4-partitions=0` aomenc emits a BYTE-IDENTICAL + // stream at this recipe (same hits, same per-frame diff counts), so + // the 1:4 shape is not the discriminator either. + // i.e. this mandelbrot 192x128 source has a pre-existing INTER-frame + // pixel defect on this tree (r1 already recorded it as "open, NOT mine" + // with rect partitions off; it is now this gate's blocker). testsrc2 at + // 192x128 decodes pixel-exact on the same recipe but fires no 1:4 strip + // in 4 of 12 attempts that decode whole. So the gate stays `#[ignore]`d + // rather than weakened: a source whose baseline is exact AND that fires + // an intra 1:4 strip has not been found yet. + #[ignore = "blocked: the mandelbrot gate source has a pre-existing inter-frame pixel defect on this tree (zero-hit streams mismatch identically) -- see the MEASURED note above"] + fn a_real_aomenc_inter_sequence_with_an_intra_1to4_strip_decodes_pixel_exact_10bit() { + intra_rect4_in_inter_gate(10); + } + + fn intra_rect4_in_inter_gate(bit_depth: u32) { + const NAME: &str = + "a_real_aomenc_inter_sequence_with_an_intra_1to4_strip_decodes_pixel_exact"; + if !have_ffmpeg() { + eprintln!("SKIP {NAME}: no ffmpeg"); + return; + } + if !have_aomenc() { + eprintln!("SKIP {NAME}: no aomenc at {}", aomenc_path().display()); + return; + } + let (width, height, frame_count) = (192usize, 128usize, 8usize); + let mut refusals: Vec = Vec::new(); + let mut uncounted_exact = 0u32; + let mut compared = 0u32; + let mut shapes = [0usize; 4]; + for attempt in 0..40u32 { + let seed = 42 + attempt; + // Same source class as the 2:1 sibling gate: a FAST mandelbrot + // zoom (`end_scale`/`end_pts`) so consecutive frames share almost + // no content and aomenc's RD codes blocks INTRA inside INTER + // frames, with `--kf-min-dist=1000` forbidding a new key frame. + let source = format!( + "mandelbrot=size={width}x{height}:start_scale={}:end_scale=0.004:end_pts=8:rate=25", + 5.0 - f64::from(attempt) * 0.06 + ); + let y4m = Command::new("ffmpeg") + .args([ + "-v", "error", "-f", "lavfi", "-i", &source, "-vf", "hue=s=0", "-pix_fmt", + if bit_depth == 10 { "yuv420p10le" } else { "yuv420p" }, + "-strict", "-1", "-t", "0.32", "-f", "yuv4mpegpipe", "-strict", "-1", "-", + ]) + .stdin(Stdio::null()) + .stdout(Stdio::piped()) + .stderr(Stdio::piped()) + .output() + .expect("ffmpeg failed to run"); + assert!( + y4m.status.success(), + "ffmpeg fixture: {}", + String::from_utf8_lossy(&y4m.stderr) + ); + let depth_args: &[&str] = if bit_depth == 10 { + &["-b", "10", "--input-bit-depth=10"] + } else { + &[] + }; + // MEASURED (r1, 40 attempts): `--cpu-used=0` makes aomenc pick + // 128x128 superblocks on this frame size, which decode_stream + // refuses by name, so the preset sweep starts at 1. + let cpu = format!("--cpu-used={}", 1 + attempt % 4); + // The higher the quantiser the more 1:4 intra strips inside inter + // frames, so the sweep walks cq 63 first. + let cq = format!("--cq-level={}", [63u32, 55, 45, 35][(attempt / 4) as usize % 4]); + let mut child = Command::new(aomenc_path()) + .args(depth_args) + .arg(&cpu) + .arg(&cq) + .args([ + // Every flag spelled exactly once (class + // [[aomenc-last-flag-wins]]). These are what the gate is + // about: 1:4 partitions ON, min size 16 so the 16x16-level + // 1:4 (refused elsewhere) is out of reach. + "--enable-rect-partitions=1", + "--enable-1to4-partitions=1", + // MEASURED (r1): at `--min-partition-size=16` aomenc codes + // 16x16-level 1:4 partitions (16x4/4x16 strips), which the + // inter partition path refuses by name (another lane's + // surface) in 12/40 attempts. 32 keeps this gate's two + // reachable levels -- the 32-level 32x8/8x32 and the + // superblock-level 64x16/16x64 -- and nothing else. + "--min-partition-size=32", + "--max-partition-size=64", + // MEASURED (r1): with tx-size search ON, 8/40 attempts stop + // at the 2:1 strip's own split-tx refusal (merge-cross-product, + // another lane's surface) before a 1:4 strip is reached. + "--enable-tx-size-search=0", + "--enable-filter-intra=1", + "--enable-intra-edge-filter=1", + "--codec=av1", + "--passes=1", + "--end-usage=q", + "--lag-in-frames=0", + "--auto-alt-ref=0", + "--kf-min-dist=1000", + "--kf-max-dist=1000", + "--threads=1", + "--row-mt=0", + "--enable-order-hint=0", + "--enable-warped-motion=0", + "--enable-obmc=0", + "--enable-masked-comp=0", + "--enable-interintra-comp=0", + "--enable-dist-wtd-comp=0", + "--enable-diff-wtd-comp=0", + "--enable-onesided-comp=0", + "--enable-interintra-wedge=0", + "--enable-smooth-interintra=0", + "--enable-ab-partitions=0", + "--enable-smooth-intra=0", + "--enable-paeth-intra=0", + "--enable-directional-intra=0", + "--enable-angle-delta=0", + "--enable-cdef=0", + "--enable-restoration=0", + // Ledger dead-end (lane-r14): a NEW gate spelling + // `--enable-cfl-intra=1` retires that tool from + // `NEVER_EXERCISED_8BIT` on the flag alone while no CfL + // hit counter exists to assert -- so it stays 0 here. + // Palette stays 0 for the same class of reason: this arm + // refuses a screen-content frame whole, so a palette flag + // would buy no coverage. + "--enable-palette=0", + "--enable-intrabc=0", + "--enable-cfl-intra=0", + "--enable-ref-frame-mvs=0", + "--obu", + "-o", + "-", + "-", + ]) + .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: Vec = + (0..4).map(decode::intra_rect4_strip_in_inter_hits).collect(); + let frames = match decode_stream(&stream) { + Ok(frames) => frames, + Err(e) => { + let msg = e.to_string(); + assert!( + msg.contains("unsupported"), + "intra-1:4-in-inter decode failed outright (seed {seed}): {msg}" + ); + refusals.push(format!("seed {seed} {cpu} {cq}: {msg}")); + continue; + } + }; + let delta: Vec = (0..4) + .map(|k| decode::intra_rect4_strip_in_inter_hits(k) - before[k]) + .collect(); + 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); + eprintln!( + "intra14 gate {bit_depth}-bit seed={seed} {cpu} {cq}: intra 1:4 strips in inter \ + frames 64x16={} 16x64={} 32x8={} 8x32={}", + delta[0], delta[1], delta[2], delta[3] + ); + for (i, (got, want)) in frames.iter().zip(&ffmpeg_frames).enumerate() { + for (plane, (g, w)) in [ + ("Y", (&got.y, &want.y)), + ("U", (&got.u, &want.u)), + ("V", (&got.v, &want.v)), + ] { + let stride = if plane == "Y" { width } else { width / 2 }; + if let Some(at) = g.iter().zip(w.iter()).position(|(a, b)| a != b) { + let maxd = g + .iter() + .zip(w.iter()) + .map(|(a, b)| i32::from(*a).abs_diff(i32::from(*b))) + .max() + .unwrap_or(0); + eprintln!( + "intra14 gate {bit_depth}-bit seed={seed}: frame {i} {plane} first \ + diff at ({}, {}) got {} want {} ({} samples differ, max |d|={maxd})", + at % stride, + at / stride, + g[at], + w[at], + g.iter().zip(w.iter()).filter(|(a, b)| a != b).count(), + ); + } + assert_eq!(g, w, "{plane} vs ffmpeg (seed {seed}, frame {i})"); + } + } + compared += 1; + if delta.iter().all(|d| *d == 0) { + uncounted_exact += 1; + refusals.push(format!( + "seed {seed} {cpu} {cq}: decoded and pixel-compared, but no intra 1:4 strip on \ + the inter path" + )); + } + for k in 0..4 { + shapes[k] += delta[k]; + } + // Both LEVELS (32 and 64) is the bar; orientation is whichever the + // encoder picks. + if shapes[0] + shapes[1] > 0 && shapes[2] + shapes[3] > 0 { + break; + } + } + gate_buckets( + NAME, + compared - uncounted_exact, + uncounted_exact, + refusals.len() - uncounted_exact as usize, + ); + eprintln!( + "{NAME} ({bit_depth}-bit): compared {compared} streams, intra 1:4 strips in inter \ + frames: 64x16={} 16x64={} 32x8={} 8x32={}; refusals:\n{}", + shapes[0], + shapes[1], + shapes[2], + shapes[3], + refusals.join("\n") + ); + assert!( + compared > 0, + "{NAME} ({bit_depth}-bit): every attempt hit a named refusal -- nothing was \ + pixel-compared:\n{}", + refusals.join("\n") + ); + assert!( + shapes[2] + shapes[3] > 0, + "{NAME} ({bit_depth}-bit): no 32-level intra 1:4 strip (32x8/8x32) fired over \ + {compared} compared streams (64x16={} 16x64={} 32x8={} 8x32={})", + shapes[0], + shapes[1], + shapes[2], + shapes[3] + ); + } + fn tx_select_inter_gate(bit_depth: u32) { if !have_ffmpeg() { eprintln!( diff --git a/lanes/intra14-r1.report.md b/lanes/intra14-r1.report.md new file mode 100644 index 00000000..ddfc8d70 --- /dev/null +++ b/lanes/intra14-r1.report.md @@ -0,0 +1,105 @@ +# lane-intra14 r1 -- intra-coded 1:4 rect strips on the INTER block path + +Branch `lane-intra14` off main `7a47fc1`. **RED**: the decoder work is done and +demonstrably fires, but NO real-aomenc attempt on this tree can be +pixel-compared, so the lifted refusal is **ungated** and this branch MUST NOT +merge as-is. + +## What changed + +* `crates/ec-av1/src/decode.rs:5987` (`decode_intra_rect_in_inter`) -- the + `(size_group, tx_cat)` table gains the 1:4 rows `(8,32) -> (1,2)` and + `(16,64) -> (2,3)`, read off libaom `size_group_lookup` + (common_data.h:61) and `bsize_to_tx_size_depth_table` (blockd.h:1347). A 1:4 + strip then decodes through the KEY-FRAME readers that already prove the + shape: `decode_block_rect4` (32-level 32x8/8x32) and `decode_block_rect64` + (SB-level 64x16/16x64) -- transform tables, per-unit split walk, chroma, + Reach, neighbour records, palette/filter-intra refusals all reused unchanged. +* `crates/ec-av1/src/decode.rs` `INTRA_IN_INTER_MODE` (thread-local) -- the one + genuine difference on an inter frame is the mode-info read. + `read_intra_mode_rect` now, when it is set, (a) takes the `skip` the inter + path already read instead of re-reading skip/segment id/cdef/delta-q and + (b) reads the luma mode off `y_mode[size_group]` + (libaom `read_intra_block_mode_info`, decodemv.c:1189) instead of + `kf_y_mode[above][left]` (decodemv.c's key-frame reader). Everything after + that -- angle deltas (decodemv.c:1191/1203), uv_mode + CfL (1196-1201), + palette (1215), filter intra (the `read_filter_intra_mode_info` tail) -- is + bit-identical between the two libaom readers, which is why no other symbol + needed a branch. +* Counters `INTRA_RECT4_IN_INTER_HITS` (0=64x16, 1=16x64, 2=32x8, 3=8x32), + exported as `stream::intra_rect4_in_inter_counters()` and printed by + `examples/decode_probe`. +* `refusal_inventory.rs:76` -- "an intra-coded 1:4 (or other non-2:1) rect + strip on the inter block path" replaced by the narrower + "an intra-coded 16x4/4x16 strip on the inter block path (the 16x16-level 1:4 + inter partition is refused before this point)": 16x4/4x16 is unreachable + because `decode.rs:20332` refuses the 16x16-level 1:4 inter partition first, + and `decode_block_rect4`'s tables are 32x8-specific. +* `stream.rs` -- gate `a_real_aomenc_inter_sequence_with_an_intra_1to4_strip_decodes_pixel_exact` + (+ `_10bit`), currently `#[ignore]`d with the blocker named (see below). + +## Why the gate cannot pass on this tree (MEASURED) + +40 gate attempts per depth + ~150 recipe-sweep attempts (frame sizes 64x64, +96x96, 128x128, 192x128, 256x192; mandelbrot fast-zoom, static-background + +moving overlay, 64x16/16x64/32x8/8x32 moving bars, testsrc2; cq 35..63; +cpu-used 1..4; min/max-partition-size 32/32, 32/64, 64/64): + +* Every stream in which an intra 1:4 strip actually fires (counters 1..4 per + stream, e.g. `32x8=4`, `64x16=2`, `16x64=3`, `8x32=4`) ALSO carries a + non-skip INTER 2:1 rect strip ("a non-skip rectangular (HORZ/VERT/HORZ_B) + strip needs rectangular residual coding"), an SB-level AB partition, or a + sub-8 inter partition -- each another lane's named refusal, hit before the + frame completes, so the attempt is never pixel-compared. +* Every recipe under which all attempts decode whole (`--max-partition-size=32`, + or a static background with a moving overlay) fires ZERO 1:4 intra strips: + aomenc only reaches for 1:4 partitions in the same neighbourhoods where it + also picks the SB-level rect/AB shapes this decoder still refuses. +* Class [[counter-from-refused-stream]] applies: the counters above come from + REFUSED streams and prove only that the new code path is entered, never that + its pixels are right. The gate counts deltas on decoded+compared attempts + only, which is why it currently fails/ignores rather than reading green. + +So: **un-ignore and re-run this gate once the inter rect-leaf lane (lane-r14 r3, +`decode.rs` var-tx leaves) lands** -- that is the refusal that aborts every +candidate stream. + +## Film check (his ReelB extract) + +`decode_probe scratchpad/census3/kf/seg_4500.obu` (3840x1608 yuv420p10le, +213 frame headers): + +* BEFORE (charter premise): stops at "an intra-coded 1:4 (or other non-2:1) + rect strip on the inter block path". +* AFTER: `intra_rect4_in_inter: 64x16=0 16x64=4 32x8=0 8x32=0` -- four intra + 16x64 strips decode -- and the stop string is now + "a split intra strip whose transform unit is 64x32 (no luma coefficient + tables for that shape here)" (`decode_rect_split`'s luma-shape guard: the + SB-level 2:1 strip at tx depth 0, i.e. a TX_64X32 luma transform, which no + path here codes). Frames decoded (EC_AV1_FINAL_DUMP file count): 1 (the head + key frame) -- the new stop is still inside decode-order frame 1. + +EVIDENCE: /tmp/claude-1000/.../scratchpad/census3/kf/seg_4500.obu | decode_probe before/after the change, EC_AV1_FINAL_DUMP file count | 4 intra 16x64 strips decoded; stop string moved from the 1:4 refusal to "transform unit is 64x32"; 1 frame dumped +EVIDENCE: $HOME/.cache/intra14-suite-r1.log | `cargo test -p ec-av1 --lib` under a systemd unit (MemoryMax=10G) | test result: ok. 367 passed; 0 failed; 33 ignored (2 of them this lane's gate arms); 616.84s + +## Residue + +* fix-now (next round / successor lane): the gate is `#[ignore]`d. deferred -- + what unblocks it: the inter rect-strip refusal ("a non-skip rectangular + (HORZ/VERT/HORZ_B) strip needs rectangular residual coding"), lane-r14 r3. +* deferred: pixel-byte compare of the film's pre-stop frames through + EC_PROBE_OUT16 -- only ONE frame decodes before the stop, and it is the key + frame already proven bit-exact by lane-hgkf; what unblocks a meaningful + compare is the 64x32 luma transform above. +* accepted: `--enable-cfl-intra=0` and `--enable-palette=0` in the new gate + (ledger dead-end: a new gate spelling `--enable-cfl-intra=1` retires the tool + from `NEVER_EXERCISED_8BIT` on the flag alone with no CfL counter to assert; + the screen-content frame is refused whole on this path, so a palette flag + would buy no coverage). Deviation from the charter's flag list, stated here. +* accepted: `--enable-tx-size-search=0` and `--min-partition-size=32` in the + gate recipe -- measured, both named in the source comments. +* open (NOT mine, found here): at 192x128 mandelbrot start_scale 4.76, cq 55, + cpu-used 1, WITHOUT any rect/1:4 partition (`--enable-rect-partitions=0`), + decode-order frame 4 mismatches ffmpeg by 3729 luma samples (max |d| = 6) and + frames 5-7 drift (24k samples, max |d| ~220). Pre-existing square-path defect + on this tree, unrelated to this lane. diff --git a/lanes/intra14-r2.report.md b/lanes/intra14-r2.report.md new file mode 100644 index 00000000..fbfcfd0a --- /dev/null +++ b/lanes/intra14-r2.report.md @@ -0,0 +1,101 @@ +# lane-intra14 r2 -- merge main, un-ignore the gate, re-measure + +Branch `lane-intra14`, base main `18bf7dc`. **RED**: the r1 blocker refusal is +gone and the gate now reaches the pixel compare, but every compared attempt +mismatches on a defect this lane does not own, so the lifted refusal is still +**ungated** and this branch MUST NOT merge as-is. + +## 1. Merge (commit 4672212) + +`git merge --no-commit main` -- one conflict (stream.rs counter accessors, +resolved keeping BOTH lanes' functions: `intra_rect4_in_inter_counters` and +lane-r14's `rect64_inter_tu_hits`). md5 of the merged files vs main: + +| file | main | merged | +|---|---|---| +| cdf.rs (incl. NZ_MAP / FILTER_INTRA regions) | a3fb168e | a3fb168e | +| cdf_state.rs | 6faaa22c | 6faaa22c | +| encode.rs | 6c9f9f66 | 6c9f9f66 | +| mvstack.rs | 3ff196a2 | 3ff196a2 | + +i.e. every file this lane does not own came through byte-identical to main; +`decode.rs` / `refusal_inventory.rs` / `decode_probe.rs` carry only this lane's +additions on top of main's text (`git diff main -- ` reviewed hunk by hunk). + +## 2. The gate, un-ignored and re-run (8-bit, 40 attempts) + +`--exact stream::tests::a_real_aomenc_inter_sequence_with_an_intra_1to4_strip_decodes_pixel_exact --nocapture` + +Before (r1 tree): 40/40 attempts refused, 0 pixel-compared. +After the merge: **3 attempts decode whole**, one of them firing the feature: + +* seed 52 (`--cpu-used=3 --cq-level=45`): `64x16=4 16x64=3 32x8=0 8x32=0` +* seed 46 (`--cpu-used=1 --cq-level=55`): `0 0 0 0` +* seed 54 (`--cpu-used=1 --cq-level=35`): `0 0 0 0` + +All three MISMATCH ffmpeg, and **the two zero-hit attempts mismatch exactly like +the firing one**: decode-order frame 3/4 luma ~3.7-4.5k samples at max |d| 6..17 +(first diff around x=128..141, y=58..59), then frames 5-7 drift to ~24k samples +at max |d| ~220 as the references carry the error. So the failure is NOT the 1:4 +strip path: it is a pre-existing INTER-frame defect of this mandelbrot 192x128 +source on this tree -- the same one r1 already recorded as "open, NOT mine" +(3729 samples, max |d| = 6, with rect partitions off). Control: re-encoding the +seed-52 recipe with `--enable-1to4-partitions=0` yields a byte-identical stream +(same hits, same per-frame diff counts), so aomenc ignores that flag here and +the shape is not the discriminator either. + +Remaining refusals over the 40 attempts (37 of them, all other lanes' surfaces): +inter SB-level AB (12), inter 16x16-level AB or 1:4 (6), non-skip rect strip +needs rect residual coding (5), split intra strip whose TU is 32x64 / 64x32 (5), +inter partition below 8x8 (4), sub-8 angle delta / other (5). + +The two gate arms are therefore **`#[ignore]`d again, with the new blocker +measured and named in the source** (stream.rs, above both arms) instead of the +stale r1 reason. The gate itself is unchanged and unweakened: counters are +per-attempt deltas on decoded+compared attempts only, every decode-order frame +compared, a decode error is never a SKIP. + +### Recipe hunt for a clean-baseline source (240-recipe matrix + a 4-source probe) +* matrix 192x128/256x192/128x128 x min-part 16/32 x tx-size-search 0/1 x + cq 63/55/45/35/25 x cpu 1..4 (98 recipes ran before the 10-min bound): exactly + ONE fired 1:4 strips (192x128, min=32, txs=1, cq35, cpu2 -> `64x16=2 16x64=4`) + and it mismatches (118035 samples); 7 more decoded with zero hits. +* `testsrc2=192x128` on the same recipe: 4 of 12 attempts decode **pixel-exact** + (clean baseline) but fire zero 1:4 strips; the other 8 hit named refusals. +* `--enable-cfl-intra=1` was NOT re-measured -- the run budget went to the + mismatch triage. deferred. + +## 3. Film check (his ReelB extract, unchanged by the merge) + +`decode_probe scratchpad/census3/kf/seg_4500.obu` (3840x1608 yuv420p10le, 213 +frame headers): still stops at "a split intra strip whose transform unit is +64x32 (no luma coefficient tables for that shape here)", still decodes +`intra_rect4_in_inter: 64x16=0 16x64=4 32x8=0 8x32=0`. `EC_AV1_FINAL_DUMP` file +count is 0 (r1 measured 1 on the pre-merge tree) -- the stop is inside +decode-order frame 1 either way. + +EVIDENCE: $HOME/.cache/intra14-r2-fi0.log, $HOME/.cache/intra14-r2-sweep.log, $HOME/.cache/intra14-r2-src.log | un-ignored gate + 240-recipe matrix + 4-source probe under systemd-run scopes | 3/40 attempts pixel-compared (0 before the merge), seed 52 fires 64x16=4 16x64=3, and the two zero-hit attempts mismatch identically +EVIDENCE: scratchpad/census3/kf/seg_4500.obu | decode_probe under a 6G scope, EC_AV1_FINAL_DUMP file count | stop string unchanged ("transform unit is 64x32"), 4 intra 16x64 strips decoded, 0 frames completed + +## 4. Suite + +`cargo test -p ec-av1 --lib` under a user systemd unit (MemoryMax=10G): +**370 passed; 0 failed; 34 ignored** (2 of the ignored are this lane's gate +arms); 889.13s. + +EVIDENCE: $HOME/.cache/intra14-suite-r2.log | systemd-run --user --unit ... MemoryMax=10G, EC_NOMEMGUARD=1 EC_AV1_REQUIRE_AOMENC=1, nice -n 10 -j3 | test result: ok. 370 passed; 0 failed; 34 ignored; 889.13s + +## Residue + +* fix-now (successor / another lane): the pre-existing inter-frame pixel defect + on 192x128 mandelbrot at cq 35..55, cpu 1..3 -- reproducible with ZERO 1:4 + strips and zero rect partitions, first divergence decode-order frame 3/4 luma + around (130,58) with max |d| < 20. It is unrefused (silent), so every gate on + mandelbrot inter content is measuring it. deferred -- what unblocks this lane: + either that fix, or a source whose inter baseline is exact AND that fires an + intra 1:4 strip. +* deferred: `--enable-cfl-intra=1` arm -- what unblocks it: a green gate to add + it to. +* accepted: `--enable-filter-intra=1` stays in the recipe. An earlier r2 run with + it at 0 showed zero mismatches, but only ONE stream was compared in that run, + so it proves nothing; the claim is withdrawn.