From d8a0bf959b1dfa45014e16bc09897324957cde82 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 09:53:52 +0300 Subject: [PATCH] docs(av1): lane-split report -- the split lambda swept, control wins, census shipped Also extracts split_census_base and enumerates its whole domain in a test. --- crates/ec-av1/src/encode.rs | 31 ++++++++- lanes/split.report.md | 130 ++++++++++++++++++++++++++++++++++++ 2 files changed, 158 insertions(+), 3 deletions(-) create mode 100644 lanes/split.report.md diff --git a/crates/ec-av1/src/encode.rs b/crates/ec-av1/src/encode.rs index ba984fd7..87e10e72 100644 --- a/crates/ec-av1/src/encode.rs +++ b/crates/ec-av1/src/encode.rs @@ -4283,6 +4283,13 @@ pub(crate) fn split_census_on() -> bool { *ON } +/// Where one (site, frame type, block side) bucket starts in [`SPLIT_CENSUS`]. +/// Sides below 8 and above 64 fold into the end rows, which no caller offers. +fn split_census_base(site: usize, key: bool, side: usize) -> usize { + let side_idx = (side.trailing_zeros() as usize).saturating_sub(3).min(3); + ((site * 2 + usize::from(!key)) * 4 + side_idx) * 10 +} + /// Records one split trial into [`SPLIT_CENSUS`]. `split` and `flat` are each /// `(rate in bits, distortion as squared error)`. fn split_census( @@ -4294,8 +4301,7 @@ fn split_census( flat: (f64, f64), ) { use std::sync::atomic::Ordering::Relaxed; - let side_idx = (side.trailing_zeros() as usize).saturating_sub(3).min(3); - let base = ((site * 2 + usize::from(!key)) * 4 + side_idx) * 10; + let base = split_census_base(site, key, side); let add = |i: usize, v: u64| { SPLIT_CENSUS[base + i].fetch_add(v, Relaxed); }; @@ -4326,7 +4332,7 @@ pub(crate) fn dump_split_census() { for site in 0..2 { for key in [true, false] { for side_idx in 0..4 { - let base = ((site * 2 + usize::from(!key)) * 4 + side_idx) * 10; + let base = split_census_base(site, key, 8 << side_idx); let v: [u64; 10] = std::array::from_fn(|i| SPLIT_CENSUS[base + i].load(Relaxed)); if v[0] == 0 { continue; @@ -12314,6 +12320,25 @@ pub(crate) fn encode_sequence_with_ctx( #[cfg(test)] mod tests { + /// Every (site, frame type, block side) the census can be called with + /// lands in its own ten-counter bucket, inside the array (class + /// `enumerate-table-domain`: an off-by-one here would silently add two + /// sites' trials together). + #[test] + fn the_split_census_buckets_are_distinct_and_in_bounds() { + let mut seen = std::collections::BTreeSet::new(); + for site in 0..2 { + for key in [true, false] { + for side in [8usize, 16, 32, 64] { + let base = super::split_census_base(site, key, side); + assert!(base + 10 <= super::SPLIT_CENSUS.len(), "{site} {key} {side}"); + assert!(seen.insert(base), "{site} {key} {side} collides"); + } + } + } + assert_eq!(seen.len(), 16); + } + /// An [`crate::mvstack::MvStack`] with every context at zero and no /// neighbours, for the pricer tests below to fill the one band each of /// them is about. diff --git a/lanes/split.report.md b/lanes/split.report.md new file mode 100644 index 00000000..0a4ad677 --- /dev/null +++ b/lanes/split.report.md @@ -0,0 +1,130 @@ +# lane-split — the split decision's own calibration: swept, and the control wins + +lane-txd left one live hypothesis behind its refuted arm (class +`rd-rate-term-calibration`): the correct `tx_depth` price is a one-sided push +AWAY from splitting, so maybe what is mis-calibrated is the weight the split +trial's rate is judged under, not the price. This lane restored the correct +pricing (`60c3cdf6` + its pins), built the knob and the census, and swept. +The sweep is single-peaked and its peak IS the control weight, and every +point on it is worse than the row-0-priced control. The pricing fix goes back +out again; the census and the swept knob stay. + +## The knob + +`EC_AV1_SPLIT_LAMBDA` (`encode::split_lambda_mult`, constant `SPLIT_LAMBDA = +1.0`) multiplies the RATE term of the transform-SPLIT trial only — the intra +`tx_depth` depth>0 candidates in `code_square` and the inter var-tx depth-1 +trial in `commit_inter_luma`. Below 1 the split is charged less for its bits +and fires more; above 1, less. The flat arm is untouched, so this is exactly +the depth-0-versus-split margin and nothing else. + +## Sweep — film B gate row, WITH the correct `tx_depth` pricing on + +Deciding gate, 12-frame native, BD-rate vs libaom cpu-used 6 / rav1e speed 6. + +| `EC_AV1_SPLIT_LAMBDA` | film B | bars 2160p | +|---|---|---| +| 0.6 | +28.4 / +0.5 | +10.5 / −11.8 | +| 0.8 | +26.1 / −0.9 | +10.0 / −12.2 | +| **1.0 (control weight)** | **+25.2 / −1.6** | **+8.7 / −13.4** | +| 1.25 | +25.9 / −1.1 | +8.9 / −13.2 | +| 1.5 | +26.2 / −0.9 | +9.3 / −13.0 | +| 2.0 | +26.3 / −0.8 | +11.7 / −11.4 | +| — control, row-0 pricing (`2caf213b`) | **+24.9 / −1.9** | +8.7 / −13.4 | + +The λ=1.0 row reproduces lane-txd's arm to the decimal, so the sweep is +against a reproduced control. The curve has ONE optimum, it sits at the +weight the encoder already uses, and it is still 0.3 worse on both columns +than the row-0-priced control. No re-weighting of the split's rate recovers +what correct pricing costs — so the split trial's λ was not the mis-calibrated +term either, and the class `rd-rate-term-calibration` reading of lane-txd's +result is refuted on its own terms. + +## Census 1 — the split DECISION (`EC_AV1_SPLIT_CENSUS=1`) + +Film B gate crop, 12 frames, q150, the shipped (row-0-priced) encoder. Rows +are TRIALS OFFERED by the RD search, which includes partition candidates that +later lose — not coded blocks; the coded-block view is census 2 below. + +``` +site frame side offered split share% win_rate win_dist lose_rate lose_dist +intra key 16 7504 1671 22.3 19.07 335 25.97 444 +intra key 32 1876 166 8.8 62.25 1381 78.58 1553 +intra inter 8 12424 4620 37.2 9.26 362 10.26 533 +intra inter 16 4704 942 20.0 23.29 1714 28.73 2109 +inter inter 16 1711 167 9.8 14.96 1480 21.14 1741 +inter inter 32 936 250 26.7 37.86 5869 38.32 6302 +inter inter 64 5280 483 9.1 15.77 8333 16.02 8461 +``` + +`win_rate`/`lose_rate` are bits (including the `tx_depth` / `txfm_split` +symbols), `win_dist`/`lose_dist` squared error. Read: the winner is cheaper on +BOTH terms in every row — the loser is never a rate-versus-distortion trade +the weight could tip, which is the same thing the sweep says from the outside. + +With the correct pricing ON the shares fall exactly where lane-txd's price +table predicts (intra key 16: 22.3% → 21.0%, intra inter 8: 37.2% → 32.9%, +inter var-tx 32: 26.7% → 27.9%) — a 4-point drop on the inter frame's intra +blocks, which are the 66% ctx-2 population. + +## Census 2 — ours vs libaom, coded blocks, same crop and rate + +Both streams read by OUR decoder (`EC_AV1_BITCENSUS=1 syntax_census`), film B +gate crop 1920x1024 @ 00:40:00, 12 frames, `-g 12`. Ours q150 = 27343 payload +bytes; libaom `-cpu-used 6 -crf 30` = 28590. Split share = the share of coded +blocks whose PUBLISHED luma transform is smaller than the block, read as the +mass the tx-size histogram moves down against the block-size histogram. + +| | key frame | whole stream | +|---|---|---| +| ours | 4.8% | 1.0% | +| libaom crf 30 | 7.6% | 2.1% | + +libaom splits about twice as often as we do at the same rate — so we are on +the LOW side of libaom's split rate, and the sweep says every step toward +libaom's rate (λ 0.8, 0.6) costs 1.2 and 3.5 BD points on film B. The split +rate is not where film B's +25% lives; a lane that goes after it by moving +this margin is measuring the wrong knob. + +## Gate — the shipped tree + +Encoder output is BYTE-IDENTICAL to `2caf213b` (both stream pins green and +UNMOVED at 8325 / 33014, at the default preset and at `EC_AV1_SPEED=6`), so +the rows are the control's, re-measured here: + +| row | shipped | +|---|---| +| film A | +21.0 / −4.8 | +| film B | +24.9 / −1.9 | +| screen | +14.5 / −33.2 | +| bars 1080p | −2.0 / −17.6 | +| bars 2160p | +8.7 / −13.4 | + +`bd_rate_film_long_gop` was not run: nothing ships that moves a byte. + +## Suite + +* `--skip stream::` 338 passed / 0 failed / 32 ignored; `stream:: --skip + 10bit` 200 / 0 / 15; `10bit` 42 / 0 / 1. All RC=0. +* `--ignored encoder::tests::every_speed_preset_decodes_sample_exact_through_both_decoders` + passed. +* `encode::tests::the_split_census_buckets_are_distinct_and_in_bounds` — the + census index enumerated over its whole domain (class + `enumerate-table-domain`). +* `timeout 900 cargo check --workspace --all-targets -j4`: 0 errors, 0 ec-av1 + warnings. + +## Disposition + +`deferred: the tx_depth context pricing — built twice (lane-ctx2, lane-txd), +now swept against its own split weight and still losing at every point. What +would unblock it is NOT another calibration knob on this margin: the census +says the losing arm is worse on rate AND distortion together, so the depth +trial is choosing between two arms the search already separates cleanly. +Whatever film B's +25% is, it is not the transform-split margin.` + +`deferred: a bug found while building the census — encoder.rs used +bool::then_some to build a Drop guard, which CONSTRUCTS and then DROPS the +guard when the flag is off. Fixed here (then_some -> then); no other +then_some in the crate builds a value with a Drop impl (grep: 3 hits, all +Copy scalars).`