report(av1): the LAST2 census and the frame interpolation filter tables
Browse files at this commit6a21052fe0587e75783f5db951994fafd4a2e04dParent: 56cd82e1 changed file +91 -61
- lanes/refs.report.md +91 -61
lanes/refs.report.mdmodified+91 -61
| @@ -2,38 +2,35 @@ | |||
| 2 | 2 | ||
| 3 | Worktree `edith_codecs-refs`, branch `lane-refs` off main 68e96c56. Every gate | 3 | Worktree `edith_codecs-refs`, branch `lane-refs` off main 68e96c56. Every gate |
| 4 | arm is the prebuilt release lib-test binary running `bd_rate_screen_native` | 4 | arm is the prebuilt release lib-test binary running `bd_rate_screen_native` |
| 5 | -(12 pictures, `gop 12`, four quantizers); each row is read off that log's own | 5 | +(12 pictures, `gop 12`, four quantizers, native `gate_crop` window); every row |
| 6 | -header line, one selector env var per arm (the 5-row gate does not fit a 900 s | 6 | +is read off that log's own header line, never off the argument order. |
| 7 | -timeout). | ||
| 8 | 7 | ||
| 9 | -## 0. The controls reproduce, to the digit | 8 | +## 0. The controls reproduce |
| 10 | 9 | ||
| 11 | -| clip | control vs libaom / vs rav1e | charter | | 10 | +| clip | control (vs libaom / vs rav1e) | charter | |
| 12 | |---|---|---| | 11 | |---|---|---| |
| 13 | | film A, 12 frames | +21.7 / -4.4 | +21.7 / -4.4 | | 12 | | film A, 12 frames | +21.7 / -4.4 | +21.7 / -4.4 | |
| 14 | | film B, 12 frames | +26.9 / -0.6 | +26.9 / -0.6 | | 13 | | film B, 12 frames | +26.9 / -0.6 | +26.9 / -0.6 | |
| 15 | | screen capture, 12 frames | +20.1 / -30.4 | +20.1 / -30.4 | | 14 | | screen capture, 12 frames | +20.1 / -30.4 | +20.1 / -30.4 | |
| 16 | 15 | ||
| 17 | -## 1. LAST2 — the census, taken BEFORE the slot bookkeeping | 16 | +All three land to the digit. |
| 17 | + | ||
| 18 | +## 1. LAST2 — the census, before the machinery | ||
| 18 | 19 | ||
| 19 | `encoder.rs`'s `ref_frame_idx` maps LAST2/LAST3 onto LAST's own DPB slot, so | 20 | `encoder.rs`'s `ref_frame_idx` maps LAST2/LAST3 onto LAST's own DPB slot, so |
| 20 | the picture before LAST is not merely unoffered to the search, it is not | 21 | the picture before LAST is not merely unoffered to the search, it is not |
| 21 | -retained. Building the real thing is not a small diff (a second retained | 22 | +retained at all. Building it out is not a small diff (a second retained slot |
| 22 | -slot at every level, `ref_frame_idx`/`refresh_frame_flags`, sign bias, order | 23 | +per level, `ref_frame_idx` / `refresh_frame_flags` / `ref_frame_sign_bias` / |
| 23 | -hints, `record_mi`, the motion field, the search offering LAST2 through the | 24 | +order hints for it, a per-reference mv stack, the writer's `single_ref` tree, |
| 24 | -per-reference mv stack, and a second MOTION SEARCH per block -- today even | 25 | +`record_mi`, and — the expensive part — a SECOND motion search per block, on |
| 25 | -GOLDEN and ALTREF are offered search-FREE, `search_inter_block`'s `extra` | 26 | +the stage that already owns most of the encode wall: `search_inter_block`'s |
| 26 | -prices only their NEARESTMV/GLOBALMV, precisely because a second search | 27 | +existing extra references are priced search-FREE for exactly that reason). |
| 27 | -doubles the stage that already owns most of the encode wall). | 28 | +So the lever was PRICED first (`last2_census`, `--ignored`, 3.3 s): |
| 28 | - | 29 | + |
| 29 | -So `last2_census` (`encode.rs`, `--ignored`) prices the lever first, on the | 30 | +every 16x16 luma block of the gate's own 12-picture window of both real films |
| 30 | -gate's OWN window and loader (`probe::gate_crop`, 12 pictures): every 16x16 | 31 | +gets one full-pel diamond search against the NEAR reference and the same |
| 31 | -luma block of every picture gets one full-pel diamond search against the NEAR | 32 | +search against the FAR one, at the two lags the pyramid offers — (1, 2) for |
| 32 | -reference and the same search against the FAR one, at the two lags the pyramid | 33 | +the leaf chain, (4, 8) for the ARF level, which is rav1e's own pair. |
| 33 | -offers -- (1, 2) for the leaf chain, (4, 8) for the ARF level (rav1e's own | ||
| 34 | -pair: its ARFs read LAST@-4 + LAST2@-8). | ||
| 35 | - | ||
| 36 | - cargo test -p ec-av1 --release --lib -- --ignored last2_census --nocapture | ||
| 37 | 34 | ||
| 38 | | clip | level (near/far lag) | blocks | far wins | far wins >10% | SAD near | SAD best-of | prediction energy removed | | 35 | | clip | level (near/far lag) | blocks | far wins | far wins >10% | SAD near | SAD best-of | prediction energy removed | |
| 39 | |---|---|---|---|---|---|---|---| | 36 | |---|---|---|---|---|---|---|---| |
| @@ -42,42 +39,75 @@ pair: its ARFs read LAST@-4 + LAST2@-8). | |||
| 42 | | film B | leaf (1/2) | 76800 | 38.1% | 21.2% | 18946199 | 17572121 | **7.25%** | | 39 | | film B | leaf (1/2) | 76800 | 38.1% | 21.2% | 18946199 | 17572121 | **7.25%** | |
| 43 | | film B | ARF (4/8) | 30720 | 44.3% | 22.5% | 8539904 | 7824079 | **8.38%** | | 40 | | film B | ARF (4/8) | 30720 | 44.3% | 22.5% | 8539904 | 7824079 | **8.38%** | |
| 44 | 41 | ||
| 45 | -READ IT HONESTLY: the last column is prediction ENERGY (SAD), not bytes. A | 42 | +READ IT AS: a second past reference is chosen by ~4 blocks in 10 and by more |
| 46 | -second reference wins about 4 blocks in 10 and wins by more than 10% on 1 in 5, | 43 | +than 10% of SAD by ~1 in 5; best-of-two removes 7-10% of the total residual |
| 47 | -and best-of-{LAST, LAST2} removes 7-10% of the frame's total absolute | 44 | +ENERGY before any rate is paid for naming the reference or for the second |
| 48 | -prediction error -- before any of it is paid back in the `single_ref` bits | 45 | +search. That is the largest un-taken prediction lever measured on this content |
| 49 | -that name the second reference, the mv bits its own stack costs, and the | 46 | +so far (the anchors' non-skip area is the standing film B gap), and the ARF |
| 50 | -second motion search's wall. 7-10% of SAD is the CEILING of the lever, and the | 47 | +level — where the census is strongest — is exactly the level libaom and rav1e |
| 51 | -ARF level (10.3% / 8.4%) is where it sits, not the leaf chain. | 48 | +spend their extra slots on. |
| 52 | - | 49 | + |
| 53 | -## 2. The frame interpolation filter | 50 | +**Decision: the lever is worth building, and it does not fit this lane.** The |
| 54 | - | 51 | +census is the charter's own first step ("before wiring the full search"), and |
| 55 | -Wired (this lane): `mc::predict` hardwired `InterpFilterKind::Regular`, so the | 52 | +the build is chartered as its own lane below. |
| 56 | -encoder could not have coded a non-REGULAR frame whatever its header said. | 53 | + |
| 57 | -The kernel now lives on `FrameCtx::interp_filter` (copied into every | 54 | +## 2. The frame interpolation filter — WIRED, MEASURED, REJECTED as a default |
| 58 | -tile-search worker by `filter_ctx_copy`), `encode_inter_frame` writes the SAME | 55 | + |
| 59 | -kernel into the frame header, and the search, the block trials, the compound | 56 | +The premise held: `mc::predict` hardwired `InterpFilterKind::Regular`, so the |
| 60 | -predictors and the trial decode all read it. `EC_AV1_INTERP=smooth|sharp` or | 57 | +encoder could not have coded a SMOOTH or SHARP frame whatever the header said. |
| 61 | -the process-global `set_frame_interp` select it; the default stays REGULAR and | 58 | +The kernel now travels on `FrameCtx::interp_filter` (copied into every |
| 62 | -byte-identical. | 59 | +tile-search worker by `filter_ctx_copy`, so a threaded search reads the same |
| 63 | - | 60 | +kernel), and `encode_inter_frame` writes that one kernel into the header — |
| 64 | -Witness (not ignored): | 61 | +one place, so header and prediction cannot disagree. `EC_AV1_INTERP= |
| 65 | -`each_frame_interpolation_filter_codes_its_own_stream_ffmpeg_decodes_exactly` | 62 | +smooth|sharp` (or `set_frame_interp`) selects it; the default is unchanged |
| 66 | --- the three kernels code three DIFFERENT streams (a filter that never reached | 63 | +REGULAR and byte-identical. |
| 67 | -the prediction would code REGULAR's bytes, class `symbol consumption gap`) and | 64 | + |
| 68 | -ffmpeg reconstructs every frame of each of them exactly. | 65 | +| arm | film A | film B | keep rule | |
| 69 | - | 66 | +|---|---|---|---| |
| 70 | -### SMOOTH on the 12-frame gate | 67 | +| REGULAR (control) | +21.7 / -4.4 | +26.9 / -0.6 | — | |
| 71 | - | 68 | +| SMOOTH | **+40.9 / +10.2** | +26.3 / -0.4 | film A loses 19.2 / 14.6 | |
| 72 | -| clip | control | EC_AV1_INTERP=smooth | | 69 | +| SHARP | +24.0 / -2.9 | +28.4 / +0.6 | both rows worse on both columns | |
| 73 | -|---|---|---| | 70 | + |
| 74 | -| film A | +21.7 / -4.4 | **+40.9 / +10.2** | | 71 | +SMOOTH is a catastrophe on film A (19 BD points) for 0.6 of a point on film B's |
| 75 | -| film B | +26.9 / -0.6 | **+26.3 / -0.4** | | 72 | +libaom column while its rav1e column goes 0.2 the wrong way; SHARP is worse |
| 76 | -| bars 1080p | -1.0 / -16.8 | -1.4 / -17.2 | | 73 | +everywhere. The keep rule (both films down on both columns) is nowhere near |
| 77 | -| bars 2160p | +9.4 / -12.7 | +9.3 / -12.9 | | 74 | +met, so **REGULAR stays the default at every preset** and the per-frame |
| 78 | - | 75 | +CHOOSER was not built: its ceiling is film B's +0.6/-0.2 mixed-sign move, and |
| 79 | -Film B and both bars rows improve; film A loses NINETEEN BD points (0.2 dB at | 76 | +its downside when a proxy mispicks is film A's 19 points (ladder rung 1 — it |
| 80 | -every quantizer). The two real films disagree in sign, so SMOOTH is not a | 77 | +does not need to exist). The wiring stays because it is what makes the |
| 81 | -default -- the keep rule ("both film rows improve") is unmet by a wide margin. | 78 | +measurement possible at all and because it removes the hardwired-kernel |
| 82 | - | 79 | +ceiling; it is proved by a witness rather than left as a claim. |
| 83 | -(SHARP arms pending.) | 80 | + |
| 81 | +## 3. Invariants | ||
| 82 | + | ||
| 83 | +* `each_frame_interpolation_filter_codes_its_own_stream_ffmpeg_decodes_exactly` | ||
| 84 | + (new, NOT ignored): each of the three kernels codes a DISTINCT stream (a | ||
| 85 | + kernel that never reached the prediction would code REGULAR's bytes — class | ||
| 86 | + `symbol consumption gap`) and ffmpeg reconstructs every frame of each of them | ||
| 87 | + exactly against our own reconstruction. Green. | ||
| 88 | +* `cargo test -p ec-av1 --release --lib`: see §4. | ||
| 89 | +* `cargo check --workspace --all-targets`: see §4. | ||
| 90 | + | ||
| 91 | +## 4. Suite and check | ||
| 92 | + | ||
| 93 | +(filled in below from the detached runs) | ||
| 94 | + | ||
| 95 | +## 5. Deferred | ||
| 96 | + | ||
| 97 | +* **LAST2 / a real second past reference — deferred, chartered.** What it | ||
| 98 | + needs: DPB slot 7 is free (the key's copy, never read back), so the leaf | ||
| 99 | + chain can alternate its refresh between slots 0 and 7 and name the older of | ||
| 100 | + the two as LAST2 while the ARF levels take theirs from the anchor pair; | ||
| 101 | + `ref_frame_idx[1]`, `refresh_frame_flags`, `ref_frame_sign_bias`, the order | ||
| 102 | + hints and a per-reference mv stack follow; the cheapest first arm offers | ||
| 103 | + LAST2 through the EXISTING search-free `extra` path (NEARESTMV/GLOBALMV | ||
| 104 | + only, as GOLDEN is offered today) so the second motion search — and its wall, | ||
| 105 | + which is the user's stated priority — is a second arm, not a prerequisite. | ||
| 106 | + Witness: a clip where the picture before LAST is the better reference, N | ||
| 107 | + blocks coded off LAST2, exact through ffmpeg and `decode_stream`, hidden | ||
| 108 | + frame display order intact. Unblocked by: a lane of its own with the wall | ||
| 109 | + budget for the desync hunt. | ||
| 110 | +* **The per-frame interpolation-filter chooser — dropped, not deferred**: §2's | ||
| 111 | + table is its refutation, not a gap. | ||
| 112 | +* The long-GOP gate was not run: nothing from this lane changes a default, so | ||
| 113 | + there is nothing for it to confirm. | ||