forge
Explore
Log in

Don't you dare go Hollow

Merge branch 'lane-sqchroma': square-partition tx-size-search chroma gate 8/10-bit (premise of a square-path chroma defect measured false on 52 streams); hue=s=0 guard removed from the rect gates (275/0 on branch)

Browse files at this commit

e6343c59af9695408e79ecfc6a00681c5b99e07bAhmet Kaan GümüşParent: 9f2896053e8047
crates/ec-av1/src/decode.rsmodified+20 -0
@@ -737,6 +737,23 @@ thread_local! {
737 const { std::cell::Cell::new(0) };737 const { std::cell::Cell::new(0) };
738 }738 }
739 739
740+// How many plain SQUARE intra blocks (lane-sqchroma r1) resolved a luma
741+// transform smaller than their own side (`tx_depth != 0`) while coding a
742+// chroma prediction other than `DC_PRED` -- the pair the square path's chroma
743+// only exercises with aomenc's tx-size search left ON (its default), which
744+// every older recipe in this file pins off. Counted at the block, so a stream
745+// where RD happened to give every split-transform block a DC chroma mode
746+// reads as zero rather than silently passing for free.
747+thread_local! {
748+ static SQ_CHROMA_TX_HITS: std::cell::Cell<usize> =
749+ const { std::cell::Cell::new(0) };
750+}
751+
752+/// Current value of [`SQ_CHROMA_TX_HITS`].
753+pub(crate) fn sq_chroma_tx_hits() -> usize {
754+ SQ_CHROMA_TX_HITS.with(|c| c.get())
755+}
756+
740 /// Current value of [`TX_DEPTH_HITS`].757 /// Current value of [`TX_DEPTH_HITS`].
741 pub(crate) fn tx_depth_hits() -> usize {758 pub(crate) fn tx_depth_hits() -> usize {
742 TX_DEPTH_HITS.with(|c| c.get())759 TX_DEPTH_HITS.with(|c| c.get())
@@ -5739,6 +5756,9 @@ fn decode_block(
5739 } else {5756 } else {
5740 (side, luma_tx)5757 (side, luma_tx)
5741 };5758 };
5759+ if tx_select && logical_tx < side && uv_mode != DC_PRED {
5760+ SQ_CHROMA_TX_HITS.with(|c| c.set(c.get() + 1));
5761+ }
5742 let luma_set = if tx_select {5762 let luma_set = if tx_select {
5743 txbset_for(logical_tx, reduced_tx_set)5763 txbset_for(logical_tx, reduced_tx_set)
5744 } else {5764 } else {
crates/ec-av1/src/stream.rsmodified+209 -26
@@ -10627,6 +10627,196 @@ mod tests {
10627 );10627 );
10628 }10628 }
10629 10629
10630+ /// lane-sqchroma r1 gate: a plain SQUARE-partition intra key frame with
10631+ /// REAL chroma (no `hue=s=0` guard) and aomenc's tx-size search left at
10632+ /// its own DEFAULT (on) -- the combination the user's films hit
10633+ /// everywhere and that no gate in this file covered: every older recipe
10634+ /// pins `--enable-tx-size-search=0`, and the one that does not
10635+ /// (`a_real_aomenc_stream_with_a_split_transform_horz_vert_strip_decodes_pixel_exact`)
10636+ /// desaturates its fixture. With the search on, RD gives a square block a
10637+ /// luma transform smaller than its own side while chroma keeps the
10638+ /// block's single `side/2` transform and its own `uv_mode`-derived
10639+ /// `tx_type` -- the pair [`crate::decode::sq_chroma_tx_hits`] counts and
10640+ /// this gate hard-asserts, so a stream whose split-transform blocks all
10641+ /// landed on `DC_PRED` chroma cannot pass for free.
10642+ ///
10643+ /// Sweeps seeds 8-bit and finishes with one 10-bit stream of the same
10644+ /// recipe (his films are `yuv420p10le`), whose sequence header's
10645+ /// `bit_depth` is asserted before any pixel is compared. Only a missing
10646+ /// tool SKIPs: a decode error that is not a named refusal, and every
10647+ /// pixel mismatch, FAIL.
10648+ #[test]
10649+ fn a_real_aomenc_intra_stream_with_tx_size_search_and_chroma_decodes_pixel_exact() {
10650+ const NAME: &str =
10651+ "a_real_aomenc_intra_stream_with_tx_size_search_and_chroma_decodes_pixel_exact";
10652+ let _gate_lock = lock_gate_counters();
10653+ if !have_ffmpeg() {
10654+ eprintln!("SKIP {NAME}: no ffmpeg");
10655+ return;
10656+ }
10657+ if !have_aomenc() {
10658+ eprintln!("SKIP {NAME}: no aomenc at {}", aomenc_path().display());
10659+ return;
10660+ }
10661+ let (width, height) = (192usize, 128usize);
10662+ // NOTE: no `--enable-tx-size-search=0` (the point of this gate), and
10663+ // no chroma filter on the fixture (the other point). Square
10664+ // partitions only: rect/AB/1to4 all off.
10665+ let base_args: Vec<&str> = vec![
10666+ "--codec=av1",
10667+ "--passes=1",
10668+ "--end-usage=q",
10669+ "--cpu-used=0",
10670+ "--threads=1",
10671+ "--row-mt=0",
10672+ "--sb-size=64",
10673+ "--enable-rect-partitions=0",
10674+ "--enable-ab-partitions=0",
10675+ "--enable-1to4-partitions=0",
10676+ "--min-partition-size=16",
10677+ "--max-partition-size=32",
10678+ "--enable-restoration=0",
10679+ "--enable-palette=0",
10680+ "--deltaq-mode=0",
10681+ "--enable-intrabc=0",
10682+ "--limit=1",
10683+ ];
10684+ let encode = |y4m: &[u8], extra: &[&str]| -> Vec<u8> {
10685+ let mut args = base_args.clone();
10686+ args.extend_from_slice(extra);
10687+ args.extend_from_slice(&["--obu", "-o", "-", "-"]);
10688+ let mut child = Command::new(aomenc_path())
10689+ .args(&args)
10690+ .stdin(Stdio::piped())
10691+ .stdout(Stdio::piped())
10692+ .stderr(Stdio::piped())
10693+ .spawn()
10694+ .expect("aomenc failed to start");
10695+ child
10696+ .stdin
10697+ .take()
10698+ .expect("aomenc stdin")
10699+ .write_all(y4m)
10700+ .expect("writing y4m to aomenc");
10701+ let out = child.wait_with_output().expect("aomenc failed to run");
10702+ assert!(
10703+ out.status.success(),
10704+ "aomenc refused the fixture: {}",
10705+ String::from_utf8_lossy(&out.stderr)
10706+ );
10707+ assert!(!out.stdout.is_empty(), "{NAME}: aomenc wrote an empty stream");
10708+ out.stdout
10709+ };
10710+ let render = |source: &str, pix_fmt: &str| -> Vec<u8> {
10711+ let y4m = Command::new("ffmpeg")
10712+ .args([
10713+ "-v", "error", "-f", "lavfi", "-i", source, "-t", "0.04", "-pix_fmt", pix_fmt,
10714+ "-strict", "-1", "-f", "yuv4mpegpipe", "-",
10715+ ])
10716+ .stdin(Stdio::null())
10717+ .stdout(Stdio::piped())
10718+ .stderr(Stdio::piped())
10719+ .output()
10720+ .expect("ffmpeg failed to run");
10721+ assert!(
10722+ y4m.status.success(),
10723+ "ffmpeg fixture: {}",
10724+ String::from_utf8_lossy(&y4m.stderr)
10725+ );
10726+ y4m.stdout
10727+ };
10728+ let mut named_refusals = 0u32;
10729+ let mut matched = 0u32;
10730+ // Hits counted ONLY over attempts that decoded AND pixel-compared:
10731+ // a stream that later refuses must not lend its firings to the
10732+ // assertion below (class refusal-hides-a-defect).
10733+ let mut firing = 0usize;
10734+ let n_attempts: u32 = std::env::var("EC_SQCHROMA_GATE_ATTEMPTS")
10735+ .ok()
10736+ .and_then(|s| s.parse().ok())
10737+ .unwrap_or(10);
10738+ for attempt in 0..n_attempts {
10739+ let seed = 42 + attempt;
10740+ // Two quantisers per seed: the coarse one keeps most blocks on
10741+ // one transform, the fine one is what actually splits them.
10742+ let cq = if attempt % 2 == 0 { "--cq-level=20" } else { "--cq-level=40" };
10743+ let y4m = render(
10744+ &gradients_source(seed, width, height, "duration=0.04:rate=25"),
10745+ "yuv420p",
10746+ );
10747+ let stream = encode(&y4m, &[cq]);
10748+ let before = crate::decode::sq_chroma_tx_hits();
10749+ let frames = match decode_stream(&stream) {
10750+ Err(e) => {
10751+ let msg = e.to_string();
10752+ assert!(
10753+ msg.contains("unsupported"),
10754+ "{NAME} failed outright, not a named refusal (seed {seed}): {msg}"
10755+ );
10756+ named_refusals += 1;
10757+ continue;
10758+ }
10759+ Ok(frames) => frames,
10760+ };
10761+ let ffmpeg_frames = ffmpeg_decode_sequence(&stream, width, height, 1);
10762+ assert_eq!(frames.len(), 1, "{NAME}: expected one frame (seed {seed})");
10763+ assert_eq!(frames[0].y, ffmpeg_frames[0].y, "{NAME} luma vs ffmpeg (seed {seed})");
10764+ assert_eq!(frames[0].u, ffmpeg_frames[0].u, "{NAME} U vs ffmpeg (seed {seed})");
10765+ assert_eq!(frames[0].v, ffmpeg_frames[0].v, "{NAME} V vs ffmpeg (seed {seed})");
10766+ firing += crate::decode::sq_chroma_tx_hits() - before;
10767+ matched += 1;
10768+ }
10769+ // Same recipe, 10-bit: his two films are both yuv420p10le, so the
10770+ // square+tx-search+chroma claim is only worth anything if it holds
10771+ // at their bit depth too.
10772+ let y4m10 = render(
10773+ &gradients_source(42, width, height, "duration=0.04:rate=25"),
10774+ "yuv420p10le",
10775+ );
10776+ let stream10 = encode(&y4m10, &["--cq-level=20", "--input-bit-depth=10", "--bit-depth=10"]);
10777+ let mut probe = Av1Parser::new();
10778+ let mut pos = 0usize;
10779+ while pos < stream10.len() && probe.sequence_header().is_none() {
10780+ let obu = probe.parse_obu(&stream10[pos..]).unwrap();
10781+ pos += obu.total_size;
10782+ }
10783+ assert_eq!(
10784+ probe
10785+ .sequence_header()
10786+ .expect("stream has a sequence header OBU")
10787+ .color_config
10788+ .bit_depth,
10789+ 10,
10790+ "{NAME}: aomenc did not actually write a 10-bit sequence header"
10791+ );
10792+ let before10 = crate::decode::sq_chroma_tx_hits();
10793+ let frames10 = match decode_stream(&stream10) {
10794+ Ok(frames) => frames,
10795+ Err(e) => panic!("{NAME}: decode_stream refused the 10-bit stream: {e}"),
10796+ };
10797+ let ffmpeg10 = ffmpeg_decode_sequence_10bit(&stream10, width, height, 1);
10798+ assert_eq!(frames10[0].y, ffmpeg10[0].y, "{NAME} luma vs ffmpeg (10-bit)");
10799+ assert_eq!(frames10[0].u, ffmpeg10[0].u, "{NAME} U vs ffmpeg (10-bit)");
10800+ assert_eq!(frames10[0].v, ffmpeg10[0].v, "{NAME} V vs ffmpeg (10-bit)");
10801+ let firing10 = crate::decode::sq_chroma_tx_hits() - before10;
10802+ firing += firing10;
10803+ matched += 1;
10804+ assert!(
10805+ matched > 1,
10806+ "{NAME}: every 8-bit attempt refused; the gate decoded only the 10-bit stream"
10807+ );
10808+ assert!(
10809+ firing > 0,
10810+ "{NAME}: zero square blocks split their luma transform under a non-DC chroma mode \
10811+ ({matched} matches, {named_refusals} refusals) -- gate proved nothing this run"
10812+ );
10813+ eprintln!(
10814+ "{NAME}: {matched} pixel-exact decodes ({named_refusals} named refusals out of \
10815+ {n_attempts} 8-bit attempts), split-tx-with-chroma blocks: {firing} \
10816+ (10-bit stream: {firing10})"
10817+ );
10818+ }
10819+
10630 /// lane-rectsplit r1 gate (a): a real `aomenc` key frame whose 32x3210820 /// lane-rectsplit r1 gate (a): a real `aomenc` key frame whose 32x32
10631 /// quadrants split HORZ/VERT into true 32x16/16x32 strips, with the10821 /// quadrants split HORZ/VERT into true 32x16/16x32 strips, with the
10632 /// tx-size search left at aomenc's own default (ON) -- every sibling10822 /// tx-size search left at aomenc's own default (ON) -- every sibling
@@ -10670,17 +10860,14 @@ mod tests {
10670 let y4m = Command::new("ffmpeg")10860 let y4m = Command::new("ffmpeg")
10671 .args([10861 .args([
10672 "-v", "error", "-f", "lavfi", "-i", &source,10862 "-v", "error", "-f", "lavfi", "-i", &source,
10673- // Desaturated (`hue=s=0`, the same guard10863+ // REAL chroma (lane-sqchroma r1 dropped the `hue=s=0`
10674- // `a_real_aomenc_intra_stream_with_tx_select_decodes_pixel_exact`10864+ // guard this recipe carried): the "PRE-EXISTING square-path
10675- // uses): with the tx-size search ON, a real chroma10865+ // chroma defect" that guard named does not reproduce at
10676- // gradient hits a PRE-EXISTING chroma defect on the plain10866+ // HEAD -- seeds 42..61, cq 12/20/32/45, plus testsrc2 and
10677- // SQUARE path -- measured this round with10867+ // mandelbrot, all decode pixel-exact with
10678- // `--enable-rect-partitions=0` on this very recipe, seed10868+ // `--enable-rect-partitions=0`, and this gate is green with
10679- // 42, U plane, i.e. with no rect strip in the stream at10869+ // the filter gone. Its own gate is
10680- // all. Flat chroma keeps that unrelated defect out of10870+ // `a_real_aomenc_intra_stream_with_tx_size_search_and_chroma_decodes_pixel_exact`.
10681- // this gate (gate-recipe-confound class); it is open
10682- // residue in lanes/rectsplit-r1.report.md, not fixed here.
10683- "-vf", "hue=s=0",
10684 "-pix_fmt", "yuv420p", "-f",10871 "-pix_fmt", "yuv420p", "-f",
10685 "yuv4mpegpipe", "-",10872 "yuv4mpegpipe", "-",
10686 ])10873 ])
@@ -10842,10 +11029,9 @@ mod tests {
10842 let y4m = Command::new("ffmpeg")11029 let y4m = Command::new("ffmpeg")
10843 .args([11030 .args([
10844 "-v", "error", "-f", "lavfi", "-i", &source,11031 "-v", "error", "-f", "lavfi", "-i", &source,
10845- // Same `hue=s=0` guard as gate (a): a real chroma gradient11032+ // Real chroma: the `hue=s=0` guard gate (a) carried is
10846- // under the tx-size search hits a PRE-EXISTING square-path11033+ // gone (lane-sqchroma r1 -- the square-path chroma defect
10847- // chroma defect that has nothing to do with this lane.11034+ // it named does not reproduce at HEAD).
10848- "-vf", "hue=s=0",
10849 "-pix_fmt", "yuv420p", "-f", "yuv4mpegpipe", "-",11035 "-pix_fmt", "yuv420p", "-f", "yuv4mpegpipe", "-",
10850 ])11036 ])
10851 .stdin(Stdio::null())11037 .stdin(Stdio::null())
@@ -11042,17 +11228,14 @@ mod tests {
11042 let y4m = Command::new("ffmpeg")11228 let y4m = Command::new("ffmpeg")
11043 .args([11229 .args([
11044 "-v", "error", "-f", "lavfi", "-i", &source,11230 "-v", "error", "-f", "lavfi", "-i", &source,
11045- // Desaturated (`hue=s=0`, the same guard11231+ // REAL chroma (lane-sqchroma r1 dropped the `hue=s=0`
11046- // `a_real_aomenc_intra_stream_with_tx_select_decodes_pixel_exact`11232+ // guard this recipe carried): the "PRE-EXISTING square-path
11047- // uses): with the tx-size search ON, a real chroma11233+ // chroma defect" that guard named does not reproduce at
11048- // gradient hits a PRE-EXISTING chroma defect on the plain11234+ // HEAD -- seeds 42..61, cq 12/20/32/45, plus testsrc2 and
11049- // SQUARE path -- measured this round with11235+ // mandelbrot, all decode pixel-exact with
11050- // `--enable-rect-partitions=0` on this very recipe, seed11236+ // `--enable-rect-partitions=0`, and this gate is green with
11051- // 42, U plane, i.e. with no rect strip in the stream at11237+ // the filter gone. Its own gate is
11052- // all. Flat chroma keeps that unrelated defect out of11238+ // `a_real_aomenc_intra_stream_with_tx_size_search_and_chroma_decodes_pixel_exact`.
11053- // this gate (gate-recipe-confound class); it is open
11054- // residue in lanes/rectsplit-r1.report.md, not fixed here.
11055- "-vf", "hue=s=0",
11056 "-pix_fmt", "yuv420p", "-f",11239 "-pix_fmt", "yuv420p", "-f",
11057 "yuv4mpegpipe", "-",11240 "yuv4mpegpipe", "-",
11058 ])11241 ])
lanes/sqchroma-r1.report.mdadded+90 -0
@@ -0,0 +1,90 @@
1+# lane-sqchroma r1 — the chartered square-path chroma defect does not reproduce
2+
3+## Verdict
4+
5+The charter's premise is FALSE at HEAD (f31a2c5). A plain SQUARE-partition intra key
6+frame with real chroma and aomenc's tx-size search left ON decodes **pixel-exact**, in
7+every recipe I could build around the chartered one, 8-bit and 10-bit. Nothing was
8+fixed because nothing was broken; what shipped is the missing gate that pins the
9+capability, and the removal of the stale `hue=s=0` guard the (wrong) premise put into
10+two live rect gates.
11+
12+## Reproduction attempt (the chartered recipe, exactly)
13+
14+`gradients_source(seed, 192x128, duration=0.04:rate=25)` -> `yuv420p` (NO `hue=s=0`) ->
15+aomenc `--cpu-used=0 --threads=1 --row-mt=0 --sb-size=64 --enable-rect-partitions=0
16+--enable-ab-partitions=0 --enable-1to4-partitions=0 --min-partition-size=16
17+--max-partition-size=32 --enable-restoration=0 --enable-palette=0 --deltaq-mode=0
18+--enable-filter-intra=0 --enable-cfl-intra=0 --enable-intrabc=0` (no
19+`--enable-tx-size-search=0`), decoded by `examples/decode_probe` and diffed plane by
20+plane against `ffmpeg -i s.obu -pix_fmt yuv420p -f rawvideo`.
21+
22+- seeds 42..61 at cq 45: 20/20 exact (Y=0 U=0 V=0 mismatching bytes).
23+- seeds 42..61 at cq 20: 20/20 exact.
24+- seed 42 (the charter's named seed) traced: `tx_depth != 0` fires 6 times, `uv_mode`
25+ takes values 0/1/2/5/11 -- the exact "luma tx_depth>0 with a non-DC uv_mode" pairing
26+ the defect was attributed to. Seed 55: 10 depth hits, uv_modes 0/2/7/12. Still exact.
27+- harder content, same square recipe, cq 12 and 32: `testsrc2`, `mandelbrot`,
28+ `smptebars`, `rgbtestsrc` -- 8/8 exact (streams up to 4 KB, i.e. real chroma residual).
29+- with `--enable-cfl-intra=1 --enable-filter-intra=1` (the CFL-under-split-luma
30+ candidate the charter names): testsrc2 + mandelbrot at cq 12/32, 4/4 exact.
31+- free partition tree (no min/max pin) + CFL: 5/6 exact, 1 named refusal
32+ (`HORZ_A/HORZ_B/VERT_A below 16x16` -- an unrelated, already-named refusal).
33+
34+So no divergence to localise: no EC_AV1_PREFILT_DUMP split, no EC_TRACE_COEFF ladder,
35+no lane-sub8 cherry-pick needed (`decode_block` already computes `smooth_neighbor_uv`
36+from `above_uv_mode`/`left_uv_mode` at decode.rs:5696 -- the square >=16 path never
37+passed `false`; only the leaf8/split4 paths did, and lane-sub8 r5 fixed those).
38+
39+Most likely origin of the premise: it was measured on the pre-merge lane-rectsplit
40+branch, not on main-with-everything-merged (main f31a2c5 carries lane-tiny, lane-seg,
41+lane-intrabc and the rectsplit merge itself), and it was recorded as fact in a comment
42+rather than re-checked. Class: my-charters-shipped-stale-premises.
43+
44+## What changed
45+
46+- `crates/ec-av1/src/decode.rs:735` — new `SQ_CHROMA_TX_HITS` counter + `sq_chroma_tx_hits()`;
47+ bumped at `decode.rs:5638` in `decode_block` when `tx_select && logical_tx < side &&
48+ uv_mode != DC_PRED` (square block whose luma transform split under a non-DC chroma mode).
49+- `crates/ec-av1/src/stream.rs:9924` — new gate
50+ `a_real_aomenc_intra_stream_with_tx_size_search_and_chroma_decodes_pixel_exact`.
51+- `crates/ec-av1/src/stream.rs` (3 sites) — `-vf hue=s=0` dropped from the two live rect
52+ gates and the ignored SB-strip gate; the stale "PRE-EXISTING square-path chroma defect"
53+ comments replaced with what was actually measured. Both live gates stay green with real
54+ chroma, so those gates now cover chroma too.
55+
56+## Gate
57+
58+`a_real_aomenc_intra_stream_with_tx_size_search_and_chroma_decodes_pixel_exact`:
59+square partitions only, tx-size search at aomenc's default (ON), real chroma, 10 8-bit
60+attempts (seeds 42..51, cq alternating 20/40) plus one 10-bit stream (`--bit-depth=10`,
61+sequence-header `bit_depth == 10` asserted before any pixel compare). Hits counted only
62+over attempts that decoded AND pixel-compared; `firing > 0` hard-asserted; a non-refusal
63+decode error or any pixel mismatch FAILS, only a missing tool SKIPs.
64+
65+```
66+CARGO_TARGET_DIR=$HOME/.cache/cargo-target-sqchroma EC_AV1_REQUIRE_AOMENC=1 \
67+ cargo test -p ec-av1 --lib a_real_aomenc_intra_stream_with_tx_size_search_and_chroma -- --nocapture
68+```
69+
70+EVIDENCE: gate stderr | 10 8-bit aomenc streams + 1 10-bit, decoded and diffed vs ffmpeg | `11 pixel-exact decodes (0 named refusals out of 10 8-bit attempts), split-tx-with-chroma blocks: 23 (10-bit stream: 2)` — test ok
71+EVIDENCE: scratchpad sweep.sh/src2.sh output | 40 gradient streams (seeds 42..61 at cq 45 and cq 20) + 12 testsrc2/mandelbrot/smptebars/rgbtestsrc streams, square-only recipe, decode_probe vs ffmpeg rawvideo | every plane Y=0 U=0 V=0 mismatching bytes
72+EVIDENCE: rectsplit gates with the hue filter removed | `cargo test -p ec-av1 --lib split_transform_horz_vert filter_intra_on_a_horz_vert_strip` | both ok (16 decoded seeds, split-tx delta 3; 30 matches, filter_intra_rect delta 9)
73+
74+## Suite
75+
76+`EC_AV1_REQUIRE_AOMENC=1 cargo test -p ec-av1 --lib` (worktree, target-sqchroma): **275 passed, 0 failed, 23 ignored** in 1647s.
77+
78+## Refusals
79+
80+None lifted (none were in the way -- the path already decodes). `refusal_inventory` and
81+`gate_coverage` untouched and green.
82+
83+## Residue
84+
85+- accepted: the charter's localisation plan (PREFILT dump, chroma tx_type derivation,
86+ CFL-under-split-luma, chroma edge-filter type) was not executed -- there is no
87+ divergence to localise. The tx_type/CFL rules were therefore NOT re-audited against
88+ libaom this round; if a real square chroma defect turns up later it is unexamined ground.
89+- deferred(rectsplit r2): `a_real_aomenc_stream_with_a_split_transform_superblock_strip_decodes_pixel_exact`
90+ stays `#[ignore]`d (measured RED on luma, seed 50) -- untouched by this lane beyond its comment.