From e6bd6d8212debc9d64ca9ed836e93e3c99b8a7c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Tue, 8 Sep 2026 01:52:31 +0300 Subject: [PATCH] feat(av1): per-superblock delta_q on at presets 5 and 6, gated off screen content lane-deltaq measured the whole mapping sweep flat because the tpl lookahead was one picture; with the window back the map is real. 12-frame bd_rate_screen_native, BD vs libaom / vs rav1e, off -> on: preset 6: film A +27.2/-0.2 -> +26.6/-0.4, film B +35.2/+6.6 -> +34.7/+6.4 preset 5: film A +26.6/-0.7 -> +25.8/-1.1, film B +33.3/+4.9 -> +32.8/+4.6 preset 4: film B +29.9/+2.0 -> +30.2/+2.6 -- rejected The desktop capture was the only row delta_q cost, so the map is gated on !allow_screen_content_tools, the content gate b64_residual/b64_compound take: its four q points code the identical byte counts on and off. --- crates/ec-av1/src/encode.rs | 6 +++++ crates/ec-av1/src/speed.rs | 39 +++++++++++++++++----------- lanes/dq3.report.md | 52 +++++++++++++++++++++++++++++++++++++ 3 files changed, 82 insertions(+), 15 deletions(-) create mode 100644 lanes/dq3.report.md diff --git a/crates/ec-av1/src/encode.rs b/crates/ec-av1/src/encode.rs index 6c5fe0f7..98ed0b6a 100644 --- a/crates/ec-av1/src/encode.rs +++ b/crates/ec-av1/src/encode.rs @@ -10070,8 +10070,14 @@ pub(crate) fn encode_inter_frame( // tpl map the lambda factor comes from ([`deltaq_for_factor`]). Present // only when the map is, and `delta_q_res` follows straight into the frame // header (`write_delta_q_params`) and into the tile writer's own plan. + // Not on a screen frame ([`b64_residual`]'s content gate): lane-dq3 + // measured the per-superblock quantizer as a win on both films and a + // 0.5 loss vs libaom on the desktop capture, so a frame that set + // `allow_screen_content_tools` codes no delta syntax at all and stays + // byte-identical to the pre-lane encoder. let deltaq_res: Option = tpl_factors .as_ref() + .filter(|_| !screen) .and(deltaq_res_log2().map(|r| 1i32 << r)); let sb_q: Option> = match (&tpl_factors, deltaq_res) { (Some(f), Some(res)) => { diff --git a/crates/ec-av1/src/speed.rs b/crates/ec-av1/src/speed.rs index 50440701..7b1349d2 100644 --- a/crates/ec-av1/src/speed.rs +++ b/crates/ec-av1/src/speed.rs @@ -200,25 +200,34 @@ pub(crate) const I64_ROOT: [bool; 11] = [crate::encode::I64_ROOT; 11]; /// `encode::deltaq_res_log2`: the per-superblock quantizer's `delta_q_res` /// LOG2 (2 = a step of 4 qindex), or `4` for "no delta_q syntax at all". /// -/// SHIPPED OFF at every preset. lane-deltaq measured the whole mapping sweep -/// on the 12-frame native gate against its own control (film A +34.8/+5.0, -/// film B +47.0/+16.5, screen +33.4/-23.8): +/// ON (res 4) AT PRESETS 5 AND 6, off everywhere else, and never on a screen +/// frame -- `encode_inter_frame` gates the whole map on +/// `!allow_screen_content_tools`, the same content gate `b64_residual` and +/// `b64_compound` take, so a desktop capture codes no delta syntax and stays +/// byte-identical to the pre-lane encoder. /// -/// | arm | film A | film B | screen | +/// lane-deltaq measured the mapping sweep with the tpl lookahead still cut to +/// one picture, so the map it read was inert and every arm was flat. With the +/// window back (lane-tplwin) lane-dq2 re-measured and lane-dq3 shipped it, +/// 12-frame `bd_rate_screen_native`, BD vs libaom / vs rav1e, off -> on: +/// +/// | preset | film A | film B | screen capture | /// |---|---|---|---| -/// | res 4, K 1.0 | +34.7 / +5.2 | +46.7 / +16.6 | +34.1 / -23.6 | -/// | res 4, K 1.3 | +34.7 / +5.1 | +46.8 / +16.6 | +34.3 / -23.5 | -/// | res 8, K 1.0 | +35.2 / +5.3 | +47.8 / +17.1 | +35.0 / -23.4 | +/// | 6 | +27.2/-0.2 -> +26.6/-0.4 | +35.2/+6.6 -> +34.7/+6.4 | +26.0/-27.2, byte-identical | +/// | 5 | +26.6/-0.7 -> +25.8/-1.1 | +33.3/+4.9 -> +32.8/+4.6 | gated off | +/// | 4 | +23.7/-2.9 -> +23.1/-3.1 | +29.9/+2.0 -> +30.2/+2.6 | gated off | /// -/// The best arm moves neither film row by as much as the keep rule's 0.5 on -/// either column (film A -0.1/+0.2, film B -0.3/+0.1) and costs screen 0.7 -/// against libaom. Coarser steps (res 8) are worse everywhere. The syntax is -/// all there and proven three ways +/// Both films gain on both columns at 5 and 6 (the four q points of the +/// capture row code the identical byte counts on and off). PRESET 4 REJECTS +/// -- film B goes the wrong way on both columns there. Preset 3 rejects +/// (lane-dq2: film B worse on both columns) and preset 0 is neutral, so they +/// stay off. Coarser steps (res 8) were worse everywhere in lane-deltaq's +/// sweep. The syntax is proven three ways /// (`a_moving_detail_clip_codes_two_delta_q_levels_both_decoders_read_exactly`); -/// `EC_AV1_DELTAQ=2` switches it on. Above preset 6 it is inert anyway -- -/// [`TPL_DEPTH`] cuts the lookahead to one picture there, so there is no map -/// to vary the quantizer by (lane-tplwin gave presets 1..6 a window back). -pub(crate) const DELTAQ_RES: [u8; 11] = [4; 11]; +/// `EC_AV1_DELTAQ=2` forces it on at any preset, `EC_AV1_DELTAQ=0` off. +/// Above preset 6 it is inert anyway -- [`TPL_DEPTH`] cuts the lookahead to +/// one picture there, so there is no map to vary the quantizer by. +pub(crate) const DELTAQ_RES: [u8; 11] = [4, 4, 4, 4, 4, 2, 2, 4, 4, 4, 4]; /// `encode::SPLIT_RD_THRESHOLD`: how cheap a block has to be before its split /// trial is withheld. The single biggest wall lever in the tile search. diff --git a/lanes/dq3.report.md b/lanes/dq3.report.md new file mode 100644 index 00000000..c75ab6c7 --- /dev/null +++ b/lanes/dq3.report.md @@ -0,0 +1,52 @@ +# lane-dq3 -- per-superblock delta_q shipped at presets 5 and 6, gated off screen + +## Change + +* `crates/ec-av1/src/encode.rs` (`encode_inter_frame`, the `deltaq_res` binding): + `.filter(|_| !screen)` -- a frame that set `allow_screen_content_tools` codes + no delta syntax at all, the same content gate `b64_residual` / `b64_compound` + take. This is what makes the capture row byte-identical, at any preset and + even under `EC_AV1_DELTAQ=2`. +* `crates/ec-av1/src/speed.rs`: `DELTAQ_RES = [4,4,4,4,4,2,2,4,4,4,4]` -- + res 4 (`delta_q_res` log2 = 2) at presets 5 and 6, off everywhere else. + +## Measurement -- 12-frame `bd_rate_screen_native`, BD vs libaom / vs rav1e + +Control = same binary with `EC_AV1_DELTAQ=0`; arm = delta_q on. + +| preset | film A off -> on | film B off -> on | verdict | +|---|---|---|---| +| 6 | +27.2/-0.2 -> +26.6/-0.4 | +35.2/+6.6 -> +34.7/+6.4 | SHIP (both films, both columns) | +| 5 | +26.6/-0.7 -> +25.8/-1.1 | +33.3/+4.9 -> +32.8/+4.6 | SHIP (both films, both columns) | +| 4 | +23.7/-2.9 -> +23.1/-3.1 | +29.9/+2.0 -> +30.2/+2.6 | REJECT (film B worse on both) | +| 3 | (lane-dq2) | film B worse on both | REJECT | +| 0 | (lane-deltaq) neutral | | stays off | + +Preset 6 reproduces lane-dq2's numbers to the digit on both films. + +### Screen capture, preset 6 -- BYTE-IDENTICAL + +| arm | ours PSNR/bytes per point | vs libaom | vs rav1e | +|---|---|---|---| +| control | 45.40/37996, 48.11/46966, 50.55/58908, 52.93/74047 | +26.0% | -27.2% | +| shipped | 45.40/37996, 48.11/46966, 50.55/58908, 52.93/74047 | +26.0% | -27.2% | + +All four q points code the identical byte count; the row prints +`screen frames on=48 off=0`, so the gate is what is doing it. + +The two `testsrc2` bars rows are fixtures, not decisions (they move: 1080p ++68.4 -> +67.0, 2160p +62.7 -> +64.1). + +## Invariants (release binary) + +* `EC_COMP_MISMATCH=1 --include-ignored identically_with_one_and_four`: 3 passed + (decode / recon / filter thread determinism). +* `EC_COMP_MISMATCH=1 the_facade_codes_the_same_bytes_as_encode_sequence`: 1 passed. +* `--ignored every_speed_preset_decodes_sample_exact_through_both_decoders`: 1 passed. +* Bitrate pins unchanged (8562 / 33357), preset 0 untouched -- green inside the suite. +* `cargo test -p ec-av1 --release`: **568 passed, 0 failed, 45 ignored**. +* `cargo check --workspace --all-targets -j4`: 0 errors, 0 ec-av1 warnings. + +## Logs + +`$HOME/.cache/dq3/{p6-ship,p6-ctl,p5-on,p5-ctl,p4-on,p4-ctl,inv,suite}.log`.