forge
Explore
Log in

Don't you dare go Hollow

Merge branch 'lane-txset' (cdb209a0): the luma transform-type search (intra 5-type reduced set), screen-gated; forward kernels for all 16 types; the writer had coded one type everywhere

Browse files at this commit

5b253199ba84d4fcc92d23bc49a95ff89fa7ae7cAhmet Kaan GümüşParent: f1f811ccf5dfd3
Screen capture +27.8/-26.0 -> +20.8/-30.1; the film rows lose
unconditionally (local RD on references), so the search is gated on
screen content and the film rows stay byte-identical. Pins unchanged.
crates/ec-av1/src/decode.rsmodified+8 -0
@@ -5997,6 +5997,14 @@ pub(crate) fn tx_type_from_symbol(cdf_len: usize, t: usize) -> Option<TxType> {
59975997 }
59985998 }
59995999
6000+/// [`tx_type_from_symbol`] inverted: which symbol of a `cdf_len`-wide
6001+/// `tx_type` CDF names `tx_type`, or `None` when that set does not hold it
6002+/// (class `table-and-reader-move-together` -- the writer picks its symbol
6003+/// through the reader's own map, so the two cannot drift).
6004+pub(crate) fn tx_type_symbol(cdf_len: usize, tx_type: TxType) -> Option<usize> {
6005+ (0..cdf_len.saturating_sub(1)).find(|&t| tx_type_from_symbol(cdf_len, t) == Some(tx_type))
6006+}
6007+
60006008 /// The remainder of a level the base and base-range syntax could not reach
60016009 /// (spec 5.11.40): its bit length in unary, then that many of its own bits,
60026010 /// most significant first — the exact inverse of [`crate::tile::write_golomb`].
crates/ec-av1/src/encode.rsmodified+128 -9
@@ -252,6 +252,48 @@ fn tx_select_inter() -> bool {
252252 ENV.unwrap_or_else(|| crate::speed::at(&crate::speed::TX_SELECT_INTER))
253253 }
254254
255+/// SCREEN CONTENT ONLY, measured (12-frame `bd_rate_screen_native`, control
256+/// vs arm): the capture row goes +27.8/-26.0 -> +20.8/-30.1 -- seven points
257+/// against libaom -- while BOTH film rows LOSE (film A +21.7/-4.4 ->
258+/// +22.1/-4.0, film B +26.9/-0.6 -> +28.1/+0.7) and 2160p bars lose 0.8/1.1.
259+/// The keep rule wants both films down, so this takes the same content gate
260+/// palette, intrabc and the angle-delta refinement already stand behind: a
261+/// non-screen frame is byte-identical to the encoder before the lane.
262+///
263+/// The transform types an intra luma transform unit of `set` may be coded
264+/// with -- exactly the alphabet the writer's `tx_type` symbol names for that
265+/// set, so a searched type is always one the tile can express (lane-txset).
266+/// `DCT_DCT` first: it is the incumbent every other candidate has to beat.
267+///
268+/// Under this encoder's `reduced_tx_set` header bit every intra set at 16x16
269+/// and below is `TX_SET_INTRA_2` (spec `get_tx_set`), the five types
270+/// [`TxType::from_symbol`] names; 32x32 and 64x64 luma code no symbol at all,
271+/// and inter luma reads the two-type `TX_SET_INTER_3`, left at `DCT_DCT`
272+/// here.
273+pub(crate) fn tx_type_candidates(set: TxbSet, screen: bool) -> &'static [TxType] {
274+ const DCT: [TxType; 1] = [TxType::DctDct];
275+ const INTRA2: [TxType; 5] = [
276+ TxType::DctDct,
277+ TxType::AdstAdst,
278+ TxType::AdstDct,
279+ TxType::DctAdst,
280+ TxType::Idtx,
281+ ];
282+ match set {
283+ TxbSet::Luma16 | TxbSet::Luma8 | TxbSet::Luma4 if screen && tx_type_search() => &INTRA2,
284+ _ => &DCT,
285+ }
286+}
287+
288+fn tx_type_search() -> bool {
289+ static ENV: std::sync::LazyLock<Option<bool>> = std::sync::LazyLock::new(|| {
290+ crate::envflags::var("EC_AV1_TXSET")
291+ .ok()
292+ .map(|v| !matches!(v.as_str(), "0" | "off"))
293+ });
294+ ENV.unwrap_or_else(|| crate::speed::at(&crate::speed::TX_TYPE_SEARCH))
295+}
296+
255297 fn tx_select() -> bool {
256298 static ENV: std::sync::LazyLock<Option<bool>> = std::sync::LazyLock::new(|| {
257299 crate::envflags::var("EC_AV1_TX_SELECT")
@@ -2128,6 +2170,7 @@ impl Plane<'_> {
21282170 let (skip_ctx, sign_ctx) = self.coef_ctx(x, y, side, at.set);
21292171 let bits = crate::tile::rdoq(
21302172 &mut levels, &scaled, side, base_q_idx, at.set, skip_ctx, sign_ctx, rdoq_lambda(),
2173+ tx_type,
21312174 );
21322175 (levels, Some(bits))
21332176 } else {
@@ -2182,12 +2225,13 @@ impl Plane<'_> {
21822225 } else {
21832226 {
21842227 let (skip_ctx, sign_ctx) = self.coef_ctx(x, y, side, at.set);
2185- crate::tile::coeff_bits(
2228+ crate::tile::coeff_bits_typed(
21862229 &levels,
21872230 at.set,
21882231 crate::decode::q_ctx_of(base_q_idx),
21892232 skip_ctx,
21902233 sign_ctx,
2234+ tx_type,
21912235 )
21922236 }
21932237 };
@@ -2258,6 +2302,7 @@ impl Plane<'_> {
22582302 let (skip_ctx, sign_ctx) = self.coef_ctx(x, y, side, set);
22592303 let bits = crate::tile::rdoq(
22602304 &mut levels, &scaled, side, base_q_idx, set, skip_ctx, sign_ctx, rdoq_lambda(),
2305+ TxType::DctDct,
22612306 );
22622307 (levels, Some(bits))
22632308 } else {
@@ -2353,7 +2398,7 @@ impl Plane<'_> {
23532398 // `filter_intra`), not once over the whole block.
23542399 filter_intra: Option<u8>,
23552400 search: &Search, fctx: &crate::decode::FrameCtx,
2356- ) -> (Vec<i32>, f64, f64) {
2401+ ) -> (Vec<i32>, f64, f64, Vec<TxType>) {
23572402 let At { x, y, side, reach, .. } = at;
23582403 let tx = side >> depth;
23592404 let n = 1usize << depth;
@@ -2369,6 +2414,11 @@ impl Plane<'_> {
23692414 // for its `txb_skip` context, not context 0 ([`Plane::coef_ctx`]).
23702415 self.ctx.tu_split = n > 1;
23712416 let (mut sse, mut bits) = (0.0, 0.0);
2417+ // One entry per unit at its own `tu_row * n + tu_col`, which is how
2418+ // the writer indexes them (tile.rs `write_luma_tus`) -- a unit the
2419+ // frame edge cuts away is never coded there, so a compacted list
2420+ // would slide every later unit's type onto the wrong transform.
2421+ let mut tx_types = vec![TxType::DctDct; n * n];
23722422 for tu_row in 0..n {
23732423 for tu_col in 0..n {
23742424 let (col_off, row_off) = (tu_col * tx, tu_row * tx);
@@ -2406,7 +2456,27 @@ impl Plane<'_> {
24062456 )
24072457 }
24082458 None => {
2409- self.trial(tu, mode, angle_delta, search.base_q_idx, search.deadzone, fctx)
2459+ // lane-txset: the unit picks its own transform type
2460+ // out of the set the writer can name it in, priced
2461+ // through the same RDOQ'd trial path (its `bits`
2462+ // already carry the `tx_type` symbol itself).
2463+ let mut best: Option<(f64, TxType, Trial)> = None;
2464+ for &tx_type in tx_type_candidates(set, search.screen) {
2465+ let candidate = self.trial_typed(
2466+ tu, mode, angle_delta, search.base_q_idx, search.deadzone,
2467+ tx_type, fctx,
2468+ );
2469+ let cost = candidate.sse + search.lambda * candidate.bits;
2470+ if best.as_ref().is_none_or(|(best, _, _)| cost < *best) {
2471+ best = Some((cost, tx_type, candidate));
2472+ }
2473+ }
2474+ let (_, tx_type, trial) =
2475+ best.expect("the candidate list is never empty");
2476+ tx_types[tu_row * n + tu_col] = tx_type;
2477+ TX_TYPE_HITS[tx_type as usize]
2478+ .fetch_add(1, std::sync::atomic::Ordering::Relaxed);
2479+ trial
24102480 }
24112481 };
24122482 sse += trial.sse;
@@ -2419,7 +2489,7 @@ impl Plane<'_> {
24192489 }
24202490 }
24212491 self.ctx.tu_split = false;
2422- (levels, sse, bits)
2492+ (levels, sse, bits, tx_types)
24232493 }
24242494
24252495 /// Writes a trial's reconstruction back into the plane, and the
@@ -2637,7 +2707,7 @@ impl Plane<'_> {
26372707 at: At,
26382708 search: &Search,
26392709 mode_bits: &[f64; 13], fctx: &crate::decode::FrameCtx,
2640- ) -> (Vec<Coeff>, u8, i32, f64) {
2710+ ) -> (Vec<Coeff>, u8, i32, f64, TxType) {
26412711 let At {
26422712 x, y, side, reach, ..
26432713 } = at;
@@ -2777,6 +2847,23 @@ impl Plane<'_> {
27772847 ANGLE_DELTA_HITS[(crate::tile::ANGLE_DELTA_ZERO as i32 + angle_delta) as usize]
27782848 .fetch_add(1, std::sync::atomic::Ordering::Relaxed);
27792849 }
2850+ // lane-txset: the block's own transform type, searched on the mode
2851+ // and angle the trials above settled -- the same ordering the angle
2852+ // refinement uses, and the same RD terms.
2853+ let mut tx_type = TxType::DctDct;
2854+ for &candidate_type in tx_type_candidates(at.set, search.screen).iter().skip(1) {
2855+ let candidate = self.trial_typed(
2856+ at, mode, angle_delta, search.base_q_idx, search.deadzone, candidate_type, fctx,
2857+ );
2858+ let cost_t =
2859+ candidate.sse + search.lambda * (candidate.bits + mode_bits[usize::from(mode)]);
2860+ if cost_t < cost {
2861+ cost = cost_t;
2862+ tx_type = candidate_type;
2863+ trial = candidate;
2864+ }
2865+ }
2866+ TX_TYPE_HITS[tx_type as usize].fetch_add(1, std::sync::atomic::Ordering::Relaxed);
27802867 if census_on() {
27812868 LUMA_RANK[sad_rank(&ranking, mode).min(12)]
27822869 .fetch_add(1, std::sync::atomic::Ordering::Relaxed);
@@ -2784,7 +2871,7 @@ impl Plane<'_> {
27842871 self.commit(x, y, side, &trial);
27852872 // A 64-point transform codes only its top-left 32x32 corner, which is
27862873 // the grid `code_from_prediction` hands back (lane-i64).
2787- (coeffs(&trial.levels, side.min(BLOCK)), mode, angle_delta, cost)
2874+ (coeffs(&trial.levels, side.min(BLOCK)), mode, angle_delta, cost, tx_type)
27882875 }
27892876 }
27902877
@@ -3586,6 +3673,19 @@ fn tx_depth_bits(side: usize, depth: usize) -> f64 {
35863673 }
35873674 }
35883675
3676+/// How many luma transform units resolved to each [`TxType`], indexed by the
3677+/// enum's own discriminant (lane-txset): the fire count a witness asserts on,
3678+/// and the instrument that says which types the search actually reaches.
3679+pub(crate) static TX_TYPE_HITS: [std::sync::atomic::AtomicUsize; 16] =
3680+ [const { std::sync::atomic::AtomicUsize::new(0) }; 16];
3681+
3682+/// Reads [`TX_TYPE_HITS`] and zeroes it, so a gate or a test attributes the
3683+/// counts to its own encode.
3684+#[cfg(test)]
3685+pub(crate) fn take_tx_type_hits() -> [usize; 16] {
3686+ std::array::from_fn(|t| TX_TYPE_HITS[t].swap(0, std::sync::atomic::Ordering::Relaxed))
3687+}
3688+
35893689 /// How many blocks resolved to each `tx_depth`, the fire count that says
35903690 /// whether the depth search below reaches its candidates at all.
35913691 static TX_DEPTH_HITS: [std::sync::atomic::AtomicUsize; 3] =
@@ -4377,8 +4477,9 @@ fn code_square(
43774477 reach: Reach::of(side, x, y, luma.true_width, luma.true_height, fctx),
43784478 set: luma_set,
43794479 };
4380- let (mut luma_coeffs, mode, angle_delta, mut cost) =
4480+ let (mut luma_coeffs, mode, angle_delta, mut cost, tx_type) =
43814481 luma.search_block(at, search, mode_bits, fctx);
4482+ let mut luma_tx_types = vec![tx_type];
43824483 // The depth search runs on the mode the whole-block transform picked --
43834484 // libaom's own ordering, and the reason it costs one extra pass per depth
43844485 // rather than one per (mode, depth) pair.
@@ -4398,15 +4499,19 @@ fn code_square(
43984499 luma.snapshot(x, y, side),
43994500 luma_coeffs,
44004501 );
4502+ let mut best_types = std::mem::take(&mut luma_tx_types);
44014503 for depth in 1..=max_tx_depth(side) {
4402- let (levels, sse, bits) = luma.code_tx_depth(at, mode, angle_delta, depth, None, search, fctx);
4504+ let (levels, sse, bits, types) =
4505+ luma.code_tx_depth(at, mode, angle_delta, depth, None, search, fctx);
44034506 let cost_d = sse
44044507 + search.lambda
44054508 * (bits + mode_bits[usize::from(mode)] + tx_depth_bits(side, depth));
44064509 if cost_d < best.0 {
44074510 best = (cost_d, depth, luma.snapshot(x, y, side), coeffs(&levels, side));
4511+ best_types = types;
44084512 }
44094513 }
4514+ luma_tx_types = best_types;
44104515 luma.restore(x, y, side, &best.2);
44114516 cost = best.0;
44124517 tx_depth = best.1 as u8;
@@ -4503,7 +4608,10 @@ fn code_square(
45034608 let mut best: Option<(f64, u8, usize, (Vec<u8>, Vec<CoefCtx>), Vec<Coeff>)> = None;
45044609 for fi in 0..5u8 {
45054610 for depth in 0..=max_depth {
4506- let (levels, sse, bits) =
4611+ // A filter-intra block's units are coded through
4612+ // `code_from_prediction`, which is `DCT_DCT` throughout, so
4613+ // this arm keeps the empty (all-`DCT_DCT`) type list.
4614+ let (levels, sse, bits, _) =
45074615 luma.code_tx_depth(at, DC_PRED, 0, depth, Some(fi), search, fctx);
45084616 let cost_f = sse
45094617 + search.lambda
@@ -4564,6 +4672,12 @@ fn code_square(
45644672 }
45654673 }
45664674 }
4675+ // A palette or filter-intra block's luma was recoded through `DCT_DCT`
4676+ // (its levels came from `code_from_prediction`), so the searched types
4677+ // belong to a block this one no longer is.
4678+ if palette.is_some() || filter_intra.is_some() {
4679+ luma_tx_types = Vec::new();
4680+ }
45674681 (
45684682 BlockCoeffs {
45694683 u,
@@ -4577,6 +4691,7 @@ fn code_square(
45774691 filter_intra,
45784692 cfl_alphas,
45794693 angle_delta_y: angle_delta as i8,
4694+ luma_tx_types,
45804695 ..BlockCoeffs::default()
45814696 },
45824697 cost,
@@ -5847,6 +5962,7 @@ fn code_square_inter(
58475962 palette: None,
58485963 palette_uv: None,
58495964 tx_depth,
5965+ luma_tx_types: Vec::new(),
58505966 inter: Some(info),
58515967 motion_mode: motion_won,
58525968 },
@@ -5869,6 +5985,7 @@ fn code_square_inter(
58695985 chroma[0].commit(x / 2, y / 2, side / 2, &u);
58705986 chroma[1].commit(x / 2, y / 2, side / 2, &v);
58715987 (BlockCoeffs {
5988+ luma_tx_types: Vec::new(),
58725989 angle_delta_y: 0,
58735990 cfl_alphas: None,
58745991 filter_intra: None,
@@ -9117,6 +9234,7 @@ fn search_inter_block(
91179234 chroma[1].commit(x / 2, y / 2, BLOCK / 2, &best.v);
91189235 (
91199236 BlockCoeffs {
9237+ luma_tx_types: Vec::new(),
91209238 angle_delta_y: 0,
91219239 cfl_alphas: None,
91229240 filter_intra: None,
@@ -11802,6 +11920,7 @@ mod tests {
1180211920 let (_, inter_header) = inter_frame_headers(width, height, 100, 1, 0).unwrap();
1180311921
1180411922 let residual_block = BlockCoeffs {
11923+ luma_tx_types: Vec::new(),
1180511924 angle_delta_y: 0,
1180611925 cfl_alphas: None,
1180711926 filter_intra: None,
crates/ec-av1/src/encoder.rsmodified+112 -0
@@ -3615,6 +3615,118 @@ mod tests {
36153615 eprintln!("delta_q witness: {levels} quantizer levels, {} bytes", stream.len());
36163616 }
36173617
3618+ /// lane-txset's witness: a clip of hard directional edges makes the intra
3619+ /// luma search take EVERY type of the five-type reduced set
3620+ /// (`TX_SET_INTRA_2`: `DCT_DCT`, `ADST_ADST`, `ADST_DCT`, `DCT_ADST`,
3621+ /// `IDTX`) at least once -- the fire count, class `gate-blind-to-feature`
3622+ /// -- and both decoders reconstruct every frame sample-exact from the
3623+ /// `tx_type` symbols that name them. Before the lane the writer coded
3624+ /// `DCT_DCT` for every luma transform unit ever written, so this is also
3625+ /// the statement that the other four are REACHABLE at all.
3626+ #[test]
3627+ fn an_edge_clip_codes_every_reduced_set_tx_type_both_decoders_read_exactly() {
3628+ // `knob_write`: the screen override below is process-global, and the
3629+ // type search is SCREEN-ONLY (`encode::tx_type_candidates`).
3630+ let _knobs = crate::speed::knob_write();
3631+ crate::encode::force_screen(Some(true));
3632+ let _gate_lock = crate::stream::tests::lock_gate_counters();
3633+ let (width, height) = (320usize, 192usize);
3634+ // Sharp horizontal and vertical steps: a vertical edge is what an
3635+ // `ADST` column pass beats a `DCT` one on, a horizontal edge the
3636+ // mirror, and the flat/ramp areas between them are where `IDTX` wins.
3637+ let sources: Vec<Picture> = (0..2)
3638+ .map(|t| {
3639+ let mut p = test_card(width, height, t * 3);
3640+ for y in 0..height {
3641+ for x in 0..width {
3642+ let v = match ((x + t * 4) / 16 % 2, y / 16 % 2) {
3643+ (0, 0) => 16u16,
3644+ (1, 0) => 235,
3645+ (0, 1) => (x % 64 * 3) as u16,
3646+ _ => (y % 64 * 3) as u16,
3647+ };
3648+ p.y[y * width + x] = v;
3649+ }
3650+ }
3651+ p
3652+ })
3653+ .collect();
3654+ let config = EncoderConfig {
3655+ width,
3656+ height,
3657+ base_q_idx: 90,
3658+ gop: 2,
3659+ colour: Colour::Bt709Limited,
3660+ tile_cols_log2: 0,
3661+ tile_rows_log2: 0,
3662+ };
3663+ let mut enc = Av1Encoder::new(config).unwrap();
3664+ let _ = crate::encode::take_tx_type_hits();
3665+ let mut stream = Vec::new();
3666+ for packet in encode_all(&mut enc, &sources) {
3667+ stream.extend_from_slice(&packet.data);
3668+ }
3669+ let hits = crate::encode::take_tx_type_hits();
3670+ // The type search is a speed lever (`speed::TX_TYPE_SEARCH`); above
3671+ // the presets that carry it only `DCT_DCT` is offered, and the
3672+ // exactness half below is what still runs there. The FULL five-type
3673+ // fire count is preset 0's to make: a faster preset prunes modes and
3674+ // partitions before a type is ever priced on them, so `ADST_ADST` and
3675+ // `IDTX` stop winning on this clip at preset 6 (measured: hits
3676+ // `[0, 6192, 0, 79, 284, ..]`). Every preset that carries the lever
3677+ // still has to reach SOME non-`DCT_DCT` type -- that is the
3678+ // "reachable at all" statement, class `gate-blind-to-feature`.
3679+ if crate::speed::at(&crate::speed::TX_TYPE_SEARCH) {
3680+ let non_dct: usize = hits.iter().sum::<usize>()
3681+ - hits[crate::transform::TxType::DctDct as usize];
3682+ assert!(
3683+ non_dct > 0,
3684+ "every luma transform unit took DCT_DCT: {hits:?}"
3685+ );
3686+ }
3687+ if crate::speed::at(&crate::speed::TX_TYPE_SEARCH) && crate::speed::speed() == 0 {
3688+ for (name, ty) in [
3689+ ("DCT_DCT", crate::transform::TxType::DctDct),
3690+ ("ADST_ADST", crate::transform::TxType::AdstAdst),
3691+ ("ADST_DCT", crate::transform::TxType::AdstDct),
3692+ ("DCT_ADST", crate::transform::TxType::DctAdst),
3693+ ("IDTX", crate::transform::TxType::Idtx),
3694+ ] {
3695+ assert!(
3696+ hits[ty as usize] > 0,
3697+ "no luma transform unit took {name}: {hits:?}"
3698+ );
3699+ }
3700+ } else {
3701+ eprintln!(
3702+ "SKIP the five-type fire count at preset {}: {hits:?}",
3703+ crate::speed::speed()
3704+ );
3705+ }
3706+ let ours = crate::stream::decode_stream(&stream).expect("our decoder");
3707+ assert_eq!(ours.len(), sources.len(), "our decoder's frames");
3708+ if have_ffmpeg() {
3709+ let theirs = ffmpeg_decode_luma(&stream, width, height);
3710+ assert_eq!(theirs.len(), sources.len(), "ffmpeg's frames");
3711+ for (i, (a, b)) in ours.iter().zip(&theirs).enumerate() {
3712+ let got: Vec<u8> = a.y.iter().map(|&v| v as u8).collect();
3713+ if let Some(at) = got.iter().zip(b).position(|(x, y)| x != y) {
3714+ panic!(
3715+ "frame {i}: luma differs first at ({}, {}): ours {} vs ffmpeg {}",
3716+ at % width,
3717+ at / width,
3718+ got[at],
3719+ b[at],
3720+ );
3721+ }
3722+ }
3723+ } else {
3724+ eprintln!("SKIP the ffmpeg half: no ffmpeg");
3725+ }
3726+ crate::encode::force_screen(None);
3727+ eprintln!("tx_type witness: hits {hits:?}, {} bytes", stream.len());
3728+ }
3729+
36183730 /// Every SHIPPED SPEED PRESET codes a stream both decoders reconstruct
36193731 /// sample-exact -- ours and ffmpeg's -- and codes a DIFFERENT stream from
36203732 /// its neighbour (a preset that changes no byte is a preset that buys no
crates/ec-av1/src/speed.rsmodified+8 -0
@@ -483,6 +483,14 @@ pub(crate) const RESTORATION: [bool; 11] = [
483483 pub(crate) const TPL_DEPTH: [usize; 11] =
484484 [crate::encode::TPL_DEPTH, 8, 8, 4, 4, 4, 4, 1, 1, 1, 1];
485485
486+/// `encode::tx_type_search`: whether an intra luma transform unit searches
487+/// its own `tx_type` instead of coding `DCT_DCT` (lane-txset). The five-type
488+/// reduced-set alphabet the writer already codes is what it picks from, so a
489+/// preset that turns it off is byte-identical to the encoder before the lane.
490+pub(crate) const TX_TYPE_SEARCH: [bool; 11] = [
491+ true, true, true, true, true, true, true, false, false, false, false,
492+];
493+
486494 /// `filter_search`: whether the deblock ladder's +-1/+-2 refinement stage runs.
487495 pub(crate) const DEBLOCK_REFINE: [bool; 11] = [
488496 true, true, true, true, true, true, true, false, false, false, false,
crates/ec-av1/src/tile.rsmodified+77 -10
@@ -21,6 +21,7 @@ use crate::cdf;
2121 use crate::cdf_state::{Cdfs, MvComponentCdfs, TxbSet, TxbTables};
2222 use crate::decode::{TXFM_CTX_INIT, txfm_partition_ctx_rect};
2323 use crate::msac::SymbolEncoder;
24+use crate::transform::TxType;
2425 use crate::mvstack::{MiGrid, MiInfo, NO_REF1, find_mv_stack, mv16};
2526
2627 // ---------------------------------------------------------------------------
@@ -1674,6 +1675,10 @@ pub struct Coeff {
16741675 pub struct BlockCoeffs {
16751676 /// The luma transform's coefficients.
16761677 pub luma: Vec<Coeff>,
1678+ /// One transform type per luma transform unit, raster order (lane-txset).
1679+ /// Empty is `DCT_DCT` throughout -- what every block coded before the
1680+ /// search offered a type, and what an inter block still carries.
1681+ pub luma_tx_types: Vec<TxType>,
16771682 /// The U plane's.
16781683 pub u: Vec<Coeff>,
16791684 /// The V plane's.
@@ -3994,6 +3999,7 @@ fn write_block(
39943999 &grids[0],
39954000 tx_mode,
39964001 all_scans,
4002+ &block.luma_tx_types,
39974003 )?;
39984004 tx < side
39994005 } else {
@@ -4008,6 +4014,7 @@ fn write_block(
40084014 &neighbours.around(at, side),
40094015 tx_mode,
40104016 tx_select,
4017+ block_tx_type(block),
40114018 );
40124019 neighbours.record_planes(at, side, mode, grids, !split);
40134020 clear_skip_band(neighbours, at_mi, side);
@@ -4092,6 +4099,7 @@ fn write_leaf8(
40924099 &grids[0],
40934100 tx_mode,
40944101 all_scans,
4102+ &block.luma_tx_types,
40954103 )?;
40964104 tx < 8
40974105 } else {
@@ -4106,6 +4114,7 @@ fn write_leaf8(
41064114 &neighbours.around_mi(leaf_mi, 8),
41074115 tx_mode,
41084116 tx_select,
4117+ block_tx_type(block),
41094118 );
41104119 neighbours.record_mi_planes(leaf_mi, 8, grids, !split);
41114120 clear_skip_band(neighbours, leaf_mi, 8);
@@ -4127,6 +4136,9 @@ fn write_block_planes(
41274136 // A block whose luma was already written as several transform units
41284137 // ([`write_luma_select`]) has only its chroma planes left here.
41294138 skip_luma: bool,
4139+ // This block's single luma transform type (lane-txset); chroma's is
4140+ // derived from its mode by the decoder and codes no symbol.
4141+ luma_tx_type: TxType,
41304142 ) {
41314143 for (plane, (grid, scan)) in grids.iter().zip(scans.iter()).enumerate() {
41324144 if plane == 0 && skip_luma {
@@ -4153,6 +4165,7 @@ fn write_block_planes(
41534165 skip_ctx,
41544166 dc_sign_ctx(around[plane].dc_vote),
41554167 Some(plane),
4168+ if plane == 0 { luma_tx_type } else { TxType::DctDct },
41564169 );
41574170 #[cfg(test)]
41584171 census_record(
@@ -4173,6 +4186,12 @@ fn write_block_planes(
41734186 }
41744187 }
41754188
4189+/// The single luma transform type a block carries, `DCT_DCT` for one that
4190+/// never searched one (lane-txset).
4191+fn block_tx_type(block: &BlockCoeffs) -> TxType {
4192+ block.luma_tx_types.first().copied().unwrap_or(TxType::DctDct)
4193+}
4194+
41764195 /// The `(side / tx)^2` transform units of one block's luma residual, raster
41774196 /// order, each with its own coefficient context and each published before the
41784197 /// next one reads it (decode.rs `decode_block`'s multi-transform-unit branch).
@@ -4192,6 +4211,10 @@ fn write_luma_tus(
41924211 // lane-av1tx2 r2: an INTER block's split units read the inter coefficient
41934212 // tables, not the intra ones (`TxbSet::Luma*Inter`).
41944213 inter: bool,
4214+ // One transform type per unit in this same raster order (lane-txset).
4215+ // Empty -- what every caller that never searched a type passes -- is
4216+ // `DCT_DCT` throughout, the one type this writer used to code.
4217+ tx_types: &[TxType],
41954218 ) -> Result<()> {
41964219 if tx < side && side > 32 && tx < 32 {
41974220 // A 64x64 block's own levels reach the writer as the 32x32 corner a
@@ -4268,6 +4291,10 @@ fn write_luma_tus(
42684291 skip_ctx,
42694292 dc_sign_ctx(around.dc_vote),
42704293 Some(0),
4294+ tx_types
4295+ .get(tu_row * n + tu_col)
4296+ .copied()
4297+ .unwrap_or(TxType::DctDct),
42714298 );
42724299 #[cfg(test)]
42734300 census_record(
@@ -4308,6 +4335,7 @@ fn write_luma_select(
43084335 grid: &[i32],
43094336 mode: usize,
43104337 scans: &[Vec<u16>; 4],
4338+ tx_types: &[TxType],
43114339 ) -> Result<usize> {
43124340 let max_tx = side.min(64);
43134341 let ctx = neighbours.tx_size_ctx(at_mi, max_tx);
@@ -4324,7 +4352,7 @@ fn write_luma_select(
43244352 }
43254353 }
43264354 let tx = max_tx >> depth;
4327- write_luma_tus(enc, cdfs, neighbours, at_mi, side, tx, grid, mode, scans, false)?;
4355+ write_luma_tus(enc, cdfs, neighbours, at_mi, side, tx, grid, mode, scans, false, tx_types)?;
43284356 neighbours.record_tx(at_mi, side, tx);
43294357 Ok(tx)
43304358 }
@@ -4697,6 +4725,19 @@ fn scan_of(side: usize) -> &'static Vec<u16> {
46974725 }
46984726
46994727 pub(crate) fn coeff_bits(
4728+ grid: &[i32],
4729+ set: TxbSet,
4730+ q_ctx: usize,
4731+ skip_ctx: usize,
4732+ sign_ctx: usize,
4733+) -> f64 {
4734+ coeff_bits_typed(grid, set, q_ctx, skip_ctx, sign_ctx, TxType::DctDct)
4735+}
4736+
4737+/// [`coeff_bits`] for levels a named transform type produced: the `tx_type`
4738+/// symbol is part of what the block spends, so a search comparing types has
4739+/// to see each one's own symbol priced (lane-txset).
4740+pub(crate) fn coeff_bits_typed(
47004741 grid: &[i32],
47014742 set: TxbSet,
47024743 q_ctx: usize,
@@ -4708,6 +4749,7 @@ pub(crate) fn coeff_bits(
47084749 // largest remaining pricer error for every other block.
47094750 skip_ctx: usize,
47104751 sign_ctx: usize,
4752+ tx_type: TxType,
47114753 ) -> f64 {
47124754 // `Cdfs::new` builds every table a tile writer adapts -- tens of
47134755 // kilobytes -- and this function is called once per priced candidate:
@@ -4743,7 +4785,7 @@ pub(crate) fn coeff_bits(
47434785 }
47444786 let scan = scan_of(coding.side);
47454787 let mut enc = SymbolEncoder::pricer();
4746- write_coeffs(&mut enc, &mut coding, grid, scan, skip_ctx, sign_ctx, None);
4788+ write_coeffs(&mut enc, &mut coding, grid, scan, skip_ctx, sign_ctx, None, tx_type);
47474789 enc.bits()
47484790 };
47494791 // lane-av1speed2: 60% of the transform units of an inter stream hold no
@@ -4842,6 +4884,7 @@ pub(crate) fn rdoq(
48424884 skip_ctx: usize,
48434885 sign_ctx: usize,
48444886 lambda: f64,
4887+ tx_type: TxType,
48454888 ) -> f64 {
48464889 // A 64-point transform carries its top-left 32x32 alone, and that corner
48474890 // is what the writer and the pricer take (`coded_corner`).
@@ -4857,16 +4900,17 @@ pub(crate) fn rdoq(
48574900 q_ctx: usize,
48584901 skip_ctx: usize,
48594902 sign_ctx: usize,
4903+ tx_type: TxType,
48604904 ) -> f64 {
48614905 if dense.is_empty() {
4862- return coeff_bits(levels, set, q_ctx, skip_ctx, sign_ctx);
4906+ return coeff_bits_typed(levels, set, q_ctx, skip_ctx, sign_ctx, tx_type);
48634907 }
48644908 for row in 0..coded {
48654909 dense[row * coded..][..coded].copy_from_slice(&levels[row * side..][..coded]);
48664910 }
4867- coeff_bits(dense, set, q_ctx, skip_ctx, sign_ctx)
4911+ coeff_bits_typed(dense, set, q_ctx, skip_ctx, sign_ctx, tx_type)
48684912 }
4869- let mut bits = price(levels, &mut dense, side, coded, set, q_ctx, skip_ctx, sign_ctx);
4913+ let mut bits = price(levels, &mut dense, side, coded, set, q_ctx, skip_ctx, sign_ctx, tx_type);
48704914 // The DC has its own quantiser, so its squared error per unit of level is
48714915 // `(dc_q / ac_q)^2` of an AC coefficient's.
48724916 let dc = f64::from(crate::quant::dc_q(8, i32::from(base_q_idx)));
@@ -4905,7 +4949,7 @@ pub(crate) fn rdoq(
49054949 let candidate = level - level.signum();
49064950 levels[i] = candidate;
49074951 budget -= 1;
4908- let after = price(levels, &mut dense, side, coded, set, q_ctx, skip_ctx, sign_ctx);
4952+ let after = price(levels, &mut dense, side, coded, set, q_ctx, skip_ctx, sign_ctx, tx_type);
49094953 let distortion = weight
49104954 * ((s - f64::from(candidate)).powi(2) - (s - f64::from(level)).powi(2));
49114955 if distortion + lambda * (after - bits) < 0.0 {
@@ -5177,6 +5221,10 @@ fn write_coeffs(
51775221 skip_ctx: usize,
51785222 sign_ctx: usize,
51795223 plane: Option<usize>,
5224+ // Which transform type these levels were produced with (lane-txset).
5225+ // Only a luma set whose alphabet holds more than one type codes it;
5226+ // chroma never codes a `tx_type` symbol at all.
5227+ tx_type: TxType,
51805228 ) {
51815229 if let Some(plane) = plane {
51825230 ec_rng_trace(|| format!("EC_PLANE plane={plane} tell_before={}", enc.tell()));
@@ -5212,8 +5260,18 @@ fn write_coeffs(
52125260 // A luma transform whose type set holds more than one type codes which it
52135261 // is, right after the all-zero flag (spec 5.11.39). The writer only ever
52145262 // uses DCT_DCT, which is index one of `Tx_Type_Intra_Inv_Set2`.
5215- if let Some(tx_type) = coding.tx_type.as_deref_mut() {
5216- enc.symbol(TX_TYPE_DCT_DCT_SET2, tx_type);
5263+ if let Some(cdf) = coding.tx_type.as_deref_mut() {
5264+ // The symbol comes from the DECODER's own map, keyed by this set's
5265+ // alphabet width, so a type this set cannot express is caught here
5266+ // rather than desyncing the tile. The search only ever offers types
5267+ // the set holds ([`crate::encode::tx_type_candidates`]).
5268+ let symbol = crate::decode::tx_type_symbol(cdf.len(), tx_type);
5269+ debug_assert!(
5270+ symbol.is_some(),
5271+ "{tx_type:?} is not in the {}-symbol tx_type set",
5272+ cdf.len() - 1
5273+ );
5274+ enc.symbol(symbol.unwrap_or(TX_TYPE_DCT_DCT_SET2), cdf);
52175275 if plane.is_some() {
52185276 ec_rng_trace(|| format!("EC_TXTYPE tell={} rng={}", enc.tell(), enc.rng()));
52195277 }
@@ -6242,6 +6300,7 @@ pub(crate) fn sb_coeff_inter_frame_tile_cdfs(
62426300 0,
62436301 &all_scans,
62446302 true,
6303+ &block.luma_tx_types,
62456304 )?;
62466305 }
62476306 write_block_planes(
@@ -6253,6 +6312,7 @@ pub(crate) fn sb_coeff_inter_frame_tile_cdfs(
62536312 &neighbours.around(sb_at, SB),
62546313 0,
62556314 split,
6315+ block_tx_type(block),
62566316 );
62576317 neighbours.record_planes(sb_at, SB, 0, &grids, !split);
62586318 }
@@ -6690,6 +6750,7 @@ pub(crate) fn sb_coeff_inter_frame_tile_cdfs(
66906750 mode_for_tx,
66916751 &all_scans,
66926752 is_inter,
6753+ &block.luma_tx_types,
66936754 )?;
66946755 }
66956756 write_block_planes(
@@ -6705,6 +6766,7 @@ pub(crate) fn sb_coeff_inter_frame_tile_cdfs(
67056766 &neighbours.around(at, BLOCK),
67066767 mode_for_tx,
67076768 split,
6769+ block_tx_type(block),
67086770 );
67096771 neighbours.record_planes(at, BLOCK, mode_for_tx, &grids, !split);
67106772 }
@@ -6929,6 +6991,7 @@ fn write_inter_frame_leaf(
69296991 if split {
69306992 write_luma_tus(
69316993 enc, cdfs, neighbours, at_mi, SUB, tx, &grids[0], mode_for_tx, all_scans, is_inter,
6994+ &block.luma_tx_types,
69326995 )?;
69336996 }
69346997 write_block_planes(
@@ -6944,6 +7007,7 @@ fn write_inter_frame_leaf(
69447007 &neighbours.around(at, SUB),
69457008 mode_for_tx,
69467009 split,
7010+ block_tx_type(block),
69477011 );
69487012 neighbours.record_planes(at, SUB, mode_for_tx, &grids, !split);
69497013 }
@@ -7184,6 +7248,7 @@ fn write_inter_frame_leaf8(
71847248 if split {
71857249 write_luma_tus(
71867250 enc, cdfs, neighbours, leaf_mi, 8, tx, &grids[0], mode_for_tx, all_scans, is_inter,
7251+ &block.luma_tx_types,
71877252 )?;
71887253 }
71897254 write_block_planes(
@@ -7195,6 +7260,7 @@ fn write_inter_frame_leaf8(
71957260 &neighbours.around_mi(leaf_mi, 8),
71967261 mode_for_tx,
71977262 split,
7263+ block_tx_type(block),
71987264 );
71997265 neighbours.record_mi_planes(leaf_mi, 8, &grids, !split);
72007266 neighbours.record_inter_mi(leaf_mi, 8, block.skip, is_inter, block_ref(block));
@@ -7939,6 +8005,7 @@ mod tests {
79398005 0,
79408006 0,
79418007 None,
8008+ TxType::DctDct,
79428009 );
79438010 priced += luma_32_coeff_bits(grid);
79448011 }
@@ -8887,7 +8954,7 @@ mod tests {
88878954 .sum();
88888955 d + lambda * coeff_bits(grid, set, crate::decode::q_ctx_of(q), 0, 0)
88898956 };
8890- let bits = rdoq(&mut levels, &scaled, side, q, set, 0, 0, lambda);
8957+ let bits = rdoq(&mut levels, &scaled, side, q, set, 0, 0, lambda, TxType::DctDct);
88918958 assert_eq!(bits, coeff_bits(&levels, set, crate::decode::q_ctx_of(q), 0, 0));
88928959 assert!(cost(&levels) <= cost(&before), "{:?} vs {:?}", cost(&levels), cost(&before));
88938960 // The tail is what it is for: the last coded position moves earlier.
@@ -8908,7 +8975,7 @@ mod tests {
89088975 if v < 0.0 { -l } else { l }
89098976 })
89108977 .collect();
8911- let bits = rdoq(&mut levels, &scaled, side, q, set, 0, 0, lambda);
8978+ let bits = rdoq(&mut levels, &scaled, side, q, set, 0, 0, lambda, TxType::DctDct);
89128979 let corner: Vec<i32> = (0..32)
89138980 .flat_map(|row| levels[row * side..][..32].to_vec())
89148981 .collect();
crates/ec-av1/src/transform.rsmodified+40 -6
@@ -1483,11 +1483,25 @@ pub fn forward_transform_2d_typed(residual: &[i32], side: usize, tx_type: TxType
14831483 if tx_type == TxType::DctDct {
14841484 return forward_transform_2d(residual, side);
14851485 }
1486- debug_assert_eq!(
1487- tx_type.flip(),
1488- (false, false),
1489- "a flipped ADST needs its residual mirrored before this basis applies"
1490- );
1486+ // A FLIPADST axis is the plain ADST kernel with the DECODER's output
1487+ // mirrored (`dequant_and_inverse_typed_wh`'s `ud_flip`/`lr_flip`: row
1488+ // `h - 1 - i`, column `w - 1 - j`). A mirror is its own inverse, so the
1489+ // analysis half is the same plain basis over the mirrored residual --
1490+ // lane-txset, which is what lets every FLIPADST-bearing type share the
1491+ // kernels below instead of needing its own.
1492+ let (ud_flip, lr_flip) = tx_type.flip();
1493+ let mirrored: Vec<i32> = if ud_flip || lr_flip {
1494+ (0..side)
1495+ .flat_map(|row| {
1496+ let src = if ud_flip { side - 1 - row } else { row };
1497+ (0..side).map(move |col| (src, if lr_flip { side - 1 - col } else { col }))
1498+ })
1499+ .map(|(r, c)| residual[r * side + c])
1500+ .collect()
1501+ } else {
1502+ Vec::new()
1503+ };
1504+ let residual: &[i32] = if mirrored.is_empty() { residual } else { &mirrored };
14911505 let (row_kind, col_kind) = tx_type.axes();
14921506 let (hb, vb) = (axis_basis_t(side, row_kind), axis_basis_t(side, col_kind));
14931507 let mut rows = vec![0.0f64; side * side];
@@ -2162,7 +2176,27 @@ mod tests {
21622176 (sum / (side * side) as f64).sqrt()
21632177 };
21642178 let dct = rmse(TxType::DctDct);
2165- for tx in [TxType::AdstDct, TxType::DctAdst, TxType::AdstAdst] {
2179+ // lane-txset: every one of the sixteen types, not just the four
2180+ // the reduced set names -- the FLIPADST and 1D-ADST/DCT families
2181+ // reach the forward side through the mirrored residual, and a
2182+ // mirror on the wrong axis reads exactly as a blown-up rmse here.
2183+ for tx in [
2184+ TxType::AdstDct,
2185+ TxType::DctAdst,
2186+ TxType::AdstAdst,
2187+ TxType::Idtx,
2188+ TxType::VDct,
2189+ TxType::HDct,
2190+ TxType::VAdst,
2191+ TxType::HAdst,
2192+ TxType::VFlipAdst,
2193+ TxType::HFlipAdst,
2194+ TxType::FlipAdstDct,
2195+ TxType::DctFlipAdst,
2196+ TxType::FlipAdstFlipAdst,
2197+ TxType::AdstFlipAdst,
2198+ TxType::FlipAdstAdst,
2199+ ] {
21662200 let e = rmse(tx);
21672201 assert!(
21682202 e < 2.0 * dct,
lanes/txset.report.mdadded+194 -0
@@ -0,0 +1,194 @@
1+# lane-txset -- the transform-type search
2+
3+Branch `lane-txset` off main `3ebe0de9`. Scope: which `tx_type` an intra luma
4+transform unit is coded with, the forward kernels the missing types need, and
5+the writer symbol that names them.
6+
7+## 1. Instrument: what was coded, what was searched (read off the code)
8+
9+The writer coded ONE transform type, everywhere, always:
10+
11+ tile.rs:5216 enc.symbol(TX_TYPE_DCT_DCT_SET2, tx_type); // a constant
12+
13+and the search never varied a luma type either -- `search_block` and
14+`code_tx_depth` both go through `code_from_prediction`/`trial`, which pass
15+`TxType::DctDct` (`encode.rs:1993`, `:2278`). The only non-DCT types this
16+encoder has ever produced are CHROMA's, which code no symbol at all: the
17+decoder derives them from the chroma mode (`search_chroma` ->
18+`default_intra_tx_type`).
19+
20+STALE PREMISE IN THE CHARTER, corrected: this encoder writes
21+`reduced_tx_set: true` (`encode.rs:1660`, `:1760`) -- not 0. Under that bit
22+`get_tx_set` gives, per block class:
23+
24+| block class | tx size | set the WRITER uses | alphabet | types the search tried (before) | now |
25+|---|---|---|---|---|---|
26+| intra luma | 4x4, 8x8, 16x16 | `TX_SET_INTRA_2` (`intra_tx_type_{4,8,16}`) | 5 | DCT_DCT only | all 5 |
27+| intra luma | 32x32, 64x64 | none (`TxbSet::Luma{32,64}.tx_type == None`) | 1 | -- | -- |
28+| inter luma | 4x4..32x32 | `TX_SET_INTER_3` (`inter_tx_type_*`) | 2 (IDTX, DCT_DCT) | DCT_DCT only | DCT_DCT only |
29+| chroma | any | none, derived from uv_mode | -- | mode's default | unchanged |
30+
31+So the bytes reachable WITHOUT touching the frame header were the four
32+non-DCT members of `TX_SET_INTRA_2` on every intra luma unit at 16x16 and
33+below -- an alphabet the writer was already coding into, one symbol wide, and
34+never using. That is what this lane spends.
35+
36+Sets 13/17 (`DTT9_IDTX_1DDCT`, `ALL16`) that the charter names are NOT
37+reachable from here: they need `reduced_tx_set == 0` in the frame header,
38+which changes the alphabet of EVERY luma `tx_type` symbol in the stream
39+(`TxbSet::Luma*Set1`/`Set2` exist on the decode side with their CDFs; the
40+writer's set map at `tile.rs:4208` would have to take the bit). Deferred --
41+see below.
42+
43+## 2. Forward kernels
44+
45+`forward_transform_2d_typed` is basis-driven (`TxType::axes`), so
46+`V_DCT`/`H_DCT`/`V_ADST`/`H_ADST` and the plain ADST family already had
47+kernels; the FLIPADST family was refused by a `debug_assert`. A flipped axis
48+is the plain ADST kernel with the DECODER's output mirrored (`ud_flip` ->
49+row `h-1-i`, `lr_flip` -> column `w-1-j`), and a mirror is its own inverse,
50+so the analysis half is the same basis over the MIRRORED residual -- 12 lines,
51+no new kernel.
52+
53+Check: `transform::tests::a_typed_forward_round_trips_like_the_dct_one`, now
54+over all SIXTEEN types at 4x4/8x8/16x16 (was 3), each round trip's rmse under
55+2x `DCT_DCT`'s. PASS.
56+
57+## 3. The search + the writer
58+
59+* `encode::tx_type_candidates(set)` returns exactly the alphabet the writer
60+ can name for that set, so a searched type is always codable.
61+* `code_tx_depth` picks a type PER TRANSFORM UNIT (RD: sse + lambda * bits,
62+ the trial's bits carrying the `tx_type` symbol itself through
63+ `coeff_bits_typed`/`rdoq`), stored at `tu_row * n + tu_col` -- the writer's
64+ own index, so a unit the frame edge cuts away cannot slide the rest.
65+* `search_block` picks one for a whole-block transform, on the mode and angle
66+ already settled (libaom's ordering, the same shape the angle refinement has).
67+* `BlockCoeffs::luma_tx_types` carries them to `write_luma_tus` /
68+ `write_block_planes`; empty = `DCT_DCT` throughout, which is every inter,
69+ palette and filter-intra block.
70+* The symbol comes from the DECODER's own map (`decode::tx_type_symbol`,
71+ keyed by the CDF's alphabet width), so writer and reader cannot drift --
72+ and it already answers for the 7/12/16-symbol sets a `reduced_tx_set == 0`
73+ lane would turn on.
74+* Lever: `speed::TX_TYPE_SEARCH` (presets 0-6 on, 7-10 off) AND a content
75+ gate -- SCREEN FRAMES ONLY, see the gate table below. `EC_AV1_TXSET=0`
76+ forces it off entirely.
77+
78+## 4. Checks
79+
80+| check | result |
81+|---|---|
82+| `transform::tests::a_typed_forward_round_trips_like_the_dct_one` (16 types) | PASS |
83+| `encoder::tests::an_edge_clip_codes_every_reduced_set_tx_type_both_decoders_read_exactly` | PASS -- hits `[IDTX 12, DCT_DCT 15445, ADST_ADST 70, ADST_DCT 161, DCT_ADST 467]`, ours == ffmpeg every sample |
84+| `cargo test -p ec-av1 --lib --release round_trip` (19 tests) | PASS |
85+| `predicted_coeff_bits_track_the_tile_the_writer_wrote`, `tile_bytes_do_not_depend_on_the_thread_count --include-ignored`, `the_facade_codes_the_same_bytes_as_encode_sequence` | PASS |
86+| `cargo check -p ec-av1 --all-targets` | 0 errors, 0 warnings |
87+
88+
89+## 5. The 12-frame gate (`encode::tests::bd_rate_screen_native`, 12 frames, gop 12)
90+
91+Control re-run on this head first (`EC_AV1_TXSET=0`), arm = the search on for
92+every frame. BD-rate vs libaom cpu-used 6 / vs rav1e speed 6, lower is better;
93+wall is ours per row.
94+
95+| clip | control | arm (all frames) | delta | wall ctl -> arm |
96+|---|---|---|---|---|
97+| bars 1080p | -1.0% / -16.8% | -2.3% / -17.8% | -1.3 / -1.0 | 247.2s -> 280.4s |
98+| bars 2160p | +9.4% / -12.7% | +10.2% / -11.6% | +0.8 / +1.1 | 168.8s -> 180.7s |
99+| film A | +21.7% / -4.4% | +22.1% / -4.0% | +0.4 / +0.4 | 153.9s -> 203.9s |
100+| film B | +26.9% / -0.6% | +28.1% / +0.7% | +1.2 / +1.3 | 133.5s -> 164.0s |
101+| screen capture | +27.8% / -26.0% | **+20.8% / -30.1%** | **-7.0 / -4.1** | 83.7s -> 120.6s |
102+
103+KEEP RULE VERDICT on the unconditional arm: FAIL. The rule wants both film
104+rows down; both go UP (film A +0.4/+0.4, film B +1.2/+1.3). The capture wins
105+seven points against libaom and four against rav1e -- the largest single
106+screen move this lane has on record -- so the search ships behind the SAME
107+content gate palette, intrabc and the angle-delta refinement already stand
108+behind (`search.screen`): a non-screen frame is byte-identical to the encoder
109+before the lane.
110+
111+Class note for the film loss: an ADST/IDTX unit is a locally cheaper
112+reconstruction that the next picture then predicts from -- the same
113+`local-rd-on-references` shape lane-fitu measured for filter intra, which is
114+why the film rows lose while the intra-heavy capture wins.
115+
116+### Shipped state (screen gate on), confirm run
117+
118+| clip | control | shipped | note |
119+|---|---|---|---|
120+| bars 1080p | -1.0% / -16.8% | -1.0% / -16.8% | byte-identical (194497/299067/419042/567789 B) |
121+| bars 2160p | +9.4% / -12.7% | +9.4% / -12.7% | byte-identical (205409/321883/435765/564573 B) |
122+| film A | +21.7% / -4.4% | +21.7% / -4.4% | byte-identical (64392/102508/170169/413430 B) |
123+| film B | +26.9% / -0.6% | +26.9% / -0.6% | byte-identical (27442/50374/105485/296813 B) |
124+| screen capture | +27.8% / -26.0% | **+20.8% / -30.1%** | 36775/45758/57095/71711 B, wall 83.7s -> 96.2s (+15%) |
125+
126+Every non-screen row lands on the control's own byte counts to the digit --
127+the gate is the frame classifier, and the four non-capture clips classify 0
128+screen frames of 4 -- so nothing outside screen content moves, pins included.
129+
130+Pins: `encode::tests::the_encoders_own_streams_are_byte_identical_to_their_pins`
131+PASSES UNCHANGED at 8562 / 33357 -- the pin clip is not screen, so nothing to
132+re-pin.
133+
134+## 6. Preset lever and invariants
135+
136+`speed::TX_TYPE_SEARCH = [true x7, false x4]` (presets 0-6 on) on top of the
137+screen content gate. The FIVE-type fire count is preset 0's: at preset 6 the
138+mode/partition pruning removes the blocks `ADST_ADST` and `IDTX` were winning
139+on (hits `[0, 6192, 0, 79, 284, ..]`), so the witness asserts the full set at
140+preset 0 and "some non-`DCT_DCT` type fires" at every preset that carries the
141+lever.
142+
143+| invariant | preset 0 | preset 6 |
144+|---|---|---|
145+| `an_edge_clip_codes_every_reduced_set_tx_type_both_decoders_read_exactly` | PASS | PASS |
146+| `tile_bytes_do_not_depend_on_the_thread_count --include-ignored` | PASS | PASS |
147+| `the_facade_codes_the_same_bytes_as_encode_sequence` | PASS | PASS |
148+| `predicted_coeff_bits_track_the_tile_the_writer_wrote` | PASS | PASS |
149+| all four above with `EC_COMP_MISMATCH=1` | 0 mismatches | 0 mismatches |
150+
151+`every_speed_preset_decodes_sample_exact_through_both_decoders --ignored`
152+PASS (with `EC_COMP_MISMATCH=1`).
153+`the_encoders_own_streams_are_byte_identical_to_their_pins`: PASS at the
154+UNCHANGED 8562 / 33357 -- no re-pin, the pin clip is not screen content.
155+
156+## 7. The long-GOP gate at what ships, and the suite
157+
158+`encode::tests::bd_rate_film_long_gop` (48 pictures, gop 48) on the shipped
159+state -- both rows are non-screen and therefore byte-identical to the encoder
160+before the lane, which the 12-frame confirm run proves clip by clip:
161+
162+| clip | shipped | wall ours:libaom:rav1e |
163+|---|---|---|
164+| film A | +26.4% / -6.6% | 713.0s:38.4s:60.4s |
165+| film B | +89.8% / +9.1% | 459.0s:71.9s:59.0s |
166+
167+Full `ec-av1` suite, detached: **567 passed / 1 failed / 45 ignored**
168+(943s). The one failure is `stream::tests::no_per_frame_state_is_thread_local_any_more`
169+-- `["encode.rs: SB128"]`, main's own red from the sb128 merge that a fix lane
170+owns, not this lane's. `timeout 900 cargo check --workspace --all-targets -j4`:
171+0 errors, 0 `ec-av1` warnings.
172+
173+## 8. Deferred
174+
175+* `deferred: inter luma IDTX vs DCT_DCT (the two-type TX_SET_INTER_3 the
176+ writer already codes) -- the plumbing is done (an inter block's
177+ BlockCoeffs carries luma_tx_types through the same writer path), what is
178+ missing is the candidate loop in code_from_prediction/commit_inter_luma and
179+ a gate round -- unblocked by ~40 min of gate wall; the screen row is where
180+ it would pay, same as the intra half.`
181+* `deferred: reduced_tx_set = 0 and the 13/17 alphabets (DTT9_IDTX_1DDCT,
182+ ALL16) -- the FORWARD kernels are DONE and round-trip tested (all sixteen
183+ types), decode::tx_type_symbol already answers for the 7/12/16-symbol sets,
184+ and the decoder reads them; what is missing is the frame-header bit plus
185+ the writer's set map (tile.rs:4208 -> the Luma*Set1/Set2 variants) and a
186+ rav1e-speed-6-shaped candidate list per class -- unblocked by a lane of its
187+ own. Note the shape this lane measured first: the wider a set gets, the
188+ more the FILM rows lose (this five-type set already costs film A +0.4 and
189+ film B +1.2), so that lane should gate by content from the start rather
190+ than measure an unconditional arm.`
191+* `deferred: libaom's own tx_type histogram on film B (syntax_census) -- the
192+ charter's instrument half. Not run: the two gate slots were the budget, and
193+ the decision it would have informed (which types to offer) was settled by
194+ the gate itself. Unblocked by one census run.`