forge
Explore
Log in

Don't you dare go Hollow

A speed preset axis (0..=10), preset 0 the search we ship

Browse files at this commit

597c1a3db7040a08bd93ca2c9a2ab06972322786Ahmet Kaan GümüşParent: 9b5376d
  • feat
    • a speed preset axis (0..=10), preset 0 the search we ship
Show full message
feat(av1): a speed preset axis (0..=10), preset 0 the search we ship

Every search lever this crate already has an EC_AV1_* knob for reads its
default from a per-speed table in the new `speed` module, indexed by one
process-global preset (`Av1Encoder::with_speed`, `EC_AV1_SPEED`). Index 0
of every table IS the shipped constant, so preset 0 is byte-identical by
construction; `speed::levers` names what each preset switches off, and
ec-bench codes one row per preset {0,3,6,10}.
crates/ec-av1/src/encode.rsmodified+63 -63
@@ -206,7 +206,7 @@ pub(crate) fn take_predicted_bits() -> Vec<f64> {
206 }206 }
207 207
208 /// Whether a 16x16 inter leaf may split into four 8x8 ones of its own.208 /// Whether a 16x16 inter leaf may split into four 8x8 ones of its own.
209-const SPLIT_INTER_8: bool = true;209+pub(crate) const SPLIT_INTER_8: bool = true;
210 210
211 /// [`SPLIT_INTER_8`], or what `EC_AV1_SPLIT_INTER8` names in a test build.211 /// [`SPLIT_INTER_8`], or what `EC_AV1_SPLIT_INTER8` names in a test build.
212 /// Whether a key frame codes `tx_mode == TxMode::Select` and searches each212 /// Whether a key frame codes `tx_mode == TxMode::Select` and searches each
@@ -223,41 +223,39 @@ const SPLIT_INTER_8: bool = true;
223 /// third, for 13% encode wall. `EC_AV1_TX_SELECT_INTER=0` turns it off for an223 /// third, for 13% encode wall. `EC_AV1_TX_SELECT_INTER=0` turns it off for an
224 /// A/B on one build.224 /// A/B on one build.
225 fn tx_select_inter() -> bool {225 fn tx_select_inter() -> bool {
226- static ON: std::sync::OnceLock<bool> = std::sync::OnceLock::new();226+ static ENV: std::sync::LazyLock<Option<bool>> = std::sync::LazyLock::new(|| {
227- *ON.get_or_init(|| {227+ crate::envflags::var("EC_AV1_TX_SELECT_INTER")
228- !matches!(228+ .ok()
229- std::env::var("EC_AV1_TX_SELECT_INTER").as_deref(),229+ .map(|v| !matches!(v.as_str(), "0" | "off"))
230- Ok("0") | Ok("off")230+ });
231- )231+ ENV.unwrap_or_else(|| crate::speed::at(&crate::speed::TX_SELECT_INTER))
232- })
233 }232 }
234 233
235 fn tx_select() -> bool {234 fn tx_select() -> bool {
236- static ON: std::sync::OnceLock<bool> = std::sync::OnceLock::new();235+ static ENV: std::sync::LazyLock<Option<bool>> = std::sync::LazyLock::new(|| {
237- *ON.get_or_init(|| {236+ crate::envflags::var("EC_AV1_TX_SELECT")
238- !matches!(237+ .ok()
239- std::env::var("EC_AV1_TX_SELECT").as_deref(),238+ .map(|v| !matches!(v.as_str(), "0" | "off"))
240- Ok("0") | Ok("off")239+ });
241- )240+ ENV.unwrap_or_else(|| crate::speed::at(&crate::speed::TX_SELECT_KEY))
242- })
243 }241 }
244 242
245 fn split_inter_8() -> bool {243 fn split_inter_8() -> bool {
246 match std::env::var("EC_AV1_SPLIT_INTER8").ok() {244 match std::env::var("EC_AV1_SPLIT_INTER8").ok() {
247 Some(v) if cfg!(test) => v != "0",245 Some(v) if cfg!(test) => v != "0",
248- _ => SPLIT_INTER_8,246+ _ => crate::speed::at(&crate::speed::SPLIT_8),
249 }247 }
250 }248 }
251 249
252 /// Whether a 16x16 (or 8x8) leaf runs a motion search of its own beside the250 /// Whether a 16x16 (or 8x8) leaf runs a motion search of its own beside the
253 /// NEARESTMV candidate it always had.251 /// NEARESTMV candidate it always had.
254-const LEAF_NEW_MV: bool = true;252+pub(crate) const LEAF_NEW_MV: bool = true;
255 253
256 /// Whether GOLDEN/ALTREF get a `NEWMV` search of their own. Measured on the254 /// Whether GOLDEN/ALTREF get a `NEWMV` search of their own. Measured on the
257 /// BD gate: with the early-out below at its swept margin, -1.7/-2.5/-0.0255 /// BD gate: with the early-out below at its swept margin, -1.7/-2.5/-0.0
258 /// points vs libaom and -1.6/-2.3/-0.0 vs rav1e for 4%/4%/0.3% more motion256 /// points vs libaom and -1.6/-2.3/-0.0 vs rav1e for 4%/4%/0.3% more motion
259 /// searches (the census `bd_rate_vs_libaom_and_rav1e` prints).257 /// searches (the census `bd_rate_vs_libaom_and_rav1e` prints).
260-const EXTRA_REF_NEW_MV: bool = true;258+pub(crate) const EXTRA_REF_NEW_MV: bool = true;
261 259
262 /// How much cheaper an extra reference's `NEARESTMV` has to be than LAST's260 /// How much cheaper an extra reference's `NEARESTMV` has to be than LAST's
263 /// own best vector before that reference's `NEWMV` search is skipped: a261 /// own best vector before that reference's `NEWMV` search is skipped: a
@@ -334,7 +332,7 @@ fn leaf_second_new_margin() -> f64 {
334 fn leaf_second_new_mv() -> bool {332 fn leaf_second_new_mv() -> bool {
335 match std::env::var("EC_AV1_LEAF_SECOND_NEWMV").ok() {333 match std::env::var("EC_AV1_LEAF_SECOND_NEWMV").ok() {
336 Some(v) => v != "0",334 Some(v) => v != "0",
337- None => true,335+ None => crate::speed::at(&crate::speed::LEAF_SECOND),
338 }336 }
339 }337 }
340 338
@@ -343,13 +341,13 @@ fn leaf_second_new_mv() -> bool {
343 /// block at any leaf size (`tile::write_inter_frame_leaf`/`..._leaf8` both341 /// block at any leaf size (`tile::write_inter_frame_leaf`/`..._leaf8` both
344 /// route through `write_compound_block`, which is sized by `bw4`/`bh4`); what342 /// route through `write_compound_block`, which is sized by `bw4`/`bh4`); what
345 /// was missing was the encoder ever forming one below 32x32.343 /// was missing was the encoder ever forming one below 32x32.
346-const LEAF_COMPOUND: bool = true;344+pub(crate) const LEAF_COMPOUND: bool = true;
347 345
348 /// [`LEAF_COMPOUND`], or what `EC_AV1_LEAF_COMPOUND` names in any build.346 /// [`LEAF_COMPOUND`], or what `EC_AV1_LEAF_COMPOUND` names in any build.
349 fn leaf_compound() -> bool {347 fn leaf_compound() -> bool {
350 match std::env::var("EC_AV1_LEAF_COMPOUND").ok() {348 match std::env::var("EC_AV1_LEAF_COMPOUND").ok() {
351 Some(v) => v != "0",349 Some(v) => v != "0",
352- None => LEAF_COMPOUND,350+ None => crate::speed::at(&crate::speed::LEAF_COMPOUND),
353 }351 }
354 }352 }
355 353
@@ -366,7 +364,7 @@ fn leaf_new_mv() -> bool {
366 /// the true frame edge cut through was ever split there; inside the frame364 /// the true frame edge cut through was ever split there; inside the frame
367 /// every block was coded whole, which left the partition decision the key365 /// every block was coded whole, which left the partition decision the key
368 /// frame already makes unmade for eleven frames out of twelve.366 /// frame already makes unmade for eleven frames out of twelve.
369-const SPLIT_INTER_BLOCKS: bool = true;367+pub(crate) const SPLIT_INTER_BLOCKS: bool = true;
370 368
371 /// [`SPLIT_INTER_BLOCKS`], or what `EC_AV1_SPLIT_INTER` names when the369 /// [`SPLIT_INTER_BLOCKS`], or what `EC_AV1_SPLIT_INTER` names when the
372 /// measurement that keeps it is running (test builds only, like370 /// measurement that keeps it is running (test builds only, like
@@ -374,7 +372,7 @@ const SPLIT_INTER_BLOCKS: bool = true;
374 fn split_inter_blocks() -> bool {372 fn split_inter_blocks() -> bool {
375 match std::env::var("EC_AV1_SPLIT_INTER").ok() {373 match std::env::var("EC_AV1_SPLIT_INTER").ok() {
376 Some(v) if cfg!(test) => v != "0",374 Some(v) if cfg!(test) => v != "0",
377- _ => SPLIT_INTER_BLOCKS,375+ _ => crate::speed::at(&crate::speed::SPLIT_INTER),
378 }376 }
379 }377 }
380 378
@@ -382,13 +380,13 @@ fn split_inter_blocks() -> bool {
382 /// Wiener filter per 64x64 luma restoration unit, picked from380 /// Wiener filter per 64x64 luma restoration unit, picked from
383 /// [`crate::filter_search::WIENER_CANDIDATES`]. Swept by `EC_AV1_LR` in a381 /// [`crate::filter_search::WIENER_CANDIDATES`]. Swept by `EC_AV1_LR` in a
384 /// test build, like [`lambda_scale`].382 /// test build, like [`lambda_scale`].
385-const RESTORATION: bool = true;383+pub(crate) const RESTORATION: bool = true;
386 384
387 /// [`RESTORATION`], or what `EC_AV1_LR` names in a test build.385 /// [`RESTORATION`], or what `EC_AV1_LR` names in a test build.
388 fn restoration_enabled() -> bool {386 fn restoration_enabled() -> bool {
389 match std::env::var("EC_AV1_LR").ok() {387 match std::env::var("EC_AV1_LR").ok() {
390 Some(v) if cfg!(test) => v != "0",388 Some(v) if cfg!(test) => v != "0",
391- _ => RESTORATION,389+ _ => crate::speed::at(&crate::speed::RESTORATION),
392 }390 }
393 }391 }
394 392
@@ -405,7 +403,7 @@ fn restoration_enabled() -> bool {
405 /// +31.7/+40.6/+27.8, for barely more speed. The split trial is where this403 /// +31.7/+40.6/+27.8, for barely more speed. The split trial is where this
406 /// encoder's inter quality lives, so `0` ships and the knob stays for a404 /// encoder's inter quality lives, so `0` ships and the knob stays for a
407 /// future explicit speed preset.405 /// future explicit speed preset.
408-const SPLIT_BREAKOUT_COEFFS: usize = 0;406+pub(crate) const SPLIT_BREAKOUT_COEFFS: usize = 0;
409 407
410 /// libaom's `partition_search_breakout_rate_thr` shape, in this encoder's own408 /// libaom's `partition_search_breakout_rate_thr` shape, in this encoder's own
411 /// currency: a 32x32 inter block whose whole-block RD cost per pixel comes409 /// currency: a 32x32 inter block whose whole-block RD cost per pixel comes
@@ -431,17 +429,14 @@ const SPLIT_BREAKOUT_COEFFS: usize = 0;
431 /// +51.3/-14.2 (the 1080p film 0.2 worse for a finer search) and 0.25 is429 /// +51.3/-14.2 (the 1080p film 0.2 worse for a finer search) and 0.25 is
432 /// +16.6/-0.6, +46.9/+19.1, +51.6/-14.5 (screen 0.3 worse vs libaom, 3s off430 /// +16.6/-0.6, +46.9/+19.1, +51.6/-14.5 (screen 0.3 worse vs libaom, 3s off
433 /// the screen wall). Neither clears the keep rule; 0.125 stays.431 /// the screen wall). Neither clears the keep rule; 0.125 stays.
434-const SPLIT_RD_THRESHOLD: f64 = 0.125;432+pub(crate) const SPLIT_RD_THRESHOLD: f64 = 0.125;
435 433
436 /// [`SPLIT_RD_THRESHOLD`], swept by `EC_AV1_SPLIT_RD` in any build.434 /// [`SPLIT_RD_THRESHOLD`], swept by `EC_AV1_SPLIT_RD` in any build.
437 fn split_rd_threshold() -> f64 {435 fn split_rd_threshold() -> f64 {
438- static T: std::sync::OnceLock<f64> = std::sync::OnceLock::new();436+ static ENV: std::sync::LazyLock<Option<f64>> = std::sync::LazyLock::new(|| {
439- *T.get_or_init(|| {437+ crate::envflags::var("EC_AV1_SPLIT_RD").ok().and_then(|v| v.parse().ok())
440- std::env::var("EC_AV1_SPLIT_RD")438+ });
441- .ok()439+ ENV.unwrap_or_else(|| crate::speed::at(&crate::speed::SPLIT_RD))
442- .and_then(|v| v.parse().ok())
443- .unwrap_or(SPLIT_RD_THRESHOLD)
444- })
445 }440 }
446 441
447 /// Whether `cost` over a `side` x `side` block is cheap enough per pixel that442 /// Whether `cost` over a `side` x `side` block is cheap enough per pixel that
@@ -456,7 +451,7 @@ fn split_rd_breakout(cost: f64, side: usize, lambda: f64) -> bool {
456 fn split_breakout_coeffs() -> usize {451 fn split_breakout_coeffs() -> usize {
457 match std::env::var("EC_AV1_SPLIT_BREAKOUT").ok() {452 match std::env::var("EC_AV1_SPLIT_BREAKOUT").ok() {
458 Some(v) if cfg!(test) => v.parse().unwrap_or(SPLIT_BREAKOUT_COEFFS),453 Some(v) if cfg!(test) => v.parse().unwrap_or(SPLIT_BREAKOUT_COEFFS),
459- _ => SPLIT_BREAKOUT_COEFFS,454+ _ => crate::speed::at(&crate::speed::SPLIT_BREAKOUT),
460 }455 }
461 }456 }
462 457
@@ -2811,10 +2806,10 @@ impl Reach {
2811 /// [`warp_prediction`]); `EC_AV1_WARP=0` turns the tool -- and the two header2806 /// [`warp_prediction`]); `EC_AV1_WARP=0` turns the tool -- and the two header
2812 /// bits -- back off for an A/B on one build.2807 /// bits -- back off for an A/B on one build.
2813 pub(crate) fn warp_on() -> bool {2808 pub(crate) fn warp_on() -> bool {
2814- static ON: std::sync::LazyLock<bool> = std::sync::LazyLock::new(|| {2809+ static ENV: std::sync::LazyLock<Option<bool>> = std::sync::LazyLock::new(|| {
2815- !matches!(crate::envflags::var("EC_AV1_WARP").as_deref(), Ok("0") | Ok("off"))2810+ crate::envflags::var("EC_AV1_WARP").ok().map(|v| !matches!(v.as_str(), "0" | "off"))
2816 });2811 });
2817- *ON2812+ ENV.unwrap_or_else(|| crate::speed::at(&crate::speed::WARP))
2818 }2813 }
2819 2814
2820 /// The smallest LEAF an OBMC candidate is offered for, so the census can2815 /// The smallest LEAF an OBMC candidate is offered for, so the census can
@@ -3124,10 +3119,10 @@ static INTER_TX_SPLIT_HITS: [std::sync::atomic::AtomicUsize; 8] =
3124 /// residual to reach there -- the tool was being judged on content that3119 /// residual to reach there -- the tool was being judged on content that
3125 /// cannot pay for it (class `gate-blind-to-feature`). `EC_AV1_TX32_DEPTH`.3120 /// cannot pay for it (class `gate-blind-to-feature`). `EC_AV1_TX32_DEPTH`.
3126 fn tx32_depth_search() -> bool {3121 fn tx32_depth_search() -> bool {
3127- static ON: std::sync::LazyLock<bool> = std::sync::LazyLock::new(|| {3122+ static ENV: std::sync::LazyLock<Option<bool>> = std::sync::LazyLock::new(|| {
3128- !matches!(crate::envflags::var("EC_AV1_TX32_DEPTH").as_deref(), Ok("0") | Ok("off"))3123+ crate::envflags::var("EC_AV1_TX32_DEPTH").ok().map(|v| !matches!(v.as_str(), "0" | "off"))
3129 });3124 });
3130- *ON3125+ ENV.unwrap_or_else(|| crate::speed::at(&crate::speed::TX32_DEPTH))
3131 }3126 }
3132 3127
3133 /// Whether a COMPOUND inter winner is offered the var-tx split at all: its3128 /// Whether a COMPOUND inter winner is offered the var-tx split at all: its
@@ -3139,10 +3134,10 @@ fn tx32_depth_search() -> bool {
3139 /// 32x32 depth search); `EC_AV1_COMP_VARTX=0` turns it off.3134 /// 32x32 depth search); `EC_AV1_COMP_VARTX=0` turns it off.
3140 /// `EC_AV1_COMP_VARTX`.3135 /// `EC_AV1_COMP_VARTX`.
3141 fn compound_var_tx() -> bool {3136 fn compound_var_tx() -> bool {
3142- static ON: std::sync::LazyLock<bool> = std::sync::LazyLock::new(|| {3137+ static ENV: std::sync::LazyLock<Option<bool>> = std::sync::LazyLock::new(|| {
3143- !matches!(crate::envflags::var("EC_AV1_COMP_VARTX").as_deref(), Ok("0") | Ok("off"))3138+ crate::envflags::var("EC_AV1_COMP_VARTX").ok().map(|v| !matches!(v.as_str(), "0" | "off"))
3144 });3139 });
3145- *ON3140+ ENV.unwrap_or_else(|| crate::speed::at(&crate::speed::COMPOUND_VAR_TX))
3146 }3141 }
3147 3142
3148 /// How many 32x32-and-below inter blocks each reference frame won, indexed by3143 /// How many 32x32-and-below inter blocks each reference frame won, indexed by
@@ -4098,15 +4093,19 @@ pub(crate) fn take_angle_delta_hits() -> [usize; 7] {
4098 /// Whether the luma search refines a directional winner's `angle_delta_y`4093 /// Whether the luma search refines a directional winner's `angle_delta_y`
4099 /// (`EC_AV1_ANGLE=0` switches it off, the lane's own on/off pair).4094 /// (`EC_AV1_ANGLE=0` switches it off, the lane's own on/off pair).
4100 fn angle_delta_on() -> bool {4095 fn angle_delta_on() -> bool {
4101- static ON: std::sync::OnceLock<bool> = std::sync::OnceLock::new();4096+ static ENV: std::sync::LazyLock<Option<bool>> = std::sync::LazyLock::new(|| {
4102- *ON.get_or_init(|| std::env::var("EC_AV1_ANGLE").as_deref() != Ok("0"))4097+ crate::envflags::var("EC_AV1_ANGLE").ok().map(|v| v != "0")
4098+ });
4099+ ENV.unwrap_or_else(|| crate::speed::at(&crate::speed::ANGLE))
4103 }4100 }
4104 4101
4105 /// Whether the chroma search offers `UV_CFL_PRED` at all (`EC_AV1_CFL=0`4102 /// Whether the chroma search offers `UV_CFL_PRED` at all (`EC_AV1_CFL=0`
4106 /// switches it off, which is how the lane measured its own on/off pair).4103 /// switches it off, which is how the lane measured its own on/off pair).
4107 fn cfl_on() -> bool {4104 fn cfl_on() -> bool {
4108- static ON: std::sync::OnceLock<bool> = std::sync::OnceLock::new();4105+ static ENV: std::sync::LazyLock<Option<bool>> = std::sync::LazyLock::new(|| {
4109- *ON.get_or_init(|| std::env::var("EC_AV1_CFL").as_deref() != Ok("0"))4106+ crate::envflags::var("EC_AV1_CFL").ok().map(|v| v != "0")
4107+ });
4108+ ENV.unwrap_or_else(|| crate::speed::at(&crate::speed::CFL))
4110 }4109 }
4111 4110
4112 /// Whether the intra search offers the five recursive filter-intra modes at4111 /// Whether the intra search offers the five recursive filter-intra modes at
@@ -4152,11 +4151,12 @@ pub(crate) fn take_uv_mode_hits() -> [usize; 14] {
4152 /// winner sat at SAD rank 0 for 67-77% of blocks and inside the top three4151 /// winner sat at SAD rank 0 for 67-77% of blocks and inside the top three
4153 /// for 88%. `EC_AV1_CHROMA_K` sweeps it in any build.4152 /// for 88%. `EC_AV1_CHROMA_K` sweeps it in any build.
4154 fn chroma_top_k() -> Option<usize> {4153 fn chroma_top_k() -> Option<usize> {
4155- static K: std::sync::OnceLock<Option<usize>> = std::sync::OnceLock::new();4154+ static ENV: std::sync::LazyLock<Option<Option<usize>>> = std::sync::LazyLock::new(|| {
4156- *K.get_or_init(|| match std::env::var("EC_AV1_CHROMA_K").ok() {4155+ crate::envflags::var("EC_AV1_CHROMA_K")
4157- Some(v) => v.parse::<usize>().ok().filter(|&k| k > 0),4156+ .ok()
4158- None => CHROMA_TOP_K,4157+ .map(|v| v.parse::<usize>().ok().filter(|&k| k > 0))
4159- })4158+ });
4159+ ENV.unwrap_or_else(|| crate::speed::at(&crate::speed::CHROMA_K))
4160 }4160 }
4161 4161
4162 /// [`chroma_top_k`]'s default. `None`: no `K` cleared the keep rule on the BD4162 /// [`chroma_top_k`]'s default. `None`: no `K` cleared the keep rule on the BD
@@ -4170,7 +4170,7 @@ fn chroma_top_k() -> Option<usize> {
4170 /// RE-MEASURED on lane-av1rejudge at [`LAMBDA_SCALE`] 0.05 with warp on:4170 /// RE-MEASURED on lane-av1rejudge at [`LAMBDA_SCALE`] 0.05 with warp on:
4171 /// K=4 is +17.1/-0.1, +47.1/+19.2, +51.6/-13.8 against the base's4171 /// K=4 is +17.1/-0.1, +47.1/+19.2, +51.6/-13.8 against the base's
4172 /// +16.7/-0.5, +47.0/+19.1, +51.3/-14.3 -- every row worse. Still `None`.4172 /// +16.7/-0.5, +47.0/+19.1, +51.3/-14.3 -- every row worse. Still `None`.
4173-const CHROMA_TOP_K: Option<usize> = None;4173+pub(crate) const CHROMA_TOP_K: Option<usize> = None;
4174 4174
4175 fn search_chroma(4175 fn search_chroma(
4176 chroma: &mut [Plane; 2],4176 chroma: &mut [Plane; 2],
@@ -5458,7 +5458,7 @@ fn prune_top_k() -> Option<usize> {
5458 .and_then(|v| v.parse::<usize>().ok());5458 .and_then(|v| v.parse::<usize>().ok());
5459 match swept {5459 match swept {
5460 Some(k) if cfg!(test) => Some(k),5460 Some(k) if cfg!(test) => Some(k),
5461- _ => PRUNE_TOP_K,5461+ _ => crate::speed::at(&crate::speed::PRUNE_K),
5462 }5462 }
5463 }5463 }
5464 5464
@@ -5478,7 +5478,7 @@ fn set_test_top_k_override(value: Option<usize>) {
5478 5478
5479 /// The default: unpruned, thirteen full trials per block, same as before this5479 /// The default: unpruned, thirteen full trials per block, same as before this
5480 /// lever. Set from the sweep in the lane report if the quality gate clears it.5480 /// lever. Set from the sweep in the lane report if the quality gate clears it.
5481-const PRUNE_TOP_K: Option<usize> = None;5481+pub(crate) const PRUNE_TOP_K: Option<usize> = None;
5482 5482
5483 /// [`Search::top_k`] for [`search_inter_block`]'s intra-candidate loop --5483 /// [`Search::top_k`] for [`search_inter_block`]'s intra-candidate loop --
5484 /// kept apart from [`prune_top_k`]/[`PRUNE_TOP_K`] because the two paths'5484 /// kept apart from [`prune_top_k`]/[`PRUNE_TOP_K`] because the two paths'
@@ -5497,7 +5497,7 @@ fn prune_top_k_inter() -> Option<usize> {
5497 .and_then(|v| v.parse::<usize>().ok());5497 .and_then(|v| v.parse::<usize>().ok());
5498 match swept {5498 match swept {
5499 Some(k) if cfg!(test) => Some(k),5499 Some(k) if cfg!(test) => Some(k),
5500- _ => INTER_PRUNE_TOP_K,5500+ _ => crate::speed::at(&crate::speed::PRUNE_K_INTER),
5501 }5501 }
5502 }5502 }
5503 5503
@@ -5521,7 +5521,7 @@ fn set_test_top_k_override_inter(value: Option<usize>) {
5521 /// `K=3`, ships as default. Unlike the key-frame path (still `None`), an5521 /// `K=3`, ships as default. Unlike the key-frame path (still `None`), an
5522 /// inter block's intra candidates rarely win against NEWMV/NEARESTMV, so5522 /// inter block's intra candidates rarely win against NEWMV/NEARESTMV, so
5523 /// pruning them costs less quality here.5523 /// pruning them costs less quality here.
5524-const INTER_PRUNE_TOP_K: Option<usize> = Some(3);5524+pub(crate) const INTER_PRUNE_TOP_K: Option<usize> = Some(3);
5525 5525
5526 // Per-thread nanosecond counters `stage_timing_breakdown_inter` (and5526 // Per-thread nanosecond counters `stage_timing_breakdown_inter` (and
5527 // [`crate::mc::predict`], through [`stage_add`]) accumulate into, so an5527 // [`crate::mc::predict`], through [`stage_add`]) accumulate into, so an
@@ -6835,7 +6835,7 @@ fn mv_component_bits(diff: i32) -> Option<f64> {
6835 fn extra_ref_new_mv() -> bool {6835 fn extra_ref_new_mv() -> bool {
6836 match std::env::var("EC_AV1_MV_EXTRA_NEW").ok() {6836 match std::env::var("EC_AV1_MV_EXTRA_NEW").ok() {
6837 Some(v) if cfg!(test) => v != "0",6837 Some(v) if cfg!(test) => v != "0",
6838- _ => EXTRA_REF_NEW_MV,6838+ _ => crate::speed::at(&crate::speed::EXTRA_REF_NEW),
6839 }6839 }
6840 }6840 }
6841 6841
@@ -6861,13 +6861,13 @@ pub(crate) fn flat_order_hints(order_hint: u32, key_hint: u32, has_altref: bool)
6861 /// `EC_AV1_COMPOUND=1` arms it in a test build (which is what the BD gate6861 /// `EC_AV1_COMPOUND=1` arms it in a test build (which is what the BD gate
6862 /// runs as), and every block still codes SINGLE, so the only cost is one6862 /// runs as), and every block still codes SINGLE, so the only cost is one
6863 /// `comp_mode` symbol per inter block.6863 /// `comp_mode` symbol per inter block.
6864-const REFERENCE_SELECT: bool = true;6864+pub(crate) const REFERENCE_SELECT: bool = true;
6865 6865
6866 /// [`REFERENCE_SELECT`], with the test-build environment override.6866 /// [`REFERENCE_SELECT`], with the test-build environment override.
6867 pub(crate) fn reference_select() -> bool {6867 pub(crate) fn reference_select() -> bool {
6868 match std::env::var("EC_AV1_COMPOUND").ok() {6868 match std::env::var("EC_AV1_COMPOUND").ok() {
6869 Some(v) if cfg!(test) => v != "0",6869 Some(v) if cfg!(test) => v != "0",
6870- _ => REFERENCE_SELECT,6870+ _ => crate::speed::at(&crate::speed::COMPOUND),
6871 }6871 }
6872 }6872 }
6873 6873
@@ -8040,7 +8040,7 @@ fn tpl_strength() -> f64 {
8040 /// The streaming facade holds `depth - 1` pictures back so it feeds8040 /// The streaming facade holds `depth - 1` pictures back so it feeds
8041 /// `encode_inter_frame` the same window `encode_sequence` does; both read8041 /// `encode_inter_frame` the same window `encode_sequence` does; both read
8042 /// THIS function, so the two paths cannot disagree about the window.8042 /// THIS function, so the two paths cannot disagree about the window.
8043-const TPL_DEPTH: usize = 8;8043+pub(crate) const TPL_DEPTH: usize = 8;
8044 8044
8045 /// The exponent the dependence ratio is read through ([`tpl_lambda_factors`]).8045 /// The exponent the dependence ratio is read through ([`tpl_lambda_factors`]).
8046 /// 0.5 is libaom's own square-root compression of its dependence ratio.8046 /// 0.5 is libaom's own square-root compression of its dependence ratio.
@@ -8112,7 +8112,7 @@ pub(crate) fn tpl_depth() -> usize {
8112 .ok()8112 .ok()
8113 .and_then(|v| v.parse::<usize>().ok())8113 .and_then(|v| v.parse::<usize>().ok())
8114 .filter(|d| *d >= 1)8114 .filter(|d| *d >= 1)
8115- .unwrap_or(TPL_DEPTH)8115+ .unwrap_or_else(|| crate::speed::at(&crate::speed::TPL_DEPTH))
8116 .max(1)8116 .max(1)
8117 }8117 }
8118 8118
crates/ec-av1/src/encoder.rsmodified+18 -0
@@ -659,6 +659,24 @@ const _: fn() = || {
659 };659 };
660 660
661 impl Av1Encoder {661 impl Av1Encoder {
662+ /// [`Av1Encoder::new`] at a SPEED PRESET (`speed` 0..=10, rav1e's scale:
663+ /// 0 is the full search this encoder has always run and is byte for byte
664+ /// identical to [`Av1Encoder::new`]; higher presets switch search levers
665+ /// off, [`crate::speed::levers`] naming which).
666+ ///
667+ /// The preset is process-global (the tile search reads it from worker
668+ /// threads -- see [`crate::speed`]), so it is set here for every encode
669+ /// that follows on this process, and two encoders at different speeds
670+ /// must not run concurrently. `EC_AV1_SPEED=<n>` is the same knob for a
671+ /// caller that does not construct the encoder itself.
672+ ///
673+ /// # Errors
674+ /// [`Av1Encoder::new`]'s.
675+ pub fn with_speed(config: EncoderConfig, speed: u8) -> Result<Self> {
676+ crate::speed::set_speed(speed);
677+ Self::new(config)
678+ }
679+
662 /// # Errors680 /// # Errors
663 /// Returns an error when `config.width`/`config.height` are zero, odd,681 /// Returns an error when `config.width`/`config.height` are zero, odd,
664 /// or larger than the 16-bit frame size an AV1 sequence header carries,682 /// or larger than the 16-bit frame size an AV1 sequence header carries,
crates/ec-av1/src/filter_search.rsmodified+27 -8
@@ -291,15 +291,29 @@ pub(crate) fn pick_filters(
291 .filter_map(|d| u8::try_from(i32::from(best.lf.0) + d).ok())291 .filter_map(|d| u8::try_from(i32::from(best.lf.0) + d).ok())
292 .filter(|&l| l <= 63)292 .filter(|&l| l <= 63)
293 .collect();293 .collect();
294- stage(&mut best, &refine, |c, v| c.lf = (v, v), |t| t.sse_y, &mut st)?;294+ // Which of these stages run is the SPEED PRESET's filter-search lever
295+ // (`crate::speed`): each stage costs one whole-frame decode per candidate
296+ // it has not seen, and the filter search is 19-28% of the encoder's wall.
297+ // At speed 0 every table below reads its shipped value, so the sequence is
298+ // the one this function always ran.
299+ if crate::speed::at(&crate::speed::DEBLOCK_REFINE) {
300+ stage(&mut best, &refine, |c, v| c.lf = (v, v), |t| t.sse_y, &mut st)?;
301+ }
295 // Deblocking chroma, three points around the luma winner.302 // Deblocking chroma, three points around the luma winner.
296- let chroma_levels = [0, best.lf.0 / 2, best.lf.0];303+ if crate::speed::at(&crate::speed::DEBLOCK_CHROMA) {
297- stage(&mut best, &chroma_levels, |c, v| c.lf.1 = v, |t| t.sse_uv, &mut st)?;304+ let chroma_levels = [0, best.lf.0 / 2, best.lf.0];
305+ stage(&mut best, &chroma_levels, |c, v| c.lf.1 = v, |t| t.sse_uv, &mut st)?;
306+ }
298 // CDEF, primary then secondary, luma on luma error and chroma on chroma.307 // CDEF, primary then secondary, luma on luma error and chroma on chroma.
299- stage(&mut best, &CDEF_PRI, |c, v| c.y.0 = v, |t| t.sse_y, &mut st)?;308+ // `n == 0` leaves every strength at 0, i.e. deblocking only.
300- stage(&mut best, &CDEF_SEC, |c, v| c.y.1 = v, |t| t.sse_y, &mut st)?;309+ let n = crate::speed::at(&crate::speed::CDEF_STRENGTHS);
301- stage(&mut best, &CDEF_PRI, |c, v| c.uv.0 = v, |t| t.sse_uv, &mut st)?;310+ if n > 0 {
302- stage(&mut best, &CDEF_SEC, |c, v| c.uv.1 = v, |t| t.sse_uv, &mut st)?;311+ let (pri, sec) = (&CDEF_PRI[..n.min(CDEF_PRI.len())], &CDEF_SEC[..n.min(CDEF_SEC.len())]);
312+ stage(&mut best, pri, |c, v| c.y.0 = v, |t| t.sse_y, &mut st)?;
313+ stage(&mut best, sec, |c, v| c.y.1 = v, |t| t.sse_y, &mut st)?;
314+ stage(&mut best, pri, |c, v| c.uv.0 = v, |t| t.sse_uv, &mut st)?;
315+ stage(&mut best, sec, |c, v| c.uv.1 = v, |t| t.sse_uv, &mut st)?;
316+ }
303 317
304 CHOSEN.with(|c| c.borrow_mut().push(best));318 CHOSEN.with(|c| c.borrow_mut().push(best));
305 let trials = st.trials;319 let trials = st.trials;
@@ -342,7 +356,12 @@ pub(crate) fn pick_filters(
342 }356 }
343 let mut order: Vec<usize> = (0..pool.len()).collect();357 let mut order: Vec<usize> = (0..pool.len()).collect();
344 order.sort_by_key(|&i| std::cmp::Reverse(counts[i]));358 order.sort_by_key(|&i| std::cmp::Reverse(counts[i]));
345- presets.extend(order.iter().take(7).map(|&i| pool[i]));359+ presets.extend(
360+ order
361+ .iter()
362+ .take(crate::speed::at(&crate::speed::CDEF_PRESETS))
363+ .map(|&i| pool[i]),
364+ );
346 // The cheapest list length: `bits` costs one literal per superblock plus365 // The cheapest list length: `bits` costs one literal per superblock plus
347 // twelve header bits per extra pair, and buys whatever per-unit error the366 // twelve header bits per extra pair, and buys whatever per-unit error the
348 // wider choice removes.367 // wider choice removes.
crates/ec-av1/src/lib.rsmodified+1 -0
@@ -46,6 +46,7 @@ pub mod obu;
46 mod par;46 mod par;
47 pub mod quant;47 pub mod quant;
48 mod refusal_inventory;48 mod refusal_inventory;
49+pub mod speed;
49 mod restoration;50 mod restoration;
50 pub mod sequence;51 pub mod sequence;
51 mod superres;52 mod superres;
crates/ec-av1/src/speed.rsadded+284 -0
@@ -0,0 +1,284 @@
1+//! The encoder's SPEED PRESET axis (lane-av1fast): one number, 0..=10 like
2+//! rav1e's `--speed`, that picks a default for every search lever this crate
3+//! already has a knob for.
4+//!
5+//! Speed 0 is today's search, byte for byte -- every table below reads its
6+//! shipped default at index 0, so `encoder::tests`' byte pins are the pin on
7+//! that. Higher speeds trade BD-rate for wall by switching off the levers in
8+//! [`levers`], each of which was already measured on its own (the doc comment
9+//! on each knob in [`crate::encode`] carries its sweep).
10+//!
11+//! The value is PROCESS-GLOBAL, the same shape [`crate::par`]'s thread counts
12+//! use, because the levers are read from the tile-search worker threads --
13+//! a thread-local would not reach them. One speed per process at a time:
14+//! [`crate::encoder::Av1Encoder::with_speed`] sets it at construction, so two
15+//! encoders at different speeds must not run concurrently in one process.
16+//! `EC_AV1_SPEED=<n>` is the environment form the gates and `ec-bench` use.
17+//! Every individual `EC_AV1_*` lever override still wins over the preset.
18+
19+use std::sync::atomic::{AtomicU8, Ordering};
20+
21+/// The highest preset. 10 is the fastest, as in rav1e.
22+pub const MAX_SPEED: u8 = 10;
23+
24+/// 255 = "not read yet"; the env read happens once and the value is a plain
25+/// atomic afterwards, so a caller can set it without touching the process
26+/// environment.
27+static SPEED: AtomicU8 = AtomicU8::new(u8::MAX);
28+
29+/// This process's speed preset, 0..=[`MAX_SPEED`].
30+#[must_use]
31+pub fn speed() -> u8 {
32+ match SPEED.load(Ordering::Relaxed) {
33+ u8::MAX => {
34+ let n = crate::envflags::var("EC_AV1_SPEED")
35+ .ok()
36+ .and_then(|v| v.trim().parse::<u8>().ok())
37+ .unwrap_or(0)
38+ .min(MAX_SPEED);
39+ SPEED.store(n, Ordering::Relaxed);
40+ n
41+ }
42+ n => n,
43+ }
44+}
45+
46+/// Sets the preset for everything encoded afterwards in this process.
47+pub fn set_speed(n: u8) {
48+ SPEED.store(n.min(MAX_SPEED), Ordering::Relaxed);
49+}
50+
51+/// `TABLE[speed()]`, the shape every lever below is read through.
52+pub(crate) fn at<T: Copy>(table: &[T; 11]) -> T {
53+ table[speed() as usize]
54+}
55+
56+// ---------------------------------------------------------------------------
57+// The lever tables. Index 0 of each is the shipped default of the constant
58+// named in the comment; the rest is this lane's composition (see the report
59+// table for what each step measured).
60+// ---------------------------------------------------------------------------
61+
62+/// `encode::SPLIT_RD_THRESHOLD`: how cheap a block has to be before its split
63+/// trial is withheld. The single biggest wall lever in the tile search.
64+pub(crate) const SPLIT_RD: [f64; 11] =
65+ [crate::encode::SPLIT_RD_THRESHOLD, 0.125, 0.25, 0.5, 0.5, 1.0, 1.5, 2.0, 3.0, 4.0, 6.0];
66+
67+/// `encode::SPLIT_BREAKOUT_COEFFS`: libaom's coefficient-count breakout.
68+pub(crate) const SPLIT_BREAKOUT: [usize; 11] = [crate::encode::SPLIT_BREAKOUT_COEFFS, 0, 0, 0, 0, 0, 1, 1, 2, 4, 4];
69+
70+/// `encode::SPLIT_INTER_8`: a 16x16 leaf may split into four 8x8 ones.
71+pub(crate) const SPLIT_8: [bool; 11] =
72+ [crate::encode::SPLIT_INTER_8, true, true, true, false, false, false, false, false, false, false];
73+
74+/// `encode::SPLIT_INTER_BLOCKS`: a 32x32 inter block may split at all
75+/// (`false` = 32x32-only partitioning).
76+pub(crate) const SPLIT_INTER: [bool; 11] =
77+ [crate::encode::SPLIT_INTER_BLOCKS, true, true, true, true, true, true, true, false, false, false];
78+
79+/// `encode::leaf_second_new_mv`: a leaf searches its SECOND reference.
80+pub(crate) const LEAF_SECOND: [bool; 11] =
81+ [true, true, true, false, false, false, false, false, false, false, false];
82+
83+/// `encode::EXTRA_REF_NEW_MV`: GOLDEN/ALTREF get a `NEWMV` search of their own.
84+pub(crate) const EXTRA_REF_NEW: [bool; 11] =
85+ [crate::encode::EXTRA_REF_NEW_MV, true, true, true, false, false, false, false, false, false, false];
86+
87+/// `encode::LEAF_COMPOUND`: a leaf is offered compound candidates.
88+pub(crate) const LEAF_COMPOUND: [bool; 11] =
89+ [crate::encode::LEAF_COMPOUND, true, false, false, false, false, false, false, false, false, false];
90+
91+/// `encode::REFERENCE_SELECT`: compound prediction at all.
92+pub(crate) const COMPOUND: [bool; 11] =
93+ [crate::encode::REFERENCE_SELECT, true, true, true, true, true, false, false, false, false, false];
94+
95+/// `encode::warp_on`: local warped motion.
96+pub(crate) const WARP: [bool; 11] =
97+ [true, true, true, false, false, false, false, false, false, false, false];
98+
99+/// `encode::tx_select_inter`: var-tx / tx-depth search inside inter frames.
100+pub(crate) const TX_SELECT_INTER: [bool; 11] =
101+ [true, true, true, true, true, false, false, false, false, false, false];
102+
103+/// `encode::tx32_depth_search`.
104+pub(crate) const TX32_DEPTH: [bool; 11] =
105+ [true, true, true, true, false, false, false, false, false, false, false];
106+
107+/// `encode::compound_var_tx`.
108+pub(crate) const COMPOUND_VAR_TX: [bool; 11] =
109+ [true, true, true, false, false, false, false, false, false, false, false];
110+
111+/// `encode::tx_select`: the KEY frame's transform-depth search.
112+pub(crate) const TX_SELECT_KEY: [bool; 11] =
113+ [true, true, true, true, true, true, true, false, false, false, false];
114+
115+/// `encode::PRUNE_TOP_K`: intra luma modes fully tried on a key frame.
116+pub(crate) const PRUNE_K: [Option<usize>; 11] = [
117+ crate::encode::PRUNE_TOP_K,
118+ None,
119+ Some(4),
120+ Some(4),
121+ Some(3),
122+ Some(3),
123+ Some(2),
124+ Some(2),
125+ Some(2),
126+ Some(1),
127+ Some(1),
128+];
129+
130+/// `encode::INTER_PRUNE_TOP_K`: the same for intra candidates inside an inter
131+/// frame.
132+pub(crate) const PRUNE_K_INTER: [Option<usize>; 11] = [
133+ crate::encode::INTER_PRUNE_TOP_K,
134+ Some(3),
135+ Some(3),
136+ Some(2),
137+ Some(2),
138+ Some(2),
139+ Some(1),
140+ Some(1),
141+ Some(1),
142+ Some(1),
143+ Some(1),
144+];
145+
146+/// `encode::CHROMA_TOP_K`: chroma modes fully tried.
147+pub(crate) const CHROMA_K: [Option<usize>; 11] = [
148+ crate::encode::CHROMA_TOP_K,
149+ Some(4),
150+ Some(3),
151+ Some(3),
152+ Some(2),
153+ Some(2),
154+ Some(2),
155+ Some(1),
156+ Some(1),
157+ Some(1),
158+ Some(1),
159+];
160+
161+/// `encode::angle_delta_on`: refining a directional intra winner's delta.
162+pub(crate) const ANGLE: [bool; 11] =
163+ [true, true, true, true, false, false, false, false, false, false, false];
164+
165+/// `encode::cfl_on`: chroma-from-luma in the chroma search.
166+pub(crate) const CFL: [bool; 11] =
167+ [true, true, true, true, true, false, false, false, false, false, false];
168+
169+/// `encode::RESTORATION`: the loop-restoration (Wiener) search.
170+pub(crate) const RESTORATION: [bool; 11] =
171+ [crate::encode::RESTORATION, true, true, true, true, false, false, false, false, false, false];
172+
173+/// `encode::TPL_DEPTH`: lookahead pictures the lambda map reads (1 = off).
174+pub(crate) const TPL_DEPTH: [usize; 11] = [crate::encode::TPL_DEPTH, 8, 8, 4, 4, 2, 1, 1, 1, 1, 1];
175+
176+/// `filter_search`: whether the deblock ladder's +-1/+-2 refinement stage runs.
177+pub(crate) const DEBLOCK_REFINE: [bool; 11] =
178+ [true, true, true, true, true, false, false, false, false, false, false];
179+
180+/// `filter_search`: whether chroma gets a deblock stage of its own.
181+pub(crate) const DEBLOCK_CHROMA: [bool; 11] =
182+ [true, true, true, true, true, true, false, false, false, false, false];
183+
184+/// `filter_search`: how many of `CDEF_PRI` / `CDEF_SEC` each CDEF stage tries
185+/// (0 = no CDEF search at all, the frame keeps strength 0 = deblock only).
186+pub(crate) const CDEF_STRENGTHS: [usize; 11] = [5, 5, 5, 5, 3, 3, 3, 2, 2, 0, 0];
187+
188+/// `filter_search`: how many extra per-superblock CDEF presets the header may
189+/// carry beyond the frame winner (0 = `cdef_bits` 0).
190+pub(crate) const CDEF_PRESETS: [usize; 11] = [7, 7, 7, 7, 7, 3, 3, 0, 0, 0, 0];
191+
192+/// What preset `n` switches off relative to speed 0, for a gate or a bench row
193+/// to print (class `gate-blind-to-feature`: a preset that silently disables
194+/// nothing is a preset that buys nothing).
195+#[must_use]
196+pub fn levers(n: u8) -> Vec<String> {
197+ let n = usize::from(n.min(MAX_SPEED));
198+ let mut out = Vec::new();
199+ let mut flag = |name: &str, t: &[bool; 11]| {
200+ if !t[n] {
201+ out.push(format!("no {name}"));
202+ }
203+ };
204+ flag("8x8 split", &SPLIT_8);
205+ flag("32x32 split (32x32-only partitions)", &SPLIT_INTER);
206+ flag("leaf second-reference search", &LEAF_SECOND);
207+ flag("extra-reference NEWMV", &EXTRA_REF_NEW);
208+ flag("leaf compound", &LEAF_COMPOUND);
209+ flag("compound", &COMPOUND);
210+ flag("warp", &WARP);
211+ flag("inter var-tx/tx-depth", &TX_SELECT_INTER);
212+ flag("32x32 tx depth", &TX32_DEPTH);
213+ flag("compound var-tx", &COMPOUND_VAR_TX);
214+ flag("key tx-depth", &TX_SELECT_KEY);
215+ flag("angle delta", &ANGLE);
216+ flag("CfL", &CFL);
217+ flag("loop restoration", &RESTORATION);
218+ flag("deblock refine", &DEBLOCK_REFINE);
219+ flag("chroma deblock stage", &DEBLOCK_CHROMA);
220+ if SPLIT_RD[n] > SPLIT_RD[0] {
221+ out.push(format!("split-RD breakout {}", SPLIT_RD[n]));
222+ }
223+ if SPLIT_BREAKOUT[n] > 0 {
224+ out.push(format!("coeff breakout {}", SPLIT_BREAKOUT[n]));
225+ }
226+ if PRUNE_K[n] != PRUNE_K[0] {
227+ out.push(format!("intra top-{}", PRUNE_K[n].unwrap_or(13)));
228+ }
229+ if PRUNE_K_INTER[n] != PRUNE_K_INTER[0] {
230+ out.push(format!("inter-intra top-{}", PRUNE_K_INTER[n].unwrap_or(13)));
231+ }
232+ if CHROMA_K[n] != CHROMA_K[0] {
233+ out.push(format!("chroma top-{}", CHROMA_K[n].unwrap_or(7)));
234+ }
235+ if TPL_DEPTH[n] != TPL_DEPTH[0] {
236+ out.push(if TPL_DEPTH[n] <= 1 {
237+ "no tpl".to_string()
238+ } else {
239+ format!("tpl depth {}", TPL_DEPTH[n])
240+ });
241+ }
242+ if CDEF_STRENGTHS[n] == 0 {
243+ out.push("no CDEF search".to_string());
244+ } else if CDEF_STRENGTHS[n] != CDEF_STRENGTHS[0] {
245+ out.push(format!("CDEF {} strengths", CDEF_STRENGTHS[n]));
246+ }
247+ if CDEF_PRESETS[n] != CDEF_PRESETS[0] {
248+ out.push(format!("CDEF presets {}", CDEF_PRESETS[n]));
249+ }
250+ out
251+}
252+
253+#[cfg(test)]
254+mod tests {
255+ use super::*;
256+
257+ /// Speed 0 must be every lever's shipped default -- the byte pins are the
258+ /// pin on that, and this is the cheap statement of the same rule.
259+ #[test]
260+ fn speed_zero_disables_nothing() {
261+ assert!(levers(0).is_empty(), "{:?}", levers(0));
262+ assert_eq!(SPLIT_RD[0], 0.125);
263+ assert_eq!(SPLIT_BREAKOUT[0], 0);
264+ assert_eq!(TPL_DEPTH[0], 8);
265+ assert_eq!(PRUNE_K[0], None);
266+ assert_eq!(PRUNE_K_INTER[0], Some(3));
267+ assert_eq!(CHROMA_K[0], None);
268+ assert_eq!(CDEF_STRENGTHS[0], 5);
269+ }
270+
271+ /// Every preset switches off something the one below it did not, and the
272+ /// monotone levers never come back on.
273+ #[test]
274+ fn presets_are_monotone_in_speed() {
275+ for n in 1..=MAX_SPEED {
276+ let (a, b) = (levers(n - 1), levers(n));
277+ assert!(b.len() >= a.len(), "speed {n} loosens: {a:?} -> {b:?}");
278+ assert!(SPLIT_RD[n as usize] >= SPLIT_RD[n as usize - 1]);
279+ assert!(TPL_DEPTH[n as usize] <= TPL_DEPTH[n as usize - 1]);
280+ assert!(CDEF_STRENGTHS[n as usize] <= CDEF_STRENGTHS[n as usize - 1]);
281+ }
282+ assert!(!levers(MAX_SPEED).is_empty());
283+ }
284+}
lanes/bd-speed0.logadded+11 -0
@@ -0,0 +1,11 @@
1+
2+running 1 test
3+test encode::tests::bd_rate_screen_native ...
4+native crop, 12 frames, gop=12; tiles (0, 0), tile threads 1, intrabc false, palette maxcolors 128
5+| clip | ours PSNR/bytes per point | BD-rate vs libaom | BD-rate vs rav1e | wall ours:libaom:rav1e (noisy) |
6+|---|---|---|---|---|
7+bars 1080p: sequence, pyramid requested Some(Pyramid { mini_gop: 4, arf_q_offset: -16, leaf_q_offset: 8 }) effective Some(Pyramid { mini_gop: 4, arf_q_offset: -16, leaf_q_offset: 8 })
8+bars 1080p: pricer armings default=17 real=183
9+bars 1080p: motion_mode 32x32 SIMPLE=77834 OBMC=0 WARP=160 | 16x16 SIMPLE=3194 OBMC=0 WARP=261 | 8x8 SIMPLE=13280 OBMC=0 WARP=1286 (0.0% OBMC / 1.8% WARP of 96015 eligible)
10+bars 1080p: inter var-tx depths of 11770 blocks -- leaf single 0=1311 1=691 (34.5% split) | leaf compound 0=1242 1=694 (35.8% split) | 32x32 single 0=968 1=2080 (68.2% split) | 32x32 compound 0=2438 1=2346 (49.0% split)
11+bars 1080p: screen frames on=0 off=4 (0.0% on); palette blocks luma 0 chroma 0; intrabc blocks 0 (searched 0 / valid 0 / won 0)
lanes/bd-speed3.logadded+11 -0
@@ -0,0 +1,11 @@
1+
2+running 1 test
3+test encode::tests::bd_rate_screen_native ...
4+native crop, 12 frames, gop=12; tiles (0, 0), tile threads 1, intrabc false, palette maxcolors 128
5+| clip | ours PSNR/bytes per point | BD-rate vs libaom | BD-rate vs rav1e | wall ours:libaom:rav1e (noisy) |
6+|---|---|---|---|---|
7+bars 1080p: sequence, pyramid requested Some(Pyramid { mini_gop: 4, arf_q_offset: -16, leaf_q_offset: 8 }) effective Some(Pyramid { mini_gop: 4, arf_q_offset: -16, leaf_q_offset: 8 })
8+bars 1080p: pricer armings default=16 real=170
9+bars 1080p: motion_mode 32x32 SIMPLE=0 OBMC=0 WARP=0 | 16x16 SIMPLE=0 OBMC=0 WARP=0 | 8x8 SIMPLE=0 OBMC=0 WARP=0 (0.0% OBMC / 0.0% WARP of 0 eligible)
10+bars 1080p: inter var-tx depths of 5684 blocks -- leaf single 0=1423 1=794 (35.8% split) | leaf compound 0=0 1=0 (0.0% split) | 32x32 single 0=1099 1=2368 (68.3% split) | 32x32 compound 0=0 1=0 (0.0% split)
11+bars 1080p: screen frames on=0 off=4 (0.0% on); palette blocks luma 0 chroma 0; intrabc blocks 0 (searched 0 / valid 0 / won 0)
lanes/bd-speed6.logadded+11 -0
@@ -0,0 +1,11 @@
1+
2+running 1 test
3+test encode::tests::bd_rate_screen_native ...
4+native crop, 12 frames, gop=12; tiles (0, 0), tile threads 1, intrabc false, palette maxcolors 128
5+| clip | ours PSNR/bytes per point | BD-rate vs libaom | BD-rate vs rav1e | wall ours:libaom:rav1e (noisy) |
6+|---|---|---|---|---|
7+bars 1080p: sequence, pyramid requested Some(Pyramid { mini_gop: 4, arf_q_offset: -16, leaf_q_offset: 8 }) effective Some(Pyramid { mini_gop: 4, arf_q_offset: -16, leaf_q_offset: 8 })
8+bars 1080p: pricer armings default=12 real=141
9+bars 1080p: motion_mode 32x32 SIMPLE=0 OBMC=0 WARP=0 | 16x16 SIMPLE=0 OBMC=0 WARP=0 | 8x8 SIMPLE=0 OBMC=0 WARP=0 (0.0% OBMC / 0.0% WARP of 0 eligible)
10+bars 1080p: inter var-tx depths of 0 blocks -- leaf single 0=0 1=0 (0.0% split) | leaf compound 0=0 1=0 (0.0% split) | 32x32 single 0=0 1=0 (0.0% split) | 32x32 compound 0=0 1=0 (0.0% split)
11+bars 1080p: screen frames on=0 off=4 (0.0% on); palette blocks luma 0 chroma 0; intrabc blocks 0 (searched 0 / valid 0 / won 0)
tools/ec-bench/src/main.rsmodified+26 -4
@@ -524,6 +524,15 @@ fn bench_av1_encode(rows: &mut Vec<Row>) {
524 Some((cols, f.next().and_then(|v| v.parse().ok()).unwrap_or(0)))524 Some((cols, f.next().and_then(|v| v.parse().ok()).unwrap_or(0)))
525 })525 })
526 .unwrap_or((0, 0));526 .unwrap_or((0, 0));
527+ // One row per SPEED PRESET (`ec_av1::speed`): 0 is the full search every
528+ // byte pin carries, 10 the fastest. `EC_AV1_SPEED=<n>` benches a single
529+ // preset instead of the ladder.
530+ let presets: Vec<u8> = match std::env::var("EC_AV1_SPEED").ok().and_then(|v| v.parse().ok()) {
531+ Some(n) => vec![n],
532+ None => vec![0, 3, 6, 10],
533+ };
534+ let mut first_stream = Vec::new();
535+ for &speed in &presets {
527 let cfg = Av1Config {536 let cfg = Av1Config {
528 width: w as usize,537 width: w as usize,
529 height: h as usize,538 height: h as usize,
@@ -540,8 +549,9 @@ fn bench_av1_encode(rows: &mut Vec<Row>) {
540 // shape of it. The `hidden` column below is how many frames of the row549 // shape of it. The `hidden` column below is how many frames of the row
541 // were coded ahead of their display position.550 // were coded ahead of their display position.
542 let pyramid = Pyramid::from_env();551 let pyramid = Pyramid::from_env();
552+ ec_av1::speed::set_speed(speed);
543 let mut enc = match pyramid {553 let mut enc = match pyramid {
544- None => Av1Encoder::new(cfg).expect("av1 encoder"),554+ None => Av1Encoder::with_speed(cfg, speed).expect("av1 encoder"),
545 Some(p) => Av1Encoder::with_pyramid(cfg, p).expect("av1 encoder"),555 Some(p) => Av1Encoder::with_pyramid(cfg, p).expect("av1 encoder"),
546 };556 };
547 let frame_len = (w * h + 2 * (w.div_ceil(2) * h.div_ceil(2))) as usize;557 let frame_len = (w * h + 2 * (w.div_ceil(2) * h.div_ceil(2))) as usize;
@@ -579,20 +589,32 @@ fn bench_av1_encode(rows: &mut Vec<Row>) {
579 (None, None) => "flat".to_string(),589 (None, None) => "flat".to_string(),
580 };590 };
581 let media_s = n as f64 / 30.0;591 let media_s = n as f64 / 30.0;
592+ let levers = match ec_av1::speed::levers(speed) {
593+ v if v.is_empty() => "full search".to_string(),
594+ v => v.join(", "),
595+ };
582 let fps = if wall > 0.0 { f64::from(n) / wall } else { 0.0 };596 let fps = if wall > 0.0 { f64::from(n) / wall } else { 0.0 };
583 let bytes_per_frame = stream.len() as f64 / f64::from(n);597 let bytes_per_frame = stream.len() as f64 / f64::from(n);
584 rows.push(Row {598 rows.push(Row {
585 component: "ec-av1",599 component: "ec-av1",
586 direction: "encode",600 direction: "encode",
587 content: format!(601 content: format!(
588- "{w}x{h}, {n} frames, gop=10, {coded_under}, {hidden} hidden, {fps:.1} fps, \602+ "speed {speed} [{levers}], {w}x{h}, {n} frames, gop=10, {coded_under}, \
589- {bytes_per_frame:.0} B/frame"603+ {hidden} hidden, {fps:.1} fps, {bytes_per_frame:.0} B/frame"
590 ),604 ),
591 media: format!("{media_s:.1}s"),605 media: format!("{media_s:.1}s"),
592 wall_ms: wall * 1000.0,606 wall_ms: wall * 1000.0,
593 rtf: (wall > 0.0).then_some(media_s / wall),607 rtf: (wall > 0.0).then_some(media_s / wall),
594 });608 });
595-609+ if first_stream.is_empty() {
610+ first_stream = stream;
611+ }
612+ }
613+ // The decode row reads the FIRST preset's stream, so the number stays
614+ // comparable across runs of this bench.
615+ ec_av1::speed::set_speed(0);
616+ let stream = first_stream;
617+ let media_s = n as f64 / 30.0;
596 let start = Instant::now();618 let start = Instant::now();
597 let pictures = ec_av1::stream::decode_stream(&stream).expect("av1 decode_stream");619 let pictures = ec_av1::stream::decode_stream(&stream).expect("av1 decode_stream");
598 let wall = start.elapsed().as_secs_f64();620 let wall = start.elapsed().as_secs_f64();