From 5c1d094f315e65c27d41af516d4014ca2a3f8699 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 00:26:51 +0300 Subject: [PATCH] test(av1): the typed round trip covers 32x32 (IDTX); an le16 arm for the inter search The unconditional inter arm loses 20+ BD points on both synthetic bars rows of the 12-frame gate while film A gains 0.2; libaom's own census never codes IDTX at 32x32, so EC_AV1_TXSET_INTER=le16 offers the two-type set at 16x16 and below only. --- crates/ec-av1/src/encode.rs | 21 +++++++------ crates/ec-av1/src/transform.rs | 14 +++++++-- lanes/txset2.report.md | 56 ++++++++++++++++++++++++++++++++++ 3 files changed, 79 insertions(+), 12 deletions(-) diff --git a/crates/ec-av1/src/encode.rs b/crates/ec-av1/src/encode.rs index 9e511420..3ca7ca96 100644 --- a/crates/ec-av1/src/encode.rs +++ b/crates/ec-av1/src/encode.rs @@ -292,22 +292,22 @@ pub(crate) fn tx_type_candidates(set: TxbSet, screen: bool) -> &'static [TxType] /// (`IDTX`, `DCT_DCT`) and 32x32 is `EXT_TX_SET_DCT_IDTX` -- the same two /// types, a symbol the writer already codes and never varied. 64x64 codes no /// `tx_type` symbol at all, so it is not offered one. -/// `EC_AV1_TXSET_INTER`: `0`/`off`, `screen` (screen frames only), anything -/// else on for every frame. +/// `EC_AV1_TXSET_INTER`: `0`/`off`, `screen` (screen frames only), `le16` +/// (16x16 and below, the sizes libaom's own census picks a non-`DCT_DCT` +/// inter type on -- it never takes `IDTX` at 32x32 on film B), anything else +/// on for every frame at every size. pub(crate) fn inter_tx_type_candidates(set: TxbSet, screen: bool) -> &'static [TxType] { const DCT: [TxType; 1] = [TxType::DctDct]; const INTER3: [TxType; 2] = [TxType::DctDct, TxType::Idtx]; - let on = match inter_tx_type_search() { + let mode = inter_tx_type_search(); + let on = match mode { InterTxSearch::Off => false, InterTxSearch::Screen => screen, - InterTxSearch::All => true, + InterTxSearch::All | InterTxSearch::Le16 => true, }; match set { - TxbSet::Luma32Inter | TxbSet::Luma16Inter | TxbSet::Luma8Inter | TxbSet::Luma4Inter - if on => - { - &INTER3 - } + TxbSet::Luma32Inter if on && mode != InterTxSearch::Le16 => &INTER3, + TxbSet::Luma16Inter | TxbSet::Luma8Inter | TxbSet::Luma4Inter if on => &INTER3, _ => &DCT, } } @@ -316,6 +316,8 @@ pub(crate) fn inter_tx_type_candidates(set: TxbSet, screen: bool) -> &'static [T pub(crate) enum InterTxSearch { Off, Screen, + /// 16x16 and below only. + Le16, All, } @@ -346,6 +348,7 @@ fn inter_tx_type_search() -> InterTxSearch { crate::envflags::var("EC_AV1_TXSET_INTER").ok().map(|v| match v.as_str() { "0" | "off" => InterTxSearch::Off, "screen" => InterTxSearch::Screen, + "le16" => InterTxSearch::Le16, _ => InterTxSearch::All, }) }); diff --git a/crates/ec-av1/src/transform.rs b/crates/ec-av1/src/transform.rs index bef434f3..1d40feb9 100644 --- a/crates/ec-av1/src/transform.rs +++ b/crates/ec-av1/src/transform.rs @@ -2160,7 +2160,10 @@ mod tests { /// and the mode search would read as a loss. #[test] fn a_typed_forward_round_trips_like_the_dct_one() { - for side in [4usize, 8, 16] { + // lane-txset2: 32 too -- the INTER search offers `IDTX` at 32x32 + // (`TxbSet::Luma32Inter`'s `EXT_TX_SET_DCT_IDTX`), a size the intra + // sets never name and this round trip never covered. + for side in [4usize, 8, 16, 32] { let residual: Vec = noise(side * side, 7 + side as u64) .iter() .map(|&v| v / 4) @@ -2180,7 +2183,10 @@ mod tests { // the reduced set names -- the FLIPADST and 1D-ADST/DCT families // reach the forward side through the mirrored residual, and a // mirror on the wrong axis reads exactly as a blown-up rmse here. - for tx in [ + // At 32x32 the only types any set names are `DCT_DCT` and + // `IDTX` (`EXT_TX_SET_DCT_IDTX`; ADST is undefined above 16), and + // the inter search offers exactly those. + let all = [ TxType::AdstDct, TxType::DctAdst, TxType::AdstAdst, @@ -2196,7 +2202,9 @@ mod tests { TxType::FlipAdstFlipAdst, TxType::AdstFlipAdst, TxType::FlipAdstAdst, - ] { + ]; + let types: &[TxType] = if side > 16 { &[TxType::Idtx] } else { &all }; + for &tx in types { let e = rmse(tx); assert!( e < 2.0 * dct, diff --git a/lanes/txset2.report.md b/lanes/txset2.report.md index 8fb142c0..e448a757 100644 --- a/lanes/txset2.report.md +++ b/lanes/txset2.report.md @@ -30,3 +30,59 @@ Witness: `encoder::tests::an_inter_clip_codes_both_inter_set_tx_types_both_decod -- PASS, hits `[DCT_DCT 154 .., IDTX 1368 ..]`, ours == ffmpeg every sample. Gate rows: see below (arms running). + +### The 12-frame gate (`encode::tests::bd_rate_screen_native`, 12 frames, gop 12) + +Control re-run on this head (`EC_AV1_TXSET_INTER=0`, which is also the +default): it REPRODUCES the charter's numbers to the digit, byte counts +included. + +| clip | control | arm: every frame, every size | delta | wall ctl -> arm | +|---|---|---|---|---| +| bars 1080p | -1.0% / -16.8% | **+23.1% / +3.3%** | +24.1 / +20.1 | 177.2s -> 182.0s | +| bars 2160p | +9.4% / -12.7% | **+31.2% / +3.7%** | +21.8 / +16.4 | 155.9s -> 160.7s | +| film A | +21.7% / -4.4% | +21.5% / -4.5% | -0.2 / -0.1 | 154.9s -> 167.7s | +| film B | +26.9% / -0.6% | +27.2% / -0.3% | +0.3 / +0.3 | 161.5s -> 167.6s | +| screen capture | +20.8% / -30.1% | +20.1% / -30.4% | -0.7 / -0.3 | 112.2s -> 109.5s | + +KEEP RULE on the unconditional arm: FAIL, and not marginally -- the two +synthetic bars rows lose TWENTY points (2 dB of luma PSNR at the same byte +count). Film A is 0.2/0.1 down, film B 0.3/0.3 up, the capture 0.7/0.3 down. + +The identity transform is not mis-scaled at 32x32: the typed round trip now +covers `side = 32` for the two types any set names there (`DCT_DCT`, `IDTX`; +ADST is undefined above 16) and `IDTX`'s rmse stays inside the DCT's 2x bound. +The bars collapse is the `local-rd-on-references` class again, at its loudest: +a flat synthetic frame is all 32x32 inter blocks whose residual `IDTX` prices +cheapest locally, and every later frame predicts from that reconstruction. + +## Step 3 -- what libaom actually picks (instrument, read off lane-libcen's census) + +`lanes/libcen.report.md`'s census files (`~/.cache/lc-libcen/cen-*.txt`, +`crates/ec-av1/examples/syntax_census.rs`) already carry the per-frame +`tx_type` histogram keyed by CDF row length, so no new run was needed. Film B, +libaom cpu-used 6 crf41 (48 pictures), row length -> set: 3 = the 2-symbol +inter `DCT_IDTX` (32x32), 6 = the 5-symbol `TX_SET_INTRA_2` (intra 16x16 and, +under `reduced_tx_set`, all intra), 8 = the 7-symbol `TX_SET_INTRA_1` (intra +8x8/4x4), 13 = the 12-symbol `TX_SET_INTER_2` (inter 16x16), 17 = ALL16 +(inter 8x8/4x4). + +| frame | set3 (inter 32) | set6 (intra 16) | set8 (intra 8/4) | set13 (inter 16) | set17 (inter <=8) | +|---|---|---|---|---|---| +| key (718 symbols) | -- | 85.3% | 14.7% | -- | -- | +| arf hint 30 (1058) | 27.5% | 6.8% | 4.5% | 51.7% | 9.7% | +| arf hint 15 (364) | 34.1% | 1.7% | 1.6% | 46.8% | 15.7% | +| arf hint 7 (61) | 67.2% | 1.6% | -- | 19.7% | 11.5% | +| arf hint 3 (41) | 78.0% | -- | -- | 9.7% | 12.3% | + +Two readings, both decisions: + +1. **libaom never codes `IDTX` at 32x32 on film B.** Every one of its set3 + symbols is symbol 1 (`DCT_DCT`); symbol 0 does not appear in any frame of + the stream. That is exactly the size our unconditional arm loses its twenty + points on -- hence the `le16` arm below. +2. **41% of its inter `tx_type` symbols are in sets 13/17**, i.e. the alphabets + `reduced_tx_set = 0` unlocks, and they are spread across nine or more + distinct types (set13 symbols 3..11 at 1.5-14% each). Our own stream codes + `set3/1` and `set6/1` only, 100% `DCT_DCT` in inter frames -- the gap step 2 + is aimed at.