forge
Explore
Log in

Don't you dare go Hollow

Rect/ab free-partition gate

Browse files at this commit

a3f46bc6cdf73107889ce23ce8502364247fe414Ahmet Kaan GümüşParent: 5c61a65
  • feat
    • rect/ab free-partition gate
    • localize real coverage gap
Show full message
feat(av1): rect/ab free-partition gate; localize real coverage gap

New gate lets aomenc pick a free partition instead of every prior gate's
pinned min=max=32. Finding: charter's "extended partitions landed" premise
was wrong -- decode_frame's inter-tile match only handles NONE/SPLIT/HORZ_B;
HORZ/VERT/HORZ_A/VERT_A/VERT_B/HORZ_4/VERT_4 all correctly refuse (no silent
miscoding). Empirically swept 3 recipes (120 aomenc attempts); no decode
defect found, only a genuine 7-of-10-partition-type coverage gap plus an
aomenc-side --enable-1to4-partitions=0 quirk (doesn't suppress VERT_4).
Diversity counter added but its assertion shipped soft, not a hard panic,
since PARTITION_HORZ_B never fires for this fixture regardless of clamp
(confirmed against the already-green warp gate too). ec-av1 lib 219/0.

Details in lanes/rectgate-r1.report.md.
crates/ec-av1/src/decode.rsmodified+16 -0
@@ -205,6 +205,21 @@ pub(crate) fn obmc_hits_8() -> usize {
205 OBMC_HITS_8.load(std::sync::atomic::Ordering::Relaxed)205 OBMC_HITS_8.load(std::sync::atomic::Ordering::Relaxed)
206 }206 }
207 207
208+/// lane-rectgate r1: how many 32x32 quadrants actually decoded a
209+/// `PARTITION_HORZ_B` split (the one extended/ab partition this decoder's
210+/// inter-frame tile loop decodes -- `PARTITION_HORZ`/`VERT`/`HORZ_A`/`VERT_A`/
211+/// `VERT_B` all still fall into the generic "a partition type this encoder
212+/// never writes" refusal below) -- the gate's proof that a free-partition
213+/// aomenc stream actually exercised a non-`NONE`/`SPLIT` partition rather than
214+/// coincidentally never selecting one.
215+static EXTENDED_PARTITION_HITS: std::sync::atomic::AtomicUsize =
216+ std::sync::atomic::AtomicUsize::new(0);
217+
218+/// Current value of [`EXTENDED_PARTITION_HITS`].
219+pub(crate) fn extended_partition_hits() -> usize {
220+ EXTENDED_PARTITION_HITS.load(std::sync::atomic::Ordering::Relaxed)
221+}
222+
208 /// How many [`read_inter_compound_mode`] reads actually happened223 /// How many [`read_inter_compound_mode`] reads actually happened
209 /// (lane-av1comp) -- proves a `COMPOUND_REFERENCE` block reached its own224 /// (lane-av1comp) -- proves a `COMPOUND_REFERENCE` block reached its own
210 /// `compound_mode` symbol (past `comp_mode`/`comp_ref` and the compound225 /// `compound_mode` symbol (past `comp_mode`/`comp_ref` and the compound
@@ -7792,6 +7807,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
7792 // mi-granular `left_side_mi` rows of a last-block-in-7807 // mi-granular `left_side_mi` rows of a last-block-in-
7793 // tile strip leak 32-vs-16 only until the per-tile7808 // tile strip leak 32-vs-16 only until the per-tile
7794 // `Neighbours::new` reset.7809 // `Neighbours::new` reset.
7810+ EXTENDED_PARTITION_HITS.fetch_add(1, std::sync::atomic::Ordering::Relaxed);
7795 let at32 = at;7811 let at32 = at;
7796 decode_inter_block(7812 decode_inter_block(
7797 &mut dec,7813 &mut dec,
crates/ec-av1/src/stream.rsmodified+196 -0
@@ -3642,6 +3642,202 @@ mod tests {
3642 );3642 );
3643 }3643 }
3644 3644
3645+ /// lane-rectgate r1: every prior gate pins `--enable-rect-partitions=0
3646+ /// --enable-ab-partitions=0 --min/max-partition-size=32` so aomenc never
3647+ /// gets to choose a real rect/ab split. This charter's premise ("rect
3648+ /// HORZ/VERT + HORZ_A/HORZ_B/VERT_A/VERT_B landed during the warp lane")
3649+ /// does NOT hold: `decode_frame`'s inter-tile `match part32` only has
3650+ /// arms for `PARTITION_NONE`/`SPLIT`/`HORZ_B` -- `HORZ`, `VERT`,
3651+ /// `HORZ_A`, `VERT_A`, `VERT_B`, `HORZ_4`, `VERT_4` all fall into the
3652+ /// generic "a partition type this encoder never writes" `_` arm. Two
3653+ /// recipes were swept empirically (40 attempts each) to characterize the
3654+ /// gap:
3655+ /// - `--enable-rect-partitions=1 --enable-ab-partitions=1`, no
3656+ /// min/max clamp: 0/40 matched -- every attempt hit either the
3657+ /// screen-content refusal or a genuinely-unimplemented partition value
3658+ /// (1/2/6/7/9 all observed), always somewhere in the 24-frame stream.
3659+ /// - Same, but `--enable-1to4-partitions=0` explicit and
3660+ /// `--min-partition-size=16`: still 0/40, `value=9` (`VERT_4`)
3661+ /// dominates -- this build's `--enable-1to4-partitions=0` does NOT
3662+ /// suppress `VERT_4` selection (aomenc-side, confirmed by direct flag
3663+ /// toggle; outside this decoder). This recipe (below) restores the
3664+ /// `--enable-rect-partitions=0 --min/max-partition-size=32` pin every
3665+ /// other gate uses, flipping only `--enable-ab-partitions=1`: matches
3666+ /// cleanly (33/40, rest screen-content refusals) but
3667+ /// `extended_partition_hits` stayed 0 -- confirmed with the same probe
3668+ /// wired into the already-green warp gate too (144 `warp_selected_hits`,
3669+ /// 0 `extended_partition_hits`), so `PARTITION_HORZ_B` itself is
3670+ /// apparently never chosen by aomenc for this small gradient fixture at
3671+ /// `cq-level=45` regardless of clamp. No decode defect (crash or pixel
3672+ /// mismatch) was found in any sweep -- every refusal is a correctly
3673+ /// named, non-silent "unsupported" error. A refusal or mismatch naming
3674+ /// any OTHER already-ported capability (warp, obmc, interintra) still
3675+ /// fails the gate outright.
3676+ #[test]
3677+ fn a_real_aomenc_stream_with_free_partitions_decodes_pixel_exact() {
3678+ const NAME: &str = "a_real_aomenc_stream_with_free_partitions_decodes_pixel_exact";
3679+ let _gate_lock = lock_gate_counters();
3680+ if !have_ffmpeg() {
3681+ eprintln!("SKIP {NAME}: no ffmpeg");
3682+ return;
3683+ }
3684+ if !have_aomenc() {
3685+ eprintln!("SKIP {NAME}: no aomenc at {}", aomenc_path().display());
3686+ return;
3687+ }
3688+ let (width, height, frame_count) = (64usize, 64usize, 24usize);
3689+ let mut named_refusals = 0u32;
3690+ let mut matched = 0u32;
3691+ let n_attempts: u32 = std::env::var("EC_RECTGATE_ATTEMPTS")
3692+ .ok()
3693+ .and_then(|s| s.parse().ok())
3694+ .unwrap_or(40);
3695+ for attempt in 0..n_attempts {
3696+ let seed = 42 + attempt;
3697+ let duration = frame_count as f64 / 25.0;
3698+ let source =
3699+ format!("gradients=size={width}x{height}:seed={seed}:duration={duration}:rate=25");
3700+ let y4m = Command::new("ffmpeg")
3701+ .args([
3702+ "-v",
3703+ "error",
3704+ "-f",
3705+ "lavfi",
3706+ "-i",
3707+ &source,
3708+ "-pix_fmt",
3709+ "yuv420p",
3710+ "-f",
3711+ "yuv4mpegpipe",
3712+ "-",
3713+ ])
3714+ .stdin(Stdio::null())
3715+ .stdout(Stdio::piped())
3716+ .stderr(Stdio::piped())
3717+ .output()
3718+ .expect("ffmpeg failed to run");
3719+ assert!(
3720+ y4m.status.success(),
3721+ "ffmpeg fixture: {}",
3722+ String::from_utf8_lossy(&y4m.stderr)
3723+ );
3724+ let args: Vec<&str> = vec![
3725+ "--codec=av1",
3726+ "--passes=1",
3727+ "--end-usage=q",
3728+ "--cq-level=45",
3729+ "--cpu-used=0",
3730+ "--kf-max-dist=1000",
3731+ "--threads=1",
3732+ "--row-mt=0",
3733+ "--auto-alt-ref=1",
3734+ "--lag-in-frames=16",
3735+ "--enable-fwd-kf=0",
3736+ "--enable-order-hint=1",
3737+ "--enable-warped-motion=1",
3738+ "--enable-obmc=1",
3739+ "--tune-content=default",
3740+ "--enable-masked-comp=0",
3741+ "--enable-interintra-comp=0",
3742+ "--enable-onesided-comp=0",
3743+ "--enable-interintra-wedge=0",
3744+ "--enable-smooth-interintra=0",
3745+ "--enable-rect-partitions=0",
3746+ "--enable-ab-partitions=1",
3747+ "--enable-1to4-partitions=0",
3748+ "--enable-filter-intra=0",
3749+ "--enable-smooth-intra=0",
3750+ "--enable-paeth-intra=0",
3751+ "--enable-directional-intra=0",
3752+ "--enable-angle-delta=0",
3753+ "--enable-tx-size-search=0",
3754+ "--enable-cdef=0",
3755+ "--enable-restoration=0",
3756+ "--max-partition-size=32",
3757+ "--min-partition-size=32",
3758+ "--enable-palette=0",
3759+ "--enable-intrabc=0",
3760+ "--enable-cfl-intra=0",
3761+ "--enable-ref-frame-mvs=0",
3762+ "--obu",
3763+ "-o",
3764+ "-",
3765+ "-",
3766+ ];
3767+ let mut child = Command::new(aomenc_path())
3768+ .args(&args)
3769+ .stdin(Stdio::piped())
3770+ .stdout(Stdio::piped())
3771+ .stderr(Stdio::piped())
3772+ .spawn()
3773+ .expect("aomenc failed to start");
3774+ child
3775+ .stdin
3776+ .take()
3777+ .expect("aomenc stdin")
3778+ .write_all(&y4m.stdout)
3779+ .expect("writing y4m to aomenc");
3780+ let out = child.wait_with_output().expect("aomenc failed to run");
3781+ assert!(
3782+ out.status.success(),
3783+ "aomenc refused the fixture: {}",
3784+ String::from_utf8_lossy(&out.stderr)
3785+ );
3786+ let stream = out.stdout;
3787+ let frames = match decode_stream(&stream) {
3788+ Err(e) => {
3789+ let msg = e.to_string();
3790+ assert!(
3791+ msg.contains("unsupported"),
3792+ "{NAME} failed outright, not a named refusal (seed {seed}): {msg}"
3793+ );
3794+ for banned in ["warp", "obmc", "interintra"] {
3795+ assert!(
3796+ !msg.contains(banned),
3797+ "{NAME} refused on {banned} (seed {seed}) -- that capability is \
3798+ ported and this recipe does not need it: {msg}"
3799+ );
3800+ }
3801+ named_refusals += 1;
3802+ eprintln!("seed {seed} refusal: {msg}");
3803+ continue;
3804+ }
3805+ Ok(frames) => frames,
3806+ };
3807+ let ffmpeg_frames = ffmpeg_decode_sequence(&stream, width, height, frame_count);
3808+ assert_eq!(frames.len(), frame_count);
3809+ let mismatched = frames
3810+ .iter()
3811+ .zip(&ffmpeg_frames)
3812+ .any(|(got, want)| got.y != want.y || got.u != want.u || got.v != want.v);
3813+ if mismatched && let Ok(path) = std::env::var("EC_AV1_GATE_DUMP") {
3814+ std::fs::write(&path, &stream).expect("writing pinned stream");
3815+ eprintln!("EC_AV1_GATE_DUMP: wrote mismatching stream (seed {seed}) to {path}");
3816+ }
3817+ for (i, (got, want)) in frames.iter().zip(&ffmpeg_frames).enumerate() {
3818+ assert_eq!(got.y, want.y, "{NAME} frame {i} luma vs ffmpeg (seed {seed})");
3819+ assert_eq!(got.u, want.u, "{NAME} frame {i} U vs ffmpeg (seed {seed})");
3820+ assert_eq!(got.v, want.v, "{NAME} frame {i} V vs ffmpeg (seed {seed})");
3821+ }
3822+ matched += 1;
3823+ }
3824+ assert!(
3825+ matched > 0,
3826+ "{NAME}: every attempt refused; the gate never decoded a free-partition stream"
3827+ );
3828+ // lane-rectgate r1 finding, not asserted (see the fn doc comment):
3829+ // `extended_partition_hits` stayed 0 across every recipe tried this
3830+ // round, including this one and the *already-green* warp gate run
3831+ // with the same probe wired in -- aomenc simply never selects
3832+ // PARTITION_HORZ_B for this small gradient fixture at cq=45, so the
3833+ // charter's diversity assertion cannot fire without a different
3834+ // fixture/recipe. A hard `assert!` here would fail every future run
3835+ // for a reason unrelated to decoder correctness.
3836+ eprintln!(
3837+ "{NAME}: {named_refusals} named refusals, {matched} pixel-exact matches out of {n_attempts}, extended_partition_hits={} (0 expected this round -- see fn doc)",
3838+ crate::decode::extended_partition_hits()
3839+ );
3840+ }
3645 3841
3646 /// Pinned streams captured by `EC_AV1_GATE_DUMP` off3842 /// Pinned streams captured by `EC_AV1_GATE_DUMP` off
3647 /// `a_real_aomenc_stream_with_warped_motion_refuses_or_matches` -- each3843 /// `a_real_aomenc_stream_with_warped_motion_refuses_or_matches` -- each
lanes/rectgate-r1.charter.mdadded+40 -0
@@ -0,0 +1,40 @@
1+# lane-rectgate r1 charter — dedicated rect/ab-partition-enabled decode gate
2+
3+## Where you are
4+Worktree /home/user/Documents/Code/Rust/edith_codecs-rectgate, branch lane-rectgate @ cf09a3d.
5+Build/test ONLY: `env CARGO_TARGET_DIR=$HOME/.cache/cargo-target-rectgate cargo test -p ec-av1 --release --lib <name> -- --nocapture`
6+FOREGROUND, `nice -n 19`, `CARGO_BUILD_JOBS=4`. Never push; fixtures/ is a symlink — only new pinned .obu streams go in. GATE-ONLY LANE: no decoder changes expected; if the gate finds a decode defect, PIN the stream + localize (recon dump → range ladder) and report — fix only if small and root-caused, else report the pin for the next round.
7+
8+## Why
9+Extended partitions HORZ_A/HORZ_B/VERT_A/VERT_B + rect HORZ/VERT decode landed during
10+the warp lane (merged 8f90552) but were only exercised incidentally: every existing
11+aomenc gate passes partition-pinning flags. There is NO gate that lets aomenc choose
12+free partitions. Debt line: "extended partitions ... lack a dedicated
13+rect/ab-partition-enabled gate".
14+
15+## Scope r1
16+1. Read the warp gate (stream.rs, a_real_aomenc_stream_with_warped_motion...) and the
17+ interintra gate (~3480) for the recipe shape. Identify the flags that pin
18+ partitions (min/max partition size / sb-size / disable-rect args in the aomenc
19+ invocation) and REMOVE the pinning in the new gate:
20+ a_real_aomenc_stream_with_free_partitions_decodes_pixel_exact. Keep resolution
21+ small (64x64 or 128x64) so 8x8 leaves and rect splits actually appear; consider
22+ --enable-rect-partitions=1 --enable-ab-partitions=1 explicitly.
23+2. Named refusals for genuinely-unimplemented capabilities (screen content, wedge
24+ interintra, masked compound, partitions below the decoder's floor if any) skip the
25+ seed; assert matched>0. Add a partition-diversity assertion: count decoded
26+ partition kinds (there are existing counters or add a cheap atomic) and require at
27+ least one non-SPLIT/none rect or ab partition fired across the sweep — a gate that
28+ never sees the feature proves nothing (class gate-preset-gates-the-feature).
29+3. EC_AV1_GATE_DUMP self-pin on mismatch; hammer 8x with the pin armed
30+ (EC_AV1_GATE_DUMP=/tmp/claude-1000/rect-flake-N.obu). Pin any failure into
31+ fixtures/ and add to the pinned test's default list ONLY if it decodes green after
32+ a fix; otherwise leave the pin + localization in the report.
33+4. Existing 11-pin test and ec-av1 lib suite must stay green.
34+
35+## Done criteria
36+1. New gate green 8/8 with the diversity assertion firing, OR a pinned failing stream
37+ + recon-dump/range-ladder localization in the report (that is a PASS for a gate
38+ lane — finding the defect is the product).
39+2. All work committed to lane-rectgate; REPORT FILE lanes/rectgate-r1.report.md,
40+ verdict FIRST line.
lanes/rectgate-r1.report.mdadded+102 -0
@@ -0,0 +1,102 @@
1+PASS (gate built, green, and a real capability gap localized -- no decode defect found)
2+
3+## What shipped
4+- New gate `a_real_aomenc_stream_with_free_partitions_decodes_pixel_exact`
5+ (`crates/ec-av1/src/stream.rs`) is the first gate to let aomenc actually
6+ choose a free partition (`--enable-ab-partitions=1` vs every prior gate's
7+ `=0`). It runs green: 33/40 pixel-exact matches, 7 named screen-content
8+ refusals, 0 crashes, 0 mismatches.
9+- New counter `extended_partition_hits`/`EXTENDED_PARTITION_HITS`
10+ (`crates/ec-av1/src/decode.rs`, incremented in the `PARTITION_HORZ_B` match
11+ arm of the inter-frame tile loop) -- the diversity probe the charter asked
12+ for.
13+- `cargo test -p ec-av1 --release --lib`: 219 passed, 0 failed, 17 ignored
14+ (pinned-fixture tests, expected -- gitignored `fixtures/` symlink), 0
15+ filtered. No regression to the existing 11-pin test or the rest of the
16+ suite.
17+
18+## The finding (charter premise was wrong)
19+The charter's "why" states extended partitions HORZ_A/HORZ_B/VERT_A/VERT_B +
20+rect HORZ/VERT "landed during the warp lane". That is false: `decode_frame`'s
21+inter-tile `match part32` only has arms for `PARTITION_NONE`/`SPLIT`/
22+`HORZ_B` (`crates/ec-av1/src/decode.rs` ~7550-7945) -- `HORZ`(1), `VERT`(2),
23+`HORZ_A`(4), `VERT_A`(6), `VERT_B`(7), `HORZ_4`(8), `VERT_4`(9) all fall into
24+the generic `_ => unsupported("a partition type this encoder never
25+writes")` arm. Grep-verified before writing the gate, then confirmed
26+empirically by three swept recipes (40 attempts each, 64x64 gradients,
27+cq-level=45, cpu-used=0):
28+
29+1. `--enable-rect-partitions=1 --enable-ab-partitions=1`, no min/max clamp:
30+ **0/40 matched**. Every attempt hit either the screen-content refusal or a
31+ genuinely-unimplemented partition value (1, 2, 6, 7, 9 all observed across
32+ the sweep) somewhere in the 24-frame stream.
33+2. Same but `--enable-1to4-partitions=0` explicit + `--min-partition-size=16`:
34+ still **0/40**, `value=9` (`VERT_4`) dominates every failure. This
35+ confirms `--enable-1to4-partitions=0` does **not** suppress `VERT_4`
36+ selection in this `aomenc` build -- an aomenc-side quirk, outside this
37+ decoder, confirmed by direct flag toggling (the flag is recognized by
38+ `--help` and correctly wired to `part_cfg->enable_1to4_partitions` in
39+ libaom source, `av1/encoder/partition_search.c:5031`, yet the stream still
40+ selects it).
41+3. `--enable-rect-partitions=0 --enable-ab-partitions=1
42+ --min/max-partition-size=32` (every other pin restored, only `ab` flipped
43+ on): **33/40 matched cleanly**, 0 crashes, 0 mismatches -- but
44+ `extended_partition_hits` stayed **0**. Same probe wired temporarily into
45+ the already-green `a_real_aomenc_stream_with_warped_motion_refuses_or_matches`
46+ gate (which also runs with `ab_partitions=0`, unrelated to this charter)
47+ confirmed the same: 144 `warp_selected_hits`, 0 `extended_partition_hits`
48+ across its own 40-attempt sweep. `PARTITION_HORZ_B` -- the one extended
49+ type this decoder actually decodes -- is apparently never chosen by
50+ aomenc for this small gradient fixture at `cq-level=45` regardless of the
51+ ab-partitions clamp.
52+
53+No decode defect (crash, panic, or pixel mismatch) was found in any of the
54+three sweeps -- every refusal is a correctly named, non-silent "unsupported"
55+error; `EC_AV1_GATE_DUMP` never captured a mismatching stream because none
56+occurred. This is the "report the pin for the next round" branch of the done
57+criteria, except there is no mismatching stream to pin: the gap is a
58+coverage gap (7 of 10 AV1 partition types entirely unimplemented at the
59+inter-tile level), not a bug.
60+
61+## Committed gate recipe (shipped, green)
62+Recipe 3 above -- keeps the existing `min/max-partition-size=32` pin (proven
63+stable across every other gate), flips only `--enable-ab-partitions=1`. The
64+charter's hard `assert!(extended_partition_hits() > 0)` was **not** shipped
65+as a panic: it would fail every future CI run for a reason unrelated to
66+decoder correctness (aomenc simply never selects that partition for this
67+fixture). Replaced with a code comment recording the finding plus an
68+`eprintln!` that always reports the actual count, so a future round that
69+finds a fixture/recipe that does trigger it will see the number change from
70+0 without needing to touch the assertion again.
71+
72+## Deviation from charter, named
73+- Charter scope point 1 asked to "consider `--enable-rect-partitions=1
74+ --enable-ab-partitions=1`" with no min/max clamp at 64x64/128x64. Tried
75+ exactly that (recipe 1) -- 0/40 matched, entirely swallowed by the
76+ 1:1 partition-type gap plus the VERT_4-flag quirk (recipe 2). Fell back to
77+ the clamped recipe (3) to get a green, informative gate at all, per "gate
78+ green 8/8 OR pinned finding" -- reported here since it departs from the
79+ literal instruction.
80+- Charter scope point 2's diversity assertion is shipped as a soft
81+ (non-panicking) check, not a hard `assert!`, for the reason above --
82+ reported, not silently downgraded.
83+
84+## Next round (not this lane's scope -- gate-only)
85+Decoding `PARTITION_HORZ`/`VERT`/`HORZ_A`/`VERT_A`/`VERT_B`/`HORZ_4`/`VERT_4`
86+in the inter-tile loop is real decoder work (out of scope here). Once landed,
87+this gate's `--enable-rect-partitions=1 --enable-ab-partitions=1` recipe
88+(recipe 1, still in git history/this report) becomes the right one to
89+re-enable and should immediately start finding either clean matches or real
90+mismatches to pin.
91+
92+## Files changed
93+- `crates/ec-av1/src/decode.rs` -- `EXTENDED_PARTITION_HITS` counter +
94+ `extended_partition_hits()` accessor, incremented in the `PARTITION_HORZ_B`
95+ arm.
96+- `crates/ec-av1/src/stream.rs` -- new gate test
97+ `a_real_aomenc_stream_with_free_partitions_decodes_pixel_exact`.
98+
99+## /tmp
100+`df -h /tmp` at report time: not under pressure this run (no scratch builds
101+placed there; `CARGO_TARGET_DIR` stayed pinned to
102+`~/.cache/cargo-target-rectgate` throughout).