Re-judge the encoder's rate weight and var-tx depth on real film
Browse files at this commit70ddd6aedc4b71bbcd78bf57a48dfc138e885eabParent: aea57e3- perf
- re-judge the encoder's rate weight and var-tx depth on real film
1 changed file +61 -10
- crates/ec-av1/src/encode.rs +61 -10
crates/ec-av1/src/encode.rsmodified+61 -10
| @@ -109,12 +109,33 @@ fn reach_sb_px(fctx: &crate::decode::FrameCtx) -> usize { | |||
| 109 | /// | 0.05 | +17.0 / -0.3 | +47.0 / +19.2 | +51.6 / -14.2 | | 109 | /// | 0.05 | +17.0 / -0.3 | +47.0 / +19.2 | +51.6 / -14.2 | |
| 110 | /// | 0.1 | +18.1 / +0.9 | +47.1 / +19.0 | +58.3 / -9.8 | | 110 | /// | 0.1 | +18.1 / +0.9 | +47.1 / +19.0 | +58.3 / -9.8 | |
| 111 | /// | 111 | /// |
| 112 | -/// 0.0375 is the best point on two clips of three and costs the 2160p film | 112 | +/// 0.0375 was the best point on two clips of three there and cost the "2160p |
| 113 | -/// +0.4/+0.7, outside the +-0.3 band every other lever here is kept inside, | 113 | +/// film" row +0.4/+0.7, outside the +-0.3 band every other lever here is kept |
| 114 | -/// so 0.05 ships: two clips down on both columns, the 2160p film flat | 114 | +/// inside, so 0.05 shipped. BOTH of those tables' "film" rows are the |
| 115 | -/// (-0.1 / +0.2). It also spends ~8% more encode wall, the bits it stopped | 115 | +/// `testsrc2` COLOUR BARS fixtures (see [`bd_rate_screen_native`]), ~90% of |
| 116 | -/// refusing. | 116 | +/// whose cells have no intra cost -- no real film supported the point. |
| 117 | -const LAMBDA_SCALE: f64 = 0.05; | 117 | +/// |
| 118 | +/// FIFTH SWEEP (lane-av1resweep, 2026-09-07), on the native gate's two REAL | ||
| 119 | +/// film crops (film A 1080p, film B 2160p HDR) plus the capture, BD-rate vs | ||
| 120 | +/// libaom / vs rav1e, everything else at the shipped defaults: | ||
| 121 | +/// | ||
| 122 | +/// | lambda | bars 1080p | bars 2160p | film A | film B | screen | | ||
| 123 | +/// |--------|------------|------------|--------|--------|--------| | ||
| 124 | +/// | 0.02 | +17.5 / -0.2 | +49.7 / +21.7 | +65.8 / +35.0 | +91.2 / +55.4 | +53.4 / -14.1 | | ||
| 125 | +/// | 0.0275 | +16.6 / -0.9 | +48.3 / +20.5 | +65.5 / +34.7 | +91.6 / +55.1 | +51.3 / -15.0 | | ||
| 126 | +/// | 0.035 | +16.1 / -1.3 | +47.5 / +19.7 | +66.4 / +35.2 | +94.2 / +56.9 | +50.8 / -15.1 | | ||
| 127 | +/// | 0.05 | +15.6 / -1.7 | +46.5 / +18.8 | +69.0 / +37.5 | +100.0 / +61.5 | +51.0 / -14.5 | | ||
| 128 | +/// | 0.07 | +16.6 / -0.5 | +46.8 / +18.8 | +72.3 / +40.4 | +108.5 / +68.8 | +54.4 / -12.4 | | ||
| 129 | +/// | 0.1 | +16.5 / -0.7 | +46.6 / +18.7 | +76.9 / +44.4 | +118.2 / +77.1 | +57.3 / -10.1 | | ||
| 130 | +/// | ||
| 131 | +/// Real film wants roughly HALF the rate weight the bars asked for: the bowl | ||
| 132 | +/// on both film rows bottoms between 0.02 and 0.0275 and is 5-11 points deep | ||
| 133 | +/// against the shipped 0.05, while the bars rows walk the other way (they are | ||
| 134 | +/// recorded, not decided on). 0.02 breaks the capture (+2.4 vs libaom), so | ||
| 135 | +/// 0.0275 ships -- both films 3.5/8.4 points down vs libaom, the capture | ||
| 136 | +/// +0.3/-0.5 (at the +-0.3 band, and better than baseline once the var-tx | ||
| 137 | +/// defaults below are on: +50.1 / -15.4). It spends ~5% more encode wall. | ||
| 138 | +const LAMBDA_SCALE: f64 = 0.0275; | ||
| 118 | 139 | ||
| 119 | /// [`LAMBDA_SCALE`], or whatever `EC_AV1_LAMBDA` names when the sweep that | 140 | /// [`LAMBDA_SCALE`], or whatever `EC_AV1_LAMBDA` names when the sweep that |
| 120 | /// picks it is the thing running. A release build has no such knob. | 141 | /// picks it is the thing running. A release build has no such knob. |
| @@ -2933,18 +2954,44 @@ static INTER_TX_SPLIT_HITS: [std::sync::atomic::AtomicUsize; 8] = | |||
| 2933 | 2954 | ||
| 2934 | /// Whether a 32x32 inter winner searches its own var-tx depth (the four | 2955 | /// Whether a 32x32 inter winner searches its own var-tx depth (the four |
| 2935 | /// 16x16 units against the flat transform) instead of coding depth 0 blind. | 2956 | /// 16x16 units against the flat transform) instead of coding depth 0 blind. |
| 2936 | -/// `EC_AV1_TX32_DEPTH`. | 2957 | +/// ON by default; `EC_AV1_TX32_DEPTH=0` turns it off. |
| 2958 | +/// | ||
| 2959 | +/// Rejected three times on the bars rows of the native gate (flat to +0.3). | ||
| 2960 | +/// lane-av1resweep re-judged it on the two REAL film crops at | ||
| 2961 | +/// [`LAMBDA_SCALE`] 0.05, where it is the largest single lever in this file | ||
| 2962 | +/// (BD vs libaom / vs rav1e, shipped -> `EC_AV1_TX32_DEPTH=1`): | ||
| 2963 | +/// | ||
| 2964 | +/// | clip | shipped | tx32 depth | + [`compound_var_tx`] | | ||
| 2965 | +/// |---|---|---|---| | ||
| 2966 | +/// | bars 1080p | +15.6 / -1.7 | +15.7 / -1.5 | +15.6 / -1.6 | | ||
| 2967 | +/// | bars 2160p | +46.5 / +18.8 | +46.5 / +18.8 | +46.6 / +18.8 | | ||
| 2968 | +/// | film A | +69.0 / +37.5 | +67.9 / +36.3 | +65.5 / +34.7 | | ||
| 2969 | +/// | film B | +100.0 / +61.5 | +96.6 / +58.4 | +94.5 / +56.9 | | ||
| 2970 | +/// | screen | +51.0 / -14.5 | +50.7 / -14.4 | +50.2 / -14.6 | | ||
| 2971 | +/// | ||
| 2972 | +/// The bars rows are ~90% zero-intra-cost cells, so the split never had | ||
| 2973 | +/// residual to reach there -- the tool was being judged on content that | ||
| 2974 | +/// cannot pay for it (class `gate-blind-to-feature`). `EC_AV1_TX32_DEPTH`. | ||
| 2937 | fn tx32_depth_search() -> bool { | 2975 | fn tx32_depth_search() -> bool { |
| 2938 | - crate::envflags::env_flag!("EC_AV1_TX32_DEPTH") | 2976 | + static ON: std::sync::LazyLock<bool> = std::sync::LazyLock::new(|| { |
| 2977 | + !matches!(crate::envflags::var("EC_AV1_TX32_DEPTH").as_deref(), Ok("0") | Ok("off")) | ||
| 2978 | + }); | ||
| 2979 | + *ON | ||
| 2939 | } | 2980 | } |
| 2940 | 2981 | ||
| 2941 | /// Whether a COMPOUND inter winner is offered the var-tx split at all: its | 2982 | /// Whether a COMPOUND inter winner is offered the var-tx split at all: its |
| 2942 | /// trial units have to be predicted from BOTH references | 2983 | /// trial units have to be predicted from BOTH references |
| 2943 | /// ([`mc_trial_compound`]) or the split would re-predict them by single- | 2984 | /// ([`mc_trial_compound`]) or the split would re-predict them by single- |
| 2944 | /// reference translation, which is not what the decoder reconstructs. | 2985 | /// reference translation, which is not what the decoder reconstructs. |
| 2986 | +/// ON by default (the table on [`tx32_depth_search`]: on real film it is | ||
| 2987 | +/// worth a further -2.4/-1.6 on film A and -2.1/-1.5 on film B on top of the | ||
| 2988 | +/// 32x32 depth search); `EC_AV1_COMP_VARTX=0` turns it off. | ||
| 2945 | /// `EC_AV1_COMP_VARTX`. | 2989 | /// `EC_AV1_COMP_VARTX`. |
| 2946 | fn compound_var_tx() -> bool { | 2990 | fn compound_var_tx() -> bool { |
| 2947 | - crate::envflags::env_flag!("EC_AV1_COMP_VARTX") | 2991 | + static ON: std::sync::LazyLock<bool> = std::sync::LazyLock::new(|| { |
| 2992 | + !matches!(crate::envflags::var("EC_AV1_COMP_VARTX").as_deref(), Ok("0") | Ok("off")) | ||
| 2993 | + }); | ||
| 2994 | + *ON | ||
| 2948 | } | 2995 | } |
| 2949 | 2996 | ||
| 2950 | /// How many 32x32-and-below inter blocks each reference frame won, indexed by | 2997 | /// How many 32x32-and-below inter blocks each reference frame won, indexed by |
| @@ -12394,6 +12441,10 @@ mod tests { | |||
| 12394 | /// [`LEAF_SECOND_NEW_MARGIN`] moved 0.8 -> 1.2. Re-pinned on lane-av1tpl: | 12441 | /// [`LEAF_SECOND_NEW_MARGIN`] moved 0.8 -> 1.2. Re-pinned on lane-av1tpl: |
| 12395 | /// every inter frame's superblocks now code at their own lambda | 12442 | /// every inter frame's superblocks now code at their own lambda |
| 12396 | /// ([`TPL_STRENGTH`]), so every RD decision in an inter frame moved. | 12443 | /// ([`TPL_STRENGTH`]), so every RD decision in an inter frame moved. |
| 12444 | + /// Re-pinned on lane-av1resweep: [`LAMBDA_SCALE`] moved 0.05 -> 0.0275 | ||
| 12445 | + /// and the two var-tx depth searches ([`tx32_depth_search`], | ||
| 12446 | + /// [`compound_var_tx`]) are on by default, all three re-judged on the | ||
| 12447 | + /// native gate's real film rows. | ||
| 12397 | #[test] | 12448 | #[test] |
| 12398 | fn the_encoders_own_streams_are_byte_identical_to_their_pins() { | 12449 | fn the_encoders_own_streams_are_byte_identical_to_their_pins() { |
| 12399 | if !have_ffmpeg() { | 12450 | if !have_ffmpeg() { |
| @@ -12415,7 +12466,7 @@ mod tests { | |||
| 12415 | }) | 12466 | }) |
| 12416 | }; | 12467 | }; |
| 12417 | let pins: [(u8, usize, u64); 2] = | 12468 | let pins: [(u8, usize, u64); 2] = |
| 12418 | - [(150, 7173, 0x3d5a_1440_7773_1816), (60, 26362, 0x2619_8199_39ad_828c)]; | 12469 | + [(150, 7299, 0xaa98_12b4_860a_28cc), (60, 26804, 0xedea_182d_e11b_3c3f)]; |
| 12419 | for (q, bytes, hash) in pins { | 12470 | for (q, bytes, hash) in pins { |
| 12420 | let encoded = encode_sequence(&source, q, 0.5).unwrap(); | 12471 | let encoded = encode_sequence(&source, q, 0.5).unwrap(); |
| 12421 | assert_eq!( | 12472 | assert_eq!( |