From 92428b38651d5c33bcb5d0890564e2370e6af8f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Mon, 7 Sep 2026 07:17:55 +0300 Subject: [PATCH] perf(av1): re-sweep the coding pyramid on real film -- 16:-24:16 The shipped 4:-16:8 was chosen when the BD gate's "film" rows were still testsrc2 colour bars, and CfL, the luma angle deltas, filter intra, the propagating tpl map and the rate-loop step have all landed since, so the shape was unswept on real content (class `unswept decision constants`). Swept through the gate's own EC_AV1_PYRAMID knob on the two real film rows of encode::tests::bd_rate_screen_native: the mini-GOP axis at the shipped offsets, then both offset axes at the best mini-GOP, then the joint corners (21 arms, table in Pyramid::default and lanes/pyr3.sweep.txt). 16:-24:16 takes 8.6 / 7.6 BD points off film A and 10.5 / 10.9 off film B against 4:-16:8 (vs libaom / vs rav1e); the screen row is byte-identical in every arm because the content gate codes it flat. Leaf +16 was the swept range's edge and still improving on film A, so two arms past it were run: film B turns back up at +20, so +16 is where both films are minimal. Pins re-taken: encode_sequence codes the 4-picture pin clip as one truncated group now (hidden ALTREF at q-24, three leaves at q+16), 7373 -> 8076 at q=150 and 27074 -> 27585 at q=60; EC_AV1_PYRAMID=4:-16:8 restores them. --- crates/ec-av1/src/encode.rs | 8 ++++- crates/ec-av1/src/encoder.rs | 57 ++++++++++++++++++++++++++++++++++-- lanes/pyr3.sweep.txt | 23 +++++++++++++++ 3 files changed, 84 insertions(+), 4 deletions(-) create mode 100644 lanes/pyr3.sweep.txt diff --git a/crates/ec-av1/src/encode.rs b/crates/ec-av1/src/encode.rs index bcf7862c..7b3b3870 100644 --- a/crates/ec-av1/src/encode.rs +++ b/crates/ec-av1/src/encode.rs @@ -13006,6 +13006,12 @@ mod tests { // so every block taking either codes different syntax and different // coefficients -- 8194 -> 7321 at q=150 and 28285 -> 27285 at q=60. // `EC_AV1_CFL=0` / `EC_AV1_ANGLE=0` restore each half. + // Re-taken on lane-pyr3: the mini-GOP of the default pyramid is 16 + // pictures at `q-24` / `q+16` now (the sweep in [`Pyramid::default`]), + // so these four pictures code as one truncated group -- a hidden + // ALTREF at `q-24` and three leaves at `q+16` -- instead of one + // mini-GOP of 4 at `q-16` / `q+8`: 7373 -> 8076 at q=150 and + // 27074 -> 27585 at q=60. `EC_AV1_PYRAMID=4:-16:8` restores these. // Re-taken on lane-fintra: the sequence header sets // `enable_filter_intra`, so every DC_PRED intra block of at most // 32x32 without a luma palette carries a `use_filter_intra` flag and @@ -13013,7 +13019,7 @@ mod tests { // prediction and different coefficients -- 7321 -> 7373 at q=150 and // 27285 -> 27074 at q=60. `EC_AV1_FILTER_INTRA=0` restores these. let pins: [(u8, usize, u64); 2] = - [(150, 7373, 0xd0af_b890_28bc_cfbf), (60, 27074, 0x8324_0e9f_5971_e4e7)]; + [(150, 8076, 0x8171_4818_e223_ab21), (60, 27585, 0xdbe7_eecd_6d64_c4f5)]; for (q, bytes, hash) in pins { let encoded = encode_sequence(&source, q, 0.5).unwrap(); assert_eq!( diff --git a/crates/ec-av1/src/encoder.rs b/crates/ec-av1/src/encoder.rs index 85d4fea0..2dc98f1d 100644 --- a/crates/ec-av1/src/encoder.rs +++ b/crates/ec-av1/src/encoder.rs @@ -542,11 +542,62 @@ impl Default for Pyramid { /// entry point still codes flat, since a picture no longer maps to a /// packet under a pyramid — [`Av1Encoder::with_pyramid`] plus /// [`Av1Encoder::encode_frames`] is the streaming surface that reorders. + /// RE-SWEPT on lane-pyr3, on main 503d7aa9 -- `4:-16:8` was chosen when + /// the gate's "film" rows were still colour bars, and CfL, the luma + /// angle deltas, filter intra, the propagating tpl map and the rate-loop + /// step have all landed since (class `unswept decision constants`). The + /// axes were swept in the order mini-GOP first at the shipped offsets, + /// then both offset axes at the best mini-GOP, then the joint corners + /// (`encode::tests::bd_rate_screen_native`, BD-rate vs libaom / vs + /// rav1e; the bars rows move by at most 4 points across the WHOLE sweep + /// and decide nothing, the screen row is byte-identical in every arm + /// because the content gate codes it flat): + /// + /// | arm | film A | film B | + /// |---|---|---| + /// | flat (no pyramid) | +61.4 / +31.3 | +85.3 / +49.7 | + /// | 2:-16:8 | +59.2 / +28.1 | +82.3 / +49.1 | + /// | 4:-16:8 (was shipped) | +52.8 / +23.3 | +81.0 / +46.1 | + /// | 8:-16:8 | +54.3 / +24.4 | +81.8 / +45.8 | + /// | 16:-16:8 | +50.8 / +21.4 | +73.8 / +38.7 | + /// | 8:-8:8 | +58.0 / +27.5 | +83.3 / +46.5 | + /// | 8:-24:8 | +52.7 / +23.4 | +83.7 / +48.4 | + /// | 8:-32:8 | +52.3 / +23.1 | +86.8 / +51.9 | + /// | 8:-16:0 | +60.7 / +30.7 | +85.3 / +51.2 | + /// | 8:-16:4 | +57.6 / +27.4 | +84.1 / +48.6 | + /// | 8:-16:12 | +51.8 / +22.2 | +80.4 / +43.9 | + /// | 8:-16:16 | +50.1 / +20.5 | +80.6 / +43.4 | + /// | 16:-24:8 | +47.8 / +19.0 | +71.5 / +37.4 | + /// | 16:-16:12 | +48.0 / +18.9 | +71.1 / +35.7 | + /// | 16:-16:16 | +45.9 / +17.0 | +69.3 / +34.0 | + /// | 16:-24:12 | +45.6 / +17.0 | +70.2 / +35.6 | + /// | **16:-24:16** | **+44.2 / +15.7** | **+70.5 / +35.2** | + /// | 16:-32:16 | +43.6 / +15.2 | +71.2 / +36.2 | + /// | 16:-24:20 (past the swept range) | +42.9 / +14.5 | +70.8 / +34.9 | + /// | 16:-24:24 (past the swept range) | +42.6 / +14.1 | +71.3 / +35.7 | + /// + /// `16:-24:16` ships: it takes 8.6 / 7.6 points off film A and 10.5 / + /// 10.9 off film B against the old defaults, and every axis through it + /// is at or next to its own minimum. The two arms past the swept leaf + /// range were run because leaf `+16` was the range's edge and still + /// improving (class `instrument at bound`): film A keeps falling to + /// `+24` but film B turns back up at `+20`, so `+16` is where BOTH films + /// are minimal and the bound is not the answer. Deeper ARF is the same + /// shape -- `-32` buys 0.6 on film A and gives 0.7 back on film B. + /// + /// TWO THINGS THIS SWEEP DOES NOT SAY. The mini-GOP axis is measured + /// against a gate that codes 12 frames with `gop = 12`, and a group is + /// cut at every key frame (`encode_frames`), so `16` here is really + /// "one hidden ARF per GOP" and any mini-GOP over 12 codes the same + /// stream; on a stream with a longer GOP `16` is a genuine 16-picture + /// group, which this gate cannot measure. And the offsets were swept at + /// mini-GOP 8 before 16 won the first axis; the two joint corners at 16 + /// confirm the same gradient, but the full grid at 16 is not measured. fn default() -> Self { Self { - mini_gop: 4, - arf_q_offset: -16, - leaf_q_offset: 8, + mini_gop: 16, + arf_q_offset: -24, + leaf_q_offset: 16, } } } diff --git a/lanes/pyr3.sweep.txt b/lanes/pyr3.sweep.txt new file mode 100644 index 00000000..bfb1501e --- /dev/null +++ b/lanes/pyr3.sweep.txt @@ -0,0 +1,23 @@ +lane-pyr3 pyramid shape sweep on main 503d7aa9 (bd_rate_screen_native, BD-rate vs libaom / vs rav1e) +arm film A film B screen +flat +61.4%|+31.3% +85.3%|+49.7% +49.2%|-16.0% +2:-16:8 +59.2%|+28.1% +82.3%|+49.1% +4:-16:8 +52.8%|+23.3% +81.0%|+46.1% +49.2%|-16.0% +8:-16:8 +54.3%|+24.4% +81.8%|+45.8% +16:-16:8 +50.8%|+21.4% +73.8%|+38.7% +8:-8:8 +58.0%|+27.5% +83.3%|+46.5% +8:-24:8 +52.7%|+23.4% +83.7%|+48.4% +8:-32:8 +52.3%|+23.1% +86.8%|+51.9% +8:-16:0 +60.7%|+30.7% +85.3%|+51.2% +8:-16:4 +57.6%|+27.4% +84.1%|+48.6% +8:-16:12 +51.8%|+22.2% +80.4%|+43.9% +8:-16:16 +50.1%|+20.5% +80.6%|+43.4% +16:-24:8 +47.8%|+19.0% +71.5%|+37.4% +16:-16:12 +48.0%|+18.9% +71.1%|+35.7% +16:-16:16 +45.9%|+17.0% +69.3%|+34.0% +16:-24:12 +45.6%|+17.0% +70.2%|+35.6% +16:-24:16 +44.2%|+15.7% +70.5%|+35.2% +16:-32:16 +43.6%|+15.2% +71.2%|+36.2% +16:-24:20 +42.9%|+14.5% +70.8%|+34.9% +16:-24:24 +42.6%|+14.1% +71.3%|+35.7% +16:-24:16 +44.2%|+15.7% +70.5%|+35.2% +49.2%|-16.0%