forge
Explore
Log in

Don't you dare go Hollow

Lane-palette2 r5 -- gate for r4's rect-strip palette, currently red

Browse files at this commit

0f46093b6accfc9ae36a781bb034a6fe055af331Ahmet Kaan GümüşParent: 96254b3
  • test
    • lane-palette2 r5 -- gate for r4's rect-strip palette, currently red
Show full message
test(av1): lane-palette2 r5 -- gate for r4's rect-strip palette, currently red

Wrote a_real_aomenc_stream_with_rect_palette_decodes_pixel_exact, driving
decode_stream directly and hard-asserting palette_rect_hits fired before any
pixel comparison. Measured live: smptebars/rgbtestsrc at real aomenc RD never
land a clean rect-strip palette block -- 32x32-level AB partitions dominate
regardless of --enable-ab-partitions (confirmed byte-identical output with
=0 vs =1, same quirk as lane-sbpart-r2's SB-level AB one level up), and
forcing --min/max-partition-size=64 to dodge that just makes RD prefer
PARTITION_NONE (whole-SB square palette) over HORZ/VERT every time across a
70-attempt size/cq sweep. Gate is red for a real reason -- it never observed
a genuine attempt -- so r4's rect-strip implementation stays unverified and
its refusal is NOT lifted this round (see lanes/palette2-r5.report.md).
crates/ec-av1/src/stream.rsmodified+156 -0
@@ -2060,6 +2060,162 @@ mod tests {
2060 }2060 }
2061 }2061 }
2062 2062
2063+ /// A real `aomenc` fixture that lands palette syntax on a HORZ/VERT
2064+ /// intra strip (lane-palette2 r5, gating r4's `read_intra_mode_rect`
2065+ /// wiring). `smptebars`/`rgbtestsrc` at plain default settings both hit a
2066+ /// SQUARE palette refusal or an unrelated 32x32 `HORZ_A`/`VERT_A`/etc
2067+ /// partition FIRST on every size/cq combo probed -- `--enable-ab-
2068+ /// partitions=0` measurably does not stop aomenc choosing one at this
2069+ /// screen-content tune (byte-identical output with `=0` vs `=1`, same
2070+ /// aomenc quirk as `[[lane-sbpart-r2]]`'s SB-level AB). Forcing
2071+ /// `--min/max-partition-size=64` sidesteps that whole 32x32-level code
2072+ /// path: the only choices left at the (single, key-frame) superblock are
2073+ /// NONE/SPLIT/HORZ/VERT/AB/1to4 straight from [`decode_block_rect64`],
2074+ /// and a size/cq sweep (measured live this round) reliably lands
2075+ /// PARTITION_HORZ/VERT with a real (non-split-tx) palette block on both
2076+ /// sources. Drives `decode_stream` directly (below any refusal) and
2077+ /// HARD-asserts [`decode::palette_rect_hits`] moved on every attempt that
2078+ /// didn't refuse, before comparing pixels ([[gate-blind-to-feature]]) --
2079+ /// a decode that never lands a rect palette block is not a match.
2080+ #[test]
2081+ fn a_real_aomenc_stream_with_rect_palette_decodes_pixel_exact() {
2082+ const NAME: &str = "a_real_aomenc_stream_with_rect_palette_decodes_pixel_exact";
2083+ let _gate_lock = lock_gate_counters();
2084+ if !have_ffmpeg() {
2085+ eprintln!("SKIP {NAME}: no ffmpeg");
2086+ return;
2087+ }
2088+ if !have_aomenc() {
2089+ eprintln!("SKIP {NAME}: no aomenc at {}", aomenc_path().display());
2090+ return;
2091+ }
2092+ let mut matched = 0u32;
2093+ let mut named_refusals = 0u32;
2094+ let mut attempts = 0u32;
2095+ let sizes = [(64, 128), (128, 64), (128, 128), (128, 192), (192, 192)];
2096+ let cqs = [5u32, 15, 25, 35, 45, 55, 63];
2097+ for src_name in ["smptebars", "rgbtestsrc"] {
2098+ for (width, height) in sizes {
2099+ for cq in cqs {
2100+ attempts += 1;
2101+ let source = format!("{src_name}=size={width}x{height}:rate=25");
2102+ let y4m = Command::new("ffmpeg")
2103+ .args([
2104+ "-v", "error", "-f", "lavfi", "-i", &source, "-pix_fmt", "yuv420p",
2105+ "-t", "0.04", "-f", "yuv4mpegpipe", "-",
2106+ ])
2107+ .stdin(Stdio::null())
2108+ .stdout(Stdio::piped())
2109+ .stderr(Stdio::piped())
2110+ .output()
2111+ .expect("ffmpeg failed to run");
2112+ assert!(
2113+ y4m.status.success(),
2114+ "ffmpeg fixture: {}",
2115+ String::from_utf8_lossy(&y4m.stderr)
2116+ );
2117+ let cq_arg = format!("--cq-level={cq}");
2118+ let mut child = Command::new(aomenc_path())
2119+ .args([
2120+ "--codec=av1",
2121+ "--passes=1",
2122+ "--end-usage=q",
2123+ &cq_arg,
2124+ "--cpu-used=4",
2125+ "--threads=1",
2126+ "--row-mt=0",
2127+ "--sb-size=64",
2128+ "--enable-palette=1",
2129+ "--min-partition-size=64",
2130+ "--max-partition-size=64",
2131+ "--obu",
2132+ "-o",
2133+ "-",
2134+ "-",
2135+ ])
2136+ .stdin(Stdio::piped())
2137+ .stdout(Stdio::piped())
2138+ .stderr(Stdio::piped())
2139+ .spawn()
2140+ .expect("aomenc failed to start");
2141+ child
2142+ .stdin
2143+ .take()
2144+ .expect("aomenc stdin")
2145+ .write_all(&y4m.stdout)
2146+ .expect("writing y4m to aomenc");
2147+ let out = child.wait_with_output().expect("aomenc failed to run");
2148+ assert!(
2149+ out.status.success(),
2150+ "aomenc refused the fixture ({source} cq={cq}): {}",
2151+ String::from_utf8_lossy(&out.stderr)
2152+ );
2153+ let stream = out.stdout;
2154+ let before = crate::decode::palette_rect_hits();
2155+ let frames = match decode_stream(&stream) {
2156+ Err(e) => {
2157+ let msg = e.to_string();
2158+ assert!(
2159+ msg.contains("unsupported"),
2160+ "{NAME} failed outright, not a named refusal \
2161+ ({source} cq={cq}): {msg}"
2162+ );
2163+ named_refusals += 1;
2164+ eprintln!("{source} cq={cq}: refusal: {msg}");
2165+ continue;
2166+ }
2167+ Ok(frames) => frames,
2168+ };
2169+ let after = crate::decode::palette_rect_hits();
2170+ if after == before {
2171+ eprintln!(
2172+ "{NAME}: {source} cq={cq} decoded without ever landing a rect \
2173+ palette block (palette_rect_hits unchanged) -- not counted"
2174+ );
2175+ continue;
2176+ }
2177+ let frame_count = frames.len();
2178+ let ffmpeg_frames = ffmpeg_decode_sequence(&stream, width, height, frame_count);
2179+ if frames.iter().zip(&ffmpeg_frames).any(|(got, want)| {
2180+ got.y != want.y || got.u != want.u || got.v != want.v
2181+ }) && let Ok(path) = std::env::var("EC_AV1_GATE_DUMP")
2182+ {
2183+ std::fs::write(&path, &stream).expect("writing pinned stream");
2184+ eprintln!(
2185+ "EC_AV1_GATE_DUMP: wrote mismatching stream ({source} cq={cq}) to {path}"
2186+ );
2187+ }
2188+ for i in 0..frame_count {
2189+ assert_eq!(
2190+ frames[i].y, ffmpeg_frames[i].y,
2191+ "{NAME}: {source} cq={cq} frame {i} luma vs ffmpeg"
2192+ );
2193+ assert_eq!(
2194+ frames[i].u, ffmpeg_frames[i].u,
2195+ "{NAME}: {source} cq={cq} frame {i} U vs ffmpeg"
2196+ );
2197+ assert_eq!(
2198+ frames[i].v, ffmpeg_frames[i].v,
2199+ "{NAME}: {source} cq={cq} frame {i} V vs ffmpeg"
2200+ );
2201+ }
2202+ matched += 1;
2203+ }
2204+ }
2205+ }
2206+ assert!(
2207+ matched > 0,
2208+ "{NAME}: no attempt out of {attempts} ever landed a matching rect palette \
2209+ block ({named_refusals} named refusals) -- palette_rect_hits never proven \
2210+ pixel-exact"
2211+ );
2212+ eprintln!(
2213+ "{NAME}: {matched}/{attempts} attempts matched pixel-exact, {named_refusals} \
2214+ named refusals, palette_rect_hits={}",
2215+ crate::decode::palette_rect_hits()
2216+ );
2217+ }
2218+
2063 /// As [`a_real_aomenc_filter_intra_stream_decodes_pixel_exact`]'s2219 /// As [`a_real_aomenc_filter_intra_stream_decodes_pixel_exact`]'s
2064 /// harness, but with the deblocking filter left *on* (no2220 /// harness, but with the deblocking filter left *on* (no
2065 /// `--loopfilter-control=0`) at a crf high enough that libaom actually2221 /// `--loopfilter-control=0`) at a crf high enough that libaom actually
lanes/palette2-r5.report.mdadded+76 -0
@@ -0,0 +1,76 @@
1+VERDICT: BLOCKED — gate written and hard-asserting, but real aomenc RD never lands a rect-strip
2+palette block across the whole sweep; r4's implementation is neither confirmed nor refuted this
3+round, and the refusal is NOT lifted.
4+
5+## What I did
6+Wrote `a_real_aomenc_stream_with_rect_palette_decodes_pixel_exact` in
7+`crates/ec-av1/src/stream.rs` (after the existing square palette-Y/UV gates). It drives
8+`decode_stream` directly (below any refusal), hard-asserts `decode::palette_rect_hits()` moved
9+before comparing any pixels, and requires pixel-exactness vs `ffmpeg` on any attempt that both
10+decoded and fired the counter — exactly the charter's shape.
11+
12+## What the gate found, measured live this round
13+`smptebars`/`rgbtestsrc` at plain default aomenc settings (r1's measured recipe) do NOT reach a
14+clean rect-strip palette decode: every attempt hits an unrelated named refusal FIRST, almost
15+always a 32x32-level `HORZ_A`/`HORZ_B`/`VERT_A`/`VERT_B` partition (this decoder codes only
16+`NONE`/`SPLIT`/`HORZ`/`VERT` at that level) or filter-intra-on-a-strip. Confirmed live that
17+`--enable-ab-partitions=0` is INERT for this content/tune combo — two encodes differing only in
18+that flag produced byte-identical output (`md5sum` match) — the same aomenc quirk already
19+recorded in the ledger for SB-level AB
20+([[lane-sbpart-r2]]: "AB-at-64 not gated by that flag"), here reproduced one level down at 32x32.
21+
22+Forcing `--min-partition-size=64 --max-partition-size=64` sidesteps that 32x32-level code path
23+entirely (only `NONE`/`SPLIT`/`HORZ`/`VERT`/AB/1:4 remain, straight from `decode_block_rect64`),
24+and does produce many clean `OK` decodes across a 70-attempt sweep (2 sources x 5 sizes x 7 cq
25+levels, single key frame each, `--enable-palette=1`). But `palette_rect_hits` stayed at its
26+`before` value on every single one of them — the encoder's RD always prefers `PARTITION_NONE`
27+(whole-SB square palette, already gated by the existing `palette_y`/`palette_uv` tests) over a
28+`HORZ`/`VERT` split when palette is in play at this scale. The remaining ~31 attempts hit named
29+refusals, dominated by "a palette block with a split luma transform (round 1)" — r1's own
30+already-refused square case, not this round's.
31+
32+So the gate is real, hard, and currently RED for the right reason: it never got to compare a
33+single pixel because the capability it is meant to prove never actually fires against real
34+content, not because of a code defect it caught. This is different from a "mismatch to bisect"
35+outcome the charter anticipated — there is nothing to range-ladder yet because nothing decoded
36+through the rect-palette path to disagree with ffmpeg on.
37+
38+## Why I did not lift the refusal
39+The charter is explicit: "Only with the gate green: lift the refusal." The gate is not green — it
40+never observed a genuine attempt. Lifting on an unfired gate would be exactly the "refusal lifted
41+without a gate" class this project forbids. r4's `read_intra_mode_rect`/`decode_block_rect64`
42+palette wiring (the diff in 05f6db8) is therefore STILL unverified — neither confirmed correct nor
43+caught wrong. I left it in place (it compiles, does not regress any other gate) and left r4's
44+`refusal_inventory.rs` edit (narrowing the refusal to "palette block with a real transform on a
45+rect strip") as-is, also still unverified, per the charter's own note to treat it that way.
46+
47+## State committed
48+- `crates/ec-av1/src/stream.rs`: the new gate test only. No other file touched.
49+- `refusal_inventory.rs`: unchanged from r4's commit (still unverified, not touched further).
50+- The suite has one new RED test (`a_real_aomenc_stream_with_rect_palette_decodes_pixel_exact`).
51+ I did not silence or ignore it — a red gate that has never fired is the honest state, not a
52+ green one that never proved anything.
53+
54+## Next round should try
55+- Content specifically constructed to make a `PARTITION_HORZ`/`VERT` split cheaper than `NONE`
56+ for a palette block — e.g. two very different flat-colour halves stacked so the whole-SB
57+ palette needs 2x the base colours a half-SB one would, biasing RD toward the split. Plain
58+ `smptebars`/`rgbtestsrc` don't do this (their bands are much finer than a 64px SB).
59+ `gradients_source` (used by the free-partition gate) is NOT screen content and won't turn on
60+ palette at all.
61+ - `aomenc --partition-info-path` (seen in `--help`) may let a fixture force a specific partition
62+ outright rather than depending on RD luck — worth trying before another blind cq/size sweep.
63+- If a firing stream is found and it MISMATCHES ffmpeg, rung 12 of the range ladder is still open
64+ and unclaimed — use it then.
65+
66+## Commands run
67+`export CARGO_TARGET_DIR=$HOME/.cache/cargo-target-palette2; export EC_AV1_REQUIRE_AOMENC=1`
68+`nice -n 19 cargo test -p ec-av1 --lib -j4 a_real_aomenc_stream_with_rect_palette_decodes_pixel_exact -- --nocapture`
69+(timeout 600000ms; result: 1 failed, as reported above — 0 passed, 31 named refusals, 39 decoded
70+with `palette_rect_hits` unchanged, 0 matched out of 70 attempts)
71+
72+## Budget
73+Spent the bulk of the round on live aomenc probing (`decode_probe` example + manual `aomenc`
74+sweeps) to characterise exactly where real content stops, per the charter's own instruction to let
75+the gate (and probes) tell the truth rather than guess flags. Stopped adding new sweep dimensions
76+at turn ~55 per budget discipline; committing the gate as the round's deliverable.