forge
Explore
Log in

Don't you dare go Hollow

stream: run the SVT split-transform gate on a committed pin, count off the wire

Browse files at this commit

1e73b1b278100aee4ed720ca221f35f9eb354005Ahmet Kaan GümüşParent: b6966d6
`an_svt_screen_palette_block_with_a_split_transform_decodes_exactly` read its
stream from whatever `EC_AV1_SVT1_STREAM` named and SKIPped when that was
unset, so on a stock box it never ran -- and an oracle count that cannot be
pinned is the same defect as one that is not: the gate was handing ffmpeg the
length of our own decode as the expected frame count, with nothing on the box
able to prove the number wrong.

The crop is now committed: `crates/ec-av1/fixtures/svt1-split-tx-pin.obu`,
1838 bytes, sha256
c9d9c0ae934fba72fc9a9374bc36853f290796a8a4d6442140e239669e0b341f. It is a
REPLAY, not a fresh capture -- two independent encodes of

    ffmpeg -v error -f lavfi \
      -i "smptehdbars=s=192x152:r=12,drawgrid=w=8:h=8:t=1:c=black" \
      -frames:v 1 -c:v libsvtav1 -preset 8 -crf 50 \
      -svtav1-params "lp=1:screen-content-mode=1" -g 12 -f obu out.obu

produce those exact bytes (SVT-AV1 v3.1.2). `-frames:v 1` is the part lane-
svt1's own 6x5x6 search lacked: it ran FOUR frames per stream and the
~200k-sample misses that killed every candidate were on the INTER frames
(lanes/svt1.report.md). One key frame has no inter frames, and this one
reaches the fixed arm and is pixel-exact.

The count is derived from the WIRE, not from a literal: the gate parses the
pin's own OBUs with `Av1Parser` and asserts `decoded.len() == frame_headers`
BEFORE handing that number to the oracle. A header count would OVER-count a
stream carrying `show_existing_frame` (spec 5.9.5 codes no pixels, so the
header count exceeds the shown-frame count), so that case is asserted
impossible on this pin rather than assumed -- which is what makes "one header
== one shown frame" a checked fact here instead of an argument.

`EC_AV1_SVT1_STREAM` still overrides the pin for a re-capture, and
`crate_pin` is called with a string LITERAL on purpose: the pin inventory
scans for that spelling, and a const argument would leave this pin outside the
"every pin a gate reads is a committed crate-local copy" invariant.

Non-vacuity, measured: the gate runs on a stock box with the env var unset
(0.18s, no SKIP), and `skip_split_tx_override_hits() > 0` mutated to `> 1`
reds -- so the premise arm fires exactly once on this pin and the gate cannot
pass blind. The count assert mutated to `frame_headers + 1` reds with
"the stream codes 1 frame(s), the decode showed 1", which is also the proof
the wire count and the decode agree.

count-vacuity sweep: 59 site(s); 58 spec-pinned, 1 not -- the SVT gate no
longer spends a decode-derived `.len()` at all, so it leaves the population.
crates/ec-av1/fixtures/svt1-split-tx-pin.obuadded+0 -0

Binary file changed

