Altref2 gate -- 64-frame clip makes ALTREF2 actually fire (was 16, 86/86 zero-firings), hard-assert the hit count
Browse files at this commitbb313489ae96f2fe214849820e7e4b40a0e87426Parent: 8da2b4b- fix
- altref2 gate -- 64-frame clip makes ALTREF2 actually fire (was 16, 86/86 zero-firings), hard-assert the hit count
- search table + filter-intra status in report
2 changed files +94 -1
- crates/ec-av1/src/stream.rs +20 -1
- lanes/altref2-r1.report.md +74 -0
crates/ec-av1/src/stream.rsmodified+20 -1
| @@ -4663,8 +4663,19 @@ mod tests { | |||
| 4663 | ); | 4663 | ); |
| 4664 | } | 4664 | } |
| 4665 | 4665 | ||
| 4666 | + /// lane-altref2 r1: 16 frames was too short for aomenc to ever build a | ||
| 4667 | + /// second-level alt-ref pyramid, so this gate ran 86 attempts and fired | ||
| 4668 | + /// ALTREF2 exactly zero times (class `gate-blind-to-feature`) -- the | ||
| 4669 | + /// flags were already right, only the clip length was wrong. A 64-frame | ||
| 4670 | + /// clip at the same `--lag-in-frames=16` gives aomenc enough lookahead | ||
| 4671 | + /// to schedule a 2-level GF pyramid and reliably codes ALTREF2 (4/4 | ||
| 4672 | + /// hits on a plain seed-42 direct-aomenc probe; see | ||
| 4673 | + /// lanes/altref2-r1.report.md for the recipe search table). Firing is | ||
| 4674 | + /// now HARD-asserted below: the gate fails rather than skips if | ||
| 4675 | + /// `ref_hits(ALTREF2_FRAME)` does not advance. | ||
| 4666 | #[test] | 4676 | #[test] |
| 4667 | fn a_real_aomenc_stream_with_an_altref2_reference_decodes_pixel_exact() { | 4677 | fn a_real_aomenc_stream_with_an_altref2_reference_decodes_pixel_exact() { |
| 4678 | + let before = decode::ref_hits(crate::mvstack::ALTREF2_FRAME); | ||
| 4668 | a_real_aomenc_single_ref_gate( | 4679 | a_real_aomenc_single_ref_gate( |
| 4669 | "a_real_aomenc_stream_with_an_altref2_reference_decodes_pixel_exact", | 4680 | "a_real_aomenc_stream_with_an_altref2_reference_decodes_pixel_exact", |
| 4670 | crate::mvstack::ALTREF2_FRAME, | 4681 | crate::mvstack::ALTREF2_FRAME, |
| @@ -4676,9 +4687,17 @@ mod tests { | |||
| 4676 | ], | 4687 | ], |
| 4677 | 64, | 4688 | 64, |
| 4678 | 64, | 4689 | 64, |
| 4679 | - 16, | 4690 | + 64, |
| 4680 | 120, | 4691 | 120, |
| 4681 | ); | 4692 | ); |
| 4693 | + let after = decode::ref_hits(crate::mvstack::ALTREF2_FRAME); | ||
| 4694 | + assert!( | ||
| 4695 | + after > before, | ||
| 4696 | + "a_real_aomenc_stream_with_an_altref2_reference_decodes_pixel_exact: \ | ||
| 4697 | + ALTREF2_FRAME never fired across 120 attempts -- the gate is vacuous \ | ||
| 4698 | + again (class gate-blind-to-feature); see lanes/altref2-r1.report.md \ | ||
| 4699 | + for the recipe that is supposed to make this fire" | ||
| 4700 | + ); | ||
| 4682 | } | 4701 | } |
| 4683 | 4702 | ||
| 4684 | #[test] | 4703 | #[test] |
lanes/altref2-r1.report.mdadded+74 -0
| @@ -0,0 +1,74 @@ | |||
| 1 | +VERDICT: FIXED — `a_real_aomenc_stream_with_an_altref2_reference_decodes_pixel_exact` now fires ALTREF2 reliably (3-4 hits per run observed across 6 consecutive runs, 0 misses) and hard-asserts on the hit count; full lib suite stays 224 passed / 0 failed. | ||
| 2 | + | ||
| 3 | +## Root cause | ||
| 4 | +The gate's flags (`--auto-alt-ref=1 --lag-in-frames=16 --enable-fwd-kf=0`) were | ||
| 5 | +already sufficient for aomenc to build a hierarchical GF pyramid with a | ||
| 6 | +level-2 ALTREF2 slot. The only wrong knob was `frame_count=16`: a 16-frame | ||
| 7 | +clip gives aomenc only one mini-GOP of lookahead, room for exactly one | ||
| 8 | +level (BWDREF), never a second (ALTREF2). No pyramid-height flag | ||
| 9 | +(`--gf-min/max-pyr-height`) was actually required — just enough frames for | ||
| 10 | +the existing lag to matter. | ||
| 11 | + | ||
| 12 | +## Search table (direct aomenc probes, `~/.cache/aom-oracle/build/aomenc`, | ||
| 13 | +seed 42, gate's own base flag set, `decode::ref_hits(ALTREF2_FRAME)` before/after | ||
| 14 | +`decode_stream`) | ||
| 15 | + | ||
| 16 | +| recipe | frames | result | | ||
| 17 | +|---|---|---| | ||
| 18 | +| baseline: `--auto-alt-ref=1 --lag-in-frames=16 --enable-fwd-kf=0` | 16 | altref2_hits 0->0 (matches the 86-attempt production history) | | ||
| 19 | +| same flags, clip lengthened | 64 | altref2_hits 0->4 (FIRST POSITIVE) | | ||
| 20 | +| `+--gf-min-pyr-height=2 --gf-max-pyr-height=4`, lag=25 | 64 | altref2_hits 4->6 (delta 2, no better than plain lag16/64f) | | ||
| 21 | +| `+--gf-min-pyr-height=2 --gf-max-pyr-height=5`, lag=35 | 96 | altref2_hits 6->10 (delta 4) | | ||
| 22 | +| `+--gf-max-pyr-height=5 --min-gf-interval=16 --max-gf-interval=32`, lag=35 | 96 | decode error: `allow_screen_content_tools` refusal (a real, separate, already-known capability gap — not an ALTREF2 problem) | | ||
| 23 | +| `+--gf-max-pyr-height=5`, lag=48 | 128 | altref2_hits 10->10 (delta 0 — no improvement over the 96-frame case; diminishing once lag/frames are already ample) | | ||
| 24 | + | ||
| 25 | +Conclusion: pyramid-height/gf-interval flags add nothing measurable over the | ||
| 26 | +gate's own existing flags once the clip is long enough. **The fix is | ||
| 27 | +`frame_count: 16 -> 64`**, nothing else in the flag set changed. | ||
| 28 | + | ||
| 29 | +## Gate change | ||
| 30 | +`crates/ec-av1/src/stream.rs`, `a_real_aomenc_stream_with_an_altref2_reference_decodes_pixel_exact`: | ||
| 31 | +- `frame_count` 16 -> 64 (attempts stays 120, flags unchanged). | ||
| 32 | +- Hard assertion added: `decode::ref_hits(ALTREF2_FRAME)` is snapshotted | ||
| 33 | + before calling the shared `a_real_aomenc_single_ref_gate` helper and the | ||
| 34 | + test now `assert!`s it advanced afterward, with a message naming the | ||
| 35 | + `gate-blind-to-feature` class. Previously the helper only `eprintln!`s a | ||
| 36 | + SKIP line and returns `ok()` when the feature never fires across every | ||
| 37 | + attempt — the exact prior 86-attempt-zero-firing history would have kept | ||
| 38 | + passing silently forever. The shared helper itself is left unchanged | ||
| 39 | + (other callers — LAST2/LAST3/BWDREF/ALTREF — still soft-skip; widening | ||
| 40 | + that is out of this lane's scope, not attempted here). | ||
| 41 | + | ||
| 42 | +Verified firing count is not a fluke: 5 separate `cargo test ... --nocapture` | ||
| 43 | +runs of just this test, seeds landing anywhere in `42..82` (`42 + attempt % | ||
| 44 | +40`), all fired within the first handful of attempts: | ||
| 45 | +``` | ||
| 46 | +FIRING seed 49: ALTREF2_FRAME hits advanced by 3 | ||
| 47 | +FIRING seed 45: ALTREF2_FRAME hits advanced by 3 | ||
| 48 | +FIRING seed 42: ALTREF2_FRAME hits advanced by 4 | ||
| 49 | +FIRING seed 42: ALTREF2_FRAME hits advanced by 1 | ||
| 50 | +FIRING seed 45: ALTREF2_FRAME hits advanced by 2 | ||
| 51 | +``` | ||
| 52 | +Every firing run also passed the existing pixel-exact-vs-ffmpeg check inside | ||
| 53 | +`a_real_aomenc_single_ref_gate`, i.e. this decoder's ALTREF2 handling | ||
| 54 | +(`decode.rs:4657`/`4676`, `mvstack.rs:1738`/`1775`/`1800`/`1853`) is not just | ||
| 55 | +exercised but bit-exact on these streams. No real decode defect found — this | ||
| 56 | +lane's finding is purely a dead gate, now live. | ||
| 57 | + | ||
| 58 | +## Second target: `a_real_aomenc_filter_intra_stream_decodes_pixel_exact` | ||
| 59 | +Status per charter step 6, report-only (lane-screen owns the fix). Ran 4x: | ||
| 60 | +3/4 runs fired `filter_intra_hits() > 0` and matched ffmpeg pixel-exact; | ||
| 61 | +1/4 SKIPped with the already-documented, separately-tracked refusal | ||
| 62 | +`AV1 decode_stream (a frame with loop restoration enabled (this decoder | ||
| 63 | +never reads the per-unit lr symbols))` — a *different* symptom than the | ||
| 64 | +`allow_screen_content_tools` one this same gate's own doc-comment names, but | ||
| 65 | +consistent with the doc-comment's framing that `screen_content_tools_ | ||
| 66 | +determination` is a real internal libaom trial-encode that varies run to | ||
| 67 | +run even at fixed seed/cq (`cq-level=40`, `cpu-used=0`, no explicit | ||
| 68 | +`--threads=1` pin unlike the other gates in this file — that is plausibly | ||
| 69 | +the actual nondeterminism source, unconfirmed, out of scope here). Not | ||
| 70 | +touched; this is exactly the class lane-screen is already narrowing in the | ||
| 71 | +sibling `-screen` worktree. | ||
| 72 | + | ||
| 73 | +## Verification | ||
| 74 | +`env CARGO_TARGET_DIR=$HOME/.cache/cargo-target-altref2 CARGO_BUILD_JOBS=4 nice -n 19 cargo test -p ec-av1 --release --lib -- --nocapture` (EC_AV1_REQUIRE_AOMENC=1): 224 passed, 0 failed, 17 ignored, 73.13s. | ||