forge
Explore
Log in

Don't you dare go Hollow

Merge branch 'lane-ab32': 32x32-level AB partition gates at 8/10-bit; 10-bit fixture noise knob

Browse files at this commit

8e2dc8687a470b75f12ccf31a25da9ff418a7d66Ahmet Kaan GümüşParent: 2d1093559e552c
crates/ec-av1/src/stream.rsmodified+285 -1
@@ -3076,6 +3076,23 @@ mod tests {
3076 extra: &[&str],3076 extra: &[&str],
3077 ) -> Vec<u8> {3077 ) -> Vec<u8> {
3078 let duration = frames as f64 / 25.0;3078 let duration = frames as f64 / 25.0;
3079+ // lane-ab32 r1: `--ec-fixture-noise` is not an aomenc flag -- it is a
3080+ // fixture request, consumed (and stripped) here: the smooth gradients
3081+ // source codes as PARTITION_NONE everywhere, so a partition gate needs
3082+ // seeded noise on top of it to give the RD a reason to split.
3083+ let noisy = extra.contains(&"--ec-fixture-noise");
3084+ let stripped: Vec<&str> = extra
3085+ .iter()
3086+ .copied()
3087+ .filter(|a| *a != "--ec-fixture-noise")
3088+ .collect();
3089+ let extra: &[&str] = &stripped;
3090+ let base = gradients_source(seed, width, height, &format!("duration={duration}:rate=25"));
3091+ let source = if noisy {
3092+ format!("{base},noise=alls=40:all_seed={seed}")
3093+ } else {
3094+ base
3095+ };
3079 let y4m = Command::new("ffmpeg")3096 let y4m = Command::new("ffmpeg")
3080 .args([3097 .args([
3081 "-v",3098 "-v",
@@ -3083,7 +3100,7 @@ mod tests {
3083 "-f",3100 "-f",
3084 "lavfi",3101 "lavfi",
3085 "-i",3102 "-i",
3086- &gradients_source(seed, width, height, &format!("duration={duration}:rate=25")),3103+ &source,
3087 "-pix_fmt",3104 "-pix_fmt",
3088 "yuv420p10le",3105 "yuv420p10le",
3089 "-strict",3106 "-strict",
@@ -9807,6 +9824,273 @@ mod tests {
9807 );9824 );
9808 }9825 }
9809 9826
9827+ /// lane-ab32 r1: the 32x32-level AB arms (`PARTITION_HORZ_A`/`_HORZ_B`/
9828+ /// `_VERT_A`/`_VERT_B` -- two 16x16 squares plus one 32x16/16x32 strip)
9829+ /// are decoded on the INTRA path (decode.rs `PARTITION_HORZ_A` .. the
9830+ /// 32x32 refusal) but nothing asserted they fire: the INTER AB gate above
9831+ /// only SOFT-notes `partab_hits`, and the four per-arm counters
9832+ /// lane-part32 added had no consumer at all (class
9833+ /// `refusal-lifted-without-a-gate`). This drives a real key-frame-only
9834+ /// aomenc at `--enable-ab-partitions=1 --enable-rect-partitions=1
9835+ /// --sb-size=64 --min-partition-size=16 --max-partition-size=32`, so every
9836+ /// AB split aomenc picks is a 32-level one, pixel-compares every
9837+ /// successful decode against ffmpeg's decode of the same bytes, and
9838+ /// hard-asserts each arm fired at least once over the seed sweep --
9839+ /// counting deltas only from attempts that decoded AND compared (class
9840+ /// `counter-from-refused-stream`).
9841+ #[test]
9842+ fn a_real_aomenc_stream_with_a_32_level_ab_partition_decodes_pixel_exact() {
9843+ const NAME: &str = "a_real_aomenc_stream_with_a_32_level_ab_partition_decodes_pixel_exact";
9844+ let _gate_lock = lock_gate_counters();
9845+ if !have_ffmpeg() {
9846+ eprintln!("SKIP {NAME}: no ffmpeg");
9847+ return;
9848+ }
9849+ if !have_aomenc() {
9850+ eprintln!("SKIP {NAME}: no aomenc at {}", aomenc_path().display());
9851+ return;
9852+ }
9853+ let (width, height) = (256usize, 256usize);
9854+ let arms: [(&str, fn() -> usize); 4] = [
9855+ ("HORZ_A_32", crate::decode::intra_horz_a_hits),
9856+ ("HORZ_B_32", crate::decode::intra_horz_b_hits),
9857+ ("VERT_A_32", crate::decode::intra_vert_a_hits),
9858+ ("VERT_B_32", crate::decode::intra_vert_b_hits),
9859+ ];
9860+ let mut totals = [0usize; 4];
9861+ let mut refusals: Vec<String> = Vec::new();
9862+ let mut compared = 0usize;
9863+ for &seed in &LR_SEEDS {
9864+ // Smooth gradients code as PARTITION_NONE everywhere (r1: 16/16
9865+ // attempts decoded pixel-exact with zero AB hits), so the fixture
9866+ // carries seeded noise to give the intra RD a reason to split.
9867+ let source = format!(
9868+ "{},noise=alls=40:all_seed={seed}",
9869+ gradients_source(seed, width, height, "duration=0.04:rate=25")
9870+ );
9871+ let y4m = Command::new("ffmpeg")
9872+ .args([
9873+ "-v",
9874+ "error",
9875+ "-f",
9876+ "lavfi",
9877+ "-i",
9878+ &source,
9879+ "-frames:v",
9880+ "1",
9881+ "-pix_fmt",
9882+ "yuv420p",
9883+ "-f",
9884+ "yuv4mpegpipe",
9885+ "-",
9886+ ])
9887+ .stdin(Stdio::null())
9888+ .stdout(Stdio::piped())
9889+ .stderr(Stdio::piped())
9890+ .output()
9891+ .expect("ffmpeg failed to run");
9892+ assert!(
9893+ y4m.status.success(),
9894+ "{NAME}: ffmpeg fixture (seed {seed}): {}",
9895+ String::from_utf8_lossy(&y4m.stderr)
9896+ );
9897+ // The flags under test come LAST: aomenc keeps the LAST
9898+ // occurrence of a repeated flag (measured 2026-09-02 by md5 of
9899+ // four orderings), so an override appended after the base recipe
9900+ // is the one that lands. Nothing here is repeated, and each of the
9901+ // four arm counters below proves the AB flag actually arrived.
9902+ let args: Vec<&str> = vec![
9903+ "--codec=av1",
9904+ "--passes=1",
9905+ "--end-usage=q",
9906+ "--cq-level=45",
9907+ "--cpu-used=0",
9908+ "--limit=1",
9909+ "--kf-max-dist=0",
9910+ "--lag-in-frames=0",
9911+ "--threads=1",
9912+ "--row-mt=0",
9913+ "--enable-1to4-partitions=0",
9914+ "--enable-filter-intra=0",
9915+ "--enable-smooth-intra=0",
9916+ "--enable-paeth-intra=0",
9917+ "--enable-directional-intra=0",
9918+ "--enable-angle-delta=0",
9919+ "--enable-tx-size-search=0",
9920+ "--enable-cdef=0",
9921+ "--enable-restoration=0",
9922+ "--enable-palette=0",
9923+ "--enable-intrabc=0",
9924+ "--enable-cfl-intra=0",
9925+ "--enable-ref-frame-mvs=0",
9926+ "--sb-size=64",
9927+ "--enable-rect-partitions=1",
9928+ "--enable-ab-partitions=1",
9929+ "--min-partition-size=16",
9930+ "--max-partition-size=32",
9931+ "--obu",
9932+ "-o",
9933+ "-",
9934+ "-",
9935+ ];
9936+ let mut child = Command::new(aomenc_path())
9937+ .args(&args)
9938+ .stdin(Stdio::piped())
9939+ .stdout(Stdio::piped())
9940+ .stderr(Stdio::piped())
9941+ .spawn()
9942+ .expect("aomenc failed to start");
9943+ child
9944+ .stdin
9945+ .take()
9946+ .expect("aomenc stdin")
9947+ .write_all(&y4m.stdout)
9948+ .expect("writing y4m to aomenc");
9949+ let out = child.wait_with_output().expect("aomenc failed to run");
9950+ assert!(
9951+ out.status.success(),
9952+ "aomenc refused the fixture (seed {seed}): {}",
9953+ String::from_utf8_lossy(&out.stderr)
9954+ );
9955+ let stream = out.stdout;
9956+ let before: Vec<usize> = arms.iter().map(|(_, f)| f()).collect();
9957+ let frames = match decode_stream(&stream) {
9958+ Err(e) => {
9959+ let msg = e.to_string();
9960+ assert!(
9961+ msg.contains("unsupported"),
9962+ "{NAME} failed outright, not a named refusal (seed {seed}): {msg}"
9963+ );
9964+ for v in [4, 5, 6, 7] {
9965+ assert!(
9966+ !msg.contains(&format!(
9967+ "a 32x32 partition type this decoder does not code (value={v})"
9968+ )),
9969+ "{NAME} refused a 32-level AB partition (value={v}, seed {seed}) -- \
9970+ all four arms are ported, this refusal is forbidden: {msg}"
9971+ );
9972+ }
9973+ refusals.push(format!("seed {seed}: {msg}"));
9974+ continue;
9975+ }
9976+ Ok(frames) => frames,
9977+ };
9978+ let deltas: Vec<usize> = arms
9979+ .iter()
9980+ .zip(before.iter())
9981+ .map(|((_, f), b)| f() - b)
9982+ .collect();
9983+ let fired: Vec<String> = arms
9984+ .iter()
9985+ .zip(deltas.iter())
9986+ .map(|((label, _), d)| format!("{label}={d}"))
9987+ .collect();
9988+ let fired = fired.join(" ");
9989+ let ffmpeg_frames = ffmpeg_decode_sequence(&stream, width, height, frames.len());
9990+ assert_eq!(
9991+ frames.len(),
9992+ ffmpeg_frames.len(),
9993+ "{NAME}: seed {seed}: shown-frame count vs ffmpeg"
9994+ );
9995+ for (i, (got, want)) in frames.iter().zip(&ffmpeg_frames).enumerate() {
9996+ assert_eq!(
9997+ got.y, want.y,
9998+ "{NAME} frame {i} luma vs ffmpeg (seed {seed}) [{fired}]"
9999+ );
10000+ assert_eq!(
10001+ got.u, want.u,
10002+ "{NAME} frame {i} U vs ffmpeg (seed {seed}) [{fired}]"
10003+ );
10004+ assert_eq!(
10005+ got.v, want.v,
10006+ "{NAME} frame {i} V vs ffmpeg (seed {seed}) [{fired}]"
10007+ );
10008+ }
10009+ compared += 1;
10010+ for (i, d) in deltas.iter().enumerate() {
10011+ totals[i] += d;
10012+ }
10013+ }
10014+ assert!(
10015+ compared > 0,
10016+ "{NAME}: every attempt hit a named refusal:\n{}",
10017+ refusals.join("\n")
10018+ );
10019+ for (i, (label, _)) in arms.iter().enumerate() {
10020+ assert!(
10021+ totals[i] > 0,
10022+ "{NAME}: {compared} attempt(s) decoded pixel-exact but {label} never fired -- \
10023+ the gate would prove nothing about that arm. refusals:\n{}",
10024+ refusals.join("\n")
10025+ );
10026+ }
10027+ eprintln!(
10028+ "{NAME}: {compared}/{} attempts pixel-exact, HORZ_A_32={} HORZ_B_32={} \
10029+ VERT_A_32={} VERT_B_32={}, {} named refusals",
10030+ LR_SEEDS.len(),
10031+ totals[0],
10032+ totals[1],
10033+ totals[2],
10034+ totals[3],
10035+ refusals.len()
10036+ );
10037+ }
10038+
10039+ /// lane-ab32 r1: the 10-bit twin of the gate above -- his two films are
10040+ /// yuv420p10le, so an 8-bit-only AB gate proves nothing about the streams
10041+ /// that matter. Same recipe through [`ten_bit_tool_gate`], which sums the
10042+ /// per-arm counters only over attempts that decoded and pixel-compared.
10043+ #[test]
10044+ fn a_real_aomenc_10bit_stream_with_a_32_level_ab_partition_decodes_pixel_exact() {
10045+ const NAME: &str =
10046+ "a_real_aomenc_10bit_stream_with_a_32_level_ab_partition_decodes_pixel_exact";
10047+ if !have_ffmpeg() {
10048+ eprintln!("SKIP {NAME}: no ffmpeg");
10049+ return;
10050+ }
10051+ if !have_aomenc() {
10052+ eprintln!("SKIP {NAME}: no aomenc at {}", aomenc_path().display());
10053+ return;
10054+ }
10055+ ten_bit_tool_gate(
10056+ NAME,
10057+ 256,
10058+ 256,
10059+ 1,
10060+ &[
10061+ "--ec-fixture-noise",
10062+ "--cq-level=45",
10063+ "--limit=1",
10064+ "--kf-max-dist=0",
10065+ "--enable-1to4-partitions=0",
10066+ "--enable-filter-intra=0",
10067+ "--enable-smooth-intra=0",
10068+ "--enable-paeth-intra=0",
10069+ "--enable-directional-intra=0",
10070+ "--enable-angle-delta=0",
10071+ "--enable-tx-size-search=0",
10072+ "--enable-cdef=0",
10073+ "--enable-restoration=0",
10074+ "--enable-palette=0",
10075+ "--enable-intrabc=0",
10076+ "--enable-cfl-intra=0",
10077+ "--enable-ref-frame-mvs=0",
10078+ // last wins: the flags under test go after the base recipe
10079+ "--enable-rect-partitions=1",
10080+ "--enable-ab-partitions=1",
10081+ "--min-partition-size=16",
10082+ "--max-partition-size=32",
10083+ ],
10084+ &LR_SEEDS,
10085+ &[
10086+ ("HORZ_A_32", crate::decode::intra_horz_a_hits),
10087+ ("HORZ_B_32", crate::decode::intra_horz_b_hits),
10088+ ("VERT_A_32", crate::decode::intra_vert_a_hits),
10089+ ("VERT_B_32", crate::decode::intra_vert_b_hits),
10090+ ],
10091+ );
10092+ }
10093+
9810 /// lane-cwarp r1: a real `--enable-global-motion=1 --enable-dist-wtd-comp=1`10094 /// lane-cwarp r1: a real `--enable-global-motion=1 --enable-dist-wtd-comp=1`
9811 /// stream over a rotating/zooming source, so a `GLOBAL_GLOBALMV` compound10095 /// stream over a rotating/zooming source, so a `GLOBAL_GLOBALMV` compound
9812 /// block lands under a ROTZOOM/AFFINE model and each of its two references10096 /// block lands under a ROTZOOM/AFFINE model and each of its two references
lanes/ab32-r1.report.mdadded+120 -0
@@ -0,0 +1,120 @@
1+# lane-ab32 r1 — the 32-level AB partitions were already decoded; what was missing was the gate
2+
3+## Charter premise: STALE (re-measured, not assumed)
4+
5+The charter said ReelC's head stops at `refusal_inventory.rs:44` "a 32x32 partition type this
6+decoder does not code (value=4)" = `PARTITION_HORZ_A` at 32x32, and that the four AB arms at
7+32x32 had to be written.
8+
9+Both halves are false at main `df5d630`:
10+
11+- All four INTRA arms exist (`crates/ec-av1/src/decode.rs`, lane-part32 r1: `PARTITION_HORZ_A`
12+ ~8972, `HORZ_B` ~9047, `VERT_A` ~9122, `VERT_B` ~9197, each two 16x16 squares + one
13+ 32x16/16x32 `decode_block_rect` strip), and so do all four INTER twins
14+ (`decode.rs` 32-level inter match, arms at +290/+678/+839/+1000 from 15011).
15+ The 32-level `_ =>` refusal now only covers values 8/9 (`PARTITION_HORZ_4`/`VERT_4`),
16+ which lane-tx64x16 owns (its 86226fe implements them).
17+- ReelC's head does not reach that refusal:
18+ `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))`
19+ reelc5.obu stops at the identical string. Both are lane-tx64x16 territory, not this lane's.
20+
21+What WAS missing is the thing the charter's GATE section describes: nothing asserted the 32-level
22+AB arms ever fire. `partab_hits` is only SOFT-noted by the INTER AB gate (stream.rs ~7952: "zero
23+AB partitions fired this run ... sampling, not a regression"), and the four per-arm counters
24+lane-part32 added (`intra_horz_a_hits` .. `intra_vert_b_hits`) had NO consumer anywhere
25+(`grep -rn intra_horz_a_hits crates/ec-av1/src` = decode.rs only). Class
26+`refusal-lifted-without-a-gate`. That is what this round ships.
27+
28+## Files changed
29+
30+- `crates/ec-av1/src/stream.rs` — new gate `a_real_aomenc_stream_with_a_32_level_ab_partition_decodes_pixel_exact`
31+ (8-bit) and its 10-bit twin `a_real_aomenc_10bit_stream_with_a_32_level_ab_partition_decodes_pixel_exact`;
32+ tool flags placed AFTER the base recipe (coordinator correction 2026-09-02: aomenc keeps the
33+ LAST occurrence of a repeated flag, not the first; nothing in these recipes is repeated, and
34+ reordering left every counter byte-identical -- see below); per-arm, per-attempt
35+ counter deltas summed only over attempts that decoded AND pixel-compared (class
36+ `counter-from-refused-stream`); each of `HORZ_A_32/HORZ_B_32/VERT_A_32/VERT_B_32` hard-asserted
37+ nonzero; Err tolerated only when the message contains "unsupported", and the four 32-level AB
38+ refusal strings (value=4..7) are explicitly FORBIDDEN.
39+- `crates/ec-av1/src/stream.rs` `encode_10bit_gradients_seed` — consumes and strips a
40+ `--ec-fixture-noise` pseudo-flag that adds `noise=alls=40:all_seed=<seed>` to the lavfi source
41+ (explicit seed per COMMON). Needed because the smooth gradients fixture codes as
42+ PARTITION_NONE everywhere.
43+- `crates/ec-av1/src/stream.rs` `ten_bit_tool_gate` — its Err arm tolerated ANY decode error as a
44+ "named refusal"; now asserts the message contains "unsupported" (COMMON rule), which every
45+ existing 10-bit gate still satisfies (suite totals below).
46+
47+No decoder change: `decode.rs` is untouched this round.
48+
49+## Why the fixture carries noise (measured, not guessed)
50+
51+First run: 16/16 attempts decoded pixel-exact, zero AB hits. The oracle says the encoder never
52+wrote one — partition value histogram at BLOCK_32X32 (bsize=9) from the instrumented aomdec:
53+
54+```
55+smooth gradients, cq45 : (this recipe, before noise) value=0/1/2 only
56+gradients+noise, cq16 : 33 value=0, 14 value=1, 17 value=2 <- still no AB
57+gradients+noise, cq45 : 4 value=0, 1 value=2, 28 value=3, 7 value=4, 6 value=5, 8 value=6, 10 value=7
58+```
59+
60+`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`
61+
62+So the gate ships noise + cq-level=45; cq-level=16 would have been a vacuous gate.
63+
64+## Gate results
65+
66+`EC_AV1_REQUIRE_AOMENC=1 cargo test -p ec-av1 --lib a_real_aomenc_stream_with_a_32_level_ab_partition_decodes -- --nocapture`
67+
68+`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`
69+
70+`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`
71+
72+## Flag-ordering correction
73+
74+The charter said "first repeated flag wins"; the coordinator corrected this mid-round to LAST
75+wins. The recipes were rewritten so the flags under test (`--sb-size=64
76+--enable-rect-partitions=1 --enable-ab-partitions=1 --min-partition-size=16
77+--max-partition-size=32`) come after the base recipe. No flag is repeated in either recipe, and
78+the counters are identical before and after the reorder (8-bit 101/118/71/80, 10-bit
79+55/50/46/45) -- the arrival proof is the counters themselves: all four AB arms fire, which only
80+happens if `--enable-ab-partitions=1` reached aomenc, and every AB sub-block is 16x16, which
81+only happens under `--min-partition-size=16 --max-partition-size=32`.
82+
83+## Suite
84+
85+`EC_AV1_REQUIRE_AOMENC=1 cargo test -p ec-av1 --lib` -> `$HOME/.cache/ab32-suite.log`.
86+The full run was SIGTERMed by the environment near the end on BOTH attempts (the log ends
87+`process didn't exit successfully: ... (signal: 15, SIGTERM)` with the long `real_clip_*` /
88+`altref*` tests still running), so there is no final `test result:` line. Partial totals from the
89+log: 179 tests `... ok`, 3 `ignored` (pre-existing: rect64q delta-q drift, rectsplit r3 SB strip,
90+perf probes), 1 FAILED:
91+
92+- `decode::tests::nz_map_ctx_offset_tables_match_the_rect_rule` — `32x64 nz_map offset at
93+ display (row 0, col 2): left 6, right 11`. PRE-EXISTING on main `df5d630` and untouched by this
94+ diff (this round changes `stream.rs` only; no table, no decoder path). It is the exact
95+ conflict the ledger already records: "rectsplit r4 domain test asserts table[col][row] ...
96+ 32x64 (row2,col0): base_ctx 6 vs table[0][2]=11 — the two conventions contradict".
97+
98+Sibling gates, run individually and all green after the change:
99+
100+```
101+superblock_level 2 passed 0 failed 1 ignored
102+ab_partition 6 passed 0 failed 0 ignored (includes both new gates)
103+split_transform 1 passed 0 failed 1 ignored
104+tiny_frame_size_sweep 1 passed 0 failed 0 ignored
105+refusal_inventory 3 passed 0 failed 0 ignored
106+gate_coverage 9 passed 0 failed 0 ignored (no coverage-list edit was needed)
107+```
108+
109+## Refusals
110+
111+None lifted — none of this lane's four values was refused at df5d630. `refusal_inventory.rs` and
112+`gate_coverage.rs` are unchanged except where the suite required (see totals).
113+
114+## Residue
115+
116+- deferred: the INTER 32-level AB arms are coded but still ungated per-arm — there are no
117+ per-arm INTER counters (only the shared, soft-noted `partab_hits`). Unblocked by adding four
118+ INTER counters next to the intra ones and a second recipe with alt-refs. accepted for r1: the
119+ charter's <30% rule does not hold here (new counters + a second multi-frame gate).
120+- deferred: ReelC/reelc5 still stop at the 64-level 1:4 refusal — owned by lane-tx64x16.