forge
Explore
Log in

Don't you dare go Hollow

lane-av1p1pin: pin the 4:4:4 sb128 128-root rect witness, gate it byte-exact

Browse files at this commit

c4b999cc9cc2da93ec20faabcbcaf121c130405aAhmet Kaan GümüşParent: 927c533
Recipe P1 of lanes/av1witness2recheck.report.md was measured but never
pinned: its 595 bytes lived only under /tmp. Rebuilt from the report's
exact ffmpeg+aomenc lines -- sha256
68773f2c6e01a2d211bf0213479accb4c2c360132c0e1bc3b326eab7861925b1, so the
recipe did not drift.

Pinned as fixtures/444_sb128rect_chroma_tile_witness.obu (distinct from
444_sb128rect_lr_witness.obu) and gated by
a_444_sb128_rect_chroma_tile_witness_is_byte_exact: all 3 frames, all 3
planes byte-exact vs aomdec and ffmpeg yuv444p rawvideo, plus census
deltas proving the guarded 128-root VERT chroma tiling fired 6 times
(edge_vert, part128 vert, intra_vert) with HORZ still 0.

Non-vacuous, three mutations, three reds: counter expectation 6->7 reds;
a flipped U sample reds the aomdec arm; a flipped V sample placed after
the aomdec block reds the ffmpeg arm alone. No decode-path edit.
crates/ec-av1/fixtures/444_sb128rect_chroma_tile_witness.obuadded+0 -0

Binary file changed

