diff --git a/crates/ec-av1/src/stream.rs b/crates/ec-av1/src/stream.rs index d0f77156..6ddc6610 100644 --- a/crates/ec-av1/src/stream.rs +++ b/crates/ec-av1/src/stream.rs @@ -7407,7 +7407,237 @@ pub(crate) mod tests { } eprintln!("{NAME}: 4:2:0 control {h4} HORZ_4 / {v4} VERT_4 strips, 0 own-extent gathers"); } + /// lane-av1gates444: the live 4:4:4 LOSSY cell the chroma-format sweep + /// measured EXACT 4/4 and left unpinned. The recipe is the sweep's own + /// §6.2 encode, reproduced LIVE against the oracle `aomenc` rather than + /// from a pin, because the claim these three gates carry is a property + /// of the *decoder* at a geometry, not of a blob: + /// ```text + /// ffmpeg -f lavfi -i "testsrc2=size=x:rate=25" -frames:v 4 \ + /// -pix_fmt yuv444p -f yuv4mpegpipe - | \ + /// aomenc --codec=av1 --profile=1 --passes=1 --end-usage=q --cq-level=20 \ + /// --cpu-used=2 --threads=1 --row-mt=0 --lag-in-frames=0 \ + /// --kf-max-dist=100 --limit=4 --obu -o - - + /// ``` + /// `rate=25` is load-bearing (testsrc2's pattern is time-parameterised) + /// and `--limit=4` is the sweep's frame count: at `--limit=6` the same + /// recipe emits 7674 / 11465 / 19121 bytes instead of the sweep's + /// 5938 / 8945 / 15239, i.e. a different stream than the one measured. + /// `--profile=1` is what makes the source 4:4:4 at all. + /// + /// Every assertion here is a non-vacuity assertion first and a pixel + /// compare second. The frame count, the per-frame geometry and the + /// FULL-RESOLUTION chroma plane length are asserted because a truncated + /// or 4:2:0-shaped decode can pass a lenient compare; the + /// `rect4_inter_own_chroma444_hits()` reach assert is there because the + /// class these cells belong to is the 4:4:4-only own-chroma-extent route + /// in [`decode_inter_block`]'s `around_c` (a 4:2:0 stream of the same + /// content leaves it at 0), and a counter at 0 would mean the gate + /// measured a different route than it names. + fn encode_444_lossy_live(name: &str, w: usize, h: usize) -> Vec { + if !have_aomenc() { + eprintln!( + "SKIP {name}: no aomenc oracle at {} -- run scripts/build-aom-oracle.sh", + aomenc_path().display() + ); + return Vec::new(); + } + let source = format!("testsrc2=size={w}x{h}:rate=25"); + let y4m = Command::new("ffmpeg") + .args([ + "-v", + "error", + "-f", + "lavfi", + "-i", + &source, + "-frames:v", + "4", + "-pix_fmt", + "yuv444p", + "-f", + "yuv4mpegpipe", + "-", + ]) + .stdin(Stdio::null()) + .stdout(Stdio::piped()) + .stderr(Stdio::piped()) + .output() + .expect("ffmpeg failed to run"); + assert!( + y4m.status.success(), + "{name}: ffmpeg refused the {w}x{h} 4:4:4 source: {}", + String::from_utf8_lossy(&y4m.stderr) + ); + let out = run_with_stdin( + Command::new(aomenc_path()).args([ + "--codec=av1", + "--profile=1", + "--passes=1", + "--end-usage=q", + "--cq-level=20", + "--cpu-used=2", + "--threads=1", + "--row-mt=0", + "--lag-in-frames=0", + "--kf-max-dist=100", + "--limit=4", + "--obu", + "-o", + "-", + "-", + ]), + &y4m.stdout, + ); + assert!( + out.status.success(), + "{name}: aomenc refused the {w}x{h} 4:4:4 lossy recipe: {}", + String::from_utf8_lossy(&out.stderr) + ); + assert!( + !out.stdout.is_empty(), + "{name}: aomenc produced no OBU for {w}x{h} -- a zero-length stream would \ + decode to nothing and the compare below would compare nothing" + ); + out.stdout + } + + /// The body every 4:4:4 lossy live gate runs: assert the oracle compare + /// CANNOT be skipped, assert the decode really is the cell it claims + /// (frame count, geometry, full-resolution chroma), assert the 4:4:4-only + /// own-extent route really ran, then compare every frame in decode order + /// against the oracle aomdec with the length asserted first. + /// + /// The aomdec assert is deliberately a HARD failure, not the + /// `if aomdec_path().is_file()` skip the older gates use: a gate that + /// measures exactness and then quietly skips the compare reports green + /// for a decoder it never looked at (class gate-blind-to-the-arm). It + /// fires only when the gate is actually running, i.e. the oracle aomenc + /// resolved -- and aomenc and aomdec ship in the same build directory, + /// so an aomdec that is missing while aomenc is present is a broken + /// oracle, not a checkout without one. + fn gate_444_lossy_live_exact(name: &str, w: usize, h: usize) { + let stream = encode_444_lossy_live(name, w, h); + if stream.is_empty() { + return; // no oracle at all: the SKIP above already said so + } + assert!( + aomdec_path().is_file(), + "{name}: the oracle aomenc resolved to {} but no aomdec sits beside it at {} -- \ + the pixel compare would silently skip, which this gate treats as a failure", + aomenc_path().display(), + aomdec_path().display() + ); + let _guard = lock_gate_counters(); + crate::decode::reset_rect4_inter_own_chroma444_hits(); + let frames = decode_stream(&stream).unwrap_or_else(|e| { + panic!("{name}: the live {w}x{h} 4:4:4 lossy stream was refused: {e}") + }); + let own = crate::decode::rect4_inter_own_chroma444_hits(); + assert!( + own > 0, + "{name}: no 4:4:4 1:4 inter strip read its chroma context over its own extent -- \ + the route this cell is a witness for never ran (measured: 13 at 66x66, 12 at \ + 130x122, 24 at 256x128)" + ); + assert_eq!( + frames.len(), + 4, + "{name}: decoded {} frame(s), the recipe encodes 4 -- a short decode would make the \ + oracle compare cover a prefix of the cell", + frames.len() + ); + for (i, f) in frames.iter().enumerate() { + assert_eq!( + (f.width, f.height), + (w, h), + "{name}: frame {i} is {}x{}, the cell is {w}x{h}", + f.width, + f.height + ); + // At 4:4:4 both chroma planes are full resolution. A decoder that + // kept a subsampled extent would hand quarter-size planes to the + // byte compare; say so here instead of letting the compare + // stand in for the shape claim. + assert_eq!( + f.u.len(), + w * h, + "{name}: frame {i} U plane is {} samples; at 4:4:4 it must be full resolution \ + ({w}x{h})", + f.u.len() + ); + assert_eq!( + f.v.len(), + w * h, + "{name}: frame {i} V plane is {} samples; at 4:4:4 it must be full resolution \ + ({w}x{h})", + f.v.len() + ); + assert_eq!( + f.y.len(), + w * h, + "{name}: frame {i} luma plane is {} samples, expected {w}x{h}", + f.y.len() + ); + } + let (decoded, hidden) = decode_all_frames_vs_oracle(&stream, name); + assert_eq!( + decoded, 4, + "{name}: the oracle decoded {decoded} frame(s) in decode order, the recipe carries 4 \ + (so far {hidden} hidden)" + ); + eprintln!( + "{name}: {w}x{h} 4:4:4 lossy, {decoded} decode-order frame(s) byte-exact vs aomdec \ + ({hidden} hidden), {own} own-extent 1:4 chroma gather(s)" + ); + } + + /// lane-av1gates444 cell 1: **odd coded dims, 66x66** -- the partial-frame + /// walk in BOTH axes (66 is not a multiple of 8, so the frame is a + /// partial superblock column AND a partial row). Measured EXACT 4/4 by + /// the chroma-format sweep (§6.2, 5938 bytes) and unpinned: nothing in + /// the crate would go red if the odd-dimension 4:4:4 walk regressed, + /// and the only red-before evidence was a lane report nobody re-runs. + #[test] + fn a_444_lossy_odd_66x66_stream_decodes_pixel_exact() { + gate_444_lossy_live_exact("a_444_lossy_odd_66x66_stream_decodes_pixel_exact", 66, 66); + } + + /// lane-av1gates444 cell 2: **odd coded dims, 130x122** -- the + /// partial-frame RIGHT edge that the sweep found DIVERGENT (first wrong + /// sample Y(128,16), 11521 samples on frame 3) until lane-av1444rect's + /// 4:4:4 own-chroma-extent fix landed. It measures EXACT 4/4 on this + /// tree and is the discriminating geometry: 66x66 was exact at the same + /// settings while this was not, so the pair is what keeps "the 4:4:4 + /// partial-frame walk is right" from being a one-geometry accident. + #[test] + fn a_444_lossy_odd_130x122_stream_decodes_pixel_exact() { + gate_444_lossy_live_exact( + "a_444_lossy_odd_130x122_stream_decodes_pixel_exact", + 130, + 122, + ); + } + + /// lane-av1gates444 cell 3: **256x128**, the sweep's cell recorded as + /// "4:4:4 superres 256x128 (`--superres-mode=1`)". + /// + /// IT IS NOT A SUPERRES CELL, and this gate is named for what it is + /// instead. Measured here, live: encoding 256x128 with and without + /// `--superres-mode=1` produces BYTE-IDENTICAL OBU (15239 bytes, + /// sha256 06621606…, both), so the flag is a no-op on this aomenc build + /// and the sweep's cell was a plain 4:4:4 lossy cq-20 stream that + /// happened to carry the flag. The cell's actual value is the geometry + /// plus the filter stages: 256x128 is two full 128 superblock columns, + /// and the strip walk runs there with the post-deblock/CDEF/LR chain + /// live on the later frames -- so this is the third witness for the + /// 4:4:4 lossy strip class at a geometry the 128x96 rect4 gate does not + /// cover. + #[test] + fn a_444_lossy_256x128_stream_decodes_pixel_exact() { + gate_444_lossy_live_exact("a_444_lossy_256x128_stream_decodes_pixel_exact", 256, 128); + } /// lane-av1444rect r2 — the SAME class as the gate above, second /// instance: `decode_rect4_16_intrabc` applied the 4:2:0 pair geometry at /// ss (0,0), where `is_chroma_reference` makes an intra-BC 1:4 strip its diff --git a/lanes/av1gates444.report.md b/lanes/av1gates444.report.md new file mode 100644 index 00000000..3fdcafe0 --- /dev/null +++ b/lanes/av1gates444.report.md @@ -0,0 +1,173 @@ +# lane-av1gates444 — three measured-EXACT 4:4:4 lossy cells, pinned + +## 1. What this lane is + +Tests only. `crates/ec-av1/src/decode.rs` is **not** edited in the committed +tree (`git diff --stat` on the lane commit: `crates/ec-av1/src/stream.rs | 225 +insertions(+), 0 deletions`). No new `#[ignore]`. No new `tests/*.rs` file — +all three gates live in the existing `ec-av1` lib test binary +(`crates/ec-av1/src/stream.rs`, `pub(crate) mod tests`). + +Branch `lane-av1gates444`, one commit `81f88fd1` on top of `a21f3680`. + +## 2. The cells, and the recipe that reproduces them + +The three cells come from `lanes/av1formatsweep.report.md` §6.2 and +`lanes/av1444rect.report.md` §8. All three were **EXACT 4/4 with no committed +gate**; only the lane report carried the evidence. + +The sweep's encode is reproduced byte-for-byte. The stream sizes and sha256 +prefixes below match the sweep's table exactly, which is how the recipe is +confirmed rather than approximated: + +```text +ffmpeg -f lavfi -i "testsrc2=size=x:rate=25" -frames:v 4 \ + -pix_fmt yuv444p -f yuv4mpegpipe - | \ +aomenc --codec=av1 --profile=1 --passes=1 --end-usage=q --cq-level=20 \ + --cpu-used=2 --threads=1 --row-mt=0 --lag-in-frames=0 \ + --kf-max-dist=100 --limit=4 --obu -o - - +``` + +| cell | gate | bytes | sha256 | sweep said | +|---|---|---|---|---| +| odd 66x66 | `a_444_lossy_odd_66x66_stream_decodes_pixel_exact` | 5938 | `973eddf4…` | 5938 / `973eddf4…` | +| odd 130x122 | `a_444_lossy_odd_130x122_stream_decodes_pixel_exact` | 8945 | `c87ac65b…` | 8945 / `c87ac65b…` | +| 256x128 | `a_444_lossy_256x128_stream_decodes_pixel_exact` | 15239 | `06621606…` | 15239 / `06621606…` | + +Two flags are load-bearing and both are documented in the gate's doc comment: + +- `rate=25` — testsrc2's pattern is time-parameterised, so `rate=1` is a + different stream. +- `--limit=4` — the sweep's frame count. At `--limit=6` the same recipe emits + 7674 / 11465 / 19121 bytes, i.e. a *different* stream than the one measured. + Measured, not assumed. +- `--profile=1` is what makes the source 4:4:4 at all. + +### 2.1 The third cell is NOT a superres cell + +The sweep recorded it as "4:4:4 **superres** 256x128 (`--superres-mode=1`)" and +`av1444rect` §8 corrected that. Measured here to settle it independently: + +| encode | bytes | sha256 | +|---|---|---| +| 256x128 without `--superres-mode=1` | 15239 | `881ab784…` at limit=6 / `06621606…` at limit=4 | +| 256x128 **with** `--superres-mode=1` | 15239 | identical | + +The flag is a no-op on this aomenc build. The gate is therefore named +`a_444_lossy_256x128_stream_decodes_pixel_exact` — for its geometry — and the +doc comment says so explicitly, so the next lane does not re-derive a superres +claim from the sweep's table. + +## 3. The three gates + +All three share two helpers in the same file: `encode_444_lossy_live` (ffmpeg +y4m → live aomenc, `run_with_stdin` deadline, non-empty-OBU assert) and +`gate_444_lossy_live_exact` (the body). Modelled on +`a_444_lossy_rect4_inter_stream_decodes_pixel_exact` (stream.rs:7240), with +three deliberate differences: + +1. **No pin.** The stream is encoded live against the oracle aomenc, because + the claim is a property of the decoder at a geometry, not of a blob. The + sweep's byte counts live in the doc comment as the recipe's provenance. +2. **The pixel compare cannot be skipped.** The old gate guards it with + `if aomdec_path().is_file()`; these three assert. If aomenc resolved but + no aomdec sits beside it, the gate FAILS rather than reporting green for a + decoder it never looked at (class `gate-blind-to-the-arm`). It still SKIPs + when there is no oracle at all, which `have_aomenc()` turns into a hard + failure under `EC_AV1_REQUIRE_AOMENC=1` — the crate's existing convention. +3. **Per-cell geometry, asserted before the compare.** Frame count 4, and per + frame `(f.width, f.height) == (W, H)` plus `f.u.len() == f.v.len() == + f.y.len() == W*H`. At 4:4:4 a decoder keeping a subsampled extent would + hand quarter-size planes to the byte compare; the gate says which invariant + broke instead of letting the compare stand in for the shape claim. + +Non-vacuity, per cell: `decode::rect4_inter_own_chroma444_hits() > 0` after a +reset — the 4:4:4-only own-chroma-extent route in `decode_inter_block`'s +`around_c` that this class is about. A 4:2:0 stream of the same content reads +0. Measured **13 / 12 / 24** own-extent gathers at 66x66 / 130x122 / 256x128. + +## 4. Green (this tree, oracle aomenc + aomdec present) + +``` +$ ec_av1 a_444_lossy_odd_66x66_stream_decodes_pixel_exact --nocapture +a_444_lossy_odd_66x66_stream_decodes_pixel_exact: 66x66 4:4:4 lossy, 4 decode-order frame(s) + byte-exact vs aomdec (0 hidden), 13 own-extent 1:4 chroma gather(s) +test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 714 filtered out + +$ ec_av1 a_444_lossy_odd_130x122_stream_decodes_pixel_exact --nocapture +a_444_lossy_odd_130x122_stream_decodes_pixel_exact: 130x122 4:4:4 lossy, 4 decode-order frame(s) + byte-exact vs aomdec (0 hidden), 12 own-extent 1:4 chroma gather(s) +test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 714 filtered out + +$ ec_av1 a_444_lossy_256x128_stream_decodes_pixel_exact --nocapture +a_444_lossy_256x128_stream_decodes_pixel_exact: 256x128 4:4:4 lossy, 4 decode-order frame(s) + byte-exact vs aomdec (0 hidden), 24 own-extent 1:4 chroma gather(s) +test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 714 filtered out +``` + +Untouched-and-still-green, same binary: + +``` +$ ec_av1 a_444_lossy_rect4_inter --test-threads=1 → ok +$ ec_av1 unrefreshed_primary_ref_slot --test-threads=1 → ok (the stream.rs source-scan guard) +``` + +## 5. Red-before, measured (both mutations reverted, neither committed) + +### 5.1 `decode.rs` `around_c` own-extent arm → the 4:2:0 pair extent + +`Some(_) if ss_x(fctx) == 0 => { hit!(…); around }` replaced with the pair +gather `neighbours.around_mi_rect(s.pair_mi, pw, ph)` at `(16,8)` HORZ / +`(8,16)` VERT. The `hit!` stayed, so the reach assert still fires and the red +lands on the pixel arm rather than the counter — the lesson from +skill://ec-av1-pipeline-gate-counters. + +| gate | result | +|---|---| +| 66x66 | **green** — expected, see 5.3 | +| 130x122 | **RED**: decode-order frame 3 of 4, byte 2208 (ours 134 vs oracle 170), **11521 bytes differ** | +| 256x128 | **RED**: decode-order frame 2 of 4, byte 192 (ours 92 vs oracle 106), **25296 bytes differ** | + +The 130x122 number is the sweep's, to the byte: sweep §6.2 said "DIVERGENT +from f3, 11521 samples, first (f3, s2208) = Y(128,16)". The 256x128 numbers are +`av1444rect` §8's base row ("DIVERGENT f2 25296"). + +### 5.2 `ec-av1-syntax` `compute_image_size` — the mi-grid ceil floored + +`h.mi_cols = 2 * ((h.frame_width + 7) >> 3)` → +`2 * (h.frame_width >> 3)` (and the row line likewise). + +| gate | result | +|---|---| +| 66x66 | **RED**: `restoration.rs:783` — "range end index 4098 out of range for slice of length 4096" | +| 130x122 | **RED**: decode-order frame 0 of 4, byte 128 (ours 74 vs oracle 170), 22724 bytes differ | +| 256x128 | **green**, correctly — 256x128 is a multiple of 8 in both axes, so the ceil and the floor agree and the cell is not supposed to see this mutation | + +### 5.3 What 66x66 is, stated honestly + +`odd444_66x66` is a **coverage pin, not a witness for the strip fix**. The +sweep measured it EXACT 4/4 on the *pre-fix* base, so mutation 5.1 cannot +make it red and no mutation of the strip route ever will. Its +load-bearingness is mutation 5.2: it is the only gate here whose geometry is +partial in **both** axes, and dropping the mode-info grid's ceil breaks it on +the first decode. 130x122 and 256x128 are witnesses for the 4:4:4 lossy +strip-own-extent class; 66x66 is the pin for the odd-in-both-axes 4:4:4 lossy +walk. Both roles are load-bearing and neither is invented. + +## 6. Invariants held + +- `crates/ec-av1/src/decode.rs`: not edited in the committed tree. +- Existing gates: not edited — the commit is 225 insertions, 0 deletions, one + file. +- Same test binary: `crates/ec-av1/src/stream.rs`, `pub(crate) mod tests`. +- No new `#[ignore]`. +- Commit message carries the mechanism and the measurements, no host paths. + +## 7. Not done, stated + +- The three gates encode on every run, so each costs one ffmpeg + one aomenc + (~0.6 s measured, all three together). If a future lane finds that too + expensive for a loop run, the pin migration is mechanical: the byte counts + and sha256 prefixes are in §2. +- Only 8-bit lossy cq-20 is covered. 4:4:4 lossy at 10/12 bits and the tile + cells stay the sweep's open list; nothing here narrows that gap.