crates/ec-av1/src/gate_coverage.rsmodified+24 -20
@@ -2250,8 +2250,12 @@ mod count_vacuity {
2250 let mut out: Vec<(String, &str)> = Vec::new();2250 let mut out: Vec<(String, &str)> = Vec::new();
2251 for (i, line) in lines.iter().enumerate() {2251 for (i, line) in lines.iter().enumerate() {
2252 let t = line.trim_start();2252 let t = line.trim_start();
2253- let Some(rest) = t.strip_prefix("fn ") else { continue };2253+ let Some(rest) = t.strip_prefix("fn ") else {
2254- let Some(nm) = rest.split('(').next() else { continue };2254+ continue;
2255+ };
2256+ let Some(nm) = rest.split('(').next() else {
2257+ continue;
2258+ };
2255 if nm.contains(' ') {2259 if nm.contains(' ') {
2256 continue;2260 continue;
2257 }2261 }
@@ -2551,7 +2555,6 @@ mod count_vacuity {
2551 s.len()2555 s.len()
2552 );2556 );
2553 }2557 }
2554-
2555 }2558 }
2556 2559
2557 #[cfg(test)]2560 #[cfg(test)]
@@ -2598,23 +2601,24 @@ mod count_vacuity_tests {
2598 // call (`-frames:v 1` / `-vframes 1` / `--limit=N` / a helper's `frames`2601 // call (`-frames:v 1` / `-vframes 1` / `--limit=N` / a helper's `frames`
2599 // parameter / the arm tuple's `frame_count` / the wire's own OBU frame2602 // parameter / the arm tuple's `frame_count` / the wire's own OBU frame
2600 // headers), so the count handed to the oracle is a value already proven2603 // headers), so the count handed to the oracle is a value already proven
2601- // against the encode instead of read off our decode. The two that remain2604+ // against the encode instead of read off our decode. Two rows survived
2602- // are the two that are not a count to fix:2605+ // that round; lane-av1pinspec2 closed both, so the ceiling is now 0.
2603- // * `an_svt_screen_palette_block_with_a_split_transform_decodes_exactly`2606+ //
2604- // reads the path `EC_AV1_SVT1_STREAM` names, and that crop is not2607+ // lane-av1pinspec2: 2 -> 1, for the SVT row. That gate was handed
2605- // committed to `fixtures/`, so no `--limit`, no `-frames:v` and no2608+ // forward last round because the count was underivable: the stream came
2606- // frame count exists anywhere in the tree for it. The doc comment's2609+ // from `EC_AV1_SVT1_STREAM`, was never committed, and the gate SKIPped
2607- // "12-frame stream" is prose about one capture and the env var2610+ // on a stock box -- so a wire-derived assert would have been an
2608- // accepts any file, so asserting 12 would pin a number nothing can2611+ // unexercised assert wearing a pin's clothes. The crop is now COMMITTED
2609- // check. Counting the stream's own OBU frame headers with2612+ // (`fixtures/svt1-split-tx-pin.obu`, a byte-reproducible replay of a
2610- // `Av1Parser` would derive one, and is left on the table2613+ // `-frames:v 1` libsvtav1 encode), the gate reads it, and its count
2611- // deliberately: the gate SKIPs on any box without that env var, so2614+ // comes from the stream's own OBU frame headers with
2612- // such an assert would ship unexercised.2615+ // `show_existing_frame` asserted false, so a header count cannot
2613- // * a `///` DOC COMMENT quoting the pre-r4 body of2616+ // over-count. The gate runs on a stock box, so the assert executes.
2614- // `pinned_lr_sgr_stream_call_unique_dump`, which this line-based2617+ //
2615- // scan cannot tell from code. The gate it describes already spends2618+ // The remaining unpinned row is a `///` DOC COMMENT quoting the pre-r4
2616- // `FRAMES` and asserts `pics.len() == FRAMES`.2619+ // body of `pinned_lr_sgr_stream_call_unique_dump`, which this
2617- const UNPINNED_CEILING: usize = 2;2620+ // line-based scan cannot tell from code.
2621+ const UNPINNED_CEILING: usize = 1;
2618 let unpinned = s.iter().filter(|x| x.pinned_by.is_none()).count();2622 let unpinned = s.iter().filter(|x| x.pinned_by.is_none()).count();
2619 assert!(2623 assert!(
2620 unpinned <= UNPINNED_CEILING,2624 unpinned <= UNPINNED_CEILING,
crates/ec-av1/src/stream.rsmodified+97 -30
@@ -5582,23 +5582,52 @@ pub(crate) mod tests {
5582 }5582 }
5583 }5583 }
5584 5584
5585- /// lane-svt1: an SVT-AV1 (v3.1.2, `-preset 8 -crf 35`) screen key frame5585+ /// lane-svt1: an SVT-AV1 (v3.1.2, `-preset 8`) screen key frame codes 16x16
5586- /// codes 16x16 PALETTE blocks with `skip == 1` whose `tx_depth` split the5586+ /// PALETTE blocks with `skip == 1` whose `tx_depth` split the luma
5587- /// luma transform. [`crate::decode::decode_block`] armed the palette5587+ /// transform. [`crate::decode::decode_block`] armed the palette prediction
5588- /// prediction only when the transform covered the whole block, so that one5588+ /// only when the transform covered the whole block, so that one block
5589- /// block predicted DC off its own edges instead: the right symbols (the5589+ /// predicted DC off its own edges instead: the right symbols (the whole mode
5590- /// whole mode ladder diffs clean against an instrumented aomdec) and the5590+ /// ladder diffs clean against an instrumented aomdec) and the wrong pixels
5591- /// wrong pixels -- 812 luma samples in frame 0, carried by the V_PRED5591+ /// -- 812 luma samples in frame 0, carried by the V_PRED blocks under it to
5592- /// blocks under it to 10122 samples over the 12-frame stream.5592+ /// 10122 samples over the 12-frame stream the defect was found on.
5593- ///5593+ ///
5594- /// No lavfi recipe witnesses it in a stream this decoder otherwise decodes:5594+ /// lane-av1pinspec2: the gate used to RIDE an external crop named by
5595- /// 6 sources x 5 sizes x 6 crf values through `libsvtav1 -preset 85595+ /// `EC_AV1_SVT1_STREAM` and SKIP when that was unset, so it never ran on a
5596- /// -svtav1-params screen-content-mode=1` produced 8 streams that reach the5596+ /// stock box -- which is exactly why its oracle count could not be pinned
5597- /// path, and every one of them either refuses on an unrelated Golomb tail5597+ /// (an assert on a gate that never executes is an unexercised assert wearing
5598- /// or misses by ~200k samples on unrelated inter-frame defects (both5598+ /// a pin's clothes). It now runs on the COMMITTED pin
5599- /// recorded in `lanes/svt1.report.md`). So the gate rides the kept stream5599+ /// `crates/ec-av1/fixtures/svt1-split-tx-pin.obu`.
5600- /// named by `EC_AV1_SVT1_STREAM` and SKIPs when it is unset -- the screen5600+ ///
5601- /// crop itself is never committed to `fixtures/`.5601+ /// The pin is a REPLAY, not a fresh capture, and the recipe is recorded
5602+ /// because it reproduces the bytes exactly (two independent encodes on this
5603+ /// box, SVT-AV1 v3.1.2, both sha256
5604+ /// `c9d9c0ae934fba72fc9a9374bc36853f290796a8a4d6442140e239669e0b341f`,
5605+ /// 1838 bytes):
5606+ ///
5607+ /// ffmpeg -v error -f lavfi \
5608+ /// -i "smptehdbars=s=192x152:r=12,drawgrid=w=8:h=8:t=1:c=black" \
5609+ /// -frames:v 1 -c:v libsvtav1 -preset 8 -crf 50 \
5610+ /// -svtav1-params "lp=1:screen-content-mode=1" -g 12 -f obu out.obu
5611+ ///
5612+ /// `-frames:v 1` is the part lane-svt1's search lacked: its 6x5x6 sweep ran
5613+ /// FOUR frames per stream, and the ~200k-sample misses that killed every
5614+ /// candidate were on the INTER frames (`lanes/svt1.report.md`). One key
5615+ /// frame has no inter frames, and this one reaches the fixed arm
5616+ /// (`skip_split_tx_override_hits == 1`) and is pixel-exact.
5617+ ///
5618+ /// THE COUNT, and why it is derived from the wire rather than from a
5619+ /// literal. The oracle is handed the number of frame OBUs this stream
5620+ /// actually codes, counted with `Av1Parser` below -- never our decode's
5621+ /// length, which is the thing under test. A header count would OVER-count
5622+ /// a stream carrying `show_existing_frame` (spec 5.9.5: it codes no pixels,
5623+ /// so the header count is larger than the shown-frame count), so that case
5624+ /// is asserted impossible on this pin rather than assumed: the loop refuses
5625+ /// any frame header with `show_existing_frame` set, which is what makes
5626+ /// "one header == one shown frame" a checked fact here instead of an
5627+ /// argument.
5628+ ///
5629+ /// `EC_AV1_SVT1_STREAM` still overrides the pin, so a re-capture is one env
5630+ /// var away; `crate_pin` falls back to `pin_dir()` for the same reason.
5602 ///5631 ///
5603 /// `skip_split_tx_override_hits` is asserted non-zero so the row cannot5632 /// `skip_split_tx_override_hits` is asserted non-zero so the row cannot
5604 /// pass on a stream that never reaches the fixed arm (class5633 /// pass on a stream that never reaches the fixed arm (class
@@ -5606,29 +5635,67 @@ pub(crate) mod tests {
5606 #[test]5635 #[test]
5607 fn an_svt_screen_palette_block_with_a_split_transform_decodes_exactly() {5636 fn an_svt_screen_palette_block_with_a_split_transform_decodes_exactly() {
5608 const NAME: &str = "an_svt_screen_palette_block_with_a_split_transform_decodes_exactly";5637 const NAME: &str = "an_svt_screen_palette_block_with_a_split_transform_decodes_exactly";
5609- let Ok(path) = std::env::var("EC_AV1_SVT1_STREAM") else {5638+ const PIN: &str = "svt1-split-tx-pin.obu";
5610- eprintln!("SKIP {NAME}: EC_AV1_SVT1_STREAM names no stream");
5611- return;
5612- };
5613 if !have_ffmpeg() {5639 if !have_ffmpeg() {
5614 eprintln!("SKIP {NAME}: no ffmpeg");5640 eprintln!("SKIP {NAME}: no ffmpeg");
5615 return;5641 return;
5616 }5642 }
5617- let data = match std::fs::read(&path) {5643+ let path = match std::env::var("EC_AV1_SVT1_STREAM") {
5618- Ok(data) => data,5644+ Ok(p) => std::path::PathBuf::from(p),
5619- Err(e) => {5645+ // The name is spelled as a LITERAL here even though `PIN` is right
5620- eprintln!("SKIP {NAME}: {path}: {e}");5646+ // above, on purpose: `gate_coverage::pin_inventory` matches a pin
5621- return;5647+ // read by the quote that follows the callee name, so a const
5622- }5648+ // argument would leave this pin outside the "every pin a gate reads
5649+ // is a committed crate-local copy" invariant. The dup is the
5650+ // coverage -- and it is also why this comment must NOT quote that
5651+ // spelling: the scanner reads prose too, and a quoted spelling here
5652+ // parses as a pin called " and would not see a const argument, ...".
5653+ Err(_) => crate_pin("svt1-split-tx-pin.obu"),
5654+ };
5655+ let data = require_pin(&path, PIN);
5656+ // The ENCODE's frame count, read off the WIRE: parse this stream's own
5657+ // OBUs and count the frame headers. `show_existing_frame` is refused
5658+ // here on purpose -- such a header codes no pixels, so counting it
5659+ // would make this count larger than the frames the oracle can decode.
5660+ let mut parser = Av1Parser::new();
5661+ let mut pos = 0usize;
5662+ let mut frame_headers = 0usize;
5663+ while pos < data.len() {
5664+ let Ok(obu) = parser.parse_obu(&data[pos..]) else {
5665+ break;
5623 };5666 };
5667+ pos += obu.total_size.max(1);
5668+ let header = match &obu.kind {
5669+ ObuKind::Frame(h, _) | ObuKind::FrameHeader(h) => h,
5670+ _ => continue,
5671+ };
5672+ assert!(
5673+ !header.show_existing_frame,
5674+ "{NAME}: frame header {frame_headers} sets show_existing_frame, so the header \
5675+ count is not the shown-frame count and this gate's oracle budget would be wrong"
5676+ );
5677+ frame_headers += 1;
5678+ }
5679+ assert!(
5680+ frame_headers > 0,
5681+ "{NAME}: {} carries no frame header at all",
5682+ path.display()
5683+ );
5624 crate::decode::reset_skip_split_tx_override_hits();5684 crate::decode::reset_skip_split_tx_override_hits();
5625- let decoded = decode_stream(&data).expect("the kept SVT-AV1 screen stream decodes");5685+ let decoded = decode_stream(&data).expect("the pinned SVT-AV1 screen stream decodes");
5626 assert!(5686 assert!(
5627 crate::decode::skip_split_tx_override_hits() > 0,5687 crate::decode::skip_split_tx_override_hits() > 0,
5628- "{NAME}: no skipped split-transform palette block in {path} -- the gate would pass blind"5688+ "{NAME}: no skipped split-transform palette block in {} -- the gate would pass blind",
5689+ path.display()
5690+ );
5691+ assert_eq!(
5692+ decoded.len(),
5693+ frame_headers,
5694+ "{NAME}: the stream codes {frame_headers} frame(s), the decode showed {}",
5695+ decoded.len()
5629 );5696 );
5630 let (width, height) = (decoded[0].width, decoded[0].height);5697 let (width, height) = (decoded[0].width, decoded[0].height);
5631- let want = ffmpeg_decode_sequence(&data, width, height, decoded.len());5698+ let want = ffmpeg_decode_sequence(&data, width, height, frame_headers);
5632 for (i, (got, want)) in decoded.iter().zip(&want).enumerate() {5699 for (i, (got, want)) in decoded.iter().zip(&want).enumerate() {
5633 assert_eq!(got.y, want.y, "frame {i} luma vs ffmpeg");5700 assert_eq!(got.y, want.y, "frame {i} luma vs ffmpeg");
5634 assert_eq!(got.u, want.u, "frame {i} U vs ffmpeg");5701 assert_eq!(got.u, want.u, "frame {i} U vs ffmpeg");