crates/ec-av1/src/stream.rsmodified+195 -1
@@ -11306,6 +11306,200 @@ pub(crate) mod tests {
1130611306 );
1130711307 }
1130811308 }
11309+
11310+ /// lane-av1p1pin: the permanent pin for the 4:4:4 superblock-128
11311+ /// 128-root rect witness -- recipe P1 of `lanes/av1witness2recheck.report.md`.
11312+ ///
11313+ /// Provenance. Encoder: `~/.cache/aom-oracle/build/aomenc --codec=av1
11314+ /// --obu -o s1d.obu --passes=1 --threads=1 bands444.y4m --limit=3
11315+ /// --kf-max-dist=1 --cpu-used=2 --end-usage=q --cq-level=20 --sb-size=128
11316+ /// --enable-rect-partitions=1 --enable-1to4-partitions=1
11317+ /// --min-partition-size=4`, over the ffmpeg 8.1.2 lavfi source
11318+ /// `nullsrc=s=320x256:rate=30:d=1,geq=lum='mod(floor((Y+T*160)/8)*67,255)':
11319+ /// cb='128+20*sin(Y/17+T)':cr='128+20*sin(X/23+T*2)' -pix_fmt yuv444p`
11320+ /// (`bands444.y4m`, sha256
11321+ /// `fa6218399cce8dd9eaadb6e24642d31cb2d2bde505b39a8df237938492c642ee`).
11322+ /// Pinned bytes: `crates/ec-av1/fixtures/444_sb128rect_chroma_tile_witness.obu`,
11323+ /// 595 bytes, sha256
11324+ /// `68773f2c6e01a2d211bf0213479accb4c2c360132c0e1bc3b326eab7861925b1`
11325+ /// (FNV-1a `0xd4fa_ac7b_dccc_520b`). Rebuilt byte-for-byte from the recipe
11326+ /// on `9a535ccb` -- the recipe did not drift. 3 frames, 320x256, yuv444p.
11327+ /// This is NOT `fixtures/444_sb128rect_lr_witness.obu` (794 B, sha256
11328+ /// `27825e14...`), the other in-tree 4:4:4 sb128 stream.
11329+ ///
11330+ /// What it guards. At the report's old base `fe3e8418` this stream
11331+ /// panicked -- rc=101, `decode.rs:17631: assertion failed: lossless_frame
11332+ /// || (chroma_w / chroma_tx, chroma_h / chroma_tx) == (nch_x, nch_y)` --
11333+ /// because the 128-rect chroma unit walk was hardcoded to the 4:2:0 mu-chunk
11334+ /// span, so a 128-root HORZ/VERT block at 4:4:4 coded half its chroma units.
11335+ /// Closed by `349b3918` (the per-axis invariant now at `decode.rs:24515`);
11336+ /// byte-exactness by `fa70a68c`.
11337+ ///
11338+ /// Two load-bearing arms, both proven to bite (lanes/av1p1pin.report.md):
11339+ /// (1) the census deltas -- 6 gathered edge-VERT 128-roots, 6
11340+ /// `PARTITION_VERT` 128 roots, 6 key-frame intra 128-axis blocks, 8 coded
11341+ /// `32x32` VERT strips -- so the gate fails, rather than passes, if a
11342+ /// future stream stops coding the shape (class `gate-blind-to-feature`);
11343+ /// (2) every sample of every frame against ffmpeg `yuv444p` rawvideo, with
11344+ /// the plane-length guard that stops a short plane from zip-truncating the
11345+ /// compare. Oracle arm is aomdec `--rawvideo` as well; neither is a shim.
11346+ #[test]
11347+ fn a_444_sb128_rect_chroma_tile_witness_is_byte_exact() {
11348+ const NAME: &str = "a_444_sb128_rect_chroma_tile_witness_is_byte_exact";
11349+ const FIXTURE_LEN: usize = 595;
11350+ const FIXTURE_FNV: u64 = 0xd4fa_ac7b_dccc_520b;
11351+ const W: usize = 320;
11352+ const H: usize = 256;
11353+ const FRAMES: usize = 3;
11354+ /// The guarded path: 128-root rect chroma tiling at 4:4:4.
11355+ const EDGE_VERT: usize = 6;
11356+ const PART128_VERT: usize = 6;
11357+ const INTRA128_VERT: usize = 6;
11358+ const RECT4_32_VERT: usize = 8;
11359+ const RECT4_32_CODED: usize = 8;
11360+ let obu = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR"))
11361+ .join("fixtures/444_sb128rect_chroma_tile_witness.obu");
11362+ let stream = read_pin(&obu, FIXTURE_LEN, FIXTURE_FNV, NAME);
11363+
11364+ let _guard = lock_gate_counters();
11365+ let rect_before = sb128_rect_counters();
11366+ let part_before = part128_census();
11367+ let r432_before = rect4_32_counters();
11368+ let frames = decode_stream(&stream)
11369+ .unwrap_or_else(|e| panic!("{NAME}: the pinned stream no longer decodes cleanly: {e}"));
11370+ let rect_after = sb128_rect_counters();
11371+ let part_after = part128_census();
11372+ let r432_after = rect4_32_counters();
11373+
11374+ assert_eq!(frames.len(), FRAMES, "{NAME}: frame count");
11375+ for f in &frames {
11376+ assert_eq!(
11377+ (f.width, f.height),
11378+ (W, H),
11379+ "{NAME}: dimensions -- a resized frame would make the oracle \
11380+ slices below compare the wrong samples"
11381+ );
11382+ }
11383+
11384+ // Non-vacuity: the guarded 128-root VERT path really fired.
11385+ assert_eq!(
11386+ rect_after.1 - rect_before.1,
11387+ EDGE_VERT,
11388+ "{NAME}: gathered edge-VERT 128 roots moved (expected {EDGE_VERT}) -- this \
11389+ stream is the witness for the 128-rect 4:4:4 chroma tiling, so a \
11390+ different count means the shape is gone or the counter moved (class \
11391+ gate-blind-to-feature)"
11392+ );
11393+ assert_eq!(
11394+ part_after.3 - part_before.3,
11395+ PART128_VERT,
11396+ "{NAME}: 128-root PARTITION_VERT blocks moved (expected {PART128_VERT})"
11397+ );
11398+ assert_eq!(
11399+ part_after.6 - part_before.6,
11400+ INTRA128_VERT,
11401+ "{NAME}: key-frame intra 128-axis blocks moved (expected {INTRA128_VERT})"
11402+ );
11403+ assert_eq!(
11404+ part_after.2 - part_before.2,
11405+ 0,
11406+ "{NAME}: 128-root PARTITION_HORZ fired on this VERT witness"
11407+ );
11408+ assert_eq!(
11409+ rect_after.0 - rect_before.0,
11410+ 0,
11411+ "{NAME}: gathered edge-HORZ 128 roots fired on this VERT witness"
11412+ );
11413+ assert_eq!(
11414+ (r432_after.1 - r432_before.1, r432_after.2 - r432_before.2),
11415+ (RECT4_32_VERT, RECT4_32_CODED),
11416+ "{NAME}: the 32x32 VERT strip counts moved -- the coded half of the \
11417+ chroma tiling is what the old assert under-counted"
11418+ );
11419+
11420+ // Oracle 1: aomdec rawvideo.
11421+ if aomdec_available(NAME) {
11422+ let dir = std::env::temp_dir().join(format!("ec-av1-p1pin-{}", std::process::id()));
11423+ let _ = std::fs::remove_dir_all(&dir);
11424+ std::fs::create_dir_all(&dir).expect("scratch dir");
11425+ let raw = dir.join("aomdec.raw");
11426+ let out = Command::new(aomdec_path())
11427+ .args(["--codec=av1", "--rawvideo", "-o"])
11428+ .arg(&raw)
11429+ .arg(&obu)
11430+ .stdin(Stdio::null())
11431+ .stdout(Stdio::piped())
11432+ .stderr(Stdio::piped())
11433+ .output()
11434+ .expect("aomdec failed to run");
11435+ assert!(
11436+ out.status.success(),
11437+ "{NAME}: the oracle aomdec refused the stream: {}",
11438+ String::from_utf8_lossy(&out.stderr)
11439+ );
11440+ let ref_raw = std::fs::read(&raw).expect("aomdec rawvideo output");
11441+ let _ = std::fs::remove_dir_all(&dir);
11442+ assert_eq!(ref_raw.len(), W * H * 3 * FRAMES, "{NAME}: aomdec raw size");
11443+ for (i, f) in frames.iter().enumerate() {
11444+ let base = i * W * H * 3;
11445+ for ((plane, off), p) in [(&f.y, 0usize), (&f.u, W * H), (&f.v, 2 * W * H)]
11446+ .into_iter()
11447+ .zip(["y", "u", "v"])
11448+ {
11449+ let want = &ref_raw[base + off..base + off + W * H];
11450+ assert_eq!(
11451+ plane.len(),
11452+ want.len(),
11453+ "{NAME}: aomdec frame {i} plane {p}: ours has {} samples, the oracle's \
11454+ has {} -- a short plane would zip-truncate the compare below and \
11455+ hide a chroma-span defect",
11456+ plane.len(),
11457+ want.len()
11458+ );
11459+ let bad = plane
11460+ .iter()
11461+ .zip(want)
11462+ .filter(|&(&a, &b)| a as u8 != b)
11463+ .count();
11464+ assert_eq!(
11465+ bad, 0,
11466+ "{NAME}: aomdec frame {i} plane {p}: {bad} samples differ (class \
11467+ sb128-rect-chroma-tiling)"
11468+ );
11469+ }
11470+ }
11471+ }
11472+
11473+ // Oracle 2: ffmpeg yuv444p rawvideo. Hard-fails, never skips, when
11474+ // EC_AV1_REQUIRE_FFMPEG=1 (see have_ffmpeg).
11475+ if have_ffmpeg() {
11476+ let refs = ffmpeg_decode_sequence_444(&stream, W, H, FRAMES);
11477+ for (i, (got, want)) in frames.iter().zip(refs.iter()).enumerate() {
11478+ for (p, (g, r)) in [(&got.y, &want.y), (&got.u, &want.u), (&got.v, &want.v)]
11479+ .iter()
11480+ .enumerate()
11481+ {
11482+ assert_eq!(
11483+ g.len(),
11484+ r.len(),
11485+ "{NAME}: ffmpeg frame {i} plane {p}: ours has {} samples, ffmpeg's has \
11486+ {} -- a short plane would zip-truncate the compare below and hide a \
11487+ chroma-span defect",
11488+ g.len(),
11489+ r.len()
11490+ );
11491+ let bad = g.iter().zip(r.iter()).filter(|(a, b)| a != b).count();
11492+ assert_eq!(
11493+ bad, 0,
11494+ "{NAME}: ffmpeg frame {i} plane {p}: {bad} samples differ (class \
11495+ sb128-rect-chroma-tiling)"
11496+ );
11497+ }
11498+ }
11499+ } else {
11500+ eprintln!("SKIP {NAME}: no ffmpeg -- the ffmpeg oracle arm only");
11501+ }
11502+ }
1130911503 /// lane-lossless128: a LOSSLESS key frame that codes a 128-axis
1131011504 /// (`BLOCK_64X128`) intra block -- the shape libaom's `read_tx_size` forces
1131111505 /// to `TX_4X4` on its very first line (`decodeframe.c:1183`), so every plane
@@ -25361,7 +25555,7 @@ exit 0
2536125555 /// single-reference, and the compound arm contributes 8 of 96 route hits
2536225556 /// and none of the 8 that change an answer.
2536325557 ///
25364- /// The other 26 pinned 4:4:4 fixtures in this tree reach the arm zero
25558+ /// The other 27 pinned 4:4:4 fixtures in this tree reach the arm zero
2536525559 /// times (`444_intrabc_rect4_witness`, `444_leaf8_oob`,
2536625560 /// `444_lossy_rect4_*`, `444_lossy_superres_*`, `444_sb128rect_lr_witness`,
2536725561 /// and every `ll444_*`), so this one witness is the only thing pinning
lanes/av1p1pin.report.mdadded+114 -0
@@ -0,0 +1,114 @@
1+# lane-av1p1pin — pin recipe P1 and gate it byte-exact vs ffmpeg
2+
3+Base: `9a535ccb` (main). Branch: `lane/av1p1pin`. No decode-path edit.
4+
5+## r1 — The recipe did not drift; bytes are the report's bytes
6+
7+Rebuilt from scratch in `/tmp/av1p1pin` with the report's exact lines
8+(`lanes/av1witness2recheck.report.md` r"Commands"), ffmpeg 8.1.2 on PATH and
9+`~/.cache/aom-oracle/build/aomenc`:
10+
11+```
12+ffmpeg -y -f lavfi -i "nullsrc=s=320x256:rate=30:d=1,geq=lum='mod(floor((Y+T*160)/8)*67,255)':cb='128+20*sin(Y/17+T)':cr='128+20*sin(X/23+T*2)'" -pix_fmt yuv444p bands444.y4m
13+aomenc --codec=av1 --obu -o s1d.obu --passes=1 --threads=1 bands444.y4m --limit=3 --kf-max-dist=1 --cpu-used=2 --end-usage=q --cq-level=20 --sb-size=128 --enable-rect-partitions=1 --enable-1to4-partitions=1 --min-partition-size=4
14+```
15+
16+| file | sha256 | size |
17+|---|---|---|
18+| `bands444.y4m` (input) | `fa6218399cce8dd9eaadb6e24642d31cb2d2bde505b39a8df237938492c642ee` | — |
19+| `s1d.obu` (stream) | `68773f2c6e01a2d211bf0213479accb4c2c360132c0e1bc3b326eab7861925b1` | **595 B** |
20+
21+Both match the report verbatim, so the pin is the report's stream, not a
22+lookalike. Stop condition not hit.
23+
24+## r2 — Pinned in-tree
25+
26+`crates/ec-av1/fixtures/444_sb128rect_chroma_tile_witness.obu`, 595 bytes,
27+sha256 `68773f2c6e01a2d211bf0213479accb4c2c360132c0e1bc3b326eab7861925b1`
28+(FNV-1a `0xd4fa_ac7b_dccc_520b`, asserted in the gate). The name says the
29+shape: 4:4:4, 320x256, `--sb-size=128`, the 128-root rect chroma-tiling
30+witness. Provenance is in the gate's doc comment, not only here.
31+
32+This is a NEW pin. The tree's only other 4:4:4 sb128 fixture is
33+`444_sb128rect_lr_witness.obu` (794 B, sha256 `27825e14…`), a different
34+stream; the report's r"Outcome" already established the P1 bytes lived only
35+under `/tmp`.
36+
37+## r3 — Census on this tree, re-measured (not quoted from the report)
38+
39+`EC_NOMEMGUARD=1 decode_probe s1d.obu` on `9a535ccb`:
40+
41+```
42+OK: 3 frames decoded, 320x256
43+sb128_rect: edge_horz=0 edge_vert=6 inter_128x64=0 inter_64x128=0
44+part128: split=7 none=5 horz=0 vert=6 ab=[0,0,0,0] intra_horz=0 intra_vert=6
45+rect4_32: horz=0 vert=8 coded=8
46+```
47+
48+Identical to the report's numbers. These are the values the gate pins.
49+
50+## r4 — The gate
51+
52+`stream::tests::a_444_sb128_rect_chroma_tile_witness_is_byte_exact`
53+(`crates/ec-av1/src/stream.rs`). Two arms, both load-bearing:
54+
55+1. **Non-vacuity.** Deltas over the decode, under `lock_gate_counters()`:
56+ `sb128_rect_counters().1` (gathered edge-VERT 128 roots) `== 6`;
57+ `part128_census().3` (128-root `PARTITION_VERT`) `== 6`;
58+ `part128_census().6` (key-frame intra 128-axis) `== 6`;
59+ `rect4_32_counters().1/.2` (32x32 VERT strips, coded) `== (8, 8)`.
60+ Plus the two zeros that make the shape specific rather than incidental:
61+ `part128` HORZ `== 0`, gathered edge-HORZ `== 0`. A stream that stops coding
62+ the 128-root VERT shape reds here instead of passing on a decode that never
63+ reached the guarded walk (class `gate-blind-to-feature`).
64+2. **Pixel-exactness.** Every sample of all 3 frames, all 3 planes, vs
65+ `aomdec --codec=av1 --rawvideo` and vs `ffmpeg -f obu -pix_fmt yuv444p
66+ -f rawvideo`. Both oracles are real decoders, not shims. Each compare is
67+ guarded by a plane-length assert first, so a short plane cannot zip-truncate
68+ the comparison into a false zero (class `short-plane-hides-span`).
69+ `EC_AV1_REQUIRE_FFMPEG=1` turns a missing ffmpeg into a hard assert inside
70+ `have_ffmpeg()`, so the ffmpeg arm cannot silently skip.
71+
72+Frame 0 is a key frame and the report's `intra_vert=6` is its census, so the
73+guarded walk is exercised on the key frame; frames 1/2 are inter.
74+
75+## r5 — The gate is not vacuous: three mutations, three reds
76+
77+Each mutation was applied to the gate only, run, then reverted. Nothing touched
78+`decode.rs`.
79+
80+| # | mutation | result |
81+|---|---|---|
82+| A | `EDGE_VERT` expectation `6 → 7` (counter arm) | **RED** — `stream.rs:11385`, "gathered edge-VERT 128 roots moved (expected 7)" |
83+| B | `frames[1].u[7] += 1` before the oracle compares | **RED** — "aomdec frame 1 plane u: 1 samples differ" |
84+| C | perturb `frames[2].v[1234] += 1` AFTER the aomdec block, inside the ffmpeg arm only | **RED** — "ffmpeg frame 2 plane 2: 1 samples differ" |
85+
86+A proves the non-vacuity assertion reads a real measured value, not a tautology
87+the decode cannot fail. B and C prove each oracle arm separately bites (C is the
88+one that matters for this task: it reds on the ffmpeg compare with aomdec
89+already green, so the ffmpeg arm is not riding on aomdec's verdict).
90+
91+Post-revert: `EC_AV1_REQUIRE_FFMPEG=1 cargo test -p ec-av1 --lib
92+a_444_sb128_rect_chroma_tile_witness_is_byte_exact` → **1 passed, 0 failed**.
93+
94+## r6 — What this does and does not claim
95+
96+- Claims: these exact 595 bytes are permanently in-tree; on `9a535ccb` they
97+ decode to 3 frames that are byte-identical to ffmpeg and aomdec on all three
98+ planes; and that decode provably routes through the 128-root VERT chroma
99+ tiling path 6 times.
100+- Does not claim: the 4:4:4 class is exact. One stream, one shape. The
101+ report's own instrument limit ("one stream per predicate") carries over
102+ unchanged.
103+- Control inherited: the report shows these bytes panicked at `fe3e8418`
104+ (`decode.rs:17631`, the 128-rect chroma assert). So the pin is a live
105+ regression witness, not a fixture that always passed.
106+- Local scoped run only: one example build plus this one named gate test. No
107+ full suite, nothing pushed, nothing merged.
108+
109+## Files
110+
111+- `crates/ec-av1/fixtures/444_sb128rect_chroma_tile_witness.obu` (new, 595 B)
112+- `crates/ec-av1/src/stream.rs` (new gate at ~11310; one stale doc count
113+ "26 pinned 4:4:4 fixtures" → 27 in
114+ `the_pinned_444_quadrant_witness_...`'s comment, moved by this pin)