diff --git a/crates/ec-av1/src/encode.rs b/crates/ec-av1/src/encode.rs index 797cb3cf..d50779a6 100644 --- a/crates/ec-av1/src/encode.rs +++ b/crates/ec-av1/src/encode.rs @@ -21044,15 +21044,18 @@ mod tests { eprintln!("PARITY q={q} bytes={} fnv1a={hash:016x} speed={} pyramid {:?} effective {:?}", e.stream.len(), crate::speed::speed(), crate::encoder::Pyramid::from_env(), last_sequence_pyramid()); } - /// lane-refs: IS A SECOND PAST REFERENCE WORTH RETAINING? `encoder.rs`'s - /// `ref_frame_idx` maps `LAST2`/`LAST3` onto `LAST`'s own DPB slot, so no - /// block can predict from the picture before `LAST` -- while rav1e's ARFs - /// read LAST@-4 plus LAST2@-8 and libaom holds up to seven distinct - /// pictures. Building that (a second retained slot, the search offering - /// it, a witness, a second motion search per block) is a week of wall on - /// the stage that already owns most of the encode, so this census prices - /// the lever FIRST (class `gate-blind-to-feature`, "count how often the - /// feature would fire before building the machine"). + /// lane-refs/lane-last2: IS A SECOND PAST REFERENCE WORTH RETAINING? The + /// lever this census priced SHIPS since lane-last2 (merge `321b2dc1`): + /// `EC_AV1_LAST2` (default OFF) retains a second past leaf picture in + /// `LEAF_SLOTS`, names it `ref_frame_idx[1]`, and offers it to the 32x32 + /// search with its own `NEWMV` (`EC_AV1_LAST2_NEW`); the ARF-level lags + /// the census's far row measures were already banked by `arf_altref`. + /// This census stays the PRICING arm (class `gate-blind-to-feature`): its + /// best-of-two SAD shares are read against the fire share the gate census + /// prints (`references ... LAST2 n (n%)`) and the refutation in + /// `lanes/last2.report.md` §4 -- a pure-SAD best-of-two over-counts the + /// lever by more than an order of magnitude once NEAR/NEAREST/DRL off + /// `LAST`, the backward `ALTREF`, and the rate term price in. /// /// The measurement is on the gate's own window and loader (`gate_crop`, /// 12 pictures) of the two real films: every 16x16 luma block of every diff --git a/lanes/l2.charter.md b/lanes/l2.charter.md new file mode 100644 index 00000000..4f098d6d --- /dev/null +++ b/lanes/l2.charter.md @@ -0,0 +1,88 @@ +# lane-l2 — re-judge LAST2 on the current substrate: the deciding long-GOP gate + +GOAL: LAST2 is a second retained past reference (`LAST2_FRAME` naming its own +DPB slot instead of aliasing `LAST`'s). The machinery SHIPS at base `a8f2186a` +from lane-last2 (merge `321b2dc1`): `EC_AV1_LAST2` knob default OFF +(`encoder.rs` `last2()` / `const LAST2 = false`), leaf chain alternating +`LEAF_SLOTS = [0, 7]` with `leaf_hist` carried across mini-GOPs, +`ref_frame_idx[1]` + per-slot `sign_bias`/`order_hints` coding, the 32x32 +`extra` search offer with LAST2's own `NEWMV` search +(`EC_AV1_LAST2_NEW=0` = search-free arm), the RD pricer's LAST2 leaf, and the +witness `a_leaf_predicts_off_last2_when_the_picture_two_back_matches`. What +lane-last2 NEVER measured: the long-GOP gate (its handover: "No long-GOP arm +was run because nothing ships"), and its 12-frame refutation predates +lane-intertx / lane-rectres / lane-tplhalf — the RD landscape moved. This lane +re-judges the lever on the current substrate, on the gates the keep rule +actually reads, and either flips the default or documents the standing +refutation with the deciding table filled in. + +Work ONLY in this worktree (`lane-l2`, +`/home/user/Documents/Code/Rust/edith_codecs-l2`). Absolute paths only. +Never touch main's checkout, never push, never `git checkout `, never +repo-wide `cargo fmt`. `export +CARGO_TARGET_DIR=$HOME/.cache/cargo-target-l2` on every cargo command. Logs +under `~/.cache/l2/`. Gates on server-1 (`user@host-e`) per +`skill://ec-av1-remote-gate-runners`: repo `/home/user/gates/repo-l2`, target +`/home/user/gates/target-l2`, `systemd-run --user -p MemoryMax=5G`, +`--ignored --exact` FULL test paths, one gate at a time, LOADAVG before AND +after, logs tee'd under `~/.cache/l2/`. Pins 8291 / 33227. Keep rule: one film +row ≥0.5 BD down on a column, the other flat within ±0.3, screen not worse by +0.3, wall ≤+15%. Sign: BD-rate, lower better. + +## 1. Charter / census ground truth + +- Commit this charter first. +- The stale premise in `encode.rs` `last2_census`'s doc comment (~L21048, + "no block can predict from the picture before LAST ... a week of wall") is + OBSOLETE — the machinery exists and is default-off. Refresh it to name what + ships and where the lever's measurement lives (clean cutover: no comment + claiming a gap the code no longer has). +- The per-lag SAD census (`last2_census`, `--ignored`) is the arm that priced + the lever (`refs.report.md` §1: leaf best-of-two removes 6.99% film A / + 7.25% film B of SAD energy; ARF row already banked by `arf_altref`). Re-run + it on the current HEAD if the real films are reachable locally; cite the + numbers next to the fire share. +- The gate census already prints LAST2's real share + (`references LAST n LAST2 n GOLDEN n ALTREF n of m inter blocks (LAST2 %)`, + `encode.rs` `bd_rate_screen_native`, one `take_ref_frame_hits()` read, no + drain-then-read). Keep it; every arm row must show it. + +## 2. Witnesses FIRST (before any BD gate) + +- Re-run `encoder::tests::a_leaf_predicts_off_last2_when_the_picture_two_back_matches` + locally (release): it must show the lever OFF coding 0 LAST2 blocks and ON + coding a real count (>0 — the `gate-blind-to-feature` guard), and both + decoders (`decode_stream` AND ffmpeg) sample-exact. +- OFF must stay today's behavior bit-exact: the pins test stays green with + the knob untouched (8291 / 33227). + +If any witness shows an encoder-reconstruction mismatch: STOP, do not gate, +report class + path:line, default stays OFF. + +## 3. Measure (server-1, per the skill recipe) + +Control = default (knob off), arm = `EC_AV1_LAST2=1`, same HEAD. Sanity gate +FIRST: the control must reproduce the standing table within ±0.2/cell +(long-GOP film A +20.9/-9.0, film B +70.4/-2.2; native rows per +`lanes/rectres.report.md` §3b off columns), else STOP and report substrate +suspicion. + +- `encode::tests::bd_rate_film_long_gop` (deciding; both films in one run). +- `encode::tests::bd_rate_screen_native` (all five rows). +- Census share per clip from both arm logs; walls ours off→on; LOADAVG pairs. + +## 4. Keep rule + +Met → default ON at the measured presets + pins at default and +`EC_AV1_SPEED=6` + three-lane lib suite LOCALLY +(`--skip stream::` / `stream:: --skip 10bit` / `10bit`) + +`timeout 900 cargo check --workspace --all-targets -j4` (0 ec-av1 warnings). +Not met → default stays OFF, document. Mismatch → OFF, report (see §2). + +## DONE + +Commits on `lane-l2` (charter, code-if-any, report) + +`lanes/l2.report.md` with EVIDENCE lines +(`EVIDENCE: | | `), disposition +`ships-on | stays-off | stopped`, BD tables both gates, LAST2 census share per +clip, walls, LOADAVG pairs, pins line. Never merge or push. diff --git a/lanes/l2.report.md b/lanes/l2.report.md new file mode 100644 index 00000000..71604a0f --- /dev/null +++ b/lanes/l2.report.md @@ -0,0 +1,185 @@ +# lane-l2 — re-judge LAST2 on the current substrate: the deciding long-GOP gate + +Base: `a8f2186a` (lane-l2 worktree). Disposition: **stays-off** — on the +deciding gate the lever was never in the keep rule's reach (best delta +anywhere is -0.3 BD, the rule asks ≥0.5), it fires for real but tiny +(0.5-1.1% of inter blocks on the films, 0.0% on bars 2160p and screen), and +it costs +4.4-9.7% encoder wall. The machinery from lane-last2 (merge +`321b2dc1`) stays behind `EC_AV1_LAST2` (default OFF = today's behavior bit +for bit — the control reproduces the standing table to the digit on four of +five native rows and both long-GOP rows). Pins untouched at 8291 / 33227 (no +default change, so no pin run, no lib suite). Never merged, never pushed. + +## 0. What this lane actually was (the stale premise, corrected) + +The task text priced the lever from `last2_census`'s doc comment, which still +claimed `ref_frame_idx` aliases `LAST2` onto `LAST`'s slot and called the +build "a week of wall". That premise was STALE at the base: lane-last2 +already shipped the whole machine — `EC_AV1_LAST2` knob (default OFF, +`encoder.rs` `last2()`/`const LAST2 = false`), the leaf chain alternating its +refresh over `LEAF_SLOTS = [0, 7]` with `leaf_hist` carried across mini-GOPs, +`ref_frame_idx[1]` + per-slot `sign_bias`/`order_hints` coding, the 32x32 +`extra` search offer with LAST2's own `NEWMV` (`EC_AV1_LAST2_NEW`), the RD +pricer's LAST2 leaf, the OBMC picture table, the trial-decode `RefPix` slot, +the witness, and the gate census line. What lane-last2 NEVER measured: the +long-GOP gate (its own handover: "No long-GOP arm was run because nothing +ships"), and its 12-frame refutation predates lane-intertx/lane-rectres/ +lane-tplhalf. So this lane re-ran the per-lag SAD census, re-witnessed, and +filled in the deciding table on server-1; the only source change needed was +retiring the stale doc comment itself. + +## 1. What shipped (commits `eaf64ec4`, `eeae0580`) + +- `lanes/l2.charter.md` — this lane's charter, committed first. +- `encode.rs` `last2_census` doc comment rewritten: it now states what ships + (the lever is real, `EC_AV1_LAST2`, leaf chain, 32x32 offer with its own + NEWMV), that the census stays the PRICING arm, and that its best-of-two SAD + shares over-count the lever by more than an order of magnitude once + NEAR/NEAREST/DRL off `LAST`, the backward `ALTREF`, and the rate term price + in — pointing at `last2.report.md` §4's refutation and the gate census's + fire share. Comment-only; no behavior change. +- No other source change: the charter's build steps (1) DPB slot, (2) search + offer + own motion search, (3) witness, (4) census share — were all + already in the base and are measured here as they shipped. + +## 2. Witnesses (all local, release, BEFORE any gate) + +- `encoder::tests::a_leaf_predicts_off_last2_when_the_picture_two_back_matches` + PASS in 1.53 s: lever OFF codes LAST 101 / **LAST2 0** / GOLDEN 18 / + ALTREF 3 (2933 B); lever ON codes LAST 54 / **LAST2 40** / GOLDEN 16 / + ALTREF 0 (2449 B) — the census/counter guard (`off == 0`, `on >= 8`) + proves the blocks were really CODED off LAST2 and that OFF is today's + behavior; `decode_stream` AND ffmpeg both reconstruct all nine display + positions sample-exact; one `show_existing_frame` per hidden frame. + EVIDENCE: ~/.cache/l2/witness.log | cargo test --release --lib -- + a_leaf_predicts_off_last2_when_the_picture_two_back_matches --nocapture | + "off: ... LAST2 0 ... on: ... LAST2 40 ...", ok, both decoders exact. + LOADAVG 1.57/1.17/1.11 before, 1.52/1.17/1.11 after (1.6 s run). +- `encode::tests::the_encoders_own_streams_are_byte_identical_to_their_pins` + PASS in 4.85 s at the default (knob untouched): OFF is bit-exact at the + pins. EVIDENCE: local run, pins test ok, 8291 / 33227 unchanged. +- Per-lag SAD census `encode::tests::last2_census` re-run on this HEAD, + reproduces `refs.report.md` §1 EXACTLY (deterministic): film A leaf 6.99% / + ARF 10.31%, film B leaf 7.25% / ARF 8.38% of prediction SAD removed by + best-of-two. The pricing census is unchanged and the refutation stands: + pure-SAD over-counts the lever ~an order of magnitude (38% of blocks by + SAD vs 0.5-1.1% coded once rate, NEAR/NEAREST/DRL and the backward ALTREF + price in). EVIDENCE: ~/.cache/l2/sad-census.log | --ignored --exact + encode::tests::last2_census | table identical to refs.report §1, 2.63 s. + +## 3. BD measurement (server-1 user@host-e, per the skill recipe) + +Repo `/home/user/gates/repo-l2`, target `/home/user/gates/target-l2`, +rsync of worktree `eeae0580` (`--exclude /fixtures/ /target/ /.git/`), +fixtures symlink, `rm -f .git && git init -q`, warm release compile 56.5 s. +Four gates run STRICTLY serially by one remote chain +(`/home/user/gates/gate-chain-l2.sh`): control = `EC_AV1_LAST2=0`, arm = +`EC_AV1_LAST2=1`, same HEAD, `MemoryMax=5G`, ffmpeg PATH shim, `--ignored +--exact` full test paths, per-gate logs on the server and copied to +`~/.cache/l2/`. + +Sanity gate PASSED: the control reproduces the standing table within the +±0.2/cell requirement — long-GOP film A +20.9/-9.0 and film B +70.4/-2.2 TO +THE DIGIT, native rows bars 1080p -3.3/-19.0, bars 2160p +8.4/-13.9, film A ++17.9/-6.3, film B +22.6/-3.8 TO THE DIGIT. The fifth native row reads ++13.7/-33.6 where `rectres.report.md` §3b records +14.4/-33.2 — exactly the +screen-default improvement lane-intertx's merge (`c736be2c`) documents +("+14.4 -> +13.7"), which this HEAD contains; against the corrected standing +number the row reproduces to the digit too. This is a documented base change, +not substrate suspicion. + +### 3a. Long-GOP BD (deciding; 48 pictures, gop=48, both films) + +BD-rate, lower better: + +| row | off vs libaom | off vs rav1e | on vs libaom | on vs rav1e | wall ours off->on | +|---|---|---|---|---|---| +| film A (1080p) 1920x768 | +20.9% | -9.0% | +20.6% | -9.1% | 1398.2s -> 1479.8s (+5.8%) | +| film B (2160p HDR) 1920x1024 | +70.4% | -2.2% | +70.3% | -2.1% | 1100.9s -> 1156.8s (+5.1%) | + +EVIDENCE: ~/.cache/l2/lg-control.log | server-1 gate, MemoryMax=5G, ffmpeg shim +PATH | film A +20.9%/-9.0%, film B +70.4%/-2.2% (== standing table to the +digit), LAST2 0.0% both films; test ok (exactness assertions held at every +clip x q x frame). Service runtime 52m07.6s. LOADAVG 0.52/0.45/0.23 before, +1.26/1.19/1.11 after. +EVIDENCE: ~/.cache/l2/lg-arm.log | server-1 gate, EC_AV1_LAST2=1 | +film A +20.6%/-9.1%, film B +70.3%/-2.1%; LAST2 1289 of 235454 (0.5%) film A, +2358 of 220341 (1.1%) film B. Service runtime 54m25.0s. LOADAVG +1.26/1.19/1.11 before, 1.06/1.11/1.09 after. + +### 3b. 12-frame native guard (all five rows) + +| row | off vs libaom | off vs rav1e | on vs libaom | on vs rav1e | wall ours off->on | +|---|---|---|---|---|---| +| bars 1080p | -3.3% | -19.0% | -3.4% | -19.0% | 423.1s -> 451.8s (+6.8%) | +| bars 2160p | +8.4% | -13.9% | +8.4% | -13.9% | 353.6s -> 388.0s (+9.7%) | +| film A | +17.9% | -6.3% | +17.7% | -6.5% | 370.0s -> 389.8s (+5.4%) | +| film B | +22.6% | -3.8% | +22.6% | -3.8% | 317.4s -> 332.1s (+4.6%) | +| screen capture | +13.7% | -33.6% | +13.7% | -33.6% | 235.7s -> 241.4s (+2.4%) | + +EVIDENCE: ~/.cache/l2/nat-control.log | server-1 gate, five rows | table above +"off" columns; four rows == the standing table to the digit, screen row == +the intertx-corrected standing number. Service runtime 34m31.7s. LOADAVG +1.06/1.11/1.09 before, 1.08/1.13/1.11 after. +EVIDENCE: ~/.cache/l2/nat-arm.log | server-1 gate, five rows, EC_AV1_LAST2=1 | +table above "on" columns; screen row byte-identical to control (LAST2 0 +coded there). Service runtime 36m20.9s. LOADAVG 1.08/1.13/1.11 before, +1.09/1.13/1.09 after. + +### LAST2 census share per clip (the arm runs' gate census) + +| clip | LAST2 / inter blocks | share | +|---|---|---| +| film A long-GOP (192 frames) | 1289 / 235454 | 0.5% | +| film B long-GOP (192 frames) | 2358 / 220341 | 1.1% | +| bars 1080p (48 frames) | 134 / 21474 | 0.6% | +| bars 2160p (48 frames) | 0 / 14557 | 0.0% | +| film A 12f (48 frames) | 330 / 53433 | 0.6% | +| film B 12f (48 frames) | 326 / 48822 | 0.7% | +| screen capture (48 frames) | 0 / 11162 | 0.0% | + +The lever FIRES on real film and is NOT a dead knob (the counter is read +once per clip by `take_ref_frame_hits` — no drain-then-read), it is simply +chosen by ~1 block in 150 on the long-GOP films, and the screen clip never +takes it. + +## 4. Keep rule — NOT met; disposition + +- One film row ≥0.5 BD down on a column: best delta anywhere is -0.3 (film A + long-GOP vs libaom; -0.2 on the 12-frame film A row). FAILS. +- Other film row flat within ±0.3: yes (-0.1/+0.1). +- Screen not worse by 0.3: yes (byte-identical, 0.0). +- Wall ≤+15%: yes (+2.4% to +9.7%). + +The deciding clause fails on the gate that decides — consistent with +lane-last2's 12-frame refutation at its older base, now confirmed on the +current substrate with the long-GOP table filled in. Default stays OFF; no +pin run, no three-lane suite (the default did not flip); the pins themselves +were re-verified green at the default locally, and the OFF path's bit-exactness +is additionally proven by the control reproducing the standing table to the +digit. `fix-now | deferred() | accepted`: nothing deferred — the +charter's measurement is complete; the arm stays parked behind `EC_AV1_LAST2` +(witnessed, census-visible). A future change that makes the older picture +worth MORE (e.g. a prediction lever that specifically prices lag-2 content) +re-runs the same four gates, not the census. + +## 5. Procedure notes (for the next lane on server-1) + +- A sequential multi-gate chain script on the server (one systemd-run unit per + gate, `--wait`, per-gate log files, LOADAVG before/after each unit echoed + into one chain log) keeps "one gate at a time" honest across a ~3 h batch + without a babysitting ssh session; the four gates cost 52m/54m/35m/36m. +- A control row may legitimately differ from the standing table where a + MERGED default changed it — diff the delta against the merge message's own + recorded number (here intertx's "+14.4 -> +13.7") before declaring + substrate suspicion. Reproduce-to-the-digit everywhere else is what makes + the one moving row attributable. +- `--ignored --exact` needs the full test path even for the diagnostic + censuses (`encode::tests::last2_census`, not `last2_census`). + +## 6. Non-goals respected + +Main checkout untouched, never pushed/merged, no repo-wide formatters (the +only source commit is a comment block, `git show eeae0580` is 12+/9-), media +files read-only, one gate at a time on server-1 (serial chain, LOADAVG pairs +recorded), logs under ~/.cache/l2/ and /home/user/gates/logs/.