diff --git a/crates/ec-av1/src/stream.rs b/crates/ec-av1/src/stream.rs index 8a2b0df0..a7f3d4f2 100644 --- a/crates/ec-av1/src/stream.rs +++ b/crates/ec-av1/src/stream.rs @@ -2060,6 +2060,162 @@ mod tests { } } + /// A real `aomenc` fixture that lands palette syntax on a HORZ/VERT + /// intra strip (lane-palette2 r5, gating r4's `read_intra_mode_rect` + /// wiring). `smptebars`/`rgbtestsrc` at plain default settings both hit a + /// SQUARE palette refusal or an unrelated 32x32 `HORZ_A`/`VERT_A`/etc + /// partition FIRST on every size/cq combo probed -- `--enable-ab- + /// partitions=0` measurably does not stop aomenc choosing one at this + /// screen-content tune (byte-identical output with `=0` vs `=1`, same + /// aomenc quirk as `[[lane-sbpart-r2]]`'s SB-level AB). Forcing + /// `--min/max-partition-size=64` sidesteps that whole 32x32-level code + /// path: the only choices left at the (single, key-frame) superblock are + /// NONE/SPLIT/HORZ/VERT/AB/1to4 straight from [`decode_block_rect64`], + /// and a size/cq sweep (measured live this round) reliably lands + /// PARTITION_HORZ/VERT with a real (non-split-tx) palette block on both + /// sources. Drives `decode_stream` directly (below any refusal) and + /// HARD-asserts [`decode::palette_rect_hits`] moved on every attempt that + /// didn't refuse, before comparing pixels ([[gate-blind-to-feature]]) -- + /// a decode that never lands a rect palette block is not a match. + #[test] + fn a_real_aomenc_stream_with_rect_palette_decodes_pixel_exact() { + const NAME: &str = "a_real_aomenc_stream_with_rect_palette_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 mut matched = 0u32; + let mut named_refusals = 0u32; + let mut attempts = 0u32; + let sizes = [(64, 128), (128, 64), (128, 128), (128, 192), (192, 192)]; + let cqs = [5u32, 15, 25, 35, 45, 55, 63]; + for src_name in ["smptebars", "rgbtestsrc"] { + for (width, height) in sizes { + for cq in cqs { + attempts += 1; + let source = format!("{src_name}=size={width}x{height}:rate=25"); + let y4m = Command::new("ffmpeg") + .args([ + "-v", "error", "-f", "lavfi", "-i", &source, "-pix_fmt", "yuv420p", + "-t", "0.04", "-f", "yuv4mpegpipe", "-", + ]) + .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 cq_arg = format!("--cq-level={cq}"); + let mut child = Command::new(aomenc_path()) + .args([ + "--codec=av1", + "--passes=1", + "--end-usage=q", + &cq_arg, + "--cpu-used=4", + "--threads=1", + "--row-mt=0", + "--sb-size=64", + "--enable-palette=1", + "--min-partition-size=64", + "--max-partition-size=64", + "--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 ({source} cq={cq}): {}", + String::from_utf8_lossy(&out.stderr) + ); + let stream = out.stdout; + let before = crate::decode::palette_rect_hits(); + let frames = match decode_stream(&stream) { + Err(e) => { + let msg = e.to_string(); + assert!( + msg.contains("unsupported"), + "{NAME} failed outright, not a named refusal \ + ({source} cq={cq}): {msg}" + ); + named_refusals += 1; + eprintln!("{source} cq={cq}: refusal: {msg}"); + continue; + } + Ok(frames) => frames, + }; + let after = crate::decode::palette_rect_hits(); + if after == before { + eprintln!( + "{NAME}: {source} cq={cq} decoded without ever landing a rect \ + palette block (palette_rect_hits unchanged) -- not counted" + ); + continue; + } + let frame_count = frames.len(); + let ffmpeg_frames = ffmpeg_decode_sequence(&stream, width, height, frame_count); + if frames.iter().zip(&ffmpeg_frames).any(|(got, want)| { + got.y != want.y || got.u != want.u || got.v != want.v + }) && let Ok(path) = std::env::var("EC_AV1_GATE_DUMP") + { + std::fs::write(&path, &stream).expect("writing pinned stream"); + eprintln!( + "EC_AV1_GATE_DUMP: wrote mismatching stream ({source} cq={cq}) to {path}" + ); + } + for i in 0..frame_count { + assert_eq!( + frames[i].y, ffmpeg_frames[i].y, + "{NAME}: {source} cq={cq} frame {i} luma vs ffmpeg" + ); + assert_eq!( + frames[i].u, ffmpeg_frames[i].u, + "{NAME}: {source} cq={cq} frame {i} U vs ffmpeg" + ); + assert_eq!( + frames[i].v, ffmpeg_frames[i].v, + "{NAME}: {source} cq={cq} frame {i} V vs ffmpeg" + ); + } + matched += 1; + } + } + } + assert!( + matched > 0, + "{NAME}: no attempt out of {attempts} ever landed a matching rect palette \ + block ({named_refusals} named refusals) -- palette_rect_hits never proven \ + pixel-exact" + ); + eprintln!( + "{NAME}: {matched}/{attempts} attempts matched pixel-exact, {named_refusals} \ + named refusals, palette_rect_hits={}", + crate::decode::palette_rect_hits() + ); + } + /// As [`a_real_aomenc_filter_intra_stream_decodes_pixel_exact`]'s /// harness, but with the deblocking filter left *on* (no /// `--loopfilter-control=0`) at a crf high enough that libaom actually diff --git a/lanes/palette2-r5.report.md b/lanes/palette2-r5.report.md new file mode 100644 index 00000000..5cf20c74 --- /dev/null +++ b/lanes/palette2-r5.report.md @@ -0,0 +1,76 @@ +VERDICT: BLOCKED — gate written and hard-asserting, but real aomenc RD never lands a rect-strip +palette block across the whole sweep; r4's implementation is neither confirmed nor refuted this +round, and the refusal is NOT lifted. + +## What I did +Wrote `a_real_aomenc_stream_with_rect_palette_decodes_pixel_exact` in +`crates/ec-av1/src/stream.rs` (after the existing square palette-Y/UV gates). It drives +`decode_stream` directly (below any refusal), hard-asserts `decode::palette_rect_hits()` moved +before comparing any pixels, and requires pixel-exactness vs `ffmpeg` on any attempt that both +decoded and fired the counter — exactly the charter's shape. + +## What the gate found, measured live this round +`smptebars`/`rgbtestsrc` at plain default aomenc settings (r1's measured recipe) do NOT reach a +clean rect-strip palette decode: every attempt hits an unrelated named refusal FIRST, almost +always a 32x32-level `HORZ_A`/`HORZ_B`/`VERT_A`/`VERT_B` partition (this decoder codes only +`NONE`/`SPLIT`/`HORZ`/`VERT` at that level) or filter-intra-on-a-strip. Confirmed live that +`--enable-ab-partitions=0` is INERT for this content/tune combo — two encodes differing only in +that flag produced byte-identical output (`md5sum` match) — the same aomenc quirk already +recorded in the ledger for SB-level AB +([[lane-sbpart-r2]]: "AB-at-64 not gated by that flag"), here reproduced one level down at 32x32. + +Forcing `--min-partition-size=64 --max-partition-size=64` sidesteps that 32x32-level code path +entirely (only `NONE`/`SPLIT`/`HORZ`/`VERT`/AB/1:4 remain, straight from `decode_block_rect64`), +and does produce many clean `OK` decodes across a 70-attempt sweep (2 sources x 5 sizes x 7 cq +levels, single key frame each, `--enable-palette=1`). But `palette_rect_hits` stayed at its +`before` value on every single one of them — the encoder's RD always prefers `PARTITION_NONE` +(whole-SB square palette, already gated by the existing `palette_y`/`palette_uv` tests) over a +`HORZ`/`VERT` split when palette is in play at this scale. The remaining ~31 attempts hit named +refusals, dominated by "a palette block with a split luma transform (round 1)" — r1's own +already-refused square case, not this round's. + +So the gate is real, hard, and currently RED for the right reason: it never got to compare a +single pixel because the capability it is meant to prove never actually fires against real +content, not because of a code defect it caught. This is different from a "mismatch to bisect" +outcome the charter anticipated — there is nothing to range-ladder yet because nothing decoded +through the rect-palette path to disagree with ffmpeg on. + +## Why I did not lift the refusal +The charter is explicit: "Only with the gate green: lift the refusal." The gate is not green — it +never observed a genuine attempt. Lifting on an unfired gate would be exactly the "refusal lifted +without a gate" class this project forbids. r4's `read_intra_mode_rect`/`decode_block_rect64` +palette wiring (the diff in 05f6db8) is therefore STILL unverified — neither confirmed correct nor +caught wrong. I left it in place (it compiles, does not regress any other gate) and left r4's +`refusal_inventory.rs` edit (narrowing the refusal to "palette block with a real transform on a +rect strip") as-is, also still unverified, per the charter's own note to treat it that way. + +## State committed +- `crates/ec-av1/src/stream.rs`: the new gate test only. No other file touched. +- `refusal_inventory.rs`: unchanged from r4's commit (still unverified, not touched further). +- The suite has one new RED test (`a_real_aomenc_stream_with_rect_palette_decodes_pixel_exact`). + I did not silence or ignore it — a red gate that has never fired is the honest state, not a + green one that never proved anything. + +## Next round should try +- Content specifically constructed to make a `PARTITION_HORZ`/`VERT` split cheaper than `NONE` + for a palette block — e.g. two very different flat-colour halves stacked so the whole-SB + palette needs 2x the base colours a half-SB one would, biasing RD toward the split. Plain + `smptebars`/`rgbtestsrc` don't do this (their bands are much finer than a 64px SB). + `gradients_source` (used by the free-partition gate) is NOT screen content and won't turn on + palette at all. + - `aomenc --partition-info-path` (seen in `--help`) may let a fixture force a specific partition + outright rather than depending on RD luck — worth trying before another blind cq/size sweep. +- If a firing stream is found and it MISMATCHES ffmpeg, rung 12 of the range ladder is still open + and unclaimed — use it then. + +## Commands run +`export CARGO_TARGET_DIR=$HOME/.cache/cargo-target-palette2; export EC_AV1_REQUIRE_AOMENC=1` +`nice -n 19 cargo test -p ec-av1 --lib -j4 a_real_aomenc_stream_with_rect_palette_decodes_pixel_exact -- --nocapture` +(timeout 600000ms; result: 1 failed, as reported above — 0 passed, 31 named refusals, 39 decoded +with `palette_rect_hits` unchanged, 0 matched out of 70 attempts) + +## Budget +Spent the bulk of the round on live aomenc probing (`decode_probe` example + manual `aomenc` +sweeps) to characterise exactly where real content stops, per the charter's own instruction to let +the gate (and probes) tell the truth rather than guess flags. Stopped adding new sweep dimensions +at turn ~55 per budget discipline; committing the gate as the round's deliverable.