diff --git a/crates/ec-av1/src/encoder.rs b/crates/ec-av1/src/encoder.rs index 59921b19..d23a4360 100644 --- a/crates/ec-av1/src/encoder.rs +++ b/crates/ec-av1/src/encoder.rs @@ -1298,6 +1298,31 @@ pub(crate) fn tpl_fut() -> usize { .unwrap_or_else(|| crate::speed::at(&crate::speed::TPL_FUT)) } +/// lane-tplhalf: mode 2's split -- how many display-PAST neighbours the top +/// ARF's window opens with, the rest of the budget coming from the buffered +/// future ([`crate::speed::TPL_FUT_HALF`], `EC_AV1_TPL_FUT_HALF=`). +pub(crate) fn tpl_fut_half() -> usize { + std::env::var("EC_AV1_TPL_FUT_HALF") + .ok() + .and_then(|v| v.parse().ok()) + .unwrap_or_else(|| crate::speed::at(&crate::speed::TPL_FUT_HALF)) +} + +/// lane-tplhalf: how many entries mode 2's window holds in total, `0` meaning +/// `tpl_depth() - 1` -- the ARF window's budget alone, so raising it does not +/// deepen every other frame's lambda pass the way `EC_AV1_TPL_D` does +/// ([`crate::speed::TPL_FUT_WIN`], `EC_AV1_TPL_FUT_WIN=`). +pub(crate) fn tpl_fut_win(depth: usize) -> usize { + match std::env::var("EC_AV1_TPL_FUT_WIN") + .ok() + .and_then(|v| v.parse().ok()) + .unwrap_or_else(|| crate::speed::at(&crate::speed::TPL_FUT_WIN)) + { + 0 => depth - 1, + n => n, + } +} + /// lane-lookahead: whether the pyramid path holds one group of lookahead /// ([`crate::speed::LOOKAHEAD`], `EC_AV1_LOOKAHEAD=0|1`). fn lookahead() -> bool { @@ -2253,10 +2278,10 @@ impl Av1Encoder { // the nearest past and the nearest future neighbour spans the // whole group), which is the arm's known cost. (2, _, _) => { - let half = std::env::var("EC_AV1_TPL_FUT_HALF").ok().and_then(|v| v.parse().ok()).unwrap_or((depth - 1) / 2); + let budget = tpl_fut_win(depth); let mut w = past(); - w.truncate(half.max(1)); - let room = (depth - 1).saturating_sub(w.len()); + w.truncate(tpl_fut_half().max(1)); + let room = budget.saturating_sub(w.len()); w.extend(arf_tpl_future(room)); w } diff --git a/crates/ec-av1/src/speed.rs b/crates/ec-av1/src/speed.rs index 511ea7d0..b4bf6f68 100644 --- a/crates/ec-av1/src/speed.rs +++ b/crates/ec-av1/src/speed.rs @@ -180,7 +180,6 @@ //! preset 3 BELOW preset 0 in every pass at load 16-25. The single-thread fps //! column above comes from the BD arms themselves and is ordered correctly. - use std::sync::atomic::{AtomicU8, Ordering}; /// The highest preset. 10 is the fastest, as in rav1e. @@ -515,6 +514,46 @@ pub(crate) const LOOKAHEAD: bool = true; /// +-0.3) at +3.2% / +0.2% wall. pub(crate) const TPL_FUT: [usize; 11] = [2; 11]; +/// lane-tplhalf: mode 2's SPLIT -- how many display-PAST neighbours the top +/// ARF's window opens with; the rest of [`TPL_FUT_WIN`] comes from the +/// buffered future. `EC_AV1_TPL_FUT_HALF=` overrides it, and the value is +/// clamped up to 1 (a zero past half is mode 1, refuted). +/// +/// Swept on the 48-picture long-GOP gate at `TPL_DEPTH = 8` (budget 7), +/// BD-rate vs libaom / vs rav1e, lower better: +/// +/// | past half | film A | film B | wall A | wall B | +/// |---|---|---|---|---| +/// | 1 (6 future) | +21.1/-8.9 | +71.2/-1.9 | 548.5s | 429.1s | +/// | **2 (5 future, ships)** | **+20.9/-9.0** | **+71.0/-1.8** | 551.3s | 442.3s | +/// | 3 (4 future, the old default) | +21.1/-8.9 | +71.5/-1.5 | 547.0s | 423.0s | +/// | 5 (2 future) | +21.1/-8.9 | +71.5/-1.6 | 561.8s | 438.6s | +/// +/// Bracketed on both sides: 2 is down on all four columns against 3, and 1 +/// and 5 are both worse than it. Presets 3..6 run `TPL_DEPTH = 4`, where the +/// old `(depth-1)/2` split was 1 -- left there, unswept. +pub(crate) const TPL_FUT_HALF: [usize; 11] = [2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1]; + +/// lane-tplhalf: how many entries mode 2's window holds in TOTAL, `0` meaning +/// `encode::tpl_depth() - 1` (the budget every other tpl path uses). +/// `EC_AV1_TPL_FUT_WIN=` overrides it. The winning split takes its whole +/// future side from the budget's edge, so the budget was swept apart from +/// it (class `instrument at bound`) and apart from `EC_AV1_TPL_D`, which +/// deepens EVERY frame's lambda pass. 48-picture long-GOP, half=2: +/// +/// | window | film A | film B | +/// |---|---|---| +/// | 7 (`tpl_depth-1`, the split's own arm) | +20.9/-9.0 | +71.0/-1.8 | +/// | 9 | +21.0/-9.0 | +70.7/-2.0 | +/// | **11 (ships at presets 0..=2)** | **+20.9/-9.0** | **+70.4/-2.2** | +/// +/// 11 is film B -0.6/-0.4 against 7 with film A flat -- the keep rule -- and +/// saturates the one-group lookahead (2 past + 8 future available). Presets +/// 3..=6 keep 0 (`depth-1` = 3 at `TPL_DEPTH=4`), unswept. `TPL_D=10` at +/// half=2 was byte-identical to WIN=9: extra depth on non-ARF frames is +/// unused because a pyramid leaf's window is the group's own successors. +pub(crate) const TPL_FUT_WIN: [usize; 11] = [11, 11, 11, 0, 0, 0, 0, 0, 0, 0, 0]; + /// lane-arfpred: the qindex below which the ARF temporal filter is OFF -- /// libaom scales `arnr` strength with the quantizer and stops filtering at /// the high-quality end for the same reason: a picture we are about to @@ -805,8 +844,7 @@ pub(crate) const RESTORATION: [bool; 11] = [ /// (`presets_are_monotone_in_speed`) forbids them going below preset 3's 4 /// in any case. /// * **presets 7..10 stay at 1**, unmeasured: not swept by this lane. -pub(crate) const TPL_DEPTH: [usize; 11] = - [crate::encode::TPL_DEPTH, 8, 8, 4, 4, 4, 4, 1, 1, 1, 1]; +pub(crate) const TPL_DEPTH: [usize; 11] = [crate::encode::TPL_DEPTH, 8, 8, 4, 4, 4, 4, 1, 1, 1, 1]; /// `encode::tx_type_search`: whether an intra luma transform unit searches /// its own `tx_type` instead of coding `DCT_DCT` (lane-txset). The five-type @@ -988,12 +1026,16 @@ static KNOBS: std::sync::RwLock<()> = std::sync::RwLock::new(()); #[cfg(test)] #[must_use] pub(crate) fn knob_read() -> std::sync::RwLockReadGuard<'static, ()> { - KNOBS.read().unwrap_or_else(std::sync::PoisonError::into_inner) + KNOBS + .read() + .unwrap_or_else(std::sync::PoisonError::into_inner) } /// Held by a test that SETS a process-global knob; see [`KNOBS`]. #[cfg(test)] #[must_use] pub(crate) fn knob_write() -> std::sync::RwLockWriteGuard<'static, ()> { - KNOBS.write().unwrap_or_else(std::sync::PoisonError::into_inner) + KNOBS + .write() + .unwrap_or_else(std::sync::PoisonError::into_inner) } diff --git a/lanes/tplhalf.report.md b/lanes/tplhalf.report.md new file mode 100644 index 00000000..2840500c --- /dev/null +++ b/lanes/tplhalf.report.md @@ -0,0 +1,87 @@ +# lane-tplhalf: the top ARF's tpl split, then its budget + +Claude Code died mid-lane after the split commit (`0c8d5778`) and after +the WIN sweep logs landed; this report closes that lane. + +## 1. Premise + +`TPL_FUT=2` (lane-tplfut) concatenates past then future, nearest-first. +The split was `(tpl_depth()-1)/2` = 3 past + 4 future at depth 8, unswept. +The future half is taken from the budget's edge, so the budget itself had +to be swept apart from `EC_AV1_TPL_D` (which deepens every frame's lambda +pass, not the ARF window). Class: instrument-at-bound. + +## 2. Split sweep (`EC_AV1_TPL_FUT_HALF`) + +Deciding gate: `encode::tests::bd_rate_film_long_gop` (48 pictures), one +thread, native crops. BD vs libaom cpu-used 6 / rav1e speed 6, lower +better. Logs: `~/.cache/tplhalf/{control,h1,h2,h5}.log`. Load before each +arm 2.8-4.7, after 2.9-4.4. + +| past half | film A | film B | wall A | wall B | log | +|---|---|---|---|---|---| +| 1 (6 future) | +21.1 / -8.9 | +71.2 / -1.9 | 548.5s | 429.1s | h1.log | +| **2 (5 future, SHIPS)** | **+20.9 / -9.0** | **+71.0 / -1.8** | 551.3s | 442.3s | h2.log | +| 3 (4 future, old default) | +21.1 / -8.9 | +71.5 / -1.5 | 547.0s | 423.0s | control.log | +| 5 (2 future) | +21.1 / -8.9 | +71.5 / -1.6 | 561.8s | 438.6s | h5.log | + +Bracketed: 2 is down on all four columns against 3 (film A -0.2/-0.1, +film B -0.5/-0.3), and 1 and 5 are both worse than it on the deciding +film B libaom column. Wall of 2 is +0.8% / +4.6% vs 3, under the +15% +ceiling. `speed::TPL_FUT_HALF` = 2 at presets 0..=2; presets 3..=6 keep 1 +(`TPL_DEPTH=4`, unswept). + +## 3. Budget sweep (`EC_AV1_TPL_FUT_WIN`) at half=2 + +Same gate. `0` means `tpl_depth()-1` = 7. Logs: `h2.log`, `w9.log`, +`w11.log`, `h2d10.log`, `w11h3.log`. + +| window | film A | film B | wall A | wall B | log | +|---|---|---|---|---|---| +| 7 (`depth-1`) | +20.9 / -9.0 | +71.0 / -1.8 | 551.3s | 442.3s | h2.log | +| 9 | +21.0 / -9.0 | +70.7 / -2.0 | 545.3s | 430.2s | w9.log | +| **11 (SHIPS at presets 0..=2)** | **+20.9 / -9.0** | **+70.4 / -2.2** | 578.6s | 431.3s | w11.log | +| 11, half=3 (split re-check) | +20.9 / -9.0 | +70.9 / -1.9 | 554.8s | 437.7s | w11h3.log | +| `TPL_D=10` at half=2 | +21.0 / -9.0 | +70.7 / -2.0 | 543.7s | 435.8s | h2d10.log | + +11 vs 7: film B -0.6 / -0.4, film A 0.0 / 0.0 -- keep rule (one row +>=0.5 down, the other flat). Wall A +5.0%, wall B -2.5%. 11 saturates +the one-group lookahead (2 past + 8 future available). Half=3 at the +larger budget loses to half=2, so the split does not flip. + +`TPL_D=10` at half=2 is byte-identical to WIN=9 (same PSNR/bytes on both +films): extra depth on non-ARF frames is unused because a pyramid leaf's +window is the group's own successors. That is why WIN is its own knob. + +`speed::TPL_FUT_WIN` = 11 at presets 0..=2; presets 3..=6 keep 0 +(`depth-1` = 3 at `TPL_DEPTH=4`), unswept. + +## 4. 12-picture native guard + +STRUCTURALLY BLIND: `group_target` absorbs a 12-picture tail into one +group, so no next group is buffered and mode 2 falls back to the past +window. Not re-run; the standing table's 12-frame rows are the guard. + +## 5. Witness + +`encoder::tests::the_future_tpl_window_still_codes_every_picture_and_moves_the_stream` +already names that mode 2 at the old 3-past split is byte-identical on +the 128x128 fixture and that `EC_AV1_TPL_FUT_HALF=1` moves it. No new +witness: the long-GOP gate is the measurement. + +## 6. Other gates + +Recorded at merge time (this file's suite line). Pins are expected +unmoved: the 4-picture pin fixture has no next group, so the fallback +keeps the past window. + +## Deviations + +* Claude subscription died after the split commit and after the WIN + logs; this close is from those logs plus the WIN default they keep. +* Presets 3..=6 split and budget left unswept (named in the tables). +* 12-frame rows not re-measured (structurally blind, accepted). + +## Suite line + +Pending merge gates on this close.