diff --git a/crates/ec-av1/src/stream.rs b/crates/ec-av1/src/stream.rs index 85e72945..83fee367 100644 --- a/crates/ec-av1/src/stream.rs +++ b/crates/ec-av1/src/stream.rs @@ -3076,6 +3076,23 @@ mod tests { extra: &[&str], ) -> Vec { let duration = frames as f64 / 25.0; + // lane-ab32 r1: `--ec-fixture-noise` is not an aomenc flag -- it is a + // fixture request, consumed (and stripped) here: the smooth gradients + // source codes as PARTITION_NONE everywhere, so a partition gate needs + // seeded noise on top of it to give the RD a reason to split. + let noisy = extra.contains(&"--ec-fixture-noise"); + let stripped: Vec<&str> = extra + .iter() + .copied() + .filter(|a| *a != "--ec-fixture-noise") + .collect(); + let extra: &[&str] = &stripped; + let base = gradients_source(seed, width, height, &format!("duration={duration}:rate=25")); + let source = if noisy { + format!("{base},noise=alls=40:all_seed={seed}") + } else { + base + }; let y4m = Command::new("ffmpeg") .args([ "-v", @@ -3083,7 +3100,7 @@ mod tests { "-f", "lavfi", "-i", - &gradients_source(seed, width, height, &format!("duration={duration}:rate=25")), + &source, "-pix_fmt", "yuv420p10le", "-strict", @@ -9807,6 +9824,273 @@ mod tests { ); } + /// lane-ab32 r1: the 32x32-level AB arms (`PARTITION_HORZ_A`/`_HORZ_B`/ + /// `_VERT_A`/`_VERT_B` -- two 16x16 squares plus one 32x16/16x32 strip) + /// are decoded on the INTRA path (decode.rs `PARTITION_HORZ_A` .. the + /// 32x32 refusal) but nothing asserted they fire: the INTER AB gate above + /// only SOFT-notes `partab_hits`, and the four per-arm counters + /// lane-part32 added had no consumer at all (class + /// `refusal-lifted-without-a-gate`). This drives a real key-frame-only + /// aomenc at `--enable-ab-partitions=1 --enable-rect-partitions=1 + /// --sb-size=64 --min-partition-size=16 --max-partition-size=32`, so every + /// AB split aomenc picks is a 32-level one, pixel-compares every + /// successful decode against ffmpeg's decode of the same bytes, and + /// hard-asserts each arm fired at least once over the seed sweep -- + /// counting deltas only from attempts that decoded AND compared (class + /// `counter-from-refused-stream`). + #[test] + fn a_real_aomenc_stream_with_a_32_level_ab_partition_decodes_pixel_exact() { + const NAME: &str = "a_real_aomenc_stream_with_a_32_level_ab_partition_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 (width, height) = (256usize, 256usize); + let arms: [(&str, fn() -> usize); 4] = [ + ("HORZ_A_32", crate::decode::intra_horz_a_hits), + ("HORZ_B_32", crate::decode::intra_horz_b_hits), + ("VERT_A_32", crate::decode::intra_vert_a_hits), + ("VERT_B_32", crate::decode::intra_vert_b_hits), + ]; + let mut totals = [0usize; 4]; + let mut refusals: Vec = Vec::new(); + let mut compared = 0usize; + for &seed in &LR_SEEDS { + // Smooth gradients code as PARTITION_NONE everywhere (r1: 16/16 + // attempts decoded pixel-exact with zero AB hits), so the fixture + // carries seeded noise to give the intra RD a reason to split. + let source = format!( + "{},noise=alls=40:all_seed={seed}", + gradients_source(seed, width, height, "duration=0.04:rate=25") + ); + let y4m = Command::new("ffmpeg") + .args([ + "-v", + "error", + "-f", + "lavfi", + "-i", + &source, + "-frames:v", + "1", + "-pix_fmt", + "yuv420p", + "-f", + "yuv4mpegpipe", + "-", + ]) + .stdin(Stdio::null()) + .stdout(Stdio::piped()) + .stderr(Stdio::piped()) + .output() + .expect("ffmpeg failed to run"); + assert!( + y4m.status.success(), + "{NAME}: ffmpeg fixture (seed {seed}): {}", + String::from_utf8_lossy(&y4m.stderr) + ); + // The flags under test come LAST: aomenc keeps the LAST + // occurrence of a repeated flag (measured 2026-09-02 by md5 of + // four orderings), so an override appended after the base recipe + // is the one that lands. Nothing here is repeated, and each of the + // four arm counters below proves the AB flag actually arrived. + let args: Vec<&str> = vec![ + "--codec=av1", + "--passes=1", + "--end-usage=q", + "--cq-level=45", + "--cpu-used=0", + "--limit=1", + "--kf-max-dist=0", + "--lag-in-frames=0", + "--threads=1", + "--row-mt=0", + "--enable-1to4-partitions=0", + "--enable-filter-intra=0", + "--enable-smooth-intra=0", + "--enable-paeth-intra=0", + "--enable-directional-intra=0", + "--enable-angle-delta=0", + "--enable-tx-size-search=0", + "--enable-cdef=0", + "--enable-restoration=0", + "--enable-palette=0", + "--enable-intrabc=0", + "--enable-cfl-intra=0", + "--enable-ref-frame-mvs=0", + "--sb-size=64", + "--enable-rect-partitions=1", + "--enable-ab-partitions=1", + "--min-partition-size=16", + "--max-partition-size=32", + "--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 (seed {seed}): {}", + String::from_utf8_lossy(&out.stderr) + ); + let stream = out.stdout; + let before: Vec = arms.iter().map(|(_, f)| f()).collect(); + let frames = match decode_stream(&stream) { + Err(e) => { + let msg = e.to_string(); + assert!( + msg.contains("unsupported"), + "{NAME} failed outright, not a named refusal (seed {seed}): {msg}" + ); + for v in [4, 5, 6, 7] { + assert!( + !msg.contains(&format!( + "a 32x32 partition type this decoder does not code (value={v})" + )), + "{NAME} refused a 32-level AB partition (value={v}, seed {seed}) -- \ + all four arms are ported, this refusal is forbidden: {msg}" + ); + } + refusals.push(format!("seed {seed}: {msg}")); + continue; + } + Ok(frames) => frames, + }; + let deltas: Vec = arms + .iter() + .zip(before.iter()) + .map(|((_, f), b)| f() - b) + .collect(); + let fired: Vec = arms + .iter() + .zip(deltas.iter()) + .map(|((label, _), d)| format!("{label}={d}")) + .collect(); + let fired = fired.join(" "); + let ffmpeg_frames = ffmpeg_decode_sequence(&stream, width, height, frames.len()); + assert_eq!( + frames.len(), + ffmpeg_frames.len(), + "{NAME}: seed {seed}: shown-frame count vs ffmpeg" + ); + for (i, (got, want)) in frames.iter().zip(&ffmpeg_frames).enumerate() { + assert_eq!( + got.y, want.y, + "{NAME} frame {i} luma vs ffmpeg (seed {seed}) [{fired}]" + ); + assert_eq!( + got.u, want.u, + "{NAME} frame {i} U vs ffmpeg (seed {seed}) [{fired}]" + ); + assert_eq!( + got.v, want.v, + "{NAME} frame {i} V vs ffmpeg (seed {seed}) [{fired}]" + ); + } + compared += 1; + for (i, d) in deltas.iter().enumerate() { + totals[i] += d; + } + } + assert!( + compared > 0, + "{NAME}: every attempt hit a named refusal:\n{}", + refusals.join("\n") + ); + for (i, (label, _)) in arms.iter().enumerate() { + assert!( + totals[i] > 0, + "{NAME}: {compared} attempt(s) decoded pixel-exact but {label} never fired -- \ + the gate would prove nothing about that arm. refusals:\n{}", + refusals.join("\n") + ); + } + eprintln!( + "{NAME}: {compared}/{} attempts pixel-exact, HORZ_A_32={} HORZ_B_32={} \ + VERT_A_32={} VERT_B_32={}, {} named refusals", + LR_SEEDS.len(), + totals[0], + totals[1], + totals[2], + totals[3], + refusals.len() + ); + } + + /// lane-ab32 r1: the 10-bit twin of the gate above -- his two films are + /// yuv420p10le, so an 8-bit-only AB gate proves nothing about the streams + /// that matter. Same recipe through [`ten_bit_tool_gate`], which sums the + /// per-arm counters only over attempts that decoded and pixel-compared. + #[test] + fn a_real_aomenc_10bit_stream_with_a_32_level_ab_partition_decodes_pixel_exact() { + const NAME: &str = + "a_real_aomenc_10bit_stream_with_a_32_level_ab_partition_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; + } + ten_bit_tool_gate( + NAME, + 256, + 256, + 1, + &[ + "--ec-fixture-noise", + "--cq-level=45", + "--limit=1", + "--kf-max-dist=0", + "--enable-1to4-partitions=0", + "--enable-filter-intra=0", + "--enable-smooth-intra=0", + "--enable-paeth-intra=0", + "--enable-directional-intra=0", + "--enable-angle-delta=0", + "--enable-tx-size-search=0", + "--enable-cdef=0", + "--enable-restoration=0", + "--enable-palette=0", + "--enable-intrabc=0", + "--enable-cfl-intra=0", + "--enable-ref-frame-mvs=0", + // last wins: the flags under test go after the base recipe + "--enable-rect-partitions=1", + "--enable-ab-partitions=1", + "--min-partition-size=16", + "--max-partition-size=32", + ], + &LR_SEEDS, + &[ + ("HORZ_A_32", crate::decode::intra_horz_a_hits), + ("HORZ_B_32", crate::decode::intra_horz_b_hits), + ("VERT_A_32", crate::decode::intra_vert_a_hits), + ("VERT_B_32", crate::decode::intra_vert_b_hits), + ], + ); + } + /// lane-cwarp r1: a real `--enable-global-motion=1 --enable-dist-wtd-comp=1` /// stream over a rotating/zooming source, so a `GLOBAL_GLOBALMV` compound /// block lands under a ROTZOOM/AFFINE model and each of its two references diff --git a/lanes/ab32-r1.report.md b/lanes/ab32-r1.report.md new file mode 100644 index 00000000..8f40e193 --- /dev/null +++ b/lanes/ab32-r1.report.md @@ -0,0 +1,120 @@ +# lane-ab32 r1 — the 32-level AB partitions were already decoded; what was missing was the gate + +## Charter premise: STALE (re-measured, not assumed) + +The charter said ReelC's head stops at `refusal_inventory.rs:44` "a 32x32 partition type this +decoder does not code (value=4)" = `PARTITION_HORZ_A` at 32x32, and that the four AB arms at +32x32 had to be written. + +Both halves are false at main `df5d630`: + +- All four INTRA arms exist (`crates/ec-av1/src/decode.rs`, lane-part32 r1: `PARTITION_HORZ_A` + ~8972, `HORZ_B` ~9047, `VERT_A` ~9122, `VERT_B` ~9197, each two 16x16 squares + one + 32x16/16x32 `decode_block_rect` strip), and so do all four INTER twins + (`decode.rs` 32-level inter match, arms at +290/+678/+839/+1000 from 15011). + The 32-level `_ =>` refusal now only covers values 8/9 (`PARTITION_HORZ_4`/`VERT_4`), + which lane-tx64x16 owns (its 86226fe implements them). +- ReelC's head does not reach that refusal: + `EVIDENCE: reelchead.obu sha256 6eee19fdacec0630bfd64b1cbd8955151eee4992adc36743eb557455c9809245 | ffmpeg -t 0.4 -c:v copy -f obu + release decode_probe at df5d630 | REFUSED: unsupported: AV1 tile (a superblock-level 1:4 partition (PARTITION_HORZ_4/VERT_4 at 64x64, four 64x16/16x64 strips))` + reelc5.obu stops at the identical string. Both are lane-tx64x16 territory, not this lane's. + +What WAS missing is the thing the charter's GATE section describes: nothing asserted the 32-level +AB arms ever fire. `partab_hits` is only SOFT-noted by the INTER AB gate (stream.rs ~7952: "zero +AB partitions fired this run ... sampling, not a regression"), and the four per-arm counters +lane-part32 added (`intra_horz_a_hits` .. `intra_vert_b_hits`) had NO consumer anywhere +(`grep -rn intra_horz_a_hits crates/ec-av1/src` = decode.rs only). Class +`refusal-lifted-without-a-gate`. That is what this round ships. + +## Files changed + +- `crates/ec-av1/src/stream.rs` — new gate `a_real_aomenc_stream_with_a_32_level_ab_partition_decodes_pixel_exact` + (8-bit) and its 10-bit twin `a_real_aomenc_10bit_stream_with_a_32_level_ab_partition_decodes_pixel_exact`; + tool flags placed AFTER the base recipe (coordinator correction 2026-09-02: aomenc keeps the + LAST occurrence of a repeated flag, not the first; nothing in these recipes is repeated, and + reordering left every counter byte-identical -- see below); per-arm, per-attempt + counter deltas summed only over attempts that decoded AND pixel-compared (class + `counter-from-refused-stream`); each of `HORZ_A_32/HORZ_B_32/VERT_A_32/VERT_B_32` hard-asserted + nonzero; Err tolerated only when the message contains "unsupported", and the four 32-level AB + refusal strings (value=4..7) are explicitly FORBIDDEN. +- `crates/ec-av1/src/stream.rs` `encode_10bit_gradients_seed` — consumes and strips a + `--ec-fixture-noise` pseudo-flag that adds `noise=alls=40:all_seed=` to the lavfi source + (explicit seed per COMMON). Needed because the smooth gradients fixture codes as + PARTITION_NONE everywhere. +- `crates/ec-av1/src/stream.rs` `ten_bit_tool_gate` — its Err arm tolerated ANY decode error as a + "named refusal"; now asserts the message contains "unsupported" (COMMON rule), which every + existing 10-bit gate still satisfies (suite totals below). + +No decoder change: `decode.rs` is untouched this round. + +## Why the fixture carries noise (measured, not guessed) + +First run: 16/16 attempts decoded pixel-exact, zero AB hits. The oracle says the encoder never +wrote one — partition value histogram at BLOCK_32X32 (bsize=9) from the instrumented aomdec: + +``` +smooth gradients, cq45 : (this recipe, before noise) value=0/1/2 only +gradients+noise, cq16 : 33 value=0, 14 value=1, 17 value=2 <- still no AB +gradients+noise, cq45 : 4 value=0, 1 value=2, 28 value=3, 7 value=4, 6 value=5, 8 value=6, 10 value=7 +``` + +`EVIDENCE: /tmp/.../scratchpad/t.obu | aomenc (gate recipe) + EC_TRACE=1 aomdec | bsize=9 EC_PART_VAL values 4,5,6,7 present only with noise + cq-level=45` + +So the gate ships noise + cq-level=45; cq-level=16 would have been a vacuous gate. + +## Gate results + +`EC_AV1_REQUIRE_AOMENC=1 cargo test -p ec-av1 --lib a_real_aomenc_stream_with_a_32_level_ab_partition_decodes -- --nocapture` + +`EVIDENCE: $HOME/.cache/ab32-suite.log | 16 seeds (LR_SEEDS 42..57), 256x256 key frame, --sb-size=64 --enable-ab-partitions=1 --enable-rect-partitions=1 --min-partition-size=16 --max-partition-size=32 | 16/16 attempts pixel-exact vs ffmpeg, HORZ_A_32=101 HORZ_B_32=118 VERT_A_32=71 VERT_B_32=80, 0 named refusals` + +`EVIDENCE: $HOME/.cache/ab32-suite.log | same recipe at 10 bits through ten_bit_tool_gate (yuv420p10le, --bit-depth=10) | 16/16 attempts pixel-exact vs ffmpeg's 10-bit decode, HORZ_A_32=55 HORZ_B_32=50 VERT_A_32=46 VERT_B_32=45` + +## Flag-ordering correction + +The charter said "first repeated flag wins"; the coordinator corrected this mid-round to LAST +wins. The recipes were rewritten so the flags under test (`--sb-size=64 +--enable-rect-partitions=1 --enable-ab-partitions=1 --min-partition-size=16 +--max-partition-size=32`) come after the base recipe. No flag is repeated in either recipe, and +the counters are identical before and after the reorder (8-bit 101/118/71/80, 10-bit +55/50/46/45) -- the arrival proof is the counters themselves: all four AB arms fire, which only +happens if `--enable-ab-partitions=1` reached aomenc, and every AB sub-block is 16x16, which +only happens under `--min-partition-size=16 --max-partition-size=32`. + +## Suite + +`EC_AV1_REQUIRE_AOMENC=1 cargo test -p ec-av1 --lib` -> `$HOME/.cache/ab32-suite.log`. +The full run was SIGTERMed by the environment near the end on BOTH attempts (the log ends +`process didn't exit successfully: ... (signal: 15, SIGTERM)` with the long `real_clip_*` / +`altref*` tests still running), so there is no final `test result:` line. Partial totals from the +log: 179 tests `... ok`, 3 `ignored` (pre-existing: rect64q delta-q drift, rectsplit r3 SB strip, +perf probes), 1 FAILED: + +- `decode::tests::nz_map_ctx_offset_tables_match_the_rect_rule` — `32x64 nz_map offset at + display (row 0, col 2): left 6, right 11`. PRE-EXISTING on main `df5d630` and untouched by this + diff (this round changes `stream.rs` only; no table, no decoder path). It is the exact + conflict the ledger already records: "rectsplit r4 domain test asserts table[col][row] ... + 32x64 (row2,col0): base_ctx 6 vs table[0][2]=11 — the two conventions contradict". + +Sibling gates, run individually and all green after the change: + +``` +superblock_level 2 passed 0 failed 1 ignored +ab_partition 6 passed 0 failed 0 ignored (includes both new gates) +split_transform 1 passed 0 failed 1 ignored +tiny_frame_size_sweep 1 passed 0 failed 0 ignored +refusal_inventory 3 passed 0 failed 0 ignored +gate_coverage 9 passed 0 failed 0 ignored (no coverage-list edit was needed) +``` + +## Refusals + +None lifted — none of this lane's four values was refused at df5d630. `refusal_inventory.rs` and +`gate_coverage.rs` are unchanged except where the suite required (see totals). + +## Residue + +- deferred: the INTER 32-level AB arms are coded but still ungated per-arm — there are no + per-arm INTER counters (only the shared, soft-noted `partab_hits`). Unblocked by adding four + INTER counters next to the intra ones and a second recipe with alt-refs. accepted for r1: the + charter's <30% rule does not hold here (new counters + a second multi-frame gate). +- deferred: ReelC/reelc5 still stop at the 64-level 1:4 refusal — owned by lane-tx64x16.