forge
Explore
Log in

Don't you dare go Hollow

Bound the RDOQ pass to small levels and a per-block price budget

Browse files at this commit

eb7b07c2f0e604acddb511ca57eef6c5b01f4332Ahmet Kaan GümüşParent: 30a94a1
  • perf
    • bound the RDOQ pass to small levels and a per-block price budget
Show full message
perf(av1): bound the RDOQ pass to small levels and a per-block price budget

Unbounded it re-coded the block once per candidate level and a fine-quantizer
32x32 carries hundreds, which took the 12-frame native gate from minutes to
not finishing a row in 35. Levels above 2 are never candidates and a block
spends at most 24 prices, taken from the tail backwards; the q=150 pin moves
9853 -> 9059 B against the unbounded pass's 8959, at +26% wall instead of
+256%.
crates/ec-av1/src/tile.rsmodified+45 -2
@@ -4525,6 +4525,32 @@ pub(crate) fn coeff_bits(
4525 })4525 })
4526 }4526 }
4527 4527
4528+/// The largest level [`rdoq`] offers a candidate for, and the most prices it
4529+/// may spend on one block. `EC_AV1_RDOQ_MAXLEVEL` / `EC_AV1_RDOQ_BUDGET`
4530+/// sweep them; see [`rdoq`] for why both exist.
4531+const RDOQ_MAX_LEVEL: u32 = 2;
4532+const RDOQ_BUDGET: u32 = 24;
4533+
4534+fn rdoq_max_level() -> u32 {
4535+ static ENV: LazyLock<u32> = LazyLock::new(|| {
4536+ crate::envflags::var("EC_AV1_RDOQ_MAXLEVEL")
4537+ .ok()
4538+ .and_then(|v| v.parse().ok())
4539+ .unwrap_or(RDOQ_MAX_LEVEL)
4540+ });
4541+ *ENV
4542+}
4543+
4544+fn rdoq_budget() -> u32 {
4545+ static ENV: LazyLock<u32> = LazyLock::new(|| {
4546+ crate::envflags::var("EC_AV1_RDOQ_BUDGET")
4547+ .ok()
4548+ .and_then(|v| v.parse().ok())
4549+ .unwrap_or(RDOQ_BUDGET)
4550+ });
4551+ *ENV
4552+}
4553+
4528 /// Rate-distortion optimised quantisation (lane-rdoq): the pass every4554 /// Rate-distortion optimised quantisation (lane-rdoq): the pass every
4529 /// reference encoder runs after the quantiser and this one did not have.4555 /// reference encoder runs after the quantiser and this one did not have.
4530 ///4556 ///
@@ -4602,18 +4628,35 @@ pub(crate) fn rdoq(
4602 if census {4628 if census {
4603 census_block(levels, scaled, side, coded, bits);4629 census_block(levels, scaled, side, coded, bits);
4604 }4630 }
4631+ // Where the pass may spend its prices. Every candidate here costs a whole
4632+ // `write_coeffs`, where rav1e's incremental model costs a table lookup,
4633+ // so both bounds exist to keep that affordable -- and both cut where the
4634+ // decisions do not pay anyway:
4635+ // * a level above [`RDOQ_MAX_LEVEL`] is never a candidate: one step off
4636+ // a big level gives back a fraction of a bit for a whole quantiser
4637+ // step of squared error. What pays is `1 -> 0` and `2 -> 1`.
4638+ // * at most [`RDOQ_BUDGET`] prices per block, spent from the TAIL
4639+ // backwards -- the eob end, where dropping a level also shortens the
4640+ // eob -- so a fine-quantizer block carrying two hundred coefficients
4641+ // cannot cost two hundred re-codings.
4642+ let mut budget = rdoq_budget();
4643+ let max_level = rdoq_max_level();
4605 for &position in scan_of(coded).iter().rev() {4644 for &position in scan_of(coded).iter().rev() {
4645+ if budget == 0 {
4646+ break;
4647+ }
4606 let (row, col) = (usize::from(position) / coded, usize::from(position) % coded);4648 let (row, col) = (usize::from(position) / coded, usize::from(position) % coded);
4607 let i = row * side + col;4649 let i = row * side + col;
4608- if levels[i] == 0 {4650+ if levels[i] == 0 || levels[i].unsigned_abs() > max_level {
4609 continue;4651 continue;
4610 }4652 }
4611 let s = f64::from(scaled[i]);4653 let s = f64::from(scaled[i]);
4612 let weight = if i == 0 { dc_weight } else { 1.0 };4654 let weight = if i == 0 { dc_weight } else { 1.0 };
4613- loop {4655+ while budget > 0 {
4614 let level = levels[i];4656 let level = levels[i];
4615 let candidate = level - level.signum();4657 let candidate = level - level.signum();
4616 levels[i] = candidate;4658 levels[i] = candidate;
4659+ budget -= 1;
4617 let after = price(levels, &mut dense, side, coded, set, q_ctx, skip_ctx, sign_ctx);4660 let after = price(levels, &mut dense, side, coded, set, q_ctx, skip_ctx, sign_ctx);
4618 let distortion = weight4661 let distortion = weight
4619 * ((s - f64::from(candidate)).powi(2) - (s - f64::from(level)).powi(2));4662 * ((s - f64::from(candidate)).powi(2) - (s - f64::from(level)).powi(2));
lanes/rdoq-ctl.logmodified+26 -0
@@ -18,3 +18,29 @@ bars 2160p: inter var-tx depths of 9166 blocks -- leaf single 0=1267 1=519 (29.1
18 bars 2160p: screen frames on=0 off=4 (0.0% on); palette blocks luma 0 chroma 0; intrabc blocks 0 (searched 0 / valid 0 / won 0)18 bars 2160p: screen frames on=0 off=4 (0.0% on); palette blocks luma 0 chroma 0; intrabc blocks 0 (searched 0 / valid 0 / won 0)
19 bars 2160p: filter intra on=true blocks 13065 (modes DC=3422 V=776 H=2756 D157=4292 PAETH=1819)19 bars 2160p: filter intra on=true blocks 13065 (modes DC=3422 V=776 H=2756 D157=4292 PAETH=1819)
20 | bars 2160p 1920x1024 | 43.68 dB/232087 B, 47.61 dB/341622 B, 51.20 dB/455971 B, 54.53 dB/583936 B | +12.7% | -9.8% | 43.1s:6.3s:20.9s |20 | bars 2160p 1920x1024 | 43.68 dB/232087 B, 47.61 dB/341622 B, 51.20 dB/455971 B, 54.53 dB/583936 B | +12.7% | -9.8% | 43.1s:6.3s:20.9s |
21+film A (1080p source): sequence, pyramid requested Some(Pyramid { mini_gop: 8, arf_q_offset: -32, leaf_q_offset: 12, mid_q_offset: Some(-8), quarter_q_offset: None, key_q_offset: -48 }) effective Some(Pyramid { mini_gop: 8, arf_q_offset: -32, leaf_q_offset: 12, mid_q_offset: Some(-8), quarter_q_offset: None, key_q_offset: -48 })
22+film A (1080p source): pricer armings default=20 real=213
23+film A (1080p source): motion_mode 32x32 SIMPLE=41201 OBMC=0 WARP=1328 | 16x16 SIMPLE=20494 OBMC=0 WARP=1604 | 8x8 SIMPLE=4922 OBMC=0 WARP=846 (0.0% OBMC / 5.4% WARP of 70395 eligible)
24+film A (1080p source): inter var-tx depths of 86180 blocks -- leaf single 0=13762 1=2584 (15.8% split) | leaf compound 0=33584 1=6988 (17.2% split) | 32x32 single 0=7232 1=5556 (43.4% split) | 32x32 compound 0=10091 1=6383 (38.7% split)
25+film A (1080p source): screen frames on=0 off=4 (0.0% on); palette blocks luma 0 chroma 0; intrabc blocks 0 (searched 0 / valid 0 / won 0)
26+film A (1080p source): filter intra on=true blocks 24046 (modes DC=6056 V=3557 H=4424 D157=6925 PAETH=3084)
27+| film A (1080p source) 1920x768 | 44.24 dB/75308 B, 45.83 dB/125849 B, 47.06 dB/217800 B, 48.32 dB/519421 B | +37.1% | +7.3% | 77.1s:11.0s:16.9s |
28+film B (2160p HDR source): sequence, pyramid requested Some(Pyramid { mini_gop: 8, arf_q_offset: -32, leaf_q_offset: 12, mid_q_offset: Some(-8), quarter_q_offset: None, key_q_offset: -48 }) effective Some(Pyramid { mini_gop: 8, arf_q_offset: -32, leaf_q_offset: 12, mid_q_offset: Some(-8), quarter_q_offset: None, key_q_offset: -48 })
29+film B (2160p HDR source): pricer armings default=20 real=190
30+film B (2160p HDR source): motion_mode 32x32 SIMPLE=51492 OBMC=0 WARP=1137 | 16x16 SIMPLE=13701 OBMC=0 WARP=1016 | 8x8 SIMPLE=2084 OBMC=0 WARP=450 (0.0% OBMC / 3.7% WARP of 69880 eligible)
31+film B (2160p HDR source): inter var-tx depths of 75943 blocks -- leaf single 0=12882 1=2214 (14.7% split) | leaf compound 0=28716 1=5173 (15.3% split) | 32x32 single 0=7785 1=5849 (42.9% split) | 32x32 compound 0=8393 1=4931 (37.0% split)
32+film B (2160p HDR source): screen frames on=0 off=4 (0.0% on); palette blocks luma 0 chroma 0; intrabc blocks 0 (searched 0 / valid 0 / won 0)
33+film B (2160p HDR source): filter intra on=true blocks 18034 (modes DC=4989 V=2447 H=2570 D157=6251 PAETH=1777)
34+| film B (2160p HDR source) 1920x1024 | 46.74 dB/34523 B, 48.06 dB/70377 B, 49.16 dB/149444 B, 50.29 dB/398789 B | +52.5% | +22.3% | 78.1s:22.4s:16.4s |
35+screen capture (2026-07-25 02-09-04.mkv): sequence, pyramid requested Some(Pyramid { mini_gop: 8, arf_q_offset: -32, leaf_q_offset: 12, mid_q_offset: Some(-8), quarter_q_offset: None, key_q_offset: -48 }) effective None
36+screen capture (2026-07-25 02-09-04.mkv): pricer armings default=155 real=0
37+screen capture (2026-07-25 02-09-04.mkv): motion_mode 32x32 SIMPLE=23654 OBMC=0 WARP=160 | 16x16 SIMPLE=1322 OBMC=0 WARP=318 | 8x8 SIMPLE=562 OBMC=0 WARP=576 (0.0% OBMC / 4.0% WARP of 26592 eligible)
38+screen capture (2026-07-25 02-09-04.mkv): inter var-tx depths of 34092 blocks -- leaf single 0=5772 1=7043 (55.0% split) | leaf compound 0=2826 1=2851 (50.2% split) | 32x32 single 0=6059 1=8017 (57.0% split) | 32x32 compound 0=860 1=664 (43.6% split)
39+screen capture (2026-07-25 02-09-04.mkv): screen frames on=48 off=0 (100.0% on); palette blocks luma 9907 chroma 1109; intrabc blocks 0 (searched 0 / valid 0 / won 0)
40+screen capture (2026-07-25 02-09-04.mkv): filter intra on=true blocks 8198 (modes DC=98 V=2410 H=5376 D157=223 PAETH=91)
41+| screen capture (2026-07-25 02-09-04.mkv) 1920x1024 | 45.87 dB/40155 B, 48.55 dB/51325 B, 50.86 dB/63998 B, 53.07 dB/80203 B | +33.4% | -23.8% | 45.1s:10.3s:14.4s |
42+ok
43+
44+test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 602 filtered out; finished in 457.99s
45+
46+RC=0
lanes/rdoq-l07.logadded+6 -0
@@ -0,0 +1,6 @@
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+|---|---|---|---|---|
lanes/rdoq-r2.logadded+6 -0
@@ -0,0 +1,6 @@
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+|---|---|---|---|---|